Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
make it pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladinlight committed Mar 28, 2023
1 parent 8de2983 commit eb271d7
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 36 deletions.
11 changes: 0 additions & 11 deletions packages/chain-adapters/src/cosmossdk/CosmosSdkBaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AssetId, ChainId, fromChainId, generateAssetIdFromOsmosisDenom } from '
import { BIP44Params, KnownChainIds } from '@shapeshiftoss/types'
import * as unchained from '@shapeshiftoss/unchained-client'
import { bech32 } from 'bech32'
import BigNumber from 'bignumber.js'

import { ChainAdapter as IChainAdapter } from '../api'
import { ErrorHandler } from '../error/ErrorHandler'
Expand Down Expand Up @@ -58,16 +57,6 @@ export const assertIsValidatorAddress = (validator: string, chainId: CosmosSdkCh
}
}

type ConfirmationSpeed = 'slow' | 'average' | 'fast'

export const calcFee = (
fee: string | number | BigNumber,
speed: ConfirmationSpeed,
scalars: Record<ConfirmationSpeed, BigNumber>,
): string => {
return bnOrZero(fee).times(scalars[speed]).toFixed(0, BigNumber.ROUND_CEIL).toString()
}

const transformValidator = (validator: unchained.cosmossdk.types.Validator): Validator => ({
address: validator.address,
moniker: validator.moniker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import {
GetFeeDataInput,
SignTxInput,
} from '../../types'
import { toAddressNList } from '../../utils'
import { bn, calcFee, toAddressNList } from '../../utils'
import {
assertIsValidatorAddress,
ChainAdapterArgs,
CosmosSdkBaseAdapter,
} from '../CosmosSdkBaseAdapter'
import { Message, ValidatorAction } from '../types'

export const MIN_FEE = '2500'

const SUPPORTED_CHAIN_IDS = [KnownChainIds.CosmosMainnet]
const DEFAULT_CHAIN_ID = KnownChainIds.CosmosMainnet

Expand Down Expand Up @@ -275,12 +277,15 @@ export class ChainAdapter extends CosmosSdkBaseAdapter<KnownChainIds.CosmosMainn
}: Partial<GetFeeDataInput<KnownChainIds.CosmosMainnet>>): Promise<
FeeDataEstimate<KnownChainIds.CosmosMainnet>
> {
const gasLimit = '250000'
const scalars = { fast: bn(2), average: bn(1.5), slow: bn(1) }

// We currently don't have a way to query validators to get dynamic fees, so they are hard coded.
// When we find a strategy to make this more dynamic, we can use 'sendMax' to define max amount.
return {
fast: { txFee: '5000', chainSpecific: { gasLimit: '250000' } },
average: { txFee: '3500', chainSpecific: { gasLimit: '250000' } },
slow: { txFee: '2500', chainSpecific: { gasLimit: '250000' } },
fast: { txFee: calcFee(MIN_FEE, 'fast', scalars), chainSpecific: { gasLimit } },
average: { txFee: calcFee(MIN_FEE, 'average', scalars), chainSpecific: { gasLimit } },
slow: { txFee: calcFee(MIN_FEE, 'slow', scalars), chainSpecific: { gasLimit } },
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import {
SignTxInput,
} from '../../types'
import { toAddressNList } from '../../utils'
import { bn } from '../../utils/bignumber'
import { bn, calcFee } from '../../utils'
import {
assertIsValidatorAddress,
calcFee,
ChainAdapterArgs,
CosmosSdkBaseAdapter,
} from '../CosmosSdkBaseAdapter'
Expand Down
11 changes: 0 additions & 11 deletions packages/chain-adapters/src/evm/EvmBaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '@shapeshiftoss/hdwallet-core'
import { BIP44Params, KnownChainIds } from '@shapeshiftoss/types'
import * as unchained from '@shapeshiftoss/unchained-client'
import BigNumber from 'bignumber.js'
import { utils } from 'ethers'
import WAValidator from 'multicoin-address-validator'
import { numberToHex } from 'web3-utils'
Expand Down Expand Up @@ -68,16 +67,6 @@ export const isEvmChainId = (
return evmChainIds.includes(maybeEvmChainId as EvmChainId)
}

type ConfirmationSpeed = 'slow' | 'average' | 'fast'

export const calcFee = (
fee: string | number | BigNumber,
speed: ConfirmationSpeed,
scalars: Record<ConfirmationSpeed, BigNumber>,
): string => {
return bnOrZero(fee).times(scalars[speed]).toFixed(0, BigNumber.ROUND_CEIL).toString()
}

type EvmApi =
| unchained.ethereum.V1Api
| unchained.avalanche.V1Api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as unchained from '@shapeshiftoss/unchained-client'

import { ChainAdapterDisplayName } from '../../types'
import { FeeDataEstimate, GetFeeDataInput } from '../../types'
import { bn, bnOrZero } from '../../utils/bignumber'
import { calcFee, ChainAdapterArgs, EvmBaseAdapter } from '../EvmBaseAdapter'
import { bn, bnOrZero, calcFee } from '../../utils'
import { ChainAdapterArgs, EvmBaseAdapter } from '../EvmBaseAdapter'
import { GasFeeDataEstimate } from '../types'

const SUPPORTED_CHAIN_IDS = [KnownChainIds.AvalancheMainnet]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as unchained from '@shapeshiftoss/unchained-client'

import { ChainAdapterDisplayName } from '../../types'
import { FeeDataEstimate, GetFeeDataInput } from '../../types'
import { bn, bnOrZero } from '../../utils/bignumber'
import { calcFee, ChainAdapterArgs, EvmBaseAdapter } from '../EvmBaseAdapter'
import { bn, bnOrZero, calcFee } from '../../utils'
import { ChainAdapterArgs, EvmBaseAdapter } from '../EvmBaseAdapter'
import { GasFeeDataEstimate } from '../types'

const SUPPORTED_CHAIN_IDS = [KnownChainIds.BnbSmartChainMainnet]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
ValidAddressResultType,
ZrxGasApiResponse,
} from '../../types'
import { bn, bnOrZero } from '../../utils/bignumber'
import { calcFee, ChainAdapterArgs, EvmBaseAdapter } from '../EvmBaseAdapter'
import { bn, bnOrZero, calcFee } from '../../utils'
import { ChainAdapterArgs, EvmBaseAdapter } from '../EvmBaseAdapter'
import { GasFeeDataEstimate } from '../types'

const SUPPORTED_CHAIN_IDS = [KnownChainIds.EthereumMainnet]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as unchained from '@shapeshiftoss/unchained-client'

import { ChainAdapterDisplayName } from '../../types'
import { FeeDataEstimate, GetFeeDataInput } from '../../types'
import { bn, bnOrZero } from '../../utils/bignumber'
import { calcFee, ChainAdapterArgs, EvmBaseAdapter } from '../EvmBaseAdapter'
import { bn, bnOrZero, calcFee } from '../../utils'
import { ChainAdapterArgs, EvmBaseAdapter } from '../EvmBaseAdapter'
import { GasFeeDataEstimate } from '../types'

const SUPPORTED_CHAIN_IDS = [KnownChainIds.OptimismMainnet]
Expand Down
12 changes: 12 additions & 0 deletions packages/chain-adapters/src/utils/fees.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import BigNumber from 'bignumber.js'

import { FeeDataKey } from '../types'
import { bnOrZero } from './bignumber'

export type ConfirmationSpeed = `${FeeDataKey}`
export type Fee = string | number | BigNumber
export type Scalars = Record<ConfirmationSpeed, BigNumber>

export const calcFee = (fee: Fee, speed: ConfirmationSpeed, scalars: Scalars): string => {
return bnOrZero(fee).times(scalars[speed]).toFixed(0, BigNumber.ROUND_CEIL).toString()
}
2 changes: 2 additions & 0 deletions packages/chain-adapters/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
fromChainId,
} from '@shapeshiftoss/caip'

export * from './bignumber'
export * from './bip44'
export * from './fees'
export * from './utxoUtils'

export const getAssetNamespace = (type: string): AssetNamespace => {
Expand Down

0 comments on commit eb271d7

Please sign in to comment.