@axonfi/sdk 0.4.4 → 0.5.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 +95 -10
- package/dist/index.cjs +111 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +96 -4
- package/dist/index.d.ts +96 -4
- package/dist/index.js +108 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -382,7 +382,7 @@ interface BotConfig {
|
|
|
382
382
|
/** Relayer always requires AI scan for this bot regardless of amount. */
|
|
383
383
|
requireAiVerification: boolean;
|
|
384
384
|
}
|
|
385
|
-
/** Parameters for addBot / updateBotConfig. */
|
|
385
|
+
/** Parameters for addBot / updateBotConfig (raw on-chain format). */
|
|
386
386
|
interface BotConfigParams {
|
|
387
387
|
maxPerTxAmount: bigint;
|
|
388
388
|
/** Hard cap for rebalancing (executeSwap) input amount in USD. 0 = no cap (default). */
|
|
@@ -391,6 +391,33 @@ interface BotConfigParams {
|
|
|
391
391
|
aiTriggerThreshold: bigint;
|
|
392
392
|
requireAiVerification: boolean;
|
|
393
393
|
}
|
|
394
|
+
/** Human-friendly spending limit input. SDK converts dollar amounts to 6-decimal base units. */
|
|
395
|
+
interface SpendingLimitInput {
|
|
396
|
+
/** Max spend in this window in USD (e.g. 1000 = $1,000). */
|
|
397
|
+
amount: number;
|
|
398
|
+
/** Max transactions in this window. 0 = no count limit. */
|
|
399
|
+
maxCount: number;
|
|
400
|
+
/** Window size in seconds: 3600=1h, 86400=1d, 604800=1w. Use WINDOW constants. */
|
|
401
|
+
windowSeconds: number;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Human-friendly bot config input for addBot / updateBotConfig.
|
|
405
|
+
*
|
|
406
|
+
* Dollar amounts are plain numbers (e.g. 100 = $100). The SDK converts
|
|
407
|
+
* to 6-decimal base units (USDC precision) before sending to the contract.
|
|
408
|
+
*/
|
|
409
|
+
interface BotConfigInput {
|
|
410
|
+
/** Hard per-tx cap in USD (e.g. 100 = $100). 0 = no cap. */
|
|
411
|
+
maxPerTxAmount: number;
|
|
412
|
+
/** Hard rebalance cap in USD (e.g. 50 = $50). 0 = no cap. */
|
|
413
|
+
maxRebalanceAmount: number;
|
|
414
|
+
/** Rolling window spending limits. Up to 5. */
|
|
415
|
+
spendingLimits: SpendingLimitInput[];
|
|
416
|
+
/** AI scan trigger threshold in USD (e.g. 50 = $50). 0 = never by amount. */
|
|
417
|
+
aiTriggerThreshold: number;
|
|
418
|
+
/** Always require AI scan regardless of amount. */
|
|
419
|
+
requireAiVerification: boolean;
|
|
420
|
+
}
|
|
394
421
|
/** Owner-set ceilings bounding operator actions. */
|
|
395
422
|
interface OperatorCeilings {
|
|
396
423
|
/** Operator cannot set a bot's maxPerTxAmount above this. 0 = no ceiling. */
|
|
@@ -963,6 +990,8 @@ declare function getChain(chainId: number): Chain$1;
|
|
|
963
990
|
declare function createAxonPublicClient(chainId: number, rpcUrl: string): PublicClient;
|
|
964
991
|
/** Create a viem WalletClient from a raw private key (signing-only, no RPC needed). */
|
|
965
992
|
declare function createAxonWalletClient(privateKey: Hex, chainId: number): WalletClient;
|
|
993
|
+
/** Convert human-friendly BotConfigInput (dollar amounts) to on-chain BotConfigParams (6-decimal bigints). */
|
|
994
|
+
declare function toBotConfigParams(input: BotConfigInput): BotConfigParams;
|
|
966
995
|
/**
|
|
967
996
|
* Returns the full BotConfig for a bot address from the vault.
|
|
968
997
|
* If the bot has never been added, isActive will be false and all
|
|
@@ -1009,11 +1038,74 @@ declare function isRebalanceTokenWhitelisted(publicClient: PublicClient, vaultAd
|
|
|
1009
1038
|
* The vault is owned by the walletClient's account. Permissionless — any
|
|
1010
1039
|
* address can deploy, no Axon approval required.
|
|
1011
1040
|
*
|
|
1041
|
+
* The factory address is fetched automatically from the Axon relayer.
|
|
1042
|
+
*
|
|
1012
1043
|
* @param walletClient Wallet that will own the deployed vault.
|
|
1013
|
-
* @param
|
|
1044
|
+
* @param publicClient Public client for the vault's chain.
|
|
1045
|
+
* @param relayerUrl Override relayer URL (defaults to https://relay.axonfi.xyz).
|
|
1014
1046
|
* @returns Address of the newly deployed vault.
|
|
1015
1047
|
*/
|
|
1016
|
-
declare function deployVault(walletClient: WalletClient, publicClient: PublicClient,
|
|
1048
|
+
declare function deployVault(walletClient: WalletClient, publicClient: PublicClient, relayerUrl?: string): Promise<Address>;
|
|
1049
|
+
/**
|
|
1050
|
+
* Register a bot on the vault with its initial spending configuration.
|
|
1051
|
+
*
|
|
1052
|
+
* Must be called by the vault owner (or operator if ceilings allow).
|
|
1053
|
+
* This is an on-chain transaction — requires gas on the owner's wallet.
|
|
1054
|
+
*
|
|
1055
|
+
* @param walletClient Owner wallet (must be vault owner or authorized operator).
|
|
1056
|
+
* @param publicClient Public client for the vault's chain.
|
|
1057
|
+
* @param vaultAddress Vault to register the bot on.
|
|
1058
|
+
* @param botAddress Public address of the bot to register.
|
|
1059
|
+
* @param config Bot spending configuration — human-readable USD amounts (e.g. 100 = $100).
|
|
1060
|
+
* @returns Transaction hash.
|
|
1061
|
+
*/
|
|
1062
|
+
declare function addBot(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, botAddress: Address, config: BotConfigInput): Promise<Hex>;
|
|
1063
|
+
/**
|
|
1064
|
+
* Update an existing bot's spending configuration.
|
|
1065
|
+
*
|
|
1066
|
+
* Must be called by the vault owner (or operator within ceilings).
|
|
1067
|
+
* On-chain transaction — requires gas.
|
|
1068
|
+
*
|
|
1069
|
+
* @param walletClient Owner/operator wallet.
|
|
1070
|
+
* @param publicClient Public client for the vault's chain.
|
|
1071
|
+
* @param vaultAddress Vault the bot is registered on.
|
|
1072
|
+
* @param botAddress Bot to update.
|
|
1073
|
+
* @param config New spending configuration — human-readable USD amounts.
|
|
1074
|
+
* @returns Transaction hash.
|
|
1075
|
+
*/
|
|
1076
|
+
declare function updateBotConfig(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, botAddress: Address, config: BotConfigInput): Promise<Hex>;
|
|
1077
|
+
/**
|
|
1078
|
+
* Remove a bot from the vault whitelist.
|
|
1079
|
+
*
|
|
1080
|
+
* Must be called by the vault owner (or operator).
|
|
1081
|
+
* The bot will immediately lose the ability to sign valid intents.
|
|
1082
|
+
* On-chain transaction — requires gas.
|
|
1083
|
+
*
|
|
1084
|
+
* @param walletClient Owner/operator wallet.
|
|
1085
|
+
* @param publicClient Public client for the vault's chain.
|
|
1086
|
+
* @param vaultAddress Vault to remove the bot from.
|
|
1087
|
+
* @param botAddress Bot to remove.
|
|
1088
|
+
* @returns Transaction hash.
|
|
1089
|
+
*/
|
|
1090
|
+
declare function removeBot(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, botAddress: Address): Promise<Hex>;
|
|
1091
|
+
/**
|
|
1092
|
+
* Deposit tokens or native ETH into the vault.
|
|
1093
|
+
*
|
|
1094
|
+
* Permissionless — anyone can deposit. For ERC-20 tokens, this function
|
|
1095
|
+
* handles the approve + deposit in one call. For native ETH, pass
|
|
1096
|
+
* `NATIVE_ETH` (or `'ETH'`) as the token.
|
|
1097
|
+
*
|
|
1098
|
+
* On-chain transaction — requires gas on the depositor's wallet.
|
|
1099
|
+
*
|
|
1100
|
+
* @param walletClient Wallet sending the deposit (anyone, not just owner).
|
|
1101
|
+
* @param publicClient Public client for the vault's chain.
|
|
1102
|
+
* @param vaultAddress Vault to deposit into.
|
|
1103
|
+
* @param token Token address, or NATIVE_ETH for ETH deposits.
|
|
1104
|
+
* @param amount Amount in base units (e.g. 5_000_000n for 5 USDC, 10n**16n for 0.01 ETH).
|
|
1105
|
+
* @param ref Optional bytes32 reference linking to an off-chain record. Defaults to 0x0.
|
|
1106
|
+
* @returns Transaction hash of the deposit.
|
|
1107
|
+
*/
|
|
1108
|
+
declare function deposit(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, token: Address, amount: bigint, ref?: Hex): Promise<Hex>;
|
|
1017
1109
|
|
|
1018
1110
|
interface KeystoreV3 {
|
|
1019
1111
|
version: 3;
|
|
@@ -3338,4 +3430,4 @@ declare const AxonRegistryAbi: readonly [{
|
|
|
3338
3430
|
readonly inputs: readonly [];
|
|
3339
3431
|
}];
|
|
3340
3432
|
|
|
3341
|
-
export { type AmountInput, AxonClient, type AxonClientConfig, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, type BotConfig, type BotConfigParams, CHAIN_NAMES, Chain, DEFAULT_APPROVED_TOKENS, 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, getDefaultApprovedTokens, 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 };
|
|
3433
|
+
export { type AmountInput, AxonClient, type AxonClientConfig, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, type BotConfig, type BotConfigInput, type BotConfigParams, CHAIN_NAMES, Chain, DEFAULT_APPROVED_TOKENS, 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 SpendingLimitInput, 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, addBot, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, deposit, encodeRef, encryptKeystore, extractX402Metadata, findMatchingOption, formatPaymentSignature, getBotConfig, getChain, getDefaultApprovedTokens, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, parseChainId, parsePaymentRequired, randomNonce, randomPermit2Nonce, removeBot, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signPermit2WitnessTransfer, signSwapIntent, signTransferWithAuthorization, toBotConfigParams, updateBotConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -382,7 +382,7 @@ interface BotConfig {
|
|
|
382
382
|
/** Relayer always requires AI scan for this bot regardless of amount. */
|
|
383
383
|
requireAiVerification: boolean;
|
|
384
384
|
}
|
|
385
|
-
/** Parameters for addBot / updateBotConfig. */
|
|
385
|
+
/** Parameters for addBot / updateBotConfig (raw on-chain format). */
|
|
386
386
|
interface BotConfigParams {
|
|
387
387
|
maxPerTxAmount: bigint;
|
|
388
388
|
/** Hard cap for rebalancing (executeSwap) input amount in USD. 0 = no cap (default). */
|
|
@@ -391,6 +391,33 @@ interface BotConfigParams {
|
|
|
391
391
|
aiTriggerThreshold: bigint;
|
|
392
392
|
requireAiVerification: boolean;
|
|
393
393
|
}
|
|
394
|
+
/** Human-friendly spending limit input. SDK converts dollar amounts to 6-decimal base units. */
|
|
395
|
+
interface SpendingLimitInput {
|
|
396
|
+
/** Max spend in this window in USD (e.g. 1000 = $1,000). */
|
|
397
|
+
amount: number;
|
|
398
|
+
/** Max transactions in this window. 0 = no count limit. */
|
|
399
|
+
maxCount: number;
|
|
400
|
+
/** Window size in seconds: 3600=1h, 86400=1d, 604800=1w. Use WINDOW constants. */
|
|
401
|
+
windowSeconds: number;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Human-friendly bot config input for addBot / updateBotConfig.
|
|
405
|
+
*
|
|
406
|
+
* Dollar amounts are plain numbers (e.g. 100 = $100). The SDK converts
|
|
407
|
+
* to 6-decimal base units (USDC precision) before sending to the contract.
|
|
408
|
+
*/
|
|
409
|
+
interface BotConfigInput {
|
|
410
|
+
/** Hard per-tx cap in USD (e.g. 100 = $100). 0 = no cap. */
|
|
411
|
+
maxPerTxAmount: number;
|
|
412
|
+
/** Hard rebalance cap in USD (e.g. 50 = $50). 0 = no cap. */
|
|
413
|
+
maxRebalanceAmount: number;
|
|
414
|
+
/** Rolling window spending limits. Up to 5. */
|
|
415
|
+
spendingLimits: SpendingLimitInput[];
|
|
416
|
+
/** AI scan trigger threshold in USD (e.g. 50 = $50). 0 = never by amount. */
|
|
417
|
+
aiTriggerThreshold: number;
|
|
418
|
+
/** Always require AI scan regardless of amount. */
|
|
419
|
+
requireAiVerification: boolean;
|
|
420
|
+
}
|
|
394
421
|
/** Owner-set ceilings bounding operator actions. */
|
|
395
422
|
interface OperatorCeilings {
|
|
396
423
|
/** Operator cannot set a bot's maxPerTxAmount above this. 0 = no ceiling. */
|
|
@@ -963,6 +990,8 @@ declare function getChain(chainId: number): Chain$1;
|
|
|
963
990
|
declare function createAxonPublicClient(chainId: number, rpcUrl: string): PublicClient;
|
|
964
991
|
/** Create a viem WalletClient from a raw private key (signing-only, no RPC needed). */
|
|
965
992
|
declare function createAxonWalletClient(privateKey: Hex, chainId: number): WalletClient;
|
|
993
|
+
/** Convert human-friendly BotConfigInput (dollar amounts) to on-chain BotConfigParams (6-decimal bigints). */
|
|
994
|
+
declare function toBotConfigParams(input: BotConfigInput): BotConfigParams;
|
|
966
995
|
/**
|
|
967
996
|
* Returns the full BotConfig for a bot address from the vault.
|
|
968
997
|
* If the bot has never been added, isActive will be false and all
|
|
@@ -1009,11 +1038,74 @@ declare function isRebalanceTokenWhitelisted(publicClient: PublicClient, vaultAd
|
|
|
1009
1038
|
* The vault is owned by the walletClient's account. Permissionless — any
|
|
1010
1039
|
* address can deploy, no Axon approval required.
|
|
1011
1040
|
*
|
|
1041
|
+
* The factory address is fetched automatically from the Axon relayer.
|
|
1042
|
+
*
|
|
1012
1043
|
* @param walletClient Wallet that will own the deployed vault.
|
|
1013
|
-
* @param
|
|
1044
|
+
* @param publicClient Public client for the vault's chain.
|
|
1045
|
+
* @param relayerUrl Override relayer URL (defaults to https://relay.axonfi.xyz).
|
|
1014
1046
|
* @returns Address of the newly deployed vault.
|
|
1015
1047
|
*/
|
|
1016
|
-
declare function deployVault(walletClient: WalletClient, publicClient: PublicClient,
|
|
1048
|
+
declare function deployVault(walletClient: WalletClient, publicClient: PublicClient, relayerUrl?: string): Promise<Address>;
|
|
1049
|
+
/**
|
|
1050
|
+
* Register a bot on the vault with its initial spending configuration.
|
|
1051
|
+
*
|
|
1052
|
+
* Must be called by the vault owner (or operator if ceilings allow).
|
|
1053
|
+
* This is an on-chain transaction — requires gas on the owner's wallet.
|
|
1054
|
+
*
|
|
1055
|
+
* @param walletClient Owner wallet (must be vault owner or authorized operator).
|
|
1056
|
+
* @param publicClient Public client for the vault's chain.
|
|
1057
|
+
* @param vaultAddress Vault to register the bot on.
|
|
1058
|
+
* @param botAddress Public address of the bot to register.
|
|
1059
|
+
* @param config Bot spending configuration — human-readable USD amounts (e.g. 100 = $100).
|
|
1060
|
+
* @returns Transaction hash.
|
|
1061
|
+
*/
|
|
1062
|
+
declare function addBot(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, botAddress: Address, config: BotConfigInput): Promise<Hex>;
|
|
1063
|
+
/**
|
|
1064
|
+
* Update an existing bot's spending configuration.
|
|
1065
|
+
*
|
|
1066
|
+
* Must be called by the vault owner (or operator within ceilings).
|
|
1067
|
+
* On-chain transaction — requires gas.
|
|
1068
|
+
*
|
|
1069
|
+
* @param walletClient Owner/operator wallet.
|
|
1070
|
+
* @param publicClient Public client for the vault's chain.
|
|
1071
|
+
* @param vaultAddress Vault the bot is registered on.
|
|
1072
|
+
* @param botAddress Bot to update.
|
|
1073
|
+
* @param config New spending configuration — human-readable USD amounts.
|
|
1074
|
+
* @returns Transaction hash.
|
|
1075
|
+
*/
|
|
1076
|
+
declare function updateBotConfig(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, botAddress: Address, config: BotConfigInput): Promise<Hex>;
|
|
1077
|
+
/**
|
|
1078
|
+
* Remove a bot from the vault whitelist.
|
|
1079
|
+
*
|
|
1080
|
+
* Must be called by the vault owner (or operator).
|
|
1081
|
+
* The bot will immediately lose the ability to sign valid intents.
|
|
1082
|
+
* On-chain transaction — requires gas.
|
|
1083
|
+
*
|
|
1084
|
+
* @param walletClient Owner/operator wallet.
|
|
1085
|
+
* @param publicClient Public client for the vault's chain.
|
|
1086
|
+
* @param vaultAddress Vault to remove the bot from.
|
|
1087
|
+
* @param botAddress Bot to remove.
|
|
1088
|
+
* @returns Transaction hash.
|
|
1089
|
+
*/
|
|
1090
|
+
declare function removeBot(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, botAddress: Address): Promise<Hex>;
|
|
1091
|
+
/**
|
|
1092
|
+
* Deposit tokens or native ETH into the vault.
|
|
1093
|
+
*
|
|
1094
|
+
* Permissionless — anyone can deposit. For ERC-20 tokens, this function
|
|
1095
|
+
* handles the approve + deposit in one call. For native ETH, pass
|
|
1096
|
+
* `NATIVE_ETH` (or `'ETH'`) as the token.
|
|
1097
|
+
*
|
|
1098
|
+
* On-chain transaction — requires gas on the depositor's wallet.
|
|
1099
|
+
*
|
|
1100
|
+
* @param walletClient Wallet sending the deposit (anyone, not just owner).
|
|
1101
|
+
* @param publicClient Public client for the vault's chain.
|
|
1102
|
+
* @param vaultAddress Vault to deposit into.
|
|
1103
|
+
* @param token Token address, or NATIVE_ETH for ETH deposits.
|
|
1104
|
+
* @param amount Amount in base units (e.g. 5_000_000n for 5 USDC, 10n**16n for 0.01 ETH).
|
|
1105
|
+
* @param ref Optional bytes32 reference linking to an off-chain record. Defaults to 0x0.
|
|
1106
|
+
* @returns Transaction hash of the deposit.
|
|
1107
|
+
*/
|
|
1108
|
+
declare function deposit(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, token: Address, amount: bigint, ref?: Hex): Promise<Hex>;
|
|
1017
1109
|
|
|
1018
1110
|
interface KeystoreV3 {
|
|
1019
1111
|
version: 3;
|
|
@@ -3338,4 +3430,4 @@ declare const AxonRegistryAbi: readonly [{
|
|
|
3338
3430
|
readonly inputs: readonly [];
|
|
3339
3431
|
}];
|
|
3340
3432
|
|
|
3341
|
-
export { type AmountInput, AxonClient, type AxonClientConfig, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, type BotConfig, type BotConfigParams, CHAIN_NAMES, Chain, DEFAULT_APPROVED_TOKENS, 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, getDefaultApprovedTokens, 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 };
|
|
3433
|
+
export { type AmountInput, AxonClient, type AxonClientConfig, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, type BotConfig, type BotConfigInput, type BotConfigParams, CHAIN_NAMES, Chain, DEFAULT_APPROVED_TOKENS, 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 SpendingLimitInput, 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, addBot, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, deposit, encodeRef, encryptKeystore, extractX402Metadata, findMatchingOption, formatPaymentSignature, getBotConfig, getChain, getDefaultApprovedTokens, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, parseChainId, parsePaymentRequired, randomNonce, randomPermit2Nonce, removeBot, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signPermit2WitnessTransfer, signSwapIntent, signTransferWithAuthorization, toBotConfigParams, updateBotConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { keccak256, stringToBytes, createPublicClient, http, createWalletClient, parseUnits } from 'viem';
|
|
1
|
+
import { keccak256, stringToBytes, createPublicClient, http, createWalletClient, erc20Abi, 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';
|
|
@@ -2544,8 +2544,6 @@ var AxonVaultFactoryAbi = [
|
|
|
2544
2544
|
"inputs": []
|
|
2545
2545
|
}
|
|
2546
2546
|
];
|
|
2547
|
-
|
|
2548
|
-
// src/vault.ts
|
|
2549
2547
|
function getChain(chainId) {
|
|
2550
2548
|
switch (chainId) {
|
|
2551
2549
|
case 8453:
|
|
@@ -2577,6 +2575,33 @@ function createAxonWalletClient(privateKey, chainId) {
|
|
|
2577
2575
|
// signing is local — transport is unused but required by viem
|
|
2578
2576
|
});
|
|
2579
2577
|
}
|
|
2578
|
+
var USDC_DECIMALS = 6n;
|
|
2579
|
+
var USDC_UNIT = 10n ** USDC_DECIMALS;
|
|
2580
|
+
function toBotConfigParams(input) {
|
|
2581
|
+
return {
|
|
2582
|
+
maxPerTxAmount: BigInt(Math.round(input.maxPerTxAmount * Number(USDC_UNIT))),
|
|
2583
|
+
maxRebalanceAmount: BigInt(Math.round(input.maxRebalanceAmount * Number(USDC_UNIT))),
|
|
2584
|
+
spendingLimits: input.spendingLimits.map((sl) => ({
|
|
2585
|
+
amount: BigInt(Math.round(sl.amount * Number(USDC_UNIT))),
|
|
2586
|
+
maxCount: BigInt(sl.maxCount),
|
|
2587
|
+
windowSeconds: BigInt(sl.windowSeconds)
|
|
2588
|
+
})),
|
|
2589
|
+
aiTriggerThreshold: BigInt(Math.round(input.aiTriggerThreshold * Number(USDC_UNIT))),
|
|
2590
|
+
requireAiVerification: input.requireAiVerification
|
|
2591
|
+
};
|
|
2592
|
+
}
|
|
2593
|
+
var DEFAULT_RELAYER_URL = "https://relay.axonfi.xyz";
|
|
2594
|
+
async function getFactoryAddress(chainId, relayerUrl) {
|
|
2595
|
+
const base2 = relayerUrl ?? DEFAULT_RELAYER_URL;
|
|
2596
|
+
const resp = await fetch(`${base2}/v1/chains`);
|
|
2597
|
+
if (!resp.ok) throw new Error(`Failed to fetch chain config from relayer [${resp.status}]`);
|
|
2598
|
+
const data = await resp.json();
|
|
2599
|
+
const chain = data.chains?.find((c) => c.chainId === chainId);
|
|
2600
|
+
if (!chain?.factoryAddress) {
|
|
2601
|
+
throw new Error(`No factory address available for chainId ${chainId}. Check the relayer's chain configuration.`);
|
|
2602
|
+
}
|
|
2603
|
+
return chain.factoryAddress;
|
|
2604
|
+
}
|
|
2580
2605
|
async function getBotConfig(publicClient, vaultAddress, botAddress) {
|
|
2581
2606
|
const result = await publicClient.readContract({
|
|
2582
2607
|
address: vaultAddress,
|
|
@@ -2725,10 +2750,13 @@ async function isRebalanceTokenWhitelisted(publicClient, vaultAddress, token) {
|
|
|
2725
2750
|
args: [token]
|
|
2726
2751
|
});
|
|
2727
2752
|
}
|
|
2728
|
-
async function deployVault(walletClient, publicClient,
|
|
2753
|
+
async function deployVault(walletClient, publicClient, relayerUrl) {
|
|
2729
2754
|
if (!walletClient.account) {
|
|
2730
2755
|
throw new Error("walletClient has no account attached");
|
|
2731
2756
|
}
|
|
2757
|
+
const chainId = walletClient.chain?.id;
|
|
2758
|
+
if (!chainId) throw new Error("walletClient has no chain configured");
|
|
2759
|
+
const factoryAddress = await getFactoryAddress(chainId, relayerUrl);
|
|
2732
2760
|
const hash = await walletClient.writeContract({
|
|
2733
2761
|
address: factoryAddress,
|
|
2734
2762
|
abi: AxonVaultFactoryAbi,
|
|
@@ -2749,6 +2777,81 @@ async function deployVault(walletClient, publicClient, factoryAddress) {
|
|
|
2749
2777
|
}
|
|
2750
2778
|
throw new Error("VaultDeployed event not found in transaction receipt");
|
|
2751
2779
|
}
|
|
2780
|
+
async function addBot(walletClient, publicClient, vaultAddress, botAddress, config) {
|
|
2781
|
+
if (!walletClient.account) {
|
|
2782
|
+
throw new Error("walletClient has no account attached");
|
|
2783
|
+
}
|
|
2784
|
+
const params = toBotConfigParams(config);
|
|
2785
|
+
const hash = await walletClient.writeContract({
|
|
2786
|
+
address: vaultAddress,
|
|
2787
|
+
abi: AxonVaultAbi,
|
|
2788
|
+
functionName: "addBot",
|
|
2789
|
+
args: [botAddress, params],
|
|
2790
|
+
account: walletClient.account,
|
|
2791
|
+
chain: walletClient.chain ?? null
|
|
2792
|
+
});
|
|
2793
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
2794
|
+
return hash;
|
|
2795
|
+
}
|
|
2796
|
+
async function updateBotConfig(walletClient, publicClient, vaultAddress, botAddress, config) {
|
|
2797
|
+
if (!walletClient.account) {
|
|
2798
|
+
throw new Error("walletClient has no account attached");
|
|
2799
|
+
}
|
|
2800
|
+
const params = toBotConfigParams(config);
|
|
2801
|
+
const hash = await walletClient.writeContract({
|
|
2802
|
+
address: vaultAddress,
|
|
2803
|
+
abi: AxonVaultAbi,
|
|
2804
|
+
functionName: "updateBotConfig",
|
|
2805
|
+
args: [botAddress, params],
|
|
2806
|
+
account: walletClient.account,
|
|
2807
|
+
chain: walletClient.chain ?? null
|
|
2808
|
+
});
|
|
2809
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
2810
|
+
return hash;
|
|
2811
|
+
}
|
|
2812
|
+
async function removeBot(walletClient, publicClient, vaultAddress, botAddress) {
|
|
2813
|
+
if (!walletClient.account) {
|
|
2814
|
+
throw new Error("walletClient has no account attached");
|
|
2815
|
+
}
|
|
2816
|
+
const hash = await walletClient.writeContract({
|
|
2817
|
+
address: vaultAddress,
|
|
2818
|
+
abi: AxonVaultAbi,
|
|
2819
|
+
functionName: "removeBot",
|
|
2820
|
+
args: [botAddress],
|
|
2821
|
+
account: walletClient.account,
|
|
2822
|
+
chain: walletClient.chain ?? null
|
|
2823
|
+
});
|
|
2824
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
2825
|
+
return hash;
|
|
2826
|
+
}
|
|
2827
|
+
async function deposit(walletClient, publicClient, vaultAddress, token, amount, ref = "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
2828
|
+
if (!walletClient.account) {
|
|
2829
|
+
throw new Error("walletClient has no account attached");
|
|
2830
|
+
}
|
|
2831
|
+
const isEth = token.toLowerCase() === NATIVE_ETH.toLowerCase();
|
|
2832
|
+
if (!isEth) {
|
|
2833
|
+
const approveTx = await walletClient.writeContract({
|
|
2834
|
+
address: token,
|
|
2835
|
+
abi: erc20Abi,
|
|
2836
|
+
functionName: "approve",
|
|
2837
|
+
args: [vaultAddress, amount],
|
|
2838
|
+
account: walletClient.account,
|
|
2839
|
+
chain: walletClient.chain ?? null
|
|
2840
|
+
});
|
|
2841
|
+
await publicClient.waitForTransactionReceipt({ hash: approveTx });
|
|
2842
|
+
}
|
|
2843
|
+
const hash = await walletClient.writeContract({
|
|
2844
|
+
address: vaultAddress,
|
|
2845
|
+
abi: AxonVaultAbi,
|
|
2846
|
+
functionName: "deposit",
|
|
2847
|
+
args: [token, amount, ref],
|
|
2848
|
+
account: walletClient.account,
|
|
2849
|
+
chain: walletClient.chain ?? null,
|
|
2850
|
+
...isEth ? { value: amount } : {}
|
|
2851
|
+
});
|
|
2852
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
2853
|
+
return hash;
|
|
2854
|
+
}
|
|
2752
2855
|
|
|
2753
2856
|
// src/tokens.ts
|
|
2754
2857
|
var Token = /* @__PURE__ */ ((Token2) => {
|
|
@@ -4373,6 +4476,6 @@ var AxonRegistryAbi = [
|
|
|
4373
4476
|
}
|
|
4374
4477
|
];
|
|
4375
4478
|
|
|
4376
|
-
export { AxonClient, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, CHAIN_NAMES, Chain, DEFAULT_APPROVED_TOKENS, DEFAULT_DEADLINE_SECONDS, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, KNOWN_TOKENS, NATIVE_ETH, PAYMENT_INTENT_TYPEHASH, PERMIT2_ADDRESS, PaymentErrorCode, RELAYER_API, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, Token, USDC, USDC_EIP712_DOMAIN, WINDOW, WITNESS_TYPE_STRING, X402_PROXY_ADDRESS, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, encodeRef, encryptKeystore, extractX402Metadata, findMatchingOption, formatPaymentSignature, getBotConfig, getChain, getDefaultApprovedTokens, 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 };
|
|
4479
|
+
export { AxonClient, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, CHAIN_NAMES, Chain, DEFAULT_APPROVED_TOKENS, DEFAULT_DEADLINE_SECONDS, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, KNOWN_TOKENS, NATIVE_ETH, PAYMENT_INTENT_TYPEHASH, PERMIT2_ADDRESS, PaymentErrorCode, RELAYER_API, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, Token, USDC, USDC_EIP712_DOMAIN, WINDOW, WITNESS_TYPE_STRING, X402_PROXY_ADDRESS, addBot, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, deposit, encodeRef, encryptKeystore, extractX402Metadata, findMatchingOption, formatPaymentSignature, getBotConfig, getChain, getDefaultApprovedTokens, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, parseChainId, parsePaymentRequired, randomNonce, randomPermit2Nonce, removeBot, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signPermit2WitnessTransfer, signSwapIntent, signTransferWithAuthorization, toBotConfigParams, updateBotConfig };
|
|
4377
4480
|
//# sourceMappingURL=index.js.map
|
|
4378
4481
|
//# sourceMappingURL=index.js.map
|