@exagent/sdk 0.1.5 → 0.1.7

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 CHANGED
@@ -1337,7 +1337,17 @@ declare class ExagentStaking {
1337
1337
  }
1338
1338
 
1339
1339
  /** SDK version — sent to API for version gating */
1340
- declare const SDK_VERSION = "0.1.4";
1340
+ declare const SDK_VERSION = "0.1.6";
1341
+ /**
1342
+ * Default RPC URL for Base mainnet.
1343
+ * Uses a higher-limit public endpoint to avoid rate-limiting.
1344
+ * Users should set BASE_RPC_URL env var for production use.
1345
+ */
1346
+ declare const DEFAULT_RPC_URL = "https://base-rpc.publicnode.com";
1347
+ /**
1348
+ * Get RPC URL from environment or use default.
1349
+ */
1350
+ declare function getRpcUrl(): string;
1341
1351
  declare const CHAIN_CONFIG: {
1342
1352
  readonly mainnet: {
1343
1353
  blockExplorers: {
@@ -1823,6 +1833,10 @@ declare class ExagentClient {
1823
1833
  * Useful for simulation or multi-step workflows
1824
1834
  */
1825
1835
  buildRouterTrade(intent: Omit<TradeIntent, 'action'>, agentId?: bigint): Promise<RouterTradeResponse>;
1836
+ /**
1837
+ * Read current ERC-20 allowance for a (token, spender) pair
1838
+ */
1839
+ private getAllowance;
1826
1840
  /**
1827
1841
  * Approve token spending for router
1828
1842
  */
@@ -2334,4 +2348,4 @@ declare class ExagentVaultFactory {
2334
2348
  }>;
2335
2349
  }
2336
2350
 
2337
- export { type AgentMetadata, type AgentProfile, type StakingInfo$1 as ApiStakingInfo, CHAIN_CONFIG, CONTRACT_ADDRESSES, type CanCreateVaultResult, type CreateVaultOptions, DEX_ADDRESSES, type DepositInfo, EXAGENT_API_CONFIG, EXAGENT_STAKING_ABI, EXAGENT_VAULT_FACTORY_ABI, type EarningsTierInfo, ExagentClient, type ExagentClientConfig, ExagentRegistry, ExagentStaking, ExagentVault, ExagentVaultFactory, type GlobalAgentId, type LockInfo, type NetworkType, type PerformanceSnapshot, type PriceQuote, type RouteQuote, type RouteStep, type RouterTradeResponse, SDK_VERSION, type ServiceRequest, type StakeInfo, type StakingInfo, type TradeIntent, type TradeResult, type UserVaultPosition, type VaultActivityEntry, type VaultConfig, type VaultCreationRequirements, type VaultInfo, type VaultPosition, type VaultSummary, type VaultTradeEntry, type WithdrawalRequest, ZERO_X_CONFIG, buildGlobalAgentId, parseGlobalAgentId };
2351
+ export { type AgentMetadata, type AgentProfile, type StakingInfo$1 as ApiStakingInfo, CHAIN_CONFIG, CONTRACT_ADDRESSES, type CanCreateVaultResult, type CreateVaultOptions, DEFAULT_RPC_URL, DEX_ADDRESSES, type DepositInfo, EXAGENT_API_CONFIG, EXAGENT_STAKING_ABI, EXAGENT_VAULT_FACTORY_ABI, type EarningsTierInfo, ExagentClient, type ExagentClientConfig, ExagentRegistry, ExagentStaking, ExagentVault, ExagentVaultFactory, type GlobalAgentId, type LockInfo, type NetworkType, type PerformanceSnapshot, type PriceQuote, type RouteQuote, type RouteStep, type RouterTradeResponse, SDK_VERSION, type ServiceRequest, type StakeInfo, type StakingInfo, type TradeIntent, type TradeResult, type UserVaultPosition, type VaultActivityEntry, type VaultConfig, type VaultCreationRequirements, type VaultInfo, type VaultPosition, type VaultSummary, type VaultTradeEntry, type WithdrawalRequest, ZERO_X_CONFIG, buildGlobalAgentId, getRpcUrl, parseGlobalAgentId };
package/dist/index.d.ts CHANGED
@@ -1337,7 +1337,17 @@ declare class ExagentStaking {
1337
1337
  }
1338
1338
 
1339
1339
  /** SDK version — sent to API for version gating */
1340
- declare const SDK_VERSION = "0.1.4";
1340
+ declare const SDK_VERSION = "0.1.6";
1341
+ /**
1342
+ * Default RPC URL for Base mainnet.
1343
+ * Uses a higher-limit public endpoint to avoid rate-limiting.
1344
+ * Users should set BASE_RPC_URL env var for production use.
1345
+ */
1346
+ declare const DEFAULT_RPC_URL = "https://base-rpc.publicnode.com";
1347
+ /**
1348
+ * Get RPC URL from environment or use default.
1349
+ */
1350
+ declare function getRpcUrl(): string;
1341
1351
  declare const CHAIN_CONFIG: {
1342
1352
  readonly mainnet: {
1343
1353
  blockExplorers: {
@@ -1823,6 +1833,10 @@ declare class ExagentClient {
1823
1833
  * Useful for simulation or multi-step workflows
1824
1834
  */
1825
1835
  buildRouterTrade(intent: Omit<TradeIntent, 'action'>, agentId?: bigint): Promise<RouterTradeResponse>;
1836
+ /**
1837
+ * Read current ERC-20 allowance for a (token, spender) pair
1838
+ */
1839
+ private getAllowance;
1826
1840
  /**
1827
1841
  * Approve token spending for router
1828
1842
  */
@@ -2334,4 +2348,4 @@ declare class ExagentVaultFactory {
2334
2348
  }>;
2335
2349
  }
2336
2350
 
2337
- export { type AgentMetadata, type AgentProfile, type StakingInfo$1 as ApiStakingInfo, CHAIN_CONFIG, CONTRACT_ADDRESSES, type CanCreateVaultResult, type CreateVaultOptions, DEX_ADDRESSES, type DepositInfo, EXAGENT_API_CONFIG, EXAGENT_STAKING_ABI, EXAGENT_VAULT_FACTORY_ABI, type EarningsTierInfo, ExagentClient, type ExagentClientConfig, ExagentRegistry, ExagentStaking, ExagentVault, ExagentVaultFactory, type GlobalAgentId, type LockInfo, type NetworkType, type PerformanceSnapshot, type PriceQuote, type RouteQuote, type RouteStep, type RouterTradeResponse, SDK_VERSION, type ServiceRequest, type StakeInfo, type StakingInfo, type TradeIntent, type TradeResult, type UserVaultPosition, type VaultActivityEntry, type VaultConfig, type VaultCreationRequirements, type VaultInfo, type VaultPosition, type VaultSummary, type VaultTradeEntry, type WithdrawalRequest, ZERO_X_CONFIG, buildGlobalAgentId, parseGlobalAgentId };
2351
+ export { type AgentMetadata, type AgentProfile, type StakingInfo$1 as ApiStakingInfo, CHAIN_CONFIG, CONTRACT_ADDRESSES, type CanCreateVaultResult, type CreateVaultOptions, DEFAULT_RPC_URL, DEX_ADDRESSES, type DepositInfo, EXAGENT_API_CONFIG, EXAGENT_STAKING_ABI, EXAGENT_VAULT_FACTORY_ABI, type EarningsTierInfo, ExagentClient, type ExagentClientConfig, ExagentRegistry, ExagentStaking, ExagentVault, ExagentVaultFactory, type GlobalAgentId, type LockInfo, type NetworkType, type PerformanceSnapshot, type PriceQuote, type RouteQuote, type RouteStep, type RouterTradeResponse, SDK_VERSION, type ServiceRequest, type StakeInfo, type StakingInfo, type TradeIntent, type TradeResult, type UserVaultPosition, type VaultActivityEntry, type VaultConfig, type VaultCreationRequirements, type VaultInfo, type VaultPosition, type VaultSummary, type VaultTradeEntry, type WithdrawalRequest, ZERO_X_CONFIG, buildGlobalAgentId, getRpcUrl, parseGlobalAgentId };
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  CHAIN_CONFIG: () => CHAIN_CONFIG,
24
24
  CONTRACT_ADDRESSES: () => CONTRACT_ADDRESSES,
25
+ DEFAULT_RPC_URL: () => DEFAULT_RPC_URL,
25
26
  DEX_ADDRESSES: () => DEX_ADDRESSES,
26
27
  EXAGENT_API_CONFIG: () => EXAGENT_API_CONFIG,
27
28
  EXAGENT_STAKING_ABI: () => EXAGENT_STAKING_ABI,
@@ -34,6 +35,7 @@ __export(index_exports, {
34
35
  SDK_VERSION: () => SDK_VERSION,
35
36
  ZERO_X_CONFIG: () => ZERO_X_CONFIG,
36
37
  buildGlobalAgentId: () => buildGlobalAgentId,
38
+ getRpcUrl: () => getRpcUrl,
37
39
  parseGlobalAgentId: () => parseGlobalAgentId
38
40
  });
39
41
  module.exports = __toCommonJS(index_exports);
@@ -2057,7 +2059,14 @@ var ExagentStaking = class {
2057
2059
 
2058
2060
  // src/constants.ts
2059
2061
  var import_chains = require("viem/chains");
2060
- var SDK_VERSION = "0.1.4";
2062
+ var SDK_VERSION = "0.1.6";
2063
+ var DEFAULT_RPC_URL = "https://base-rpc.publicnode.com";
2064
+ function getRpcUrl() {
2065
+ if (typeof process !== "undefined" && process.env) {
2066
+ return process.env.BASE_RPC_URL || process.env.EXAGENT_RPC_URL || DEFAULT_RPC_URL;
2067
+ }
2068
+ return DEFAULT_RPC_URL;
2069
+ }
2061
2070
  var CHAIN_CONFIG = {
2062
2071
  mainnet: import_chains.base
2063
2072
  };
@@ -2067,13 +2076,10 @@ var CONTRACT_ADDRESSES = {
2067
2076
  exaToken: "0x13403Fb738C97cF7564F279288468c140AaEd05c",
2068
2077
  staking: "0xAF1729D1519A72f7d9b87aa23a305b775e2849DA",
2069
2078
  router: "0x11daD5366D903a3eF5d8f07EFF87ce6b173859a9",
2070
- vaultFactory: "0x0000000000000000000000000000000000000000",
2071
- // Phase 2 — pending deploy
2079
+ vaultFactory: "0xe9F1F6393448921bD29a1cBAbd951Bb8F8EA4A6f",
2072
2080
  feeCollector: "0xe66328a964AF93bEF2eDB226D039C35aE6e66De1",
2073
- buyback: "0x0000000000000000000000000000000000000000",
2074
- // Phase 2 — pending deploy
2075
- serviceEscrow: "0x0000000000000000000000000000000000000000"
2076
- // Phase 2 — pending deploy
2081
+ buyback: "0x39967532b640B2f735548c7a5b46d8D890A0B2f2",
2082
+ serviceEscrow: "0x63A4d1dA774422EFC2cc57d71F948231BD812516"
2077
2083
  }
2078
2084
  };
2079
2085
  var DEX_ADDRESSES = {
@@ -2148,9 +2154,10 @@ var ExagentClient = class {
2148
2154
  this.apiKey = config.apiKey;
2149
2155
  validateContractAddresses(this.network);
2150
2156
  const chain = CHAIN_CONFIG[this.network];
2157
+ const rpcUrl = config.rpcUrl || getRpcUrl();
2151
2158
  this.publicClient = (0, import_viem2.createPublicClient)({
2152
2159
  chain,
2153
- transport: (0, import_viem2.http)(config.rpcUrl)
2160
+ transport: (0, import_viem2.http)(rpcUrl)
2154
2161
  });
2155
2162
  if (config.walletClient) {
2156
2163
  this.walletClient = config.walletClient;
@@ -2160,7 +2167,7 @@ var ExagentClient = class {
2160
2167
  this.walletClient = (0, import_viem2.createWalletClient)({
2161
2168
  account: this.account,
2162
2169
  chain,
2163
- transport: (0, import_viem2.http)(config.rpcUrl)
2170
+ transport: (0, import_viem2.http)(rpcUrl)
2164
2171
  });
2165
2172
  } else {
2166
2173
  throw new Error("Either privateKey or walletClient must be provided");
@@ -2304,11 +2311,21 @@ var ExagentClient = class {
2304
2311
  const agentId = await this.getAgentId();
2305
2312
  if (!agentId) throw new Error("Agent not registered");
2306
2313
  const routerTrade = await this.buildRouterTrade(intent, agentId);
2314
+ const seen = /* @__PURE__ */ new Set();
2307
2315
  for (const approval of routerTrade.approvals) {
2316
+ const key = `${approval.token.toLowerCase()}:${approval.spender.toLowerCase()}`;
2317
+ if (seen.has(key)) continue;
2318
+ seen.add(key);
2319
+ const amount = BigInt(approval.amount);
2320
+ const existing = await this.getAllowance(
2321
+ approval.token,
2322
+ approval.spender
2323
+ );
2324
+ if (existing >= amount) continue;
2308
2325
  await this.approveToken(
2309
2326
  approval.token,
2310
2327
  approval.spender,
2311
- BigInt(approval.amount)
2328
+ amount
2312
2329
  );
2313
2330
  }
2314
2331
  const hash = await this.walletClient.sendTransaction({
@@ -2353,6 +2370,21 @@ var ExagentClient = class {
2353
2370
  }
2354
2371
  return response.json();
2355
2372
  }
2373
+ /**
2374
+ * Read current ERC-20 allowance for a (token, spender) pair
2375
+ */
2376
+ async getAllowance(token, spender) {
2377
+ try {
2378
+ const data = await this.publicClient.call({
2379
+ to: token,
2380
+ data: `0xdd62ed3e${this.account.address.slice(2).padStart(64, "0")}${spender.slice(2).padStart(64, "0")}`
2381
+ });
2382
+ if (!data.data || data.data === "0x") return 0n;
2383
+ return BigInt(data.data);
2384
+ } catch {
2385
+ return 0n;
2386
+ }
2387
+ }
2356
2388
  /**
2357
2389
  * Approve token spending for router
2358
2390
  */
@@ -3014,6 +3046,7 @@ var ExagentVaultFactory = class {
3014
3046
  0 && (module.exports = {
3015
3047
  CHAIN_CONFIG,
3016
3048
  CONTRACT_ADDRESSES,
3049
+ DEFAULT_RPC_URL,
3017
3050
  DEX_ADDRESSES,
3018
3051
  EXAGENT_API_CONFIG,
3019
3052
  EXAGENT_STAKING_ABI,
@@ -3026,5 +3059,6 @@ var ExagentVaultFactory = class {
3026
3059
  SDK_VERSION,
3027
3060
  ZERO_X_CONFIG,
3028
3061
  buildGlobalAgentId,
3062
+ getRpcUrl,
3029
3063
  parseGlobalAgentId
3030
3064
  });
package/dist/index.mjs CHANGED
@@ -2024,7 +2024,14 @@ var ExagentStaking = class {
2024
2024
 
2025
2025
  // src/constants.ts
2026
2026
  import { base } from "viem/chains";
2027
- var SDK_VERSION = "0.1.4";
2027
+ var SDK_VERSION = "0.1.6";
2028
+ var DEFAULT_RPC_URL = "https://base-rpc.publicnode.com";
2029
+ function getRpcUrl() {
2030
+ if (typeof process !== "undefined" && process.env) {
2031
+ return process.env.BASE_RPC_URL || process.env.EXAGENT_RPC_URL || DEFAULT_RPC_URL;
2032
+ }
2033
+ return DEFAULT_RPC_URL;
2034
+ }
2028
2035
  var CHAIN_CONFIG = {
2029
2036
  mainnet: base
2030
2037
  };
@@ -2034,13 +2041,10 @@ var CONTRACT_ADDRESSES = {
2034
2041
  exaToken: "0x13403Fb738C97cF7564F279288468c140AaEd05c",
2035
2042
  staking: "0xAF1729D1519A72f7d9b87aa23a305b775e2849DA",
2036
2043
  router: "0x11daD5366D903a3eF5d8f07EFF87ce6b173859a9",
2037
- vaultFactory: "0x0000000000000000000000000000000000000000",
2038
- // Phase 2 — pending deploy
2044
+ vaultFactory: "0xe9F1F6393448921bD29a1cBAbd951Bb8F8EA4A6f",
2039
2045
  feeCollector: "0xe66328a964AF93bEF2eDB226D039C35aE6e66De1",
2040
- buyback: "0x0000000000000000000000000000000000000000",
2041
- // Phase 2 — pending deploy
2042
- serviceEscrow: "0x0000000000000000000000000000000000000000"
2043
- // Phase 2 — pending deploy
2046
+ buyback: "0x39967532b640B2f735548c7a5b46d8D890A0B2f2",
2047
+ serviceEscrow: "0x63A4d1dA774422EFC2cc57d71F948231BD812516"
2044
2048
  }
2045
2049
  };
2046
2050
  var DEX_ADDRESSES = {
@@ -2115,9 +2119,10 @@ var ExagentClient = class {
2115
2119
  this.apiKey = config.apiKey;
2116
2120
  validateContractAddresses(this.network);
2117
2121
  const chain = CHAIN_CONFIG[this.network];
2122
+ const rpcUrl = config.rpcUrl || getRpcUrl();
2118
2123
  this.publicClient = createPublicClient({
2119
2124
  chain,
2120
- transport: http(config.rpcUrl)
2125
+ transport: http(rpcUrl)
2121
2126
  });
2122
2127
  if (config.walletClient) {
2123
2128
  this.walletClient = config.walletClient;
@@ -2127,7 +2132,7 @@ var ExagentClient = class {
2127
2132
  this.walletClient = createWalletClient({
2128
2133
  account: this.account,
2129
2134
  chain,
2130
- transport: http(config.rpcUrl)
2135
+ transport: http(rpcUrl)
2131
2136
  });
2132
2137
  } else {
2133
2138
  throw new Error("Either privateKey or walletClient must be provided");
@@ -2271,11 +2276,21 @@ var ExagentClient = class {
2271
2276
  const agentId = await this.getAgentId();
2272
2277
  if (!agentId) throw new Error("Agent not registered");
2273
2278
  const routerTrade = await this.buildRouterTrade(intent, agentId);
2279
+ const seen = /* @__PURE__ */ new Set();
2274
2280
  for (const approval of routerTrade.approvals) {
2281
+ const key = `${approval.token.toLowerCase()}:${approval.spender.toLowerCase()}`;
2282
+ if (seen.has(key)) continue;
2283
+ seen.add(key);
2284
+ const amount = BigInt(approval.amount);
2285
+ const existing = await this.getAllowance(
2286
+ approval.token,
2287
+ approval.spender
2288
+ );
2289
+ if (existing >= amount) continue;
2275
2290
  await this.approveToken(
2276
2291
  approval.token,
2277
2292
  approval.spender,
2278
- BigInt(approval.amount)
2293
+ amount
2279
2294
  );
2280
2295
  }
2281
2296
  const hash = await this.walletClient.sendTransaction({
@@ -2320,6 +2335,21 @@ var ExagentClient = class {
2320
2335
  }
2321
2336
  return response.json();
2322
2337
  }
2338
+ /**
2339
+ * Read current ERC-20 allowance for a (token, spender) pair
2340
+ */
2341
+ async getAllowance(token, spender) {
2342
+ try {
2343
+ const data = await this.publicClient.call({
2344
+ to: token,
2345
+ data: `0xdd62ed3e${this.account.address.slice(2).padStart(64, "0")}${spender.slice(2).padStart(64, "0")}`
2346
+ });
2347
+ if (!data.data || data.data === "0x") return 0n;
2348
+ return BigInt(data.data);
2349
+ } catch {
2350
+ return 0n;
2351
+ }
2352
+ }
2323
2353
  /**
2324
2354
  * Approve token spending for router
2325
2355
  */
@@ -2980,6 +3010,7 @@ var ExagentVaultFactory = class {
2980
3010
  export {
2981
3011
  CHAIN_CONFIG,
2982
3012
  CONTRACT_ADDRESSES,
3013
+ DEFAULT_RPC_URL,
2983
3014
  DEX_ADDRESSES,
2984
3015
  EXAGENT_API_CONFIG,
2985
3016
  EXAGENT_STAKING_ABI,
@@ -2992,5 +3023,6 @@ export {
2992
3023
  SDK_VERSION,
2993
3024
  ZERO_X_CONFIG,
2994
3025
  buildGlobalAgentId,
3026
+ getRpcUrl,
2995
3027
  parseGlobalAgentId
2996
3028
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exagent/sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "TypeScript SDK for Exagent",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",