From 66a776a33dc222d73576a07f16c587f1bb78ccc9 Mon Sep 17 00:00:00 2001 From: Guilherme Dantas Date: Mon, 1 Apr 2024 15:57:27 -0300 Subject: [PATCH] fix: ERC-20 portal docs (`amount` -> `value`) --- contracts/common/InputEncoding.sol | 6 ++-- contracts/portals/ERC20Portal.sol | 6 ++-- contracts/portals/IERC20Portal.sol | 6 ++-- test/foundry/portals/ERC20Portal.t.sol | 48 +++++++++++++------------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/contracts/common/InputEncoding.sol b/contracts/common/InputEncoding.sol index 74a54928..a41be2fb 100644 --- a/contracts/common/InputEncoding.sol +++ b/contracts/common/InputEncoding.sol @@ -33,20 +33,20 @@ library InputEncoding { /// @notice Encode an ERC-20 token deposit. /// @param token The token contract /// @param sender The token sender - /// @param amount The amount of tokens being sent + /// @param value The amount of tokens being sent /// @param execLayerData Additional data to be interpreted by the execution layer /// @return The encoded input payload function encodeERC20Deposit( IERC20 token, address sender, - uint256 amount, + uint256 value, bytes calldata execLayerData ) internal pure returns (bytes memory) { return abi.encodePacked( token, // 20B sender, // 20B - amount, // 32B + value, // 32B execLayerData // arbitrary size ); } diff --git a/contracts/portals/ERC20Portal.sol b/contracts/portals/ERC20Portal.sol index 19ddbf8f..201213e1 100644 --- a/contracts/portals/ERC20Portal.sol +++ b/contracts/portals/ERC20Portal.sol @@ -23,10 +23,10 @@ contract ERC20Portal is IERC20Portal, Portal { function depositERC20Tokens( IERC20 token, address appContract, - uint256 amount, + uint256 value, bytes calldata execLayerData ) external override { - bool success = token.transferFrom(msg.sender, appContract, amount); + bool success = token.transferFrom(msg.sender, appContract, value); if (!success) { revert ERC20TransferFailed(); @@ -35,7 +35,7 @@ contract ERC20Portal is IERC20Portal, Portal { bytes memory payload = InputEncoding.encodeERC20Deposit( token, msg.sender, - amount, + value, execLayerData ); diff --git a/contracts/portals/IERC20Portal.sol b/contracts/portals/IERC20Portal.sol index b7ee309c..1cb6b983 100644 --- a/contracts/portals/IERC20Portal.sol +++ b/contracts/portals/IERC20Portal.sol @@ -18,18 +18,18 @@ interface IERC20Portal is IPortal { /// @notice Transfer ERC-20 tokens to an application contract /// and add an input to the application's input box to signal such operation. /// - /// The caller must allow the portal to withdraw at least `amount` tokens + /// The caller must allow the portal to withdraw at least `value` tokens /// from their account beforehand, by calling the `approve` function in the /// token contract. /// /// @param token The ERC-20 token contract /// @param appContract The application contract address - /// @param amount The amount of tokens to be transferred + /// @param value The amount of tokens to be transferred /// @param execLayerData Additional data to be interpreted by the execution layer function depositERC20Tokens( IERC20 token, address appContract, - uint256 amount, + uint256 value, bytes calldata execLayerData ) external; } diff --git a/test/foundry/portals/ERC20Portal.t.sol b/test/foundry/portals/ERC20Portal.t.sol index 951e1aa9..a52d08a7 100644 --- a/test/foundry/portals/ERC20Portal.t.sol +++ b/test/foundry/portals/ERC20Portal.t.sol @@ -58,12 +58,12 @@ contract ERC20PortalTest is ERC165Test { assertEq(address(_portal.getInputBox()), address(_inputBox)); } - function testTokenReturnsTrue(uint256 amount, bytes calldata data) public { - bytes memory transferFrom = _encodeTransferFrom(amount); + function testTokenReturnsTrue(uint256 value, bytes calldata data) public { + bytes memory transferFrom = _encodeTransferFrom(value); vm.mockCall(address(_token), transferFrom, abi.encode(true)); - bytes memory payload = _encodePayload(_token, amount, data); + bytes memory payload = _encodePayload(_token, value, data); bytes memory addInput = _encodeAddInput(payload); @@ -74,15 +74,15 @@ contract ERC20PortalTest is ERC165Test { vm.expectCall(address(_inputBox), addInput, 1); vm.prank(_alice); - _portal.depositERC20Tokens(_token, _appContract, amount, data); + _portal.depositERC20Tokens(_token, _appContract, value, data); } - function testTokenReturnsFalse(uint256 amount, bytes calldata data) public { - bytes memory transferFrom = _encodeTransferFrom(amount); + function testTokenReturnsFalse(uint256 value, bytes calldata data) public { + bytes memory transferFrom = _encodeTransferFrom(value); vm.mockCall(address(_token), transferFrom, abi.encode(false)); - bytes memory payload = _encodePayload(_token, amount, data); + bytes memory payload = _encodePayload(_token, value, data); bytes memory addInput = _encodeAddInput(payload); @@ -91,19 +91,19 @@ contract ERC20PortalTest is ERC165Test { vm.expectRevert(IERC20Portal.ERC20TransferFailed.selector); vm.prank(_alice); - _portal.depositERC20Tokens(_token, _appContract, amount, data); + _portal.depositERC20Tokens(_token, _appContract, value, data); } function testTokenReverts( - uint256 amount, + uint256 value, bytes calldata data, bytes memory errorData ) public { - bytes memory transferFrom = _encodeTransferFrom(amount); + bytes memory transferFrom = _encodeTransferFrom(value); vm.mockCallRevert(address(_token), transferFrom, errorData); - bytes memory payload = _encodePayload(_token, amount, data); + bytes memory payload = _encodePayload(_token, value, data); bytes memory addInput = _encodeAddInput(payload); @@ -112,25 +112,25 @@ contract ERC20PortalTest is ERC165Test { vm.expectRevert(errorData); vm.prank(_alice); - _portal.depositERC20Tokens(_token, _appContract, amount, data); + _portal.depositERC20Tokens(_token, _appContract, value, data); } function testNormalToken( uint256 supply, - uint256 amount, + uint256 value, bytes calldata data ) public { - amount = bound(amount, 0, supply); + value = bound(value, 0, supply); NormalToken token = new NormalToken(_alice, supply); - bytes memory payload = _encodePayload(token, amount, data); + bytes memory payload = _encodePayload(token, value, data); bytes memory addInput = _encodeAddInput(payload); vm.startPrank(_alice); - token.approve(address(_portal), amount); + token.approve(address(_portal), value); vm.mockCall(address(_inputBox), addInput, abi.encode(bytes32(0))); @@ -142,32 +142,32 @@ contract ERC20PortalTest is ERC165Test { vm.expectCall(address(_inputBox), addInput, 1); vm.expectEmit(true, true, false, true, address(token)); - emit IERC20.Transfer(_alice, _appContract, amount); + emit IERC20.Transfer(_alice, _appContract, value); // deposit tokens - _portal.depositERC20Tokens(token, _appContract, amount, data); + _portal.depositERC20Tokens(token, _appContract, value, data); vm.stopPrank(); // balances after - assertEq(token.balanceOf(_alice), supply - amount); - assertEq(token.balanceOf(_appContract), amount); + assertEq(token.balanceOf(_alice), supply - value); + assertEq(token.balanceOf(_appContract), value); assertEq(token.balanceOf(address(_portal)), 0); } function _encodePayload( IERC20 token, - uint256 amount, + uint256 value, bytes calldata data ) internal view returns (bytes memory) { - return InputEncoding.encodeERC20Deposit(token, _alice, amount, data); + return InputEncoding.encodeERC20Deposit(token, _alice, value, data); } function _encodeTransferFrom( - uint256 amount + uint256 value ) internal view returns (bytes memory) { return - abi.encodeCall(IERC20.transferFrom, (_alice, _appContract, amount)); + abi.encodeCall(IERC20.transferFrom, (_alice, _appContract, value)); } function _encodeAddInput(