@aegis-engine/core 0.1.0 → 0.1.1
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/README.md +284 -17
- package/dist/actions/directPoolSwap.d.ts +13 -2
- package/dist/aegis-core.js +520 -568
- package/dist/config.d.ts +0 -4
- package/dist/index.d.ts +4 -4
- package/package.json +1 -1
package/dist/aegis-core.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { encodeAbiParameters as
|
|
5
|
-
import { mainnet as
|
|
1
|
+
var Pe = Object.defineProperty;
|
|
2
|
+
var ke = (e, t, n) => t in e ? Pe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var S = (e, t, n) => ke(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { encodeAbiParameters as C, keccak256 as Me, encodeFunctionData as $, getAddress as m, createWalletClient as P, custom as k, erc20Abi as q, http as Re, createPublicClient as De, fallback as Ne, isAddress as Fe } from "viem";
|
|
5
|
+
import { mainnet as Be } from "viem/chains";
|
|
6
6
|
function K(e) {
|
|
7
7
|
return (e == null ? void 0 : e.toLowerCase()) ?? "";
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function b(e, t) {
|
|
10
10
|
return e.toLowerCase() === t.toLowerCase();
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
return e === null || t === null ? e === t :
|
|
12
|
+
function Ue(e, t) {
|
|
13
|
+
return e === null || t === null ? e === t : b(e, t);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function ne(e, t) {
|
|
16
16
|
return e.toLowerCase() === t.toLowerCase();
|
|
17
17
|
}
|
|
18
|
-
const
|
|
18
|
+
const z = [
|
|
19
19
|
{
|
|
20
20
|
type: "function",
|
|
21
21
|
name: "execute",
|
|
@@ -69,7 +69,7 @@ const V = [
|
|
|
69
69
|
],
|
|
70
70
|
outputs: []
|
|
71
71
|
}
|
|
72
|
-
],
|
|
72
|
+
], oe = [
|
|
73
73
|
{
|
|
74
74
|
type: "function",
|
|
75
75
|
name: "approve",
|
|
@@ -97,7 +97,7 @@ const V = [
|
|
|
97
97
|
{ name: "nonce", type: "uint48" }
|
|
98
98
|
]
|
|
99
99
|
}
|
|
100
|
-
],
|
|
100
|
+
], J = [
|
|
101
101
|
{
|
|
102
102
|
type: "function",
|
|
103
103
|
name: "quoteExactInputSingle",
|
|
@@ -160,13 +160,13 @@ const V = [
|
|
|
160
160
|
{ name: "gasEstimate", type: "uint256" }
|
|
161
161
|
]
|
|
162
162
|
}
|
|
163
|
-
],
|
|
163
|
+
], ae = 0n, Ge = 2n ** 128n - 1n, O = {
|
|
164
164
|
SWAP_EXACT_IN_SINGLE: 6,
|
|
165
165
|
SWAP_EXACT_OUT_SINGLE: 8,
|
|
166
166
|
SETTLE: 11,
|
|
167
167
|
TAKE: 14,
|
|
168
168
|
TAKE_PORTION: 16
|
|
169
|
-
},
|
|
169
|
+
}, ie = {
|
|
170
170
|
name: "poolKey",
|
|
171
171
|
type: "tuple",
|
|
172
172
|
components: [
|
|
@@ -176,75 +176,75 @@ const V = [
|
|
|
176
176
|
{ name: "tickSpacing", type: "int24" },
|
|
177
177
|
{ name: "hooks", type: "address" }
|
|
178
178
|
]
|
|
179
|
-
},
|
|
179
|
+
}, Ke = [
|
|
180
180
|
{
|
|
181
181
|
name: "params",
|
|
182
182
|
type: "tuple",
|
|
183
183
|
components: [
|
|
184
|
-
|
|
184
|
+
ie,
|
|
185
185
|
{ name: "zeroForOne", type: "bool" },
|
|
186
186
|
{ name: "amountIn", type: "uint128" },
|
|
187
187
|
{ name: "amountOutMinimum", type: "uint128" },
|
|
188
188
|
{ name: "hookData", type: "bytes" }
|
|
189
189
|
]
|
|
190
190
|
}
|
|
191
|
-
],
|
|
191
|
+
], We = [
|
|
192
192
|
{
|
|
193
193
|
name: "params",
|
|
194
194
|
type: "tuple",
|
|
195
195
|
components: [
|
|
196
|
-
|
|
196
|
+
ie,
|
|
197
197
|
{ name: "zeroForOne", type: "bool" },
|
|
198
198
|
{ name: "amountOut", type: "uint128" },
|
|
199
199
|
{ name: "amountInMaximum", type: "uint128" },
|
|
200
200
|
{ name: "hookData", type: "bytes" }
|
|
201
201
|
]
|
|
202
202
|
}
|
|
203
|
-
],
|
|
203
|
+
], Le = [
|
|
204
204
|
{ name: "currency", type: "address" },
|
|
205
205
|
{ name: "amount", type: "uint256" },
|
|
206
206
|
{ name: "payerIsUser", type: "bool" }
|
|
207
|
-
],
|
|
207
|
+
], re = [
|
|
208
208
|
{ name: "currency", type: "address" },
|
|
209
209
|
{ name: "recipient", type: "address" },
|
|
210
210
|
{ name: "amount", type: "uint256" }
|
|
211
|
-
],
|
|
211
|
+
], $e = [
|
|
212
212
|
{ name: "currency", type: "address" },
|
|
213
213
|
{ name: "recipient", type: "address" },
|
|
214
214
|
{ name: "bips", type: "uint256" }
|
|
215
215
|
];
|
|
216
|
-
function
|
|
216
|
+
function qe(e) {
|
|
217
217
|
return `0x${e.map((t) => t.toString(16).padStart(2, "0")).join("")}`;
|
|
218
218
|
}
|
|
219
|
-
function
|
|
219
|
+
function ze(e, t) {
|
|
220
220
|
return {
|
|
221
221
|
requiresV4Unlock: !0,
|
|
222
|
-
actions:
|
|
222
|
+
actions: qe(e),
|
|
223
223
|
params: t
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
|
-
function
|
|
227
|
-
return
|
|
228
|
-
abi:
|
|
226
|
+
function Ve(e, t) {
|
|
227
|
+
return $({
|
|
228
|
+
abi: z,
|
|
229
229
|
functionName: "execute",
|
|
230
230
|
args: [e, t]
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
|
-
function
|
|
234
|
-
return
|
|
235
|
-
abi:
|
|
233
|
+
function He(e) {
|
|
234
|
+
return $({
|
|
235
|
+
abi: z,
|
|
236
236
|
functionName: "permitBatch",
|
|
237
237
|
args: [e.owner, e.permitBatch, e.signature]
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
|
-
function
|
|
241
|
-
return
|
|
242
|
-
abi:
|
|
240
|
+
function je(e) {
|
|
241
|
+
return $({
|
|
242
|
+
abi: z,
|
|
243
243
|
functionName: "multicall",
|
|
244
244
|
args: [e]
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
|
-
function
|
|
247
|
+
function Xe(e) {
|
|
248
248
|
if (!e) return !1;
|
|
249
249
|
if ("bips" in e) {
|
|
250
250
|
if (!Number.isInteger(e.bips) || e.bips < 0 || e.bips > 1e4)
|
|
@@ -253,25 +253,25 @@ function Ze(e) {
|
|
|
253
253
|
}
|
|
254
254
|
return e.amount > 0n;
|
|
255
255
|
}
|
|
256
|
-
function
|
|
256
|
+
function Qe(e, t) {
|
|
257
257
|
return "bips" in e ? {
|
|
258
258
|
action: O.TAKE_PORTION,
|
|
259
|
-
params:
|
|
259
|
+
params: C($e, [t, e.recipient, BigInt(e.bips)])
|
|
260
260
|
} : {
|
|
261
261
|
action: O.TAKE,
|
|
262
|
-
params:
|
|
262
|
+
params: C(re, [t, e.recipient, e.amount])
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
|
-
function
|
|
266
|
-
if (e < 0n || e >
|
|
265
|
+
function M(e, t = "Amount") {
|
|
266
|
+
if (e < 0n || e > Ge)
|
|
267
267
|
throw new Error(`${t} is too large for a single V4 swap.`);
|
|
268
268
|
}
|
|
269
|
-
function
|
|
270
|
-
return t ?
|
|
269
|
+
function Ye(e, t) {
|
|
270
|
+
return t ? je([He(t), e]) : e;
|
|
271
271
|
}
|
|
272
|
-
function
|
|
273
|
-
return
|
|
274
|
-
|
|
272
|
+
function ce(e) {
|
|
273
|
+
return Me(
|
|
274
|
+
C(
|
|
275
275
|
[
|
|
276
276
|
{ name: "currency0", type: "address" },
|
|
277
277
|
{ name: "currency1", type: "address" },
|
|
@@ -289,8 +289,8 @@ function ue(e) {
|
|
|
289
289
|
)
|
|
290
290
|
);
|
|
291
291
|
}
|
|
292
|
-
function
|
|
293
|
-
const t = e.zeroForOne ? e.poolKey.currency0 : e.poolKey.currency1, n = e.zeroForOne ? e.poolKey.currency1 : e.poolKey.currency0, o =
|
|
292
|
+
function ue(e) {
|
|
293
|
+
const t = e.zeroForOne ? e.poolKey.currency0 : e.poolKey.currency1, n = e.zeroForOne ? e.poolKey.currency1 : e.poolKey.currency0, o = Xe(e.fee) ? e.fee : null, a = o ? Qe(o, n) : null, i = ze(
|
|
294
294
|
[
|
|
295
295
|
e.swapAction,
|
|
296
296
|
O.SETTLE,
|
|
@@ -299,20 +299,20 @@ function le(e) {
|
|
|
299
299
|
],
|
|
300
300
|
[
|
|
301
301
|
e.encodedSwapParams,
|
|
302
|
-
|
|
302
|
+
C(Le, [t, e.settleAmount, !0]),
|
|
303
303
|
...a ? [a.params] : [],
|
|
304
|
-
|
|
304
|
+
C(re, [n, e.recipient, ae])
|
|
305
305
|
]
|
|
306
306
|
);
|
|
307
307
|
return {
|
|
308
|
-
calldata:
|
|
308
|
+
calldata: Ye(Ve([i], e.deadline), e.permit),
|
|
309
309
|
value: 0n
|
|
310
310
|
};
|
|
311
311
|
}
|
|
312
|
-
function
|
|
313
|
-
return
|
|
312
|
+
function Je(e) {
|
|
313
|
+
return M(e.amountIn, "Swap input amount"), M(e.amountOutMinimum, "Swap minimum output"), ue({
|
|
314
314
|
swapAction: O.SWAP_EXACT_IN_SINGLE,
|
|
315
|
-
encodedSwapParams:
|
|
315
|
+
encodedSwapParams: C(Ke, [
|
|
316
316
|
{
|
|
317
317
|
poolKey: e.poolKey,
|
|
318
318
|
zeroForOne: e.zeroForOne,
|
|
@@ -330,10 +330,10 @@ function tt(e) {
|
|
|
330
330
|
fee: e.fee
|
|
331
331
|
});
|
|
332
332
|
}
|
|
333
|
-
function
|
|
334
|
-
return
|
|
333
|
+
function Ze(e) {
|
|
334
|
+
return M(e.amountOut, "Swap output amount"), M(e.amountInMaximum, "Swap maximum input"), ue({
|
|
335
335
|
swapAction: O.SWAP_EXACT_OUT_SINGLE,
|
|
336
|
-
encodedSwapParams:
|
|
336
|
+
encodedSwapParams: C(We, [
|
|
337
337
|
{
|
|
338
338
|
poolKey: e.poolKey,
|
|
339
339
|
zeroForOne: e.zeroForOne,
|
|
@@ -344,39 +344,39 @@ function nt(e) {
|
|
|
344
344
|
]),
|
|
345
345
|
poolKey: e.poolKey,
|
|
346
346
|
zeroForOne: e.zeroForOne,
|
|
347
|
-
settleAmount:
|
|
347
|
+
settleAmount: ae,
|
|
348
348
|
recipient: e.recipient,
|
|
349
349
|
deadline: e.deadline,
|
|
350
350
|
permit: e.permit,
|
|
351
351
|
fee: e.fee
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
|
-
function
|
|
354
|
+
function le(e, t) {
|
|
355
355
|
var n;
|
|
356
356
|
return ((n = t.explorerTxUrl) == null ? void 0 : n.call(t, e)) ?? "#";
|
|
357
357
|
}
|
|
358
|
-
const
|
|
358
|
+
const y = 1, ge = m("0x00581261a1200956ea05d1810fF28ffd66D8E254"), On = m("0x8f29BD5c8429730fA4C46e6295c4e679eDEdd0cC"), Pn = 8388608, et = 50, pe = m(
|
|
359
359
|
"0x8ea2C7de60ef1Cd4dcE64ea2DDDe2f99F0127eFC"
|
|
360
360
|
);
|
|
361
|
-
function
|
|
361
|
+
function _(e) {
|
|
362
362
|
return e ? m(e) : void 0;
|
|
363
363
|
}
|
|
364
|
-
function
|
|
364
|
+
function I(e) {
|
|
365
365
|
if (!e.permit2 || !e.quoter)
|
|
366
366
|
throw new Error("Missing Permit2 or V4 Quoter contract address.");
|
|
367
367
|
return {
|
|
368
368
|
permit2: m(e.permit2),
|
|
369
369
|
quoter: m(e.quoter),
|
|
370
|
-
poolManager:
|
|
371
|
-
positionDescriptor:
|
|
372
|
-
positionManager:
|
|
373
|
-
stateView:
|
|
374
|
-
universalRouter:
|
|
375
|
-
universalRouterV2_1_1:
|
|
370
|
+
poolManager: _(e.poolManager),
|
|
371
|
+
positionDescriptor: _(e.positionDescriptor),
|
|
372
|
+
positionManager: _(e.positionManager),
|
|
373
|
+
stateView: _(e.stateView),
|
|
374
|
+
universalRouter: _(e.universalRouter),
|
|
375
|
+
universalRouterV2_1_1: _(e.universalRouterV2_1_1)
|
|
376
376
|
};
|
|
377
377
|
}
|
|
378
|
-
const
|
|
379
|
-
1:
|
|
378
|
+
const me = {
|
|
379
|
+
1: I({
|
|
380
380
|
poolManager: "0x000000000004444c5dc75cB358380D2e3dE08A90",
|
|
381
381
|
positionDescriptor: "0xd1428ba554f4c8450b763a0b2040a4935c63f06c",
|
|
382
382
|
positionManager: "0xbd216513d74c8cf14cf4747e6aaa6420ff64ee9e",
|
|
@@ -386,7 +386,7 @@ const de = {
|
|
|
386
386
|
universalRouterV2_1_1: "0x4c82d1fbfe28c977cbb58d8c7ff8fcf9f70a2cca",
|
|
387
387
|
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
388
388
|
}),
|
|
389
|
-
10:
|
|
389
|
+
10: I({
|
|
390
390
|
poolManager: "0x9a13f98cb987694c9f086b1f5eb990eea8264ec3",
|
|
391
391
|
positionDescriptor: "0xedd81496169c46df161b8513a52ffecaaaa66743",
|
|
392
392
|
positionManager: "0x3c3ea4b57a46241e54610e5f022e5c45859a1017",
|
|
@@ -396,7 +396,7 @@ const de = {
|
|
|
396
396
|
universalRouterV2_1_1: "0x8b844f885672f333bc0042cb669255f93a4c1e6b",
|
|
397
397
|
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
398
398
|
}),
|
|
399
|
-
130:
|
|
399
|
+
130: I({
|
|
400
400
|
poolManager: "0x1f98400000000000000000000000000000000004",
|
|
401
401
|
positionDescriptor: "0x9fb28449a191cd8c03a1b7abfb0f5996ecf7f722",
|
|
402
402
|
positionManager: "0x4529a01c7a0410167c5740c487a8de60232617bf",
|
|
@@ -406,7 +406,7 @@ const de = {
|
|
|
406
406
|
universalRouterV2_1_1: "0xfdf682f51fe81aa4898f0ae2163d8a55c127fbc7",
|
|
407
407
|
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
408
408
|
}),
|
|
409
|
-
137:
|
|
409
|
+
137: I({
|
|
410
410
|
poolManager: "0x67366782805870060151383f4bbff9dab53e5cd6",
|
|
411
411
|
positionDescriptor: "0x0892771f0c1b78ad6013d6e5536007e1c16e6794",
|
|
412
412
|
positionManager: "0x1ec2ebf4f37e7363fdfe3551602425af0b3ceef9",
|
|
@@ -416,7 +416,7 @@ const de = {
|
|
|
416
416
|
universalRouterV2_1_1: "0x8b844f885672f333bc0042cb669255f93a4c1e6b",
|
|
417
417
|
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
418
418
|
}),
|
|
419
|
-
8453:
|
|
419
|
+
8453: I({
|
|
420
420
|
poolManager: "0x498581ff718922c3f8e6a244956af099b2652b2b",
|
|
421
421
|
positionDescriptor: "0x25d093633990dc94bedeed76c8f3cdaa75f3e7d5",
|
|
422
422
|
positionManager: "0x7c5f5a4bbd8fd63184577525326123b519429bdc",
|
|
@@ -426,7 +426,7 @@ const de = {
|
|
|
426
426
|
universalRouterV2_1_1: "0xfdf682f51fe81aa4898f0ae2163d8a55c127fbc7",
|
|
427
427
|
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
428
428
|
}),
|
|
429
|
-
42161:
|
|
429
|
+
42161: I({
|
|
430
430
|
poolManager: "0x360e68faccca8ca495c1b759fd9eee466db9fb32",
|
|
431
431
|
positionDescriptor: "0xe2023f3fa515cf070e07fd9d51c1d236e07843f4",
|
|
432
432
|
positionManager: "0xd88f38f930b7952f2db2432cb002e7abbf3dd869",
|
|
@@ -436,59 +436,59 @@ const de = {
|
|
|
436
436
|
universalRouterV2_1_1: "0x8b844f885672f333bc0042cb669255f93a4c1e6b",
|
|
437
437
|
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
438
438
|
})
|
|
439
|
-
},
|
|
439
|
+
}, V = me[y], tt = V.permit2, nt = V.quoter, ot = [
|
|
440
440
|
"https://eth.drpc.org",
|
|
441
441
|
"https://ethereum-rpc.publicnode.com",
|
|
442
442
|
"https://cloudflare-eth.com"
|
|
443
|
-
],
|
|
444
|
-
chainId:
|
|
445
|
-
chain:
|
|
443
|
+
], at = "https://aegis.markets/graphql/meta", it = {
|
|
444
|
+
chainId: y,
|
|
445
|
+
chain: Be,
|
|
446
446
|
name: "Ethereum",
|
|
447
|
-
router:
|
|
448
|
-
permit2:
|
|
449
|
-
quoter:
|
|
450
|
-
v4Contracts:
|
|
451
|
-
rpcUrls:
|
|
447
|
+
router: ge,
|
|
448
|
+
permit2: tt,
|
|
449
|
+
quoter: nt,
|
|
450
|
+
v4Contracts: V,
|
|
451
|
+
rpcUrls: ot,
|
|
452
452
|
explorerTxUrl: (e) => `https://etherscan.io/tx/${e}`,
|
|
453
453
|
poolExplorerUrl: (e) => `https://app.uniswap.org/explore/pools/ethereum/${e}`,
|
|
454
|
-
metadataEndpoint:
|
|
454
|
+
metadataEndpoint: at,
|
|
455
455
|
fee: {
|
|
456
|
-
bps:
|
|
456
|
+
bps: et,
|
|
457
457
|
recipient: pe
|
|
458
458
|
}
|
|
459
|
-
},
|
|
460
|
-
[
|
|
461
|
-
},
|
|
459
|
+
}, H = {
|
|
460
|
+
[y]: it
|
|
461
|
+
}, x = {
|
|
462
462
|
USDC: {
|
|
463
|
-
chainId:
|
|
463
|
+
chainId: y,
|
|
464
464
|
address: m("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"),
|
|
465
465
|
name: "USD Coin",
|
|
466
466
|
symbol: "USDC",
|
|
467
467
|
decimals: 6
|
|
468
468
|
},
|
|
469
469
|
WATER: {
|
|
470
|
-
chainId:
|
|
470
|
+
chainId: y,
|
|
471
471
|
address: m("0x828B22c9ea1c20B551EeFC6198174C4bb7a8CBF6"),
|
|
472
472
|
name: "WATER",
|
|
473
473
|
symbol: "WATER",
|
|
474
474
|
decimals: 18
|
|
475
475
|
},
|
|
476
476
|
WOOD: {
|
|
477
|
-
chainId:
|
|
477
|
+
chainId: y,
|
|
478
478
|
address: m("0x670AfdD7226e73d3CC55B5cd83933E46aF22DECd"),
|
|
479
479
|
name: "WOOD",
|
|
480
480
|
symbol: "WOOD",
|
|
481
481
|
decimals: 18
|
|
482
482
|
},
|
|
483
483
|
GRASS: {
|
|
484
|
-
chainId:
|
|
484
|
+
chainId: y,
|
|
485
485
|
address: m("0xF06Ad052b0d8D511D0B6f00100b8e402639209EF"),
|
|
486
486
|
name: "GRASS",
|
|
487
487
|
symbol: "GRASS",
|
|
488
488
|
decimals: 18
|
|
489
489
|
},
|
|
490
490
|
STONE: {
|
|
491
|
-
chainId:
|
|
491
|
+
chainId: y,
|
|
492
492
|
address: m("0xCabcc33D9Ff7e24F413d939773D232C0d50dCc7f"),
|
|
493
493
|
name: "STONE",
|
|
494
494
|
symbol: "STONE",
|
|
@@ -498,125 +498,65 @@ const de = {
|
|
|
498
498
|
// mark stays correct even when the metadata service is unreachable.
|
|
499
499
|
iconUrl: "https://ichi-images.s3.us-east-1.amazonaws.com/tokens/logo_256_stone_2.svg"
|
|
500
500
|
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
return {
|
|
504
|
-
id: e,
|
|
505
|
-
chainId: E,
|
|
506
|
-
symbol: t,
|
|
507
|
-
poolId: n,
|
|
508
|
-
poolKey: {
|
|
509
|
-
currency0: o,
|
|
510
|
-
currency1: a,
|
|
511
|
-
fee: at,
|
|
512
|
-
tickSpacing: i,
|
|
513
|
-
hooks: ot
|
|
514
|
-
},
|
|
515
|
-
token: y[t],
|
|
516
|
-
counterToken: y.USDC,
|
|
517
|
-
router: me,
|
|
518
|
-
permit2: fe,
|
|
519
|
-
quoter: he,
|
|
520
|
-
label: `${y.USDC.symbol} / ${t}`
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
const lt = B(
|
|
524
|
-
"WATER_USDC",
|
|
525
|
-
"WATER",
|
|
526
|
-
"0x01409fc6f1bf49e20bf05df5d4dcb96ed3977ea717bc4a135e9deacd92ebc0af",
|
|
527
|
-
y.WATER.address,
|
|
528
|
-
y.USDC.address,
|
|
529
|
-
60
|
|
530
|
-
), st = B(
|
|
531
|
-
"WOOD_USDC",
|
|
532
|
-
"WOOD",
|
|
533
|
-
"0x0f8a98e3fdb7ea4438a3f7342f040cbc9d1eced1b90a876d38f3453100243356",
|
|
534
|
-
y.WOOD.address,
|
|
535
|
-
y.USDC.address,
|
|
536
|
-
60
|
|
537
|
-
), mt = B(
|
|
538
|
-
"GRASS_USDC",
|
|
539
|
-
"GRASS",
|
|
540
|
-
"0xd0194ad1f57730361b93ecf8da86e18590bd5e1f64e4a35f3a5b5bd666e48ae1",
|
|
541
|
-
y.USDC.address,
|
|
542
|
-
y.GRASS.address,
|
|
543
|
-
60
|
|
544
|
-
), pt = B(
|
|
545
|
-
"STONE_USDC",
|
|
546
|
-
"STONE",
|
|
547
|
-
"0x3fa06e44e4bee9539887681eab6b608b646784e2027ea6292198cde0690aff54",
|
|
548
|
-
y.USDC.address,
|
|
549
|
-
y.STONE.address,
|
|
550
|
-
60
|
|
551
|
-
), Un = {
|
|
552
|
-
WATER_USDC: lt,
|
|
553
|
-
WOOD_USDC: st,
|
|
554
|
-
GRASS_USDC: mt,
|
|
555
|
-
STONE_USDC: pt
|
|
556
|
-
}, Nn = [
|
|
557
|
-
"WATER_USDC",
|
|
558
|
-
"WOOD_USDC",
|
|
559
|
-
"GRASS_USDC",
|
|
560
|
-
"STONE_USDC"
|
|
561
|
-
], we = 50, ye = pe, X = {
|
|
562
|
-
USDC: y.USDC,
|
|
501
|
+
}, se = 50, de = pe, j = {
|
|
502
|
+
USDC: x.USDC,
|
|
563
503
|
USDT: {
|
|
564
|
-
chainId:
|
|
504
|
+
chainId: y,
|
|
565
505
|
address: m("0xdAC17F958D2ee523a2206206994597C13D831ec7"),
|
|
566
506
|
name: "Tether USD",
|
|
567
507
|
symbol: "USDT",
|
|
568
508
|
decimals: 6
|
|
569
509
|
},
|
|
570
510
|
WETH: {
|
|
571
|
-
chainId:
|
|
511
|
+
chainId: y,
|
|
572
512
|
address: m("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
|
573
513
|
name: "Wrapped Ether",
|
|
574
514
|
symbol: "WETH",
|
|
575
515
|
decimals: 18
|
|
576
516
|
},
|
|
577
517
|
ETH: {
|
|
578
|
-
chainId:
|
|
518
|
+
chainId: y,
|
|
579
519
|
address: m("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"),
|
|
580
520
|
name: "Ether",
|
|
581
521
|
symbol: "ETH",
|
|
582
522
|
decimals: 18
|
|
583
523
|
},
|
|
584
524
|
WBTC: {
|
|
585
|
-
chainId:
|
|
525
|
+
chainId: y,
|
|
586
526
|
address: m("0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"),
|
|
587
527
|
name: "Wrapped Bitcoin",
|
|
588
528
|
symbol: "WBTC",
|
|
589
529
|
decimals: 8
|
|
590
530
|
},
|
|
591
531
|
STETH: {
|
|
592
|
-
chainId:
|
|
532
|
+
chainId: y,
|
|
593
533
|
address: m("0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"),
|
|
594
534
|
name: "Lido Staked Ether",
|
|
595
535
|
symbol: "stETH",
|
|
596
536
|
decimals: 18
|
|
597
537
|
}
|
|
598
|
-
},
|
|
599
|
-
USDC:
|
|
600
|
-
ETH:
|
|
601
|
-
WATER:
|
|
602
|
-
WOOD:
|
|
603
|
-
GRASS:
|
|
604
|
-
STONE:
|
|
605
|
-
},
|
|
606
|
-
|
|
607
|
-
),
|
|
608
|
-
|
|
609
|
-
),
|
|
610
|
-
default:
|
|
611
|
-
wolfgame:
|
|
612
|
-
},
|
|
613
|
-
function
|
|
538
|
+
}, rt = {
|
|
539
|
+
USDC: x.USDC,
|
|
540
|
+
ETH: j.ETH,
|
|
541
|
+
WATER: x.WATER,
|
|
542
|
+
WOOD: x.WOOD,
|
|
543
|
+
GRASS: x.GRASS,
|
|
544
|
+
STONE: x.STONE
|
|
545
|
+
}, ct = Object.values(
|
|
546
|
+
j
|
|
547
|
+
), ut = Object.values(
|
|
548
|
+
rt
|
|
549
|
+
), kn = {
|
|
550
|
+
default: ct,
|
|
551
|
+
wolfgame: ut
|
|
552
|
+
}, Mn = j;
|
|
553
|
+
function Z(e) {
|
|
614
554
|
return {
|
|
615
555
|
...e,
|
|
616
556
|
address: m(e.address)
|
|
617
557
|
};
|
|
618
558
|
}
|
|
619
|
-
function
|
|
559
|
+
function lt(e) {
|
|
620
560
|
const t = m(e.currency0), n = m(e.currency1);
|
|
621
561
|
if (t.toLowerCase() >= n.toLowerCase())
|
|
622
562
|
throw new Error(
|
|
@@ -630,9 +570,9 @@ function wt(e) {
|
|
|
630
570
|
hooks: m(e.hooks)
|
|
631
571
|
};
|
|
632
572
|
}
|
|
633
|
-
function
|
|
573
|
+
function pt(e, t) {
|
|
634
574
|
var o, a;
|
|
635
|
-
const n =
|
|
575
|
+
const n = me[e.chainId];
|
|
636
576
|
return {
|
|
637
577
|
...n,
|
|
638
578
|
...t == null ? void 0 : t.v4Contracts,
|
|
@@ -641,14 +581,14 @@ function yt(e, t) {
|
|
|
641
581
|
quoter: ((a = e.v4Contracts) == null ? void 0 : a.quoter) ?? e.quoter ?? (t == null ? void 0 : t.quoter) ?? (n == null ? void 0 : n.quoter)
|
|
642
582
|
};
|
|
643
583
|
}
|
|
644
|
-
function
|
|
584
|
+
function mt(e, t) {
|
|
645
585
|
var a;
|
|
646
|
-
const n =
|
|
586
|
+
const n = pt(e, t);
|
|
647
587
|
if (!t && (!e.chain || !e.router || !((a = e.rpcUrls) != null && a.length)))
|
|
648
588
|
throw new Error(
|
|
649
589
|
`Missing viem chain, Aegis router, or RPC URLs for chain ${e.chainId}.`
|
|
650
590
|
);
|
|
651
|
-
const o =
|
|
591
|
+
const o = I(n);
|
|
652
592
|
return {
|
|
653
593
|
chainId: e.chainId,
|
|
654
594
|
chain: e.chain ?? t.chain,
|
|
@@ -661,31 +601,31 @@ function Et(e, t) {
|
|
|
661
601
|
explorerTxUrl: e.explorerTxUrl ?? (t == null ? void 0 : t.explorerTxUrl),
|
|
662
602
|
poolExplorerUrl: e.poolExplorerUrl ?? (t == null ? void 0 : t.poolExplorerUrl),
|
|
663
603
|
metadataEndpoint: e.metadataEndpoint ?? (t == null ? void 0 : t.metadataEndpoint),
|
|
664
|
-
// Fee stays
|
|
604
|
+
// Fee stays Aegis-controlled: it is never read from host input, only inherited from
|
|
665
605
|
// the bundled base chain config (e.g. mainnet keeps its 50 bps fee).
|
|
666
606
|
fee: t == null ? void 0 : t.fee
|
|
667
607
|
};
|
|
668
608
|
}
|
|
669
|
-
function
|
|
670
|
-
const t = { ...
|
|
609
|
+
function Rn(e) {
|
|
610
|
+
const t = { ...H };
|
|
671
611
|
if (!e) return t;
|
|
672
612
|
for (const [n, o] of Object.entries(e)) {
|
|
673
613
|
if (!o) continue;
|
|
674
614
|
const a = o.chainId ?? Number(n);
|
|
675
|
-
t[a] =
|
|
615
|
+
t[a] = mt(
|
|
676
616
|
{ ...o, chainId: a },
|
|
677
617
|
t[a]
|
|
678
618
|
);
|
|
679
619
|
}
|
|
680
620
|
return t;
|
|
681
621
|
}
|
|
682
|
-
function
|
|
683
|
-
const n =
|
|
622
|
+
function st(e, t = H) {
|
|
623
|
+
const n = Z(e.token), o = Z(e.counterToken), a = e.chainId ?? n.chainId ?? o.chainId ?? y, i = t[a];
|
|
684
624
|
if (!i) throw new Error(`No Aegis swap chain config found for chain ${a}.`);
|
|
685
625
|
if (n.chainId !== a || o.chainId !== a)
|
|
686
626
|
throw new Error(`Pool token chain ids must match chain ${a}.`);
|
|
687
|
-
const c =
|
|
688
|
-
if (e.poolId && !
|
|
627
|
+
const c = lt(e.poolKey), r = ce(c);
|
|
628
|
+
if (e.poolId && !ne(e.poolId, r))
|
|
689
629
|
throw new Error("Configured pool id does not match the pool key.");
|
|
690
630
|
return {
|
|
691
631
|
id: e.id,
|
|
@@ -701,52 +641,52 @@ function bt(e, t = j) {
|
|
|
701
641
|
label: e.label ?? `${o.symbol} / ${n.symbol}`
|
|
702
642
|
};
|
|
703
643
|
}
|
|
704
|
-
function
|
|
644
|
+
function Dn(e, t = H) {
|
|
705
645
|
return e != null && e.length ? Object.fromEntries(
|
|
706
646
|
e.map((n) => {
|
|
707
|
-
const o =
|
|
647
|
+
const o = st(n, t);
|
|
708
648
|
return [o.id, o];
|
|
709
649
|
})
|
|
710
650
|
) : {};
|
|
711
651
|
}
|
|
712
|
-
function
|
|
652
|
+
function fe(e) {
|
|
713
653
|
if (!Number.isFinite(e) || e < 0 || e > 2e3)
|
|
714
654
|
throw new Error("Slippage must be between 0% and 20%.");
|
|
715
655
|
}
|
|
716
|
-
function
|
|
717
|
-
return
|
|
656
|
+
function dt(e, t) {
|
|
657
|
+
return fe(t), e * BigInt(1e4 - Math.round(t)) / 10000n;
|
|
718
658
|
}
|
|
719
|
-
function
|
|
720
|
-
return
|
|
659
|
+
function ft(e, t) {
|
|
660
|
+
return fe(t), (e * BigInt(1e4 + Math.round(t)) + 9999n) / 10000n;
|
|
721
661
|
}
|
|
722
|
-
function
|
|
662
|
+
function ht(e, t) {
|
|
723
663
|
return t <= 0 ? 0n : e * BigInt(t) / 10000n;
|
|
724
664
|
}
|
|
725
|
-
function
|
|
665
|
+
function wt(e, t) {
|
|
726
666
|
return t <= 0 ? e : (e * 10000n + BigInt(1e4 - t - 1)) / BigInt(1e4 - t);
|
|
727
667
|
}
|
|
728
|
-
function
|
|
668
|
+
function yt(e, t) {
|
|
729
669
|
if (t <= 0) return e;
|
|
730
670
|
const n = BigInt(1e4 - t);
|
|
731
671
|
return (e * 10000n + n - 1n) / n;
|
|
732
672
|
}
|
|
733
|
-
function
|
|
734
|
-
return
|
|
673
|
+
function D(e) {
|
|
674
|
+
return M(e), e;
|
|
735
675
|
}
|
|
736
|
-
function
|
|
737
|
-
if (
|
|
738
|
-
if (
|
|
676
|
+
function Et(e, t) {
|
|
677
|
+
if (b(t.address, e.currency0)) return !0;
|
|
678
|
+
if (b(t.address, e.currency1)) return !1;
|
|
739
679
|
throw new Error("Input token is not part of this pool.");
|
|
740
680
|
}
|
|
741
|
-
function
|
|
742
|
-
const o =
|
|
743
|
-
if (!
|
|
681
|
+
function bt(e, t, n) {
|
|
682
|
+
const o = ce(e.poolKey);
|
|
683
|
+
if (!ne(o, e.poolId))
|
|
744
684
|
throw new Error("Configured pool id does not match the pool key.");
|
|
745
|
-
const a =
|
|
746
|
-
if (!a || !i ||
|
|
685
|
+
const a = b(t.address, e.poolKey.currency0) || b(t.address, e.poolKey.currency1), i = b(n.address, e.poolKey.currency0) || b(n.address, e.poolKey.currency1);
|
|
686
|
+
if (!a || !i || b(t.address, n.address))
|
|
747
687
|
throw new Error("Selected tokens do not match this direct pool.");
|
|
748
688
|
}
|
|
749
|
-
function
|
|
689
|
+
function At(e, t) {
|
|
750
690
|
if (Array.isArray(e)) {
|
|
751
691
|
const a = e[0], i = e[1];
|
|
752
692
|
if (typeof a == "bigint" && typeof i == "bigint")
|
|
@@ -758,56 +698,56 @@ function xt(e, t) {
|
|
|
758
698
|
return { amount: o, gasEstimate: n.gasEstimate };
|
|
759
699
|
throw new Error("Unexpected V4 Quoter response.");
|
|
760
700
|
}
|
|
761
|
-
async function
|
|
762
|
-
var d, f, w,
|
|
701
|
+
async function St(e) {
|
|
702
|
+
var d, f, w, A;
|
|
763
703
|
if ((d = e.signal) != null && d.aborted) throw new DOMException("Quote request aborted", "AbortError");
|
|
764
704
|
if (e.amount <= 0n) throw new Error("Enter an amount to swap.");
|
|
765
|
-
|
|
766
|
-
const t = e.market.poolKey, n =
|
|
705
|
+
D(e.amount), bt(e.market, e.tokenIn, e.tokenOut);
|
|
706
|
+
const t = e.market.poolKey, n = Et(t, e.tokenIn), o = ((f = e.fee) == null ? void 0 : f.bps) ?? 0;
|
|
767
707
|
if (!Number.isInteger(o) || o < 0 || o >= 1e4)
|
|
768
708
|
throw new Error("Fee must be an integer between 0 and 9999 bps.");
|
|
769
|
-
const a = e.mode === "exactOut" ?
|
|
709
|
+
const a = e.mode === "exactOut" ? D(wt(e.amount, o)) : e.amount, i = e.mode === "exactOut" ? await e.publicClient.simulateContract({
|
|
770
710
|
address: e.market.quoter,
|
|
771
|
-
abi:
|
|
711
|
+
abi: J,
|
|
772
712
|
functionName: "quoteExactOutputSingle",
|
|
773
713
|
args: [{ poolKey: t, zeroForOne: n, exactAmount: a, hookData: "0x" }],
|
|
774
714
|
account: e.account
|
|
775
715
|
}) : await e.publicClient.simulateContract({
|
|
776
716
|
address: e.market.quoter,
|
|
777
|
-
abi:
|
|
717
|
+
abi: J,
|
|
778
718
|
functionName: "quoteExactInputSingle",
|
|
779
719
|
args: [{ poolKey: t, zeroForOne: n, exactAmount: e.amount, hookData: "0x" }],
|
|
780
720
|
account: e.account
|
|
781
721
|
});
|
|
782
722
|
if ((w = e.signal) != null && w.aborted) throw new DOMException("Quote request aborted", "AbortError");
|
|
783
|
-
const c =
|
|
723
|
+
const c = At(
|
|
784
724
|
i.result,
|
|
785
725
|
e.mode === "exactOut" ? "amountIn" : "amountOut"
|
|
786
|
-
), r = e.mode === "exactOut" ? c.amount : e.amount, u = e.mode === "exactOut" ? a : c.amount, l = e.mode === "exactOut" ? u - e.amount :
|
|
726
|
+
), r = e.mode === "exactOut" ? c.amount : e.amount, u = e.mode === "exactOut" ? a : c.amount, l = e.mode === "exactOut" ? u - e.amount : ht(u, o), p = u - l, s = e.mode === "exactOut" ? p : dt(p, e.slippageBps);
|
|
787
727
|
return {
|
|
788
728
|
mode: e.mode,
|
|
789
729
|
poolKey: t,
|
|
790
730
|
zeroForOne: n,
|
|
791
731
|
amountIn: r,
|
|
792
|
-
amountOut:
|
|
732
|
+
amountOut: p,
|
|
793
733
|
grossAmountOut: u,
|
|
794
|
-
amountOutMinimum: e.mode === "exactOut" ? u :
|
|
795
|
-
amountInMaximum: e.mode === "exactOut" ?
|
|
796
|
-
userAmountOutMinimum:
|
|
734
|
+
amountOutMinimum: e.mode === "exactOut" ? u : D(yt(s, o)),
|
|
735
|
+
amountInMaximum: e.mode === "exactOut" ? D(ft(r, e.slippageBps)) : r,
|
|
736
|
+
userAmountOutMinimum: s,
|
|
797
737
|
feeAmount: l,
|
|
798
738
|
feeBps: o,
|
|
799
|
-
feeRecipient: o > 0 ? ((
|
|
739
|
+
feeRecipient: o > 0 ? ((A = e.fee) == null ? void 0 : A.recipient) ?? null : null,
|
|
800
740
|
gasEstimate: c.gasEstimate
|
|
801
741
|
};
|
|
802
742
|
}
|
|
803
|
-
function
|
|
804
|
-
return e.mode === t.mode && e.zeroForOne === t.zeroForOne &&
|
|
743
|
+
function he(e, t) {
|
|
744
|
+
return e.mode === t.mode && e.zeroForOne === t.zeroForOne && b(e.poolKey.currency0, t.poolKey.currency0) && b(e.poolKey.currency1, t.poolKey.currency1) && e.poolKey.fee === t.poolKey.fee && e.poolKey.tickSpacing === t.poolKey.tickSpacing && b(e.poolKey.hooks, t.poolKey.hooks) && e.feeBps === t.feeBps && Ue(e.feeRecipient, t.feeRecipient);
|
|
805
745
|
}
|
|
806
|
-
function
|
|
807
|
-
return
|
|
746
|
+
function Nn(e, t) {
|
|
747
|
+
return he(e, t) && e.amountIn === t.amountIn && e.amountOut === t.amountOut && e.grossAmountOut === t.grossAmountOut && e.amountOutMinimum === t.amountOutMinimum && e.amountInMaximum === t.amountInMaximum && e.userAmountOutMinimum === t.userAmountOutMinimum && e.feeAmount === t.feeAmount;
|
|
808
748
|
}
|
|
809
|
-
function
|
|
810
|
-
return !e || !
|
|
749
|
+
function It(e, t) {
|
|
750
|
+
return !e || !he(e, t) ? { quote: t, priceMovedBeyondTolerance: !1 } : t.mode === "exactIn" ? t.amountOut < e.userAmountOutMinimum ? { quote: t, priceMovedBeyondTolerance: !0 } : {
|
|
811
751
|
quote: {
|
|
812
752
|
...t,
|
|
813
753
|
amountOutMinimum: t.amountOutMinimum > e.amountOutMinimum ? t.amountOutMinimum : e.amountOutMinimum,
|
|
@@ -822,28 +762,28 @@ function Pt(e, t) {
|
|
|
822
762
|
priceMovedBeyondTolerance: !1
|
|
823
763
|
};
|
|
824
764
|
}
|
|
825
|
-
function
|
|
765
|
+
function Ct(e) {
|
|
826
766
|
return e.mode === "exactOut" ? e.amountInMaximum : e.amountIn;
|
|
827
767
|
}
|
|
828
|
-
function
|
|
768
|
+
function Tt(e) {
|
|
829
769
|
return e.feeRecipient ? e.mode === "exactIn" ? e.feeBps > 0 ? { recipient: e.feeRecipient, bips: e.feeBps } : null : e.feeAmount > 0n ? { recipient: e.feeRecipient, amount: e.feeAmount } : null : null;
|
|
830
770
|
}
|
|
831
|
-
function
|
|
771
|
+
function we(e) {
|
|
832
772
|
for (let n = e; n && typeof n == "object"; n = n.cause)
|
|
833
773
|
if (n.code === 4001) return !0;
|
|
834
774
|
const t = e instanceof Error ? e.message.toLowerCase() : "";
|
|
835
775
|
return t.includes("user rejected") || t.includes("user denied") || t.includes("rejected the request") || t.includes("request rejected");
|
|
836
776
|
}
|
|
837
|
-
const
|
|
838
|
-
function
|
|
839
|
-
if (
|
|
840
|
-
return
|
|
777
|
+
const vt = "Request rejected.";
|
|
778
|
+
function _t(e, t) {
|
|
779
|
+
if (we(e))
|
|
780
|
+
return vt;
|
|
841
781
|
const n = e instanceof Error ? e.message : "";
|
|
842
782
|
if (!n) return t;
|
|
843
783
|
const o = n.toLowerCase();
|
|
844
784
|
return o.includes("wallet_switchethereumchain") || o.includes("wallet_addethereumchain") ? "Network switch failed." : o.includes("insufficient funds") ? "Insufficient funds for gas." : o.includes("execution reverted") || o.includes("swap reverted") ? "Swap reverted on-chain." : o.includes("token not found") ? "Token is not supported by KyberSwap." : o.includes("kyberswap api error") ? "KyberSwap could not build this route. Try again." : t;
|
|
845
785
|
}
|
|
846
|
-
class
|
|
786
|
+
class ye extends Error {
|
|
847
787
|
constructor({
|
|
848
788
|
status: n,
|
|
849
789
|
statusText: o,
|
|
@@ -852,14 +792,14 @@ class Se extends Error {
|
|
|
852
792
|
body: c
|
|
853
793
|
}) {
|
|
854
794
|
super(i);
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
795
|
+
S(this, "status");
|
|
796
|
+
S(this, "statusText");
|
|
797
|
+
S(this, "code");
|
|
798
|
+
S(this, "body");
|
|
859
799
|
this.name = "KyberSwapApiError", this.status = n, this.statusText = o, this.code = a, this.body = c;
|
|
860
800
|
}
|
|
861
801
|
}
|
|
862
|
-
const
|
|
802
|
+
const Ee = "https://aggregator-api.kyberswap.com", W = "Aegis", xt = {
|
|
863
803
|
1: "ethereum",
|
|
864
804
|
10: "optimism",
|
|
865
805
|
56: "bsc",
|
|
@@ -880,13 +820,13 @@ const Ie = "https://aggregator-api.kyberswap.com", L = "Aegis", Ut = {
|
|
|
880
820
|
59144: "linea",
|
|
881
821
|
80094: "berachain"
|
|
882
822
|
};
|
|
883
|
-
function
|
|
884
|
-
const t =
|
|
823
|
+
function be(e) {
|
|
824
|
+
const t = xt[e];
|
|
885
825
|
if (!t)
|
|
886
826
|
throw new Error(`KyberSwap does not support chain ${e}.`);
|
|
887
827
|
return t;
|
|
888
828
|
}
|
|
889
|
-
async function
|
|
829
|
+
async function Ae(e) {
|
|
890
830
|
const t = e.clone();
|
|
891
831
|
let n, o, a;
|
|
892
832
|
try {
|
|
@@ -900,7 +840,7 @@ async function Te(e) {
|
|
|
900
840
|
}
|
|
901
841
|
}
|
|
902
842
|
const i = a ? `: ${a.slice(0, 300)}` : "", c = o !== void 0 ? ` ${o}` : "", r = e.statusText || "Request failed";
|
|
903
|
-
return new
|
|
843
|
+
return new ye({
|
|
904
844
|
status: e.status,
|
|
905
845
|
statusText: r,
|
|
906
846
|
code: o,
|
|
@@ -908,10 +848,10 @@ async function Te(e) {
|
|
|
908
848
|
body: n
|
|
909
849
|
});
|
|
910
850
|
}
|
|
911
|
-
function
|
|
912
|
-
return e instanceof
|
|
851
|
+
function Se(e) {
|
|
852
|
+
return e instanceof ye && (e.status === 429 || e.status >= 500);
|
|
913
853
|
}
|
|
914
|
-
function
|
|
854
|
+
function Ot(e) {
|
|
915
855
|
if (!(e != null && e.routeSummary) || !(e != null && e.routerAddress))
|
|
916
856
|
throw new Error("Invalid response from KyberSwap API");
|
|
917
857
|
return {
|
|
@@ -922,7 +862,7 @@ function Nt(e) {
|
|
|
922
862
|
routeSummary: e.routeSummary
|
|
923
863
|
};
|
|
924
864
|
}
|
|
925
|
-
function
|
|
865
|
+
function Pt(e) {
|
|
926
866
|
if (!(e != null && e.data) || !(e != null && e.routerAddress))
|
|
927
867
|
throw new Error("Invalid encoded route from KyberSwap API");
|
|
928
868
|
return {
|
|
@@ -931,7 +871,7 @@ function Ft(e) {
|
|
|
931
871
|
routerAddress: m(e.routerAddress)
|
|
932
872
|
};
|
|
933
873
|
}
|
|
934
|
-
async function
|
|
874
|
+
async function kt({
|
|
935
875
|
tokenIn: e,
|
|
936
876
|
tokenOut: t,
|
|
937
877
|
amountIn: n,
|
|
@@ -948,21 +888,21 @@ async function Bt({
|
|
|
948
888
|
});
|
|
949
889
|
a && r.set("origin", a), i && (r.set("feeAmount", i.feeAmount), r.set("chargeFeeBy", i.chargeFeeBy), r.set("isInBps", String(i.isInBps)), r.set("feeReceiver", i.feeReceiver));
|
|
950
890
|
const u = await fetch(
|
|
951
|
-
`${
|
|
891
|
+
`${Ee}/${be(o)}/api/v1/routes?${r}`,
|
|
952
892
|
{
|
|
953
893
|
method: "GET",
|
|
954
894
|
headers: {
|
|
955
895
|
Accept: "application/json",
|
|
956
|
-
"X-Client-Id":
|
|
896
|
+
"X-Client-Id": W
|
|
957
897
|
},
|
|
958
898
|
signal: c
|
|
959
899
|
}
|
|
960
900
|
);
|
|
961
|
-
if (!u.ok) throw await
|
|
901
|
+
if (!u.ok) throw await Ae(u);
|
|
962
902
|
const l = await u.json();
|
|
963
|
-
return
|
|
903
|
+
return Ot(l.data);
|
|
964
904
|
}
|
|
965
|
-
async function
|
|
905
|
+
async function Mt({
|
|
966
906
|
routeSummary: e,
|
|
967
907
|
sender: t,
|
|
968
908
|
recipient: n,
|
|
@@ -971,13 +911,13 @@ async function Wt({
|
|
|
971
911
|
signal: i
|
|
972
912
|
}) {
|
|
973
913
|
const c = await fetch(
|
|
974
|
-
`${
|
|
914
|
+
`${Ee}/${be(a)}/api/v1/route/build`,
|
|
975
915
|
{
|
|
976
916
|
method: "POST",
|
|
977
917
|
headers: {
|
|
978
918
|
Accept: "application/json",
|
|
979
919
|
"Content-Type": "application/json",
|
|
980
|
-
"X-Client-Id":
|
|
920
|
+
"X-Client-Id": W
|
|
981
921
|
},
|
|
982
922
|
body: JSON.stringify({
|
|
983
923
|
routeSummary: e,
|
|
@@ -987,38 +927,38 @@ async function Wt({
|
|
|
987
927
|
slippageTolerance: o,
|
|
988
928
|
deadline: Math.floor(Date.now() / 1e3 + 600),
|
|
989
929
|
enableGasEstimation: !1,
|
|
990
|
-
source:
|
|
930
|
+
source: W
|
|
991
931
|
}),
|
|
992
932
|
signal: i
|
|
993
933
|
}
|
|
994
934
|
);
|
|
995
|
-
if (!c.ok) throw await
|
|
935
|
+
if (!c.ok) throw await Ae(c);
|
|
996
936
|
const r = await c.json();
|
|
997
|
-
return
|
|
937
|
+
return Pt(r.data);
|
|
998
938
|
}
|
|
999
|
-
const
|
|
1000
|
-
function
|
|
1001
|
-
return
|
|
939
|
+
const Rt = 2, Dt = "Route temporarily unavailable. Refresh the quote and try again.";
|
|
940
|
+
function Fn(e, t) {
|
|
941
|
+
return Se(e) ? Dt : _t(e, t);
|
|
1002
942
|
}
|
|
1003
|
-
function
|
|
943
|
+
function Nt(e, t) {
|
|
1004
944
|
if (!Number.isFinite(t) || t < 0 || t > 2e3)
|
|
1005
945
|
throw new Error("Slippage must be between 0% and 20%.");
|
|
1006
946
|
return e * BigInt(1e4 - Math.round(t)) / 10000n;
|
|
1007
947
|
}
|
|
1008
|
-
function
|
|
948
|
+
function Ft(e, t) {
|
|
1009
949
|
if (t <= 0) return 0n;
|
|
1010
950
|
const n = BigInt(1e4 - t);
|
|
1011
951
|
return (e * 10000n + n - 1n) / n - e;
|
|
1012
952
|
}
|
|
1013
|
-
function
|
|
1014
|
-
return e !==
|
|
1015
|
-
feeAmount: String(
|
|
953
|
+
function Bt(e) {
|
|
954
|
+
return e !== y ? null : {
|
|
955
|
+
feeAmount: String(se),
|
|
1016
956
|
chargeFeeBy: "currency_out",
|
|
1017
957
|
isInBps: !0,
|
|
1018
|
-
feeReceiver:
|
|
958
|
+
feeReceiver: de
|
|
1019
959
|
};
|
|
1020
960
|
}
|
|
1021
|
-
function
|
|
961
|
+
function Ut(e) {
|
|
1022
962
|
const t = e.routeSummary.gasEstimate ?? e.routeSummary.gas ?? "0";
|
|
1023
963
|
try {
|
|
1024
964
|
return BigInt(t);
|
|
@@ -1026,12 +966,12 @@ function zt(e) {
|
|
|
1026
966
|
return 0n;
|
|
1027
967
|
}
|
|
1028
968
|
}
|
|
1029
|
-
function
|
|
969
|
+
function Gt(e) {
|
|
1030
970
|
var t;
|
|
1031
971
|
return ((t = e.routeSummary.route) == null ? void 0 : t.flat()) ?? [];
|
|
1032
972
|
}
|
|
1033
|
-
function
|
|
1034
|
-
const o =
|
|
973
|
+
function Kt(e, t, n) {
|
|
974
|
+
const o = Gt(e);
|
|
1035
975
|
return o.length ? o.map((a) => ({
|
|
1036
976
|
dex: a.exchange || a.poolType || "Unknown",
|
|
1037
977
|
inputToken: t,
|
|
@@ -1044,17 +984,17 @@ function Ht(e, t, n) {
|
|
|
1044
984
|
part: a.part || 0
|
|
1045
985
|
}));
|
|
1046
986
|
}
|
|
1047
|
-
async function
|
|
987
|
+
async function g(e, t, n, o, a = "exactIn", i, c, r) {
|
|
1048
988
|
if (a === "exactOut")
|
|
1049
989
|
throw new Error("Exact output is not supported for aggregated routes.");
|
|
1050
990
|
if (e.chainId !== t.chainId)
|
|
1051
991
|
throw new Error("Input and output tokens must be on the same chain.");
|
|
1052
992
|
if (n <= 0n)
|
|
1053
993
|
throw new Error("Enter an amount to swap.");
|
|
1054
|
-
const u =
|
|
1055
|
-
let
|
|
1056
|
-
for (let
|
|
1057
|
-
const d = await
|
|
994
|
+
const u = Bt(e.chainId), l = i ? Rt : 1;
|
|
995
|
+
let p;
|
|
996
|
+
for (let s = 0; s < l; s += 1) {
|
|
997
|
+
const d = await kt({
|
|
1058
998
|
tokenIn: e.address,
|
|
1059
999
|
tokenOut: t.address,
|
|
1060
1000
|
amountIn: n.toString(),
|
|
@@ -1062,10 +1002,10 @@ async function ee(e, t, n, o, a = "exactIn", i, c, r) {
|
|
|
1062
1002
|
origin: i,
|
|
1063
1003
|
fee: u,
|
|
1064
1004
|
signal: c
|
|
1065
|
-
}), f = BigInt(d.routeSummary.amountOut), w = u ?
|
|
1005
|
+
}), f = BigInt(d.routeSummary.amountOut), w = u ? se : 0, A = Ft(f, w), E = Nt(f, o);
|
|
1066
1006
|
let h = null;
|
|
1067
1007
|
try {
|
|
1068
|
-
h = i ? await
|
|
1008
|
+
h = i ? await Mt({
|
|
1069
1009
|
routeSummary: d.routeSummary,
|
|
1070
1010
|
sender: i,
|
|
1071
1011
|
recipient: i,
|
|
@@ -1073,32 +1013,32 @@ async function ee(e, t, n, o, a = "exactIn", i, c, r) {
|
|
|
1073
1013
|
chainId: e.chainId,
|
|
1074
1014
|
signal: c
|
|
1075
1015
|
}) : null;
|
|
1076
|
-
} catch (
|
|
1077
|
-
if (
|
|
1016
|
+
} catch (T) {
|
|
1017
|
+
if (p = T, i && s < l - 1 && Se(T))
|
|
1078
1018
|
continue;
|
|
1079
|
-
throw
|
|
1019
|
+
throw T;
|
|
1080
1020
|
}
|
|
1081
1021
|
return {
|
|
1082
1022
|
inputToken: e,
|
|
1083
1023
|
outputToken: t,
|
|
1084
1024
|
amountIn: n,
|
|
1085
1025
|
amountOut: f,
|
|
1086
|
-
gasEstimate: h != null && h.gas ? BigInt(h.gas) :
|
|
1087
|
-
hops:
|
|
1026
|
+
gasEstimate: h != null && h.gas ? BigInt(h.gas) : Ut(d),
|
|
1027
|
+
hops: Kt(d, e, t),
|
|
1088
1028
|
routerAddress: (h == null ? void 0 : h.routerAddress) ?? d.routerAddress,
|
|
1089
1029
|
calldata: (h == null ? void 0 : h.data) ?? null,
|
|
1090
1030
|
transactionValue: h != null && h.transactionValue ? BigInt(h.transactionValue) : 0n,
|
|
1091
1031
|
priceImpact: d.routeSummary.priceImpact ?? 0,
|
|
1092
|
-
feeAmount:
|
|
1032
|
+
feeAmount: A,
|
|
1093
1033
|
feeBps: w,
|
|
1094
|
-
feeRecipient: u ?
|
|
1095
|
-
userAmountOutMinimum:
|
|
1096
|
-
amountOutMinimum:
|
|
1034
|
+
feeRecipient: u ? de : null,
|
|
1035
|
+
userAmountOutMinimum: E,
|
|
1036
|
+
amountOutMinimum: E
|
|
1097
1037
|
};
|
|
1098
1038
|
}
|
|
1099
|
-
throw
|
|
1039
|
+
throw p instanceof Error ? p : new Error("Swap route could not be encoded. Try again.");
|
|
1100
1040
|
}
|
|
1101
|
-
const
|
|
1041
|
+
const F = 2n ** 160n - 1n, Ie = 2n ** 256n - 1n, Ce = 600, Wt = 1800, Te = 1800, Lt = Ce, $t = 2 ** 48 - 1, qt = {
|
|
1102
1042
|
PermitBatch: [
|
|
1103
1043
|
{ name: "details", type: "PermitDetails[]" },
|
|
1104
1044
|
{ name: "spender", type: "address" },
|
|
@@ -1111,14 +1051,14 @@ const N = 2n ** 160n - 1n, ve = 2n ** 256n - 1n, xe = 600, jt = 1800, Oe = 1800,
|
|
|
1111
1051
|
{ name: "nonce", type: "uint48" }
|
|
1112
1052
|
]
|
|
1113
1053
|
};
|
|
1114
|
-
async function
|
|
1115
|
-
const t = e.amount ??
|
|
1054
|
+
async function zt(e) {
|
|
1055
|
+
const t = e.amount ?? Ie, n = P({
|
|
1116
1056
|
account: e.account,
|
|
1117
1057
|
chain: e.chain,
|
|
1118
|
-
transport:
|
|
1058
|
+
transport: k(e.provider)
|
|
1119
1059
|
}), { request: o } = await e.publicClient.simulateContract({
|
|
1120
1060
|
address: e.token,
|
|
1121
|
-
abi:
|
|
1061
|
+
abi: q,
|
|
1122
1062
|
functionName: "approve",
|
|
1123
1063
|
args: [e.permit2, t],
|
|
1124
1064
|
account: e.account
|
|
@@ -1129,22 +1069,22 @@ async function Jt(e) {
|
|
|
1129
1069
|
if ((await e.publicClient.waitForTransactionReceipt({ hash: a })).status === "reverted") throw new Error("Token approval reverted.");
|
|
1130
1070
|
return a;
|
|
1131
1071
|
}
|
|
1132
|
-
function
|
|
1072
|
+
function B(e) {
|
|
1133
1073
|
return e.publicClient.readContract({
|
|
1134
1074
|
address: e.token,
|
|
1135
|
-
abi:
|
|
1075
|
+
abi: q,
|
|
1136
1076
|
functionName: "allowance",
|
|
1137
1077
|
args: [e.owner, e.spender]
|
|
1138
1078
|
});
|
|
1139
1079
|
}
|
|
1140
|
-
async function
|
|
1141
|
-
const t = e.amount ??
|
|
1080
|
+
async function ee(e) {
|
|
1081
|
+
const t = e.amount ?? Ie, o = await P({
|
|
1142
1082
|
account: e.account,
|
|
1143
1083
|
chain: e.chain,
|
|
1144
|
-
transport:
|
|
1084
|
+
transport: k(e.provider)
|
|
1145
1085
|
}).writeContract({
|
|
1146
1086
|
address: e.token,
|
|
1147
|
-
abi:
|
|
1087
|
+
abi: q,
|
|
1148
1088
|
functionName: "approve",
|
|
1149
1089
|
args: [e.spender, t],
|
|
1150
1090
|
account: e.account,
|
|
@@ -1153,14 +1093,14 @@ async function te(e) {
|
|
|
1153
1093
|
if ((await e.publicClient.waitForTransactionReceipt({ hash: o })).status === "reverted") throw new Error("Token approval reverted.");
|
|
1154
1094
|
return o;
|
|
1155
1095
|
}
|
|
1156
|
-
async function
|
|
1157
|
-
const t = e.amount && e.amount <
|
|
1096
|
+
async function Vt(e) {
|
|
1097
|
+
const t = e.amount && e.amount < F ? e.amount : F, n = e.expiration ?? $t, o = P({
|
|
1158
1098
|
account: e.account,
|
|
1159
1099
|
chain: e.chain,
|
|
1160
|
-
transport:
|
|
1100
|
+
transport: k(e.provider)
|
|
1161
1101
|
}), { request: a } = await e.publicClient.simulateContract({
|
|
1162
1102
|
address: e.permit2,
|
|
1163
|
-
abi:
|
|
1103
|
+
abi: oe,
|
|
1164
1104
|
functionName: "approve",
|
|
1165
1105
|
args: [e.token, e.router, t, n],
|
|
1166
1106
|
account: e.account
|
|
@@ -1171,33 +1111,33 @@ async function Zt(e) {
|
|
|
1171
1111
|
if ((await e.publicClient.waitForTransactionReceipt({ hash: i })).status === "reverted") throw new Error("Permit2 approval reverted.");
|
|
1172
1112
|
return i;
|
|
1173
1113
|
}
|
|
1174
|
-
function
|
|
1114
|
+
function ve(e) {
|
|
1175
1115
|
return e.publicClient.readContract({
|
|
1176
1116
|
address: e.permit2,
|
|
1177
|
-
abi:
|
|
1117
|
+
abi: oe,
|
|
1178
1118
|
functionName: "allowance",
|
|
1179
1119
|
args: [e.account, e.token, e.router]
|
|
1180
1120
|
});
|
|
1181
1121
|
}
|
|
1182
|
-
async function
|
|
1183
|
-
const [t, n, o] = await (e.allowanceRead ??
|
|
1184
|
-
if (t >= e.amount && Number(n) > a +
|
|
1122
|
+
async function Ht(e) {
|
|
1123
|
+
const [t, n, o] = await (e.allowanceRead ?? ve(e)), a = Math.floor(Date.now() / 1e3);
|
|
1124
|
+
if (t >= e.amount && Number(n) > a + Lt)
|
|
1185
1125
|
return null;
|
|
1186
1126
|
const i = {
|
|
1187
1127
|
details: [
|
|
1188
1128
|
{
|
|
1189
1129
|
token: e.token,
|
|
1190
|
-
amount: e.sizing === "max" || e.amount >
|
|
1191
|
-
expiration: a +
|
|
1130
|
+
amount: e.sizing === "max" || e.amount > F ? F : e.amount,
|
|
1131
|
+
expiration: a + Te,
|
|
1192
1132
|
nonce: Number(o)
|
|
1193
1133
|
}
|
|
1194
1134
|
],
|
|
1195
1135
|
spender: e.router,
|
|
1196
|
-
sigDeadline: BigInt(a +
|
|
1136
|
+
sigDeadline: BigInt(a + Wt)
|
|
1197
1137
|
}, r = await P({
|
|
1198
1138
|
account: e.account,
|
|
1199
1139
|
chain: e.chain,
|
|
1200
|
-
transport:
|
|
1140
|
+
transport: k(e.provider)
|
|
1201
1141
|
}).signTypedData({
|
|
1202
1142
|
account: e.account,
|
|
1203
1143
|
domain: {
|
|
@@ -1205,7 +1145,7 @@ async function gt(e) {
|
|
|
1205
1145
|
chainId: e.chainId,
|
|
1206
1146
|
verifyingContract: e.permit2
|
|
1207
1147
|
},
|
|
1208
|
-
types:
|
|
1148
|
+
types: qt,
|
|
1209
1149
|
primaryType: "PermitBatch",
|
|
1210
1150
|
message: i
|
|
1211
1151
|
});
|
|
@@ -1215,51 +1155,51 @@ async function gt(e) {
|
|
|
1215
1155
|
signature: r
|
|
1216
1156
|
};
|
|
1217
1157
|
}
|
|
1218
|
-
const
|
|
1219
|
-
function
|
|
1158
|
+
const jt = "https://ichi-images.s3.us-east-1.amazonaws.com/tokens", G = /* @__PURE__ */ new Map();
|
|
1159
|
+
function te(e, t, n) {
|
|
1220
1160
|
return `${e}|evm_${t}_${n.toLowerCase()}`;
|
|
1221
1161
|
}
|
|
1222
|
-
function
|
|
1162
|
+
function Xt(e, t) {
|
|
1223
1163
|
return `evm_${e}_${t.toLowerCase()}`;
|
|
1224
1164
|
}
|
|
1225
|
-
function
|
|
1165
|
+
function Qt(e) {
|
|
1226
1166
|
const t = e == null ? void 0 : e.trim();
|
|
1227
1167
|
if (!t) return null;
|
|
1228
1168
|
const n = t.split("-"), a = (n.length > 1 ? n[n.length - 1] : t).trim().toLowerCase();
|
|
1229
1169
|
return !a || !/^[a-z0-9]+$/.test(a) ? null : a;
|
|
1230
1170
|
}
|
|
1231
|
-
function
|
|
1232
|
-
const t =
|
|
1233
|
-
return t ? `${
|
|
1171
|
+
function Yt(e) {
|
|
1172
|
+
const t = Qt(e);
|
|
1173
|
+
return t ? `${jt}/logo_256_${t}.svg` : null;
|
|
1234
1174
|
}
|
|
1235
|
-
function
|
|
1175
|
+
function Bn(e, t) {
|
|
1236
1176
|
var n, o;
|
|
1237
|
-
return ((n = e.iconUrl) != null && n.trim() ? e.iconUrl : null) ?? ((o = t[K(e.address)]) == null ? void 0 : o.iconURL) ??
|
|
1177
|
+
return ((n = e.iconUrl) != null && n.trim() ? e.iconUrl : null) ?? ((o = t[K(e.address)]) == null ? void 0 : o.iconURL) ?? Yt(e.symbol);
|
|
1238
1178
|
}
|
|
1239
|
-
function
|
|
1240
|
-
return `query AegisSwapWidgetTokenMetadata { ${t.map((o, a) => `t${a}: getGlobalToken(id: ${JSON.stringify(
|
|
1179
|
+
function Jt(e, t) {
|
|
1180
|
+
return `query AegisSwapWidgetTokenMetadata { ${t.map((o, a) => `t${a}: getGlobalToken(id: ${JSON.stringify(Xt(e, o))}) { chainId address symbol displayName fullName decimals iconURL }`).join(" ")} }`;
|
|
1241
1181
|
}
|
|
1242
|
-
async function
|
|
1182
|
+
async function Un(e) {
|
|
1243
1183
|
var r, u;
|
|
1244
1184
|
const t = e.endpoint.trim(), n = [
|
|
1245
1185
|
...new Map(
|
|
1246
1186
|
e.addresses.map((l) => {
|
|
1247
|
-
const
|
|
1248
|
-
return [
|
|
1187
|
+
const p = m(l);
|
|
1188
|
+
return [p.toLowerCase(), p];
|
|
1249
1189
|
})
|
|
1250
1190
|
).values()
|
|
1251
1191
|
], o = /* @__PURE__ */ new Map(), a = n.filter((l) => {
|
|
1252
|
-
const
|
|
1253
|
-
if (!G.has(
|
|
1254
|
-
const
|
|
1255
|
-
return
|
|
1192
|
+
const p = te(t, e.chainId, l);
|
|
1193
|
+
if (!G.has(p)) return !0;
|
|
1194
|
+
const s = G.get(p);
|
|
1195
|
+
return s && o.set(K(l), s), !1;
|
|
1256
1196
|
});
|
|
1257
1197
|
if (!a.length || typeof fetch != "function") return o;
|
|
1258
1198
|
const i = await fetch(t, {
|
|
1259
1199
|
method: "POST",
|
|
1260
1200
|
headers: { "Content-Type": "application/json" },
|
|
1261
1201
|
body: JSON.stringify({
|
|
1262
|
-
query:
|
|
1202
|
+
query: Jt(e.chainId, a)
|
|
1263
1203
|
}),
|
|
1264
1204
|
signal: e.signal
|
|
1265
1205
|
});
|
|
@@ -1268,63 +1208,63 @@ async function qn(e) {
|
|
|
1268
1208
|
const c = await i.json();
|
|
1269
1209
|
if ((r = c.errors) != null && r.length)
|
|
1270
1210
|
throw new Error(((u = c.errors[0]) == null ? void 0 : u.message) ?? "Token metadata request failed.");
|
|
1271
|
-
return a.forEach((l,
|
|
1211
|
+
return a.forEach((l, p) => {
|
|
1272
1212
|
var d;
|
|
1273
|
-
const
|
|
1274
|
-
G.set(
|
|
1213
|
+
const s = ((d = c.data) == null ? void 0 : d[`t${p}`]) ?? null;
|
|
1214
|
+
G.set(te(t, e.chainId, l), s), s && o.set(K(l), s);
|
|
1275
1215
|
}), o;
|
|
1276
1216
|
}
|
|
1277
|
-
function
|
|
1217
|
+
function Zt() {
|
|
1278
1218
|
return typeof window > "u" ? null : window.ethereum ?? null;
|
|
1279
1219
|
}
|
|
1280
|
-
function
|
|
1281
|
-
return typeof e != "string" || !
|
|
1220
|
+
function U(e) {
|
|
1221
|
+
return typeof e != "string" || !Fe(e) ? null : m(e);
|
|
1282
1222
|
}
|
|
1283
|
-
function
|
|
1223
|
+
function gt(e) {
|
|
1284
1224
|
return !!(e && typeof e == "object" && typeof e.request == "function");
|
|
1285
1225
|
}
|
|
1286
|
-
function
|
|
1287
|
-
return
|
|
1226
|
+
function en(e) {
|
|
1227
|
+
return gt(e) ? { provider: e, account: null } : !e || typeof e != "object" ? { provider: null, account: null } : {
|
|
1288
1228
|
provider: e.provider ?? null,
|
|
1289
|
-
account:
|
|
1229
|
+
account: U(e.account)
|
|
1290
1230
|
};
|
|
1291
1231
|
}
|
|
1292
|
-
async function
|
|
1232
|
+
async function tn(e) {
|
|
1293
1233
|
const t = await e.request({ method: "eth_accounts" });
|
|
1294
|
-
return
|
|
1234
|
+
return U(t == null ? void 0 : t[0]);
|
|
1295
1235
|
}
|
|
1296
|
-
async function
|
|
1236
|
+
async function nn(e) {
|
|
1297
1237
|
const t = await e.request({ method: "eth_requestAccounts" });
|
|
1298
|
-
return
|
|
1238
|
+
return U(t == null ? void 0 : t[0]);
|
|
1299
1239
|
}
|
|
1300
|
-
async function
|
|
1240
|
+
async function L(e) {
|
|
1301
1241
|
const t = await e.request({ method: "eth_chainId" });
|
|
1302
1242
|
if (typeof t != "string" || !/^0x[0-9a-f]+$/i.test(t)) return null;
|
|
1303
1243
|
const n = Number.parseInt(t, 16);
|
|
1304
1244
|
return Number.isSafeInteger(n) ? n : null;
|
|
1305
1245
|
}
|
|
1306
|
-
function
|
|
1246
|
+
function on(e) {
|
|
1307
1247
|
return `0x${e.toString(16)}`;
|
|
1308
1248
|
}
|
|
1309
|
-
function
|
|
1249
|
+
function an(e) {
|
|
1310
1250
|
const t = e, n = [t.message, t.shortMessage, t.details].filter((o) => typeof o == "string").join(" ").toLowerCase();
|
|
1311
1251
|
return t.code === 4902 || n.includes("unrecognized chain") || n.includes("unknown chain") || n.includes("chain has not been added") || n.includes("not added to wallet");
|
|
1312
1252
|
}
|
|
1313
|
-
function
|
|
1253
|
+
function rn(e) {
|
|
1314
1254
|
return typeof e == "number" ? { chainId: e } : e;
|
|
1315
1255
|
}
|
|
1316
|
-
function
|
|
1256
|
+
function cn(e) {
|
|
1317
1257
|
var t, n;
|
|
1318
1258
|
return (t = e.rpcUrls) != null && t.length ? e.rpcUrls : ((n = e.chain) == null ? void 0 : n.rpcUrls.default.http) ?? [];
|
|
1319
1259
|
}
|
|
1320
|
-
function
|
|
1260
|
+
function un(e) {
|
|
1321
1261
|
var n, o;
|
|
1322
1262
|
const t = (o = (n = e.chain) == null ? void 0 : n.blockExplorers) == null ? void 0 : o.default.url;
|
|
1323
1263
|
return t ? [t] : [];
|
|
1324
1264
|
}
|
|
1325
|
-
async function
|
|
1265
|
+
async function ln(e, t) {
|
|
1326
1266
|
var i, c;
|
|
1327
|
-
const n =
|
|
1267
|
+
const n = rn(t), o = on(n.chainId), a = {
|
|
1328
1268
|
method: "wallet_switchEthereumChain",
|
|
1329
1269
|
params: [{ chainId: o }]
|
|
1330
1270
|
};
|
|
@@ -1332,10 +1272,10 @@ async function wn(e, t) {
|
|
|
1332
1272
|
await e.request(a);
|
|
1333
1273
|
return;
|
|
1334
1274
|
} catch (r) {
|
|
1335
|
-
if (!
|
|
1336
|
-
const u =
|
|
1275
|
+
if (!an(r)) throw r;
|
|
1276
|
+
const u = cn(n);
|
|
1337
1277
|
if (u.length === 0) throw r;
|
|
1338
|
-
const l =
|
|
1278
|
+
const l = un(n);
|
|
1339
1279
|
await e.request({
|
|
1340
1280
|
method: "wallet_addEthereumChain",
|
|
1341
1281
|
params: [
|
|
@@ -1358,21 +1298,21 @@ async function wn(e, t) {
|
|
|
1358
1298
|
params: [{ chainId: o }]
|
|
1359
1299
|
});
|
|
1360
1300
|
}
|
|
1361
|
-
function
|
|
1301
|
+
function Gn(e, t) {
|
|
1362
1302
|
const n = t.map(
|
|
1363
|
-
(o) =>
|
|
1303
|
+
(o) => Re(o, {
|
|
1364
1304
|
batch: !0,
|
|
1365
1305
|
retryCount: 2,
|
|
1366
1306
|
retryDelay: 150,
|
|
1367
1307
|
timeout: 1e4
|
|
1368
1308
|
})
|
|
1369
1309
|
);
|
|
1370
|
-
return
|
|
1310
|
+
return De({
|
|
1371
1311
|
chain: e,
|
|
1372
|
-
transport: n.length === 1 ? n[0] :
|
|
1312
|
+
transport: n.length === 1 ? n[0] : Ne(n)
|
|
1373
1313
|
});
|
|
1374
1314
|
}
|
|
1375
|
-
function
|
|
1315
|
+
function Kn(e, t) {
|
|
1376
1316
|
const n = e;
|
|
1377
1317
|
if (!n.on || !n.removeListener) return () => {
|
|
1378
1318
|
};
|
|
@@ -1388,7 +1328,7 @@ function Vn(e, t) {
|
|
|
1388
1328
|
(i = n.removeListener) == null || i.call(n, "accountsChanged", o), (c = n.removeListener) == null || c.call(n, "chainChanged", a);
|
|
1389
1329
|
};
|
|
1390
1330
|
}
|
|
1391
|
-
async function
|
|
1331
|
+
async function pn({
|
|
1392
1332
|
wallet: e,
|
|
1393
1333
|
publicClient: t,
|
|
1394
1334
|
activeChain: n,
|
|
@@ -1399,24 +1339,24 @@ async function yn({
|
|
|
1399
1339
|
permit: r,
|
|
1400
1340
|
setStatus: u,
|
|
1401
1341
|
setTxHash: l,
|
|
1402
|
-
onSubmitted:
|
|
1342
|
+
onSubmitted: p
|
|
1403
1343
|
}) {
|
|
1404
|
-
const
|
|
1344
|
+
const s = BigInt(Math.floor(Date.now() / 1e3) + Ce), d = Tt(c), f = c.mode === "exactOut" ? Ze({
|
|
1405
1345
|
poolKey: c.poolKey,
|
|
1406
1346
|
zeroForOne: c.zeroForOne,
|
|
1407
1347
|
amountOut: c.grossAmountOut,
|
|
1408
1348
|
amountInMaximum: c.amountInMaximum,
|
|
1409
1349
|
recipient: e.account,
|
|
1410
|
-
deadline:
|
|
1350
|
+
deadline: s,
|
|
1411
1351
|
permit: r,
|
|
1412
1352
|
fee: d
|
|
1413
|
-
}) :
|
|
1353
|
+
}) : Je({
|
|
1414
1354
|
poolKey: c.poolKey,
|
|
1415
1355
|
zeroForOne: c.zeroForOne,
|
|
1416
1356
|
amountIn: c.amountIn,
|
|
1417
1357
|
amountOutMinimum: c.amountOutMinimum,
|
|
1418
1358
|
recipient: e.account,
|
|
1419
|
-
deadline:
|
|
1359
|
+
deadline: s,
|
|
1420
1360
|
permit: r,
|
|
1421
1361
|
fee: d
|
|
1422
1362
|
});
|
|
@@ -1424,17 +1364,17 @@ async function yn({
|
|
|
1424
1364
|
const w = P({
|
|
1425
1365
|
account: e.account,
|
|
1426
1366
|
chain: n.chain,
|
|
1427
|
-
transport:
|
|
1428
|
-
}),
|
|
1367
|
+
transport: k(e.provider)
|
|
1368
|
+
}), A = await t.estimateGas({
|
|
1429
1369
|
account: e.account,
|
|
1430
1370
|
to: o.router,
|
|
1431
1371
|
data: f.calldata,
|
|
1432
1372
|
value: f.value
|
|
1433
|
-
}),
|
|
1373
|
+
}), E = await w.sendTransaction({
|
|
1434
1374
|
to: o.router,
|
|
1435
1375
|
data: f.calldata,
|
|
1436
1376
|
value: f.value,
|
|
1437
|
-
gas:
|
|
1377
|
+
gas: A * 12n / 10n
|
|
1438
1378
|
}), h = {
|
|
1439
1379
|
mode: c.mode,
|
|
1440
1380
|
inputSymbol: a.symbol,
|
|
@@ -1444,31 +1384,31 @@ async function yn({
|
|
|
1444
1384
|
feeAmount: c.feeAmount,
|
|
1445
1385
|
feeBps: c.feeBps
|
|
1446
1386
|
};
|
|
1447
|
-
l(
|
|
1387
|
+
l(E);
|
|
1448
1388
|
try {
|
|
1449
|
-
|
|
1389
|
+
p == null || p(E, h);
|
|
1450
1390
|
} catch (R) {
|
|
1451
1391
|
console.warn("[AegisSwapWidget] onSubmitted callback failed", R);
|
|
1452
1392
|
}
|
|
1453
|
-
let
|
|
1393
|
+
let T = null;
|
|
1454
1394
|
const v = await t.waitForTransactionReceipt({
|
|
1455
|
-
hash:
|
|
1395
|
+
hash: E,
|
|
1456
1396
|
onReplaced: (R) => {
|
|
1457
|
-
|
|
1397
|
+
T = R.reason, l(R.transaction.hash);
|
|
1458
1398
|
}
|
|
1459
1399
|
});
|
|
1460
|
-
if (
|
|
1400
|
+
if (T === "cancelled") throw new Error("Swap was cancelled in the wallet.");
|
|
1461
1401
|
if (v.status === "reverted") throw new Error("Swap reverted on-chain.");
|
|
1462
|
-
const
|
|
1402
|
+
const Q = v.gasUsed ?? 0n, Y = v.effectiveGasPrice ?? 0n, Oe = {
|
|
1463
1403
|
transactionHash: v.transactionHash,
|
|
1464
1404
|
blockNumber: v.blockNumber ?? 0n,
|
|
1465
|
-
gasUsed:
|
|
1466
|
-
effectiveGasPrice:
|
|
1467
|
-
feeWei:
|
|
1405
|
+
gasUsed: Q,
|
|
1406
|
+
effectiveGasPrice: Y,
|
|
1407
|
+
feeWei: Q * Y
|
|
1468
1408
|
};
|
|
1469
|
-
return { receipt: v, summary:
|
|
1409
|
+
return { receipt: v, summary: Oe, swapDetails: h };
|
|
1470
1410
|
}
|
|
1471
|
-
async function
|
|
1411
|
+
async function mn({
|
|
1472
1412
|
wallet: e,
|
|
1473
1413
|
publicClient: t,
|
|
1474
1414
|
activeChain: n,
|
|
@@ -1481,7 +1421,7 @@ async function En({
|
|
|
1481
1421
|
setStatus: l
|
|
1482
1422
|
}) {
|
|
1483
1423
|
try {
|
|
1484
|
-
return await
|
|
1424
|
+
return await Ht({
|
|
1485
1425
|
provider: e.provider,
|
|
1486
1426
|
publicClient: t,
|
|
1487
1427
|
account: e.account,
|
|
@@ -1494,9 +1434,9 @@ async function En({
|
|
|
1494
1434
|
sizing: r,
|
|
1495
1435
|
allowanceRead: u
|
|
1496
1436
|
});
|
|
1497
|
-
} catch (
|
|
1498
|
-
if (
|
|
1499
|
-
return l("approving"), await
|
|
1437
|
+
} catch (p) {
|
|
1438
|
+
if (we(p)) throw p;
|
|
1439
|
+
return l("approving"), await Vt({
|
|
1500
1440
|
provider: e.provider,
|
|
1501
1441
|
publicClient: t,
|
|
1502
1442
|
account: e.account,
|
|
@@ -1506,14 +1446,14 @@ async function En({
|
|
|
1506
1446
|
router: a,
|
|
1507
1447
|
// undefined -> MAX_UINT160, mirroring the 'max' permit sizing above.
|
|
1508
1448
|
amount: r === "max" ? void 0 : c,
|
|
1509
|
-
expiration: Math.floor(Date.now() / 1e3) +
|
|
1449
|
+
expiration: Math.floor(Date.now() / 1e3) + Te
|
|
1510
1450
|
}), null;
|
|
1511
1451
|
}
|
|
1512
1452
|
}
|
|
1513
|
-
function
|
|
1453
|
+
function Wn() {
|
|
1514
1454
|
return typeof document > "u" ? !0 : document.visibilityState !== "hidden";
|
|
1515
1455
|
}
|
|
1516
|
-
async function
|
|
1456
|
+
async function Ln(e, t, n, o) {
|
|
1517
1457
|
let a;
|
|
1518
1458
|
for (let i = 0; i < t; i += 1) {
|
|
1519
1459
|
i > 0 && await new Promise((c) => setTimeout(c, n));
|
|
@@ -1525,53 +1465,67 @@ async function jn(e, t, n, o) {
|
|
|
1525
1465
|
}
|
|
1526
1466
|
throw a ?? new Error("retryOnError was called with attempts < 1.");
|
|
1527
1467
|
}
|
|
1528
|
-
async function
|
|
1468
|
+
async function X(e, t, n, o) {
|
|
1529
1469
|
let a = await e();
|
|
1530
1470
|
for (let i = 1; i < n && !t(a); i += 1)
|
|
1531
1471
|
await new Promise((c) => setTimeout(c, o)), a = await e();
|
|
1532
1472
|
return a;
|
|
1533
1473
|
}
|
|
1534
|
-
async function
|
|
1535
|
-
return await
|
|
1536
|
-
() =>
|
|
1474
|
+
async function sn(e, t, n = 12, o = 250) {
|
|
1475
|
+
return await X(
|
|
1476
|
+
() => L(e),
|
|
1537
1477
|
(i) => i === t,
|
|
1538
1478
|
n,
|
|
1539
1479
|
o
|
|
1540
1480
|
) === t;
|
|
1541
1481
|
}
|
|
1542
|
-
async function
|
|
1482
|
+
async function _e(e) {
|
|
1543
1483
|
var a, i;
|
|
1544
|
-
const t = await
|
|
1484
|
+
const t = await L(e.provider);
|
|
1545
1485
|
if ((a = e.onChainId) == null || a.call(e, t), t === e.chain.chainId) return;
|
|
1546
|
-
await
|
|
1547
|
-
const n = await
|
|
1486
|
+
await ln(e.provider, e.chain);
|
|
1487
|
+
const n = await sn(e.provider, e.chain.chainId), o = n ? e.chain.chainId : await L(e.provider);
|
|
1548
1488
|
if ((i = e.onChainId) == null || i.call(e, o), !n)
|
|
1549
1489
|
throw new Error("Network switch did not complete. Switch to the correct network and try again.");
|
|
1550
1490
|
}
|
|
1551
|
-
async function
|
|
1491
|
+
async function $n(e = {}) {
|
|
1552
1492
|
var o;
|
|
1553
|
-
let t = e.provider ?? await ((o = e.getProvider) == null ? void 0 : o.call(e)) ??
|
|
1493
|
+
let t = e.provider ?? await ((o = e.getProvider) == null ? void 0 : o.call(e)) ?? Zt(), n = U(e.account);
|
|
1554
1494
|
if ((!t || !n) && e.connectWallet) {
|
|
1555
|
-
const a =
|
|
1495
|
+
const a = en(await e.connectWallet());
|
|
1556
1496
|
t = a.provider ?? t, n = n ?? a.account;
|
|
1557
1497
|
}
|
|
1558
1498
|
if (!t) throw new Error("No wallet provider found.");
|
|
1559
|
-
if (n || (n = e.requestAccount === !1 ? await
|
|
1499
|
+
if (n || (n = e.requestAccount === !1 ? await tn(t) : await nn(t)), !n) throw new Error("Wallet connection was not completed.");
|
|
1560
1500
|
return { provider: t, account: n };
|
|
1561
1501
|
}
|
|
1562
|
-
class
|
|
1502
|
+
class dn extends Error {
|
|
1563
1503
|
constructor(n) {
|
|
1564
1504
|
super("Price moved beyond your slippage tolerance. Review the updated quote and try again.");
|
|
1565
|
-
|
|
1505
|
+
S(this, "quote");
|
|
1566
1506
|
this.name = "DirectPoolSwapPriceMovedError", this.quote = n;
|
|
1567
1507
|
}
|
|
1568
1508
|
}
|
|
1569
|
-
|
|
1570
|
-
return
|
|
1509
|
+
function fn(e) {
|
|
1510
|
+
return St({
|
|
1511
|
+
publicClient: e.publicClient,
|
|
1512
|
+
account: e.account,
|
|
1513
|
+
market: e.market,
|
|
1514
|
+
tokenIn: e.inputToken,
|
|
1515
|
+
tokenOut: e.outputToken,
|
|
1516
|
+
mode: e.mode,
|
|
1517
|
+
amount: e.amount,
|
|
1518
|
+
slippageBps: e.slippageBps,
|
|
1519
|
+
fee: e.activeChain.fee ?? null,
|
|
1520
|
+
signal: e.signal
|
|
1521
|
+
});
|
|
1571
1522
|
}
|
|
1572
|
-
async function
|
|
1523
|
+
async function hn(e, t) {
|
|
1524
|
+
return X(e, (n) => n >= t, 5, 300);
|
|
1525
|
+
}
|
|
1526
|
+
async function wn(e) {
|
|
1573
1527
|
var a;
|
|
1574
|
-
const t = () =>
|
|
1528
|
+
const t = () => B({
|
|
1575
1529
|
publicClient: e.publicClient,
|
|
1576
1530
|
token: e.token.address,
|
|
1577
1531
|
owner: e.wallet.account,
|
|
@@ -1580,7 +1534,7 @@ async function In(e) {
|
|
|
1580
1534
|
let n = await t();
|
|
1581
1535
|
if (n >= e.amount) return { approvalHash: null, allowance: n };
|
|
1582
1536
|
(a = e.onStatus) == null || a.call(e, "approving");
|
|
1583
|
-
const o = await
|
|
1537
|
+
const o = await zt({
|
|
1584
1538
|
provider: e.wallet.provider,
|
|
1585
1539
|
publicClient: e.publicClient,
|
|
1586
1540
|
account: e.wallet.account,
|
|
@@ -1589,23 +1543,23 @@ async function In(e) {
|
|
|
1589
1543
|
permit2: e.permit2,
|
|
1590
1544
|
amount: e.approvalMode === "exact" ? e.amount : void 0
|
|
1591
1545
|
});
|
|
1592
|
-
if (n = await
|
|
1546
|
+
if (n = await hn(t, e.amount), n < e.amount)
|
|
1593
1547
|
throw new Error("Approval confirmed, but allowance is still below this quote. Try again.");
|
|
1594
1548
|
return { approvalHash: o, allowance: n };
|
|
1595
1549
|
}
|
|
1596
|
-
async function
|
|
1597
|
-
var
|
|
1598
|
-
await
|
|
1550
|
+
async function qn(e) {
|
|
1551
|
+
var p, s, d;
|
|
1552
|
+
await _e({
|
|
1599
1553
|
provider: e.wallet.provider,
|
|
1600
1554
|
chain: e.activeChain,
|
|
1601
1555
|
onChainId: e.onWalletChainId
|
|
1602
1556
|
});
|
|
1603
|
-
const t =
|
|
1557
|
+
const t = B({
|
|
1604
1558
|
publicClient: e.publicClient,
|
|
1605
1559
|
token: e.inputToken.address,
|
|
1606
1560
|
owner: e.wallet.account,
|
|
1607
1561
|
spender: e.market.permit2
|
|
1608
|
-
}).catch(() => null), n =
|
|
1562
|
+
}).catch(() => null), n = ve({
|
|
1609
1563
|
publicClient: e.publicClient,
|
|
1610
1564
|
permit2: e.market.permit2,
|
|
1611
1565
|
account: e.wallet.account,
|
|
@@ -1614,29 +1568,29 @@ async function Qn(e) {
|
|
|
1614
1568
|
});
|
|
1615
1569
|
n.catch(() => {
|
|
1616
1570
|
});
|
|
1617
|
-
const o = await
|
|
1571
|
+
const o = await fn({
|
|
1618
1572
|
publicClient: e.publicClient,
|
|
1619
1573
|
account: e.wallet.account,
|
|
1574
|
+
activeChain: e.activeChain,
|
|
1620
1575
|
market: e.market,
|
|
1621
|
-
|
|
1622
|
-
|
|
1576
|
+
inputToken: e.inputToken,
|
|
1577
|
+
outputToken: e.outputToken,
|
|
1623
1578
|
mode: e.mode,
|
|
1624
1579
|
amount: e.amount,
|
|
1625
1580
|
slippageBps: e.slippageBps,
|
|
1626
|
-
fee: e.fee ?? e.activeChain.fee ?? null,
|
|
1627
1581
|
signal: e.signal
|
|
1628
|
-
}), a =
|
|
1582
|
+
}), a = It(e.displayedQuote ?? null, o);
|
|
1629
1583
|
if (a.priceMovedBeyondTolerance)
|
|
1630
|
-
throw (
|
|
1631
|
-
const i = a.quote, c =
|
|
1584
|
+
throw (p = e.onStatus) == null || p.call(e, "idle"), new dn(o);
|
|
1585
|
+
const i = a.quote, c = Ct(i);
|
|
1632
1586
|
if (c <= 0n) throw new Error("Quote returned an empty amount. Try again.");
|
|
1633
|
-
let r = await t ?? await
|
|
1587
|
+
let r = await t ?? await B({
|
|
1634
1588
|
publicClient: e.publicClient,
|
|
1635
1589
|
token: e.inputToken.address,
|
|
1636
1590
|
owner: e.wallet.account,
|
|
1637
1591
|
spender: e.market.permit2
|
|
1638
1592
|
});
|
|
1639
|
-
if (r < c && (r = (await
|
|
1593
|
+
if (r < c && (r = (await wn({
|
|
1640
1594
|
wallet: e.wallet,
|
|
1641
1595
|
publicClient: e.publicClient,
|
|
1642
1596
|
activeChain: e.activeChain,
|
|
@@ -1647,8 +1601,8 @@ async function Qn(e) {
|
|
|
1647
1601
|
onStatus: e.onStatus
|
|
1648
1602
|
})).allowance), r < c)
|
|
1649
1603
|
throw new Error(`Approve ${e.inputToken.symbol} before swapping.`);
|
|
1650
|
-
(
|
|
1651
|
-
const u = await
|
|
1604
|
+
(s = e.onStatus) == null || s.call(e, "signing");
|
|
1605
|
+
const u = await mn({
|
|
1652
1606
|
wallet: e.wallet,
|
|
1653
1607
|
publicClient: e.publicClient,
|
|
1654
1608
|
activeChain: e.activeChain,
|
|
@@ -1662,7 +1616,7 @@ async function Qn(e) {
|
|
|
1662
1616
|
var w;
|
|
1663
1617
|
return (w = e.onStatus) == null ? void 0 : w.call(e, f);
|
|
1664
1618
|
}
|
|
1665
|
-
}), l = await
|
|
1619
|
+
}), l = await pn({
|
|
1666
1620
|
wallet: e.wallet,
|
|
1667
1621
|
publicClient: e.publicClient,
|
|
1668
1622
|
activeChain: e.activeChain,
|
|
@@ -1683,34 +1637,34 @@ async function Qn(e) {
|
|
|
1683
1637
|
});
|
|
1684
1638
|
return (d = e.onStatus) == null || d.call(e, "success"), {
|
|
1685
1639
|
hash: l.receipt.transactionHash,
|
|
1686
|
-
explorerUrl:
|
|
1640
|
+
explorerUrl: le(l.receipt.transactionHash, e.activeChain),
|
|
1687
1641
|
quote: i,
|
|
1688
1642
|
receiptSummary: l.summary,
|
|
1689
1643
|
swap: l.swapDetails
|
|
1690
1644
|
};
|
|
1691
1645
|
}
|
|
1692
|
-
async function
|
|
1646
|
+
async function yn(e, t) {
|
|
1693
1647
|
try {
|
|
1694
1648
|
return await e.estimateGas(t) * 12n / 10n;
|
|
1695
1649
|
} catch {
|
|
1696
1650
|
return;
|
|
1697
1651
|
}
|
|
1698
1652
|
}
|
|
1699
|
-
const
|
|
1700
|
-
function
|
|
1701
|
-
return e.address.toLowerCase() ===
|
|
1653
|
+
const En = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
1654
|
+
function xe(e) {
|
|
1655
|
+
return e.address.toLowerCase() === En.toLowerCase();
|
|
1702
1656
|
}
|
|
1703
|
-
class
|
|
1657
|
+
class bn extends Error {
|
|
1704
1658
|
constructor(n) {
|
|
1705
1659
|
super("Price moved beyond your slippage tolerance. Review the updated quote and try again.");
|
|
1706
|
-
|
|
1660
|
+
S(this, "quote");
|
|
1707
1661
|
this.name = "KyberSwapPriceMovedError", this.quote = n;
|
|
1708
1662
|
}
|
|
1709
1663
|
}
|
|
1710
|
-
async function
|
|
1664
|
+
async function An(e) {
|
|
1711
1665
|
var a;
|
|
1712
|
-
if (
|
|
1713
|
-
const t = () =>
|
|
1666
|
+
if (xe(e.inputToken)) return { approvalHashes: [], allowance: e.amount };
|
|
1667
|
+
const t = () => B({
|
|
1714
1668
|
publicClient: e.publicClient,
|
|
1715
1669
|
token: e.inputToken.address,
|
|
1716
1670
|
owner: e.wallet.account,
|
|
@@ -1721,7 +1675,7 @@ async function vn(e) {
|
|
|
1721
1675
|
(a = e.onStatus) == null || a.call(e, "approving");
|
|
1722
1676
|
const o = [];
|
|
1723
1677
|
if (n > 0n && o.push(
|
|
1724
|
-
await
|
|
1678
|
+
await ee({
|
|
1725
1679
|
provider: e.wallet.provider,
|
|
1726
1680
|
publicClient: e.publicClient,
|
|
1727
1681
|
account: e.wallet.account,
|
|
@@ -1731,7 +1685,7 @@ async function vn(e) {
|
|
|
1731
1685
|
amount: 0n
|
|
1732
1686
|
})
|
|
1733
1687
|
), o.push(
|
|
1734
|
-
await
|
|
1688
|
+
await ee({
|
|
1735
1689
|
provider: e.wallet.provider,
|
|
1736
1690
|
publicClient: e.publicClient,
|
|
1737
1691
|
account: e.wallet.account,
|
|
@@ -1740,11 +1694,11 @@ async function vn(e) {
|
|
|
1740
1694
|
spender: e.spender,
|
|
1741
1695
|
amount: e.approvalMode === "max" ? void 0 : e.amount
|
|
1742
1696
|
})
|
|
1743
|
-
), n = await
|
|
1697
|
+
), n = await X(t, (i) => i >= e.amount, 5, 300), n < e.amount)
|
|
1744
1698
|
throw new Error("Approval confirmed, but allowance is still below this quote. Try again.");
|
|
1745
1699
|
return { approvalHashes: o, allowance: n };
|
|
1746
1700
|
}
|
|
1747
|
-
function
|
|
1701
|
+
function Sn(e) {
|
|
1748
1702
|
return {
|
|
1749
1703
|
mode: "exactIn",
|
|
1750
1704
|
inputSymbol: e.inputToken.symbol,
|
|
@@ -1755,7 +1709,7 @@ function xn(e) {
|
|
|
1755
1709
|
feeBps: e.feeBps
|
|
1756
1710
|
};
|
|
1757
1711
|
}
|
|
1758
|
-
function
|
|
1712
|
+
function In(e) {
|
|
1759
1713
|
const t = e.gasUsed ?? 0n, n = e.effectiveGasPrice ?? 0n;
|
|
1760
1714
|
return {
|
|
1761
1715
|
transactionHash: e.transactionHash,
|
|
@@ -1765,14 +1719,14 @@ function On(e) {
|
|
|
1765
1719
|
feeWei: t * n
|
|
1766
1720
|
};
|
|
1767
1721
|
}
|
|
1768
|
-
async function
|
|
1769
|
-
var
|
|
1770
|
-
await
|
|
1722
|
+
async function zn(e) {
|
|
1723
|
+
var s, d, f, w, A;
|
|
1724
|
+
await _e({
|
|
1771
1725
|
provider: e.wallet.provider,
|
|
1772
1726
|
chain: e.activeChain,
|
|
1773
1727
|
onChainId: e.onWalletChainId
|
|
1774
1728
|
});
|
|
1775
|
-
const t = e.displayedQuote ?? await
|
|
1729
|
+
const t = e.displayedQuote ?? await g(
|
|
1776
1730
|
e.inputToken,
|
|
1777
1731
|
e.outputToken,
|
|
1778
1732
|
e.amount,
|
|
@@ -1781,7 +1735,7 @@ async function Yn(e) {
|
|
|
1781
1735
|
null,
|
|
1782
1736
|
e.signal
|
|
1783
1737
|
);
|
|
1784
|
-
await
|
|
1738
|
+
await An({
|
|
1785
1739
|
wallet: e.wallet,
|
|
1786
1740
|
publicClient: e.publicClient,
|
|
1787
1741
|
activeChain: e.activeChain,
|
|
@@ -1790,8 +1744,8 @@ async function Yn(e) {
|
|
|
1790
1744
|
amount: t.amountIn,
|
|
1791
1745
|
approvalMode: e.approvalMode ?? "exact",
|
|
1792
1746
|
onStatus: e.onStatus
|
|
1793
|
-
}), (
|
|
1794
|
-
const n = await
|
|
1747
|
+
}), (s = e.onStatus) == null || s.call(e, "submitting");
|
|
1748
|
+
const n = await g(
|
|
1795
1749
|
e.inputToken,
|
|
1796
1750
|
e.outputToken,
|
|
1797
1751
|
e.amount,
|
|
@@ -1801,13 +1755,13 @@ async function Yn(e) {
|
|
|
1801
1755
|
e.signal
|
|
1802
1756
|
);
|
|
1803
1757
|
if (e.displayedQuote && n.amountOut < e.displayedQuote.userAmountOutMinimum)
|
|
1804
|
-
throw (d = e.onStatus) == null || d.call(e, "idle"), new
|
|
1758
|
+
throw (d = e.onStatus) == null || d.call(e, "idle"), new bn(n);
|
|
1805
1759
|
if (!n.calldata) throw new Error("Swap route could not be encoded. Try again.");
|
|
1806
|
-
const o = n.transactionValue || (
|
|
1760
|
+
const o = n.transactionValue || (xe(e.inputToken) ? n.amountIn : 0n), a = P({
|
|
1807
1761
|
account: e.wallet.account,
|
|
1808
1762
|
chain: e.activeChain.chain,
|
|
1809
|
-
transport:
|
|
1810
|
-
}), i = await
|
|
1763
|
+
transport: k(e.wallet.provider)
|
|
1764
|
+
}), i = await yn(e.publicClient, {
|
|
1811
1765
|
account: e.wallet.account,
|
|
1812
1766
|
to: n.routerAddress,
|
|
1813
1767
|
data: n.calldata,
|
|
@@ -1819,43 +1773,43 @@ async function Yn(e) {
|
|
|
1819
1773
|
...i ? { gas: i } : {}
|
|
1820
1774
|
});
|
|
1821
1775
|
(f = e.onTxHash) == null || f.call(e, c);
|
|
1822
|
-
const r =
|
|
1776
|
+
const r = Sn(n);
|
|
1823
1777
|
try {
|
|
1824
1778
|
(w = e.onSubmitted) == null || w.call(e, c, r);
|
|
1825
|
-
} catch (
|
|
1826
|
-
console.warn("[AegisCore] onSubmitted callback failed",
|
|
1779
|
+
} catch (E) {
|
|
1780
|
+
console.warn("[AegisCore] onSubmitted callback failed", E);
|
|
1827
1781
|
}
|
|
1828
1782
|
let u = null;
|
|
1829
1783
|
const l = await e.publicClient.waitForTransactionReceipt({
|
|
1830
1784
|
hash: c,
|
|
1831
|
-
onReplaced: (
|
|
1785
|
+
onReplaced: (E) => {
|
|
1832
1786
|
var h;
|
|
1833
|
-
u =
|
|
1787
|
+
u = E.reason, (h = e.onTxHash) == null || h.call(e, E.transaction.hash);
|
|
1834
1788
|
}
|
|
1835
1789
|
});
|
|
1836
1790
|
if (u === "cancelled") throw new Error("Swap was cancelled in the wallet.");
|
|
1837
1791
|
if (l.status === "reverted") throw new Error("Swap reverted on-chain.");
|
|
1838
|
-
const
|
|
1839
|
-
return (
|
|
1792
|
+
const p = In(l);
|
|
1793
|
+
return (A = e.onStatus) == null || A.call(e, "success"), {
|
|
1840
1794
|
hash: l.transactionHash,
|
|
1841
|
-
explorerUrl:
|
|
1795
|
+
explorerUrl: le(l.transactionHash, e.activeChain),
|
|
1842
1796
|
quote: n,
|
|
1843
|
-
receiptSummary:
|
|
1797
|
+
receiptSummary: p,
|
|
1844
1798
|
swap: r
|
|
1845
1799
|
};
|
|
1846
1800
|
}
|
|
1847
|
-
function
|
|
1801
|
+
function Vn(e) {
|
|
1848
1802
|
return e === "approving" || e === "signing" || e === "submitting";
|
|
1849
1803
|
}
|
|
1850
|
-
const
|
|
1804
|
+
const Cn = {
|
|
1851
1805
|
total: 0,
|
|
1852
1806
|
completed: 0,
|
|
1853
1807
|
active: null
|
|
1854
1808
|
};
|
|
1855
|
-
function
|
|
1809
|
+
function N({ total: e, completed: t }) {
|
|
1856
1810
|
return e <= 0 ? 0 : t / e * 100;
|
|
1857
1811
|
}
|
|
1858
|
-
function
|
|
1812
|
+
function Tn({
|
|
1859
1813
|
status: e,
|
|
1860
1814
|
txHash: t,
|
|
1861
1815
|
approvalRequired: n,
|
|
@@ -1863,7 +1817,7 @@ function Dn({
|
|
|
1863
1817
|
authorizationRequired: a
|
|
1864
1818
|
}) {
|
|
1865
1819
|
const i = n || o, c = a, r = e === "idle" && !o ? 0 : 1 + (i ? 1 : 0) + (c ? 1 : 0);
|
|
1866
|
-
if (r === 0) return
|
|
1820
|
+
if (r === 0) return Cn;
|
|
1867
1821
|
if (e === "success") return { total: r, completed: r, active: null };
|
|
1868
1822
|
if (e === "idle")
|
|
1869
1823
|
return {
|
|
@@ -1873,8 +1827,8 @@ function Dn({
|
|
|
1873
1827
|
};
|
|
1874
1828
|
if (e === "approving") {
|
|
1875
1829
|
if (o && c) {
|
|
1876
|
-
const
|
|
1877
|
-
return { total: r, completed:
|
|
1830
|
+
const p = i ? 1 : 0;
|
|
1831
|
+
return { total: r, completed: p, active: p + 1 };
|
|
1878
1832
|
}
|
|
1879
1833
|
return {
|
|
1880
1834
|
total: r,
|
|
@@ -1896,7 +1850,7 @@ function Dn({
|
|
|
1896
1850
|
active: t ? null : r
|
|
1897
1851
|
};
|
|
1898
1852
|
}
|
|
1899
|
-
function
|
|
1853
|
+
function Hn({
|
|
1900
1854
|
status: e,
|
|
1901
1855
|
inputSymbol: t,
|
|
1902
1856
|
txHash: n,
|
|
@@ -1905,7 +1859,7 @@ function Zn({
|
|
|
1905
1859
|
approvalDone: i,
|
|
1906
1860
|
authorizationRequired: c
|
|
1907
1861
|
}) {
|
|
1908
|
-
const r =
|
|
1862
|
+
const r = Tn({
|
|
1909
1863
|
status: e,
|
|
1910
1864
|
txHash: n,
|
|
1911
1865
|
approvalRequired: a,
|
|
@@ -1928,116 +1882,114 @@ function Zn({
|
|
|
1928
1882
|
state: "pending",
|
|
1929
1883
|
label: `ERC20 approval complete · ready to swap · ${r.completed} of ${r.total} prompts done`,
|
|
1930
1884
|
walletPrompts: r,
|
|
1931
|
-
completePct:
|
|
1885
|
+
completePct: N(r),
|
|
1932
1886
|
activeWidthPct: 0
|
|
1933
1887
|
} : null : e === "approving" ? {
|
|
1934
1888
|
state: "pending",
|
|
1935
1889
|
label: i && c ? `Approving Permit2 router · wallet prompt ${r.active ?? 1} of ${r.total}` : `Approving ${t} for Permit2 · wallet prompt ${r.active ?? 1} of ${r.total}`,
|
|
1936
1890
|
walletPrompts: r,
|
|
1937
|
-
completePct:
|
|
1891
|
+
completePct: N(r),
|
|
1938
1892
|
activeWidthPct: 100
|
|
1939
1893
|
} : a || i ? {
|
|
1940
1894
|
state: e === "submitting" && n ? "mining" : "pending",
|
|
1941
1895
|
label: e === "signing" ? `ERC20 approval complete · sign Permit2 permit · wallet prompt ${r.active ?? 2} of ${r.total}` : n ? `Confirming swap · ${r.completed} of ${r.total} wallet prompts complete` : `Approve complete · submitting swap · wallet prompt ${r.active ?? r.total} of ${r.total}`,
|
|
1942
1896
|
walletPrompts: r,
|
|
1943
|
-
completePct:
|
|
1897
|
+
completePct: N(r),
|
|
1944
1898
|
activeWidthPct: 100
|
|
1945
1899
|
} : {
|
|
1946
1900
|
state: e === "submitting" && n ? "mining" : "pending",
|
|
1947
1901
|
label: e === "signing" ? c ? `Signing Permit2 spending permit · wallet prompt ${r.active ?? 1} of ${r.total}` : "Preparing swap" : n ? `Confirming swap on-chain · ${r.completed} of ${r.total} wallet prompts complete` : `Submitting swap · wallet prompt ${r.active ?? r.total} of ${r.total}`,
|
|
1948
1902
|
walletPrompts: r,
|
|
1949
|
-
completePct:
|
|
1903
|
+
completePct: N(r),
|
|
1950
1904
|
activeWidthPct: 100
|
|
1951
1905
|
};
|
|
1952
1906
|
}
|
|
1953
1907
|
export {
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1908
|
+
Pn as AEGIS_DYNAMIC_FEE_FLAG,
|
|
1909
|
+
H as AEGIS_SWAP_CHAINS,
|
|
1910
|
+
y as AEGIS_SWAP_CHAIN_ID,
|
|
1911
|
+
et as AEGIS_SWAP_DEFAULT_FEE_BPS,
|
|
1958
1912
|
pe as AEGIS_SWAP_DEFAULT_FEE_RECIPIENT,
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
Zn as transactionProgressView,
|
|
2042
|
-
bn as waitForProviderChain
|
|
1913
|
+
at as AEGIS_SWAP_DEFAULT_METADATA_ENDPOINT,
|
|
1914
|
+
ot as AEGIS_SWAP_DEFAULT_RPC_URLS,
|
|
1915
|
+
On as AEGIS_SWAP_HOOK,
|
|
1916
|
+
it as AEGIS_SWAP_MAINNET_CHAIN,
|
|
1917
|
+
V as AEGIS_SWAP_MAINNET_UNISWAP_V4_CONTRACTS,
|
|
1918
|
+
tt as AEGIS_SWAP_PERMIT2,
|
|
1919
|
+
ge as AEGIS_SWAP_ROUTER,
|
|
1920
|
+
x as AEGIS_SWAP_TOKENS,
|
|
1921
|
+
nt as AEGIS_SWAP_V4_QUOTER,
|
|
1922
|
+
Mn as AGGREGATED_SWAP_CURATED_TOKENS,
|
|
1923
|
+
j as AGGREGATED_SWAP_DEFAULT_TOKENS,
|
|
1924
|
+
ct as AGGREGATED_SWAP_DEFAULT_TOKEN_LIST,
|
|
1925
|
+
kn as AGGREGATED_SWAP_TOKEN_PRESETS,
|
|
1926
|
+
rt as AGGREGATED_SWAP_WOLFGAME_TOKENS,
|
|
1927
|
+
ut as AGGREGATED_SWAP_WOLFGAME_TOKEN_LIST,
|
|
1928
|
+
Te as DEFAULT_PERMIT_EXPIRATION_SECONDS,
|
|
1929
|
+
dn as DirectPoolSwapPriceMovedError,
|
|
1930
|
+
ye as KyberSwapApiError,
|
|
1931
|
+
bn as KyberSwapPriceMovedError,
|
|
1932
|
+
Ge as MAX_UINT128,
|
|
1933
|
+
F as MAX_UINT160,
|
|
1934
|
+
Ie as MAX_UINT256,
|
|
1935
|
+
En as NATIVE_TOKEN_ADDRESS,
|
|
1936
|
+
$t as PERMIT2_FAR_FUTURE_EXPIRATION,
|
|
1937
|
+
Ce as SWAP_TX_DEADLINE_SECONDS,
|
|
1938
|
+
me as UNISWAP_V4_CONTRACTS_BY_CHAIN,
|
|
1939
|
+
Fn as aggregatedSwapErrorMessage,
|
|
1940
|
+
wn as approveDirectPoolSwapInput,
|
|
1941
|
+
ee as approveErc20Spender,
|
|
1942
|
+
zt as approveErc20ToPermit2,
|
|
1943
|
+
An as approveKyberSwapInput,
|
|
1944
|
+
Vt as approvePermit2ToRouter,
|
|
1945
|
+
M as assertUint128,
|
|
1946
|
+
Je as buildExactInSwapTransaction,
|
|
1947
|
+
Ze as buildExactOutSwapTransaction,
|
|
1948
|
+
Mt as buildKyberSwapRoute,
|
|
1949
|
+
Ht as buildSignedPermitBatch,
|
|
1950
|
+
ce as computePoolId,
|
|
1951
|
+
mt as createAegisSwapChainConfig,
|
|
1952
|
+
Rn as createAegisSwapChains,
|
|
1953
|
+
Dn as createAegisSwapMarketsFromPools,
|
|
1954
|
+
st as createAegisSwapPoolMarket,
|
|
1955
|
+
I as createAegisSwapUniswapV4Contracts,
|
|
1956
|
+
Gn as createSwapPublicClient,
|
|
1957
|
+
_e as ensureWalletChain,
|
|
1958
|
+
_t as errorMessage,
|
|
1959
|
+
yn as estimateSwapGasWithBuffer,
|
|
1960
|
+
qn as executeDirectPoolSwap,
|
|
1961
|
+
zn as executeKyberSwap,
|
|
1962
|
+
g as fetchAggregatedSwapQuote,
|
|
1963
|
+
fn as fetchDirectPoolSwapQuote,
|
|
1964
|
+
Un as fetchGlobalTokenMetadata,
|
|
1965
|
+
kt as fetchKyberSwapRoute,
|
|
1966
|
+
le as getExplorerUrl,
|
|
1967
|
+
Yt as getIchiIconGuess,
|
|
1968
|
+
Zt as getInjectedProvider,
|
|
1969
|
+
tn as getProviderAccount,
|
|
1970
|
+
L as getProviderChainId,
|
|
1971
|
+
Et as getZeroForOne,
|
|
1972
|
+
Vn as isBusy,
|
|
1973
|
+
Wn as isDocumentVisible,
|
|
1974
|
+
gt as isEip1193Provider,
|
|
1975
|
+
xe as isNativeToken,
|
|
1976
|
+
Se as isRetryableKyberSwapError,
|
|
1977
|
+
we as isUserRejectedError,
|
|
1978
|
+
U as normalizeAccount,
|
|
1979
|
+
en as normalizeWalletConnection,
|
|
1980
|
+
Tt as outputFeeForQuote,
|
|
1981
|
+
X as pollUntil,
|
|
1982
|
+
Ct as quoteSpendAmount,
|
|
1983
|
+
B as readErc20Allowance,
|
|
1984
|
+
ve as readPermit2RouterAllowance,
|
|
1985
|
+
It as reconcileSubmitQuote,
|
|
1986
|
+
nn as requestProviderAccount,
|
|
1987
|
+
Bn as resolveTokenIconUrl,
|
|
1988
|
+
$n as resolveWalletSession,
|
|
1989
|
+
Ln as retryOnError,
|
|
1990
|
+
Nn as sameQuote,
|
|
1991
|
+
Kn as subscribeProvider,
|
|
1992
|
+
ln as switchProviderChain,
|
|
1993
|
+
Hn as transactionProgressView,
|
|
1994
|
+
sn as waitForProviderChain
|
|
2043
1995
|
};
|