@axonfi/sdk 0.1.2 → 0.2.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
@@ -210,7 +210,7 @@ declare function getTokenSymbolByAddress(address: string): string | null;
210
210
  *
211
211
  * @throws if the symbol has no address on the given chain.
212
212
  */
213
- declare function resolveToken(token: Address | Token, chainId: number): Address;
213
+ declare function resolveToken(token: Address | Token | KnownTokenSymbol, chainId: number): Address;
214
214
 
215
215
  /**
216
216
  * keccak256 of the PaymentIntent type string — used for manual digest
@@ -321,6 +321,20 @@ declare const RELAYER_API: {
321
321
  readonly TOS_ACCEPT: "/v1/tos/accept";
322
322
  };
323
323
 
324
+ /**
325
+ * Accepts any way to identify a token:
326
+ * - `Address` ('0x...') — raw contract address
327
+ * - `Token` enum (Token.USDC) — type-safe symbol
328
+ * - `KnownTokenSymbol` string ('USDC') — bare string shorthand
329
+ */
330
+ type TokenInput = Address | Token | KnownTokenSymbol;
331
+ /**
332
+ * Accepts amounts in any format:
333
+ * - `bigint` — raw base units (e.g. 5_000_000n for 5 USDC). Passed through as-is.
334
+ * - `number` — human-readable (e.g. 5.2 for 5.2 USDC). SDK converts using token decimals.
335
+ * - `string` — human-readable string (e.g. '5.2'). Recommended for computed values to avoid float precision issues.
336
+ */
337
+ type AmountInput = bigint | number | string;
324
338
  /** Rolling window spending limit. Stored on-chain, enforced by relayer. */
