@axonfi/sdk 0.4.0 → 0.4.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/README.md +15 -9
- package/dist/index.cjs +4325 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3256 -0
- package/dist/index.d.ts +3256 -21
- package/dist/index.js +4261 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/abis/AxonRegistry.d.ts +0 -294
- package/dist/abis/AxonRegistry.d.ts.map +0 -1
- package/dist/abis/AxonRegistry.js +0 -381
- package/dist/abis/AxonRegistry.js.map +0 -1
- package/dist/abis/AxonVault.d.ts +0 -1577
- package/dist/abis/AxonVault.d.ts.map +0 -1
- package/dist/abis/AxonVault.js +0 -2026
- package/dist/abis/AxonVault.js.map +0 -1
- package/dist/abis/AxonVaultFactory.d.ts +0 -207
- package/dist/abis/AxonVaultFactory.d.ts.map +0 -1
- package/dist/abis/AxonVaultFactory.js +0 -269
- package/dist/abis/AxonVaultFactory.js.map +0 -1
- package/dist/amounts.d.ts +0 -37
- package/dist/amounts.d.ts.map +0 -1
- package/dist/amounts.js +0 -72
- package/dist/amounts.js.map +0 -1
- package/dist/amounts.spec.d.ts +0 -2
- package/dist/amounts.spec.d.ts.map +0 -1
- package/dist/amounts.spec.js +0 -92
- package/dist/amounts.spec.js.map +0 -1
- package/dist/client.d.ts +0 -196
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -621
- package/dist/client.js.map +0 -1
- package/dist/client.spec.d.ts +0 -2
- package/dist/client.spec.d.ts.map +0 -1
- package/dist/client.spec.js +0 -437
- package/dist/client.spec.js.map +0 -1
- package/dist/constants.d.ts +0 -110
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -172
- package/dist/constants.js.map +0 -1
- package/dist/constants.spec.d.ts +0 -2
- package/dist/constants.spec.d.ts.map +0 -1
- package/dist/constants.spec.js +0 -95
- package/dist/constants.spec.js.map +0 -1
- package/dist/eip3009.d.ts +0 -45
- package/dist/eip3009.d.ts.map +0 -1
- package/dist/eip3009.js +0 -85
- package/dist/eip3009.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/keystore.d.ts +0 -60
- package/dist/keystore.d.ts.map +0 -1
- package/dist/keystore.js +0 -182
- package/dist/keystore.js.map +0 -1
- package/dist/keystore.spec.d.ts +0 -2
- package/dist/keystore.spec.d.ts.map +0 -1
- package/dist/keystore.spec.js +0 -71
- package/dist/keystore.spec.js.map +0 -1
- package/dist/permit2.d.ts +0 -45
- package/dist/permit2.d.ts.map +0 -1
- package/dist/permit2.js +0 -81
- package/dist/permit2.js.map +0 -1
- package/dist/signer.d.ts +0 -35
- package/dist/signer.d.ts.map +0 -1
- package/dist/signer.js +0 -132
- package/dist/signer.js.map +0 -1
- package/dist/signer.spec.d.ts +0 -2
- package/dist/signer.spec.d.ts.map +0 -1
- package/dist/signer.spec.js +0 -94
- package/dist/signer.spec.js.map +0 -1
- package/dist/tokens.d.ts +0 -215
- package/dist/tokens.d.ts.map +0 -1
- package/dist/tokens.js +0 -247
- package/dist/tokens.js.map +0 -1
- package/dist/types.d.ts +0 -302
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -8
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -29
- package/dist/utils.js.map +0 -1
- package/dist/vault.d.ts +0 -60
- package/dist/vault.d.ts.map +0 -1
- package/dist/vault.js +0 -267
- package/dist/vault.js.map +0 -1
- package/dist/vault.spec.d.ts +0 -2
- package/dist/vault.spec.d.ts.map +0 -1
- package/dist/vault.spec.js +0 -162
- package/dist/vault.spec.js.map +0 -1
- package/dist/x402.d.ts +0 -88
- package/dist/x402.d.ts.map +0 -1
- package/dist/x402.js +0 -124
- package/dist/x402.js.map +0 -1
- package/dist/x402.spec.d.ts +0 -2
- package/dist/x402.spec.d.ts.map +0 -1
- package/dist/x402.spec.js +0 -411
- package/dist/x402.spec.js.map +0 -1
package/dist/vault.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { createPublicClient, createWalletClient, http } from 'viem';
|
|
2
|
-
import { privateKeyToAccount } from 'viem/accounts';
|
|
3
|
-
import { base, baseSepolia, arbitrum, arbitrumSepolia } from 'viem/chains';
|
|
4
|
-
import { AxonVaultAbi } from './abis/AxonVault.js';
|
|
5
|
-
import { AxonVaultFactoryAbi } from './abis/AxonVaultFactory.js';
|
|
6
|
-
// ============================================================================
|
|
7
|
-
// Chain helpers
|
|
8
|
-
// ============================================================================
|
|
9
|
-
/** Returns the viem Chain object for a supported Axon chain ID. */
|
|
10
|
-
export function getChain(chainId) {
|
|
11
|
-
switch (chainId) {
|
|
12
|
-
case 8453:
|
|
13
|
-
return base;
|
|
14
|
-
case 84532:
|
|
15
|
-
return baseSepolia;
|
|
16
|
-
case 42161:
|
|
17
|
-
return arbitrum;
|
|
18
|
-
case 421614:
|
|
19
|
-
return arbitrumSepolia;
|
|
20
|
-
default:
|
|
21
|
-
throw new Error(`Unsupported chainId: ${chainId}. Supported: 8453 (Base), 84532 (Base Sepolia), 42161 (Arbitrum), 421614 (Arbitrum Sepolia)`);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/** Create a viem PublicClient for the given chain and RPC URL. */
|
|
25
|
-
export function createAxonPublicClient(chainId, rpcUrl) {
|
|
26
|
-
return createPublicClient({
|
|
27
|
-
chain: getChain(chainId),
|
|
28
|
-
transport: http(rpcUrl),
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/** Create a viem WalletClient from a raw private key (signing-only, no RPC needed). */
|
|
32
|
-
export function createAxonWalletClient(privateKey, chainId) {
|
|
33
|
-
const account = privateKeyToAccount(privateKey);
|
|
34
|
-
return createWalletClient({
|
|
35
|
-
account,
|
|
36
|
-
chain: getChain(chainId),
|
|
37
|
-
transport: http(), // signing is local — transport is unused but required by viem
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
// ============================================================================
|
|
41
|
-
// Read-only vault helpers
|
|
42
|
-
// ============================================================================
|
|
43
|
-
/**
|
|
44
|
-
* Returns the full BotConfig for a bot address from the vault.
|
|
45
|
-
* If the bot has never been added, isActive will be false and all
|
|
46
|
-
* numeric fields will be 0n.
|
|
47
|
-
*/
|
|
48
|
-
export async function getBotConfig(publicClient, vaultAddress, botAddress) {
|
|
49
|
-
const result = await publicClient.readContract({
|
|
50
|
-
address: vaultAddress,
|
|
51
|
-
abi: AxonVaultAbi,
|
|
52
|
-
functionName: 'getBotConfig',
|
|
53
|
-
args: [botAddress],
|
|
54
|
-
});
|
|
55
|
-
return {
|
|
56
|
-
isActive: result.isActive,
|
|
57
|
-
registeredAt: result.registeredAt,
|
|
58
|
-
maxPerTxAmount: result.maxPerTxAmount,
|
|
59
|
-
maxRebalanceAmount: result.maxRebalanceAmount,
|
|
60
|
-
spendingLimits: result.spendingLimits.map((sl) => ({
|
|
61
|
-
amount: sl.amount,
|
|
62
|
-
maxCount: sl.maxCount,
|
|
63
|
-
windowSeconds: sl.windowSeconds,
|
|
64
|
-
})),
|
|
65
|
-
aiTriggerThreshold: result.aiTriggerThreshold,
|
|
66
|
-
requireAiVerification: result.requireAiVerification,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
/** Returns whether a bot address is currently active in the vault. */
|
|
70
|
-
export async function isBotActive(publicClient, vaultAddress, botAddress) {
|
|
71
|
-
return publicClient.readContract({
|
|
72
|
-
address: vaultAddress,
|
|
73
|
-
abi: AxonVaultAbi,
|
|
74
|
-
functionName: 'isBotActive',
|
|
75
|
-
args: [botAddress],
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/** Returns the operator ceilings set by the vault owner. */
|
|
79
|
-
export async function getOperatorCeilings(publicClient, vaultAddress) {
|
|
80
|
-
const result = await publicClient.readContract({
|
|
81
|
-
address: vaultAddress,
|
|
82
|
-
abi: AxonVaultAbi,
|
|
83
|
-
functionName: 'operatorCeilings',
|
|
84
|
-
});
|
|
85
|
-
// viem returns multiple named outputs as a tuple; destructure by position
|
|
86
|
-
const [maxPerTxAmount, maxBotDailyLimit, maxOperatorBots, vaultDailyAggregate, minAiTriggerFloor] = result;
|
|
87
|
-
return {
|
|
88
|
-
maxPerTxAmount,
|
|
89
|
-
maxBotDailyLimit,
|
|
90
|
-
maxOperatorBots,
|
|
91
|
-
vaultDailyAggregate,
|
|
92
|
-
minAiTriggerFloor,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Returns the maximum USDC an operator-compromised wallet could drain per day.
|
|
97
|
-
* Computed on-chain as: min(maxOperatorBots × maxBotDailyLimit, vaultDailyAggregate).
|
|
98
|
-
* Returns 0n if operator has no bot-add permission.
|
|
99
|
-
*/
|
|
100
|
-
export async function operatorMaxDrainPerDay(publicClient, vaultAddress) {
|
|
101
|
-
return publicClient.readContract({
|
|
102
|
-
address: vaultAddress,
|
|
103
|
-
abi: AxonVaultAbi,
|
|
104
|
-
functionName: 'operatorMaxDrainPerDay',
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/** Returns whether the vault is currently paused. */
|
|
108
|
-
export async function isVaultPaused(publicClient, vaultAddress) {
|
|
109
|
-
return publicClient.readContract({
|
|
110
|
-
address: vaultAddress,
|
|
111
|
-
abi: AxonVaultAbi,
|
|
112
|
-
functionName: 'paused',
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
/** Returns the EIP-712 domain separator for this vault (for off-chain verification). */
|
|
116
|
-
export async function getDomainSeparator(publicClient, vaultAddress) {
|
|
117
|
-
return publicClient.readContract({
|
|
118
|
-
address: vaultAddress,
|
|
119
|
-
abi: AxonVaultAbi,
|
|
120
|
-
functionName: 'DOMAIN_SEPARATOR',
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/** Returns the vault contract version number. */
|
|
124
|
-
export async function getVaultVersion(publicClient, vaultAddress) {
|
|
125
|
-
const version = await publicClient.readContract({
|
|
126
|
-
address: vaultAddress,
|
|
127
|
-
abi: AxonVaultAbi,
|
|
128
|
-
functionName: 'VERSION',
|
|
129
|
-
});
|
|
130
|
-
return Number(version);
|
|
131
|
-
}
|
|
132
|
-
/** Returns the vault owner address. */
|
|
133
|
-
export async function getVaultOwner(publicClient, vaultAddress) {
|
|
134
|
-
return publicClient.readContract({
|
|
135
|
-
address: vaultAddress,
|
|
136
|
-
abi: AxonVaultAbi,
|
|
137
|
-
functionName: 'owner',
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
/** Returns the vault operator address (address(0) if no operator set). */
|
|
141
|
-
export async function getVaultOperator(publicClient, vaultAddress) {
|
|
142
|
-
return publicClient.readContract({
|
|
143
|
-
address: vaultAddress,
|
|
144
|
-
abi: AxonVaultAbi,
|
|
145
|
-
functionName: 'operator',
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Check whether a destination address is allowed for a given bot.
|
|
150
|
-
*
|
|
151
|
-
* Logic mirrors the on-chain enforcement order:
|
|
152
|
-
* 1. If destination is on the global blacklist → blocked
|
|
153
|
-
* 2. If global whitelist is non-empty → destination must be on it
|
|
154
|
-
* 3. If bot-specific whitelist is non-empty → destination must be on it
|
|
155
|
-
* 4. Otherwise → allowed
|
|
156
|
-
*/
|
|
157
|
-
export async function isDestinationAllowed(publicClient, vaultAddress, botAddress, destination) {
|
|
158
|
-
// Step 1: Check global blacklist
|
|
159
|
-
const isBlacklisted = await publicClient.readContract({
|
|
160
|
-
address: vaultAddress,
|
|
161
|
-
abi: AxonVaultAbi,
|
|
162
|
-
functionName: 'globalDestinationBlacklist',
|
|
163
|
-
args: [destination],
|
|
164
|
-
});
|
|
165
|
-
if (isBlacklisted) {
|
|
166
|
-
return { allowed: false, reason: 'Destination is on the global blacklist' };
|
|
167
|
-
}
|
|
168
|
-
// Step 2: Check global whitelist (if non-empty, destination must be on it)
|
|
169
|
-
const globalCount = await publicClient.readContract({
|
|
170
|
-
address: vaultAddress,
|
|
171
|
-
abi: AxonVaultAbi,
|
|
172
|
-
functionName: 'globalDestinationCount',
|
|
173
|
-
});
|
|
174
|
-
if (globalCount > 0n) {
|
|
175
|
-
const isGlobalWhitelisted = await publicClient.readContract({
|
|
176
|
-
address: vaultAddress,
|
|
177
|
-
abi: AxonVaultAbi,
|
|
178
|
-
functionName: 'globalDestinationWhitelist',
|
|
179
|
-
args: [destination],
|
|
180
|
-
});
|
|
181
|
-
if (!isGlobalWhitelisted) {
|
|
182
|
-
return { allowed: false, reason: 'Destination is not on the global whitelist' };
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
// Step 3: Check bot-specific whitelist (if non-empty, destination must be on it)
|
|
186
|
-
const botCount = await publicClient.readContract({
|
|
187
|
-
address: vaultAddress,
|
|
188
|
-
abi: AxonVaultAbi,
|
|
189
|
-
functionName: 'botDestinationCount',
|
|
190
|
-
args: [botAddress],
|
|
191
|
-
});
|
|
192
|
-
if (botCount > 0n) {
|
|
193
|
-
const isBotWhitelisted = await publicClient.readContract({
|
|
194
|
-
address: vaultAddress,
|
|
195
|
-
abi: AxonVaultAbi,
|
|
196
|
-
functionName: 'botDestinationWhitelist',
|
|
197
|
-
args: [botAddress, destination],
|
|
198
|
-
});
|
|
199
|
-
if (!isBotWhitelisted) {
|
|
200
|
-
return { allowed: false, reason: 'Destination is not on the bot whitelist' };
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return { allowed: true };
|
|
204
|
-
}
|
|
205
|
-
// ============================================================================
|
|
206
|
-
// Rebalance token whitelist (on-chain reads)
|
|
207
|
-
// ============================================================================
|
|
208
|
-
/** Returns the number of tokens in the vault's on-chain rebalance whitelist. 0 = no on-chain whitelist. */
|
|
209
|
-
export async function getRebalanceTokenCount(publicClient, vaultAddress) {
|
|
210
|
-
const count = await publicClient.readContract({
|
|
211
|
-
address: vaultAddress,
|
|
212
|
-
abi: AxonVaultAbi,
|
|
213
|
-
functionName: 'rebalanceTokenCount',
|
|
214
|
-
});
|
|
215
|
-
return Number(count);
|
|
216
|
-
}
|
|
217
|
-
/** Returns whether a token is in the vault's on-chain rebalance whitelist. */
|
|
218
|
-
export async function isRebalanceTokenWhitelisted(publicClient, vaultAddress, token) {
|
|
219
|
-
return publicClient.readContract({
|
|
220
|
-
address: vaultAddress,
|
|
221
|
-
abi: AxonVaultAbi,
|
|
222
|
-
functionName: 'rebalanceTokenWhitelist',
|
|
223
|
-
args: [token],
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
// ============================================================================
|
|
227
|
-
// Factory — deploy a new vault
|
|
228
|
-
// ============================================================================
|
|
229
|
-
/**
|
|
230
|
-
* Deploy a new AxonVault via the factory.
|
|
231
|
-
*
|
|
232
|
-
* The vault is owned by the walletClient's account. Permissionless — any
|
|
233
|
-
* address can deploy, no Axon approval required.
|
|
234
|
-
*
|
|
235
|
-
* @param walletClient Wallet that will own the deployed vault.
|
|
236
|
-
* @param factoryAddress Address of the deployed AxonVaultFactory.
|
|
237
|
-
* @returns Address of the newly deployed vault.
|
|
238
|
-
*/
|
|
239
|
-
export async function deployVault(walletClient, publicClient, factoryAddress) {
|
|
240
|
-
if (!walletClient.account) {
|
|
241
|
-
throw new Error('walletClient has no account attached');
|
|
242
|
-
}
|
|
243
|
-
const hash = await walletClient.writeContract({
|
|
244
|
-
address: factoryAddress,
|
|
245
|
-
abi: AxonVaultFactoryAbi,
|
|
246
|
-
functionName: 'deployVault',
|
|
247
|
-
args: [],
|
|
248
|
-
account: walletClient.account,
|
|
249
|
-
chain: walletClient.chain ?? null,
|
|
250
|
-
});
|
|
251
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
252
|
-
// Extract vault address from the VaultDeployed event
|
|
253
|
-
for (const log of receipt.logs) {
|
|
254
|
-
try {
|
|
255
|
-
// The second indexed topic is the vault address (owner is first indexed)
|
|
256
|
-
if (log.topics.length >= 3 && log.topics[2]) {
|
|
257
|
-
const vaultAddress = `0x${log.topics[2].slice(26)}`;
|
|
258
|
-
return vaultAddress;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
catch {
|
|
262
|
-
// Not a VaultDeployed log, continue
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
throw new Error('VaultDeployed event not found in transaction receipt');
|
|
266
|
-
}
|
|
267
|
-
//# sourceMappingURL=vault.js.map
|
package/dist/vault.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vault.js","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE3E,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGjE,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E,mEAAmE;AACnE,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,IAAI;YACP,OAAO,IAAI,CAAC;QACd,KAAK,KAAK;YACR,OAAO,WAAW,CAAC;QACrB,KAAK,KAAK;YACR,OAAO,QAAQ,CAAC;QAClB,KAAK,MAAM;YACT,OAAO,eAAe,CAAC;QACzB;YACE,MAAM,IAAI,KAAK,CACb,wBAAwB,OAAO,6FAA6F,CAC7H,CAAC;IACN,CAAC;AACH,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,sBAAsB,CAAC,OAAe,EAAE,MAAc;IACpE,OAAO,kBAAkB,CAAC;QACxB,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC;QACxB,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC;KACxB,CAAC,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C,CAAC,EAAE,CAAC;gBAC5C,MAAM,YAAY,GAAG,KAAK,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,EAAa,CAAC;gBAC/D,OAAO,YAAY,CAAC;YACtB,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,oCAAoC;QACtC,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;AAC1E,CAAC"}
|
package/dist/vault.spec.d.ts
DELETED
package/dist/vault.spec.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vault.spec.d.ts","sourceRoot":"","sources":["../src/vault.spec.ts"],"names":[],"mappings":""}
|
package/dist/vault.spec.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { jest, describe, it, expect } from '@jest/globals';
|
|
2
|
-
import { getBotConfig, isBotActive, getOperatorCeilings, operatorMaxDrainPerDay, isVaultPaused, getVaultVersion, getVaultOwner, getVaultOperator, isDestinationAllowed, getChain, } from './vault.js';
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
// Mock publicClient
|
|
5
|
-
// ---------------------------------------------------------------------------
|
|
6
|
-
function mockPublicClient(readResults) {
|
|
7
|
-
return {
|
|
8
|
-
readContract: jest.fn(({ functionName, args }) => {
|
|
9
|
-
const key = args ? `${functionName}:${args.join(',')}` : functionName;
|
|
10
|
-
if (key in readResults)
|
|
11
|
-
return Promise.resolve(readResults[key]);
|
|
12
|
-
if (functionName in readResults)
|
|
13
|
-
return Promise.resolve(readResults[functionName]);
|
|
14
|
-
return Promise.reject(new Error(`Unmocked readContract: ${key}`));
|
|
15
|
-
}),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const VAULT = '0x1111111111111111111111111111111111111111';
|
|
19
|
-
const BOT = '0x2222222222222222222222222222222222222222';
|
|
20
|
-
const DEST = '0x3333333333333333333333333333333333333333';
|
|
21
|
-
const OWNER = '0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
|
|
22
|
-
const OPERATOR = '0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB';
|
|
23
|
-
describe('getChain', () => {
|
|
24
|
-
it('returns base for 8453', () => {
|
|
25
|
-
expect(getChain(8453).id).toBe(8453);
|
|
26
|
-
});
|
|
27
|
-
it('returns baseSepolia for 84532', () => {
|
|
28
|
-
expect(getChain(84532).id).toBe(84532);
|
|
29
|
-
});
|
|
30
|
-
it('throws for unsupported chain ID', () => {
|
|
31
|
-
expect(() => getChain(999)).toThrow('Unsupported chainId: 999');
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
describe('isBotActive', () => {
|
|
35
|
-
it('returns true when bot is active', async () => {
|
|
36
|
-
const client = mockPublicClient({ [`isBotActive:${BOT}`]: true });
|
|
37
|
-
expect(await isBotActive(client, VAULT, BOT)).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
it('returns false when bot is not active', async () => {
|
|
40
|
-
const client = mockPublicClient({ [`isBotActive:${BOT}`]: false });
|
|
41
|
-
expect(await isBotActive(client, VAULT, BOT)).toBe(false);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
describe('isVaultPaused', () => {
|
|
45
|
-
it('returns true when vault is paused', async () => {
|
|
46
|
-
const client = mockPublicClient({ paused: true });
|
|
47
|
-
expect(await isVaultPaused(client, VAULT)).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
it('returns false when vault is not paused', async () => {
|
|
50
|
-
const client = mockPublicClient({ paused: false });
|
|
51
|
-
expect(await isVaultPaused(client, VAULT)).toBe(false);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe('getVaultVersion', () => {
|
|
55
|
-
it('returns the version as a number', async () => {
|
|
56
|
-
const client = mockPublicClient({ VERSION: 1n });
|
|
57
|
-
expect(await getVaultVersion(client, VAULT)).toBe(1);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe('getVaultOwner', () => {
|
|
61
|
-
it('returns the owner address', async () => {
|
|
62
|
-
const client = mockPublicClient({ owner: OWNER });
|
|
63
|
-
expect(await getVaultOwner(client, VAULT)).toBe(OWNER);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
describe('getVaultOperator', () => {
|
|
67
|
-
it('returns the operator address', async () => {
|
|
68
|
-
const client = mockPublicClient({ operator: OPERATOR });
|
|
69
|
-
expect(await getVaultOperator(client, VAULT)).toBe(OPERATOR);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe('getBotConfig', () => {
|
|
73
|
-
it('returns a full BotConfig struct', async () => {
|
|
74
|
-
const raw = {
|
|
75
|
-
isActive: true,
|
|
76
|
-
registeredAt: 1700000000n,
|
|
77
|
-
maxPerTxAmount: 10000000n,
|
|
78
|
-
spendingLimits: [{ amount: 100000000n, maxCount: 10n, windowSeconds: 86400n }],
|
|
79
|
-
aiTriggerThreshold: 5000000n,
|
|
80
|
-
requireAiVerification: false,
|
|
81
|
-
};
|
|
82
|
-
const client = mockPublicClient({ [`getBotConfig:${BOT}`]: raw });
|
|
83
|
-
const config = await getBotConfig(client, VAULT, BOT);
|
|
84
|
-
expect(config.isActive).toBe(true);
|
|
85
|
-
expect(config.registeredAt).toBe(1700000000n);
|
|
86
|
-
expect(config.maxPerTxAmount).toBe(10000000n);
|
|
87
|
-
expect(config.spendingLimits).toHaveLength(1);
|
|
88
|
-
expect(config.spendingLimits[0].windowSeconds).toBe(86400n);
|
|
89
|
-
expect(config.requireAiVerification).toBe(false);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
describe('getOperatorCeilings', () => {
|
|
93
|
-
it('returns ceilings from a tuple', async () => {
|
|
94
|
-
const tuple = [100n, 200n, 5n, 1000n, 50n];
|
|
95
|
-
const client = mockPublicClient({ operatorCeilings: tuple });
|
|
96
|
-
const ceilings = await getOperatorCeilings(client, VAULT);
|
|
97
|
-
expect(ceilings.maxPerTxAmount).toBe(100n);
|
|
98
|
-
expect(ceilings.maxBotDailyLimit).toBe(200n);
|
|
99
|
-
expect(ceilings.maxOperatorBots).toBe(5n);
|
|
100
|
-
expect(ceilings.vaultDailyAggregate).toBe(1000n);
|
|
101
|
-
expect(ceilings.minAiTriggerFloor).toBe(50n);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
describe('operatorMaxDrainPerDay', () => {
|
|
105
|
-
it('returns the drain amount', async () => {
|
|
106
|
-
const client = mockPublicClient({ operatorMaxDrainPerDay: 500000000n });
|
|
107
|
-
expect(await operatorMaxDrainPerDay(client, VAULT)).toBe(500000000n);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
describe('isDestinationAllowed', () => {
|
|
111
|
-
it('blocks blacklisted destinations', async () => {
|
|
112
|
-
const client = mockPublicClient({
|
|
113
|
-
[`globalDestinationBlacklist:${DEST}`]: true,
|
|
114
|
-
});
|
|
115
|
-
const result = await isDestinationAllowed(client, VAULT, BOT, DEST);
|
|
116
|
-
expect(result.allowed).toBe(false);
|
|
117
|
-
expect(result.reason).toContain('blacklist');
|
|
118
|
-
});
|
|
119
|
-
it('blocks when not on global whitelist (non-empty whitelist)', async () => {
|
|
120
|
-
const client = mockPublicClient({
|
|
121
|
-
[`globalDestinationBlacklist:${DEST}`]: false,
|
|
122
|
-
globalDestinationCount: 3n,
|
|
123
|
-
[`globalDestinationWhitelist:${DEST}`]: false,
|
|
124
|
-
});
|
|
125
|
-
const result = await isDestinationAllowed(client, VAULT, BOT, DEST);
|
|
126
|
-
expect(result.allowed).toBe(false);
|
|
127
|
-
expect(result.reason).toContain('global whitelist');
|
|
128
|
-
});
|
|
129
|
-
it('allows when global whitelist is empty and no bot whitelist', async () => {
|
|
130
|
-
const client = mockPublicClient({
|
|
131
|
-
[`globalDestinationBlacklist:${DEST}`]: false,
|
|
132
|
-
globalDestinationCount: 0n,
|
|
133
|
-
[`botDestinationCount:${BOT}`]: 0n,
|
|
134
|
-
});
|
|
135
|
-
const result = await isDestinationAllowed(client, VAULT, BOT, DEST);
|
|
136
|
-
expect(result.allowed).toBe(true);
|
|
137
|
-
expect(result.reason).toBeUndefined();
|
|
138
|
-
});
|
|
139
|
-
it('blocks when not on bot whitelist (non-empty bot whitelist)', async () => {
|
|
140
|
-
const client = mockPublicClient({
|
|
141
|
-
[`globalDestinationBlacklist:${DEST}`]: false,
|
|
142
|
-
globalDestinationCount: 0n,
|
|
143
|
-
[`botDestinationCount:${BOT}`]: 2n,
|
|
144
|
-
[`botDestinationWhitelist:${BOT},${DEST}`]: false,
|
|
145
|
-
});
|
|
146
|
-
const result = await isDestinationAllowed(client, VAULT, BOT, DEST);
|
|
147
|
-
expect(result.allowed).toBe(false);
|
|
148
|
-
expect(result.reason).toContain('bot whitelist');
|
|
149
|
-
});
|
|
150
|
-
it('allows when on both whitelists', async () => {
|
|
151
|
-
const client = mockPublicClient({
|
|
152
|
-
[`globalDestinationBlacklist:${DEST}`]: false,
|
|
153
|
-
globalDestinationCount: 1n,
|
|
154
|
-
[`globalDestinationWhitelist:${DEST}`]: true,
|
|
155
|
-
[`botDestinationCount:${BOT}`]: 1n,
|
|
156
|
-
[`botDestinationWhitelist:${BOT},${DEST}`]: true,
|
|
157
|
-
});
|
|
158
|
-
const result = await isDestinationAllowed(client, VAULT, BOT, DEST);
|
|
159
|
-
expect(result.allowed).toBe(true);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
//# sourceMappingURL=vault.spec.js.map
|
package/dist/vault.spec.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vault.spec.js","sourceRoot":"","sources":["../src/vault.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EACL,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,aAAa,EAC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AC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/x402.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/** Resource descriptor from the x402 PAYMENT-REQUIRED header. */
|
|
2
|
-
export interface X402Resource {
|
|
3
|
-
/** URL of the resource being unlocked. */
|
|
4
|
-
url: string;
|
|
5
|
-
/** Human-readable description of the resource. */
|
|
6
|
-
description?: string;
|
|
7
|
-
/** MIME type of the resource. */
|
|
8
|
-
mimeType?: string;
|
|
9
|
-
}
|
|
10
|
-
/** A single payment option from the `accepts` array. */
|
|
11
|
-
export interface X402PaymentOption {
|
|
12
|
-
/** Recipient address (merchant). */
|
|
13
|
-
payTo: string;
|
|
14
|
-
/** Amount in token base units (string). */
|
|
15
|
-
amount: string;
|
|
16
|
-
/** Token contract address. */
|
|
17
|
-
asset: string;
|
|
18
|
-
/** CAIP-2 network identifier, e.g. "eip155:8453". */
|
|
19
|
-
network: string;
|
|
20
|
-
/** Settlement scheme: "exact" (EIP-3009) or "permit2". */
|
|
21
|
-
scheme?: string;
|
|
22
|
-
/** Additional option-specific fields. */
|
|
23
|
-
extra?: Record<string, unknown>;
|
|
24
|
-
}
|
|
25
|
-
/** Parsed x402 PAYMENT-REQUIRED response. */
|
|
26
|
-
export interface X402PaymentRequired {
|
|
27
|
-
/** x402 protocol version. */
|
|
28
|
-
x402Version: number;
|
|
29
|
-
/** Resource being unlocked. */
|
|
30
|
-
resource: X402Resource;
|
|
31
|
-
/** Accepted payment options. */
|
|
32
|
-
accepts: X402PaymentOption[];
|
|
33
|
-
}
|
|
34
|
-
/** Result of handlePaymentRequired — contains everything needed to retry the request. */
|
|
35
|
-
export interface X402HandleResult {
|
|
36
|
-
/** Base64-encoded JSON for the PAYMENT-SIGNATURE header. */
|
|
37
|
-
paymentSignature: string;
|
|
38
|
-
/** The payment option that was selected and funded. */
|
|
39
|
-
selectedOption: X402PaymentOption;
|
|
40
|
-
/** Axon payment result (txHash, requestId, etc.). */
|
|
41
|
-
fundingResult: {
|
|
42
|
-
requestId: string;
|
|
43
|
-
status: string;
|
|
44
|
-
txHash?: string;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Parse the PAYMENT-REQUIRED header value (base64 JSON).
|
|
49
|
-
*
|
|
50
|
-
* The x402 spec encodes the payment requirements as a base64-encoded JSON
|
|
51
|
-
* string in the response header.
|
|
52
|
-
*/
|
|
53
|
-
export declare function parsePaymentRequired(headerValue: string): X402PaymentRequired;
|
|
54
|
-
/**
|
|
55
|
-
* Parse a CAIP-2 network identifier to a numeric chain ID.
|
|
56
|
-
*
|
|
57
|
-
* @example parseChainId("eip155:8453") // → 8453
|
|
58
|
-
* @example parseChainId("eip155:84532") // → 84532
|
|
59
|
-
*/
|
|
60
|
-
export declare function parseChainId(network: string): number;
|
|
61
|
-
/**
|
|
62
|
-
* Find a payment option matching the bot's chain ID.
|
|
63
|
-
*
|
|
64
|
-
* Prefers USDC options (EIP-3009 path — no gas needed from bot).
|
|
65
|
-
* Falls back to any matching chain option.
|
|
66
|
-
*
|
|
67
|
-
* @returns The best matching payment option, or null if none match.
|
|
68
|
-
*/
|
|
69
|
-
export declare function findMatchingOption(accepts: X402PaymentOption[], chainId: number): X402PaymentOption | null;
|
|
70
|
-
/**
|
|
71
|
-
* Extract metadata fields from a parsed x402 header for payment enrichment.
|
|
72
|
-
*
|
|
73
|
-
* These fields flow into the Axon payment record, giving vault owners
|
|
74
|
-
* full visibility into what their bots are accessing.
|
|
75
|
-
*/
|
|
76
|
-
export declare function extractX402Metadata(parsed: X402PaymentRequired, selectedOption: X402PaymentOption): {
|
|
77
|
-
resourceUrl: string;
|
|
78
|
-
memo: string | null;
|
|
79
|
-
recipientLabel: string | null;
|
|
80
|
-
metadata: Record<string, string>;
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Format a payment signature payload for the PAYMENT-SIGNATURE header.
|
|
84
|
-
*
|
|
85
|
-
* The x402 spec requires the header value to be base64-encoded JSON.
|
|
86
|
-
*/
|
|
87
|
-
export declare function formatPaymentSignature(payload: Record<string, unknown>): string;
|
|
88
|
-
//# sourceMappingURL=x402.d.ts.map
|
package/dist/x402.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../src/x402.ts"],"names":[],"mappings":"AAOA,iEAAiE;AACjE,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wDAAwD;AACxD,MAAM,WAAW,iBAAiB;IAChC,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,6CAA6C;AAC7C,MAAM,WAAW,mBAAmB;IAClC,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,QAAQ,EAAE,YAAY,CAAC;IACvB,gCAAgC;IAChC,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAED,yFAAyF;AACzF,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,gBAAgB,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,cAAc,EAAE,iBAAiB,CAAC;IAClC,qDAAqD;IACrD,aAAa,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA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