-
Notifications
You must be signed in to change notification settings - Fork 24
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
Sponsor payment #326
base: master
Are you sure you want to change the base?
Sponsor payment #326
Conversation
* Supports Ether and ERC-20 token payments with enhanced security feature$. | ||
* @custom:storage-location erc7201:iden3.storage.SponsorPayment | ||
*/ | ||
contract SponsorPayment is ReentrancyGuardUpgradeable, EIP712Upgradeable, Ownable2StepUpgradeable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is a motivation to use nonReentrant functionality in this contract?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to prevent nonReentrant attack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is only protection from internal calls,no?
/** | ||
* @dev Payment details used in claim logic. | ||
*/ | ||
struct ERC20SponsorPaymentInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
honestly I don't like the word Sponsor in the context of prepaid verificactions. Open discussion @demonsh @Kolezhniuk @AndriianChestnykh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vmidyllic What is your suggestion?
if (withdrawalDelay == 0) revert InvalidParameter("Invalid withdrawal delay"); | ||
SponsorPaymentStorage storage $ = _getSponsorPaymentStorage(); | ||
$.ownerPercentage = ownerPercentage; | ||
$.withdrawalDelay = withdrawalDelay; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is withdrawalDelay corresponds to all 'payments' or acts as a general configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't get your question yes it acts as a general configuration, so withdrawalDelay corresponds to all 'payments'
* Supports Ether and ERC-20 token payments with enhanced security feature$. | ||
* @custom:storage-location erc7201:iden3.storage.SponsorPayment | ||
*/ | ||
contract SponsorPayment is ReentrancyGuardUpgradeable, EIP712Upgradeable, Ownable2StepUpgradeable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to ask @AndriianChestnykh if we inherit different upgradeable contracts and they are all Initializable ( have the same storage location), will be that a problem for upgrade?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there should be no problem for upgrades.
contracts/payment/SponsorPayment.sol
Outdated
struct SponsorPaymentStorage { | ||
mapping(address => mapping(address => uint256)) balances; // sponsor => token => balance | ||
mapping(address => mapping(address => WithdrawalRequest)) withdrawalRequests; // sponsor => token => request | ||
mapping(bytes32 => bool) isWithdrawn; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not clear what is bytes32 without any comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
$.withdrawalDelay = withdrawalDelay; | ||
__ReentrancyGuard_init(); | ||
__EIP712_init("SponsorPayment", VERSION); | ||
__Ownable_init(owner); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not it be __Ownable2Step_init ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, maybe @AndriianChestnykh could help here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__Ownable2Step_init
is an empty function. __Ownable_init
looks correct for owner setup.
contracts/payment/SponsorPayment.sol
Outdated
* @param addr Address to check | ||
*/ | ||
function _isContract(address addr) private view returns (bool) { | ||
uint256 size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is the same check target.code.length > 0 (you can test)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced this check
SponsorPaymentStorage storage $ = _getSponsorPaymentStorage(); | ||
|
||
if (msg.value == 0) revert InvalidDeposit("Invalid value amount"); | ||
$.balances[_msgSender()][address(0)] += msg.value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we deposit to 0 address for native token?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm store native coin deposit per specific sponsor under address(0)
Any objection or suggestions?
function depositERC20(uint256 amount, address token) external nonReentrant validToken(token) { | ||
SponsorPaymentStorage storage $ = _getSponsorPaymentStorage(); | ||
if (amount == 0) revert InvalidDeposit("Invalid token amount"); | ||
IERC20(token).safeTransferFrom(_msgSender(), address(this), amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is allowance in token contract is given sepatelly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can see the interaction with SC by reviewing unit tests
contracts/payment/SponsorPayment.sol
Outdated
emit ERC20Withdrawal(_msgSender(), token, amount); | ||
} | ||
|
||
function _claimPayment( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method name confuses me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please suggest the name that don't make you confuse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussion in the separate thread. I'm against of the usage the word 'claim' to avoid missunderstanding.
Pull Request Test Coverage Report for Build 12584161757Details
💛 - Coveralls |
contracts/payment/SponsorPayment.sol
Outdated
0x98fc76e32452055302f77aa95cd08aa0cf22c02a3ebdaee3e1411f6c47c2ef00; | ||
|
||
modifier validToken(address token) { | ||
if (token != address(0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if token == address(0) - it is valid ?
based on the modifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
token == address(0) || token.code.length == 0
-> then revert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
* Supports Ether and ERC-20 token payments with enhanced security feature$. | ||
* @custom:storage-location erc7201:iden3.storage.SponsorPayment | ||
*/ | ||
contract SponsorPayment is ReentrancyGuardUpgradeable, EIP712Upgradeable, Ownable2StepUpgradeable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there should be no problem for upgrades.
contracts/payment/SponsorPayment.sol
Outdated
} | ||
|
||
/** | ||
* @dev Main storage $tructure for the contract |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
structure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
contracts/payment/SponsorPayment.sol
Outdated
* @dev Main storage $tructure for the contract | ||
*/ | ||
struct SponsorPaymentStorage { | ||
mapping(address => mapping(address => uint256)) balances; // sponsor => token => balance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better use kind of "inline comments" for mappings mapping(address sponsor => mapping(address token => uint256 balance))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
$.withdrawalDelay = withdrawalDelay; | ||
__ReentrancyGuard_init(); | ||
__EIP712_init("SponsorPayment", VERSION); | ||
__Ownable_init(owner); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__Ownable2Step_init
is an empty function. __Ownable_init
looks correct for owner setup.
contracts/payment/SponsorPayment.sol
Outdated
"ERC20SponsorPaymentInfo(address recipient,uint256 amount,address token,uint256 expiration,uint256 nonce,bytes metadata)" | ||
); | ||
|
||
bytes32 public constant PAYMENT_CLAIM_DATA_TYPE_HASH = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just SPONSOR_PAYMENT_INFO_TYPE_HASH for name consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
contracts/payment/SponsorPayment.sol
Outdated
$.ownerPercentFee = ownerPercentFee; | ||
} | ||
|
||
function _tryRecoverSigner( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put all private and internal methods after public methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contracts/payment/SponsorPayment.sol
Outdated
struct WithdrawalRequest { | ||
uint256 amount; | ||
uint256 lockTime; | ||
bool exists; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can amount > 0 indicate that request exists to same 1 storage slot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, refactored
contracts/payment/SponsorPayment.sol
Outdated
|
||
function _getWithdrawalAmount(address token) private view returns (uint256) { | ||
SponsorPaymentStorage storage $ = _getSponsorPaymentStorage(); | ||
WithdrawalRequest memory request = $.withdrawalRequests[_msgSender()][token]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storage
but not memory
data allocation in such cases saves some gas.
Some details: