-
Notifications
You must be signed in to change notification settings - Fork 86
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
feat(earn): prepare transactions for supply when gas fee is covered #5483
Changes from 4 commits
70dfbe7
f55646f
512b9fc
bd8dbf3
e62a806
7821108
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,47 @@ describe('prepareTransactions module', () => { | |
feeCurrencies: mockFeeCurrencies, | ||
}) | ||
}) | ||
it("returns a 'possible' result when the balances for feeCurrencies are too low to cover the fee but isGasSubsidized is true", async () => { | ||
mocked(estimateFeesPerGas).mockResolvedValue({ | ||
maxFeePerGas: BigInt(100), | ||
maxPriorityFeePerGas: BigInt(2), | ||
baseFeePerGas: BigInt(50), | ||
}) | ||
mocked(estimateGas).mockResolvedValue(BigInt(1_000)) | ||
|
||
// max gas fee is 10 * 10k = 100k units, too high for either fee currency | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where do the 10 and 10k come from? should this be 100 (maxFeePerGas) * 1k (gas) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was copy pasted from the previous test...I think you're right. I'll fix it in both! |
||
|
||
const result = await prepareTransactions({ | ||
feeCurrencies: mockFeeCurrencies, | ||
spendToken: mockSpendToken, | ||
spendTokenAmount: new BigNumber(45_000), | ||
decreasedAmountGasFeeMultiplier: 1, | ||
baseTransactions: [ | ||
{ | ||
from: '0xfrom' as Address, | ||
to: '0xto' as Address, | ||
data: '0xdata', | ||
}, | ||
], | ||
isGasSubsidized: true, | ||
}) | ||
expect(result).toStrictEqual({ | ||
type: 'possible', | ||
feeCurrency: mockFeeCurrencies[0], | ||
transactions: [ | ||
{ | ||
from: '0xfrom', | ||
to: '0xto', | ||
data: '0xdata', | ||
|
||
gas: BigInt(1000), | ||
maxFeePerGas: BigInt(100), | ||
maxPriorityFeePerGas: BigInt(2), | ||
_baseFeePerGas: BigInt(50), | ||
}, | ||
], | ||
}) | ||
}) | ||
it("returns a 'not-enough-balance-for-gas' result when gas estimation throws error due to insufficient funds", async () => { | ||
mocked(estimateFeesPerGas).mockResolvedValue({ | ||
maxFeePerGas: BigInt(100), | ||
|
@@ -304,6 +345,46 @@ describe('prepareTransactions module', () => { | |
decreasedSpendAmount: new BigNumber(4.35), // 70.0 balance minus maxGasFee | ||
}) | ||
}) | ||
it("returns a 'possible' result when spending the exact max amount of a feeCurrency, and no other feeCurrency has enough balance to pay for the fee and isGasSubsidized is true", async () => { | ||
mocked(estimateFeesPerGas).mockResolvedValue({ | ||
maxFeePerGas: BigInt(1), | ||
maxPriorityFeePerGas: BigInt(2), | ||
baseFeePerGas: BigInt(1), | ||
}) | ||
|
||
const result = await prepareTransactions({ | ||
feeCurrencies: mockFeeCurrencies, | ||
spendToken: mockFeeCurrencies[1], | ||
spendTokenAmount: mockFeeCurrencies[1].balance.shiftedBy(mockFeeCurrencies[1].decimals), | ||
decreasedAmountGasFeeMultiplier: 1.01, | ||
isGasSubsidized: true, | ||
baseTransactions: [ | ||
{ | ||
from: '0xfrom' as Address, | ||
to: '0xto' as Address, | ||
data: '0xdata', | ||
_estimatedGasUse: BigInt(50), | ||
gas: BigInt(15_000), | ||
}, | ||
], | ||
}) | ||
expect(result).toStrictEqual({ | ||
type: 'possible', | ||
feeCurrency: mockFeeCurrencies[0], | ||
transactions: [ | ||
{ | ||
_baseFeePerGas: BigInt(1), | ||
_estimatedGasUse: BigInt(50), | ||
from: '0xfrom', | ||
gas: BigInt(15_000), | ||
maxFeePerGas: BigInt(1), | ||
maxPriorityFeePerGas: BigInt(2), | ||
to: '0xto', | ||
data: '0xdata', | ||
}, | ||
], | ||
}) | ||
}) | ||
it("returns a 'need-decrease-spend-amount-for-gas' result when spending close to the max amount of a feeCurrency, and no other feeCurrency has enough balance to pay for the fee", async () => { | ||
mocked(estimateFeesPerGas).mockResolvedValue({ | ||
maxFeePerGas: BigInt(1), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specify the feature gate here. E.g.,
jest.mocked(getFeatureGate).mockImplementation(gate => gate === <gate-name>)
, so this can be cleaned up when removing a gate. Also should this be reset in a beforeEach so it doesn't affect other tests?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already had it reset in the beforeEach, but I'll do the mockImplementation in both