@piprail/sdk 2.13.1 → 2.14.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/CHANGELOG.md +70 -0
- package/dist/{algorand-TQCYK2XT.js → algorand-6J3IABVF.js} +12 -11
- package/dist/{algorand-AQK5EAUF.cjs → algorand-QU6G2DQZ.cjs} +43 -42
- package/dist/{aptos-RYQOSFBQ.js → aptos-DHOMTBLZ.js} +11 -10
- package/dist/{aptos-65UX7GKA.cjs → aptos-LFTQGBBK.cjs} +41 -40
- package/dist/{chunk-DCOUJZPL.cjs → chunk-GYM46G5L.cjs} +16 -0
- package/dist/{chunk-O32N6MFN.js → chunk-PAMKCWVW.js} +16 -0
- package/dist/index.cjs +484 -231
- package/dist/index.d.cts +270 -7
- package/dist/index.d.ts +270 -7
- package/dist/index.js +280 -27
- package/dist/{ledger-mF_SoiDB.d.ts → ledger-uFtXlIHY.d.cts} +31 -1
- package/dist/{ledger-mF_SoiDB.d.cts → ledger-uFtXlIHY.d.ts} +31 -1
- package/dist/{near-VDATC5AV.js → near-5PXTVQ47.js} +14 -5
- package/dist/{near-UDPFA6SV.cjs → near-YNNK7RW7.cjs} +39 -30
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/{solana-VYLWFNAH.js → solana-HITVI3HF.js} +22 -7
- package/dist/{solana-RQNXFCZO.cjs → solana-N3UCNCYE.cjs} +54 -39
- package/dist/{stellar-KBR4V77T.js → stellar-2QT6YYKN.js} +4 -4
- package/dist/{stellar-OK2HW5PZ.cjs → stellar-Y3SQN7S5.cjs} +23 -23
- package/dist/{sui-SVFBJFW5.cjs → sui-4AL4E6XU.cjs} +35 -27
- package/dist/{sui-BXHB6D3W.js → sui-FV5L6WF5.js} +20 -12
- package/dist/{ton-NNKQFQ6U.js → ton-5FWDQ4QR.js} +18 -7
- package/dist/{ton-D7YN6BGR.cjs → ton-5HDVOTMR.cjs} +33 -22
- package/dist/{tron-W2D5PQXV.js → tron-AZDY7BMQ.js} +10 -10
- package/dist/{tron-WZFU57NX.cjs → tron-TX2B4N2A.cjs} +39 -39
- package/dist/{xrpl-5NHY3NEL.cjs → xrpl-5TYDLQFS.cjs} +31 -31
- package/dist/{xrpl-37E23W53.js → xrpl-UJL5J7CY.js} +13 -13
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkGYM46G5Lcjs = require('./chunk-GYM46G5L.cjs');
|
|
12
12
|
|
|
13
13
|
// src/drivers/solana/index.ts
|
|
14
14
|
var _web3js = require('@solana/web3.js');
|
|
@@ -17,6 +17,7 @@ var _web3js = require('@solana/web3.js');
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
+
|
|
20
21
|
var _spltoken = require('@solana/spl-token');
|
|
21
22
|
|
|
22
23
|
// src/drivers/solana/chains.ts
|
|
@@ -126,15 +127,15 @@ async function verifySolana(params) {
|
|
|
126
127
|
detail: `Transaction ${signature} failed on-chain.`
|
|
127
128
|
};
|
|
128
129
|
}
|
|
129
|
-
if (
|
|
130
|
+
if (!Number.isFinite(tx.blockTime)) {
|
|
130
131
|
return {
|
|
131
132
|
ok: false,
|
|
132
133
|
error: "payment_expired",
|
|
133
|
-
detail: `Cannot determine the age of ${signature} (no blockTime).`
|
|
134
|
+
detail: `Cannot determine the age of ${signature} (no/invalid blockTime).`
|
|
134
135
|
};
|
|
135
136
|
}
|
|
136
137
|
const ageSeconds = Math.floor(Date.now() / 1e3) - tx.blockTime;
|
|
137
|
-
if (ageSeconds > accept.maxTimeoutSeconds) {
|
|
138
|
+
if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
|
|
138
139
|
return {
|
|
139
140
|
ok: false,
|
|
140
141
|
error: "payment_expired",
|
|
@@ -236,7 +237,7 @@ function isEmptySig(sig) {
|
|
|
236
237
|
function memoRandomNonce() {
|
|
237
238
|
const g = globalThis.crypto;
|
|
238
239
|
if (!_optionalChain([g, 'optionalAccess', _3 => _3.getRandomValues])) {
|
|
239
|
-
throw new (0,
|
|
240
|
+
throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
|
|
240
241
|
"this runtime lacks Web Crypto (globalThis.crypto.getRandomValues); SVM exact needs a CSPRNG nonce."
|
|
241
242
|
);
|
|
242
243
|
}
|
|
@@ -248,7 +249,7 @@ function memoDataFor(accept) {
|
|
|
248
249
|
if (accept.extra.memo !== void 0) {
|
|
249
250
|
const bytes = Buffer.from(accept.extra.memo, "utf8");
|
|
250
251
|
if (bytes.length > MAX_MEMO_BYTES) {
|
|
251
|
-
throw new (0,
|
|
252
|
+
throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
|
|
252
253
|
`SVM exact: extra.memo is ${bytes.length} bytes; the scheme caps it at ${MAX_MEMO_BYTES}.`
|
|
253
254
|
);
|
|
254
255
|
}
|
|
@@ -262,15 +263,15 @@ function memoInstruction(accept) {
|
|
|
262
263
|
async function payExactSolana(input) {
|
|
263
264
|
const { connection, keypair, accept } = input;
|
|
264
265
|
if (accept.asset === "native") {
|
|
265
|
-
throw new (0,
|
|
266
|
+
throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
|
|
266
267
|
"SVM exact is SPL-token only (TransferChecked); native SOL is not exact-payable. Pay via onchain-proof."
|
|
267
268
|
);
|
|
268
269
|
}
|
|
269
270
|
if (!accept.extra.feePayer) {
|
|
270
|
-
throw new (0,
|
|
271
|
+
throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)("SVM exact rail must advertise extra.feePayer (the merchant sponsor key).");
|
|
271
272
|
}
|
|
272
273
|
if (accept.extra.decimals === void 0) {
|
|
273
|
-
throw new (0,
|
|
274
|
+
throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)("SVM exact rail must advertise extra.decimals for the TransferChecked.");
|
|
274
275
|
}
|
|
275
276
|
let feePayer;
|
|
276
277
|
let mint;
|
|
@@ -280,12 +281,12 @@ async function payExactSolana(input) {
|
|
|
280
281
|
mint = new (0, _web3js.PublicKey)(accept.asset);
|
|
281
282
|
payTo = new (0, _web3js.PublicKey)(accept.payTo);
|
|
282
283
|
} catch (err) {
|
|
283
|
-
throw new (0,
|
|
284
|
+
throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
|
|
284
285
|
`SVM exact: bad feePayer/asset/payTo (${err instanceof Error ? err.message : String(err)}).`
|
|
285
286
|
);
|
|
286
287
|
}
|
|
287
288
|
if (feePayer.equals(payTo)) {
|
|
288
|
-
throw new (0,
|
|
289
|
+
throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
|
|
289
290
|
"SVM exact: the fee payer must differ from payTo \u2014 payTo appears in the transfer instruction, which the fee payer must not (a scheme MUST-rule). Use a separate relayer key for the gate."
|
|
290
291
|
);
|
|
291
292
|
}
|
|
@@ -299,7 +300,7 @@ async function payExactSolana(input) {
|
|
|
299
300
|
destInfo = "unknown";
|
|
300
301
|
}
|
|
301
302
|
if (destInfo === null) {
|
|
302
|
-
throw new (0,
|
|
303
|
+
throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
|
|
303
304
|
`SVM exact: the recipient's token account for ${mint.toBase58()} doesn't exist yet \u2014 the exact rail can't create it. Pay via onchain-proof (which creates it), or have ${payTo.toBase58()} create its associated token account first.`
|
|
304
305
|
);
|
|
305
306
|
}
|
|
@@ -330,11 +331,11 @@ async function payExactSolana(input) {
|
|
|
330
331
|
tx.sign([keypair]);
|
|
331
332
|
const buyerIndex = message.staticAccountKeys.findIndex((k) => k.equals(keypair.publicKey));
|
|
332
333
|
if (buyerIndex < 1 || buyerIndex >= message.header.numRequiredSignatures) {
|
|
333
|
-
throw new (0,
|
|
334
|
+
throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)("SVM exact: could not locate the buyer signer slot.");
|
|
334
335
|
}
|
|
335
336
|
const buyerSig = tx.signatures[buyerIndex];
|
|
336
337
|
if (!buyerSig || isEmptySig(buyerSig)) {
|
|
337
|
-
throw new (0,
|
|
338
|
+
throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)("SVM exact: the wallet did not produce a buyer signature.");
|
|
338
339
|
}
|
|
339
340
|
const transaction = Buffer.from(tx.serialize()).toString("base64");
|
|
340
341
|
return {
|
|
@@ -361,15 +362,15 @@ async function verifyAndSettleExactSolana(input) {
|
|
|
361
362
|
if (!accept.extra.feePayer) throw new Error("rail is missing extra.feePayer");
|
|
362
363
|
railFeePayer = new (0, _web3js.PublicKey)(accept.extra.feePayer);
|
|
363
364
|
} catch (err) {
|
|
364
|
-
throw new (0,
|
|
365
|
+
throw new (0, _chunkGYM46G5Lcjs.SettlementError)(`SVM exact: rail has a bad payTo/asset/feePayer (${err instanceof Error ? err.message : String(err)}).`);
|
|
365
366
|
}
|
|
366
367
|
if (!railFeePayer.equals(feePayerKeypair.publicKey)) {
|
|
367
|
-
throw new (0,
|
|
368
|
+
throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
|
|
368
369
|
"SVM exact: the gate relayer key does not match the rail extra.feePayer \u2014 misconfigured rail."
|
|
369
370
|
);
|
|
370
371
|
}
|
|
371
372
|
if (feePayerKeypair.publicKey.equals(payTo)) {
|
|
372
|
-
throw new (0,
|
|
373
|
+
throw new (0, _chunkGYM46G5Lcjs.SettlementError)("SVM exact: the fee payer must differ from payTo \u2014 misconfigured rail.");
|
|
373
374
|
}
|
|
374
375
|
const program = tokenProgramFor(accept);
|
|
375
376
|
let tx;
|
|
@@ -429,6 +430,8 @@ async function verifyAndSettleExactSolana(input) {
|
|
|
429
430
|
if (price > MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS) {
|
|
430
431
|
return fail("signature_invalid", `Compute-unit price ${price} \xB5lamports exceeds the ${MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS} cap (fee-payer drain guard).`);
|
|
431
432
|
}
|
|
433
|
+
} else {
|
|
434
|
+
return fail("signature_invalid", `Unexpected ComputeBudget instruction (discriminator ${data[0]}) \u2014 only set-unit-limit/price are allowed (fee-payer drain guard).`);
|
|
432
435
|
}
|
|
433
436
|
}
|
|
434
437
|
const isSignedSigner = (pubkey) => {
|
|
@@ -509,7 +512,7 @@ async function verifyAndSettleExactSolana(input) {
|
|
|
509
512
|
} catch (err) {
|
|
510
513
|
const msg = err instanceof Error ? err.message : String(err);
|
|
511
514
|
if (/blockhash|block height|expired/i.test(msg)) return fail("payment_expired", `Settle broadcast rejected \u2014 blockhash expired: ${shorten(msg)}.`);
|
|
512
|
-
throw new (0,
|
|
515
|
+
throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
|
|
513
516
|
`SVM exact settle: the merchant fee payer failed to broadcast (${shorten(msg)}). The buyer's signed transaction is still valid \u2014 fund/fix the fee payer and the buyer can re-present it.`,
|
|
514
517
|
{ cause: err }
|
|
515
518
|
);
|
|
@@ -519,7 +522,7 @@ async function verifyAndSettleExactSolana(input) {
|
|
|
519
522
|
return fail("tx_reverted", `Settle tx ${txid} reverted on-chain (a post-simulate race).`);
|
|
520
523
|
}
|
|
521
524
|
if (confirmed === "timeout") {
|
|
522
|
-
throw new (0,
|
|
525
|
+
throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
|
|
523
526
|
`SVM exact settle: broadcast ${txid} but it did not confirm in time. It likely landed \u2014 re-verify by signature before re-presenting; do NOT re-pay.`
|
|
524
527
|
);
|
|
525
528
|
}
|
|
@@ -562,18 +565,18 @@ async function pollConfirmed(connection, signature) {
|
|
|
562
565
|
|
|
563
566
|
function toKeypair(wallet, network) {
|
|
564
567
|
if (typeof wallet !== "object" || wallet === null) {
|
|
565
|
-
throw new (0,
|
|
568
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
566
569
|
`chain ${network} is Solana; wallet must be { key } (base58 secret) or { signer }.`
|
|
567
570
|
);
|
|
568
571
|
}
|
|
569
|
-
|
|
572
|
+
_chunkGYM46G5Lcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Solana");
|
|
570
573
|
if ("signer" in wallet) {
|
|
571
574
|
return wallet.signer;
|
|
572
575
|
}
|
|
573
576
|
if ("key" in wallet) {
|
|
574
577
|
const sk = wallet.key;
|
|
575
578
|
if (typeof sk === "string" && sk.startsWith("0x")) {
|
|
576
|
-
throw new (0,
|
|
579
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
577
580
|
`chain ${network} is Solana, but the wallet { key } is a 0x\u2026 hex key \u2014 that's an EVM key. A Solana key is a base58 secret string (or a 64-byte Uint8Array).`
|
|
578
581
|
);
|
|
579
582
|
}
|
|
@@ -581,12 +584,12 @@ function toKeypair(wallet, network) {
|
|
|
581
584
|
const bytes = typeof sk === "string" ? _bs582.default.decode(sk) : sk;
|
|
582
585
|
return _web3js.Keypair.fromSecretKey(bytes);
|
|
583
586
|
} catch (err) {
|
|
584
|
-
throw new (0,
|
|
587
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
585
588
|
`chain ${network} is Solana; the wallet { key } isn't a valid Solana secret (expected a base58 secret string or a 64-byte Uint8Array): ${err instanceof Error ? err.message : String(err)}.`
|
|
586
589
|
);
|
|
587
590
|
}
|
|
588
591
|
}
|
|
589
|
-
throw new (0,
|
|
592
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
590
593
|
`chain ${network} is Solana; wallet must be { key } (base58 secret) or { signer }.`
|
|
591
594
|
);
|
|
592
595
|
}
|
|
@@ -615,15 +618,15 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
615
618
|
const info = preset.tokens[token.toUpperCase()];
|
|
616
619
|
if (!info) {
|
|
617
620
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
618
|
-
throw new (0,
|
|
621
|
+
throw new (0, _chunkGYM46G5Lcjs.UnknownTokenError)(
|
|
619
622
|
`token "${token}" isn't built in for Solana (known: ${known}). Pass { mint, decimals } instead, or use 'native'.`
|
|
620
623
|
);
|
|
621
624
|
}
|
|
622
625
|
return { asset: info.mint, decimals: info.decimals, symbol: info.symbol };
|
|
623
626
|
}
|
|
624
|
-
|
|
627
|
+
_chunkGYM46G5Lcjs.rejectForeignToken.call(void 0, token, "solana", network);
|
|
625
628
|
if (!("mint" in token)) {
|
|
626
|
-
throw new (0,
|
|
629
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
627
630
|
`chain ${network} is Solana; a custom token must be { mint, decimals }.`
|
|
628
631
|
);
|
|
629
632
|
}
|
|
@@ -642,14 +645,14 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
642
645
|
},
|
|
643
646
|
assertValidPayTo(payTo) {
|
|
644
647
|
if (payTo.startsWith("0x")) {
|
|
645
|
-
throw new (0,
|
|
648
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
646
649
|
`chain ${network} is Solana, but payTo "${payTo}" looks like an EVM address.`
|
|
647
650
|
);
|
|
648
651
|
}
|
|
649
652
|
try {
|
|
650
653
|
new (0, _web3js.PublicKey)(payTo);
|
|
651
654
|
} catch (e7) {
|
|
652
|
-
throw new (0,
|
|
655
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
653
656
|
`chain ${network} is Solana, but payTo "${payTo}" is not a base58 address.`
|
|
654
657
|
);
|
|
655
658
|
}
|
|
@@ -661,7 +664,7 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
661
664
|
try {
|
|
662
665
|
return await paySolana({ connection, keypair: wallet._native, accept });
|
|
663
666
|
} catch (err) {
|
|
664
|
-
throw _nullishCoalesce(
|
|
667
|
+
throw _nullishCoalesce(_chunkGYM46G5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
665
668
|
}
|
|
666
669
|
},
|
|
667
670
|
async confirm(ref) {
|
|
@@ -672,19 +675,19 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
672
675
|
});
|
|
673
676
|
info = value[0];
|
|
674
677
|
} catch (err) {
|
|
675
|
-
throw new (0,
|
|
678
|
+
throw new (0, _chunkGYM46G5Lcjs.ConfirmationTimeoutError)(
|
|
676
679
|
`Solana payment ${ref} could not be confirmed (RPC read failed).`,
|
|
677
680
|
{ cause: err }
|
|
678
681
|
);
|
|
679
682
|
}
|
|
680
683
|
if (!info || info.err || info.confirmationStatus !== "confirmed" && info.confirmationStatus !== "finalized") {
|
|
681
|
-
throw new (0,
|
|
684
|
+
throw new (0, _chunkGYM46G5Lcjs.ConfirmationTimeoutError)(`Solana payment ${ref} did not confirm in time.`);
|
|
682
685
|
}
|
|
683
686
|
return { height: String(info.slot) };
|
|
684
687
|
},
|
|
685
688
|
async estimateCost(accept) {
|
|
686
689
|
if (accept.scheme === "exact") {
|
|
687
|
-
return
|
|
690
|
+
return _chunkGYM46G5Lcjs.nativeCost.call(void 0, {
|
|
688
691
|
symbol: "SOL",
|
|
689
692
|
decimals: SOL_DECIMALS,
|
|
690
693
|
fee: 0n,
|
|
@@ -694,7 +697,7 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
694
697
|
}
|
|
695
698
|
const base = 5000n;
|
|
696
699
|
if (accept.asset === "native") {
|
|
697
|
-
return
|
|
700
|
+
return _chunkGYM46G5Lcjs.nativeCost.call(void 0, {
|
|
698
701
|
symbol: "SOL",
|
|
699
702
|
decimals: SOL_DECIMALS,
|
|
700
703
|
fee: base,
|
|
@@ -703,7 +706,7 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
703
706
|
});
|
|
704
707
|
}
|
|
705
708
|
const ataRent = 2039280n;
|
|
706
|
-
return
|
|
709
|
+
return _chunkGYM46G5Lcjs.nativeCost.call(void 0, {
|
|
707
710
|
symbol: "SOL",
|
|
708
711
|
decimals: SOL_DECIMALS,
|
|
709
712
|
fee: base + ataRent,
|
|
@@ -717,14 +720,26 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
717
720
|
if (asset === "native") return { token: native, native };
|
|
718
721
|
let token;
|
|
719
722
|
try {
|
|
720
|
-
const
|
|
721
|
-
|
|
723
|
+
const mint = new (0, _web3js.PublicKey)(asset);
|
|
724
|
+
const info = await connection.getAccountInfo(mint);
|
|
725
|
+
const programId = _optionalChain([info, 'optionalAccess', _8 => _8.owner, 'access', _9 => _9.equals, 'call', _10 => _10(_spltoken.TOKEN_2022_PROGRAM_ID)]) ? _spltoken.TOKEN_2022_PROGRAM_ID : _spltoken.TOKEN_PROGRAM_ID;
|
|
726
|
+
const ata = _spltoken.getAssociatedTokenAddressSync.call(void 0, mint, owner, false, programId);
|
|
727
|
+
token = (await _spltoken.getAccount.call(void 0, connection, ata, "confirmed", programId)).amount;
|
|
722
728
|
} catch (e) {
|
|
723
729
|
token = e instanceof _spltoken.TokenAccountNotFoundError ? 0n : null;
|
|
724
730
|
}
|
|
725
731
|
return { token, native };
|
|
726
732
|
},
|
|
727
|
-
// No receive prerequisite
|
|
733
|
+
// No receive prerequisite for the DEFAULT onchain-proof rail — the payer's tx idempotently
|
|
734
|
+
// creates the recipient's ATA (pay.ts). KNOWN LIMITATION (documented, not a bug): on the opt-in
|
|
735
|
+
// `exact` rail the buyer cannot create the ATA (payExactSolana throws if payTo's token account
|
|
736
|
+
// is missing), so `planPayment`/`canAfford` can be OPTIMISTIC for an exact payment to a
|
|
737
|
+
// brand-new recipient whose ATA doesn't yet exist — marked payable, and `autoRoute` would pick
|
|
738
|
+
// it then refuse (pre-broadcast, recoverable) at pay time. Mitigations in practice: onchain-proof
|
|
739
|
+
// is always co-offered (and DOES create the ATA), `exact` + `autoRoute` are both off by default,
|
|
740
|
+
// and most merchant receive accounts already exist. 'n/a' is correct for onchain-proof; an
|
|
741
|
+
// exact-aware probe needs the token-program-correct ATA derivation (an extra mint-owner read)
|
|
742
|
+
// and is deferred as disproportionate to this opt-in edge.
|
|
728
743
|
async recipientReady() {
|
|
729
744
|
return { ready: "n/a" };
|
|
730
745
|
},
|
|
@@ -771,7 +786,7 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
771
786
|
let tokenProgram = "spl-token";
|
|
772
787
|
try {
|
|
773
788
|
const info = await connection.getAccountInfo(new (0, _web3js.PublicKey)(asset));
|
|
774
|
-
if (_optionalChain([info, 'optionalAccess',
|
|
789
|
+
if (_optionalChain([info, 'optionalAccess', _11 => _11.owner, 'access', _12 => _12.equals, 'call', _13 => _13(_spltoken.TOKEN_2022_PROGRAM_ID)])) tokenProgram = "token-2022";
|
|
775
790
|
} catch (e9) {
|
|
776
791
|
}
|
|
777
792
|
return { method: "svm", extra: { feePayer: fp, tokenProgram } };
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
parseUnits,
|
|
13
13
|
rejectForeignToken,
|
|
14
14
|
toInsufficientFundsError
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-PAMKCWVW.js";
|
|
16
16
|
|
|
17
17
|
// src/drivers/stellar/index.ts
|
|
18
18
|
import { Horizon, StrKey as StrKey2 } from "@stellar/stellar-sdk";
|
|
@@ -147,7 +147,7 @@ async function verifyStellar(params) {
|
|
|
147
147
|
const wantAsset = parseStellarAssetId(accept.asset);
|
|
148
148
|
let txs;
|
|
149
149
|
try {
|
|
150
|
-
txs = await reader.transactionsForAccount(accept.payTo,
|
|
150
|
+
txs = await reader.transactionsForAccount(accept.payTo, 200);
|
|
151
151
|
} catch {
|
|
152
152
|
return rpcFailed(nonce);
|
|
153
153
|
}
|
|
@@ -163,11 +163,11 @@ async function verifyStellar(params) {
|
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
165
|
const ageSeconds = Math.floor(Date.now() / 1e3) - Math.floor(Date.parse(tx.created_at) / 1e3);
|
|
166
|
-
if (Number.isFinite(ageSeconds)
|
|
166
|
+
if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
|
|
167
167
|
return {
|
|
168
168
|
ok: false,
|
|
169
169
|
error: "payment_expired",
|
|
170
|
-
detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
|
|
170
|
+
detail: Number.isFinite(ageSeconds) ? `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.` : `Cannot determine the age of ${tx.hash} (unparseable created_at "${tx.created_at}") \u2014 fail closed.`
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
173
|
let payments;
|
|
@@ -12,7 +12,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkGYM46G5Lcjs = require('./chunk-GYM46G5L.cjs');
|
|
16
16
|
|
|
17
17
|
// src/drivers/stellar/index.ts
|
|
18
18
|
var _stellarsdk = require('@stellar/stellar-sdk');
|
|
@@ -98,30 +98,30 @@ function mapSubmitError(err) {
|
|
|
98
98
|
const seen = codes.join(", ");
|
|
99
99
|
const has = (re) => codes.some((c) => re.test(c));
|
|
100
100
|
if (has(/op_no_destination/i)) {
|
|
101
|
-
return new (0,
|
|
101
|
+
return new (0, _chunkGYM46G5Lcjs.RecipientNotReadyError)(
|
|
102
102
|
`Stellar destination account doesn't exist yet \u2014 create it with \u22651 XLM (the base reserve) before it can receive. (Stellar: ${seen})`,
|
|
103
103
|
{ cause: err }
|
|
104
104
|
);
|
|
105
105
|
}
|
|
106
106
|
if (has(/op_(no_trust|line_full|not_authorized)/i) && !has(/src_no_trust/i)) {
|
|
107
|
-
return new (0,
|
|
107
|
+
return new (0, _chunkGYM46G5Lcjs.RecipientNotReadyError)(
|
|
108
108
|
`Stellar destination can't hold this asset \u2014 it needs a trustline for it (and to be authorized) before it can receive. (Stellar: ${seen})`,
|
|
109
109
|
{ cause: err }
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
112
|
if (has(/underfunded|insufficient|low_reserve|src_no_trust/i)) {
|
|
113
|
-
return new (0,
|
|
113
|
+
return new (0, _chunkGYM46G5Lcjs.InsufficientFundsError)(
|
|
114
114
|
`Stellar payment failed: the sender can't cover it \u2014 balance, base reserve, or no trustline to send this asset. (Stellar: ${seen})`,
|
|
115
115
|
{ cause: err }
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
if (isAccountNotFound(err)) {
|
|
119
|
-
return new (0,
|
|
119
|
+
return new (0, _chunkGYM46G5Lcjs.InsufficientFundsError)(
|
|
120
120
|
"Stellar source account not found on-chain \u2014 fund the sender (\u2265 base reserve) before it can pay.",
|
|
121
121
|
{ cause: err }
|
|
122
122
|
);
|
|
123
123
|
}
|
|
124
|
-
return _nullishCoalesce(
|
|
124
|
+
return _nullishCoalesce(_chunkGYM46G5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
125
125
|
}
|
|
126
126
|
function isAccountNotFound(err) {
|
|
127
127
|
const e = err;
|
|
@@ -147,7 +147,7 @@ async function verifyStellar(params) {
|
|
|
147
147
|
const wantAsset = parseStellarAssetId(accept.asset);
|
|
148
148
|
let txs;
|
|
149
149
|
try {
|
|
150
|
-
txs = await reader.transactionsForAccount(accept.payTo,
|
|
150
|
+
txs = await reader.transactionsForAccount(accept.payTo, 200);
|
|
151
151
|
} catch (e2) {
|
|
152
152
|
return rpcFailed(nonce);
|
|
153
153
|
}
|
|
@@ -163,11 +163,11 @@ async function verifyStellar(params) {
|
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
165
|
const ageSeconds = Math.floor(Date.now() / 1e3) - Math.floor(Date.parse(tx.created_at) / 1e3);
|
|
166
|
-
if (Number.isFinite(ageSeconds)
|
|
166
|
+
if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
|
|
167
167
|
return {
|
|
168
168
|
ok: false,
|
|
169
169
|
error: "payment_expired",
|
|
170
|
-
detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
|
|
170
|
+
detail: Number.isFinite(ageSeconds) ? `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.` : `Cannot determine the age of ${tx.hash} (unparseable created_at "${tx.created_at}") \u2014 fail closed.`
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
173
|
let payments;
|
|
@@ -218,7 +218,7 @@ function assetMatches(p, want) {
|
|
|
218
218
|
}
|
|
219
219
|
function parseAmount(amount, decimals) {
|
|
220
220
|
try {
|
|
221
|
-
return
|
|
221
|
+
return _chunkGYM46G5Lcjs.parseUnits.call(void 0, amount, decimals);
|
|
222
222
|
} catch (e4) {
|
|
223
223
|
return 0n;
|
|
224
224
|
}
|
|
@@ -242,13 +242,13 @@ function rpcFailed(nonce) {
|
|
|
242
242
|
|
|
243
243
|
function assertStellarWallet(wallet, network) {
|
|
244
244
|
if (typeof wallet !== "object" || wallet === null) {
|
|
245
|
-
throw new (0,
|
|
245
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
246
246
|
`chain ${network} is Stellar; wallet must be { key } (S\u2026 seed) or { keypair }.`
|
|
247
247
|
);
|
|
248
248
|
}
|
|
249
|
-
|
|
249
|
+
_chunkGYM46G5Lcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Stellar");
|
|
250
250
|
if (!("key" in wallet) && !("keypair" in wallet)) {
|
|
251
|
-
throw new (0,
|
|
251
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
252
252
|
`chain ${network} is Stellar; wallet must be { key } (S\u2026 seed) or { keypair }.`
|
|
253
253
|
);
|
|
254
254
|
}
|
|
@@ -258,11 +258,11 @@ function resolveStellarWallet(config) {
|
|
|
258
258
|
if (config.keypair) return config.keypair;
|
|
259
259
|
if (config.key) {
|
|
260
260
|
if (!_stellarsdk.StrKey.isValidEd25519SecretSeed(config.key)) {
|
|
261
|
-
throw new (0,
|
|
261
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)("Stellar wallet { key } is not a valid S\u2026 secret seed.");
|
|
262
262
|
}
|
|
263
263
|
return _stellarsdk.Keypair.fromSecret(config.key);
|
|
264
264
|
}
|
|
265
|
-
throw new (0,
|
|
265
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)("Stellar wallet needs { key } (S\u2026 seed) or { keypair }.");
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
// src/drivers/stellar/index.ts
|
|
@@ -317,7 +317,7 @@ function makeStellarNetwork(preset, rpcUrl) {
|
|
|
317
317
|
const info = preset.tokens[token.toUpperCase()];
|
|
318
318
|
if (!info) {
|
|
319
319
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
320
|
-
throw new (0,
|
|
320
|
+
throw new (0, _chunkGYM46G5Lcjs.UnknownTokenError)(
|
|
321
321
|
`token "${token}" isn't built in for Stellar (known: ${known}). Pass { issuer, code, decimals } for a custom asset, or use 'native'.`
|
|
322
322
|
);
|
|
323
323
|
}
|
|
@@ -327,10 +327,10 @@ function makeStellarNetwork(preset, rpcUrl) {
|
|
|
327
327
|
symbol: info.symbol
|
|
328
328
|
};
|
|
329
329
|
}
|
|
330
|
-
|
|
330
|
+
_chunkGYM46G5Lcjs.rejectForeignToken.call(void 0, token, "stellar", network);
|
|
331
331
|
const t = token;
|
|
332
332
|
if (!t.issuer || !t.code || typeof t.decimals !== "number") {
|
|
333
|
-
throw new (0,
|
|
333
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
334
334
|
`chain ${network} is Stellar; a custom token must be { issuer, code, decimals }.`
|
|
335
335
|
);
|
|
336
336
|
}
|
|
@@ -351,12 +351,12 @@ function makeStellarNetwork(preset, rpcUrl) {
|
|
|
351
351
|
},
|
|
352
352
|
assertValidPayTo(payTo) {
|
|
353
353
|
if (payTo.startsWith("0x")) {
|
|
354
|
-
throw new (0,
|
|
354
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
355
355
|
`chain ${network} is Stellar, but payTo "${payTo}" looks like an EVM address.`
|
|
356
356
|
);
|
|
357
357
|
}
|
|
358
358
|
if (!_stellarsdk.StrKey.isValidEd25519PublicKey(payTo)) {
|
|
359
|
-
throw new (0,
|
|
359
|
+
throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
|
|
360
360
|
`chain ${network} is Stellar, but payTo "${payTo}" is not a valid Stellar account (G\u2026).`
|
|
361
361
|
);
|
|
362
362
|
}
|
|
@@ -377,10 +377,10 @@ function makeStellarNetwork(preset, rpcUrl) {
|
|
|
377
377
|
await _chunkCQREG5LEcjs.delay.call(void 0, 1500);
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
|
-
throw new (0,
|
|
380
|
+
throw new (0, _chunkGYM46G5Lcjs.ConfirmationTimeoutError)(`Stellar tx ${ref} not visible on Horizon in time.`);
|
|
381
381
|
},
|
|
382
382
|
async estimateCost() {
|
|
383
|
-
return
|
|
383
|
+
return _chunkGYM46G5Lcjs.nativeCost.call(void 0, {
|
|
384
384
|
symbol: XLM_SYMBOL,
|
|
385
385
|
decimals: STELLAR_DECIMALS,
|
|
386
386
|
fee: 100n,
|
|
@@ -404,7 +404,7 @@ function makeStellarNetwork(preset, rpcUrl) {
|
|
|
404
404
|
}
|
|
405
405
|
const toBase = (s) => {
|
|
406
406
|
try {
|
|
407
|
-
return s != null ?
|
|
407
|
+
return s != null ? _chunkGYM46G5Lcjs.parseUnits.call(void 0, s, STELLAR_DECIMALS) : 0n;
|
|
408
408
|
} catch (e7) {
|
|
409
409
|
return 0n;
|
|
410
410
|
}
|