Skip to content

Commit

Permalink
fix deps and types
Browse files Browse the repository at this point in the history
  • Loading branch information
ZumZoom committed Oct 7, 2022
1 parent 5b4d063 commit 91cc7d2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 49 deletions.
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@
"dependencies": {
"@metamask/eth-sig-util": "4.0.1",
"@openzeppelin/contracts": "4.7.3",
"bn.js": "5.2.1",
"chai": "4.3.6",
"chai-as-promised": "7.1.1",
"chai-bn": "0.3.1",
"ethereumjs-util": "7.1.5",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-beta.24"
"ethers": "5.7.1"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "1.0.3",
Expand All @@ -46,14 +41,14 @@
"@typechain/hardhat": "6.1.3",
"@typechain/ethers-v5": "10.1.0",
"@types/chai": "4.3.3",
"@types/chai-as-promised": "7.1.5",
"@types/eth-sig-util": "2.1.1",
"@types/ethereumjs-util": "6.1.0",
"@types/mocha": "9.1.1",
"@types/node": "18.7.21",
"@typescript-eslint/eslint-plugin": "5.38.0",
"@typescript-eslint/parser": "5.38.0",
"acquit": "1.2.1",
"chai": "4.3.6",
"commander": "9.4.0",
"create-ts-index": "1.14.0",
"cross-spawn": "7.0.3",
Expand All @@ -65,9 +60,10 @@
"eslint-plugin-promise": "6.0.1",
"eslint-plugin-standard": "5.0.0",
"ethereumjs-wallet": "1.0.2",
"ethers": "5.7.1",
"hardhat": "2.11.2",
"hardhat-gas-reporter": "1.0.9",
"prettier": "2.7.1",
"prettier-plugin-solidity": "1.0.0-beta.24",
"rimraf": "3.0.2",
"shx": "0.3.4",
"solhint": "3.3.7",
Expand Down
18 changes: 6 additions & 12 deletions src/permit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { SignTypedDataVersion, TypedDataUtils } from '@metamask/eth-sig-util';
import { fromRpcSig } from 'ethereumjs-util';
import { Token } from './utils';
import { constants } from './prelude';
import { CallOverrides, BigNumber } from 'ethers';
import { Contract } from 'ethers';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { splitSignature } from 'ethers/lib/utils';

export const TypedDataVersion = SignTypedDataVersion.V4;
export const defaultDeadline = constants.MAX_UINT256;
Expand Down Expand Up @@ -92,17 +91,12 @@ export function buildDataLikeDai(
} as const;
}

export interface PermittableToken extends Token {
nonces(owner: string, overrides?: CallOverrides): Promise<BigNumber>;
name(overrides?: CallOverrides): Promise<string>;
}

