@t2000/sdk 0.1.0

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 ADDED
@@ -0,0 +1,221 @@
1
+ # @t2000/sdk
2
+
3
+ The complete TypeScript SDK for AI agent bank accounts on Sui. Send USDC, earn yield via NAVI Protocol, swap on Cetus DEX, borrow against collateral — all from a single class.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@t2000/sdk)](https://www.npmjs.com/package/@t2000/sdk)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ **[Website](https://t2000.ai)** · **[GitHub](https://github.com/mission69b/t2000)** · **[CLI](https://www.npmjs.com/package/@t2000/cli)** · **[x402](https://www.npmjs.com/package/@t2000/x402)**
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @t2000/sdk
14
+ # or
15
+ pnpm add @t2000/sdk
16
+ # or
17
+ yarn add @t2000/sdk
18
+ ```
19
+
20
+ **Requirements:** Node.js 18+ · TypeScript 5+ (optional but recommended)
21
+
22
+ ## Quick Start
23
+
24
+ ```typescript
25
+ import { T2000 } from '@t2000/sdk';
26
+
27
+ // Create or load a bank account
28
+ const agent = await T2000.create({ passphrase: 'my-secret' });
29
+
30
+ // Check balance
31
+ const balance = await agent.balance();
32
+ console.log(`$${balance.available} USDC available`);
33
+
34
+ // Send USDC
35
+ await agent.send({ to: '0x...', amount: 10 });
36
+
37
+ // Save (earn yield via NAVI Protocol)
38
+ await agent.save({ amount: 50 });
39
+
40
+ // Swap USDC → SUI (via Cetus DEX)
41
+ await agent.swap({ from: 'USDC', to: 'SUI', amount: 5 });
42
+
43
+ // Borrow against savings
44
+ await agent.borrow({ amount: 20 });
45
+ ```
46
+
47
+ ## API Reference
48
+
49
+ ### `T2000.create(options)`
50
+
51
+ Creates a new bank account or loads an existing one.
52
+
53
+ ```typescript
54
+ const agent = await T2000.create({
55
+ passphrase: 'my-secret', // Required — encrypts/decrypts the key
56
+ network: 'mainnet', // 'mainnet' | 'testnet' (default: 'mainnet')
57
+ rpcUrl: 'https://...', // Custom RPC endpoint (optional)
58
+ keyPath: '~/.t2000/wallet.key', // Custom key file path (optional)
59
+ });
60
+ ```
61
+
62
+ ### Core Methods
63
+
64
+ | Method | Description | Returns |
65
+ |--------|-------------|---------|
66
+ | `agent.balance()` | Available USDC + savings + gas reserve | `BalanceResponse` |
67
+ | `agent.send({ to, amount })` | Transfer USDC to any Sui address | `SendResult` |
68
+ | `agent.save({ amount })` | Deposit USDC to NAVI Protocol (earn APY) | `SaveResult` |
69
+ | `agent.withdraw({ amount })` | Withdraw USDC from savings | `WithdrawResult` |
70
+ | `agent.swap({ from, to, amount })` | Swap via Cetus CLMM DEX | `SwapResult` |
71
+ | `agent.borrow({ amount })` | Borrow USDC against collateral | `BorrowResult` |
72
+ | `agent.repay({ amount })` | Repay outstanding borrows | `RepayResult` |
73
+
74
+ ### Query Methods
75
+
76
+ | Method | Description | Returns |
77
+ |--------|-------------|---------|
78
+ | `agent.healthFactor()` | Lending health factor | `HealthFactorResult` |
79
+ | `agent.earnings()` | Yield earned to date | `EarningsResult` |
80
+ | `agent.rates()` | Current save/borrow APYs | `RatesResult` |
81
+ | `agent.positions()` | All open DeFi positions | `PositionsResult` |
82
+ | `agent.fundStatus()` | Complete savings summary | `FundStatusResult` |
83
+ | `agent.maxWithdraw()` | Max safe withdrawal amount | `MaxWithdrawResult` |
84
+ | `agent.maxBorrow()` | Max safe borrow amount | `MaxBorrowResult` |
85
+ | `agent.deposit()` | Wallet address + funding instructions | `DepositInfo` |
86
+ | `agent.history()` | Transaction history | `TransactionRecord[]` |
87
+
88
+ ### Key Management
89
+
90
+ ```typescript
91
+ import {
92
+ generateKeypair,
93
+ keypairFromPrivateKey,
94
+ exportPrivateKey,
95
+ getAddress,
96
+ } from '@t2000/sdk';
97
+
98
+ // Generate a new keypair
99
+ const keypair = generateKeypair();
100
+
101
+ // Import from private key (bech32 or hex)
102
+ const imported = keypairFromPrivateKey('suiprivkey1...');
103
+
104
+ // Export private key (bech32 format)
105
+ const privkey = exportPrivateKey(keypair);
106
+
107
+ // Get the Sui address
108
+ const address = getAddress(keypair);
109
+ ```
110
+
111
+ ### Events
112
+
113
+ ```typescript
114
+ agent.on('balanceChange', (e) => {
115
+ console.log(`${e.cause}: ${e.asset} changed`);
116
+ });
117
+
118
+ agent.on('healthWarning', (e) => {
119
+ console.log(`Health factor: ${e.healthFactor}`);
120
+ });
121
+
122
+ agent.on('yield', (e) => {
123
+ console.log(`Earned: $${e.earned}`);
124
+ });
125
+ ```
126
+
127
+ ### Utility Functions
128
+
129
+ ```typescript
130
+ import {
131
+ mistToSui,
132
+ suiToMist,
133
+ usdcToRaw,
134
+ rawToUsdc,
135
+ formatUsd,
136
+ formatSui,
137
+ validateAddress,
138
+ truncateAddress,
139
+ } from '@t2000/sdk';
140
+
141
+ mistToSui(1_000_000_000n); // 1.0
142
+ usdcToRaw(10.50); // 10_500_000n
143
+ formatUsd(1234.5); // "$1,234.50"
144
+ truncateAddress('0xabcd...1234'); // "0xabcd...1234"
145
+ validateAddress('0x...'); // throws if invalid
146
+ ```
147
+
148
+ ## Gas Abstraction
149
+
150
+ Gas is handled automatically with three strategies:
151
+
152
+ 1. **Self-funded** — uses the agent's SUI balance
153
+ 2. **Auto-topup** — swaps $1 USDC → SUI when gas runs low (< 0.05 SUI)
154
+ 3. **Sponsored** — Gas Station fallback for bootstrapping (first 10 transactions)
155
+
156
+ Every transaction result includes a `gasMethod` field indicating which strategy was used.
157
+
158
+ ## Configuration
159
+
160
+ | Environment Variable | Description | Default |
161
+ |---------------------|-------------|---------|
162
+ | `T2000_PASSPHRASE` | Bank account passphrase | — |
163
+ | `T2000_NETWORK` | `mainnet` or `testnet` | `mainnet` |
164
+ | `T2000_RPC_URL` | Custom Sui RPC URL | Sui public fullnode |
165
+ | `T2000_KEY_PATH` | Path to encrypted key file | `~/.t2000/wallet.key` |
166
+ | `T2000_API_URL` | t2000 API base URL | `https://api.t2000.ai` |
167
+
168
+ ## Supported Assets
169
+
170
+ | Asset | Type | Decimals |
171
+ |-------|------|----------|
172
+ | USDC | `0xdba3...::usdc::USDC` | 6 |
173
+ | SUI | `0x2::sui::SUI` | 9 |
174
+
175
+ ## Error Handling
176
+
177
+ ```typescript
178
+ import { T2000Error } from '@t2000/sdk';
179
+
180
+ try {
181
+ await agent.send({ to: '0x...', amount: 1000 });
182
+ } catch (e) {
183
+ if (e instanceof T2000Error) {
184
+ console.log(e.code); // 'INSUFFICIENT_BALANCE'
185
+ console.log(e.message); // Human-readable message
186
+ }
187
+ }
188
+ ```
189
+
190
+ Common error codes: `INSUFFICIENT_BALANCE` · `INVALID_ADDRESS` · `INVALID_AMOUNT` · `HEALTH_FACTOR_TOO_LOW` · `NO_COLLATERAL` · `WALLET_NOT_FOUND` · `SIMULATION_FAILED` · `TRANSACTION_FAILED` · `PROTOCOL_PAUSED` · `INSUFFICIENT_GAS` · `SLIPPAGE_EXCEEDED` · `ASSET_NOT_SUPPORTED` · `WITHDRAW_WOULD_LIQUIDATE`
191
+
192
+ ## Testing
193
+
194
+ ```bash
195
+ # Run all SDK unit tests (92 tests)
196
+ pnpm --filter @t2000/sdk test
197
+ ```
198
+
199
+ | Test File | Coverage |
200
+ |-----------|----------|
201
+ | `format.test.ts` | `mistToSui`, `suiToMist`, `usdcToRaw`, `rawToUsdc`, `rawToDisplay`, `displayToRaw`, `bpsToPercent`, `formatUsd`, `formatSui`, `formatLargeNumber` |
202
+ | `sui.test.ts` | `validateAddress`, `truncateAddress` |
203
+ | `simulate.test.ts` | `throwIfSimulationFailed` (success, failure, missing error, metadata) |
204
+ | `hashcash.test.ts` | PoW generation and verification |
205
+ | `keyManager.test.ts` | Key generation, encryption, decryption, import/export |
206
+ | `errors.test.ts` | `T2000Error` construction, serialization, `mapWalletError`, `mapMoveAbortCode` |
207
+ | `navi.test.ts` | NAVI math utilities (health factor, APY, position calculations) |
208
+
209
+ ## Protocol Fees
210
+
211
+ | Operation | Fee |
212
+ |-----------|-----|
213
+ | Save (deposit) | 0.10% |
214
+ | Swap | 0.10% |
215
+ | Borrow | 0.05% |
216
+
217
+ Fees are collected by the t2000 protocol treasury on-chain.
218
+
219
+ ## License
220
+
221
+ MIT — see [LICENSE](https://github.com/mission69b/t2000/blob/main/LICENSE)