From a8e061a1663f38e322335e08e71c1f20f8be42f5 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 8 Aug 2024 00:25:48 +0300 Subject: [PATCH] Update METADEPOSIT_TYPEHASH (#44) * Update METADEPOSIT_TYPEHASH * cleanup of MetaDepositParams --- .../static-a-token/StaticATokenLM.sol | 5 +- .../interfaces/IStaticATokenLM.sol | 2 - .../StaticATokenMetaTransactions.t.sol | 93 +++++++++---------- tests/utils/SigUtils.sol | 38 ++++---- 4 files changed, 63 insertions(+), 75 deletions(-) diff --git a/src/periphery/contracts/static-a-token/StaticATokenLM.sol b/src/periphery/contracts/static-a-token/StaticATokenLM.sol index a1e5b7f0..508d5a2e 100644 --- a/src/periphery/contracts/static-a-token/StaticATokenLM.sol +++ b/src/periphery/contracts/static-a-token/StaticATokenLM.sol @@ -42,7 +42,7 @@ contract StaticATokenLM is bytes32 public constant METADEPOSIT_TYPEHASH = keccak256( - 'Deposit(address depositor,address receiver,uint256 assets,uint16 referralCode,bool depositToAave,uint256 nonce,uint256 deadline,PermitParams permit)' + 'Deposit(address depositor,address receiver,uint256 assets,uint16 referralCode,bool depositToAave,uint256 nonce,uint256 deadline)' ); bytes32 public constant METAWITHDRAWAL_TYPEHASH = keccak256( @@ -149,8 +149,7 @@ contract StaticATokenLM is referralCode, depositToAave, nonce, - deadline, - permit + deadline ) ) ) diff --git a/src/periphery/contracts/static-a-token/interfaces/IStaticATokenLM.sol b/src/periphery/contracts/static-a-token/interfaces/IStaticATokenLM.sol index b36c328b..a5afeace 100644 --- a/src/periphery/contracts/static-a-token/interfaces/IStaticATokenLM.sol +++ b/src/periphery/contracts/static-a-token/interfaces/IStaticATokenLM.sol @@ -13,8 +13,6 @@ interface IStaticATokenLM is IInitializableStaticATokenLM, IERC4626 { } struct PermitParams { - address owner; - address spender; uint256 value; uint256 deadline; uint8 v; diff --git a/tests/periphery/static-a-token/StaticATokenMetaTransactions.t.sol b/tests/periphery/static-a-token/StaticATokenMetaTransactions.t.sol index 62dd690a..dc8c68d2 100644 --- a/tests/periphery/static-a-token/StaticATokenMetaTransactions.t.sol +++ b/tests/periphery/static-a-token/StaticATokenMetaTransactions.t.sol @@ -43,18 +43,17 @@ contract StaticATokenMetaTransactions is BaseTest { IStaticATokenLM.PermitParams memory permitParams; // generate combined permit - SigUtils.DepositPermit memory depositPermit = SigUtils.DepositPermit({ - owner: user, - spender: spender, - value: 1e6, + SigUtils.MetaDepositParams memory metaDepositParams = SigUtils.MetaDepositParams({ + depositor: user, + receiver: spender, + assets: 1e6, referralCode: 0, fromUnderlying: true, nonce: staticATokenLM.nonces(user), - deadline: block.timestamp + 1 days, - permit: permitParams + deadline: block.timestamp + 1 days }); bytes32 digest = SigUtils.getTypedDepositHash( - depositPermit, + metaDepositParams, staticATokenLM.METADEPOSIT_TYPEHASH(), staticATokenLM.DOMAIN_SEPARATOR() ); @@ -62,19 +61,19 @@ contract StaticATokenMetaTransactions is BaseTest { IStaticATokenLM.SignatureParams memory sigParams = IStaticATokenLM.SignatureParams(v, r, s); - uint256 previewDeposit = staticATokenLM.previewDeposit(depositPermit.value); + uint256 previewDeposit = staticATokenLM.previewDeposit(metaDepositParams.assets); staticATokenLM.metaDeposit( - depositPermit.owner, - depositPermit.spender, - depositPermit.value, - depositPermit.referralCode, - depositPermit.fromUnderlying, - depositPermit.deadline, + metaDepositParams.depositor, + metaDepositParams.receiver, + metaDepositParams.assets, + metaDepositParams.referralCode, + metaDepositParams.fromUnderlying, + metaDepositParams.deadline, permitParams, sigParams ); - assertEq(staticATokenLM.balanceOf(depositPermit.spender), previewDeposit); + assertEq(staticATokenLM.balanceOf(metaDepositParams.receiver), previewDeposit); } function test_metaDepositATokenUnderlying() public { @@ -99,8 +98,6 @@ contract StaticATokenMetaTransactions is BaseTest { (uint8 pV, bytes32 pR, bytes32 pS) = vm.sign(userPrivateKey, permitDigest); IStaticATokenLM.PermitParams memory permitParams = IStaticATokenLM.PermitParams( - permit.owner, - permit.spender, permit.value, permit.deadline, pV, @@ -109,20 +106,19 @@ contract StaticATokenMetaTransactions is BaseTest { ); // generate combined permit - SigUtils.DepositPermit memory depositPermit = SigUtils.DepositPermit({ - owner: user, - spender: spender, - value: permit.value, + SigUtils.MetaDepositParams memory metaDepositParams = SigUtils.MetaDepositParams({ + depositor: user, + receiver: spender, + assets: permit.value, referralCode: 0, fromUnderlying: true, nonce: staticATokenLM.nonces(user), - deadline: permit.deadline, - permit: permitParams + deadline: permit.deadline }); (uint8 v, bytes32 r, bytes32 s) = vm.sign( userPrivateKey, SigUtils.getTypedDepositHash( - depositPermit, + metaDepositParams, staticATokenLM.METADEPOSIT_TYPEHASH(), staticATokenLM.DOMAIN_SEPARATOR() ) @@ -130,19 +126,19 @@ contract StaticATokenMetaTransactions is BaseTest { IStaticATokenLM.SignatureParams memory sigParams = IStaticATokenLM.SignatureParams(v, r, s); - uint256 previewDeposit = staticATokenLM.previewDeposit(depositPermit.value); + uint256 previewDeposit = staticATokenLM.previewDeposit(metaDepositParams.assets); uint256 shares = staticATokenLM.metaDeposit( - depositPermit.owner, - depositPermit.spender, - depositPermit.value, - depositPermit.referralCode, - depositPermit.fromUnderlying, - depositPermit.deadline, + metaDepositParams.depositor, + metaDepositParams.receiver, + metaDepositParams.assets, + metaDepositParams.referralCode, + metaDepositParams.fromUnderlying, + metaDepositParams.deadline, permitParams, sigParams ); assertEq(shares, previewDeposit); - assertEq(staticATokenLM.balanceOf(depositPermit.spender), previewDeposit); + assertEq(staticATokenLM.balanceOf(metaDepositParams.receiver), previewDeposit); } function test_metaDepositAToken() public { @@ -168,8 +164,6 @@ contract StaticATokenMetaTransactions is BaseTest { (uint8 pV, bytes32 pR, bytes32 pS) = vm.sign(userPrivateKey, permitDigest); IStaticATokenLM.PermitParams memory permitParams = IStaticATokenLM.PermitParams( - permit.owner, - permit.spender, permit.value, permit.deadline, pV, @@ -178,18 +172,17 @@ contract StaticATokenMetaTransactions is BaseTest { ); // generate combined permit - SigUtils.DepositPermit memory depositPermit = SigUtils.DepositPermit({ - owner: user, - spender: spender, - value: permit.value, + SigUtils.MetaDepositParams memory metaDepositParams = SigUtils.MetaDepositParams({ + depositor: user, + receiver: spender, + assets: permit.value, referralCode: 0, fromUnderlying: false, nonce: staticATokenLM.nonces(user), - deadline: permit.deadline, - permit: permitParams + deadline: permit.deadline }); bytes32 digest = SigUtils.getTypedDepositHash( - depositPermit, + metaDepositParams, staticATokenLM.METADEPOSIT_TYPEHASH(), staticATokenLM.DOMAIN_SEPARATOR() ); @@ -197,20 +190,20 @@ contract StaticATokenMetaTransactions is BaseTest { IStaticATokenLM.SignatureParams memory sigParams = IStaticATokenLM.SignatureParams(v, r, s); - uint256 previewDeposit = staticATokenLM.previewDeposit(depositPermit.value); + uint256 previewDeposit = staticATokenLM.previewDeposit(metaDepositParams.assets); staticATokenLM.metaDeposit( - depositPermit.owner, - depositPermit.spender, - depositPermit.value, - depositPermit.referralCode, - depositPermit.fromUnderlying, - depositPermit.deadline, + metaDepositParams.depositor, + metaDepositParams.receiver, + metaDepositParams.assets, + metaDepositParams.referralCode, + metaDepositParams.fromUnderlying, + metaDepositParams.deadline, permitParams, sigParams ); - assertEq(staticATokenLM.balanceOf(depositPermit.spender), previewDeposit); + assertEq(staticATokenLM.balanceOf(metaDepositParams.receiver), previewDeposit); } function test_metaWithdraw() public { @@ -219,7 +212,7 @@ contract StaticATokenMetaTransactions is BaseTest { _depositAToken(amountToDeposit, user); - SigUtils.WithdrawPermit memory permit = SigUtils.WithdrawPermit({ + SigUtils.MetaWithdrawParams memory permit = SigUtils.MetaWithdrawParams({ owner: user, spender: spender, staticAmount: 0, diff --git a/tests/utils/SigUtils.sol b/tests/utils/SigUtils.sol index 8c64e400..311a256d 100644 --- a/tests/utils/SigUtils.sol +++ b/tests/utils/SigUtils.sol @@ -12,7 +12,7 @@ library SigUtils { uint256 deadline; } - struct WithdrawPermit { + struct MetaWithdrawParams { address owner; address spender; uint256 staticAmount; @@ -22,15 +22,14 @@ library SigUtils { uint256 deadline; } - struct DepositPermit { - address owner; - address spender; - uint256 value; + struct MetaDepositParams { + address depositor; + address receiver; + uint256 assets; uint16 referralCode; bool fromUnderlying; uint256 nonce; uint256 deadline; - IStaticATokenLM.PermitParams permit; } // computes the hash of a permit @@ -49,7 +48,7 @@ library SigUtils { } function getWithdrawHash( - WithdrawPermit memory permit, + MetaWithdrawParams memory permit, bytes32 typehash ) internal pure returns (bytes32) { return @@ -68,21 +67,20 @@ library SigUtils { } function getDepositHash( - DepositPermit memory permit, + MetaDepositParams memory params, bytes32 typehash ) internal pure returns (bytes32) { return keccak256( abi.encode( typehash, - permit.owner, - permit.spender, - permit.value, - permit.referralCode, - permit.fromUnderlying, - permit.nonce, - permit.deadline, - permit.permit + params.depositor, + params.receiver, + params.assets, + params.referralCode, + params.fromUnderlying, + params.nonce, + params.deadline ) ); } @@ -98,20 +96,20 @@ library SigUtils { } function getTypedWithdrawHash( - WithdrawPermit memory permit, + MetaWithdrawParams memory params, bytes32 typehash, bytes32 domainSeparator ) public pure returns (bytes32) { return - keccak256(abi.encodePacked('\x19\x01', domainSeparator, getWithdrawHash(permit, typehash))); + keccak256(abi.encodePacked('\x19\x01', domainSeparator, getWithdrawHash(params, typehash))); } function getTypedDepositHash( - DepositPermit memory permit, + MetaDepositParams memory params, bytes32 typehash, bytes32 domainSeparator ) public pure returns (bytes32) { return - keccak256(abi.encodePacked('\x19\x01', domainSeparator, getDepositHash(permit, typehash))); + keccak256(abi.encodePacked('\x19\x01', domainSeparator, getDepositHash(params, typehash))); } }