@t2000/sdk 0.16.2 → 0.16.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 t2000
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -71,6 +71,22 @@ await agent.investUnearn({ asset: 'SUI' });
71
71
 
72
72
  // Sell position (auto-withdraws if earning first)
73
73
  await agent.investSell({ asset: 'SUI', usdAmount: 'all' });
74
+
75
+ // Buy into a strategy (single atomic PTB)
76
+ await agent.investStrategy({ strategy: 'bluechip', usdAmount: 200 });
77
+
78
+ // Check strategy status
79
+ const status = await agent.getStrategyStatus({ strategy: 'bluechip' });
80
+ console.log(`Total value: $${status.totalValue}`);
81
+
82
+ // Rebalance strategy to target weights
83
+ await agent.rebalanceStrategy({ strategy: 'bluechip' });
84
+
85
+ // Set up dollar-cost averaging
86
+ await agent.setupAutoInvest({ amount: 50, frequency: 'weekly', strategy: 'bluechip' });
87
+
88
+ // Run pending DCA purchases
89
+ await agent.runAutoInvest();
74
90
  ```
75
91
 
76
92
  ## API Reference
@@ -179,7 +195,28 @@ const agent = T2000.fromPrivateKey('suiprivkey1q...');
179
195
  | `agent.investSell({ asset, usdAmount \| 'all', maxSlippage? })` | Sell crypto back to USDC (auto-withdraws if earning) | `InvestResult` |
180
196
  | `agent.investEarn({ asset })` | Deposit invested asset into best-rate lending for yield | `InvestEarnResult` |
181
197
  | `agent.investUnearn({ asset })` | Withdraw from lending, keep in portfolio | `InvestUnearnResult` |
182
- | `agent.getPortfolio()` | Investment positions + P&L | `PortfolioResult` |
198
+ | `agent.getPortfolio()` | Investment positions + P&L (grouped by strategy) | `PortfolioResult` |
199
+
200
+ ### Strategy Methods
201
+
202
+ | Method | Description | Returns |
203
+ |--------|-------------|---------|
204
+ | `agent.investStrategy({ strategy, usdAmount, maxSlippage?, dryRun? })` | Buy into a strategy (single atomic PTB) | `StrategyBuyResult` |
205
+ | `agent.sellStrategy({ strategy, maxSlippage? })` | Sell all positions in a strategy | `StrategySellResult` |
206
+ | `agent.rebalanceStrategy({ strategy, maxSlippage?, driftThreshold? })` | Rebalance to target weights | `StrategyRebalanceResult` |
207
+ | `agent.getStrategyStatus({ strategy })` | Positions, weights, drift for a strategy | `StrategyStatusResult` |
208
+ | `agent.getStrategies()` | List all available strategies | `StrategyDefinition[]` |
209
+ | `agent.createStrategy({ name, allocations, description? })` | Create a custom strategy | `StrategyDefinition` |
210
+ | `agent.deleteStrategy({ name })` | Delete a custom strategy (no active positions) | `void` |
211
+
212
+ ### Auto-Invest (DCA) Methods
213
+
214
+ | Method | Description | Returns |
215
+ |--------|-------------|---------|
216
+ | `agent.setupAutoInvest({ amount, frequency, strategy?, asset? })` | Schedule recurring purchases | `AutoInvestSchedule` |
217
+ | `agent.getAutoInvestStatus()` | View schedules and pending runs | `AutoInvestStatus` |
218
+ | `agent.runAutoInvest()` | Execute all pending DCA purchases | `AutoInvestRunResult` |
219
+ | `agent.stopAutoInvest({ id? })` | Stop one or all schedules | `void` |
183
220
 
184
221
  ### Key Management
185
222
 
@@ -383,7 +420,7 @@ Fees are collected by the t2000 protocol treasury on-chain.
383
420
 
384
421
  ## MCP Server
385
422
 
386
- 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.
423
+ The SDK powers the [`@t2000/mcp`](https://www.npmjs.com/package/@t2000/mcp) server — 21 tools and 6 prompts for Claude Desktop, Cursor, and any MCP-compatible AI platform. Run `t2000 mcp` to start.
387
424
 
388
425
  ## License
389
426
 
@@ -1488,12 +1488,13 @@ var SuilendAdapter = class {
1488
1488
  if (!reserve) throw new T2000Error("ASSET_NOT_SUPPORTED", `${assetInfo.displayName} reserve not found on Suilend`);
1489
1489
  const caps = await this.fetchObligationCaps(address);
1490
1490
  if (caps.length === 0) throw new T2000Error("NO_COLLATERAL", "No Suilend position found");
1491
- const positions = await this.getPositions(address);
1492
- const deposited = positions.supplies.find((s) => s.asset === assetKey)?.amount ?? 0;
1491
+ const obligation = await this.fetchObligation(caps[0].obligationId);
1492
+ const dep = obligation.deposits.find((d) => d.reserveIdx === reserve.arrayIndex);
1493
+ const ratio = cTokenRatio(reserve);
1494
+ const deposited = dep ? dep.ctokenAmount * ratio / 10 ** reserve.mintDecimals : 0;
1493
1495
  const effectiveAmount = Math.min(amount, deposited);
1494
1496
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on Suilend`);
1495
- const ratio = cTokenRatio(reserve);
1496
- const ctokenAmount = Math.ceil(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
1497
+ const ctokenAmount = dep && effectiveAmount >= deposited * 0.999 ? dep.ctokenAmount : Math.floor(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
1497
1498
  const tx = new transactions.Transaction();
1498
1499
  tx.setSender(address);
1499
1500
  const [ctokens] = tx.moveCall({
@@ -1534,12 +1535,13 @@ var SuilendAdapter = class {
1534
1535
  if (!reserve) throw new T2000Error("ASSET_NOT_SUPPORTED", `${assetInfo.displayName} reserve not found on Suilend`);
1535
1536
  const caps = await this.fetchObligationCaps(address);
1536
1537
  if (caps.length === 0) throw new T2000Error("NO_COLLATERAL", "No Suilend position found");
1537
- const positions = await this.getPositions(address);
1538
- const deposited = positions.supplies.find((s) => s.asset === assetKey)?.amount ?? 0;
1538
+ const obligation = await this.fetchObligation(caps[0].obligationId);
1539
+ const dep = obligation.deposits.find((d) => d.reserveIdx === reserve.arrayIndex);
1540
+ const ratio = cTokenRatio(reserve);
1541
+ const deposited = dep ? dep.ctokenAmount * ratio / 10 ** reserve.mintDecimals : 0;
1539
1542
  const effectiveAmount = Math.min(amount, deposited);
1540
1543
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on Suilend`);
1541
- const ratio = cTokenRatio(reserve);
1542
- const ctokenAmount = Math.ceil(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
1544
+ const ctokenAmount = dep && effectiveAmount >= deposited * 0.999 ? dep.ctokenAmount : Math.floor(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
1543
1545
  const [ctokens] = tx.moveCall({
1544
1546
  target: `${pkg}::lending_market::withdraw_ctokens`,
1545
1547
  typeArguments: [LENDING_MARKET_TYPE, assetInfo.type],