diff --git a/.changeset/pink-areas-double.md b/.changeset/pink-areas-double.md new file mode 100644 index 00000000..d77d9d3e --- /dev/null +++ b/.changeset/pink-areas-double.md @@ -0,0 +1,5 @@ +--- +'openzeppelin-confidential-contracts': minor +--- + +`ERC7984ERC20Wrapper`: return the amount of wrapped token sent on wrap calls. diff --git a/contracts/interfaces/IERC7984ERC20Wrapper.sol b/contracts/interfaces/IERC7984ERC20Wrapper.sol index 3c49d6d0..73c02b51 100644 --- a/contracts/interfaces/IERC7984ERC20Wrapper.sol +++ b/contracts/interfaces/IERC7984ERC20Wrapper.sol @@ -7,8 +7,12 @@ import {IERC7984} from "./IERC7984.sol"; /// @dev Interface for ERC7984ERC20Wrapper contract. interface IERC7984ERC20Wrapper is IERC7984 { - /// @dev Wraps `amount` of the underlying token into a confidential token and sends it to `to`. - function wrap(address to, uint256 amount) external; + /** + * @dev Wraps `amount` of the underlying token into a confidential token and sends it to `to`. + * + * Returns amount of wrapped token sent. + */ + function wrap(address to, uint256 amount) external returns (euint64); /** * @dev Unwraps tokens from `from` and sends the underlying tokens to `to`. The caller must be `from` diff --git a/contracts/token/ERC7984/extensions/ERC7984ERC20Wrapper.sol b/contracts/token/ERC7984/extensions/ERC7984ERC20Wrapper.sol index 1737f59b..c2fd3647 100644 --- a/contracts/token/ERC7984/extensions/ERC7984ERC20Wrapper.sol +++ b/contracts/token/ERC7984/extensions/ERC7984ERC20Wrapper.sol @@ -79,13 +79,18 @@ abstract contract ERC7984ERC20Wrapper is ERC7984, IERC7984ERC20Wrapper, IERC1363 * @dev See {IERC7984ERC20Wrapper-wrap}. Tokens are exchanged at a fixed rate specified by {rate} such that * `amount / rate()` confidential tokens are sent. The amount transferred in is rounded down to the nearest * multiple of {rate}. + * + * Returns the amount of wrapped token sent. */ - function wrap(address to, uint256 amount) public virtual override { + function wrap(address to, uint256 amount) public virtual override returns (euint64) { // take ownership of the tokens SafeERC20.safeTransferFrom(IERC20(underlying()), msg.sender, address(this), amount - (amount % rate())); // mint confidential token - _mint(to, FHE.asEuint64(SafeCast.toUint64(amount / rate()))); + euint64 wrappedAmountSent = _mint(to, FHE.asEuint64(SafeCast.toUint64(amount / rate()))); + FHE.allowTransient(wrappedAmountSent, msg.sender); + + return wrappedAmountSent; } /// @dev Unwrap without passing an input proof. See {unwrap-address-address-bytes32-bytes} for more details.