Skip to content

Commit

Permalink
feat: getSendGasLimitERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
skeremidchiev committed Mar 31, 2022
1 parent 9f6e332 commit 85072c9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
28 changes: 14 additions & 14 deletions src/assets/native.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TESTNET_NATIVE } from './testnet'
import { AssetMap, ChainId } from '../types'
import { AssetMap, ChainId, AssetTypes } from '../types'
import { sendGasLimits } from '../assets/sendGasLimits'

const nativeAssets: AssetMap = {
BTC: {
name: 'Bitcoin',
chain: ChainId.Bitcoin,
type: 'native',
type: AssetTypes.native,
code: 'BTC',
coinGeckoId: 'bitcoin',
color: '#f7931a',
Expand All @@ -16,7 +16,7 @@ const nativeAssets: AssetMap = {
BCH: {
name: 'Bitcoin Cash',
chain: ChainId.BitcoinCash,
type: 'native',
type: AssetTypes.native,
code: 'BCH',
coinGeckoId: 'bitcoin-cash',
color: '#a1db5e',
Expand All @@ -26,7 +26,7 @@ const nativeAssets: AssetMap = {
ETH: {
name: 'Ether',
chain: ChainId.Ethereum,
type: 'native',
type: AssetTypes.native,
code: 'ETH',
coinGeckoId: 'ethereum',
color: '#627eea',
Expand All @@ -36,7 +36,7 @@ const nativeAssets: AssetMap = {
RBTC: {
name: 'Rootstock BTC',
chain: ChainId.Rootstock,
type: 'native',
type: AssetTypes.native,
code: 'RBTC',
coinGeckoId: 'rootstock',
color: '#006e3c',
Expand All @@ -46,7 +46,7 @@ const nativeAssets: AssetMap = {
BNB: {
name: 'Binance Coin',
chain: ChainId.BinanceSmartChain,
type: 'native',
type: AssetTypes.native,
code: 'BNB',
coinGeckoId: 'binancecoin',
color: '#f9a825',
Expand All @@ -56,7 +56,7 @@ const nativeAssets: AssetMap = {
NEAR: {
name: 'Near',
chain: ChainId.Near,
type: 'native',
type: AssetTypes.native,
code: 'NEAR',
coinGeckoId: 'near',
color: '#000000',
Expand All @@ -66,7 +66,7 @@ const nativeAssets: AssetMap = {
SOL: {
name: 'Solana',
chain: ChainId.Solana,
type: 'native',
type: AssetTypes.native,
code: 'SOL',
coinGeckoId: 'solana',
color: '#008080',
Expand All @@ -76,7 +76,7 @@ const nativeAssets: AssetMap = {
MATIC: {
name: 'Matic',
chain: ChainId.Polygon,
type: 'native',
type: AssetTypes.native,
code: 'MATIC',
coinGeckoId: 'matic-network',
color: '#8247E5',
Expand All @@ -86,7 +86,7 @@ const nativeAssets: AssetMap = {
ARBETH: {
name: 'Arbitrum ETH',
chain: ChainId.Arbitrum,
type: 'native',
type: AssetTypes.native,
code: 'ARBETH',
coinGeckoId: 'ethereum',
color: '#28A0EF',
Expand All @@ -97,7 +97,7 @@ const nativeAssets: AssetMap = {
FUSE: {
name: 'Fuse Network',
chain: ChainId.Fuse,
type: 'native',
type: AssetTypes.native,
code: 'FUSE',
coinGeckoId: 'fuse-network-token',
color: '#46e8b6',
Expand All @@ -107,7 +107,7 @@ const nativeAssets: AssetMap = {
LUNA: {
name: 'Luna',
chain: ChainId.Terra,
type: 'native',
type: AssetTypes.native,
code: 'LUNA',
coinGeckoId: 'terra-luna',
color: '#008080',
Expand All @@ -117,7 +117,7 @@ const nativeAssets: AssetMap = {
UST: {
name: 'TerraUSD',
chain: ChainId.Terra,
type: 'native',
type: AssetTypes.native,
code: 'UST',
decimals: 6,
color: '#0083ff',
Expand All @@ -128,7 +128,7 @@ const nativeAssets: AssetMap = {
AVAX: {
name: 'Avalanche',
chain: ChainId.Avalanche,
type: 'native',
type: AssetTypes.native,
code: 'AVAX',
coinGeckoId: 'avalanche-2',
color: '#E84141',
Expand Down
23 changes: 21 additions & 2 deletions src/assets/sendGasLimits.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
import { ChainId } from '../types'
import { nonERC20SupportChain } from '../chains'

const sendGasLimits = {
BTC: 290,
NATIVE_EVM: 21000, // EVM -> ETH, RBTC, MATIC, BNB, AVAX, FUSE
ERC20_EVM: 90000, // EVM -> ETH, RBTC, MATIC, BNB, AVAX, FUSE
TERRA: 100000, // applies on both native and ERC2 Terra assets
ARBETH: 620000,
ARBETH: 620000, // for native asset is around ~420k and for ERC20 ~540k
NEAR: 10000000000000,
SOL: 1000000
}

export { sendGasLimits }
const getSendGasLimitERC20 = (chainId: ChainId): number | null => {
if (nonERC20SupportChain(chainId)) {
return null
}

switch (chainId) {
case ChainId.Arbitrum:
return sendGasLimits.ARBETH
case ChainId.Terra:
return sendGasLimits.TERRA
default:
// EVM standard gas limit
return sendGasLimits.ERC20_EVM
}
}

export { sendGasLimits, getSendGasLimitERC20 }
6 changes: 5 additions & 1 deletion src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,8 @@ function isEthereumChain(chain: ChainId) {
].includes(chain)
}

export { chains, isEthereumChain }
function nonERC20SupportChain(chain: ChainId) {
return [ChainId.Bitcoin, ChainId.BitcoinCash, ChainId.Near, ChainId.Solana].includes(chain)
}

export { chains, isEthereumChain, nonERC20SupportChain }
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js'
import { assets, testnetAssets, chainToTokenAddressMap, chainToTestnetTokenAddressMap } from './assets'
import { chains, isEthereumChain } from './chains'
import { dappChains } from './dapps'
import { Asset, ChainId } from './types'
import { Asset, AssetTypes, ChainId } from './types'

function unitToCurrency(asset: Asset, value: number | BigNumber): BigNumber {
const multiplier = new BigNumber(10).pow(asset.decimals)
Expand All @@ -25,5 +25,6 @@ export {
unitToCurrency,
currencyToUnit,
Asset,
AssetTypes,
ChainId
}
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ export interface Chain {
formatTransactionHash: (hash: string) => string
}

export type AssetType = 'native' | 'erc20'
export enum AssetTypes {
native = 'native',
erc20 = 'erc20'
}

export type AssetType = AssetTypes.native | AssetTypes.erc20

export enum ChainId {
Bitcoin = 'bitcoin',
Expand Down

0 comments on commit 85072c9

Please sign in to comment.