Skip to content

Commit aa2a535

Browse files
committed
feat: Update SafeERC20 to match latest Solidity version
1 parent 49f9b00 commit aa2a535

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

contracts/src/token/erc20/utils/safe_erc20.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ mod sol {
3939
///
4040
/// * `token` - Address of the ERC-20 token.
4141
#[derive(Debug)]
42-
#[allow(missing_docs)]
4342
error SafeErc20FailedOperation(address token);
4443

4544
/// Indicates a failed [`ISafeErc20::safe_decrease_allowance`] request.
@@ -48,7 +47,6 @@ mod sol {
4847
/// * `current_allowance` - Current allowance of the `spender`.
4948
/// * `requested_decrease` - Requested decrease in allowance for `spender`.
5049
#[derive(Debug)]
51-
#[allow(missing_docs)]
5250
error SafeErc20FailedDecreaseAllowance(
5351
address spender,
5452
uint256 current_allowance,
@@ -350,7 +348,6 @@ pub trait ISafeErc20 {
350348
) -> Result<(), Self::Error>;
351349
}
352350

353-
#[public]
354351
impl ISafeErc20 for SafeErc20 {
355352
type Error = Error;
356353

@@ -480,7 +477,8 @@ impl ISafeErc20 for SafeErc20 {
480477
if Self::account_has_code(to) == 0 {
481478
self.safe_transfer_from(token, from, to, value)
482479
} else {
483-
let call = IErc1363::transferFromAndCallCall { from, to, value, data: data.into() };
480+
let data_bytes = data.into();
481+
let call = IErc1363::transferFromAndCallCall { from, to, value, data: data_bytes };
484482
if !Self::call_optional_return_bool(&token, &call)? {
485483
return Err(Error::SafeErc20FailedOperation(SafeErc20FailedOperation { token }));
486484
}
@@ -510,9 +508,9 @@ impl ISafeErc20 for SafeErc20 {
510508

511509
impl SafeErc20 {
512510
#[inline]
513-
fn account_has_code(addr: Address) -> usize {
514-
// SAFETY: extcodesize is a pure query, no state mutation or re-entrancy
515-
unsafe { stylus_sdk::prelude::extcodesize(addr) }
511+
fn account_has_code(addr: Address) -> bool {
512+
// returns true if `addr` has contract code
513+
addr.has_code()
516514
}
517515

518516
fn call_optional_return(
@@ -558,7 +556,7 @@ impl SafeErc20 {
558556

559557
let return_data = match result {
560558
Ok(bytes) => bytes,
561-
Err(_) => return Ok(false), // keep soft failure but make it explicit
559+
Err(_) => return Ok(false), // keep "soft" failure but make it explicit
562560
};
563561

564562
Ok(Self::encodes_true(&return_data))

0 commit comments

Comments
 (0)