@piprail/sdk 1.3.1 → 1.5.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.
@@ -11,7 +11,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
11
11
 
12
12
 
13
13
 
14
- var _chunkYJPWIK5Lcjs = require('./chunk-YJPWIK5L.cjs');
14
+ var _chunkIQGT65WScjs = require('./chunk-IQGT65WS.cjs');
15
15
 
16
16
  // src/drivers/stellar/index.ts
17
17
  var _stellarsdk = require('@stellar/stellar-sdk');
@@ -97,30 +97,30 @@ function mapSubmitError(err) {
97
97
  const seen = codes.join(", ");
98
98
  const has = (re) => codes.some((c) => re.test(c));
99
99
  if (has(/op_no_destination/i)) {
100
- return new (0, _chunkYJPWIK5Lcjs.RecipientNotReadyError)(
100
+ return new (0, _chunkIQGT65WScjs.RecipientNotReadyError)(
101
101
  `Stellar destination account doesn't exist yet \u2014 create it with \u22651 XLM (the base reserve) before it can receive. (Stellar: ${seen})`,
102
102
  { cause: err }
103
103
  );
104
104
  }
105
105
  if (has(/op_(no_trust|line_full|not_authorized)/i) && !has(/src_no_trust/i)) {
106
- return new (0, _chunkYJPWIK5Lcjs.RecipientNotReadyError)(
106
+ return new (0, _chunkIQGT65WScjs.RecipientNotReadyError)(
107
107
  `Stellar destination can't hold this asset \u2014 it needs a trustline for it (and to be authorized) before it can receive. (Stellar: ${seen})`,
108
108
  { cause: err }
109
109
  );
110
110
  }
111
111
  if (has(/underfunded|insufficient|low_reserve|src_no_trust/i)) {
112
- return new (0, _chunkYJPWIK5Lcjs.InsufficientFundsError)(
112
+ return new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
113
113
  `Stellar payment failed: the sender can't cover it \u2014 balance, base reserve, or no trustline to send this asset. (Stellar: ${seen})`,
114
114
  { cause: err }
115
115
  );
116
116
  }
117
117
  if (isAccountNotFound(err)) {
118
- return new (0, _chunkYJPWIK5Lcjs.InsufficientFundsError)(
118
+ return new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
119
119
  "Stellar source account not found on-chain \u2014 fund the sender (\u2265 base reserve) before it can pay.",
120
120
  { cause: err }
121
121
  );
122
122
  }
123
- return _nullishCoalesce(_chunkYJPWIK5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
123
+ return _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
124
124
  }
125
125
  function isAccountNotFound(err) {
126
126
  const e = err;
@@ -217,7 +217,7 @@ function assetMatches(p, want) {
217
217
  }
218
218
  function parseAmount(amount, decimals) {
219
219
  try {
220
- return _chunkYJPWIK5Lcjs.parseUnits.call(void 0, amount, decimals);
220
+ return _chunkIQGT65WScjs.parseUnits.call(void 0, amount, decimals);
221
221
  } catch (e4) {
222
222
  return 0n;
223
223
  }
@@ -241,22 +241,22 @@ function rpcFailed(nonce) {
241
241
 
242
242
  function assertStellarWallet(wallet, network) {
243
243
  if (typeof wallet !== "object" || wallet === null) {
244
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
244
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
245
245
  `chain ${network} is Stellar; wallet must be { secret } (S\u2026 seed) or { keypair }.`
246
246
  );
247
247
  }
248
248
  if ("privateKey" in wallet || "walletClient" in wallet) {
249
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
249
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
250
250
  `chain ${network} is Stellar; an EVM wallet can't be used \u2014 pass { secret } (S\u2026 seed) or { keypair }.`
251
251
  );
252
252
  }
253
253
  if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keyPair" in wallet) {
254
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
254
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
255
255
  `chain ${network} is Stellar; that looks like a Solana/TON wallet \u2014 pass { secret } (S\u2026 seed) or { keypair }.`
256
256
  );
257
257
  }
258
258
  if (!("secret" in wallet) && !("keypair" in wallet)) {
259
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
259
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
260
260
  `chain ${network} is Stellar; wallet must be { secret } (S\u2026 seed) or { keypair }.`
261
261
  );
262
262
  }
@@ -266,16 +266,20 @@ function resolveStellarWallet(config) {
266
266
  if (config.keypair) return config.keypair;
267
267
  if (config.secret) {
268
268
  if (!_stellarsdk.StrKey.isValidEd25519SecretSeed(config.secret)) {
269
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
269
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
270
270
  "Stellar wallet { secret } is not a valid S\u2026 secret seed."
271
271
  );
272
272
  }
273
273
  return _stellarsdk.Keypair.fromSecret(config.secret);
274
274
  }
275
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)("Stellar wallet needs { secret } (S\u2026 seed) or { keypair }.");
275
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("Stellar wallet needs { secret } (S\u2026 seed) or { keypair }.");
276
276
  }
