From ce140b67861a977dc2e9b2436f3fab77ee657cdc Mon Sep 17 00:00:00 2001 From: Bruno Barbieri <1247834+brunobar79@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:27:36 -0400 Subject: [PATCH] bump swaps sdk (#5574) --- package.json | 2 +- src/handlers/swap.ts | 9 +++++---- src/raps/actions/unlock.ts | 4 ++-- src/raps/unlockAndSwap.ts | 10 +++++----- yarn.lock | 8 ++++---- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index f24302481d8..f3b87b59ccd 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "@notifee/react-native": "5.6.0", "@rainbow-me/provider": "0.0.11", "@rainbow-me/react-native-animated-number": "0.0.2", - "@rainbow-me/swaps": "0.10.0", + "@rainbow-me/swaps": "0.12.0", "@react-native-async-storage/async-storage": "1.18.2", "@react-native-camera-roll/camera-roll": "5.7.1", "@react-native-clipboard/clipboard": "1.13.2", diff --git a/src/handlers/swap.ts b/src/handlers/swap.ts index 7c21f0c052a..abcc81cfe1e 100644 --- a/src/handlers/swap.ts +++ b/src/handlers/swap.ts @@ -9,12 +9,12 @@ import { getWrappedAssetMethod, PermitSupportedTokenList, Quote, - RAINBOW_ROUTER_CONTRACT_ADDRESS, + getRainbowRouterContractAddress, WRAPPED_ASSET, } from '@rainbow-me/swaps'; import { Contract } from '@ethersproject/contracts'; import { MaxUint256 } from '@ethersproject/constants'; -import { mapKeys, mapValues } from 'lodash'; +import { get, mapKeys, mapValues } from 'lodash'; import { IS_TESTING } from 'react-native-dotenv'; import { Token } from '../entities/tokens'; import { estimateGasWithPadding, getProviderForNetwork, toHexNoLeadingZeros } from './web3'; @@ -104,7 +104,8 @@ export const getDefaultGasLimitForTrade = (tradeDetails: Quote, chainId: ChainId export const getStateDiff = async (provider: StaticJsonRpcProvider, tradeDetails: Quote): Promise => { const tokenAddress = tradeDetails.sellTokenAddress; const fromAddr = tradeDetails.from; - const toAddr = RAINBOW_ROUTER_CONTRACT_ADDRESS; + const chainId = (await provider.getNetwork()).chainId; + const toAddr = getRainbowRouterContractAddress(chainId); const tokenContract = new Contract(tokenAddress, erc20ABI, provider); const { number: blockNumber } = await (provider.getBlock as () => Promise)(); @@ -161,7 +162,7 @@ export const getSwapGasLimitWithFakeApproval = async ( from: tradeDetails.from, gas: toHexNoLeadingZeros(gas), gasPrice: toHexNoLeadingZeros(`100000000000`), - to: (tradeDetails as CrosschainQuote)?.allowanceTarget || RAINBOW_ROUTER_CONTRACT_ADDRESS, + to: (tradeDetails as CrosschainQuote)?.allowanceTarget || getRainbowRouterContractAddress(chainId), value: '0x0', // 100 gwei }, 'latest', diff --git a/src/raps/actions/unlock.ts b/src/raps/actions/unlock.ts index a642e480c20..6686103960f 100644 --- a/src/raps/actions/unlock.ts +++ b/src/raps/actions/unlock.ts @@ -1,7 +1,7 @@ import { MaxUint256 } from '@ethersproject/constants'; import { Contract } from '@ethersproject/contracts'; import { Signer } from '@ethersproject/abstract-signer'; -import { ALLOWS_PERMIT, PermitSupportedTokenList, RAINBOW_ROUTER_CONTRACT_ADDRESS } from '@rainbow-me/swaps'; +import { ALLOWS_PERMIT, PermitSupportedTokenList, getRainbowRouterContractAddress } from '@rainbow-me/swaps'; import { captureException } from '@sentry/react-native'; import { isNull } from 'lodash'; import { alwaysRequireApprove } from '../../config/debug'; @@ -120,7 +120,7 @@ const unlock = async ( assetAddress, contractAddress, }); - const contractAllowsPermit = contractAddress === RAINBOW_ROUTER_CONTRACT_ADDRESS; + const contractAllowsPermit = contractAddress === getRainbowRouterContractAddress(chainId); gasLimit = await estimateApprove(accountAddress, assetAddress, contractAddress, chainId, contractAllowsPermit); } catch (e) { logger.sentry(`[${actionName}] Error estimating gas`); diff --git a/src/raps/unlockAndSwap.ts b/src/raps/unlockAndSwap.ts index ae1f1e18193..71fbea3337d 100644 --- a/src/raps/unlockAndSwap.ts +++ b/src/raps/unlockAndSwap.ts @@ -3,7 +3,7 @@ import { ChainId, ETH_ADDRESS as ETH_ADDRESS_AGGREGATOR, PermitSupportedTokenList, - RAINBOW_ROUTER_CONTRACT_ADDRESS, + getRainbowRouterContractAddress, WRAPPED_ASSET, } from '@rainbow-me/swaps'; import { assetNeedsUnlocking, estimateApprove } from './actions'; @@ -41,7 +41,7 @@ export const estimateUnlockAndSwap = async (swapParameters: SwapActionParameters accountAddress, inputAmount, inputCurrency, - RAINBOW_ROUTER_CONTRACT_ADDRESS, + getRainbowRouterContractAddress(chainId), chainId ); } @@ -50,7 +50,7 @@ export const estimateUnlockAndSwap = async (swapParameters: SwapActionParameters let swapGasLimit; if (swapAssetNeedsUnlocking) { - unlockGasLimit = await estimateApprove(accountAddress, inputCurrency.address, RAINBOW_ROUTER_CONTRACT_ADDRESS, chainId); + unlockGasLimit = await estimateApprove(accountAddress, inputCurrency.address, getRainbowRouterContractAddress(chainId), chainId); gasLimits = gasLimits.concat(unlockGasLimit); } @@ -88,7 +88,7 @@ export const createUnlockAndSwapRap = async (swapParameters: SwapActionParameter accountAddress, inputAmount, inputCurrency, - RAINBOW_ROUTER_CONTRACT_ADDRESS, + getRainbowRouterContractAddress(chainId), chainId ); } @@ -100,7 +100,7 @@ export const createUnlockAndSwapRap = async (swapParameters: SwapActionParameter amount: inputAmount, assetToUnlock: inputCurrency, chainId, - contractAddress: RAINBOW_ROUTER_CONTRACT_ADDRESS, + contractAddress: getRainbowRouterContractAddress(chainId), }); actions = actions.concat(unlock); } diff --git a/yarn.lock b/yarn.lock index 5fd5dae1200..481521f0dba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3314,10 +3314,10 @@ dependencies: react-merge-refs "^1.0.0" -"@rainbow-me/swaps@0.10.0": - version "0.10.0" - resolved "https://registry.yarnpkg.com/@rainbow-me/swaps/-/swaps-0.10.0.tgz#d1d2a67e751feb1fddf1206de5b0b4d514fedf2d" - integrity sha512-hBh9fhTWzqgDPIhi+R2ZzTGww0yIGnNZaHasEtpByRuHsxGWoljfbu3Eq/Sdi5pxpQiEnJPqmsLWfga+I54RmQ== +"@rainbow-me/swaps@0.12.0": + version "0.12.0" + resolved "https://registry.yarnpkg.com/@rainbow-me/swaps/-/swaps-0.12.0.tgz#0b52c304e4f4616993bc1943a590fc285cc3eef6" + integrity sha512-Ag26PvCHc4HvpJqUli6ojYx6slHPjSvlhmyvPhmia3vM21Zx1+o2/HxzzQh7Hu5Lig8vlJy5+0M0CcpsmFLJHA== dependencies: "@ethereumjs/util" "9.0.0" "@ethersproject/abi" "5.7.0"