Repository navigation
fix(ui): use full balance on MAX for non-native tokens #1141
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@relayprotocol/relay-kit-ui': patch | ||
| --- | ||
|
|
||
| MAX now uses the full balance for non-native tokens. The execution and gas buffers only apply to native tokens. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { | ||
| MAX_INPUT_BUFFER_BPS, | ||
| MIN_INPUT_BUFFER_UNITS | ||
| } from '../constants/maxAmountBuffer.js' | ||
|
|
||
| /** | ||
| * Headroom subtracted from a native balance on MAX to avoid exact-balance | ||
| * execution edge cases. | ||
| */ | ||
| export const getExecutionBuffer = (amount: bigint): bigint => { | ||
| if (amount <= 0n) return 0n | ||
|
|
||
| const bpsBuffer = (amount * MAX_INPUT_BUFFER_BPS) / 10000n | ||
| const minimumBuffer = | ||
| amount > MIN_INPUT_BUFFER_UNITS ? MIN_INPUT_BUFFER_UNITS : amount | ||
|
|
||
| return bpsBuffer > minimumBuffer ? bpsBuffer : minimumBuffer | ||
| } | ||
|
|
||
| /** | ||
| * Returns the amount to populate when MAX is clicked. Native tokens keep an | ||
| * execution buffer plus the gas fee buffer; other tokens use the full balance | ||
| * since gas is paid in the native token. | ||
| */ | ||
| export const getMaxAmount = ( | ||
| balance: bigint, | ||
| isFromNative: boolean, | ||
| feeBufferAmount: bigint = 0n | ||
| ): bigint => { | ||
| if (balance <= 0n) return 0n | ||
| if (!isFromNative) return balance | ||
|
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.
The new full-balance branch has no regression test. Without a test for the Base USDC sale and one confirming that native-token MAX keeps gas headroom, a later change could restore the original ERC-20 bug or break the native behavior without being caught. Greptile automatically discovered a related ticket stating that the Base USDC case should have a regression test, which informed this comment. Source Used: Linear — MAX leaves gas reserve for ERC-20 sales Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
|
|
||
| const totalBufferAmount = getExecutionBuffer(balance) + feeBufferAmount | ||
| return balance > totalBufferAmount ? balance - totalBufferAmount : 0n | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.