277
277
 
278
278
  // src/drivers/stellar/index.ts
279
+ function isStellarNotFound(e) {
280
+ const x = e;
281
+ return _optionalChain([x, 'optionalAccess', _9 => _9.response, 'optionalAccess', _10 => _10.status]) === 404 || _optionalChain([x, 'optionalAccess', _11 => _11.name]) === "NotFoundError";
282
+ }
279
283
  var stellarDriver = {
280
284
  family: "stellar",
281
285
  resolve(opts) {
@@ -323,7 +327,7 @@ function makeStellarNetwork(preset, rpcUrl) {
323
327
  const info = preset.tokens[token.toUpperCase()];
324
328
  if (!info) {
325
329
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
326
- throw new (0, _chunkYJPWIK5Lcjs.UnknownTokenError)(
330
+ throw new (0, _chunkIQGT65WScjs.UnknownTokenError)(
327
331
  `token "${token}" isn't built in for Stellar (known: ${known}). Pass { issuer, code, decimals } for a custom asset, or use 'native'.`
328
332
  );
329
333
  }
@@ -333,10 +337,10 @@ function makeStellarNetwork(preset, rpcUrl) {
333
337
  symbol: info.symbol
334
338
  };
335
339
  }
336
- _chunkYJPWIK5Lcjs.rejectForeignToken.call(void 0, token, "stellar", network);
340
+ _chunkIQGT65WScjs.rejectForeignToken.call(void 0, token, "stellar", network);
337
341
  const t = token;
338
342
  if (!t.issuer || !t.code || typeof t.decimals !== "number") {
339
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
343
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
340
344
  `chain ${network} is Stellar; a custom token must be { issuer, code, decimals }.`
341
345
  );
342
346
  }
@@ -357,12 +361,12 @@ function makeStellarNetwork(preset, rpcUrl) {
357
361
  },
358
362
  assertValidPayTo(payTo) {
359
363
  if (payTo.startsWith("0x")) {
360
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
364
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
361
365
  `chain ${network} is Stellar, but payTo "${payTo}" looks like an EVM address.`
362
366
  );
363
367
  }
364
368
  if (!_stellarsdk.StrKey.isValidEd25519PublicKey(payTo)) {
365
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
369
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
366
370
  `chain ${network} is Stellar, but payTo "${payTo}" is not a valid Stellar account (G\u2026).`
367
371
  );
368
372
  }
@@ -383,10 +387,10 @@ function makeStellarNetwork(preset, rpcUrl) {
383
387
  await _chunkCQREG5LEcjs.delay.call(void 0, 1500);
384
388
  }
385
389
  }
386
- throw new (0, _chunkYJPWIK5Lcjs.ConfirmationTimeoutError)(`Stellar tx ${ref} not visible on Horizon in time.`);
390
+ throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(`Stellar tx ${ref} not visible on Horizon in time.`);
387
391
  },
