mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
made changes as per review
This commit is contained in:
parent
ee409212b1
commit
79ed60b729
|
@ -2,11 +2,11 @@ pragma solidity ^0.7.0;
|
|||
|
||||
contract Events {
|
||||
event depositWithPermit(
|
||||
address _asset,
|
||||
address _owner,
|
||||
address asset,
|
||||
address owner,
|
||||
uint256 nonce,
|
||||
uint256 _amount,
|
||||
uint256 _deadline,
|
||||
uint256 amount,
|
||||
uint256 deadline,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
|
|
|
@ -2,52 +2,21 @@ pragma solidity ^0.7.6;
|
|||
|
||||
import {TokenInterface} from "../../common/interfaces.sol";
|
||||
|
||||
interface ERC20_functions {
|
||||
function totalSupply() external view returns (uint);
|
||||
|
||||
function balanceOf(address account) external view returns (uint);
|
||||
|
||||
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 owner,
|
||||
address spender,
|
||||
uint256 value,
|
||||
uint256 deadline,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
) external;
|
||||
interface TokenInterfaceWithPermit is TokenInterface {
|
||||
function permit(
|
||||
address owner,
|
||||
address spender,
|
||||
uint256 value,
|
||||
uint256 deadline,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
) external;
|
||||
|
||||
}
|
||||
|
||||
interface ERC20_dai_functions {
|
||||
function totalSupply() external view returns (uint);
|
||||
interface DAITokenInterfaceWithPermit is TokenInterface {
|
||||
|
||||
function balanceOf(address account) external view returns (uint);
|
||||
|
||||
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;
|
||||
function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,37 +3,37 @@ pragma experimental ABIEncoderV2;
|
|||
|
||||
import {TokenInterface, MemoryInterface} from "../../common/interfaces.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 {Events} from "./events.sol";
|
||||
|
||||
/**
|
||||
* @title permit_erc20.
|
||||
* @dev Adding permit functionality to ERC_20.
|
||||
* @title ERC20 Permit.
|
||||
* @dev Deposit ERC20 using Permit.
|
||||
*/
|
||||
|
||||
|
||||
contract permit_erc20 {
|
||||
contract ERC20PermitResolver {
|
||||
address private immutable daiAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F; // dai has a different implementation for permit
|
||||
|
||||
/**
|
||||
* @notice ERC20_Permit functionality
|
||||
* @dev Adding permit functionality to ERC_20.
|
||||
* @param _asset 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 )
|
||||
* @notice Deposit ERC20 using Permit
|
||||
* @dev Deposing ERC20 using Permit functionality. https://eips.ethereum.org/EIPS/eip-2612
|
||||
* @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.
|
||||
* @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 _deadline The deadline decided by the owner.
|
||||
* @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 for permit.
|
||||
* @param v 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.
|
||||
*/
|
||||
function depositWithPermit(
|
||||
address _asset,
|
||||
address _owner,
|
||||
address token,
|
||||
address owner,
|
||||
uint256 nonce,
|
||||
uint256 _amount,
|
||||
uint256 _deadline,
|
||||
uint256 amount,
|
||||
uint256 deadline,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
|
@ -41,24 +41,24 @@ contract permit_erc20 {
|
|||
external
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
if(_asset==daiAddress){
|
||||
ERC20_dai_functions token = ERC20_dai_functions(_asset);
|
||||
token.permit(_owner, address(this), nonce, _deadline, true, v, r, s);
|
||||
token.transferFrom(_owner, address(this), _amount);
|
||||
if(token == daiAddress){
|
||||
DAITokenInterfaceWithPermit token = DAITokenInterfaceWithPermit(token);
|
||||
token.permit(owner, address(this), nonce, deadline, true, v, r, s);
|
||||
token.transferFrom(owner, address(this), amount);
|
||||
}
|
||||
else{
|
||||
ERC20_functions token = ERC20_functions(_asset);
|
||||
token.permit(_owner, address(this), _amount, _deadline, v, r, s);
|
||||
token.transferFrom(_owner, address(this), _amount);
|
||||
TokenInterfaceWithPermit token = TokenInterfaceWithPermit(token);
|
||||
token.permit(owner, address(this), amount, deadline, v, r, s);
|
||||
token.transferFrom(owner, address(this), amount);
|
||||
}
|
||||
|
||||
_eventName = "depositWithPermit(address,address,uint256,uint256,uint256,uint8,bytes32,bytes32)";
|
||||
_eventParam = abi.encode(
|
||||
_asset,
|
||||
_owner,
|
||||
token,
|
||||
owner,
|
||||
nonce,
|
||||
_amount,
|
||||
_deadline,
|
||||
amount,
|
||||
deadline,
|
||||
v,
|
||||
r,
|
||||
s
|
||||
|
@ -68,6 +68,6 @@ contract permit_erc20 {
|
|||
|
||||
}
|
||||
|
||||
contract ConnectV2Permit_erc20 is permit_erc20{
|
||||
string public name = "permit_erc20";
|
||||
contract ConnectERC20Permit is ERC20PermitResolver{
|
||||
string public name = "ERC20PermitResolver";
|
||||
}
|
||||
|
|
23
package-lock.json
generated
23
package-lock.json
generated
|
@ -22,6 +22,7 @@
|
|||
"hardhat-docgen": "^1.2.0",
|
||||
"inquirer": "^8.2.0",
|
||||
"minimist": "^1.2.5",
|
||||
"run": "^1.4.0",
|
||||
"solc": "^0.8.10",
|
||||
"typechain": "^6.0.5"
|
||||
},
|
||||
|
@ -26553,6 +26554,20 @@
|
|||
"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": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz",
|
||||
|
@ -51849,6 +51864,14 @@
|
|||
"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": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz",
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
"hardhat-docgen": "^1.2.0",
|
||||
"inquirer": "^8.2.0",
|
||||
"minimist": "^1.2.5",
|
||||
"run": "^1.4.0",
|
||||
"solc": "^0.8.10",
|
||||
"typechain": "^6.0.5"
|
||||
},
|
||||
|
|
|
@ -32,7 +32,7 @@ describe("starting tests for aave", function () {
|
|||
|
||||
//deploying the main contract
|
||||
owner = await ethers.getSigners();
|
||||
contract1 = await ethers.getContractFactory("permit_erc20");
|
||||
contract1 = await ethers.getContractFactory("ERC20PermitResolver");
|
||||
our_deployed_contract = await contract1.deploy();
|
||||
await our_deployed_contract.deployed();
|
||||
|
||||
|
@ -58,7 +58,7 @@ describe("starting tests for aave", function () {
|
|||
|
||||
|
||||
//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
|
||||
|
|
|
@ -31,7 +31,7 @@ describe("starting tests for dai", function () {
|
|||
|
||||
//deploying the main contract
|
||||
owner = await ethers.getSigners();
|
||||
contract1 = await ethers.getContractFactory("permit_erc20");
|
||||
contract1 = await ethers.getContractFactory("ERC20PermitResolver");
|
||||
our_deployed_contract = await contract1.deploy();
|
||||
await our_deployed_contract.deployed();
|
||||
|
||||
|
@ -57,7 +57,7 @@ describe("starting tests for dai", function () {
|
|||
|
||||
|
||||
//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
|
||||
|
|
Loading…
Reference in New Issue
Block a user