-
Notifications
You must be signed in to change notification settings - Fork 279
feat: TIP-1035 #3828
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?
feat: TIP-1035 #3828
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 |
|---|---|---|
|
|
@@ -179,15 +179,23 @@ impl StablecoinDEX { | |
| } | ||
|
|
||
| /// Transfer tokens from user, accounting for pathUSD | ||
| fn transfer_from(&mut self, token: Address, from: Address, amount: u128) -> Result<()> { | ||
| TIP20Token::from_address(token)?.transfer_from( | ||
| self.address, | ||
| ITIP20::transferFromCall { | ||
| from, | ||
| to: self.address, | ||
| amount: U256::from(amount), | ||
| }, | ||
| )?; | ||
| fn transfer_from(&mut self, token: Address, sender: Address, amount: u128) -> Result<()> { | ||
|
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. should we create this fn as a new TIP20 helper (i.e it would ensure that impl and registry are always aligned + that
Member
Author
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. added here be93800 |
||
| if self.storage.spec().is_t5() { | ||
| TIP20Token::from_address(token)?.system_transfer_from( | ||
| self.address, | ||
| sender, | ||
| U256::from(amount), | ||
| )?; | ||
| } else { | ||
| TIP20Token::from_address(token)?.transfer_from( | ||
| self.address, | ||
| ITIP20::transferFromCall { | ||
| from: sender, | ||
| to: self.address, | ||
| amount: U256::from(amount), | ||
| }, | ||
| )?; | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
|
|
@@ -199,30 +207,30 @@ impl StablecoinDEX { | |
| /// redundant SLOAD. | ||
| fn decrement_balance_or_transfer_from( | ||
| &mut self, | ||
| user: Address, | ||
| sender: Address, | ||
| token: Address, | ||
| amount: u128, | ||
| check_pause: bool, | ||
| ) -> Result<()> { | ||
| // Ensure that the token can be transferred | ||
| let tip20 = TIP20Token::from_address(token)?; | ||
| tip20.ensure_transfer_authorized(user, self.address)?; | ||
| tip20.ensure_transfer_authorized(sender, self.address)?; | ||
|
|
||
| let user_balance = self.balance_of(user, token)?; | ||
| let user_balance = self.balance_of(sender, token)?; | ||
| if user_balance >= amount { | ||
| // When fully covered by internal balance, TIP-20 transferFrom won't run, | ||
| // so we must check the pause state ourselves (spec: T4+). | ||
| if check_pause && self.storage.spec().is_t4() { | ||
| tip20.check_not_paused()?; | ||
| } | ||
| self.sub_balance(user, token, amount) | ||
| self.sub_balance(sender, token, amount) | ||
| } else { | ||
| let remaining = amount | ||
| .checked_sub(user_balance) | ||
| .ok_or(TempoPrecompileError::under_overflow())?; | ||
|
|
||
| self.transfer_from(token, user, remaining)?; | ||
| self.set_balance(user, token, 0) | ||
| self.transfer_from(token, sender, remaining)?; | ||
| self.set_balance(sender, token, 0) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Can we also add
TIP_20_ESCROW_PRECOMPILEto this, ig it also needs to be updated in the TIP itself.CC: @danrobinson
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.
we don't yet have this const defined so i'd suggest we do it in scope of TIP-1034