@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,8 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 _chunkV2IJ5HUWcjs = require('./chunk-V2IJ5HUW.cjs');
3
+ var _chunkMZAJQYM3cjs = require('./chunk-MZAJQYM3.cjs');
4
4
 
5
5
 
6
+ var _chunkMZXVXC3Ccjs = require('./chunk-MZXVXC3C.cjs');
6
7
 
7
8
 
8
9
 
@@ -13,7 +14,10 @@ var _chunkV2IJ5HUWcjs = require('./chunk-V2IJ5HUW.cjs');
13
14
 
14
15
 
15
16
 
16
- var _chunkQONQSZHJcjs = require('./chunk-QONQSZHJ.cjs');
17
+
18
+
19
+
20
+ var _chunk6XTNI2OQcjs = require('./chunk-6XTNI2OQ.cjs');
17
21
 
18
22
  // src/drivers/algorand/index.ts
19
23
  var _algosdk = require('algosdk'); var _algosdk2 = _interopRequireDefault(_algosdk);
@@ -61,13 +65,13 @@ async function payAlgorand(params) {
61
65
  } catch (err) {
62
66
  const mapped = mapAlgorandError(err, accept.payTo);
63
67
  if (mapped) throw mapped;
64
- throw _nullishCoalesce(_chunkQONQSZHJcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
68
+ throw _nullishCoalesce(_chunk6XTNI2OQcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
65
69
  }
66
70
  }
67
71
  function mapAlgorandError(err, payTo) {
68
72
  const m = err instanceof Error ? err.message : String(err);
69
73
  if (/must optin/i.test(m) || /missing from/i.test(m) && m.includes(payTo)) {
70
- return new (0, _chunkQONQSZHJcjs.RecipientNotReadyError)(
74
+ return new (0, _chunk6XTNI2OQcjs.RecipientNotReadyError)(
71
75
  `Algorand recipient ${payTo} hasn't opted into this asset \u2014 it must opt in (a 0-amount asset transfer to itself) before it can receive. (Algorand: ${firstLine(m)})`,
72
76
  { cause: err }
73
77
  );
@@ -75,7 +79,7 @@ function mapAlgorandError(err, payTo) {
75
79
  if (/overspend|below min|min(imum)? balance|tried to spend|balance \d+ below|asset \d+ missing from|insufficient|underflow/i.test(
76
80
  m
77
81
  )) {
78
- return new (0, _chunkQONQSZHJcjs.InsufficientFundsError)(
82
+ return new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
79
83
  `Algorand payment failed: the sender can't cover it \u2014 token balance, ALGO for fees, the 0.1-ALGO minimum balance, or a missing asset opt-in on the sender. (Algorand: ${firstLine(m)})`,
80
84
  { cause: err }
81
85
  );
@@ -86,6 +90,144 @@ function firstLine(message) {
86
90
  return message.split("\n")[0].slice(0, 160);
87
91
  }
88
92
 
93
+ // src/drivers/algorand/swap.ts
94
+ var VESTIGE_API = "https://api.vestigelabs.org";
95
+ var ALGO_ASA = 0;
96
+ function sourceFor(poolFee) {
97
+ const fee = typeof poolFee === "number" ? `${(poolFee * 100).toFixed(2)}%` : "the pool's own fee";
98
+ return {
99
+ kind: "provider",
100
+ name: "Vestige",
101
+ note: `Third-party Algorand DEX aggregator (api.vestigelabs.org), used keyless. It returns an UNSIGNED atomic transaction group in which every signer is you: nobody co-signs and nothing is delegated. Pool fee on this route: ${fee}. PipRail adds nothing.`
102
+ };
103
+ }
104
+ function asaId(t) {
105
+ if (t.asset === "native") return ALGO_ASA;
106
+ const n = Number(t.asset);
107
+ return Number.isSafeInteger(n) && n > 0 ? n : null;
108
+ }
109
+ function side(t, amount) {
110
+ const decimals = t.asset === "native" ? ALGO_DECIMALS : t.decimals;
111
+ return {
112
+ asset: t.asset,
113
+ symbol: _nullishCoalesce(t.symbol, () => ( (t.asset === "native" ? "ALGO" : t.asset))),
114
+ decimals,
115
+ amount: amount.toString(),
116
+ amountFormatted: _chunk6XTNI2OQcjs.formatUnits.call(void 0, amount, decimals)
117
+ };
118
+ }
119
+ async function req(url, init) {
120
+ const ctrl = new AbortController();
121
+ const timer = setTimeout(() => ctrl.abort(), 15e3);
122
+ try {
123
+ const res = await fetch(url, { ..._nullishCoalesce(init, () => ( {})), signal: ctrl.signal });
124
+ if (!res.ok) return null;
125
+ return await res.json();
126
+ } catch (e2) {
127
+ return null;
128
+ } finally {
129
+ clearTimeout(timer);
130
+ }
131
+ }
132
+ async function quoteAlgorandSwap(p) {
133
+ if (p.wantAmount <= 0n) return null;
134
+ const fromAsa = asaId(p.from);
135
+ const toAsa = asaId(p.to);
136
+ if (fromAsa === null || toAsa === null || fromAsa === toAsa) return null;
137
+ const quoteFor = (amountIn) => req(
138
+ `${VESTIGE_API}/swap/v4?from_asa=${fromAsa}&to_asa=${toAsa}&amount=${amountIn.toString()}&mode=sef&denominating_asset_id=0`
139
+ );
140
+ const fromDecimals = p.from.asset === "native" ? ALGO_DECIMALS : p.from.decimals;
141
+ let probeIn = 10n ** BigInt(Math.max(fromDecimals - 2, 1));
142
+ let probeOut = 0;
143
+ for (let step = 0; step < 4; step += 1) {
144
+ const probe = await quoteFor(probeIn);
145
+ const out = _optionalChain([probe, 'optionalAccess', _ => _.amount_out]);
146
+ if (out && out > 0) {
147
+ probeOut = out;
148
+ break;
149
+ }
150
+ probeIn *= 10n;
151
+ }
152
+ if (!probeOut) return null;
153
+ let needIn = (probeIn * p.wantAmount + BigInt(probeOut) - 1n) / BigInt(probeOut);
154
+ needIn = _chunkMZXVXC3Ccjs.applySlippage.call(void 0, needIn, p.slippageBps);
155
+ const real = await quoteFor(needIn);
156
+ const realOut = _optionalChain([real, 'optionalAccess', _2 => _2.amount_out]);
157
+ if (!realOut) return null;
158
+ if (BigInt(Math.floor(realOut)) < p.wantAmount) return null;
159
+ const poolFee = _optionalChain([real, 'access', _3 => _3.single, 'optionalAccess', _4 => _4.transactions, 'optionalAccess', _5 => _5[0], 'optionalAccess', _6 => _6.swaps, 'optionalAccess', _7 => _7[0], 'optionalAccess', _8 => _8.fee]);
160
+ return {
161
+ source: sourceFor(poolFee),
162
+ network: p.network,
163
+ from: side(p.from, needIn),
164
+ to: side(p.to, BigInt(Math.floor(realOut))),
165
+ maxSpend: needIn.toString(),
166
+ maxSpendFormatted: _chunk6XTNI2OQcjs.formatUnits.call(void 0, needIn, fromDecimals),
167
+ slippageBps: p.slippageBps,
168
+ // The build endpoint wants the ENTIRE quote response back, unmodified.
169
+ route: { quote: real }
170
+ };
171
+ }
172
+ async function swapAlgorand(p) {
173
+ const route = p.quote.route;
174
+ if (!_optionalChain([route, 'optionalAccess', _9 => _9.quote])) {
175
+ throw new Error("Algorand: swap quote is missing its Vestige routing data \u2014 re-quote before swapping.");
176
+ }
177
+ const slippage = p.quote.slippageBps / 1e4;
178
+ const unsigned = await req(
179
+ `${VESTIGE_API}/swap/v4/transactions?sender=${p.signer.addr}&slippage=${slippage}`,
180
+ {
181
+ method: "POST",
182
+ headers: { "content-type": "application/json" },
183
+ body: JSON.stringify(route.quote)
184
+ }
185
+ );
186
+ if (!_optionalChain([unsigned, 'optionalAccess', _10 => _10.length])) {
187
+ throw new (0, _chunk6XTNI2OQcjs.RecipientNotReadyError)(
188
+ "Vestige could not build this swap. The usual cause is that your account is not opted in to the asset you are swapping INTO: opt in first, then re-quote. Nothing was spent."
189
+ );
190
+ }
191
+ for (const t of unsigned) {
192
+ if (t.signers && t.signers.some((s) => s !== p.signer.addr)) {
193
+ throw new Error(
194
+ "Algorand swap refused: the built group asks a third party to co-sign, which this rail must never do. Nothing was signed."
195
+ );
196
+ }
197
+ }
198
+ try {
199
+ const signed = unsigned.map((t) => {
200
+ const decoded = p.algosdk.decodeUnsignedTransaction(Buffer.from(t.txn, "base64"));
201
+ return decoded.signTxn(p.signer.sk);
202
+ });
203
+ const res = await p.algod.sendRawTransaction(signed).do();
204
+ const txid = _nullishCoalesce(res.txid, () => ( res.txId));
205
+ if (!txid) throw new Error("Algorand: sendRawTransaction returned no transaction id.");
206
+ return {
207
+ transaction: txid,
208
+ network: p.quote.network,
209
+ source: p.quote.source,
210
+ from: p.quote.from,
211
+ to: p.quote.to
212
+ };
213
+ } catch (err) {
214
+ const msg = String(_nullishCoalesce(_optionalChain([err, 'optionalAccess', _11 => _11.message]), () => ( err)));
215
+ if (/asset .* missing|not opted in|receiver error/i.test(msg)) {
216
+ throw new (0, _chunk6XTNI2OQcjs.RecipientNotReadyError)(
217
+ `Algorand swap refused: your account must opt in to the asset you are swapping INTO first. (${msg.slice(0, 140)})`,
218
+ { cause: err }
219
+ );
220
+ }
221
+ if (/overspend|insufficient|below min/i.test(msg)) {
222
+ throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
223
+ `Algorand swap failed: the account can't cover it (balance, the 0.1 ALGO minimum, or group fees). (${msg.slice(0, 140)})`,
224
+ { cause: err }
225
+ );
226
+ }
227
+ throw err;
228
+ }
229
+ }
230
+
89
231
  // src/drivers/algorand/exact.ts
90
232
 
91
233
  var ZERO_ADDRESS = _algosdk2.default.Address.zeroAddress().toString();
@@ -101,34 +243,34 @@ function isSet(addr) {
101
243
  }
102
244
  function randomNote() {
103
245
  const g = globalThis.crypto;
104
- if (!_optionalChain([g, 'optionalAccess', _ => _.getRandomValues])) {
105
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)("Algorand exact: no Web Crypto CSPRNG available to generate a unique note.");
246
+ if (!_optionalChain([g, 'optionalAccess', _12 => _12.getRandomValues])) {
247
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)("Algorand exact: no Web Crypto CSPRNG available to generate a unique note.");
106
248
  }
107
249
  return g.getRandomValues(new Uint8Array(32));
108
250
  }
109
251
  async function payExactAlgorand(input) {
110
252
  const { suggestedParams, sk, sender, accept } = input;
111
253
  if (accept.asset === "native") {
112
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(
254
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(
113
255
  "Algorand exact is ASA-only (an asset transfer); native ALGO is not exact-payable. Pay via onchain-proof."
114
256
  );
115
257
  }
116
- const feePayer = _optionalChain([accept, 'access', _2 => _2.extra, 'optionalAccess', _3 => _3.feePayer]);
258
+ const feePayer = _optionalChain([accept, 'access', _13 => _13.extra, 'optionalAccess', _14 => _14.feePayer]);
117
259
  if (!feePayer) {
118
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)("Algorand exact rail must advertise extra.feePayer (the fee sponsor address).");
260
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)("Algorand exact rail must advertise extra.feePayer (the fee sponsor address).");
119
261
  }
120
262
  const assetId = parseAlgorandAssetId(accept.asset);
121
263
  if (assetId === null) {
122
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(`Algorand exact rail asset "${accept.asset}" must be a numeric ASA id.`);
264
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(`Algorand exact rail asset "${accept.asset}" must be a numeric ASA id.`);
123
265
  }
124
266
  if (!_algosdk2.default.isValidAddress(feePayer)) {
125
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(`Algorand exact: extra.feePayer "${feePayer}" is not a valid Algorand address.`);
267
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(`Algorand exact: extra.feePayer "${feePayer}" is not a valid Algorand address.`);
126
268
  }
127
269
  if (!_algosdk2.default.isValidAddress(accept.payTo)) {
128
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(`Algorand exact: payTo "${accept.payTo}" is not a valid Algorand address.`);
270
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(`Algorand exact: payTo "${accept.payTo}" is not a valid Algorand address.`);
129
271
  }
130
272
  if (feePayer === sender) {
131
- throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(
273
+ throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(
132
274
  "Algorand exact: the fee payer must differ from the payer \u2014 the buyer must pay ZERO ALGO (the sponsor pays the pooled fee)."
133
275
  );
134
276
  }
@@ -168,20 +310,20 @@ function decodeElement(bytes) {
168
310
  try {
169
311
  const st = _algosdk2.default.decodeSignedTransaction(bytes);
170
312
  return { txn: st.txn, signed: st.sig != null || st.msig != null || st.lsig != null, raw: bytes };
171
- } catch (e2) {
313
+ } catch (e3) {
172
314
  return { txn: _algosdk2.default.decodeUnsignedTransaction(bytes), signed: false, raw: bytes };
173
315
  }
174
316
  }
175
317
  async function verifyAndSettleExactAlgorand(input) {
176
318
  const { client, feePayerSk, feePayerAddr, payload, accept } = input;
177
- const railFeePayer = _optionalChain([accept, 'access', _4 => _4.extra, 'optionalAccess', _5 => _5.feePayer]);
178
- if (!railFeePayer) throw new (0, _chunkQONQSZHJcjs.SettlementError)("Algorand exact: rail is missing extra.feePayer.");
319
+ const railFeePayer = _optionalChain([accept, 'access', _15 => _15.extra, 'optionalAccess', _16 => _16.feePayer]);
320
+ if (!railFeePayer) throw new (0, _chunk6XTNI2OQcjs.SettlementError)("Algorand exact: rail is missing extra.feePayer.");
179
321
  if (railFeePayer !== feePayerAddr) {
180
- throw new (0, _chunkQONQSZHJcjs.SettlementError)("Algorand exact: the gate relayer address does not match the rail extra.feePayer \u2014 misconfigured rail.");
322
+ throw new (0, _chunk6XTNI2OQcjs.SettlementError)("Algorand exact: the gate relayer address does not match the rail extra.feePayer \u2014 misconfigured rail.");
181
323
  }
182
324
  const assetId = parseAlgorandAssetId(accept.asset);
183
- if (assetId === null) throw new (0, _chunkQONQSZHJcjs.SettlementError)(`Algorand exact: rail asset "${accept.asset}" is not a numeric ASA id.`);
184
- if (!_algosdk2.default.isValidAddress(accept.payTo)) throw new (0, _chunkQONQSZHJcjs.SettlementError)(`Algorand exact: rail payTo "${accept.payTo}" is invalid.`);
325
+ if (assetId === null) throw new (0, _chunk6XTNI2OQcjs.SettlementError)(`Algorand exact: rail asset "${accept.asset}" is not a numeric ASA id.`);
326
+ if (!_algosdk2.default.isValidAddress(accept.payTo)) throw new (0, _chunk6XTNI2OQcjs.SettlementError)(`Algorand exact: rail payTo "${accept.payTo}" is invalid.`);
185
327
  const { paymentIndex, paymentGroup } = payload;
186
328
  if (paymentGroup.length !== GROUP_SIZE) {
187
329
  return fail("signature_invalid", `Algorand exact expects a ${GROUP_SIZE}-transaction group (payment + fee), got ${paymentGroup.length}.`);
@@ -209,7 +351,7 @@ async function verifyAndSettleExactAlgorand(input) {
209
351
  return fail("transfer_not_found", `Transfer asset id ${at.assetIndex} \u2260 rail asset ${assetId}.`);
210
352
  }
211
353
  if (!addrEq(at.receiver, accept.payTo)) {
212
- return fail("wrong_recipient", `Transfer pays ${_optionalChain([at, 'access', _6 => _6.receiver, 'optionalAccess', _7 => _7.toString, 'call', _8 => _8()])}, not payTo ${accept.payTo}.`);
354
+ return fail("wrong_recipient", `Transfer pays ${_optionalChain([at, 'access', _17 => _17.receiver, 'optionalAccess', _18 => _18.toString, 'call', _19 => _19()])}, not payTo ${accept.payTo}.`);
213
355
  }
214
356
  if (BigInt(at.amount) < BigInt(accept.amount)) {
215
357
  return fail("amount_too_low", `Transfer pays ${at.amount} of the ASA, required ${accept.amount}.`);
@@ -224,7 +366,7 @@ async function verifyAndSettleExactAlgorand(input) {
224
366
  return fail("signature_invalid", "The fee transaction must be a payment (pay) transaction.");
225
367
  }
226
368
  if (!addrEq(fee.sender, railFeePayer)) {
227
- return fail("signature_invalid", `The fee transaction sender ${_optionalChain([fee, 'access', _9 => _9.sender, 'optionalAccess', _10 => _10.toString, 'call', _11 => _11()])} is not the rail fee payer ${railFeePayer}.`);
369
+ return fail("signature_invalid", `The fee transaction sender ${_optionalChain([fee, 'access', _20 => _20.sender, 'optionalAccess', _21 => _21.toString, 'call', _22 => _22()])} is not the rail fee payer ${railFeePayer}.`);
228
370
  }
229
371
  if (BigInt(fee.payment.amount) !== 0n) {
230
372
  return fail("signature_invalid", "The fee transaction must move 0 ALGO (it only pools the group fee).");
@@ -247,7 +389,7 @@ async function verifyAndSettleExactAlgorand(input) {
247
389
  try {
248
390
  feeSigned = fee.signTxn(feePayerSk);
249
391
  } catch (err) {
250
- throw new (0, _chunkQONQSZHJcjs.SettlementError)(`Algorand exact settle: the gate could not sign the fee transaction (${shorten(err instanceof Error ? err.message : String(err))}).`, { cause: err });
392
+ throw new (0, _chunk6XTNI2OQcjs.SettlementError)(`Algorand exact settle: the gate could not sign the fee transaction (${shorten(err instanceof Error ? err.message : String(err))}).`, { cause: err });
251
393
  }
252
394
  const signedGroup = elements.map((el, i) => i === paymentIndex ? payElement.raw : feeSigned);
253
395
  try {
@@ -259,7 +401,7 @@ async function verifyAndSettleExactAlgorand(input) {
259
401
  if (/overspend|below min|underflow|insufficient|asset|frozen|opt|missing/i.test(m)) return fail("tx_reverted", `Group would fail on-chain: ${shorten(m)}.`);
260
402
  return fail("tx_reverted", `Group would fail on-chain: ${shorten(m)}.`);
261
403
  }
262
- } catch (e3) {
404
+ } catch (e4) {
263
405
  }
264
406
  const buyerTxid = pay.txID();
265
407
  try {
@@ -269,7 +411,7 @@ async function verifyAndSettleExactAlgorand(input) {
269
411
  if (/signature|sig|auth|malformed/i.test(m)) return fail("signature_invalid", `Settle rejected \u2014 bad signature: ${shorten(m)}.`);
270
412
  if (/already in ledger|already committed|duplicate/i.test(m)) return fail("tx_already_used", `This payment was already settled: ${shorten(m)}.`);
271
413
  if (/\bround\b|expired|lifetime|stale|validity/i.test(m)) return fail("payment_expired", `Settle rejected \u2014 validity window expired: ${shorten(m)}.`);
272
- throw new (0, _chunkQONQSZHJcjs.SettlementError)(
414
+ throw new (0, _chunk6XTNI2OQcjs.SettlementError)(
273
415
  `Algorand exact settle: the group failed to submit (${shorten(m)}). The buyer's signed transaction is still valid \u2014 fund/fix the fee payer (${railFeePayer}) and the buyer can re-present it.`,
274
416
  { cause: err }
275
417
  );
@@ -278,10 +420,10 @@ async function verifyAndSettleExactAlgorand(input) {
278
420
  try {
279
421
  round = await client.waitForConfirmation(buyerTxid);
280
422
  } catch (err) {
281
- throw new (0, _chunkQONQSZHJcjs.SettlementError)(`Algorand exact settle: submitted ${buyerTxid} but confirmation read failed (${shorten(err instanceof Error ? err.message : String(err))}). It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`, { cause: err });
423
+ throw new (0, _chunk6XTNI2OQcjs.SettlementError)(`Algorand exact settle: submitted ${buyerTxid} but confirmation read failed (${shorten(err instanceof Error ? err.message : String(err))}). It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`, { cause: err });
282
424
  }
283
425
  if (round === null) {
284
- throw new (0, _chunkQONQSZHJcjs.SettlementError)(`Algorand exact settle: submitted ${buyerTxid} but it did not confirm in time. It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`);
426
+ throw new (0, _chunk6XTNI2OQcjs.SettlementError)(`Algorand exact settle: submitted ${buyerTxid} but it did not confirm in time. It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`);
285
427
  }
286
428
  return {
287
429
  ok: true,
@@ -308,7 +450,7 @@ async function verifyAlgorand(params) {
308
450
  let txs;
309
451
  try {
310
452
  txs = await reader.transactionsForAccount(accept.payTo, 200);
311
- } catch (e4) {
453
+ } catch (e5) {
312
454
  return rpcFailed(nonce);
313
455
  }
314
456
  const tx = txs.find((t) => typeof t.note === "string" && t.note === nonce);
@@ -337,7 +479,7 @@ async function verifyAlgorand(params) {
337
479
  let paid = 0n;
338
480
  try {
339
481
  paid = tx.amount ? BigInt(tx.amount) : 0n;
340
- } catch (e5) {
482
+ } catch (e6) {
341
483
  paid = 0n;
342
484
  }
343
485
  if (paid < required) {
@@ -377,13 +519,13 @@ function rpcFailed(nonce) {
377
519
 
378
520
  function assertAlgorandWallet(wallet, network) {
379
521
  if (typeof wallet !== "object" || wallet === null) {
380
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
522
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
381
523
  `chain ${network} is Algorand; wallet must be { key } (25-word mnemonic) or { account }.`
382
524
  );
383
525
  }
384
- _chunkQONQSZHJcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Algorand");
526
+ _chunk6XTNI2OQcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Algorand");
385
527
  if (!("key" in wallet) && !("account" in wallet)) {
386
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
528
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
387
529
  `chain ${network} is Algorand; wallet must be { key } (25-word mnemonic) or { account }.`
388
530
  );
389
531
  }
@@ -398,13 +540,13 @@ function resolveAlgorandWallet(config) {
398
540
  const { addr, sk } = _algosdk2.default.mnemonicToSecretKey(config.key);
399
541
  return { addr: addr.toString(), sk };
400
542
  } catch (cause) {
401
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
543
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
402
544
  "Algorand wallet { key } is not a valid 25-word Algorand mnemonic.",
403
545
  { cause }
404
546
  );
405
547
  }
406
548
  }
407
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)("Algorand wallet needs { key } (25-word mnemonic) or { account }.");
549
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)("Algorand wallet needs { key } (25-word mnemonic) or { account }.");
408
550
  }
409
551
 
410
552
  // src/drivers/algorand/index.ts
@@ -450,12 +592,12 @@ function makeAlgorandNetwork(preset, algodUrl) {
450
592
  const settleClient = {
451
593
  async simulate(signedGroup) {
452
594
  const resp = await algod.simulateRawTransactions(signedGroup).do();
453
- const fm = _optionalChain([resp, 'optionalAccess', _12 => _12.txnGroups, 'optionalAccess', _13 => _13[0], 'optionalAccess', _14 => _14.failureMessage]);
595
+ const fm = _optionalChain([resp, 'optionalAccess', _23 => _23.txnGroups, 'optionalAccess', _24 => _24[0], 'optionalAccess', _25 => _25.failureMessage]);
454
596
  return { failureMessage: fm && fm.length > 0 ? fm : null };
455
597
  },
456
598
  async submit(signedGroup) {
457
599
  const res = await algod.sendRawTransaction(signedGroup).do();
458
- return _nullishCoalesce(_optionalChain([res, 'optionalAccess', _15 => _15.txid]), () => ( ""));
600
+ return _nullishCoalesce(_optionalChain([res, 'optionalAccess', _26 => _26.txid]), () => ( ""));
459
601
  },
460
602
  async waitForConfirmation(txid) {
461
603
  const info = await _algosdk2.default.waitForConfirmation(algod, txid, 10);
@@ -472,7 +614,7 @@ function makeAlgorandNetwork(preset, algodUrl) {
472
614
  // spec id to the driver still matches. Mirrors TON's legacy-id tolerance; the
473
615
  // normalizeNetwork alias remains the canonical seam. We still EMIT the padded form —
474
616
  // changing that would break every deployed PipRail 2.x buyer, so it waits for a major.
475
- supports: (n) => n === network || n === _chunkV2IJ5HUWcjs.ALGORAND_SPEC_CAIP2,
617
+ supports: (n) => n === network || n === _chunkMZAJQYM3cjs.ALGORAND_SPEC_CAIP2,
476
618
  resolveToken(token) {
477
619
  if (token === "native") {
478
620
  return { asset: "native", decimals: ALGO_DECIMALS, symbol: ALGO_SYMBOL };
@@ -481,16 +623,16 @@ function makeAlgorandNetwork(preset, algodUrl) {
481
623
  const info = preset.tokens[token.toUpperCase()];
482
624
  if (!info) {
483
625
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
484
- throw new (0, _chunkQONQSZHJcjs.UnknownTokenError)(
626
+ throw new (0, _chunk6XTNI2OQcjs.UnknownTokenError)(
485
627
  `token "${token}" isn't built in for Algorand (known: ${known}). Pass { assetId, decimals } for a custom ASA, or use 'native'.`
486
628
  );
487
629
  }
488
630
  return { asset: algorandAssetId(info.assetId), decimals: info.decimals, symbol: info.symbol };
489
631
  }
490
- _chunkQONQSZHJcjs.rejectForeignToken.call(void 0, token, "algorand", network);
632
+ _chunk6XTNI2OQcjs.rejectForeignToken.call(void 0, token, "algorand", network);
491
633
  const t = token;
492
634
  if (typeof t.assetId !== "number" || typeof t.decimals !== "number") {
493
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
635
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
494
636
  `chain ${network} is Algorand; a custom token must be { assetId, decimals }.`
495
637
  );
496
638
  }
@@ -511,12 +653,12 @@ function makeAlgorandNetwork(preset, algodUrl) {
511
653
  },
512
654
  assertValidPayTo(payTo) {
513
655
  if (payTo.startsWith("0x")) {
514
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
656
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
515
657
  `chain ${network} is Algorand, but payTo "${payTo}" looks like an EVM address.`
516
658
  );
517
659
  }
518
660
  if (!_algosdk2.default.isValidAddress(payTo)) {
519
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
661
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
520
662
  `chain ${network} is Algorand, but payTo "${payTo}" is not a valid Algorand address.`
521
663
  );
522
664
  }
@@ -533,14 +675,14 @@ function makeAlgorandNetwork(preset, algodUrl) {
533
675
  const info = await _algosdk2.default.waitForConfirmation(algod, ref, 10);
534
676
  return { height: String(_nullishCoalesce(info.confirmedRound, () => ( 0))) };
535
677
  } catch (err) {
536
- throw new (0, _chunkQONQSZHJcjs.ConfirmationTimeoutError)(`Algorand tx ${ref} did not confirm in time.`, {
678
+ throw new (0, _chunk6XTNI2OQcjs.ConfirmationTimeoutError)(`Algorand tx ${ref} did not confirm in time.`, {
537
679
  cause: err
538
680
  });
539
681
  }
540
682
  },
541
683
  async estimateCost(accept) {
542
684
  if (accept.scheme === "exact") {
543
- return _chunkQONQSZHJcjs.nativeCost.call(void 0, {
685
+ return _chunk6XTNI2OQcjs.nativeCost.call(void 0, {
544
686
  symbol: ALGO_SYMBOL,
545
687
  decimals: ALGO_DECIMALS,
546
688
  fee: 0n,
@@ -548,7 +690,7 @@ function makeAlgorandNetwork(preset, algodUrl) {
548
690
  detail: "gasless \u2014 the fee payer (facilitator/relayer) pools the group fee; the buyer pays 0 ALGO"
549
691
  });
550
692
  }
551
- return _chunkQONQSZHJcjs.nativeCost.call(void 0, {
693
+ return _chunk6XTNI2OQcjs.nativeCost.call(void 0, {
552
694
  symbol: ALGO_SYMBOL,
553
695
  decimals: ALGO_DECIMALS,
554
696
  fee: 1000n,
@@ -556,17 +698,22 @@ function makeAlgorandNetwork(preset, algodUrl) {
556
698
  detail: "min fee 1000 \xB5Algos (1 transaction)"
557
699
  });
558
700
  },
701
+ /** The bound wallet's own address — where THIS wallet gets paid. Derived from the key
702
+ * material only: no RPC, nothing moved. See {@link ResolvedNetwork.addressOf}. */
703
+ async addressOf(wallet) {
704
+ return String(resolveAlgorandWallet(wallet._native).addr);
705
+ },
559
706
  async balanceOf(wallet, asset) {
560
707
  let owner;
561
708
  try {
562
709
  owner = resolveAlgorandWallet(wallet._native).addr;
563
- } catch (e6) {
710
+ } catch (e7) {
564
711
  return { token: null, native: null };
565
712
  }
566
713
  let info;
567
714
  try {
568
715
  info = await algod.accountInformation(owner).do();
569
- } catch (e7) {
716
+ } catch (e8) {
570
717
  return { token: null, native: null };
571
718
  }
572
719
  const native = info.amount != null ? BigInt(info.amount) : null;
@@ -584,12 +731,20 @@ function makeAlgorandNetwork(preset, algodUrl) {
584
731
  const optedIn = (_nullishCoalesce(info.assets, () => ( []))).some((a) => Number(a.assetId) === assetId);
585
732
  return optedIn ? { ready: true } : { ready: false, reason: "NOT_OPTED_IN" };
586
733
  } catch (e) {
587
- if (/does not exist|no accounts found|404|account not found/i.test(String(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _16 => _16.message]), () => ( e))))) {
734
+ if (/does not exist|no accounts found|404|account not found/i.test(String(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _27 => _27.message]), () => ( e))))) {
588
735
  return { ready: false, reason: "NOT_OPTED_IN" };
589
736
  }
590
737
  return { ready: "unknown" };
591
738
  }
592
739
  },
740
+ /* ---- swap (OPTIONAL, opt-in): via Vestige, keyless + no integrator fee. See ./swap.ts ---- */
741
+ async quoteSwap({ from, to, wantAmount, slippageBps }) {
742
+ return quoteAlgorandSwap({ network, from, to, wantAmount, slippageBps });
743
+ },
744
+ async swap(wallet, quote) {
745
+ const signer = resolveAlgorandWallet(wallet._native);
746
+ return swapAlgorand({ algosdk: _algosdk2.default, algod, signer, quote });
747
+ },
593
748
  async verify(_ref, accept) {
594
749
  return verifyAlgorand({ reader, accept });
595
750
  },
@@ -635,7 +790,7 @@ function makeAlgorandNetwork(preset, algodUrl) {
635
790
  if (!fp && relayer) {
636
791
  try {
637
792
  fp = resolveAlgorandWallet(relayer._native).addr;
638
- } catch (e8) {
793
+ } catch (e9) {
639
794
  return null;
640
795
  }
641
796
  }
@@ -679,7 +834,7 @@ function adaptTxn(raw) {
679
834
  function decodeNote(bytes) {
680
835
  try {
681
836
  return new TextDecoder().decode(bytes);
682
- } catch (e9) {
837
+ } catch (e10) {
683
838
  return void 0;
684
839
  }
685
840
  }