Skip to content

Commit

Permalink
Merge pull request #90 from Cryptorubic/feature/1inch-fix-address
Browse files Browse the repository at this point in the history
  • Loading branch information
axtezy authored May 30, 2022
2 parents 5a705e6 + 0574c27 commit b74cf6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CelerCrossChainSupportedBlockchain, string> = {
[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
};
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ export abstract class OneinchAbstractProvider extends InstantTradeProvider {
): Promise<OneinchTrade> {
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");
Expand All @@ -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;
Expand Down Expand Up @@ -136,12 +136,13 @@ export abstract class OneinchAbstractProvider extends InstantTradeProvider {
path: Token[];
data: string | null;
}> {
const isDefaultWrappedAddress = options.wrappedAddress === oneinchApiParams.nativeAddress;
const isNative = from.isNative || from.address === oneinchApiParams.nativeAddress;
const fromTokenAddress =
isNative && !isDefaultWrappedAddress ? 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
Expand Down

0 comments on commit b74cf6e

Please sign in to comment.