@piprail/sdk 2.16.2 → 3.0.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +343 -0
  2. package/README.md +1 -0
  3. package/dist/{algorand-25FMBCT3.js → algorand-HL57PQHE.js} +157 -2
  4. package/dist/{algorand-Q3TUQLPK.cjs → algorand-W776EEM2.cjs} +205 -50
  5. package/dist/{aptos-VBJONBFY.cjs → aptos-5QBXJ6NV.cjs} +255 -39
  6. package/dist/{aptos-SBV6SGDP.js → aptos-H5VLH2QL.js} +217 -1
  7. package/dist/{chunk-QONQSZHJ.cjs → chunk-6XTNI2OQ.cjs} +44 -44
  8. package/dist/{chunk-OXEFPLZA.cjs → chunk-6ZRAIQXF.cjs} +4 -4
  9. package/dist/chunk-GVCGUSTE.js +30 -0
  10. package/dist/{chunk-V2IJ5HUW.cjs → chunk-MZAJQYM3.cjs} +1 -0
  11. package/dist/chunk-MZXVXC3C.cjs +30 -0
  12. package/dist/{chunk-2CX7XRZK.js → chunk-TZDVZCTC.js} +1 -0
  13. package/dist/{chunk-C52H5TYB.js → chunk-YXBQKBDH.js} +2 -2
  14. package/dist/index.cjs +2929 -1444
  15. package/dist/index.d.cts +625 -13
  16. package/dist/index.d.ts +625 -13
  17. package/dist/index.js +2506 -1021
  18. package/dist/{near-OLKCMTBI.js → near-5X2CQGML.js} +197 -1
  19. package/dist/{near-5LTTDU6G.cjs → near-XSQXEIHT.cjs} +242 -46
  20. package/dist/{solana-AI2G7V33.cjs → solana-EBV6PUCU.cjs} +211 -52
  21. package/dist/{solana-HTKDRTD3.js → solana-O6Q6QILH.js} +167 -8
  22. package/dist/{stellar-E2KWEV2E.cjs → stellar-5C7FQLPS.cjs} +191 -29
  23. package/dist/{stellar-EUFZLX6J.js → stellar-YF5LOJEM.js} +163 -1
  24. package/dist/{sui-KCIITCYH.js → sui-JFQSDNSZ.js} +165 -3
  25. package/dist/{sui-Q3NJOJZS.cjs → sui-WIZEAO7E.cjs} +185 -23
  26. package/dist/{ton-J7TQWRN4.cjs → ton-AGTKLQA5.cjs} +264 -22
  27. package/dist/{ton-WH2JVQOO.js → ton-OZKFNRLT.js} +244 -2
  28. package/dist/{tron-FXBXDNEY.js → tron-HG3IOOCG.js} +283 -1
  29. package/dist/{tron-HIPMOX7S.cjs → tron-S4WX7OHY.cjs} +323 -41
  30. package/dist/{xrpl-RUOB37QH.js → xrpl-GOVHMYYK.js} +222 -5
  31. package/dist/{xrpl-SVVS445B.cjs → xrpl-YS3IXPLV.cjs} +273 -56
  32. package/package.json +12 -2
  33. package/dist/{chunk-QU25LSVS.js → chunk-5GRBEMCA.js} +44 -44
@@ -1,5 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
+ var _chunkMZXVXC3Ccjs = require('./chunk-MZXVXC3C.cjs');
3
4
 
4
5
 
5
6
 
@@ -10,7 +11,10 @@
10
11
 
11
12
 
12
13
 
13
- var _chunkQONQSZHJcjs = require('./chunk-QONQSZHJ.cjs');
14
+
15
+
16
+
17
+ var _chunk6XTNI2OQcjs = require('./chunk-6XTNI2OQ.cjs');
14
18
 
15
19
  // src/drivers/near/index.ts
16
20
  var _nearapijs = require('near-api-js');
