From dc04cd01da1e3c0e5d42bc5c190824485e97c9a7 Mon Sep 17 00:00:00 2001 From: axtezy Date: Mon, 30 May 2022 15:24:32 +0300 Subject: [PATCH 1/2] Fix 1inch wrapped address --- package.json | 2 +- .../constants/wrapped-native.ts | 15 ++++++++++----- .../oneinch-common/oneinch-abstract-provider.ts | 15 ++++++++------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 5b5e45332b..f95ab1d56c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "1.3.0", + "version": "1.3.2", "description": "Simplify dApp creation", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/features/cross-chain/providers/rubic-trade-provider/rubic-cross-chain-contract-trade/constants/wrapped-native.ts b/src/features/cross-chain/providers/rubic-trade-provider/rubic-cross-chain-contract-trade/constants/wrapped-native.ts index c9c256a5c9..bf09d28e09 100644 --- a/src/features/cross-chain/providers/rubic-trade-provider/rubic-cross-chain-contract-trade/constants/wrapped-native.ts +++ b/src/features/cross-chain/providers/rubic-trade-provider/rubic-cross-chain-contract-trade/constants/wrapped-native.ts @@ -1,10 +1,15 @@ import { BLOCKCHAIN_NAME } from '@core/blockchain/models/blockchain-name'; import { CelerCrossChainSupportedBlockchain } from '@features/cross-chain/providers/celer-trade-provider/constants/celer-cross-chain-supported-blockchain'; +import { defaultEthereumProviderConfiguration } from '@features/instant-trades/dexes/ethereum/default-constants'; +import { defaultFantomProviderConfiguration } from '@features/instant-trades/dexes/fantom/default-constants'; +import { defaultBscProviderConfiguration } from '@features/instant-trades/dexes/bsc/default-constants'; +import { defaultPolygonProviderConfiguration } from '@features/instant-trades/dexes/polygon/default-constants'; +import { defaultAvalancheProviderConfiguration } from '@features/instant-trades/dexes/avalanche/default-constants'; export const wrappedNative: Record = { - [BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN]: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', - [BLOCKCHAIN_NAME.POLYGON]: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270', - [BLOCKCHAIN_NAME.AVALANCHE]: '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7', - [BLOCKCHAIN_NAME.FANTOM]: '0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83', - [BLOCKCHAIN_NAME.ETHEREUM]: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' + [BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN]: defaultBscProviderConfiguration.wethAddress, + [BLOCKCHAIN_NAME.POLYGON]: defaultPolygonProviderConfiguration.wethAddress, + [BLOCKCHAIN_NAME.AVALANCHE]: defaultAvalancheProviderConfiguration.wethAddress, + [BLOCKCHAIN_NAME.FANTOM]: defaultFantomProviderConfiguration.wethAddress, + [BLOCKCHAIN_NAME.ETHEREUM]: defaultEthereumProviderConfiguration.wethAddress }; diff --git a/src/features/instant-trades/dexes/common/oneinch-common/oneinch-abstract-provider.ts b/src/features/instant-trades/dexes/common/oneinch-common/oneinch-abstract-provider.ts index 15fe2ed8a2..48cffbcc83 100644 --- a/src/features/instant-trades/dexes/common/oneinch-common/oneinch-abstract-provider.ts +++ b/src/features/instant-trades/dexes/common/oneinch-common/oneinch-abstract-provider.ts @@ -83,12 +83,12 @@ export abstract class OneinchAbstractProvider extends InstantTradeProvider { ): Promise { const fullOptions = combineOptions(options, this.defaultOptions); - const fromClone = createTokenNativeAddressProxy(from, oneinchApiParams.nativeAddress); + const fromTokenClone = createTokenNativeAddressProxy(from, oneinchApiParams.nativeAddress); const toTokenClone = createTokenNativeAddressProxy(toToken, oneinchApiParams.nativeAddress); const supportedTokensAddresses = await this.getSupportedTokensByBlockchain(); if ( - !supportedTokensAddresses.includes(fromClone.address.toLowerCase()) || + !supportedTokensAddresses.includes(fromTokenClone.address.toLowerCase()) || !supportedTokensAddresses.includes(toTokenClone.address.toLowerCase()) ) { throw new RubicSdkError("Oneinch doesn't support this tokens"); @@ -97,7 +97,7 @@ export abstract class OneinchAbstractProvider extends InstantTradeProvider { const [contractAddress, { toTokenAmountInWei, estimatedGas, path, data }] = await Promise.all([ this.loadContractAddress(), - this.getTradeInfo(fromClone, toTokenClone, fullOptions) + this.getTradeInfo(fromTokenClone, toTokenClone, fullOptions) ]); path[0] = from; path[path.length - 1] = toToken; @@ -136,12 +136,13 @@ export abstract class OneinchAbstractProvider extends InstantTradeProvider { path: Token[]; data: string | null; }> { + const isDefaultWethAddress = options.wrappedAddress === oneinchApiParams.nativeAddress; + const isNative = from.isNative || from.address === oneinchApiParams.nativeAddress; + const fromTokenAddress = + isNative && !isDefaultWethAddress ? options.wrappedAddress : from.address; const quoteTradeParams: OneinchQuoteRequest = { params: { - fromTokenAddress: - options.wrappedAddress !== oneinchApiParams.nativeAddress - ? options.wrappedAddress - : from.address, + fromTokenAddress, toTokenAddress: toToken.address, amount: from.stringWeiAmount, mainRouteParts: options.disableMultihops ? '1' : undefined From 0574c27b9aae838fd5a7be5720eabd392677f770 Mon Sep 17 00:00:00 2001 From: axtezy Date: Mon, 30 May 2022 15:39:22 +0300 Subject: [PATCH 2/2] Fix naming --- .../dexes/common/oneinch-common/oneinch-abstract-provider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/features/instant-trades/dexes/common/oneinch-common/oneinch-abstract-provider.ts b/src/features/instant-trades/dexes/common/oneinch-common/oneinch-abstract-provider.ts index 48cffbcc83..40aba92f17 100644 --- a/src/features/instant-trades/dexes/common/oneinch-common/oneinch-abstract-provider.ts +++ b/src/features/instant-trades/dexes/common/oneinch-common/oneinch-abstract-provider.ts @@ -136,10 +136,10 @@ export abstract class OneinchAbstractProvider extends InstantTradeProvider { path: Token[]; data: string | null; }> { - const isDefaultWethAddress = options.wrappedAddress === oneinchApiParams.nativeAddress; + const isDefaultWrappedAddress = options.wrappedAddress === oneinchApiParams.nativeAddress; const isNative = from.isNative || from.address === oneinchApiParams.nativeAddress; const fromTokenAddress = - isNative && !isDefaultWethAddress ? options.wrappedAddress : from.address; + isNative && !isDefaultWrappedAddress ? options.wrappedAddress : from.address; const quoteTradeParams: OneinchQuoteRequest = { params: { fromTokenAddress,