From 554cb349fdc7552713795a17172a69ab8e79f893 Mon Sep 17 00:00:00 2001 From: Alain Olivier Date: Fri, 15 Mar 2024 16:35:31 +0100 Subject: [PATCH] refactor(contracts): <- add amount field in IPReceiver receiveUserData() --- contracts/interfaces/IPReceiver.sol | 3 ++- contracts/pToken.sol | 2 +- contracts/pTokenNoGSN.sol | 2 +- contracts/test-contracts/PReceiver.sol | 12 ++++++------ package-lock.json | 4 ++-- package.json | 2 +- test/05-ptoken.test.js | 1 + 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/contracts/interfaces/IPReceiver.sol b/contracts/interfaces/IPReceiver.sol index 4cf19d6..5102a84 100644 --- a/contracts/interfaces/IPReceiver.sol +++ b/contracts/interfaces/IPReceiver.sol @@ -10,7 +10,8 @@ interface IPReceiver { /* * @dev Function called when userData.length > 0 when minting the pToken * + * @param amount * @param userData */ - function receiveUserData(bytes calldata userData) external; + function receiveUserData(uint256 amount, bytes calldata userData) external; } diff --git a/contracts/pToken.sol b/contracts/pToken.sol index 2a59eb3..5e349be 100644 --- a/contracts/pToken.sol +++ b/contracts/pToken.sol @@ -90,7 +90,7 @@ contract PToken is // This way, a user also has the option include userData even when minting to an externally owned account. // Here excessivelySafeCall executes a low-level call which does not revert the caller transaction if the callee reverts, // with the increased protection for returnbombing, i.e. the returndata copy is limited to 256 bytes. - bytes memory data = abi.encodeWithSelector(IPReceiver.receiveUserData.selector, userData); + bytes memory data = abi.encodeWithSelector(IPReceiver.receiveUserData.selector, value, userData); (bool success,) = recipient.excessivelySafeCall(gasleft() - gasReserve, 0, 0, data); if (!success) emit ReceiveUserDataFailed(); } diff --git a/contracts/pTokenNoGSN.sol b/contracts/pTokenNoGSN.sol index 679ad8f..b6ea080 100644 --- a/contracts/pTokenNoGSN.sol +++ b/contracts/pTokenNoGSN.sol @@ -93,7 +93,7 @@ contract PTokenNoGSN is // This way, a user also has the option include userData even when minting to an externally owned account. // Here excessivelySafeCall executes a low-level call which does not revert the caller transaction if the callee reverts, // with the increased protection for returnbombing, i.e. the returndata copy is limited to 256 bytes. - bytes memory data = abi.encodeWithSelector(IPReceiver.receiveUserData.selector, userData); + bytes memory data = abi.encodeWithSelector(IPReceiver.receiveUserData.selector, value, userData); (bool success,) = recipient.excessivelySafeCall(gasleft() - gasReserve, 0, 0, data); if (!success) emit ReceiveUserDataFailed(); } diff --git a/contracts/test-contracts/PReceiver.sol b/contracts/test-contracts/PReceiver.sol index cea5466..5406884 100644 --- a/contracts/test-contracts/PReceiver.sol +++ b/contracts/test-contracts/PReceiver.sol @@ -3,15 +3,15 @@ pragma solidity ^0.6.2; import {IPReceiver} from "../interfaces/IPReceiver.sol"; contract PReceiver is IPReceiver { - event UserData(bytes data); + event UserData(uint256 amount, bytes data); - function receiveUserData(bytes calldata userData) external override { - emit UserData(userData); + function receiveUserData(uint256 amount, bytes calldata userData) external override { + emit UserData(amount, userData); } } contract PReceiverReverting is IPReceiver { - function receiveUserData(bytes calldata) external override { + function receiveUserData(uint256, bytes calldata) external override { require(false, "Revert!"); } } @@ -19,7 +19,7 @@ contract PReceiverReverting is IPReceiver { contract NotImplementingReceiveUserDataFxn {} contract PReceiverRevertingReturnBombing is IPReceiver { - function receiveUserData(bytes calldata) external override { + function receiveUserData(uint256, bytes calldata) external override { assembly { return(0, 1000000) } @@ -27,7 +27,7 @@ contract PReceiverRevertingReturnBombing is IPReceiver { } contract PReceiverRevertingReturnBombingReverting is IPReceiver { - function receiveUserData(bytes calldata) external override { + function receiveUserData(uint256, bytes calldata) external override { assembly { revert(0, 1000000) } diff --git a/package-lock.json b/package-lock.json index f75185c..8a10ed4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ptokens-erc777-smart-contract", - "version": "3.12.0", + "version": "4.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ptokens-erc777-smart-contract", - "version": "3.12.0", + "version": "4.0.0", "license": "MIT", "dependencies": { "@nomiclabs/hardhat-etherscan": "3.1.0", diff --git a/package.json b/package.json index 25ac462..c3494b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ptokens-erc777-smart-contract", - "version": "3.12.0", + "version": "4.0.0", "description": "The pToken ERC777 smart-contract & CLI", "main": "cli.js", "scripts": { diff --git a/test/05-ptoken.test.js b/test/05-ptoken.test.js index 446f4b9..289e9fa 100644 --- a/test/05-ptoken.test.js +++ b/test/05-ptoken.test.js @@ -182,6 +182,7 @@ USE_GSN.map(_useGSN => assertMintEvent(events, recipientContract.address, OWNER.address, AMOUNT, data, operatorData) const userDataEvent = recipientContract.interface.parseLog(events.at(-1)) assert.strictEqual(userDataEvent.name, 'UserData') + assert.strictEqual(userDataEvent.args.amount.toNumber(), AMOUNT) assert.strictEqual(userDataEvent.args.data, data) })