Skip to content

Latest commit

 

History

History
287 lines (253 loc) · 9.01 KB

NTransferUtilV2.md

File metadata and controls

287 lines (253 loc) · 9.01 KB

NTransferUtilV2.sol

View Source: contracts/libraries/NTransferUtilV2.sol

NTransferUtilV2

Functions

ensureApproval

Ensures approval of ERC20-like token

function ensureApproval(IERC20 malicious, address spender, uint256 amount) external nonpayable

Arguments

Name Type Description
malicious IERC20
spender address
amount uint256
Source Code
function ensureApproval(
    IERC20 malicious,
    address spender,
    uint256 amount
  ) external {
    require(address(malicious) != address(0), "Invalid token address");
    require(spender != address(0), "Invalid spender");
    require(amount > 0, "Invalid transfer amount");

    malicious.safeIncreaseAllowance(spender, amount);
  }

ensureTransfer

Ensures transfer of ERC20-like token

function ensureTransfer(IERC20 malicious, address recipient, uint256 amount) external nonpayable

Arguments

Name Type Description
malicious IERC20
recipient address
amount uint256
Source Code
function ensureTransfer(
    IERC20 malicious,
    address recipient,
    uint256 amount
  ) external {
    require(address(malicious) != address(0), "Invalid token address");
    require(recipient != address(0), "Spender can't be zero");
    require(amount > 0, "Invalid transfer amount");

    uint256 balanceBeforeTransfer = malicious.balanceOf(recipient);
    malicious.safeTransfer(recipient, amount);
    uint256 balanceAfterTransfer = malicious.balanceOf(recipient);

    // @suppress-subtraction
    uint256 actualTransferAmount = balanceAfterTransfer - balanceBeforeTransfer;

    require(actualTransferAmount == amount, "Invalid transfer");
  }

ensureTransferFrom

Ensures transferFrom of ERC20-like token

function ensureTransferFrom(IERC20 malicious, address sender, address recipient, uint256 amount) external nonpayable

Arguments

Name Type Description
malicious IERC20
sender address
recipient address
amount uint256
Source Code
function ensureTransferFrom(
    IERC20 malicious,
    address sender,
    address recipient,
    uint256 amount
  ) external {
    require(address(malicious) != address(0), "Invalid token address");
    require(sender != address(0), "Invalid sender");
    require(recipient != address(0), "Invalid recipient");
    require(amount > 0, "Invalid transfer amount");

    uint256 balanceBeforeTransfer = malicious.balanceOf(recipient);
    malicious.safeTransferFrom(sender, recipient, amount);
    uint256 balanceAfterTransfer = malicious.balanceOf(recipient);

    // @suppress-subtraction
    uint256 actualTransferAmount = balanceAfterTransfer - balanceBeforeTransfer;

    require(actualTransferAmount == amount, "Invalid transfer");
  }

Contracts