txflow-sdk 0.2.1 → 0.2.3

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 CHANGED
@@ -10,7 +10,12 @@ npm install txflow-sdk
10
10
 
11
11
  ## Quick Start
12
12
 
13
- TxFlow uses an **agent wallet pattern**: a user wallet authorizes a temporary agent wallet via EIP-712 signature, and all subsequent trading actions are signed by the agent wallet.
13
+ TxFlow uses an **agent wallet pattern** with two distinct wallets:
14
+
15
+ - **User Wallet**: The main wallet that owns the funds. Required for authorization, withdrawals, and transfers.
16
+ - **Agent Wallet**: A temporary wallet authorized by the user wallet. It only has **trading permissions** (place/cancel/modify orders, update leverage and margin mode). It cannot move funds.
17
+
18
+ The user wallet signs an `ApproveAgent` message to grant the agent wallet trading rights. After that, all trading operations use the agent wallet's key.
14
19
 
15
20
  ```typescript
16
21
  import { TxFlowClient } from "txflow-sdk";
@@ -23,10 +28,10 @@ const client = new TxFlowClient({
23
28
  privateKey: agentWallet.privateKey,
24
29
  });
25
30
 
26
- // Step 1: Authorize the agent wallet (one-time)
31
+ // Step 1: User wallet authorizes the agent wallet (one-time)
27
32
  await client.approveAgent(userWallet);
28
33
 
29
- // Step 2: Place orders using the agent wallet
34
+ // Step 2: Agent wallet places orders (no user wallet needed)
30
35
  const result = await client.placeOrder({
31
36
  asset: 1, // Asset index (use getPerpMeta to look up)
32
37
  isBuy: true,
@@ -35,13 +40,16 @@ const result = await client.placeOrder({
35
40
  reduceOnly: false,
36
41
  timeInForce: "gtc",
37
42
  });
43
+
44
+ // User wallet is needed for fund operations
45
+ await client.withdraw(userWallet, { destination: "0x...", amount: "100" });
38
46
  ```
39
47
 
40
48
  ## Configuration
41
49
 
42
50
  ```typescript
43
51
  const client = new TxFlowClient({
44
- privateKey: "0x...", // Agent wallet private key (required)
52
+ privateKey: "0x...", // Agent wallet private key (required, trading only)
45
53
  baseUrl: "https://testnet-api.txflow.net", // API base URL (optional)
46
54
  isMainnet: true, // Source identifier for signing (optional, default: true)
47
55
  vaultAddress: null, // Vault address if applicable (optional)
@@ -67,7 +75,9 @@ All signing logic, EIP-712 domains, and API calls adapt automatically based on t
67
75
 
68
76
  ## API Reference
69
77
 
70
- ### Trading
78
+ ### Trading (Agent Wallet)
79
+
80
+ These methods are signed by the **agent wallet** (the `privateKey` provided in the constructor). The agent must be authorized by the user wallet via `approveAgent` before use.
71
81
 
72
82
  #### `placeOrder(params)`
73
83
 
@@ -118,7 +128,7 @@ await client.modifyOrder({
118
128
  });
119
129
  ```
120
130
 
121
- ### Account Settings
131
+ ### Account Settings (Agent Wallet)
122
132
 
123
133
  #### `updateLeverage(params)`
124
134
 
@@ -132,12 +142,14 @@ await client.updateLeverage({ asset: 1, leverage: 10 });
132
142
  await client.updateMarginMode({ asset: 1, isCross: true });
133
143
  ```
134
144
 
135
- ### User Actions
145
+ ### User Actions (User Wallet)
136
146
 
137
- These methods require the **user wallet** (not the agent wallet).
147
+ These methods require the **user wallet** to be passed explicitly. The user wallet is the main wallet that owns the funds and has full account control. The agent wallet **cannot** perform these operations.
138
148
 
139
149
  #### `approveAgent(userWallet, params?)`
140
150
 
151
+ Authorizes the agent wallet for trading. Must be called once before the agent can trade.
152
+
141
153
  ```typescript
