diff --git a/package.json b/package.json index e5991401de..2b1626af0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "2.9.5", + "version": "2.9.9", "description": "Simplify dApp creation", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/features/cross-chain/providers/lifi-trade-provider/constants/lifi-cross-chain-supported-blockchain.ts b/src/features/cross-chain/providers/lifi-trade-provider/constants/lifi-cross-chain-supported-blockchain.ts index ef19ca3456..1096f850a5 100644 --- a/src/features/cross-chain/providers/lifi-trade-provider/constants/lifi-cross-chain-supported-blockchain.ts +++ b/src/features/cross-chain/providers/lifi-trade-provider/constants/lifi-cross-chain-supported-blockchain.ts @@ -9,9 +9,12 @@ export const lifiCrossChainSupportedBlockchains = [ BLOCKCHAIN_NAME.MOONRIVER, BLOCKCHAIN_NAME.ARBITRUM, BLOCKCHAIN_NAME.OPTIMISM, + BLOCKCHAIN_NAME.CRONOS, + BLOCKCHAIN_NAME.OKE_X_CHAIN, BLOCKCHAIN_NAME.GNOSIS, BLOCKCHAIN_NAME.FUSE, - BLOCKCHAIN_NAME.MOONBEAM + BLOCKCHAIN_NAME.MOONBEAM, + BLOCKCHAIN_NAME.CELO ] as const; export type LifiCrossChainSupportedBlockchain = typeof lifiCrossChainSupportedBlockchains[number]; diff --git a/src/features/cross-chain/providers/lifi-trade-provider/lifi-cross-chain-trade-provider.ts b/src/features/cross-chain/providers/lifi-trade-provider/lifi-cross-chain-trade-provider.ts index 76f35fc9c5..0130bbbfad 100644 --- a/src/features/cross-chain/providers/lifi-trade-provider/lifi-cross-chain-trade-provider.ts +++ b/src/features/cross-chain/providers/lifi-trade-provider/lifi-cross-chain-trade-provider.ts @@ -1,11 +1,11 @@ -import { CROSS_CHAIN_TRADE_TYPE } from 'src/features'; -import { BlockchainName, BlockchainsInfo, PriceToken, Web3Pure } from 'src/core'; +import { CROSS_CHAIN_TRADE_TYPE, LiFiTradeSubtype, TradeType } from 'src/features'; +import { BLOCKCHAIN_NAME, BlockchainName, BlockchainsInfo, PriceToken, Web3Pure } from 'src/core'; import BigNumber from 'bignumber.js'; import { LifiCrossChainSupportedBlockchain, lifiCrossChainSupportedBlockchains } from 'src/features/cross-chain/providers/lifi-trade-provider/constants/lifi-cross-chain-supported-blockchain'; -import LIFI, { RouteOptions } from '@lifi/sdk'; +import LIFI, { Route, RouteOptions } from '@lifi/sdk'; import { LifiCrossChainTrade } from 'src/features/cross-chain/providers/lifi-trade-provider/lifi-cross-chain-trade'; import { Injector } from 'src/core/sdk/injector'; import { WrappedCrossChainTrade } from 'src/features/cross-chain/providers/common/models/wrapped-cross-chain-trade'; @@ -72,14 +72,20 @@ export class LifiCrossChainTradeProvider extends CrossChainTradeProvider { ); const tokenAmountIn = from.weiAmount.minus(feeAmount).toFixed(0); - const routeOptions: RouteOptions = { + let routeOptions: RouteOptions = { slippage: options.slippageTolerance, order: 'RECOMMENDED', - allowSwitchChain: false, - bridges: { - deny: ['multichain'] // @TODO remove after whitelisting - } + allowSwitchChain: false }; + // @TODO remove after whitelisting + if (fromBlockchain === BLOCKCHAIN_NAME.CRONOS || toBlockchain === BLOCKCHAIN_NAME.CRONOS) { + routeOptions = { + ...routeOptions, + bridges: { + deny: ['multichain'] + } + }; + } const fromChainId = BlockchainsInfo.getBlockchainByName(fromBlockchain).id; const toChainId = BlockchainsInfo.getBlockchainByName(toBlockchain).id; @@ -122,21 +128,7 @@ export class LifiCrossChainTradeProvider extends CrossChainTradeProvider { ? await LifiCrossChainTrade.getGasData(from, to, bestRoute) : null; - const steps = (bestRoute.steps[0] as LifiStep).includedSteps; - const sourceDex = - steps?.[0] && steps[0].action.fromChainId === steps[0].action.toChainId - ? steps?.[0].tool - : undefined; - - const [, ...stepsWithoutFirst] = steps; - const targetDex = stepsWithoutFirst.find( - provider => provider.action.fromChainId === provider.action.toChainId - )?.tool; - - const itType = { - from: sourceDex ? lifiProviders[sourceDex] : undefined, - to: targetDex ? lifiProviders[targetDex] : undefined - }; + const { itType, subType } = this.parseTradeTypes(bestRoute); const trade = new LifiCrossChainTrade( { @@ -147,7 +139,8 @@ export class LifiCrossChainTradeProvider extends CrossChainTradeProvider { toTokenAmountMin: Web3Pure.fromWei(bestRoute.toAmountMin, to.decimals), feeInfo, priceImpact, - itType + itType, + subType }, options.providerAddress ); @@ -213,4 +206,35 @@ export class LifiCrossChainTradeProvider extends CrossChainTradeProvider { cryptoFee: null }; } + + private parseTradeTypes(route: Route): { + subType: LiFiTradeSubtype; + itType: { from: TradeType | undefined; to: TradeType | undefined }; + } { + const steps = + route.steps.length === 1 ? (route.steps[0] as LifiStep).includedSteps : route.steps; + const sourceDex = + steps?.[0] && steps[0].action.fromChainId === steps[0].action.toChainId + ? steps?.[0].toolDetails.name.toLowerCase() + : undefined; + + const [, ...stepsWithoutFirst] = steps; + const targetDex = stepsWithoutFirst + .find(provider => provider.action.fromChainId === provider.action.toChainId) + ?.toolDetails.name.toLowerCase(); + + const subType = steps?.find( + provider => provider.action.fromChainId !== provider.action.toChainId + )?.tool as LiFiTradeSubtype; + + const itType = { + from: sourceDex ? lifiProviders[sourceDex] : undefined, + to: targetDex ? lifiProviders[targetDex] : undefined + }; + + return { + subType, + itType + }; + } } diff --git a/src/features/cross-chain/providers/lifi-trade-provider/lifi-cross-chain-trade.ts b/src/features/cross-chain/providers/lifi-trade-provider/lifi-cross-chain-trade.ts index 354a960652..c4463e54c0 100644 --- a/src/features/cross-chain/providers/lifi-trade-provider/lifi-cross-chain-trade.ts +++ b/src/features/cross-chain/providers/lifi-trade-provider/lifi-cross-chain-trade.ts @@ -2,6 +2,7 @@ import BigNumber from 'bignumber.js'; import { BlockchainsInfo, PriceTokenAmount, Web3Public, Web3Pure } from 'src/core'; import { CROSS_CHAIN_TRADE_TYPE, + Li_FI_TRADE_SUBTYPE, SwapTransactionOptions, TRADE_TYPE, TradeType @@ -57,7 +58,8 @@ export class LifiCrossChainTrade extends CrossChainTrade { itType: { from: TRADE_TYPE.ONE_INCH, to: TRADE_TYPE.ONE_INCH - } + }, + subType: Li_FI_TRADE_SUBTYPE.CONNEXT }, EMPTY_ADDRESS ).getContractParams({}); @@ -126,6 +128,7 @@ export class LifiCrossChainTrade extends CrossChainTrade { feeInfo: FeeInfo; priceImpact: number; itType: { from: TradeType | undefined; to: TradeType | undefined }; + subType: LiFiTradeSubtype; }, providerAddress: string ) { @@ -136,7 +139,7 @@ export class LifiCrossChainTrade extends CrossChainTrade { this.route = crossChainTrade.route; this.gasData = crossChainTrade.gasData; this.toTokenAmountMin = crossChainTrade.toTokenAmountMin; - this.subType = this.route?.steps?.[0]?.tool as LiFiTradeSubtype; + this.subType = crossChainTrade.subType; this.feeInfo = crossChainTrade.feeInfo; this.priceImpact = crossChainTrade.priceImpact; diff --git a/src/features/cross-chain/providers/lifi-trade-provider/models/lifi-providers.ts b/src/features/cross-chain/providers/lifi-trade-provider/models/lifi-providers.ts index 636a9553d9..468194d36a 100644 --- a/src/features/cross-chain/providers/lifi-trade-provider/models/lifi-providers.ts +++ b/src/features/cross-chain/providers/lifi-trade-provider/models/lifi-providers.ts @@ -1,5 +1,5 @@ export const Li_FI_TRADE_SUBTYPE = { - CONNECT: 'connext', + CONNEXT: 'connext', HOP: 'hop', CELER_BRIDGE: 'cbridge', MULTICHAIN: 'multichain',