From d515febb94a9d93ed960e38581c4e1f50b973926 Mon Sep 17 00:00:00 2001 From: Harshit Yadav Date: Wed, 9 Mar 2022 03:22:13 +0530 Subject: [PATCH] check --- .env.example | 1 + .../connectors/permit_erc20/events.sol | 14 ++ .../connectors/permit_erc20/interface.sol | 53 ++++++ .../mainnet/connectors/permit_erc20/main.sol | 62 +++++++ package-lock.json | 153 ++++++++++++------ package.json | 13 +- test/mainnet/permit_erc20/test-aave.js | 113 +++++++++++++ test/mainnet/permit_erc20/test-dai.js | 112 +++++++++++++ 8 files changed, 466 insertions(+), 55 deletions(-) create mode 100644 contracts/mainnet/connectors/permit_erc20/events.sol create mode 100644 contracts/mainnet/connectors/permit_erc20/interface.sol create mode 100644 contracts/mainnet/connectors/permit_erc20/main.sol create mode 100644 test/mainnet/permit_erc20/test-aave.js create mode 100644 test/mainnet/permit_erc20/test-dai.js diff --git a/.env.example b/.env.example index 2525a67a..1be4f380 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ ETHERSCAN_API_KEY="" PRIVATE_KEY="" +PUBLIC_ADDRESS="" TENDERLY_PROJECT="" TENDERLY_USERNAME="" ALCHEMY_ID="" \ No newline at end of file diff --git a/contracts/mainnet/connectors/permit_erc20/events.sol b/contracts/mainnet/connectors/permit_erc20/events.sol new file mode 100644 index 00000000..2bd0abfa --- /dev/null +++ b/contracts/mainnet/connectors/permit_erc20/events.sol @@ -0,0 +1,14 @@ +pragma solidity ^0.7.0; + +contract Events { + event depositWithPermit( + address _asset, + address _owner, + uint256 nonce, + uint256 _amount, + uint256 _deadline, + uint8 v, + bytes32 r, + bytes32 s + ); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/permit_erc20/interface.sol b/contracts/mainnet/connectors/permit_erc20/interface.sol new file mode 100644 index 00000000..f66dbbdc --- /dev/null +++ b/contracts/mainnet/connectors/permit_erc20/interface.sol @@ -0,0 +1,53 @@ +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 ERC20_dai_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 holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external; + +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/permit_erc20/main.sol b/contracts/mainnet/connectors/permit_erc20/main.sol new file mode 100644 index 00000000..9045b291 --- /dev/null +++ b/contracts/mainnet/connectors/permit_erc20/main.sol @@ -0,0 +1,62 @@ +pragma solidity ^0.7.6; +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 {Helpers} from "./helpers.sol"; +import {Events} from "./events.sol"; + +/** + * @title permit_erc20. + * @dev Adding permit functionality to ERC_20. + */ + + /* put the dev, vghra details and the parms and cases ofr dai and aave*/ + +contract permit_erc20 { + address dai_address = 0x6B175474E89094C44Da98b954EedeAC495271d0F; + + function depositWithPermit( + address _asset, + address _owner, + uint256 nonce, + uint256 _amount, + uint256 _deadline, + uint8 v, + bytes32 r, + bytes32 s + ) + external + returns (string memory _eventName, bytes memory _eventParam) + { + if(_asset==dai_address){ + 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); + } + else{ + ERC20_functions token = ERC20_functions(_asset); + 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, + nonce, + _amount, + _deadline, + v, + r, + s + ); + + } + +} + +contract ConnectV2Permit_erc20 is permit_erc20{ + string public name = "permit_erc20"; +} diff --git a/package-lock.json b/package-lock.json index aadbddd5..ab570b4a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "@uniswap/v3-periphery": "^1.3.0", "chalk": "^5.0.0", "dotenv": "^10.0.0", + "ethers-utils": "^2.1.11", "hardhat-docgen": "^1.2.0", "inquirer": "^8.2.0", "minimist": "^1.2.5", @@ -32,12 +33,12 @@ "@openzeppelin/test-helpers": "^0.5.15", "@studydefi/money-legos": "^2.4.2", "@tenderly/hardhat-tenderly": "^1.0.13", - "@types/chai": "^4.2.22", + "@types/chai": "^4.3.0", "@types/chai-as-promised": "^7.1.4", "@types/inquirer": "^8.1.3", - "@types/mocha": "^9.0.0", - "@types/node": "^16.11.11", - "chai": "^4.3.4", + "@types/mocha": "^9.1.0", + "@types/node": "^16.11.26", + "chai": "^4.3.6", "chai-as-promised": "^7.1.1", "ethereum-waffle": "^3.4.0", "ethers": "^5.5.2", @@ -49,8 +50,8 @@ "prettier-plugin-solidity": "^1.0.0-beta.18", "solhint": "^3.3.6", "solidity-coverage": "0.7.17", - "ts-node": "^10.4.0", - "typescript": "^4.5.2", + "ts-node": "^10.7.0", + "typescript": "^4.6.2", "web3": "^1.6.1" } }, @@ -4665,9 +4666,9 @@ } }, "node_modules/@types/chai": { - "version": "4.2.22", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.22.tgz", - "integrity": "sha512-tFfcE+DSTzWAgifkjik9AySNqIyNoYwmR+uecPwwD/XRNfvOjmC/FjCxpiUGDkDVDphPfCUecSQVFw+lN3M3kQ==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.0.tgz", + "integrity": "sha512-/ceqdqeRraGolFTcfoXNiqjyQhZzbINDngeoAq9GoHa8PPK1yNzTaxWjA6BFWp5Ua9JpXEMSS4s5i9tS0hOJtw==", "dev": true }, "node_modules/@types/chai-as-promised": { @@ -4755,15 +4756,15 @@ } }, "node_modules/@types/mocha": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.0.0.tgz", - "integrity": "sha512-scN0hAWyLVAvLR9AyW7HoFF5sJZglyBsbPuHO4fv7JRvfmPBMfp1ozWqOf/e4wwPNxezBZXRfWzMb6iFLgEVRA==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.0.tgz", + "integrity": "sha512-QCWHkbMv4Y5U9oW10Uxbr45qMMSzl4OzijsozynUAgx3kEHUdXB00udx2dWDQ7f2TU2a2uuiFaRZjCe3unPpeg==", "dev": true }, "node_modules/@types/node": { - "version": "16.11.11", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.11.tgz", - "integrity": "sha512-KB0sixD67CeecHC33MYn+eYARkqTheIRNuu97y2XMjR7Wu3XibO1vaY6VBV6O/a89SPI81cEUIYT87UqUWlZNw==" + "version": "16.11.26", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.26.tgz", + "integrity": "sha512-GZ7bu5A6+4DtG7q9GsoHXy3ALcgeIHP4NnL0Vv2wu0uUB/yQex26v0tf6/na1mm0+bS9Uw+0DFex7aaKr2qawQ==" }, "node_modules/@types/node-fetch": { "version": "2.5.12", @@ -6607,15 +6608,16 @@ } }, "node_modules/chai": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.4.tgz", - "integrity": "sha512-yS5H68VYOCtN1cjfwumDSuzn/9c+yza4f3reKXlE5rUg7SFcCEy90gJvydNgOYtblyf4Zi6jIWRnXOgErta0KA==", + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.6.tgz", + "integrity": "sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==", "dev": true, "dependencies": { "assertion-error": "^1.1.0", "check-error": "^1.0.2", "deep-eql": "^3.0.1", "get-func-name": "^2.0.0", + "loupe": "^2.3.1", "pathval": "^1.1.1", "type-detect": "^4.0.5" }, @@ -9440,6 +9442,18 @@ "@ethersproject/wordlists": "5.5.0" } }, + "node_modules/ethers-utils": { + "version": "2.1.11", + "resolved": "https://registry.npmjs.org/ethers-utils/-/ethers-utils-2.1.11.tgz", + "integrity": "sha512-BfkGStBmmLjhTldmp5lifiwUeDjx/yowoWfmUnnvPNsix5PFE8IXQdY5VT/Qo1SXMgxzCe8m0Z8ysUw6Q9OmAw==", + "deprecated": "deprecated; please upgrade to ethers (see: https://docs.ethers.io/v5/api/utils/)", + "dependencies": { + "bn.js": "^4.4.0", + "hash.js": "^1.0.0", + "js-sha3": "0.5.7", + "xmlhttprequest": "1.8.0" + } + }, "node_modules/ethjs-abi": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/ethjs-abi/-/ethjs-abi-0.2.1.tgz", @@ -22859,8 +22873,7 @@ "node_modules/js-sha3": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.7.tgz", - "integrity": "sha1-DU/9gALVMzqrr0oj7tL2N0yfKOc=", - "dev": true + "integrity": "sha1-DU/9gALVMzqrr0oj7tL2N0yfKOc=" }, "node_modules/js-tokens": { "version": "4.0.0", @@ -23349,6 +23362,15 @@ "loose-envify": "cli.js" } }, + "node_modules/loupe": { + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.4.tgz", + "integrity": "sha512-OvKfgCC2Ndby6aSTREl5aCCPTNIzlDfQZvZxNUrBrihDhL3xcrYegTblhmEiCrg2kKQz4XsFIaemE5BF4ybSaQ==", + "dev": true, + "dependencies": { + "get-func-name": "^2.0.0" + } + }, "node_modules/lower-case": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz", @@ -28456,9 +28478,9 @@ } }, "node_modules/ts-node": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.4.0.tgz", - "integrity": "sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A==", + "version": "10.7.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", + "integrity": "sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==", "dev": true, "dependencies": { "@cspotcode/source-map-support": "0.7.0", @@ -28472,11 +28494,13 @@ "create-require": "^1.1.0", "diff": "^4.0.1", "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.0", "yn": "3.1.1" }, "bin": { "ts-node": "dist/bin.js", "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", "ts-node-script": "dist/bin-script.js", "ts-node-transpile-only": "dist/bin-transpile.js", "ts-script": "dist/bin-script-deprecated.js" @@ -28666,9 +28690,9 @@ } }, "node_modules/typescript": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", - "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.2.tgz", + "integrity": "sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -29019,6 +29043,12 @@ "uuid": "bin/uuid" } }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz", + "integrity": "sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA==", + "dev": true + }, "node_modules/validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", @@ -30723,7 +30753,6 @@ "version": "1.8.0", "resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz", "integrity": "sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw=", - "dev": true, "engines": { "node": ">=0.4.0" } @@ -34654,9 +34683,9 @@ } }, "@types/chai": { - "version": "4.2.22", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.22.tgz", - "integrity": "sha512-tFfcE+DSTzWAgifkjik9AySNqIyNoYwmR+uecPwwD/XRNfvOjmC/FjCxpiUGDkDVDphPfCUecSQVFw+lN3M3kQ==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.0.tgz", + "integrity": "sha512-/ceqdqeRraGolFTcfoXNiqjyQhZzbINDngeoAq9GoHa8PPK1yNzTaxWjA6BFWp5Ua9JpXEMSS4s5i9tS0hOJtw==", "dev": true }, "@types/chai-as-promised": { @@ -34746,15 +34775,15 @@ } }, "@types/mocha": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.0.0.tgz", - "integrity": "sha512-scN0hAWyLVAvLR9AyW7HoFF5sJZglyBsbPuHO4fv7JRvfmPBMfp1ozWqOf/e4wwPNxezBZXRfWzMb6iFLgEVRA==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.0.tgz", + "integrity": "sha512-QCWHkbMv4Y5U9oW10Uxbr45qMMSzl4OzijsozynUAgx3kEHUdXB00udx2dWDQ7f2TU2a2uuiFaRZjCe3unPpeg==", "dev": true }, "@types/node": { - "version": "16.11.11", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.11.tgz", - "integrity": "sha512-KB0sixD67CeecHC33MYn+eYARkqTheIRNuu97y2XMjR7Wu3XibO1vaY6VBV6O/a89SPI81cEUIYT87UqUWlZNw==" + "version": "16.11.26", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.26.tgz", + "integrity": "sha512-GZ7bu5A6+4DtG7q9GsoHXy3ALcgeIHP4NnL0Vv2wu0uUB/yQex26v0tf6/na1mm0+bS9Uw+0DFex7aaKr2qawQ==" }, "@types/node-fetch": { "version": "2.5.12", @@ -36322,15 +36351,16 @@ } }, "chai": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.4.tgz", - "integrity": "sha512-yS5H68VYOCtN1cjfwumDSuzn/9c+yza4f3reKXlE5rUg7SFcCEy90gJvydNgOYtblyf4Zi6jIWRnXOgErta0KA==", + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.6.tgz", + "integrity": "sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==", "dev": true, "requires": { "assertion-error": "^1.1.0", "check-error": "^1.0.2", "deep-eql": "^3.0.1", "get-func-name": "^2.0.0", + "loupe": "^2.3.1", "pathval": "^1.1.1", "type-detect": "^4.0.5" } @@ -38622,6 +38652,17 @@ "@ethersproject/wordlists": "5.5.0" } }, + "ethers-utils": { + "version": "2.1.11", + "resolved": "https://registry.npmjs.org/ethers-utils/-/ethers-utils-2.1.11.tgz", + "integrity": "sha512-BfkGStBmmLjhTldmp5lifiwUeDjx/yowoWfmUnnvPNsix5PFE8IXQdY5VT/Qo1SXMgxzCe8m0Z8ysUw6Q9OmAw==", + "requires": { + "bn.js": "^4.4.0", + "hash.js": "^1.0.0", + "js-sha3": "0.5.7", + "xmlhttprequest": "1.8.0" + } + }, "ethjs-abi": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/ethjs-abi/-/ethjs-abi-0.2.1.tgz", @@ -48850,8 +48891,7 @@ "js-sha3": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.7.tgz", - "integrity": "sha1-DU/9gALVMzqrr0oj7tL2N0yfKOc=", - "dev": true + "integrity": "sha1-DU/9gALVMzqrr0oj7tL2N0yfKOc=" }, "js-tokens": { "version": "4.0.0", @@ -49255,6 +49295,15 @@ "js-tokens": "^3.0.0 || ^4.0.0" } }, + "loupe": { + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.4.tgz", + "integrity": "sha512-OvKfgCC2Ndby6aSTREl5aCCPTNIzlDfQZvZxNUrBrihDhL3xcrYegTblhmEiCrg2kKQz4XsFIaemE5BF4ybSaQ==", + "dev": true, + "requires": { + "get-func-name": "^2.0.0" + } + }, "lower-case": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz", @@ -53378,9 +53427,9 @@ } }, "ts-node": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.4.0.tgz", - "integrity": "sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A==", + "version": "10.7.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", + "integrity": "sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==", "dev": true, "requires": { "@cspotcode/source-map-support": "0.7.0", @@ -53394,6 +53443,7 @@ "create-require": "^1.1.0", "diff": "^4.0.1", "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.0", "yn": "3.1.1" }, "dependencies": { @@ -53530,9 +53580,9 @@ } }, "typescript": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", - "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==" + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.2.tgz", + "integrity": "sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==" }, "typical": { "version": "2.6.1", @@ -53827,6 +53877,12 @@ "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", "dev": true }, + "v8-compile-cache-lib": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz", + "integrity": "sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA==", + "dev": true + }, "validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", @@ -55257,8 +55313,7 @@ "xmlhttprequest": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz", - "integrity": "sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw=", - "dev": true + "integrity": "sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw=" }, "xtend": { "version": "4.0.2", diff --git a/package.json b/package.json index 84f57114..140b1298 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "@uniswap/v3-periphery": "^1.3.0", "chalk": "^5.0.0", "dotenv": "^10.0.0", + "ethers-utils": "^2.1.11", "hardhat-docgen": "^1.2.0", "inquirer": "^8.2.0", "minimist": "^1.2.5", @@ -48,12 +49,12 @@ "@openzeppelin/test-helpers": "^0.5.15", "@studydefi/money-legos": "^2.4.2", "@tenderly/hardhat-tenderly": "^1.0.13", - "@types/chai": "^4.2.22", + "@types/chai": "^4.3.0", "@types/chai-as-promised": "^7.1.4", "@types/inquirer": "^8.1.3", - "@types/mocha": "^9.0.0", - "@types/node": "^16.11.11", - "chai": "^4.3.4", + "@types/mocha": "^9.1.0", + "@types/node": "^16.11.26", + "chai": "^4.3.6", "chai-as-promised": "^7.1.1", "ethereum-waffle": "^3.4.0", "ethers": "^5.5.2", @@ -65,8 +66,8 @@ "prettier-plugin-solidity": "^1.0.0-beta.18", "solhint": "^3.3.6", "solidity-coverage": "0.7.17", - "ts-node": "^10.4.0", - "typescript": "^4.5.2", + "ts-node": "^10.7.0", + "typescript": "^4.6.2", "web3": "^1.6.1" } } diff --git a/test/mainnet/permit_erc20/test-aave.js b/test/mainnet/permit_erc20/test-aave.js new file mode 100644 index 00000000..8c4e4a46 --- /dev/null +++ b/test/mainnet/permit_erc20/test-aave.js @@ -0,0 +1,113 @@ +const { ethers } = require("hardhat"); +const {hexlify} = require('ethers-utils'); +const EthUtil = require('ethereumjs-util') +const { soliditySha3 } = require("web3-utils"); +const dotenv = require('dotenv'); +dotenv.config(); + +const { expect } = require("chai"); + +const private_key ='0x' + process.env.PRIVATE_KEY; +const public_address = process.env.PUBLIC_ADDRESS; +const deadline = 1000000000000; +const value = 10000000; + +describe("starting tests for aave", function () { + let account_with_funds; + let my_account; + let owner; + let contract1; + let our_deployed_contract; + let aave_token_address="0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9"; + let address_having_aave_tokens = "0xddfAbCdc4D8FfC6d5beaf154f18B778f892A0740"; + let address_having_no_aave_tokens = public_address; + let contract; + + + before(async () =>{ + + //deploying the main contract + owner = await ethers.getSigners(); + contract1 = await ethers.getContractFactory("permit_erc20"); + our_deployed_contract = await contract1.deploy(); + await our_deployed_contract.deployed(); + + // impersonating a acccount that has some AAVE tokens + await hre.network.provider.request({ + method: "hardhat_impersonateAccount", + params: [address_having_aave_tokens], + }); + account_with_funds=await ethers.getSigner(address_having_aave_tokens); + + //impersonating my account, i have the private key of it + await hre.network.provider.request({ + method: "hardhat_impersonateAccount", + params: [address_having_no_aave_tokens], + }); + my_account=await ethers.getSigner(address_having_no_aave_tokens); + + //giving myself some transaction fee + await network.provider.send("hardhat_setBalance", [ + address_having_no_aave_tokens, + "0x1000000000000000000000000000000000", + ]); // will need to remove this, this is so that i can make transactions locally as i have no eth + + + //creating instance of the AAVE token contract + aave_token_contract = await ethers.getContractAt("ERC20_functions", aave_token_address); + + + // needed for getting public variables necessary for hashing + const abi_contract = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"delegatee","type":"address"},{"indexed":false,"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"DelegateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"DelegatedPowerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DELEGATE_BY_TYPE_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DELEGATE_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EIP712_REVISION","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REVISION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_aaveGovernance","outputs":[{"internalType":"contract ITransferHook","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"_votingSnapshots","outputs":[{"internalType":"uint128","name":"blockNumber","type":"uint128"},{"internalType":"uint128","name":"value","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_votingSnapshotsCounts","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"}],"name":"delegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"delegateBySig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"},{"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"delegateByType","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"},{"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"delegateByTypeBySig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegator","type":"address"},{"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"getDelegateeByType","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"blockNumber","type":"uint256"},{"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"getPowerAtBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"getPowerCurrent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"totalSupplyAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]; + contract = new web3.eth.Contract(abi_contract, aave_token_address) + + }); + + + describe("tests", function(){ + it("testing_balance", async function(){ + await aave_token_contract.connect(account_with_funds).approve(my_account.address,value); + await aave_token_contract.connect(my_account).transferFrom(account_with_funds.address,my_account.address,value); + + + expect(await aave_token_contract.balanceOf(my_account.address)).to.equal(value); + expect(await aave_token_contract.balanceOf(our_deployed_contract.address)).to.equal(0); + + // Account with some funds gave my account some funds and now those funds will be deposited to our deployed contract using "depositWithPermit" function + }); + + + it("creating hash, signing, calling permit, transfer", async function(){ + + //getting the parameters which will be used to generate data hash + let PERMIT_TYPEHASH = await contract.methods.PERMIT_TYPEHASH().call(); + let currentValidNonce = await contract.methods._nonces(my_account.address).call(); + let DOMAIN_SEPARATOR = await contract.methods.DOMAIN_SEPARATOR().call(); + + + // generating the hash to sign using private key, the hash will be similar to the one that will be sent as a message in permit function + const encoded = web3.eth.abi.encodeParameters(['bytes32', 'address', 'address', 'uint256', 'uint256', 'uint256'],[PERMIT_TYPEHASH, my_account.address, our_deployed_contract.address, value, currentValidNonce, deadline]); + 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); + + + //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)); + + + //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"); + }); + + + }); + + }); \ No newline at end of file diff --git a/test/mainnet/permit_erc20/test-dai.js b/test/mainnet/permit_erc20/test-dai.js new file mode 100644 index 00000000..8c4526de --- /dev/null +++ b/test/mainnet/permit_erc20/test-dai.js @@ -0,0 +1,112 @@ +const { ethers } = require("hardhat"); +const {hexlify} = require('ethers-utils'); +const EthUtil = require('ethereumjs-util') +const { soliditySha3 } = require("web3-utils"); +const dotenv = require('dotenv'); +dotenv.config(); + +const { expect } = require("chai"); + +const private_key ='0x' + process.env.PRIVATE_KEY; +const public_address = process.env.PUBLIC_ADDRESS; +const deadline = 1000000000000; +const value = 10000000; + +describe("starting tests for dai", function () { + let account_with_funds; + let my_account; + let owner; + let contract1; + let our_deployed_contract; + let aave_token_address="0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9"; + let dai_token_address = "0x6B175474E89094C44Da98b954EedeAC495271d0F"; + let address_having_aave_tokens = "0xddfAbCdc4D8FfC6d5beaf154f18B778f892A0740"; + let address_having_no_aave_tokens = public_address; + let contract; + + + before(async () =>{ + + //deploying the main contract + owner = await ethers.getSigners(); + contract1 = await ethers.getContractFactory("permit_erc20"); + our_deployed_contract = await contract1.deploy(); + await our_deployed_contract.deployed(); + + // impersonating a acccount that has some AAVE tokens + await hre.network.provider.request({ + method: "hardhat_impersonateAccount", + params: [address_having_aave_tokens], + }); + account_with_funds=await ethers.getSigner(address_having_aave_tokens); + + //impersonating my account, i have the private key of it + await hre.network.provider.request({ + method: "hardhat_impersonateAccount", + params: [address_having_no_aave_tokens], + }); + my_account=await ethers.getSigner(address_having_no_aave_tokens); + + //giving myself some transaction fee + await network.provider.send("hardhat_setBalance", [ + address_having_no_aave_tokens, + "0x1000000000000000000000000000000000", + ]); // will need to remove this, this is so that i can make transactions locally as i have no eth + + + //creating instance of the AAVE token contract + aave_token_contract = await ethers.getContractAt("ERC20_functions", dai_token_address); + + + // needed for getting public variables necessary for hashing + const abi_contract = [{"inputs":[{"internalType":"uint256","name":"chainId_","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"src","type":"address"},{"indexed":true,"internalType":"address","name":"guy","type":"address"},{"indexed":false,"internalType":"uint256","name":"wad","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"internalType":"bytes4","name":"sig","type":"bytes4"},{"indexed":true,"internalType":"address","name":"usr","type":"address"},{"indexed":true,"internalType":"bytes32","name":"arg1","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"arg2","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"LogNote","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"src","type":"address"},{"indexed":true,"internalType":"address","name":"dst","type":"address"},{"indexed":false,"internalType":"uint256","name":"wad","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":true,"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"src","type":"address"},{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"move","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"holder","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"bool","name":"allowed","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"pull","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"push","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"src","type":"address"},{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"wards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]; + contract = new web3.eth.Contract(abi_contract, dai_token_address) + + }); + + + describe("tests", function(){ + it("testing_balance", async function(){ + + await aave_token_contract.connect(account_with_funds).approve(my_account.address,value); + await aave_token_contract.connect(my_account).transferFrom(account_with_funds.address,my_account.address,value); + + expect(await aave_token_contract.balanceOf(my_account.address)).to.equal(value); + expect(await aave_token_contract.balanceOf(our_deployed_contract.address)).to.equal(0); + + // Some Account with the funds gave my account some funds and now those funds will be deposited to our deployed contract using "depositWithPermit" function + }); + + + it("creating hash, signing, calling permit, transfer", async function(){ + + //getting the parameters which will be used to generate data hash + let PERMIT_TYPEHASH = await contract.methods.PERMIT_TYPEHASH().call(); + let currentValidNonce = await contract.methods.nonces(my_account.address).call(); + let DOMAIN_SEPARATOR = await contract.methods.DOMAIN_SEPARATOR().call(); + + // generating the hash to sign using private key, the hash will be similar to the one that will be sent as a message in permit function + const encoded = web3.eth.abi.encodeParameters(['bytes32', 'address', 'address', 'uint256', 'uint256', 'bool'],[PERMIT_TYPEHASH, my_account.address, our_deployed_contract.address, currentValidNonce, deadline, true]); + 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); + + + //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)); + + + //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"); + }); + + + }); + + }); \ No newline at end of file