Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(contracts): <- add amount field in IPReceiver receiveUserData() #3

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

"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
Loading