Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: release v1.715.0 #8259

Merged
merged 9 commits into from
Dec 4, 2024
2 changes: 1 addition & 1 deletion .env.base
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ REACT_APP_FEATURE_READ_ONLY_ASSETS=true
# Swapper chain-specific flags. Use me if you're working on a swapper which brings first time swapper support for a chain,
# meaning we don't want to enable the selection for said chain in prod just yet
# Or alternatively, if we know that a given chain is very unstable and we may want to disable it in swapper altogether.
REACT_APP_FEATURE_SWAPPER_SOLANA=false
REACT_APP_FEATURE_SWAPPER_SOLANA=true

# Swapper feature flags - other .env files will override these
REACT_APP_FEATURE_CHAINFLIP_SWAP=false
Expand Down
4 changes: 3 additions & 1 deletion .env.develop
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
REACT_APP_FEATURE_SWAPPER_SOLANA=true

# Swapper feature flags
REACT_APP_FEATURE_LIMIT_ORDERS=true
REACT_APP_FEATURE_CHAINFLIP_SWAP=true
REACT_APP_FEATURE_CHAINFLIP_SWAP_DCA=false
REACT_APP_FEATURE_PUBLIC_TRADE_ROUTE=true
REACT_APP_FEATURE_LIMIT_ORDERS=true
REACT_APP_FEATURE_JUPITER_SWAP=true

# mixpanel
REACT_APP_MIXPANEL_TOKEN=1c1369f6ea23a6404bac41b42817cc4b
Expand Down
85 changes: 49 additions & 36 deletions packages/chain-adapters/src/evm/base/BaseChainAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { KnownChainIds } from '@shapeshiftoss/types'
import * as unchained from '@shapeshiftoss/unchained-client'
import BigNumber from 'bignumber.js'

import { ErrorHandler } from '../../error/ErrorHandler'
import type { FeeDataEstimate, GetFeeDataInput } from '../../types'
import { ChainAdapterDisplayName } from '../../types'
import { bnOrZero } from '../../utils'
Expand Down Expand Up @@ -64,48 +65,60 @@ export class ChainAdapter extends EvmBaseAdapter<KnownChainIds.BaseMainnet> {
}

