diff --git a/src/entities/index.ts b/src/entities/index.ts index 75ef7a30256..79ff4248f82 100644 --- a/src/entities/index.ts +++ b/src/entities/index.ts @@ -1,16 +1,16 @@ export { default as AssetTypes, AssetType } from './assetTypes'; -export type { - BlocksToConfirmation, - BlocksToConfirmationByBaseFee, - BlocksToConfirmationByPriorityFee, - GasFeeParam, - GasFeeParams, - GasFeeParamsBySpeed, - TransactionGasParams, - GasFeeLegacyParams, - GasFeeLegacyParamsBySpeed, +export { + type BlocksToConfirmation, + type BlocksToConfirmationByBaseFee, + type BlocksToConfirmationByPriorityFee, + type GasFeeParam, + type GasFeeParams, + type GasFeeParamsBySpeed, + type TransactionGasParams, + type GasFeeLegacyParams, + type GasFeeLegacyParamsBySpeed, GasSpeed, - TransactionLegacyGasParams, + type TransactionLegacyGasParams, } from './gas'; export { NativeCurrencyKeys } from './nativeCurrencyTypes'; export type { NativeCurrencyKey } from './nativeCurrencyTypes'; diff --git a/src/helpers/gas.ts b/src/helpers/gas.ts deleted file mode 100644 index 540cf9752ad..00000000000 --- a/src/helpers/gas.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { Network } from '@/networks/types'; -import { memoFn } from '../utils/memoFn'; -import { gasUtils } from '@/utils'; -import { getNetworkObj } from '@/networks'; - -const { GasTrends } = gasUtils; -const { FALLING, NO_TREND, RISING, STABLE, SURGING } = GasTrends; - -const PRIORITY_FEE_INCREMENT = 1; -const PRIORITY_FEE_L2_INCREMENT = 0.01; - -const PRIORITY_FEE_THRESHOLD = 0.15; -const PRIORITY_FEE_L2_THRESHOLD = 0.01; - -export const getTrendKey = memoFn((trend: number) => { - if (trend === -1) { - return FALLING; - } else if (trend === 1) { - return RISING; - } else if (trend === 2) { - return SURGING; - } else if (trend === 0) { - return STABLE; - } - return NO_TREND; -}); - -export const calculateMinerTipAddDifference = memoFn((maxPriorityFee: string, txNetwork: Network) => { - const networkObject = getNetworkObj(txNetwork); - const isL2 = networkObject.networkType === 'layer2'; - const FEE_INCREMENT = isL2 ? PRIORITY_FEE_L2_INCREMENT : PRIORITY_FEE_INCREMENT; - const FEE_THRESHOLD = isL2 ? PRIORITY_FEE_L2_THRESHOLD : PRIORITY_FEE_THRESHOLD; - const diff = Math.round((Number(maxPriorityFee) % FEE_INCREMENT) * 100) / 100; - if (diff > FEE_INCREMENT - FEE_THRESHOLD) { - return 2 * FEE_INCREMENT - diff; - } else { - return FEE_INCREMENT - diff; - } -}); - -export const calculateMinerTipSubstDifference = memoFn((maxPriorityFee: string, txNetwork: Network) => { - const networkObject = getNetworkObj(txNetwork); - const isL2 = networkObject.networkType === 'layer2'; - const FEE_INCREMENT = isL2 ? PRIORITY_FEE_L2_INCREMENT : PRIORITY_FEE_INCREMENT; - const FEE_THRESHOLD = isL2 ? PRIORITY_FEE_L2_THRESHOLD : PRIORITY_FEE_THRESHOLD; - const diff = Math.round((Number(maxPriorityFee) % FEE_INCREMENT) * 100) / 100; - if (diff < FEE_THRESHOLD) { - return FEE_INCREMENT + diff; - } else { - return diff || FEE_INCREMENT; - } -}); diff --git a/src/hooks/useHasEnoughGas.ts b/src/hooks/useHasEnoughGas.ts new file mode 100644 index 00000000000..d283375a97a --- /dev/null +++ b/src/hooks/useHasEnoughGas.ts @@ -0,0 +1,13 @@ +import { useGasStore } from '@/state/gas/gasStore'; +import { ChainId } from '@/entities/chains'; +import { gweiToWei } from '@/parsers'; +import { lessThan } from '@/__swaps__/utils/numbers'; +import { ethereumUtils } from '@/utils'; + +export const useHasEnoughGas = async ({ chainId }: { chainId: ChainId }) => { + const nativeAsset = await ethereumUtils.getNativeAssetForNetwork(ethereumUtils.getNetworkFromChainId(chainId)); + + const { selectedGas } = useGasStore(); + + return lessThan(selectedGas?.gasFee?.amount || '0', gweiToWei(nativeAsset?.balance?.amount || '0')); +}; diff --git a/src/networks/arbitrum.ts b/src/networks/arbitrum.ts index 8a9ae182fe6..64ad99e2c73 100644 --- a/src/networks/arbitrum.ts +++ b/src/networks/arbitrum.ts @@ -1,10 +1,9 @@ import { getProviderForNetwork, proxyRpcEndpoint } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; import { arbitrum } from '@wagmi/chains'; import { ARBITRUM_ETH_ADDRESS } from '@/references'; -import { getArbitrumGasPrices } from '@/redux/gas'; import { getRemoteConfig } from '@/model/remoteConfig'; +import { getGasSpeeds } from '.'; export const getArbitrumNetworkObject = (): NetworkProperties => { const { arbitrum_enabled, arbitrum_tx_enabled } = getRemoteConfig(); @@ -42,17 +41,10 @@ export const getArbitrumNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT, gasUtils.CUSTOM], - + speeds: getGasSpeeds(), // ? gasType: 'eip1559', roundGasDisplay: true, - - // this prob can just be blockTime - pollingIntervalInMs: 3_000, - - // needs more research - getGasPrices: getArbitrumGasPrices, }, swaps: { diff --git a/src/networks/avalanche.ts b/src/networks/avalanche.ts index 813fce77c90..4a78ebd0313 100644 --- a/src/networks/avalanche.ts +++ b/src/networks/avalanche.ts @@ -1,10 +1,9 @@ import { getProviderForNetwork, proxyRpcEndpoint } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; import { avalanche } from '@wagmi/chains'; import { AVAX_AVALANCHE_ADDRESS } from '@/references'; -import { getAvalancheGasPrices } from '@/redux/gas'; import { getRemoteConfig } from '@/model/remoteConfig'; +import { getGasSpeeds } from '.'; export const getAvalancheNetworkObject = (): NetworkProperties => { const { avalanche_enabled, avalanche_tx_enabled } = getRemoteConfig(); @@ -42,15 +41,10 @@ export const getAvalancheNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT, gasUtils.CUSTOM], + speeds: getGasSpeeds(), // ? gasType: 'eip1559', roundGasDisplay: true, - - // this prob can just be blockTime, - pollingIntervalInMs: 5_000, - - getGasPrices: getAvalancheGasPrices, }, swaps: { diff --git a/src/networks/base.ts b/src/networks/base.ts index f483b210019..b39c25ccafc 100644 --- a/src/networks/base.ts +++ b/src/networks/base.ts @@ -1,10 +1,9 @@ import { getProviderForNetwork, proxyRpcEndpoint } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; import { base } from '@wagmi/chains'; import { BASE_ETH_ADDRESS } from '@/references'; -import { getBaseGasPrices } from '@/redux/gas'; import { getRemoteConfig } from '@/model/remoteConfig'; +import { getGasSpeeds } from '.'; export const getBaseNetworkObject = (): NetworkProperties => { const { base_enabled, base_tx_enabled, op_chains_enabled, op_chains_tx_enabled } = getRemoteConfig(); @@ -41,16 +40,11 @@ export const getBaseNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT, gasUtils.CUSTOM], + speeds: getGasSpeeds(), // ? gasType: 'eip1559', roundGasDisplay: true, OptimismTxFee: true, - - // this prob can just be blockTime, - pollingIntervalInMs: 5_000, - - getGasPrices: getBaseGasPrices, }, swaps: { diff --git a/src/networks/blast.ts b/src/networks/blast.ts index a0a7ba98d44..af2c335c66b 100644 --- a/src/networks/blast.ts +++ b/src/networks/blast.ts @@ -1,13 +1,10 @@ +import { blast } from 'viem/chains'; import { getProviderForNetwork, proxyRpcEndpoint } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; -import { blast } from 'viem/chains'; -import { getBlastGasPrices } from '@/redux/gas'; import { getRemoteConfig } from '@/model/remoteConfig'; import { BLAST_MAINNET_RPC } from 'react-native-dotenv'; import { BLAST_ETH_ADDRESS } from '@/references'; - -const BLAST_CHAIN_ID = 81457; +import { getGasSpeeds } from '.'; export const getBlastNetworkObject = (): NetworkProperties => { const { blast_enabled, blast_tx_enabled } = getRemoteConfig(); @@ -30,7 +27,7 @@ export const getBlastNetworkObject = (): NetworkProperties => { }, balanceCheckerAddress: '', - rpc: proxyRpcEndpoint(BLAST_CHAIN_ID), + rpc: proxyRpcEndpoint(blast.id), getProvider: getProviderForNetwork(Network.blast), // features @@ -45,15 +42,10 @@ export const getBlastNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT, gasUtils.CUSTOM], + speeds: getGasSpeeds(), // ? gasType: 'eip1559', roundGasDisplay: true, - - // this prob can just be blockTime, - pollingIntervalInMs: 5_000, - - getGasPrices: getBlastGasPrices, }, swaps: { diff --git a/src/networks/bsc.ts b/src/networks/bsc.ts index f69d37a88b3..418d9de10d2 100644 --- a/src/networks/bsc.ts +++ b/src/networks/bsc.ts @@ -1,10 +1,10 @@ import { getProviderForNetwork, proxyRpcEndpoint } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; import { bsc } from '@wagmi/chains'; import { BNB_BSC_ADDRESS, BNB_MAINNET_ADDRESS } from '@/references'; -import { getBscGasPrices } from '@/redux/gas'; import { getRemoteConfig } from '@/model/remoteConfig'; +import { getGasSpeeds } from '.'; +import { GasSpeed } from '@/entities'; export const getBSCNetworkObject = (): NetworkProperties => { const { bsc_enabled, bsc_tx_enabled } = getRemoteConfig(); @@ -43,17 +43,11 @@ export const getBSCNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT], + speeds: getGasSpeeds([GasSpeed.NORMAL, GasSpeed.FAST, GasSpeed.URGENT]), // ? gasType: 'legacy', roundGasDisplay: false, - - // this prob can just be blockTime - pollingIntervalInMs: 3_000, - - // needs more research - getGasPrices: getBscGasPrices, }, swaps: { diff --git a/src/networks/degen.ts b/src/networks/degen.ts index de95637f4c3..636caf4aa14 100644 --- a/src/networks/degen.ts +++ b/src/networks/degen.ts @@ -1,11 +1,10 @@ import { getProviderForNetwork, proxyRpcEndpoint } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; import { degen } from 'viem/chains'; import { DEGEN_CHAIN_DEGEN_ADDRESS } from '@/references'; -import { getDegenGasPrices } from '@/redux/gas'; import { getRemoteConfig } from '@/model/remoteConfig'; import { DEGEN_MAINNET_RPC } from 'react-native-dotenv'; +import { getGasSpeeds } from '.'; export const getDegenNetworkObject = (): NetworkProperties => { const { degen_enabled, degen_tx_enabled } = getRemoteConfig(); @@ -44,15 +43,10 @@ export const getDegenNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT, gasUtils.CUSTOM], + speeds: getGasSpeeds(), // ? gasType: 'eip1559', roundGasDisplay: true, - - // this prob can just be blockTime, - pollingIntervalInMs: 5_000, - - getGasPrices: getDegenGasPrices, }, swaps: { diff --git a/src/networks/gnosis.ts b/src/networks/gnosis.ts index ad90dbac2d0..19427fb111c 100644 --- a/src/networks/gnosis.ts +++ b/src/networks/gnosis.ts @@ -1,9 +1,9 @@ import { getProviderForNetwork } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; import { gnosis } from '@wagmi/chains'; import { ETH_ADDRESS } from '@/references'; -import { getOptimismGasPrices } from '@/redux/gas'; +import { getGasSpeeds } from '.'; +import { GasSpeed } from '@/entities'; export const getGnosisNetworkObject = (): NetworkProperties => { return { @@ -39,17 +39,12 @@ export const getGnosisNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL], + speeds: getGasSpeeds([GasSpeed.NORMAL]), // ? gasType: 'legacy', roundGasDisplay: true, OptimismTxFee: true, - - // this prob can just be blockTime, - pollingIntervalInMs: 5_000, - - getGasPrices: getOptimismGasPrices, }, swaps: { diff --git a/src/networks/goerli.ts b/src/networks/goerli.ts index 82e9c501ee5..6b10c9dd161 100644 --- a/src/networks/goerli.ts +++ b/src/networks/goerli.ts @@ -1,9 +1,10 @@ import { getProviderForNetwork, proxyRpcEndpoint } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; import { goerli } from '@wagmi/chains'; import { ETH_ADDRESS } from '@/references'; import { getRemoteConfig } from '@/model/remoteConfig'; +import { GasSpeed } from '@/entities'; +import { getGasSpeeds } from '.'; export const getGoerliNetworkObject = (): NetworkProperties => { const { goerli_enabled, goerli_tx_enabled } = getRemoteConfig(); @@ -43,15 +44,9 @@ export const getGoerliNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL, gasUtils.FAST, gasUtils.CUSTOM], + speeds: getGasSpeeds([GasSpeed.NORMAL, GasSpeed.FAST, GasSpeed.URGENT]), gasType: 'eip1559', roundGasDisplay: true, - - // this prob can just be blockTime - pollingIntervalInMs: 5_000, - - // needs more research - getGasPrices: async () => null, }, swaps: { diff --git a/src/networks/index.ts b/src/networks/index.ts index 6cf68c4e728..1b4896bc03b 100644 --- a/src/networks/index.ts +++ b/src/networks/index.ts @@ -13,6 +13,13 @@ import { getBlastNetworkObject } from './blast'; import { getDegenNetworkObject } from './degen'; import store from '@/redux/store'; import * as ls from '@/storage'; +import { GasSpeed } from '@/entities'; + +export const DEFAULT_GAS_SPEEDS = Object.values(GasSpeed); + +export const getGasSpeeds = (speeds?: GasSpeed[]) => { + return speeds || DEFAULT_GAS_SPEEDS; +}; /** * Array of all Rainbow Networks diff --git a/src/networks/mainnet.ts b/src/networks/mainnet.ts index caeab7da391..4d8e56547a9 100644 --- a/src/networks/mainnet.ts +++ b/src/networks/mainnet.ts @@ -1,9 +1,9 @@ import { getProviderForNetwork, proxyRpcEndpoint } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; import { mainnet } from '@wagmi/chains'; import { ETH_ADDRESS } from '@/references'; import { getRemoteConfig } from '@/model/remoteConfig'; +import { getGasSpeeds } from '.'; export const getMainnetNetworkObject = (): NetworkProperties => { const { mainnet_enabled, mainnet_tx_enabled } = getRemoteConfig(); @@ -43,15 +43,9 @@ export const getMainnetNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT, gasUtils.CUSTOM], + speeds: getGasSpeeds(), gasType: 'eip1559', roundGasDisplay: true, - - // this prob can just be blockTime - pollingIntervalInMs: 5_000, - - // needs more research - getGasPrices: async () => null, }, swaps: { diff --git a/src/networks/optimism.ts b/src/networks/optimism.ts index ade896684be..da5abdb3c82 100644 --- a/src/networks/optimism.ts +++ b/src/networks/optimism.ts @@ -1,10 +1,9 @@ import { getProviderForNetwork, proxyRpcEndpoint } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; import { optimism } from '@wagmi/chains'; import { OPTIMISM_ETH_ADDRESS } from '@/references'; -import { getOptimismGasPrices } from '@/redux/gas'; import { getRemoteConfig } from '@/model/remoteConfig'; +import { getGasSpeeds } from '.'; export const getOptimismNetworkObject = (): NetworkProperties => { const { optimism_enabled, optimism_tx_enabled, op_chains_enabled, op_chains_tx_enabled } = getRemoteConfig(); @@ -41,17 +40,11 @@ export const getOptimismNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT, gasUtils.CUSTOM], - + speeds: getGasSpeeds(), // ? gasType: 'eip1559', roundGasDisplay: true, OptimismTxFee: true, - - // this prob can just be blockTime, - pollingIntervalInMs: 5_000, - - getGasPrices: getOptimismGasPrices, }, swaps: { diff --git a/src/networks/polygon.ts b/src/networks/polygon.ts index 91650074209..7b16239122e 100644 --- a/src/networks/polygon.ts +++ b/src/networks/polygon.ts @@ -1,10 +1,10 @@ import { getProviderForNetwork, proxyRpcEndpoint } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; import { polygon } from '@wagmi/chains'; import { MATIC_MAINNET_ADDRESS, MATIC_POLYGON_ADDRESS } from '@/references'; -import { getPolygonGasPrices } from '@/redux/gas'; import { getRemoteConfig } from '@/model/remoteConfig'; +import { getGasSpeeds } from '.'; +import { GasSpeed } from '@/entities'; export const getPolygonNetworkObject = (): NetworkProperties => { const { polygon_tx_enabled } = getRemoteConfig(); @@ -42,16 +42,10 @@ export const getPolygonNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT], - + speeds: getGasSpeeds([GasSpeed.NORMAL, GasSpeed.FAST, GasSpeed.URGENT]), // ? gasType: 'legacy', roundGasDisplay: false, - - // this prob can just be blockTime - pollingIntervalInMs: 2_000, - - getGasPrices: getPolygonGasPrices, }, swaps: { diff --git a/src/networks/types.ts b/src/networks/types.ts index 77501e0f459..755f4fe6882 100644 --- a/src/networks/types.ts +++ b/src/networks/types.ts @@ -1,5 +1,4 @@ import { EthereumAddress } from '@/entities'; -import { GasPricesAPIData } from '@/entities/gas'; import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { Chain } from '@wagmi/chains'; // network.ts @@ -59,11 +58,6 @@ export interface NetworkProperties extends Chain { // for some networks gas is so cheap we dont want to round the gwei # roundGasDisplay: boolean; - - // this prob can just be blockTime - pollingIntervalInMs: number; - - getGasPrices: () => Promise; }; swaps: { diff --git a/src/networks/zora.ts b/src/networks/zora.ts index 2bde888fd7c..d69e98a1ae5 100644 --- a/src/networks/zora.ts +++ b/src/networks/zora.ts @@ -1,10 +1,9 @@ import { getProviderForNetwork, proxyRpcEndpoint } from '@/handlers/web3'; import { Network, NetworkProperties } from './types'; -import { gasUtils } from '@/utils'; import { zora } from '@wagmi/chains'; import { ZORA_ETH_ADDRESS } from '@/references'; -import { getZoraGasPrices } from '@/redux/gas'; import { getRemoteConfig } from '@/model/remoteConfig'; +import { getGasSpeeds } from '.'; export const getZoraNetworkObject = (): NetworkProperties => { const { zora_enabled, zora_tx_enabled, op_chains_enabled, op_chains_tx_enabled } = getRemoteConfig(); @@ -41,17 +40,11 @@ export const getZoraNetworkObject = (): NetworkProperties => { }, gas: { - speeds: [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT, gasUtils.CUSTOM], - + speeds: getGasSpeeds(), // ? gasType: 'eip1559', roundGasDisplay: true, OptimismTxFee: true, - - // this prob can just be blockTime, - pollingIntervalInMs: 5_000, - - getGasPrices: getZoraGasPrices, }, swaps: { diff --git a/src/raps/actions/crosschainSwap.test.ts b/src/raps/actions/crosschainSwap.test.ts deleted file mode 100644 index 3e444fb89cd..00000000000 --- a/src/raps/actions/crosschainSwap.test.ts +++ /dev/null @@ -1,70 +0,0 @@ -// import { Wallet } from '@ethersproject/wallet'; -// import { -// CrosschainQuote, -// ETH_ADDRESS as ETH_ADDRESS_AGGREGATORS, -// QuoteError, -// SwapType, -// getCrosschainQuote, -// } from '@rainbow-me/swaps'; -// import { getProvider } from '@wagmi/core'; -// import { mainnet } from 'viem/chains'; -// import { beforeAll, expect, test } from 'vitest'; - -// import { ChainId } from '~/core/types/chains'; -// import { -// TEST_ADDRESS_3, -// TEST_PK_3, -// USDC_ARBITRUM_ASSET, -// delay, -// } from '~/test/utils'; - -// import { createTestWagmiClient } from '../../wagmi/createTestWagmiClient'; - -// import { -// estimateCrosschainSwapGasLimit, -// executeCrosschainSwap, -// } from './crosschainSwap'; - -// let crosschainQuote: CrosschainQuote | QuoteError | null; - -// beforeAll(async () => { -// createTestWagmiClient(); -// await delay(3000); -// crosschainQuote = await getCrosschainQuote({ -// chainId: 1, -// fromAddress: TEST_ADDRESS_3, -// sellTokenAddress: ETH_ADDRESS_AGGREGATORS, -// buyTokenAddress: USDC_ARBITRUM_ASSET.address, -// sellAmount: '1000000000000000000', -// slippage: 5, -// destReceiver: TEST_ADDRESS_3, -// swapType: SwapType.crossChain, -// toChainId: ChainId.arbitrum, -// }); -// }, 20000); - -// test('[rap/crosschainSwap] :: should estimate crosschain swap gas limit', async () => { -// const swapGasLimit = await estimateCrosschainSwapGasLimit({ -// chainId: mainnet.id, -// requiresApprove: false, -// quote: crosschainQuote as CrosschainQuote, -// }); -// expect(Number(swapGasLimit)).toBeGreaterThan(0); -// }); - -// test('[rap/crosschainSwap] :: should execute crosschain swap', async () => { -// const provider = getProvider({ chainId: mainnet.id }); -// const wallet = new Wallet(TEST_PK_3, provider); - -// const swapTx = await executeCrosschainSwap({ -// gasLimit: '600000', -// gasParams: { -// maxFeePerGas: '2000000000000', -// maxPriorityFeePerGas: '2000000000', -// }, -// quote: crosschainQuote as CrosschainQuote, -// wallet, -// }); - -// expect(swapTx?.hash).toBeDefined(); -// }); diff --git a/src/raps/actions/crosschainSwap.ts b/src/raps/actions/crosschainSwap.ts index 5293f30c7c9..9da16056185 100644 --- a/src/raps/actions/crosschainSwap.ts +++ b/src/raps/actions/crosschainSwap.ts @@ -11,16 +11,16 @@ import { addNewTransaction } from '@/state/pendingTransactions'; import { RainbowError, logger } from '@/logger'; import { gasStore } from '@/state/gas/gasStore'; -import { TransactionGasParams, TransactionLegacyGasParams } from '@/__swaps__/types/gas'; +import { TransactionGasParams, TransactionLegacyGasParams } from '@/entities/gas'; import { toHex } from '@/__swaps__/utils/hex'; -import { ActionProps, RapActionResult } from '../references'; +import { ActionProps, RapActionResult } from '@/raps/references'; import { CHAIN_IDS_WITH_TRACE_SUPPORT, SWAP_GAS_PADDING, estimateSwapGasLimitWithFakeApproval, getDefaultGasLimitForTrade, overrideWithFastSpeedIfNeeded, -} from '../utils'; +} from '@/raps/utils'; import { ethereumUtils } from '@/utils'; import { TokenColors } from '@/graphql/__generated__/metadata'; import { ParsedAsset } from '@/resources/assets/types'; diff --git a/src/raps/actions/ens.ts b/src/raps/actions/ens.ts index 4e66f6e59a7..5933473f6b8 100644 --- a/src/raps/actions/ens.ts +++ b/src/raps/actions/ens.ts @@ -3,7 +3,8 @@ import { captureException } from '@sentry/react-native'; import { IS_TESTING } from 'react-native-dotenv'; import { ENSActionParameters, ENSRap, ENSRapActionType, RapENSAction, RapENSActionParameters } from '@/raps/common'; import { analytics } from '@/analytics'; -import { ENSRegistrationRecords, NewTransaction, TransactionGasParamAmounts } from '@/entities'; +import { ENSRegistrationRecords, NewTransaction } from '@/entities'; +import { TransactionGasParams } from '@/entities/gas'; import { estimateENSTransactionGasLimit, formatRecordsForTransaction } from '@/handlers/ens'; import { toHex } from '@/handlers/web3'; import { NetworkTypes } from '@/helpers'; @@ -11,8 +12,8 @@ import { ENSRegistrationTransactionType, getENSExecutionDetails, REGISTRATION_MO import * as i18n from '@/languages'; import { saveCommitRegistrationParameters, updateTransactionRegistrationParameters } from '@/redux/ensRegistration'; import store from '@/redux/store'; +import { gasStore } from '@/state/gas/gasStore'; import logger from '@/utils/logger'; -import { parseGasParamAmounts } from '@/parsers'; import { addNewTransaction } from '@/state/pendingTransactions'; import { Network } from '@/networks/types'; import { @@ -308,8 +309,8 @@ const ensAction = async ( ): Promise => { logger.log(`[${actionName}] base nonce`, baseNonce, 'index:', index); const { dispatch } = store; + const { selectedGas } = gasStore.getState(); const { accountAddress: ownerAddress } = store.getState().settings; - const { selectedGasFee } = store.getState().gas; const { name, duration, rentPrice, records, salt, toAddress, mode } = parameters; @@ -353,7 +354,7 @@ const ensAction = async ( let maxFeePerGas; let maxPriorityFeePerGas; try { - const gasParams = parseGasParamAmounts(selectedGasFee) as TransactionGasParamAmounts; + const gasParams = selectedGas.transactionGasParams as TransactionGasParams; maxFeePerGas = gasParams.maxFeePerGas; maxPriorityFeePerGas = gasParams.maxPriorityFeePerGas; diff --git a/src/raps/actions/swap.test.ts b/src/raps/actions/swap.test.ts deleted file mode 100644 index 869ceda545c..00000000000 --- a/src/raps/actions/swap.test.ts +++ /dev/null @@ -1,63 +0,0 @@ -// import { Wallet } from '@ethersproject/wallet'; -// import { -// ETH_ADDRESS as ETH_ADDRESS_AGGREGATORS, -// Quote, -// QuoteError, -// SwapType, -// getQuote, -// } from '@rainbow-me/swaps'; -// import { getProvider } from '@wagmi/core'; -// import { mainnet } from 'viem/chains'; -// import { beforeAll, expect, test } from 'vitest'; - -// import { TEST_ADDRESS_2, TEST_PK_2, delay } from '~/test/utils'; - -// import { createTestWagmiClient } from '../../wagmi/createTestWagmiClient'; - -// import { estimateSwapGasLimit, executeSwap } from './swap'; - -// let quote: Quote | QuoteError | null; - -// beforeAll(async () => { -// createTestWagmiClient(); -// await delay(3000); -// quote = await getQuote({ -// chainId: 1, -// fromAddress: TEST_ADDRESS_2, -// sellTokenAddress: ETH_ADDRESS_AGGREGATORS, -// buyTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', -// sellAmount: '1000000000000000000', -// slippage: 5, -// destReceiver: TEST_ADDRESS_2, -// swapType: SwapType.normal, -// toChainId: 1, -// }); -// }, 10000); - -// test('[rap/swap] :: should estimate swap gas limit', async () => { -// const swapGasLimit = await estimateSwapGasLimit({ -// chainId: mainnet.id, -// requiresApprove: false, -// quote: quote as Quote, -// }); - -// expect(Number(swapGasLimit)).toBeGreaterThan(0); -// }); - -// test('[rap/swap] :: should execute swap', async () => { -// const provider = getProvider({ chainId: mainnet.id }); -// const wallet = new Wallet(TEST_PK_2, provider); -// const swapTx = await executeSwap({ -// chainId: mainnet.id, -// gasLimit: '600000', -// gasParams: { -// maxFeePerGas: '800000000000', -// maxPriorityFeePerGas: '2000000000', -// }, -// quote: quote as Quote, -// wallet, -// permit: false, -// }); - -// expect(swapTx?.hash).toBeDefined(); -// }); diff --git a/src/raps/actions/swap.ts b/src/raps/actions/swap.ts index b3f86a50bb7..82806975d00 100644 --- a/src/raps/actions/swap.ts +++ b/src/raps/actions/swap.ts @@ -30,9 +30,9 @@ import { ethereumUtils } from '@/utils'; import { gasUnits, REFERRER } from '@/references'; import { gasStore } from '@/state/gas/gasStore'; -import { TransactionGasParams, TransactionLegacyGasParams } from '@/__swaps__/types/gas'; +import { TransactionGasParams, TransactionLegacyGasParams } from '@/entities/gas'; import { toHex } from '@/__swaps__/utils/hex'; -import { ActionProps, RapActionResult } from '../references'; +import { ActionProps, RapActionResult } from '@/raps/references'; import { CHAIN_IDS_WITH_TRACE_SUPPORT, SWAP_GAS_PADDING, @@ -40,11 +40,11 @@ import { getDefaultGasLimitForTrade, overrideWithFastSpeedIfNeeded, populateSwap, -} from '../utils'; +} from '@/raps/utils'; import { populateApprove } from './unlock'; import { TokenColors } from '@/graphql/__generated__/metadata'; -import { swapMetadataStorage } from '../common'; +import { swapMetadataStorage } from '@/raps/common'; import { ParsedAsset } from '@/resources/assets/types'; const WRAP_GAS_PADDING = 1.002; diff --git a/src/raps/actions/unlock.test.ts b/src/raps/actions/unlock.test.ts deleted file mode 100644 index 801981ac9ed..00000000000 --- a/src/raps/actions/unlock.test.ts +++ /dev/null @@ -1,74 +0,0 @@ -// import { Wallet } from '@ethersproject/wallet'; -// import { getRainbowRouterContractAddress } from '@rainbow-me/swaps'; -// import { getProvider } from '@wagmi/core'; -// import { mainnet } from 'viem/chains'; -// import { beforeAll, expect, test } from 'vitest'; - -// import { -// RAINBOW_WALLET_ADDRESS, -// TEST_PK_1, -// USDC_MAINNET_ASSET, -// delay, -// } from '~/test/utils'; - -// import { createTestWagmiClient } from '../../wagmi/createTestWagmiClient'; - -// import { -// assetNeedsUnlocking, -// estimateApprove, -// executeApprove, -// getAssetRawAllowance, -// } from './unlock'; - -// beforeAll(async () => { -// createTestWagmiClient(); -// await delay(3000); -// }); - -// test('[rap/unlock] :: get raw allowance', async () => { -// const rawAllowance = await getAssetRawAllowance({ -// owner: RAINBOW_WALLET_ADDRESS, -// assetAddress: USDC_MAINNET_ASSET.address, -// spender: getRainbowRouterContractAddress(mainnet.id), -// chainId: mainnet.id, -// }); -// expect(rawAllowance).toBe('0'); -// }); - -// test('[rap/unlock] :: asset needs unlocking', async () => { -// const needsUnlocking = await assetNeedsUnlocking({ -// amount: '1000', -// owner: RAINBOW_WALLET_ADDRESS, -// assetToUnlock: USDC_MAINNET_ASSET, -// spender: getRainbowRouterContractAddress(mainnet.id), -// chainId: mainnet.id, -// }); -// expect(needsUnlocking).toBe(true); -// }); - -// test('[rap/unlock] :: estimate approve', async () => { -// const approveGasLimit = await estimateApprove({ -// owner: RAINBOW_WALLET_ADDRESS, -// tokenAddress: USDC_MAINNET_ASSET.address, -// spender: getRainbowRouterContractAddress(mainnet.id), -// chainId: mainnet.id, -// }); -// expect(Number(approveGasLimit)).toBeGreaterThan(0); -// }); - -// test('[rap/unlock] :: should execute approve', async () => { -// const provider = getProvider({ chainId: mainnet.id }); -// const wallet = new Wallet(TEST_PK_1, provider); -// const approvalTx = await executeApprove({ -// chainId: mainnet.id, -// gasLimit: '60000', -// gasParams: { -// maxFeePerGas: '800000000000', -// maxPriorityFeePerGas: '2000000000', -// }, -// spender: getRainbowRouterContractAddress(mainnet.id), -// tokenAddress: USDC_MAINNET_ASSET.address, -// wallet, -// }); -// expect(approvalTx.hash).toBeDefined(); -// }); diff --git a/src/raps/actions/unlock.ts b/src/raps/actions/unlock.ts index 44c6615a794..55e48f065cc 100644 --- a/src/raps/actions/unlock.ts +++ b/src/raps/actions/unlock.ts @@ -6,7 +6,7 @@ import { getProviderForNetwork } from '@/handlers/web3'; import { Address, erc20Abi, erc721Abi } from 'viem'; import { ChainId } from '@/entities/chains'; -import { TransactionGasParams, TransactionLegacyGasParams } from '@/__swaps__/types/gas'; +import { TransactionGasParams, TransactionLegacyGasParams } from '@/entities/gas'; import { NewTransaction } from '@/entities/transactions'; import { TxHash } from '@/resources/transactions/types'; import { addNewTransaction } from '@/state/pendingTransactions'; @@ -18,7 +18,7 @@ import { ParsedAsset as SwapsParsedAsset } from '@/__swaps__/types/assets'; import { convertAmountToRawAmount, greaterThan } from '@/helpers/utilities'; import { ActionProps, RapActionResult } from '@/raps/references'; -import { overrideWithFastSpeedIfNeeded } from './../utils'; +import { overrideWithFastSpeedIfNeeded } from '@/raps/utils'; import { ethereumUtils } from '@/utils'; import { toHex } from '@/__swaps__/utils/hex'; import { TokenColors } from '@/graphql/__generated__/metadata'; diff --git a/src/raps/common.ts b/src/raps/common.ts index 5346e7439b2..6d725aa01de 100644 --- a/src/raps/common.ts +++ b/src/raps/common.ts @@ -1,5 +1,5 @@ import { MMKV } from 'react-native-mmkv'; -import { RapAction, RapActionParameterMap, RapActionTypes } from './references'; +import { RapAction, RapActionParameterMap, RapActionTypes } from '@/raps/references'; import { STORAGE_IDS } from '@/model/mmkv'; import { logger } from '@/logger'; import { EthereumAddress, Records } from '@/entities'; diff --git a/src/raps/execute.ts b/src/raps/execute.ts index b4c4e4e665d..1c8ca565bf5 100644 --- a/src/raps/execute.ts +++ b/src/raps/execute.ts @@ -5,8 +5,8 @@ import { Signer } from '@ethersproject/abstract-signer'; import { RainbowError, logger } from '@/logger'; -import { swap, unlock } from './actions'; -import { crosschainSwap } from './actions/crosschainSwap'; +import { swap, unlock } from '@/raps/actions'; +import { crosschainSwap } from '@/raps/actions/crosschainSwap'; import { ActionProps, Rap, @@ -16,9 +16,9 @@ import { RapActionTypes, RapSwapActionParameters, RapTypes, -} from './references'; -import { createUnlockAndCrosschainSwapRap } from './unlockAndCrosschainSwap'; -import { createUnlockAndSwapRap } from './unlockAndSwap'; +} from '@/raps/references'; +import { createUnlockAndCrosschainSwapRap } from '@/raps/unlockAndCrosschainSwap'; +import { createUnlockAndSwapRap } from '@/raps/unlockAndSwap'; export function createSwapRapByType(type: T, swapParameters: RapSwapActionParameters) { switch (type) { diff --git a/src/raps/registerENS.ts b/src/raps/registerENS.ts index 4f47f2bd33f..34c63a036cf 100644 --- a/src/raps/registerENS.ts +++ b/src/raps/registerENS.ts @@ -1,6 +1,6 @@ import { AddressZero } from '@ethersproject/constants'; import { isEmpty } from 'lodash'; -import { createNewENSAction, createNewENSRap, ENSActionParameters, RapENSAction, ENSRapActionType } from './common'; +import { createNewENSAction, createNewENSRap, ENSActionParameters, RapENSAction, ENSRapActionType } from '@/raps/common'; import { Records } from '@/entities'; import { formatRecordsForTransaction, diff --git a/src/raps/unlockAndCrosschainSwap.test.ts b/src/raps/unlockAndCrosschainSwap.test.ts deleted file mode 100644 index a32824a1289..00000000000 --- a/src/raps/unlockAndCrosschainSwap.test.ts +++ /dev/null @@ -1,132 +0,0 @@ -// import { CrosschainQuote, Quote, QuoteError } from '@rainbow-me/swaps'; -// import { beforeAll, expect, test } from 'vitest'; - -// import { -// ENS_MAINNET_ASSET, -// ETH_MAINNET_ASSET, -// TEST_ADDRESS_2, -// USDC_ARBITRUM_ASSET, -// delay, -// } from '~/test/utils'; - -// import { createTestWagmiClient } from '../wagmi/createTestWagmiClient'; - -// import { -// createUnlockAndCrosschainSwapRap, -// estimateUnlockAndCrosschainSwap, -// } from './unlockAndCrosschainSwap'; - -// let swapGasLimit = 0; - -// const needsUnlockQuote: Quote | QuoteError | null = { -// chainId: 1, -// buyAmount: '22815411', -// buyAmountDisplay: '22815411', -// buyAmountInEth: '7674057708816777', -// buyTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', -// data: '0x415565b0000000000000000000000000c18360217d8f7ab5e7c516566761ea12ce7f9d72000...', -// defaultGasLimit: '350000', -// fee: '8500000000000000', -// feeInEth: '62648258821781', -// feePercentageBasisPoints: 8500000000000000, -// from: '0x5B570F0F8E2a29B7bCBbfC000f9C7b78D45b7C35', -// protocols: [ -// { -// name: 'Uniswap_V3', -// part: 100, -// }, -// ], -// sellAmount: '1000000000000000000', -// sellAmountDisplay: '1000000000000000000', -// sellAmountInEth: '7370383390797876', -// sellAmountMinusFees: '991500000000000000', -// sellTokenAddress: '0xc18360217d8f7ab5e7c516566761ea12ce7f9d72', -// swapType: 'normal', -// to: '0xdef1c0ded9bec7f1a1670819833240f027b25eff', -// tradeAmountUSD: 21.84463710898238, -// value: '0', -// }; - -// const doesntNeedUnlockQuote: Quote | QuoteError | null = { -// chainId: 1, -// buyAmount: '2934529154', -// buyAmountDisplay: '2934529154', -// buyAmountInEth: '988585673036047522', -// buyTokenAddress: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', -// data: '0x37c6145a...', -// defaultGasLimit: '520000', -// fee: '10978750000000000', -// feeInEth: '10978750000000000', -// feePercentageBasisPoints: 10978750000000000, -// from: TEST_ADDRESS_2, -// protocols: [ -// { -// name: 'rainbow', -// part: 100, -// }, -// { -// name: 'hop', -// part: 100, -// }, -// ], -// sellAmount: '1000000000000000000', -// sellAmountDisplay: '1000000000000000000', -// sellAmountInEth: '1000000000000000000', -// sellAmountMinusFees: '989021250000000000', -// sellTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', -// swapType: 'cross-chain', -// to: TEST_ADDRESS_2, -// tradeAmountUSD: 2963.84, -// value: '0x0de0b6b3a7640000', -// }; - -// beforeAll(async () => { -// createTestWagmiClient(); -// await delay(3000); -// }); - -// test.skip('[rap/unlockAndCrosschainSwap] :: estimate unlock and crosschain swap rap without unlock', async () => { -// const gasLimit = await estimateUnlockAndCrosschainSwap({ -// quote: doesntNeedUnlockQuote as CrosschainQuote, -// chainId: 1, -// assetToSell: ETH_MAINNET_ASSET, -// sellAmount: '1000000000000000000', -// assetToBuy: USDC_ARBITRUM_ASSET, -// }); -// swapGasLimit = Number(gasLimit); -// expect(swapGasLimit).toBeGreaterThan(0); -// }); - -// test.skip('[rap/unlockAndCrosschainSwap] :: estimate unlock and crosschain swap rap with unlock', async () => { -// const gasLimit = await estimateUnlockAndCrosschainSwap({ -// quote: needsUnlockQuote as CrosschainQuote, -// chainId: 1, -// assetToSell: ENS_MAINNET_ASSET, -// sellAmount: '1000000000000000000', -// assetToBuy: USDC_ARBITRUM_ASSET, -// }); -// expect(Number(gasLimit)).toBeGreaterThan(0); -// expect(Number(gasLimit)).toBeGreaterThan(swapGasLimit); -// }); - -// test('[rap/unlockAndCrosschainSwap] :: create unlock and crosschain swap rap without unlock', async () => { -// const rap = await createUnlockAndCrosschainSwapRap({ -// quote: doesntNeedUnlockQuote as CrosschainQuote, -// chainId: 1, -// sellAmount: '1000000000000000000', -// assetToSell: ETH_MAINNET_ASSET, -// assetToBuy: USDC_ARBITRUM_ASSET, -// }); -// expect(rap.actions.length).toBe(1); -// }); - -// test('[rap/unlockAndCrosschainSwap] :: create unlock and crosschain swap rap with unlock', async () => { -// const rap = await createUnlockAndCrosschainSwapRap({ -// quote: needsUnlockQuote as CrosschainQuote, -// chainId: 1, -// sellAmount: '1000000000000000000', -// assetToSell: ENS_MAINNET_ASSET, -// assetToBuy: USDC_ARBITRUM_ASSET, -// }); -// expect(rap.actions.length).toBe(2); -// }); diff --git a/src/raps/unlockAndCrosschainSwap.ts b/src/raps/unlockAndCrosschainSwap.ts index c1cf28a8713..2cffaa0db5a 100644 --- a/src/raps/unlockAndCrosschainSwap.ts +++ b/src/raps/unlockAndCrosschainSwap.ts @@ -1,15 +1,15 @@ import { ALLOWS_PERMIT, ChainId, ETH_ADDRESS as ETH_ADDRESS_AGGREGATOR, PermitSupportedTokenList, WRAPPED_ASSET } from '@rainbow-me/swaps'; import { Address } from 'viem'; -import { ETH_ADDRESS } from '../references'; +import { ETH_ADDRESS } from '@/references'; import { isNativeAsset } from '@/handlers/assets'; import { add } from '@/helpers/utilities'; import { ethereumUtils, isLowerCaseMatch } from '@/utils'; -import { assetNeedsUnlocking, estimateApprove } from './actions'; -import { estimateCrosschainSwapGasLimit } from './actions/crosschainSwap'; -import { createNewAction, createNewRap } from './common'; -import { RapAction, RapSwapActionParameters, RapUnlockActionParameters } from './references'; +import { assetNeedsUnlocking, estimateApprove } from '@/raps/actions'; +import { estimateCrosschainSwapGasLimit } from '@/raps/actions/crosschainSwap'; +import { createNewAction, createNewRap } from '@/raps/common'; +import { RapAction, RapSwapActionParameters, RapUnlockActionParameters } from '@/raps/references'; export const estimateUnlockAndCrosschainSwap = async (swapParameters: RapSwapActionParameters<'crosschainSwap'>) => { const { sellAmount, quote, chainId, assetToSell } = swapParameters; diff --git a/src/raps/unlockAndSwap.test.ts b/src/raps/unlockAndSwap.test.ts deleted file mode 100644 index 25723e374ee..00000000000 --- a/src/raps/unlockAndSwap.test.ts +++ /dev/null @@ -1,255 +0,0 @@ -// import { Wallet } from '@ethersproject/wallet'; -// import { -// ChainId, -// ETH_ADDRESS as ETH_ADDRESS_AGGREGATORS, -// Quote, -// QuoteError, -// SwapType, -// getQuote, -// } from '@rainbow-me/swaps'; -// import { getProvider } from '@wagmi/core'; -// import { beforeAll, expect, test } from 'vitest'; - -// import { -// ENS_MAINNET_ASSET, -// ETH_MAINNET_ASSET, -// TEST_ADDRESS_2, -// TEST_PK_1, -// USDC_MAINNET_ASSET, -// WETH_MAINNET_ASSET, -// delay, -// } from '~/test/utils'; - -// import { gasStore } from '../state'; -// import { GasSpeed } from '../types/gas'; -// import { createTestWagmiClient } from '../wagmi/createTestWagmiClient'; - -// import { walletExecuteRap } from './execute'; -// import { createUnlockAndSwapRap, estimateUnlockAndSwap } from './unlockAndSwap'; - -// let swapGasLimit = 0; - -// let needsUnlockQuote: Quote | QuoteError | null; -// let doesntNeedUnlockQuote: Quote | QuoteError | null; -// let ethToEnsQuote: Quote | QuoteError | null; -// let unwrapEthQuote: Quote | QuoteError | null; -// let wrapEthQuote: Quote | QuoteError | null; - -// const SELECTED_GAS = { -// display: '73 - 86 Gwei', -// estimatedTime: { amount: 15, display: '~ 15 sec' }, -// gasFee: { amount: '4323764263200000', display: '$8.64' }, -// maxBaseFee: { -// amount: '800000000000', -// display: '800 Gwei', -// gwei: '800', -// }, -// maxPriorityFeePerGas: { -// amount: '3000000000', -// display: '3 Gwei', -// gwei: '3', -// }, -// option: GasSpeed.NORMAL, -// transactionGasParams: { -// maxPriorityFeePerGas: '0xb2d05e00', -// maxFeePerGas: '0xba43b74000', -// }, -// }; - -// beforeAll(async () => { -// createTestWagmiClient(); -// await delay(3000); -// doesntNeedUnlockQuote = await getQuote({ -// chainId: 1, -// fromAddress: TEST_ADDRESS_2, -// sellTokenAddress: ETH_ADDRESS_AGGREGATORS, -// buyTokenAddress: USDC_MAINNET_ASSET.address, -// sellAmount: '1000000000000000000', -// slippage: 5, -// destReceiver: TEST_ADDRESS_2, -// swapType: SwapType.normal, -// toChainId: 1, -// }); -// ethToEnsQuote = await getQuote({ -// chainId: 1, -// fromAddress: TEST_ADDRESS_2, -// sellTokenAddress: ETH_MAINNET_ASSET.address, -// buyTokenAddress: ENS_MAINNET_ASSET.address, -// sellAmount: '1000000000000000000', -// slippage: 5, -// destReceiver: TEST_ADDRESS_2, -// swapType: SwapType.normal, -// toChainId: 1, -// }); -// needsUnlockQuote = await getQuote({ -// chainId: 1, -// fromAddress: TEST_ADDRESS_2, -// sellTokenAddress: ENS_MAINNET_ASSET.address, -// buyTokenAddress: USDC_MAINNET_ASSET.address, -// sellAmount: '1000000000000000000', -// slippage: 5, -// destReceiver: TEST_ADDRESS_2, -// swapType: SwapType.normal, -// toChainId: 1, -// }); -// wrapEthQuote = await getQuote({ -// chainId: 1, -// fromAddress: TEST_ADDRESS_2, -// sellTokenAddress: ETH_MAINNET_ASSET.address, -// buyTokenAddress: WETH_MAINNET_ASSET.address, -// sellAmount: '1000000000000000000', -// slippage: 5, -// destReceiver: TEST_ADDRESS_2, -// swapType: SwapType.normal, -// toChainId: 1, -// }); -// unwrapEthQuote = await getQuote({ -// chainId: 1, -// fromAddress: TEST_ADDRESS_2, -// sellTokenAddress: WETH_MAINNET_ASSET.address, -// buyTokenAddress: ETH_MAINNET_ASSET.address, -// sellAmount: '100000000000000000', -// slippage: 5, -// destReceiver: TEST_ADDRESS_2, -// swapType: SwapType.normal, -// toChainId: 1, -// }); -// }, 10000); - -// test.skip('[rap/unlockAndSwap] :: estimate unlock and swap rap without unlock', async () => { -// const gasLimit = await estimateUnlockAndSwap({ -// quote: doesntNeedUnlockQuote as Quote, -// chainId: 1, -// assetToSell: ETH_MAINNET_ASSET, -// sellAmount: '1000000000000000000', -// assetToBuy: USDC_MAINNET_ASSET, -// }); -// expect(Number(gasLimit)).toBeGreaterThan(0); -// swapGasLimit = Number(gasLimit); -// }); - -// test.skip('[rap/unlockAndSwap] :: estimate unlock and swap rap with unlock', async () => { -// const gasLimit = await estimateUnlockAndSwap({ -// quote: needsUnlockQuote as Quote, -// chainId: 1, -// assetToSell: ENS_MAINNET_ASSET, -// sellAmount: '1000000000000000000', -// assetToBuy: USDC_MAINNET_ASSET, -// }); -// expect(Number(gasLimit)).toBeGreaterThan(0); -// expect(Number(gasLimit)).toBeGreaterThan(swapGasLimit); -// }); - -// test('[rap/unlockAndSwap] :: create unlock and swap rap without unlock', async () => { -// const rap = await createUnlockAndSwapRap({ -// quote: doesntNeedUnlockQuote as Quote, -// chainId: 1, -// sellAmount: '1000000000000000000', -// assetToSell: ETH_MAINNET_ASSET, -// assetToBuy: USDC_MAINNET_ASSET, -// }); -// expect(rap.actions.length).toBe(1); -// }); - -// test('[rap/unlockAndSwap] :: create unlock and swap rap without unlock and execute it', async () => { -// const provider = getProvider({ chainId: ChainId.mainnet }); -// const wallet = new Wallet(TEST_PK_1, provider); -// const swap = await walletExecuteRap(wallet, 'swap', { -// quote: doesntNeedUnlockQuote as Quote, -// chainId: 1, -// sellAmount: '1000000000000000000', -// assetToSell: ETH_MAINNET_ASSET, -// assetToBuy: USDC_MAINNET_ASSET, -// }); -// expect(swap.nonce).toBeDefined(); -// }); - -// test('[rap/unlockAndSwap] :: create unlock and swap rap with unlock', async () => { -// const rap = await createUnlockAndSwapRap({ -// quote: needsUnlockQuote as Quote, -// chainId: 1, -// sellAmount: '1000000000000000000', -// assetToSell: ENS_MAINNET_ASSET, -// assetToBuy: USDC_MAINNET_ASSET, -// }); -// expect(rap.actions.length).toBe(2); -// }); - -// test('[rap/unlockAndSwap] :: create swap rap and execute it', async () => { -// const { setSelectedGas } = gasStore.getState(); -// setSelectedGas({ -// selectedGas: SELECTED_GAS, -// }); -// const provider = getProvider({ chainId: ChainId.mainnet }); -// const wallet = new Wallet(TEST_PK_1, provider); -// const swap = await walletExecuteRap(wallet, 'swap', { -// quote: ethToEnsQuote as Quote, -// chainId: 1, -// sellAmount: '1000000000000000000', -// assetToSell: ETH_MAINNET_ASSET, -// assetToBuy: ENS_MAINNET_ASSET, -// }); -// expect(swap.nonce).toBeDefined(); -// }); - -// test('[rap/unlockAndSwap] :: create unlock and swap rap with unlock and execute it', async () => { -// const { setSelectedGas } = gasStore.getState(); -// setSelectedGas({ -// selectedGas: SELECTED_GAS, -// }); -// const provider = getProvider({ chainId: ChainId.mainnet }); -// const wallet = new Wallet(TEST_PK_1, provider); -// const swap = await walletExecuteRap(wallet, 'swap', { -// quote: needsUnlockQuote as Quote, -// chainId: 1, -// sellAmount: '1000000000000000000', -// assetToSell: ENS_MAINNET_ASSET, -// assetToBuy: USDC_MAINNET_ASSET, -// }); -// expect(swap.nonce).toBeDefined(); -// }); - -// test('[rap/unlockAndSwap] :: create unlock and wrap eth rap with unlock and execute it', async () => { -// const { setSelectedGas } = gasStore.getState(); -// setSelectedGas({ -// selectedGas: SELECTED_GAS, -// }); -// const provider = getProvider({ chainId: ChainId.mainnet }); -// const wallet = new Wallet(TEST_PK_1, provider); -// const swap = await walletExecuteRap(wallet, 'swap', { -// quote: wrapEthQuote as Quote, -// chainId: 1, -// sellAmount: '1000000000000000000', -// assetToSell: ETH_MAINNET_ASSET, -// assetToBuy: WETH_MAINNET_ASSET, -// }); -// expect(swap.nonce).toBeDefined(); -// }); - -// test('[rap/unlockAndSwap] :: create unwrap eth rap', async () => { -// const rap = await createUnlockAndSwapRap({ -// quote: unwrapEthQuote as Quote, -// chainId: 1, -// sellAmount: '100000000000000000', -// assetToSell: WETH_MAINNET_ASSET, -// assetToBuy: ETH_MAINNET_ASSET, -// }); -// expect(rap.actions.length).toBe(1); -// }); - -// test('[rap/unlockAndSwap] :: create unwrap weth rap and execute it', async () => { -// const { setSelectedGas } = gasStore.getState(); -// setSelectedGas({ -// selectedGas: SELECTED_GAS, -// }); -// const provider = getProvider({ chainId: ChainId.mainnet }); -// const wallet = new Wallet(TEST_PK_1, provider); -// const swap = await walletExecuteRap(wallet, 'swap', { -// quote: unwrapEthQuote as Quote, -// chainId: 1, -// sellAmount: '100000000000000000', -// assetToSell: WETH_MAINNET_ASSET, -// assetToBuy: ETH_MAINNET_ASSET, -// }); -// expect(swap.nonce).toBeDefined(); -// }); diff --git a/src/raps/unlockAndSwap.ts b/src/raps/unlockAndSwap.ts index 4f50fc40144..6984e806208 100644 --- a/src/raps/unlockAndSwap.ts +++ b/src/raps/unlockAndSwap.ts @@ -7,16 +7,16 @@ import { } from '@rainbow-me/swaps'; import { Address } from 'viem'; -import { ETH_ADDRESS } from '../references'; +import { ETH_ADDRESS } from '@/references'; import { ChainId } from '@/entities/chains'; import { isNativeAsset } from '@/handlers/assets'; import { add } from '@/helpers/utilities'; import { ethereumUtils, isLowerCaseMatch } from '@/utils'; -import { assetNeedsUnlocking, estimateApprove, estimateSwapGasLimit } from './actions'; -import { estimateUnlockAndSwapFromMetadata } from './actions/swap'; -import { createNewAction, createNewRap } from './common'; -import { RapAction, RapSwapActionParameters, RapUnlockActionParameters } from './references'; +import { assetNeedsUnlocking, estimateApprove, estimateSwapGasLimit } from '@/raps/actions'; +import { estimateUnlockAndSwapFromMetadata } from '@/raps/actions/swap'; +import { createNewAction, createNewRap } from '@/raps/common'; +import { RapAction, RapSwapActionParameters, RapUnlockActionParameters } from '@/raps/references'; import { isWrapNative } from '@/handlers/swap'; export const estimateUnlockAndSwap = async (swapParameters: RapSwapActionParameters<'swap'>) => { diff --git a/src/raps/utils.ts b/src/raps/utils.ts index 17811dda1d1..c2c437033c1 100644 --- a/src/raps/utils.ts +++ b/src/raps/utils.ts @@ -13,7 +13,7 @@ import { GasFeeParamsBySpeed, TransactionGasParams, TransactionLegacyGasParams, -} from '@/__swaps__/types/gas'; +} from '@/entities/gas'; import { ChainId } from '@/entities/chains'; import { gasUnits } from '@/references'; import { toHexNoLeadingZeros } from '@/handlers/web3';