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 v Signature param
|
||||||
* @param s Signature param
|
* @param s Signature param
|
||||||
* @param r Signature param
|
* @param r Signature param
|
||||||
* @param chainId Passing the chainId in order to be fork-compatible
|
|
||||||
*/
|
*/
|
||||||
function permit(
|
function permit(
|
||||||
address owner,
|
address owner,
|
||||||
|
@ -159,8 +158,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
uint256 deadline,
|
uint256 deadline,
|
||||||
uint8 v,
|
uint8 v,
|
||||||
bytes32 r,
|
bytes32 r,
|
||||||
bytes32 s,
|
bytes32 s
|
||||||
uint256 chainId
|
|
||||||
) external {
|
) external {
|
||||||
require(owner != address(0), StaticATokenErrors.INVALID_OWNER);
|
require(owner != address(0), StaticATokenErrors.INVALID_OWNER);
|
||||||
//solium-disable-next-line
|
//solium-disable-next-line
|
||||||
|
@ -170,7 +168,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
keccak256(
|
keccak256(
|
||||||
abi.encodePacked(
|
abi.encodePacked(
|
||||||
'\x19\x01',
|
'\x19\x01',
|
||||||
getDomainSeparator(chainId),
|
getDomainSeparator(),
|
||||||
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, currentValidNonce, deadline))
|
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)
|
* - `false` if the msg.sender comes already with aTokens (e.g. aUSDC)
|
||||||
* @param deadline The deadline timestamp, type(uint256).max for max deadline
|
* @param deadline The deadline timestamp, type(uint256).max for max deadline
|
||||||
* @param sigParams Signature params: v,r,s
|
* @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
|
* @return uint256 The amount of StaticAToken minted, static balance
|
||||||
*/
|
*/
|
||||||
function metaDeposit(
|
function metaDeposit(
|
||||||
|
@ -202,8 +199,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
uint16 referralCode,
|
uint16 referralCode,
|
||||||
bool fromUnderlying,
|
bool fromUnderlying,
|
||||||
uint256 deadline,
|
uint256 deadline,
|
||||||
SignatureParams calldata sigParams,
|
SignatureParams calldata sigParams
|
||||||
uint256 chainId
|
|
||||||
) external returns (uint256) {
|
) external returns (uint256) {
|
||||||
require(depositor != address(0), StaticATokenErrors.INVALID_DEPOSITOR);
|
require(depositor != address(0), StaticATokenErrors.INVALID_DEPOSITOR);
|
||||||
//solium-disable-next-line
|
//solium-disable-next-line
|
||||||
|
@ -213,7 +209,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
keccak256(
|
keccak256(
|
||||||
abi.encodePacked(
|
abi.encodePacked(
|
||||||
'\x19\x01',
|
'\x19\x01',
|
||||||
getDomainSeparator(chainId),
|
getDomainSeparator(),
|
||||||
keccak256(
|
keccak256(
|
||||||
abi.encode(
|
abi.encode(
|
||||||
METADEPOSIT_TYPEHASH,
|
METADEPOSIT_TYPEHASH,
|
||||||
|
@ -248,7 +244,6 @@ contract StaticATokenLM is ERC20 {
|
||||||
* - `false` for the recipient to get aTokens (e.g. aUSDC)
|
* - `false` for the recipient to get aTokens (e.g. aUSDC)
|
||||||
* @param deadline The deadline timestamp, type(uint256).max for max deadline
|
* @param deadline The deadline timestamp, type(uint256).max for max deadline
|
||||||
* @param sigParams Signature params: v,r,s
|
* @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 amountToBurn: StaticATokens burnt, static balance
|
||||||
* @return amountToWithdraw: underlying/aToken send to `recipient`, dynamic balance
|
* @return amountToWithdraw: underlying/aToken send to `recipient`, dynamic balance
|
||||||
*/
|
*/
|
||||||
|
@ -259,8 +254,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
uint256 dynamicAmount,
|
uint256 dynamicAmount,
|
||||||
bool toUnderlying,
|
bool toUnderlying,
|
||||||
uint256 deadline,
|
uint256 deadline,
|
||||||
SignatureParams calldata sigParams,
|
SignatureParams calldata sigParams
|
||||||
uint256 chainId
|
|
||||||
) external returns (uint256, uint256) {
|
) external returns (uint256, uint256) {
|
||||||
require(owner != address(0), StaticATokenErrors.INVALID_OWNER);
|
require(owner != address(0), StaticATokenErrors.INVALID_OWNER);
|
||||||
//solium-disable-next-line
|
//solium-disable-next-line
|
||||||
|
@ -270,7 +264,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
keccak256(
|
keccak256(
|
||||||
abi.encodePacked(
|
abi.encodePacked(
|
||||||
'\x19\x01',
|
'\x19\x01',
|
||||||
getDomainSeparator(chainId),
|
getDomainSeparator(),
|
||||||
keccak256(
|
keccak256(
|
||||||
abi.encode(
|
abi.encode(
|
||||||
METAWITHDRAWAL_TYPEHASH,
|
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
|
* @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
|
* @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
|
return
|
||||||
keccak256(
|
keccak256(
|
||||||
abi.encode(
|
abi.encode(
|
||||||
|
|
|
@ -538,13 +538,13 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
||||||
await expect(
|
await expect(
|
||||||
staticAToken
|
staticAToken
|
||||||
.connect(spender)
|
.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);
|
).to.be.revertedWith(LM_ERRORS.INVALID_SIGNATURE);
|
||||||
|
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await staticAToken
|
await staticAToken
|
||||||
.connect(spender)
|
.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(
|
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(
|
await expect(
|
||||||
staticAToken
|
staticAToken
|
||||||
.connect(spender)
|
.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);
|
).to.be.revertedWith(LM_ERRORS.INVALID_OWNER);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
staticAToken
|
staticAToken
|
||||||
.connect(spender)
|
.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);
|
).to.be.revertedWith(LM_ERRORS.INVALID_EXPIRATION);
|
||||||
|
|
||||||
expect((await staticAToken.allowance(owner._address, spender._address)).toString()).to.be.equal(
|
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,
|
verifyingContract: staticAToken.address,
|
||||||
};
|
};
|
||||||
const domainSeperator = _TypedDataEncoder.hashDomain(domain);
|
const domainSeperator = _TypedDataEncoder.hashDomain(domain);
|
||||||
const seperator = await staticAToken.getDomainSeparator(chainId);
|
const seperator = await staticAToken.getDomainSeparator();
|
||||||
expect(seperator).to.be.eq(domainSeperator);
|
expect(seperator).to.be.eq(domainSeperator);
|
||||||
|
|
||||||
const userPrivateKey = require('../../../../test-wallets.js').accounts[0].secretKey;
|
const userPrivateKey = require('../../../../test-wallets.js').accounts[0].secretKey;
|
||||||
|
@ -697,24 +697,14 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
||||||
referralCode,
|
referralCode,
|
||||||
fromUnderlying,
|
fromUnderlying,
|
||||||
deadline,
|
deadline,
|
||||||
sigParams,
|
sigParams
|
||||||
chainId
|
|
||||||
)
|
)
|
||||||
).to.be.revertedWith(LM_ERRORS.INVALID_DEPOSITOR);
|
).to.be.revertedWith(LM_ERRORS.INVALID_DEPOSITOR);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
staticAToken
|
staticAToken
|
||||||
.connect(user2Signer)
|
.connect(user2Signer)
|
||||||
.metaDeposit(
|
.metaDeposit(depositor, recipient, value, referralCode, fromUnderlying, 0, sigParams)
|
||||||
depositor,
|
|
||||||
recipient,
|
|
||||||
value,
|
|
||||||
referralCode,
|
|
||||||
fromUnderlying,
|
|
||||||
0,
|
|
||||||
sigParams,
|
|
||||||
chainId
|
|
||||||
)
|
|
||||||
).to.be.revertedWith(LM_ERRORS.INVALID_EXPIRATION);
|
).to.be.revertedWith(LM_ERRORS.INVALID_EXPIRATION);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
|
@ -727,8 +717,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
||||||
referralCode,
|
referralCode,
|
||||||
fromUnderlying,
|
fromUnderlying,
|
||||||
deadline,
|
deadline,
|
||||||
sigParams,
|
sigParams
|
||||||
chainId
|
|
||||||
)
|
)
|
||||||
).to.be.revertedWith(LM_ERRORS.INVALID_SIGNATURE);
|
).to.be.revertedWith(LM_ERRORS.INVALID_SIGNATURE);
|
||||||
|
|
||||||
|
@ -736,16 +725,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await staticAToken
|
await staticAToken
|
||||||
.connect(user2Signer)
|
.connect(user2Signer)
|
||||||
.metaDeposit(
|
.metaDeposit(depositor, recipient, value, referralCode, fromUnderlying, deadline, sigParams)
|
||||||
depositor,
|
|
||||||
recipient,
|
|
||||||
value,
|
|
||||||
referralCode,
|
|
||||||
fromUnderlying,
|
|
||||||
deadline,
|
|
||||||
sigParams,
|
|
||||||
chainId
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const ctxtAfterDeposit = await getContext(ctxtParams);
|
const ctxtAfterDeposit = await getContext(ctxtParams);
|
||||||
|
@ -810,7 +790,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
||||||
verifyingContract: staticAToken.address,
|
verifyingContract: staticAToken.address,
|
||||||
};
|
};
|
||||||
const domainSeperator = _TypedDataEncoder.hashDomain(domain);
|
const domainSeperator = _TypedDataEncoder.hashDomain(domain);
|
||||||
const seperator = await staticAToken.getDomainSeparator(chainId);
|
const seperator = await staticAToken.getDomainSeparator();
|
||||||
expect(seperator).to.be.eq(domainSeperator);
|
expect(seperator).to.be.eq(domainSeperator);
|
||||||
|
|
||||||
const userPrivateKey = require('../../../../test-wallets.js').accounts[0].secretKey;
|
const userPrivateKey = require('../../../../test-wallets.js').accounts[0].secretKey;
|
||||||
|
@ -871,24 +851,14 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
||||||
dynamicAmount,
|
dynamicAmount,
|
||||||
toUnderlying,
|
toUnderlying,
|
||||||
deadline,
|
deadline,
|
||||||
sigParams,
|
sigParams
|
||||||
chainId
|
|
||||||
)
|
)
|
||||||
).to.be.revertedWith(LM_ERRORS.INVALID_OWNER);
|
).to.be.revertedWith(LM_ERRORS.INVALID_OWNER);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
staticAToken
|
staticAToken
|
||||||
.connect(user2Signer)
|
.connect(user2Signer)
|
||||||
.metaWithdraw(
|
.metaWithdraw(owner, recipient, staticAmount, dynamicAmount, toUnderlying, 0, sigParams)
|
||||||
owner,
|
|
||||||
recipient,
|
|
||||||
staticAmount,
|
|
||||||
dynamicAmount,
|
|
||||||
toUnderlying,
|
|
||||||
0,
|
|
||||||
sigParams,
|
|
||||||
chainId
|
|
||||||
)
|
|
||||||
).to.be.revertedWith(LM_ERRORS.INVALID_EXPIRATION);
|
).to.be.revertedWith(LM_ERRORS.INVALID_EXPIRATION);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
|
@ -901,8 +871,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
||||||
dynamicAmount,
|
dynamicAmount,
|
||||||
toUnderlying,
|
toUnderlying,
|
||||||
deadline,
|
deadline,
|
||||||
sigParams,
|
sigParams
|
||||||
chainId
|
|
||||||
)
|
)
|
||||||
).to.be.revertedWith(LM_ERRORS.INVALID_SIGNATURE);
|
).to.be.revertedWith(LM_ERRORS.INVALID_SIGNATURE);
|
||||||
|
|
||||||
|
@ -917,8 +886,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
||||||
dynamicAmount,
|
dynamicAmount,
|
||||||
toUnderlying,
|
toUnderlying,
|
||||||
deadline,
|
deadline,
|
||||||
sigParams,
|
sigParams
|
||||||
chainId
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -940,7 +908,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
||||||
verifyingContract: staticAToken.address,
|
verifyingContract: staticAToken.address,
|
||||||
};
|
};
|
||||||
const domainSeperator = _TypedDataEncoder.hashDomain(domain);
|
const domainSeperator = _TypedDataEncoder.hashDomain(domain);
|
||||||
const seperator = await staticAToken.getDomainSeparator(chainId);
|
const seperator = await staticAToken.getDomainSeparator();
|
||||||
expect(seperator).to.be.eq(domainSeperator);
|
expect(seperator).to.be.eq(domainSeperator);
|
||||||
|
|
||||||
const userPrivateKey = require('../../../../test-wallets.js').accounts[0].secretKey;
|
const userPrivateKey = require('../../../../test-wallets.js').accounts[0].secretKey;
|
||||||
|
@ -1003,8 +971,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
|
||||||
dynamicAmount,
|
dynamicAmount,
|
||||||
toUnderlying,
|
toUnderlying,
|
||||||
deadline,
|
deadline,
|
||||||
sigParams,
|
sigParams
|
||||||
chainId
|
|
||||||
)
|
)
|
||||||
).to.be.revertedWith(LM_ERRORS.ONLY_ONE_AMOUNT_FORMAT_ALLOWED);
|
).to.be.revertedWith(LM_ERRORS.ONLY_ONE_AMOUNT_FORMAT_ALLOWED);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user