@axonfi/sdk 0.5.0 → 0.5.2

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.cjs CHANGED
@@ -2546,282 +2546,6 @@ var AxonVaultFactoryAbi = [
2546
2546
  "inputs": []
2547
2547
  }
2548
2548
  ];
2549
- function getChain(chainId) {
2550
- switch (chainId) {
2551
- case 8453:
2552
- return chains.base;
2553
- case 84532:
2554
- return chains.baseSepolia;
2555
- case 42161:
2556
- return chains.arbitrum;
2557
- case 421614:
2558
- return chains.arbitrumSepolia;
2559
- default:
2560
- throw new Error(
2561
- `Unsupported chainId: ${chainId}. Supported: 8453 (Base), 84532 (Base Sepolia), 42161 (Arbitrum), 421614 (Arbitrum Sepolia)`
2562
- );
2563
- }
2564
- }
2565
- function createAxonPublicClient(chainId, rpcUrl) {
2566
- return viem.createPublicClient({
2567
- chain: getChain(chainId),
2568
- transport: viem.http(rpcUrl)
2569
- });
2570
- }
2571
- function createAxonWalletClient(privateKey, chainId) {
2572
- const account = accounts.privateKeyToAccount(privateKey);
2573
- return viem.createWalletClient({
2574
- account,
2575
- chain: getChain(chainId),
2576
- transport: viem.http()
2577
- // signing is local — transport is unused but required by viem
2578
- });
2579
- }
2580
- async function getBotConfig(publicClient, vaultAddress, botAddress) {
2581
- const result = await publicClient.readContract({
2582
- address: vaultAddress,
2583
- abi: AxonVaultAbi,
2584
- functionName: "getBotConfig",
2585
- args: [botAddress]
2586
- });
2587
- return {
2588
- isActive: result.isActive,
2589
- registeredAt: result.registeredAt,
2590
- maxPerTxAmount: result.maxPerTxAmount,
2591
- maxRebalanceAmount: result.maxRebalanceAmount,
2592
- spendingLimits: result.spendingLimits.map((sl) => ({
2593
- amount: sl.amount,
2594
- maxCount: sl.maxCount,
2595
- windowSeconds: sl.windowSeconds
2596
- })),
2597
- aiTriggerThreshold: result.aiTriggerThreshold,
2598
- requireAiVerification: result.requireAiVerification
2599
- };
2600
- }
2601
- async function isBotActive(publicClient, vaultAddress, botAddress) {
2602
- return publicClient.readContract({
2603
- address: vaultAddress,
2604
- abi: AxonVaultAbi,
2605
- functionName: "isBotActive",
2606
- args: [botAddress]
2607
- });
2608
- }
2609
- async function getOperatorCeilings(publicClient, vaultAddress) {
2610
- const result = await publicClient.readContract({
2611
- address: vaultAddress,
2612
- abi: AxonVaultAbi,
2613
- functionName: "operatorCeilings"
2614
- });
2615
- const [maxPerTxAmount, maxBotDailyLimit, maxOperatorBots, vaultDailyAggregate, minAiTriggerFloor] = result;
2616
- return {
2617
- maxPerTxAmount,
2618
- maxBotDailyLimit,
2619
- maxOperatorBots,
2620
- vaultDailyAggregate,
2621
- minAiTriggerFloor
2622
- };
2623
- }
2624
- async function operatorMaxDrainPerDay(publicClient, vaultAddress) {
2625
- return publicClient.readContract({
2626
- address: vaultAddress,
2627
- abi: AxonVaultAbi,
2628
- functionName: "operatorMaxDrainPerDay"
2629
- });
2630
- }
2631
- async function isVaultPaused(publicClient, vaultAddress) {
2632
- return publicClient.readContract({
2633
- address: vaultAddress,
2634
- abi: AxonVaultAbi,
2635
- functionName: "paused"
2636
- });
2637
- }
2638
- async function getDomainSeparator(publicClient, vaultAddress) {
2639
- return publicClient.readContract({
2640
- address: vaultAddress,
2641
- abi: AxonVaultAbi,
2642
- functionName: "DOMAIN_SEPARATOR"
2643
- });
2644
- }
2645
- async function getVaultVersion(publicClient, vaultAddress) {
2646
- const version = await publicClient.readContract({
2647
- address: vaultAddress,
2648
- abi: AxonVaultAbi,
2649
- functionName: "VERSION"
2650
- });
2651
- return Number(version);
2652
- }
2653
- async function getVaultOwner(publicClient, vaultAddress) {
2654
- return publicClient.readContract({
2655
- address: vaultAddress,
2656
- abi: AxonVaultAbi,
2657
- functionName: "owner"
2658
- });
2659
- }
2660
- async function getVaultOperator(publicClient, vaultAddress) {
2661
- return publicClient.readContract({
2662
- address: vaultAddress,
2663
- abi: AxonVaultAbi,
2664
- functionName: "operator"
2665
- });
2666
- }
2667
- async function isDestinationAllowed(publicClient, vaultAddress, botAddress, destination) {
2668
- const isBlacklisted = await publicClient.readContract({
2669
- address: vaultAddress,
2670
- abi: AxonVaultAbi,
2671
- functionName: "globalDestinationBlacklist",
2672
- args: [destination]
2673
- });
2674
- if (isBlacklisted) {
2675
- return { allowed: false, reason: "Destination is on the global blacklist" };
2676
- }
2677
- const globalCount = await publicClient.readContract({
2678
- address: vaultAddress,
2679
- abi: AxonVaultAbi,
2680
- functionName: "globalDestinationCount"
2681
- });
2682
- if (globalCount > 0n) {
2683
- const isGlobalWhitelisted = await publicClient.readContract({
2684
- address: vaultAddress,
2685
- abi: AxonVaultAbi,
2686
- functionName: "globalDestinationWhitelist",
2687
- args: [destination]
2688
- });
2689
- if (!isGlobalWhitelisted) {
2690
- return { allowed: false, reason: "Destination is not on the global whitelist" };
2691
- }
2692
- }
2693
- const botCount = await publicClient.readContract({
2694
- address: vaultAddress,
2695
- abi: AxonVaultAbi,
2696
- functionName: "botDestinationCount",
2697
- args: [botAddress]
2698
- });
2699
- if (botCount > 0n) {
2700
- const isBotWhitelisted = await publicClient.readContract({
2701
- address: vaultAddress,
2702
- abi: AxonVaultAbi,
2703
- functionName: "botDestinationWhitelist",
2704
- args: [botAddress, destination]
2705
- });
2706
- if (!isBotWhitelisted) {
2707
- return { allowed: false, reason: "Destination is not on the bot whitelist" };
2708
- }
2709
- }
2710
- return { allowed: true };
2711
- }
2712
- async function getRebalanceTokenCount(publicClient, vaultAddress) {
2713
- const count = await publicClient.readContract({
2714
- address: vaultAddress,
2715
- abi: AxonVaultAbi,
2716
- functionName: "rebalanceTokenCount"
2717
- });
2718
- return Number(count);
2719
- }
2720
- async function isRebalanceTokenWhitelisted(publicClient, vaultAddress, token) {
2721
- return publicClient.readContract({
2722
- address: vaultAddress,
2723
- abi: AxonVaultAbi,
2724
- functionName: "rebalanceTokenWhitelist",
2725
- args: [token]
2726
- });
2727
- }
2728
- async function deployVault(walletClient, publicClient, factoryAddress) {
2729
- if (!walletClient.account) {
2730
- throw new Error("walletClient has no account attached");
2731
- }
2732
- const hash = await walletClient.writeContract({
2733
- address: factoryAddress,
2734
- abi: AxonVaultFactoryAbi,
2735
- functionName: "deployVault",
2736
- args: [],
2737
- account: walletClient.account,
2738
- chain: walletClient.chain ?? null
2739
- });
2740
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
2741
- for (const log of receipt.logs) {
2742
- try {
2743
- if (log.topics.length >= 3 && log.topics[2]) {
2744
- const vaultAddress = `0x${log.topics[2].slice(26)}`;
2745
- return vaultAddress;
2746
- }
2747
- } catch {
2748
- }
2749
- }
2750
- throw new Error("VaultDeployed event not found in transaction receipt");
2751
- }
2752
- async function addBot(walletClient, publicClient, vaultAddress, botAddress, config) {
2753
- if (!walletClient.account) {
2754
- throw new Error("walletClient has no account attached");
2755
- }
2756
- const hash = await walletClient.writeContract({
2757
- address: vaultAddress,
2758
- abi: AxonVaultAbi,
2759
- functionName: "addBot",
2760
- args: [botAddress, config],
2761
- account: walletClient.account,
2762
- chain: walletClient.chain ?? null
2763
- });
2764
- await publicClient.waitForTransactionReceipt({ hash });
2765
- return hash;
2766
- }
2767
- async function updateBotConfig(walletClient, publicClient, vaultAddress, botAddress, config) {
2768
- if (!walletClient.account) {
2769
- throw new Error("walletClient has no account attached");
2770
- }
2771
- const hash = await walletClient.writeContract({
2772
- address: vaultAddress,
2773
- abi: AxonVaultAbi,
2774
- functionName: "updateBotConfig",
2775
- args: [botAddress, config],
2776
- account: walletClient.account,
2777
- chain: walletClient.chain ?? null
2778
- });
2779
- await publicClient.waitForTransactionReceipt({ hash });
2780
- return hash;
2781
- }
2782
- async function removeBot(walletClient, publicClient, vaultAddress, botAddress) {
2783
- if (!walletClient.account) {
2784
- throw new Error("walletClient has no account attached");
2785
- }
2786
- const hash = await walletClient.writeContract({
2787
- address: vaultAddress,
2788
- abi: AxonVaultAbi,
2789
- functionName: "removeBot",
2790
- args: [botAddress],
2791
- account: walletClient.account,
2792
- chain: walletClient.chain ?? null
2793
- });
2794
- await publicClient.waitForTransactionReceipt({ hash });
2795
- return hash;
2796
- }
2797
- async function deposit(walletClient, publicClient, vaultAddress, token, amount, ref = "0x0000000000000000000000000000000000000000000000000000000000000000") {
2798
- if (!walletClient.account) {
2799
- throw new Error("walletClient has no account attached");
2800
- }
2801
- const isEth = token.toLowerCase() === NATIVE_ETH.toLowerCase();
2802
- if (!isEth) {
2803
- const approveTx = await walletClient.writeContract({
2804
- address: token,
2805
- abi: viem.erc20Abi,
2806
- functionName: "approve",
2807
- args: [vaultAddress, amount],
2808
- account: walletClient.account,
2809
- chain: walletClient.chain ?? null
2810
- });
2811
- await publicClient.waitForTransactionReceipt({ hash: approveTx });
2812
- }
2813
- const hash = await walletClient.writeContract({
2814
- address: vaultAddress,
2815
- abi: AxonVaultAbi,
2816
- functionName: "deposit",
2817
- args: [token, amount, ref],
2818
- account: walletClient.account,
2819
- chain: walletClient.chain ?? null,
2820
- ...isEth ? { value: amount } : {}
2821
- });
2822
- await publicClient.waitForTransactionReceipt({ hash });
2823
- return hash;
2824
- }
2825
2549
 
