@exagent/sdk 0.1.11 → 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.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,20 +221,13 @@ 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",
239
- name: "updateConfig",
227
+ name: "setConfig",
240
228
  inputs: [
241
229
  { name: "agentId", type: "uint256" },
242
- { name: "newConfigHash", type: "bytes32" }
230
+ { name: "configHash", type: "bytes32" }
243
231
  ],
244
232
  outputs: [],
245
233
  stateMutability: "nonpayable"
@@ -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: "OwnerAlreadyHasAgent", inputs: [{ name: "existingAgentId", type: "uint256" }] },
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: "NameAlreadyTaken", inputs: [] },
362
- { type: "error", name: "AgentNotOwner", inputs: [] },
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
@@ -655,7 +593,7 @@ var ExagentRegistry = class {
655
593
  chain: this.chain,
656
594
  address: this.address,
657
595
  abi: EXAGENT_REGISTRY_ABI,
658
- functionName: "updateConfig",
596
+ functionName: "setConfig",
659
597
  args: [agentId, configHash]
660
598
  });
661
599
  return hash;
@@ -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.10";
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: "0xAF1729D1519A72f7d9b87aa23a305b775e2849DA",
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
  /**
@@ -2374,13 +2291,37 @@ var ExagentClient = class {
2374
2291
  amount
2375
2292
  );
2376
2293
  }
2377
- const hash = await this.walletClient.sendTransaction({
2294
+ const txParams = {
2378
2295
  account: this.account,
2379
2296
  chain: CHAIN_CONFIG[this.network],
2380
2297
  to: routerTrade.transaction.to,
2381
2298
  data: routerTrade.transaction.data,
2382
2299
  value: BigInt(routerTrade.transaction.value)
2383
- });
2300
+ };
2301
+ try {
2302
+ const estimated = await this.publicClient.estimateGas({
2303
+ account: this.account,
2304
+ to: routerTrade.transaction.to,
2305
+ data: routerTrade.transaction.data,
2306
+ value: BigInt(routerTrade.transaction.value)
2307
+ });
2308
+ txParams.gas = estimated * 150n / 100n;
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"}`);
2323
+ }
2324
+ const hash = await this.walletClient.sendTransaction(txParams);
2384
2325
  return {
2385
2326
  hash,
2386
2327
  agentId,
@@ -2398,6 +2339,13 @@ var ExagentClient = class {
2398
2339
  const id = agentId ?? await this.getAgentId();
2399
2340
  if (!id) throw new Error("Agent not registered");
2400
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
+ }
2401
2349
  const response = await fetch(`${apiUrl}/v1/router/trade`, {
2402
2350
  method: "POST",
2403
2351
  headers: this.apiHeaders("application/json"),
@@ -2408,7 +2356,7 @@ var ExagentClient = class {
2408
2356
  amountIn: intent.amountIn.toString(),
2409
2357
  slippageBps: intent.maxSlippageBps ?? 50,
2410
2358
  taker: this.account.address,
2411
- ...intent.configHash && { configHash: intent.configHash }
2359
+ ...configHash && { configHash }
2412
2360
  })
2413
2361
  });
2414
2362
  if (!response.ok) {
@@ -2501,7 +2449,8 @@ var ExagentClient = class {
2501
2449
  const response = await fetch(`${apiUrl}/v1/rankings/leaderboard?${params}`, {
2502
2450
  headers: this.apiHeaders()
2503
2451
  });
2504
- return response.json();
2452
+ const data = await response.json();
2453
+ return data.agents ?? [];
2505
2454
  }
2506
2455
  // ============ Vault Functions (Phase 4: Copy Trading) ============
2507
2456
  /**
@@ -3096,6 +3045,8 @@ var ExagentVaultFactory = class {
3096
3045
  DEFAULT_RPC_URL,
3097
3046
  DEX_ADDRESSES,
3098
3047
  EXAGENT_API_CONFIG,
3048
+ EXAGENT_REGISTRY_ABI,
3049
+ EXAGENT_ROUTER_ABI,
3099
3050
  EXAGENT_STAKING_ABI,
3100
3051
  EXAGENT_VAULT_FACTORY_ABI,
3101
3052
  ExagentClient,