142
154
  await client.approveAgent(userWallet, {
143
155
  agentAddress: "0x...", // defaults to SDK agent address
@@ -147,6 +159,8 @@ await client.approveAgent(userWallet, {
147
159
 
148
160
  #### `withdraw(userWallet, params)`
149
161
 
162
+ Withdraw USDC to an external address. Minimum amount is 2 USDC.
163
+
150
164
  ```typescript
151
165
  await client.withdraw(userWallet, {
152
166
  destination: "0x...",
@@ -156,6 +170,8 @@ await client.withdraw(userWallet, {
156
170
 
157
171
  #### `transferToken(userWallet, params)`
158
172
 
173
+ Transfer USDC between your own perp and spot accounts.
174
+
159
175
  ```typescript
160
176
  await client.transferToken(userWallet, {
161
177
  amount: "100",
@@ -166,6 +182,8 @@ await client.transferToken(userWallet, {
166
182
 
167
183
  #### `sendToken(userWallet, params)`
168
184
 
185
+ Send USDC to another user's address.
186
+
169
187
  ```typescript
170
188
  await client.sendToken(userWallet, {
171
189
  toAddress: "0x...",
@@ -188,10 +206,18 @@ const candles = await client.getCandleSnapshot({
188
206
  endTime: Date.now(),
189
207
  });
190
208
  const fees = await client.getUserFees("0xUSER_ADDRESS");
191
- const funding = await client.getFundingHistory({
209
+ ```
210
+
211
+ ### History
212
+
213
+ ```typescript
214
+ const orderHistory = await client.getOrderHistory({
192
215
  user: "0xUSER_ADDRESS",
193
- startTime: Date.now() - 86400000,
216
+ startTime: Date.now() - 30 * 86400000,
194
217
  });
218
+ const tradeHistory = await client.getTradeHistory("0xUSER_ADDRESS");
219
+ const fundingHistory = await client.getFundingHistory("0xUSER_ADDRESS");
220
+ const ledger = await client.getUserNonFundingLedgerUpdates("0xUSER_ADDRESS");
195
221
  ```
196
222
 
197
223
  ### Testnet Faucet
@@ -324,8 +350,8 @@ Or if installed globally via npm:
324
350
 
325
351
  | Variable | Required | Description |
326
352
  |---|---|---|
327
- | `TXFLOW_AGENT_PRIVATE_KEY` | Yes | Agent wallet private key for signing trades |
328
- | `TXFLOW_USER_PRIVATE_KEY` | No | User wallet private key (only for `approve_agent`) |
353
+ | `TXFLOW_AGENT_PRIVATE_KEY` | Yes | Agent wallet private key (trading only: orders, cancels, leverage, margin) |
354
+ | `TXFLOW_USER_PRIVATE_KEY` | No | User wallet private key (for `approve_agent`, withdrawals, and transfers) |
329
355
  | `TXFLOW_BASE_URL` | No | API URL (default: `https://testnet-api.txflow.net`) |
330
356
 
331
357
  ### Available Tools
package/dist/client.d.ts CHANGED
@@ -51,17 +51,20 @@ export declare class TxFlowClient {
51
51
  reduceOnly: boolean;
52
52
  }): Promise<InfoResponse>;
53
53
  getUserState(user: string): Promise<InfoResponse>;
54
- getFundingHistory(params: {
55
- user: string;
56
- startTime: number;
57
- endTime?: number;
58
- }): Promise<InfoResponse>;
54
+ getFundingHistory(user: string): Promise<InfoResponse>;
59
55
  getUserFees(user: string): Promise<InfoResponse>;
60
56
  getReferral(user: string): Promise<InfoResponse>;
61
57
  getPerpMeta(dex?: string): Promise<InfoResponse>;
62
58
  getSpotMeta(dex?: string): Promise<InfoResponse>;
63
59
  getActiveAssetData(user: string, coin: string): Promise<InfoResponse>;
64
60
  getL2Book(coin: string | number): Promise<InfoResponse>;
61
+ getOrderHistory(params: {
62
+ user: string;
63
+ startTime: number;
64
+ endTime?: number;
65
+ }): Promise<InfoResponse>;
66
+ getTradeHistory(user: string): Promise<InfoResponse>;
67
+ getUserNonFundingLedgerUpdates(user: string): Promise<InfoResponse>;
65
68
  getCandleSnapshot(params: {
66
69
  coin: string;
67
70
  interval: string;
package/dist/client.js CHANGED
@@ -344,8 +344,8 @@ export class TxFlowClient {
344
344
  async getUserState(user) {
345
345
  return this.postInfo({ type: "clearinghouseState", user });
346
346
  }
347
- async getFundingHistory(params) {
348
- return this.postInfo({ type: "userfunding", ...params });
347
+ async getFundingHistory(user) {
348
+ return this.postInfo({ type: "userFundings", user });
349
349
  }
350
350
  async getUserFees(user) {
351
351
  return this.postInfo({ type: "userfees", user });
@@ -365,6 +365,20 @@ export class TxFlowClient {
365
365
  async getL2Book(coin) {
366
366
  return this.postInfo({ type: "l2book", coin: String(coin) });
367
367
  }
368
+ async getOrderHistory(params) {
369
+ return this.postInfo({
370
+ type: "historicalOrders",
371
+ user: params.user,
372
+ startTime: params.startTime,
373
+ endTime: params.endTime ?? Date.now(),
374
+ });
375
+ }
376
+ async getTradeHistory(user) {
377
+ return this.postInfo({ type: "userFills", user });
378
+ }
379
+ async getUserNonFundingLedgerUpdates(user) {
380
+ return this.postInfo({ type: "userNonFundingLedgerUpdates", user });
381
+ }
368
382
  async getCandleSnapshot(params) {
369
383
  return this.postInfo({ type: "candleSnapshot", ...params });
370
384
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "txflow-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "TypeScript SDK for TxFlow perpetual DEX with EIP-712 signing and MCP server",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",