2826
2550
  // src/tokens.ts
2827
2551
  var Token = /* @__PURE__ */ ((Token2) => {
@@ -3016,72 +2740,393 @@ var KNOWN_TOKENS = {
3016
2740
  addresses: {
3017
2741
  8453: "0x940181a94A35A4569E4529A3CDfB74e38FD98631"
3018
2742
  }
3019
- },
3020
- GMX: {
3021
- symbol: "GMX",
3022
- name: "GMX",
3023
- decimals: 18,
3024
- addresses: {
3025
- 42161: "0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a"
2743
+ },
2744
+ GMX: {
2745
+ symbol: "GMX",
2746
+ name: "GMX",
2747
+ decimals: 18,
2748
+ addresses: {
2749
+ 42161: "0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a"
2750
+ }
2751
+ }
2752
+ };
2753
+ var DEFAULT_APPROVED_TOKENS = [
2754
+ "USDC",
2755
+ "USDT",
2756
+ "DAI",
2757
+ "WETH",
2758
+ "WBTC",
2759
+ "cbBTC",
2760
+ "wstETH",
2761
+ "weETH",
2762
+ "cbETH",
2763
+ "rETH"
2764
+ ];
2765
+ function getDefaultApprovedTokens(chainId) {
2766
+ const addresses = [];
2767
+ for (const symbol of DEFAULT_APPROVED_TOKENS) {
2768
+ const entry = KNOWN_TOKENS[symbol];
2769
+ const addr = entry.addresses[chainId];
2770
+ if (addr) addresses.push(addr);
2771
+ }
2772
+ return addresses;
2773
+ }
2774
+ var addressToSymbol = /* @__PURE__ */ new Map();
2775
+ for (const token of Object.values(KNOWN_TOKENS)) {
2776
+ for (const addr of Object.values(token.addresses)) {
2777
+ addressToSymbol.set(addr.toLowerCase(), token.symbol);
2778
+ }
2779
+ }
2780
+ function getKnownTokensForChain(chainId) {
2781
+ const result = [];
2782
+ for (const token of Object.values(KNOWN_TOKENS)) {
2783
+ const addr = token.addresses[chainId];
2784
+ if (addr) {
2785
+ result.push({ ...token, address: addr });
2786
+ }
2787
+ }
2788
+ return result;
2789
+ }
2790
+ function getTokenSymbolByAddress(address) {
2791
+ return addressToSymbol.get(address.toLowerCase()) ?? null;
2792
+ }
2793
+ function resolveToken(token, chainId) {
2794
+ if (typeof token === "string" && token.startsWith("0x")) {
2795
+ if (token === "0x0000000000000000000000000000000000000000") {
2796
+ throw new Error("Token address cannot be the zero address");
2797
+ }
2798
+ return token;
2799
+ }
2800
+ const entry = KNOWN_TOKENS[token];
2801
+ if (!entry) {
2802
+ throw new Error(`Unknown token symbol: ${token}`);
2803
+ }
2804
+ const addr = entry.addresses[chainId];
2805
+ if (!addr) {
2806
+ throw new Error(`Token ${token} is not available on chain ${chainId}`);
2807
+ }
2808
+ return addr;
2809
+ }
2810
+
2811
+ // src/vault.ts
2812
+ function getChain(chainId) {
2813
+ switch (chainId) {
2814
+ case 8453:
2815
+ return chains.base;
2816
+ case 84532:
2817
+ return chains.baseSepolia;
2818
+ case 42161:
2819
+ return chains.arbitrum;
2820
+ case 421614:
2821
+ return chains.arbitrumSepolia;
2822
+ default:
2823
+ throw new Error(
2824
+ `Unsupported chainId: ${chainId}. Supported: 8453 (Base), 84532 (Base Sepolia), 42161 (Arbitrum), 421614 (Arbitrum Sepolia)`
2825
+ );
2826
+ }
2827
+ }
2828
+ function createAxonPublicClient(chainId, rpcUrl) {
2829
+ return viem.createPublicClient({
2830
+ chain: getChain(chainId),
2831
+ transport: viem.http(rpcUrl)
2832
+ });
2833
+ }
2834
+ function createAxonWalletClient(privateKey, chainId) {
2835
+ const account = accounts.privateKeyToAccount(privateKey);
2836
+ return viem.createWalletClient({
2837
+ account,
2838
+ chain: getChain(chainId),
2839
+ transport: viem.http()
2840
+ // signing is local — transport is unused but required by viem
2841
+ });
2842
+ }
2843
+ var USDC_DECIMALS = 6n;
2844
+ var USDC_UNIT = 10n ** USDC_DECIMALS;
2845
+ function toBotConfigParams(input) {
2846
+ return {
2847
+ maxPerTxAmount: BigInt(Math.round(input.maxPerTxAmount * Number(USDC_UNIT))),
2848
+ maxRebalanceAmount: BigInt(Math.round(input.maxRebalanceAmount * Number(USDC_UNIT))),
2849
+ spendingLimits: input.spendingLimits.map((sl) => ({
2850
+ amount: BigInt(Math.round(sl.amount * Number(USDC_UNIT))),
2851
+ maxCount: BigInt(sl.maxCount),
2852
+ windowSeconds: BigInt(sl.windowSeconds)
2853
+ })),
2854
+ aiTriggerThreshold: BigInt(Math.round(input.aiTriggerThreshold * Number(USDC_UNIT))),
2855
+ requireAiVerification: input.requireAiVerification
2856
+ };
2857
+ }
2858
+ var DEFAULT_RELAYER_URL = "https://relay.axonfi.xyz";
2859
+ async function getFactoryAddress(chainId, relayerUrl) {
2860
+ const base2 = relayerUrl ?? DEFAULT_RELAYER_URL;
2861
+ const resp = await fetch(`${base2}/v1/chains`);
2862
+ if (!resp.ok) throw new Error(`Failed to fetch chain config from relayer [${resp.status}]`);
2863
+ const data = await resp.json();
2864
+ const chain = data.chains?.find((c) => c.chainId === chainId);
2865
+ if (!chain?.factoryAddress) {
2866
+ throw new Error(`No factory address available for chainId ${chainId}. Check the relayer's chain configuration.`);
2867
+ }
2868
+ return chain.factoryAddress;
2869
+ }
2870
+ async function getBotConfig(publicClient, vaultAddress, botAddress) {
2871
+ const result = await publicClient.readContract({
2872
+ address: vaultAddress,
2873
+ abi: AxonVaultAbi,
2874
+ functionName: "getBotConfig",
2875
+ args: [botAddress]
2876
+ });
2877
+ return {
2878
+ isActive: result.isActive,
2879
+ registeredAt: result.registeredAt,
2880
+ maxPerTxAmount: result.maxPerTxAmount,
2881
+ maxRebalanceAmount: result.maxRebalanceAmount,
2882
+ spendingLimits: result.spendingLimits.map((sl) => ({
2883
+ amount: sl.amount,
2884
+ maxCount: sl.maxCount,
2885
+ windowSeconds: sl.windowSeconds
2886
+ })),
2887
+ aiTriggerThreshold: result.aiTriggerThreshold,
2888
+ requireAiVerification: result.requireAiVerification
2889
+ };
2890
+ }
2891
+ async function isBotActive(publicClient, vaultAddress, botAddress) {
2892
+ return publicClient.readContract({
2893
+ address: vaultAddress,
2894
+ abi: AxonVaultAbi,
2895
+ functionName: "isBotActive",
2896
+ args: [botAddress]
2897
+ });
2898
+ }
2899
+ async function getOperatorCeilings(publicClient, vaultAddress) {
2900
+ const result = await publicClient.readContract({
2901
+ address: vaultAddress,
2902
+ abi: AxonVaultAbi,
2903
+ functionName: "operatorCeilings"
2904
+ });
2905
+ const [maxPerTxAmount, maxBotDailyLimit, maxOperatorBots, vaultDailyAggregate, minAiTriggerFloor] = result;
2906
+ return {
2907
+ maxPerTxAmount,
2908
+ maxBotDailyLimit,
2909
+ maxOperatorBots,
2910
+ vaultDailyAggregate,
2911
+ minAiTriggerFloor
2912
+ };
2913
+ }
2914
+ async function operatorMaxDrainPerDay(publicClient, vaultAddress) {
2915
+ return publicClient.readContract({
2916
+ address: vaultAddress,
2917
+ abi: AxonVaultAbi,
2918
+ functionName: "operatorMaxDrainPerDay"
2919
+ });
2920
+ }
2921
+ async function isVaultPaused(publicClient, vaultAddress) {
2922
+ return publicClient.readContract({
2923
+ address: vaultAddress,
2924
+ abi: AxonVaultAbi,
2925
+ functionName: "paused"
2926
+ });
2927
+ }
2928
+ async function getDomainSeparator(publicClient, vaultAddress) {
2929
+ return publicClient.readContract({
2930
+ address: vaultAddress,
2931
+ abi: AxonVaultAbi,
2932
+ functionName: "DOMAIN_SEPARATOR"
2933
+ });
2934
+ }
2935
+ async function getVaultVersion(publicClient, vaultAddress) {
2936
+ const version = await publicClient.readContract({
2937
+ address: vaultAddress,
2938
+ abi: AxonVaultAbi,
2939
+ functionName: "VERSION"
2940
+ });
2941
+ return Number(version);
2942
+ }
2943
+ async function getVaultOwner(publicClient, vaultAddress) {
2944
+ return publicClient.readContract({
2945
+ address: vaultAddress,
2946
+ abi: AxonVaultAbi,
2947
+ functionName: "owner"
2948
+ });
2949
+ }
2950
+ async function getVaultOperator(publicClient, vaultAddress) {
2951
+ return publicClient.readContract({
2952
+ address: vaultAddress,
2953
+ abi: AxonVaultAbi,
2954
+ functionName: "operator"
2955
+ });
2956
+ }
2957
+ async function isDestinationAllowed(publicClient, vaultAddress, botAddress, destination) {
2958
+ const isBlacklisted = await publicClient.readContract({
2959
+ address: vaultAddress,
2960
+ abi: AxonVaultAbi,
2961
+ functionName: "globalDestinationBlacklist",
2962
+ args: [destination]
2963
+ });
2964
+ if (isBlacklisted) {
2965
+ return { allowed: false, reason: "Destination is on the global blacklist" };
2966
+ }
2967
+ const globalCount = await publicClient.readContract({
2968
+ address: vaultAddress,
2969
+ abi: AxonVaultAbi,
2970
+ functionName: "globalDestinationCount"
2971
+ });
2972
+ if (globalCount > 0n) {
2973
+ const isGlobalWhitelisted = await publicClient.readContract({
2974
+ address: vaultAddress,
2975
+ abi: AxonVaultAbi,
2976
+ functionName: "globalDestinationWhitelist",
2977
+ args: [destination]
2978
+ });
2979
+ if (!isGlobalWhitelisted) {
2980
+ return { allowed: false, reason: "Destination is not on the global whitelist" };
2981
+ }
2982
+ }
2983
+ const botCount = await publicClient.readContract({
2984
+ address: vaultAddress,
2985
+ abi: AxonVaultAbi,
2986
+ functionName: "botDestinationCount",
2987
+ args: [botAddress]
2988
+ });
2989
+ if (botCount > 0n) {
2990
+ const isBotWhitelisted = await publicClient.readContract({
2991
+ address: vaultAddress,
2992
+ abi: AxonVaultAbi,
2993
+ functionName: "botDestinationWhitelist",
2994
+ args: [botAddress, destination]
2995
+ });
2996
+ if (!isBotWhitelisted) {
2997
+ return { allowed: false, reason: "Destination is not on the bot whitelist" };
3026
2998
  }
3027
2999
  }
3028
- };
3029
- var DEFAULT_APPROVED_TOKENS = [
3030
- "USDC",
3031
- "USDT",
3032
- "DAI",
3033
- "WETH",
3034
- "WBTC",
3035
- "cbBTC",
3036
- "wstETH",
3037
- "weETH",
3038
- "cbETH",
3039
- "rETH"
3040
- ];
3041
- function getDefaultApprovedTokens(chainId) {
3042
- const addresses = [];
3043
- for (const symbol of DEFAULT_APPROVED_TOKENS) {
3044
- const entry = KNOWN_TOKENS[symbol];
3045
- const addr = entry.addresses[chainId];
3046
- if (addr) addresses.push(addr);
3000
+ return { allowed: true };
3001
+ }
3002
+ async function getRebalanceTokenCount(publicClient, vaultAddress) {
3003
+ const count = await publicClient.readContract({
3004
+ address: vaultAddress,
3005
+ abi: AxonVaultAbi,
3006
+ functionName: "rebalanceTokenCount"
3007
+ });
3008
+ return Number(count);
3009
+ }
3010
+ async function isRebalanceTokenWhitelisted(publicClient, vaultAddress, token) {
3011
+ return publicClient.readContract({
3012
+ address: vaultAddress,
3013
+ abi: AxonVaultAbi,
3014
+ functionName: "rebalanceTokenWhitelist",
3015
+ args: [token]
3016
+ });
3017
+ }
3018
+ async function deployVault(walletClient, publicClient, relayerUrl) {
3019
+ if (!walletClient.account) {
3020
+ throw new Error("walletClient has no account attached");
3047
3021
  }
3048
- return addresses;
3022
+ const chainId = walletClient.chain?.id;
3023
+ if (!chainId) throw new Error("walletClient has no chain configured");
3024
+ const factoryAddress = await getFactoryAddress(chainId, relayerUrl);
3025
+ const hash = await walletClient.writeContract({
3026
+ address: factoryAddress,
3027
+ abi: AxonVaultFactoryAbi,
3028
+ functionName: "deployVault",
3029
+ args: [],
3030
+ account: walletClient.account,
3031
+ chain: walletClient.chain ?? null
3032
+ });
3033
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
3034
+ for (const log of receipt.logs) {
3035
+ try {
3036
+ if (log.topics.length >= 3 && log.topics[2]) {
3037
+ const vaultAddress = `0x${log.topics[2].slice(26)}`;
3038
+ return vaultAddress;
3039
+ }
3040
+ } catch {
3041
+ }
3042
+ }
3043
+ throw new Error("VaultDeployed event not found in transaction receipt");
3049
3044
  }
3050
- var addressToSymbol = /* @__PURE__ */ new Map();
3051
- for (const token of Object.values(KNOWN_TOKENS)) {
3052
- for (const addr of Object.values(token.addresses)) {
3053
- addressToSymbol.set(addr.toLowerCase(), token.symbol);
3045
+ async function addBot(walletClient, publicClient, vaultAddress, botAddress, config) {
3046
+ if (!walletClient.account) {
3047
+ throw new Error("walletClient has no account attached");
3054
3048
  }
3049
+ const params = toBotConfigParams(config);
3050
+ const hash = await walletClient.writeContract({
3051
+ address: vaultAddress,
3052
+ abi: AxonVaultAbi,
3053
+ functionName: "addBot",
3054
+ args: [botAddress, params],
3055
+ account: walletClient.account,
3056
+ chain: walletClient.chain ?? null
3057
+ });
3058
+ await publicClient.waitForTransactionReceipt({ hash });
3059
+ return hash;
3055
3060
  }
3056
- function getKnownTokensForChain(chainId) {
3057
- const result = [];
3058
- for (const token of Object.values(KNOWN_TOKENS)) {
3059
- const addr = token.addresses[chainId];
3060
- if (addr) {
3061
- result.push({ ...token, address: addr });
3062
- }
3061
+ async function updateBotConfig(walletClient, publicClient, vaultAddress, botAddress, config) {
3062
+ if (!walletClient.account) {
3063
+ throw new Error("walletClient has no account attached");
3063
3064
  }
3064
- return result;
3065
+ const params = toBotConfigParams(config);
3066
+ const hash = await walletClient.writeContract({
3067
+ address: vaultAddress,
3068
+ abi: AxonVaultAbi,
3069
+ functionName: "updateBotConfig",
3070
+ args: [botAddress, params],
3071
+ account: walletClient.account,
3072
+ chain: walletClient.chain ?? null
3073
+ });
3074
+ await publicClient.waitForTransactionReceipt({ hash });
3075
+ return hash;
3065
3076
  }
3066
- function getTokenSymbolByAddress(address) {
3067
- return addressToSymbol.get(address.toLowerCase()) ?? null;
3077
+ async function removeBot(walletClient, publicClient, vaultAddress, botAddress) {
3078
+ if (!walletClient.account) {
3079
+ throw new Error("walletClient has no account attached");
3080
+ }
3081
+ const hash = await walletClient.writeContract({
3082
+ address: vaultAddress,
3083
+ abi: AxonVaultAbi,
3084
+ functionName: "removeBot",
3085
+ args: [botAddress],
3086
+ account: walletClient.account,
3087
+ chain: walletClient.chain ?? null
3088
+ });
3089
+ await publicClient.waitForTransactionReceipt({ hash });
3090
+ return hash;
3068
3091
  }
3069
- function resolveToken(token, chainId) {
3070
- if (typeof token === "string" && token.startsWith("0x")) {
3071
- if (token === "0x0000000000000000000000000000000000000000") {
3072
- throw new Error("Token address cannot be the zero address");
3073
- }
3074
- return token;
3092
+ async function deposit(walletClient, publicClient, vaultAddress, token, amount, ref = "0x0000000000000000000000000000000000000000000000000000000000000000") {
3093
+ if (!walletClient.account) {
3094
+ throw new Error("walletClient has no account attached");
3075
3095
  }
3076
- const entry = KNOWN_TOKENS[token];
3077
- if (!entry) {
3078
- throw new Error(`Unknown token symbol: ${token}`);
3096
+ const isEthSymbol = token === "ETH" || token === "eth";
3097
+ let tokenAddress;
3098
+ if (isEthSymbol) {
3099
+ tokenAddress = NATIVE_ETH;
3100
+ } else if (token.startsWith("0x")) {
3101
+ tokenAddress = token;
3102
+ } else {
3103
+ const chainId = walletClient.chain?.id;
3104
+ if (!chainId) throw new Error("walletClient has no chain \u2014 cannot resolve token symbol");
3105
+ tokenAddress = resolveToken(token, chainId);
3079
3106
  }
3080
- const addr = entry.addresses[chainId];
3081
- if (!addr) {
3082
- throw new Error(`Token ${token} is not available on chain ${chainId}`);
3107
+ const isEth = tokenAddress.toLowerCase() === NATIVE_ETH.toLowerCase();
3108
+ if (!isEth) {
3109
+ const approveTx = await walletClient.writeContract({
3110
+ address: tokenAddress,
3111
+ abi: viem.erc20Abi,
3112
+ functionName: "approve",
3113
+ args: [vaultAddress, amount],
3114
+ account: walletClient.account,
3115
+ chain: walletClient.chain ?? null
3116
+ });
3117
+ await publicClient.waitForTransactionReceipt({ hash: approveTx });
3083
3118
  }
3084
- return addr;
3119
+ const hash = await walletClient.writeContract({
3120
+ address: vaultAddress,
3121
+ abi: AxonVaultAbi,
3122
+ functionName: "deposit",
3123
+ args: [tokenAddress, amount, ref],
3124
+ account: walletClient.account,
3125
+ chain: walletClient.chain ?? null,
3126
+ ...isEth ? { value: amount } : {}
3127
+ });
3128
+ await publicClient.waitForTransactionReceipt({ hash });
3129
+ return hash;
3085
3130
  }
3086
3131
  function resolveTokenDecimals(token, chainId) {
3087
3132
  if (typeof token === "string" && token.startsWith("0x")) {
@@ -4513,6 +4558,7 @@ exports.signPayment = signPayment;
4513
4558
  exports.signPermit2WitnessTransfer = signPermit2WitnessTransfer;
4514
4559
  exports.signSwapIntent = signSwapIntent;
4515
4560
  exports.signTransferWithAuthorization = signTransferWithAuthorization;
4561
+ exports.toBotConfigParams = toBotConfigParams;
4516
4562
  exports.updateBotConfig = updateBotConfig;
4517
4563
  //# sourceMappingURL=index.cjs.map
4518
4564
  //# sourceMappingURL=index.cjs.map