-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathpermitSig.js
75 lines (62 loc) · 1.92 KB
/
permitSig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// 签名脚本
import { ethers } from "ethers";
import {} from 'dotenv/config'
// ERC20Permit 合约地址
const tokenAddress = "0x912ce59144191c1204e64559fe8253a0e49e6548";
// 读取私钥数组
const privateKeys = process.env.PRIVATE_KEYS.split(",");
// 相应的 nonce 数组
const nonces = ["Nonce_Wallet_1", "Nonce_Wallet_2"]
// 授权接收者的地址
const spenderAddress = "Your_Spender_Addr";
// 授权数量
const value = ethers.constants.MaxUint256;
console.log(value)
// 设置过期时间
const deadline = ethers.constants.MaxUint256;
async function signPermitMessage(wallet, nonce) {
const domain = {
name: "Arbitrum",
version: "1",
chainId: 42161, // Ethereum 主网的 Chain ID
verifyingContract: tokenAddress,
};
const types = {
Permit: [
{ name: "owner", type: "address" },
{ name: "spender", type: "address" },
{ name: "value", type: "uint256" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" },
],
};
const message = {
owner: wallet.address,
spender: spenderAddress,
value: value.toString(),
nonce: nonce,
deadline: deadline,
};
const signature = await wallet._signTypedData(domain, types, message);
return signature;
}
async function generatePermitSignatures() {
const signatures = [];
const vParams = [];
const rParams = [];
const sParams = [];
for (let i = 0; i < privateKeys.length; i++) {
const wallet = new ethers.Wallet(privateKeys[i]);
const signature = await signPermitMessage(wallet, nonces[i]);
const { v, r, s } = ethers.utils.splitSignature(signature);
vParams.push(v);
rParams.push(r);
sParams.push(s);
signatures.push({ signature, v, r, s });
}
return [signatures, vParams, rParams, sParams];
}
(async () => {
const [signatures,vParams, rParams, sParams] = await generatePermitSignatures();
console.log("Permit Signatures:", signatures);
})();