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

Modify l2deposit using spender from user with permit #115

Conversation

108356037
Copy link
Contributor

@108356037 108356037 commented Nov 10, 2022

This PR modifies L2Deposit.sol & IL2Deposit.sol using spendFromUserToWithPermit.
Related test case files are also modified, run test case with the following command at project root:

export MAINNET_NODE_RPC_URL=xxxxxxxxx
DEPLOYED=false forge test -vvv --match-path "contracts/test/forkMainnet/L2Deposit/*.t.sol" --fork-url ${MAINNET_NODE_RPC_URL} --fork-block-number '15451000'

contracts/test/forkMainnet/L2Deposit/Deposit.t.sol Outdated Show resolved Hide resolved
contracts/test/forkMainnet/L2Deposit/Optimism.t.sol Outdated Show resolved Hide resolved
Comment on lines 137 to 143
_deposit.l1TokenAddr, // tokenAddr
address(l2Deposit), // requester
_deposit.sender, // user
address(l2Deposit), // recipient
_deposit.amount, // amount
getEIP712Hash(l2Deposit.EIP712_DOMAIN_SEPARATOR(), L2DepositLibEIP712._getDepositHash(DEFAULT_DEPOSIT)), // actionHash
uint64(_deposit.expiry) // expiry
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 the case where I think named parameter can help. What do you think? @pilagod @charlesjhongc

Copy link
Contributor

Choose a reason for hiding this comment

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

I forgot this is a struct initialization. @108356037 Can you test if we could use named parameter to initialize a struct (e.g., the SpendWithPermit struct)?

SpenderLibEIP712.SpendWithPermit({
    tokenAddr: _deposit.l1TokenAddr,
    requester:  address(l2Deposit),
    ...
})

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 mean like this ?:

function _createSpenderPermitFromL2Deposit(L2DepositLibEIP712.Deposit memory _deposit) internal view returns (SpenderLibEIP712.SpendWithPermit memory) {
        return
            SpenderLibEIP712.SpendWithPermit({
                tokenAddr: _deposit.l1TokenAddr,
                requester: address(l2Deposit),
                user: _deposit.sender,
                recipient: address(l2Deposit),
                amount: _deposit.amount,
                actionHash: getEIP712Hash(l2Deposit.EIP712_DOMAIN_SEPARATOR(), L2DepositLibEIP712._getDepositHash(DEFAULT_DEPOSIT)),
                expiry: uint64(_deposit.expiry)
            });
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested the code with _createSpenderPermitFromL2Deposit rewritten as above, all test case passed. 🫡

Copy link
Contributor

Choose a reason for hiding this comment

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

Yap! This is awesome. I would like to proceed with named parameter. Let's wait for the comment from @pilagod and @charlesjhongc

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think named params should be better.

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modify to named parameters in several places:
7b4392e

Copy link
Contributor

@charlesjhongc charlesjhongc left a comment

Choose a reason for hiding this comment

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

I think this PR is mature enough and only some minors are left. But should be waiting for #114 get merged and rebase on it.

Comment on lines 137 to 143
_deposit.l1TokenAddr, // tokenAddr
address(l2Deposit), // requester
_deposit.sender, // user
address(l2Deposit), // recipient
_deposit.amount, // amount
getEIP712Hash(l2Deposit.EIP712_DOMAIN_SEPARATOR(), L2DepositLibEIP712._getDepositHash(DEFAULT_DEPOSIT)), // actionHash
uint64(_deposit.expiry) // expiry
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think named params should be better.

contracts/test/forkMainnet/L2Deposit/Setup.t.sol Outdated Show resolved Hide resolved
@pilagod
Copy link
Contributor

pilagod commented Nov 14, 2022

The #114 had been merged. We could start to do the sign permit refinement 💪

@108356037
Copy link
Contributor Author

108356037 commented Nov 14, 2022

The #114 had been merged. We could start to do the sign permit refinement 💪

Modified the test cases using signSpendWithPermit() from contracts-test/utils/Permit.sol 🫡

@108356037 108356037 merged commit 4aa11d0 into spender_permit_feature Nov 14, 2022
@108356037 108356037 deleted the modify-l2deposit-using-spenderFromUserWithPermit branch November 14, 2022 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants