From 9a8a1f55a6911c0fe7e8172a97293057e234b098 Mon Sep 17 00:00:00 2001 From: Riley Date: Fri, 18 Aug 2023 11:18:55 -0700 Subject: [PATCH] Update EIP-6909: Update reference implementation to specification Merged by EIP-Bot. --- EIPS/eip-6909.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/EIPS/eip-6909.md b/EIPS/eip-6909.md index 13177930d1388..b36af5ed9ec1f 100644 --- a/EIPS/eip-6909.md +++ b/EIPS/eip-6909.md @@ -510,11 +510,12 @@ contract ERC6909 { /// @param receiver The address of the receiver. /// @param id The id of the token. /// @param amount The amount of the token. - function transfer(address receiver, uint256 id, uint256 amount) public { + function transfer(address receiver, uint256 id, uint256 amount) public returns (bool) { if (balanceOf[msg.sender][id] < amount) revert InsufficientBalance(msg.sender, id); balanceOf[msg.sender][id] -= amount; balanceOf[receiver][id] += amount; emit Transfer(msg.sender, receiver, id, amount); + return true; } /// @notice Transfers an amount of an id from a sender to a receiver. @@ -522,34 +523,39 @@ contract ERC6909 { /// @param receiver The address of the receiver. /// @param id The id of the token. /// @param amount The amount of the token. - function transferFrom(address sender, address receiver, uint256 id, uint256 amount) public { + function transferFrom(address sender, address receiver, uint256 id, uint256 amount) public returns (bool) { if (sender != msg.sender && !isOperator[sender][msg.sender]) { - if (allowance[sender][msg.sender][id] < amount) { - revert InsufficientPermission(msg.sender, id); + uint256 senderAllowance = allowance[sender][msg.sender][id]; + if (senderAllowance < amount) revert InsufficientPermission(msg.sender, id); + if (senderAllowance != type(uint256).max) { + allowance[sender][msg.sender][id] = senderAllowance - amount; } - allowance[sender][msg.sender][id] -= amount; } if (balanceOf[sender][id] < amount) revert InsufficientBalance(sender, id); balanceOf[sender][id] -= amount; balanceOf[receiver][id] += amount; emit Transfer(sender, receiver, id, amount); + return true; } /// @notice Approves an amount of an id to a spender. /// @param spender The address of the spender. /// @param id The id of the token. /// @param amount The amount of the token. - function approve(address spender, uint256 id, uint256 amount) public { + function approve(address spender, uint256 id, uint256 amount) public returns (bool) { allowance[msg.sender][spender][id] = amount; emit Approval(msg.sender, spender, id, amount); + return true; } + /// @notice Sets or removes a spender as an operator for the caller. /// @param spender The address of the spender. /// @param approved The approval status. - function setOperator(address spender, bool approved) public { + function setOperator(address spender, bool approved) public returns (bool) { isOperator[msg.sender][spender] = approved; emit OperatorSet(msg.sender, spender, approved); + return true; } /// @notice Checks if a contract implements an interface.