Skip to content

Commit

Permalink
Add stubs for the rest of ERC20-related safe-functions
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNeshi committed Sep 24, 2024
1 parent 282e9f9 commit 23ca2af
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
34 changes: 34 additions & 0 deletions contracts/src/token/erc20/utils/safe_erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,38 @@ impl SafeErc20 {

Ok(())
}

/// Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
/// non-reverting calls are assumed to be successful.
pub fn safe_increase_allowance(
&mut self,
token: Address,
spender: Address,
value: U256,
) -> Result<(), Error> {
todo!()
}

/// Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
/// value, non-reverting calls are assumed to be successful.
pub fn safe_decrease_allowance(
&mut self,
token: Address,
spender: Address,
requested_decrease: U256,
) -> Result<(), Error> {
todo!()
}

/// Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
/// non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
/// to be set to zero before setting it to a non-zero value, such as USDT.
pub fn force_approve(
&mut self,
token: Address,
spender: Address,
value: U256,
) -> Result<(), Error> {
todo!()
}
}
3 changes: 3 additions & 0 deletions examples/safe-erc20/tests/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ sol!(
contract SafeErc20 {
function safeTransfer(address token, address to, uint256 value) external;
function safeTransferFrom(address token, address from, address to, uint256 value) external;
function safeIncreaseAllowance(address token, address spender, uint256 value) external;
function safeDecreaseAllowance(address token, address spender, uint256 requestedDecrease) external;
function forceApprove(address token, address spender, uint256 value) external;

error SafeErc20FailedOperation(address token);
error SafeErc20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
Expand Down

0 comments on commit 23ca2af

Please sign in to comment.