388
392
  async estimateCost() {
389
- return _chunkYJPWIK5Lcjs.nativeCost.call(void 0, {
393
+ return _chunkIQGT65WScjs.nativeCost.call(void 0, {
390
394
  symbol: XLM_SYMBOL,
391
395
  decimals: STELLAR_DECIMALS,
392
396
  fee: 100n,
@@ -394,6 +398,52 @@ function makeStellarNetwork(preset, rpcUrl) {
394
398
  detail: "base fee 100 stroops (1 operation)"
395
399
  });
396
400
  },
401
+ async balanceOf(wallet, asset) {
402
+ let owner;
403
+ try {
404
+ owner = resolveStellarWallet(wallet._native).publicKey();
405
+ } catch (e6) {
406
+ return { token: null, native: null };
407
+ }
408
+ let lines;
409
+ try {
410
+ const account = await server.loadAccount(owner);
411
+ lines = account.balances;
412
+ } catch (e) {
413
+ return isStellarNotFound(e) ? { token: 0n, native: 0n } : { token: null, native: null };
414
+ }
415
+ const toBase = (s) => {
416
+ try {
417
+ return s != null ? _chunkIQGT65WScjs.parseUnits.call(void 0, s, STELLAR_DECIMALS) : 0n;
418
+ } catch (e7) {
419
+ return 0n;
420
+ }
421
+ };
422
+ const native = toBase(_optionalChain([lines, 'access', _12 => _12.find, 'call', _13 => _13((b) => b.asset_type === "native"), 'optionalAccess', _14 => _14.balance]));
423
+ if (asset === "native") return { token: native, native };
424
+ const parts = parseStellarAssetId(asset);
425
+ const line = parts ? lines.find(
426
+ (b) => (b.asset_type === "credit_alphanum4" || b.asset_type === "credit_alphanum12") && b.asset_code === parts.code && b.asset_issuer === parts.issuer
427
+ ) : void 0;
428
+ return { token: toBase(_optionalChain([line, 'optionalAccess', _15 => _15.balance])), native };
429
+ },
430
+ async recipientReady(payTo, asset) {
431
+ let lines;
432
+ try {
433
+ const account = await server.loadAccount(payTo);
434
+ lines = account.balances;
435
+ } catch (e) {
436
+ if (isStellarNotFound(e)) return { ready: false, reason: "INACTIVE" };
437
+ return { ready: "unknown" };
438
+ }
439
+ if (asset === "native") return { ready: true };
440
+ const parts = parseStellarAssetId(asset);
441
+ if (!parts) return { ready: "unknown" };
442
+ const hasTrustline = lines.some(
443
+ (b) => (b.asset_type === "credit_alphanum4" || b.asset_type === "credit_alphanum12") && b.asset_code === parts.code && b.asset_issuer === parts.issuer
444
+ );
445
+ return hasTrustline ? { ready: true } : { ready: false, reason: "NO_TRUSTLINE" };
446
+ },
397
447
  async verify(_ref, accept) {
398
448
  return verifyStellar({ reader, accept });
399
449
  }
@@ -6,7 +6,7 @@ import {
6
6
  nativeCost,
7
7
  rejectForeignToken,
8
8
  toInsufficientFundsError
9
- } from "./chunk-AGKC3C7Y.js";
9
+ } from "./chunk-QDS6FBZP.js";
10
10
 
11
11
  // src/drivers/sui/index.ts
12
12
  import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
@@ -294,6 +294,29 @@ function makeSuiNetwork(preset, rpcUrl) {
294
294
  detail: "\u22480.003 SUI (computation + storage; storage is largely rebated on success)"
295
295
  });
296
296
  },
297
+ async balanceOf(wallet, asset) {
298
+ let owner;
299
+ try {
300
+ owner = resolveSuiKeypair(wallet._native).toSuiAddress();
301
+ } catch {
302
+ return { token: null, native: null };
303
+ }
304
+ const readBal = async (coinType) => {
305
+ try {
306
+ return BigInt((await client.getBalance({ owner, coinType })).totalBalance);
307
+ } catch {
308
+ return null;
309
+ }
310
+ };
311
+ const native = await readBal("0x2::sui::SUI");
312
+ if (asset === "native") return { token: native, native };
313
+ const token = await readBal(asset);
314
+ return { token, native };
315
+ },
316
+ // No receive prerequisite — any Sui address receives SUI/coins immediately.
317
+ async recipientReady() {
318
+ return { ready: "n/a" };
319
+ },
297
320
  async verify(ref, accept) {
298
321
  return verifySui({ reader, digest: ref, accept });
299
322
  }
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- var _chunkYJPWIK5Lcjs = require('./chunk-YJPWIK5L.cjs');
9
+ var _chunkIQGT65WScjs = require('./chunk-IQGT65WS.cjs');
10
10
 
11
11
  // src/drivers/sui/index.ts
12
12
  var _jsonRpc = require('@mysten/sui/jsonRpc');