@@ -61,18 +65,18 @@ async function payNear(params) {
61
65
  return res.hash;
62
66
  } catch (err) {
63
67
  if (isNearRegistrationError(err)) {
64
- throw new (0, _chunkQONQSZHJcjs.RecipientNotReadyError)(
68
+ throw new (0, _chunk6XTNI2OQcjs.RecipientNotReadyError)(
65
69
  `NEAR recipient ${accept.payTo} isn't registered on token ${accept.asset} (NEP-145 storage_deposit) \u2014 register it once (\u22480.00125 NEAR) before it can receive. (NEAR: not registered)`,
66
70
  { cause: err }
67
71
  );
68
72
  }
69
73
  if (isNearAffordability(err)) {
70
- throw new (0, _chunkQONQSZHJcjs.InsufficientFundsError)(
74
+ throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
71
75
  err instanceof Error ? err.message : "Insufficient NEAR balance for the payment.",
72
76
  { cause: err }
73
77
  );
74
78
  }
75
- throw _nullishCoalesce(_chunkQONQSZHJcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
79
+ throw _nullishCoalesce(_chunk6XTNI2OQcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
76
80
  }
77
81
  }
78
82
  async function payNearNative(params) {
@@ -82,12 +86,12 @@ async function payNearNative(params) {
82
86
  return res.hash;
83
87
  } catch (err) {
84
88
  if (isNearAffordability(err)) {
85
- throw new (0, _chunkQONQSZHJcjs.InsufficientFundsError)(
89
+ throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
86
90
  err instanceof Error ? err.message : "Insufficient NEAR balance for the payment.",
87
91
  { cause: err }
88
92
  );
89
93
  }
90
- throw _nullishCoalesce(_chunkQONQSZHJcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
94
+ throw _nullishCoalesce(_chunk6XTNI2OQcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
91
95
  }
92
96
  }
93
97
  function isNearRegistrationError(err) {
@@ -109,28 +113,28 @@ var NONCE_BLOCK_MULTIPLIER = 1000000n;
109
113
  async function payExactNear(input) {
110
114
  const { signer, senderId, blockHeight, accessKeyNonce, accept } = input;
111
115
  if (accept.asset === "native") {
112
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(
116
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(
113
117
  "NEAR exact is NEP-141-only (an ft_transfer); native NEAR is not exact-payable. Pay via onchain-proof."
114
118
  );
115
119
  }
116
120
  if (!isValidNearAccountId(accept.asset)) {
117
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(`NEAR exact: asset "${accept.asset}" must be a NEP-141 contract account id.`);
121
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(`NEAR exact: asset "${accept.asset}" must be a NEP-141 contract account id.`);
118
122
  }
119
123
  if (!isValidNearAccountId(accept.payTo)) {
120
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(`NEAR exact: payTo "${accept.payTo}" is not a valid NEAR account id.`);
124
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(`NEAR exact: payTo "${accept.payTo}" is not a valid NEAR account id.`);
121
125
  }
122
126
  if (!isValidNearAccountId(senderId)) {
123
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(`NEAR exact: sender "${senderId}" is not a valid NEAR account id.`);
127
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(`NEAR exact: sender "${senderId}" is not a valid NEAR account id.`);
124
128
  }
125
129
  const t = accept.maxTimeoutSeconds;
126
130
  if (!Number.isInteger(t) || t <= 0) {
127
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)("NEAR exact: maxTimeoutSeconds must be a positive integer.");
131
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)("NEAR exact: maxTimeoutSeconds must be a positive integer.");
128
132
  }
129
133
  const timeoutBlocks = BigInt(Math.max(1, Math.ceil(t / ESTIMATED_BLOCK_SECONDS)));
130
134
  const maxBlockHeight = blockHeight + timeoutBlocks;
131
135
  const nonce = accessKeyNonce + 1n;
132
136
  if (nonce >= blockHeight * NONCE_BLOCK_MULTIPLIER) {
133
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(
137
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(
134
138
  "NEAR exact: the access-key nonce is at the protocol ceiling for this block height; cannot build a delegate action."
135
139
  );
136
140
  }
@@ -259,7 +263,7 @@ async function verifyAndSettleExactNear(input) {
259
263
  if (/not enough|insufficient|exceeded the prepaid gas|NotEnoughBalance|doesn't have enough|is not registered/i.test(m)) {
260
264
  return fail("tx_reverted", `the ft_transfer would fail on chain: ${shorten(m)}.`);
261
265
  }
262
- throw new (0, _chunkQONQSZHJcjs.SettlementError)(
266
+ throw new (0, _chunk6XTNI2OQcjs.SettlementError)(
263
267
  `NEAR exact settle: the relayer could not submit the delegate (${shorten(m)}). The buyer's signed delegate is still valid \u2014 fund/fix the relayer and the buyer can re-present it.`,
264
268
  { cause: err }
265
269
  );
@@ -408,13 +412,13 @@ function txNotFound(hash) {
408
412
 
409
413
  function assertNearWallet(wallet, network) {
410
414
  if (typeof wallet !== "object" || wallet === null) {
411
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
415
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
412
416
  `chain ${network} is NEAR; wallet must be { accountId, key } (key = ed25519:\u2026).`
413
417
  );
414
418
  }
415
- _chunkQONQSZHJcjs.assertNoLegacyWalletKey.call(void 0, wallet, "NEAR");
419
+ _chunk6XTNI2OQcjs.assertNoLegacyWalletKey.call(void 0, wallet, "NEAR");
416
420
  if (!("accountId" in wallet) || !("key" in wallet)) {
417
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
421
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
418
422
  `chain ${network} is NEAR; wallet must be { accountId, key } (key = ed25519:\u2026).`
419
423
  );
420
424
  }
@@ -422,19 +426,173 @@ function assertNearWallet(wallet, network) {
422
426
  }
423
427
  function resolveNearWallet(config) {
424
428
  if (!config.accountId || !config.key) {
425
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)("NEAR wallet needs { accountId, key } (key = ed25519:\u2026).");
429
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)("NEAR wallet needs { accountId, key } (key = ed25519:\u2026).");
426
430
  }
427
431
  let signer;
428
432
  try {
429
433
  signer = _nearapijs.KeyPairSigner.fromSecretKey(config.key);
430
434
  } catch (cause) {
431
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)("NEAR wallet { key } is not a valid ed25519:\u2026 secret key.", {
435
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)("NEAR wallet { key } is not a valid ed25519:\u2026 secret key.", {
432
436
  cause
433
437
  });
434
438
  }
435
439
  return { accountId: config.accountId, signer };
436
440
  }
437
441
 
442
+ // src/drivers/near/swap.ts
443
+ var REF_EXCHANGE = "v2.ref-finance.near";
444
+ var WRAP_NEAR = "wrap.near";
445
+ var REF_INDEXER = "https://indexer.ref.finance";
446
+ function sourceFor(feeBps) {
447
+ const fee = feeBps === null ? "the pool's own fee" : `${(feeBps / 100).toFixed(2)}%`;
448
+ return {
449
+ kind: "provider",
450
+ name: "Ref Finance",
451
+ note: `Third-party NEAR AMM (v2.ref-finance.near), used keyless over the chain's own RPC. The swap is one ft_transfer_call receipt chain, so no solver ever takes possession of the funds, which is why this is used instead of an intent network. Pool fee on this route: ${fee}. PipRail adds nothing.`
452
+ };
453
+ }
454
+ function refToken(t) {
455
+ return t.asset === "native" ? WRAP_NEAR : t.asset;
456
+ }
457
+ function side(t, amount) {
458
+ const decimals = t.asset === "native" ? NEAR_DECIMALS : t.decimals;
459
+ return {
460
+ asset: t.asset,
461
+ symbol: _nullishCoalesce(t.symbol, () => ( (t.asset === "native" ? "NEAR" : t.asset))),
462
+ decimals,
463
+ amount: amount.toString(),
464
+ amountFormatted: _chunk6XTNI2OQcjs.formatUnits.call(void 0, amount, decimals)
465
+ };
466
+ }
467
+ async function getJson(url) {
468
+ const ctrl = new AbortController();
469
+ const timer = setTimeout(() => ctrl.abort(), 12e3);
470
+ try {
471
+ const res = await fetch(url, { signal: ctrl.signal });
472
+ if (!res.ok) return null;
473
+ return await res.json();
474
+ } catch (e10) {
475
+ return null;
476
+ } finally {
477
+ clearTimeout(timer);
478
+ }
479
+ }
480
+ async function findPools(tokenIn, tokenOut) {
481
+ const all = await getJson(`${REF_INDEXER}/list-top-pools`);
482
+ if (!Array.isArray(all)) return [];
483
+ return all.filter(
484
+ (p) => Array.isArray(p.token_account_ids) && p.token_account_ids.includes(tokenIn) && p.token_account_ids.includes(tokenOut)
485
+ ).sort((a, b) => Number(_nullishCoalesce(b.tvl, () => ( 0))) - Number(_nullishCoalesce(a.tvl, () => ( 0)))).slice(0, 4).map((p) => ({ ...p, id: Number(p.id) }));
486
+ }
487
+ async function quoteNearSwap(p) {
488
+ if (p.wantAmount <= 0n) return null;
489
+ const tokenIn = refToken(p.from);
490
+ const tokenOut = refToken(p.to);
491
+ if (tokenIn === tokenOut) return null;
492
+ const pools = await findPools(tokenIn, tokenOut);
493
+ if (!pools.length) return null;
494
+ const fromDecimals = p.from.asset === "native" ? NEAR_DECIMALS : p.from.decimals;
495
+ const probeIn = 10n ** BigInt(Math.max(fromDecimals - 2, 1));
496
+ const getReturn = async (poolId, amountIn) => {
497
+ try {
498
+ const out = await p.client.view(REF_EXCHANGE, "get_return", {
499
+ pool_id: poolId,
500
+ token_in: tokenIn,
501
+ amount_in: amountIn.toString(),
502
+ token_out: tokenOut
503
+ });
504
+ const s = String(_nullishCoalesce(out, () => ( "")));
505
+ return s && /^\d+$/.test(s) ? BigInt(s) : null;
506
+ } catch (e11) {
507
+ return null;
508
+ }
509
+ };
510
+ for (const pool of pools) {
511
+ const probeOut = await getReturn(pool.id, probeIn);
512
+ if (probeOut === null || probeOut <= 0n) continue;
513
+ let needIn = (probeIn * p.wantAmount + probeOut - 1n) / probeOut;
514
+ needIn = _chunkMZXVXC3Ccjs.applySlippage.call(void 0, needIn, p.slippageBps);
515
+ const realOut = await getReturn(pool.id, needIn);
516
+ if (realOut === null) continue;
517
+ if (realOut < p.wantAmount) continue;
518
+ const minOut = p.wantAmount;
519
+ return {
520
+ source: sourceFor(typeof pool.total_fee === "number" ? pool.total_fee : null),
521
+ network: p.network,
522
+ from: side(p.from, needIn),
523
+ to: side(p.to, realOut),
524
+ maxSpend: needIn.toString(),
525
+ maxSpendFormatted: _chunk6XTNI2OQcjs.formatUnits.call(void 0, needIn, fromDecimals),
526
+ slippageBps: p.slippageBps,
527
+ route: {
528
+ poolId: pool.id,
529
+ tokenIn,
530
+ tokenOut,
531
+ amountIn: needIn.toString(),
532
+ minAmountOut: minOut.toString()
533
+ }
534
+ };
535
+ }
536
+ return null;
537
+ }
538
+ async function swapNear(p) {
539
+ const route = p.quote.route;
540
+ if (!_optionalChain([route, 'optionalAccess', _10 => _10.poolId]) || !route.tokenIn) {
541
+ throw new Error("NEAR: swap quote is missing its Ref routing data \u2014 re-quote before swapping.");
542
+ }
543
+ const msg = JSON.stringify({
544
+ force: 0,
545
+ actions: [
546
+ {
547
+ pool_id: route.poolId,
548
+ token_in: route.tokenIn,
549
+ token_out: route.tokenOut,
550
+ amount_in: route.amountIn,
551
+ min_amount_out: route.minAmountOut
552
+ }
553
+ ]
554
+ });
555
+ try {
556
+ const tx = await p.call({
557
+ contractId: route.tokenIn,
558
+ method: "ft_transfer_call",
559
+ args: { receiver_id: REF_EXCHANGE, amount: route.amountIn, msg },
560
+ // NEP-141 transfer_call into an AMM needs generous gas: 180 TGas.
561
+ gas: 180000000000000n,
562
+ // ft_transfer_call requires exactly 1 yoctoNEAR as a signing assertion.
563
+ deposit: 1n
564
+ });
565
+ return {
566
+ transaction: tx,
567
+ network: p.quote.network,
568
+ source: p.quote.source,
569
+ from: p.quote.from,
570
+ to: p.quote.to
571
+ };
572
+ } catch (err) {
573
+ const msgText = String(_nullishCoalesce(_optionalChain([err, 'optionalAccess', _11 => _11.message]), () => ( err)));
574
+ if (/storage|not registered|NotRegistered/i.test(msgText)) {
575
+ throw new (0, _chunk6XTNI2OQcjs.RecipientNotReadyError)(
576
+ "NEAR swap refused: your account is not storage-registered on the token you are swapping INTO. Call storage_deposit on that token contract first (about 0.00125 NEAR).",
577
+ { cause: err }
578
+ );
579
+ }
580
+ if (/ERR_MIN_AMOUNT|slippage/i.test(msgText)) {
581
+ throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
582
+ "NEAR swap refused: the pool could not deliver the minimum output, so the tokens were returned. Re-quote and retry.",
583
+ { cause: err }
584
+ );
585
+ }
586
+ if (/insufficient|balance|exceeded/i.test(msgText)) {
587
+ throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
588
+ `NEAR swap failed: the account can't cover it (token balance or NEAR for gas). (${msgText.slice(0, 160)})`,
589
+ { cause: err }
590
+ );
591
+ }
592
+ throw err;
593
+ }
594
+ }
595
+
438
596
  // src/drivers/near/index.ts
439
597
  var nearDriver = {
440
598
  family: "near",
@@ -462,18 +620,18 @@ function makeNearNetwork(preset, rpcUrl) {
462
620
  logs: _nullishCoalesce(r.outcome.logs, () => ( []))
463
621
  }));
464
622
  const txn = outcome.transaction;
465
- const receiverId = _optionalChain([txn, 'optionalAccess', _10 => _10.receiver_id]);
466
- const nativeDeposit = sumTransferDeposits(_optionalChain([txn, 'optionalAccess', _11 => _11.actions])).toString();
623
+ const receiverId = _optionalChain([txn, 'optionalAccess', _12 => _12.receiver_id]);
624
+ const nativeDeposit = sumTransferDeposits(_optionalChain([txn, 'optionalAccess', _13 => _13.actions])).toString();
467
625
  let timestampMs;
468
626
  try {
469
- const blockHash = _optionalChain([outcome, 'access', _12 => _12.transaction_outcome, 'optionalAccess', _13 => _13.block_hash]);
627
+ const blockHash = _optionalChain([outcome, 'access', _14 => _14.transaction_outcome, 'optionalAccess', _15 => _15.block_hash]);
470
628
  if (blockHash) {
471
629
  const block = await provider.viewBlock({ blockId: blockHash });
472
630
  const header = block.header;
473
- const ns = _nullishCoalesce(_optionalChain([header, 'optionalAccess', _14 => _14.timestamp_nanosec]), () => ( (_optionalChain([header, 'optionalAccess', _15 => _15.timestamp]) != null ? String(header.timestamp) : void 0)));
631
+ const ns = _nullishCoalesce(_optionalChain([header, 'optionalAccess', _16 => _16.timestamp_nanosec]), () => ( (_optionalChain([header, 'optionalAccess', _17 => _17.timestamp]) != null ? String(header.timestamp) : void 0)));
474
632
  if (ns != null) timestampMs = Number(BigInt(ns) / 1000000n);
475
633
  }
476
- } catch (e10) {
634
+ } catch (e12) {
477
635
  }
478
636
  return { success, receipts, receiverId, nativeDeposit, timestampMs };
479
637
  }
@@ -490,16 +648,16 @@ function makeNearNetwork(preset, rpcUrl) {
490
648
  const info = preset.tokens[token.toUpperCase()];
491
649
  if (!info) {
492
650
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
493
- throw new (0, _chunkQONQSZHJcjs.UnknownTokenError)(
651
+ throw new (0, _chunk6XTNI2OQcjs.UnknownTokenError)(
494
652
  `token "${token}" isn't built in for NEAR (known: ${known}). Pass { contractId, decimals } for a custom NEP-141.`
495
653
  );
496
654
  }
497
655
  return { asset: info.contractId, decimals: info.decimals, symbol: info.symbol };
498
656
  }
499
- _chunkQONQSZHJcjs.rejectForeignToken.call(void 0, token, "near", network);
657
+ _chunk6XTNI2OQcjs.rejectForeignToken.call(void 0, token, "near", network);
500
658
  const t = token;
501
659
  if (!t.contractId || typeof t.decimals !== "number") {
502
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
660
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
503
661
  `chain ${network} is NEAR; a custom token must be { contractId, decimals }.`
504
662
  );
505
663
  }
@@ -518,12 +676,12 @@ function makeNearNetwork(preset, rpcUrl) {
518
676
  },
519
677
  assertValidPayTo(payTo) {
520
678
  if (payTo.startsWith("0x")) {
521
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
679
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
522
680
  `chain ${network} is NEAR, but payTo "${payTo}" looks like an EVM/Sui 0x address.`
523
681
  );
524
682
  }
525
683
  if (!isValidNearAccountId(payTo)) {
526
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
684
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
527
685
  `chain ${network} is NEAR, but payTo "${payTo}" is not a valid NEAR account id.`
528
686
  );
529
687
  }
@@ -535,7 +693,7 @@ function makeNearNetwork(preset, rpcUrl) {
535
693
  const { accountId, signer } = resolveNearWallet(wallet._native);
536
694
  const account = new (0, _nearapijs.Account)(accountId, provider, signer);
537
695
  const hashOf = (outcome) => {
538
- const hash2 = _optionalChain([outcome, 'access', _16 => _16.transaction, 'optionalAccess', _17 => _17.hash]);
696
+ const hash2 = _optionalChain([outcome, 'access', _18 => _18.transaction, 'optionalAccess', _19 => _19.hash]);
539
697
  if (!hash2) throw new Error("NEAR: signAndSendTransaction returned no tx hash.");
540
698
  return hash2;
541
699
  };
@@ -565,13 +723,13 @@ function makeNearNetwork(preset, rpcUrl) {
565
723
  try {
566
724
  const tx = await reader.txStatus(hash, senderId);
567
725
  if (tx && tx.success) return { height: "0" };
568
- } catch (e11) {
726
+ } catch (e13) {
569
727
  }
570
- throw new (0, _chunkQONQSZHJcjs.ConfirmationTimeoutError)(`NEAR tx ${hash} not confirmed in time.`);
728
+ throw new (0, _chunk6XTNI2OQcjs.ConfirmationTimeoutError)(`NEAR tx ${hash} not confirmed in time.`);
571
729
  },
572
730
  async estimateCost(accept) {
573
731
  if (accept.scheme === "exact") {
574
- return _chunkQONQSZHJcjs.nativeCost.call(void 0, {
732
+ return _chunk6XTNI2OQcjs.nativeCost.call(void 0, {
575
733
  symbol: "NEAR",
576
734
  decimals: NEAR_DECIMALS,
577
735
  fee: 0n,
@@ -579,7 +737,7 @@ function makeNearNetwork(preset, rpcUrl) {
579
737
  detail: "gasless \u2014 the relayer prepays gas + the 1 yocto; the buyer pays 0 NEAR"
580
738
  });
581
739
  }
582
- return _chunkQONQSZHJcjs.nativeCost.call(void 0, {
740
+ return _chunk6XTNI2OQcjs.nativeCost.call(void 0, {
583
741
  symbol: "NEAR",
584
742
  decimals: NEAR_DECIMALS,
585
743
  fee: 1500000000000000000000n,
@@ -587,11 +745,16 @@ function makeNearNetwork(preset, rpcUrl) {
587
745
  detail: "~14 TGas for ft_transfer (\u22480.0015 NEAR) + 1 yoctoNEAR deposit"
588
746
  });
589
747
  },
748
+ /** The bound wallet's own address — where THIS wallet gets paid. Derived from the key
749
+ * material only: no RPC, nothing moved. See {@link ResolvedNetwork.addressOf}. */
750
+ async addressOf(wallet) {
751
+ return resolveNearWallet(wallet._native).accountId;
752
+ },
590
753
  async balanceOf(wallet, asset) {
591
754
  let accountId;
592
755
  try {
593
756
  accountId = resolveNearWallet(wallet._native).accountId;
594
- } catch (e12) {
757
+ } catch (e14) {
595
758
  return { token: null, native: null };
596
759
  }
597
760
  let native = null;
@@ -603,7 +766,7 @@ function makeNearNetwork(preset, rpcUrl) {
603
766
  });
604
767
  native = r.amount != null ? BigInt(r.amount) : null;
605
768
  } catch (e) {
606
- native = /does not exist|UNKNOWN_ACCOUNT/i.test(String(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _18 => _18.message]), () => ( e)))) ? 0n : null;
769
+ native = /does not exist|UNKNOWN_ACCOUNT/i.test(String(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _20 => _20.message]), () => ( e)))) ? 0n : null;
607
770
  }
608
771
  if (asset === "native") return { token: native, native };
609
772
  let token = null;
@@ -617,7 +780,7 @@ function makeNearNetwork(preset, rpcUrl) {
617
780
  });
