mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
fix: Remove chainId from input params, retrieve from assembly instead
This commit is contained in:
parent
8a253fc0ac
commit
290ba077f5
|
@ -150,7 +150,6 @@ contract StaticATokenLM is ERC20 {
|
|||
* @param v Signature param
|
||||
* @param s Signature param
|
||||
* @param r Signature param
|
||||
* @param chainId Passing the chainId in order to be fork-compatible
|
||||
*/
|
||||
function permit(
|
||||
address owner,
|
||||
|
@ -159,8 +158,7 @@ contract StaticATokenLM is ERC20 {
|
|||
uint256 deadline,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s,
|
||||
uint256 chainId
|
||||
bytes32 s
|
||||
) external {
|
||||
require(owner != address(0), StaticATokenErrors.INVALID_OWNER);
|
||||
//solium-disable-next-line
|
||||
|
@ -170,7 +168,7 @@ contract StaticATokenLM is ERC20 {
|
|||
keccak256(
|
||||
abi.encodePacked(
|
||||
'\x19\x01',
|
||||
getDomainSeparator(chainId),
|
||||
getDomainSeparator(),
|
||||
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, currentValidNonce, deadline))
|
||||
)
|
||||
);
|
||||
|
@ -192,7 +190,6 @@ contract StaticATokenLM is ERC20 {
|
|||
* - `false` if the msg.sender comes already with aTokens (e.g. aUSDC)
|
||||
* @param deadline The deadline timestamp, type(uint256).max for max deadline
|
||||
* @param sigParams Signature params: v,r,s
|
||||
* @param chainId Passing the chainId in order to be fork-compatible
|
||||
* @return uint256 The amount of StaticAToken minted, static balance
|
||||
*/
|
||||
function metaDeposit(
|
||||
|
@ -202,8 +199,7 @@ contract StaticATokenLM is ERC20 {
|
|||
uint16 referralCode,
|
||||
bool fromUnderlying,
|
||||
uint256 deadline,
|
||||
SignatureParams calldata sigParams,
|
||||
uint256 chainId
|
||||
SignatureParams calldata sigParams
|
||||
) external returns (uint256) {
|
||||
require(depositor != address(0), StaticATokenErrors.INVALID_DEPOSITOR);
|
||||
//solium-disable-next-line
|
||||
|
@ -213,7 +209,7 @@ contract StaticATokenLM is ERC20 {
|
|||
keccak256(
|
||||
abi.encodePacked(
|
||||
'\x19\x01',
|
||||
getDomainSeparator(chainId),
|
||||
getDomainSeparator(),
|
||||
keccak256(
|
||||
abi.encode(
|
||||
METADEPOSIT_TYPEHASH,
|
||||
|
@ -248,7 +244,6 @@ contract StaticATokenLM is ERC20 {
|
|||
* - `false` for the recipient to get aTokens (e.g. aUSDC)
|
||||
* @param deadline The deadline timestamp, type(uint256).max for max deadline
|
||||
* @param sigParams Signature params: v,r,s
|
||||
* @param chainId Passing the chainId in order to be fork-compatible
|
||||
* @return amountToBurn: StaticATokens burnt, static balance
|
||||
* @return amountToWithdraw: underlying/aToken send to `recipient`, dynamic balance
|
||||
*/
|
||||
|
@ -259,8 +254,7 @@ contract StaticATokenLM is ERC20 {
|
|||
uint256 dynamicAmount,
|
||||
bool toUnderlying,
|
||||
uint256 deadline,
|
||||
SignatureParams calldata sigParams,
|
||||
uint256 chainId
|
||||
SignatureParams calldata sigParams
|
||||
) external returns (uint256, uint256) {
|
||||
require(owner != address(0), StaticATokenErrors.INVALID_OWNER);
|
||||
//solium-disable-next-line
|
||||
|
@ -270,7 +264,7 @@ contract StaticATokenLM is ERC20 {
|
|||
keccak256(
|
||||
abi.encodePacked(
|
||||
'\x19\x01',
|
||||
getDomainSeparator(chainId),
|
||||
getDomainSeparator(),
|
||||
keccak256(
|
||||
abi.encode(
|
||||
METAWITHDRAWAL_TYPEHASH,
|
||||
|
@ -334,10 +328,13 @@ contract StaticATokenLM is ERC20 {
|
|||
|
||||
/**
|
||||
* @dev Function to return a dynamic domain separator, in order to be compatible with forks changing chainId
|
||||
* @param chainId The chain id
|
||||
* @return bytes32 The domain separator
|
||||
**/
|
||||
function getDomainSeparator(uint256 chainId) public view returns (bytes32) {
|
||||
function getDomainSeparator() public view returns (bytes32) {
|
||||
uint256 chainId;
|
||||
assembly {
|
||||
chainId := chainid()
|
||||
}
|
||||
return
|
||||
keccak256(
|
||||
abi.encode(
|
||||
|
|
|
@ -538,13 +538,13 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
await expect(
|
||||
staticAToken
|
||||
.connect(spender)
|
||||
.permit(spender._address, spender._address, permitAmount, expiration, v, r, s, chainId)
|
||||
.permit(spender._address, spender._address, permitAmount, expiration, v, r, s)
|
||||
).to.be.revertedWith(LM_ERRORS.INVALID_SIGNATURE);
|
||||
|
||||
await waitForTx(
|
||||
await staticAToken
|
||||
.connect(spender)
|
||||
.permit(owner._address, spender._address, permitAmount, expiration, v, r, s, chainId)
|
||||
.permit(owner._address, spender._address, permitAmount, expiration, v, r, s)
|
||||
);
|
||||
|
||||
expect((await staticAToken.allowance(owner._address, spender._address)).toString()).to.be.equal(
|
||||
|
@ -616,13 +616,13 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
await expect(
|
||||
staticAToken
|
||||
.connect(spender)
|
||||
.permit(ZERO_ADDRESS, spender._address, permitAmount, expiration, v, r, s, chainId)
|
||||
.permit(ZERO_ADDRESS, spender._address, permitAmount, expiration, v, r, s)
|
||||
).to.be.revertedWith(LM_ERRORS.INVALID_OWNER);
|
||||
|
||||
await expect(
|
||||
staticAToken
|
||||
.connect(spender)
|
||||
.permit(owner._address, spender._address, permitAmount, expiration, v, r, s, chainId)
|
||||
.permit(owner._address, spender._address, permitAmount, expiration, v, r, s)
|
||||
).to.be.revertedWith(LM_ERRORS.INVALID_EXPIRATION);
|
||||
|
||||
expect((await staticAToken.allowance(owner._address, spender._address)).toString()).to.be.equal(
|
||||
|
@ -642,7 +642,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
verifyingContract: staticAToken.address,
|
||||
};
|
||||
const domainSeperator = _TypedDataEncoder.hashDomain(domain);
|
||||
const seperator = await staticAToken.getDomainSeparator(chainId);
|
||||
const seperator = await staticAToken.getDomainSeparator();
|
||||
expect(seperator).to.be.eq(domainSeperator);
|
||||
|
||||
const userPrivateKey = require('../../../../test-wallets.js').accounts[0].secretKey;
|
||||
|
@ -697,24 +697,14 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
referralCode,
|
||||
fromUnderlying,
|
||||
deadline,
|
||||
sigParams,
|
||||
chainId
|
||||
sigParams
|
||||
)
|
||||
).to.be.revertedWith(LM_ERRORS.INVALID_DEPOSITOR);
|
||||
|
||||
await expect(
|
||||
staticAToken
|
||||
.connect(user2Signer)
|
||||
.metaDeposit(
|
||||
depositor,
|
||||
recipient,
|
||||
value,
|
||||
referralCode,
|
||||
fromUnderlying,
|
||||
0,
|
||||
sigParams,
|
||||
chainId
|
||||
)
|
||||
.metaDeposit(depositor, recipient, value, referralCode, fromUnderlying, 0, sigParams)
|
||||
).to.be.revertedWith(LM_ERRORS.INVALID_EXPIRATION);
|
||||
|
||||
await expect(
|
||||
|
@ -727,8 +717,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
referralCode,
|
||||
fromUnderlying,
|
||||
deadline,
|
||||
sigParams,
|
||||
chainId
|
||||
sigParams
|
||||
)
|
||||
).to.be.revertedWith(LM_ERRORS.INVALID_SIGNATURE);
|
||||
|
||||
|
@ -736,16 +725,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
await waitForTx(
|
||||
await staticAToken
|
||||
.connect(user2Signer)
|
||||
.metaDeposit(
|
||||
depositor,
|
||||
recipient,
|
||||
value,
|
||||
referralCode,
|
||||
fromUnderlying,
|
||||
deadline,
|
||||
sigParams,
|
||||
chainId
|
||||
)
|
||||
.metaDeposit(depositor, recipient, value, referralCode, fromUnderlying, deadline, sigParams)
|
||||
);
|
||||
|
||||
const ctxtAfterDeposit = await getContext(ctxtParams);
|
||||
|
@ -810,7 +790,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
verifyingContract: staticAToken.address,
|
||||
};
|
||||
const domainSeperator = _TypedDataEncoder.hashDomain(domain);
|
||||
const seperator = await staticAToken.getDomainSeparator(chainId);
|
||||
const seperator = await staticAToken.getDomainSeparator();
|
||||
expect(seperator).to.be.eq(domainSeperator);
|
||||
|
||||
const userPrivateKey = require('../../../../test-wallets.js').accounts[0].secretKey;
|
||||
|
@ -871,24 +851,14 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
dynamicAmount,
|
||||
toUnderlying,
|
||||
deadline,
|
||||
sigParams,
|
||||
chainId
|
||||
sigParams
|
||||
)
|
||||
).to.be.revertedWith(LM_ERRORS.INVALID_OWNER);
|
||||
|
||||
await expect(
|
||||
staticAToken
|
||||
.connect(user2Signer)
|
||||
.metaWithdraw(
|
||||
owner,
|
||||
recipient,
|
||||
staticAmount,
|
||||
dynamicAmount,
|
||||
toUnderlying,
|
||||
0,
|
||||
sigParams,
|
||||
chainId
|
||||
)
|
||||
.metaWithdraw(owner, recipient, staticAmount, dynamicAmount, toUnderlying, 0, sigParams)
|
||||
).to.be.revertedWith(LM_ERRORS.INVALID_EXPIRATION);
|
||||
|
||||
await expect(
|
||||
|
@ -901,8 +871,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
dynamicAmount,
|
||||
toUnderlying,
|
||||
deadline,
|
||||
sigParams,
|
||||
chainId
|
||||
sigParams
|
||||
)
|
||||
).to.be.revertedWith(LM_ERRORS.INVALID_SIGNATURE);
|
||||
|
||||
|
@ -917,8 +886,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
dynamicAmount,
|
||||
toUnderlying,
|
||||
deadline,
|
||||
sigParams,
|
||||
chainId
|
||||
sigParams
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -940,7 +908,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
verifyingContract: staticAToken.address,
|
||||
};
|
||||
const domainSeperator = _TypedDataEncoder.hashDomain(domain);
|
||||
const seperator = await staticAToken.getDomainSeparator(chainId);
|
||||
const seperator = await staticAToken.getDomainSeparator();
|
||||
expect(seperator).to.be.eq(domainSeperator);
|
||||
|
||||
const userPrivateKey = require('../../../../test-wallets.js').accounts[0].secretKey;
|
||||
|
@ -1003,8 +971,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
|||
dynamicAmount,
|
||||
toUnderlying,
|
||||
deadline,
|
||||
sigParams,
|
||||
chainId
|
||||
sigParams
|
||||
)
|
||||
).to.be.revertedWith(LM_ERRORS.ONLY_ONE_AMOUNT_FORMAT_ALLOWED);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user