async getGasFeeData(): Promise<GasFeeDataEstimate> {
const { fast, average, slow, l1GasPrice } = await this.api.getGasFees()

return {
fast: { ...fast, l1GasPrice },
average: { ...average, l1GasPrice },
slow: { ...slow, l1GasPrice },
try {
const { fast, average, slow, l1GasPrice } = await this.api.getGasFees()

return {
fast: { ...fast, l1GasPrice },
average: { ...average, l1GasPrice },
slow: { ...slow, l1GasPrice },
}
} catch (err) {
return ErrorHandler(err, {
translation: 'chainAdapters.errors.getGasFeeData',
})
}
}

async getFeeData(
input: GetFeeDataInput<KnownChainIds.BaseMainnet>,
): Promise<FeeDataEstimate<KnownChainIds.BaseMainnet>> {
const req = await this.buildEstimateGasRequest(input)

const { gasLimit, l1GasLimit } = await this.api.estimateGas(req)
const { fast, average, slow } = await this.getGasFeeData()

return {
fast: {
txFee: bnOrZero(
BigNumber.max(fast.gasPrice, fast.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(fast.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...fast },
},
average: {
txFee: bnOrZero(
BigNumber.max(average.gasPrice, average.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(average.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...average },
},
slow: {
txFee: bnOrZero(
BigNumber.max(slow.gasPrice, slow.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(slow.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...slow },
},
try {
const req = await this.buildEstimateGasRequest(input)

const { gasLimit, l1GasLimit } = await this.api.estimateGas(req)
const { fast, average, slow } = await this.getGasFeeData()

return {
fast: {
txFee: bnOrZero(
BigNumber.max(fast.gasPrice, fast.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(fast.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...fast },
},
average: {
txFee: bnOrZero(
BigNumber.max(average.gasPrice, average.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(average.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...average },
},
slow: {
txFee: bnOrZero(
BigNumber.max(slow.gasPrice, slow.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(slow.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...slow },
},
}
} catch (err) {
return ErrorHandler(err, {
translation: 'chainAdapters.errors.getFeeData',
})
}
}
}
107 changes: 60 additions & 47 deletions packages/chain-adapters/src/evm/bnbsmartchain/BscChainAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { KnownChainIds } from '@shapeshiftoss/types'
import * as unchained from '@shapeshiftoss/unchained-client'
import BigNumber from 'bignumber.js'

import { ErrorHandler } from '../../error/ErrorHandler'
import type { FeeDataEstimate, GetFeeDataInput } from '../../types'
import { ChainAdapterDisplayName } from '../../types'
import { bn, bnOrZero } from '../../utils/bignumber'
Expand Down Expand Up @@ -63,57 +64,69 @@ export class ChainAdapter extends EvmBaseAdapter<KnownChainIds.BnbSmartChainMain
}

async getGasFeeData(): Promise<GasFeeDataEstimate & { baseFeePerGas?: string }> {
const { fast, average, slow, baseFeePerGas } = await this.providers.http.getGasFees()
return { fast, average, slow, baseFeePerGas }
try {
const { fast, average, slow, baseFeePerGas } = await this.providers.http.getGasFees()
return { fast, average, slow, baseFeePerGas }
} catch (err) {
return ErrorHandler(err, {
translation: 'chainAdapters.errors.getGasFeeData',
})
}
}

async getFeeData(
input: GetFeeDataInput<KnownChainIds.BnbSmartChainMainnet>,
): Promise<FeeDataEstimate<KnownChainIds.BnbSmartChainMainnet>> {
const req = await this.buildEstimateGasRequest(input)

const { gasLimit } = await this.providers.http.estimateGas(req)
const { fast, average, slow, baseFeePerGas } = await this.getGasFeeData()

// Binance official JSON-RPC endpoint has a minimum enforced gas price of 3 Gwei
const MIN_GAS_PRICE = '3000000000'

;[fast, average, slow].forEach(estimate => {
estimate.gasPrice = BigNumber.max(estimate.gasPrice, MIN_GAS_PRICE).toFixed(0)

if (estimate.maxFeePerGas) {
estimate.maxFeePerGas = BigNumber.max(estimate.maxFeePerGas, MIN_GAS_PRICE).toFixed(0)
}

if (estimate.maxPriorityFeePerGas) {
estimate.maxPriorityFeePerGas = BigNumber.max(
bn(estimate.maxPriorityFeePerGas).plus(bnOrZero(baseFeePerGas)),
MIN_GAS_PRICE,
)
.minus(bnOrZero(baseFeePerGas))
.toFixed(0)
}
})

return {
fast: {
txFee: bnOrZero(
BigNumber.max(fast.gasPrice, fast.maxFeePerGas ?? 0).times(gasLimit),
).toFixed(0),
chainSpecific: { gasLimit, ...fast, gasPrice: fast.gasPrice },
},
average: {
txFee: bnOrZero(
BigNumber.max(average.gasPrice, average.maxFeePerGas ?? 0).times(gasLimit),
).toFixed(0),
chainSpecific: { gasLimit, ...average, gasPrice: average.gasPrice },
},
slow: {
txFee: bnOrZero(
BigNumber.max(slow.gasPrice, slow.maxFeePerGas ?? 0).times(gasLimit),
).toFixed(0),
chainSpecific: { gasLimit, ...slow, gasPrice: slow.gasPrice },
},
} as FeeDataEstimate<KnownChainIds.BnbSmartChainMainnet>
try {
const req = await this.buildEstimateGasRequest(input)

const { gasLimit } = await this.providers.http.estimateGas(req)
const { fast, average, slow, baseFeePerGas } = await this.getGasFeeData()

// Binance official JSON-RPC endpoint has a minimum enforced gas price of 3 Gwei
const MIN_GAS_PRICE = '3000000000'

;[fast, average, slow].forEach(estimate => {
estimate.gasPrice = BigNumber.max(estimate.gasPrice, MIN_GAS_PRICE).toFixed(0)

if (estimate.maxFeePerGas) {
estimate.maxFeePerGas = BigNumber.max(estimate.maxFeePerGas, MIN_GAS_PRICE).toFixed(0)
}

if (estimate.maxPriorityFeePerGas) {
estimate.maxPriorityFeePerGas = BigNumber.max(
bn(estimate.maxPriorityFeePerGas).plus(bnOrZero(baseFeePerGas)),
MIN_GAS_PRICE,
)
.minus(bnOrZero(baseFeePerGas))
.toFixed(0)
}
})

return {
fast: {
txFee: bnOrZero(
BigNumber.max(fast.gasPrice, fast.maxFeePerGas ?? 0).times(gasLimit),
).toFixed(0),
chainSpecific: { gasLimit, ...fast, gasPrice: fast.gasPrice },
},
average: {
txFee: bnOrZero(
BigNumber.max(average.gasPrice, average.maxFeePerGas ?? 0).times(gasLimit),
).toFixed(0),
chainSpecific: { gasLimit, ...average, gasPrice: average.gasPrice },
},
slow: {
txFee: bnOrZero(
BigNumber.max(slow.gasPrice, slow.maxFeePerGas ?? 0).times(gasLimit),
).toFixed(0),
chainSpecific: { gasLimit, ...slow, gasPrice: slow.gasPrice },
},
} as FeeDataEstimate<KnownChainIds.BnbSmartChainMainnet>
} catch (err) {
return ErrorHandler(err, {
translation: 'chainAdapters.errors.getFeeData',
})
}
}
}
85 changes: 49 additions & 36 deletions packages/chain-adapters/src/evm/optimism/OptimismChainAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { KnownChainIds } from '@shapeshiftoss/types'
import * as unchained from '@shapeshiftoss/unchained-client'
import BigNumber from 'bignumber.js'

import { ErrorHandler } from '../../error/ErrorHandler'
import type { FeeDataEstimate, GetFeeDataInput } from '../../types'
import { ChainAdapterDisplayName } from '../../types'
import { bnOrZero } from '../../utils'
Expand Down Expand Up @@ -66,48 +67,60 @@ export class ChainAdapter extends EvmBaseAdapter<KnownChainIds.OptimismMainnet>
}

async getGasFeeData(): Promise<GasFeeDataEstimate> {
const { fast, average, slow, l1GasPrice } = await this.api.getGasFees()

return {
fast: { ...fast, l1GasPrice },
average: { ...average, l1GasPrice },
slow: { ...slow, l1GasPrice },
try {
const { fast, average, slow, l1GasPrice } = await this.api.getGasFees()

return {
fast: { ...fast, l1GasPrice },
average: { ...average, l1GasPrice },
slow: { ...slow, l1GasPrice },
}
} catch (err) {
return ErrorHandler(err, {
translation: 'chainAdapters.errors.getGasFeeData',
})
}
}

async getFeeData(
input: GetFeeDataInput<KnownChainIds.OptimismMainnet>,
): Promise<FeeDataEstimate<KnownChainIds.OptimismMainnet>> {
const req = await this.buildEstimateGasRequest(input)

const { gasLimit, l1GasLimit } = await this.api.estimateGas(req)
const { fast, average, slow } = await this.getGasFeeData()

return {
fast: {
txFee: bnOrZero(
BigNumber.max(fast.gasPrice, fast.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(fast.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...fast },
},
average: {
txFee: bnOrZero(
BigNumber.max(average.gasPrice, average.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(average.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...average },
},
slow: {
txFee: bnOrZero(
BigNumber.max(slow.gasPrice, slow.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(slow.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...slow },
},
try {
const req = await this.buildEstimateGasRequest(input)

const { gasLimit, l1GasLimit } = await this.api.estimateGas(req)
const { fast, average, slow } = await this.getGasFeeData()

return {
fast: {
txFee: bnOrZero(
BigNumber.max(fast.gasPrice, fast.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(fast.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...fast },
},
average: {
txFee: bnOrZero(
BigNumber.max(average.gasPrice, average.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(average.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...average },
},
slow: {
txFee: bnOrZero(
BigNumber.max(slow.gasPrice, slow.maxFeePerGas ?? 0)
.times(gasLimit)
.plus(bnOrZero(slow.l1GasPrice).times(l1GasLimit)),
).toFixed(0),
chainSpecific: { gasLimit, l1GasLimit, ...slow },
},
}
} catch (err) {
return ErrorHandler(err, {
translation: 'chainAdapters.errors.getFeeData',
})
}
}
}
16 changes: 12 additions & 4 deletions packages/swapper/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ const DEFAULT_LIFI_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005' // .5%
const DEFAULT_THOR_SLIPPAGE_DECIMAL_PERCENTAGE = '0.01' // 1%
const DEFAULT_ARBITRUM_BRIDGE_SLIPPAGE_DECIMAL_PERCENTAGE = '0' // no slippage for Arbitrum Bridge, so no slippage tolerance
const DEFAULT_CHAINFLIP_SLIPPAGE_DECIMAL_PERCENTAGE = '0.02' // 2%
const DEFAULT_JUPITER_SLIPPAGE_DECIMAL_PERCENTAGE = '0.01' // 1%

export const getDefaultSlippageDecimalPercentageForSwapper = (
swapperName?: SwapperName,
swapperName: SwapperName | undefined,
): string => {
if (swapperName === undefined) return DEFAULT_SLIPPAGE_DECIMAL_PERCENTAGE
switch (swapperName) {
Expand All @@ -128,8 +127,17 @@ export const getDefaultSlippageDecimalPercentageForSwapper = (
case SwapperName.Chainflip:
return DEFAULT_CHAINFLIP_SLIPPAGE_DECIMAL_PERCENTAGE
case SwapperName.Jupiter:
return DEFAULT_JUPITER_SLIPPAGE_DECIMAL_PERCENTAGE
throw new Error('Default slippage not supported by Jupiter')
default:
assertUnreachable(swapperName)
return assertUnreachable(swapperName)
}
}

export const isAutoSlippageSupportedBySwapper = (swapperName: SwapperName): boolean => {
switch (swapperName) {
case SwapperName.Jupiter:
return true
default:
return false
}
}
Loading
Loading