@axonfi/sdk 0.9.0 → 0.10.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/index.d.cts CHANGED
@@ -579,10 +579,6 @@ interface ExecuteInput {
579
579
  deadline?: bigint;
580
580
  /** Arbitrary metadata stored off-chain. */
581
581
  metadata?: Record<string, string>;
582
- /** Source token for pre-swap — an address, Token enum, or bare symbol string. */
583
- fromToken?: TokenInput;
584
- /** Max input for pre-swap: bigint (raw), number (human), or string (human). */
585
- maxFromAmount?: AmountInput;
586
582
  }
587
583
  /**
588
584
  * Input for AxonClient.swap(). Signs a SwapIntent and submits to
@@ -620,6 +616,13 @@ interface PaymentResult {
620
616
  estimatedResolutionMs?: number;
621
617
  /** Rejection reason. Present when status === 'rejected'. */
622
618
  reason?: string;
619
+ /**
620
+ * Machine-readable error code. Present when status === 'rejected'.
621
+ * Notable values:
622
+ * - `'SWAP_REQUIRED'` — vault lacks the payment token. The SDK auto-handles
623
+ * this by signing a SwapIntent and resubmitting.
624
+ */
625
+ errorCode?: string;
623
626
  }
624
627
  /** High-level vault info returned by AxonClient.getVaultInfo(). */
625
628
  interface VaultInfo {
@@ -797,6 +800,10 @@ declare class AxonClient {
797
800
  * - `"approved"`: fast path — txHash available immediately
798
801
  * - `"pending_review"`: AI scan or human review in progress — poll for status
799
802
  * - `"rejected"`: payment was rejected — reason field explains why
803
+ *
804
+ * If the vault doesn't hold enough of the payment token, the relayer returns
805
+ * `errorCode: 'SWAP_REQUIRED'`. The SDK automatically signs a SwapIntent and
806
+ * resubmits the payment with swap fields — no action needed from the caller.
800
807
  */
801
808
  pay(input: PayInput): Promise<PaymentResult>;
802
809
  /**
@@ -938,6 +945,7 @@ declare class AxonClient {
938
945
  private _buildPaymentIntent;
939
946
  private _buildExecuteIntent;
940
947
  private _buildSwapIntent;
948
+ private _submitPaymentWithSwap;
941
949
  private _submitPayment;
942
950
  private _submitExecute;
943
951
  private _submitSwap;
package/dist/index.d.ts CHANGED
@@ -579,10 +579,6 @@ interface ExecuteInput {
579
579
  deadline?: bigint;
580
580
  /** Arbitrary metadata stored off-chain. */
581
581
  metadata?: Record<string, string>;
582
- /** Source token for pre-swap — an address, Token enum, or bare symbol string. */
583
- fromToken?: TokenInput;
584
- /** Max input for pre-swap: bigint (raw), number (human), or string (human). */
585
- maxFromAmount?: AmountInput;
586
582
  }
587
583
  /**
588
584
  * Input for AxonClient.swap(). Signs a SwapIntent and submits to
@@ -620,6 +616,13 @@ interface PaymentResult {
620
616
  estimatedResolutionMs?: number;
621
617
  /** Rejection reason. Present when status === 'rejected'. */
622
618
  reason?: string;
619
+ /**
620
+ * Machine-readable error code. Present when status === 'rejected'.
621
+ * Notable values:
622
+ * - `'SWAP_REQUIRED'` — vault lacks the payment token. The SDK auto-handles
623
+ * this by signing a SwapIntent and resubmitting.
624
+ */
625
+ errorCode?: string;
623
626
  }
624
627
  /** High-level vault info returned by AxonClient.getVaultInfo(). */
