@t2000/sdk 0.13.0 → 0.14.1
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 +37 -9
- package/dist/adapters/index.cjs +21 -4
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +21 -4
- package/dist/adapters/index.js.map +1 -1
- package/dist/{index-Dd4EvUGr.d.cts → index-B14ZyQZt.d.cts} +226 -129
- package/dist/{index-Dd4EvUGr.d.ts → index-B14ZyQZt.d.ts} +226 -129
- package/dist/index.cjs +408 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +134 -57
- package/dist/index.d.ts +134 -57
- package/dist/index.js +402 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,6 +53,18 @@ await agent.rebalance(); // execute
|
|
|
53
53
|
|
|
54
54
|
// Withdraw — always returns USDC (auto-swaps non-USDC positions)
|
|
55
55
|
await agent.withdraw({ amount: 25 });
|
|
56
|
+
|
|
57
|
+
// Invest in crypto assets
|
|
58
|
+
await agent.investBuy({ asset: 'SUI', usdAmount: 100 });
|
|
59
|
+
await agent.investBuy({ asset: 'BTC', usdAmount: 500 });
|
|
60
|
+
await agent.investBuy({ asset: 'ETH', usdAmount: 200 });
|
|
61
|
+
|
|
62
|
+
// Check portfolio
|
|
63
|
+
const portfolio = await agent.getPortfolio();
|
|
64
|
+
console.log(`P&L: ${portfolio.unrealizedPnL}`);
|
|
65
|
+
|
|
66
|
+
// Sell position
|
|
67
|
+
await agent.investSell({ asset: 'SUI', usdAmount: 'all' });
|
|
56
68
|
```
|
|
57
69
|
|
|
58
70
|
## API Reference
|
|
@@ -153,6 +165,14 @@ const agent = T2000.fromPrivateKey('suiprivkey1q...');
|
|
|
153
165
|
|
|
154
166
|
**Types:** `SafeguardConfig` — `{ maxPerTx?, maxDailySend?, locked? }` · `SafeguardError` — thrown when limits exceeded or agent locked
|
|
155
167
|
|
|
168
|
+
### Investment Methods
|
|
169
|
+
|
|
170
|
+
| Method | Description | Returns |
|
|
171
|
+
|--------|-------------|---------|
|
|
172
|
+
| `agent.investBuy({ asset, usdAmount, maxSlippage? })` | Buy crypto asset with USD | `InvestResult` |
|
|
173
|
+
| `agent.investSell({ asset, usdAmount \| 'all', maxSlippage? })` | Sell crypto back to USDC | `InvestResult` |
|
|
174
|
+
| `agent.getPortfolio()` | Investment positions + P&L | `PortfolioResult` |
|
|
175
|
+
|
|
156
176
|
### Key Management
|
|
157
177
|
|
|
158
178
|
```typescript
|
|
@@ -228,6 +248,7 @@ import {
|
|
|
228
248
|
rawToUsdc,
|
|
229
249
|
formatUsd,
|
|
230
250
|
formatSui,
|
|
251
|
+
formatAssetAmount,
|
|
231
252
|
validateAddress,
|
|
232
253
|
truncateAddress,
|
|
233
254
|
} from '@t2000/sdk';
|
|
@@ -237,6 +258,11 @@ usdcToRaw(10.50); // 10_500_000n
|
|
|
237
258
|
formatUsd(1234.5); // "$1234.50"
|
|
238
259
|
truncateAddress('0xabcdef...1234'); // "0xabcd...1234"
|
|
239
260
|
validateAddress('0x...'); // throws if invalid
|
|
261
|
+
|
|
262
|
+
// Asset-aware decimal formatting
|
|
263
|
+
formatAssetAmount('BTC', 0.00123456); // "0.00123456" (8 decimals)
|
|
264
|
+
formatAssetAmount('ETH', 1.5); // "1.50000000" (8 decimals)
|
|
265
|
+
formatAssetAmount('SUI', 105.26); // "105.260000000" (9 decimals)
|
|
240
266
|
```
|
|
241
267
|
|
|
242
268
|
### Advanced: Exposed Internals
|
|
@@ -278,13 +304,15 @@ Save auto-converts non-USDC wallet stablecoins, withdraw auto-swaps non-USDC
|
|
|
278
304
|
positions back to USDC, and repay auto-swaps USDC to the borrowed asset if
|
|
279
305
|
debt is non-USDC (from rebalance). Rebalance optimizes across all stablecoins internally.
|
|
280
306
|
|
|
281
|
-
| Asset | Display | Type | Decimals | Save | Borrow | Withdraw | Rebalance (internal) |
|
|
282
|
-
|
|
283
|
-
| USDC | USDC | `0xdba3...::usdc::USDC` | 6 | ✅ | ✅ | ✅ (always returns USDC) | ✅ |
|
|
284
|
-
| USDT | suiUSDT | `0x375f...::usdt::USDT` | 6 | — (via rebalance) | — | — | ✅ |
|
|
285
|
-
| USDe | suiUSDe | `0x41d5...::sui_usde::SUI_USDE` | 6 | — (via rebalance) | — | — | ✅ |
|
|
286
|
-
| USDsui | USDsui | `0x44f8...::usdsui::USDSUI` | 6 | — (via rebalance) | — | — | ✅ |
|
|
287
|
-
| SUI | SUI | `0x2::sui::SUI` | 9 | — | — | — | — |
|
|
307
|
+
| Asset | Display | Type | Decimals | Save | Borrow | Withdraw | Rebalance (internal) | Invest |
|
|
308
|
+
|-------|---------|------|----------|------|--------|----------|---------------------|--------|
|
|
309
|
+
| USDC | USDC | `0xdba3...::usdc::USDC` | 6 | ✅ | ✅ | ✅ (always returns USDC) | ✅ | — |
|
|
310
|
+
| USDT | suiUSDT | `0x375f...::usdt::USDT` | 6 | — (via rebalance) | — | — | ✅ | — |
|
|
311
|
+
| USDe | suiUSDe | `0x41d5...::sui_usde::SUI_USDE` | 6 | — (via rebalance) | — | — | ✅ | — |
|
|
312
|
+
| USDsui | USDsui | `0x44f8...::usdsui::USDSUI` | 6 | — (via rebalance) | — | — | ✅ | — |
|
|
313
|
+
| SUI | SUI | `0x2::sui::SUI` | 9 | — | — | — | — | ✅ |
|
|
314
|
+
| BTC | Bitcoin | `0xaafb...::btc::BTC` | 8 | — | — | — | — | ✅ |
|
|
315
|
+
| ETH | Ethereum | `0xd0e8...::eth::ETH` | 8 | — | — | — | — | ✅ |
|
|
288
316
|
|
|
289
317
|
## Error Handling
|
|
290
318
|
|
|
@@ -306,7 +334,7 @@ Common error codes: `INSUFFICIENT_BALANCE` · `INVALID_ADDRESS` · `INVALID_AMOU
|
|
|
306
334
|
## Testing
|
|
307
335
|
|
|
308
336
|
```bash
|
|
309
|
-
# Run all SDK unit tests (
|
|
337
|
+
# Run all SDK unit tests (469 tests)
|
|
310
338
|
pnpm --filter @t2000/sdk test
|
|
311
339
|
```
|
|
312
340
|
|
|
@@ -347,7 +375,7 @@ Fees are collected by the t2000 protocol treasury on-chain.
|
|
|
347
375
|
|
|
348
376
|
## MCP Server
|
|
349
377
|
|
|
350
|
-
The SDK powers the [`@t2000/mcp`](https://www.npmjs.com/package/@t2000/mcp) server —
|
|
378
|
+
The SDK powers the [`@t2000/mcp`](https://www.npmjs.com/package/@t2000/mcp) server — 19 tools and 6 prompts for Claude Desktop, Cursor, and any MCP-compatible AI platform. Run `t2000 mcp` to start.
|
|
351
379
|
|
|
352
380
|
## License
|
|
353
381
|
|
package/dist/adapters/index.cjs
CHANGED
|
@@ -39,6 +39,18 @@ var SUPPORTED_ASSETS = {
|
|
|
39
39
|
decimals: 9,
|
|
40
40
|
symbol: "SUI",
|
|
41
41
|
displayName: "SUI"
|
|
42
|
+
},
|
|
43
|
+
BTC: {
|
|
44
|
+
type: "0xaafb102dd0902f5055cadecd687fb5b71ca82ef0e0285d90afde828ec58ca96b::btc::BTC",
|
|
45
|
+
decimals: 8,
|
|
46
|
+
symbol: "BTC",
|
|
47
|
+
displayName: "Bitcoin"
|
|
48
|
+
},
|
|
49
|
+
ETH: {
|
|
50
|
+
type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH",
|
|
51
|
+
decimals: 8,
|
|
52
|
+
symbol: "ETH",
|
|
53
|
+
displayName: "Ethereum"
|
|
42
54
|
}
|
|
43
55
|
};
|
|
44
56
|
var STABLE_ASSETS = ["USDC", "USDT", "USDe", "USDsui"];
|
|
@@ -48,6 +60,11 @@ var T2000_TREASURY_ID = process.env.T2000_TREASURY_ID ?? "0x3bb501b8300125dca590
|
|
|
48
60
|
process.env.T2000_API_URL ?? "https://api.t2000.ai";
|
|
49
61
|
var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
|
|
50
62
|
var CETUS_PACKAGE = "0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb";
|
|
63
|
+
var INVESTMENT_ASSETS = {
|
|
64
|
+
SUI: SUPPORTED_ASSETS.SUI,
|
|
65
|
+
BTC: SUPPORTED_ASSETS.BTC,
|
|
66
|
+
ETH: SUPPORTED_ASSETS.ETH
|
|
67
|
+
};
|
|
51
68
|
var SENTINEL = {
|
|
52
69
|
PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7"};
|
|
53
70
|
|
|
@@ -1075,10 +1092,10 @@ var CetusAdapter = class {
|
|
|
1075
1092
|
};
|
|
1076
1093
|
}
|
|
1077
1094
|
getSupportedPairs() {
|
|
1078
|
-
const pairs = [
|
|
1079
|
-
|
|
1080
|
-
{ from: "
|
|
1081
|
-
|
|
1095
|
+
const pairs = [];
|
|
1096
|
+
for (const asset of Object.keys(INVESTMENT_ASSETS)) {
|
|
1097
|
+
pairs.push({ from: "USDC", to: asset }, { from: asset, to: "USDC" });
|
|
1098
|
+
}
|
|
1082
1099
|
for (const a of STABLE_ASSETS) {
|
|
1083
1100
|
for (const b of STABLE_ASSETS) {
|
|
1084
1101
|
if (a !== b) pairs.push({ from: a, to: b });
|