@@ -45,7 +45,7 @@ async function paySui(params) {
45
45
  } else {
46
46
  const coins = await client.getCoins({ owner: sender, coinType: accept.asset });
47
47
  if (!coins.data.length) {
48
- throw new (0, _chunkYJPWIK5Lcjs.InsufficientFundsError)(
48
+ throw new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
49
49
  `Sui wallet holds no ${accept.asset} coin objects to pay from.`
50
50
  );
51
51
  }
@@ -64,14 +64,14 @@ async function paySui(params) {
64
64
  });
65
65
  return res.digest;
66
66
  } catch (err) {
67
- if (err instanceof _chunkYJPWIK5Lcjs.InsufficientFundsError) throw err;
67
+ if (err instanceof _chunkIQGT65WScjs.InsufficientFundsError) throw err;
68
68
  if (isSuiAffordability(err)) {
69
- throw new (0, _chunkYJPWIK5Lcjs.InsufficientFundsError)(
69
+ throw new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
70
70
  err instanceof Error ? err.message : "Insufficient SUI/coin balance for the payment.",
71
71
  { cause: err }
72
72
  );
73
73
  }
74
- throw _nullishCoalesce(_chunkYJPWIK5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
74
+ throw _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
75
75
  }
76
76
  }
77
77
  function isSuiAffordability(err) {
@@ -151,22 +151,22 @@ function txNotFound(digest) {
151
151
  var _ed25519 = require('@mysten/sui/keypairs/ed25519');
152
152
  function assertSuiWallet(wallet, network) {
153
153
  if (typeof wallet !== "object" || wallet === null) {
154
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
154
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
155
155
  `chain ${network} is Sui; wallet must be { privateKey } (suiprivkey1\u2026 ) or { keypair }.`
156
156
  );
157
157
  }
158
158
  if ("walletClient" in wallet) {
159
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
159
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
160
160
  `chain ${network} is Sui; a viem { walletClient } can't be used \u2014 pass { privateKey } (suiprivkey1\u2026) or { keypair }.`
161
161
  );
162
162
  }
163
163
  if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keyPair" in wallet || "secret" in wallet || "seed" in wallet || "accountId" in wallet) {
164
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
164
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
165
165
  `chain ${network} is Sui; that looks like another family's wallet \u2014 pass { privateKey } (suiprivkey1\u2026) or { keypair }.`
166
166
  );
167
167
  }
168
168
  if (!("privateKey" in wallet) && !("keypair" in wallet)) {
169
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
169
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
170
170
  `chain ${network} is Sui; wallet must be { privateKey } (suiprivkey1\u2026) or { keypair }.`
171
171
  );
172
172
  }
@@ -178,13 +178,13 @@ function resolveSuiKeypair(config) {
178
178
  try {
179
179
  return _ed25519.Ed25519Keypair.fromSecretKey(config.privateKey);
180
180
  } catch (cause) {
181
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
181
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
182
182
  "Sui wallet { privateKey } is not a valid suiprivkey1\u2026 secret (or 32-byte key).",
183
183
  { cause }
184
184
  );
185
185
  }
186
186
  }
187
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)("Sui wallet needs { privateKey } (suiprivkey1\u2026) or { keypair }.");
187
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("Sui wallet needs { privateKey } (suiprivkey1\u2026) or { keypair }.");
188
188
  }
189
189
 
190
190
  // src/drivers/sui/index.ts
@@ -236,16 +236,16 @@ function makeSuiNetwork(preset, rpcUrl) {
236
236
  const info = preset.tokens[token.toUpperCase()];
237
237
  if (!info) {
238
238
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
239
- throw new (0, _chunkYJPWIK5Lcjs.UnknownTokenError)(
239
+ throw new (0, _chunkIQGT65WScjs.UnknownTokenError)(
240
240
  `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'.`
241
241
  );
242
242
  }
243
243
  return { asset: info.coinType, decimals: info.decimals, symbol: info.symbol };
244
244
  }
245
- _chunkYJPWIK5Lcjs.rejectForeignToken.call(void 0, token, "sui", network);
245
+ _chunkIQGT65WScjs.rejectForeignToken.call(void 0, token, "sui", network);
246
246
  const t = token;
247
247
  if (!t.coinType || typeof t.decimals !== "number") {
248
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
248
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
249
249
  `chain ${network} is Sui; a custom token must be { coinType, decimals }.`
250
250
  );
251
251
  }
@@ -264,7 +264,7 @@ function makeSuiNetwork(preset, rpcUrl) {
264
264
  },
