@exagent/sdk 0.1.18 → 0.1.19
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 +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +55 -17
- package/dist/index.mjs +58 -18
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1509,7 +1509,16 @@ declare class ExagentClient {
|
|
|
1509
1509
|
/** Standard headers for all API requests (includes SDK version for gating) */
|
|
1510
1510
|
private apiHeaders;
|
|
1511
1511
|
/**
|
|
1512
|
-
* Register as a new agent on Exagent
|
|
1512
|
+
* Register as a new agent on Exagent.
|
|
1513
|
+
*
|
|
1514
|
+
* RECOMMENDED: Register your agent at https://exagent.io instead of using this method.
|
|
1515
|
+
* The website handles the full registration flow including risk universe selection,
|
|
1516
|
+
* position size limits, daily loss limits, and metadata upload — all in one step.
|
|
1517
|
+
* After registering on the website, use your agent ID in agent-config.json.
|
|
1518
|
+
*
|
|
1519
|
+
* This SDK method is available for programmatic registration but uses default
|
|
1520
|
+
* risk parameters (universe=1, maxPositionSize=10%, maxDailyLoss=5%).
|
|
1521
|
+
*
|
|
1513
1522
|
* @param metadata Agent metadata (will be uploaded to IPFS)
|
|
1514
1523
|
* @returns The assigned agent ID
|
|
1515
1524
|
* @throws Error if wallet already owns an agent (one agent per wallet rule)
|
|
@@ -1528,9 +1537,19 @@ declare class ExagentClient {
|
|
|
1528
1537
|
*/
|
|
1529
1538
|
getAgentByName(name: string): Promise<bigint>;
|
|
1530
1539
|
/**
|
|
1531
|
-
* Get the current agent's ID (if registered)
|
|
1540
|
+
* Get the current agent's ID (if registered).
|
|
1541
|
+
*
|
|
1542
|
+
* Resolution order:
|
|
1543
|
+
* 1. Cached value (from prior register() or getAgentId() call)
|
|
1544
|
+
* 2. walletToAgent mapping (linked wallets)
|
|
1545
|
+
* 3. Owner lookup (unlinked owner wallet)
|
|
1546
|
+
*
|
|
1547
|
+
* If the agent was just registered, public RPCs may return stale data (0).
|
|
1548
|
+
* Use `retries` to wait for the on-chain state to propagate.
|
|
1549
|
+
*
|
|
1550
|
+
* @param retries Number of retries with 2s delay for stale RPC reads (default: 0)
|
|
1532
1551
|
*/
|
|
1533
|
-
getAgentId(): Promise<bigint | undefined>;
|
|
1552
|
+
getAgentId(retries?: number): Promise<bigint | undefined>;
|
|
1534
1553
|
/**
|
|
1535
1554
|
* Get agent profile
|
|
1536
1555
|
* @param agentId Optional agent ID (defaults to current agent)
|
package/dist/index.d.ts
CHANGED
|
@@ -1509,7 +1509,16 @@ declare class ExagentClient {
|
|
|
1509
1509
|
/** Standard headers for all API requests (includes SDK version for gating) */
|
|
1510
1510
|
private apiHeaders;
|
|
1511
1511
|
/**
|
|
1512
|
-
* Register as a new agent on Exagent
|
|
1512
|
+
* Register as a new agent on Exagent.
|
|
1513
|
+
*
|
|
1514
|
+
* RECOMMENDED: Register your agent at https://exagent.io instead of using this method.
|
|
1515
|
+
* The website handles the full registration flow including risk universe selection,
|
|
1516
|
+
* position size limits, daily loss limits, and metadata upload — all in one step.
|
|
1517
|
+
* After registering on the website, use your agent ID in agent-config.json.
|
|
1518
|
+
*
|
|
1519
|
+
* This SDK method is available for programmatic registration but uses default
|
|
1520
|
+
* risk parameters (universe=1, maxPositionSize=10%, maxDailyLoss=5%).
|
|
1521
|
+
*
|
|
1513
1522
|
* @param metadata Agent metadata (will be uploaded to IPFS)
|
|
1514
1523
|
* @returns The assigned agent ID
|
|
1515
1524
|
* @throws Error if wallet already owns an agent (one agent per wallet rule)
|
|
@@ -1528,9 +1537,19 @@ declare class ExagentClient {
|
|
|
1528
1537
|
*/
|
|
1529
1538
|
getAgentByName(name: string): Promise<bigint>;
|
|
1530
1539
|
/**
|
|
1531
|
-
* Get the current agent's ID (if registered)
|
|
1540
|
+
* Get the current agent's ID (if registered).
|
|
1541
|
+
*
|
|
1542
|
+
* Resolution order:
|
|
1543
|
+
* 1. Cached value (from prior register() or getAgentId() call)
|
|
1544
|
+
* 2. walletToAgent mapping (linked wallets)
|
|
1545
|
+
* 3. Owner lookup (unlinked owner wallet)
|
|
1546
|
+
*
|
|
1547
|
+
* If the agent was just registered, public RPCs may return stale data (0).
|
|
1548
|
+
* Use `retries` to wait for the on-chain state to propagate.
|
|
1549
|
+
*
|
|
1550
|
+
* @param retries Number of retries with 2s delay for stale RPC reads (default: 0)
|
|
1532
1551
|
*/
|
|
1533
|
-
getAgentId(): Promise<bigint | undefined>;
|
|
1552
|
+
getAgentId(retries?: number): Promise<bigint | undefined>;
|
|
1534
1553
|
/**
|
|
1535
1554
|
* Get agent profile
|
|
1536
1555
|
* @param agentId Optional agent ID (defaults to current agent)
|
package/dist/index.js
CHANGED
|
@@ -1213,7 +1213,7 @@ var CHAIN_CONFIG = {
|
|
|
1213
1213
|
var CONTRACT_ADDRESSES = {
|
|
1214
1214
|
mainnet: {
|
|
1215
1215
|
agentRegistry: "0x2261706C751F8ac5cdDb481B7b56EA2137d4A723",
|
|
1216
|
-
router: "
|
|
1216
|
+
router: "0x20feB3054750970773Fe7370c391732EE0559743",
|
|
1217
1217
|
vaultFactory: "0x1E0e4E445A9fda2e7aBBfFEcA80392ABb0921554",
|
|
1218
1218
|
feeCollector: "0x00Ab9847049b5496619dFDd1A7bd36FA49eB7195",
|
|
1219
1219
|
serviceEscrow: "0x63A4d1dA774422EFC2cc57d71F948231BD812516"
|
|
@@ -1321,7 +1321,16 @@ var ExagentClient = class {
|
|
|
1321
1321
|
}
|
|
1322
1322
|
// ============ Agent Registration ============
|
|
1323
1323
|
/**
|
|
1324
|
-
* Register as a new agent on Exagent
|
|
1324
|
+
* Register as a new agent on Exagent.
|
|
1325
|
+
*
|
|
1326
|
+
* RECOMMENDED: Register your agent at https://exagent.io instead of using this method.
|
|
1327
|
+
* The website handles the full registration flow including risk universe selection,
|
|
1328
|
+
* position size limits, daily loss limits, and metadata upload — all in one step.
|
|
1329
|
+
* After registering on the website, use your agent ID in agent-config.json.
|
|
1330
|
+
*
|
|
1331
|
+
* This SDK method is available for programmatic registration but uses default
|
|
1332
|
+
* risk parameters (universe=1, maxPositionSize=10%, maxDailyLoss=5%).
|
|
1333
|
+
*
|
|
1325
1334
|
* @param metadata Agent metadata (will be uploaded to IPFS)
|
|
1326
1335
|
* @returns The assigned agent ID
|
|
1327
1336
|
* @throws Error if wallet already owns an agent (one agent per wallet rule)
|
|
@@ -1363,19 +1372,34 @@ var ExagentClient = class {
|
|
|
1363
1372
|
return this.registry.getAgentByName(name);
|
|
1364
1373
|
}
|
|
1365
1374
|
/**
|
|
1366
|
-
* Get the current agent's ID (if registered)
|
|
1375
|
+
* Get the current agent's ID (if registered).
|
|
1376
|
+
*
|
|
1377
|
+
* Resolution order:
|
|
1378
|
+
* 1. Cached value (from prior register() or getAgentId() call)
|
|
1379
|
+
* 2. walletToAgent mapping (linked wallets)
|
|
1380
|
+
* 3. Owner lookup (unlinked owner wallet)
|
|
1381
|
+
*
|
|
1382
|
+
* If the agent was just registered, public RPCs may return stale data (0).
|
|
1383
|
+
* Use `retries` to wait for the on-chain state to propagate.
|
|
1384
|
+
*
|
|
1385
|
+
* @param retries Number of retries with 2s delay for stale RPC reads (default: 0)
|
|
1367
1386
|
*/
|
|
1368
|
-
async getAgentId() {
|
|
1387
|
+
async getAgentId(retries = 0) {
|
|
1369
1388
|
if (this._agentId) return this._agentId;
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1389
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
1390
|
+
if (attempt > 0) {
|
|
1391
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
1392
|
+
}
|
|
1393
|
+
const agentId = await this.registry.getAgentForWallet(this.account.address);
|
|
1394
|
+
if (agentId > 0n) {
|
|
1395
|
+
this._agentId = agentId;
|
|
1396
|
+
return agentId;
|
|
1397
|
+
}
|
|
1398
|
+
const ownedAgentId = await this.registry.getAgentByOwner(this.account.address);
|
|
1399
|
+
if (ownedAgentId > 0n) {
|
|
1400
|
+
this._agentId = ownedAgentId;
|
|
1401
|
+
return ownedAgentId;
|
|
1402
|
+
}
|
|
1379
1403
|
}
|
|
1380
1404
|
return void 0;
|
|
1381
1405
|
}
|
|
@@ -1823,14 +1847,28 @@ var ExagentClient = class {
|
|
|
1823
1847
|
}
|
|
1824
1848
|
parseAgentIdFromReceipt(receipt) {
|
|
1825
1849
|
const registryAddress = this.registry.address.toLowerCase();
|
|
1850
|
+
const AGENT_REGISTERED_TOPIC = (0, import_viem2.keccak256)(
|
|
1851
|
+
(0, import_viem2.toHex)("AgentRegistered(uint256,address,string,string)")
|
|
1852
|
+
);
|
|
1853
|
+
const TRANSFER_TOPIC = (0, import_viem2.keccak256)(
|
|
1854
|
+
(0, import_viem2.toHex)("Transfer(address,address,uint256)")
|
|
1855
|
+
);
|
|
1856
|
+
const ZERO_ADDRESS2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
1826
1857
|
for (const log of receipt.logs) {
|
|
1827
1858
|
if (log.address.toLowerCase() !== registryAddress) continue;
|
|
1828
|
-
if (log.topics
|
|
1829
|
-
|
|
1830
|
-
|
|
1859
|
+
if (log.topics[0] === AGENT_REGISTERED_TOPIC && log.topics[1]) {
|
|
1860
|
+
return BigInt(log.topics[1]);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
for (const log of receipt.logs) {
|
|
1864
|
+
if (log.address.toLowerCase() !== registryAddress) continue;
|
|
1865
|
+
if (log.topics[0] === TRANSFER_TOPIC && log.topics[1] === ZERO_ADDRESS2 && log.topics[3]) {
|
|
1866
|
+
return BigInt(log.topics[3]);
|
|
1831
1867
|
}
|
|
1832
1868
|
}
|
|
1833
|
-
throw new Error(
|
|
1869
|
+
throw new Error(
|
|
1870
|
+
"Could not extract agent ID from transaction receipt.\nNeither AgentRegistered nor ERC721 Transfer event found in logs.\nCheck the transaction on BaseScan to verify registration succeeded."
|
|
1871
|
+
);
|
|
1834
1872
|
}
|
|
1835
1873
|
};
|
|
1836
1874
|
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
createWalletClient,
|
|
5
5
|
http,
|
|
6
6
|
decodeErrorResult,
|
|
7
|
-
maxUint256
|
|
7
|
+
maxUint256,
|
|
8
|
+
keccak256 as keccak2562,
|
|
9
|
+
toHex
|
|
8
10
|
} from "viem";
|
|
9
11
|
import { privateKeyToAccount } from "viem/accounts";
|
|
10
12
|
|
|
@@ -1180,7 +1182,7 @@ var CHAIN_CONFIG = {
|
|
|
1180
1182
|
var CONTRACT_ADDRESSES = {
|
|
1181
1183
|
mainnet: {
|
|
1182
1184
|
agentRegistry: "0x2261706C751F8ac5cdDb481B7b56EA2137d4A723",
|
|
1183
|
-
router: "
|
|
1185
|
+
router: "0x20feB3054750970773Fe7370c391732EE0559743",
|
|
1184
1186
|
vaultFactory: "0x1E0e4E445A9fda2e7aBBfFEcA80392ABb0921554",
|
|
1185
1187
|
feeCollector: "0x00Ab9847049b5496619dFDd1A7bd36FA49eB7195",
|
|
1186
1188
|
serviceEscrow: "0x63A4d1dA774422EFC2cc57d71F948231BD812516"
|
|
@@ -1288,7 +1290,16 @@ var ExagentClient = class {
|
|
|
1288
1290
|
}
|
|
1289
1291
|
// ============ Agent Registration ============
|
|
1290
1292
|
/**
|
|
1291
|
-
* Register as a new agent on Exagent
|
|
1293
|
+
* Register as a new agent on Exagent.
|
|
1294
|
+
*
|
|
1295
|
+
* RECOMMENDED: Register your agent at https://exagent.io instead of using this method.
|
|
1296
|
+
* The website handles the full registration flow including risk universe selection,
|
|
1297
|
+
* position size limits, daily loss limits, and metadata upload — all in one step.
|
|
1298
|
+
* After registering on the website, use your agent ID in agent-config.json.
|
|
1299
|
+
*
|
|
1300
|
+
* This SDK method is available for programmatic registration but uses default
|
|
1301
|
+
* risk parameters (universe=1, maxPositionSize=10%, maxDailyLoss=5%).
|
|
1302
|
+
*
|
|
1292
1303
|
* @param metadata Agent metadata (will be uploaded to IPFS)
|
|
1293
1304
|
* @returns The assigned agent ID
|
|
1294
1305
|
* @throws Error if wallet already owns an agent (one agent per wallet rule)
|
|
@@ -1330,19 +1341,34 @@ var ExagentClient = class {
|
|
|
1330
1341
|
return this.registry.getAgentByName(name);
|
|
1331
1342
|
}
|
|
1332
1343
|
/**
|
|
1333
|
-
* Get the current agent's ID (if registered)
|
|
1344
|
+
* Get the current agent's ID (if registered).
|
|
1345
|
+
*
|
|
1346
|
+
* Resolution order:
|
|
1347
|
+
* 1. Cached value (from prior register() or getAgentId() call)
|
|
1348
|
+
* 2. walletToAgent mapping (linked wallets)
|
|
1349
|
+
* 3. Owner lookup (unlinked owner wallet)
|
|
1350
|
+
*
|
|
1351
|
+
* If the agent was just registered, public RPCs may return stale data (0).
|
|
1352
|
+
* Use `retries` to wait for the on-chain state to propagate.
|
|
1353
|
+
*
|
|
1354
|
+
* @param retries Number of retries with 2s delay for stale RPC reads (default: 0)
|
|
1334
1355
|
*/
|
|
1335
|
-
async getAgentId() {
|
|
1356
|
+
async getAgentId(retries = 0) {
|
|
1336
1357
|
if (this._agentId) return this._agentId;
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1358
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
1359
|
+
if (attempt > 0) {
|
|
1360
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
1361
|
+
}
|
|
1362
|
+
const agentId = await this.registry.getAgentForWallet(this.account.address);
|
|
1363
|
+
if (agentId > 0n) {
|
|
1364
|
+
this._agentId = agentId;
|
|
1365
|
+
return agentId;
|
|
1366
|
+
}
|
|
1367
|
+
const ownedAgentId = await this.registry.getAgentByOwner(this.account.address);
|
|
1368
|
+
if (ownedAgentId > 0n) {
|
|
1369
|
+
this._agentId = ownedAgentId;
|
|
1370
|
+
return ownedAgentId;
|
|
1371
|
+
}
|
|
1346
1372
|
}
|
|
1347
1373
|
return void 0;
|
|
1348
1374
|
}
|
|
@@ -1790,14 +1816,28 @@ var ExagentClient = class {
|
|
|
1790
1816
|
}
|
|
1791
1817
|
parseAgentIdFromReceipt(receipt) {
|
|
1792
1818
|
const registryAddress = this.registry.address.toLowerCase();
|
|
1819
|
+
const AGENT_REGISTERED_TOPIC = keccak2562(
|
|
1820
|
+
toHex("AgentRegistered(uint256,address,string,string)")
|
|
1821
|
+
);
|
|
1822
|
+
const TRANSFER_TOPIC = keccak2562(
|
|
1823
|
+
toHex("Transfer(address,address,uint256)")
|
|
1824
|
+
);
|
|
1825
|
+
const ZERO_ADDRESS2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
1793
1826
|
for (const log of receipt.logs) {
|
|
1794
1827
|
if (log.address.toLowerCase() !== registryAddress) continue;
|
|
1795
|
-
if (log.topics
|
|
1796
|
-
|
|
1797
|
-
|
|
1828
|
+
if (log.topics[0] === AGENT_REGISTERED_TOPIC && log.topics[1]) {
|
|
1829
|
+
return BigInt(log.topics[1]);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
for (const log of receipt.logs) {
|
|
1833
|
+
if (log.address.toLowerCase() !== registryAddress) continue;
|
|
1834
|
+
if (log.topics[0] === TRANSFER_TOPIC && log.topics[1] === ZERO_ADDRESS2 && log.topics[3]) {
|
|
1835
|
+
return BigInt(log.topics[3]);
|
|
1798
1836
|
}
|
|
1799
1837
|
}
|
|
1800
|
-
throw new Error(
|
|
1838
|
+
throw new Error(
|
|
1839
|
+
"Could not extract agent ID from transaction receipt.\nNeither AgentRegistered nor ERC721 Transfer event found in logs.\nCheck the transaction on BaseScan to verify registration succeeded."
|
|
1840
|
+
);
|
|
1801
1841
|
}
|
|
1802
1842
|
};
|
|
1803
1843
|
|