@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.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,20 +185,13 @@ 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",
204
- name: "updateConfig",
191
+ name: "setConfig",
205
192
  inputs: [
206
193
  { name: "agentId", type: "uint256" },
207
- { name: "newConfigHash", type: "bytes32" }
194
+ { name: "configHash", type: "bytes32" }
208
195
  ],
209
196
  outputs: [],
210
197
  stateMutability: "nonpayable"
@@ -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: "OwnerAlreadyHasAgent", inputs: [{ name: "existingAgentId", type: "uint256" }] },
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: "NameAlreadyTaken", inputs: [] },
327
- { type: "error", name: "AgentNotOwner", inputs: [] },
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
@@ -620,7 +557,7 @@ var ExagentRegistry = class {
620
557
  chain: this.chain,
621
558
  address: this.address,
622
559
  abi: EXAGENT_REGISTRY_ABI,
623
- functionName: "updateConfig",
560
+ functionName: "setConfig",
624
561
  args: [agentId, configHash]
625
562
  });
626
563
  return hash;
@@ -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.10";
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: "0xAF1729D1519A72f7d9b87aa23a305b775e2849DA",
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
  /**
@@ -2339,13 +2255,37 @@ var ExagentClient = class {
2339
2255
  amount
2340
2256
  );
2341
2257
  }
2342
- const hash = await this.walletClient.sendTransaction({
2258
+ const txParams = {
2343
2259
  account: this.account,
2344
2260
  chain: CHAIN_CONFIG[this.network],
2345
2261
  to: routerTrade.transaction.to,
2346
2262
  data: routerTrade.transaction.data,
2347
2263
  value: BigInt(routerTrade.transaction.value)
2348
- });
2264
+ };
2265
+ try {
2266
+ const estimated = await this.publicClient.estimateGas({
2267
+ account: this.account,
2268
+ to: routerTrade.transaction.to,
2269
+ data: routerTrade.transaction.data,
2270
+ value: BigInt(routerTrade.transaction.value)
2271
+ });
2272
+ txParams.gas = estimated * 150n / 100n;
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"}`);
2287
+ }
2288
+ const hash = await this.walletClient.sendTransaction(txParams);
2349
2289
  return {
2350
2290
  hash,
2351
2291
  agentId,
@@ -2363,6 +2303,13 @@ var ExagentClient = class {
2363
2303
  const id = agentId ?? await this.getAgentId();
2364
2304
  if (!id) throw new Error("Agent not registered");
2365
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
+ }
2366
2313
  const response = await fetch(`${apiUrl}/v1/router/trade`, {
2367
2314
  method: "POST",
2368
2315
  headers: this.apiHeaders("application/json"),
@@ -2373,7 +2320,7 @@ var ExagentClient = class {
2373
2320
  amountIn: intent.amountIn.toString(),
2374
2321
  slippageBps: intent.maxSlippageBps ?? 50,
2375
2322
  taker: this.account.address,
2376
- ...intent.configHash && { configHash: intent.configHash }
2323
+ ...configHash && { configHash }
2377
2324
  })
2378
2325
  });
2379
2326
  if (!response.ok) {
@@ -2466,7 +2413,8 @@ var ExagentClient = class {
2466
2413
  const response = await fetch(`${apiUrl}/v1/rankings/leaderboard?${params}`, {
2467
2414
  headers: this.apiHeaders()
2468
2415
  });
2469
- return response.json();
2416
+ const data = await response.json();
2417
+ return data.agents ?? [];
2470
2418
  }
2471
2419
  // ============ Vault Functions (Phase 4: Copy Trading) ============
2472
2420
  /**
@@ -3060,6 +3008,8 @@ export {
3060
3008
  DEFAULT_RPC_URL,
3061
3009
  DEX_ADDRESSES,
3062
3010
  EXAGENT_API_CONFIG,
3011
+ EXAGENT_REGISTRY_ABI,
3012
+ EXAGENT_ROUTER_ABI,
3063
3013
  EXAGENT_STAKING_ABI,
3064
3014
  EXAGENT_VAULT_FACTORY_ABI,
3065
3015
  ExagentClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exagent/sdk",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "TypeScript SDK for Exagent",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",