diff --git a/package.json b/package.json index 0068b73bdc..d020ede366 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "5.45.5", + "version": "5.45.6", "description": "Simplify dApp creation", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/core/blockchain/web3-public-service/web3-public/evm-web3-public/evm-web3-public.ts b/src/core/blockchain/web3-public-service/web3-public/evm-web3-public/evm-web3-public.ts index d63216598f..3878e60cb1 100644 --- a/src/core/blockchain/web3-public-service/web3-public/evm-web3-public/evm-web3-public.ts +++ b/src/core/blockchain/web3-public-service/web3-public/evm-web3-public/evm-web3-public.ts @@ -208,7 +208,8 @@ export class EvmWeb3Public extends Web3Public { private allowMultipleRequests(err: unknown): boolean { return ( (err instanceof Error && err.message.includes('unsigned transaction')) || - this.blockchainName === BLOCKCHAIN_NAME.ZETACHAIN + this.blockchainName === BLOCKCHAIN_NAME.ZETACHAIN || + (err instanceof Error && err.message.includes('out of gas')) ); } diff --git a/src/features/on-chain/calculation-manager/providers/dexes/common/uniswap-v3-abstract/utils/quoter-controller/spark-dex-v3-quoter-controller.ts b/src/features/on-chain/calculation-manager/providers/dexes/common/uniswap-v3-abstract/utils/quoter-controller/spark-dex-v3-quoter-controller.ts index 248eab2ec7..ae35644b5f 100644 --- a/src/features/on-chain/calculation-manager/providers/dexes/common/uniswap-v3-abstract/utils/quoter-controller/spark-dex-v3-quoter-controller.ts +++ b/src/features/on-chain/calculation-manager/providers/dexes/common/uniswap-v3-abstract/utils/quoter-controller/spark-dex-v3-quoter-controller.ts @@ -1,12 +1,16 @@ +import BigNumber from 'bignumber.js'; +import { RubicSdkError } from 'src/common/errors'; import { Token } from 'src/common/tokens'; import { compareAddresses } from 'src/common/utils/blockchain'; +import { notNull } from 'src/common/utils/object'; import { EvmBlockchainName } from 'src/core/blockchain/models/blockchain-name'; import { MethodData } from 'src/core/blockchain/web3-public-service/web3-public/models/method-data'; import { Exact } from 'src/features/on-chain/calculation-manager/providers/common/on-chain-trade/evm-on-chain-trade/models/exact'; +import { UniswapV3Route } from 'src/features/on-chain/calculation-manager/providers/dexes/common/uniswap-v3-abstract/models/uniswap-v3-route'; import { AbiItem } from 'web3-utils'; import { UniswapV3RouterConfiguration } from '../../models/uniswap-v3-router-configuration'; -import { LiquidityPool } from './models/liquidity-pool'; +import { FeeAmount, LiquidityPool } from './models/liquidity-pool'; import { UniswapV3QuoterController } from './uniswap-v3-quoter-controller'; interface GetQuoterMethodsDataOptions { @@ -27,6 +31,8 @@ interface QuoteExactInputSingleParams { } export class SparkDexV3QuoterController extends UniswapV3QuoterController { + protected readonly feeAmounts: FeeAmount[] = [100, 500, 3000]; + constructor( blockchain: EvmBlockchainName, routerConfiguration: UniswapV3RouterConfiguration, @@ -136,4 +142,62 @@ export class SparkDexV3QuoterController extends UniswapV3QuoterController { }) .flat(); } + + public async getAllRoutes( + from: Token, + to: Token, + exact: Exact, + weiAmount: string, + routeMaxTransitTokens: number + ): Promise { + const routesLiquidityPools = await this.getAllLiquidityPools(from, to); + const options: Omit = { + routesLiquidityPools, + from, + to, + exact, + weiAmount + }; + const quoterMethodsData = [...Array(routeMaxTransitTokens + 1)] + .map((_, maxTransitTokens) => + this.getQuoterMethodsData( + { + ...options, + maxTransitTokens + }, + [], + from.address + ) + ) + .flat(); + + const results = await this.web3Public.multicallContractMethods< + string | { amountOut: string } + >( + this.quoterContractAddress, + this.quoterContractABI, + quoterMethodsData.map(quoterMethodData => quoterMethodData.methodData) + ); + + return results + .map((result, index) => { + const pool = quoterMethodsData?.[index]; + if (!pool) { + throw new RubicSdkError('Pool has to be defined'); + } + if (result.success) { + return { + outputAbsoluteAmount: new BigNumber( + result?.output! instanceof Object + ? result?.output?.amountOut + : result.output! + ), + poolsPath: pool.poolsPath, + initialTokenAddress: from.address + }; + } + return null; + }) + .filter(notNull); + } } diff --git a/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-contract-abi.ts b/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-contract-abi.ts index 749fd46904..e7a4536c73 100644 --- a/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-contract-abi.ts +++ b/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-contract-abi.ts @@ -1,6 +1,6 @@ import { AbiItem } from 'web3-utils'; -export const SPARK_DEX_V3_FLARE_SWAP_ROUTER_CONTRACT = '0xCb70f9bA912a99849d19FC24Ccb7925ED307b877'; +export const SPARK_DEX_V3_FLARE_SWAP_ROUTER_CONTRACT = '0x8a1E35F5c98C4E85B36B7B253222eE17773b2781'; export const SPARK_DEX_V3_FLARE_SWAP_ROUTER_ABI: AbiItem[] = [ { diff --git a/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-quoter-data.ts b/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-quoter-data.ts index 7184085550..3ffb7e865e 100644 --- a/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-quoter-data.ts +++ b/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-quoter-data.ts @@ -1,7 +1,7 @@ import { AbiItem } from 'web3-utils'; export const SPARK_DEX_V3_FLARE_QUOTER_CONTRACT_ADDRESS = - '0x2DcABbB3a5Fe9DBb1F43edf48449aA7254Ef3a80'; + '0x5B5513c55fd06e2658010c121c37b07fC8e8B705'; export const SPARK_DEX_V3_FLARE_QUOTER_CONTRACT_ABI: AbiItem[] = [ { diff --git a/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/uniswap-v3-spark-dex-flare-router-config.ts b/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-router-config.ts similarity index 100% rename from src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/uniswap-v3-spark-dex-flare-router-config.ts rename to src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-router-config.ts diff --git a/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/spark-dex-v3-flare-provider.ts b/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/spark-dex-v3-flare-provider.ts index 9e85e7f073..25f471d4e3 100644 --- a/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/spark-dex-v3-flare-provider.ts +++ b/src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/spark-dex-v3-flare-provider.ts @@ -4,6 +4,7 @@ import { compareAddresses } from 'src/common/utils/blockchain'; import { BLOCKCHAIN_NAME } from 'src/core/blockchain/models/blockchain-name'; import { EvmWeb3Pure } from 'src/core/blockchain/web3-pure/typed-web3-pure/evm-web3-pure/evm-web3-pure'; import { createTokenNativeAddressProxyInPathStartAndEnd } from 'src/features/common/utils/token-native-address-proxy'; +import { UNI_SWAP_V3_SPARK_DEX_FLARE_ROUTER_CONFIGURATION } from 'src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-router-config'; import { ON_CHAIN_TRADE_TYPE, @@ -22,7 +23,6 @@ import { SPARK_DEX_V3_FLARE_QUOTER_CONTRACT_ABI, SPARK_DEX_V3_FLARE_QUOTER_CONTRACT_ADDRESS } from './constants/spark-dex-v3-flare-quoter-data'; -import { UNI_SWAP_V3_SPARK_DEX_FLARE_ROUTER_CONFIGURATION } from './constants/uniswap-v3-spark-dex-flare-router-config'; import { SparkDexV3FlareTrade } from './spark-dex-v3-flare-trade'; export class SparkDexV3FlareProvider extends UniswapV3AlgebraAbstractProvider { @@ -47,7 +47,7 @@ export class SparkDexV3FlareProvider extends UniswapV3AlgebraAbstractProvider