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

Commit

Permalink
fix: update osmosis min fee to comply with v15.0.0 min consensus fee …
Browse files Browse the repository at this point in the history
…update (#1227)
  • Loading branch information
kaladinlight authored Mar 28, 2023
1 parent 4826d62 commit b89d78b
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 28 deletions.
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,13 +19,16 @@ import {
SignTxInput,
} from '../../types'
import { toAddressNList } from '../../utils'
import { bn, calcFee } from '../../utils'
import {
assertIsValidatorAddress,
ChainAdapterArgs,
CosmosSdkBaseAdapter,
} from '../CosmosSdkBaseAdapter'
import { Message, ValidatorAction } from '../types'

export const MIN_FEE = '2500'

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

Expand Down Expand Up @@ -329,12 +332,15 @@ export class ChainAdapter extends CosmosSdkBaseAdapter<KnownChainIds.OsmosisMain
}: Partial<GetFeeDataInput<KnownChainIds.OsmosisMainnet>>): Promise<
FeeDataEstimate<KnownChainIds.OsmosisMainnet>
> {
const gasLimit = '300000'
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: '300000' } },
average: { txFee: '3500', chainSpecific: { gasLimit: '300000' } },
slow: { txFee: '2500', chainSpecific: { gasLimit: '300000' } },
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
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
2 changes: 1 addition & 1 deletion packages/swapper/src/swappers/osmosis/OsmosisSwapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export class OsmosisSwapper implements Swapper<ChainId> {
this.deps.cosmosUrl,
buyAssetDenom,
OSMO_COSMO_CHANNEL,
'0',
osmosis.MIN_FEE,
accountNumber,
ibcAccountNumber,
ibcSequence,
Expand Down
2 changes: 1 addition & 1 deletion packages/swapper/src/swappers/osmosis/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export const buildTradeTx = async ({
fee: {
amount: [
{
amount: '0',
amount: osmosis.MIN_FEE,
denom: 'uosmo',
},
],
Expand Down

0 comments on commit b89d78b

Please sign in to comment.