Skip to content

Commit

Permalink
cleanup raps + network specific gas logic
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat committed Apr 27, 2024
1 parent cc1bc6d commit 6a5356d
Show file tree
Hide file tree
Showing 32 changed files with 93 additions and 800 deletions.
22 changes: 11 additions & 11 deletions src/entities/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
52 changes: 0 additions & 52 deletions src/helpers/gas.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/hooks/useHasEnoughGas.ts
Original file line number Diff line number Diff line change
@@ -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'));
};
12 changes: 2 additions & 10 deletions src/networks/arbitrum.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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: {
Expand Down
10 changes: 2 additions & 8 deletions src/networks/avalanche.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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: {
Expand Down
10 changes: 2 additions & 8 deletions src/networks/base.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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: {
Expand Down
16 changes: 4 additions & 12 deletions src/networks/blast.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -30,7 +27,7 @@ export const getBlastNetworkObject = (): NetworkProperties => {
},

balanceCheckerAddress: '',
rpc: proxyRpcEndpoint(BLAST_CHAIN_ID),
rpc: proxyRpcEndpoint(blast.id),
getProvider: getProviderForNetwork(Network.blast),

// features
Expand All @@ -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: {
Expand Down
12 changes: 3 additions & 9 deletions src/networks/bsc.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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: {
Expand Down
10 changes: 2 additions & 8 deletions src/networks/degen.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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: {
Expand Down
11 changes: 3 additions & 8 deletions src/networks/gnosis.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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: {
Expand Down
11 changes: 3 additions & 8 deletions src/networks/goerli.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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: {
Expand Down
7 changes: 7 additions & 0 deletions src/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions src/networks/mainnet.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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: {
Expand Down
Loading

0 comments on commit 6a5356d

Please sign in to comment.