618
781
  token = r.result ? BigInt(JSON.parse(Buffer.from(r.result).toString())) : null;
619
782
  } catch (e) {
620
- token = /does not exist|not registered|UNKNOWN_ACCOUNT/i.test(String(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _19 => _19.message]), () => ( e)))) ? 0n : null;
783
+ token = /does not exist|not registered|UNKNOWN_ACCOUNT/i.test(String(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _21 => _21.message]), () => ( e)))) ? 0n : null;
621
784
  }
622
785
  return { token, native };
623
786
  },
@@ -633,10 +796,43 @@ function makeNearNetwork(preset, rpcUrl) {
633
796
  });
634
797
  const parsed = r.result ? JSON.parse(Buffer.from(r.result).toString()) : null;
635
798
  return parsed == null ? { ready: false, reason: "NOT_REGISTERED" } : { ready: true };
636
- } catch (e13) {
799
+ } catch (e15) {
637
800
  return { ready: "unknown" };
638
801
  }
639
802
  },
803
+ /* ---- swap (OPTIONAL, opt-in): via Ref Finance, keyless over the chain's own RPC.
804
+ Chosen over NEAR Intents because Intents re-adds a facilitator. See ./swap.ts ---- */
805
+ async quoteSwap({ from, to, wantAmount, slippageBps }) {
806
+ const viewClient = {
807
+ async view(contractId, method, args) {
808
+ const r = await provider.query({
809
+ request_type: "call_function",
810
+ finality: "final",
811
+ account_id: contractId,
812
+ method_name: method,
813
+ args_base64: Buffer.from(JSON.stringify(args)).toString("base64")
814
+ });
815
+ return r.result ? JSON.parse(Buffer.from(r.result).toString()) : null;
816
+ }
817
+ };
818
+ return quoteNearSwap({ client: viewClient, network, from, to, wantAmount, slippageBps });
819
+ },
820
+ async swap(wallet, quote) {
821
+ const { accountId, signer } = resolveNearWallet(wallet._native);
822
+ const account = new (0, _nearapijs.Account)(accountId, provider, signer);
823
+ return swapNear({
824
+ quote,
825
+ async call({ contractId, method, args, gas, deposit }) {
826
+ const outcome = await account.signAndSendTransaction({
827
+ receiverId: contractId,
828
+ actions: [_nearapijs.actions.functionCall(method, args, gas, deposit)]
829
+ });
830
+ const hash = _optionalChain([outcome, 'access', _22 => _22.transaction, 'optionalAccess', _23 => _23.hash]);
831
+ if (!hash) throw new Error("NEAR: signAndSendTransaction returned no tx hash.");
832
+ return hash;
833
+ }
834
+ });
835
+ },
640
836
  async verify(ref, accept) {
641
837
  const { senderId, hash } = decodeRef(ref);
642
838
  return verifyNear({ reader, hash, senderId, accept });
@@ -659,7 +855,7 @@ function makeNearNetwork(preset, rpcUrl) {
659
855
  provider.viewBlock({ finality: "final" })
660
856
  ]);