625
628
  interface VaultInfo {
@@ -797,6 +800,10 @@ declare class AxonClient {
797
800
  * - `"approved"`: fast path — txHash available immediately
798
801
  * - `"pending_review"`: AI scan or human review in progress — poll for status
799
802
  * - `"rejected"`: payment was rejected — reason field explains why
803
+ *
804
+ * If the vault doesn't hold enough of the payment token, the relayer returns
805
+ * `errorCode: 'SWAP_REQUIRED'`. The SDK automatically signs a SwapIntent and
806
+ * resubmits the payment with swap fields — no action needed from the caller.
800
807
  */
801
808
  pay(input: PayInput): Promise<PaymentResult>;
802
809
  /**
@@ -938,6 +945,7 @@ declare class AxonClient {
938
945
  private _buildPaymentIntent;
939
946
  private _buildExecuteIntent;
940
947
  private _buildSwapIntent;
948
+ private _submitPaymentWithSwap;
941
949
  private _submitPayment;
942
950
  private _submitExecute;
943
951
  private _submitSwap;
package/dist/index.js CHANGED
@@ -3973,11 +3973,30 @@ var AxonClient = class {
3973
3973
  * - `"approved"`: fast path — txHash available immediately
3974
3974
  * - `"pending_review"`: AI scan or human review in progress — poll for status
3975
3975
  * - `"rejected"`: payment was rejected — reason field explains why
3976
+ *
3977
+ * If the vault doesn't hold enough of the payment token, the relayer returns
3978
+ * `errorCode: 'SWAP_REQUIRED'`. The SDK automatically signs a SwapIntent and
3979
+ * resubmits the payment with swap fields — no action needed from the caller.
3976
3980
  */
3977
3981
  async pay(input) {
3978
3982
  const intent = this._buildPaymentIntent(input);
3979
3983
  const signature = await signPayment(this.walletClient, this.vaultAddress, this.chainId, intent);
3980
- return this._submitPayment(intent, signature, input);
3984
+ const result = await this._submitPayment(intent, signature, input);
3985
+ if (result.status === "rejected" && result.errorCode === "SWAP_REQUIRED") {
3986
+ const swapIntent = {
3987
+ bot: this.botAddress,
3988
+ toToken: intent.token,
3989
+ // swap TO the payment token
3990
+ minToAmount: intent.amount,
3991
+ // need at least the payment amount
3992
+ deadline: intent.deadline,
3993
+ // same deadline
3994
+ ref: intent.ref
3995
+ };
3996
+ const swapSig = await signSwapIntent(this.walletClient, this.vaultAddress, this.chainId, swapIntent);
3997
+ return this._submitPaymentWithSwap(intent, signature, input, swapIntent, swapSig);
3998
+ }
3999
+ return result;
3981
4000
  }
3982
4001
  // ============================================================================
3983
4002
  // execute()
@@ -4250,6 +4269,38 @@ Timestamp: ${timestamp}`;
4250
4269
  ref: this._resolveRef(input.memo, input.ref)
4251
4270
  };
4252
4271
  }
4272
+ async _submitPaymentWithSwap(intent, signature, input, swapIntent, swapSignature) {
4273
+ const idempotencyKey = generateUuid();
4274
+ const body = {
4275
+ // Routing
4276
+ chainId: this.chainId,
4277
+ vaultAddress: this.vaultAddress,
4278
+ // Flat intent fields (matches relayer DTO)
4279
+ bot: intent.bot,
4280
+ to: intent.to,
4281
+ token: intent.token,
4282
+ amount: intent.amount.toString(),
4283
+ deadline: intent.deadline.toString(),
4284
+ ref: intent.ref,
4285
+ signature,
4286
+ // Swap fields
4287
+ swapSignature,
4288
+ swapToToken: swapIntent.toToken,
4289
+ swapMinToAmount: swapIntent.minToAmount.toString(),
4290
+ swapDeadline: swapIntent.deadline.toString(),
4291
+ swapRef: swapIntent.ref,
4292
+ // Off-chain metadata
4293
+ idempotencyKey,
4294
+ ...input.memo !== void 0 && { memo: input.memo },
4295
+ ...input.resourceUrl !== void 0 && { resourceUrl: input.resourceUrl },
4296
+ ...input.invoiceId !== void 0 && { invoiceId: input.invoiceId },
4297
+ ...input.orderId !== void 0 && { orderId: input.orderId },
4298
+ ...input.recipientLabel !== void 0 && { recipientLabel: input.recipientLabel },
4299
+ ...input.metadata !== void 0 && { metadata: input.metadata },
4300
+ ...input.x402Funding !== void 0 && { x402Funding: input.x402Funding }
4301
+ };
4302
+ return this._post(RELAYER_API.PAYMENTS, idempotencyKey, body);
4303
+ }
4253
4304
  async _submitPayment(intent, signature, input) {
4254
4305
  const idempotencyKey = input.idempotencyKey ?? generateUuid();
4255
4306
  const body = {
@@ -4278,8 +4329,6 @@ Timestamp: ${timestamp}`;
4278
4329
  }
4279
4330
  async _submitExecute(intent, signature, input) {
4280
4331
  const idempotencyKey = input.idempotencyKey ?? generateUuid();
4281
- const fromToken = input.fromToken !== void 0 ? resolveToken(input.fromToken, this.chainId) : void 0;
4282
- const maxFromAmount = input.maxFromAmount !== void 0 ? parseAmount(input.maxFromAmount, input.fromToken ?? input.tokens?.[0] ?? "USDC", this.chainId) : void 0;
4283
4332
  const body = {
4284
4333
  chainId: this.chainId,
4285
4334
  vaultAddress: this.vaultAddress,
@@ -4295,9 +4344,6 @@ Timestamp: ${timestamp}`;
4295
4344
  signature,
4296
4345
  // Protocol calldata
4297
4346
  callData: input.callData,
4298
- // Optional pre-swap
4299
- ...fromToken !== void 0 && { fromToken },
4300
- ...maxFromAmount !== void 0 && { maxFromAmount: maxFromAmount.toString() },
4301
4347
  // Off-chain metadata
4302
4348
  idempotencyKey,
4303
4349
  ...input.memo !== void 0 && { memo: input.memo },