@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/dist/index.d.cts
CHANGED
|
@@ -17,8 +17,6 @@ declare enum Token {
|
|
|
17
17
|
COMP = "COMP",
|
|
18
18
|
CRV = "CRV",
|
|
19
19
|
SNX = "SNX",
|
|
20
|
-
ARB = "ARB",
|
|
21
|
-
AERO = "AERO",
|
|
22
20
|
GMX = "GMX"
|
|
23
21
|
}
|
|
24
22
|
interface KnownToken {
|
|
@@ -185,22 +183,6 @@ declare const KNOWN_TOKENS: {
|
|
|
185
183
|
readonly 8453: "0x22e6966B799c4D5B13BE962E1D117b56327FDa66";
|
|
186
184
|
};
|
|
187
185
|
};
|
|
188
|
-
readonly ARB: {
|
|
189
|
-
readonly symbol: "ARB";
|
|
190
|
-
readonly name: "Arbitrum";
|
|
191
|
-
readonly decimals: 18;
|
|
192
|
-
readonly addresses: {
|
|
193
|
-
readonly 42161: "0x912CE59144191C1204E64559FE8253a0e49E6548";
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
readonly AERO: {
|
|
197
|
-
readonly symbol: "AERO";
|
|
198
|
-
readonly name: "Aerodrome";
|
|
199
|
-
readonly decimals: 18;
|
|
200
|
-
readonly addresses: {
|
|
201
|
-
readonly 8453: "0x940181a94A35A4569E4529A3CDfB74e38FD98631";
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
186
|
readonly GMX: {
|
|
205
187
|
readonly symbol: "GMX";
|
|
206
188
|
readonly name: "GMX";
|
|
@@ -1101,11 +1083,11 @@ declare function removeBot(walletClient: WalletClient, publicClient: PublicClien
|
|
|
1101
1083
|
* @param publicClient Public client for the vault's chain.
|
|
1102
1084
|
* @param vaultAddress Vault to deposit into.
|
|
1103
1085
|
* @param token Token symbol ('USDC', 'WETH'), Token enum, raw address, or NATIVE_ETH / 'ETH' for ETH deposits.
|
|
1104
|
-
* @param amount
|
|
1086
|
+
* @param amount Human-readable amount (e.g. 500 for 500 USDC, 0.1 for 0.1 ETH) or raw bigint in base units.
|
|
1105
1087
|
* @param ref Optional bytes32 reference linking to an off-chain record. Defaults to 0x0.
|
|
1106
1088
|
* @returns Transaction hash of the deposit.
|
|
1107
1089
|
*/
|
|
1108
|
-
declare function deposit(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, token: Address | string, amount: bigint, ref?: Hex): Promise<Hex>;
|
|
1090
|
+
declare function deposit(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, token: Address | string, amount: bigint | number | string, ref?: Hex): Promise<Hex>;
|
|
1109
1091
|
|
|
1110
1092
|
interface KeystoreV3 {
|
|
1111
1093
|
version: 3;
|
package/dist/index.d.ts
CHANGED
|
@@ -17,8 +17,6 @@ declare enum Token {
|
|
|
17
17
|
COMP = "COMP",
|
|
18
18
|
CRV = "CRV",
|
|
19
19
|
SNX = "SNX",
|
|
20
|
-
ARB = "ARB",
|
|
21
|
-
AERO = "AERO",
|
|
22
20
|
GMX = "GMX"
|
|
23
21
|
}
|
|
24
22
|
interface KnownToken {
|
|
@@ -185,22 +183,6 @@ declare const KNOWN_TOKENS: {
|
|
|
185
183
|
readonly 8453: "0x22e6966B799c4D5B13BE962E1D117b56327FDa66";
|
|
186
184
|
};
|
|
187
185
|
};
|
|
188
|
-
readonly ARB: {
|
|
189
|
-
readonly symbol: "ARB";
|
|
190
|
-
readonly name: "Arbitrum";
|
|
191
|
-
readonly decimals: 18;
|
|
192
|
-
readonly addresses: {
|
|
193
|
-
readonly 42161: "0x912CE59144191C1204E64559FE8253a0e49E6548";
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
readonly AERO: {
|
|
197
|
-
readonly symbol: "AERO";
|
|
198
|
-
readonly name: "Aerodrome";
|
|
199
|
-
readonly decimals: 18;
|
|
200
|
-
readonly addresses: {
|
|
201
|
-
readonly 8453: "0x940181a94A35A4569E4529A3CDfB74e38FD98631";
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
186
|
readonly GMX: {
|
|
205
187
|
readonly symbol: "GMX";
|
|
206
188
|
readonly name: "GMX";
|
|
@@ -1101,11 +1083,11 @@ declare function removeBot(walletClient: WalletClient, publicClient: PublicClien
|
|
|
1101
1083
|
* @param publicClient Public client for the vault's chain.
|
|
1102
1084
|
* @param vaultAddress Vault to deposit into.
|
|
1103
1085
|
* @param token Token symbol ('USDC', 'WETH'), Token enum, raw address, or NATIVE_ETH / 'ETH' for ETH deposits.
|
|
1104
|
-
* @param amount
|
|
1086
|
+
* @param amount Human-readable amount (e.g. 500 for 500 USDC, 0.1 for 0.1 ETH) or raw bigint in base units.
|
|
1105
1087
|
* @param ref Optional bytes32 reference linking to an off-chain record. Defaults to 0x0.
|
|
1106
1088
|
* @returns Transaction hash of the deposit.
|
|
1107
1089
|
*/
|
|
1108
|
-
declare function deposit(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, token: Address | string, amount: bigint, ref?: Hex): Promise<Hex>;
|
|
1090
|
+
declare function deposit(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, token: Address | string, amount: bigint | number | string, ref?: Hex): Promise<Hex>;
|
|
1109
1091
|
|
|
1110
1092
|
interface KeystoreV3 {
|
|
1111
1093
|
version: 3;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { keccak256, stringToBytes, createPublicClient, http, createWalletClient, erc20Abi
|
|
1
|
+
import { keccak256, stringToBytes, parseUnits, createPublicClient, http, createWalletClient, erc20Abi } 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';
|
|
@@ -47,32 +47,19 @@ var CHAIN_NAMES = {
|
|
|
47
47
|
[8453 /* Base */]: "Base",
|
|
48
48
|
[84532 /* BaseSepolia */]: "Base Sepolia",
|
|
49
49
|
[42161 /* Arbitrum */]: "Arbitrum One",
|
|
50
|
-
[421614 /* ArbitrumSepolia */]: "Arbitrum Sepolia"
|
|
51
|
-
// Future v1 chains (metadata only — not in SUPPORTED_CHAIN_IDS yet)
|
|
52
|
-
10: "Optimism",
|
|
53
|
-
11155420: "OP Sepolia",
|
|
54
|
-
137: "Polygon",
|
|
55
|
-
80002: "Polygon Amoy"
|
|
50
|
+
[421614 /* ArbitrumSepolia */]: "Arbitrum Sepolia"
|
|
56
51
|
};
|
|
57
52
|
var EXPLORER_TX = {
|
|
58
53
|
[8453 /* Base */]: "https://basescan.org/tx/",
|
|
59
54
|
[84532 /* BaseSepolia */]: "https://sepolia.basescan.org/tx/",
|
|
60
55
|
[42161 /* Arbitrum */]: "https://arbiscan.io/tx/",
|
|
61
|
-
[421614 /* ArbitrumSepolia */]: "https://sepolia.arbiscan.io/tx/"
|
|
62
|
-
10: "https://optimistic.etherscan.io/tx/",
|
|
63
|
-
11155420: "https://sepolia-optimism.etherscan.io/tx/",
|
|
64
|
-
137: "https://polygonscan.com/tx/",
|
|
65
|
-
80002: "https://amoy.polygonscan.com/tx/"
|
|
56
|
+
[421614 /* ArbitrumSepolia */]: "https://sepolia.arbiscan.io/tx/"
|
|
66
57
|
};
|
|
67
58
|
var EXPLORER_ADDR = {
|
|
68
59
|
[8453 /* Base */]: "https://basescan.org/address/",
|
|
69
60
|
[84532 /* BaseSepolia */]: "https://sepolia.basescan.org/address/",
|
|
70
61
|
[42161 /* Arbitrum */]: "https://arbiscan.io/address/",
|
|
71
|
-
[421614 /* ArbitrumSepolia */]: "https://sepolia.arbiscan.io/address/"
|
|
72
|
-
10: "https://optimistic.etherscan.io/address/",
|
|
73
|
-
11155420: "https://sepolia-optimism.etherscan.io/address/",
|
|
74
|
-
137: "https://polygonscan.com/address/",
|
|
75
|
-
80002: "https://amoy.polygonscan.com/address/"
|
|
62
|
+
[421614 /* ArbitrumSepolia */]: "https://sepolia.arbiscan.io/address/"
|
|
76
63
|
};
|
|
77
64
|
var DEFAULT_DEADLINE_SECONDS = 300;
|
|
78
65
|
var WINDOW = {
|
|
@@ -2563,8 +2550,6 @@ var Token = /* @__PURE__ */ ((Token2) => {
|
|
|
2563
2550
|
Token2["COMP"] = "COMP";
|
|
2564
2551
|
Token2["CRV"] = "CRV";
|
|
2565
2552
|
Token2["SNX"] = "SNX";
|
|
2566
|
-
Token2["ARB"] = "ARB";
|
|
2567
|
-
Token2["AERO"] = "AERO";
|
|
2568
2553
|
Token2["GMX"] = "GMX";
|
|
2569
2554
|
return Token2;
|
|
2570
2555
|
})(Token || {});
|
|
@@ -2722,23 +2707,6 @@ var KNOWN_TOKENS = {
|
|
|
2722
2707
|
8453: "0x22e6966B799c4D5B13BE962E1D117b56327FDa66"
|
|
2723
2708
|
}
|
|
2724
2709
|
},
|
|
2725
|
-
// ── Chain-native governance ─────────────────────────────
|
|
2726
|
-
ARB: {
|
|
2727
|
-
symbol: "ARB",
|
|
2728
|
-
name: "Arbitrum",
|
|
2729
|
-
decimals: 18,
|
|
2730
|
-
addresses: {
|
|
2731
|
-
42161: "0x912CE59144191C1204E64559FE8253a0e49E6548"
|
|
2732
|
-
}
|
|
2733
|
-
},
|
|
2734
|
-
AERO: {
|
|
2735
|
-
symbol: "AERO",
|
|
2736
|
-
name: "Aerodrome",
|
|
2737
|
-
decimals: 18,
|
|
2738
|
-
addresses: {
|
|
2739
|
-
8453: "0x940181a94A35A4569E4529A3CDfB74e38FD98631"
|
|
2740
|
-
}
|
|
2741
|
-
},
|
|
2742
2710
|
GMX: {
|
|
2743
2711
|
symbol: "GMX",
|
|
2744
2712
|
name: "GMX",
|
|
@@ -2806,6 +2774,44 @@ function resolveToken(token, chainId) {
|
|
|
2806
2774
|
return addr;
|
|
2807
2775
|
}
|
|
2808
2776
|
|
|
2777
|
+
// src/amounts.ts
|
|
2778
|
+
function resolveTokenDecimals(token, chainId) {
|
|
2779
|
+
if (typeof token === "string" && token.startsWith("0x")) {
|
|
2780
|
+
const symbol = getTokenSymbolByAddress(token);
|
|
2781
|
+
if (!symbol) {
|
|
2782
|
+
throw new Error(
|
|
2783
|
+
`Unknown token address ${token} \u2014 cannot determine decimals. Use a bigint amount instead, or pass a known token symbol.`
|
|
2784
|
+
);
|
|
2785
|
+
}
|
|
2786
|
+
const entry2 = KNOWN_TOKENS[symbol];
|
|
2787
|
+
return entry2.decimals;
|
|
2788
|
+
}
|
|
2789
|
+
const entry = KNOWN_TOKENS[token];
|
|
2790
|
+
if (!entry) {
|
|
2791
|
+
throw new Error(
|
|
2792
|
+
`Unknown token symbol "${token}" \u2014 cannot determine decimals. Use a bigint amount instead, or use a known symbol (${Object.keys(KNOWN_TOKENS).join(", ")}).`
|
|
2793
|
+
);
|
|
2794
|
+
}
|
|
2795
|
+
return entry.decimals;
|
|
2796
|
+
}
|
|
2797
|
+
function parseAmount(amount, token, chainId) {
|
|
2798
|
+
if (typeof amount === "bigint") {
|
|
2799
|
+
return amount;
|
|
2800
|
+
}
|
|
2801
|
+
const decimals = resolveTokenDecimals(token);
|
|
2802
|
+
const str = typeof amount === "number" ? amount.toString() : amount;
|
|
2803
|
+
const dotIndex = str.indexOf(".");
|
|
2804
|
+
if (dotIndex !== -1) {
|
|
2805
|
+
const decimalPlaces = str.length - dotIndex - 1;
|
|
2806
|
+
if (decimalPlaces > decimals) {
|
|
2807
|
+
throw new Error(
|
|
2808
|
+
`Amount "${str}" has ${decimalPlaces} decimal places, but ${typeof token === "string" && token.startsWith("0x") ? "this token" : token} only supports ${decimals}. Truncate or round your amount.`
|
|
2809
|
+
);
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
return parseUnits(str, decimals);
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2809
2815
|
// src/vault.ts
|
|
2810
2816
|
function getChain(chainId) {
|
|
2811
2817
|
switch (chainId) {
|
|
@@ -3103,12 +3109,20 @@ async function deposit(walletClient, publicClient, vaultAddress, token, amount,
|
|
|
3103
3109
|
tokenAddress = resolveToken(token, chainId);
|
|
3104
3110
|
}
|
|
3105
3111
|
const isEth = tokenAddress.toLowerCase() === NATIVE_ETH.toLowerCase();
|
|
3112
|
+
let resolvedAmount;
|
|
3113
|
+
if (typeof amount === "bigint") {
|
|
3114
|
+
resolvedAmount = amount;
|
|
3115
|
+
} else if (isEth) {
|
|
3116
|
+
resolvedAmount = parseAmount(amount, "WETH");
|
|
3117
|
+
} else {
|
|
3118
|
+
resolvedAmount = parseAmount(amount, token);
|
|
3119
|
+
}
|
|
3106
3120
|
if (!isEth) {
|
|
3107
3121
|
const approveTx = await walletClient.writeContract({
|
|
3108
3122
|
address: tokenAddress,
|
|
3109
3123
|
abi: erc20Abi,
|
|
3110
3124
|
functionName: "approve",
|
|
3111
|
-
args: [vaultAddress,
|
|
3125
|
+
args: [vaultAddress, resolvedAmount],
|
|
3112
3126
|
account: walletClient.account,
|
|
3113
3127
|
chain: walletClient.chain ?? null
|
|
3114
3128
|
});
|
|
@@ -3118,50 +3132,14 @@ async function deposit(walletClient, publicClient, vaultAddress, token, amount,
|
|
|
3118
3132
|
address: vaultAddress,
|
|
3119
3133
|
abi: AxonVaultAbi,
|
|
3120
3134
|
functionName: "deposit",
|
|
3121
|
-
args: [tokenAddress,
|
|
3135
|
+
args: [tokenAddress, resolvedAmount, ref],
|
|
3122
3136
|
account: walletClient.account,
|
|
3123
3137
|
chain: walletClient.chain ?? null,
|
|
3124
|
-
...isEth ? { value:
|
|
3138
|
+
...isEth ? { value: resolvedAmount } : {}
|
|
3125
3139
|
});
|
|
3126
3140
|
await publicClient.waitForTransactionReceipt({ hash });
|
|
3127
3141
|
return hash;
|
|
3128
3142
|
}
|
|
3129
|
-
function resolveTokenDecimals(token, chainId) {
|
|
3130
|
-
if (typeof token === "string" && token.startsWith("0x")) {
|
|
3131
|
-
const symbol = getTokenSymbolByAddress(token);
|
|
3132
|
-
if (!symbol) {
|
|
3133
|
-
throw new Error(
|
|
3134
|
-
`Unknown token address ${token} \u2014 cannot determine decimals. Use a bigint amount instead, or pass a known token symbol.`
|
|
3135
|
-
);
|
|
3136
|
-
}
|
|
3137
|
-
const entry2 = KNOWN_TOKENS[symbol];
|
|
3138
|
-
return entry2.decimals;
|
|
3139
|
-
}
|
|
3140
|
-
const entry = KNOWN_TOKENS[token];
|
|
3141
|
-
if (!entry) {
|
|
3142
|
-
throw new Error(
|
|
3143
|
-
`Unknown token symbol "${token}" \u2014 cannot determine decimals. Use a bigint amount instead, or use a known symbol (${Object.keys(KNOWN_TOKENS).join(", ")}).`
|
|
3144
|
-
);
|
|
3145
|
-
}
|
|
3146
|
-
return entry.decimals;
|
|
3147
|
-
}
|
|
3148
|
-
function parseAmount(amount, token, chainId) {
|
|
3149
|
-
if (typeof amount === "bigint") {
|
|
3150
|
-
return amount;
|
|
3151
|
-
}
|
|
3152
|
-
const decimals = resolveTokenDecimals(token);
|
|
3153
|
-
const str = typeof amount === "number" ? amount.toString() : amount;
|
|
3154
|
-
const dotIndex = str.indexOf(".");
|
|
3155
|
-
if (dotIndex !== -1) {
|
|
3156
|
-
const decimalPlaces = str.length - dotIndex - 1;
|
|
3157
|
-
if (decimalPlaces > decimals) {
|
|
3158
|
-
throw new Error(
|
|
3159
|
-
`Amount "${str}" has ${decimalPlaces} decimal places, but ${typeof token === "string" && token.startsWith("0x") ? "this token" : token} only supports ${decimals}. Truncate or round your amount.`
|
|
3160
|
-
);
|
|
3161
|
-
}
|
|
3162
|
-
}
|
|
3163
|
-
return parseUnits(str, decimals);
|
|
3164
|
-
}
|
|
3165
3143
|
|
|
3166
3144
|
// src/utils.ts
|
|
3167
3145
|
function generateUuid() {
|