@piprail/sdk 2.7.0 → 2.8.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.
@@ -8,7 +8,7 @@ import {
8
8
  nativeCost,
9
9
  rejectForeignToken,
10
10
  toInsufficientFundsError
11
- } from "./chunk-7XK22JSQ.js";
11
+ } from "./chunk-W3HOMXOF.js";
12
12
 
13
13
  // src/drivers/solana/index.ts
14
14
  import { Connection, PublicKey as PublicKey3 } from "@solana/web3.js";
@@ -221,6 +221,8 @@ import {
221
221
  import bs58 from "bs58";
222
222
  var COMPUTE_UNIT_LIMIT = 2e4;
223
223
  var COMPUTE_UNIT_PRICE_MICROLAMPORTS = 1;
224
+ var MEMO_PROGRAM_ID = new PublicKey2("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr");
225
+ var MAX_MEMO_BYTES = 256;
224
226
  var MAX_COMPUTE_UNIT_LIMIT = 300000n;
225
227
  var MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 100000n;
226
228
  var CB_SET_UNIT_LIMIT = 2;
@@ -231,6 +233,32 @@ function tokenProgramFor(accept) {
231
233
  function isEmptySig(sig) {
232
234
  return !sig || sig.every((b) => b === 0);
233
235
  }
236
+ function memoRandomNonce() {
237
+ const g = globalThis.crypto;
238
+ if (!g?.getRandomValues) {
239
+ throw new UnsupportedSchemeError(
240
+ "this runtime lacks Web Crypto (globalThis.crypto.getRandomValues); SVM exact needs a CSPRNG nonce."
241
+ );
242
+ }
243
+ const raw = new Uint8Array(16);
244
+ g.getRandomValues(raw);
245
+ return Buffer.from([...raw].map((b) => b.toString(16).padStart(2, "0")).join(""), "utf8");
246
+ }
247
+ function memoDataFor(accept) {
248
+ if (accept.extra.memo !== void 0) {
249
+ const bytes = Buffer.from(accept.extra.memo, "utf8");
250
+ if (bytes.length > MAX_MEMO_BYTES) {
251
+ throw new UnsupportedSchemeError(
252
+ `SVM exact: extra.memo is ${bytes.length} bytes; the scheme caps it at ${MAX_MEMO_BYTES}.`
253
+ );
254
+ }
255
+ return bytes;
256
+ }
257
+ return memoRandomNonce();
258
+ }
259
+ function memoInstruction(accept) {
260
+ return new TransactionInstruction({ programId: MEMO_PROGRAM_ID, keys: [], data: memoDataFor(accept) });
261
+ }
234
262
  async function payExactSolana(input) {
235
263
  const { connection, keypair, accept } = input;
236
264
  if (accept.asset === "native") {
@@ -275,6 +303,7 @@ async function payExactSolana(input) {
275
303
  `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.`
276
304
  );
277
305
  }
306
+ const memoIx = memoInstruction(accept);
278
307
  const instructions = [
279
308
  ComputeBudgetProgram.setComputeUnitLimit({ units: COMPUTE_UNIT_LIMIT }),
280
309
  ComputeBudgetProgram.setComputeUnitPrice({ microLamports: COMPUTE_UNIT_PRICE_MICROLAMPORTS }),
@@ -287,7 +316,9 @@ async function payExactSolana(input) {
287
316
  accept.extra.decimals,
288
317
  [],
289
318
  program
290
- )
319
+ ),
320
+ memoIx
321
+ // [3] SPL-Memo (scheme MUST); keeps the tx at 4 ix, inside Path-1's 3-to-7.
291
322
  ];
292
323
  const { blockhash } = await connection.getLatestBlockhash();
293
324
  const message = new TransactionMessage({
@@ -12,7 +12,7 @@ import {
12
12
  parseUnits,
13
13
  rejectForeignToken,
14
14
  toInsufficientFundsError
15
- } from "./chunk-7XK22JSQ.js";
15
+ } from "./chunk-W3HOMXOF.js";
16
16
 
17
17
  // src/drivers/stellar/index.ts
18
18
  import { Horizon, StrKey as StrKey2 } from "@stellar/stellar-sdk";
@@ -12,7 +12,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
12
12
 
13
13
 
14
14
 
15
- var _chunkJG6KRAW6cjs = require('./chunk-JG6KRAW6.cjs');
15
+ var _chunkVPENSVOIcjs = require('./chunk-VPENSVOI.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, _chunkJG6KRAW6cjs.RecipientNotReadyError)(
101
+ return new (0, _chunkVPENSVOIcjs.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, _chunkJG6KRAW6cjs.RecipientNotReadyError)(
107
+ return new (0, _chunkVPENSVOIcjs.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, _chunkJG6KRAW6cjs.InsufficientFundsError)(
113
+ return new (0, _chunkVPENSVOIcjs.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, _chunkJG6KRAW6cjs.InsufficientFundsError)(
119
+ return new (0, _chunkVPENSVOIcjs.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(_chunkJG6KRAW6cjs.toInsufficientFundsError.call(void 0, err), () => ( err));
124
+ return _nullishCoalesce(_chunkVPENSVOIcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
125
125
  }
126
126
  function isAccountNotFound(err) {
127
127
  const e = err;
@@ -218,7 +218,7 @@ function assetMatches(p, want) {
218
218
  }
219
219
  function parseAmount(amount, decimals) {
220
220
  try {
221
- return _chunkJG6KRAW6cjs.parseUnits.call(void 0, amount, decimals);
221
+ return _chunkVPENSVOIcjs.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, _chunkJG6KRAW6cjs.WrongFamilyError)(
245
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
246
246
  `chain ${network} is Stellar; wallet must be { key } (S\u2026 seed) or { keypair }.`
247
247
  );
248
248
  }
249
- _chunkJG6KRAW6cjs.assertNoLegacyWalletKey.call(void 0, wallet, "Stellar");
249
+ _chunkVPENSVOIcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Stellar");
250
250
  if (!("key" in wallet) && !("keypair" in wallet)) {
251
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
251
+ throw new (0, _chunkVPENSVOIcjs.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, _chunkJG6KRAW6cjs.WrongFamilyError)("Stellar wallet { key } is not a valid S\u2026 secret seed.");
261
+ throw new (0, _chunkVPENSVOIcjs.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, _chunkJG6KRAW6cjs.WrongFamilyError)("Stellar wallet needs { key } (S\u2026 seed) or { keypair }.");
265
+ throw new (0, _chunkVPENSVOIcjs.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, _chunkJG6KRAW6cjs.UnknownTokenError)(
320
+ throw new (0, _chunkVPENSVOIcjs.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
- _chunkJG6KRAW6cjs.rejectForeignToken.call(void 0, token, "stellar", network);
330
+ _chunkVPENSVOIcjs.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, _chunkJG6KRAW6cjs.WrongFamilyError)(
333
+ throw new (0, _chunkVPENSVOIcjs.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, _chunkJG6KRAW6cjs.WrongFamilyError)(
354
+ throw new (0, _chunkVPENSVOIcjs.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, _chunkJG6KRAW6cjs.WrongFamilyError)(
359
+ throw new (0, _chunkVPENSVOIcjs.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, _chunkJG6KRAW6cjs.ConfirmationTimeoutError)(`Stellar tx ${ref} not visible on Horizon in time.`);
380
+ throw new (0, _chunkVPENSVOIcjs.ConfirmationTimeoutError)(`Stellar tx ${ref} not visible on Horizon in time.`);
381
381
  },
382
382
  async estimateCost() {
383
- return _chunkJG6KRAW6cjs.nativeCost.call(void 0, {
383
+ return _chunkVPENSVOIcjs.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 ? _chunkJG6KRAW6cjs.parseUnits.call(void 0, s, STELLAR_DECIMALS) : 0n;
407
+ return s != null ? _chunkVPENSVOIcjs.parseUnits.call(void 0, s, STELLAR_DECIMALS) : 0n;
408
408
  } catch (e7) {
409
409
  return 0n;
410
410
  }
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
 
10
- var _chunkJG6KRAW6cjs = require('./chunk-JG6KRAW6.cjs');
10
+ var _chunkVPENSVOIcjs = require('./chunk-VPENSVOI.cjs');
11
11
 
12
12
  // src/drivers/sui/index.ts
13
13
  var _jsonRpc = require('@mysten/sui/jsonRpc');
@@ -46,7 +46,7 @@ async function paySui(params) {
46
46
  } else {
47
47
  const coins = await client.getCoins({ owner: sender, coinType: accept.asset });
48
48
  if (!coins.data.length) {
49
- throw new (0, _chunkJG6KRAW6cjs.InsufficientFundsError)(
49
+ throw new (0, _chunkVPENSVOIcjs.InsufficientFundsError)(
50
50
  `Sui wallet holds no ${accept.asset} coin objects to pay from.`
51
51
  );
52
52
  }
@@ -65,14 +65,14 @@ async function paySui(params) {
65
65
  });
66
66
  return res.digest;
67
67
  } catch (err) {
68
- if (err instanceof _chunkJG6KRAW6cjs.InsufficientFundsError) throw err;
68
+ if (err instanceof _chunkVPENSVOIcjs.InsufficientFundsError) throw err;
69
69
  if (isSuiAffordability(err)) {
70
- throw new (0, _chunkJG6KRAW6cjs.InsufficientFundsError)(
70
+ throw new (0, _chunkVPENSVOIcjs.InsufficientFundsError)(
71
71
  err instanceof Error ? err.message : "Insufficient SUI/coin balance for the payment.",
72
72
  { cause: err }
73
73
  );
74
74
  }
75
- throw _nullishCoalesce(_chunkJG6KRAW6cjs.toInsufficientFundsError.call(void 0, err), () => ( err));
75
+ throw _nullishCoalesce(_chunkVPENSVOIcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
76
76
  }
77
77
  }
78
78
  function isSuiAffordability(err) {
@@ -152,13 +152,13 @@ function txNotFound(digest) {
152
152
  var _ed25519 = require('@mysten/sui/keypairs/ed25519');
153
153
  function assertSuiWallet(wallet, network) {
154
154
  if (typeof wallet !== "object" || wallet === null) {
155
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
155
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
156
156
  `chain ${network} is Sui; wallet must be { key } (suiprivkey1\u2026 ) or { keypair }.`
157
157
  );
158
158
  }
159
- _chunkJG6KRAW6cjs.assertNoLegacyWalletKey.call(void 0, wallet, "Sui");
159
+ _chunkVPENSVOIcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Sui");
160
160
  if (!("key" in wallet) && !("keypair" in wallet)) {
161
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
161
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
162
162
  `chain ${network} is Sui; wallet must be { key } (suiprivkey1\u2026) or { keypair }.`
163
163
  );
164
164
  }
@@ -170,13 +170,13 @@ function resolveSuiKeypair(config) {
170
170
  try {
171
171
  return _ed25519.Ed25519Keypair.fromSecretKey(config.key);
172
172
  } catch (cause) {
173
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
173
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
174
174
  "Sui wallet { key } is not a valid suiprivkey1\u2026 secret (or 32-byte key).",
175
175
  { cause }
176
176
  );
177
177
  }
178
178
  }
179
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)("Sui wallet needs { key } (suiprivkey1\u2026) or { keypair }.");
179
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)("Sui wallet needs { key } (suiprivkey1\u2026) or { keypair }.");
180
180
  }
181
181
 
182
182
  // src/drivers/sui/index.ts
@@ -228,16 +228,16 @@ function makeSuiNetwork(preset, rpcUrl) {
228
228
  const info = preset.tokens[token.toUpperCase()];
229
229
  if (!info) {
230
230
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
231
- throw new (0, _chunkJG6KRAW6cjs.UnknownTokenError)(
231
+ throw new (0, _chunkVPENSVOIcjs.UnknownTokenError)(
232
232
  `token "${token}" isn't built in for Sui (known: ${known}). Note: no native USDT on Sui. Pass { coinType, decimals } for a custom coin, or use 'native'.`
233
233
  );
234
234
  }
235
235
  return { asset: info.coinType, decimals: info.decimals, symbol: info.symbol };
236
236
  }
237
- _chunkJG6KRAW6cjs.rejectForeignToken.call(void 0, token, "sui", network);
237
+ _chunkVPENSVOIcjs.rejectForeignToken.call(void 0, token, "sui", network);
238
238
  const t = token;
239
239
  if (!t.coinType || typeof t.decimals !== "number") {
240
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
240
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
241
241
  `chain ${network} is Sui; a custom token must be { coinType, decimals }.`
242
242
  );
243
243
  }
@@ -256,7 +256,7 @@ function makeSuiNetwork(preset, rpcUrl) {
256
256
  },
257
257
  assertValidPayTo(payTo) {
258
258
  if (!_utils.isValidSuiAddress.call(void 0, payTo)) {
259
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
259
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
260
260
  `chain ${network} is Sui, but payTo "${payTo}" is not a valid Sui address (0x + 32 bytes).`
261
261
  );
262
262
  }
@@ -273,11 +273,11 @@ function makeSuiNetwork(preset, rpcUrl) {
273
273
  const tx = await client.waitForTransaction({ digest: ref, options: { showEffects: true } });
274
274
  return { height: String(_nullishCoalesce(tx.checkpoint, () => ( "0"))) };
275
275
  } catch (err) {
276
- throw new (0, _chunkJG6KRAW6cjs.ConfirmationTimeoutError)(`Sui tx ${ref} did not finalize in time.`, { cause: err });
276
+ throw new (0, _chunkVPENSVOIcjs.ConfirmationTimeoutError)(`Sui tx ${ref} did not finalize in time.`, { cause: err });
277
277
  }
278
278
  },
279
279
  async estimateCost() {
280
- return _chunkJG6KRAW6cjs.nativeCost.call(void 0, {
280
+ return _chunkVPENSVOIcjs.nativeCost.call(void 0, {
281
281
  symbol: SUI_SYMBOL,
282
282
  decimals: SUI_DECIMALS,
283
283
  fee: 3000000n,
@@ -7,7 +7,7 @@ import {
7
7
  nativeCost,
8
8
  rejectForeignToken,
9
9
  toInsufficientFundsError
10
- } from "./chunk-7XK22JSQ.js";
10
+ } from "./chunk-W3HOMXOF.js";
11
11
 
12
12
  // src/drivers/sui/index.ts
13
13
  import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
@@ -9,16 +9,17 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
9
9
 
10
10
 
11
11
 
12
- var _chunkJG6KRAW6cjs = require('./chunk-JG6KRAW6.cjs');
12
+ var _chunkVPENSVOIcjs = require('./chunk-VPENSVOI.cjs');
13
13
 
14
14
  // src/drivers/ton/index.ts
15
15
  var _core = require('@ton/core');
16
16
  var _ton = require('@ton/ton');
17
17
 
18
18
  // src/drivers/ton/chains.ts
19
+ var TON_NATIVE_SYMBOL = "GRAM";
19
20
  var TON_DECIMALS = 9;
20
21
  var TON_MAINNET = {
21
- caip2: "ton:-239",
22
+ caip2: "tvm:-239",
22
23
  defaultRpc: "https://toncenter.com/api/v2/jsonRPC",
23
24
  tokens: {
24
25
  // USD₮ (Tether) — native, dominant stablecoin on TON. Master + 6 decimals
@@ -75,7 +76,7 @@ async function waitForSeqno(opened, from, { tries = 30, intervalMs = 2e3 } = {})
75
76
  }
76
77
  if (current > from) return;
77
78
  }
78
- throw new (0, _chunkJG6KRAW6cjs.ConfirmationTimeoutError)(
79
+ throw new (0, _chunkVPENSVOIcjs.ConfirmationTimeoutError)(
79
80
  `TON wallet seqno did not advance past ${from} \u2014 the payment may not have been accepted.`
80
81
  );
81
82
  }
@@ -203,13 +204,13 @@ var _crypto = require('@ton/crypto');
203
204
 
204
205
  function assertTonWallet(wallet, network) {
205
206
  if (typeof wallet !== "object" || wallet === null) {
206
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
207
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
207
208
  `chain ${network} is TON; wallet must be { key } (24-word mnemonic) or { keyPair }.`
208
209
  );
209
210
  }
210
- _chunkJG6KRAW6cjs.assertNoLegacyWalletKey.call(void 0, wallet, "TON");
211
+ _chunkVPENSVOIcjs.assertNoLegacyWalletKey.call(void 0, wallet, "TON");
211
212
  if (!("key" in wallet) && !("keyPair" in wallet)) {
212
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
213
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
213
214
  `chain ${network} is TON; wallet must be { key } (24-word mnemonic) or { keyPair }.`
214
215
  );
215
216
  }
@@ -220,13 +221,13 @@ async function resolveTonWallet(config) {
220
221
  let keyPair;
221
222
  if (config.key) {
222
223
  if (typeof config.key !== "string" && !Array.isArray(config.key)) {
223
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
224
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
224
225
  "chain is TON; the wallet { key } must be a 24-word mnemonic (a string or string[])."
225
226
  );
226
227
  }
227
228
  const words = Array.isArray(config.key) ? config.key : config.key.trim().split(/\s+/);
228
229
  if (!await _crypto.mnemonicValidate.call(void 0, words)) {
229
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
230
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
230
231
  "chain is TON; the wallet { key } is not a valid TON mnemonic (expected 24 words from the TON/BIP-39 wordlist)."
231
232
  );
232
233
  }
@@ -234,7 +235,7 @@ async function resolveTonWallet(config) {
234
235
  } else if (config.keyPair) {
235
236
  keyPair = config.keyPair;
236
237
  } else {
237
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)("TON wallet needs { key } (24-word mnemonic) or { keyPair }.");
238
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)("TON wallet needs { key } (24-word mnemonic) or { keyPair }.");
238
239
  }
239
240
  const contract = version === "v5r1" ? _ton.WalletContractV5R1.create({ workchain: 0, publicKey: keyPair.publicKey }) : _ton.WalletContractV4.create({ workchain: 0, publicKey: keyPair.publicKey });
240
241
  return { keyPair, contract };
@@ -268,24 +269,27 @@ function makeTonNetwork(preset, rpcUrl) {
268
269
  return {
269
270
  family: "ton",
270
271
  network,
271
- supports: (n) => n === network,
272
+ // Accept the canonical `tvm:-239` and the legacy `ton:-239` directly, so a
273
+ // caller that bypasses `normalizeNetwork` and hands the raw legacy id to the
274
+ // driver still matches. The normalizeNetwork alias is the canonical seam.
275
+ supports: (n) => n === network || n === "ton:-239",
272
276
  resolveToken(token) {
273
277
  if (token === "native") {
274
- return { asset: "native", decimals: TON_DECIMALS, symbol: "TON" };
278
+ return { asset: "native", decimals: TON_DECIMALS, symbol: TON_NATIVE_SYMBOL };
275
279
  }
276
280
  if (typeof token === "string") {
277
281
  const info = preset.tokens[token.toUpperCase()];
278
282
  if (!info) {
279
283
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
280
- throw new (0, _chunkJG6KRAW6cjs.UnknownTokenError)(
284
+ throw new (0, _chunkVPENSVOIcjs.UnknownTokenError)(
281
285
  `token "${token}" isn't built in for TON (known: ${known}). Note: native USDC doesn't exist on TON. Pass { master, decimals } for a custom jetton, or use 'native'.`
282
286
  );
283
287
  }
284
288
  return { asset: info.master, decimals: info.decimals, symbol: info.symbol };
285
289
  }
286
- _chunkJG6KRAW6cjs.rejectForeignToken.call(void 0, token, "ton", network);
290
+ _chunkVPENSVOIcjs.rejectForeignToken.call(void 0, token, "ton", network);
287
291
  if (!("master" in token)) {
288
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
292
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
289
293
  `chain ${network} is TON; a custom token must be { master, decimals }.`
290
294
  );
291
295
  }
@@ -296,7 +300,7 @@ function makeTonNetwork(preset, rpcUrl) {
296
300
  };
297
301
  },
298
302
  describeAsset(asset) {
299
- if (asset === "native") return { symbol: "TON", decimals: TON_DECIMALS };
303
+ if (asset === "native") return { symbol: TON_NATIVE_SYMBOL, decimals: TON_DECIMALS };
300
304
  for (const info of Object.values(preset.tokens)) {
301
305
  if (info.master === asset) return { symbol: info.symbol, decimals: info.decimals };
302
306
  }
@@ -304,14 +308,14 @@ function makeTonNetwork(preset, rpcUrl) {
304
308
  },
305
309
  assertValidPayTo(payTo) {
306
310
  if (payTo.startsWith("0x")) {
307
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
311
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
308
312
  `chain ${network} is TON, but payTo "${payTo}" looks like an EVM address.`
309
313
  );
310
314
  }
311
315
  try {
312
316
  _core.Address.parse(payTo);
313
317
  } catch (e6) {
314
- throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
318
+ throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
315
319
  `chain ${network} is TON, but payTo "${payTo}" is not a valid TON address.`
316
320
  );
317
321
  }
@@ -327,7 +331,7 @@ function makeTonNetwork(preset, rpcUrl) {
327
331
  const watch = await watchAccountFor(accept);
328
332
  return encodeRef(watch, accept.extra.nonce);
329
333
  } catch (err) {
330
- throw _nullishCoalesce(_chunkJG6KRAW6cjs.toInsufficientFundsError.call(void 0, err), () => ( err));
334
+ throw _nullishCoalesce(_chunkVPENSVOIcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
331
335
  }
332
336
  },
333
337
  async confirm(ref) {
@@ -346,12 +350,12 @@ function makeTonNetwork(preset, rpcUrl) {
346
350
  if (inc && inc.comment === nonce) return { height: tx.lt.toString() };
347
351
  }
348
352
  }
349
- throw new (0, _chunkJG6KRAW6cjs.ConfirmationTimeoutError)(`TON payment for nonce ${nonce} did not settle in time.`);
353
+ throw new (0, _chunkVPENSVOIcjs.ConfirmationTimeoutError)(`TON payment for nonce ${nonce} did not settle in time.`);
350
354
  },
351
355
  async estimateCost(accept) {
352
356
  const fee = accept.asset === "native" ? 10000000n : 50000000n;
353
- const detail = accept.asset === "native" ? "~0.01 TON network fee" : "~0.05 TON attached for the jetton transfer (leftover refunded)";
354
- return _chunkJG6KRAW6cjs.nativeCost.call(void 0, { symbol: "TON", decimals: TON_DECIMALS, fee, basis: "heuristic", detail });
357
+ const detail = accept.asset === "native" ? `~0.01 ${TON_NATIVE_SYMBOL} network fee` : `~0.05 ${TON_NATIVE_SYMBOL} attached for the jetton transfer (leftover refunded)`;
358
+ return _chunkVPENSVOIcjs.nativeCost.call(void 0, { symbol: TON_NATIVE_SYMBOL, decimals: TON_DECIMALS, fee, basis: "heuristic", detail });
355
359
  },
356
360
  async balanceOf(wallet, asset) {
357
361
  let owner;
@@ -9,16 +9,17 @@ import {
9
9
  nativeCost,
10
10
  rejectForeignToken,
11
11
  toInsufficientFundsError
12
- } from "./chunk-7XK22JSQ.js";
12
+ } from "./chunk-W3HOMXOF.js";
13
13
 
14
14
  // src/drivers/ton/index.ts
15
15
  import { Address as Address2 } from "@ton/core";
16
16
  import { JettonMaster, TonClient } from "@ton/ton";
17
17
 
18
18
  // src/drivers/ton/chains.ts
19
+ var TON_NATIVE_SYMBOL = "GRAM";
19
20
  var TON_DECIMALS = 9;
20
21
  var TON_MAINNET = {
21
- caip2: "ton:-239",
22
+ caip2: "tvm:-239",
22
23
  defaultRpc: "https://toncenter.com/api/v2/jsonRPC",
23
24
  tokens: {
24
25
  // USD₮ (Tether) — native, dominant stablecoin on TON. Master + 6 decimals
@@ -268,10 +269,13 @@ function makeTonNetwork(preset, rpcUrl) {
268
269
  return {
269
270
  family: "ton",
270
271
  network,
271
- supports: (n) => n === network,
272
+ // Accept the canonical `tvm:-239` and the legacy `ton:-239` directly, so a
273
+ // caller that bypasses `normalizeNetwork` and hands the raw legacy id to the
274
+ // driver still matches. The normalizeNetwork alias is the canonical seam.
275
+ supports: (n) => n === network || n === "ton:-239",
272
276
  resolveToken(token) {
273
277
  if (token === "native") {
274
- return { asset: "native", decimals: TON_DECIMALS, symbol: "TON" };
278
+ return { asset: "native", decimals: TON_DECIMALS, symbol: TON_NATIVE_SYMBOL };
275
279
  }
276
280
  if (typeof token === "string") {
277
281
  const info = preset.tokens[token.toUpperCase()];
@@ -296,7 +300,7 @@ function makeTonNetwork(preset, rpcUrl) {
296
300
  };
297
301
  },
298
302
  describeAsset(asset) {
299
- if (asset === "native") return { symbol: "TON", decimals: TON_DECIMALS };
303
+ if (asset === "native") return { symbol: TON_NATIVE_SYMBOL, decimals: TON_DECIMALS };
300
304
  for (const info of Object.values(preset.tokens)) {
301
305
  if (info.master === asset) return { symbol: info.symbol, decimals: info.decimals };
302
306
  }
@@ -350,8 +354,8 @@ function makeTonNetwork(preset, rpcUrl) {
350
354
  },
351
355
  async estimateCost(accept) {
352
356
  const fee = accept.asset === "native" ? 10000000n : 50000000n;
353
- const detail = accept.asset === "native" ? "~0.01 TON network fee" : "~0.05 TON attached for the jetton transfer (leftover refunded)";
354
- return nativeCost({ symbol: "TON", decimals: TON_DECIMALS, fee, basis: "heuristic", detail });
357
+ const detail = accept.asset === "native" ? `~0.01 ${TON_NATIVE_SYMBOL} network fee` : `~0.05 ${TON_NATIVE_SYMBOL} attached for the jetton transfer (leftover refunded)`;
358
+ return nativeCost({ symbol: TON_NATIVE_SYMBOL, decimals: TON_DECIMALS, fee, basis: "heuristic", detail });
355
359
  },
356
360
  async balanceOf(wallet, asset) {
357
361
  let owner;