@cowprotocol/permit-utils 3.2.1 → 3.2.3
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/abi/erc20.d.ts +47 -0
- package/const.d.ts +4 -6
- package/consts/1inchPermitUtils.d.ts +69 -13
- package/index.cjs +1 -1
- package/index.d.ts +1 -1
- package/index.js +421 -338
- package/lib/getPermitUtilsInstance.d.ts +23 -2
- package/package.json +4 -12
- package/types.d.ts +14 -12
- package/utils/PermitProviderConnector.d.ts +9 -10
- package/utils/buildPermitCallData.d.ts +3 -2
- package/utils/getEip712Domain.d.ts +3 -2
- package/utils/getTokenName.d.ts +3 -2
- package/utils/getTokenPermitVersion.d.ts +3 -2
- package/utils/getContract.d.ts +0 -3
package/index.js
CHANGED
|
@@ -1,276 +1,320 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { defaultAbiCoder as w } from "@ethersproject/abi";
|
|
6
|
-
import { BigNumber as B } from "@ethersproject/bignumber";
|
|
7
|
-
import { Contract as K } from "@ethersproject/contracts";
|
|
1
|
+
import { maxUint256 as U, bytesToHex as x, encodeFunctionData as O, decodeAbiParameters as w, toHex as H, createWalletClient as F, http as G, erc20Abi as j } from "viem";
|
|
2
|
+
import { privateKeyToAccount as B } from "viem/accounts";
|
|
3
|
+
import { PERMIT_HOOK_DAPP_ID as K } from "@cowprotocol/hook-dapp-lib";
|
|
4
|
+
import { estimateGas as R, readContract as E } from "wagmi/actions";
|
|
8
5
|
import { getTokenId as V } from "@cowprotocol/cow-sdk";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
name: m
|
|
6
|
+
const q = "0xa50dc0f7fc051309434deb3b1c71e927dbb711759231d8ecbf630c85d94a42fe", k = B(q), W = 55000n, P = 80000n, L = U, z = 157788e6;
|
|
7
|
+
async function ke(a, n, e, r, t, i, {
|
|
8
|
+
version: s,
|
|
9
|
+
type: o,
|
|
10
|
+
name: d
|
|
15
11
|
}) {
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
12
|
+
const l = d || t;
|
|
13
|
+
if (o === "unsupported")
|
|
18
14
|
return !1;
|
|
19
|
-
if (!
|
|
20
|
-
throw new Error(`No token name for ${
|
|
21
|
-
const
|
|
22
|
-
chainId:
|
|
23
|
-
tokenName:
|
|
24
|
-
tokenAddress:
|
|
25
|
-
callData:
|
|
26
|
-
version:
|
|
15
|
+
if (!l)
|
|
16
|
+
throw new Error(`No token name for ${r}`);
|
|
17
|
+
const m = {
|
|
18
|
+
chainId: n,
|
|
19
|
+
tokenName: l,
|
|
20
|
+
tokenAddress: r,
|
|
21
|
+
callData: i,
|
|
22
|
+
version: s
|
|
27
23
|
};
|
|
28
|
-
let
|
|
29
|
-
if (
|
|
30
|
-
...
|
|
24
|
+
let c;
|
|
25
|
+
if (i.startsWith(T) ? c = e.recoverPermitOwnerFromCallData({
|
|
26
|
+
...m,
|
|
31
27
|
// I don't know why this was removed, ok?
|
|
32
28
|
// We added it back on buildPermitCallData.ts
|
|
33
29
|
// But it looks like this is needed 🤷
|
|
34
30
|
// Check the test for this method https://github.com/1inch/permit-signed-approvals-utils/blob/master/src/eip-2612-permit.test.ts#L85-L106
|
|
35
|
-
callData:
|
|
36
|
-
}) :
|
|
37
|
-
...
|
|
38
|
-
callData:
|
|
39
|
-
})), !!
|
|
31
|
+
callData: i.replace(T, "0x")
|
|
32
|
+
}) : i.startsWith(b) && (c = e.recoverDaiLikePermitOwnerFromCallData({
|
|
33
|
+
...m,
|
|
34
|
+
callData: i.replace(b, "0x")
|
|
35
|
+
})), !!c)
|
|
40
36
|
try {
|
|
41
|
-
return (await
|
|
37
|
+
return (await c).toLowerCase() === a.toLowerCase();
|
|
42
38
|
} catch (p) {
|
|
43
|
-
|
|
39
|
+
console.debug(`[checkHasValidPendingPermit] Failed to check permit validity for owner ${a} with callData ${i}`, p);
|
|
40
|
+
return;
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
|
-
async function
|
|
47
|
-
eip2612Utils:
|
|
48
|
-
callDataParams:
|
|
43
|
+
async function N({
|
|
44
|
+
eip2612Utils: a,
|
|
45
|
+
callDataParams: n
|
|
49
46
|
}) {
|
|
50
|
-
const [e,
|
|
51
|
-
return (await
|
|
47
|
+
const [e, r, t, ...i] = n;
|
|
48
|
+
return (await a.buildPermitCallData(e, r, t, ...i)).replace("0x", T);
|
|
52
49
|
}
|
|
53
|
-
async function
|
|
54
|
-
eip2612Utils:
|
|
55
|
-
callDataParams:
|
|
50
|
+
async function $({
|
|
51
|
+
eip2612Utils: a,
|
|
52
|
+
callDataParams: n
|
|
56
53
|
}) {
|
|
57
|
-
return (await
|
|
54
|
+
return (await a.buildDaiLikePermitCallData(...n)).replace("0x", b);
|
|
55
|
+
}
|
|
56
|
+
function C() {
|
|
57
|
+
return Math.ceil((Date.now() + z) / 1e3);
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
return
|
|
59
|
+
function J(a) {
|
|
60
|
+
return !!a && a.type !== "unsupported";
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const I = {}, Q = [4001, -32e3], Y = ["user denied", "user rejected", "rejected transaction", "transaction was rejected"];
|
|
63
|
+
function X(a) {
|
|
64
|
+
if (!a) return !1;
|
|
65
|
+
if (Q.includes(a.code)) return !0;
|
|
66
|
+
const n = (typeof a == "string" ? a : a.message)?.toLowerCase() || "";
|
|
67
|
+
return Y.some((e) => n.includes(e));
|
|
64
68
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const r = Y(n), e = b[r];
|
|
69
|
+
async function Ce(a) {
|
|
70
|
+
const n = te(a), e = I[n];
|
|
68
71
|
if (e)
|
|
69
72
|
return await e;
|
|
70
|
-
const
|
|
73
|
+
const r = Z(a).catch((t) => {
|
|
74
|
+
if (X(t))
|
|
75
|
+
throw t;
|
|
71
76
|
console.debug("[generatePermitHook] cached request failed", t);
|
|
72
77
|
}).finally(() => {
|
|
73
|
-
delete
|
|
78
|
+
delete I[n];
|
|
74
79
|
});
|
|
75
|
-
return
|
|
80
|
+
return I[n] = r, r;
|
|
76
81
|
}
|
|
77
|
-
async function
|
|
82
|
+
async function Z(a) {
|
|
78
83
|
const {
|
|
79
|
-
inputToken:
|
|
84
|
+
inputToken: n,
|
|
80
85
|
spender: e,
|
|
81
|
-
chainId:
|
|
86
|
+
chainId: r,
|
|
82
87
|
permitInfo: t,
|
|
83
|
-
|
|
84
|
-
account:
|
|
85
|
-
eip2612Utils:
|
|
86
|
-
nonce:
|
|
87
|
-
} =
|
|
88
|
-
if (!
|
|
89
|
-
throw new Error(`Trying to generate permit hook for unsupported token: ${
|
|
90
|
-
if (!
|
|
91
|
-
throw new Error(`No token name for token: ${
|
|
92
|
-
const
|
|
93
|
-
eip2612Utils:
|
|
88
|
+
config: i,
|
|
89
|
+
account: s,
|
|
90
|
+
eip2612Utils: o,
|
|
91
|
+
nonce: d
|
|
92
|
+
} = a, l = n.address, m = t.name || n.name;
|
|
93
|
+
if (!J(t))
|
|
94
|
+
throw new Error(`Trying to generate permit hook for unsupported token: ${l}`);
|
|
95
|
+
if (!m)
|
|
96
|
+
throw new Error(`No token name for token: ${l}`);
|
|
97
|
+
const c = s || k.address, p = d === void 0 ? await o.getTokenNonce(l, c) : d, y = C(), h = a.amount || L, u = t.type === "eip-2612" ? await N({
|
|
98
|
+
eip2612Utils: o,
|
|
94
99
|
callDataParams: [{
|
|
95
|
-
owner:
|
|
100
|
+
owner: c,
|
|
96
101
|
spender: e,
|
|
97
|
-
value:
|
|
102
|
+
value: h.toString(),
|
|
98
103
|
nonce: p,
|
|
99
104
|
deadline: y
|
|
100
|
-
},
|
|
101
|
-
}) : await
|
|
102
|
-
eip2612Utils:
|
|
105
|
+
}, r, m, l, t.version]
|
|
106
|
+
}) : await $({
|
|
107
|
+
eip2612Utils: o,
|
|
103
108
|
callDataParams: [{
|
|
104
|
-
holder:
|
|
109
|
+
holder: c,
|
|
105
110
|
spender: e,
|
|
106
111
|
allowed: !0,
|
|
107
|
-
value:
|
|
112
|
+
value: h.toString(),
|
|
108
113
|
nonce: p,
|
|
109
114
|
expiry: y
|
|
110
|
-
},
|
|
111
|
-
}),
|
|
115
|
+
}, r, m, l, t.version]
|
|
116
|
+
}), f = await ee({
|
|
117
|
+
data: u,
|
|
118
|
+
from: c,
|
|
119
|
+
to: l,
|
|
120
|
+
config: i,
|
|
121
|
+
isUserAccount: !!s
|
|
122
|
+
});
|
|
112
123
|
return {
|
|
113
|
-
target:
|
|
114
|
-
callData:
|
|
115
|
-
gasLimit:
|
|
116
|
-
dappId:
|
|
124
|
+
target: l,
|
|
125
|
+
callData: u,
|
|
126
|
+
gasLimit: f.toString(),
|
|
127
|
+
dappId: K
|
|
117
128
|
};
|
|
118
129
|
}
|
|
119
|
-
async function
|
|
130
|
+
async function ee({
|
|
131
|
+
data: a,
|
|
132
|
+
from: n,
|
|
133
|
+
to: e,
|
|
134
|
+
config: r,
|
|
135
|
+
isUserAccount: t
|
|
136
|
+
}) {
|
|
120
137
|
try {
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}),
|
|
126
|
-
return
|
|
127
|
-
} catch (
|
|
128
|
-
return console.debug("[calculatePermitGasLimit] Failed to estimateGas, using default",
|
|
138
|
+
const i = await R(r, {
|
|
139
|
+
account: n,
|
|
140
|
+
to: e,
|
|
141
|
+
data: a
|
|
142
|
+
}), s = t ? i : i + i / 10n;
|
|
143
|
+
return s > P ? s : P;
|
|
144
|
+
} catch (i) {
|
|
145
|
+
return console.debug("[calculatePermitGasLimit] Failed to estimateGas, using default", i), P;
|
|
129
146
|
}
|
|
130
147
|
}
|
|
131
|
-
function
|
|
148
|
+
function te(a) {
|
|
132
149
|
const {
|
|
133
|
-
inputToken:
|
|
150
|
+
inputToken: n,
|
|
134
151
|
chainId: e,
|
|
135
|
-
account:
|
|
152
|
+
account: r,
|
|
136
153
|
amount: t
|
|
137
|
-
} =
|
|
138
|
-
return `${
|
|
154
|
+
} = a;
|
|
155
|
+
return `${n.address.toLowerCase()}-${e}${r ? `-${r.toLowerCase()}` : ""}${t ? `-${t.toString()}` : ""}`;
|
|
139
156
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
class J {
|
|
144
|
-
constructor(r, e) {
|
|
145
|
-
this.provider = r, this.walletSigner = e;
|
|
157
|
+
class ne {
|
|
158
|
+
constructor(n, e) {
|
|
159
|
+
this.publicClient = n, this.walletClient = e;
|
|
146
160
|
}
|
|
147
|
-
contractEncodeABI(
|
|
148
|
-
|
|
161
|
+
contractEncodeABI(n, e, r, t) {
|
|
162
|
+
const i = t.map((s) => s instanceof Uint8Array ? x(s) : s);
|
|
163
|
+
return O({
|
|
164
|
+
abi: n,
|
|
165
|
+
functionName: r,
|
|
166
|
+
args: i
|
|
167
|
+
});
|
|
149
168
|
}
|
|
150
|
-
signTypedData(
|
|
151
|
-
const t = Object.
|
|
152
|
-
return
|
|
169
|
+
signTypedData(n, e, r) {
|
|
170
|
+
const t = Object.fromEntries(Object.entries(e.types).filter(([s]) => s !== "EIP712Domain")), i = this.walletClient.account ?? n;
|
|
171
|
+
return this.walletClient.signTypedData({
|
|
172
|
+
account: i,
|
|
173
|
+
domain: e.domain,
|
|
174
|
+
types: t,
|
|
175
|
+
primaryType: e.primaryType,
|
|
176
|
+
message: e.message
|
|
177
|
+
});
|
|
153
178
|
}
|
|
154
|
-
ethCall(
|
|
155
|
-
return this.
|
|
156
|
-
to:
|
|
179
|
+
ethCall(n, e) {
|
|
180
|
+
return this.publicClient.call({
|
|
181
|
+
to: n,
|
|
157
182
|
data: e
|
|
158
|
-
})
|
|
183
|
+
}).then(({
|
|
184
|
+
data: r
|
|
185
|
+
}) => r || "0x");
|
|
159
186
|
}
|
|
160
|
-
decodeABIParameter(
|
|
161
|
-
|
|
187
|
+
decodeABIParameter(n, e) {
|
|
188
|
+
const [r] = w([{
|
|
189
|
+
type: n
|
|
190
|
+
}], e);
|
|
191
|
+
return r;
|
|
162
192
|
}
|
|
163
|
-
decodeABIParameters(
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
B.isBigNumber(i) ? t[o] = i.toHexString() : t[o] = i;
|
|
170
|
-
}), t;
|
|
171
|
-
}
|
|
172
|
-
return a;
|
|
193
|
+
decodeABIParameters(n, e) {
|
|
194
|
+
const r = w(n, e), t = {};
|
|
195
|
+
return n.forEach((i, s) => {
|
|
196
|
+
const o = r[s], d = typeof o == "bigint" ? H(o) : o;
|
|
197
|
+
t[s] = d, i.name && (t[i.name] = d);
|
|
198
|
+
}), t;
|
|
173
199
|
}
|
|
174
200
|
}
|
|
175
|
-
const v = /* @__PURE__ */ new Map(),
|
|
176
|
-
async function
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
201
|
+
const v = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map();
|
|
202
|
+
async function ae({
|
|
203
|
+
chainId: a,
|
|
204
|
+
publicClient: n,
|
|
205
|
+
account: e,
|
|
206
|
+
walletClient: r
|
|
207
|
+
}) {
|
|
208
|
+
const t = v.get(a);
|
|
209
|
+
if (!e && t)
|
|
210
|
+
return t;
|
|
211
|
+
const i = `${a}-${e}`, s = D.get(i);
|
|
212
|
+
if (s)
|
|
213
|
+
return s;
|
|
214
|
+
let o;
|
|
215
|
+
if (!e)
|
|
216
|
+
o = F({
|
|
217
|
+
account: k,
|
|
218
|
+
chain: n.chain,
|
|
219
|
+
transport: G()
|
|
220
|
+
});
|
|
221
|
+
else if (r)
|
|
222
|
+
o = r;
|
|
223
|
+
else
|
|
224
|
+
throw new Error("Permit signing needs an active wallet client. Reconnect your wallet or use an injected extension.");
|
|
225
|
+
const d = new ne(n, o), l = await import("./1inchPermitUtils-CXu6m1-9.js").then((c) => c.Eip2612PermitUtils), m = new l(d, {
|
|
184
226
|
enabledCheckSalt: !0
|
|
185
227
|
});
|
|
186
|
-
return e ?
|
|
228
|
+
return e ? D.set(i, m) : v.set(a, m), m;
|
|
187
229
|
}
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
230
|
+
const re = [{
|
|
231
|
+
constant: !0,
|
|
232
|
+
inputs: [],
|
|
233
|
+
name: "name",
|
|
234
|
+
outputs: [{
|
|
235
|
+
name: "",
|
|
236
|
+
type: "string"
|
|
237
|
+
}],
|
|
238
|
+
payable: !1,
|
|
239
|
+
stateMutability: "view",
|
|
240
|
+
type: "function"
|
|
241
|
+
}, {
|
|
242
|
+
inputs: [],
|
|
243
|
+
name: "eip712Domain",
|
|
244
|
+
outputs: [{
|
|
245
|
+
internalType: "bytes1",
|
|
246
|
+
name: "fields",
|
|
247
|
+
type: "bytes1"
|
|
248
|
+
}, {
|
|
249
|
+
internalType: "string",
|
|
192
250
|
name: "name",
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
type: "
|
|
202
|
-
},
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
internalType: "bytes32",
|
|
234
|
-
name: "salt",
|
|
235
|
-
type: "bytes32"
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
internalType: "uint256[]",
|
|
239
|
-
name: "extensions",
|
|
240
|
-
type: "uint256[]"
|
|
241
|
-
}
|
|
242
|
-
],
|
|
243
|
-
stateMutability: "view",
|
|
244
|
-
type: "function"
|
|
245
|
-
}
|
|
246
|
-
];
|
|
247
|
-
async function Z(n, r, e) {
|
|
248
|
-
const a = S(n), o = await T(a, M, e).callStatic.eip712Domain();
|
|
249
|
-
return ee(o, r, n);
|
|
251
|
+
type: "string"
|
|
252
|
+
}, {
|
|
253
|
+
internalType: "string",
|
|
254
|
+
name: "version",
|
|
255
|
+
type: "string"
|
|
256
|
+
}, {
|
|
257
|
+
internalType: "uint256",
|
|
258
|
+
name: "chainId",
|
|
259
|
+
type: "uint256"
|
|
260
|
+
}, {
|
|
261
|
+
internalType: "address",
|
|
262
|
+
name: "verifyingContract",
|
|
263
|
+
type: "address"
|
|
264
|
+
}, {
|
|
265
|
+
internalType: "bytes32",
|
|
266
|
+
name: "salt",
|
|
267
|
+
type: "bytes32"
|
|
268
|
+
}, {
|
|
269
|
+
internalType: "uint256[]",
|
|
270
|
+
name: "extensions",
|
|
271
|
+
type: "uint256[]"
|
|
272
|
+
}],
|
|
273
|
+
stateMutability: "view",
|
|
274
|
+
type: "function"
|
|
275
|
+
}];
|
|
276
|
+
async function ie(a, n, e) {
|
|
277
|
+
const [r, t, i, s, o, d, l] = await E(e, {
|
|
278
|
+
abi: re,
|
|
279
|
+
address: a,
|
|
280
|
+
functionName: "eip712Domain"
|
|
281
|
+
}), m = {
|
|
282
|
+
fields: r,
|
|
283
|
+
name: t,
|
|
284
|
+
version: i,
|
|
285
|
+
chainId: s.toString(),
|
|
286
|
+
verifyingContract: o,
|
|
287
|
+
salt: d,
|
|
288
|
+
extensions: l.map((c) => String(c))
|
|
289
|
+
};
|
|
290
|
+
return oe(m, n, a);
|
|
250
291
|
}
|
|
251
|
-
async function
|
|
292
|
+
async function oe(a, n, e) {
|
|
252
293
|
const {
|
|
253
|
-
extensions:
|
|
294
|
+
extensions: r,
|
|
254
295
|
...t
|
|
255
|
-
} =
|
|
256
|
-
if (
|
|
296
|
+
} = a;
|
|
297
|
+
if (r.length > 0)
|
|
257
298
|
throw Error("Extensions not implemented");
|
|
258
|
-
if (t.chainId &&
|
|
259
|
-
throw Error(`ChainId mismatch. Received: '${t.chainId}', expected: '${
|
|
299
|
+
if (t.chainId && n !== parseInt(t.chainId, 16))
|
|
300
|
+
throw Error(`ChainId mismatch. Received: '${t.chainId}', expected: '${n}'`);
|
|
260
301
|
if (t.verifyingContract && e.toLowerCase() !== t.verifyingContract.toLowerCase())
|
|
261
302
|
throw Error(`Address mismatch. Received: '${t.verifyingContract}', expected: '${e}'`);
|
|
262
|
-
return
|
|
303
|
+
return ce(t);
|
|
263
304
|
}
|
|
264
|
-
const
|
|
265
|
-
function
|
|
266
|
-
const
|
|
267
|
-
return
|
|
305
|
+
const se = ["name", "version", "chainId", "verifyingContract", "salt"];
|
|
306
|
+
function ce(a) {
|
|
307
|
+
const n = parseInt(a.fields, 16);
|
|
308
|
+
return se.reduce((e, r, t) => (n & 1 << t && (e[r] = a[r]), e), {});
|
|
268
309
|
}
|
|
269
|
-
async function
|
|
270
|
-
|
|
271
|
-
|
|
310
|
+
async function le(a, n, e) {
|
|
311
|
+
return E(e, {
|
|
312
|
+
abi: j,
|
|
313
|
+
address: a,
|
|
314
|
+
functionName: "name"
|
|
315
|
+
});
|
|
272
316
|
}
|
|
273
|
-
const
|
|
317
|
+
const ue = [[{
|
|
274
318
|
constant: !0,
|
|
275
319
|
inputs: [],
|
|
276
320
|
name: "version",
|
|
@@ -293,144 +337,156 @@ const ae = [[{
|
|
|
293
337
|
stateMutability: "view",
|
|
294
338
|
type: "function"
|
|
295
339
|
}]];
|
|
296
|
-
async function
|
|
297
|
-
const
|
|
298
|
-
if (!
|
|
340
|
+
async function M(a, n, e = 0) {
|
|
341
|
+
const r = ue[e];
|
|
342
|
+
if (!r)
|
|
299
343
|
return "1";
|
|
300
344
|
try {
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
345
|
+
const t = await E(n, {
|
|
346
|
+
abi: r,
|
|
347
|
+
address: a,
|
|
348
|
+
functionName: r[0].name
|
|
304
349
|
});
|
|
305
|
-
|
|
350
|
+
if (t === "0x" || Number.isNaN(Number(t)))
|
|
351
|
+
return "1";
|
|
352
|
+
if (!t.startsWith("0x"))
|
|
353
|
+
return t;
|
|
354
|
+
const [i] = w([{
|
|
355
|
+
type: "string"
|
|
356
|
+
}], t);
|
|
357
|
+
return i;
|
|
306
358
|
} catch {
|
|
307
|
-
return
|
|
359
|
+
return M(a, n, e + 1);
|
|
308
360
|
}
|
|
309
361
|
}
|
|
310
|
-
const
|
|
362
|
+
const de = {
|
|
311
363
|
nonce: 0,
|
|
312
|
-
deadline:
|
|
313
|
-
},
|
|
364
|
+
deadline: C()
|
|
365
|
+
}, me = {
|
|
314
366
|
allowed: !0,
|
|
315
367
|
nonce: 0,
|
|
316
|
-
expiry:
|
|
317
|
-
},
|
|
368
|
+
expiry: C()
|
|
369
|
+
}, A = {}, g = {
|
|
318
370
|
type: "unsupported"
|
|
319
371
|
};
|
|
320
|
-
async function
|
|
372
|
+
async function _e(a) {
|
|
321
373
|
const {
|
|
322
|
-
tokenAddress:
|
|
374
|
+
tokenAddress: n,
|
|
323
375
|
chainId: e
|
|
324
|
-
} =
|
|
325
|
-
address:
|
|
376
|
+
} = a, r = V({
|
|
377
|
+
address: n,
|
|
326
378
|
chainId: e
|
|
327
|
-
}), t =
|
|
379
|
+
}), t = A[r];
|
|
328
380
|
if (t)
|
|
329
381
|
return t;
|
|
330
|
-
const
|
|
331
|
-
return
|
|
382
|
+
const i = pe(a);
|
|
383
|
+
return A[r] = i, i;
|
|
332
384
|
}
|
|
333
|
-
async function
|
|
385
|
+
async function pe(a) {
|
|
334
386
|
const {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
387
|
+
amount: n,
|
|
388
|
+
chainId: e,
|
|
389
|
+
config: r,
|
|
390
|
+
minGasLimit: t,
|
|
391
|
+
publicClient: i,
|
|
392
|
+
spender: s,
|
|
393
|
+
tokenAddress: o
|
|
394
|
+
} = a, d = await ae({
|
|
395
|
+
chainId: e,
|
|
396
|
+
publicClient: i
|
|
397
|
+
}), l = k.address;
|
|
398
|
+
let m;
|
|
343
399
|
try {
|
|
344
|
-
|
|
400
|
+
m = await ie(o, e, r);
|
|
345
401
|
} catch {
|
|
346
|
-
console.debug(`[checkTokenIsPermittable] Couldn't fetch eip712domain for token ${
|
|
402
|
+
console.debug(`[checkTokenIsPermittable] Couldn't fetch eip712domain for token ${o}`);
|
|
347
403
|
}
|
|
348
|
-
let
|
|
404
|
+
let c = m?.name;
|
|
349
405
|
try {
|
|
350
|
-
|
|
351
|
-
} catch (
|
|
352
|
-
if (/ETIMEDOUT/.test(
|
|
406
|
+
c || (c = await le(o, e, r));
|
|
407
|
+
} catch (u) {
|
|
408
|
+
if (/ETIMEDOUT/.test(u) && !c)
|
|
353
409
|
return {
|
|
354
410
|
error: "Failed to fetch token name from contract. RPC connection error"
|
|
355
411
|
};
|
|
356
|
-
console.debug(`[checkTokenIsPermittable] Couldn't fetch token name from the contract for token ${
|
|
412
|
+
console.debug(`[checkTokenIsPermittable] Couldn't fetch token name from the contract for token ${o}, using provided '${c}'`, u);
|
|
357
413
|
}
|
|
358
|
-
if (!
|
|
414
|
+
if (!c)
|
|
359
415
|
return {
|
|
360
|
-
error: `Token name could not be determined for ${
|
|
416
|
+
error: `Token name could not be determined for ${o}`
|
|
361
417
|
};
|
|
362
|
-
let
|
|
418
|
+
let p;
|
|
363
419
|
try {
|
|
364
|
-
|
|
365
|
-
} catch (
|
|
366
|
-
return
|
|
420
|
+
p = await d.getTokenNonce(o, l);
|
|
421
|
+
} catch (u) {
|
|
422
|
+
return u === "nonce not supported" || u.message === "nonce is NaN" ? (console.debug(`[checkTokenIsPermittable] Not a permittable token ${o} - ${c}`, u?.message || u), {
|
|
367
423
|
...g,
|
|
368
|
-
name:
|
|
369
|
-
}) : (console.debug(`[checkTokenIsPermittable] Failed to get nonce for ${
|
|
370
|
-
error:
|
|
424
|
+
name: c
|
|
425
|
+
}) : (console.debug(`[checkTokenIsPermittable] Failed to get nonce for ${o} - ${c}`, u), {
|
|
426
|
+
error: u.message || u.toString()
|
|
371
427
|
});
|
|
372
428
|
}
|
|
373
|
-
let
|
|
374
|
-
if (
|
|
429
|
+
let y = m?.version;
|
|
430
|
+
if (y === void 0)
|
|
375
431
|
try {
|
|
376
|
-
|
|
377
|
-
} catch (
|
|
378
|
-
console.debug(`[checkTokenIsPermittable] Failed to get version for ${
|
|
432
|
+
y = await M(o, r);
|
|
433
|
+
} catch (u) {
|
|
434
|
+
console.debug(`[checkTokenIsPermittable] Failed to get version for ${o} - ${c}`, u);
|
|
379
435
|
}
|
|
380
|
-
const
|
|
381
|
-
chainId:
|
|
436
|
+
const h = {
|
|
437
|
+
chainId: e,
|
|
382
438
|
eip2612PermitUtils: d,
|
|
383
|
-
nonce:
|
|
384
|
-
spender:
|
|
385
|
-
tokenAddress:
|
|
386
|
-
tokenName:
|
|
387
|
-
walletAddress:
|
|
388
|
-
version:
|
|
389
|
-
minGasLimit:
|
|
390
|
-
amount:
|
|
439
|
+
nonce: p,
|
|
440
|
+
spender: s,
|
|
441
|
+
tokenAddress: o,
|
|
442
|
+
tokenName: c,
|
|
443
|
+
walletAddress: l,
|
|
444
|
+
version: y,
|
|
445
|
+
minGasLimit: t,
|
|
446
|
+
amount: n
|
|
391
447
|
};
|
|
392
448
|
try {
|
|
393
|
-
return await
|
|
394
|
-
...
|
|
449
|
+
return await S({
|
|
450
|
+
...h,
|
|
395
451
|
type: "eip-2612",
|
|
396
|
-
|
|
452
|
+
config: r
|
|
397
453
|
});
|
|
398
|
-
} catch (
|
|
454
|
+
} catch (u) {
|
|
399
455
|
try {
|
|
400
|
-
return await
|
|
401
|
-
...
|
|
456
|
+
return await fe(o, d) ? await S({
|
|
457
|
+
...h,
|
|
402
458
|
type: "dai-like",
|
|
403
|
-
|
|
404
|
-
}) : /invalid signature/.test(
|
|
459
|
+
config: r
|
|
460
|
+
}) : /invalid signature/.test(u) || u?.code === "UNPREDICTABLE_GAS_LIMIT" ? (console.debug(`[checkTokenIsPermittable] Token ${o} - ${c} might be permittable, but it's not supported for now. Reason:`, u?.reason), {
|
|
405
461
|
...g,
|
|
406
|
-
name:
|
|
407
|
-
}) : (console.debug(`[checkTokenIsPermittable] Failed to estimate eip-2612 permit for ${
|
|
408
|
-
error:
|
|
462
|
+
name: c
|
|
463
|
+
}) : (console.debug(`[checkTokenIsPermittable] Failed to estimate eip-2612 permit for ${o} - ${c}`, u), {
|
|
464
|
+
error: u.message || u.toString()
|
|
409
465
|
});
|
|
410
466
|
} catch (f) {
|
|
411
|
-
return console.debug(`[checkTokenIsPermittable] Failed to estimate dai-like permit for ${
|
|
467
|
+
return console.debug(`[checkTokenIsPermittable] Failed to estimate dai-like permit for ${o} - ${c}`, f), {
|
|
412
468
|
error: f.message || f.toString()
|
|
413
469
|
};
|
|
414
470
|
}
|
|
415
471
|
}
|
|
416
472
|
}
|
|
417
|
-
async function
|
|
473
|
+
async function S(a) {
|
|
418
474
|
const {
|
|
419
|
-
|
|
475
|
+
config: n,
|
|
420
476
|
walletAddress: e,
|
|
421
|
-
tokenAddress:
|
|
477
|
+
tokenAddress: r,
|
|
422
478
|
tokenName: t,
|
|
423
|
-
type:
|
|
424
|
-
version:
|
|
425
|
-
minGasLimit:
|
|
426
|
-
} =
|
|
427
|
-
return
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
})
|
|
432
|
-
type:
|
|
433
|
-
version:
|
|
479
|
+
type: i,
|
|
480
|
+
version: s,
|
|
481
|
+
minGasLimit: o = W
|
|
482
|
+
} = a, l = await (i === "eip-2612" ? ye : he)(a);
|
|
483
|
+
return l ? await R(n, {
|
|
484
|
+
to: r,
|
|
485
|
+
account: e,
|
|
486
|
+
data: l
|
|
487
|
+
}) > o ? {
|
|
488
|
+
type: i,
|
|
489
|
+
version: s,
|
|
434
490
|
name: t
|
|
435
491
|
} : {
|
|
436
492
|
...g,
|
|
@@ -440,54 +496,54 @@ async function A(n) {
|
|
|
440
496
|
name: t
|
|
441
497
|
};
|
|
442
498
|
}
|
|
443
|
-
async function
|
|
499
|
+
async function ye(a) {
|
|
444
500
|
const {
|
|
445
|
-
eip2612PermitUtils:
|
|
501
|
+
eip2612PermitUtils: n,
|
|
446
502
|
walletAddress: e,
|
|
447
|
-
spender:
|
|
503
|
+
spender: r,
|
|
448
504
|
nonce: t,
|
|
449
|
-
chainId:
|
|
450
|
-
tokenName:
|
|
451
|
-
tokenAddress:
|
|
452
|
-
version:
|
|
453
|
-
amount:
|
|
454
|
-
} =
|
|
455
|
-
return
|
|
456
|
-
eip2612Utils:
|
|
505
|
+
chainId: i,
|
|
506
|
+
tokenName: s,
|
|
507
|
+
tokenAddress: o,
|
|
508
|
+
version: d,
|
|
509
|
+
amount: l
|
|
510
|
+
} = a;
|
|
511
|
+
return N({
|
|
512
|
+
eip2612Utils: n,
|
|
457
513
|
callDataParams: [{
|
|
458
|
-
...
|
|
514
|
+
...de,
|
|
459
515
|
owner: e,
|
|
460
|
-
spender:
|
|
516
|
+
spender: r,
|
|
461
517
|
nonce: t,
|
|
462
|
-
value:
|
|
463
|
-
}, +
|
|
518
|
+
value: l ? l.toString() : L.toString()
|
|
519
|
+
}, +i, s, o, d]
|
|
464
520
|
});
|
|
465
521
|
}
|
|
466
|
-
async function
|
|
467
|
-
return await
|
|
522
|
+
async function fe(a, n) {
|
|
523
|
+
return await n.getPermitTypeHash(a) === _;
|
|
468
524
|
}
|
|
469
|
-
async function
|
|
525
|
+
async function he(a) {
|
|
470
526
|
const {
|
|
471
|
-
eip2612PermitUtils:
|
|
527
|
+
eip2612PermitUtils: n,
|
|
472
528
|
tokenAddress: e,
|
|
473
|
-
walletAddress:
|
|
529
|
+
walletAddress: r,
|
|
474
530
|
spender: t,
|
|
475
|
-
nonce:
|
|
476
|
-
chainId:
|
|
477
|
-
tokenName:
|
|
478
|
-
version:
|
|
479
|
-
} =
|
|
480
|
-
return await
|
|
481
|
-
eip2612Utils:
|
|
531
|
+
nonce: i,
|
|
532
|
+
chainId: s,
|
|
533
|
+
tokenName: o,
|
|
534
|
+
version: d
|
|
535
|
+
} = a;
|
|
536
|
+
return await n.getPermitTypeHash(e) === _ ? $({
|
|
537
|
+
eip2612Utils: n,
|
|
482
538
|
callDataParams: [{
|
|
483
|
-
...
|
|
484
|
-
holder:
|
|
539
|
+
...me,
|
|
540
|
+
holder: r,
|
|
485
541
|
spender: t,
|
|
486
|
-
nonce:
|
|
487
|
-
},
|
|
542
|
+
nonce: i
|
|
543
|
+
}, s, o, e, d]
|
|
488
544
|
}) : !1;
|
|
489
545
|
}
|
|
490
|
-
const
|
|
546
|
+
const ge = [{
|
|
491
547
|
constant: !1,
|
|
492
548
|
inputs: [{
|
|
493
549
|
internalType: "address",
|
|
@@ -527,21 +583,48 @@ const me = [{
|
|
|
527
583
|
payable: !1,
|
|
528
584
|
stateMutability: "nonpayable",
|
|
529
585
|
type: "function"
|
|
530
|
-
}],
|
|
586
|
+
}], Te = [{
|
|
587
|
+
type: "function",
|
|
588
|
+
name: "permit",
|
|
589
|
+
stateMutability: "nonpayable",
|
|
590
|
+
inputs: [{
|
|
591
|
+
name: "owner",
|
|
592
|
+
type: "address"
|
|
593
|
+
}, {
|
|
594
|
+
name: "spender",
|
|
595
|
+
type: "address"
|
|
596
|
+
}, {
|
|
597
|
+
name: "value",
|
|
598
|
+
type: "uint256"
|
|
599
|
+
}, {
|
|
600
|
+
name: "deadline",
|
|
601
|
+
type: "uint256"
|
|
602
|
+
}, {
|
|
603
|
+
name: "v",
|
|
604
|
+
type: "uint8"
|
|
605
|
+
}, {
|
|
606
|
+
name: "r",
|
|
607
|
+
type: "bytes32"
|
|
608
|
+
}, {
|
|
609
|
+
name: "s",
|
|
610
|
+
type: "bytes32"
|
|
611
|
+
}],
|
|
612
|
+
outputs: []
|
|
613
|
+
}], T = "0xd505accf", b = "0x8fcbaf0c", _ = "0xea2aa0a1be11a07ed86d755c93467f4f82362b452371d1ba94d1715123511acb", ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
531
614
|
__proto__: null,
|
|
532
|
-
DAI_EIP_2612_PERMIT_ABI:
|
|
533
|
-
DAI_LIKE_PERMIT_TYPEHASH:
|
|
534
|
-
DAI_PERMIT_SELECTOR:
|
|
535
|
-
|
|
615
|
+
DAI_EIP_2612_PERMIT_ABI: ge,
|
|
616
|
+
DAI_LIKE_PERMIT_TYPEHASH: _,
|
|
617
|
+
DAI_PERMIT_SELECTOR: b,
|
|
618
|
+
EIP_2612_PERMIT_ABI: Te,
|
|
619
|
+
EIP_2612_PERMIT_SELECTOR: T
|
|
536
620
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
537
621
|
export {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
Ce as oneInchPermitUtilsConsts
|
|
622
|
+
W as DEFAULT_MIN_GAS_LIMIT,
|
|
623
|
+
k as PERMIT_ACCOUNT,
|
|
624
|
+
ke as checkIsCallDataAValidPermit,
|
|
625
|
+
Ce as generatePermitHook,
|
|
626
|
+
ae as getPermitUtilsInstance,
|
|
627
|
+
_e as getTokenPermitInfo,
|
|
628
|
+
J as isSupportedPermitInfo,
|
|
629
|
+
ve as oneInchPermitUtilsConsts
|
|
547
630
|
};
|