UNPKG

rubic-sdk

Version:
66 lines 3.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CelerUniswapV3Trade = void 0; const errors_1 = require("../../../../../../../../common/errors"); const blockchain_1 = require("../../../../../../../../common/utils/blockchain"); const evm_web3_pure_1 = require("../../../../../../../../core/blockchain/web3-pure/typed-web3-pure/evm-web3-pure/evm-web3-pure"); const provider_type_enum_1 = require("../../models/provider-type.enum"); const swap_router_contract_abi_1 = require("../../../../../../../on-chain/calculation-manager/providers/dexes/common/uniswap-v3-abstract/constants/swap-router-contract-abi"); const uniswap_v3_quoter_controller_1 = require("../../../../../../../on-chain/calculation-manager/providers/dexes/common/uniswap-v3-abstract/utils/quoter-controller/uniswap-v3-quoter-controller"); class CelerUniswapV3Trade { constructor(uniswapV3Trade) { this.uniswapV3Trade = uniswapV3Trade; this.defaultDeadline = 999999999999999; } getFirstPath() { const { route } = this.uniswapV3Trade; return uniswap_v3_quoter_controller_1.UniswapV3QuoterController.getEncodedPoolsPath(route.poolsPath, route.initialTokenAddress); } getSecondPath() { const { route } = this.uniswapV3Trade; const path = [evm_web3_pure_1.EvmWeb3Pure.addressToBytes32(route.initialTokenAddress)]; let lastTokenAddress = route.initialTokenAddress; route.poolsPath.forEach(pool => { const newToken = (0, blockchain_1.compareAddresses)(pool.token0.address, lastTokenAddress) ? pool.token1 : pool.token0; lastTokenAddress = newToken.address; path.push(`0x${pool.fee.toString(16).padStart(6, '0').padEnd(24, '0')}${lastTokenAddress .slice(2) .toLowerCase()}`); }); return path; } async modifyArgumentsForProvider(methodArguments) { const exactTokensForTokens = true; if (!methodArguments?.[0]) { throw new errors_1.RubicSdkError('[RUBIC SDK] Method arguments array must not be empty'); } methodArguments[0].push(exactTokensForTokens); } getCelerSourceObject() { const dex = swap_router_contract_abi_1.UNISWAP_V3_SWAP_ROUTER_CONTRACT_ADDRESS; const path = this.getFirstPath(); const amountOutMinimum = this.uniswapV3Trade.toTokenAmountMin.stringWeiAmount; return { dex, path, deadline: this.defaultDeadline, amountOutMinimum }; } getCelerDestinationObject(integratorAddress, receiverAddress) { const dex = swap_router_contract_abi_1.UNISWAP_V3_SWAP_ROUTER_CONTRACT_ADDRESS; const pathV3 = this.getFirstPath(); const deadline = this.defaultDeadline; const amountOutMinimum = this.uniswapV3Trade.toTokenAmountMin.stringWeiAmount; return { dex, nativeOut: this.uniswapV3Trade.to.isNative, receiverEOA: receiverAddress, integrator: integratorAddress, version: provider_type_enum_1.SwapVersion.V3, path: [evm_web3_pure_1.EvmWeb3Pure.EMPTY_ADDRESS], pathV3, deadline, amountOutMinimum }; } } exports.CelerUniswapV3Trade = CelerUniswapV3Trade; //# sourceMappingURL=celer-uniswap-v3-trade.js.map