From 71554e2c6877bae1d1f0d7d84808cf0d9e45a538 Mon Sep 17 00:00:00 2001 From: Satish Ravi Date: Wed, 15 May 2024 14:58:16 -0700 Subject: [PATCH] feat(earn): get gas padding from dynamic config (#5418) ### Description As the title ### Test plan Unit tests, manual Successful tx: https://sepolia.arbiscan.io/tx/0xe681a97041ad016ecfae008111285db3b14a60a5054abd5912109af2987245d0 https://arbiscan.io/tx/0x3a72d7edf302f4d88ae86dc42bbffd87b95d47ee9b4a1a0723ddee13cd30954f https://github.com/valora-inc/wallet/assets/5062591/86a99157-d2c8-4c21-9196-640784d1ce9a ### Related issues - Part of ACT-1178 ### Backwards compatibility Yes ### Network scalability If a new NetworkId and/or Network are added in the future, the changes in this PR will: - [x] Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added) --- src/earn/prepareTransactions.test.ts | 13 +++++++++++-- src/earn/prepareTransactions.ts | 11 ++++++++++- src/statsig/constants.ts | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/earn/prepareTransactions.test.ts b/src/earn/prepareTransactions.test.ts index dddec0295ac..c14e0e7e76e 100644 --- a/src/earn/prepareTransactions.test.ts +++ b/src/earn/prepareTransactions.test.ts @@ -3,6 +3,8 @@ import { FetchMock } from 'jest-fetch-mock/types' import aavePool from 'src/abis/AavePoolV3' import erc20 from 'src/abis/IERC20' import { prepareSupplyTransactions } from 'src/earn/prepareTransactions' +import { getDynamicConfigParams } from 'src/statsig' +import { StatsigDynamicConfigs } from 'src/statsig/types' import { TokenBalance } from 'src/tokens/slice' import { Network, NetworkId } from 'src/transactions/types' import { publicClient } from 'src/viem' @@ -36,6 +38,7 @@ const mockToken: TokenBalance = { networkId: NetworkId['arbitrum-sepolia'], } +jest.mock('src/statsig') jest.mock('src/viem/prepareTransactions') jest.mock('viem', () => ({ ...jest.requireActual('viem'), @@ -52,6 +55,12 @@ describe('prepareTransactions', () => { })) jest.spyOn(publicClient[Network.Arbitrum], 'readContract').mockResolvedValue(BigInt(0)) jest.mocked(encodeFunctionData).mockReturnValue('0xencodedData') + jest.mocked(getDynamicConfigParams).mockImplementation(({ configName, defaultValues }) => { + if (configName === StatsigDynamicConfigs.EARN_STABLECOIN_CONFIG) { + return { ...defaultValues, depositGasPadding: 100 } + } + return defaultValues + }) }) describe('prepareSupplyTransactions', () => { @@ -101,7 +110,7 @@ describe('prepareTransactions', () => { from: '0x1234', to: '0x5678', data: '0xencodedData', - gas: BigInt(50000), + gas: BigInt(50100), _estimatedGasUse: BigInt(49800), }, ] @@ -164,7 +173,7 @@ describe('prepareTransactions', () => { from: '0x1234', to: '0x5678', data: '0xencodedData', - gas: BigInt(50000), + gas: BigInt(50100), _estimatedGasUse: BigInt(49800), }, ] diff --git a/src/earn/prepareTransactions.ts b/src/earn/prepareTransactions.ts index 0e22dfefcab..8862a6462f8 100644 --- a/src/earn/prepareTransactions.ts +++ b/src/earn/prepareTransactions.ts @@ -1,6 +1,9 @@ import BigNumber from 'bignumber.js' import aavePool from 'src/abis/AavePoolV3' import erc20 from 'src/abis/IERC20' +import { getDynamicConfigParams } from 'src/statsig' +import { DynamicConfigs } from 'src/statsig/constants' +import { StatsigDynamicConfigs } from 'src/statsig/types' import { TokenBalance } from 'src/tokens/slice' import { fetchWithTimeout } from 'src/utils/fetchWithTimeout' import { publicClient } from 'src/viem' @@ -112,7 +115,13 @@ export async function prepareSupplyTransactions({ ) } - baseTransactions[baseTransactions.length - 1].gas = BigInt(supplySimulatedTx.gasNeeded) + const { depositGasPadding } = getDynamicConfigParams( + DynamicConfigs[StatsigDynamicConfigs.EARN_STABLECOIN_CONFIG] + ) + + baseTransactions[baseTransactions.length - 1].gas = BigInt( + supplySimulatedTx.gasNeeded + depositGasPadding + ) baseTransactions[baseTransactions.length - 1]._estimatedGasUse = BigInt(supplySimulatedTx.gasUsed) return prepareTransactions({ diff --git a/src/statsig/constants.ts b/src/statsig/constants.ts index 608bd1ae32c..879926cc752 100644 --- a/src/statsig/constants.ts +++ b/src/statsig/constants.ts @@ -141,6 +141,7 @@ export const DynamicConfigs = { providerName: 'Aave', providerLogoUrl: '', providerTermsAndConditionsUrl: '', + depositGasPadding: 0, }, }, } satisfies {