"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetNetworkGasInfoUseCase = void 0;
const not_found_error_1 = require("../../../domain/errors/not-found-error");
const DEFAULT_GAS_PRICE = '20000000000'; // 20 gwei
const SWAP_GAS_LIMIT = 200000;
class GetNetworkGasInfoUseCase {
    networkRepository;
    rpcClient;
    constructor(networkRepository, rpcClient) {
        this.networkRepository = networkRepository;
        this.rpcClient = rpcClient;
    }
    async execute(networkId) {
        const network = await this.networkRepository.findById(networkId);
        if (!network) {
            throw new not_found_error_1.NotFoundError('Network', networkId);
        }
        const estimate = network.chainId
            ? await this.rpcClient.getGasEstimate(network.chainId)
            : null;
        const blockNumber = estimate?.blockNumber
            ? estimate.blockNumber
            : this.fallbackBlockNumber();
        const gasPrice = estimate?.gasPrice ?? DEFAULT_GAS_PRICE;
        const gasLimit = estimate?.gasLimit ?? SWAP_GAS_LIMIT;
        const fee = (BigInt(gasPrice) * BigInt(gasLimit)).toString();
        return {
            networkId: network.id,
            blockNumber,
            gasPrice,
            gasLimit,
            fee,
        };
    }
    fallbackBlockNumber() {
        return Math.floor(Date.now() / 1000);
    }
}
exports.GetNetworkGasInfoUseCase = GetNetworkGasInfoUseCase;
//# sourceMappingURL=get-network-gas-info.use-case.js.map