Skip to content

Commit

Permalink
feat(earn): get gas padding from dynamic config (#5418)
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
satish-ravi committed May 15, 2024
1 parent 7fde064 commit 71554e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/earn/prepareTransactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'),
Expand All @@ -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', () => {
Expand Down Expand Up @@ -101,7 +110,7 @@ describe('prepareTransactions', () => {
from: '0x1234',
to: '0x5678',
data: '0xencodedData',
gas: BigInt(50000),
gas: BigInt(50100),
_estimatedGasUse: BigInt(49800),
},
]
Expand Down Expand Up @@ -164,7 +173,7 @@ describe('prepareTransactions', () => {
from: '0x1234',
to: '0x5678',
data: '0xencodedData',
gas: BigInt(50000),
gas: BigInt(50100),
_estimatedGasUse: BigInt(49800),
},
]
Expand Down
11 changes: 10 additions & 1 deletion src/earn/prepareTransactions.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/statsig/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const DynamicConfigs = {
providerName: 'Aave',
providerLogoUrl: '',
providerTermsAndConditionsUrl: '',
depositGasPadding: 0,
},
},
} satisfies {
Expand Down

0 comments on commit 71554e2

Please sign in to comment.