@1inch/solidity-utils 1.2.8 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/js/permit.js CHANGED
@@ -1,9 +1,6 @@
1
1
  const { constants } = require('@openzeppelin/test-helpers');
2
2
  const ethSigUtil = require('eth-sig-util');
3
3
  const { fromRpcSig } = require('ethereumjs-util');
4
- const { artifacts } = require('hardhat');
5
- const ERC20Permit = artifacts.require('@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol:ERC20Permit');
6
- const ERC20PermitLikeDai = artifacts.require('DaiLikePermitMock');
7
4
 
8
5
  const defaultDeadline = constants.MAX_UINT256;
9
6
 
@@ -69,22 +66,26 @@ function buildDataLikeDai (name, version, chainId, verifyingContract, holder, sp
69
66
  };
70
67
  }
71
68
 
72
- async function getPermit (owner, ownerPrivateKey, token, tokenVersion, chainId, spender, value, deadline = defaultDeadline) {
73
- const permitContract = await ERC20Permit.at(token.address);
69
+ /*
70
+ * @param permitContract The contract object with ERC20Permit type and token address for which the permit creating.
71
+ */
72
+ async function getPermit (owner, ownerPrivateKey, permitContract, tokenVersion, chainId, spender, value, deadline = defaultDeadline) {
74
73
  const nonce = await permitContract.nonces(owner);
75
74
  const name = await permitContract.name();
76
- const data = buildData(name, tokenVersion, chainId, token.address, owner, spender, value, nonce, deadline);
75
+ const data = buildData(name, tokenVersion, chainId, permitContract.address, owner, spender, value, nonce, deadline);
77
76
  const signature = ethSigUtil.signTypedMessage(Buffer.from(trim0x(ownerPrivateKey), 'hex'), { data });
78
77
  const { v, r, s } = fromRpcSig(signature);
79
78
  const permitCall = permitContract.contract.methods.permit(owner, spender, value, deadline, v, r, s).encodeABI();
80
79
  return cutSelector(permitCall);
81
80
  }
82
81
 
83
- async function getPermitLikeDai (holder, holderPrivateKey, token, tokenVersion, chainId, spender, allowed, expiry = defaultDeadline) {
84
- const permitContract = await ERC20PermitLikeDai.at(token.address);
82
+ /*
83
+ * @param permitContract The contract object with ERC20PermitLikeDai type and token address for which the permit creating.
84
+ */
85
+ async function getPermitLikeDai (holder, holderPrivateKey, permitContract, tokenVersion, chainId, spender, allowed, expiry = defaultDeadline) {
85
86
  const nonce = await permitContract.nonces(holder);
86
87
  const name = await permitContract.name();
87
- const data = buildDataLikeDai(name, tokenVersion, chainId, token.address, holder, spender, nonce, allowed, expiry);
88
+ const data = buildDataLikeDai(name, tokenVersion, chainId, permitContract.address, holder, spender, nonce, allowed, expiry);
88
89
  const signature = ethSigUtil.signTypedMessage(Buffer.from(trim0x(holderPrivateKey), 'hex'), { data });
89
90
  const { v, r, s } = fromRpcSig(signature);
90
91
  const permitCall = permitContract.contract.methods.permit(holder, spender, nonce, expiry, allowed, v, r, s).encodeABI();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1inch/solidity-utils",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -38,7 +38,7 @@
38
38
  "solidity-utils-docify": "utils/docify.utils.js"
39
39
  },
40
40
  "scripts": {
41
- "build": "rimraf ./dist && mkdir dist && shx cp -R js ./dist/js && shx cp -R utils ./dist/utils && shx cp package.json ./dist && shx cp README.md ./dist && shx cp -R ./contracts ./dist/contracts && shx rm -rf dist/contracts/mocks dist/contracts/tests && shx mkdir -p dist/contracts/mocks && shx cp ./contracts/mocks/DaiLikePermitMock.sol dist/contracts/mocks/",
41
+ "build": "rimraf ./dist && mkdir dist && shx cp -R js ./dist/js && shx cp -R utils ./dist/utils && shx cp package.json ./dist && shx cp README.md ./dist && shx cp -R ./contracts ./dist/contracts && shx rm -rf dist/contracts/mocks dist/contracts/tests",
42
42
  "coverage": "hardhat coverage",
43
43
  "lint": "yarn run lint:js && yarn run lint:sol",
44
44
  "lint:fix": "yarn run lint:js:fix && yarn run lint:sol:fix",
@@ -1,44 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.0;
4
-
5
- import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
6
-
7
- contract DaiLikePermitMock is ERC20Permit {
8
- // bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address holder,address spender,uint256 nonce,uint256 expiry,bool allowed)");
9
- bytes32 public constant PERMIT_TYPEHASH = 0xea2aa0a1be11a07ed86d755c93467f4f82362b452371d1ba94d1715123511acb;
10
-
11
- constructor(
12
- string memory name,
13
- string memory symbol,
14
- address initialAccount,
15
- uint256 initialBalance
16
- ) payable ERC20(name, symbol) ERC20Permit(name) {
17
- _mint(initialAccount, initialBalance);
18
- }
19
-
20
- function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external
21
- {
22
- bytes32 digest =
23
- keccak256(abi.encodePacked(
24
- "\x19\x01",
25
- this.DOMAIN_SEPARATOR(),
26
- keccak256(abi.encode(PERMIT_TYPEHASH,
27
- holder,
28
- spender,
29
- nonce,
30
- expiry,
31
- allowed))
32
- ));
33
-
34
- require(holder != address(0), "Dai/invalid-address-0");
35
- require(holder == ecrecover(digest, v, r, s), "Dai/invalid-permit");
36
- // solhint-disable-next-line not-rely-on-time
37
- require(expiry == 0 || block.timestamp <= expiry, "Dai/permit-expired");
38
- require(nonce == nonces(holder), "Dai/invalid-nonce");
39
- _useNonce(holder);
40
- uint wad = allowed ? type(uint128).max : 0;
41
- _approve(holder, spender, wad);
42
- emit Approval(holder, spender, wad);
43
- }
44
- }