661
857
  const accessKeyNonce = BigInt(_nullishCoalesce(accessKey.nonce, () => ( 0)));
662
- const blockHeight = BigInt(_nullishCoalesce(_optionalChain([block, 'access', _20 => _20.header, 'optionalAccess', _21 => _21.height]), () => ( 0)));
858
+ const blockHeight = BigInt(_nullishCoalesce(_optionalChain([block, 'access', _24 => _24.header, 'optionalAccess', _25 => _25.height]), () => ( 0)));
663
859
  const { payload, payerFrom, nonce } = await payExactNear({
664
860
  signer,
665
861
  senderId: accountId,
@@ -681,7 +877,7 @@ function makeNearNetwork(preset, rpcUrl) {
681
877
  if (!fp && relayer) {
682
878
  try {
683
879
  fp = resolveNearWallet(relayer._native).accountId;
684
- } catch (e14) {
880
+ } catch (e16) {
685
881
  return null;
686
882
  }
687
883
  }
@@ -701,7 +897,7 @@ function makeNearNetwork(preset, rpcUrl) {
701
897
  try {
702
898
  relayerWallet = resolveNearWallet(relayer._native);
703
899
  } catch (err) {
704
- throw new (0, _chunkQONQSZHJcjs.SettlementError)(
900
+ throw new (0, _chunk6XTNI2OQcjs.SettlementError)(
705
901
  `NEAR exact settle: the relayer wallet is invalid (${err instanceof Error ? err.message : String(err)}).`,
706
902
  { cause: err }
707
903
  );
@@ -712,8 +908,8 @@ function makeNearNetwork(preset, rpcUrl) {
712
908
  async currentBlockHeight() {
713
909
  try {
714
910
  const b = await provider.viewBlock({ finality: "final" });
715
- return _optionalChain([b, 'access', _22 => _22.header, 'optionalAccess', _23 => _23.height]) != null ? BigInt(b.header.height) : null;
716
- } catch (e15) {
911
+ return _optionalChain([b, 'access', _26 => _26.header, 'optionalAccess', _27 => _27.height]) != null ? BigInt(b.header.height) : null;
912
+ } catch (e17) {
717
913
  return null;
718
914
  }
719
915
  },
@@ -723,9 +919,9 @@ function makeNearNetwork(preset, rpcUrl) {
723
919
  actions: [_nearapijs.actions.signedDelegate({ delegateAction, signature })],
724
920
  waitUntil: "FINAL"
725
921
  });
726
- const txHash = _nullishCoalesce(_optionalChain([outcome, 'access', _24 => _24.transaction, 'optionalAccess', _25 => _25.hash]), () => ( ""));
727
- const tokenReceipt = (_nullishCoalesce(outcome.receipts_outcome, () => ( []))).find((r) => _optionalChain([r, 'access', _26 => _26.outcome, 'optionalAccess', _27 => _27.executor_id]) === accept.asset);
728
- const innerSuccess = tokenReceipt ? isSuccess(_optionalChain([tokenReceipt, 'access', _28 => _28.outcome, 'optionalAccess', _29 => _29.status])) : isSuccess(outcome.status);
922
+ const txHash = _nullishCoalesce(_optionalChain([outcome, 'access', _28 => _28.transaction, 'optionalAccess', _29 => _29.hash]), () => ( ""));
923
+ const tokenReceipt = (_nullishCoalesce(outcome.receipts_outcome, () => ( []))).find((r) => _optionalChain([r, 'access', _30 => _30.outcome, 'optionalAccess', _31 => _31.executor_id]) === accept.asset);
924
+ const innerSuccess = tokenReceipt ? isSuccess(_optionalChain([tokenReceipt, 'access', _32 => _32.outcome, 'optionalAccess', _33 => _33.status])) : isSuccess(outcome.status);
729
925
  return { txHash, innerSuccess };
730
926
  }
731
927
  };
@@ -749,7 +945,7 @@ function sumTransferDeposits(actions3) {
749
945
  if (t && t.deposit != null) {
750
946
  try {
751
947
  sum += BigInt(t.deposit);
752
- } catch (e16) {
948
+ } catch (e18) {
753
949
  }
754
950
  }
755
951
  }