@latchprotocol/widgets 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 +33 -1
- package/dist/chunks/{SwapWidget-DgyHAVc8.js → SwapWidget-CwkRtOfn.js} +58 -66
- package/dist/chunks/SwapWidget-CwkRtOfn.js.map +1 -0
- package/dist/chunks/{useLocker-D1c_NTk-.js → useLocker-CGpgCh75.js} +641 -641
- package/dist/chunks/{useLocker-D1c_NTk-.js.map → useLocker-CGpgCh75.js.map} +1 -1
- package/dist/components/LaunchWidget.d.ts.map +1 -1
- package/dist/embed.js +12 -12
- package/dist/embed.js.map +1 -1
- package/dist/headless.js +1 -1
- package/dist/index.js +87 -87
- package/dist/index.js.map +1 -1
- package/dist/latch-embed.js +1 -1
- package/dist/latch-embed.js.map +1 -1
- package/dist/latch-embed.mjs +4 -5
- package/dist/latch-embed.mjs.map +1 -1
- package/dist/trust/model.d.ts +4 -3
- package/dist/trust/model.d.ts.map +1 -1
- package/package.json +1 -5
- package/dist/chunks/SwapWidget-DgyHAVc8.js.map +0 -1
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { encodeAbiParameters as
|
|
2
|
-
import { NATIVE_CURRENCY as
|
|
3
|
-
import { B as O, b6 as F, A
|
|
4
|
-
import { useState as
|
|
5
|
-
import { describeTokenLocks as
|
|
6
|
-
import { readFeeGate as
|
|
7
|
-
function
|
|
8
|
-
if (
|
|
9
|
-
throw new RangeError(`binIdLower ${
|
|
1
|
+
import { encodeAbiParameters as C, encodeFunctionData as P, isAddressEqual as b, BaseError as J, ExecutionRevertedError as Z, decodeAbiParameters as It, zeroAddress as Lt, parseUnits as Ct } from "viem";
|
|
2
|
+
import { NATIVE_CURRENCY as At, quoterAbiFor as Tt, isDynamicLPFee as Mt, BIN_LAUNCH_GUARD_HOOK_ABI as tt, readBinPoolKeyParameters as et, binRawPriceFromId as nt, poolKeyToId as ot, readCLPoolKeyParameters as Nt, LAUNCHPAD_KIT_V2_ABI as St, getDeployment as Pt, CLOCK_MODE_CALLDATA as $t, TIMESTAMP_CLOCK_MODE as Bt, readContractClock as xt, readTokenMeta as Dt } from "@latchprotocol/sdk";
|
|
3
|
+
import { B as O, b6 as F, A, t as j, u as G, p as Q, E as N, w as f, bj as I, P as it, m as Ot, l as Et, n as _t, aT as at, W as E, a4 as Rt, bu as Ft, aI as Gt, aJ as st, G as U, _ as qt, bA as Ut, X as rt, ae as Kt, aN as Xt, aY as Yt, F as Wt, b$ as mt, bF as $, b9 as Ht, ao as Vt, ap as jt, bx as Qt, bq as ct, aj as zt, bL as Jt } from "./scan-Dhu7f4Nl.js";
|
|
4
|
+
import { useState as ht, useEffect as Zt, useRef as te, useCallback as ut, useMemo as ee } from "react";
|
|
5
|
+
import { describeTokenLocks as ne, describeLaunch as oe, summarizeTokenTrust as ie, describeLiquidity as ae, describeLpFee as se, describeProtocolFee as re, describeCreatorTax as yt, describeRegistry as ce, formatTrustSource as ue, readTokenTrust as le } from "@latchprotocol/sdk/trust";
|
|
6
|
+
import { readFeeGate as lt, readChainNow as de, readPositionLocksOf as pe, readBeneficiaryLocks as me } from "@latchprotocol/sdk/lock";
|
|
7
|
+
function he(e, t, o) {
|
|
8
|
+
if (e > t)
|
|
9
|
+
throw new RangeError(`binIdLower ${e} exceeds binIdUpper ${t}`);
|
|
10
10
|
const n = [];
|
|
11
|
-
for (let p =
|
|
12
|
-
const
|
|
11
|
+
for (let p = e; p <= t; p += 1) n.push(p);
|
|
12
|
+
const i = n.filter((p) => p >= o).length, a = n.filter((p) => p <= o).length, s = t, r = Math.min(o, t), l = [];
|
|
13
13
|
let c = 0n, d = 0n;
|
|
14
14
|
for (const p of n) {
|
|
15
|
-
const m = p >= o &&
|
|
15
|
+
const m = p >= o && i > 0 ? O / BigInt(i) : 0n, u = p <= o && a > 0 ? O / BigInt(a) : 0n, h = p === s && m > 0n ? O - c : m, y = p === r && u > 0n ? O - d : u;
|
|
16
16
|
c += h, d += y, l.push({ binId: p, deltaId: p - o, distributionX: h, distributionY: y });
|
|
17
17
|
}
|
|
18
18
|
return l;
|
|
19
19
|
}
|
|
20
|
-
class
|
|
20
|
+
class Ee extends Error {
|
|
21
21
|
constructor() {
|
|
22
22
|
super(
|
|
23
23
|
"[@latchprotocol/widgets] no sale adapter is configured. Latch has no sale contract - a launch is a pool with LaunchGuardHook attached, and buying into one is a swap. Set ProtocolAdapter.sale only if you run your own sale contract."
|
|
24
24
|
), this.name = "NoSaleAdapterError";
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
return
|
|
27
|
+
function _e(e) {
|
|
28
|
+
return e.sale !== void 0;
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const ye = [
|
|
31
31
|
{ name: "poolKey", type: "tuple", components: j },
|
|
32
32
|
{ name: "tickLower", type: "int24" },
|
|
33
33
|
{ name: "tickUpper", type: "int24" },
|
|
@@ -36,31 +36,31 @@ const yt = [
|
|
|
36
36
|
{ name: "amount1Max", type: "uint128" },
|
|
37
37
|
{ name: "owner", type: "address" },
|
|
38
38
|
{ name: "hookData", type: "bytes" }
|
|
39
|
-
],
|
|
39
|
+
], fe = [
|
|
40
40
|
{ name: "tokenId", type: "uint256" },
|
|
41
41
|
{ name: "liquidity", type: "uint256" },
|
|
42
42
|
{ name: "amount0", type: "uint128" },
|
|
43
43
|
{ name: "amount1", type: "uint128" },
|
|
44
44
|
{ name: "hookData", type: "bytes" }
|
|
45
|
-
],
|
|
45
|
+
], ft = [
|
|
46
46
|
{ name: "currency0", type: "address" },
|
|
47
47
|
{ name: "currency1", type: "address" }
|
|
48
|
-
],
|
|
48
|
+
], kt = [
|
|
49
49
|
{ name: "currency0", type: "address" },
|
|
50
50
|
{ name: "currency1", type: "address" },
|
|
51
51
|
{ name: "recipient", type: "address" }
|
|
52
|
-
],
|
|
52
|
+
], ke = [
|
|
53
53
|
{ name: "currency", type: "address" },
|
|
54
54
|
{ name: "to", type: "address" }
|
|
55
55
|
];
|
|
56
|
-
function
|
|
56
|
+
function bt() {
|
|
57
57
|
return [
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
A.SWEEP,
|
|
59
|
+
C(ke, [At, Q]),
|
|
60
60
|
"sweep unspent native value back to the caller"
|
|
61
61
|
];
|
|
62
62
|
}
|
|
63
|
-
const
|
|
63
|
+
const be = [
|
|
64
64
|
{
|
|
65
65
|
name: "params",
|
|
66
66
|
type: "tuple",
|
|
@@ -80,7 +80,7 @@ const bt = [
|
|
|
80
80
|
{ name: "hookData", type: "bytes" }
|
|
81
81
|
]
|
|
82
82
|
}
|
|
83
|
-
],
|
|
83
|
+
], we = [
|
|
84
84
|
{
|
|
85
85
|
name: "params",
|
|
86
86
|
type: "tuple",
|
|
@@ -95,180 +95,180 @@ const bt = [
|
|
|
95
95
|
]
|
|
96
96
|
}
|
|
97
97
|
];
|
|
98
|
-
function z(
|
|
98
|
+
function z(e) {
|
|
99
99
|
return {
|
|
100
|
-
currency0:
|
|
101
|
-
currency1:
|
|
102
|
-
hooks:
|
|
103
|
-
poolManager:
|
|
104
|
-
fee:
|
|
105
|
-
parameters:
|
|
100
|
+
currency0: e.currency0,
|
|
101
|
+
currency1: e.currency1,
|
|
102
|
+
hooks: e.hooks,
|
|
103
|
+
poolManager: e.poolManager,
|
|
104
|
+
fee: e.fee,
|
|
105
|
+
parameters: e.parameters
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
if (
|
|
110
|
-
throw new RangeError(`[@latchprotocol/widgets] liquidity must be positive: ${
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
z(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
108
|
+
function ge(e) {
|
|
109
|
+
if (Ce(e.tickLower, e.tickUpper), e.liquidity <= 0n)
|
|
110
|
+
throw new RangeError(`[@latchprotocol/widgets] liquidity must be positive: ${e.liquidity}`);
|
|
111
|
+
const t = F().add(
|
|
112
|
+
A.CL_MINT_POSITION,
|
|
113
|
+
C(ye, [
|
|
114
|
+
z(e.poolKey),
|
|
115
|
+
e.tickLower,
|
|
116
|
+
e.tickUpper,
|
|
117
|
+
e.liquidity,
|
|
118
|
+
e.amount0Max,
|
|
119
|
+
e.amount1Max,
|
|
120
|
+
e.owner,
|
|
121
|
+
e.hookData ?? "0x"
|
|
122
122
|
]),
|
|
123
|
-
`mint CL position [${
|
|
123
|
+
`mint CL position [${e.tickLower}, ${e.tickUpper}]`
|
|
124
124
|
).add(
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
A.SETTLE_PAIR,
|
|
126
|
+
C(ft, [e.poolKey.currency0, e.poolKey.currency1]),
|
|
127
127
|
"settle both currencies from the caller"
|
|
128
128
|
);
|
|
129
|
-
return (
|
|
130
|
-
to:
|
|
131
|
-
data:
|
|
129
|
+
return (e.value ?? 0n) > 0n && t.add(...bt()), {
|
|
130
|
+
to: e.positionManager,
|
|
131
|
+
data: P({
|
|
132
132
|
abi: G,
|
|
133
133
|
functionName: "modifyLiquidities",
|
|
134
|
-
args: [
|
|
134
|
+
args: [t.encode(), e.deadline]
|
|
135
135
|
}),
|
|
136
|
-
value:
|
|
137
|
-
planTrace:
|
|
136
|
+
value: e.value ?? 0n,
|
|
137
|
+
planTrace: t.describe()
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
|
-
function
|
|
141
|
-
if (
|
|
140
|
+
function ve(e) {
|
|
141
|
+
if (e.liquidity <= 0n)
|
|
142
142
|
throw new RangeError(
|
|
143
|
-
`[@latchprotocol/widgets] liquidity to remove must be positive: ${
|
|
143
|
+
`[@latchprotocol/widgets] liquidity to remove must be positive: ${e.liquidity}`
|
|
144
144
|
);
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
145
|
+
const t = e.recipient === e.owner ? Q : e.recipient, o = F().add(
|
|
146
|
+
A.CL_DECREASE_LIQUIDITY,
|
|
147
|
+
C(fe, [
|
|
148
|
+
e.tokenId,
|
|
149
|
+
e.liquidity,
|
|
150
|
+
e.amount0Min,
|
|
151
|
+
e.amount1Min,
|
|
152
|
+
e.hookData ?? "0x"
|
|
153
153
|
]),
|
|
154
|
-
`decrease CL position #${
|
|
154
|
+
`decrease CL position #${e.tokenId} by ${e.liquidity}`
|
|
155
155
|
).add(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
156
|
+
A.TAKE_PAIR,
|
|
157
|
+
C(kt, [
|
|
158
|
+
e.poolKey.currency0,
|
|
159
|
+
e.poolKey.currency1,
|
|
160
|
+
t
|
|
161
161
|
]),
|
|
162
162
|
"take both currencies to the recipient"
|
|
163
163
|
);
|
|
164
164
|
return {
|
|
165
|
-
to:
|
|
166
|
-
data:
|
|
165
|
+
to: e.positionManager,
|
|
166
|
+
data: P({
|
|
167
167
|
abi: G,
|
|
168
168
|
functionName: "modifyLiquidities",
|
|
169
|
-
args: [o.encode(),
|
|
169
|
+
args: [o.encode(), e.deadline]
|
|
170
170
|
}),
|
|
171
171
|
value: 0n,
|
|
172
172
|
planTrace: o.describe()
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
|
-
function
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
175
|
+
function Ie(e) {
|
|
176
|
+
const t = e.deltaIds.length;
|
|
177
|
+
if (t === 0)
|
|
178
178
|
throw new RangeError("[@latchprotocol/widgets] a bin mint must target at least one bin");
|
|
179
|
-
if (
|
|
179
|
+
if (e.distributionX.length !== t || e.distributionY.length !== t)
|
|
180
180
|
throw new RangeError(
|
|
181
181
|
"[@latchprotocol/widgets] deltaIds, distributionX and distributionY must be the same length"
|
|
182
182
|
);
|
|
183
|
-
if (!Number.isInteger(
|
|
183
|
+
if (!Number.isInteger(e.activeIdDesired) || e.activeIdDesired < 0)
|
|
184
184
|
throw new RangeError(
|
|
185
|
-
`[@latchprotocol/widgets] activeIdDesired must be a non-negative integer: ${
|
|
185
|
+
`[@latchprotocol/widgets] activeIdDesired must be a non-negative integer: ${e.activeIdDesired}`
|
|
186
186
|
);
|
|
187
187
|
const o = F().add(
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
A.BIN_ADD_LIQUIDITY,
|
|
189
|
+
C(be, [
|
|
190
190
|
{
|
|
191
|
-
poolKey: z(
|
|
192
|
-
amount0:
|
|
193
|
-
amount1:
|
|
194
|
-
amount0Max:
|
|
195
|
-
amount1Max:
|
|
196
|
-
activeIdDesired: BigInt(
|
|
197
|
-
idSlippage: BigInt(
|
|
198
|
-
deltaIds:
|
|
199
|
-
distributionX: [...
|
|
200
|
-
distributionY: [...
|
|
191
|
+
poolKey: z(e.poolKey),
|
|
192
|
+
amount0: e.amount0,
|
|
193
|
+
amount1: e.amount1,
|
|
194
|
+
amount0Max: e.amount0Max,
|
|
195
|
+
amount1Max: e.amount1Max,
|
|
196
|
+
activeIdDesired: BigInt(e.activeIdDesired),
|
|
197
|
+
idSlippage: BigInt(e.idSlippage),
|
|
198
|
+
deltaIds: e.deltaIds.map((n) => BigInt(n)),
|
|
199
|
+
distributionX: [...e.distributionX],
|
|
200
|
+
distributionY: [...e.distributionY],
|
|
201
201
|
// One entry per bin. Zero means "accept whatever the pool mints"; the
|
|
202
202
|
// real slippage guard for a bin mint is idSlippage plus amountNMax.
|
|
203
|
-
minLiquidities:
|
|
204
|
-
to:
|
|
205
|
-
hookData:
|
|
203
|
+
minLiquidities: e.deltaIds.map(() => 0n),
|
|
204
|
+
to: e.to,
|
|
205
|
+
hookData: e.hookData ?? "0x"
|
|
206
206
|
}
|
|
207
207
|
]),
|
|
208
|
-
`add bin liquidity across ${
|
|
208
|
+
`add bin liquidity across ${t} bins around id ${e.activeIdDesired}`
|
|
209
209
|
).add(
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
A.SETTLE_PAIR,
|
|
211
|
+
C(ft, [e.poolKey.currency0, e.poolKey.currency1]),
|
|
212
212
|
"settle both currencies from the caller"
|
|
213
213
|
);
|
|
214
|
-
return (
|
|
215
|
-
to:
|
|
216
|
-
data:
|
|
214
|
+
return (e.value ?? 0n) > 0n && o.add(...bt()), {
|
|
215
|
+
to: e.positionManager,
|
|
216
|
+
data: P({
|
|
217
217
|
abi: G,
|
|
218
218
|
functionName: "modifyLiquidities",
|
|
219
|
-
args: [o.encode(),
|
|
219
|
+
args: [o.encode(), e.deadline]
|
|
220
220
|
}),
|
|
221
|
-
value:
|
|
221
|
+
value: e.value ?? 0n,
|
|
222
222
|
planTrace: o.describe()
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
|
-
function
|
|
226
|
-
if (
|
|
225
|
+
function Le(e) {
|
|
226
|
+
if (e.ids.length === 0)
|
|
227
227
|
throw new RangeError("[@latchprotocol/widgets] a bin burn must target at least one bin");
|
|
228
|
-
if (
|
|
228
|
+
if (e.ids.length !== e.amounts.length)
|
|
229
229
|
throw new RangeError("[@latchprotocol/widgets] ids and amounts must be the same length");
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
const t = e.recipient === e.from ? Q : e.recipient, o = F().add(
|
|
231
|
+
A.BIN_REMOVE_LIQUIDITY,
|
|
232
|
+
C(we, [
|
|
233
233
|
{
|
|
234
|
-
poolKey: z(
|
|
235
|
-
amount0Min:
|
|
236
|
-
amount1Min:
|
|
237
|
-
ids:
|
|
238
|
-
amounts: [...
|
|
239
|
-
from:
|
|
240
|
-
hookData:
|
|
234
|
+
poolKey: z(e.poolKey),
|
|
235
|
+
amount0Min: e.amount0Min,
|
|
236
|
+
amount1Min: e.amount1Min,
|
|
237
|
+
ids: e.ids.map((n) => BigInt(n)),
|
|
238
|
+
amounts: [...e.amounts],
|
|
239
|
+
from: e.from,
|
|
240
|
+
hookData: e.hookData ?? "0x"
|
|
241
241
|
}
|
|
242
242
|
]),
|
|
243
|
-
`remove bin liquidity from ${
|
|
243
|
+
`remove bin liquidity from ${e.ids.length} bins`
|
|
244
244
|
).add(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
245
|
+
A.TAKE_PAIR,
|
|
246
|
+
C(kt, [
|
|
247
|
+
e.poolKey.currency0,
|
|
248
|
+
e.poolKey.currency1,
|
|
249
|
+
t
|
|
250
250
|
]),
|
|
251
251
|
"take both currencies to the recipient"
|
|
252
252
|
);
|
|
253
253
|
return {
|
|
254
|
-
to:
|
|
255
|
-
data:
|
|
254
|
+
to: e.positionManager,
|
|
255
|
+
data: P({
|
|
256
256
|
abi: G,
|
|
257
257
|
functionName: "modifyLiquidities",
|
|
258
|
-
args: [o.encode(),
|
|
258
|
+
args: [o.encode(), e.deadline]
|
|
259
259
|
}),
|
|
260
260
|
value: 0n,
|
|
261
261
|
planTrace: o.describe()
|
|
262
262
|
};
|
|
263
263
|
}
|
|
264
|
-
function
|
|
265
|
-
if (!Number.isInteger(
|
|
264
|
+
function Ce(e, t) {
|
|
265
|
+
if (!Number.isInteger(e) || !Number.isInteger(t))
|
|
266
266
|
throw new RangeError(
|
|
267
|
-
`[@latchprotocol/widgets] ticks must be integers: [${
|
|
267
|
+
`[@latchprotocol/widgets] ticks must be integers: [${e}, ${t}]`
|
|
268
268
|
);
|
|
269
|
-
if (
|
|
269
|
+
if (e >= t)
|
|
270
270
|
throw new RangeError(
|
|
271
|
-
`[@latchprotocol/widgets] tickLower must be below tickUpper: [${
|
|
271
|
+
`[@latchprotocol/widgets] tickLower must be below tickUpper: [${e}, ${t}]`
|
|
272
272
|
);
|
|
273
273
|
}
|
|
274
274
|
const K = [
|
|
@@ -296,7 +296,7 @@ const K = [
|
|
|
296
296
|
{ name: "lpFee", type: "uint24" }
|
|
297
297
|
]
|
|
298
298
|
}
|
|
299
|
-
],
|
|
299
|
+
], dt = 2n ** 192n, _ = [
|
|
300
300
|
{
|
|
301
301
|
type: "function",
|
|
302
302
|
name: "getLiquidity",
|
|
@@ -335,7 +335,7 @@ const K = [
|
|
|
335
335
|
}
|
|
336
336
|
]
|
|
337
337
|
}
|
|
338
|
-
],
|
|
338
|
+
], pt = [
|
|
339
339
|
{
|
|
340
340
|
type: "function",
|
|
341
341
|
name: "getBin",
|
|
@@ -351,7 +351,7 @@ const K = [
|
|
|
351
351
|
{ name: "totalShares", type: "uint256" }
|
|
352
352
|
]
|
|
353
353
|
}
|
|
354
|
-
],
|
|
354
|
+
], wt = {
|
|
355
355
|
name: "poolKey",
|
|
356
356
|
type: "tuple",
|
|
357
357
|
components: [
|
|
@@ -376,7 +376,7 @@ const K = [
|
|
|
376
376
|
stateMutability: "view",
|
|
377
377
|
inputs: [{ name: "tokenId", type: "uint256" }],
|
|
378
378
|
outputs: [
|
|
379
|
-
|
|
379
|
+
wt,
|
|
380
380
|
{ name: "tickLower", type: "int24" },
|
|
381
381
|
{ name: "tickUpper", type: "int24" },
|
|
382
382
|
{ name: "liquidity", type: "uint128" },
|
|
@@ -400,7 +400,7 @@ const K = [
|
|
|
400
400
|
name: "positions",
|
|
401
401
|
stateMutability: "view",
|
|
402
402
|
inputs: [{ name: "tokenId", type: "uint256" }],
|
|
403
|
-
outputs: [
|
|
403
|
+
outputs: [wt, { name: "binId", type: "uint24" }]
|
|
404
404
|
},
|
|
405
405
|
{
|
|
406
406
|
type: "function",
|
|
@@ -424,31 +424,31 @@ const K = [
|
|
|
424
424
|
]
|
|
425
425
|
}
|
|
426
426
|
], S = "0x0000000000000000000000000000000000000000";
|
|
427
|
-
class
|
|
427
|
+
class Ae {
|
|
428
428
|
kind = "viem";
|
|
429
429
|
isMock = !1;
|
|
430
430
|
chain;
|
|
431
|
-
#
|
|
432
|
-
constructor(
|
|
433
|
-
this.#
|
|
431
|
+
#e;
|
|
432
|
+
constructor(t) {
|
|
433
|
+
this.#e = t, this.chain = t.chain;
|
|
434
434
|
}
|
|
435
|
-
get #
|
|
436
|
-
return this.#
|
|
435
|
+
get #t() {
|
|
436
|
+
return this.#e.publicClient;
|
|
437
437
|
}
|
|
438
438
|
get #n() {
|
|
439
|
-
return this.#
|
|
439
|
+
return this.#e.overrides ?? {};
|
|
440
440
|
}
|
|
441
441
|
async getAccount() {
|
|
442
|
-
const
|
|
443
|
-
return
|
|
442
|
+
const t = this.#e.wallet;
|
|
443
|
+
return t === void 0 ? null : t.getAccount();
|
|
444
444
|
}
|
|
445
445
|
async listTokens() {
|
|
446
|
-
return this.#
|
|
446
|
+
return this.#e.tokens;
|
|
447
447
|
}
|
|
448
|
-
async getToken(
|
|
449
|
-
const o = this.#
|
|
448
|
+
async getToken(t) {
|
|
449
|
+
const o = this.#e.tokens.find((s) => b(s.address, t));
|
|
450
450
|
if (o !== void 0) return o;
|
|
451
|
-
if (b(
|
|
451
|
+
if (b(t, S))
|
|
452
452
|
return {
|
|
453
453
|
address: S,
|
|
454
454
|
symbol: this.chain.nativeCurrency.symbol,
|
|
@@ -456,45 +456,45 @@ class Ct {
|
|
|
456
456
|
decimals: this.chain.nativeCurrency.decimals,
|
|
457
457
|
isNative: !0
|
|
458
458
|
};
|
|
459
|
-
const [n,
|
|
460
|
-
this.#
|
|
461
|
-
this.#
|
|
462
|
-
this.#
|
|
459
|
+
const [n, i, a] = await Promise.all([
|
|
460
|
+
this.#t.readContract({ address: t, abi: N, functionName: "symbol" }),
|
|
461
|
+
this.#t.readContract({ address: t, abi: N, functionName: "name" }),
|
|
462
|
+
this.#t.readContract({ address: t, abi: N, functionName: "decimals" })
|
|
463
463
|
]);
|
|
464
|
-
return { address:
|
|
464
|
+
return { address: t, symbol: n, name: i, decimals: Number(a) };
|
|
465
465
|
}
|
|
466
|
-
async getBalance(
|
|
467
|
-
return
|
|
468
|
-
address:
|
|
466
|
+
async getBalance(t, o) {
|
|
467
|
+
return t.isNative === !0 || b(t.address, S) ? this.#t.getBalance({ address: o }) : this.#t.readContract({
|
|
468
|
+
address: t.address,
|
|
469
469
|
abi: N,
|
|
470
470
|
functionName: "balanceOf",
|
|
471
471
|
args: [o]
|
|
472
472
|
});
|
|
473
473
|
}
|
|
474
474
|
async listPools() {
|
|
475
|
-
return this.#
|
|
475
|
+
return this.#e.pools;
|
|
476
476
|
}
|
|
477
477
|
/**
|
|
478
478
|
* The pool's live state from its manager's `getSlot0` (plus `getLiquidity`
|
|
479
479
|
* for a CL pool). An uninitialised pool answers a zero price, which is
|
|
480
480
|
* reported as an error rather than as tick 0.
|
|
481
481
|
*/
|
|
482
|
-
async getPoolState(
|
|
482
|
+
async getPoolState(t) {
|
|
483
483
|
const o = this.#n.getPoolState;
|
|
484
|
-
if (o !== void 0) return o(
|
|
485
|
-
if (
|
|
486
|
-
const [[
|
|
487
|
-
this.#
|
|
488
|
-
this.#
|
|
484
|
+
if (o !== void 0) return o(t);
|
|
485
|
+
if (t.poolType === "CL") {
|
|
486
|
+
const [[i, a], s] = await Promise.all([
|
|
487
|
+
this.#t.readContract({ address: t.key.poolManager, abi: K, functionName: "getSlot0", args: [t.id] }),
|
|
488
|
+
this.#t.readContract({ address: t.key.poolManager, abi: _, functionName: "getLiquidity", args: [t.id] })
|
|
489
489
|
]);
|
|
490
|
-
if (
|
|
491
|
-
throw new f("getPoolState", `pool ${
|
|
492
|
-
return { poolId:
|
|
490
|
+
if (i === 0n)
|
|
491
|
+
throw new f("getPoolState", `pool ${t.id} is not initialised on ${t.key.poolManager}`);
|
|
492
|
+
return { poolId: t.id, poolType: "CL", currentTick: a, sqrtPriceX96: i, liquidity: s, source: "live" };
|
|
493
493
|
}
|
|
494
|
-
const [n] = await this.#
|
|
494
|
+
const [n] = await this.#t.readContract({ address: t.key.poolManager, abi: X, functionName: "getSlot0", args: [t.id] });
|
|
495
495
|
if (n === 0)
|
|
496
|
-
throw new f("getPoolState", `pool ${
|
|
497
|
-
return { poolId:
|
|
496
|
+
throw new f("getPoolState", `pool ${t.id} is not initialised on ${t.key.poolManager}`);
|
|
497
|
+
return { poolId: t.id, poolType: "BIN", activeId: n, source: "live" };
|
|
498
498
|
}
|
|
499
499
|
/**
|
|
500
500
|
* The two allowances `spender` needs before it can pull `token` through
|
|
@@ -503,55 +503,55 @@ class Ct {
|
|
|
503
503
|
* liquidity add; the liquidity hooks pass it, because an allowance to the
|
|
504
504
|
* router does nothing for a mint.
|
|
505
505
|
*/
|
|
506
|
-
async getApprovalRequirements(
|
|
507
|
-
if (
|
|
508
|
-
const
|
|
509
|
-
address:
|
|
506
|
+
async getApprovalRequirements(t, o, n, i) {
|
|
507
|
+
if (t.isNative === !0 || b(t.address, S)) return [];
|
|
508
|
+
const a = I(this.chain, "permit2", "pull the input token for a swap"), s = i ?? I(this.chain, "universalRouter", "execute a swap"), r = [], l = await this.#t.readContract({
|
|
509
|
+
address: t.address,
|
|
510
510
|
abi: N,
|
|
511
511
|
functionName: "allowance",
|
|
512
|
-
args: [o,
|
|
512
|
+
args: [o, a]
|
|
513
513
|
});
|
|
514
514
|
l < n && r.push({
|
|
515
515
|
kind: "erc20-to-permit2",
|
|
516
|
-
token:
|
|
517
|
-
spender:
|
|
516
|
+
token: t,
|
|
517
|
+
spender: a,
|
|
518
518
|
current: l,
|
|
519
519
|
required: n
|
|
520
520
|
});
|
|
521
|
-
const [c, d] = await this.#
|
|
522
|
-
address:
|
|
523
|
-
abi:
|
|
521
|
+
const [c, d] = await this.#t.readContract({
|
|
522
|
+
address: a,
|
|
523
|
+
abi: it,
|
|
524
524
|
functionName: "allowance",
|
|
525
|
-
args: [o,
|
|
525
|
+
args: [o, t.address, s]
|
|
526
526
|
}), p = BigInt(Math.floor(Date.now() / 1e3)), m = BigInt(d) !== 0n && BigInt(d) <= p;
|
|
527
527
|
return (BigInt(c) < n || m) && r.push({
|
|
528
528
|
kind: "permit2-to-router",
|
|
529
|
-
token:
|
|
529
|
+
token: t,
|
|
530
530
|
spender: s,
|
|
531
531
|
current: m ? 0n : BigInt(c),
|
|
532
532
|
required: n
|
|
533
533
|
}), r;
|
|
534
534
|
}
|
|
535
|
-
async buildApproval(
|
|
536
|
-
return
|
|
537
|
-
to:
|
|
538
|
-
data:
|
|
535
|
+
async buildApproval(t) {
|
|
536
|
+
return t.kind === "erc20-to-permit2" ? {
|
|
537
|
+
to: t.token.address,
|
|
538
|
+
data: P({
|
|
539
539
|
abi: N,
|
|
540
540
|
functionName: "approve",
|
|
541
|
-
args: [
|
|
541
|
+
args: [t.spender, Ot]
|
|
542
542
|
}),
|
|
543
543
|
value: 0n,
|
|
544
|
-
summary: `Approve ${
|
|
544
|
+
summary: `Approve ${t.token.symbol} for Permit2`,
|
|
545
545
|
source: "live"
|
|
546
546
|
} : {
|
|
547
|
-
to:
|
|
548
|
-
data:
|
|
549
|
-
abi:
|
|
547
|
+
to: I(this.chain, "permit2", "approve the router through Permit2"),
|
|
548
|
+
data: P({
|
|
549
|
+
abi: it,
|
|
550
550
|
functionName: "approve",
|
|
551
|
-
args: [
|
|
551
|
+
args: [t.token.address, t.spender, Et, Number(_t)]
|
|
552
552
|
}),
|
|
553
553
|
value: 0n,
|
|
554
|
-
summary: `Approve ${
|
|
554
|
+
summary: `Approve ${t.spender} to spend ${t.token.symbol} via Permit2`,
|
|
555
555
|
source: "live"
|
|
556
556
|
};
|
|
557
557
|
}
|
|
@@ -569,38 +569,38 @@ class Ct {
|
|
|
569
569
|
* Any other dynamic pool is reported `lpFeeUnknown`, which the widget renders
|
|
570
570
|
* as "dynamic" rather than as a rate it did not read.
|
|
571
571
|
*/
|
|
572
|
-
async quoteSwap(
|
|
572
|
+
async quoteSwap(t) {
|
|
573
573
|
const o = this.#n.quoteSwap;
|
|
574
|
-
if (o !== void 0) return o(
|
|
575
|
-
const n = this.chain.contracts,
|
|
576
|
-
(u) => (
|
|
574
|
+
if (o !== void 0) return o(t, this.#e.pools);
|
|
575
|
+
const n = this.chain.contracts, i = this.#e.pools.filter(
|
|
576
|
+
(u) => (t.poolId === void 0 || u.id === t.poolId) && (b(u.token0.address, t.tokenIn.address) && b(u.token1.address, t.tokenOut.address) || b(u.token1.address, t.tokenIn.address) && b(u.token0.address, t.tokenOut.address))
|
|
577
577
|
);
|
|
578
|
-
if (
|
|
578
|
+
if (i.length === 0)
|
|
579
579
|
throw new f(
|
|
580
580
|
"quoteSwap",
|
|
581
|
-
|
|
581
|
+
t.poolId !== void 0 ? `pool ${t.poolId} is not a configured pool holding both ${t.tokenIn.symbol} and ${t.tokenOut.symbol}.` : `no configured pool holds both ${t.tokenIn.symbol} and ${t.tokenOut.symbol}. This adapter quotes direct pools only; supply \`overrides.quoteSwap\` for multi-hop routes.`
|
|
582
582
|
);
|
|
583
|
-
const
|
|
583
|
+
const a = i.filter(
|
|
584
584
|
(u) => u.poolType === "CL" ? n.quoter !== void 0 : n.binQuoter !== void 0
|
|
585
585
|
);
|
|
586
|
-
if (
|
|
586
|
+
if (a.length === 0)
|
|
587
587
|
throw new f(
|
|
588
588
|
"quoteSwap",
|
|
589
|
-
`a pool for this pair exists but no quoter is configured for its type (${
|
|
589
|
+
`a pool for this pair exists but no quoter is configured for its type (${i.map((u) => u.poolType).join(", ")}). Set \`contracts.quoter\` (CL) / \`contracts.binQuoter\` (Bin), or supply \`overrides.quoteSwap\`. This adapter will not estimate a price it cannot verify.`
|
|
590
590
|
);
|
|
591
591
|
const s = await Promise.all(
|
|
592
|
-
|
|
592
|
+
a.map(async (u) => {
|
|
593
593
|
const h = u.poolType === "CL" ? n.quoter : n.binQuoter;
|
|
594
594
|
try {
|
|
595
|
-
const { result: y } = await this.#
|
|
595
|
+
const { result: y } = await this.#t.simulateContract({
|
|
596
596
|
address: h,
|
|
597
|
-
abi:
|
|
597
|
+
abi: Tt(u.poolType),
|
|
598
598
|
functionName: "quoteExactInputSingle",
|
|
599
599
|
args: [
|
|
600
600
|
{
|
|
601
601
|
poolKey: u.key,
|
|
602
|
-
zeroForOne: b(u.key.currency0,
|
|
603
|
-
exactAmount:
|
|
602
|
+
zeroForOne: b(u.key.currency0, t.tokenIn.address),
|
|
603
|
+
exactAmount: t.amountIn,
|
|
604
604
|
hookData: "0x"
|
|
605
605
|
}
|
|
606
606
|
]
|
|
@@ -620,26 +620,26 @@ class Ct {
|
|
|
620
620
|
}
|
|
621
621
|
const l = r.reduce((u, h) => h.amountOut > u.amountOut ? h : u), c = l.pool;
|
|
622
622
|
let d = c.lpFeePips, p = !1;
|
|
623
|
-
if (
|
|
623
|
+
if (Mt(c.lpFeePips)) {
|
|
624
624
|
const u = await this.#c(c);
|
|
625
625
|
u === null ? (d = 0, p = !0) : d = u;
|
|
626
626
|
}
|
|
627
|
-
const m = p ? null : await this.#u(c,
|
|
627
|
+
const m = p ? null : await this.#u(c, t.tokenIn.address, t.amountIn, d);
|
|
628
628
|
return {
|
|
629
629
|
route: [
|
|
630
630
|
{
|
|
631
631
|
poolId: c.id,
|
|
632
632
|
poolType: c.poolType,
|
|
633
|
-
tokenIn:
|
|
634
|
-
tokenOut:
|
|
633
|
+
tokenIn: t.tokenIn,
|
|
634
|
+
tokenOut: t.tokenOut,
|
|
635
635
|
lpFeePips: d,
|
|
636
636
|
hooks: c.hooks
|
|
637
637
|
}
|
|
638
638
|
],
|
|
639
|
-
amountIn:
|
|
639
|
+
amountIn: t.amountIn,
|
|
640
640
|
grossAmountOut: l.amountOut,
|
|
641
641
|
spotAmountOut: m,
|
|
642
|
-
lpFeeAmount:
|
|
642
|
+
lpFeeAmount: t.amountIn * BigInt(d) / 1000000n,
|
|
643
643
|
lpFeePips: d,
|
|
644
644
|
...p ? { lpFeeUnknown: p } : {},
|
|
645
645
|
estimatedGas: l.gasEstimate,
|
|
@@ -654,91 +654,91 @@ class Ct {
|
|
|
654
654
|
* `CLOCK_MODE`) is thrown: an unreachable RPC is an error state, never a
|
|
655
655
|
* quote annotated "dynamic".
|
|
656
656
|
*/
|
|
657
|
-
async #c(
|
|
658
|
-
const o = this.#o(
|
|
657
|
+
async #c(t) {
|
|
658
|
+
const o = this.#o(t);
|
|
659
659
|
if (o === null) return null;
|
|
660
|
-
const n = o.poolType === "CL" ?
|
|
660
|
+
const n = o.poolType === "CL" ? at(await this.#r(o.hook, "CL")) : tt;
|
|
661
661
|
try {
|
|
662
|
-
const
|
|
663
|
-
return Number(
|
|
664
|
-
} catch (
|
|
665
|
-
if (
|
|
662
|
+
const i = await this.#t.readContract({ address: o.hook, abi: n, functionName: "currentFee", args: [t.id] });
|
|
663
|
+
return Number(i);
|
|
664
|
+
} catch (i) {
|
|
665
|
+
if (i instanceof J && i.walk((a) => a instanceof Z) !== null)
|
|
666
666
|
return null;
|
|
667
|
-
throw
|
|
667
|
+
throw i;
|
|
668
668
|
}
|
|
669
669
|
}
|
|
670
670
|
/** The configured launch guard this pool names, if any, with the pool type it serves. */
|
|
671
|
-
#o(
|
|
671
|
+
#o(t) {
|
|
672
672
|
const { launchGuardHook: o, binLaunchGuardHook: n } = this.chain.contracts;
|
|
673
|
-
return
|
|
673
|
+
return t.poolType === "CL" && o !== void 0 && b(t.hooks, o) ? { hook: o, poolType: "CL" } : t.poolType === "BIN" && n !== void 0 && b(t.hooks, n) ? { hook: n, poolType: "BIN" } : null;
|
|
674
674
|
}
|
|
675
675
|
/** `amountIn` priced at the pool's spot from `getSlot0`, less `lpFeePips`; `null` when the read fails. */
|
|
676
|
-
async #u(
|
|
677
|
-
const
|
|
676
|
+
async #u(t, o, n, i) {
|
|
677
|
+
const a = b(t.key.currency0, o), s = n * BigInt(1e6 - i) / 1000000n;
|
|
678
678
|
try {
|
|
679
|
-
if (
|
|
680
|
-
const [m] = await this.#
|
|
679
|
+
if (t.poolType === "CL") {
|
|
680
|
+
const [m] = await this.#t.readContract({ address: t.key.poolManager, abi: K, functionName: "getSlot0", args: [t.id] });
|
|
681
681
|
if (m === 0n) return null;
|
|
682
682
|
const u = m * m;
|
|
683
|
-
return
|
|
683
|
+
return a ? s * u / dt : s * dt / u;
|
|
684
684
|
}
|
|
685
|
-
const [r] = await this.#
|
|
685
|
+
const [r] = await this.#t.readContract({ address: t.key.poolManager, abi: X, functionName: "getSlot0", args: [t.id] }), { binStep: l } = et(t.key), c = nt(Number(r), l);
|
|
686
686
|
if (!Number.isFinite(c) || c <= 0) return null;
|
|
687
687
|
const d = 10n ** 18n, p = BigInt(Math.round(c * 1e18));
|
|
688
|
-
return p === 0n ? null :
|
|
688
|
+
return p === 0n ? null : a ? s * p / d : s * d / p;
|
|
689
689
|
} catch {
|
|
690
690
|
return null;
|
|
691
691
|
}
|
|
692
692
|
}
|
|
693
|
-
async buildSwap(
|
|
694
|
-
const o =
|
|
693
|
+
async buildSwap(t) {
|
|
694
|
+
const o = I(this.chain, "universalRouter", "execute a swap"), n = await this.getAccount();
|
|
695
695
|
if (n === null) throw new E("build a swap");
|
|
696
|
-
const
|
|
696
|
+
const i = this.#l(t), a = Rt({
|
|
697
697
|
router: o,
|
|
698
|
-
hops:
|
|
699
|
-
amountIn:
|
|
700
|
-
minAmountOutGross:
|
|
701
|
-
minAmountOutNet:
|
|
702
|
-
expectedAmountOutGross:
|
|
703
|
-
integrator:
|
|
704
|
-
recipient:
|
|
698
|
+
hops: i,
|
|
699
|
+
amountIn: t.amountIn,
|
|
700
|
+
minAmountOutGross: t.minAmountOutGross,
|
|
701
|
+
minAmountOutNet: t.minAmountOutNet,
|
|
702
|
+
expectedAmountOutGross: t.quote.grossAmountOut,
|
|
703
|
+
integrator: t.integrator,
|
|
704
|
+
recipient: t.recipient,
|
|
705
705
|
sender: n,
|
|
706
|
-
deadline:
|
|
706
|
+
deadline: t.deadline
|
|
707
707
|
});
|
|
708
708
|
return {
|
|
709
|
-
to:
|
|
710
|
-
data:
|
|
711
|
-
value:
|
|
712
|
-
summary: `Swap ${
|
|
713
|
-
...
|
|
709
|
+
to: a.to,
|
|
710
|
+
data: a.data,
|
|
711
|
+
value: a.value,
|
|
712
|
+
summary: `Swap ${t.tokenIn.symbol} for ${t.tokenOut.symbol}`,
|
|
713
|
+
...a.integratorFee ? {
|
|
714
714
|
integratorFee: {
|
|
715
|
-
referrer:
|
|
716
|
-
feeBps:
|
|
717
|
-
currency:
|
|
718
|
-
expectedAmount:
|
|
715
|
+
referrer: a.integratorFee.referrer,
|
|
716
|
+
feeBps: a.integratorFee.feeBps,
|
|
717
|
+
currency: a.integratorFee.currency,
|
|
718
|
+
expectedAmount: a.integratorFee.expectedAmount
|
|
719
719
|
}
|
|
720
720
|
} : {},
|
|
721
721
|
source: "live"
|
|
722
722
|
};
|
|
723
723
|
}
|
|
724
|
-
#l(
|
|
724
|
+
#l(t) {
|
|
725
725
|
const o = this.#n.findRoute;
|
|
726
726
|
if (o !== void 0)
|
|
727
|
-
return o(
|
|
727
|
+
return o(t.tokenIn, t.tokenOut, this.#e.pools);
|
|
728
728
|
const n = [];
|
|
729
|
-
for (const
|
|
730
|
-
const
|
|
731
|
-
if (
|
|
729
|
+
for (const i of t.quote.route) {
|
|
730
|
+
const a = this.#e.pools.find((s) => s.id === i.poolId);
|
|
731
|
+
if (a === void 0)
|
|
732
732
|
throw new f(
|
|
733
733
|
"buildSwap",
|
|
734
|
-
`the quote routes through pool ${
|
|
734
|
+
`the quote routes through pool ${i.poolId}, which is not in the configured pool list`
|
|
735
735
|
);
|
|
736
736
|
n.push({
|
|
737
|
-
poolKey:
|
|
738
|
-
poolType:
|
|
739
|
-
currencyIn:
|
|
740
|
-
currencyOut:
|
|
741
|
-
...
|
|
737
|
+
poolKey: a.key,
|
|
738
|
+
poolType: a.poolType,
|
|
739
|
+
currencyIn: i.tokenIn.address,
|
|
740
|
+
currencyOut: i.tokenOut.address,
|
|
741
|
+
...t.hookData ? { hookData: t.hookData } : {}
|
|
742
742
|
});
|
|
743
743
|
}
|
|
744
744
|
return n;
|
|
@@ -749,75 +749,75 @@ class Ct {
|
|
|
749
749
|
* (`core/clMath.ts`; `adapters/binDistribution.ts`). The amounts reported
|
|
750
750
|
* are what the position manager settles: an add rounds towards the pool.
|
|
751
751
|
*/
|
|
752
|
-
async quoteAddLiquidity(
|
|
752
|
+
async quoteAddLiquidity(t) {
|
|
753
753
|
const o = this.#n.quoteAddLiquidity;
|
|
754
|
-
if (o !== void 0) return o(
|
|
755
|
-
const { pool: n, range:
|
|
756
|
-
if (
|
|
754
|
+
if (o !== void 0) return o(t);
|
|
755
|
+
const { pool: n, range: i } = t;
|
|
756
|
+
if (i.type === "CL") {
|
|
757
757
|
if (n.poolType !== "CL")
|
|
758
758
|
throw new f("quoteAddLiquidity", "tick range given for a bin pool");
|
|
759
|
-
const h =
|
|
760
|
-
if (
|
|
759
|
+
const h = Ft(n);
|
|
760
|
+
if (i.tickLower % h !== 0 || i.tickUpper % h !== 0)
|
|
761
761
|
throw new RangeError(
|
|
762
|
-
`[@latchprotocol/widgets] ticks must be multiples of the pool's spacing ${h}: [${
|
|
762
|
+
`[@latchprotocol/widgets] ticks must be multiples of the pool's spacing ${h}: [${i.tickLower}, ${i.tickUpper}]`
|
|
763
763
|
);
|
|
764
|
-
const y = await this.getPoolState(n), w = y.sqrtPriceX96, k =
|
|
764
|
+
const y = await this.getPoolState(n), w = y.sqrtPriceX96, k = Gt(
|
|
765
765
|
w,
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
766
|
+
st(i.tickLower),
|
|
767
|
+
st(i.tickUpper),
|
|
768
|
+
t.amount0Desired,
|
|
769
|
+
t.amount1Desired
|
|
770
770
|
);
|
|
771
771
|
if (k === 0n)
|
|
772
772
|
throw new f(
|
|
773
773
|
"quoteAddLiquidity",
|
|
774
774
|
"these amounts mint no liquidity in this range: at the pool's price the range needs the other token, or the amounts are too small"
|
|
775
775
|
);
|
|
776
|
-
const T = U(w,
|
|
777
|
-
return { pool: n, range:
|
|
776
|
+
const T = U(w, i.tickLower, i.tickUpper, k, !0), B = y.currentTick >= i.tickLower && y.currentTick < i.tickUpper, g = y.liquidity ?? 0n, M = B ? Number(k * 10000n / (g + k)) : null;
|
|
777
|
+
return { pool: n, range: i, amount0: T.amount0, amount1: T.amount1, liquidity: k, shareBps: M, source: "live" };
|
|
778
778
|
}
|
|
779
779
|
if (n.poolType !== "BIN")
|
|
780
780
|
throw new f("quoteAddLiquidity", "bin range given for a CL pool");
|
|
781
781
|
const s = (await this.getPoolState(n)).activeId;
|
|
782
|
-
if (Math.abs(s -
|
|
782
|
+
if (Math.abs(s - i.activeIdDesired) > i.idSlippage)
|
|
783
783
|
throw new f(
|
|
784
784
|
"quoteAddLiquidity",
|
|
785
|
-
`the active bin is ${s}, more than ${
|
|
785
|
+
`the active bin is ${s}, more than ${i.idSlippage} bins from the ${i.activeIdDesired} the range was built around; rebuild the range`
|
|
786
786
|
);
|
|
787
|
-
const r =
|
|
787
|
+
const r = he(i.binIdLower, i.binIdUpper, i.activeIdDesired), l = r.some((h) => h.distributionX > 0n), c = r.some((h) => h.distributionY > 0n), d = l ? t.amount0Desired : 0n, p = c ? t.amount1Desired : 0n;
|
|
788
788
|
if (d + p === 0n)
|
|
789
789
|
throw new f(
|
|
790
790
|
"quoteAddLiquidity",
|
|
791
791
|
"nothing to deposit: the chosen bins take only the token whose amount is zero"
|
|
792
792
|
);
|
|
793
|
-
const m =
|
|
793
|
+
const m = qt(n);
|
|
794
794
|
let u = 0n;
|
|
795
795
|
for (const h of r) {
|
|
796
|
-
const y = d * h.distributionX / 10n ** 18n, w = p * h.distributionY / 10n ** 18n, k =
|
|
796
|
+
const y = d * h.distributionX / 10n ** 18n, w = p * h.distributionY / 10n ** 18n, k = nt(h.binId, m);
|
|
797
797
|
u += BigInt(Math.floor(Number(y) * k)) + w;
|
|
798
798
|
}
|
|
799
|
-
return { pool: n, range:
|
|
799
|
+
return { pool: n, range: i, amount0: d, amount1: p, liquidity: u, shareBps: null, binDistribution: r, source: "live" };
|
|
800
800
|
}
|
|
801
|
-
async buildAddLiquidity(
|
|
801
|
+
async buildAddLiquidity(t) {
|
|
802
802
|
if (await this.getAccount() === null) throw new E("add liquidity");
|
|
803
|
-
const { quote: n } =
|
|
803
|
+
const { quote: n } = t, i = this.#d(n.pool, t.amount0Max, t.amount1Max);
|
|
804
804
|
if (n.range.type === "CL") {
|
|
805
|
-
const l =
|
|
805
|
+
const l = I(
|
|
806
806
|
this.chain,
|
|
807
807
|
"clPositionManager",
|
|
808
808
|
"mint a concentrated-liquidity position"
|
|
809
|
-
), c =
|
|
809
|
+
), c = ge({
|
|
810
810
|
positionManager: l,
|
|
811
811
|
poolKey: n.pool.key,
|
|
812
812
|
tickLower: n.range.tickLower,
|
|
813
813
|
tickUpper: n.range.tickUpper,
|
|
814
814
|
liquidity: n.liquidity,
|
|
815
|
-
amount0Max:
|
|
816
|
-
amount1Max:
|
|
817
|
-
owner:
|
|
818
|
-
deadline:
|
|
819
|
-
value:
|
|
820
|
-
...
|
|
815
|
+
amount0Max: t.amount0Max,
|
|
816
|
+
amount1Max: t.amount1Max,
|
|
817
|
+
owner: t.recipient,
|
|
818
|
+
deadline: t.deadline,
|
|
819
|
+
value: i,
|
|
820
|
+
...t.hookData ? { hookData: t.hookData } : {}
|
|
821
821
|
});
|
|
822
822
|
return {
|
|
823
823
|
to: c.to,
|
|
@@ -827,7 +827,7 @@ class Ct {
|
|
|
827
827
|
source: "live"
|
|
828
828
|
};
|
|
829
829
|
}
|
|
830
|
-
const
|
|
830
|
+
const a = I(
|
|
831
831
|
this.chain,
|
|
832
832
|
"binPositionManager",
|
|
833
833
|
"add liquidity to a bin pool"
|
|
@@ -837,22 +837,22 @@ class Ct {
|
|
|
837
837
|
"buildAddLiquidity",
|
|
838
838
|
"a bin mint needs a per-bin distribution; the quote did not supply one"
|
|
839
839
|
);
|
|
840
|
-
const r =
|
|
841
|
-
positionManager:
|
|
840
|
+
const r = Ie({
|
|
841
|
+
positionManager: a,
|
|
842
842
|
poolKey: n.pool.key,
|
|
843
843
|
amount0: n.amount0,
|
|
844
844
|
amount1: n.amount1,
|
|
845
|
-
amount0Max:
|
|
846
|
-
amount1Max:
|
|
845
|
+
amount0Max: t.amount0Max,
|
|
846
|
+
amount1Max: t.amount1Max,
|
|
847
847
|
activeIdDesired: n.range.activeIdDesired,
|
|
848
848
|
idSlippage: n.range.idSlippage,
|
|
849
849
|
deltaIds: s.map((l) => l.deltaId),
|
|
850
850
|
distributionX: s.map((l) => l.distributionX),
|
|
851
851
|
distributionY: s.map((l) => l.distributionY),
|
|
852
|
-
to:
|
|
853
|
-
deadline:
|
|
854
|
-
value:
|
|
855
|
-
...
|
|
852
|
+
to: t.recipient,
|
|
853
|
+
deadline: t.deadline,
|
|
854
|
+
value: i,
|
|
855
|
+
...t.hookData ? { hookData: t.hookData } : {}
|
|
856
856
|
});
|
|
857
857
|
return {
|
|
858
858
|
to: r.to,
|
|
@@ -862,8 +862,8 @@ class Ct {
|
|
|
862
862
|
source: "live"
|
|
863
863
|
};
|
|
864
864
|
}
|
|
865
|
-
#d(
|
|
866
|
-
return b(
|
|
865
|
+
#d(t, o, n) {
|
|
866
|
+
return b(t.token0.address, S) ? o : b(t.token1.address, S) ? n : 0n;
|
|
867
867
|
}
|
|
868
868
|
/**
|
|
869
869
|
* A holder's positions, reconstructed from position-manager logs and
|
|
@@ -877,52 +877,52 @@ class Ct {
|
|
|
877
877
|
* reserves and share supply. A position on a pool not in the configured
|
|
878
878
|
* list still appears, with its tokens read off their contracts.
|
|
879
879
|
*/
|
|
880
|
-
async listPositions(
|
|
880
|
+
async listPositions(t, o) {
|
|
881
881
|
const n = this.#n.listPositions;
|
|
882
|
-
if (n !== void 0) return n(
|
|
883
|
-
const
|
|
884
|
-
if (
|
|
882
|
+
if (n !== void 0) return n(t, o);
|
|
883
|
+
const i = this.#e.positionsFromBlock;
|
|
884
|
+
if (i === void 0)
|
|
885
885
|
throw new f(
|
|
886
886
|
"listPositions",
|
|
887
887
|
"position enumeration scans the position managers' transfer logs and needs `positionsFromBlock` (the block they were deployed at) in the adapter options."
|
|
888
888
|
);
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
889
|
+
const a = o?.poolType, [s, r] = await Promise.all([
|
|
890
|
+
a === "BIN" ? Promise.resolve([]) : this.#p(t, i, o),
|
|
891
|
+
a === "CL" ? Promise.resolve([]) : this.#m(t, i, o)
|
|
892
892
|
]);
|
|
893
893
|
return [...s, ...r];
|
|
894
894
|
}
|
|
895
|
-
async #p(
|
|
896
|
-
const
|
|
897
|
-
if (
|
|
898
|
-
const
|
|
899
|
-
address:
|
|
895
|
+
async #p(t, o, n) {
|
|
896
|
+
const i = this.chain.contracts.clPositionManager;
|
|
897
|
+
if (i === void 0) return [];
|
|
898
|
+
const a = await this.#t.getLogs({
|
|
899
|
+
address: i,
|
|
900
900
|
event: Y[2],
|
|
901
|
-
args: { to:
|
|
901
|
+
args: { to: t },
|
|
902
902
|
fromBlock: o,
|
|
903
903
|
toBlock: "latest"
|
|
904
|
-
}), s = [...new Set(
|
|
904
|
+
}), s = [...new Set(a.map((l) => l.args.id))], r = [];
|
|
905
905
|
for (const l of s) {
|
|
906
906
|
let c;
|
|
907
907
|
try {
|
|
908
|
-
c = await this.#
|
|
908
|
+
c = await this.#t.readContract({ address: i, abi: Y, functionName: "ownerOf", args: [l] });
|
|
909
909
|
} catch {
|
|
910
910
|
continue;
|
|
911
911
|
}
|
|
912
|
-
if (!b(c,
|
|
913
|
-
const [d, p, m, u, h, y] = await this.#
|
|
914
|
-
address:
|
|
912
|
+
if (!b(c, t)) continue;
|
|
913
|
+
const [d, p, m, u, h, y] = await this.#t.readContract({
|
|
914
|
+
address: i,
|
|
915
915
|
abi: Y,
|
|
916
916
|
functionName: "positions",
|
|
917
917
|
args: [l]
|
|
918
918
|
}), w = await this.#a(d, "CL", n);
|
|
919
919
|
if (w === null) continue;
|
|
920
920
|
const [[k, T], [B, g], M, q] = await Promise.all([
|
|
921
|
-
this.#
|
|
922
|
-
this.#
|
|
923
|
-
this.#
|
|
924
|
-
this.#
|
|
925
|
-
]), D = U(k, p, m, u, !1), x =
|
|
921
|
+
this.#t.readContract({ address: d.poolManager, abi: K, functionName: "getSlot0", args: [w.id] }),
|
|
922
|
+
this.#t.readContract({ address: d.poolManager, abi: _, functionName: "getFeeGrowthGlobals", args: [w.id] }),
|
|
923
|
+
this.#t.readContract({ address: d.poolManager, abi: _, functionName: "getPoolTickInfo", args: [w.id, p] }),
|
|
924
|
+
this.#t.readContract({ address: d.poolManager, abi: _, functionName: "getPoolTickInfo", args: [w.id, m] })
|
|
925
|
+
]), D = U(k, p, m, u, !1), x = Ut({
|
|
926
926
|
liquidity: u,
|
|
927
927
|
tickLower: p,
|
|
928
928
|
tickUpper: m,
|
|
@@ -950,36 +950,36 @@ class Ct {
|
|
|
950
950
|
}
|
|
951
951
|
return r;
|
|
952
952
|
}
|
|
953
|
-
async #m(
|
|
954
|
-
const
|
|
955
|
-
if (
|
|
956
|
-
const
|
|
957
|
-
address:
|
|
953
|
+
async #m(t, o, n) {
|
|
954
|
+
const i = this.chain.contracts.binPositionManager;
|
|
955
|
+
if (i === void 0) return [];
|
|
956
|
+
const a = await this.#t.getLogs({
|
|
957
|
+
address: i,
|
|
958
958
|
event: W[2],
|
|
959
|
-
args: { to:
|
|
959
|
+
args: { to: t },
|
|
960
960
|
fromBlock: o,
|
|
961
961
|
toBlock: "latest"
|
|
962
|
-
}), s = [...new Set(
|
|
962
|
+
}), s = [...new Set(a.flatMap((c) => c.args.ids ?? []))], r = /* @__PURE__ */ new Map();
|
|
963
963
|
for (const c of s) {
|
|
964
|
-
const d = await this.#
|
|
964
|
+
const d = await this.#t.readContract({ address: i, abi: W, functionName: "balanceOf", args: [t, c] });
|
|
965
965
|
if (d === 0n) continue;
|
|
966
|
-
const [p, m] = await this.#
|
|
966
|
+
const [p, m] = await this.#t.readContract({ address: i, abi: W, functionName: "positions", args: [c] }), u = ot(p), h = r.get(u) ?? { key: p, bins: [] };
|
|
967
967
|
h.bins.push({ binId: m, shares: d }), r.set(u, h);
|
|
968
968
|
}
|
|
969
969
|
const l = [];
|
|
970
970
|
for (const [c, { key: d, bins: p }] of r) {
|
|
971
971
|
const m = await this.#a(d, "BIN", n);
|
|
972
972
|
if (m === null) continue;
|
|
973
|
-
const [u] = await this.#
|
|
973
|
+
const [u] = await this.#t.readContract({ address: d.poolManager, abi: X, functionName: "getSlot0", args: [c] });
|
|
974
974
|
let h = 0n, y = 0n, w = 0n;
|
|
975
975
|
const k = [...p].sort((g, M) => g.binId - M.binId);
|
|
976
976
|
for (const g of k) {
|
|
977
|
-
const [M, q, , D] = await this.#
|
|
977
|
+
const [M, q, , D] = await this.#t.readContract({
|
|
978
978
|
address: d.poolManager,
|
|
979
|
-
abi:
|
|
979
|
+
abi: pt,
|
|
980
980
|
functionName: "getBin",
|
|
981
981
|
args: [c, g.binId]
|
|
982
|
-
}), x =
|
|
982
|
+
}), x = rt({ shares: g.shares, totalShares: D, reserveX: M, reserveY: q });
|
|
983
983
|
h += x.amount0, y += x.amount1, w += g.shares;
|
|
984
984
|
}
|
|
985
985
|
const T = k[0], B = k[k.length - 1];
|
|
@@ -1005,15 +1005,15 @@ class Ct {
|
|
|
1005
1005
|
* listed, else one built from the key with both tokens read off their
|
|
1006
1006
|
* contracts. `null` when `only` names a different pool.
|
|
1007
1007
|
*/
|
|
1008
|
-
async #a(
|
|
1009
|
-
const
|
|
1010
|
-
if (n !== void 0) return n.id.toLowerCase() ===
|
|
1011
|
-
const
|
|
1012
|
-
if (
|
|
1013
|
-
const [s, r] = await Promise.all([this.getToken(
|
|
1008
|
+
async #a(t, o, n) {
|
|
1009
|
+
const i = ot(t);
|
|
1010
|
+
if (n !== void 0) return n.id.toLowerCase() === i.toLowerCase() ? n : null;
|
|
1011
|
+
const a = this.#e.pools.find((c) => c.id.toLowerCase() === i.toLowerCase());
|
|
1012
|
+
if (a !== void 0) return a;
|
|
1013
|
+
const [s, r] = await Promise.all([this.getToken(t.currency0), this.getToken(t.currency1)]);
|
|
1014
1014
|
if (s === null || r === null) return null;
|
|
1015
|
-
const l = o === "CL" ? { tickSpacing:
|
|
1016
|
-
return { id:
|
|
1015
|
+
const l = o === "CL" ? { tickSpacing: Nt(t).tickSpacing } : { binStep: et(t).binStep };
|
|
1016
|
+
return { id: i, key: t, poolType: o, token0: s, token1: r, lpFeePips: t.fee, hooks: t.hooks, ...l };
|
|
1017
1017
|
}
|
|
1018
1018
|
/**
|
|
1019
1019
|
* What withdrawing `percentBps` of a position returns as PRINCIPAL, rounded
|
|
@@ -1023,35 +1023,35 @@ class Ct {
|
|
|
1023
1023
|
* principal alone, and a floor that counted fees could revert an honest
|
|
1024
1024
|
* withdrawal.
|
|
1025
1025
|
*/
|
|
1026
|
-
async quoteRemoveLiquidity(
|
|
1026
|
+
async quoteRemoveLiquidity(t, o) {
|
|
1027
1027
|
const n = this.#n.quoteRemoveLiquidity;
|
|
1028
|
-
if (n !== void 0) return n(
|
|
1028
|
+
if (n !== void 0) return n(t, o);
|
|
1029
1029
|
if (!Number.isInteger(o) || o <= 0 || o > 1e4)
|
|
1030
1030
|
throw new RangeError(`[@latchprotocol/widgets] percentBps must be an integer in (0, 10000]: ${o}`);
|
|
1031
|
-
const { pool:
|
|
1032
|
-
if (
|
|
1033
|
-
const l = await this.getPoolState(
|
|
1034
|
-
return { position:
|
|
1031
|
+
const { pool: i } = t;
|
|
1032
|
+
if (t.range.type === "CL") {
|
|
1033
|
+
const l = await this.getPoolState(i), c = t.liquidity * BigInt(o) / 10000n, d = U(l.sqrtPriceX96, t.range.tickLower, t.range.tickUpper, c, !1);
|
|
1034
|
+
return { position: t, percentBps: o, amount0: d.amount0, amount1: d.amount1, source: "live" };
|
|
1035
1035
|
}
|
|
1036
|
-
const
|
|
1036
|
+
const a = t.binAmounts ?? [];
|
|
1037
1037
|
let s = 0n, r = 0n;
|
|
1038
|
-
for (const l of
|
|
1039
|
-
const [c, d, , p] = await this.#
|
|
1040
|
-
address:
|
|
1041
|
-
abi:
|
|
1038
|
+
for (const l of a) {
|
|
1039
|
+
const [c, d, , p] = await this.#t.readContract({
|
|
1040
|
+
address: i.key.poolManager,
|
|
1041
|
+
abi: pt,
|
|
1042
1042
|
functionName: "getBin",
|
|
1043
|
-
args: [
|
|
1044
|
-
}), m =
|
|
1043
|
+
args: [i.id, l.binId]
|
|
1044
|
+
}), m = rt({ shares: l.amount * BigInt(o) / 10000n, totalShares: p, reserveX: c, reserveY: d });
|
|
1045
1045
|
s += m.amount0, r += m.amount1;
|
|
1046
1046
|
}
|
|
1047
|
-
return { position:
|
|
1047
|
+
return { position: t, percentBps: o, amount0: s, amount1: r, source: "live" };
|
|
1048
1048
|
}
|
|
1049
|
-
async buildRemoveLiquidity(
|
|
1049
|
+
async buildRemoveLiquidity(t) {
|
|
1050
1050
|
const o = await this.getAccount();
|
|
1051
1051
|
if (o === null) throw new E("remove liquidity");
|
|
1052
|
-
const { position: n } =
|
|
1052
|
+
const { position: n } = t;
|
|
1053
1053
|
if (n.range.type === "CL") {
|
|
1054
|
-
const r =
|
|
1054
|
+
const r = I(
|
|
1055
1055
|
this.chain,
|
|
1056
1056
|
"clPositionManager",
|
|
1057
1057
|
"decrease a concentrated-liquidity position"
|
|
@@ -1061,55 +1061,55 @@ class Ct {
|
|
|
1061
1061
|
"buildRemoveLiquidity",
|
|
1062
1062
|
"a CL position must carry its ERC-721 tokenId"
|
|
1063
1063
|
);
|
|
1064
|
-
const l = n.liquidity * BigInt(
|
|
1064
|
+
const l = n.liquidity * BigInt(t.percentBps) / 10000n, c = ve({
|
|
1065
1065
|
positionManager: r,
|
|
1066
1066
|
poolKey: n.pool.key,
|
|
1067
1067
|
tokenId: n.tokenId,
|
|
1068
1068
|
liquidity: l,
|
|
1069
|
-
amount0Min:
|
|
1070
|
-
amount1Min:
|
|
1071
|
-
recipient:
|
|
1069
|
+
amount0Min: t.amount0Min,
|
|
1070
|
+
amount1Min: t.amount1Min,
|
|
1071
|
+
recipient: t.recipient,
|
|
1072
1072
|
owner: o,
|
|
1073
|
-
deadline:
|
|
1074
|
-
...
|
|
1073
|
+
deadline: t.deadline,
|
|
1074
|
+
...t.hookData ? { hookData: t.hookData } : {}
|
|
1075
1075
|
});
|
|
1076
1076
|
return {
|
|
1077
1077
|
to: c.to,
|
|
1078
1078
|
data: c.data,
|
|
1079
1079
|
value: c.value,
|
|
1080
|
-
summary: `Remove ${
|
|
1080
|
+
summary: `Remove ${t.percentBps / 100}% of position #${n.tokenId}`,
|
|
1081
1081
|
source: "live"
|
|
1082
1082
|
};
|
|
1083
1083
|
}
|
|
1084
|
-
const
|
|
1084
|
+
const i = I(
|
|
1085
1085
|
this.chain,
|
|
1086
1086
|
"binPositionManager",
|
|
1087
1087
|
"remove liquidity from a bin pool"
|
|
1088
|
-
),
|
|
1089
|
-
if (
|
|
1088
|
+
), a = n.binAmounts;
|
|
1089
|
+
if (a === void 0 || a.length === 0)
|
|
1090
1090
|
throw new f(
|
|
1091
1091
|
"buildRemoveLiquidity",
|
|
1092
1092
|
"a bin burn needs the per-bin share amounts held by the position"
|
|
1093
1093
|
);
|
|
1094
|
-
const s =
|
|
1095
|
-
positionManager:
|
|
1094
|
+
const s = Le({
|
|
1095
|
+
positionManager: i,
|
|
1096
1096
|
poolKey: n.pool.key,
|
|
1097
|
-
amount0Min:
|
|
1098
|
-
amount1Min:
|
|
1099
|
-
ids:
|
|
1100
|
-
amounts:
|
|
1101
|
-
(r) => r.amount * BigInt(
|
|
1097
|
+
amount0Min: t.amount0Min,
|
|
1098
|
+
amount1Min: t.amount1Min,
|
|
1099
|
+
ids: a.map((r) => r.binId),
|
|
1100
|
+
amounts: a.map(
|
|
1101
|
+
(r) => r.amount * BigInt(t.percentBps) / 10000n
|
|
1102
1102
|
),
|
|
1103
1103
|
from: o,
|
|
1104
|
-
recipient:
|
|
1105
|
-
deadline:
|
|
1106
|
-
...
|
|
1104
|
+
recipient: t.recipient,
|
|
1105
|
+
deadline: t.deadline,
|
|
1106
|
+
...t.hookData ? { hookData: t.hookData } : {}
|
|
1107
1107
|
});
|
|
1108
1108
|
return {
|
|
1109
1109
|
to: s.to,
|
|
1110
1110
|
data: s.data,
|
|
1111
1111
|
value: s.value,
|
|
1112
|
-
summary: `Remove ${
|
|
1112
|
+
summary: `Remove ${t.percentBps / 100}% of a bin position`,
|
|
1113
1113
|
source: "live"
|
|
1114
1114
|
};
|
|
1115
1115
|
}
|
|
@@ -1118,9 +1118,9 @@ class Ct {
|
|
|
1118
1118
|
* here", signalled the way every missing contract is: `ChainConfigError`
|
|
1119
1119
|
* naming `launchGuardHook`, which `isLaunchpadNotConfigured` recognises.
|
|
1120
1120
|
*/
|
|
1121
|
-
#s(
|
|
1121
|
+
#s(t) {
|
|
1122
1122
|
const { launchGuardHook: o, binLaunchGuardHook: n } = this.chain.contracts;
|
|
1123
|
-
o === void 0 && n === void 0 &&
|
|
1123
|
+
o === void 0 && n === void 0 && I(this.chain, "launchGuardHook", t);
|
|
1124
1124
|
}
|
|
1125
1125
|
/**
|
|
1126
1126
|
* Every configured pool whose key names one of the chain's launch guards:
|
|
@@ -1133,16 +1133,16 @@ class Ct {
|
|
|
1133
1133
|
*/
|
|
1134
1134
|
async listLaunches() {
|
|
1135
1135
|
this.#s("read a launch schedule");
|
|
1136
|
-
const
|
|
1137
|
-
return (await Promise.all(
|
|
1136
|
+
const t = this.#e.pools.filter((n) => this.#o(n) !== null);
|
|
1137
|
+
return (await Promise.all(t.map((n) => this.#i(n)))).filter((n) => n !== null);
|
|
1138
1138
|
}
|
|
1139
|
-
async getLaunch(
|
|
1139
|
+
async getLaunch(t) {
|
|
1140
1140
|
this.#s("read a launch schedule");
|
|
1141
|
-
const o = this.#
|
|
1141
|
+
const o = this.#e.pools.find((n) => n.id === t);
|
|
1142
1142
|
if (o === void 0)
|
|
1143
1143
|
throw new f(
|
|
1144
1144
|
"getLaunch",
|
|
1145
|
-
`pool ${
|
|
1145
|
+
`pool ${t} is not in the configured pool list. The singleton has no pool enumeration, so the widget can only read pools the host declared.`
|
|
1146
1146
|
);
|
|
1147
1147
|
return this.#o(o) === null ? null : this.#i(o);
|
|
1148
1148
|
}
|
|
@@ -1155,36 +1155,36 @@ class Ct {
|
|
|
1155
1155
|
* swapped through anyway. A missing one is an error naming the id, not a
|
|
1156
1156
|
* shorter list.
|
|
1157
1157
|
*/
|
|
1158
|
-
async getLaunchesForToken(
|
|
1159
|
-
const o =
|
|
1158
|
+
async getLaunchesForToken(t) {
|
|
1159
|
+
const o = I(this.chain, "launchpadKitV2", "look a launch up by its token"), n = await this.#t.readContract({
|
|
1160
1160
|
address: o,
|
|
1161
|
-
abi:
|
|
1161
|
+
abi: St,
|
|
1162
1162
|
functionName: "legsOf",
|
|
1163
|
-
args: [
|
|
1163
|
+
args: [t]
|
|
1164
1164
|
});
|
|
1165
1165
|
if (n.length === 0) return [];
|
|
1166
|
-
const
|
|
1167
|
-
if (
|
|
1166
|
+
const i = n.filter((r) => this.#e.pools.every((l) => l.id !== r));
|
|
1167
|
+
if (i.length > 0)
|
|
1168
1168
|
throw new f(
|
|
1169
1169
|
"getLaunchesForToken",
|
|
1170
|
-
`the kit lists ${n.length} pool(s) for ${
|
|
1170
|
+
`the kit lists ${n.length} pool(s) for ${t} but ${i.length} of them (${i.join(", ")}) are not in the configured pool list. Declare them (the pool manager's Initialize log carries the key) so the widget can read and route through them.`
|
|
1171
1171
|
);
|
|
1172
|
-
const
|
|
1173
|
-
const l = this.#
|
|
1172
|
+
const a = n.filter((r) => {
|
|
1173
|
+
const l = this.#e.pools.find((c) => c.id === r);
|
|
1174
1174
|
return this.#o(l) === null;
|
|
1175
1175
|
});
|
|
1176
|
-
if (
|
|
1176
|
+
if (a.length > 0)
|
|
1177
1177
|
throw new f(
|
|
1178
1178
|
"getLaunchesForToken",
|
|
1179
|
-
`${
|
|
1179
|
+
`${a.length} of the kit's pools for ${t} (${a.join(", ")}) name a launch guard this chain config does not declare. Set \`contracts.launchGuardHook\` (CL) and \`contracts.binLaunchGuardHook\` (Bin) to the kit's guards; a launch cannot be shown with a leg missing.`
|
|
1180
1180
|
);
|
|
1181
1181
|
return await Promise.all(
|
|
1182
1182
|
n.map(async (r) => {
|
|
1183
|
-
const l = this.#
|
|
1183
|
+
const l = this.#e.pools.find((d) => d.id === r), c = await this.#i(l);
|
|
1184
1184
|
if (c === null)
|
|
1185
1185
|
throw new f(
|
|
1186
1186
|
"getLaunchesForToken",
|
|
1187
|
-
`the kit lists pool ${r} for ${
|
|
1187
|
+
`the kit lists pool ${r} for ${t} but its guard has no launch record for it`
|
|
1188
1188
|
);
|
|
1189
1189
|
return c;
|
|
1190
1190
|
})
|
|
@@ -1195,66 +1195,66 @@ class Ct {
|
|
|
1195
1195
|
* address book, then the hook's own `CLOCK_MODE()` (a revert means the
|
|
1196
1196
|
* block-numbered build). A transport failure throws; it is never a revert.
|
|
1197
1197
|
*/
|
|
1198
|
-
async #r(
|
|
1198
|
+
async #r(t, o = "CL") {
|
|
1199
1199
|
if (o === "CL") {
|
|
1200
|
-
const
|
|
1201
|
-
if (
|
|
1200
|
+
const a = this.chain.contracts.launchGuardHookClock;
|
|
1201
|
+
if (a !== void 0) return a;
|
|
1202
1202
|
}
|
|
1203
|
-
const n =
|
|
1204
|
-
if (o === "CL" && n?.launchGuardHook && b(n.launchGuardHook,
|
|
1205
|
-
const
|
|
1206
|
-
if (
|
|
1203
|
+
const n = Pt(this.chain.chainId);
|
|
1204
|
+
if (o === "CL" && n?.launchGuardHook && b(n.launchGuardHook, t)) {
|
|
1205
|
+
const a = n.durationClocks.launchGuardHook;
|
|
1206
|
+
if (a !== null) return a;
|
|
1207
1207
|
}
|
|
1208
|
-
const
|
|
1209
|
-
if (
|
|
1210
|
-
const
|
|
1211
|
-
if (
|
|
1208
|
+
const i = n?.launchpadV2;
|
|
1209
|
+
if (i !== void 0) {
|
|
1210
|
+
const a = o === "CL" ? i.clLaunchGuardHook : i.binLaunchGuardHook;
|
|
1211
|
+
if (a !== null && b(a, t)) return "timestamp";
|
|
1212
1212
|
}
|
|
1213
1213
|
try {
|
|
1214
|
-
const { data:
|
|
1215
|
-
if (
|
|
1216
|
-
const [s] =
|
|
1217
|
-
if (s ===
|
|
1218
|
-
throw new f("getLaunch", `hook ${
|
|
1219
|
-
} catch (
|
|
1220
|
-
if (
|
|
1214
|
+
const { data: a } = await this.#t.call({ to: t, data: $t });
|
|
1215
|
+
if (a === void 0 || a === "0x") return "contract-block";
|
|
1216
|
+
const [s] = It([{ type: "string" }], a);
|
|
1217
|
+
if (s === Bt) return "timestamp";
|
|
1218
|
+
throw new f("getLaunch", `hook ${t} reports an unknown CLOCK_MODE "${s}"`);
|
|
1219
|
+
} catch (a) {
|
|
1220
|
+
if (a instanceof J && a.walk((s) => s instanceof Z) !== null)
|
|
1221
1221
|
return "contract-block";
|
|
1222
|
-
throw
|
|
1222
|
+
throw a;
|
|
1223
1223
|
}
|
|
1224
1224
|
}
|
|
1225
|
-
async #i(
|
|
1226
|
-
const o = this.#o(
|
|
1225
|
+
async #i(t) {
|
|
1226
|
+
const o = this.#o(t);
|
|
1227
1227
|
if (o === null) return null;
|
|
1228
|
-
const n = o.hook,
|
|
1229
|
-
if (o.poolType === "BIN" &&
|
|
1228
|
+
const n = o.hook, i = await this.#r(n, o.poolType);
|
|
1229
|
+
if (o.poolType === "BIN" && i !== "timestamp")
|
|
1230
1230
|
throw new f(
|
|
1231
1231
|
"getLaunch",
|
|
1232
1232
|
`BinLaunchGuardHook ${n} answers as a block-numbered build; no such build exists, so this is not a Bin launch guard.`
|
|
1233
1233
|
);
|
|
1234
|
-
const
|
|
1234
|
+
const a = o.poolType === "CL" ? at(i) : tt, s = await this.#t.readContract({
|
|
1235
1235
|
address: n,
|
|
1236
|
-
abi:
|
|
1236
|
+
abi: a,
|
|
1237
1237
|
functionName: "getLaunch",
|
|
1238
|
-
args: [
|
|
1239
|
-
}), r =
|
|
1240
|
-
if (!
|
|
1238
|
+
args: [t.id]
|
|
1239
|
+
}), r = Kt(s, i);
|
|
1240
|
+
if (!Xt(r)) return null;
|
|
1241
1241
|
const [l, c] = await Promise.all([
|
|
1242
|
-
this.#
|
|
1242
|
+
this.#t.readContract({
|
|
1243
1243
|
address: n,
|
|
1244
|
-
abi:
|
|
1244
|
+
abi: a,
|
|
1245
1245
|
functionName: "currentFee",
|
|
1246
|
-
args: [
|
|
1246
|
+
args: [t.id]
|
|
1247
1247
|
}),
|
|
1248
1248
|
/* "Now" on the HOOK's clock. The timestamp build compares with
|
|
1249
1249
|
block.timestamp. The block-numbered build compares with the EVM's
|
|
1250
1250
|
block.number, which on an Arbitrum chain (Robinhood, 4663) is
|
|
1251
1251
|
Ethereum's block number while the RPC head is the L2 block; against
|
|
1252
1252
|
the RPC head every unopened launch rendered as settled. */
|
|
1253
|
-
|
|
1254
|
-
]), d =
|
|
1253
|
+
xt(this.#t, this.chain.chainId)
|
|
1254
|
+
]), d = i === "timestamp" ? c.timestamp : c.contractBlockNumber, [p, m] = r.launchTokenIsCurrency0 ? [t.token0, t.token1] : [t.token1, t.token0];
|
|
1255
1255
|
return {
|
|
1256
|
-
poolId:
|
|
1257
|
-
pool:
|
|
1256
|
+
poolId: t.id,
|
|
1257
|
+
pool: t,
|
|
1258
1258
|
hook: n,
|
|
1259
1259
|
launchToken: p,
|
|
1260
1260
|
quoteToken: m,
|
|
@@ -1264,13 +1264,13 @@ class Ct {
|
|
|
1264
1264
|
source: "live"
|
|
1265
1265
|
};
|
|
1266
1266
|
}
|
|
1267
|
-
async sendTransaction(
|
|
1268
|
-
const o = this.#
|
|
1267
|
+
async sendTransaction(t) {
|
|
1268
|
+
const o = this.#e.wallet;
|
|
1269
1269
|
if (o === void 0) throw new E("send a transaction");
|
|
1270
1270
|
return o.sendTransaction({
|
|
1271
|
-
to:
|
|
1272
|
-
data:
|
|
1273
|
-
value:
|
|
1271
|
+
to: t.to,
|
|
1272
|
+
data: t.data,
|
|
1273
|
+
value: t.value
|
|
1274
1274
|
});
|
|
1275
1275
|
}
|
|
1276
1276
|
/**
|
|
@@ -1280,276 +1280,276 @@ class Ct {
|
|
|
1280
1280
|
* latest block's. See `nextBlockClock` for why the pending read matters.
|
|
1281
1281
|
*/
|
|
1282
1282
|
async getBlockTimestamp() {
|
|
1283
|
-
const [
|
|
1284
|
-
this.#
|
|
1285
|
-
this.#
|
|
1286
|
-
]), n =
|
|
1287
|
-
|
|
1283
|
+
const [t, o] = await Promise.allSettled([
|
|
1284
|
+
this.#t.getBlock({ blockTag: "pending" }),
|
|
1285
|
+
this.#t.getBlock({ blockTag: "latest" })
|
|
1286
|
+
]), n = Yt(
|
|
1287
|
+
t.status === "fulfilled" ? t.value.timestamp : null,
|
|
1288
1288
|
o.status === "fulfilled" ? o.value.timestamp : null
|
|
1289
1289
|
);
|
|
1290
1290
|
if (n === null) throw o.status === "rejected" ? o.reason : new Error("no block timestamp could be read");
|
|
1291
1291
|
return n;
|
|
1292
1292
|
}
|
|
1293
|
-
async waitForTransaction(
|
|
1294
|
-
const o = await this.#
|
|
1293
|
+
async waitForTransaction(t) {
|
|
1294
|
+
const o = await this.#t.waitForTransactionReceipt({ hash: t });
|
|
1295
1295
|
return {
|
|
1296
|
-
hash:
|
|
1296
|
+
hash: t,
|
|
1297
1297
|
status: o.status === "success" ? "success" : "reverted",
|
|
1298
1298
|
blockNumber: o.blockNumber,
|
|
1299
1299
|
source: "live"
|
|
1300
1300
|
};
|
|
1301
1301
|
}
|
|
1302
1302
|
}
|
|
1303
|
-
function
|
|
1304
|
-
return new
|
|
1303
|
+
function Re(e) {
|
|
1304
|
+
return new Ae(e);
|
|
1305
1305
|
}
|
|
1306
|
-
function
|
|
1307
|
-
const
|
|
1308
|
-
return
|
|
1309
|
-
() =>
|
|
1310
|
-
[
|
|
1311
|
-
{ enabled:
|
|
1306
|
+
function Fe(e, t, o, n = {}) {
|
|
1307
|
+
const i = n.native ?? mt, a = n.lp ?? {};
|
|
1308
|
+
return $(
|
|
1309
|
+
() => Vt(e, t, o, { native: i, lp: a }),
|
|
1310
|
+
[e, t, o, i.symbol, i.decimals, a.lpLocker, a.binLpLocker, a.poolType, a.lpLockerFromBlock, (a.lpLockerTokenIds ?? []).join(",")],
|
|
1311
|
+
{ enabled: Ht(t, a), refetchIntervalMs: n.refetchIntervalMs ?? 6e4 }
|
|
1312
1312
|
);
|
|
1313
1313
|
}
|
|
1314
|
-
function
|
|
1315
|
-
const
|
|
1316
|
-
return
|
|
1317
|
-
() =>
|
|
1318
|
-
[
|
|
1319
|
-
{ enabled:
|
|
1314
|
+
function Ge(e, t, o, n = {}) {
|
|
1315
|
+
const i = n.native ?? mt, a = n.lp ?? {}, s = !!a.lpLocker || !!a.binLpLocker;
|
|
1316
|
+
return $(
|
|
1317
|
+
() => jt(e, t, o, { native: i, lp: a }),
|
|
1318
|
+
[e, t, o, i.symbol, i.decimals, a.lpLocker, a.binLpLocker, a.lpLockerFromBlock, (a.lpLockerTokenIds ?? []).join(",")],
|
|
1319
|
+
{ enabled: t !== null || s, refetchIntervalMs: n.refetchIntervalMs ?? 6e4 }
|
|
1320
1320
|
);
|
|
1321
1321
|
}
|
|
1322
|
-
function
|
|
1323
|
-
const [o, n] =
|
|
1324
|
-
return
|
|
1325
|
-
if (
|
|
1326
|
-
const
|
|
1327
|
-
return () => clearInterval(
|
|
1328
|
-
}, [
|
|
1322
|
+
function qe(e, t) {
|
|
1323
|
+
const [o, n] = ht(() => Date.now());
|
|
1324
|
+
return Zt(() => {
|
|
1325
|
+
if (e === null) return;
|
|
1326
|
+
const i = setInterval(() => n(Date.now()), 1e3);
|
|
1327
|
+
return () => clearInterval(i);
|
|
1328
|
+
}, [e]), e === null || t === null ? null : Wt(e, t, o);
|
|
1329
1329
|
}
|
|
1330
|
-
function
|
|
1331
|
-
return
|
|
1330
|
+
function L(e) {
|
|
1331
|
+
return e.status === "read" ? e.sources ?? [] : e.status === "error" && e.source ? [e.source] : [];
|
|
1332
1332
|
}
|
|
1333
|
-
function v(
|
|
1334
|
-
return { key:
|
|
1333
|
+
function v(e, t, o, n, i) {
|
|
1334
|
+
return { key: e, label: t, headline: o.headline, detail: o.detail, tone: o.tone, provenance: n.map((a) => ue(a, i.readAt).split(" · ")[0] ?? a.contract), sources: n };
|
|
1335
1335
|
}
|
|
1336
|
-
const
|
|
1336
|
+
const gt = {
|
|
1337
1337
|
"launch-leg": "a Kit v2 launch leg",
|
|
1338
1338
|
"lp-locker": "an LP-locker lock",
|
|
1339
1339
|
"position-lock": "a LatchPositionLock time lock",
|
|
1340
1340
|
given: "this page's pool list"
|
|
1341
1341
|
};
|
|
1342
|
-
function
|
|
1343
|
-
return
|
|
1342
|
+
function vt(e) {
|
|
1343
|
+
return e.length <= 1 ? e[0] ?? "" : `${e.slice(0, -1).join(", ")} and ${e[e.length - 1]}`;
|
|
1344
1344
|
}
|
|
1345
|
-
const
|
|
1346
|
-
function
|
|
1345
|
+
const Te = (e, t) => e[t.toLowerCase()] ?? `${t.slice(0, 6)}…${t.slice(-4)}`;
|
|
1346
|
+
function Me(e, t, o) {
|
|
1347
1347
|
const n = [
|
|
1348
1348
|
{
|
|
1349
|
-
...v("liquidity", "Liquidity locks",
|
|
1350
|
-
share:
|
|
1349
|
+
...v("liquidity", "Liquidity locks", ae(e.liquidity, e.kind), L(e.liquidity), t),
|
|
1350
|
+
share: e.liquidity.status !== "read" || !e.liquidity.measurable ? null : e.kind === "Bin" ? ct([{ key: "permanent", label: "Locked permanently (LP locker)", bps: e.liquidity.lockedActiveBps }], "of the active bin") : ct(
|
|
1351
1351
|
[
|
|
1352
|
-
{ key: "permanent", label: "Locked permanently (LP locker)", bps:
|
|
1353
|
-
{ key: "time", label: "Time-locked until a date", bps:
|
|
1352
|
+
{ key: "permanent", label: "Locked permanently (LP locker)", bps: e.liquidity.permanentActiveBps },
|
|
1353
|
+
{ key: "time", label: "Time-locked until a date", bps: e.liquidity.timeLockedActiveBps }
|
|
1354
1354
|
],
|
|
1355
1355
|
"of active liquidity"
|
|
1356
1356
|
)
|
|
1357
1357
|
},
|
|
1358
|
-
v("lp-fee", "LP fee",
|
|
1359
|
-
v("protocol-fee", "Protocol fee",
|
|
1358
|
+
v("lp-fee", "LP fee", se(e.lpFee), e.lpFee.kind === "error" ? [] : e.lpFee.source === null ? [] : [e.lpFee.source], t),
|
|
1359
|
+
v("protocol-fee", "Protocol fee", re(e.protocolFee), L(e.protocolFee), t)
|
|
1360
1360
|
];
|
|
1361
|
-
return
|
|
1362
|
-
poolId:
|
|
1363
|
-
title: `${
|
|
1364
|
-
foundBy: `Found through ${
|
|
1361
|
+
return e.tax.status !== "not-a-launch-pool" && n.push(v("tax", "Creator tax", yt(e.tax, t.readAt.chainNow), L(e.tax), t)), n.push(v("registry", "Hook in LatchRegistry", ce(e.registry), e.registry.status === "no-hook" ? [] : L(e.registry), t)), {
|
|
1362
|
+
poolId: e.poolId,
|
|
1363
|
+
title: `${t.symbol} / ${Te(o, e.pairedWith)} · ${e.kind} pool`,
|
|
1364
|
+
foundBy: `Found through ${vt(e.origins.map((i) => gt[i]))}.`,
|
|
1365
1365
|
rows: n
|
|
1366
1366
|
};
|
|
1367
1367
|
}
|
|
1368
|
-
function
|
|
1369
|
-
const
|
|
1370
|
-
if (
|
|
1371
|
-
return v("tax", "Creator tax", { headline: "Coming soon", detail: "Latch launches are coming soon on this chain, so there is no creator tax to read.", tone: "missing" }, [],
|
|
1372
|
-
if (
|
|
1373
|
-
return v("tax", "Creator tax", { headline: "Could not be read", detail: `The launch read failed: ${
|
|
1374
|
-
if (
|
|
1375
|
-
return v("tax", "Creator tax", { headline: "Not a Latch launch", detail: "
|
|
1376
|
-
const o =
|
|
1368
|
+
function Ne(e) {
|
|
1369
|
+
const t = e.launch;
|
|
1370
|
+
if (t.status === "not-configured")
|
|
1371
|
+
return v("tax", "Creator tax", { headline: "Coming soon", detail: "Latch launches are coming soon on this chain, so there is no creator tax to read.", tone: "missing" }, [], e);
|
|
1372
|
+
if (t.status === "error")
|
|
1373
|
+
return v("tax", "Creator tax", { headline: "Could not be read", detail: `The launch read failed: ${t.message}.`, tone: "error" }, L(t), e);
|
|
1374
|
+
if (t.launch === null)
|
|
1375
|
+
return v("tax", "Creator tax", { headline: "Not a Latch launch", detail: "This token was not launched on Latch, so no Latch creator tax applies to it.", tone: "neutral" }, L(t), e);
|
|
1376
|
+
const o = e.pools.filter((s) => s.origins.includes("launch-leg") && s.tax.status !== "not-a-launch-pool");
|
|
1377
1377
|
if (o.length === 0)
|
|
1378
|
-
return v("tax", "Creator tax", { headline: "Could not be read", detail: "No launch pool of this token could be described, so its tax was not read.", tone: "error" },
|
|
1379
|
-
const n = o.map((s) =>
|
|
1380
|
-
return n.every((s) => s.headline ===
|
|
1378
|
+
return v("tax", "Creator tax", { headline: "Could not be read", detail: "No launch pool of this token could be described, so its tax was not read.", tone: "error" }, L(t), e);
|
|
1379
|
+
const n = o.map((s) => yt(s.tax, e.readAt.chainNow)), i = o.flatMap((s) => L(s.tax)).filter((s, r, l) => l.findIndex((c) => c.address.toLowerCase() === s.address.toLowerCase()) === r), a = n[0];
|
|
1380
|
+
return n.every((s) => s.headline === a.headline && s.detail === a.detail) ? v("tax", "Creator tax", o.length === 1 ? a : { ...a, detail: `${a.detail ?? ""} Same on all ${o.length} launch pools.`.trim() }, i, e) : v("tax", "Creator tax", { headline: "Differs by pool", detail: "Each launch pool below carries its own terms.", tone: n.some((s) => s.tone === "caution") ? "caution" : "neutral" }, i, e);
|
|
1381
1381
|
}
|
|
1382
|
-
function
|
|
1383
|
-
const o =
|
|
1382
|
+
function Ue(e, t = {}) {
|
|
1383
|
+
const o = e.discovery.searched.map((i) => gt[i]), n = `Pools listed are those found through ${o.length === 0 ? "no source yet: these reads are coming soon on this chain" : vt(o)}${e.discovery.truncated ? ", and only the first of them were read" : ""}${e.discovery.positionLocksTruncated ? " (newest position locks only)" : ""}. A pool of this token that no Latch launch or lock knows about is not listed.`;
|
|
1384
1384
|
return {
|
|
1385
|
-
summary:
|
|
1386
|
-
launch: v("launch", "Latch launch",
|
|
1385
|
+
summary: ie(e),
|
|
1386
|
+
launch: v("launch", "Latch launch", oe(e.launch, e.readAt), L(e.launch), e),
|
|
1387
1387
|
tokenLocks: {
|
|
1388
|
-
...v("token-locks", "Token locks & vesting",
|
|
1389
|
-
share:
|
|
1388
|
+
...v("token-locks", "Token locks & vesting", ne(e.tokenLocks, e.symbol, e.decimals), L(e.tokenLocks), e),
|
|
1389
|
+
share: e.tokenLocks.status === "read" && e.tokenLocks.lockCount > 0 ? Qt(e.tokenLocks) : null
|
|
1390
1390
|
},
|
|
1391
|
-
creatorTax:
|
|
1392
|
-
pools:
|
|
1393
|
-
failedPools:
|
|
1391
|
+
creatorTax: Ne(e),
|
|
1392
|
+
pools: e.pools.map((i) => Me(i, e, t)),
|
|
1393
|
+
failedPools: e.failedPools.map((i) => `${i.kind} pool ${i.poolId.slice(0, 10)}… could not be described: ${i.message}.`),
|
|
1394
1394
|
discoveryNote: n,
|
|
1395
|
-
readAtNote:
|
|
1395
|
+
readAtNote: "Live from the chain. Token units, never priced. A registry listing is what the registry records, not an audit."
|
|
1396
1396
|
};
|
|
1397
1397
|
}
|
|
1398
|
-
async function
|
|
1399
|
-
const o = await
|
|
1400
|
-
token:
|
|
1401
|
-
contracts:
|
|
1402
|
-
...
|
|
1403
|
-
...
|
|
1404
|
-
...
|
|
1405
|
-
}), n = [...new Set(o.pools.map((r) => r.pairedWith.toLowerCase()))],
|
|
1398
|
+
async function Se(e, t) {
|
|
1399
|
+
const o = await le(e, {
|
|
1400
|
+
token: t.token,
|
|
1401
|
+
contracts: t.contracts,
|
|
1402
|
+
...t.pools !== void 0 ? { pools: t.pools } : {},
|
|
1403
|
+
...t.lpLockerTokenIds !== void 0 ? { lpLockerTokenIds: t.lpLockerTokenIds } : {},
|
|
1404
|
+
...t.native !== void 0 ? { native: t.native } : {}
|
|
1405
|
+
}), n = [...new Set(o.pools.map((r) => r.pairedWith.toLowerCase()))], i = t.native?.symbol ?? "ETH", a = await Promise.all(n.map((r) => r === Lt ? Promise.resolve({ symbol: i }) : Dt(e, r).catch(() => null))), s = {};
|
|
1406
1406
|
return n.forEach((r, l) => {
|
|
1407
|
-
const c =
|
|
1407
|
+
const c = a[l];
|
|
1408
1408
|
c && (s[r] = c.symbol);
|
|
1409
1409
|
}), { trust: o, symbols: s };
|
|
1410
1410
|
}
|
|
1411
|
-
function
|
|
1412
|
-
const n =
|
|
1413
|
-
return
|
|
1414
|
-
() =>
|
|
1411
|
+
function Ke(e, t, o = {}) {
|
|
1412
|
+
const n = t.contracts, i = n === null ? "none" : Object.entries(n).map(([a, s]) => `${a}:${String(s ?? "")}`).sort().join("|");
|
|
1413
|
+
return $(
|
|
1414
|
+
() => Se(e, { ...t, contracts: n }),
|
|
1415
1415
|
[
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
(
|
|
1420
|
-
(
|
|
1421
|
-
|
|
1422
|
-
|
|
1416
|
+
e,
|
|
1417
|
+
t.token.toLowerCase(),
|
|
1418
|
+
i,
|
|
1419
|
+
(t.pools ?? []).map((a) => `${a.kind}${a.poolId}`).join(","),
|
|
1420
|
+
(t.lpLockerTokenIds ?? []).join(","),
|
|
1421
|
+
t.native?.symbol,
|
|
1422
|
+
t.native?.decimals
|
|
1423
1423
|
],
|
|
1424
1424
|
{ enabled: n !== null, refetchIntervalMs: o.refetchIntervalMs ?? 6e4 }
|
|
1425
1425
|
);
|
|
1426
1426
|
}
|
|
1427
|
-
function
|
|
1428
|
-
const o =
|
|
1429
|
-
if (!/^\d+(\.\d+)?$/.test(o) || (o.split(".")[1] ?? "").length >
|
|
1427
|
+
function Xe(e, t) {
|
|
1428
|
+
const o = e.trim().replace(/_/g, "");
|
|
1429
|
+
if (!/^\d+(\.\d+)?$/.test(o) || (o.split(".")[1] ?? "").length > t) return null;
|
|
1430
1430
|
try {
|
|
1431
|
-
return
|
|
1431
|
+
return Ct(o, t);
|
|
1432
1432
|
} catch {
|
|
1433
1433
|
return null;
|
|
1434
1434
|
}
|
|
1435
1435
|
}
|
|
1436
|
-
function
|
|
1437
|
-
const
|
|
1438
|
-
if (
|
|
1439
|
-
const o = Date.UTC(Number(
|
|
1436
|
+
function Ye(e) {
|
|
1437
|
+
const t = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/.exec(e.trim());
|
|
1438
|
+
if (t === null) return null;
|
|
1439
|
+
const o = Date.UTC(Number(t[1]), Number(t[2]) - 1, Number(t[3]), Number(t[4]), Number(t[5]));
|
|
1440
1440
|
return Number.isFinite(o) ? BigInt(Math.floor(o / 1e3)) : null;
|
|
1441
1441
|
}
|
|
1442
|
-
function
|
|
1443
|
-
return new Date(Number(
|
|
1442
|
+
function We(e) {
|
|
1443
|
+
return new Date(Number(e) * 1e3).toISOString().slice(0, 16);
|
|
1444
1444
|
}
|
|
1445
|
-
function
|
|
1446
|
-
const
|
|
1447
|
-
return /^\d+$/.test(
|
|
1445
|
+
function He(e) {
|
|
1446
|
+
const t = e.trim();
|
|
1447
|
+
return /^\d+$/.test(t) ? BigInt(t) * 86400n : null;
|
|
1448
1448
|
}
|
|
1449
|
-
function
|
|
1450
|
-
return
|
|
1449
|
+
function Ve(e, t) {
|
|
1450
|
+
return e === "timelock" ? t.unlockAt === null ? null : { start: t.unlockAt, cliff: t.unlockAt, end: t.unlockAt } : t.start === null || t.cliffDays === null || t.durationDays === null ? null : { start: t.start, cliff: t.start + t.cliffDays, end: t.start + t.durationDays };
|
|
1451
1451
|
}
|
|
1452
|
-
function H(
|
|
1453
|
-
if (
|
|
1454
|
-
const o = 10n ** BigInt(
|
|
1455
|
-
return
|
|
1452
|
+
function H(e, t) {
|
|
1453
|
+
if (e === 0n) return "0";
|
|
1454
|
+
const o = 10n ** BigInt(t), n = e / o, i = (e % o).toString().padStart(t, "0").replace(/0+$/, "");
|
|
1455
|
+
return i === "" ? n.toLocaleString("en-US") : `${n.toLocaleString("en-US")}.${i}`;
|
|
1456
1456
|
}
|
|
1457
|
-
function
|
|
1458
|
-
const o = `${H(
|
|
1457
|
+
function je(e, t) {
|
|
1458
|
+
const o = `${H(e.feeWei, t.decimals)} ${t.symbol} per lock`, n = e.pendingFee, i = n !== null && n.feeWei > e.feeWei, a = i ? n.feeWei : e.feeWei, s = n === null ? null : `${n.feeWei > e.feeWei ? "An increase" : "A change"} to ${H(n.feeWei, t.decimals)} ${t.symbol} applies from ${new Date(Number(n.effectiveAt) * 1e3).toISOString().replace("T", " ").slice(0, 16)} UTC.`;
|
|
1459
1459
|
return {
|
|
1460
1460
|
fee: o,
|
|
1461
|
-
sends: `${H(
|
|
1461
|
+
sends: `${H(a, t.decimals)} ${t.symbol}`,
|
|
1462
1462
|
pending: s,
|
|
1463
|
-
note: `Charged by the lock contract itself and paid only to its fee recipient ${
|
|
1463
|
+
note: `Charged by the lock contract itself and paid only to its fee recipient ${e.recipient.slice(0, 6)}…${e.recipient.slice(-4)}.${i ? " The transaction sends the announced higher fee in case it applies before it mines; the contract refunds any surplus in the same call." : ""}`
|
|
1464
1464
|
};
|
|
1465
1465
|
}
|
|
1466
|
-
function
|
|
1467
|
-
const
|
|
1468
|
-
return
|
|
1466
|
+
function Qe(e) {
|
|
1467
|
+
const t = [];
|
|
1468
|
+
return e.approved || t.push({ key: "approve", label: `Approve LatchPositionLock to move position #${e.tokenId} (this NFT only)` }), t.push({ key: "lock", label: `Lock position #${e.tokenId} until ${new Date(Number(e.unlockAt) * 1e3).toISOString().replace("T", " ").slice(0, 16)} UTC, paying the fee` }), t;
|
|
1469
1469
|
}
|
|
1470
|
-
function
|
|
1471
|
-
const
|
|
1472
|
-
return !
|
|
1470
|
+
function ze(e) {
|
|
1471
|
+
const t = [];
|
|
1472
|
+
return !e.native && e.allowance < e.amount && t.push({ key: "approve", label: `Approve LatchTokenLock for exactly ${e.amountText} ${e.symbol}` }), t.push({ key: "lock", label: `Lock ${e.amountText} ${e.symbol}, paying the fee${e.native ? " (the amount is sent with it)" : ""}` }), t;
|
|
1473
1473
|
}
|
|
1474
|
-
const R = (
|
|
1475
|
-
function
|
|
1476
|
-
if (
|
|
1474
|
+
const R = (e, t) => e != null && t !== null && t !== void 0 && e.toLowerCase() === t.toLowerCase();
|
|
1475
|
+
function Je(e, t, o) {
|
|
1476
|
+
if (e.withdrawn) return [];
|
|
1477
1477
|
const n = ["collect"];
|
|
1478
|
-
return R(
|
|
1478
|
+
return R(e.owner, t) && (n.push("extend"), o >= e.unlockAt && n.push("withdraw")), R(e.pendingOwner, t) && n.push("accept"), n;
|
|
1479
1479
|
}
|
|
1480
|
-
function
|
|
1480
|
+
function Ze(e, t) {
|
|
1481
1481
|
const o = [];
|
|
1482
|
-
return R(
|
|
1482
|
+
return R(e.beneficiary, t) && e.claimable > 0n && o.push("claim"), R(e.pendingBeneficiary, t) && o.push("accept"), o;
|
|
1483
1483
|
}
|
|
1484
|
-
const
|
|
1484
|
+
const tn = {
|
|
1485
1485
|
collect: "Collect fees",
|
|
1486
1486
|
extend: "Extend",
|
|
1487
1487
|
withdraw: "Withdraw",
|
|
1488
1488
|
accept: "Accept lock"
|
|
1489
|
-
},
|
|
1489
|
+
}, en = {
|
|
1490
1490
|
claim: "Claim vested",
|
|
1491
1491
|
accept: "Accept lock"
|
|
1492
1492
|
};
|
|
1493
|
-
function nn(
|
|
1494
|
-
const
|
|
1495
|
-
return
|
|
1496
|
-
if (
|
|
1497
|
-
const o =
|
|
1493
|
+
function nn(e) {
|
|
1494
|
+
const t = Jt();
|
|
1495
|
+
return ee(() => {
|
|
1496
|
+
if (e !== void 0) return e;
|
|
1497
|
+
const o = t?.adapter;
|
|
1498
1498
|
return o === void 0 || o.isMock ? null : {
|
|
1499
1499
|
getAccount: () => o.getAccount(),
|
|
1500
1500
|
sendTransaction: (n) => o.sendTransaction({ ...n, summary: "Latch lock", source: "live" })
|
|
1501
1501
|
};
|
|
1502
|
-
}, [
|
|
1502
|
+
}, [e, t?.adapter]);
|
|
1503
1503
|
}
|
|
1504
|
-
function on(
|
|
1505
|
-
return
|
|
1504
|
+
function on(e) {
|
|
1505
|
+
return $(() => e === null ? Promise.resolve(null) : e.getAccount(), [e], { refetchIntervalMs: 4e3 });
|
|
1506
1506
|
}
|
|
1507
|
-
function an(
|
|
1508
|
-
return
|
|
1507
|
+
function an(e, t) {
|
|
1508
|
+
return $(
|
|
1509
1509
|
async () => {
|
|
1510
1510
|
const [o, n] = await Promise.all([
|
|
1511
|
-
|
|
1512
|
-
|
|
1511
|
+
t.positionLock === null ? Promise.resolve(null) : lt(e, t.positionLock),
|
|
1512
|
+
t.tokenLock === null ? Promise.resolve(null) : lt(e, t.tokenLock)
|
|
1513
1513
|
]);
|
|
1514
1514
|
return { position: o, token: n };
|
|
1515
1515
|
},
|
|
1516
|
-
[
|
|
1517
|
-
{ enabled:
|
|
1516
|
+
[e, t.positionLock, t.tokenLock],
|
|
1517
|
+
{ enabled: t.positionLock !== null || t.tokenLock !== null, refetchIntervalMs: 6e4 }
|
|
1518
1518
|
);
|
|
1519
1519
|
}
|
|
1520
|
-
function sn(
|
|
1521
|
-
return
|
|
1520
|
+
function sn(e, t, o) {
|
|
1521
|
+
return $(
|
|
1522
1522
|
async () => {
|
|
1523
|
-
const n = o, [
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1523
|
+
const n = o, [i, a, s] = await Promise.all([
|
|
1524
|
+
de(e),
|
|
1525
|
+
t.positionLock === null ? Promise.resolve([]) : pe(e, t.positionLock, n),
|
|
1526
|
+
t.tokenLock === null ? Promise.resolve({ locks: [] }) : me(e, t.tokenLock, n)
|
|
1527
1527
|
]);
|
|
1528
|
-
return { positions:
|
|
1528
|
+
return { positions: a, tokens: s.locks, now: i };
|
|
1529
1529
|
},
|
|
1530
|
-
[
|
|
1531
|
-
{ enabled: o !== null && (
|
|
1530
|
+
[e, t.positionLock, t.tokenLock, o],
|
|
1531
|
+
{ enabled: o !== null && (t.positionLock !== null || t.tokenLock !== null), refetchIntervalMs: 6e4 }
|
|
1532
1532
|
);
|
|
1533
1533
|
}
|
|
1534
1534
|
class V extends Error {
|
|
1535
1535
|
hash;
|
|
1536
|
-
constructor(
|
|
1537
|
-
super(`The transaction ${
|
|
1536
|
+
constructor(t) {
|
|
1537
|
+
super(`The transaction ${t.slice(0, 10)}… was mined and reverted.`), this.name = "TransactionRevertedError", this.hash = t;
|
|
1538
1538
|
}
|
|
1539
1539
|
}
|
|
1540
|
-
async function rn(
|
|
1541
|
-
await
|
|
1542
|
-
const
|
|
1543
|
-
if ((await
|
|
1544
|
-
return
|
|
1540
|
+
async function rn(e, t, o, n) {
|
|
1541
|
+
await e.call({ account: o, to: n.to, data: n.data, value: n.value });
|
|
1542
|
+
const i = await t.sendTransaction({ to: n.to, data: n.data, value: n.value });
|
|
1543
|
+
if ((await e.waitForTransactionReceipt({ hash: i })).status !== "success") throw new V(i);
|
|
1544
|
+
return i;
|
|
1545
1545
|
}
|
|
1546
|
-
function cn(
|
|
1547
|
-
const [
|
|
1546
|
+
function cn(e, t, o, n) {
|
|
1547
|
+
const [i, a] = ht({ k: "idle" }), s = te(!1), r = ut(
|
|
1548
1548
|
async (c) => {
|
|
1549
1549
|
if (s.current) return;
|
|
1550
1550
|
const d = c.map((u) => u.label);
|
|
1551
|
-
if (
|
|
1552
|
-
|
|
1551
|
+
if (t === null || o === null) {
|
|
1552
|
+
a({ k: "failed", labels: d, active: 0, message: "Connect a wallet first." });
|
|
1553
1553
|
return;
|
|
1554
1554
|
}
|
|
1555
1555
|
s.current = !0;
|
|
@@ -1557,57 +1557,57 @@ function cn(t, e, o, n) {
|
|
|
1557
1557
|
let m = 0;
|
|
1558
1558
|
try {
|
|
1559
1559
|
for (; m < c.length; m++) {
|
|
1560
|
-
|
|
1560
|
+
a({ k: "running", labels: d, active: m, phase: "simulating" });
|
|
1561
1561
|
const u = await c[m].build();
|
|
1562
|
-
await
|
|
1563
|
-
const h = await
|
|
1564
|
-
if (
|
|
1562
|
+
await e.call({ account: o, to: u.to, data: u.data, value: u.value }), a({ k: "running", labels: d, active: m, phase: "signing" });
|
|
1563
|
+
const h = await t.sendTransaction({ to: u.to, data: u.data, value: u.value });
|
|
1564
|
+
if (a({ k: "running", labels: d, active: m, phase: "confirming" }), (await e.waitForTransactionReceipt({ hash: h })).status !== "success") throw new V(h);
|
|
1565
1565
|
p.push(h);
|
|
1566
1566
|
}
|
|
1567
|
-
|
|
1567
|
+
a({ k: "done", labels: d, hashes: p }), n?.();
|
|
1568
1568
|
} catch (u) {
|
|
1569
|
-
|
|
1569
|
+
a({ k: "failed", labels: d, active: m, message: u instanceof V ? u.message : zt(u, "transaction") });
|
|
1570
1570
|
} finally {
|
|
1571
1571
|
s.current = !1;
|
|
1572
1572
|
}
|
|
1573
1573
|
},
|
|
1574
|
-
[
|
|
1575
|
-
), l =
|
|
1576
|
-
return { state:
|
|
1574
|
+
[e, t, o, n]
|
|
1575
|
+
), l = ut(() => a({ k: "idle" }), []);
|
|
1576
|
+
return { state: i, run: r, reset: l };
|
|
1577
1577
|
}
|
|
1578
1578
|
export {
|
|
1579
1579
|
sn as A,
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1580
|
+
Fe as B,
|
|
1581
|
+
Ge as C,
|
|
1582
|
+
Ke as D,
|
|
1583
|
+
Ee as N,
|
|
1584
|
+
tn as P,
|
|
1585
|
+
en as T,
|
|
1586
1586
|
V as a,
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1587
|
+
Ie as b,
|
|
1588
|
+
Le as c,
|
|
1589
|
+
ve as d,
|
|
1590
|
+
ge as e,
|
|
1591
|
+
he as f,
|
|
1592
|
+
Re as g,
|
|
1593
|
+
Se as h,
|
|
1594
|
+
_e as i,
|
|
1595
|
+
je as j,
|
|
1596
|
+
Xe as k,
|
|
1597
|
+
Ve as l,
|
|
1598
|
+
Ye as m,
|
|
1599
|
+
Qe as n,
|
|
1600
|
+
ze as o,
|
|
1601
|
+
He as p,
|
|
1602
|
+
Je as q,
|
|
1603
|
+
Ze as r,
|
|
1604
1604
|
rn as s,
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1605
|
+
We as t,
|
|
1606
|
+
Ue as u,
|
|
1607
|
+
qe as v,
|
|
1608
1608
|
on as w,
|
|
1609
1609
|
an as x,
|
|
1610
1610
|
cn as y,
|
|
1611
1611
|
nn as z
|
|
1612
1612
|
};
|
|
1613
|
-
//# sourceMappingURL=useLocker-
|
|
1613
|
+
//# sourceMappingURL=useLocker-CGpgCh75.js.map
|