Skip to content

Commit

Permalink
refactor(contracts): <- add amount field in IPReceiver receiveUserData()
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviera9 committed Mar 18, 2024
1 parent 4c48651 commit 554cb34
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion contracts/interfaces/IPReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion contracts/pToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/pTokenNoGSN.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/test-contracts/PReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ 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!");
}
}

contract NotImplementingReceiveUserDataFxn {}

contract PReceiverRevertingReturnBombing is IPReceiver {
function receiveUserData(bytes calldata) external override {
function receiveUserData(uint256, bytes calldata) external override {
assembly {
return(0, 1000000)
}
}
}

contract PReceiverRevertingReturnBombingReverting is IPReceiver {
function receiveUserData(bytes calldata) external override {
function receiveUserData(uint256, bytes calldata) external override {
assembly {
revert(0, 1000000)
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
1 change: 1 addition & 0 deletions test/05-ptoken.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down

0 comments on commit 554cb34

Please sign in to comment.