@axonfi/sdk 0.5.2 → 0.5.4
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 +3 -6
- package/dist/index.cjs +52 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -20
- package/dist/index.d.ts +2 -20
- package/dist/index.js +53 -75
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,7 +57,6 @@ import {
|
|
|
57
57
|
createAxonPublicClient, createAxonWalletClient,
|
|
58
58
|
WINDOW, Chain,
|
|
59
59
|
} from '@axonfi/sdk';
|
|
60
|
-
import { parseUnits } from 'viem';
|
|
61
60
|
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
62
61
|
|
|
63
62
|
// ── 1. Owner wallet (funded with ETH for gas) ─────────────────────
|
|
@@ -93,12 +92,10 @@ await addBot(ownerWallet, publicClient, vaultAddress, botAddress, {
|
|
|
93
92
|
|
|
94
93
|
// ── 6. Deposit funds (on-chain tx, ~0.0005 ETH gas) ───────────────
|
|
95
94
|
// Option A: Deposit ETH (vault accepts native ETH directly)
|
|
96
|
-
await deposit(ownerWallet, publicClient, vaultAddress,
|
|
97
|
-
'ETH', parseUnits('0.1', 18));
|
|
95
|
+
await deposit(ownerWallet, publicClient, vaultAddress, 'ETH', 0.1);
|
|
98
96
|
|
|
99
97
|
// Option B: Deposit USDC (SDK handles approve + deposit)
|
|
100
|
-
await deposit(ownerWallet, publicClient, vaultAddress,
|
|
101
|
-
'USDC', parseUnits('500', 6));
|
|
98
|
+
await deposit(ownerWallet, publicClient, vaultAddress, 'USDC', 500);
|
|
102
99
|
|
|
103
100
|
// ── 7. Bot is ready — gasless from here ────────────────────────────
|
|
104
101
|
// Save botKey securely. The bot never needs ETH.
|
|
@@ -130,7 +127,7 @@ Vaults accept native ETH directly — no wrapping needed. You can start a vault
|
|
|
130
127
|
// Deploy vault + deposit ETH — no USDC needed
|
|
131
128
|
const vault = await deployVault(ownerWallet, publicClient, factory);
|
|
132
129
|
await addBot(ownerWallet, publicClient, vault, botAddress, config);
|
|
133
|
-
await deposit(ownerWallet, publicClient, vault, 'ETH',
|
|
130
|
+
await deposit(ownerWallet, publicClient, vault, 'ETH', 0.5);
|
|
134
131
|
|
|
135
132
|
// Bot can now pay in any token — the relayer swaps ETH → USDC automatically
|
|
136
133
|
await axon.pay({ to: '0x...', token: 'USDC', amount: 10 });
|
package/dist/index.cjs
CHANGED
|
@@ -49,32 +49,19 @@ var CHAIN_NAMES = {
|
|
|
49
49
|
[8453 /* Base */]: "Base",
|
|
50
50
|
[84532 /* BaseSepolia */]: "Base Sepolia",
|
|
51
51
|
[42161 /* Arbitrum */]: "Arbitrum One",
|
|
52
|
-
[421614 /* ArbitrumSepolia */]: "Arbitrum Sepolia"
|
|
53
|
-
// Future v1 chains (metadata only — not in SUPPORTED_CHAIN_IDS yet)
|
|
54
|
-
10: "Optimism",
|
|
55
|
-
11155420: "OP Sepolia",
|
|
56
|
-
137: "Polygon",
|
|
57
|
-
80002: "Polygon Amoy"
|
|
52
|
+
[421614 /* ArbitrumSepolia */]: "Arbitrum Sepolia"
|
|
58
53
|
};
|
|
59
54
|
var EXPLORER_TX = {
|
|
60
55
|
[8453 /* Base */]: "https://basescan.org/tx/",
|
|
61
56
|
[84532 /* BaseSepolia */]: "https://sepolia.basescan.org/tx/",
|
|
62
57
|
[42161 /* Arbitrum */]: "https://arbiscan.io/tx/",
|
|
63
|
-
[421614 /* ArbitrumSepolia */]: "https://sepolia.arbiscan.io/tx/"
|
|
64
|
-
10: "https://optimistic.etherscan.io/tx/",
|
|
65
|
-
11155420: "https://sepolia-optimism.etherscan.io/tx/",
|
|
66
|
-
137: "https://polygonscan.com/tx/",
|
|
67
|
-
80002: "https://amoy.polygonscan.com/tx/"
|
|
58
|
+
[421614 /* ArbitrumSepolia */]: "https://sepolia.arbiscan.io/tx/"
|
|
68
59
|
};
|
|
69
60
|
var EXPLORER_ADDR = {
|
|
70
61
|
[8453 /* Base */]: "https://basescan.org/address/",
|
|
71
62
|
[84532 /* BaseSepolia */]: "https://sepolia.basescan.org/address/",
|
|
72
63
|
[42161 /* Arbitrum */]: "https://arbiscan.io/address/",
|
|
73
|
-
[421614 /* ArbitrumSepolia */]: "https://sepolia.arbiscan.io/address/"
|
|
74
|
-
10: "https://optimistic.etherscan.io/address/",
|
|
75
|
-
11155420: "https://sepolia-optimism.etherscan.io/address/",
|
|
76
|
-
137: "https://polygonscan.com/address/",
|
|
77
|
-
80002: "https://amoy.polygonscan.com/address/"
|
|
64
|
+
[421614 /* ArbitrumSepolia */]: "https://sepolia.arbiscan.io/address/"
|
|
78
65
|
};
|
|
79
66
|
var DEFAULT_DEADLINE_SECONDS = 300;
|
|
80
67
|
var WINDOW = {
|
|
@@ -2565,8 +2552,6 @@ var Token = /* @__PURE__ */ ((Token2) => {
|
|
|
2565
2552
|
Token2["COMP"] = "COMP";
|
|
2566
2553
|
Token2["CRV"] = "CRV";
|
|
2567
2554
|
Token2["SNX"] = "SNX";
|
|
2568
|
-
Token2["ARB"] = "ARB";
|
|
2569
|
-
Token2["AERO"] = "AERO";
|
|
2570
2555
|
Token2["GMX"] = "GMX";
|
|
2571
2556
|
return Token2;
|
|
2572
2557
|
})(Token || {});
|
|
@@ -2724,23 +2709,6 @@ var KNOWN_TOKENS = {
|
|
|
2724
2709
|
8453: "0x22e6966B799c4D5B13BE962E1D117b56327FDa66"
|
|
2725
2710
|
}
|
|
2726
2711
|
},
|
|
2727
|
-
// ── Chain-native governance ─────────────────────────────
|
|
2728
|
-
ARB: {
|
|
2729
|
-
symbol: "ARB",
|
|
2730
|
-
name: "Arbitrum",
|
|
2731
|
-
decimals: 18,
|
|
2732
|
-
addresses: {
|
|
2733
|
-
42161: "0x912CE59144191C1204E64559FE8253a0e49E6548"
|
|
2734
|
-
}
|
|
2735
|
-
},
|
|
2736
|
-
AERO: {
|
|
2737
|
-
symbol: "AERO",
|
|
2738
|
-
name: "Aerodrome",
|
|
2739
|
-
decimals: 18,
|
|
2740
|
-
addresses: {
|
|
2741
|
-
8453: "0x940181a94A35A4569E4529A3CDfB74e38FD98631"
|
|
2742
|
-
}
|
|
2743
|
-
},
|
|
2744
2712
|
GMX: {
|
|
2745
2713
|
symbol: "GMX",
|
|
2746
2714
|
name: "GMX",
|
|
@@ -2808,6 +2776,44 @@ function resolveToken(token, chainId) {
|
|
|
2808
2776
|
return addr;
|
|
2809
2777
|
}
|
|
2810
2778
|
|
|
2779
|
+
// src/amounts.ts
|
|
2780
|
+
function resolveTokenDecimals(token, chainId) {
|
|
2781
|
+
if (typeof token === "string" && token.startsWith("0x")) {
|
|
2782
|
+
const symbol = getTokenSymbolByAddress(token);
|
|
2783
|
+
if (!symbol) {
|
|
2784
|
+
throw new Error(
|
|
2785
|
+
`Unknown token address ${token} \u2014 cannot determine decimals. Use a bigint amount instead, or pass a known token symbol.`
|
|
2786
|
+
);
|
|
2787
|
+
}
|
|
2788
|
+
const entry2 = KNOWN_TOKENS[symbol];
|
|
2789
|
+
return entry2.decimals;
|
|
2790
|
+
}
|
|
2791
|
+
const entry = KNOWN_TOKENS[token];
|
|
2792
|
+
if (!entry) {
|
|
2793
|
+
throw new Error(
|
|
2794
|
+
`Unknown token symbol "${token}" \u2014 cannot determine decimals. Use a bigint amount instead, or use a known symbol (${Object.keys(KNOWN_TOKENS).join(", ")}).`
|
|
2795
|
+
);
|
|
2796
|
+
}
|
|
2797
|
+
return entry.decimals;
|
|
2798
|
+
}
|
|
2799
|
+
function parseAmount(amount, token, chainId) {
|
|
2800
|
+
if (typeof amount === "bigint") {
|
|
2801
|
+
return amount;
|
|
2802
|
+
}
|
|
2803
|
+
const decimals = resolveTokenDecimals(token);
|
|
2804
|
+
const str = typeof amount === "number" ? amount.toString() : amount;
|
|
2805
|
+
const dotIndex = str.indexOf(".");
|
|
2806
|
+
if (dotIndex !== -1) {
|
|
2807
|
+
const decimalPlaces = str.length - dotIndex - 1;
|
|
2808
|
+
if (decimalPlaces > decimals) {
|
|
2809
|
+
throw new Error(
|
|
2810
|
+
`Amount "${str}" has ${decimalPlaces} decimal places, but ${typeof token === "string" && token.startsWith("0x") ? "this token" : token} only supports ${decimals}. Truncate or round your amount.`
|
|
2811
|
+
);
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
return viem.parseUnits(str, decimals);
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2811
2817
|
// src/vault.ts
|
|
2812
2818
|
function getChain(chainId) {
|
|
2813
2819
|
switch (chainId) {
|
|
@@ -3105,12 +3111,20 @@ async function deposit(walletClient, publicClient, vaultAddress, token, amount,
|
|
|
3105
3111
|
tokenAddress = resolveToken(token, chainId);
|
|
3106
3112
|
}
|
|
3107
3113
|
const isEth = tokenAddress.toLowerCase() === NATIVE_ETH.toLowerCase();
|
|
3114
|
+
let resolvedAmount;
|
|
3115
|
+
if (typeof amount === "bigint") {
|
|
3116
|
+
resolvedAmount = amount;
|
|
3117
|
+
} else if (isEth) {
|
|
3118
|
+
resolvedAmount = parseAmount(amount, "WETH");
|
|
3119
|
+
} else {
|
|
3120
|
+
resolvedAmount = parseAmount(amount, token);
|
|
3121
|
+
}
|
|
3108
3122
|
if (!isEth) {
|
|
3109
3123
|
const approveTx = await walletClient.writeContract({
|
|
3110
3124
|
address: tokenAddress,
|
|
3111
3125
|
abi: viem.erc20Abi,
|
|
3112
3126
|
functionName: "approve",
|
|
3113
|
-
args: [vaultAddress,
|
|
3127
|
+
args: [vaultAddress, resolvedAmount],
|
|
3114
3128
|
account: walletClient.account,
|
|
3115
3129
|
chain: walletClient.chain ?? null
|
|
3116
3130
|
});
|
|
@@ -3120,50 +3134,14 @@ async function deposit(walletClient, publicClient, vaultAddress, token, amount,
|
|
|
3120
3134
|
address: vaultAddress,
|
|
3121
3135
|
abi: AxonVaultAbi,
|
|
3122
3136
|
functionName: "deposit",
|
|
3123
|
-
args: [tokenAddress,
|
|
3137
|
+
args: [tokenAddress, resolvedAmount, ref],
|
|
3124
3138
|
account: walletClient.account,
|
|
3125
3139
|
chain: walletClient.chain ?? null,
|
|
3126
|
-
...isEth ? { value:
|
|
3140
|
+
...isEth ? { value: resolvedAmount } : {}
|
|
3127
3141
|
});
|
|
3128
3142
|
await publicClient.waitForTransactionReceipt({ hash });
|
|
3129
3143
|
return hash;
|
|
3130
3144
|
}
|
|
3131
|
-
function resolveTokenDecimals(token, chainId) {
|
|
3132
|
-
if (typeof token === "string" && token.startsWith("0x")) {
|
|
3133
|
-
const symbol = getTokenSymbolByAddress(token);
|
|
3134
|
-
if (!symbol) {
|
|
3135
|
-
throw new Error(
|
|
3136
|
-
`Unknown token address ${token} \u2014 cannot determine decimals. Use a bigint amount instead, or pass a known token symbol.`
|
|
3137
|
-
);
|
|
3138
|
-
}
|
|
3139
|
-
const entry2 = KNOWN_TOKENS[symbol];
|
|
3140
|
-
return entry2.decimals;
|
|
3141
|
-
}
|
|
3142
|
-
const entry = KNOWN_TOKENS[token];
|
|
3143
|
-
if (!entry) {
|
|
3144
|
-
throw new Error(
|
|
3145
|
-
`Unknown token symbol "${token}" \u2014 cannot determine decimals. Use a bigint amount instead, or use a known symbol (${Object.keys(KNOWN_TOKENS).join(", ")}).`
|
|
3146
|
-
);
|
|
3147
|
-
}
|
|
3148
|
-
return entry.decimals;
|
|
3149
|
-
}
|
|
3150
|
-
function parseAmount(amount, token, chainId) {
|
|
3151
|
-
if (typeof amount === "bigint") {
|
|
3152
|
-
return amount;
|
|
3153
|
-
}
|
|
3154
|
-
const decimals = resolveTokenDecimals(token);
|
|
3155
|
-
const str = typeof amount === "number" ? amount.toString() : amount;
|
|
3156
|
-
const dotIndex = str.indexOf(".");
|
|
3157
|
-
if (dotIndex !== -1) {
|
|
3158
|
-
const decimalPlaces = str.length - dotIndex - 1;
|
|
3159
|
-
if (decimalPlaces > decimals) {
|
|
3160
|
-
throw new Error(
|
|
3161
|
-
`Amount "${str}" has ${decimalPlaces} decimal places, but ${typeof token === "string" && token.startsWith("0x") ? "this token" : token} only supports ${decimals}. Truncate or round your amount.`
|
|
3162
|
-
);
|
|
3163
|
-
}
|
|
3164
|
-
}
|
|
3165
|
-
return viem.parseUnits(str, decimals);
|
|
3166
|
-
}
|
|
3167
3145
|
|
|
3168
3146
|
// src/utils.ts
|
|
3169
3147
|
function generateUuid() {
|