265
265
  assertValidPayTo(payTo) {
266
266
  if (!_utils.isValidSuiAddress.call(void 0, payTo)) {
267
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
267
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
268
268
  `chain ${network} is Sui, but payTo "${payTo}" is not a valid Sui address (0x + 32 bytes).`
269
269
  );
270
270
  }
@@ -281,11 +281,11 @@ function makeSuiNetwork(preset, rpcUrl) {
281
281
  const tx = await client.waitForTransaction({ digest: ref, options: { showEffects: true } });
282
282
  return { height: String(_nullishCoalesce(tx.checkpoint, () => ( "0"))) };
283
283
  } catch (err) {
284
- throw new (0, _chunkYJPWIK5Lcjs.ConfirmationTimeoutError)(`Sui tx ${ref} did not finalize in time.`, { cause: err });
284
+ throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(`Sui tx ${ref} did not finalize in time.`, { cause: err });
285
285
  }
286
286
  },
287
287
  async estimateCost() {
288
- return _chunkYJPWIK5Lcjs.nativeCost.call(void 0, {
288
+ return _chunkIQGT65WScjs.nativeCost.call(void 0, {
289
289
  symbol: SUI_SYMBOL,
290
290
  decimals: SUI_DECIMALS,
291
291
  fee: 3000000n,
@@ -294,6 +294,29 @@ function makeSuiNetwork(preset, rpcUrl) {
294
294
  detail: "\u22480.003 SUI (computation + storage; storage is largely rebated on success)"
295
295
  });
296
296
  },
297
+ async balanceOf(wallet, asset) {
298
+ let owner;
299
+ try {
300
+ owner = resolveSuiKeypair(wallet._native).toSuiAddress();
301
+ } catch (e3) {
302
+ return { token: null, native: null };
303
+ }
304
+ const readBal = async (coinType) => {
305
+ try {
306
+ return BigInt((await client.getBalance({ owner, coinType })).totalBalance);
307
+ } catch (e4) {
308
+ return null;
309
+ }
310
+ };
311
+ const native = await readBal("0x2::sui::SUI");
312
+ if (asset === "native") return { token: native, native };
313
+ const token = await readBal(asset);
314
+ return { token, native };
315
+ },
316
+ // No receive prerequisite — any Sui address receives SUI/coins immediately.
317
+ async recipientReady() {
318
+ return { ready: "n/a" };
319
+ },
297
320
  async verify(ref, accept) {
298
321
  return verifySui({ reader, digest: ref, accept });
299
322
  }
@@ -8,7 +8,7 @@ import {
8
8
  nativeCost,
9
9
  rejectForeignToken,
10
10
  toInsufficientFundsError
11
- } from "./chunk-AGKC3C7Y.js";
11
+ } from "./chunk-QDS6FBZP.js";
12
12
 
13
13
  // src/drivers/ton/index.ts
14
14
  import { Address as Address2 } from "@ton/core";
@@ -346,6 +346,29 @@ function makeTonNetwork(preset, rpcUrl) {
346
346
  const detail = accept.asset === "native" ? "~0.01 TON network fee" : "~0.05 TON attached for the jetton transfer (leftover refunded)";
347
347
  return nativeCost({ symbol: "TON", decimals: TON_DECIMALS, fee, basis: "heuristic", detail });
348
348
  },
349
+ async balanceOf(wallet, asset) {
350
+ let owner;
351
+ try {
352
+ owner = (await resolveTonWallet(wallet._native)).contract.address.toString();
353
+ } catch {
354
+ return { token: null, native: null };
355
+ }
356
+ const native = await client.getBalance(Address2.parse(owner)).then((b) => BigInt(b)).catch(() => null);
357
+ if (asset === "native") return { token: native, native };
358
+ let token;
359
+ try {
360
+ const jw = await jettonWalletFor(asset, owner);
361
+ const { stack } = await client.runMethod(jw, "get_wallet_data");
362
+ token = stack.readBigNumber();
363
+ } catch {
364
+ token = null;
365
+ }
366
+ return { token, native };
367
+ },
368
+ // No receive prerequisite — the payer's gas auto-deploys the recipient's jetton wallet.
369
+ async recipientReady() {
370
+ return { ready: "n/a" };
371
+ },
349
372
  async verify(_ref, accept) {
350
373
  const watch = await watchAccountFor(accept);
351
374
  return verifyTon({ client, watch, accept });
@@ -8,7 +8,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
8
8
 
9
9
 
10
10
 
11
- var _chunkYJPWIK5Lcjs = require('./chunk-YJPWIK5L.cjs');
11
+ var _chunkIQGT65WScjs = require('./chunk-IQGT65WS.cjs');
12
12
 
13
13
  // src/drivers/ton/index.ts
14
14
  var _core = require('@ton/core');
@@ -74,7 +74,7 @@ async function waitForSeqno(opened, from, { tries = 30, intervalMs = 2e3 } = {})
74
74
  }
75
75
  if (current > from) return;
76
76
  }
77
- throw new (0, _chunkYJPWIK5Lcjs.ConfirmationTimeoutError)(
77
+ throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(
78
78
  `TON wallet seqno did not advance past ${from} \u2014 the payment may not have been accepted.`
79
79
  );
80
80
  }
@@ -202,17 +202,17 @@ var _crypto = require('@ton/crypto');
202
202
 
203
203
  function assertTonWallet(wallet, network) {
204
204
  if (typeof wallet !== "object" || wallet === null) {
205
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
205
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
206
206
  `chain ${network} is TON; wallet must be { mnemonic } (24 words) or { keyPair }.`
207
207
  );
208
208
  }
209
209
  if ("privateKey" in wallet || "walletClient" in wallet) {
210
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
210
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
211
211
  `chain ${network} is TON; an EVM wallet can't be used \u2014 pass { mnemonic } (24 words) or { keyPair }.`
212
212
  );
213
213
  }
