From 2238f150ddc85f15e462e42ea75344b1cfdf7329 Mon Sep 17 00:00:00 2001 From: PacificYield <173040337+PacificYield@users.noreply.github.com> Date: Fri, 29 Nov 2024 10:41:37 +0100 Subject: [PATCH] docs: updates NatSpec EncryptedERC20WithErrors.sol --- .../extensions/EncryptedERC20WithErrors.sol | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/contracts/token/ERC20/extensions/EncryptedERC20WithErrors.sol b/contracts/token/ERC20/extensions/EncryptedERC20WithErrors.sol index d52933f..6902178 100644 --- a/contracts/token/ERC20/extensions/EncryptedERC20WithErrors.sol +++ b/contracts/token/ERC20/extensions/EncryptedERC20WithErrors.sol @@ -30,8 +30,8 @@ abstract contract EncryptedERC20WithErrors is EncryptedERC20, EncryptedErrors { } /** - * @param name_ Name of the token. - * @param symbol_ Symbol. + * @param name_ Name of the token. + * @param symbol_ Symbol. */ constructor( string memory name_, @@ -43,7 +43,7 @@ abstract contract EncryptedERC20WithErrors is EncryptedERC20, EncryptedErrors { */ function transfer(address to, euint64 amount) public virtual override returns (bool) { _isSenderAllowedForAmount(amount); - /// Check whether the owner has enough tokens. + /// @dev Check whether the owner has enough tokens. ebool canTransfer = TFHE.le(amount, _balances[msg.sender]); euint8 errorCode = _errorDefineIfNot(canTransfer, uint8(ErrorCodes.UNSUFFICIENT_BALANCE)); _errorSave(errorCode); @@ -53,15 +53,6 @@ abstract contract EncryptedERC20WithErrors is EncryptedERC20, EncryptedErrors { return true; } - function getErrorCodeForTransferId(uint256 transferId) public view virtual returns (euint8) { - return _errorGetCodeEmitted(transferId); - } - - function _transfer(address from, address to, euint64 amount, ebool isTransferable) internal override { - _transferNoEvent(from, to, amount, isTransferable); - emit Transfer(from, to, _errorGetCounter() - 1); - } - /** * @notice See {IEncryptedERC20-transferFrom}. */ @@ -73,21 +64,37 @@ abstract contract EncryptedERC20WithErrors is EncryptedERC20, EncryptedErrors { return true; } + /** + * @notice Returns the error for a transfer id. + * @param transferId Transfer id. It can read from the `Transfer` event. + * @return errorCode Encrypted error code. + */ + function getErrorCodeForTransferId(uint256 transferId) public view virtual returns (euint8 errorCode) { + errorCode = _errorGetCodeEmitted(transferId); + } + + function _transfer(address from, address to, euint64 amount, ebool isTransferable) internal override { + _transferNoEvent(from, to, amount, isTransferable); + /// @dev It was incremented in _saveError. + emit Transfer(from, to, _errorGetCounter() - 1); + } + function _updateAllowance( address owner, address spender, euint64 amount ) internal virtual override returns (ebool isTransferable) { euint64 currentAllowance = _allowance(owner, spender); - /// Make sure sure the allowance suffices. + /// @dev It checks whether the allowance suffices. ebool allowedTransfer = TFHE.le(amount, currentAllowance); euint8 errorCode = _errorDefineIfNot(allowedTransfer, uint8(ErrorCodes.UNSUFFICIENT_APPROVAL)); - /// Make sure the owner has enough tokens. + /// @dev It checks that the owner has enough tokens. ebool canTransfer = TFHE.le(amount, _balances[owner]); ebool isNotTransferableButIsApproved = TFHE.and(TFHE.not(canTransfer), allowedTransfer); errorCode = _errorChangeIf( - isNotTransferableButIsApproved, // should indeed check that spender is approved to not leak information - // on balance of `from` to unauthorized spender via calling reencryptTransferError afterwards + isNotTransferableButIsApproved, + /// @dev Should indeed check that spender is approved to not leak information. + /// on balance of `from` to unauthorized spender via calling reencryptTransferError afterwards. uint8(ErrorCodes.UNSUFFICIENT_BALANCE), errorCode );