@aurora-is-near/intents-connect 7.20.0
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 +176 -0
- package/dist/api/createIntentsConnectApi.d.ts +31 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/types.d.ts +93 -0
- package/dist/chains.d.ts +27 -0
- package/dist/chunks/recovery-BBQaAcqE.js +1034 -0
- package/dist/chunks/recovery-BBQaAcqE.js.map +1 -0
- package/dist/errors.d.ts +94 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +197 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +7 -0
- package/dist/machine/context.d.ts +39 -0
- package/dist/machine/guards/checks/amountMustExceedFee.d.ts +2 -0
- package/dist/machine/guards/checks/destinationTokenIsTouched.d.ts +12 -0
- package/dist/machine/guards/checks/feeMustBeEstimated.d.ts +9 -0
- package/dist/machine/guards/checks/memoPresentForStellar.d.ts +6 -0
- package/dist/machine/guards/checks/mustBeSignedBeforeDeposit.d.ts +8 -0
- package/dist/machine/guards/checks/mustHaveSigningPayload.d.ts +7 -0
- package/dist/machine/guards/checks/noExecutionInFlight.d.ts +7 -0
- package/dist/machine/guards/checks/originNetworkMatches.d.ts +5 -0
- package/dist/machine/guards/checks/publicKeyMatchesStandard.d.ts +7 -0
- package/dist/machine/guards/checks/quoteMustNotHaveMoved.d.ts +8 -0
- package/dist/machine/guards/checks/recipientOnlyOnOutOperation.d.ts +11 -0
- package/dist/machine/guards/checks/round1MustBeStepless.d.ts +8 -0
- package/dist/machine/guards/checks/stepShapeIsLegal.d.ts +7 -0
- package/dist/machine/guards/checks/stepsRequiredForRealCreate.d.ts +6 -0
- package/dist/machine/guards/checks/strategiesAreExclusive.d.ts +17 -0
- package/dist/machine/guards/index.d.ts +19 -0
- package/dist/machine/index.d.ts +4 -0
- package/dist/machine/machine.d.ts +50 -0
- package/dist/machine/phases.d.ts +48 -0
- package/dist/react/IntentsConnectProvider.d.ts +12 -0
- package/dist/react/context.d.ts +12 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +149 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useExecution.d.ts +42 -0
- package/dist/recovery.d.ts +27 -0
- package/dist/runner/createExecutionRunner.d.ts +2 -0
- package/dist/runner/index.d.ts +2 -0
- package/dist/runner/types.d.ts +146 -0
- package/dist/signers/index.d.ts +2 -0
- package/dist/signers/intentsConnect.d.ts +43 -0
- package/dist/signers/standards/encoding.d.ts +15 -0
- package/dist/signers/standards/erc191.d.ts +18 -0
- package/dist/signers/standards/index.d.ts +12 -0
- package/dist/signers/standards/nep413.d.ts +22 -0
- package/dist/signers/standards/rawEd25519.d.ts +20 -0
- package/dist/signers/standards/sep53.d.ts +22 -0
- package/dist/types/execution.d.ts +133 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/providers.d.ts +63 -0
- package/dist/types/recipe.d.ts +38 -0
- package/dist/types/signing.d.ts +70 -0
- package/dist/types/transfer.d.ts +60 -0
- package/dist/types/wallet.d.ts +53 -0
- package/package.json +54 -0
- package/react/package.json +8 -0
- package/src/api/createIntentsConnectApi.test.ts +146 -0
- package/src/api/createIntentsConnectApi.ts +263 -0
- package/src/api/generated/conformance.ts +233 -0
- package/src/api/generated/openapi.ts +995 -0
- package/src/api/index.ts +17 -0
- package/src/api/types.ts +138 -0
- package/src/chains.ts +103 -0
- package/src/errors.ts +234 -0
- package/src/index.ts +73 -0
- package/src/logger.ts +21 -0
- package/src/machine/context.ts +56 -0
- package/src/machine/guards/checks/amountMustExceedFee.ts +14 -0
- package/src/machine/guards/checks/destinationTokenIsTouched.ts +31 -0
- package/src/machine/guards/checks/feeMustBeEstimated.ts +22 -0
- package/src/machine/guards/checks/memoPresentForStellar.ts +20 -0
- package/src/machine/guards/checks/mustBeSignedBeforeDeposit.ts +17 -0
- package/src/machine/guards/checks/mustHaveSigningPayload.ts +19 -0
- package/src/machine/guards/checks/noExecutionInFlight.ts +19 -0
- package/src/machine/guards/checks/originNetworkMatches.ts +23 -0
- package/src/machine/guards/checks/publicKeyMatchesStandard.ts +28 -0
- package/src/machine/guards/checks/quoteMustNotHaveMoved.ts +20 -0
- package/src/machine/guards/checks/recipientOnlyOnOutOperation.ts +23 -0
- package/src/machine/guards/checks/round1MustBeStepless.ts +17 -0
- package/src/machine/guards/checks/stepShapeIsLegal.ts +79 -0
- package/src/machine/guards/checks/stepsRequiredForRealCreate.ts +12 -0
- package/src/machine/guards/checks/strategiesAreExclusive.ts +35 -0
- package/src/machine/guards/guards.test.ts +317 -0
- package/src/machine/guards/index.ts +22 -0
- package/src/machine/index.ts +15 -0
- package/src/machine/machine.test.ts +131 -0
- package/src/machine/machine.ts +113 -0
- package/src/machine/phases.ts +81 -0
- package/src/react/IntentsConnectProvider.tsx +61 -0
- package/src/react/context.ts +34 -0
- package/src/react/index.ts +14 -0
- package/src/react/useExecution.test.tsx +281 -0
- package/src/react/useExecution.ts +246 -0
- package/src/recovery.test.ts +44 -0
- package/src/recovery.ts +45 -0
- package/src/runner/createExecutionRunner.test.ts +1388 -0
- package/src/runner/createExecutionRunner.ts +1156 -0
- package/src/runner/index.ts +9 -0
- package/src/runner/types.ts +148 -0
- package/src/signers/index.ts +7 -0
- package/src/signers/intentsConnect.ts +210 -0
- package/src/signers/signers.test.ts +415 -0
- package/src/signers/standards/encoding.ts +89 -0
- package/src/signers/standards/erc191.ts +61 -0
- package/src/signers/standards/index.ts +20 -0
- package/src/signers/standards/nep413.ts +84 -0
- package/src/signers/standards/rawEd25519.ts +46 -0
- package/src/signers/standards/sep53.ts +74 -0
- package/src/tests/setup.ts +4 -0
- package/src/types/execution.ts +177 -0
- package/src/types/index.ts +6 -0
- package/src/types/providers.ts +71 -0
- package/src/types/recipe.ts +41 -0
- package/src/types/signing.ts +99 -0
- package/src/types/transfer.ts +90 -0
- package/src/types/wallet.ts +60 -0
|
@@ -0,0 +1,1034 @@
|
|
|
1
|
+
import { proxy as $e } from "valtio/vanilla";
|
|
2
|
+
import { base58 as Me, base64 as fe } from "@scure/base";
|
|
3
|
+
const Ue = [
|
|
4
|
+
"SUCCESS",
|
|
5
|
+
"DEPOSIT_FAILED",
|
|
6
|
+
"OPERATION_FAILED"
|
|
7
|
+
], ke = [
|
|
8
|
+
"CREATED",
|
|
9
|
+
"DEPOSIT_PENDING",
|
|
10
|
+
"DEPOSIT_PROCESSING",
|
|
11
|
+
"OPERATION_PENDING",
|
|
12
|
+
"OPERATION_PROCESSING"
|
|
13
|
+
], Ge = {
|
|
14
|
+
evm: 30,
|
|
15
|
+
solana: 50
|
|
16
|
+
}, ee = 1024, Ee = [
|
|
17
|
+
"to",
|
|
18
|
+
"functionSignature",
|
|
19
|
+
"parameters",
|
|
20
|
+
"value",
|
|
21
|
+
"metadata"
|
|
22
|
+
], pe = {
|
|
23
|
+
minAmountOut: "{MIN_AMOUNT_OUT}",
|
|
24
|
+
depositAddress: "{DEPOSIT_ADDRESS}",
|
|
25
|
+
amountIn: "{AMOUNT_IN}"
|
|
26
|
+
}, qe = ["erc191", "raw_ed25519", "nep413", "sep53"], Fe = [
|
|
27
|
+
"raw_ed25519",
|
|
28
|
+
"nep413",
|
|
29
|
+
"sep53",
|
|
30
|
+
"ton_connect"
|
|
31
|
+
], He = (e) => qe.includes(
|
|
32
|
+
e
|
|
33
|
+
);
|
|
34
|
+
class I extends Error {
|
|
35
|
+
constructor(t, s) {
|
|
36
|
+
super(t), this.name = "IntentsConnectError", s?.cause !== void 0 && (this.cause = s.cause);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const te = (e) => {
|
|
40
|
+
if (e instanceof Error)
|
|
41
|
+
return e;
|
|
42
|
+
if (typeof e == "object" && e !== null) {
|
|
43
|
+
const t = e, s = typeof t.error == "object" && t.error !== null ? t.error : void 0, c = [t.message, s?.message].find(
|
|
44
|
+
(h) => typeof h == "string"
|
|
45
|
+
), g = t.code ?? s?.code;
|
|
46
|
+
if (c)
|
|
47
|
+
return new I(
|
|
48
|
+
g !== void 0 ? `${c} (code ${String(g)})` : c,
|
|
49
|
+
{ cause: e }
|
|
50
|
+
);
|
|
51
|
+
try {
|
|
52
|
+
return new I(JSON.stringify(e), { cause: e });
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return new I(String(e), { cause: e });
|
|
57
|
+
}, Be = (e) => {
|
|
58
|
+
if (!e || typeof e != "object")
|
|
59
|
+
return !1;
|
|
60
|
+
const t = e;
|
|
61
|
+
if (t.code === 4001)
|
|
62
|
+
return !0;
|
|
63
|
+
const s = t.error ?? t.cause;
|
|
64
|
+
return s && typeof s == "object" && s.code === 4001 ? !0 : typeof t.message == "string" && /user (rejected|denied|cancell?ed)/i.test(t.message);
|
|
65
|
+
};
|
|
66
|
+
class Ke extends I {
|
|
67
|
+
constructor(t, s, a) {
|
|
68
|
+
super(t), this.status = s, this.body = a, this.name = "IntentsConnectApiError";
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A `dry: false` create is already live for this (intermediary, chain). The
|
|
72
|
+
* caller must wait for a terminal status or delete the open execution.
|
|
73
|
+
*/
|
|
74
|
+
get isExecutionInFlight() {
|
|
75
|
+
return this.status === 409;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class je extends I {
|
|
79
|
+
constructor(t) {
|
|
80
|
+
super(`execution ${t} was cancelled`), this.executionId = t, this.name = "ExecutionCancelledError";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
class We extends I {
|
|
84
|
+
constructor(t) {
|
|
85
|
+
super(
|
|
86
|
+
"the runner was disposed while an execution was in flight — resume() it from a runner bound to the owning wallet"
|
|
87
|
+
), this.executionId = t, this.name = "RunnerDisposedError";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class Xe extends I {
|
|
91
|
+
constructor(t, s) {
|
|
92
|
+
super(
|
|
93
|
+
`${s} — the execution is still live server-side; call resume('${t}') to keep watching it`
|
|
94
|
+
), this.executionId = t, this.name = "ExecutionPollTimeoutError";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
class Y extends I {
|
|
98
|
+
constructor(t, s) {
|
|
99
|
+
super(
|
|
100
|
+
`the deposit transfer for execution ${t} was not completed — call retryDeposit() to prompt it again`,
|
|
101
|
+
s
|
|
102
|
+
), this.executionId = t, this.name = "DepositTransferError";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
class L extends I {
|
|
106
|
+
constructor(t, s, a = {}) {
|
|
107
|
+
super(s), this.code = t, this.meta = a, this.name = "GuardError";
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const u = (e, t, s) => {
|
|
111
|
+
throw new L(e, t, s);
|
|
112
|
+
}, Ye = /* @__PURE__ */ new Set([
|
|
113
|
+
"eth",
|
|
114
|
+
"arb",
|
|
115
|
+
"base",
|
|
116
|
+
"bsc",
|
|
117
|
+
"op",
|
|
118
|
+
"pol",
|
|
119
|
+
"avax",
|
|
120
|
+
"scroll",
|
|
121
|
+
"gnosis",
|
|
122
|
+
"xlayer",
|
|
123
|
+
"bera",
|
|
124
|
+
"monad",
|
|
125
|
+
"plasma",
|
|
126
|
+
"adi",
|
|
127
|
+
"aurora"
|
|
128
|
+
]), Ve = {
|
|
129
|
+
eth: 1,
|
|
130
|
+
arb: 42161,
|
|
131
|
+
base: 8453,
|
|
132
|
+
bsc: 56,
|
|
133
|
+
op: 10,
|
|
134
|
+
pol: 137,
|
|
135
|
+
avax: 43114,
|
|
136
|
+
scroll: 534352,
|
|
137
|
+
gnosis: 100,
|
|
138
|
+
xlayer: 196,
|
|
139
|
+
bera: 80094,
|
|
140
|
+
monad: 143,
|
|
141
|
+
plasma: 9745,
|
|
142
|
+
adi: 36900,
|
|
143
|
+
aurora: 1313161554
|
|
144
|
+
}, ne = ".omft.near", Qe = (e) => {
|
|
145
|
+
const [, t] = e.split(":");
|
|
146
|
+
if (!t?.endsWith(ne))
|
|
147
|
+
return;
|
|
148
|
+
const s = t.slice(0, -ne.length), a = s.indexOf("-");
|
|
149
|
+
if (a === -1)
|
|
150
|
+
return s ? { chain: s } : void 0;
|
|
151
|
+
const c = s.slice(0, a), g = s.slice(a + 1);
|
|
152
|
+
return c && g ? { chain: c, tokenAddress: g } : void 0;
|
|
153
|
+
}, Je = (e) => Ye.has(e), W = (e) => {
|
|
154
|
+
if (Je(e))
|
|
155
|
+
return "evm";
|
|
156
|
+
if (e === "sol")
|
|
157
|
+
return "sol";
|
|
158
|
+
if (e === "stellar")
|
|
159
|
+
return "stellar";
|
|
160
|
+
if (e === "near")
|
|
161
|
+
return "near";
|
|
162
|
+
}, se = "[INTENTS-CONNECT]", me = {
|
|
163
|
+
debug: () => {
|
|
164
|
+
},
|
|
165
|
+
warn: (e, ...t) => console.warn(`${se} ${e}`, ...t),
|
|
166
|
+
error: (e, ...t) => console.error(`${se} ${e}`, ...t)
|
|
167
|
+
}, Ut = {
|
|
168
|
+
debug: () => {
|
|
169
|
+
},
|
|
170
|
+
warn: () => {
|
|
171
|
+
},
|
|
172
|
+
error: () => {
|
|
173
|
+
}
|
|
174
|
+
}, re = () => ({
|
|
175
|
+
phase: "idle",
|
|
176
|
+
hasSubmittedSignature: !1,
|
|
177
|
+
isCancelling: !1
|
|
178
|
+
}), ze = {
|
|
179
|
+
idle: [
|
|
180
|
+
"resolving-identity",
|
|
181
|
+
"awaiting-signature",
|
|
182
|
+
"awaiting-deposit",
|
|
183
|
+
"settling",
|
|
184
|
+
"failed",
|
|
185
|
+
"cancelled"
|
|
186
|
+
],
|
|
187
|
+
"resolving-identity": ["planning", "failed", "cancelled"],
|
|
188
|
+
planning: ["creating", "failed", "cancelled"],
|
|
189
|
+
creating: ["awaiting-signature", "failed", "cancelled"],
|
|
190
|
+
"awaiting-signature": ["submitting", "failed", "cancelled"],
|
|
191
|
+
submitting: ["awaiting-deposit", "settling", "failed", "cancelled"],
|
|
192
|
+
"awaiting-deposit": ["settling", "expired", "cancelled", "failed"],
|
|
193
|
+
settling: ["success", "failed", "expired", "cancelled"],
|
|
194
|
+
expired: ["settling", "failed", "cancelled"],
|
|
195
|
+
success: [],
|
|
196
|
+
failed: [],
|
|
197
|
+
cancelled: []
|
|
198
|
+
}, Ze = [
|
|
199
|
+
"success",
|
|
200
|
+
"failed",
|
|
201
|
+
"cancelled"
|
|
202
|
+
], et = (e) => Ze.includes(e), tt = () => {
|
|
203
|
+
const e = $e({
|
|
204
|
+
state: "idle",
|
|
205
|
+
context: re()
|
|
206
|
+
}), t = {
|
|
207
|
+
get current() {
|
|
208
|
+
return e.state;
|
|
209
|
+
},
|
|
210
|
+
get context() {
|
|
211
|
+
return e.context;
|
|
212
|
+
},
|
|
213
|
+
getStore: () => e,
|
|
214
|
+
canMoveTo: (s) => ze[e.state].includes(s),
|
|
215
|
+
moveTo: (s) => (t.canMoveTo(s) && (e.state = s), t),
|
|
216
|
+
reset: () => {
|
|
217
|
+
e.state = "idle", e.context = re();
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
return t;
|
|
221
|
+
}, nt = (e, t, { logger: s = me, onMoved: a } = {}) => {
|
|
222
|
+
if (e.current === t)
|
|
223
|
+
return !0;
|
|
224
|
+
if (!e.canMoveTo(t))
|
|
225
|
+
return s.error(
|
|
226
|
+
`invalid transition requested (from ${e.current} to ${t})`
|
|
227
|
+
), !1;
|
|
228
|
+
const { current: c, context: g } = e.moveTo(t);
|
|
229
|
+
return c !== t ? !1 : (g.phase = t, a?.(t), !0);
|
|
230
|
+
}, st = (e, t) => {
|
|
231
|
+
BigInt(e) - BigInt(t) <= 0n && u(
|
|
232
|
+
"FEE_EXCEEDS_AMOUNT",
|
|
233
|
+
`network fee (${t}) exceeds the delivered amount (${e})`
|
|
234
|
+
);
|
|
235
|
+
}, rt = (e, t) => {
|
|
236
|
+
if (!t)
|
|
237
|
+
return;
|
|
238
|
+
const s = t.toLowerCase();
|
|
239
|
+
e.some((c) => c.to.toLowerCase() === s) || u(
|
|
240
|
+
"DESTINATION_TOKEN_UNTOUCHED",
|
|
241
|
+
`steps must include at least one call to destination token ${t}`
|
|
242
|
+
);
|
|
243
|
+
}, ot = (e) => {
|
|
244
|
+
const t = e.details.networkFee;
|
|
245
|
+
return t || u(
|
|
246
|
+
"FEE_NOT_ESTIMATED",
|
|
247
|
+
"no details.networkFee returned — gas estimation failed; retry the round"
|
|
248
|
+
);
|
|
249
|
+
}, it = /* @__PURE__ */ new Set(["stellar"]), oe = (e, t) => {
|
|
250
|
+
it.has(e) && !t && u(
|
|
251
|
+
"MEMO_REQUIRED",
|
|
252
|
+
"a Stellar deposit requires quote.depositMemo on both the transfer and deposit/submit"
|
|
253
|
+
);
|
|
254
|
+
}, at = (e) => {
|
|
255
|
+
e || u(
|
|
256
|
+
"DEPOSIT_BEFORE_SIGNATURE",
|
|
257
|
+
"refusing to expose a deposit address before the intent signature is submitted"
|
|
258
|
+
);
|
|
259
|
+
}, X = (e) => {
|
|
260
|
+
const { payload: t, signingStandard: s } = e.details;
|
|
261
|
+
return !t || !s ? u(
|
|
262
|
+
"NO_SIGNING_PAYLOAD",
|
|
263
|
+
"execution returned no signing payload — fee estimation likely failed"
|
|
264
|
+
) : { payload: t, standard: s };
|
|
265
|
+
}, ct = (e) => {
|
|
266
|
+
const [t] = e;
|
|
267
|
+
t && u(
|
|
268
|
+
"EXECUTION_IN_FLIGHT",
|
|
269
|
+
`execution ${t.id} is already in progress — resume it, cancel it, or wait for it to reach a terminal status`,
|
|
270
|
+
{ executionId: t.id }
|
|
271
|
+
);
|
|
272
|
+
}, dt = async (e, t) => {
|
|
273
|
+
if (!e || t == null)
|
|
274
|
+
return;
|
|
275
|
+
const s = await e();
|
|
276
|
+
s !== t && u(
|
|
277
|
+
"NETWORK_MISMATCH",
|
|
278
|
+
`wallet is on chain ${s} but the origin requires chain ${t}`
|
|
279
|
+
);
|
|
280
|
+
}, ut = (e, t) => {
|
|
281
|
+
const s = Fe.includes(e);
|
|
282
|
+
s && !t && u(
|
|
283
|
+
"PUBLIC_KEY_MISMATCH",
|
|
284
|
+
`${e} requires a publicKey — ed25519 keys are not recoverable from a signature`
|
|
285
|
+
), !s && t && u(
|
|
286
|
+
"PUBLIC_KEY_MISMATCH",
|
|
287
|
+
`${e} must omit publicKey — the signer is recovered via ecrecover`
|
|
288
|
+
);
|
|
289
|
+
}, lt = (e, t) => {
|
|
290
|
+
BigInt(t) < BigInt(e) && u(
|
|
291
|
+
"QUOTE_MOVED",
|
|
292
|
+
`quote moved: steps baked ${e} but the service now guarantees ${t}`
|
|
293
|
+
);
|
|
294
|
+
}, gt = (e, t) => {
|
|
295
|
+
t && e === "bridge-in" && u(
|
|
296
|
+
"RECIPIENT_NOT_ALLOWED",
|
|
297
|
+
"quote.recipient is only valid for out-operations"
|
|
298
|
+
);
|
|
299
|
+
}, ft = (e) => {
|
|
300
|
+
e.length > 0 && u(
|
|
301
|
+
"ROUND1_MUST_BE_STEPLESS",
|
|
302
|
+
"three-round flow: round 1 must send steps: []"
|
|
303
|
+
);
|
|
304
|
+
}, Et = new Set(Ee), pt = (e, t) => {
|
|
305
|
+
const s = Ge[t];
|
|
306
|
+
e.length > s && u(
|
|
307
|
+
"ILLEGAL_STEP_SHAPE",
|
|
308
|
+
`${t} allows at most ${s} steps, got ${e.length}`
|
|
309
|
+
), e.forEach((a, c) => {
|
|
310
|
+
Object.keys(a).forEach((h) => {
|
|
311
|
+
Et.has(h) || u(
|
|
312
|
+
"ILLEGAL_STEP_SHAPE",
|
|
313
|
+
`step ${c}: unknown key "${h}" (allowed: ${Ee.join(", ")})`
|
|
314
|
+
);
|
|
315
|
+
}), (typeof a.to != "string" || a.to === "") && u(
|
|
316
|
+
"ILLEGAL_STEP_SHAPE",
|
|
317
|
+
`step ${c}: "to" must be a non-empty string`
|
|
318
|
+
), Array.isArray(a.parameters) || u(
|
|
319
|
+
"ILLEGAL_STEP_SHAPE",
|
|
320
|
+
`step ${c}: "parameters" must be an array`
|
|
321
|
+
), typeof a.value != "string" && u(
|
|
322
|
+
"ILLEGAL_STEP_SHAPE",
|
|
323
|
+
`step ${c}: "value" must be a string`
|
|
324
|
+
), typeof a.functionSignature != "string" && u(
|
|
325
|
+
"ILLEGAL_STEP_SHAPE",
|
|
326
|
+
`step ${c}: "functionSignature" must be a string (empty for a bare value transfer)`
|
|
327
|
+
), new TextEncoder().encode(
|
|
328
|
+
a.functionSignature
|
|
329
|
+
).length > ee && u(
|
|
330
|
+
"ILLEGAL_STEP_SHAPE",
|
|
331
|
+
`step ${c}: functionSignature exceeds ${ee} bytes`
|
|
332
|
+
);
|
|
333
|
+
});
|
|
334
|
+
}, mt = (e, t) => {
|
|
335
|
+
!t && e.length === 0 && u("STEPS_REQUIRED", "dry: false requires a non-empty steps array");
|
|
336
|
+
}, he = (e) => JSON.stringify(e).includes(pe.minAmountOut), ie = (e, t) => {
|
|
337
|
+
e.kind === "threeRound" && he(t) && u(
|
|
338
|
+
"STRATEGY_CONFLICT",
|
|
339
|
+
"threeRound steps must carry literal amounts, not {MIN_AMOUNT_OUT}"
|
|
340
|
+
);
|
|
341
|
+
}, ae = 64, ce = 65, de = 64, $ = (e) => fe.decode(e), ue = (e) => fe.encode(e), U = (e) => Me.encode(e), ht = (e) => {
|
|
342
|
+
const t = e.replace(/^0x/i, "").toLowerCase();
|
|
343
|
+
if (t.length % 2 !== 0)
|
|
344
|
+
throw new Error("Hex string has an odd length");
|
|
345
|
+
if (!/^[0-9a-f]*$/.test(t))
|
|
346
|
+
throw new Error("Hex string contains non-hexadecimal characters");
|
|
347
|
+
const s = new Uint8Array(t.length / 2);
|
|
348
|
+
for (let a = 0; a < s.length; a += 1)
|
|
349
|
+
s[a] = Number.parseInt(t.slice(a * 2, a * 2 + 2), 16);
|
|
350
|
+
return s;
|
|
351
|
+
}, wt = (e) => {
|
|
352
|
+
if (e.length !== ce)
|
|
353
|
+
throw new Error(
|
|
354
|
+
`secp256k1 signature must be ${ce} bytes, got ${e.length}`
|
|
355
|
+
);
|
|
356
|
+
const t = Uint8Array.from(e), s = t[de];
|
|
357
|
+
return s >= 27 && (t[de] = s - 27), t;
|
|
358
|
+
}, we = (e, t) => {
|
|
359
|
+
if (e.length !== ae)
|
|
360
|
+
throw new Error(
|
|
361
|
+
`${t} signature must be ${ae} bytes, got ${e.length}`
|
|
362
|
+
);
|
|
363
|
+
return e;
|
|
364
|
+
}, yt = (e) => `secp256k1:${U(e)}`, M = (e) => `ed25519:${U(e)}`, St = (e) => `ed25519:${U(e)}`, Tt = (e) => e.startsWith("ed25519:") ? e : `ed25519:${e}`, ye = async ({
|
|
365
|
+
message: e,
|
|
366
|
+
provider: t,
|
|
367
|
+
expectedAddress: s
|
|
368
|
+
}) => {
|
|
369
|
+
const a = typeof t == "function" ? await t() : t, c = await a.request({ method: "eth_requestAccounts" });
|
|
370
|
+
if (!Array.isArray(c))
|
|
371
|
+
throw new Error("EVM provider returned no accounts");
|
|
372
|
+
const g = c.find(
|
|
373
|
+
(m) => typeof m == "string" && m.toLowerCase() === s.toLowerCase()
|
|
374
|
+
);
|
|
375
|
+
if (!g)
|
|
376
|
+
throw new Error("Connected EVM account does not match the execution");
|
|
377
|
+
const h = await a.request({
|
|
378
|
+
method: "personal_sign",
|
|
379
|
+
// Argument order is [message, address].
|
|
380
|
+
params: [e, g]
|
|
381
|
+
});
|
|
382
|
+
if (typeof h != "string")
|
|
383
|
+
throw new Error("EVM provider returned no signature");
|
|
384
|
+
return {
|
|
385
|
+
signature: yt(wt(ht(h)))
|
|
386
|
+
};
|
|
387
|
+
}, Se = async ({
|
|
388
|
+
bytes: e,
|
|
389
|
+
provider: t,
|
|
390
|
+
expectedAddress: s
|
|
391
|
+
}) => {
|
|
392
|
+
const a = t.publicKey?.toString();
|
|
393
|
+
if (a && a !== s)
|
|
394
|
+
throw new Error("Connected Solana account does not match the execution");
|
|
395
|
+
const c = await t.signMessage(e);
|
|
396
|
+
return {
|
|
397
|
+
signature: M(
|
|
398
|
+
we(c, "Solana")
|
|
399
|
+
),
|
|
400
|
+
publicKey: Tt(a ?? s)
|
|
401
|
+
};
|
|
402
|
+
}, Te = async ({
|
|
403
|
+
payload: e,
|
|
404
|
+
getProvider: t,
|
|
405
|
+
expectedAccountId: s
|
|
406
|
+
}) => {
|
|
407
|
+
const a = t();
|
|
408
|
+
if (!a.signMessage)
|
|
409
|
+
throw new Error("NEAR wallet does not expose signMessage");
|
|
410
|
+
const c = $(e.nonce), g = await a.signMessage({
|
|
411
|
+
message: e.message,
|
|
412
|
+
recipient: e.recipient,
|
|
413
|
+
nonce: c
|
|
414
|
+
});
|
|
415
|
+
if (!g)
|
|
416
|
+
throw new Error("NEAR wallet failed to sign the message");
|
|
417
|
+
if (g.accountId !== s)
|
|
418
|
+
throw new Error("Connected NEAR account does not match the execution");
|
|
419
|
+
const h = g.publicKey.startsWith("ed25519:") ? g.publicKey : `ed25519:${g.publicKey}`, m = g.signature;
|
|
420
|
+
let N;
|
|
421
|
+
return typeof m != "string" ? N = M(m) : m.startsWith("ed25519:") ? N = m : N = M($(m)), { signature: N, publicKey: h };
|
|
422
|
+
}, kt = (e) => `ed25519:${U(e)}`, _t = async ({
|
|
423
|
+
message: e,
|
|
424
|
+
provider: t,
|
|
425
|
+
expectedAddress: s,
|
|
426
|
+
decodePublicKey: a
|
|
427
|
+
}) => {
|
|
428
|
+
const c = await t.signMessage(e), g = c?.error;
|
|
429
|
+
if (g)
|
|
430
|
+
throw new Error(
|
|
431
|
+
typeof g == "string" ? g : g.message ?? "Stellar wallet refused to sign"
|
|
432
|
+
);
|
|
433
|
+
const { signedMessage: h, signerAddress: m } = c;
|
|
434
|
+
if (!h)
|
|
435
|
+
throw new Error("Stellar wallet returned no signed message");
|
|
436
|
+
if (m && m !== s)
|
|
437
|
+
throw new Error("Connected Stellar account does not match the execution");
|
|
438
|
+
const N = h instanceof Uint8Array ? h : $(h);
|
|
439
|
+
return {
|
|
440
|
+
signature: M(
|
|
441
|
+
we(N, "SEP-53")
|
|
442
|
+
),
|
|
443
|
+
publicKey: St(a())
|
|
444
|
+
};
|
|
445
|
+
}, b = (e, t) => e || u(
|
|
446
|
+
"WALLET_NOT_CONNECTED",
|
|
447
|
+
`no provider available to sign a ${t} payload`
|
|
448
|
+
), At = (e) => {
|
|
449
|
+
const t = JSON.parse(e);
|
|
450
|
+
if (!t || typeof t != "object")
|
|
451
|
+
throw new Error("nep413 payload_json is not an object");
|
|
452
|
+
return t;
|
|
453
|
+
}, It = async ({
|
|
454
|
+
payload: e,
|
|
455
|
+
standard: t,
|
|
456
|
+
address: s,
|
|
457
|
+
providers: a,
|
|
458
|
+
decodePublicKey: c
|
|
459
|
+
}) => {
|
|
460
|
+
switch (t) {
|
|
461
|
+
case "erc191":
|
|
462
|
+
return ye({
|
|
463
|
+
message: e.payload_json,
|
|
464
|
+
provider: b(a.evm, t),
|
|
465
|
+
expectedAddress: s
|
|
466
|
+
});
|
|
467
|
+
case "raw_ed25519":
|
|
468
|
+
return Se({
|
|
469
|
+
bytes: $(e.payload_bytes_base64),
|
|
470
|
+
provider: b(a.sol, t),
|
|
471
|
+
expectedAddress: s
|
|
472
|
+
});
|
|
473
|
+
case "nep413":
|
|
474
|
+
return Te({
|
|
475
|
+
payload: At(e.payload_json),
|
|
476
|
+
getProvider: b(a.near, t),
|
|
477
|
+
expectedAccountId: s
|
|
478
|
+
});
|
|
479
|
+
case "sep53":
|
|
480
|
+
return c ? _t({
|
|
481
|
+
message: e.payload_json,
|
|
482
|
+
provider: b(a.stellar, t),
|
|
483
|
+
expectedAddress: s,
|
|
484
|
+
decodePublicKey: c
|
|
485
|
+
}) : u(
|
|
486
|
+
"UNSUPPORTED_SIGNING_STANDARD",
|
|
487
|
+
"sep53 requires a decodePublicKey implementation (supply it from the Stellar wallet package)"
|
|
488
|
+
);
|
|
489
|
+
default:
|
|
490
|
+
return u(
|
|
491
|
+
"UNSUPPORTED_SIGNING_STANDARD",
|
|
492
|
+
`signing standard ${String(t)} is not implemented`
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
}, le = "intents.near", Nt = 32, xt = () => {
|
|
496
|
+
const e = new Uint8Array(Nt);
|
|
497
|
+
return globalThis.crypto.getRandomValues(e), e;
|
|
498
|
+
}, vt = async ({
|
|
499
|
+
text: e,
|
|
500
|
+
standard: t,
|
|
501
|
+
address: s,
|
|
502
|
+
providers: a
|
|
503
|
+
}) => {
|
|
504
|
+
switch (t) {
|
|
505
|
+
case "erc191":
|
|
506
|
+
return ye({
|
|
507
|
+
message: e,
|
|
508
|
+
provider: b(a.evm, t),
|
|
509
|
+
expectedAddress: s
|
|
510
|
+
});
|
|
511
|
+
case "raw_ed25519":
|
|
512
|
+
return Se({
|
|
513
|
+
bytes: new TextEncoder().encode(e),
|
|
514
|
+
provider: b(a.sol, t),
|
|
515
|
+
expectedAddress: s
|
|
516
|
+
});
|
|
517
|
+
case "nep413": {
|
|
518
|
+
const c = xt();
|
|
519
|
+
return {
|
|
520
|
+
...await Te({
|
|
521
|
+
payload: {
|
|
522
|
+
message: e,
|
|
523
|
+
recipient: le,
|
|
524
|
+
nonce: ue(c)
|
|
525
|
+
},
|
|
526
|
+
getProvider: b(a.near, t),
|
|
527
|
+
expectedAccountId: s
|
|
528
|
+
}),
|
|
529
|
+
nep413: {
|
|
530
|
+
recipient: le,
|
|
531
|
+
nonce: ue(c)
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
case "sep53":
|
|
536
|
+
return u(
|
|
537
|
+
"UNSUPPORTED_SIGNING_STANDARD",
|
|
538
|
+
"the delete_execution endpoint does not accept sep53 — a Stellar-origin execution cannot be cancelled client-side and clears on expiry"
|
|
539
|
+
);
|
|
540
|
+
default:
|
|
541
|
+
return u(
|
|
542
|
+
"UNSUPPORTED_SIGNING_STANDARD",
|
|
543
|
+
`cancelling a ${String(t)} origin execution is not supported yet`
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
}, bt = 3e3, Pt = 240, Dt = { kind: "placeholder" }, Ot = 10 * 6e4, Ct = 5 * 6e4, ge = 5, Rt = (e) => new Promise((t) => {
|
|
547
|
+
setTimeout(t, e);
|
|
548
|
+
}), Gt = (e) => {
|
|
549
|
+
const {
|
|
550
|
+
api: t,
|
|
551
|
+
wallet: s,
|
|
552
|
+
plugins: a,
|
|
553
|
+
pluginOptions: c,
|
|
554
|
+
makeTransfer: g,
|
|
555
|
+
autoCancelOnSignatureRejection: h = !0,
|
|
556
|
+
logger: m = me,
|
|
557
|
+
pollIntervalMs: N = bt,
|
|
558
|
+
maxPollAttempts: O = Pt,
|
|
559
|
+
onEvent: _e
|
|
560
|
+
} = e, l = tt(), _ = () => typeof s == "function" ? s() : s;
|
|
561
|
+
let P, V = !1, x, D;
|
|
562
|
+
const v = (n) => _e?.(n), y = (n) => {
|
|
563
|
+
Object.assign(l.context, n);
|
|
564
|
+
}, w = (n) => nt(l, n, {
|
|
565
|
+
logger: m,
|
|
566
|
+
onMoved: (o) => v({ type: "phase", phase: o })
|
|
567
|
+
}), C = () => {
|
|
568
|
+
if (V)
|
|
569
|
+
throw new We(l.context.executionId);
|
|
570
|
+
}, k = (n) => {
|
|
571
|
+
if (P === n)
|
|
572
|
+
throw new je(n);
|
|
573
|
+
}, Q = () => {
|
|
574
|
+
C(), l.current !== "idle" && !et(l.current) && u(
|
|
575
|
+
"EXECUTION_IN_FLIGHT",
|
|
576
|
+
`this runner is already driving an execution (phase: ${l.current}) — wait for it, cancel() it, or use another runner`
|
|
577
|
+
), l.reset(), P = void 0;
|
|
578
|
+
}, S = () => {
|
|
579
|
+
const n = _().getAddress();
|
|
580
|
+
return n || u("WALLET_NOT_CONNECTED", "no wallet is connected");
|
|
581
|
+
}, Ae = async (n) => {
|
|
582
|
+
const { payload: o, standard: r } = X(n), i = _();
|
|
583
|
+
return { envelope: await It({
|
|
584
|
+
payload: o,
|
|
585
|
+
standard: r,
|
|
586
|
+
address: S(),
|
|
587
|
+
providers: i.getProviders(),
|
|
588
|
+
decodePublicKey: i.decodePublicKey
|
|
589
|
+
}), standard: r };
|
|
590
|
+
}, Ie = async () => {
|
|
591
|
+
w("resolving-identity");
|
|
592
|
+
const n = await t.getIntermediary(S(), {
|
|
593
|
+
publicKey: _().getPublicKey?.()
|
|
594
|
+
});
|
|
595
|
+
return y({ intermediary: n }), n;
|
|
596
|
+
}, Ne = (n, o) => {
|
|
597
|
+
const r = n.recipe.type === "solana" ? o.solana : o.evm;
|
|
598
|
+
return r || u(
|
|
599
|
+
"NO_INTERMEDIARY",
|
|
600
|
+
`the service returned no ${n.recipe.type} intermediary account for this wallet`
|
|
601
|
+
);
|
|
602
|
+
}, xe = (n) => n.quote.deadline ? n : {
|
|
603
|
+
...n,
|
|
604
|
+
quote: {
|
|
605
|
+
...n.quote,
|
|
606
|
+
deadline: new Date(
|
|
607
|
+
Date.now() + Ot
|
|
608
|
+
).toISOString()
|
|
609
|
+
}
|
|
610
|
+
}, G = (n, o, r) => ({
|
|
611
|
+
version: "1.0",
|
|
612
|
+
type: n.recipe.type,
|
|
613
|
+
quote: n.quote,
|
|
614
|
+
steps: o,
|
|
615
|
+
metadata: { title: n.recipe.title, intent: n.recipe.intent },
|
|
616
|
+
dry: r,
|
|
617
|
+
publicKey: n.originChain === "ton" ? _().getPublicKey?.() : void 0
|
|
618
|
+
}), q = (n, o) => (pt(o, n.recipe.type), rt(
|
|
619
|
+
o,
|
|
620
|
+
n.recipe.destination.tokenAddress
|
|
621
|
+
), o), ve = async (n, o) => {
|
|
622
|
+
w("planning");
|
|
623
|
+
const { recipe: r, params: i, quote: d } = n, f = n.feeStrategy ?? Dt;
|
|
624
|
+
gt(r.flow, d.recipient), await dt(
|
|
625
|
+
_().getChainId,
|
|
626
|
+
n.originChainId
|
|
627
|
+
);
|
|
628
|
+
const E = {
|
|
629
|
+
intermediary: o,
|
|
630
|
+
userAddress: S()
|
|
631
|
+
};
|
|
632
|
+
if (f.kind === "placeholder") {
|
|
633
|
+
const j = r.buildSteps(
|
|
634
|
+
{ ...E, amount: pe.minAmountOut },
|
|
635
|
+
i
|
|
636
|
+
);
|
|
637
|
+
return ie(f, j), he(j) || m.warn(
|
|
638
|
+
`recipe "${r.id}" ignored ctx.amount under the placeholder fee strategy, so the service has no amount to substitute — intended only if its amounts are deliberately fixed`
|
|
639
|
+
), q(n, j);
|
|
640
|
+
}
|
|
641
|
+
ft([]);
|
|
642
|
+
const p = await t.createExecution(
|
|
643
|
+
S(),
|
|
644
|
+
G(n, [], !0)
|
|
645
|
+
), T = r.buildSteps(
|
|
646
|
+
{ ...E, amount: p.quote.minAmountOut },
|
|
647
|
+
i
|
|
648
|
+
);
|
|
649
|
+
ie(f, T);
|
|
650
|
+
const A = await t.createExecution(
|
|
651
|
+
S(),
|
|
652
|
+
G(n, q(n, T), !0)
|
|
653
|
+
), K = ot(A);
|
|
654
|
+
st(p.quote.minAmountOut, K);
|
|
655
|
+
const R = A.quote.minAmountOut;
|
|
656
|
+
y({ networkFee: K, spendable: R, bakedAmount: R }), v({ type: "quoted", networkFee: K, spendable: R });
|
|
657
|
+
const Le = r.buildSteps({ ...E, amount: R }, i);
|
|
658
|
+
return q(n, Le);
|
|
659
|
+
}, be = async (n, o) => {
|
|
660
|
+
w("creating"), mt(o, !1);
|
|
661
|
+
const r = S();
|
|
662
|
+
ct(
|
|
663
|
+
await t.listExecutions(r, { status: ke })
|
|
664
|
+
);
|
|
665
|
+
let i;
|
|
666
|
+
try {
|
|
667
|
+
i = await t.createExecution(
|
|
668
|
+
r,
|
|
669
|
+
G(n, o, !1)
|
|
670
|
+
);
|
|
671
|
+
} catch (d) {
|
|
672
|
+
if (d instanceof Ke && d.isExecutionInFlight)
|
|
673
|
+
return u("EXECUTION_IN_FLIGHT", d.message);
|
|
674
|
+
throw d;
|
|
675
|
+
}
|
|
676
|
+
y({
|
|
677
|
+
execution: i,
|
|
678
|
+
executionId: i.id,
|
|
679
|
+
status: i.status,
|
|
680
|
+
networkFee: i.details.networkFee ?? l.context.networkFee
|
|
681
|
+
}), v({ type: "created", executionId: i.id });
|
|
682
|
+
try {
|
|
683
|
+
const { bakedAmount: d } = l.context;
|
|
684
|
+
d && lt(d, i.quote.minAmountOut), X(i);
|
|
685
|
+
} catch (d) {
|
|
686
|
+
throw d instanceof L ? new L(
|
|
687
|
+
d.code,
|
|
688
|
+
`${d.message} — execution ${i.id} was created and holds the in-flight lock; cancel('${i.id}') clears it`
|
|
689
|
+
) : d;
|
|
690
|
+
}
|
|
691
|
+
return i;
|
|
692
|
+
}, J = async (n) => {
|
|
693
|
+
w("awaiting-signature");
|
|
694
|
+
const { envelope: o, standard: r } = await Ae(n);
|
|
695
|
+
k(n.id), C(), ut(r, o.publicKey), w("submitting");
|
|
696
|
+
const { status: i } = await t.submitSignature(S(), {
|
|
697
|
+
...o,
|
|
698
|
+
executionId: n.id
|
|
699
|
+
});
|
|
700
|
+
return y({ hasSubmittedSignature: !0 }), i !== "SIGNING";
|
|
701
|
+
}, Pe = (n) => {
|
|
702
|
+
if (g)
|
|
703
|
+
return (E) => g(E, void 0);
|
|
704
|
+
const o = _(), r = o.makeTransfer;
|
|
705
|
+
if (r)
|
|
706
|
+
return (E) => r.call(o, E);
|
|
707
|
+
const i = W(n), d = i ? a?.[i] : void 0;
|
|
708
|
+
if (!i || !d)
|
|
709
|
+
return u(
|
|
710
|
+
"NO_TRANSFER_IMPLEMENTATION",
|
|
711
|
+
`no transfer implementation for origin chain "${n}" — pass a wallet connector with makeTransfer, a plugin, or makeTransfer directly`
|
|
712
|
+
);
|
|
713
|
+
const f = c && typeof c == "object" && i in c ? c[i] : c;
|
|
714
|
+
return (E) => d.makeTransfer(E, f);
|
|
715
|
+
}, z = (n, o) => {
|
|
716
|
+
w("awaiting-deposit"), at(l.context.hasSubmittedSignature);
|
|
717
|
+
const { depositAddress: r, depositMemo: i } = n.quote, d = o ?? n.quote.deadline;
|
|
718
|
+
return y({ depositAddress: r, depositMemo: i, deadline: d }), v({
|
|
719
|
+
type: "deposit-address",
|
|
720
|
+
address: r,
|
|
721
|
+
memo: i,
|
|
722
|
+
deadline: d
|
|
723
|
+
}), { depositAddress: r, depositMemo: i };
|
|
724
|
+
}, F = async (n, o) => {
|
|
725
|
+
oe(n.originChain, o.quote.depositMemo);
|
|
726
|
+
const { depositAddress: r, depositMemo: i } = z(
|
|
727
|
+
o,
|
|
728
|
+
n.quote.deadline
|
|
729
|
+
);
|
|
730
|
+
if (!n.depositViaWallet)
|
|
731
|
+
return;
|
|
732
|
+
k(o.id), C();
|
|
733
|
+
const d = n.quote.swapType === "EXACT_OUTPUT" ? o.quote.amountIn : o.quote.amount, f = Pe(n.originChain);
|
|
734
|
+
let E;
|
|
735
|
+
try {
|
|
736
|
+
({ hash: E } = await f({
|
|
737
|
+
amountAtomic: d,
|
|
738
|
+
decimals: n.originToken.decimals,
|
|
739
|
+
address: r,
|
|
740
|
+
tokenAddress: n.originToken.contractAddress,
|
|
741
|
+
chain: n.originChain,
|
|
742
|
+
evmChainId: n.originChainId ?? null,
|
|
743
|
+
isNativeEvmTokenTransfer: !n.originToken.contractAddress,
|
|
744
|
+
memo: i ?? void 0
|
|
745
|
+
}));
|
|
746
|
+
} catch (p) {
|
|
747
|
+
throw new Y(o.id, { cause: te(p) });
|
|
748
|
+
}
|
|
749
|
+
y({ depositTxHash: E }), v({ type: "deposit-sent", txHash: E });
|
|
750
|
+
try {
|
|
751
|
+
await t.recordDeposit({
|
|
752
|
+
txHash: E,
|
|
753
|
+
depositAddress: r,
|
|
754
|
+
...i ? { memo: i } : {}
|
|
755
|
+
});
|
|
756
|
+
} catch (p) {
|
|
757
|
+
m.warn("failed to record the deposit (non-fatal)", p);
|
|
758
|
+
}
|
|
759
|
+
}, H = async (n) => {
|
|
760
|
+
const o = () => l.current === "awaiting-deposit" && l.context.status === "CREATED" && !l.context.depositTxHash;
|
|
761
|
+
o() || w("settling");
|
|
762
|
+
const r = S(), i = l.context.deadline ? Date.parse(l.context.deadline) : Number.NaN;
|
|
763
|
+
let d = 0, f = 0;
|
|
764
|
+
for (; d < O; ) {
|
|
765
|
+
C(), k(n);
|
|
766
|
+
let p;
|
|
767
|
+
try {
|
|
768
|
+
[p] = await t.listExecutions(r, { id: n }), f = 0;
|
|
769
|
+
} catch (A) {
|
|
770
|
+
if (f += 1, f >= ge)
|
|
771
|
+
throw A;
|
|
772
|
+
m.warn(
|
|
773
|
+
`poll for execution ${n} failed (${f}/${ge} consecutive) — retrying`,
|
|
774
|
+
A
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
if (p) {
|
|
778
|
+
if (p.status !== l.context.status && (y({ execution: p, status: p.status }), v({ type: "status", status: p.status })), Ue.includes(p.status)) {
|
|
779
|
+
if ((l.current === "expired" || l.current === "awaiting-deposit") && w("settling"), p.status === "SUCCESS")
|
|
780
|
+
return w("success"), p;
|
|
781
|
+
throw w("failed"), new Error(`execution ${p.status}`);
|
|
782
|
+
}
|
|
783
|
+
p.status === "EXPIRED" ? w("expired") : (l.current === "expired" || l.current === "awaiting-deposit" && p.status !== "CREATED") && w("settling");
|
|
784
|
+
}
|
|
785
|
+
o() && Number.isFinite(i) && Date.now() < i + Ct || (d += 1), d < O && await Rt(N);
|
|
786
|
+
}
|
|
787
|
+
const E = l.current === "expired";
|
|
788
|
+
throw w("failed"), new Xe(
|
|
789
|
+
n,
|
|
790
|
+
E ? `execution ${n} expired and was not revived within ${O} polls` : `polling timed out after ${O} attempts for execution ${n}`
|
|
791
|
+
);
|
|
792
|
+
}, B = (n) => {
|
|
793
|
+
const o = te(n);
|
|
794
|
+
throw y({ error: o }), v({ type: "error", error: o }), !(o instanceof Y) && l.current !== "cancelled" && l.current !== "failed" && w("failed"), o;
|
|
795
|
+
}, Z = async (n) => {
|
|
796
|
+
const o = n ?? l.context.executionId;
|
|
797
|
+
if (!o)
|
|
798
|
+
throw new Error("no execution to cancel");
|
|
799
|
+
const r = _();
|
|
800
|
+
y({ isCancelling: !0 });
|
|
801
|
+
try {
|
|
802
|
+
const i = await vt({
|
|
803
|
+
text: `delete_execution:${o}`,
|
|
804
|
+
standard: r.signingStandard,
|
|
805
|
+
address: S(),
|
|
806
|
+
providers: r.getProviders(),
|
|
807
|
+
decodePublicKey: r.decodePublicKey
|
|
808
|
+
}), d = P;
|
|
809
|
+
P = o;
|
|
810
|
+
try {
|
|
811
|
+
await t.deleteExecution(S(), o, i);
|
|
812
|
+
} catch (f) {
|
|
813
|
+
throw P = d, f;
|
|
814
|
+
}
|
|
815
|
+
D === o && (x = void 0, D = void 0), y({
|
|
816
|
+
error: void 0,
|
|
817
|
+
execution: void 0,
|
|
818
|
+
status: void 0,
|
|
819
|
+
networkFee: void 0,
|
|
820
|
+
spendable: void 0,
|
|
821
|
+
bakedAmount: void 0,
|
|
822
|
+
depositAddress: void 0,
|
|
823
|
+
depositMemo: void 0,
|
|
824
|
+
deadline: void 0,
|
|
825
|
+
depositTxHash: void 0,
|
|
826
|
+
hasSubmittedSignature: !1
|
|
827
|
+
}), w("cancelled") || (l.reset(), v({ type: "phase", phase: "idle" }));
|
|
828
|
+
} finally {
|
|
829
|
+
y({ isCancelling: !1 });
|
|
830
|
+
}
|
|
831
|
+
}, De = async (n) => {
|
|
832
|
+
Q();
|
|
833
|
+
try {
|
|
834
|
+
const { signingStandard: o } = _();
|
|
835
|
+
He(o) || u(
|
|
836
|
+
"UNSUPPORTED_SIGNING_STANDARD",
|
|
837
|
+
`this package cannot sign ${String(o)} yet — refusing to create an execution it could never complete`
|
|
838
|
+
);
|
|
839
|
+
const r = xe(n), i = await Ie(), d = await ve(
|
|
840
|
+
r,
|
|
841
|
+
Ne(r, i)
|
|
842
|
+
), f = await be(r, d);
|
|
843
|
+
x = r, D = f.id;
|
|
844
|
+
let E;
|
|
845
|
+
try {
|
|
846
|
+
E = await J(f);
|
|
847
|
+
} catch (p) {
|
|
848
|
+
if (h && Be(p))
|
|
849
|
+
try {
|
|
850
|
+
await Z(f.id);
|
|
851
|
+
} catch (T) {
|
|
852
|
+
m.warn(
|
|
853
|
+
"auto-cancel after a rejected signature failed — the execution still holds the in-flight lock",
|
|
854
|
+
T
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
throw p;
|
|
858
|
+
}
|
|
859
|
+
return E && await F(r, f), await H(f.id);
|
|
860
|
+
} catch (o) {
|
|
861
|
+
return B(o);
|
|
862
|
+
}
|
|
863
|
+
}, Oe = async () => {
|
|
864
|
+
const { execution: n } = l.context;
|
|
865
|
+
if (!x || !n)
|
|
866
|
+
throw new Error(
|
|
867
|
+
"nothing to retry — retryDeposit() applies only after run() stopped at the deposit transfer"
|
|
868
|
+
);
|
|
869
|
+
if (l.current !== "awaiting-deposit")
|
|
870
|
+
throw new Error(
|
|
871
|
+
`retryDeposit() requires the awaiting-deposit phase (current: ${l.current})`
|
|
872
|
+
);
|
|
873
|
+
y({ error: void 0 });
|
|
874
|
+
try {
|
|
875
|
+
return await F(x, n), await H(n.id);
|
|
876
|
+
} catch (o) {
|
|
877
|
+
return B(o);
|
|
878
|
+
}
|
|
879
|
+
}, Ce = (n) => {
|
|
880
|
+
if (g !== void 0 || _().makeTransfer !== void 0)
|
|
881
|
+
return !0;
|
|
882
|
+
const o = W(n);
|
|
883
|
+
return !!(o && a?.[o]);
|
|
884
|
+
}, Re = (n, o) => {
|
|
885
|
+
if (o?.depositViaWallet === !1)
|
|
886
|
+
return;
|
|
887
|
+
const { originAsset: r } = n.quote, i = r ? Qe(r) : void 0;
|
|
888
|
+
if (!i)
|
|
889
|
+
return;
|
|
890
|
+
const d = W(i.chain);
|
|
891
|
+
if (!d)
|
|
892
|
+
return;
|
|
893
|
+
const f = o?.originToken?.decimals;
|
|
894
|
+
if (d !== "evm" && f === void 0)
|
|
895
|
+
return;
|
|
896
|
+
const E = o?.originChainId ?? (d === "evm" ? Ve[i.chain] ?? null : null);
|
|
897
|
+
if (!(d === "evm" && E === null))
|
|
898
|
+
return {
|
|
899
|
+
originChain: i.chain,
|
|
900
|
+
originToken: {
|
|
901
|
+
contractAddress: o?.originToken?.contractAddress ?? i.tokenAddress,
|
|
902
|
+
decimals: f ?? 0
|
|
903
|
+
},
|
|
904
|
+
originChainId: E,
|
|
905
|
+
depositViaWallet: !0,
|
|
906
|
+
quote: {
|
|
907
|
+
swapType: n.quote.swapType ?? "EXACT_INPUT",
|
|
908
|
+
deadline: n.quote.deadline
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
};
|
|
912
|
+
return {
|
|
913
|
+
run: De,
|
|
914
|
+
resume: async (n, o) => {
|
|
915
|
+
Q();
|
|
916
|
+
try {
|
|
917
|
+
const [r] = await t.listExecutions(S(), {
|
|
918
|
+
id: n
|
|
919
|
+
});
|
|
920
|
+
if (!r)
|
|
921
|
+
throw new Error(`no execution found for id ${n}`);
|
|
922
|
+
const { messageSigned: i, payload: d } = r.details, f = i !== !0 && !!d;
|
|
923
|
+
r.status === "CREATED" && i !== !0 && !d && X(r), y({
|
|
924
|
+
execution: r,
|
|
925
|
+
executionId: r.id,
|
|
926
|
+
status: r.status,
|
|
927
|
+
hasSubmittedSignature: !f
|
|
928
|
+
});
|
|
929
|
+
let E = r.status === "CREATED" || r.status === "DEPOSIT_PENDING" || r.status === "EXPIRED";
|
|
930
|
+
if (f && (E = await J(r)), E && r.quote.depositAddress) {
|
|
931
|
+
const p = !!x && D === r.id;
|
|
932
|
+
let T;
|
|
933
|
+
if (p && x)
|
|
934
|
+
T = x;
|
|
935
|
+
else {
|
|
936
|
+
const A = Re(r, o);
|
|
937
|
+
A && Ce(A.originChain) && (T = A);
|
|
938
|
+
}
|
|
939
|
+
T ? (x = T, D = r.id, await F(T, r)) : (_().signingStandard === "sep53" && oe(
|
|
940
|
+
"stellar",
|
|
941
|
+
r.quote.depositMemo
|
|
942
|
+
), z(r));
|
|
943
|
+
}
|
|
944
|
+
return await H(r.id);
|
|
945
|
+
} catch (r) {
|
|
946
|
+
return B(r);
|
|
947
|
+
}
|
|
948
|
+
},
|
|
949
|
+
retryDeposit: Oe,
|
|
950
|
+
cancel: Z,
|
|
951
|
+
dispose: () => {
|
|
952
|
+
V = !0;
|
|
953
|
+
},
|
|
954
|
+
getPhase: () => l.current,
|
|
955
|
+
getStore: () => l.getStore()
|
|
956
|
+
};
|
|
957
|
+
}, qt = (e) => {
|
|
958
|
+
if (e instanceof L && e.code === "EXECUTION_IN_FLIGHT" && e.meta.executionId)
|
|
959
|
+
return { kind: "resume-or-cancel", executionId: e.meta.executionId };
|
|
960
|
+
if (e instanceof Y)
|
|
961
|
+
return {
|
|
962
|
+
kind: "retry-transfer",
|
|
963
|
+
executionId: e.executionId,
|
|
964
|
+
cause: e.cause instanceof Error ? e.cause : void 0
|
|
965
|
+
};
|
|
966
|
+
};
|
|
967
|
+
export {
|
|
968
|
+
u as $,
|
|
969
|
+
ye as A,
|
|
970
|
+
Te as B,
|
|
971
|
+
Se as C,
|
|
972
|
+
_t as D,
|
|
973
|
+
U as E,
|
|
974
|
+
ue as F,
|
|
975
|
+
Gt as G,
|
|
976
|
+
tt as H,
|
|
977
|
+
I,
|
|
978
|
+
re as J,
|
|
979
|
+
et as K,
|
|
980
|
+
nt as L,
|
|
981
|
+
It as M,
|
|
982
|
+
vt as N,
|
|
983
|
+
Ve as O,
|
|
984
|
+
ze as P,
|
|
985
|
+
Ye as Q,
|
|
986
|
+
W as R,
|
|
987
|
+
Je as S,
|
|
988
|
+
Ze as T,
|
|
989
|
+
Qe as U,
|
|
990
|
+
qt as V,
|
|
991
|
+
Y as W,
|
|
992
|
+
je as X,
|
|
993
|
+
Xe as Y,
|
|
994
|
+
L as Z,
|
|
995
|
+
We as _,
|
|
996
|
+
Ke as a,
|
|
997
|
+
me as a0,
|
|
998
|
+
Ut as a1,
|
|
999
|
+
Ue as a2,
|
|
1000
|
+
ke as a3,
|
|
1001
|
+
Ge as a4,
|
|
1002
|
+
ee as a5,
|
|
1003
|
+
Ee as a6,
|
|
1004
|
+
pe as a7,
|
|
1005
|
+
qe as a8,
|
|
1006
|
+
Fe as a9,
|
|
1007
|
+
He as aa,
|
|
1008
|
+
st as b,
|
|
1009
|
+
at as c,
|
|
1010
|
+
rt as d,
|
|
1011
|
+
X as e,
|
|
1012
|
+
ot as f,
|
|
1013
|
+
ft as g,
|
|
1014
|
+
mt as h,
|
|
1015
|
+
he as i,
|
|
1016
|
+
ie as j,
|
|
1017
|
+
we as k,
|
|
1018
|
+
Tt as l,
|
|
1019
|
+
oe as m,
|
|
1020
|
+
ct as n,
|
|
1021
|
+
dt as o,
|
|
1022
|
+
ut as p,
|
|
1023
|
+
lt as q,
|
|
1024
|
+
gt as r,
|
|
1025
|
+
pt as s,
|
|
1026
|
+
St as t,
|
|
1027
|
+
M as u,
|
|
1028
|
+
kt as v,
|
|
1029
|
+
$ as w,
|
|
1030
|
+
ht as x,
|
|
1031
|
+
wt as y,
|
|
1032
|
+
yt as z
|
|
1033
|
+
};
|
|
1034
|
+
//# sourceMappingURL=recovery-BBQaAcqE.js.map
|