@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/index.js CHANGED
@@ -1,276 +1,320 @@
1
- import { MaxUint256 as x } from "@ethersproject/constants";
2
- import { Wallet as O } from "@ethersproject/wallet";
3
- import { privateKeyToAccount as F } from "viem/accounts";
4
- import { PERMIT_HOOK_DAPP_ID as G } from "@cowprotocol/hook-dapp-lib";
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
- import { getAddress as S } from "@ethersproject/address";
10
- const L = "0xa50dc0f7fc051309434deb3b1c71e927dbb711759231d8ecbf630c85d94a42fe", be = F(L), k = new O(L), j = 55e3, I = "80000", $ = x.toBigInt(), q = 157788e6;
11
- async function we(n, r, e, a, t, o, {
12
- version: i,
13
- type: d,
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 s = m || t;
17
- if (d === "unsupported")
12
+ const l = d || t;
13
+ if (o === "unsupported")
18
14
  return !1;
19
- if (!s)
20
- throw new Error(`No token name for ${a}`);
21
- const l = {
22
- chainId: r,
23
- tokenName: s,
24
- tokenAddress: a,
25
- callData: o,
26
- version: i
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 u;
29
- if (o.startsWith(h) ? u = e.recoverPermitOwnerFromCallData({
30
- ...l,
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: o.replace(h, "0x")
36
- }) : o.startsWith(P) && (u = e.recoverDaiLikePermitOwnerFromCallData({
37
- ...l,
38
- callData: o.replace(P, "0x")
39
- })), !!u)
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 u).toLowerCase() === n.toLowerCase();
37
+ return (await c).toLowerCase() === a.toLowerCase();
42
38
  } catch (p) {
43
- return console.debug(`[checkHasValidPendingPermit] Failed to check permit validity for owner ${n} with callData ${o}`, p), !1;
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 R({
47
- eip2612Utils: n,
48
- callDataParams: r
43
+ async function N({
44
+ eip2612Utils: a,
45
+ callDataParams: n
49
46
  }) {
50
- const [e, a, t, ...o] = r;
51
- return (await n.buildPermitCallData(e, a, t, ...o)).replace("0x", h);
47
+ const [e, r, t, ...i] = n;
48
+ return (await a.buildPermitCallData(e, r, t, ...i)).replace("0x", T);
52
49
  }
53
- async function N({
54
- eip2612Utils: n,
55
- callDataParams: r
50
+ async function $({
51
+ eip2612Utils: a,
52
+ callDataParams: n
56
53
  }) {
57
- return (await n.buildDaiLikePermitCallData(...r)).replace("0x", P);
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 E() {
60
- return Math.ceil((Date.now() + q) / 1e3);
59
+ function J(a) {
60
+ return !!a && a.type !== "unsupported";
61
61
  }
62
- function W(n) {
63
- return !!n && n.type !== "unsupported";
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
- const b = {};
66
- async function ke(n) {
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 a = Q(n).catch((t) => {
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 b[r];
78
+ delete I[n];
74
79
  });
75
- return b[r] = a, a;
80
+ return I[n] = r, r;
76
81
  }
77
- async function Q(n) {
82
+ async function Z(a) {
78
83
  const {
79
- inputToken: r,
84
+ inputToken: n,
80
85
  spender: e,
81
- chainId: a,
86
+ chainId: r,
82
87
  permitInfo: t,
83
- provider: o,
84
- account: i,
85
- eip2612Utils: d,
86
- nonce: m
87
- } = n, s = r.address, l = t.name || r.name;
88
- if (!W(t))
89
- throw new Error(`Trying to generate permit hook for unsupported token: ${s}`);
90
- if (!l)
91
- throw new Error(`No token name for token: ${s}`);
92
- const u = i || k.address, p = m === void 0 ? await d.getTokenNonce(s, u) : m, y = E(), c = n.amount || $, f = t.type === "eip-2612" ? await R({
93
- eip2612Utils: d,
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: u,
100
+ owner: c,
96
101
  spender: e,
97
- value: c.toString(),
102
+ value: h.toString(),
98
103
  nonce: p,
99
104
  deadline: y
100
- }, a, l, s, t.version]
101
- }) : await N({
102
- eip2612Utils: d,
105
+ }, r, m, l, t.version]
106
+ }) : await $({
107
+ eip2612Utils: o,
103
108
  callDataParams: [{
104
- holder: u,
109
+ holder: c,
105
110
  spender: e,
106
111
  allowed: !0,
107
- value: c.toString(),
112
+ value: h.toString(),
108
113
  nonce: p,
109
114
  expiry: y
110
- }, a, l, s, t.version]
111
- }), H = await z(f, u, s, o, !!i);
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: s,
114
- callData: f,
115
- gasLimit: H,
116
- dappId: G
124
+ target: l,
125
+ callData: u,
126
+ gasLimit: f.toString(),
127
+ dappId: K
117
128
  };
118
129
  }
119
- async function z(n, r, e, a, t) {
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 o = await a.estimateGas({
122
- data: n,
123
- from: r,
124
- to: e
125
- }), i = t ? o : o.add(o.div(10));
126
- return i.gt(I) ? i.toString() : I;
127
- } catch (o) {
128
- return console.debug("[calculatePermitGasLimit] Failed to estimateGas, using default", o), I;
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 Y(n) {
148
+ function te(a) {
132
149
  const {
133
- inputToken: r,
150
+ inputToken: n,
134
151
  chainId: e,
135
- account: a,
152
+ account: r,
136
153
  amount: t
137
- } = n;
138
- return `${r.address.toLowerCase()}-${e}${a ? `-${a.toLowerCase()}` : ""}${t ? `-${t.toString()}` : ""}`;
154
+ } = a;
155
+ return `${n.address.toLowerCase()}-${e}${r ? `-${r.toLowerCase()}` : ""}${t ? `-${t.toString()}` : ""}`;
139
156
  }
140
- function T(n, r, e) {
141
- return new K(n, r, e);
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(r, e, a, t) {
148
- return T(e || "", r, this.provider).interface.encodeFunctionData(a, t);
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(r, e, a) {
151
- const t = Object.keys(e.types).reduce((i, d) => (d !== "EIP712Domain" && (i[d] = e.types[d]), i), {});
152
- return (this.walletSigner || this.provider.getSigner())._signTypedData(e.domain, t, e.message);
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(r, e) {
155
- return this.provider.call({
156
- to: r,
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(r, e) {
161
- return w.decode([r], e)[0];
187
+ decodeABIParameter(n, e) {
188
+ const [r] = w([{
189
+ type: n
190
+ }], e);
191
+ return r;
162
192
  }
163
- decodeABIParameters(r, e) {
164
- const a = w.decode(r, e);
165
- if (a && typeof a == "object") {
166
- const t = {};
167
- return Object.keys(a).forEach((o) => {
168
- const i = a[o];
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(), _ = /* @__PURE__ */ new Map();
176
- async function X(n, r, e) {
177
- const a = v.get(n);
178
- if (!e && a)
179
- return a;
180
- const t = `${n}-${e}`, o = _.get(t);
181
- if (o)
182
- return o;
183
- const i = new J(r, e ? void 0 : k), d = await import("./1inchPermitUtils-CXu6m1-9.js").then((s) => s.Eip2612PermitUtils), m = new d(i, {
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 ? (console.log(`[getPermitUtilsInstance] Set cached provider utils for chain ${n}-${e}`, m), _.set(t, m)) : (console.log(`[getPermitUtilsInstance] Set cached chain utils for chain ${n}`, m), v.set(n, m)), m;
228
+ return e ? D.set(i, m) : v.set(a, m), m;
187
229
  }
188
- const M = [
189
- {
190
- constant: !0,
191
- inputs: [],
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
- outputs: [
194
- {
195
- name: "",
196
- type: "string"
197
- }
198
- ],
199
- payable: !1,
200
- stateMutability: "view",
201
- type: "function"
202
- },
203
- {
204
- inputs: [],
205
- name: "eip712Domain",
206
- outputs: [
207
- {
208
- internalType: "bytes1",
209
- name: "fields",
210
- type: "bytes1"
211
- },
212
- {
213
- internalType: "string",
214
- name: "name",
215
- type: "string"
216
- },
217
- {
218
- internalType: "string",
219
- name: "version",
220
- type: "string"
221
- },
222
- {
223
- internalType: "uint256",
224
- name: "chainId",
225
- type: "uint256"
226
- },
227
- {
228
- internalType: "address",
229
- name: "verifyingContract",
230
- type: "address"
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 ee(n, r, e) {
292
+ async function oe(a, n, e) {
252
293
  const {
253
- extensions: a,
294
+ extensions: r,
254
295
  ...t
255
- } = n;
256
- if (a.length > 0)
296
+ } = a;
297
+ if (r.length > 0)
257
298
  throw Error("Extensions not implemented");
258
- if (t.chainId && r !== parseInt(t.chainId, 16))
259
- throw Error(`ChainId mismatch. Received: '${t.chainId}', expected: '${r}'`);
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 ne(t);
303
+ return ce(t);
263
304
  }
264
- const te = ["name", "version", "chainId", "verifyingContract", "salt"];
265
- function ne(n) {
266
- const r = parseInt(n.fields, 16);
267
- return te.reduce((e, a, t) => (r & 1 << t && (e[a] = n[a]), e), {});
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 re(n, r, e) {
270
- const a = S(n);
271
- return T(a, M, e).callStatic.name();
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 ae = [[{
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 U(n, r, e = 0) {
297
- const a = ae[e];
298
- if (!a)
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 o = T(n, a, r).interface.encodeFunctionData(a[0].name), i = await r.call({
302
- to: n,
303
- data: o
345
+ const t = await E(n, {
346
+ abi: r,
347
+ address: a,
348
+ functionName: r[0].name
304
349
  });
305
- return i === "0x" || Number.isNaN(Number(i)) ? "1" : i.startsWith("0x") ? w.decode(["string"], i).toString() : i;
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 U(n, r, e + 1);
359
+ return M(a, n, e + 1);
308
360
  }
309
361
  }
310
- const oe = {
362
+ const de = {
311
363
  nonce: 0,
312
- deadline: E()
313
- }, ie = {
364
+ deadline: C()
365
+ }, me = {
314
366
  allowed: !0,
315
367
  nonce: 0,
316
- expiry: E()
317
- }, D = {}, g = {
368
+ expiry: C()
369
+ }, A = {}, g = {
318
370
  type: "unsupported"
319
371
  };
320
- async function Ee(n) {
372
+ async function _e(a) {
321
373
  const {
322
- tokenAddress: r,
374
+ tokenAddress: n,
323
375
  chainId: e
324
- } = n, a = V({
325
- address: r,
376
+ } = a, r = V({
377
+ address: n,
326
378
  chainId: e
327
- }), t = D[a];
379
+ }), t = A[r];
328
380
  if (t)
329
381
  return t;
330
- const o = se(n);
331
- return D[a] = o, o;
382
+ const i = pe(a);
383
+ return A[r] = i, i;
332
384
  }
333
- async function se(n) {
385
+ async function pe(a) {
334
386
  const {
335
- spender: r,
336
- tokenAddress: e,
337
- chainId: a,
338
- provider: t,
339
- minGasLimit: o,
340
- amount: i
341
- } = n, d = await X(a, t), m = k.address;
342
- let s;
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
- s = await Z(e, a, t);
400
+ m = await ie(o, e, r);
345
401
  } catch {
346
- console.debug(`[checkTokenIsPermittable] Couldn't fetch eip712domain for token ${e}`);
402
+ console.debug(`[checkTokenIsPermittable] Couldn't fetch eip712domain for token ${o}`);
347
403
  }
348
- let l = s?.name;
404
+ let c = m?.name;
349
405
  try {
350
- l || (l = await re(e, a, t));
351
- } catch (c) {
352
- if (/ETIMEDOUT/.test(c) && !l)
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 ${e}, using provided '${l}'`, c);
412
+ console.debug(`[checkTokenIsPermittable] Couldn't fetch token name from the contract for token ${o}, using provided '${c}'`, u);
357
413
  }
358
- if (!l)
414
+ if (!c)
359
415
  return {
360
- error: `Token name could not be determined for ${e}`
416
+ error: `Token name could not be determined for ${o}`
361
417
  };
362
- let u;
418
+ let p;
363
419
  try {
364
- u = await d.getTokenNonce(e, m);
365
- } catch (c) {
366
- return c === "nonce not supported" || c.message === "nonce is NaN" ? (console.debug(`[checkTokenIsPermittable] Not a permittable token ${e} - ${l}`, c?.message || c), {
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: l
369
- }) : (console.debug(`[checkTokenIsPermittable] Failed to get nonce for ${e} - ${l}`, c), {
370
- error: c.message || c.toString()
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 p = s?.version;
374
- if (p === void 0)
429
+ let y = m?.version;
430
+ if (y === void 0)
375
431
  try {
376
- p = await U(e, t);
377
- } catch (c) {
378
- console.debug(`[checkTokenIsPermittable] Failed to get version for ${e} - ${l}`, c);
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 y = {
381
- chainId: a,
436
+ const h = {
437
+ chainId: e,
382
438
  eip2612PermitUtils: d,
383
- nonce: u,
384
- spender: r,
385
- tokenAddress: e,
386
- tokenName: l,
387
- walletAddress: m,
388
- version: p,
389
- minGasLimit: o,
390
- amount: i
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 A({
394
- ...y,
449
+ return await S({
450
+ ...h,
395
451
  type: "eip-2612",
396
- provider: t
452
+ config: r
397
453
  });
398
- } catch (c) {
454
+ } catch (u) {
399
455
  try {
400
- return await le(e, d) ? await A({
401
- ...y,
456
+ return await fe(o, d) ? await S({
457
+ ...h,
402
458
  type: "dai-like",
403
- provider: t
404
- }) : /invalid signature/.test(c) || c?.code === "UNPREDICTABLE_GAS_LIMIT" ? (console.debug(`[checkTokenIsPermittable] Token ${e} - ${l} might be permittable, but it's not supported for now. Reason:`, c?.reason), {
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: l
407
- }) : (console.debug(`[checkTokenIsPermittable] Failed to estimate eip-2612 permit for ${e} - ${l}`, c), {
408
- error: c.message || c.toString()
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 ${e} - ${l}`, f), {
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 A(n) {
473
+ async function S(a) {
418
474
  const {
419
- provider: r,
475
+ config: n,
420
476
  walletAddress: e,
421
- tokenAddress: a,
477
+ tokenAddress: r,
422
478
  tokenName: t,
423
- type: o,
424
- version: i,
425
- minGasLimit: d = j
426
- } = n, s = await (o === "eip-2612" ? ce : de)(n);
427
- return s ? (await r.estimateGas({
428
- data: s,
429
- from: e,
430
- to: a
431
- })).toNumber() > d ? {
432
- type: o,
433
- version: i,
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 ce(n) {
499
+ async function ye(a) {
444
500
  const {
445
- eip2612PermitUtils: r,
501
+ eip2612PermitUtils: n,
446
502
  walletAddress: e,
447
- spender: a,
503
+ spender: r,
448
504
  nonce: t,
449
- chainId: o,
450
- tokenName: i,
451
- tokenAddress: d,
452
- version: m,
453
- amount: s
454
- } = n;
455
- return R({
456
- eip2612Utils: r,
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
- ...oe,
514
+ ...de,
459
515
  owner: e,
460
- spender: a,
516
+ spender: r,
461
517
  nonce: t,
462
- value: s ? s.toString() : $.toString()
463
- }, +o, i, d, m]
518
+ value: l ? l.toString() : L.toString()
519
+ }, +i, s, o, d]
464
520
  });
465
521
  }
466
- async function le(n, r) {
467
- return await r.getPermitTypeHash(n) === C;
522
+ async function fe(a, n) {
523
+ return await n.getPermitTypeHash(a) === _;
468
524
  }
469
- async function de(n) {
525
+ async function he(a) {
470
526
  const {
471
- eip2612PermitUtils: r,
527
+ eip2612PermitUtils: n,
472
528
  tokenAddress: e,
473
- walletAddress: a,
529
+ walletAddress: r,
474
530
  spender: t,
475
- nonce: o,
476
- chainId: i,
477
- tokenName: d,
478
- version: m
479
- } = n;
480
- return await r.getPermitTypeHash(e) === C ? N({
481
- eip2612Utils: r,
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
- ...ie,
484
- holder: a,
539
+ ...me,
540
+ holder: r,
485
541
  spender: t,
486
- nonce: o
487
- }, i, d, e, m]
542
+ nonce: i
543
+ }, s, o, e, d]
488
544
  }) : !1;
489
545
  }
490
- const me = [{
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
- }], h = "0xd505accf", P = "0x8fcbaf0c", C = "0xea2aa0a1be11a07ed86d755c93467f4f82362b452371d1ba94d1715123511acb", Ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
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: me,
533
- DAI_LIKE_PERMIT_TYPEHASH: C,
534
- DAI_PERMIT_SELECTOR: P,
535
- EIP_2612_PERMIT_SELECTOR: h
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
- j as DEFAULT_MIN_GAS_LIMIT,
539
- be as PERMIT_ACCOUNT,
540
- k as PERMIT_SIGNER,
541
- we as checkIsCallDataAValidPermit,
542
- ke as generatePermitHook,
543
- X as getPermitUtilsInstance,
544
- Ee as getTokenPermitInfo,
545
- W as isSupportedPermitInfo,
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
  };