@exagent/sdk 0.1.12 → 0.1.14
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.d.mts +577 -38
- package/dist/index.d.ts +577 -38
- package/dist/index.js +75 -134
- package/dist/index.mjs +75 -135
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25,6 +25,8 @@ __export(index_exports, {
|
|
|
25
25
|
DEFAULT_RPC_URL: () => DEFAULT_RPC_URL,
|
|
26
26
|
DEX_ADDRESSES: () => DEX_ADDRESSES,
|
|
27
27
|
EXAGENT_API_CONFIG: () => EXAGENT_API_CONFIG,
|
|
28
|
+
EXAGENT_REGISTRY_ABI: () => EXAGENT_REGISTRY_ABI,
|
|
29
|
+
EXAGENT_ROUTER_ABI: () => EXAGENT_ROUTER_ABI,
|
|
28
30
|
EXAGENT_STAKING_ABI: () => EXAGENT_STAKING_ABI,
|
|
29
31
|
EXAGENT_VAULT_FACTORY_ABI: () => EXAGENT_VAULT_FACTORY_ABI,
|
|
30
32
|
ExagentClient: () => ExagentClient,
|
|
@@ -154,13 +156,6 @@ var EXAGENT_REGISTRY_ABI = [
|
|
|
154
156
|
outputs: [{ name: "", type: "uint256" }],
|
|
155
157
|
stateMutability: "view"
|
|
156
158
|
},
|
|
157
|
-
{
|
|
158
|
-
type: "function",
|
|
159
|
-
name: "nextAgentId",
|
|
160
|
-
inputs: [],
|
|
161
|
-
outputs: [{ name: "", type: "uint256" }],
|
|
162
|
-
stateMutability: "view"
|
|
163
|
-
},
|
|
164
159
|
{
|
|
165
160
|
type: "function",
|
|
166
161
|
name: "ownerOf",
|
|
@@ -226,13 +221,6 @@ var EXAGENT_REGISTRY_ABI = [
|
|
|
226
221
|
],
|
|
227
222
|
stateMutability: "view"
|
|
228
223
|
},
|
|
229
|
-
{
|
|
230
|
-
type: "function",
|
|
231
|
-
name: "version",
|
|
232
|
-
inputs: [],
|
|
233
|
-
outputs: [{ name: "", type: "string" }],
|
|
234
|
-
stateMutability: "pure"
|
|
235
|
-
},
|
|
236
224
|
// Config Epochs
|
|
237
225
|
{
|
|
238
226
|
type: "function",
|
|
@@ -251,40 +239,6 @@ var EXAGENT_REGISTRY_ABI = [
|
|
|
251
239
|
outputs: [{ name: "", type: "bytes32" }],
|
|
252
240
|
stateMutability: "view"
|
|
253
241
|
},
|
|
254
|
-
{
|
|
255
|
-
type: "function",
|
|
256
|
-
name: "getCurrentEpoch",
|
|
257
|
-
inputs: [{ name: "agentId", type: "uint256" }],
|
|
258
|
-
outputs: [{ name: "", type: "uint256" }],
|
|
259
|
-
stateMutability: "view"
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
type: "function",
|
|
263
|
-
name: "getAgentConfig",
|
|
264
|
-
inputs: [{ name: "agentId", type: "uint256" }],
|
|
265
|
-
outputs: [
|
|
266
|
-
{
|
|
267
|
-
name: "",
|
|
268
|
-
type: "tuple",
|
|
269
|
-
components: [
|
|
270
|
-
{ name: "configHash", type: "bytes32" },
|
|
271
|
-
{ name: "epochId", type: "uint256" },
|
|
272
|
-
{ name: "epochStartBlock", type: "uint256" }
|
|
273
|
-
]
|
|
274
|
-
}
|
|
275
|
-
],
|
|
276
|
-
stateMutability: "view"
|
|
277
|
-
},
|
|
278
|
-
{
|
|
279
|
-
type: "function",
|
|
280
|
-
name: "getEpochConfigHash",
|
|
281
|
-
inputs: [
|
|
282
|
-
{ name: "agentId", type: "uint256" },
|
|
283
|
-
{ name: "epochId", type: "uint256" }
|
|
284
|
-
],
|
|
285
|
-
outputs: [{ name: "", type: "bytes32" }],
|
|
286
|
-
stateMutability: "view"
|
|
287
|
-
},
|
|
288
242
|
// Mainnet: Agent retirement
|
|
289
243
|
{
|
|
290
244
|
type: "function",
|
|
@@ -352,15 +306,23 @@ var EXAGENT_REGISTRY_ABI = [
|
|
|
352
306
|
{ name: "blockNumber", type: "uint256", indexed: false }
|
|
353
307
|
]
|
|
354
308
|
},
|
|
355
|
-
// Custom errors
|
|
356
|
-
{ type: "error", name: "
|
|
309
|
+
// Custom errors — must match ExagentRegistry.sol for viem to decode reverts
|
|
310
|
+
{ type: "error", name: "AgentNotOwner", inputs: [] },
|
|
311
|
+
{ type: "error", name: "WalletAlreadyLinked", inputs: [] },
|
|
312
|
+
{ type: "error", name: "WalletNotLinked", inputs: [] },
|
|
313
|
+
{ type: "error", name: "InvalidSignature", inputs: [] },
|
|
314
|
+
{ type: "error", name: "TransferDisabled", inputs: [] },
|
|
357
315
|
{ type: "error", name: "InvalidMetadataURI", inputs: [] },
|
|
316
|
+
{ type: "error", name: "AgentDoesNotExist", inputs: [] },
|
|
317
|
+
{ type: "error", name: "NameAlreadyTaken", inputs: [] },
|
|
358
318
|
{ type: "error", name: "InvalidName", inputs: [] },
|
|
319
|
+
{ type: "error", name: "OwnerAlreadyHasAgent", inputs: [{ name: "existingAgentId", type: "uint256" }] },
|
|
359
320
|
{ type: "error", name: "InvalidRiskUniverse", inputs: [] },
|
|
360
321
|
{ type: "error", name: "InvalidTradingConfig", inputs: [] },
|
|
361
|
-
{ type: "error", name: "
|
|
362
|
-
{ type: "error", name: "
|
|
363
|
-
{ type: "error", name: "AgentIsRetired", inputs: [] }
|
|
322
|
+
{ type: "error", name: "NotAuthorizedCaller", inputs: [] },
|
|
323
|
+
{ type: "error", name: "MetadataValueTooLarge", inputs: [] },
|
|
324
|
+
{ type: "error", name: "AgentIsRetired", inputs: [] },
|
|
325
|
+
{ type: "error", name: "InvalidRiskUniverseForWhitelist", inputs: [] }
|
|
364
326
|
];
|
|
365
327
|
var ExagentRegistry = class {
|
|
366
328
|
address;
|
|
@@ -572,18 +534,6 @@ var ExagentRegistry = class {
|
|
|
572
534
|
});
|
|
573
535
|
return nonce;
|
|
574
536
|
}
|
|
575
|
-
/**
|
|
576
|
-
* Get the next agent ID that will be assigned
|
|
577
|
-
* @returns Next agent ID
|
|
578
|
-
*/
|
|
579
|
-
async getNextAgentId() {
|
|
580
|
-
const nextId = await this.publicClient.readContract({
|
|
581
|
-
address: this.address,
|
|
582
|
-
abi: EXAGENT_REGISTRY_ABI,
|
|
583
|
-
functionName: "nextAgentId"
|
|
584
|
-
});
|
|
585
|
-
return nextId;
|
|
586
|
-
}
|
|
587
537
|
/**
|
|
588
538
|
* Generate the message hash for wallet linking.
|
|
589
539
|
* Matches the contract's keccak256(abi.encodePacked(...)) exactly.
|
|
@@ -629,18 +579,6 @@ var ExagentRegistry = class {
|
|
|
629
579
|
const [canRegister, existingAgentId] = result;
|
|
630
580
|
return { canRegister, existingAgentId };
|
|
631
581
|
}
|
|
632
|
-
/**
|
|
633
|
-
* Get the registry contract version
|
|
634
|
-
* @returns Version string (e.g., "4.0.0")
|
|
635
|
-
*/
|
|
636
|
-
async getVersion() {
|
|
637
|
-
const version = await this.publicClient.readContract({
|
|
638
|
-
address: this.address,
|
|
639
|
-
abi: EXAGENT_REGISTRY_ABI,
|
|
640
|
-
functionName: "version"
|
|
641
|
-
});
|
|
642
|
-
return version;
|
|
643
|
-
}
|
|
644
582
|
// ============ Config Epochs ============
|
|
645
583
|
/**
|
|
646
584
|
* Update the agent's LLM config hash on-chain
|
|
@@ -674,54 +612,6 @@ var ExagentRegistry = class {
|
|
|
674
612
|
});
|
|
675
613
|
return configHash;
|
|
676
614
|
}
|
|
677
|
-
/**
|
|
678
|
-
* Get the current epoch ID for an agent
|
|
679
|
-
* @param agentId The agent's ID
|
|
680
|
-
* @returns Current epoch (0 if never configured)
|
|
681
|
-
*/
|
|
682
|
-
async getCurrentEpoch(agentId) {
|
|
683
|
-
const epochId = await this.publicClient.readContract({
|
|
684
|
-
address: this.address,
|
|
685
|
-
abi: EXAGENT_REGISTRY_ABI,
|
|
686
|
-
functionName: "getCurrentEpoch",
|
|
687
|
-
args: [agentId]
|
|
688
|
-
});
|
|
689
|
-
return epochId;
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* Get full config info for an agent
|
|
693
|
-
* @param agentId The agent's ID
|
|
694
|
-
* @returns AgentConfig struct (configHash, epochId, epochStartBlock)
|
|
695
|
-
*/
|
|
696
|
-
async getAgentConfig(agentId) {
|
|
697
|
-
const config = await this.publicClient.readContract({
|
|
698
|
-
address: this.address,
|
|
699
|
-
abi: EXAGENT_REGISTRY_ABI,
|
|
700
|
-
functionName: "getAgentConfig",
|
|
701
|
-
args: [agentId]
|
|
702
|
-
});
|
|
703
|
-
const result = config;
|
|
704
|
-
return {
|
|
705
|
-
configHash: result.configHash,
|
|
706
|
-
epochId: result.epochId,
|
|
707
|
-
epochStartBlock: result.epochStartBlock
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
/**
|
|
711
|
-
* Get the config hash for a specific epoch
|
|
712
|
-
* @param agentId The agent's ID
|
|
713
|
-
* @param epochId The epoch to look up
|
|
714
|
-
* @returns Config hash for that epoch
|
|
715
|
-
*/
|
|
716
|
-
async getEpochConfigHash(agentId, epochId) {
|
|
717
|
-
const configHash = await this.publicClient.readContract({
|
|
718
|
-
address: this.address,
|
|
719
|
-
abi: EXAGENT_REGISTRY_ABI,
|
|
720
|
-
functionName: "getEpochConfigHash",
|
|
721
|
-
args: [agentId, epochId]
|
|
722
|
-
});
|
|
723
|
-
return configHash;
|
|
724
|
-
}
|
|
725
615
|
/**
|
|
726
616
|
* Calculate the config hash for a provider and model
|
|
727
617
|
* @param provider The LLM provider name (e.g., "openai", "anthropic")
|
|
@@ -810,6 +700,27 @@ var ExagentRegistry = class {
|
|
|
810
700
|
}
|
|
811
701
|
};
|
|
812
702
|
|
|
703
|
+
// src/contracts/router.ts
|
|
704
|
+
var EXAGENT_ROUTER_ABI = [
|
|
705
|
+
// Custom errors — must match ExagentRouterV2.sol for viem to decode reverts
|
|
706
|
+
{ type: "error", name: "InvalidAgentId", inputs: [] },
|
|
707
|
+
{ type: "error", name: "SwapFailed", inputs: [] },
|
|
708
|
+
{ type: "error", name: "InsufficientOutput", inputs: [] },
|
|
709
|
+
{ type: "error", name: "ZeroAddress", inputs: [] },
|
|
710
|
+
{ type: "error", name: "ZeroAmount", inputs: [] },
|
|
711
|
+
{ type: "error", name: "AggregatorNotWhitelisted", inputs: [] },
|
|
712
|
+
{ type: "error", name: "ETHTransferFailed", inputs: [] },
|
|
713
|
+
{ type: "error", name: "FeeBpsTooHigh", inputs: [] },
|
|
714
|
+
{ type: "error", name: "NotAuthorizedForAgent", inputs: [{ name: "agentId", type: "uint256" }, { name: "caller", type: "address" }] },
|
|
715
|
+
{ type: "error", name: "ConfigMismatch", inputs: [{ name: "provided", type: "bytes32" }, { name: "onChain", type: "bytes32" }] },
|
|
716
|
+
{ type: "error", name: "MsgValueMismatch", inputs: [] },
|
|
717
|
+
{ type: "error", name: "FeeCollectorNotSet", inputs: [] },
|
|
718
|
+
{ type: "error", name: "TokenNotAllowedForAgent", inputs: [{ name: "agentId", type: "uint256" }, { name: "token", type: "address" }] },
|
|
719
|
+
{ type: "error", name: "NotAuthorized", inputs: [] },
|
|
720
|
+
{ type: "error", name: "RiskUniverseTooLow", inputs: [{ name: "agentId", type: "uint256" }, { name: "riskUniverse", type: "uint256" }] },
|
|
721
|
+
{ type: "error", name: "FillAlreadyProcessed", inputs: [{ name: "fillId", type: "bytes32" }] }
|
|
722
|
+
];
|
|
723
|
+
|
|
813
724
|
// src/contracts/vault.ts
|
|
814
725
|
var EXAGENT_VAULT_ABI = [
|
|
815
726
|
// ERC-4626 Standard
|
|
@@ -2105,8 +2016,8 @@ var ExagentStaking = class {
|
|
|
2105
2016
|
|
|
2106
2017
|
// src/constants.ts
|
|
2107
2018
|
var import_chains = require("viem/chains");
|
|
2108
|
-
var SDK_VERSION = "0.1.
|
|
2109
|
-
var DEFAULT_RPC_URL = "https://base
|
|
2019
|
+
var SDK_VERSION = "0.1.14";
|
|
2020
|
+
var DEFAULT_RPC_URL = "https://mainnet.base.org";
|
|
2110
2021
|
function getRpcUrl() {
|
|
2111
2022
|
if (typeof process !== "undefined" && process.env) {
|
|
2112
2023
|
return process.env.BASE_RPC_URL || process.env.EXAGENT_RPC_URL || DEFAULT_RPC_URL;
|
|
@@ -2120,7 +2031,7 @@ var CONTRACT_ADDRESSES = {
|
|
|
2120
2031
|
mainnet: {
|
|
2121
2032
|
agentRegistry: "0x2261706C751F8ac5cdDb481B7b56EA2137d4A723",
|
|
2122
2033
|
exaToken: "0x13403Fb738C97cF7564F279288468c140AaEd05c",
|
|
2123
|
-
staking: "
|
|
2034
|
+
staking: "0xe925727B21f1B86008f291E8f3102345A57B6c17",
|
|
2124
2035
|
router: "0x1BCFa13f677fDCf697D8b7d5120f544817F1de1A",
|
|
2125
2036
|
vaultFactory: "0x5b90C7F9F02F9130a92481360E9aa5Be4fcc9500",
|
|
2126
2037
|
feeCollector: "0xe66328a964AF93bEF2eDB226D039C35aE6e66De1",
|
|
@@ -2201,9 +2112,10 @@ var ExagentClient = class {
|
|
|
2201
2112
|
validateContractAddresses(this.network);
|
|
2202
2113
|
const chain = CHAIN_CONFIG[this.network];
|
|
2203
2114
|
const rpcUrl = config.rpcUrl || getRpcUrl();
|
|
2115
|
+
const transport = (0, import_viem2.http)(rpcUrl, { timeout: 6e4 });
|
|
2204
2116
|
this.publicClient = (0, import_viem2.createPublicClient)({
|
|
2205
2117
|
chain,
|
|
2206
|
-
transport
|
|
2118
|
+
transport
|
|
2207
2119
|
});
|
|
2208
2120
|
if (config.walletClient) {
|
|
2209
2121
|
this.walletClient = config.walletClient;
|
|
@@ -2213,7 +2125,7 @@ var ExagentClient = class {
|
|
|
2213
2125
|
this.walletClient = (0, import_viem2.createWalletClient)({
|
|
2214
2126
|
account: this.account,
|
|
2215
2127
|
chain,
|
|
2216
|
-
transport
|
|
2128
|
+
transport
|
|
2217
2129
|
});
|
|
2218
2130
|
} else {
|
|
2219
2131
|
throw new Error("Either privateKey or walletClient must be provided");
|
|
@@ -2265,7 +2177,8 @@ var ExagentClient = class {
|
|
|
2265
2177
|
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
2266
2178
|
const agentId = this.parseAgentIdFromReceipt(receipt);
|
|
2267
2179
|
this._agentId = agentId;
|
|
2268
|
-
await this.registry.linkOwnWallet(agentId);
|
|
2180
|
+
const linkHash = await this.registry.linkOwnWallet(agentId);
|
|
2181
|
+
await this.publicClient.waitForTransactionReceipt({ hash: linkHash });
|
|
2269
2182
|
return agentId;
|
|
2270
2183
|
}
|
|
2271
2184
|
/**
|
|
@@ -2294,6 +2207,11 @@ var ExagentClient = class {
|
|
|
2294
2207
|
this._agentId = agentId;
|
|
2295
2208
|
return agentId;
|
|
2296
2209
|
}
|
|
2210
|
+
const ownedAgentId = await this.registry.getAgentByOwner(this.account.address);
|
|
2211
|
+
if (ownedAgentId > 0n) {
|
|
2212
|
+
this._agentId = ownedAgentId;
|
|
2213
|
+
return ownedAgentId;
|
|
2214
|
+
}
|
|
2297
2215
|
return void 0;
|
|
2298
2216
|
}
|
|
2299
2217
|
/**
|
|
@@ -2389,7 +2307,20 @@ var ExagentClient = class {
|
|
|
2389
2307
|
value: BigInt(routerTrade.transaction.value)
|
|
2390
2308
|
});
|
|
2391
2309
|
txParams.gas = estimated * 150n / 100n;
|
|
2392
|
-
} catch {
|
|
2310
|
+
} catch (err) {
|
|
2311
|
+
const errorData = err?.data;
|
|
2312
|
+
if (errorData && errorData.length > 2) {
|
|
2313
|
+
try {
|
|
2314
|
+
const decoded = (0, import_viem2.decodeErrorResult)({
|
|
2315
|
+
abi: [...EXAGENT_ROUTER_ABI, ...EXAGENT_REGISTRY_ABI],
|
|
2316
|
+
data: errorData
|
|
2317
|
+
});
|
|
2318
|
+
throw new Error(`Trade will revert: ${decoded.errorName}${decoded.args ? ` (${decoded.args.join(", ")})` : ""}`);
|
|
2319
|
+
} catch (decodeErr) {
|
|
2320
|
+
if (decodeErr instanceof Error && decodeErr.message.startsWith("Trade will revert:")) throw decodeErr;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
throw new Error(`Trade will revert: gas estimation failed. ${err?.message || "Unknown reason"}`);
|
|
2393
2324
|
}
|
|
2394
2325
|
const hash = await this.walletClient.sendTransaction(txParams);
|
|
2395
2326
|
return {
|
|
@@ -2409,6 +2340,13 @@ var ExagentClient = class {
|
|
|
2409
2340
|
const id = agentId ?? await this.getAgentId();
|
|
2410
2341
|
if (!id) throw new Error("Agent not registered");
|
|
2411
2342
|
const apiUrl = EXAGENT_API_CONFIG[this.network];
|
|
2343
|
+
let configHash = intent.configHash;
|
|
2344
|
+
if (!configHash) {
|
|
2345
|
+
const onChainHash = await this.registry.getConfigHash(id);
|
|
2346
|
+
if (onChainHash && onChainHash !== "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
2347
|
+
configHash = onChainHash;
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2412
2350
|
const response = await fetch(`${apiUrl}/v1/router/trade`, {
|
|
2413
2351
|
method: "POST",
|
|
2414
2352
|
headers: this.apiHeaders("application/json"),
|
|
@@ -2419,7 +2357,7 @@ var ExagentClient = class {
|
|
|
2419
2357
|
amountIn: intent.amountIn.toString(),
|
|
2420
2358
|
slippageBps: intent.maxSlippageBps ?? 50,
|
|
2421
2359
|
taker: this.account.address,
|
|
2422
|
-
...
|
|
2360
|
+
...configHash && { configHash }
|
|
2423
2361
|
})
|
|
2424
2362
|
});
|
|
2425
2363
|
if (!response.ok) {
|
|
@@ -2512,7 +2450,8 @@ var ExagentClient = class {
|
|
|
2512
2450
|
const response = await fetch(`${apiUrl}/v1/rankings/leaderboard?${params}`, {
|
|
2513
2451
|
headers: this.apiHeaders()
|
|
2514
2452
|
});
|
|
2515
|
-
|
|
2453
|
+
const data = await response.json();
|
|
2454
|
+
return data.agents ?? [];
|
|
2516
2455
|
}
|
|
2517
2456
|
// ============ Vault Functions (Phase 4: Copy Trading) ============
|
|
2518
2457
|
/**
|
|
@@ -3107,6 +3046,8 @@ var ExagentVaultFactory = class {
|
|
|
3107
3046
|
DEFAULT_RPC_URL,
|
|
3108
3047
|
DEX_ADDRESSES,
|
|
3109
3048
|
EXAGENT_API_CONFIG,
|
|
3049
|
+
EXAGENT_REGISTRY_ABI,
|
|
3050
|
+
EXAGENT_ROUTER_ABI,
|
|
3110
3051
|
EXAGENT_STAKING_ABI,
|
|
3111
3052
|
EXAGENT_VAULT_FACTORY_ABI,
|
|
3112
3053
|
ExagentClient,
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import {
|
|
3
3
|
createPublicClient,
|
|
4
4
|
createWalletClient,
|
|
5
|
-
http
|
|
5
|
+
http,
|
|
6
|
+
decodeErrorResult
|
|
6
7
|
} from "viem";
|
|
7
8
|
import { privateKeyToAccount } from "viem/accounts";
|
|
8
9
|
|
|
@@ -119,13 +120,6 @@ var EXAGENT_REGISTRY_ABI = [
|
|
|
119
120
|
outputs: [{ name: "", type: "uint256" }],
|
|
120
121
|
stateMutability: "view"
|
|
121
122
|
},
|
|
122
|
-
{
|
|
123
|
-
type: "function",
|
|
124
|
-
name: "nextAgentId",
|
|
125
|
-
inputs: [],
|
|
126
|
-
outputs: [{ name: "", type: "uint256" }],
|
|
127
|
-
stateMutability: "view"
|
|
128
|
-
},
|
|
129
123
|
{
|
|
130
124
|
type: "function",
|
|
131
125
|
name: "ownerOf",
|
|
@@ -191,13 +185,6 @@ var EXAGENT_REGISTRY_ABI = [
|
|
|
191
185
|
],
|
|
192
186
|
stateMutability: "view"
|
|
193
187
|
},
|
|
194
|
-
{
|
|
195
|
-
type: "function",
|
|
196
|
-
name: "version",
|
|
197
|
-
inputs: [],
|
|
198
|
-
outputs: [{ name: "", type: "string" }],
|
|
199
|
-
stateMutability: "pure"
|
|
200
|
-
},
|
|
201
188
|
// Config Epochs
|
|
202
189
|
{
|
|
203
190
|
type: "function",
|
|
@@ -216,40 +203,6 @@ var EXAGENT_REGISTRY_ABI = [
|
|
|
216
203
|
outputs: [{ name: "", type: "bytes32" }],
|
|
217
204
|
stateMutability: "view"
|
|
218
205
|
},
|
|
219
|
-
{
|
|
220
|
-
type: "function",
|
|
221
|
-
name: "getCurrentEpoch",
|
|
222
|
-
inputs: [{ name: "agentId", type: "uint256" }],
|
|
223
|
-
outputs: [{ name: "", type: "uint256" }],
|
|
224
|
-
stateMutability: "view"
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
type: "function",
|
|
228
|
-
name: "getAgentConfig",
|
|
229
|
-
inputs: [{ name: "agentId", type: "uint256" }],
|
|
230
|
-
outputs: [
|
|
231
|
-
{
|
|
232
|
-
name: "",
|
|
233
|
-
type: "tuple",
|
|
234
|
-
components: [
|
|
235
|
-
{ name: "configHash", type: "bytes32" },
|
|
236
|
-
{ name: "epochId", type: "uint256" },
|
|
237
|
-
{ name: "epochStartBlock", type: "uint256" }
|
|
238
|
-
]
|
|
239
|
-
}
|
|
240
|
-
],
|
|
241
|
-
stateMutability: "view"
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
type: "function",
|
|
245
|
-
name: "getEpochConfigHash",
|
|
246
|
-
inputs: [
|
|
247
|
-
{ name: "agentId", type: "uint256" },
|
|
248
|
-
{ name: "epochId", type: "uint256" }
|
|
249
|
-
],
|
|
250
|
-
outputs: [{ name: "", type: "bytes32" }],
|
|
251
|
-
stateMutability: "view"
|
|
252
|
-
},
|
|
253
206
|
// Mainnet: Agent retirement
|
|
254
207
|
{
|
|
255
208
|
type: "function",
|
|
@@ -317,15 +270,23 @@ var EXAGENT_REGISTRY_ABI = [
|
|
|
317
270
|
{ name: "blockNumber", type: "uint256", indexed: false }
|
|
318
271
|
]
|
|
319
272
|
},
|
|
320
|
-
// Custom errors
|
|
321
|
-
{ type: "error", name: "
|
|
273
|
+
// Custom errors — must match ExagentRegistry.sol for viem to decode reverts
|
|
274
|
+
{ type: "error", name: "AgentNotOwner", inputs: [] },
|
|
275
|
+
{ type: "error", name: "WalletAlreadyLinked", inputs: [] },
|
|
276
|
+
{ type: "error", name: "WalletNotLinked", inputs: [] },
|
|
277
|
+
{ type: "error", name: "InvalidSignature", inputs: [] },
|
|
278
|
+
{ type: "error", name: "TransferDisabled", inputs: [] },
|
|
322
279
|
{ type: "error", name: "InvalidMetadataURI", inputs: [] },
|
|
280
|
+
{ type: "error", name: "AgentDoesNotExist", inputs: [] },
|
|
281
|
+
{ type: "error", name: "NameAlreadyTaken", inputs: [] },
|
|
323
282
|
{ type: "error", name: "InvalidName", inputs: [] },
|
|
283
|
+
{ type: "error", name: "OwnerAlreadyHasAgent", inputs: [{ name: "existingAgentId", type: "uint256" }] },
|
|
324
284
|
{ type: "error", name: "InvalidRiskUniverse", inputs: [] },
|
|
325
285
|
{ type: "error", name: "InvalidTradingConfig", inputs: [] },
|
|
326
|
-
{ type: "error", name: "
|
|
327
|
-
{ type: "error", name: "
|
|
328
|
-
{ type: "error", name: "AgentIsRetired", inputs: [] }
|
|
286
|
+
{ type: "error", name: "NotAuthorizedCaller", inputs: [] },
|
|
287
|
+
{ type: "error", name: "MetadataValueTooLarge", inputs: [] },
|
|
288
|
+
{ type: "error", name: "AgentIsRetired", inputs: [] },
|
|
289
|
+
{ type: "error", name: "InvalidRiskUniverseForWhitelist", inputs: [] }
|
|
329
290
|
];
|
|
330
291
|
var ExagentRegistry = class {
|
|
331
292
|
address;
|
|
@@ -537,18 +498,6 @@ var ExagentRegistry = class {
|
|
|
537
498
|
});
|
|
538
499
|
return nonce;
|
|
539
500
|
}
|
|
540
|
-
/**
|
|
541
|
-
* Get the next agent ID that will be assigned
|
|
542
|
-
* @returns Next agent ID
|
|
543
|
-
*/
|
|
544
|
-
async getNextAgentId() {
|
|
545
|
-
const nextId = await this.publicClient.readContract({
|
|
546
|
-
address: this.address,
|
|
547
|
-
abi: EXAGENT_REGISTRY_ABI,
|
|
548
|
-
functionName: "nextAgentId"
|
|
549
|
-
});
|
|
550
|
-
return nextId;
|
|
551
|
-
}
|
|
552
501
|
/**
|
|
553
502
|
* Generate the message hash for wallet linking.
|
|
554
503
|
* Matches the contract's keccak256(abi.encodePacked(...)) exactly.
|
|
@@ -594,18 +543,6 @@ var ExagentRegistry = class {
|
|
|
594
543
|
const [canRegister, existingAgentId] = result;
|
|
595
544
|
return { canRegister, existingAgentId };
|
|
596
545
|
}
|
|
597
|
-
/**
|
|
598
|
-
* Get the registry contract version
|
|
599
|
-
* @returns Version string (e.g., "4.0.0")
|
|
600
|
-
*/
|
|
601
|
-
async getVersion() {
|
|
602
|
-
const version = await this.publicClient.readContract({
|
|
603
|
-
address: this.address,
|
|
604
|
-
abi: EXAGENT_REGISTRY_ABI,
|
|
605
|
-
functionName: "version"
|
|
606
|
-
});
|
|
607
|
-
return version;
|
|
608
|
-
}
|
|
609
546
|
// ============ Config Epochs ============
|
|
610
547
|
/**
|
|
611
548
|
* Update the agent's LLM config hash on-chain
|
|
@@ -639,54 +576,6 @@ var ExagentRegistry = class {
|
|
|
639
576
|
});
|
|
640
577
|
return configHash;
|
|
641
578
|
}
|
|
642
|
-
/**
|
|
643
|
-
* Get the current epoch ID for an agent
|
|
644
|
-
* @param agentId The agent's ID
|
|
645
|
-
* @returns Current epoch (0 if never configured)
|
|
646
|
-
*/
|
|
647
|
-
async getCurrentEpoch(agentId) {
|
|
648
|
-
const epochId = await this.publicClient.readContract({
|
|
649
|
-
address: this.address,
|
|
650
|
-
abi: EXAGENT_REGISTRY_ABI,
|
|
651
|
-
functionName: "getCurrentEpoch",
|
|
652
|
-
args: [agentId]
|
|
653
|
-
});
|
|
654
|
-
return epochId;
|
|
655
|
-
}
|
|
656
|
-
/**
|
|
657
|
-
* Get full config info for an agent
|
|
658
|
-
* @param agentId The agent's ID
|
|
659
|
-
* @returns AgentConfig struct (configHash, epochId, epochStartBlock)
|
|
660
|
-
*/
|
|
661
|
-
async getAgentConfig(agentId) {
|
|
662
|
-
const config = await this.publicClient.readContract({
|
|
663
|
-
address: this.address,
|
|
664
|
-
abi: EXAGENT_REGISTRY_ABI,
|
|
665
|
-
functionName: "getAgentConfig",
|
|
666
|
-
args: [agentId]
|
|
667
|
-
});
|
|
668
|
-
const result = config;
|
|
669
|
-
return {
|
|
670
|
-
configHash: result.configHash,
|
|
671
|
-
epochId: result.epochId,
|
|
672
|
-
epochStartBlock: result.epochStartBlock
|
|
673
|
-
};
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Get the config hash for a specific epoch
|
|
677
|
-
* @param agentId The agent's ID
|
|
678
|
-
* @param epochId The epoch to look up
|
|
679
|
-
* @returns Config hash for that epoch
|
|
680
|
-
*/
|
|
681
|
-
async getEpochConfigHash(agentId, epochId) {
|
|
682
|
-
const configHash = await this.publicClient.readContract({
|
|
683
|
-
address: this.address,
|
|
684
|
-
abi: EXAGENT_REGISTRY_ABI,
|
|
685
|
-
functionName: "getEpochConfigHash",
|
|
686
|
-
args: [agentId, epochId]
|
|
687
|
-
});
|
|
688
|
-
return configHash;
|
|
689
|
-
}
|
|
690
579
|
/**
|
|
691
580
|
* Calculate the config hash for a provider and model
|
|
692
581
|
* @param provider The LLM provider name (e.g., "openai", "anthropic")
|
|
@@ -775,6 +664,27 @@ var ExagentRegistry = class {
|
|
|
775
664
|
}
|
|
776
665
|
};
|
|
777
666
|
|
|
667
|
+
// src/contracts/router.ts
|
|
668
|
+
var EXAGENT_ROUTER_ABI = [
|
|
669
|
+
// Custom errors — must match ExagentRouterV2.sol for viem to decode reverts
|
|
670
|
+
{ type: "error", name: "InvalidAgentId", inputs: [] },
|
|
671
|
+
{ type: "error", name: "SwapFailed", inputs: [] },
|
|
672
|
+
{ type: "error", name: "InsufficientOutput", inputs: [] },
|
|
673
|
+
{ type: "error", name: "ZeroAddress", inputs: [] },
|
|
674
|
+
{ type: "error", name: "ZeroAmount", inputs: [] },
|
|
675
|
+
{ type: "error", name: "AggregatorNotWhitelisted", inputs: [] },
|
|
676
|
+
{ type: "error", name: "ETHTransferFailed", inputs: [] },
|
|
677
|
+
{ type: "error", name: "FeeBpsTooHigh", inputs: [] },
|
|
678
|
+
{ type: "error", name: "NotAuthorizedForAgent", inputs: [{ name: "agentId", type: "uint256" }, { name: "caller", type: "address" }] },
|
|
679
|
+
{ type: "error", name: "ConfigMismatch", inputs: [{ name: "provided", type: "bytes32" }, { name: "onChain", type: "bytes32" }] },
|
|
680
|
+
{ type: "error", name: "MsgValueMismatch", inputs: [] },
|
|
681
|
+
{ type: "error", name: "FeeCollectorNotSet", inputs: [] },
|
|
682
|
+
{ type: "error", name: "TokenNotAllowedForAgent", inputs: [{ name: "agentId", type: "uint256" }, { name: "token", type: "address" }] },
|
|
683
|
+
{ type: "error", name: "NotAuthorized", inputs: [] },
|
|
684
|
+
{ type: "error", name: "RiskUniverseTooLow", inputs: [{ name: "agentId", type: "uint256" }, { name: "riskUniverse", type: "uint256" }] },
|
|
685
|
+
{ type: "error", name: "FillAlreadyProcessed", inputs: [{ name: "fillId", type: "bytes32" }] }
|
|
686
|
+
];
|
|
687
|
+
|
|
778
688
|
// src/contracts/vault.ts
|
|
779
689
|
var EXAGENT_VAULT_ABI = [
|
|
780
690
|
// ERC-4626 Standard
|
|
@@ -2070,8 +1980,8 @@ var ExagentStaking = class {
|
|
|
2070
1980
|
|
|
2071
1981
|
// src/constants.ts
|
|
2072
1982
|
import { base } from "viem/chains";
|
|
2073
|
-
var SDK_VERSION = "0.1.
|
|
2074
|
-
var DEFAULT_RPC_URL = "https://base
|
|
1983
|
+
var SDK_VERSION = "0.1.14";
|
|
1984
|
+
var DEFAULT_RPC_URL = "https://mainnet.base.org";
|
|
2075
1985
|
function getRpcUrl() {
|
|
2076
1986
|
if (typeof process !== "undefined" && process.env) {
|
|
2077
1987
|
return process.env.BASE_RPC_URL || process.env.EXAGENT_RPC_URL || DEFAULT_RPC_URL;
|
|
@@ -2085,7 +1995,7 @@ var CONTRACT_ADDRESSES = {
|
|
|
2085
1995
|
mainnet: {
|
|
2086
1996
|
agentRegistry: "0x2261706C751F8ac5cdDb481B7b56EA2137d4A723",
|
|
2087
1997
|
exaToken: "0x13403Fb738C97cF7564F279288468c140AaEd05c",
|
|
2088
|
-
staking: "
|
|
1998
|
+
staking: "0xe925727B21f1B86008f291E8f3102345A57B6c17",
|
|
2089
1999
|
router: "0x1BCFa13f677fDCf697D8b7d5120f544817F1de1A",
|
|
2090
2000
|
vaultFactory: "0x5b90C7F9F02F9130a92481360E9aa5Be4fcc9500",
|
|
2091
2001
|
feeCollector: "0xe66328a964AF93bEF2eDB226D039C35aE6e66De1",
|
|
@@ -2166,9 +2076,10 @@ var ExagentClient = class {
|
|
|
2166
2076
|
validateContractAddresses(this.network);
|
|
2167
2077
|
const chain = CHAIN_CONFIG[this.network];
|
|
2168
2078
|
const rpcUrl = config.rpcUrl || getRpcUrl();
|
|
2079
|
+
const transport = http(rpcUrl, { timeout: 6e4 });
|
|
2169
2080
|
this.publicClient = createPublicClient({
|
|
2170
2081
|
chain,
|
|
2171
|
-
transport
|
|
2082
|
+
transport
|
|
2172
2083
|
});
|
|
2173
2084
|
if (config.walletClient) {
|
|
2174
2085
|
this.walletClient = config.walletClient;
|
|
@@ -2178,7 +2089,7 @@ var ExagentClient = class {
|
|
|
2178
2089
|
this.walletClient = createWalletClient({
|
|
2179
2090
|
account: this.account,
|
|
2180
2091
|
chain,
|
|
2181
|
-
transport
|
|
2092
|
+
transport
|
|
2182
2093
|
});
|
|
2183
2094
|
} else {
|
|
2184
2095
|
throw new Error("Either privateKey or walletClient must be provided");
|
|
@@ -2230,7 +2141,8 @@ var ExagentClient = class {
|
|
|
2230
2141
|
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
2231
2142
|
const agentId = this.parseAgentIdFromReceipt(receipt);
|
|
2232
2143
|
this._agentId = agentId;
|
|
2233
|
-
await this.registry.linkOwnWallet(agentId);
|
|
2144
|
+
const linkHash = await this.registry.linkOwnWallet(agentId);
|
|
2145
|
+
await this.publicClient.waitForTransactionReceipt({ hash: linkHash });
|
|
2234
2146
|
return agentId;
|
|
2235
2147
|
}
|
|
2236
2148
|
/**
|
|
@@ -2259,6 +2171,11 @@ var ExagentClient = class {
|
|
|
2259
2171
|
this._agentId = agentId;
|
|
2260
2172
|
return agentId;
|
|
2261
2173
|
}
|
|
2174
|
+
const ownedAgentId = await this.registry.getAgentByOwner(this.account.address);
|
|
2175
|
+
if (ownedAgentId > 0n) {
|
|
2176
|
+
this._agentId = ownedAgentId;
|
|
2177
|
+
return ownedAgentId;
|
|
2178
|
+
}
|
|
2262
2179
|
return void 0;
|
|
2263
2180
|
}
|
|
2264
2181
|
/**
|
|
@@ -2354,7 +2271,20 @@ var ExagentClient = class {
|
|
|
2354
2271
|
value: BigInt(routerTrade.transaction.value)
|
|
2355
2272
|
});
|
|
2356
2273
|
txParams.gas = estimated * 150n / 100n;
|
|
2357
|
-
} catch {
|
|
2274
|
+
} catch (err) {
|
|
2275
|
+
const errorData = err?.data;
|
|
2276
|
+
if (errorData && errorData.length > 2) {
|
|
2277
|
+
try {
|
|
2278
|
+
const decoded = decodeErrorResult({
|
|
2279
|
+
abi: [...EXAGENT_ROUTER_ABI, ...EXAGENT_REGISTRY_ABI],
|
|
2280
|
+
data: errorData
|
|
2281
|
+
});
|
|
2282
|
+
throw new Error(`Trade will revert: ${decoded.errorName}${decoded.args ? ` (${decoded.args.join(", ")})` : ""}`);
|
|
2283
|
+
} catch (decodeErr) {
|
|
2284
|
+
if (decodeErr instanceof Error && decodeErr.message.startsWith("Trade will revert:")) throw decodeErr;
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
throw new Error(`Trade will revert: gas estimation failed. ${err?.message || "Unknown reason"}`);
|
|
2358
2288
|
}
|
|
2359
2289
|
const hash = await this.walletClient.sendTransaction(txParams);
|
|
2360
2290
|
return {
|
|
@@ -2374,6 +2304,13 @@ var ExagentClient = class {
|
|
|
2374
2304
|
const id = agentId ?? await this.getAgentId();
|
|
2375
2305
|
if (!id) throw new Error("Agent not registered");
|
|
2376
2306
|
const apiUrl = EXAGENT_API_CONFIG[this.network];
|
|
2307
|
+
let configHash = intent.configHash;
|
|
2308
|
+
if (!configHash) {
|
|
2309
|
+
const onChainHash = await this.registry.getConfigHash(id);
|
|
2310
|
+
if (onChainHash && onChainHash !== "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
2311
|
+
configHash = onChainHash;
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2377
2314
|
const response = await fetch(`${apiUrl}/v1/router/trade`, {
|
|
2378
2315
|
method: "POST",
|
|
2379
2316
|
headers: this.apiHeaders("application/json"),
|
|
@@ -2384,7 +2321,7 @@ var ExagentClient = class {
|
|
|
2384
2321
|
amountIn: intent.amountIn.toString(),
|
|
2385
2322
|
slippageBps: intent.maxSlippageBps ?? 50,
|
|
2386
2323
|
taker: this.account.address,
|
|
2387
|
-
...
|
|
2324
|
+
...configHash && { configHash }
|
|
2388
2325
|
})
|
|
2389
2326
|
});
|
|
2390
2327
|
if (!response.ok) {
|
|
@@ -2477,7 +2414,8 @@ var ExagentClient = class {
|
|
|
2477
2414
|
const response = await fetch(`${apiUrl}/v1/rankings/leaderboard?${params}`, {
|
|
2478
2415
|
headers: this.apiHeaders()
|
|
2479
2416
|
});
|
|
2480
|
-
|
|
2417
|
+
const data = await response.json();
|
|
2418
|
+
return data.agents ?? [];
|
|
2481
2419
|
}
|
|
2482
2420
|
// ============ Vault Functions (Phase 4: Copy Trading) ============
|
|
2483
2421
|
/**
|
|
@@ -3071,6 +3009,8 @@ export {
|
|
|
3071
3009
|
DEFAULT_RPC_URL,
|
|
3072
3010
|
DEX_ADDRESSES,
|
|
3073
3011
|
EXAGENT_API_CONFIG,
|
|
3012
|
+
EXAGENT_REGISTRY_ABI,
|
|
3013
|
+
EXAGENT_ROUTER_ABI,
|
|
3074
3014
|
EXAGENT_STAKING_ABI,
|
|
3075
3015
|
EXAGENT_VAULT_FACTORY_ABI,
|
|
3076
3016
|
ExagentClient,
|