From 51f29b15bb1654a441174871bde9c1efac822a88 Mon Sep 17 00:00:00 2001 From: ottebrut Date: Mon, 8 Aug 2022 14:44:23 +0300 Subject: [PATCH 1/7] Add Cronos and Oke to cross chain --- package.json | 2 +- .../constants/lifi-cross-chain-supported-blockchain.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c3e493fdb8..d665b1d9b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "2.8.2", + "version": "2.8.4-alpha.0", "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..a6cb66a986 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,6 +9,8 @@ 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 From cf88bf918dbe666a63c0fd2515ff981d55450ee3 Mon Sep 17 00:00:00 2001 From: ottebrut Date: Tue, 9 Aug 2022 17:50:22 +0300 Subject: [PATCH 2/7] Add multichain in LiFi --- package.json | 2 +- .../lifi-trade-provider/lifi-cross-chain-trade-provider.ts | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d665b1d9b2..a9a43e1a64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "2.8.4-alpha.0", + "version": "2.8.4-alpha.1", "description": "Simplify dApp creation", "main": "lib/index.js", "types": "lib/index.d.ts", 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 5de300221d..ad88c1ad87 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 @@ -75,10 +75,7 @@ export class LifiCrossChainTradeProvider extends CrossChainTradeProvider { const routeOptions: RouteOptions = { slippage: options.slippageTolerance, order: 'RECOMMENDED', - allowSwitchChain: false, - bridges: { - deny: ['multichain'] // @TODO remove after whitelisting - } + allowSwitchChain: false }; const fromChainId = BlockchainsInfo.getBlockchainByName(fromBlockchain).id; From d0de9d7c3ac8a0ff8df38e84ea23f4a6bda5cb4e Mon Sep 17 00:00:00 2001 From: ottebrut Date: Thu, 11 Aug 2022 12:09:33 +0300 Subject: [PATCH 3/7] Add celo to lifi --- package.json | 2 +- .../constants/lifi-cross-chain-supported-blockchain.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a9a43e1a64..e9463ded68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "2.8.4-alpha.1", + "version": "2.8.4-alpha.2", "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 a6cb66a986..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 @@ -13,7 +13,8 @@ export const lifiCrossChainSupportedBlockchains = [ 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]; From 8dd3e9440279bffe93ef2212909b8ae12fe88137 Mon Sep 17 00:00:00 2001 From: ottebrut Date: Thu, 11 Aug 2022 16:50:34 +0300 Subject: [PATCH 4/7] Update parsing lifi providers --- package.json | 2 +- .../lifi-cross-chain-trade-provider.ts | 54 ++++++++++++------- .../lifi-cross-chain-trade.ts | 7 ++- .../models/lifi-providers.ts | 2 +- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index b1de56fadd..d4ef8c4cfd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "2.8.4-alpha.2", + "version": "2.8.4-alpha.3", "description": "Simplify dApp creation", "main": "lib/index.js", "types": "lib/index.d.ts", 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 6014417345..191d2f482d 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 { CROSS_CHAIN_TRADE_TYPE, LiFiTradeSubtype, TradeType } from 'src/features'; import { 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'; @@ -119,21 +119,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( { @@ -144,7 +130,8 @@ export class LifiCrossChainTradeProvider extends CrossChainTradeProvider { toTokenAmountMin: Web3Pure.fromWei(bestRoute.toAmountMin, to.decimals), feeInfo, priceImpact, - itType + itType, + subType }, options.providerAddress ); @@ -210,4 +197,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', From f48e8233750ff839c6c62972706497c0a2656c5f Mon Sep 17 00:00:00 2001 From: ottebrut Date: Thu, 11 Aug 2022 18:09:38 +0300 Subject: [PATCH 5/7] Exclude multichain from certain blockchains --- package.json | 2 +- .../lifi-cross-chain-trade-provider.ts | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d4ef8c4cfd..5162b9dd03 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "2.8.4-alpha.3", + "version": "2.8.4-alpha.4", "description": "Simplify dApp creation", "main": "lib/index.js", "types": "lib/index.d.ts", 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 191d2f482d..6f0dd637d6 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,5 +1,5 @@ import { CROSS_CHAIN_TRADE_TYPE, LiFiTradeSubtype, TradeType } from 'src/features'; -import { BlockchainName, BlockchainsInfo, PriceToken, Web3Pure } from 'src/core'; +import { BLOCKCHAIN_NAME, BlockchainName, BlockchainsInfo, PriceToken, Web3Pure } from 'src/core'; import BigNumber from 'bignumber.js'; import { LifiCrossChainSupportedBlockchain, @@ -72,11 +72,23 @@ 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 }; + // @TODO remove after whitelisting + if ( + fromBlockchain === BLOCKCHAIN_NAME.CRONOS || + fromBlockchain === BLOCKCHAIN_NAME.OKE_X_CHAIN + ) { + routeOptions = { + ...routeOptions, + bridges: { + deny: ['multichain'] + } + }; + } const fromChainId = BlockchainsInfo.getBlockchainByName(fromBlockchain).id; const toChainId = BlockchainsInfo.getBlockchainByName(toBlockchain).id; From ddf4fc2b8a521ce79fd82216829719959dbba5cb Mon Sep 17 00:00:00 2001 From: ottebrut Date: Thu, 11 Aug 2022 18:24:11 +0300 Subject: [PATCH 6/7] Update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5162b9dd03..65da1ff1ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "2.8.4-alpha.4", + "version": "2.9.6", "description": "Simplify dApp creation", "main": "lib/index.js", "types": "lib/index.d.ts", From 4ffb8763a4dca549cad35a66c4a4b782325f2d7b Mon Sep 17 00:00:00 2001 From: ottebrut Date: Mon, 15 Aug 2022 10:10:18 +0300 Subject: [PATCH 7/7] minor fix --- package.json | 2 +- .../lifi-trade-provider/lifi-cross-chain-trade-provider.ts | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 65da1ff1ea..2b1626af0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "2.9.6", + "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/lifi-cross-chain-trade-provider.ts b/src/features/cross-chain/providers/lifi-trade-provider/lifi-cross-chain-trade-provider.ts index 6f0dd637d6..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 @@ -78,10 +78,7 @@ export class LifiCrossChainTradeProvider extends CrossChainTradeProvider { allowSwitchChain: false }; // @TODO remove after whitelisting - if ( - fromBlockchain === BLOCKCHAIN_NAME.CRONOS || - fromBlockchain === BLOCKCHAIN_NAME.OKE_X_CHAIN - ) { + if (fromBlockchain === BLOCKCHAIN_NAME.CRONOS || toBlockchain === BLOCKCHAIN_NAME.CRONOS) { routeOptions = { ...routeOptions, bridges: {