@axonfi/sdk 0.3.7 → 0.4.1
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/README.md +24 -3
- package/dist/index.cjs +373 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +237 -1
- package/dist/index.d.ts +237 -1
- package/dist/index.js +361 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -458,6 +458,12 @@ interface PayInput {
|
|
|
458
458
|
* If set, `memo` is ignored for ref generation but still stored off-chain.
|
|
459
459
|
*/
|
|
460
460
|
ref?: Hex;
|
|
461
|
+
/**
|
|
462
|
+
* Marks this payment as x402 bot-EOA funding. When true, the relayer
|
|
463
|
+
* records the flag for audit/context (e.g. "bot self-payment for x402").
|
|
464
|
+
* Does NOT bypass any policy checks — full pipeline still applies.
|
|
465
|
+
*/
|
|
466
|
+
x402Funding?: boolean;
|
|
461
467
|
}
|
|
462
468
|
/**
|
|
463
469
|
* Signed execute intent for DeFi protocol interactions.
|
|
@@ -612,7 +618,97 @@ interface AxonClientConfig {
|
|
|
612
618
|
* Provide either this or `account`.
|
|
613
619
|
*/
|
|
614
620
|
botPrivateKey?: Hex;
|
|
621
|
+
/** Override the relayer URL (defaults to https://relay.axonfi.xyz). */
|
|
622
|
+
relayerUrl?: string;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/** Resource descriptor from the x402 PAYMENT-REQUIRED header. */
|
|
626
|
+
interface X402Resource {
|
|
627
|
+
/** URL of the resource being unlocked. */
|
|
628
|
+
url: string;
|
|
629
|
+
/** Human-readable description of the resource. */
|
|
630
|
+
description?: string;
|
|
631
|
+
/** MIME type of the resource. */
|
|
632
|
+
mimeType?: string;
|
|
633
|
+
}
|
|
634
|
+
/** A single payment option from the `accepts` array. */
|
|
635
|
+
interface X402PaymentOption {
|
|
636
|
+
/** Recipient address (merchant). */
|
|
637
|
+
payTo: string;
|
|
638
|
+
/** Amount in token base units (string). */
|
|
639
|
+
amount: string;
|
|
640
|
+
/** Token contract address. */
|
|
641
|
+
asset: string;
|
|
642
|
+
/** CAIP-2 network identifier, e.g. "eip155:8453". */
|
|
643
|
+
network: string;
|
|
644
|
+
/** Settlement scheme: "exact" (EIP-3009) or "permit2". */
|
|
645
|
+
scheme?: string;
|
|
646
|
+
/** Additional option-specific fields. */
|
|
647
|
+
extra?: Record<string, unknown>;
|
|
648
|
+
}
|
|
649
|
+
/** Parsed x402 PAYMENT-REQUIRED response. */
|
|
650
|
+
interface X402PaymentRequired {
|
|
651
|
+
/** x402 protocol version. */
|
|
652
|
+
x402Version: number;
|
|
653
|
+
/** Resource being unlocked. */
|
|
654
|
+
resource: X402Resource;
|
|
655
|
+
/** Accepted payment options. */
|
|
656
|
+
accepts: X402PaymentOption[];
|
|
657
|
+
}
|
|
658
|
+
/** Result of handlePaymentRequired — contains everything needed to retry the request. */
|
|
659
|
+
interface X402HandleResult {
|
|
660
|
+
/** Base64-encoded JSON for the PAYMENT-SIGNATURE header. */
|
|
661
|
+
paymentSignature: string;
|
|
662
|
+
/** The payment option that was selected and funded. */
|
|
663
|
+
selectedOption: X402PaymentOption;
|
|
664
|
+
/** Axon payment result (txHash, requestId, etc.). */
|
|
665
|
+
fundingResult: {
|
|
666
|
+
requestId: string;
|
|
667
|
+
status: string;
|
|
668
|
+
txHash?: string;
|
|
669
|
+
};
|
|
615
670
|
}
|
|
671
|
+
/**
|
|
672
|
+
* Parse the PAYMENT-REQUIRED header value (base64 JSON).
|
|
673
|
+
*
|
|
674
|
+
* The x402 spec encodes the payment requirements as a base64-encoded JSON
|
|
675
|
+
* string in the response header.
|
|
676
|
+
*/
|
|
677
|
+
declare function parsePaymentRequired(headerValue: string): X402PaymentRequired;
|
|
678
|
+
/**
|
|
679
|
+
* Parse a CAIP-2 network identifier to a numeric chain ID.
|
|
680
|
+
*
|
|
681
|
+
* @example parseChainId("eip155:8453") // → 8453
|
|
682
|
+
* @example parseChainId("eip155:84532") // → 84532
|
|
683
|
+
*/
|
|
684
|
+
declare function parseChainId(network: string): number;
|
|
685
|
+
/**
|
|
686
|
+
* Find a payment option matching the bot's chain ID.
|
|
687
|
+
*
|
|
688
|
+
* Prefers USDC options (EIP-3009 path — no gas needed from bot).
|
|
689
|
+
* Falls back to any matching chain option.
|
|
690
|
+
*
|
|
691
|
+
* @returns The best matching payment option, or null if none match.
|
|
692
|
+
*/
|
|
693
|
+
declare function findMatchingOption(accepts: X402PaymentOption[], chainId: number): X402PaymentOption | null;
|
|
694
|
+
/**
|
|
695
|
+
* Extract metadata fields from a parsed x402 header for payment enrichment.
|
|
696
|
+
*
|
|
697
|
+
* These fields flow into the Axon payment record, giving vault owners
|
|
698
|
+
* full visibility into what their bots are accessing.
|
|
699
|
+
*/
|
|
700
|
+
declare function extractX402Metadata(parsed: X402PaymentRequired, selectedOption: X402PaymentOption): {
|
|
701
|
+
resourceUrl: string;
|
|
702
|
+
memo: string | null;
|
|
703
|
+
recipientLabel: string | null;
|
|
704
|
+
metadata: Record<string, string>;
|
|
705
|
+
};
|
|
706
|
+
/**
|
|
707
|
+
* Format a payment signature payload for the PAYMENT-SIGNATURE header.
|
|
708
|
+
*
|
|
709
|
+
* The x402 spec requires the header value to be base64-encoded JSON.
|
|
710
|
+
*/
|
|
711
|
+
declare function formatPaymentSignature(payload: Record<string, unknown>): string;
|
|
616
712
|
|
|
617
713
|
/**
|
|
618
714
|
* Main entry point for bots interacting with Axon.
|
|
@@ -649,6 +745,7 @@ declare class AxonClient {
|
|
|
649
745
|
private readonly chainId;
|
|
650
746
|
private readonly relayerUrl;
|
|
651
747
|
private readonly walletClient;
|
|
748
|
+
private readonly botPrivateKey;
|
|
652
749
|
constructor(config: AxonClientConfig);
|
|
653
750
|
/** Returns the bot's address derived from the configured private key. */
|
|
654
751
|
get botAddress(): Address;
|
|
@@ -743,6 +840,57 @@ declare class AxonClient {
|
|
|
743
840
|
* to another system (e.g. a custom relayer integration).
|
|
744
841
|
*/
|
|
745
842
|
signPayment(intent: PaymentIntent): Promise<Hex>;
|
|
843
|
+
/**
|
|
844
|
+
* x402 utilities for handling HTTP 402 Payment Required responses.
|
|
845
|
+
*
|
|
846
|
+
* The x402 flow:
|
|
847
|
+
* 1. Bot hits an API that returns HTTP 402 + PAYMENT-REQUIRED header
|
|
848
|
+
* 2. SDK parses the header, finds a matching payment option
|
|
849
|
+
* 3. SDK funds the bot's EOA from the vault (full Axon pipeline applies)
|
|
850
|
+
* 4. Bot signs an EIP-3009 or Permit2 authorization
|
|
851
|
+
* 5. SDK returns a PAYMENT-SIGNATURE header for the bot to retry with
|
|
852
|
+
*
|
|
853
|
+
* @example
|
|
854
|
+
* ```ts
|
|
855
|
+
* const response = await fetch('https://api.example.com/data');
|
|
856
|
+
* if (response.status === 402) {
|
|
857
|
+
* const result = await client.x402.handlePaymentRequired(response.headers);
|
|
858
|
+
* const data = await fetch('https://api.example.com/data', {
|
|
859
|
+
* headers: { 'PAYMENT-SIGNATURE': result.paymentSignature },
|
|
860
|
+
* });
|
|
861
|
+
* }
|
|
862
|
+
* ```
|
|
863
|
+
*/
|
|
864
|
+
readonly x402: {
|
|
865
|
+
/**
|
|
866
|
+
* Fund the bot's EOA from the vault for x402 settlement.
|
|
867
|
+
*
|
|
868
|
+
* This is a regular Axon payment (to = bot's own address) that goes through
|
|
869
|
+
* the full pipeline: policy engine, AI scan, human review if needed.
|
|
870
|
+
*
|
|
871
|
+
* @param amount - Amount in token base units
|
|
872
|
+
* @param token - Token address (defaults to USDC on this chain)
|
|
873
|
+
* @param metadata - Optional metadata for the payment record
|
|
874
|
+
*/
|
|
875
|
+
fund: (amount: bigint, token?: Address, metadata?: {
|
|
876
|
+
resourceUrl?: string;
|
|
877
|
+
memo?: string;
|
|
878
|
+
recipientLabel?: string;
|
|
879
|
+
metadata?: Record<string, string>;
|
|
880
|
+
}) => Promise<PaymentResult>;
|
|
881
|
+
/**
|
|
882
|
+
* Handle a full x402 flow: parse header, fund bot, sign authorization, return header.
|
|
883
|
+
*
|
|
884
|
+
* Supports both EIP-3009 (USDC) and Permit2 (any ERC-20) settlement.
|
|
885
|
+
* The bot's EOA is funded from the vault first (full Axon pipeline applies).
|
|
886
|
+
*
|
|
887
|
+
* @param headers - Response headers from the 402 response (must contain PAYMENT-REQUIRED)
|
|
888
|
+
* @param maxTimeoutMs - Maximum time to wait for pending_review resolution (default: 120s)
|
|
889
|
+
* @param pollIntervalMs - Polling interval for pending_review (default: 5s)
|
|
890
|
+
* @returns Payment signature header value + funding details
|
|
891
|
+
*/
|
|
892
|
+
handlePaymentRequired: (headers: Headers | Record<string, string>, maxTimeoutMs?: number, pollIntervalMs?: number) => Promise<X402HandleResult>;
|
|
893
|
+
};
|
|
746
894
|
private _get;
|
|
747
895
|
private _defaultDeadline;
|
|
748
896
|
private _resolveRef;
|
|
@@ -939,6 +1087,94 @@ declare function resolveTokenDecimals(token: Address | Token | KnownTokenSymbol,
|
|
|
939
1087
|
*/
|
|
940
1088
|
declare function parseAmount(amount: bigint | number | string, token: Address | Token | KnownTokenSymbol, chainId?: number): bigint;
|
|
941
1089
|
|
|
1090
|
+
/**
|
|
1091
|
+
* Per-chain EIP-712 domain parameters for USDC's EIP-3009 implementation.
|
|
1092
|
+
* These differ between testnets and mainnets (Circle uses different `name` values).
|
|
1093
|
+
*
|
|
1094
|
+
* Verified on-chain via `cast call <usdc> "name()(string)"` and
|
|
1095
|
+
* `cast call <usdc> "version()(string)"`.
|
|
1096
|
+
*/
|
|
1097
|
+
declare const USDC_EIP712_DOMAIN: Record<number, {
|
|
1098
|
+
name: string;
|
|
1099
|
+
version: string;
|
|
1100
|
+
}>;
|
|
1101
|
+
/** Parameters for EIP-3009 TransferWithAuthorization. */
|
|
1102
|
+
interface TransferAuthorization {
|
|
1103
|
+
/** Token holder (sender). */
|
|
1104
|
+
from: Address;
|
|
1105
|
+
/** Recipient of the transfer. */
|
|
1106
|
+
to: Address;
|
|
1107
|
+
/** Amount in token base units (USDC: 6 decimals). */
|
|
1108
|
+
value: bigint;
|
|
1109
|
+
/** Unix timestamp — transfer is invalid before this time. Usually 0. */
|
|
1110
|
+
validAfter: bigint;
|
|
1111
|
+
/** Unix timestamp — transfer is invalid after this time. */
|
|
1112
|
+
validBefore: bigint;
|
|
1113
|
+
/** Random bytes32 nonce (must not have been used before for this sender). */
|
|
1114
|
+
nonce: Hex;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Generate a random bytes32 nonce for EIP-3009.
|
|
1118
|
+
* Uses crypto.getRandomValues for cryptographic randomness.
|
|
1119
|
+
*/
|
|
1120
|
+
declare function randomNonce(): Hex;
|
|
1121
|
+
/**
|
|
1122
|
+
* Sign an EIP-3009 TransferWithAuthorization for USDC.
|
|
1123
|
+
*
|
|
1124
|
+
* The resulting signature can be submitted to a facilitator contract that calls
|
|
1125
|
+
* `USDC.transferWithAuthorization(from, to, value, validAfter, validBefore, nonce, v, r, s)`.
|
|
1126
|
+
*
|
|
1127
|
+
* @param privateKey - Signer's private key (must match auth.from)
|
|
1128
|
+
* @param chainId - Chain ID (determines USDC domain name/version)
|
|
1129
|
+
* @param auth - Transfer authorization parameters
|
|
1130
|
+
* @returns EIP-712 signature (65 bytes, 0x-prefixed)
|
|
1131
|
+
*/
|
|
1132
|
+
declare function signTransferWithAuthorization(privateKey: Hex, chainId: number, auth: TransferAuthorization): Promise<Hex>;
|
|
1133
|
+
|
|
1134
|
+
/** Canonical Permit2 contract address (same on all EVM chains). */
|
|
1135
|
+
declare const PERMIT2_ADDRESS: Address;
|
|
1136
|
+
/** x402 facilitator proxy contract address (same on all supported chains). */
|
|
1137
|
+
declare const X402_PROXY_ADDRESS: Address;
|
|
1138
|
+
/**
|
|
1139
|
+
* Witness type string for x402's PermitWitnessTransferFrom.
|
|
1140
|
+
* Must match what the x402 facilitator contract expects.
|
|
1141
|
+
*/
|
|
1142
|
+
declare const WITNESS_TYPE_STRING: "TransferDetails witness)TokenPermissions(address token,uint256 amount)TransferDetails(address to,uint256 requestedAmount)";
|
|
1143
|
+
/** Parameters for Permit2 PermitWitnessTransferFrom. */
|
|
1144
|
+
interface Permit2Authorization {
|
|
1145
|
+
/** Token to transfer. */
|
|
1146
|
+
token: Address;
|
|
1147
|
+
/** Maximum amount the spender can transfer. */
|
|
1148
|
+
amount: bigint;
|
|
1149
|
+
/** Spender address (the x402 proxy). */
|
|
1150
|
+
spender: Address;
|
|
1151
|
+
/** Unique nonce (random uint256). */
|
|
1152
|
+
nonce: bigint;
|
|
1153
|
+
/** Unix timestamp — signature is invalid after this time. */
|
|
1154
|
+
deadline: bigint;
|
|
1155
|
+
/** Witness: recipient address. */
|
|
1156
|
+
witnessTo: Address;
|
|
1157
|
+
/** Witness: requested amount. */
|
|
1158
|
+
witnessRequestedAmount: bigint;
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* Generate a random uint256 nonce for Permit2.
|
|
1162
|
+
* Uses crypto.getRandomValues for cryptographic randomness.
|
|
1163
|
+
*/
|
|
1164
|
+
declare function randomPermit2Nonce(): bigint;
|
|
1165
|
+
/**
|
|
1166
|
+
* Sign a Permit2 PermitWitnessTransferFrom for x402.
|
|
1167
|
+
*
|
|
1168
|
+
* The resulting signature is submitted to the x402 facilitator proxy,
|
|
1169
|
+
* which calls `Permit2.permitWitnessTransferFrom(...)` to settle the payment.
|
|
1170
|
+
*
|
|
1171
|
+
* @param privateKey - Signer's private key (token holder)
|
|
1172
|
+
* @param chainId - Chain ID
|
|
1173
|
+
* @param permit - Permit2 authorization parameters
|
|
1174
|
+
* @returns EIP-712 signature (65 bytes, 0x-prefixed)
|
|
1175
|
+
*/
|
|
1176
|
+
declare function signPermit2WitnessTransfer(privateKey: Hex, chainId: number, permit: Permit2Authorization): Promise<Hex>;
|
|
1177
|
+
|
|
942
1178
|
declare const AxonVaultAbi: readonly [{
|
|
943
1179
|
readonly type: "constructor";
|
|
944
1180
|
readonly inputs: readonly [{
|
|
@@ -3017,4 +3253,4 @@ declare const AxonRegistryAbi: readonly [{
|
|
|
3017
3253
|
readonly inputs: readonly [];
|
|
3018
3254
|
}];
|
|
3019
3255
|
|
|
3020
|
-
export { type AmountInput, AxonClient, type AxonClientConfig, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, type BotConfig, type BotConfigParams, CHAIN_NAMES, Chain, DEFAULT_DEADLINE_SECONDS, type DestinationCheckResult, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, type ExecuteInput, type ExecuteIntent, KNOWN_TOKENS, type KeystoreV3, type KnownToken, type KnownTokenSymbol, NATIVE_ETH, type OperatorCeilings, PAYMENT_INTENT_TYPEHASH, type PayInput, PaymentErrorCode, type PaymentIntent, type PaymentResult, type PaymentStatus, RELAYER_API, type RebalanceTokensResult, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, type SpendingLimit, type SupportedChainId, type SwapInput, type SwapIntent, Token, type TokenInput, type TosStatus, USDC, type VaultInfo, WINDOW, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, encodeRef, encryptKeystore, getBotConfig, getChain, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signSwapIntent };
|
|
3256
|
+
export { type AmountInput, AxonClient, type AxonClientConfig, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, type BotConfig, type BotConfigParams, CHAIN_NAMES, Chain, DEFAULT_DEADLINE_SECONDS, type DestinationCheckResult, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, type ExecuteInput, type ExecuteIntent, KNOWN_TOKENS, type KeystoreV3, type KnownToken, type KnownTokenSymbol, NATIVE_ETH, type OperatorCeilings, PAYMENT_INTENT_TYPEHASH, PERMIT2_ADDRESS, type PayInput, PaymentErrorCode, type PaymentIntent, type PaymentResult, type PaymentStatus, type Permit2Authorization, RELAYER_API, type RebalanceTokensResult, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, type SpendingLimit, type SupportedChainId, type SwapInput, type SwapIntent, Token, type TokenInput, type TosStatus, type TransferAuthorization, USDC, USDC_EIP712_DOMAIN, type VaultInfo, WINDOW, WITNESS_TYPE_STRING, type X402HandleResult, type X402PaymentOption, type X402PaymentRequired, type X402Resource, X402_PROXY_ADDRESS, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, encodeRef, encryptKeystore, extractX402Metadata, findMatchingOption, formatPaymentSignature, getBotConfig, getChain, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, parseChainId, parsePaymentRequired, randomNonce, randomPermit2Nonce, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signPermit2WitnessTransfer, signSwapIntent, signTransferWithAuthorization };
|
package/dist/index.d.ts
CHANGED
|
@@ -458,6 +458,12 @@ interface PayInput {
|
|
|
458
458
|
* If set, `memo` is ignored for ref generation but still stored off-chain.
|
|
459
459
|
*/
|
|
460
460
|
ref?: Hex;
|
|
461
|
+
/**
|
|
462
|
+
* Marks this payment as x402 bot-EOA funding. When true, the relayer
|
|
463
|
+
* records the flag for audit/context (e.g. "bot self-payment for x402").
|
|
464
|
+
* Does NOT bypass any policy checks — full pipeline still applies.
|
|
465
|
+
*/
|
|
466
|
+
x402Funding?: boolean;
|
|
461
467
|
}
|
|
462
468
|
/**
|
|
463
469
|
* Signed execute intent for DeFi protocol interactions.
|
|
@@ -612,7 +618,97 @@ interface AxonClientConfig {
|
|
|
612
618
|
* Provide either this or `account`.
|
|
613
619
|
*/
|
|
614
620
|
botPrivateKey?: Hex;
|
|
621
|
+
/** Override the relayer URL (defaults to https://relay.axonfi.xyz). */
|
|
622
|
+
relayerUrl?: string;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/** Resource descriptor from the x402 PAYMENT-REQUIRED header. */
|
|
626
|
+
interface X402Resource {
|
|
627
|
+
/** URL of the resource being unlocked. */
|
|
628
|
+
url: string;
|
|
629
|
+
/** Human-readable description of the resource. */
|
|
630
|
+
description?: string;
|
|
631
|
+
/** MIME type of the resource. */
|
|
632
|
+
mimeType?: string;
|
|
633
|
+
}
|
|
634
|
+
/** A single payment option from the `accepts` array. */
|
|
635
|
+
interface X402PaymentOption {
|
|
636
|
+
/** Recipient address (merchant). */
|
|
637
|
+
payTo: string;
|
|
638
|
+
/** Amount in token base units (string). */
|
|
639
|
+
amount: string;
|
|
640
|
+
/** Token contract address. */
|
|
641
|
+
asset: string;
|
|
642
|
+
/** CAIP-2 network identifier, e.g. "eip155:8453". */
|
|
643
|
+
network: string;
|
|
644
|
+
/** Settlement scheme: "exact" (EIP-3009) or "permit2". */
|
|
645
|
+
scheme?: string;
|
|
646
|
+
/** Additional option-specific fields. */
|
|
647
|
+
extra?: Record<string, unknown>;
|
|
648
|
+
}
|
|
649
|
+
/** Parsed x402 PAYMENT-REQUIRED response. */
|
|
650
|
+
interface X402PaymentRequired {
|
|
651
|
+
/** x402 protocol version. */
|
|
652
|
+
x402Version: number;
|
|
653
|
+
/** Resource being unlocked. */
|
|
654
|
+
resource: X402Resource;
|
|
655
|
+
/** Accepted payment options. */
|
|
656
|
+
accepts: X402PaymentOption[];
|
|
657
|
+
}
|
|
658
|
+
/** Result of handlePaymentRequired — contains everything needed to retry the request. */
|
|
659
|
+
interface X402HandleResult {
|
|
660
|
+
/** Base64-encoded JSON for the PAYMENT-SIGNATURE header. */
|
|
661
|
+
paymentSignature: string;
|
|
662
|
+
/** The payment option that was selected and funded. */
|
|
663
|
+
selectedOption: X402PaymentOption;
|
|
664
|
+
/** Axon payment result (txHash, requestId, etc.). */
|
|
665
|
+
fundingResult: {
|
|
666
|
+
requestId: string;
|
|
667
|
+
status: string;
|
|
668
|
+
txHash?: string;
|
|
669
|
+
};
|
|
615
670
|
}
|
|
671
|
+
/**
|
|
672
|
+
* Parse the PAYMENT-REQUIRED header value (base64 JSON).
|
|
673
|
+
*
|
|
674
|
+
* The x402 spec encodes the payment requirements as a base64-encoded JSON
|
|
675
|
+
* string in the response header.
|
|
676
|
+
*/
|
|
677
|
+
declare function parsePaymentRequired(headerValue: string): X402PaymentRequired;
|
|
678
|
+
/**
|
|
679
|
+
* Parse a CAIP-2 network identifier to a numeric chain ID.
|
|
680
|
+
*
|
|
681
|
+
* @example parseChainId("eip155:8453") // → 8453
|
|
682
|
+
* @example parseChainId("eip155:84532") // → 84532
|
|
683
|
+
*/
|
|
684
|
+
declare function parseChainId(network: string): number;
|
|
685
|
+
/**
|
|
686
|
+
* Find a payment option matching the bot's chain ID.
|
|
687
|
+
*
|
|
688
|
+
* Prefers USDC options (EIP-3009 path — no gas needed from bot).
|
|
689
|
+
* Falls back to any matching chain option.
|
|
690
|
+
*
|
|
691
|
+
* @returns The best matching payment option, or null if none match.
|
|
692
|
+
*/
|
|
693
|
+
declare function findMatchingOption(accepts: X402PaymentOption[], chainId: number): X402PaymentOption | null;
|
|
694
|
+
/**
|
|
695
|
+
* Extract metadata fields from a parsed x402 header for payment enrichment.
|
|
696
|
+
*
|
|
697
|
+
* These fields flow into the Axon payment record, giving vault owners
|
|
698
|
+
* full visibility into what their bots are accessing.
|
|
699
|
+
*/
|
|
700
|
+
declare function extractX402Metadata(parsed: X402PaymentRequired, selectedOption: X402PaymentOption): {
|
|
701
|
+
resourceUrl: string;
|
|
702
|
+
memo: string | null;
|
|
703
|
+
recipientLabel: string | null;
|
|
704
|
+
metadata: Record<string, string>;
|
|
705
|
+
};
|
|
706
|
+
/**
|
|
707
|
+
* Format a payment signature payload for the PAYMENT-SIGNATURE header.
|
|
708
|
+
*
|
|
709
|
+
* The x402 spec requires the header value to be base64-encoded JSON.
|
|
710
|
+
*/
|
|
711
|
+
declare function formatPaymentSignature(payload: Record<string, unknown>): string;
|
|
616
712
|
|
|
617
713
|
/**
|
|
618
714
|
* Main entry point for bots interacting with Axon.
|
|
@@ -649,6 +745,7 @@ declare class AxonClient {
|
|
|
649
745
|
private readonly chainId;
|
|
650
746
|
private readonly relayerUrl;
|
|
651
747
|
private readonly walletClient;
|
|
748
|
+
private readonly botPrivateKey;
|
|
652
749
|
constructor(config: AxonClientConfig);
|
|
653
750
|
/** Returns the bot's address derived from the configured private key. */
|
|
654
751
|
get botAddress(): Address;
|
|
@@ -743,6 +840,57 @@ declare class AxonClient {
|
|
|
743
840
|
* to another system (e.g. a custom relayer integration).
|
|
744
841
|
*/
|
|
745
842
|
signPayment(intent: PaymentIntent): Promise<Hex>;
|
|
843
|
+
/**
|
|
844
|
+
* x402 utilities for handling HTTP 402 Payment Required responses.
|
|
845
|
+
*
|
|
846
|
+
* The x402 flow:
|
|
847
|
+
* 1. Bot hits an API that returns HTTP 402 + PAYMENT-REQUIRED header
|
|
848
|
+
* 2. SDK parses the header, finds a matching payment option
|
|
849
|
+
* 3. SDK funds the bot's EOA from the vault (full Axon pipeline applies)
|
|
850
|
+
* 4. Bot signs an EIP-3009 or Permit2 authorization
|
|
851
|
+
* 5. SDK returns a PAYMENT-SIGNATURE header for the bot to retry with
|
|
852
|
+
*
|
|
853
|
+
* @example
|
|
854
|
+
* ```ts
|
|
855
|
+
* const response = await fetch('https://api.example.com/data');
|
|
856
|
+
* if (response.status === 402) {
|
|
857
|
+
* const result = await client.x402.handlePaymentRequired(response.headers);
|
|
858
|
+
* const data = await fetch('https://api.example.com/data', {
|
|
859
|
+
* headers: { 'PAYMENT-SIGNATURE': result.paymentSignature },
|
|
860
|
+
* });
|
|
861
|
+
* }
|
|
862
|
+
* ```
|
|
863
|
+
*/
|
|
864
|
+
readonly x402: {
|
|
865
|
+
/**
|
|
866
|
+
* Fund the bot's EOA from the vault for x402 settlement.
|
|
867
|
+
*
|
|
868
|
+
* This is a regular Axon payment (to = bot's own address) that goes through
|
|
869
|
+
* the full pipeline: policy engine, AI scan, human review if needed.
|
|
870
|
+
*
|
|
871
|
+
* @param amount - Amount in token base units
|
|
872
|
+
* @param token - Token address (defaults to USDC on this chain)
|
|
873
|
+
* @param metadata - Optional metadata for the payment record
|
|
874
|
+
*/
|
|
875
|
+
fund: (amount: bigint, token?: Address, metadata?: {
|
|
876
|
+
resourceUrl?: string;
|
|
877
|
+
memo?: string;
|
|
878
|
+
recipientLabel?: string;
|
|
879
|
+
metadata?: Record<string, string>;
|
|
880
|
+
}) => Promise<PaymentResult>;
|
|
881
|
+
/**
|
|
882
|
+
* Handle a full x402 flow: parse header, fund bot, sign authorization, return header.
|
|
883
|
+
*
|
|
884
|
+
* Supports both EIP-3009 (USDC) and Permit2 (any ERC-20) settlement.
|
|
885
|
+
* The bot's EOA is funded from the vault first (full Axon pipeline applies).
|
|
886
|
+
*
|
|
887
|
+
* @param headers - Response headers from the 402 response (must contain PAYMENT-REQUIRED)
|
|
888
|
+
* @param maxTimeoutMs - Maximum time to wait for pending_review resolution (default: 120s)
|
|
889
|
+
* @param pollIntervalMs - Polling interval for pending_review (default: 5s)
|
|
890
|
+
* @returns Payment signature header value + funding details
|
|
891
|
+
*/
|
|
892
|
+
handlePaymentRequired: (headers: Headers | Record<string, string>, maxTimeoutMs?: number, pollIntervalMs?: number) => Promise<X402HandleResult>;
|
|
893
|
+
};
|
|
746
894
|
private _get;
|
|
747
895
|
private _defaultDeadline;
|
|
748
896
|
private _resolveRef;
|
|
@@ -939,6 +1087,94 @@ declare function resolveTokenDecimals(token: Address | Token | KnownTokenSymbol,
|
|
|
939
1087
|
*/
|
|
940
1088
|
declare function parseAmount(amount: bigint | number | string, token: Address | Token | KnownTokenSymbol, chainId?: number): bigint;
|
|
941
1089
|
|
|
1090
|
+
/**
|
|
1091
|
+
* Per-chain EIP-712 domain parameters for USDC's EIP-3009 implementation.
|
|
1092
|
+
* These differ between testnets and mainnets (Circle uses different `name` values).
|
|
1093
|
+
*
|
|
1094
|
+
* Verified on-chain via `cast call <usdc> "name()(string)"` and
|
|
1095
|
+
* `cast call <usdc> "version()(string)"`.
|
|
1096
|
+
*/
|
|
1097
|
+
declare const USDC_EIP712_DOMAIN: Record<number, {
|
|
1098
|
+
name: string;
|
|
1099
|
+
version: string;
|
|
1100
|
+
}>;
|
|
1101
|
+
/** Parameters for EIP-3009 TransferWithAuthorization. */
|
|
1102
|
+
interface TransferAuthorization {
|
|
1103
|
+
/** Token holder (sender). */
|
|
1104
|
+
from: Address;
|
|
1105
|
+
/** Recipient of the transfer. */
|
|
1106
|
+
to: Address;
|
|
1107
|
+
/** Amount in token base units (USDC: 6 decimals). */
|
|
1108
|
+
value: bigint;
|
|
1109
|
+
/** Unix timestamp — transfer is invalid before this time. Usually 0. */
|
|
1110
|
+
validAfter: bigint;
|
|
1111
|
+
/** Unix timestamp — transfer is invalid after this time. */
|
|
1112
|
+
validBefore: bigint;
|
|
1113
|
+
/** Random bytes32 nonce (must not have been used before for this sender). */
|
|
1114
|
+
nonce: Hex;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Generate a random bytes32 nonce for EIP-3009.
|
|
1118
|
+
* Uses crypto.getRandomValues for cryptographic randomness.
|
|
1119
|
+
*/
|
|
1120
|
+
declare function randomNonce(): Hex;
|
|
1121
|
+
/**
|
|
1122
|
+
* Sign an EIP-3009 TransferWithAuthorization for USDC.
|
|
1123
|
+
*
|
|
1124
|
+
* The resulting signature can be submitted to a facilitator contract that calls
|
|
1125
|
+
* `USDC.transferWithAuthorization(from, to, value, validAfter, validBefore, nonce, v, r, s)`.
|
|
1126
|
+
*
|
|
1127
|
+
* @param privateKey - Signer's private key (must match auth.from)
|
|
1128
|
+
* @param chainId - Chain ID (determines USDC domain name/version)
|
|
1129
|
+
* @param auth - Transfer authorization parameters
|
|
1130
|
+
* @returns EIP-712 signature (65 bytes, 0x-prefixed)
|
|
1131
|
+
*/
|
|
1132
|
+
declare function signTransferWithAuthorization(privateKey: Hex, chainId: number, auth: TransferAuthorization): Promise<Hex>;
|
|
1133
|
+
|
|
1134
|
+
/** Canonical Permit2 contract address (same on all EVM chains). */
|
|
1135
|
+
declare const PERMIT2_ADDRESS: Address;
|
|
1136
|
+
/** x402 facilitator proxy contract address (same on all supported chains). */
|
|
1137
|
+
declare const X402_PROXY_ADDRESS: Address;
|
|
1138
|
+
/**
|
|
1139
|
+
* Witness type string for x402's PermitWitnessTransferFrom.
|
|
1140
|
+
* Must match what the x402 facilitator contract expects.
|
|
1141
|
+
*/
|
|
1142
|
+
declare const WITNESS_TYPE_STRING: "TransferDetails witness)TokenPermissions(address token,uint256 amount)TransferDetails(address to,uint256 requestedAmount)";
|
|
1143
|
+
/** Parameters for Permit2 PermitWitnessTransferFrom. */
|
|
1144
|
+
interface Permit2Authorization {
|
|
1145
|
+
/** Token to transfer. */
|
|
1146
|
+
token: Address;
|
|
1147
|
+
/** Maximum amount the spender can transfer. */
|
|
1148
|
+
amount: bigint;
|
|
1149
|
+
/** Spender address (the x402 proxy). */
|
|
1150
|
+
spender: Address;
|
|
1151
|
+
/** Unique nonce (random uint256). */
|
|
1152
|
+
nonce: bigint;
|
|
1153
|
+
/** Unix timestamp — signature is invalid after this time. */
|
|
1154
|
+
deadline: bigint;
|
|
1155
|
+
/** Witness: recipient address. */
|
|
1156
|
+
witnessTo: Address;
|
|
1157
|
+
/** Witness: requested amount. */
|
|
1158
|
+
witnessRequestedAmount: bigint;
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* Generate a random uint256 nonce for Permit2.
|
|
1162
|
+
* Uses crypto.getRandomValues for cryptographic randomness.
|
|
1163
|
+
*/
|
|
1164
|
+
declare function randomPermit2Nonce(): bigint;
|
|
1165
|
+
/**
|
|
1166
|
+
* Sign a Permit2 PermitWitnessTransferFrom for x402.
|
|
1167
|
+
*
|
|
1168
|
+
* The resulting signature is submitted to the x402 facilitator proxy,
|
|
1169
|
+
* which calls `Permit2.permitWitnessTransferFrom(...)` to settle the payment.
|
|
1170
|
+
*
|
|
1171
|
+
* @param privateKey - Signer's private key (token holder)
|
|
1172
|
+
* @param chainId - Chain ID
|
|
1173
|
+
* @param permit - Permit2 authorization parameters
|
|
1174
|
+
* @returns EIP-712 signature (65 bytes, 0x-prefixed)
|
|
1175
|
+
*/
|
|
1176
|
+
declare function signPermit2WitnessTransfer(privateKey: Hex, chainId: number, permit: Permit2Authorization): Promise<Hex>;
|
|
1177
|
+
|
|
942
1178
|
declare const AxonVaultAbi: readonly [{
|
|
943
1179
|
readonly type: "constructor";
|
|
944
1180
|
readonly inputs: readonly [{
|
|
@@ -3017,4 +3253,4 @@ declare const AxonRegistryAbi: readonly [{
|
|
|
3017
3253
|
readonly inputs: readonly [];
|
|
3018
3254
|
}];
|
|
3019
3255
|
|
|
3020
|
-
export { type AmountInput, AxonClient, type AxonClientConfig, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, type BotConfig, type BotConfigParams, CHAIN_NAMES, Chain, DEFAULT_DEADLINE_SECONDS, type DestinationCheckResult, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, type ExecuteInput, type ExecuteIntent, KNOWN_TOKENS, type KeystoreV3, type KnownToken, type KnownTokenSymbol, NATIVE_ETH, type OperatorCeilings, PAYMENT_INTENT_TYPEHASH, type PayInput, PaymentErrorCode, type PaymentIntent, type PaymentResult, type PaymentStatus, RELAYER_API, type RebalanceTokensResult, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, type SpendingLimit, type SupportedChainId, type SwapInput, type SwapIntent, Token, type TokenInput, type TosStatus, USDC, type VaultInfo, WINDOW, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, encodeRef, encryptKeystore, getBotConfig, getChain, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signSwapIntent };
|
|
3256
|
+
export { type AmountInput, AxonClient, type AxonClientConfig, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, type BotConfig, type BotConfigParams, CHAIN_NAMES, Chain, DEFAULT_DEADLINE_SECONDS, type DestinationCheckResult, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, type ExecuteInput, type ExecuteIntent, KNOWN_TOKENS, type KeystoreV3, type KnownToken, type KnownTokenSymbol, NATIVE_ETH, type OperatorCeilings, PAYMENT_INTENT_TYPEHASH, PERMIT2_ADDRESS, type PayInput, PaymentErrorCode, type PaymentIntent, type PaymentResult, type PaymentStatus, type Permit2Authorization, RELAYER_API, type RebalanceTokensResult, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, type SpendingLimit, type SupportedChainId, type SwapInput, type SwapIntent, Token, type TokenInput, type TosStatus, type TransferAuthorization, USDC, USDC_EIP712_DOMAIN, type VaultInfo, WINDOW, WITNESS_TYPE_STRING, type X402HandleResult, type X402PaymentOption, type X402PaymentRequired, type X402Resource, X402_PROXY_ADDRESS, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, encodeRef, encryptKeystore, extractX402Metadata, findMatchingOption, formatPaymentSignature, getBotConfig, getChain, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, parseChainId, parsePaymentRequired, randomNonce, randomPermit2Nonce, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signPermit2WitnessTransfer, signSwapIntent, signTransferWithAuthorization };
|