|
7 | 7 | prepareSupplyTransactions,
|
8 | 8 | prepareWithdrawAndClaimTransactions,
|
9 | 9 | } from 'src/earn/prepareTransactions'
|
10 |
| -import { getDynamicConfigParams } from 'src/statsig' |
11 |
| -import { StatsigDynamicConfigs } from 'src/statsig/types' |
| 10 | +import { getDynamicConfigParams, getFeatureGate } from 'src/statsig' |
| 11 | +import { StatsigDynamicConfigs, StatsigFeatureGates } from 'src/statsig/types' |
12 | 12 | import { TokenBalance } from 'src/tokens/slice'
|
13 | 13 | import { Network, NetworkId } from 'src/transactions/types'
|
14 | 14 | import { publicClient } from 'src/viem'
|
@@ -63,10 +63,16 @@ describe('prepareTransactions', () => {
|
63 | 63 | jest.mocked(encodeFunctionData).mockReturnValue('0xencodedData')
|
64 | 64 | jest.mocked(getDynamicConfigParams).mockImplementation(({ configName, defaultValues }) => {
|
65 | 65 | if (configName === StatsigDynamicConfigs.EARN_STABLECOIN_CONFIG) {
|
66 |
| - return { ...defaultValues, depositGasPadding: 100 } |
| 66 | + return { ...defaultValues, depositGasPadding: 100, approveGasPadding: 200 } |
67 | 67 | }
|
68 | 68 | return defaultValues
|
69 | 69 | })
|
| 70 | + jest.mocked(getFeatureGate).mockImplementation((featureGate) => { |
| 71 | + if (featureGate === StatsigFeatureGates.SUBSIDIZE_STABLECOIN_EARN_GAS_FEES) { |
| 72 | + return false |
| 73 | + } |
| 74 | + throw new Error(`Unexpected feature gate: ${featureGate}`) |
| 75 | + }) |
70 | 76 | })
|
71 | 77 |
|
72 | 78 | describe('prepareSupplyTransactions', () => {
|
@@ -146,6 +152,89 @@ describe('prepareTransactions', () => {
|
146 | 152 | feeCurrencies: [mockFeeCurrency],
|
147 | 153 | spendToken: mockToken,
|
148 | 154 | spendTokenAmount: new BigNumber(5),
|
| 155 | + isGasSubsidized: false, |
| 156 | + }) |
| 157 | + }) |
| 158 | + it('prepares fees from the cloud function for approve and supply when subsidizing gas fees', async () => { |
| 159 | + mockFetch.mockResponseOnce( |
| 160 | + JSON.stringify({ |
| 161 | + status: 'OK', |
| 162 | + simulatedTransactions: [ |
| 163 | + { |
| 164 | + status: 'success', |
| 165 | + blockNumber: '1', |
| 166 | + gasNeeded: 3000, |
| 167 | + gasUsed: 2800, |
| 168 | + gasPrice: '1', |
| 169 | + }, |
| 170 | + { |
| 171 | + status: 'success', |
| 172 | + blockNumber: '1', |
| 173 | + gasNeeded: 50000, |
| 174 | + gasUsed: 49800, |
| 175 | + gasPrice: '1', |
| 176 | + }, |
| 177 | + ], |
| 178 | + }) |
| 179 | + ) |
| 180 | + jest.mocked(getFeatureGate).mockImplementation((featureGate) => { |
| 181 | + if (featureGate === StatsigFeatureGates.SUBSIDIZE_STABLECOIN_EARN_GAS_FEES) { |
| 182 | + return true |
| 183 | + } |
| 184 | + throw new Error(`Unexpected feature gate: ${featureGate}`) |
| 185 | + }) |
| 186 | + |
| 187 | + const result = await prepareSupplyTransactions({ |
| 188 | + amount: '5', |
| 189 | + token: mockToken, |
| 190 | + walletAddress: '0x1234', |
| 191 | + feeCurrencies: [mockFeeCurrency], |
| 192 | + poolContractAddress: '0x5678', |
| 193 | + }) |
| 194 | + |
| 195 | + const expectedTransactions = [ |
| 196 | + { |
| 197 | + from: '0x1234', |
| 198 | + to: mockTokenAddress, |
| 199 | + data: '0xencodedData', |
| 200 | + gas: BigInt(3200), |
| 201 | + _estimatedGasUse: BigInt(2800), |
| 202 | + }, |
| 203 | + { |
| 204 | + from: '0x1234', |
| 205 | + to: '0x5678', |
| 206 | + data: '0xencodedData', |
| 207 | + gas: BigInt(50100), |
| 208 | + _estimatedGasUse: BigInt(49800), |
| 209 | + }, |
| 210 | + ] |
| 211 | + expect(result).toEqual({ |
| 212 | + type: 'possible', |
| 213 | + feeCurrency: mockFeeCurrency, |
| 214 | + transactions: expectedTransactions, |
| 215 | + }) |
| 216 | + expect(publicClient[Network.Arbitrum].readContract).toHaveBeenCalledWith({ |
| 217 | + address: mockTokenAddress, |
| 218 | + abi: erc20.abi, |
| 219 | + functionName: 'allowance', |
| 220 | + args: ['0x1234', '0x5678'], |
| 221 | + }) |
| 222 | + expect(encodeFunctionData).toHaveBeenNthCalledWith(1, { |
| 223 | + abi: erc20.abi, |
| 224 | + functionName: 'approve', |
| 225 | + args: ['0x5678', BigInt(5e6)], |
| 226 | + }) |
| 227 | + expect(encodeFunctionData).toHaveBeenNthCalledWith(2, { |
| 228 | + abi: aavePool, |
| 229 | + functionName: 'supply', |
| 230 | + args: [mockTokenAddress, BigInt(5e6), '0x1234', 0], |
| 231 | + }) |
| 232 | + expect(prepareTransactions).toHaveBeenCalledWith({ |
| 233 | + baseTransactions: expectedTransactions, |
| 234 | + feeCurrencies: [mockFeeCurrency], |
| 235 | + spendToken: mockToken, |
| 236 | + spendTokenAmount: new BigNumber(5), |
| 237 | + isGasSubsidized: true, |
149 | 238 | })
|
150 | 239 | })
|
151 | 240 |
|
@@ -204,6 +293,7 @@ describe('prepareTransactions', () => {
|
204 | 293 | feeCurrencies: [mockFeeCurrency],
|
205 | 294 | spendToken: mockToken,
|
206 | 295 | spendTokenAmount: new BigNumber(5),
|
| 296 | + isGasSubsidized: false, |
207 | 297 | })
|
208 | 298 | })
|
209 | 299 |
|
|
0 commit comments