214
214
  if (!("mnemonic" in wallet) && !("keyPair" in wallet)) {
215
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
215
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
216
216
  `chain ${network} is TON; wallet must be { mnemonic } (24 words) or { keyPair }.`
217
217
  );
218
218
  }
@@ -227,7 +227,7 @@ async function resolveTonWallet(config) {
227
227
  } else if (config.keyPair) {
228
228
  keyPair = config.keyPair;
229
229
  } else {
230
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)("TON wallet needs { mnemonic } (24 words) or { keyPair }.");
230
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("TON wallet needs { mnemonic } (24 words) or { keyPair }.");
231
231
  }
232
232
  const contract = version === "v5r1" ? _ton.WalletContractV5R1.create({ workchain: 0, publicKey: keyPair.publicKey }) : _ton.WalletContractV4.create({ workchain: 0, publicKey: keyPair.publicKey });
233
233
  return { keyPair, contract };
@@ -270,15 +270,15 @@ function makeTonNetwork(preset, rpcUrl) {
270
270
  const info = preset.tokens[token.toUpperCase()];
271
271
  if (!info) {
272
272
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
273
- throw new (0, _chunkYJPWIK5Lcjs.UnknownTokenError)(
273
+ throw new (0, _chunkIQGT65WScjs.UnknownTokenError)(
274
274
  `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'.`
275
275
  );
276
276
  }
277
277
  return { asset: info.master, decimals: info.decimals, symbol: info.symbol };
278
278
  }
279
- _chunkYJPWIK5Lcjs.rejectForeignToken.call(void 0, token, "ton", network);
279
+ _chunkIQGT65WScjs.rejectForeignToken.call(void 0, token, "ton", network);
280
280
  if (!("master" in token)) {
281
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
281
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
282
282
  `chain ${network} is TON; a custom token must be { master, decimals }.`
283
283
  );
284
284
  }
@@ -297,14 +297,14 @@ function makeTonNetwork(preset, rpcUrl) {
297
297
  },
298
298
  assertValidPayTo(payTo) {
299
299
  if (payTo.startsWith("0x")) {
300
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
300
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
301
301
  `chain ${network} is TON, but payTo "${payTo}" looks like an EVM address.`
302
302
  );
303
303
  }
304
304
  try {
305
305
  _core.Address.parse(payTo);
306
306
  } catch (e6) {
307
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
307
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
308
308
  `chain ${network} is TON, but payTo "${payTo}" is not a valid TON address.`
309
309
  );
310
310
  }
@@ -320,7 +320,7 @@ function makeTonNetwork(preset, rpcUrl) {
320
320
  const watch = await watchAccountFor(accept);
321
321
  return encodeRef(watch, accept.extra.nonce);
322
322
  } catch (err) {
323
- throw _nullishCoalesce(_chunkYJPWIK5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
323
+ throw _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
324
324
  }
325
325
  },
