@exagent/sdk 0.1.6 → 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 +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +29 -7
- package/dist/index.mjs +29 -7
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1833,6 +1833,10 @@ declare class ExagentClient {
|
|
|
1833
1833
|
* Useful for simulation or multi-step workflows
|
|
1834
1834
|
*/
|
|
1835
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;
|
|
1836
1840
|
/**
|
|
1837
1841
|
* Approve token spending for router
|
|
1838
1842
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1833,6 +1833,10 @@ declare class ExagentClient {
|
|
|
1833
1833
|
* Useful for simulation or multi-step workflows
|
|
1834
1834
|
*/
|
|
1835
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;
|
|
1836
1840
|
/**
|
|
1837
1841
|
* Approve token spending for router
|
|
1838
1842
|
*/
|
package/dist/index.js
CHANGED
|
@@ -2076,13 +2076,10 @@ var CONTRACT_ADDRESSES = {
|
|
|
2076
2076
|
exaToken: "0x13403Fb738C97cF7564F279288468c140AaEd05c",
|
|
2077
2077
|
staking: "0xAF1729D1519A72f7d9b87aa23a305b775e2849DA",
|
|
2078
2078
|
router: "0x11daD5366D903a3eF5d8f07EFF87ce6b173859a9",
|
|
2079
|
-
vaultFactory: "
|
|
2080
|
-
// Phase 2 — pending deploy
|
|
2079
|
+
vaultFactory: "0xe9F1F6393448921bD29a1cBAbd951Bb8F8EA4A6f",
|
|
2081
2080
|
feeCollector: "0xe66328a964AF93bEF2eDB226D039C35aE6e66De1",
|
|
2082
|
-
buyback: "
|
|
2083
|
-
|
|
2084
|
-
serviceEscrow: "0x0000000000000000000000000000000000000000"
|
|
2085
|
-
// Phase 2 — pending deploy
|
|
2081
|
+
buyback: "0x39967532b640B2f735548c7a5b46d8D890A0B2f2",
|
|
2082
|
+
serviceEscrow: "0x63A4d1dA774422EFC2cc57d71F948231BD812516"
|
|
2086
2083
|
}
|
|
2087
2084
|
};
|
|
2088
2085
|
var DEX_ADDRESSES = {
|
|
@@ -2314,11 +2311,21 @@ var ExagentClient = class {
|
|
|
2314
2311
|
const agentId = await this.getAgentId();
|
|
2315
2312
|
if (!agentId) throw new Error("Agent not registered");
|
|
2316
2313
|
const routerTrade = await this.buildRouterTrade(intent, agentId);
|
|
2314
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2317
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;
|
|
2318
2325
|
await this.approveToken(
|
|
2319
2326
|
approval.token,
|
|
2320
2327
|
approval.spender,
|
|
2321
|
-
|
|
2328
|
+
amount
|
|
2322
2329
|
);
|
|
2323
2330
|
}
|
|
2324
2331
|
const hash = await this.walletClient.sendTransaction({
|
|
@@ -2363,6 +2370,21 @@ var ExagentClient = class {
|
|
|
2363
2370
|
}
|
|
2364
2371
|
return response.json();
|
|
2365
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
|
+
}
|
|
2366
2388
|
/**
|
|
2367
2389
|
* Approve token spending for router
|
|
2368
2390
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -2041,13 +2041,10 @@ var CONTRACT_ADDRESSES = {
|
|
|
2041
2041
|
exaToken: "0x13403Fb738C97cF7564F279288468c140AaEd05c",
|
|
2042
2042
|
staking: "0xAF1729D1519A72f7d9b87aa23a305b775e2849DA",
|
|
2043
2043
|
router: "0x11daD5366D903a3eF5d8f07EFF87ce6b173859a9",
|
|
2044
|
-
vaultFactory: "
|
|
2045
|
-
// Phase 2 — pending deploy
|
|
2044
|
+
vaultFactory: "0xe9F1F6393448921bD29a1cBAbd951Bb8F8EA4A6f",
|
|
2046
2045
|
feeCollector: "0xe66328a964AF93bEF2eDB226D039C35aE6e66De1",
|
|
2047
|
-
buyback: "
|
|
2048
|
-
|
|
2049
|
-
serviceEscrow: "0x0000000000000000000000000000000000000000"
|
|
2050
|
-
// Phase 2 — pending deploy
|
|
2046
|
+
buyback: "0x39967532b640B2f735548c7a5b46d8D890A0B2f2",
|
|
2047
|
+
serviceEscrow: "0x63A4d1dA774422EFC2cc57d71F948231BD812516"
|
|
2051
2048
|
}
|
|
2052
2049
|
};
|
|
2053
2050
|
var DEX_ADDRESSES = {
|
|
@@ -2279,11 +2276,21 @@ var ExagentClient = class {
|
|
|
2279
2276
|
const agentId = await this.getAgentId();
|
|
2280
2277
|
if (!agentId) throw new Error("Agent not registered");
|
|
2281
2278
|
const routerTrade = await this.buildRouterTrade(intent, agentId);
|
|
2279
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2282
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;
|
|
2283
2290
|
await this.approveToken(
|
|
2284
2291
|
approval.token,
|
|
2285
2292
|
approval.spender,
|
|
2286
|
-
|
|
2293
|
+
amount
|
|
2287
2294
|
);
|
|
2288
2295
|
}
|
|
2289
2296
|
const hash = await this.walletClient.sendTransaction({
|
|
@@ -2328,6 +2335,21 @@ var ExagentClient = class {
|
|
|
2328
2335
|
}
|
|
2329
2336
|
return response.json();
|
|
2330
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
|
+
}
|
|
2331
2353
|
/**
|
|
2332
2354
|
* Approve token spending for router
|
|
2333
2355
|
*/
|