325
339
  interface SpendingLimit {
326
340
  /** Max spend in this window (token base units, e.g. USDC has 6 decimals). */
@@ -398,10 +412,10 @@ interface PaymentIntent {
398
412
  interface PayInput {
399
413
  /** Payment recipient. */
400
414
  to: Address;
401
- /** Desired output token — an address or a Token enum symbol (e.g. Token.USDC). */
402
- token: Address | Token;
403
- /** Amount in token base units. For USDC: 1 USDC = 1_000_000n. */
404
- amount: bigint;
415
+ /** Desired output token — an address, Token enum, or bare symbol string ('USDC'). */
416
+ token: TokenInput;
417
+ /** Amount: bigint (raw base units), number (human-readable), or string (human-readable). */
418
+ amount: AmountInput;
405
419
  /**
406
420
  * Human-readable payment description. Stored in relayer's PostgreSQL.
407
421
  * Gets keccak256-hashed to populate the on-chain `ref` field.
@@ -497,10 +511,10 @@ interface ExecuteInput {
497
511
  protocol: Address;
498
512
  /** The actual calldata bytes to send to the protocol. */
499
513
  callData: Hex;
500
- /** Token to approve to the protocol — an address or a Token enum symbol. */
501
- token: Address | Token;
502
- /** Amount to approve (in token base units). */
503
- amount: bigint;
514
+ /** Token to approve to the protocol — an address, Token enum, or bare symbol string ('USDC'). */
515
+ token: TokenInput;
516
+ /** Amount to approve: bigint (raw base units), number (human-readable), or string (human-readable). */
517
+ amount: AmountInput;
504
518
  /** Human-readable description. Gets keccak256-hashed to ref. */
505
519
  memo?: string;
506
520
  /**
@@ -516,20 +530,20 @@ interface ExecuteInput {
516
530
  deadline?: bigint;
517
531
  /** Arbitrary metadata stored off-chain. */
518
532
  metadata?: Record<string, string>;
519
- /** Source token for pre-swap (relayer resolves automatically if omitted). */
520
- fromToken?: Address;
521
- /** Max input for pre-swap. */
522
- maxFromAmount?: bigint;
533
+ /** Source token for pre-swap an address, Token enum, or bare symbol string. */
534
+ fromToken?: TokenInput;
535
+ /** Max input for pre-swap: bigint (raw), number (human), or string (human). */
536
+ maxFromAmount?: AmountInput;
523
537
  }
524
538
  /**
525
539
  * Input for AxonClient.swap(). Signs a SwapIntent and submits to
526
540
  * the relayer's POST /v1/swap endpoint.
527
541
  */
528
542
  interface SwapInput {
529
- /** Desired output token — an address or a Token enum symbol. */
530
- toToken: Address | Token;
531
- /** Minimum output amount (slippage floor). */
532
- minToAmount: bigint;
543
+ /** Desired output token — an address, Token enum, or bare symbol string ('WETH'). */
544
+ toToken: TokenInput;
545
+ /** Minimum output amount (slippage floor): bigint (raw), number (human), or string (human). */
546
+ minToAmount: AmountInput;
533
547
  /** Human-readable description. Gets keccak256-hashed to ref. */
534
548
  memo?: string;
535
549
  /** Override ref bytes32 directly. */
@@ -538,10 +552,10 @@ interface SwapInput {
538
552
  idempotencyKey?: string;
539
553
  /** Intent expiry (defaults to 5 min). */
540
554
  deadline?: bigint;
541
- /** Source token to swap from. */
542
- fromToken?: Address;
543
- /** Max input amount for swap. */
544
- maxFromAmount?: bigint;
555
+ /** Source token to swap from — an address, Token enum, or bare symbol string. */
556
+ fromToken?: TokenInput;
557
+ /** Max input amount for swap: bigint (raw), number (human), or string (human). */
558
+ maxFromAmount?: AmountInput;
545
559
  }
546
560
  /** Possible statuses returned by the relayer. */
547
561
  type PaymentStatus = 'approved' | 'pending_review' | 'rejected';
@@ -627,8 +641,8 @@ interface AxonClientConfig {
627
641
  *
628
642
  * const result = await client.pay({
629
643
  * to: '0x...recipient...',
630
- * token: USDC[84532],
631
- * amount: 5_000_000n, // 5 USDC
644
+ * token: 'USDC',
645
+ * amount: 5, // 5 USDC — SDK handles decimals
632
646
  * memo: 'API call #1234 — weather data',
633
647
  * })
634
648
  *
@@ -901,6 +915,40 @@ declare function encryptKeystore(privateKey: Hex, passphrase: string): Promise<K
901
915
  */
902
916
  declare function decryptKeystore(keystore: KeystoreV3 | string, passphrase: string): Promise<Hex>;
903
917
 
918
+ /**
919
+ * Look up decimals for a token by symbol, Token enum, or address.
920
+ *
921
+ * @param token - A KnownTokenSymbol ('USDC'), Token enum (Token.USDC), or address ('0x...')
922
+ * @param chainId - Optional chain ID (unused for decimal lookup, but reserved for future use)
923
+ * @returns The number of decimals for the token
924
+ * @throws If the token is an unknown address with no entry in KNOWN_TOKENS
925
+ */
926
+ declare function resolveTokenDecimals(token: Address | Token | KnownTokenSymbol, chainId?: number): number;
927
+ /**
928
+ * Convert a human-friendly amount to raw base units (bigint).
929
+ *
930
+ * - **bigint** → passed through as-is (already in base units)
931
+ * - **number** → converted to string, then parsed via `parseUnits(str, decimals)`
932
+ * - **string** → parsed directly via `parseUnits(str, decimals)`
933
+ *
934
+ * @param amount - The amount as bigint (raw), number (human), or string (human)
935
+ * @param token - Token identifier used to look up decimals (symbol, enum, or address)
936
+ * @param chainId - Optional chain ID (passed to resolveTokenDecimals)
937
+ * @returns The amount in token base units as bigint
938
+ *
939
+ * @example
940
+ * ```ts
941
+ * parseAmount(5_000_000n, 'USDC') // 5000000n (passthrough)
942
+ * parseAmount(5.2, 'USDC') // 5200000n
943
+ * parseAmount('5.2', 'USDC') // 5200000n
944
+ * parseAmount(0.001, 'WETH') // 1000000000000000n
945
+ * ```
946
+ *
947
+ * @throws If the amount has more decimal places than the token supports
948
+ * @throws If the token is unknown and amount is not bigint
949
+ */
950
+ declare function parseAmount(amount: bigint | number | string, token: Address | Token | KnownTokenSymbol, chainId?: number): bigint;
951
+
904
952
  declare const AxonVaultAbi: readonly [{
905
953
  readonly type: "constructor";
906
954
  readonly inputs: readonly [{
@@ -2998,4 +3046,4 @@ declare const AxonRegistryAbi: readonly [{
2998
3046
  readonly inputs: readonly [];
2999
3047
  }];
3000
3048
 
3001
- export { 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 TosStatus, USDC, type VaultInfo, WINDOW, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, encodeRef, encryptKeystore, getBotConfig, getChain, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getTrackUsedIntents, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, resolveToken, signExecuteIntent, signPayment, signSwapIntent };
3049
+ 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, getTrackUsedIntents, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signSwapIntent };
package/dist/index.d.ts CHANGED
@@ -210,7 +210,7 @@ declare function getTokenSymbolByAddress(address: string): string | null;
210
210
  *
211
211
  * @throws if the symbol has no address on the given chain.
212
212
  */
213
- declare function resolveToken(token: Address | Token, chainId: number): Address;
213
+ declare function resolveToken(token: Address | Token | KnownTokenSymbol, chainId: number): Address;
214
214
 
215
215
  /**
216
216
  * keccak256 of the PaymentIntent type string — used for manual digest
@@ -321,6 +321,20 @@ declare const RELAYER_API: {
321
321
  readonly TOS_ACCEPT: "/v1/tos/accept";
322
322
  };
323
323
 
324
+ /**
325
+ * Accepts any way to identify a token:
326
+ * - `Address` ('0x...') — raw contract address
327
+ * - `Token` enum (Token.USDC) — type-safe symbol
328
+ * - `KnownTokenSymbol` string ('USDC') — bare string shorthand
329
+ */
330
+ type TokenInput = Address | Token | KnownTokenSymbol;
331
+ /**
332
+ * Accepts amounts in any format:
333
+ * - `bigint` — raw base units (e.g. 5_000_000n for 5 USDC). Passed through as-is.
334
+ * - `number` — human-readable (e.g. 5.2 for 5.2 USDC). SDK converts using token decimals.
335
+ * - `string` — human-readable string (e.g. '5.2'). Recommended for computed values to avoid float precision issues.
336
+ */
337
+ type AmountInput = bigint | number | string;
324
338
  /** Rolling window spending limit. Stored on-chain, enforced by relayer. */
325
339
  interface SpendingLimit {
326
340
  /** Max spend in this window (token base units, e.g. USDC has 6 decimals). */
@@ -398,10 +412,10 @@ interface PaymentIntent {
398
412
  interface PayInput {
399
413
  /** Payment recipient. */
400
414
  to: Address;
401
- /** Desired output token — an address or a Token enum symbol (e.g. Token.USDC). */
402
- token: Address | Token;
403
- /** Amount in token base units. For USDC: 1 USDC = 1_000_000n. */
404
- amount: bigint;
415
+ /** Desired output token — an address, Token enum, or bare symbol string ('USDC'). */
416
+ token: TokenInput;
417
+ /** Amount: bigint (raw base units), number (human-readable), or string (human-readable). */
418
+ amount: AmountInput;
405
419
  /**
406
420
  * Human-readable payment description. Stored in relayer's PostgreSQL.
407
421
  * Gets keccak256-hashed to populate the on-chain `ref` field.
@@ -497,10 +511,10 @@ interface ExecuteInput {
497
511
  protocol: Address;
498
512
  /** The actual calldata bytes to send to the protocol. */
499
513
  callData: Hex;
500
- /** Token to approve to the protocol — an address or a Token enum symbol. */
501
- token: Address | Token;
502
- /** Amount to approve (in token base units). */
503
- amount: bigint;
514
+ /** Token to approve to the protocol — an address, Token enum, or bare symbol string ('USDC'). */
515
+ token: TokenInput;
516
+ /** Amount to approve: bigint (raw base units), number (human-readable), or string (human-readable). */
517
+ amount: AmountInput;
504
518
  /** Human-readable description. Gets keccak256-hashed to ref. */
505
519
  memo?: string;
506
520
  /**
@@ -516,20 +530,20 @@ interface ExecuteInput {
516
530
  deadline?: bigint;
517
531
  /** Arbitrary metadata stored off-chain. */
518
532
  metadata?: Record<string, string>;
519
- /** Source token for pre-swap (relayer resolves automatically if omitted). */
520
- fromToken?: Address;
521
- /** Max input for pre-swap. */
522
- maxFromAmount?: bigint;
533
+ /** Source token for pre-swap an address, Token enum, or bare symbol string. */
534
+ fromToken?: TokenInput;
535
+ /** Max input for pre-swap: bigint (raw), number (human), or string (human). */
536
+ maxFromAmount?: AmountInput;
523
537
  }
524
538
  /**
525
539
  * Input for AxonClient.swap(). Signs a SwapIntent and submits to
526
540
  * the relayer's POST /v1/swap endpoint.
527
541
  */
528
542
  interface SwapInput {
529
- /** Desired output token — an address or a Token enum symbol. */
530
- toToken: Address | Token;
531
- /** Minimum output amount (slippage floor). */
532
- minToAmount: bigint;
543
+ /** Desired output token — an address, Token enum, or bare symbol string ('WETH'). */
544
+ toToken: TokenInput;
545
+ /** Minimum output amount (slippage floor): bigint (raw), number (human), or string (human). */
546
+ minToAmount: AmountInput;
533
547
  /** Human-readable description. Gets keccak256-hashed to ref. */
534
548
  memo?: string;
535
549
  /** Override ref bytes32 directly. */
@@ -538,10 +552,10 @@ interface SwapInput {
538
552
  idempotencyKey?: string;
539
553
  /** Intent expiry (defaults to 5 min). */
540
554
  deadline?: bigint;
541
- /** Source token to swap from. */
542
- fromToken?: Address;
543
- /** Max input amount for swap. */
544
- maxFromAmount?: bigint;
555
+ /** Source token to swap from — an address, Token enum, or bare symbol string. */
556
+ fromToken?: TokenInput;
557
+ /** Max input amount for swap: bigint (raw), number (human), or string (human). */
558
+ maxFromAmount?: AmountInput;
545
559
  }
546
560
  /** Possible statuses returned by the relayer. */
547
561
  type PaymentStatus = 'approved' | 'pending_review' | 'rejected';
@@ -627,8 +641,8 @@ interface AxonClientConfig {
627
641
  *
628
642
  * const result = await client.pay({
629
643
  * to: '0x...recipient...',
630
- * token: USDC[84532],
631
- * amount: 5_000_000n, // 5 USDC
644
+ * token: 'USDC',
645
+ * amount: 5, // 5 USDC — SDK handles decimals
632
646
  * memo: 'API call #1234 — weather data',
633
647
  * })
634
648
  *
@@ -901,6 +915,40 @@ declare function encryptKeystore(privateKey: Hex, passphrase: string): Promise<K
901
915
  */
902
916
  declare function decryptKeystore(keystore: KeystoreV3 | string, passphrase: string): Promise<Hex>;
903
917
 
918
+ /**
919
+ * Look up decimals for a token by symbol, Token enum, or address.
920
+ *
921
+ * @param token - A KnownTokenSymbol ('USDC'), Token enum (Token.USDC), or address ('0x...')
922
+ * @param chainId - Optional chain ID (unused for decimal lookup, but reserved for future use)
923
+ * @returns The number of decimals for the token
924
+ * @throws If the token is an unknown address with no entry in KNOWN_TOKENS
925
+ */
926
+ declare function resolveTokenDecimals(token: Address | Token | KnownTokenSymbol, chainId?: number): number;
927
+ /**
928
+ * Convert a human-friendly amount to raw base units (bigint).
929
+ *
930
+ * - **bigint** → passed through as-is (already in base units)
931
+ * - **number** → converted to string, then parsed via `parseUnits(str, decimals)`
932
+ * - **string** → parsed directly via `parseUnits(str, decimals)`
933
+ *
934
+ * @param amount - The amount as bigint (raw), number (human), or string (human)
935
+ * @param token - Token identifier used to look up decimals (symbol, enum, or address)
936
+ * @param chainId - Optional chain ID (passed to resolveTokenDecimals)
937
+ * @returns The amount in token base units as bigint
938
+ *
939
+ * @example
940
+ * ```ts
941
+ * parseAmount(5_000_000n, 'USDC') // 5000000n (passthrough)
942
+ * parseAmount(5.2, 'USDC') // 5200000n
943
+ * parseAmount('5.2', 'USDC') // 5200000n
944
+ * parseAmount(0.001, 'WETH') // 1000000000000000n
945
+ * ```
946
+ *
947
+ * @throws If the amount has more decimal places than the token supports
948
+ * @throws If the token is unknown and amount is not bigint
949
+ */
950
+ declare function parseAmount(amount: bigint | number | string, token: Address | Token | KnownTokenSymbol, chainId?: number): bigint;
951
+
904
952
  declare const AxonVaultAbi: readonly [{
905
953
  readonly type: "constructor";
906
954
  readonly inputs: readonly [{
@@ -2998,4 +3046,4 @@ declare const AxonRegistryAbi: readonly [{
2998
3046
  readonly inputs: readonly [];
2999
3047
  }];
3000
3048
 
3001
- export { 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 TosStatus, USDC, type VaultInfo, WINDOW, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, encodeRef, encryptKeystore, getBotConfig, getChain, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getTrackUsedIntents, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, resolveToken, signExecuteIntent, signPayment, signSwapIntent };
3049
+ 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, getTrackUsedIntents, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signSwapIntent };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { keccak256, stringToBytes, createPublicClient, http, createWalletClient } from 'viem';
1
+ import { keccak256, stringToBytes, createPublicClient, http, createWalletClient, parseUnits } from 'viem';
2
2
  import { privateKeyToAccount } from 'viem/accounts';
3
3
  import { arbitrumSepolia, arbitrum, baseSepolia, base } from 'viem/chains';
4
4
  import { scryptAsync } from '@noble/hashes/scrypt';
@@ -3005,6 +3005,42 @@ function resolveToken(token, chainId) {
3005
3005
  }
3006
3006
  return addr;
3007
3007
  }
3008
+ function resolveTokenDecimals(token, chainId) {
3009
+ if (typeof token === "string" && token.startsWith("0x")) {
3010
+ const symbol = getTokenSymbolByAddress(token);
3011
+ if (!symbol) {
3012
+ throw new Error(
3013
+ `Unknown token address ${token} \u2014 cannot determine decimals. Use a bigint amount instead, or pass a known token symbol.`
3014
+ );
3015
+ }
3016
+ const entry2 = KNOWN_TOKENS[symbol];
3017
+ return entry2.decimals;
3018
+ }
3019
+ const entry = KNOWN_TOKENS[token];
3020
+ if (!entry) {
3021
+ throw new Error(
3022
+ `Unknown token symbol "${token}" \u2014 cannot determine decimals. Use a bigint amount instead, or use a known symbol (${Object.keys(KNOWN_TOKENS).join(", ")}).`
3023
+ );
3024
+ }
3025
+ return entry.decimals;
3026
+ }
3027
+ function parseAmount(amount, token, chainId) {
3028
+ if (typeof amount === "bigint") {
3029
+ return amount;
3030
+ }
3031
+ const decimals = resolveTokenDecimals(token);
3032
+ const str = typeof amount === "number" ? amount.toString() : amount;
3033
+ const dotIndex = str.indexOf(".");
3034
+ if (dotIndex !== -1) {
3035
+ const decimalPlaces = str.length - dotIndex - 1;
3036
+ if (decimalPlaces > decimals) {
3037
+ throw new Error(
3038
+ `Amount "${str}" has ${decimalPlaces} decimal places, but ${typeof token === "string" && token.startsWith("0x") ? "this token" : token} only supports ${decimals}. Truncate or round your amount.`
3039
+ );
3040
+ }
3041
+ }
3042
+ return parseUnits(str, decimals);
3043
+ }
3008
3044
 
3009
3045
  // src/utils.ts
3010
3046
  function generateUuid() {
@@ -3282,7 +3318,7 @@ Timestamp: ${timestamp}`;
3282
3318
  bot: this.botAddress,
3283
3319
  to: input.to,
3284
3320
  token: resolveToken(input.token, this.chainId),
3285
- amount: input.amount,
3321
+ amount: parseAmount(input.amount, input.token, this.chainId),
3286
3322
  deadline: input.deadline ?? this._defaultDeadline(),
3287
3323
  ref: this._resolveRef(input.memo, input.ref)
3288
3324
  };
@@ -3293,7 +3329,7 @@ Timestamp: ${timestamp}`;
3293
3329
  protocol: input.protocol,
3294
3330
  calldataHash: keccak256(input.callData),
3295
3331
  token: resolveToken(input.token, this.chainId),
3296
- amount: input.amount,
3332
+ amount: parseAmount(input.amount, input.token, this.chainId),
3297
3333
  deadline: input.deadline ?? this._defaultDeadline(),
3298
3334
  ref: this._resolveRef(input.memo, input.ref)
3299
3335
  };
@@ -3302,7 +3338,7 @@ Timestamp: ${timestamp}`;
3302
3338
  return {
3303
3339
  bot: this.botAddress,
3304
3340
  toToken: resolveToken(input.toToken, this.chainId),
3305
- minToAmount: input.minToAmount,
3341
+ minToAmount: parseAmount(input.minToAmount, input.toToken, this.chainId),
3306
3342
  deadline: input.deadline ?? this._defaultDeadline(),
3307
3343
  ref: this._resolveRef(input.memo, input.ref)
3308
3344
  };
@@ -3334,6 +3370,8 @@ Timestamp: ${timestamp}`;
3334
3370
  }
3335
3371
  async _submitExecute(intent, signature, input) {
3336
3372
  const idempotencyKey = input.idempotencyKey ?? generateUuid();
3373
+ const fromToken = input.fromToken !== void 0 ? resolveToken(input.fromToken, this.chainId) : void 0;
3374
+ const maxFromAmount = input.maxFromAmount !== void 0 ? parseAmount(input.maxFromAmount, input.fromToken ?? input.token, this.chainId) : void 0;
3337
3375
  const body = {
3338
3376
  chainId: this.chainId,
3339
3377
  vaultAddress: this.vaultAddress,
@@ -3349,8 +3387,8 @@ Timestamp: ${timestamp}`;
3349
3387
  // Protocol calldata
3350
3388
  callData: input.callData,
3351
3389
  // Optional pre-swap
3352
- ...input.fromToken !== void 0 && { fromToken: input.fromToken },
3353
- ...input.maxFromAmount !== void 0 && { maxFromAmount: input.maxFromAmount.toString() },
3390
+ ...fromToken !== void 0 && { fromToken },
3391
+ ...maxFromAmount !== void 0 && { maxFromAmount: maxFromAmount.toString() },
3354
3392
  // Off-chain metadata
3355
3393
  idempotencyKey,
3356
3394
  ...input.memo !== void 0 && { memo: input.memo },
@@ -3361,6 +3399,8 @@ Timestamp: ${timestamp}`;
3361
3399
  }
3362
3400
  async _submitSwap(intent, signature, input) {
3363
3401
  const idempotencyKey = input.idempotencyKey ?? generateUuid();
3402
+ const fromToken = input.fromToken !== void 0 ? resolveToken(input.fromToken, this.chainId) : void 0;
3403
+ const maxFromAmount = input.maxFromAmount !== void 0 ? parseAmount(input.maxFromAmount, input.fromToken ?? input.toToken, this.chainId) : void 0;
3364
3404
  const body = {
3365
3405
  chainId: this.chainId,
3366
3406
  vaultAddress: this.vaultAddress,
@@ -3372,8 +3412,8 @@ Timestamp: ${timestamp}`;
3372
3412
  ref: intent.ref,
3373
3413
  signature,
3374
3414
  // Optional source token
3375
- ...input.fromToken !== void 0 && { fromToken: input.fromToken },
3376
- ...input.maxFromAmount !== void 0 && { maxFromAmount: input.maxFromAmount.toString() },
3415
+ ...fromToken !== void 0 && { fromToken },
3416
+ ...maxFromAmount !== void 0 && { maxFromAmount: maxFromAmount.toString() },
3377
3417
  // Off-chain metadata
3378
3418
  idempotencyKey,
3379
3419
  ...input.memo !== void 0 && { memo: input.memo }
@@ -3883,6 +3923,6 @@ var AxonRegistryAbi = [
3883
3923
  }
3884
3924
  ];
3885
3925
 
3886
- export { AxonClient, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, CHAIN_NAMES, Chain, DEFAULT_DEADLINE_SECONDS, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, KNOWN_TOKENS, NATIVE_ETH, PAYMENT_INTENT_TYPEHASH, PaymentErrorCode, RELAYER_API, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, Token, USDC, WINDOW, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, encodeRef, encryptKeystore, getBotConfig, getChain, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getTrackUsedIntents, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, resolveToken, signExecuteIntent, signPayment, signSwapIntent };
3926
+ export { AxonClient, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, CHAIN_NAMES, Chain, DEFAULT_DEADLINE_SECONDS, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, KNOWN_TOKENS, NATIVE_ETH, PAYMENT_INTENT_TYPEHASH, PaymentErrorCode, RELAYER_API, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, Token, USDC, WINDOW, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, encodeRef, encryptKeystore, getBotConfig, getChain, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getTrackUsedIntents, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signSwapIntent };
3887
3927
  //# sourceMappingURL=index.js.map
3888
3928
  //# sourceMappingURL=index.js.map