From 1851104d6f3d5bce47c8e7cbc2afd8a2a69b35e2 Mon Sep 17 00:00:00 2001 From: Harshit Yadav Date: Sun, 13 Mar 2022 01:34:05 +0530 Subject: [PATCH] Added getId, setId --- .../mainnet/connectors/permit_erc20/main.sol | 26 ++++++++++++++----- test/mainnet/permit_erc20/test-aave.js | 6 ++--- test/mainnet/permit_erc20/test-dai.js | 6 ++--- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/contracts/mainnet/connectors/permit_erc20/main.sol b/contracts/mainnet/connectors/permit_erc20/main.sol index fc635e35..5fdd92fb 100644 --- a/contracts/mainnet/connectors/permit_erc20/main.sol +++ b/contracts/mainnet/connectors/permit_erc20/main.sol @@ -13,7 +13,7 @@ import {Events} from "./events.sol"; */ -contract ERC20PermitResolver { +contract ERC20PermitResolver is Stores { address private immutable daiAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F; // dai has a different implementation for permit /** @@ -36,23 +36,35 @@ contract ERC20PermitResolver { uint256 deadline, uint8 v, bytes32 r, - bytes32 s + bytes32 s, + uint256 getId, + uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { if(token == daiAddress){ + uint _amt = getUint(getId, amount); + DAITokenInterfaceWithPermit token = DAITokenInterfaceWithPermit(token); + token.permit(owner, address(this), nonce, deadline, true, v, r, s); - token.transferFrom(owner, address(this), amount); + token.transferFrom(owner, address(this), _amt); + + setUint(setId, _amt); } else{ + uint _amt = getUint(getId, amount); + TokenInterfaceWithPermit token = TokenInterfaceWithPermit(token); + token.permit(owner, address(this), amount, deadline, v, r, s); - token.transferFrom(owner, address(this), amount); + token.transferFrom(owner, address(this), _amt); + + setUint(setId, _amt); } - _eventName = "depositWithPermit(address,address,uint256,uint256,uint256,uint8,bytes32,bytes32)"; + _eventName = "depositWithPermit(address,address,uint256,uint256,uint256,uint8,bytes32,bytes32,uint256,uint256)"; _eventParam = abi.encode( token, owner, @@ -61,7 +73,9 @@ contract ERC20PermitResolver { deadline, v, r, - s + s, + getId, + setId ); } diff --git a/test/mainnet/permit_erc20/test-aave.js b/test/mainnet/permit_erc20/test-aave.js index 2f43d8ef..6bd1c750 100644 --- a/test/mainnet/permit_erc20/test-aave.js +++ b/test/mainnet/permit_erc20/test-aave.js @@ -95,20 +95,20 @@ describe("starting tests for aave", function () { const hash1_for_encodePacked = soliditySha3('\x19\x01', DOMAIN_SEPARATOR, hash); - console.log("The hash that will be signed using private key: ", hash1_for_encodePacked); + //console.log("The hash that will be signed using private key: ", hash1_for_encodePacked); //getting the r ,s ,v from the signature which will be passed as arguments in permit function const { v, r, s } = EthUtil.ecsign(Buffer.from(hash1_for_encodePacked.slice(2), 'hex'), Buffer.from(private_key.slice(2), 'hex')); //the sender calls permit function to take the allowance of fund transfer from the my_account(me) (Remember that they were interchanged) - await our_deployed_contract.connect(my_account).depositWithPermit(aave_token_address,my_account.address,0,value,deadline,v, hexlify(r), hexlify(s)); + await our_deployed_contract.connect(my_account).depositWithPermit(aave_token_address,my_account.address,0,value,deadline,v, hexlify(r), hexlify(s), 0, 0); //getting the finla balances expect(await aave_token_contract.balanceOf(my_account.address)).to.equal(0); expect(await aave_token_contract.balanceOf(our_deployed_contract.address)).to.equal(value); - console.log("The funds have been deposited to our contract through depositWithPermit function"); + //console.log("The funds have been deposited to our contract through depositWithPermit function"); }); }); diff --git a/test/mainnet/permit_erc20/test-dai.js b/test/mainnet/permit_erc20/test-dai.js index dd7b727c..47d4921a 100644 --- a/test/mainnet/permit_erc20/test-dai.js +++ b/test/mainnet/permit_erc20/test-dai.js @@ -92,20 +92,20 @@ describe("starting tests for dai", function () { const hash = web3.utils.keccak256(encoded, {encoding: 'hex'}); const hash1_for_encodePacked = soliditySha3('\x19\x01', DOMAIN_SEPARATOR, hash); - console.log("The hash that will be signed using private key: ", hash1_for_encodePacked); + //console.log("The hash that will be signed using private key: ", hash1_for_encodePacked); //getting the r ,s ,v from the signature which will be passed as arguments in permit function const { v, r, s } = EthUtil.ecsign(Buffer.from(hash1_for_encodePacked.slice(2), 'hex'), Buffer.from(private_key.slice(2), 'hex')); //the sender calls permit function to take the allowance of fund transfer from the my_account(me) (Remember that they were interchanged) - await our_deployed_contract.depositWithPermit(dai_token_address,my_account.address,currentValidNonce,value,deadline,v, hexlify(r), hexlify(s)); + await our_deployed_contract.depositWithPermit(dai_token_address,my_account.address,currentValidNonce,value,deadline,v, hexlify(r), hexlify(s),0 ,0); //getting the finla balances expect(await aave_token_contract.balanceOf(my_account.address)).to.equal(0); expect(await aave_token_contract.balanceOf(our_deployed_contract.address)).to.equal(value); - console.log("The funds have been deposited to our contract through depositWithPermit function"); + //console.log("The funds have been deposited to our contract through depositWithPermit function"); }); });