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

Sponsor payment #326

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Sponsor payment #326

wants to merge 8 commits into from

Conversation

Kolezhniuk
Copy link
Contributor

@Kolezhniuk Kolezhniuk commented Dec 23, 2024

Some details:

  • Sponsor deposits coins/tokens
  • Sponsor creates eip-712 signature to allow the recipient to withdraw money
  • Recipient could withdraw money until expiration time passed
  • Sponsor can withdraw tokens/coins back but after withdrawal delay period
  • Recipient claims payment with fee that is specified by contract owner
  • Owner could transfer coins/tokens to his address

@Kolezhniuk Kolezhniuk marked this pull request as ready for review December 23, 2024 07:50
* Supports Ether and ERC-20 token payments with enhanced security feature$.
* @custom:storage-location erc7201:iden3.storage.SponsorPayment
*/
contract SponsorPayment is ReentrancyGuardUpgradeable, EIP712Upgradeable, Ownable2StepUpgradeable {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to prevent nonReentrant attack

Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

struct SponsorPaymentStorage {
mapping(address => mapping(address => uint256)) balances; // sponsor => token => balance
mapping(address => mapping(address => WithdrawalRequest)) withdrawalRequests; // sponsor => token => request
mapping(bytes32 => bool) isWithdrawn;
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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 ?

Copy link
Contributor Author

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

* @param addr Address to check
*/
function _isContract(address addr) private view returns (bool) {
uint256 size;
Copy link
Contributor

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)

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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

emit ERC20Withdrawal(_msgSender(), token, amount);
}

function _claimPayment(
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

@coveralls
Copy link

coveralls commented Dec 23, 2024

Pull Request Test Coverage Report for Build 12479322610

Details

  • 108 of 118 (91.53%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.6%) to 83.447%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contracts/payment/SponsorPayment.sol 108 118 91.53%
Totals Coverage Status
Change from base Build 12413543528: -0.6%
Covered Lines: 1126
Relevant Lines: 1255

💛 - Coveralls

0x98fc76e32452055302f77aa95cd08aa0cf22c02a3ebdaee3e1411f6c47c2ef00;

modifier validToken(address token) {
if (token != address(0)) {
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants