-
Notifications
You must be signed in to change notification settings - Fork 162
Reset approval for USDT-like tokens in settlement encoding #4340
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||
| use { | ||||||
| super::{Address, TokenAddress}, | ||||||
| alloy_primitives::U256, | ||||||
| alloy_primitives::{U256, address}, | ||||||
| chain::Chain, | ||||||
| derive_more::{From, Into}, | ||||||
| }; | ||||||
|
|
||||||
|
|
@@ -60,4 +61,25 @@ impl Approval { | |||||
| ..self.0 | ||||||
| }) | ||||||
| } | ||||||
|
|
||||||
| /// Some tokens (e.g. USDT) revert when approving a non-zero value if the | ||||||
| /// current allowance is also non-zero. For these tokens the allowance must | ||||||
| /// be reset to 0 before setting a new value. | ||||||
| pub fn requires_reset(&self, chain: Chain) -> bool { | ||||||
| let tokens: &[Address] = match chain { | ||||||
| Chain::Mainnet => &[address!("dAC17F958D2ee523a2206206994597C13D831ec7")], // https://etherscan.io/token/0xdAC17F958D2ee523a2206206994597C13D831ec7 | ||||||
|
Contributor
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
Suggested change
|
||||||
|
|
||||||
| // Other implementations of USDT don't require you to reset the allowance first: | ||||||
| // - Bnb: https://bscscan.com/token/0x55d398326f99059ff775485246999027b3197955 | ||||||
| // - Base: https://basescan.org/token/0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2 | ||||||
| // - Arbitrum: https://arbiscan.io/token/0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9 | ||||||
| // - Polygon: https://polygonscan.com/token/0xc2132d05d31c914a87c6611c10748aeb04b58e8f | ||||||
| // - Avalanche: https://snowscan.xyz/token/0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7 | ||||||
| // - Linea: https://lineascan.build/token/0xa219439258ca9da29e9cc4ce5596924745e12b93 | ||||||
| // - Gnosis: https://gnosisscan.io/token/0x4ECaBa5870353805a9F068101A40E0f32ed605C6 | ||||||
| _ => &[], | ||||||
| }; | ||||||
|
|
||||||
| tokens.contains(&self.0.token.0) | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
the idea here, was to map all the tokens that requires reset. I thought there would be multiple tokens in multiple chains (this is why I went for this mapping of addresses to an tokens). When reviewing the code chain by chain, I saw that only mainnet has this behaviour, and I didn't find more cases.
So, not i'm tempted to not over-complicate this part and just check for a single address.
Let me know what you prefer
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.
Nice!
If we expect more tokens to be added we should make this configurable, though.
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.
Better is to have it in a config like @fafk mentioned
But if this is something exclusive to one or two tokens, I think this is ok as is 🤔