326
326
  async confirm(ref) {
@@ -339,12 +339,35 @@ function makeTonNetwork(preset, rpcUrl) {
339
339
  if (inc && inc.comment === nonce) return { height: tx.lt.toString() };
340
340
  }
341
341
  }
342
- throw new (0, _chunkYJPWIK5Lcjs.ConfirmationTimeoutError)(`TON payment for nonce ${nonce} did not settle in time.`);
342
+ throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(`TON payment for nonce ${nonce} did not settle in time.`);
343
343
  },
344
344
  async estimateCost(accept) {
345
345
  const fee = accept.asset === "native" ? 10000000n : 50000000n;
346
346
  const detail = accept.asset === "native" ? "~0.01 TON network fee" : "~0.05 TON attached for the jetton transfer (leftover refunded)";
347
- return _chunkYJPWIK5Lcjs.nativeCost.call(void 0, { symbol: "TON", decimals: TON_DECIMALS, fee, basis: "heuristic", detail });
347
+ return _chunkIQGT65WScjs.nativeCost.call(void 0, { symbol: "TON", decimals: TON_DECIMALS, fee, basis: "heuristic", detail });
348
+ },
349
+ async balanceOf(wallet, asset) {
350
+ let owner;
351
+ try {
352
+ owner = (await resolveTonWallet(wallet._native)).contract.address.toString();
353
+ } catch (e8) {
354
+ return { token: null, native: null };
355
+ }
356
+ const native = await client.getBalance(_core.Address.parse(owner)).then((b) => BigInt(b)).catch(() => null);
357
+ if (asset === "native") return { token: native, native };
358
+ let token;
359
+ try {
360
+ const jw = await jettonWalletFor(asset, owner);
361
+ const { stack } = await client.runMethod(jw, "get_wallet_data");
362
+ token = stack.readBigNumber();
363
+ } catch (e9) {
364
+ token = null;
365
+ }
366
+ return { token, native };
367
+ },
368
+ // No receive prerequisite — the payer's gas auto-deploys the recipient's jetton wallet.
369
+ async recipientReady() {
370
+ return { ready: "n/a" };
348
371
  },
349
372
  async verify(_ref, accept) {
350
373
  const watch = await watchAccountFor(accept);
@@ -9,7 +9,7 @@ import {
9
9
  nativeCost,
10
10
  rejectForeignToken,
11
11
  toInsufficientFundsError
12
- } from "./chunk-AGKC3C7Y.js";
12
+ } from "./chunk-QDS6FBZP.js";
13
13
 
14
14
  // src/drivers/tron/index.ts
15
15
  import { TronWeb } from "tronweb";
@@ -460,6 +460,34 @@ function makeTronNetwork(preset, rpcUrl) {
460
460
  detail: "~30k energy + bandwidth (sender not staked; pass { from } for a precise estimate)"
461
461
  });
462
462
  },
463
+ async balanceOf(wallet, asset) {
464
+ const owner = tronWeb.address.fromPrivateKey(
465
+ resolveTronPrivateKey(wallet._native)
466
+ );
467
+ if (!owner) return { token: null, native: null };
468
+ const native = await tronWeb.trx.getBalance(owner).then((n) => BigInt(n)).catch(() => null);
469
+ if (asset === "native") return { token: native, native };
470
+ let token = null;
471
+ try {
472
+ tronWeb.setAddress(owner);
473
+ const res = await tronWeb.transactionBuilder.triggerConstantContract(
474
+ asset,
475
+ "balanceOf(address)",
476
+ {},
477
+ [{ type: "address", value: owner }],
478
+ owner
479
+ );
480
+ const hex = res?.constant_result?.[0];
481
+ token = hex == null ? null : BigInt("0x" + hex);
482
+ } catch {
483
+ token = null;
484
+ }
485
+ return { token, native };
486
+ },
487
+ // No receive prerequisite — any Tron account receives TRX/TRC-20 immediately.
488
+ async recipientReady() {
489
+ return { ready: "n/a" };
490
+ },
463
491
  async verify(ref, accept) {
464
492
  const txid = stripTronPrefix(ref);
465
493
  if (accept.asset === "native") {