@exagent/sdk 0.1.12 → 0.1.13
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 +574 -35
- package/dist/index.d.ts +574 -35
- package/dist/index.js +71 -131
- package/dist/index.mjs +71 -132
- 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,7 +2016,7 @@ var ExagentStaking = class {
|
|
|
2105
2016
|
|
|
2106
2017
|
// src/constants.ts
|
|
2107
2018
|
var import_chains = require("viem/chains");
|
|
2108
|
-
var SDK_VERSION = "0.1.
|
|
2019
|
+
var SDK_VERSION = "0.1.13";
|
|
2109
2020
|
var DEFAULT_RPC_URL = "https://base-rpc.publicnode.com";
|
|
2110
2021
|
function getRpcUrl() {
|
|
2111
2022
|
if (typeof process !== "undefined" && process.env) {
|
|
@@ -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",
|
|
@@ -2265,7 +2176,8 @@ var ExagentClient = class {
|
|
|
2265
2176
|
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
2266
2177
|
const agentId = this.parseAgentIdFromReceipt(receipt);
|
|
2267
2178
|
this._agentId = agentId;
|
|
2268
|
-
await this.registry.linkOwnWallet(agentId);
|
|
2179
|
+
const linkHash = await this.registry.linkOwnWallet(agentId);
|
|
2180
|
+
await this.publicClient.waitForTransactionReceipt({ hash: linkHash });
|
|
2269
2181
|
return agentId;
|
|
2270
2182
|
}
|
|
2271
2183
|
/**
|
|
@@ -2294,6 +2206,11 @@ var ExagentClient = class {
|
|
|
2294
2206
|
this._agentId = agentId;
|
|
2295
2207
|
return agentId;
|
|
2296
2208
|
}
|
|
2209
|
+
const ownedAgentId = await this.registry.getAgentByOwner(this.account.address);
|
|
2210
|
+
if (ownedAgentId > 0n) {
|
|
2211
|
+
this._agentId = ownedAgentId;
|
|
2212
|
+
return ownedAgentId;
|
|
2213
|
+
}
|
|
2297
2214
|
return void 0;
|
|
2298
2215
|
}
|
|
2299
2216
|
/**
|
|
@@ -2389,7 +2306,20 @@ var ExagentClient = class {
|
|
|
2389
2306
|
value: BigInt(routerTrade.transaction.value)
|
|
2390
2307
|
});
|
|
2391
2308
|
txParams.gas = estimated * 150n / 100n;
|
|
2392
|
-
} catch {
|
|
2309
|
+
} catch (err) {
|
|
2310
|
+
const errorData = err?.data;
|
|
2311
|
+
if (errorData && errorData.length > 2) {
|
|
2312
|
+
try {
|
|
2313
|
+
const decoded = (0, import_viem2.decodeErrorResult)({
|
|
2314
|
+
abi: [...EXAGENT_ROUTER_ABI, ...EXAGENT_REGISTRY_ABI],
|
|
2315
|
+
data: errorData
|
|
2316
|
+
});
|
|
2317
|
+
throw new Error(`Trade will revert: ${decoded.errorName}${decoded.args ? ` (${decoded.args.join(", ")})` : ""}`);
|
|
2318
|
+
} catch (decodeErr) {
|
|
2319
|
+
if (decodeErr instanceof Error && decodeErr.message.startsWith("Trade will revert:")) throw decodeErr;
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
throw new Error(`Trade will revert: gas estimation failed. ${err?.message || "Unknown reason"}`);
|
|
2393
2323
|
}
|
|
2394
2324
|
const hash = await this.walletClient.sendTransaction(txParams);
|
|
2395
2325
|
return {
|
|
@@ -2409,6 +2339,13 @@ var ExagentClient = class {
|
|
|
2409
2339
|
const id = agentId ?? await this.getAgentId();
|
|
2410
2340
|
if (!id) throw new Error("Agent not registered");
|
|
2411
2341
|
const apiUrl = EXAGENT_API_CONFIG[this.network];
|
|
2342
|
+
let configHash = intent.configHash;
|
|
2343
|
+
if (!configHash) {
|
|
2344
|
+
const onChainHash = await this.registry.getConfigHash(id);
|
|
2345
|
+
if (onChainHash && onChainHash !== "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
2346
|
+
configHash = onChainHash;
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2412
2349
|
const response = await fetch(`${apiUrl}/v1/router/trade`, {
|
|
2413
2350
|
method: "POST",
|
|
2414
2351
|
headers: this.apiHeaders("application/json"),
|
|
@@ -2419,7 +2356,7 @@ var ExagentClient = class {
|
|
|
2419
2356
|
amountIn: intent.amountIn.toString(),
|
|
2420
2357
|
slippageBps: intent.maxSlippageBps ?? 50,
|
|
2421
2358
|
taker: this.account.address,
|
|
2422
|
-
...
|
|
2359
|
+
...configHash && { configHash }
|
|
2423
2360
|
})
|
|
2424
2361
|
});
|
|
2425
2362
|
if (!response.ok) {
|
|
@@ -2512,7 +2449,8 @@ var ExagentClient = class {
|
|
|
2512
2449
|
const response = await fetch(`${apiUrl}/v1/rankings/leaderboard?${params}`, {
|
|
2513
2450
|
headers: this.apiHeaders()
|
|
2514
2451
|
});
|
|
2515
|
-
|
|
2452
|
+
const data = await response.json();
|
|
2453
|
+
return data.agents ?? [];
|
|
2516
2454
|
}
|
|
2517
2455
|
// ============ Vault Functions (Phase 4: Copy Trading) ============
|
|
2518
2456
|
/**
|
|
@@ -3107,6 +3045,8 @@ var ExagentVaultFactory = class {
|
|
|
3107
3045
|
DEFAULT_RPC_URL,
|
|
3108
3046
|
DEX_ADDRESSES,
|
|
3109
3047
|
EXAGENT_API_CONFIG,
|
|
3048
|
+
EXAGENT_REGISTRY_ABI,
|
|
3049
|
+
EXAGENT_ROUTER_ABI,
|
|
3110
3050
|
EXAGENT_STAKING_ABI,
|
|
3111
3051
|
EXAGENT_VAULT_FACTORY_ABI,
|
|
3112
3052
|
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,7 +1980,7 @@ var ExagentStaking = class {
|
|
|
2070
1980
|
|
|
2071
1981
|
// src/constants.ts
|
|
2072
1982
|
import { base } from "viem/chains";
|
|
2073
|
-
var SDK_VERSION = "0.1.
|
|
1983
|
+
var SDK_VERSION = "0.1.13";
|
|
2074
1984
|
var DEFAULT_RPC_URL = "https://base-rpc.publicnode.com";
|
|
2075
1985
|
function getRpcUrl() {
|
|
2076
1986
|
if (typeof process !== "undefined" && process.env) {
|
|
@@ -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",
|
|
@@ -2230,7 +2140,8 @@ var ExagentClient = class {
|
|
|
2230
2140
|
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
2231
2141
|
const agentId = this.parseAgentIdFromReceipt(receipt);
|
|
2232
2142
|
this._agentId = agentId;
|
|
2233
|
-
await this.registry.linkOwnWallet(agentId);
|
|
2143
|
+
const linkHash = await this.registry.linkOwnWallet(agentId);
|
|
2144
|
+
await this.publicClient.waitForTransactionReceipt({ hash: linkHash });
|
|
2234
2145
|
return agentId;
|
|
2235
2146
|
}
|
|
2236
2147
|
/**
|
|
@@ -2259,6 +2170,11 @@ var ExagentClient = class {
|
|
|
2259
2170
|
this._agentId = agentId;
|
|
2260
2171
|
return agentId;
|
|
2261
2172
|
}
|
|
2173
|
+
const ownedAgentId = await this.registry.getAgentByOwner(this.account.address);
|
|
2174
|
+
if (ownedAgentId > 0n) {
|
|
2175
|
+
this._agentId = ownedAgentId;
|
|
2176
|
+
return ownedAgentId;
|
|
2177
|
+
}
|
|
2262
2178
|
return void 0;
|
|
2263
2179
|
}
|
|
2264
2180
|
/**
|
|
@@ -2354,7 +2270,20 @@ var ExagentClient = class {
|
|
|
2354
2270
|
value: BigInt(routerTrade.transaction.value)
|
|
2355
2271
|
});
|
|
2356
2272
|
txParams.gas = estimated * 150n / 100n;
|
|
2357
|
-
} catch {
|
|
2273
|
+
} catch (err) {
|
|
2274
|
+
const errorData = err?.data;
|
|
2275
|
+
if (errorData && errorData.length > 2) {
|
|
2276
|
+
try {
|
|
2277
|
+
const decoded = decodeErrorResult({
|
|
2278
|
+
abi: [...EXAGENT_ROUTER_ABI, ...EXAGENT_REGISTRY_ABI],
|
|
2279
|
+
data: errorData
|
|
2280
|
+
});
|
|
2281
|
+
throw new Error(`Trade will revert: ${decoded.errorName}${decoded.args ? ` (${decoded.args.join(", ")})` : ""}`);
|
|
2282
|
+
} catch (decodeErr) {
|
|
2283
|
+
if (decodeErr instanceof Error && decodeErr.message.startsWith("Trade will revert:")) throw decodeErr;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
throw new Error(`Trade will revert: gas estimation failed. ${err?.message || "Unknown reason"}`);
|
|
2358
2287
|
}
|
|
2359
2288
|
const hash = await this.walletClient.sendTransaction(txParams);
|
|
2360
2289
|
return {
|
|
@@ -2374,6 +2303,13 @@ var ExagentClient = class {
|
|
|
2374
2303
|
const id = agentId ?? await this.getAgentId();
|
|
2375
2304
|
if (!id) throw new Error("Agent not registered");
|
|
2376
2305
|
const apiUrl = EXAGENT_API_CONFIG[this.network];
|
|
2306
|
+
let configHash = intent.configHash;
|
|
2307
|
+
if (!configHash) {
|
|
2308
|
+
const onChainHash = await this.registry.getConfigHash(id);
|
|
2309
|
+
if (onChainHash && onChainHash !== "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
2310
|
+
configHash = onChainHash;
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2377
2313
|
const response = await fetch(`${apiUrl}/v1/router/trade`, {
|
|
2378
2314
|
method: "POST",
|
|
2379
2315
|
headers: this.apiHeaders("application/json"),
|
|
@@ -2384,7 +2320,7 @@ var ExagentClient = class {
|
|
|
2384
2320
|
amountIn: intent.amountIn.toString(),
|
|
2385
2321
|
slippageBps: intent.maxSlippageBps ?? 50,
|
|
2386
2322
|
taker: this.account.address,
|
|
2387
|
-
...
|
|
2323
|
+
...configHash && { configHash }
|
|
2388
2324
|
})
|
|
2389
2325
|
});
|
|
2390
2326
|
if (!response.ok) {
|
|
@@ -2477,7 +2413,8 @@ var ExagentClient = class {
|
|
|
2477
2413
|
const response = await fetch(`${apiUrl}/v1/rankings/leaderboard?${params}`, {
|
|
2478
2414
|
headers: this.apiHeaders()
|
|
2479
2415
|
});
|
|
2480
|
-
|
|
2416
|
+
const data = await response.json();
|
|
2417
|
+
return data.agents ?? [];
|
|
2481
2418
|
}
|
|
2482
2419
|
// ============ Vault Functions (Phase 4: Copy Trading) ============
|
|
2483
2420
|
/**
|
|
@@ -3071,6 +3008,8 @@ export {
|
|
|
3071
3008
|
DEFAULT_RPC_URL,
|
|
3072
3009
|
DEX_ADDRESSES,
|
|
3073
3010
|
EXAGENT_API_CONFIG,
|
|
3011
|
+
EXAGENT_REGISTRY_ABI,
|
|
3012
|
+
EXAGENT_ROUTER_ABI,
|
|
3074
3013
|
EXAGENT_STAKING_ABI,
|
|
3075
3014
|
EXAGENT_VAULT_FACTORY_ABI,
|
|
3076
3015
|
ExagentClient,
|