@cordystackx/cordy_minikit 3.1.3 → 3.1.4
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consRuntime.d.ts","sourceRoot":"","sources":["../../client/consRuntime.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"consRuntime.d.ts","sourceRoot":"","sources":["../../client/consRuntime.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAW/C;AAED,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,EAAE,IAAI,SAAiB,GAAG,MAAM,CAEnH;AAED,wBAAsB,qBAAqB,CAAC,IAAI,SAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAUnF"}
|
|
@@ -5,7 +5,9 @@ export function setConsPath(path) {
|
|
|
5
5
|
activeConsPath = DEFAULT_CONS_PATH;
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
let normalized = path.trim();
|
|
9
|
+
while (normalized.endsWith("/"))
|
|
10
|
+
normalized = normalized.slice(0, -1);
|
|
9
11
|
if (!normalized.startsWith("/") || normalized.startsWith("//") || /[?#\\]/.test(normalized)) {
|
|
10
12
|
throw new Error('ProvidersClientWrapper: "consPath" must be a same-origin path such as "/services/cons".');
|
|
11
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cctpBridge.d.ts","sourceRoot":"","sources":["../../controllers/cctpBridge.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,sBAAsB,EACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAG5D,KAAK,eAAe,GAAG,UAAU,GAAG,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"cctpBridge.d.ts","sourceRoot":"","sources":["../../controllers/cctpBridge.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,sBAAsB,EACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAG5D,KAAK,eAAe,GAAG,UAAU,GAAG,UAAU,CAAC;AAoT/C,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,sBAAsB,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAUzJ;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,eAAe,EACrB,EAAE,EAAE,eAAe,EACnB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,sBAAsB,GAC5B,OAAO,CAAC,iBAAiB,CAAC,CAgH5B"}
|
|
@@ -33,6 +33,17 @@ const MESSAGE_TRANSMITTER_ABI = [
|
|
|
33
33
|
];
|
|
34
34
|
const EMPTY_DESTINATION_CALLER = `0x${"00".repeat(32)}`;
|
|
35
35
|
const STELLAR_CCTP_RECOVERY_KEY = "cordy_minikit_stellar_cctp_recovery";
|
|
36
|
+
const STELLAR_CONFIRMATION_POLL_INTERVAL_MS = 2000;
|
|
37
|
+
const STELLAR_CONFIRMATION_MAX_POLLS = 60;
|
|
38
|
+
class StellarTransactionPendingError extends Error {
|
|
39
|
+
constructor(transactionHash, detail) {
|
|
40
|
+
super(detail
|
|
41
|
+
? `Stellar transaction ${transactionHash} was submitted, but confirmation could not be checked: ${detail}`
|
|
42
|
+
: `Stellar transaction ${transactionHash} was submitted but is still unconfirmed after ${STELLAR_CONFIRMATION_MAX_POLLS * STELLAR_CONFIRMATION_POLL_INTERVAL_MS / 1000} seconds.`);
|
|
43
|
+
this.transactionHash = transactionHash;
|
|
44
|
+
this.name = "StellarTransactionPendingError";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
36
47
|
async function getConnectedEvmProvider(connection) {
|
|
37
48
|
const connector = connection.connector;
|
|
38
49
|
if (typeof connector.getProvider === "function") {
|
|
@@ -103,11 +114,20 @@ async function submitStellarSorobanTransaction(server, contractId, method, args,
|
|
|
103
114
|
if (result.status === "ERROR")
|
|
104
115
|
throw new Error(`Stellar transaction submission failed: ${JSON.stringify(result)}`);
|
|
105
116
|
onSubmitted?.(result.hash);
|
|
106
|
-
let completed
|
|
107
|
-
|
|
108
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
117
|
+
let completed;
|
|
118
|
+
try {
|
|
109
119
|
completed = await server.getTransaction(result.hash);
|
|
120
|
+
for (let poll = 0; completed.status === "NOT_FOUND" && poll < STELLAR_CONFIRMATION_MAX_POLLS; poll += 1) {
|
|
121
|
+
await new Promise((resolve) => setTimeout(resolve, STELLAR_CONFIRMATION_POLL_INTERVAL_MS));
|
|
122
|
+
completed = await server.getTransaction(result.hash);
|
|
123
|
+
}
|
|
110
124
|
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
127
|
+
throw new StellarTransactionPendingError(result.hash, detail);
|
|
128
|
+
}
|
|
129
|
+
if (completed.status === "NOT_FOUND")
|
|
130
|
+
throw new StellarTransactionPendingError(result.hash);
|
|
111
131
|
if (completed.status !== "SUCCESS")
|
|
112
132
|
throw new Error(`Stellar transaction failed: ${JSON.stringify(completed)}`);
|
|
113
133
|
return result.hash;
|
|
@@ -192,29 +212,56 @@ async function bridgeStellarToEvm(amount, from, to, recipient, route) {
|
|
|
192
212
|
const amountIn = parseUnits(amount, 7);
|
|
193
213
|
const owner = new Address(sourceAddress).toScVal();
|
|
194
214
|
const messenger = new Address(source.tokenMessengerMinter).toScVal();
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
215
|
+
let approveHash;
|
|
216
|
+
try {
|
|
217
|
+
approveHash = await submitStellarSorobanTransaction(server, source.tokenAddress, "approve", [
|
|
218
|
+
owner,
|
|
219
|
+
messenger,
|
|
220
|
+
nativeToScVal(amountIn, { type: "i128" }),
|
|
221
|
+
nativeToScVal(latestLedger.sequence + 100000, { type: "u32" }),
|
|
222
|
+
], networkPassphrase, sourceAddress);
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
if (error instanceof StellarTransactionPendingError) {
|
|
226
|
+
return { success: false, asset: source.assetSymbol, from, to, routeId: route.id, routeName: route.name, amount, status: "pending", transactionHash: error.transactionHash, error: error.message, errorDetail: error.message };
|
|
227
|
+
}
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
201
230
|
const recoveryForBurn = (burnTransactionHash) => ({ burnTransactionHash, from, to, routeId: route.id, routeName: route.name, amount, recipient, asset: source.assetSymbol, fromNetwork: source.networkName, toNetwork: destination.networkName });
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
231
|
+
let burnHash;
|
|
232
|
+
try {
|
|
233
|
+
burnHash = await submitStellarSorobanTransaction(server, source.tokenMessengerMinter, "deposit_for_burn", [
|
|
234
|
+
owner,
|
|
235
|
+
nativeToScVal(amountIn, { type: "i128" }),
|
|
236
|
+
nativeToScVal(destination.domain, { type: "u32" }),
|
|
237
|
+
evmAddressBytes32(recipient),
|
|
238
|
+
new Address(source.tokenAddress).toScVal(),
|
|
239
|
+
xdr.ScVal.scvBytes(Buffer.alloc(32)),
|
|
240
|
+
nativeToScVal(0n, { type: "i128" }),
|
|
241
|
+
nativeToScVal(2000, { type: "u32" }),
|
|
242
|
+
], networkPassphrase, sourceAddress, (hash) => {
|
|
243
|
+
try {
|
|
244
|
+
window.localStorage.setItem(STELLAR_CCTP_RECOVERY_KEY, JSON.stringify(recoveryForBurn(hash)));
|
|
245
|
+
}
|
|
246
|
+
catch { /* Recovery storage may be unavailable in restricted browsers. */ }
|
|
247
|
+
window.dispatchEvent(new CustomEvent("cordy:stellar-cctp-burn-submitted", { detail: { transactionHash: hash } }));
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
if (error instanceof StellarTransactionPendingError) {
|
|
252
|
+
const recovery = recoveryForBurn(error.transactionHash);
|
|
253
|
+
try {
|
|
254
|
+
window.localStorage.setItem(STELLAR_CCTP_RECOVERY_KEY, JSON.stringify(recovery));
|
|
255
|
+
}
|
|
256
|
+
catch { /* Recovery storage may be unavailable in restricted browsers. */ }
|
|
257
|
+
return { success: false, ...recovery, status: "pending", transactionHash: error.transactionHash, error: error.message, errorDetail: error.message };
|
|
258
|
+
}
|
|
212
259
|
try {
|
|
213
|
-
window.localStorage.
|
|
260
|
+
window.localStorage.removeItem(STELLAR_CCTP_RECOVERY_KEY);
|
|
214
261
|
}
|
|
215
|
-
catch { /*
|
|
216
|
-
|
|
217
|
-
}
|
|
262
|
+
catch { /* Ignore storage cleanup failures. */ }
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
218
265
|
const recovery = recoveryForBurn(burnHash);
|
|
219
266
|
try {
|
|
220
267
|
window.localStorage.setItem(STELLAR_CCTP_RECOVERY_KEY, JSON.stringify(recovery));
|