txflow-sdk 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/README.md +28 -10
  2. package/package.json +1 -1
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...",
@@ -324,8 +342,8 @@ Or if installed globally via npm:
324
342
 
325
343
  | Variable | Required | Description |
326
344
  |---|---|---|
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`) |
345
+ | `TXFLOW_AGENT_PRIVATE_KEY` | Yes | Agent wallet private key (trading only: orders, cancels, leverage, margin) |
346
+ | `TXFLOW_USER_PRIVATE_KEY` | No | User wallet private key (for `approve_agent`, withdrawals, and transfers) |
329
347
  | `TXFLOW_BASE_URL` | No | API URL (default: `https://testnet-api.txflow.net`) |
330
348
 
331
349
  ### Available Tools
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "txflow-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
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",