/*
* @param permitContract The contract object with ERC20Permit type and token address for which the permit creating.
*/
export async function getPermit(
owner: SignerWithAddress,
permitContract: PermittableToken,
permitContract: Contract,
tokenVersion: string,
chainId: number,
spender: string,
Expand All @@ -123,7 +117,7 @@ export async function getPermit(
deadline,
);
const signature = await owner._signTypedData(data.domain, data.types, data.message);
const { v, r, s } = fromRpcSig(signature);
const { v, r, s } = splitSignature(signature);
const permitCall = permitContract.interface.encodeFunctionData('permit', [
owner.address,
spender,
Expand All @@ -141,7 +135,7 @@ export async function getPermit(
*/
export async function getPermitLikeDai(
holder: SignerWithAddress,
permitContract: PermittableToken,
permitContract: Contract,
tokenVersion: string,
chainId: number,
spender: string,
Expand All @@ -162,7 +156,7 @@ export async function getPermitLikeDai(
expiry,
);
const signature = await holder._signTypedData(data.domain, data.types, data.message);
const { v, r, s } = fromRpcSig(signature);
const { v, r, s } = splitSignature(signature);
const permitCall = permitContract.interface.encodeFunctionData(
'permit(address,address,uint256,uint256,bool,uint8,bytes32,bytes32)',
[holder.address, spender, nonce, expiry, allowed, v, r, s],
Expand Down
8 changes: 2 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { constants } from './prelude';
import { time } from '@nomicfoundation/hardhat-network-helpers';
import { ethers } from 'hardhat';
import { BaseContract, BigNumber, Bytes, CallOverrides, ContractTransaction } from 'ethers';
import { Contract, Bytes, ContractTransaction } from 'ethers';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';

export async function timeIncreaseTo(seconds: number | string) {
Expand All @@ -10,12 +10,8 @@ export async function timeIncreaseTo(seconds: number | string) {
await time.increaseTo(seconds);
}

export interface Token extends BaseContract {
balanceOf(account: string, overrides?: CallOverrides): Promise<BigNumber>;
}

export async function trackReceivedTokenAndTx<T extends unknown[]>(
token: Token | { address: typeof constants.ZERO_ADDRESS } | { address: typeof constants.EEE_ADDRESS },
token: Contract | { address: typeof constants.ZERO_ADDRESS } | { address: typeof constants.EEE_ADDRESS },
wallet: string,
txPromise: (...args: T) => Promise<ContractTransaction>,
...args: T
Expand Down
8 changes: 4 additions & 4 deletions test/Permitable.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect } from '../src/prelude';
import { fromRpcSig } from 'ethereumjs-util';
import { defaultDeadline, buildData, buildDataLikeDai, getPermit, getPermitLikeDai } from '../src/permit';
import { ethers } from 'hardhat';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
import { cutSelector } from '../src/permit';
import { constants } from '../src/prelude';
import { splitSignature } from 'ethers/lib/utils';

const value = 42n;

Expand Down Expand Up @@ -54,7 +54,7 @@ describe('Permitable', async function () {
nonce.toString(),
);
const signature = await signer1._signTypedData(data.domain, data.types, data.message);
const { v, r, s } = fromRpcSig(signature);
const { v, r, s } = splitSignature(signature);
// spender is signer1 but in signature spender was signer2
const permit = cutSelector(
erc20PermitMock.interface.encodeFunctionData('permit', [
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('Permitable', async function () {
true,
);
const signature = await signer1._signTypedData(data.domain, data.types, data.message);
const { v, r, s } = fromRpcSig(signature);
const { v, r, s } = splitSignature(signature);

// spender is signer1 but in signature spender was signer2
const permit = cutSelector(
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('Permitable', async function () {
nonce.toString(),
);
const signature = await signer1._signTypedData(data.domain, data.types, data.message);
const { v, r, s } = fromRpcSig(signature);
const { v, r, s } = splitSignature(signature);

const permit =
'0x' +
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.publish.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig",
"exclude": ["./test", "./hardhat.*.ts", "./dist"]
"exclude": ["./test", "./dist"]
}
31 changes: 13 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@
dependencies:
"@types/node" "*"

"@types/chai-as-promised@7.1.5", "@types/chai-as-promised@^7.1.3":
"@types/chai-as-promised@^7.1.3":
version "7.1.5"
resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.5.tgz#6e016811f6c7a64f2eed823191c3a6955094e255"
integrity sha512-jStwss93SITGBwt/niYrkf2C+/1KTeZCZl1LaeezTlqppAKeoQC7jxyqYuP72sxBGKCIbw7oHgbYssIRzT5FCQ==
Expand Down Expand Up @@ -1429,16 +1429,16 @@ [email protected]:
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215"
integrity sha512-XWwnNNFCuuSQ0m3r3C4LE3EiORltHd9M05pq6FOlVeiophzRbMo50Sbz1ehl8K3Z+jw9+vmgnXefY1hz8X+2wA==

[email protected], bn.js@^5.1.2, bn.js@^5.2.0, bn.js@^5.2.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70"
integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==

bn.js@^4.11.0, bn.js@^4.11.8, bn.js@^4.11.9:
version "4.12.0"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88"
integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==

bn.js@^5.1.2, bn.js@^5.2.0, bn.js@^5.2.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70"
integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==

brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
Expand Down Expand Up @@ -1591,18 +1591,13 @@ catering@^2.1.0, catering@^2.1.1:
resolved "https://registry.yarnpkg.com/catering/-/catering-2.1.1.tgz#66acba06ed5ee28d5286133982a927de9a04b510"
integrity sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w==

chai-as-promised@7.1.1, chai-as-promised@^7.1.1:
chai-as-promised@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/chai-as-promised/-/chai-as-promised-7.1.1.tgz#08645d825deb8696ee61725dbf590c012eb00ca0"
integrity sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==
dependencies:
check-error "^1.0.2"

[email protected]:
version "0.3.1"
resolved "https://registry.yarnpkg.com/chai-bn/-/chai-bn-0.3.1.tgz#677cd3c0b58bae83ffe51604a811d0b3c6f41544"
integrity sha512-vuzEy0Cb+k8zqi2SHOmvZdRSbKcSOJfS1Nv8+6YDJIyCzfxkTCHLNRyjRIoRJ3WJtYb/c7OHjrvLoGeyO4A/gA==

[email protected]:
version "4.3.6"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.6.tgz#ffe4ba2d9fa9d6680cc0b370adae709ec9011e9c"
Expand Down Expand Up @@ -4545,7 +4540,7 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==

prettier-plugin-solidity@^1.0.0-beta.24:
[email protected]:
version "1.0.0-beta.24"
resolved "https://registry.yarnpkg.com/prettier-plugin-solidity/-/prettier-plugin-solidity-1.0.0-beta.24.tgz#67573ca87098c14f7ccff3639ddd8a4cab2a87eb"
integrity sha512-6JlV5BBTWzmDSq4kZ9PTXc3eLOX7DF5HpbqmmaF+kloyUwOZbJ12hIYsUaZh2fVgZdV2t0vWcvY6qhILhlzgqg==
Expand All @@ -4557,16 +4552,16 @@ prettier-plugin-solidity@^1.0.0-beta.24:
solidity-comments-extractor "^0.0.7"
string-width "^4.2.3"

[email protected], prettier@^2.3.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==

prettier@^1.14.3:
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==

prettier@^2.3.1, prettier@^2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==

process-nextick-args@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
Expand Down

0 comments on commit 91cc7d2

Please sign in to comment.