Skip to content

Commit

Permalink
bump swaps sdk (#5574)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobar79 authored and ibrahimtaveras00 committed Mar 28, 2024
1 parent 783f120 commit ce140b6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions src/handlers/swap.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -104,7 +104,8 @@ export const getDefaultGasLimitForTrade = (tradeDetails: Quote, chainId: ChainId
export const getStateDiff = async (provider: StaticJsonRpcProvider, tradeDetails: Quote): Promise<any> => {
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<Block>)();

Expand Down Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions 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';
Expand Down Expand Up @@ -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`);
Expand Down
10 changes: 5 additions & 5 deletions src/raps/unlockAndSwap.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -41,7 +41,7 @@ export const estimateUnlockAndSwap = async (swapParameters: SwapActionParameters
accountAddress,
inputAmount,
inputCurrency,
RAINBOW_ROUTER_CONTRACT_ADDRESS,
getRainbowRouterContractAddress(chainId),
chainId
);
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -88,7 +88,7 @@ export const createUnlockAndSwapRap = async (swapParameters: SwapActionParameter
accountAddress,
inputAmount,
inputCurrency,
RAINBOW_ROUTER_CONTRACT_ADDRESS,
getRainbowRouterContractAddress(chainId),
chainId
);
}
Expand All @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -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"
Expand Down

0 comments on commit ce140b6

Please sign in to comment.