@toon-protocol/client 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/main.js CHANGED
@@ -83,7 +83,17 @@ var GLOBAL_OPTIONS = {
83
83
  facilitator: {
84
84
  type: "string",
85
85
  arg: "URL",
86
- help: "The x402 facilitator that relays a Base channel deposit and pays its gas. Env TOON_FACILITATOR. Default: the devnet Onboarder on Base Sepolia."
86
+ help: "The x402 facilitator that relays a Base channel deposit and pays its gas. Env TOON_FACILITATOR. Default: the one the connector names, else the devnet Onboarder on Base Sepolia."
87
+ },
88
+ "deposit-gas": {
89
+ type: "string",
90
+ arg: "auto|facilitator|self",
91
+ help: "Who pays a Base deposit's gas. auto: the facilitator, else your own ETH; facilitator: never your ETH; self: always your ETH, no facilitator. Env TOON_DEPOSIT_GAS. Default auto."
92
+ },
93
+ "deposit-method": {
94
+ type: "string",
95
+ arg: "eip3009|permit2",
96
+ help: "How a Base deposit moves the token: eip3009 for USDC-style tokens, permit2 for any ERC-20. Env TOON_DEPOSIT_METHOD. Default: what the connector names."
87
97
  },
88
98
  json: { type: "boolean", help: "Print one JSON document on stdout and nothing else." },
89
99
  quiet: { type: "boolean", help: "Suppress progress and warnings on stderr." },
@@ -338,7 +348,7 @@ function usage(command) {
338
348
  return parts.join("\n");
339
349
  }
340
350
  return [
341
- "toon \u2014 pay for an HTTP request, per request, over a payment channel.",
351
+ "toon \u2014 pay for an HTTP request, per request, from an x402 payment channel.",
342
352
  "",
343
353
  "Usage: toon <command> [options]",
344
354
  "",
@@ -352,7 +362,7 @@ function usage(command) {
352
362
  "",
353
363
  "Environment: TOON_CONNECTOR, TOON_MNEMONIC, TOON_KEYSTORE,",
354
364
  " TOON_KEYSTORE_PASSWORD, TOON_CHAIN, TOON_RPC_URL, TOON_CHANNEL_STORE,",
355
- " TOON_SOCKS.",
365
+ " TOON_SOCKS, TOON_FACILITATOR, TOON_DEPOSIT_GAS, TOON_DEPOSIT_METHOD.",
356
366
  "",
357
367
  "Run 'toon help <command>' for one command in detail."
358
368
  ].join("\n");
@@ -435,6 +445,8 @@ var RPC_ENV = "TOON_RPC_URL";
435
445
  var CHANNEL_STORE_ENV = "TOON_CHANNEL_STORE";
436
446
  var SOCKS_ENV = "TOON_SOCKS";
437
447
  var FACILITATOR_ENV = "TOON_FACILITATOR";
448
+ var DEPOSIT_GAS_ENV = "TOON_DEPOSIT_GAS";
449
+ var DEPOSIT_METHOD_ENV = "TOON_DEPOSIT_METHOD";
438
450
  function defaultChannelStorePath(home = homedir2()) {
439
451
  return join2(home, ".toon", "channels.json");
440
452
  }
@@ -443,6 +455,11 @@ function parseChain(value, from) {
443
455
  if (value === "evm" || value === "solana") return value;
444
456
  throw new UsageError(`${from} must be 'evm' or 'solana'; got '${value}'`);
445
457
  }
458
+ function parseChoice(value, from, choices) {
459
+ if (value === void 0 || value.length === 0) return void 0;
460
+ if (choices.includes(value)) return value;
461
+ throw new UsageError(`${from} must be ${choices.map((c) => `'${c}'`).join(", ")}; got '${value}'`);
462
+ }
446
463
  function parseTransport(value, from) {
447
464
  if (value === void 0 || value.length === 0) return "auto";
448
465
  if (value === "auto" || value === "http" || value === "btp") return value;
@@ -478,11 +495,25 @@ function resolveSettings(values, env, options = {}) {
478
495
  const socksProxy = socksFlag !== void 0 && socksFlag.length > 0 ? socksFlag : socksEnv !== void 0 && socksEnv.length > 0 ? socksEnv : void 0;
479
496
  const facilitator = stringOption(values, "facilitator") ?? env[FACILITATOR_ENV];
480
497
  const deposit = stringOption(values, "deposit");
498
+ const depositGasFlag = stringOption(values, "deposit-gas");
499
+ const depositGas = parseChoice(
500
+ depositGasFlag ?? env[DEPOSIT_GAS_ENV],
501
+ depositGasFlag !== void 0 ? "--deposit-gas" : DEPOSIT_GAS_ENV,
502
+ ["auto", "facilitator", "self"]
503
+ );
504
+ const depositMethodFlag = stringOption(values, "deposit-method");
505
+ const depositMethod = parseChoice(
506
+ depositMethodFlag ?? env[DEPOSIT_METHOD_ENV],
507
+ depositMethodFlag !== void 0 ? "--deposit-method" : DEPOSIT_METHOD_ENV,
508
+ ["eip3009", "permit2"]
509
+ );
481
510
  const settings = {
482
511
  connector,
483
512
  connectorSource,
484
513
  ...facilitator !== void 0 && facilitator.length > 0 ? { facilitatorUrl: facilitator } : {},
485
514
  ...deposit !== void 0 ? { deposit } : {},
515
+ ...depositGas !== void 0 ? { depositGas } : {},
516
+ ...depositMethod !== void 0 ? { depositMethod } : {},
486
517
  ...chain !== void 0 ? { chain } : {},
487
518
  ...rpcUrl !== void 0 && rpcUrl.length > 0 ? { rpcUrl } : {},
488
519
  channelStore,
@@ -542,7 +573,9 @@ function buildClientConfig(settings, keys) {
542
573
  ...settings.chain !== void 0 ? { chain: settings.chain } : {},
543
574
  ...settings.rpcUrl !== void 0 ? { rpcUrl: settings.rpcUrl } : {},
544
575
  ...settings.facilitatorUrl !== void 0 ? { facilitatorUrl: settings.facilitatorUrl } : {},
545
- ...settings.deposit !== void 0 ? { deposit: settings.deposit } : {}
576
+ ...settings.deposit !== void 0 ? { deposit: settings.deposit } : {},
577
+ ...settings.depositGas !== void 0 ? { depositGas: settings.depositGas } : {},
578
+ ...settings.depositMethod !== void 0 ? { depositMethod: settings.depositMethod } : {}
546
579
  };
547
580
  if (keys.kind === "mnemonic") {
548
581
  return { ...base, mnemonic: keys.mnemonic, keyDerivation: keys.derivation };
@@ -555,7 +588,7 @@ function buildClientConfig(settings, keys) {
555
588
  };
556
589
  }
557
590
  async function defaultCreateClient(config) {
558
- const module = await import("../client-7YIJOR5K.js");
591
+ const module = await import("../client-GAU5TOT4.js");
559
592
  const factory = module.ToonClient;
560
593
  if (factory === void 0) {
561
594
  throw new Error(
@@ -847,8 +880,9 @@ async function run2(ctx) {
847
880
  ctx.out.line("No channel is ready to settle yet.");
848
881
  return;
849
882
  }
883
+ const noneWorked = results.every((r) => r.error !== void 0);
850
884
  ctx.out.line(
851
- sub === "close" ? "Leaving every open channel. Settle each once its window has elapsed." : "Unspent deposits returned where each window had elapsed."
885
+ noneWorked ? sub === "close" ? "No channel was left." : "No deposit was returned." : sub === "close" ? "Leaving every open channel. Settle each once its window has elapsed." : "Unspent deposits returned where each window had elapsed."
852
886
  );
853
887
  for (const r of results) ctx.out.rows(exitRows(r));
854
888
  });
@@ -1288,8 +1322,14 @@ function refusalHint(result, asset) {
1288
1322
  "'toon channel deposit <base units>', then send again."
1289
1323
  ];
1290
1324
  case "F01":
1325
+ if (result.refusedBy === "path") {
1326
+ return [
1327
+ "A node past the connector could not use the packet, so the app never saw it. Your",
1328
+ "voucher was accepted and the path cost is spent; the message above names what failed."
1329
+ ];
1330
+ }
1291
1331
  return [
1292
- "The connector would not take the claim: it names a channel it cannot see, or a nonce",
1332
+ "The connector would not take the voucher: it names a channel it cannot see, or an amount",
1293
1333
  "it has already banked. Compare the two watermarks with 'toon channel status --connector-view'."
1294
1334
  ];
1295
1335
  case "F02":