UNPKG

rubic-sdk

Version:
62 lines 3.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BrontoFinanceProvider = void 0; const errors_1 = require("../../../../../../../common/errors"); const blockchain_1 = require("../../../../../../../common/utils/blockchain"); const blockchain_name_1 = require("../../../../../../../core/blockchain/models/blockchain-name"); const evm_web3_pure_1 = require("../../../../../../../core/blockchain/web3-pure/typed-web3-pure/evm-web3-pure/evm-web3-pure"); const token_native_address_proxy_1 = require("../../../../../../common/utils/token-native-address-proxy"); const on_chain_trade_type_1 = require("../../../common/models/on-chain-trade-type"); const bronto_finance_quoter_controller_1 = require("../../common/uniswap-v3-abstract/bronto-finance-quoter-controller"); const swap_router_contract_abi_1 = require("../../common/uniswap-v3-abstract/constants/swap-router-contract-abi"); const uniswap_v3_algebra_abstract_provider_1 = require("../../common/uniswap-v3-algebra-abstract/uniswap-v3-algebra-abstract-provider"); const bronto_finance_trade_1 = require("./bronto-finance-trade"); const bronto_finance_quoter_data_1 = require("./constants/bronto-finance-quoter-data"); const provider_config_1 = require("./constants/provider-config"); const router_config_1 = require("./constants/router-config"); class BrontoFinanceProvider extends uniswap_v3_algebra_abstract_provider_1.UniswapV3AlgebraAbstractProvider { constructor() { super(...arguments); this.blockchain = blockchain_name_1.BLOCKCHAIN_NAME.MEGAETH_TESTNET; this.contractAbi = swap_router_contract_abi_1.UNISWAP_V3_SWAP_ROUTER_CONTRACT_ABI; this.OnChainTradeClass = bronto_finance_trade_1.BrontoFinanceTrade; this.contractAddress = provider_config_1.MEGAETH_TESTNET_ROUTER_CONTRACT_ADDRESS; this.providerConfiguration = provider_config_1.MEGAETH_TESTNET_PROVIDER_CONFIGURATION; this.routerConfiguration = router_config_1.MEGAETH_TESTNET_ROUTER_CONFIGURATION; this.quoterController = new bronto_finance_quoter_controller_1.BrontoFinanceQuoterController(this.blockchain, this.routerConfiguration, bronto_finance_quoter_data_1.BRONTO_FINANCE_QUOTER_CONTRACT_ADDRESS, bronto_finance_quoter_data_1.BRONTO_FINANCE_QUOTER_CONTRACT_ABI, '0x2E2E73885A21E654172fB8A0D50F5E7729E74F3c'); } get type() { return on_chain_trade_type_1.ON_CHAIN_TRADE_TYPE.BRONTO_FINANCE; } createTradeInstance(tradeStruct, route, providerAddress) { const path = this.extractPath(route); return new this.OnChainTradeClass({ ...tradeStruct, path, route }, providerAddress); } extractPath(route) { const initialPool = route.poolsPath[0]; if (!initialPool) { throw new errors_1.RubicSdkError('Initial pool has to be defined'); } const path = [ (0, blockchain_1.compareAddresses)(initialPool.token0.address, route.initialTokenAddress) ? initialPool.token0 : initialPool.token1 ]; const lastToken = path[path.length - 1]; if (!lastToken) { throw new errors_1.RubicSdkError('Last token has to be defined'); } route.poolsPath.forEach(pool => { path.push(!(0, blockchain_1.compareAddresses)(pool.token0.address, lastToken.address) ? pool.token0 : pool.token1); }); return (0, token_native_address_proxy_1.createTokenNativeAddressProxyInPathStartAndEnd)(path, evm_web3_pure_1.EvmWeb3Pure.nativeTokenAddress); } } exports.BrontoFinanceProvider = BrontoFinanceProvider; //# sourceMappingURL=bronto-finance-provider.js.map