made changes as per review

This commit is contained in:
Harshit Yadav 2022-03-12 17:02:19 +05:30
parent ee409212b1
commit 79ed60b729
7 changed files with 72 additions and 79 deletions

View File

@ -2,11 +2,11 @@ pragma solidity ^0.7.0;
contract Events { contract Events {
event depositWithPermit( event depositWithPermit(
address _asset, address asset,
address _owner, address owner,
uint256 nonce, uint256 nonce,
uint256 _amount, uint256 amount,
uint256 _deadline, uint256 deadline,
uint8 v, uint8 v,
bytes32 r, bytes32 r,
bytes32 s bytes32 s

View File

@ -2,52 +2,21 @@ pragma solidity ^0.7.6;
import {TokenInterface} from "../../common/interfaces.sol"; import {TokenInterface} from "../../common/interfaces.sol";
interface ERC20_functions { interface TokenInterfaceWithPermit is TokenInterface {
function totalSupply() external view returns (uint); function permit(
address owner,
function balanceOf(address account) external view returns (uint); address spender,
uint256 value,
function transfer(address recipient, uint amount) external returns (bool); uint256 deadline,
uint8 v,
function allowance(address owner, address spender) external view returns (uint); bytes32 r,
bytes32 s
function approve(address spender, uint amount) external returns (bool); ) external;
function transferFrom(
address sender,
address recipient,
uint amount
) external returns (bool);
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
} }
interface ERC20_dai_functions { interface DAITokenInterfaceWithPermit is TokenInterface {
function totalSupply() external view returns (uint);
function balanceOf(address account) external view returns (uint); function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external;
function transfer(address recipient, uint amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint amount
) external returns (bool);
function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external;
} }

View File

@ -3,37 +3,37 @@ pragma experimental ABIEncoderV2;
import {TokenInterface, MemoryInterface} from "../../common/interfaces.sol"; import {TokenInterface, MemoryInterface} from "../../common/interfaces.sol";
import {Stores} from "../../common/stores.sol"; import {Stores} from "../../common/stores.sol";
import {ERC20_functions, ERC20_dai_functions} from "./interface.sol"; import {TokenInterfaceWithPermit, DAITokenInterfaceWithPermit} from "./interface.sol";
//import {Helpers} from "./helpers.sol"; //import {Helpers} from "./helpers.sol";
import {Events} from "./events.sol"; import {Events} from "./events.sol";
/** /**
* @title permit_erc20. * @title ERC20 Permit.
* @dev Adding permit functionality to ERC_20. * @dev Deposit ERC20 using Permit.
*/ */
contract permit_erc20 { contract ERC20PermitResolver {
address private immutable daiAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F; // dai has a different implementation for permit address private immutable daiAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F; // dai has a different implementation for permit
/** /**
* @notice ERC20_Permit functionality * @notice Deposit ERC20 using Permit
* @dev Adding permit functionality to ERC_20. * @dev Deposing ERC20 using Permit functionality. https://eips.ethereum.org/EIPS/eip-2612
* @param _asset The address of the token to call.(For AAVE Token : 0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9) * @param token The address of the token to call.(For AAVE Token : 0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9)
* @param _owner The public of the user which wants to permit the user to take funds.(Ex: - 0x3Fc046bdE274Fe8Ed2a7Fd008cD9DEB2540dfE36 ) * @param owner The public of the user which wants to permit the user to take funds.
* @param nonce The nonce of the user(Neede only if asset is DAI) //can add helper here * @param nonce The nonce of the user(Neede only if asset is DAI) //can add helper here
* @param _amount The amount of the token permitted by the owner (No need to specify in DAI, you get access to all the funds in DAI). * @param amount The amount of the token permitted by the owner (No need to specify in DAI, you get access to all the funds in DAI).
* @param _deadline The deadline decided by the owner. * @param deadline The deadline for permit.
* @param v The signature variable provided by the owner. * @param v The signature variable provided by the owner.
* @param r The signature variable provided by the owner. * @param r The signature variable provided by the owner.
* @param s The signature variable provided by the owner. * @param s The signature variable provided by the owner.
*/ */
function depositWithPermit( function depositWithPermit(
address _asset, address token,
address _owner, address owner,
uint256 nonce, uint256 nonce,
uint256 _amount, uint256 amount,
uint256 _deadline, uint256 deadline,
uint8 v, uint8 v,
bytes32 r, bytes32 r,
bytes32 s bytes32 s
@ -41,24 +41,24 @@ contract permit_erc20 {
external external
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)
{ {
if(_asset==daiAddress){ if(token == daiAddress){
ERC20_dai_functions token = ERC20_dai_functions(_asset); DAITokenInterfaceWithPermit token = DAITokenInterfaceWithPermit(token);
token.permit(_owner, address(this), nonce, _deadline, true, v, r, s); token.permit(owner, address(this), nonce, deadline, true, v, r, s);
token.transferFrom(_owner, address(this), _amount); token.transferFrom(owner, address(this), amount);
} }
else{ else{
ERC20_functions token = ERC20_functions(_asset); TokenInterfaceWithPermit token = TokenInterfaceWithPermit(token);
token.permit(_owner, address(this), _amount, _deadline, v, r, s); token.permit(owner, address(this), amount, deadline, v, r, s);
token.transferFrom(_owner, address(this), _amount); token.transferFrom(owner, address(this), amount);
} }
_eventName = "depositWithPermit(address,address,uint256,uint256,uint256,uint8,bytes32,bytes32)"; _eventName = "depositWithPermit(address,address,uint256,uint256,uint256,uint8,bytes32,bytes32)";
_eventParam = abi.encode( _eventParam = abi.encode(
_asset, token,
_owner, owner,
nonce, nonce,
_amount, amount,
_deadline, deadline,
v, v,
r, r,
s s
@ -68,6 +68,6 @@ contract permit_erc20 {
} }
contract ConnectV2Permit_erc20 is permit_erc20{ contract ConnectERC20Permit is ERC20PermitResolver{
string public name = "permit_erc20"; string public name = "ERC20PermitResolver";
} }

23
package-lock.json generated
View File

@ -22,6 +22,7 @@
"hardhat-docgen": "^1.2.0", "hardhat-docgen": "^1.2.0",
"inquirer": "^8.2.0", "inquirer": "^8.2.0",
"minimist": "^1.2.5", "minimist": "^1.2.5",
"run": "^1.4.0",
"solc": "^0.8.10", "solc": "^0.8.10",
"typechain": "^6.0.5" "typechain": "^6.0.5"
}, },
@ -26553,6 +26554,20 @@
"rlp": "bin/rlp" "rlp": "bin/rlp"
} }
}, },
"node_modules/run": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/run/-/run-1.4.0.tgz",
"integrity": "sha1-4X2ekEOrL+F3dsspnhI3848LT/o=",
"dependencies": {
"minimatch": "*"
},
"bin": {
"runjs": "cli.js"
},
"engines": {
"node": ">=v0.9.0"
}
},
"node_modules/run-async": { "node_modules/run-async": {
"version": "2.4.1", "version": "2.4.1",
"resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz",
@ -51849,6 +51864,14 @@
"bn.js": "^4.11.1" "bn.js": "^4.11.1"
} }
}, },
"run": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/run/-/run-1.4.0.tgz",
"integrity": "sha1-4X2ekEOrL+F3dsspnhI3848LT/o=",
"requires": {
"minimatch": "*"
}
},
"run-async": { "run-async": {
"version": "2.4.1", "version": "2.4.1",
"resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz",

View File

@ -38,6 +38,7 @@
"hardhat-docgen": "^1.2.0", "hardhat-docgen": "^1.2.0",
"inquirer": "^8.2.0", "inquirer": "^8.2.0",
"minimist": "^1.2.5", "minimist": "^1.2.5",
"run": "^1.4.0",
"solc": "^0.8.10", "solc": "^0.8.10",
"typechain": "^6.0.5" "typechain": "^6.0.5"
}, },

View File

@ -32,7 +32,7 @@ describe("starting tests for aave", function () {
//deploying the main contract //deploying the main contract
owner = await ethers.getSigners(); owner = await ethers.getSigners();
contract1 = await ethers.getContractFactory("permit_erc20"); contract1 = await ethers.getContractFactory("ERC20PermitResolver");
our_deployed_contract = await contract1.deploy(); our_deployed_contract = await contract1.deploy();
await our_deployed_contract.deployed(); await our_deployed_contract.deployed();
@ -58,7 +58,7 @@ describe("starting tests for aave", function () {
//creating instance of the AAVE token contract //creating instance of the AAVE token contract
aave_token_contract = await ethers.getContractAt("ERC20_functions", aave_token_address); aave_token_contract = await ethers.getContractAt("TokenInterfaceWithPermit", aave_token_address);
// needed for getting public variables necessary for hashing // needed for getting public variables necessary for hashing

View File

@ -31,7 +31,7 @@ describe("starting tests for dai", function () {
//deploying the main contract //deploying the main contract
owner = await ethers.getSigners(); owner = await ethers.getSigners();
contract1 = await ethers.getContractFactory("permit_erc20"); contract1 = await ethers.getContractFactory("ERC20PermitResolver");
our_deployed_contract = await contract1.deploy(); our_deployed_contract = await contract1.deploy();
await our_deployed_contract.deployed(); await our_deployed_contract.deployed();
@ -57,7 +57,7 @@ describe("starting tests for dai", function () {
//creating instance of the AAVE token contract //creating instance of the AAVE token contract
aave_token_contract = await ethers.getContractAt("ERC20_functions", dai_token_address); aave_token_contract = await ethers.getContractAt("DAITokenInterfaceWithPermit", dai_token_address);
// needed for getting public variables necessary for hashing // needed for getting public variables necessary for hashing