@circuitorg/agent-sdk 1.2.1 → 1.2.4
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/README.md +173 -0
- package/index.d.ts +1364 -14
- package/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ A simplified TypeScript SDK for building automated agents to deploy on Circuit.
|
|
|
13
13
|
- [🚀 Quick Start](#-quick-start)
|
|
14
14
|
- [Install the SDK](#install-the-sdk)
|
|
15
15
|
- [Create Your First Agent](#create-your-first-agent)
|
|
16
|
+
- [Required Asset setup](#required-asset-setup)
|
|
16
17
|
- [🎯 Core Concepts](#-core-concepts)
|
|
17
18
|
- [The AgentContext Object](#the-agentcontext-object)
|
|
18
19
|
- [Run/Stop Function Requirements](#runstop-function-requirements)
|
|
@@ -23,6 +24,12 @@ A simplified TypeScript SDK for building automated agents to deploy on Circuit.
|
|
|
23
24
|
- [📈 Polymarket Prediction Markets](#-polymarket-prediction-markets)
|
|
24
25
|
- [Place Market Orders](#place-market-orders)
|
|
25
26
|
- [Redeem Positions](#redeem-positions)
|
|
27
|
+
- [Hyperliquid Perpetuals Trading](#hyperliquid-perpetuals-trading)
|
|
28
|
+
- [Account Information](#account-information)
|
|
29
|
+
- [Place Orders](#place-orders)
|
|
30
|
+
- [Order Management](#order-management)
|
|
31
|
+
- [Transfer Between Accounts](#transfer-between-accounts)
|
|
32
|
+
- [📊 Transaction History](#-transaction-history)
|
|
26
33
|
- [🚀 Sign \& Send Transactions](#-sign--send-transactions)
|
|
27
34
|
- [Ethereum (any EVM chain)](#ethereum-any-evm-chain)
|
|
28
35
|
- [Solana](#solana)
|
|
@@ -65,9 +72,27 @@ Every agent receives a single `AgentContext` object that provides:
|
|
|
65
72
|
- `agent.swidge` - Cross-chain swaps and bridges (`.quote()`, `.execute()`)
|
|
66
73
|
- `agent.signAndSend()` - Execute custom built transactions on any supported chain
|
|
67
74
|
- `agent.signMessage()` - Sign messages (EVM only)
|
|
75
|
+
- `agent.transactions()` - Get transaction history with asset changes
|
|
68
76
|
|
|
69
77
|
**Important:** `currentPositions` reflects your allocated assets at the **start** of each execution. To avoid failed transactions, you should be tracking intra-run position changes based on transactions the agent makes during the execution. Circuit will provide updated positions on the next execution request.
|
|
70
78
|
|
|
79
|
+
|
|
80
|
+
#### Required Asset setup
|
|
81
|
+
> Note: For native tokens, use the following null addresses for solana/ethereum
|
|
82
|
+
```toml
|
|
83
|
+
// Requiring 1 SOL
|
|
84
|
+
[[requiredAssets]]
|
|
85
|
+
network = "solana"
|
|
86
|
+
address = "11111111111111111111111111111111"
|
|
87
|
+
minimumAmount = "1000000000"
|
|
88
|
+
|
|
89
|
+
// Requiring 1 ETH
|
|
90
|
+
[[requiredAssets]]
|
|
91
|
+
network = "ethereum:<chainId>"
|
|
92
|
+
address = "0x0000000000000000000000000000000000000000"
|
|
93
|
+
minimumAmount = "1000000000000000000"
|
|
94
|
+
```
|
|
95
|
+
|
|
71
96
|
```typescript
|
|
72
97
|
import { Agent, AgentContext } from "@circuitorg/agent-sdk";
|
|
73
98
|
|
|
@@ -121,6 +146,7 @@ Every agent function receives a single `AgentContext` object that contains:
|
|
|
121
146
|
- `agent.swidge` - Cross-chain swap operations
|
|
122
147
|
- `agent.signAndSend()` - Sign and broadcast transactions
|
|
123
148
|
- `agent.signMessage()` - Sign messages on EVM
|
|
149
|
+
- `agent.transactions()` - Get transaction history with asset changes
|
|
124
150
|
|
|
125
151
|
### Run/Stop Function Requirements
|
|
126
152
|
|
|
@@ -215,6 +241,8 @@ Built-in Swidge integration for seamless cross-chain token swaps and bridges.
|
|
|
215
241
|
### Get and execute a quote
|
|
216
242
|
> Note: It is important to always validate quotes before executing. Circuit will always do its best to return a quote, and as of now, will only filter out quotes with price impacts exceeding 100% to ensure maximum flexibility. It is on the agent to makes sure a quote is valid, given its own parameters
|
|
217
243
|
|
|
244
|
+
> **Bulk Execution:** `execute()` accepts both single quotes and arrays. Pass an array to execute multiple swaps in parallel: `await agent.swidge.execute([quote1.data, quote2.data])` returns an array of results.
|
|
245
|
+
|
|
218
246
|
```typescript
|
|
219
247
|
async function run(agent: AgentContext): Promise<void> {
|
|
220
248
|
// 1. Get quote
|
|
@@ -305,6 +333,151 @@ async function stop(agent: AgentContext): Promise<void> {
|
|
|
305
333
|
}
|
|
306
334
|
```
|
|
307
335
|
|
|
336
|
+
## Hyperliquid Perpetuals Trading
|
|
337
|
+
|
|
338
|
+
Trade perpetual futures on Hyperliquid DEX with leverage.
|
|
339
|
+
|
|
340
|
+
### Account Information
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
async function run(agent: AgentContext): Promise<void> {
|
|
344
|
+
// Check balances
|
|
345
|
+
const balances = await agent.platforms.hyperliquid.balances();
|
|
346
|
+
if (balances.success && balances.data) {
|
|
347
|
+
await agent.log(`Account value: $${balances.data.perp.accountValue}`);
|
|
348
|
+
await agent.log(`Withdrawable: $${balances.data.perp.withdrawable}`);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// View open positions
|
|
352
|
+
const positions = await agent.platforms.hyperliquid.positions();
|
|
353
|
+
if (positions.success && positions.data) {
|
|
354
|
+
for (const pos of positions.data) {
|
|
355
|
+
await agent.log(`${pos.symbol}: ${pos.side} ${pos.size} @ ${pos.entryPrice}`);
|
|
356
|
+
await agent.log(`Unrealized PnL: $${pos.unrealizedPnl}`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### Place Orders
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
async function run(agent: AgentContext): Promise<void> {
|
|
366
|
+
// Market order
|
|
367
|
+
const order = await agent.platforms.hyperliquid.placeOrder({
|
|
368
|
+
symbol: "BTC-USD",
|
|
369
|
+
side: "buy",
|
|
370
|
+
size: 0.0001,
|
|
371
|
+
price: 110000, // Acts as slippage limit for market orders
|
|
372
|
+
market: "perp",
|
|
373
|
+
type: "market"
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
if (order.success && order.data) {
|
|
377
|
+
await agent.log(`Order ${order.data.orderId}: ${order.data.status}`);
|
|
378
|
+
} else {
|
|
379
|
+
await agent.log(order.error, { error: true });
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Order Management
|
|
385
|
+
|
|
386
|
+
```typescript
|
|
387
|
+
async function run(agent: AgentContext): Promise<void> {
|
|
388
|
+
// Get open orders
|
|
389
|
+
const openOrders = await agent.platforms.hyperliquid.openOrders();
|
|
390
|
+
|
|
391
|
+
// Get specific order details
|
|
392
|
+
const order = await agent.platforms.hyperliquid.order("12345");
|
|
393
|
+
|
|
394
|
+
// Cancel an order
|
|
395
|
+
const result = await agent.platforms.hyperliquid.deleteOrder("12345", "BTC-USD");
|
|
396
|
+
|
|
397
|
+
// View historical orders
|
|
398
|
+
const history = await agent.platforms.hyperliquid.orders();
|
|
399
|
+
|
|
400
|
+
// Check order fills
|
|
401
|
+
const fills = await agent.platforms.hyperliquid.orderFills();
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### Transfer Between Accounts
|
|
406
|
+
|
|
407
|
+
```typescript
|
|
408
|
+
async function run(agent: AgentContext): Promise<void> {
|
|
409
|
+
// Transfer USDC from spot to perp account
|
|
410
|
+
const transfer = await agent.platforms.hyperliquid.transfer({
|
|
411
|
+
amount: 1000.0,
|
|
412
|
+
toPerp: true
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
if (transfer.success) {
|
|
416
|
+
await agent.log("Transfer completed");
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
## 📊 Transaction History
|
|
422
|
+
|
|
423
|
+
Get a list of asset changes for all confirmed transactions during your session. This is useful for tracking what assets have moved in and out of the agent's wallet.
|
|
424
|
+
|
|
425
|
+
> **Note:** The system needs to index new transactions, so there may be a slight delay between when you execute a transaction and when the resulting asset changes are returned in this method. Make sure you are taking that into consideration if dealing with assets the agent just transacted with.
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
async function run(agent: AgentContext): Promise<void> {
|
|
429
|
+
// Get all transaction history for this session
|
|
430
|
+
const result = await agent.transactions();
|
|
431
|
+
|
|
432
|
+
if (result.success && result.data) {
|
|
433
|
+
await agent.log(`Found ${result.data.length} asset changes`);
|
|
434
|
+
|
|
435
|
+
// Filter for outgoing transfers
|
|
436
|
+
const outgoing = result.data.filter(
|
|
437
|
+
(change) => change.from === agent.sessionWalletAddress
|
|
438
|
+
);
|
|
439
|
+
await agent.log(`Outgoing transfers: ${outgoing.length}`);
|
|
440
|
+
|
|
441
|
+
// Calculate total USD value (where price data is available)
|
|
442
|
+
const totalUsd = result.data
|
|
443
|
+
.filter((c) => c.tokenUsdPrice)
|
|
444
|
+
.reduce((sum, c) => {
|
|
445
|
+
const amount = parseFloat(c.amount);
|
|
446
|
+
const price = parseFloat(c.tokenUsdPrice!);
|
|
447
|
+
return sum + amount * price;
|
|
448
|
+
}, 0);
|
|
449
|
+
await agent.log(`Total USD value: $${totalUsd.toFixed(2)}`);
|
|
450
|
+
|
|
451
|
+
// View specific transaction details
|
|
452
|
+
for (const change of result.data) {
|
|
453
|
+
await agent.log(`${change.network}: ${change.from} → ${change.to}`);
|
|
454
|
+
await agent.log(` Amount: ${change.amount} ${change.tokenType}`);
|
|
455
|
+
if (change.token) {
|
|
456
|
+
await agent.log(` Token: ${change.token}`);
|
|
457
|
+
}
|
|
458
|
+
await agent.log(` Tx: ${change.transactionHash}`);
|
|
459
|
+
await agent.log(` Time: ${change.timestamp}`);
|
|
460
|
+
}
|
|
461
|
+
} else {
|
|
462
|
+
await agent.log(result.error || "Failed to fetch transactions", { error: true });
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
**AssetChange Structure:**
|
|
468
|
+
|
|
469
|
+
Each asset change in the response contains:
|
|
470
|
+
- `network` - Network identifier (e.g., `"ethereum:1"`, `"solana"`)
|
|
471
|
+
- `transactionHash` - Transaction hash
|
|
472
|
+
- `from` - Sender address
|
|
473
|
+
- `to` - Recipient address
|
|
474
|
+
- `amount` - Amount transferred (as string to preserve precision)
|
|
475
|
+
- `token` - Token contract address (`null` for native tokens)
|
|
476
|
+
- `tokenId` - Token ID for NFTs (`null` for fungible tokens)
|
|
477
|
+
- `tokenType` - Token type (e.g., `"native"`, `"ERC20"`, `"ERC721"`)
|
|
478
|
+
- `tokenUsdPrice` - Token price in USD at time of transaction (`null` if unavailable)
|
|
479
|
+
- `timestamp` - Transaction timestamp
|
|
480
|
+
|
|
308
481
|
## 🚀 Sign & Send Transactions
|
|
309
482
|
|
|
310
483
|
### Ethereum (any EVM chain)
|