@t2000/sdk 0.56.2 → 1.0.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 +8 -25
- package/dist/adapters/descriptors.d.cts +1 -1
- package/dist/adapters/descriptors.d.ts +1 -1
- package/dist/adapters/index.cjs +22 -17
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +12 -9
- package/dist/adapters/index.d.ts +12 -9
- package/dist/adapters/index.js +22 -17
- package/dist/adapters/index.js.map +1 -1
- package/dist/browser.cjs +14 -335
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +15 -332
- package/dist/browser.js.map +1 -1
- package/dist/{descriptors-DkKhitk_.d.cts → descriptors-CDVXo3BM.d.cts} +9 -6
- package/dist/{descriptors-DkKhitk_.d.ts → descriptors-CDVXo3BM.d.ts} +9 -6
- package/dist/index.cjs +69 -436
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -20
- package/dist/index.d.ts +24 -20
- package/dist/index.js +71 -433
- package/dist/index.js.map +1 -1
- package/dist/{token-registry-BortlMRr.d.ts → token-registry-CoTPqCbS.d.ts} +19 -84
- package/dist/{token-registry-DWRdYf6m.d.cts → token-registry-DAHghHh2.d.cts} +19 -84
- package/dist/{types-DVVns7_w.d.cts → types-jAD-e7Pq.d.cts} +1 -14
- package/dist/{types-DVVns7_w.d.ts → types-jAD-e7Pq.d.ts} +1 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,14 +53,12 @@ await agent.withdraw({ amount: 25 });
|
|
|
53
53
|
|
|
54
54
|
### `T2000.init(options)` — Create a new wallet
|
|
55
55
|
|
|
56
|
-
Creates a new bank account (generates keypair, encrypts, and saves to disk).
|
|
56
|
+
Creates a new bank account (generates keypair, encrypts, and saves to disk). Fund the returned address with a small amount of SUI for gas (Mercuryo: https://exchange.mercuryo.io/?widget_id=89960d1a-8db7-49e5-8823-4c5e01c1cea2) plus USDC to transact.
|
|
57
57
|
|
|
58
58
|
```typescript
|
|
59
|
-
const { agent, address
|
|
60
|
-
pin: 'my-secret',
|
|
59
|
+
const { agent, address } = await T2000.init({
|
|
60
|
+
pin: 'my-secret', // Required — encrypts the key
|
|
61
61
|
keyPath: '~/.t2000/wallet.key', // Optional — custom key file path
|
|
62
|
-
name: 'my-agent', // Optional — agent name for sponsor registration
|
|
63
|
-
sponsored: true, // Optional — register with gas station (default: true)
|
|
64
62
|
});
|
|
65
63
|
```
|
|
66
64
|
|
|
@@ -193,14 +191,6 @@ agent.on('yield', (e) => {
|
|
|
193
191
|
console.log(`Earned: $${e.earned}, total: $${e.total}`);
|
|
194
192
|
});
|
|
195
193
|
|
|
196
|
-
agent.on('gasAutoTopUp', (e) => {
|
|
197
|
-
console.log(`Auto-topped up gas: $${e.usdcSpent} USDC → ${e.suiReceived} SUI`);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
agent.on('gasStationFallback', (e) => {
|
|
201
|
-
console.log(`Gas station fallback: ${e.reason}`);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
194
|
agent.on('error', (e) => {
|
|
205
195
|
console.error(`Error: ${e.code} — ${e.message}`);
|
|
206
196
|
});
|
|
@@ -236,20 +226,13 @@ agent.suiClient; // SuiJsonRpcClient instance
|
|
|
236
226
|
agent.signer; // Ed25519Keypair
|
|
237
227
|
```
|
|
238
228
|
|
|
239
|
-
## Gas
|
|
240
|
-
|
|
241
|
-
Every operation (send, save, borrow, repay, withdraw) routes through a 3-step gas resolution chain via `executeWithGas()`. The agent never fails due to low gas if it has USDC or the Gas Station is reachable:
|
|
229
|
+
## Gas
|
|
242
230
|
|
|
243
|
-
|
|
244
|
-
|------|----------|-----------|--------------|
|
|
245
|
-
| 1 | **Self-funded** | SUI ≥ 0.05 | Uses the agent's own SUI for gas |
|
|
246
|
-
| 2 | **Auto-topup** | SUI < 0.05, USDC ≥ $2 | Converts $1 USDC → SUI (currently disabled, falls back to step 3) |
|
|
247
|
-
| 3 | **Sponsored** | Steps 1 & 2 fail | Gas Station sponsors the full transaction |
|
|
248
|
-
| 4 | **Error** | All fail | Throws `INSUFFICIENT_GAS` |
|
|
231
|
+
Every transaction is self-funded by the agent's wallet. Keep at least ~0.05 SUI on hand. If gas runs out the SDK throws `INSUFFICIENT_GAS` — top up via Mercuryo (https://exchange.mercuryo.io/?widget_id=89960d1a-8db7-49e5-8823-4c5e01c1cea2) or any Sui exchange.
|
|
249
232
|
|
|
250
|
-
|
|
233
|
+
> **Audric web app exception:** Audric web users transact under Enoki gas sponsorship (zkLogin), so `INSUFFICIENT_GAS` is not a user-facing concern there. The SDK itself is sponsorship-agnostic — sponsorship is wired in at the host layer (Audric web), not inside `@t2000/sdk`.
|
|
251
234
|
|
|
252
|
-
**Architecture:** Each protocol operation (NAVI, send) exposes both `buildXxxTx()` (standalone transaction) and `addXxxToTx()` (composable PTB) functions. Multi-step flows compose multiple protocol calls into a single atomic PTB.
|
|
235
|
+
**Architecture:** Each protocol operation (NAVI, send) exposes both `buildXxxTx()` (standalone transaction) and `addXxxToTx()` (composable PTB) functions. Multi-step flows compose multiple protocol calls into a single atomic PTB. If any step within a PTB fails, the entire transaction reverts — no funds left in intermediate states.
|
|
253
236
|
|
|
254
237
|
## Configuration
|
|
255
238
|
|
|
@@ -311,7 +294,7 @@ try {
|
|
|
311
294
|
}
|
|
312
295
|
```
|
|
313
296
|
|
|
314
|
-
Common error codes: `INSUFFICIENT_BALANCE` · `INVALID_ADDRESS` · `INVALID_AMOUNT` · `INVALID_ASSET` · `HEALTH_FACTOR_TOO_LOW` · `NO_COLLATERAL` · `WALLET_NOT_FOUND` · `WALLET_LOCKED` · `WALLET_EXISTS` · `SIMULATION_FAILED` · `TRANSACTION_FAILED` · `PROTOCOL_PAUSED` · `INSUFFICIENT_GAS` · `WITHDRAW_WOULD_LIQUIDATE` · `
|
|
297
|
+
Common error codes: `INSUFFICIENT_BALANCE` · `INVALID_ADDRESS` · `INVALID_AMOUNT` · `INVALID_ASSET` · `HEALTH_FACTOR_TOO_LOW` · `NO_COLLATERAL` · `WALLET_NOT_FOUND` · `WALLET_LOCKED` · `WALLET_EXISTS` · `SIMULATION_FAILED` · `TRANSACTION_FAILED` · `PROTOCOL_PAUSED` · `INSUFFICIENT_GAS` · `WITHDRAW_WOULD_LIQUIDATE` · `SWAP_NO_ROUTE` · `SWAP_FAILED`
|
|
315
298
|
|
|
316
299
|
## Protocol Integration
|
|
317
300
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-
|
|
1
|
+
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-CDVXo3BM.cjs';
|
|
2
2
|
import '@mysten/sui/transactions';
|
|
3
3
|
import '@mysten/sui/jsonRpc';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-
|
|
1
|
+
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-CDVXo3BM.js';
|
|
2
2
|
import '@mysten/sui/transactions';
|
|
3
3
|
import '@mysten/sui/jsonRpc';
|
package/dist/adapters/index.cjs
CHANGED
|
@@ -4277,8 +4277,6 @@ async function refreshOracle(tx, client, address, options) {
|
|
|
4277
4277
|
const oracleOpts = {
|
|
4278
4278
|
...sdkOptions(client),
|
|
4279
4279
|
throws: false,
|
|
4280
|
-
// Pyth update uses tx.splitCoins(tx.gas, ...) which is incompatible
|
|
4281
|
-
// with sponsored transactions where tx.gas belongs to the sponsor.
|
|
4282
4280
|
updatePythPriceFeeds: !options?.skipPythUpdate
|
|
4283
4281
|
};
|
|
4284
4282
|
await mt(tx, address, pools, oracleOpts);
|
|
@@ -4469,7 +4467,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
4469
4467
|
}
|
|
4470
4468
|
const tx = new transactions.Transaction();
|
|
4471
4469
|
tx.setSender(address);
|
|
4472
|
-
await refreshOracle(tx, client, address, { skipPythUpdate: options.
|
|
4470
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
4473
4471
|
try {
|
|
4474
4472
|
const coin = await Qe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
4475
4473
|
tx.transferObjects([coin], address);
|
|
@@ -4481,7 +4479,6 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
4481
4479
|
}
|
|
4482
4480
|
async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
4483
4481
|
const asset = options.asset ?? "USDC";
|
|
4484
|
-
const sponsored = options.sponsored ?? true;
|
|
4485
4482
|
const assetInfo = resolveAssetInfo(asset);
|
|
4486
4483
|
const posResult = await getPositions(client, address);
|
|
4487
4484
|
const supply = posResult.positions.find(
|
|
@@ -4499,7 +4496,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
4499
4496
|
});
|
|
4500
4497
|
return { coin, effectiveAmount: 0 };
|
|
4501
4498
|
}
|
|
4502
|
-
await refreshOracle(tx, client, address, { skipPythUpdate:
|
|
4499
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
4503
4500
|
try {
|
|
4504
4501
|
const coin = await Qe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
4505
4502
|
return { coin, effectiveAmount };
|
|
@@ -4523,9 +4520,8 @@ async function addSaveToTx(tx, _client, _address, coin, options = {}) {
|
|
|
4523
4520
|
}
|
|
4524
4521
|
async function addRepayToTx(tx, client, address, coin, options = {}) {
|
|
4525
4522
|
const asset = options.asset ?? "USDC";
|
|
4526
|
-
const sponsored = options.sponsored ?? true;
|
|
4527
4523
|
const assetInfo = resolveAssetInfo(asset);
|
|
4528
|
-
await refreshOracle(tx, client, address, { skipPythUpdate:
|
|
4524
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
4529
4525
|
try {
|
|
4530
4526
|
await xe(tx, assetInfo.type, coin, { env: "prod" });
|
|
4531
4527
|
} catch (err) {
|
|
@@ -4542,7 +4538,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
4542
4538
|
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
4543
4539
|
const tx = new transactions.Transaction();
|
|
4544
4540
|
tx.setSender(address);
|
|
4545
|
-
await refreshOracle(tx, client, address, { skipPythUpdate: options.
|
|
4541
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
4546
4542
|
try {
|
|
4547
4543
|
const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
4548
4544
|
if (options.collectFee) {
|
|
@@ -4574,8 +4570,8 @@ async function buildRepayTx(client, address, amount, options = {}) {
|
|
|
4574
4570
|
const rawAmount = Math.min(rawRequested, Number(totalBalance));
|
|
4575
4571
|
const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
|
|
4576
4572
|
await refreshOracle(tx, client, address, {
|
|
4577
|
-
|
|
4578
|
-
|
|
4573
|
+
skipOracle: options.skipOracle,
|
|
4574
|
+
skipPythUpdate: options.skipPythUpdate
|
|
4579
4575
|
});
|
|
4580
4576
|
try {
|
|
4581
4577
|
await xe(tx, assetInfo.type, repayCoin, {
|
|
@@ -4741,7 +4737,10 @@ var NaviAdapter = class {
|
|
|
4741
4737
|
}
|
|
4742
4738
|
async buildWithdrawTx(address, amount, asset, options) {
|
|
4743
4739
|
const normalized = normalizeAsset(asset);
|
|
4744
|
-
const result = await buildWithdrawTx(this.client, address, amount, {
|
|
4740
|
+
const result = await buildWithdrawTx(this.client, address, amount, {
|
|
4741
|
+
asset: normalized,
|
|
4742
|
+
skipPythUpdate: options?.skipPythUpdate
|
|
4743
|
+
});
|
|
4745
4744
|
return { tx: result.tx, effectiveAmount: result.effectiveAmount };
|
|
4746
4745
|
}
|
|
4747
4746
|
async buildBorrowTx(address, amount, asset, options) {
|
|
@@ -4753,8 +4752,8 @@ var NaviAdapter = class {
|
|
|
4753
4752
|
const normalized = normalizeAsset(asset);
|
|
4754
4753
|
const tx = await buildRepayTx(this.client, address, amount, {
|
|
4755
4754
|
asset: normalized,
|
|
4756
|
-
|
|
4757
|
-
|
|
4755
|
+
skipOracle: options?.skipOracle,
|
|
4756
|
+
skipPythUpdate: options?.skipPythUpdate
|
|
4758
4757
|
});
|
|
4759
4758
|
return { tx };
|
|
4760
4759
|
}
|
|
@@ -4764,17 +4763,23 @@ var NaviAdapter = class {
|
|
|
4764
4763
|
async maxBorrow(address, _asset) {
|
|
4765
4764
|
return maxBorrowAmount(this.client, address);
|
|
4766
4765
|
}
|
|
4767
|
-
async addWithdrawToTx(tx, address, amount, asset) {
|
|
4766
|
+
async addWithdrawToTx(tx, address, amount, asset, options) {
|
|
4768
4767
|
const normalized = normalizeAsset(asset);
|
|
4769
|
-
return addWithdrawToTx(tx, this.client, address, amount, {
|
|
4768
|
+
return addWithdrawToTx(tx, this.client, address, amount, {
|
|
4769
|
+
asset: normalized,
|
|
4770
|
+
skipPythUpdate: options?.skipPythUpdate
|
|
4771
|
+
});
|
|
4770
4772
|
}
|
|
4771
4773
|
async addSaveToTx(tx, address, coin, asset, options) {
|
|
4772
4774
|
const normalized = normalizeAsset(asset);
|
|
4773
4775
|
return addSaveToTx(tx, this.client, address, coin, { ...options, asset: normalized });
|
|
4774
4776
|
}
|
|
4775
|
-
async addRepayToTx(tx, address, coin, asset) {
|
|
4777
|
+
async addRepayToTx(tx, address, coin, asset, options) {
|
|
4776
4778
|
const normalized = normalizeAsset(asset);
|
|
4777
|
-
return addRepayToTx(tx, this.client, address, coin, {
|
|
4779
|
+
return addRepayToTx(tx, this.client, address, coin, {
|
|
4780
|
+
asset: normalized,
|
|
4781
|
+
skipPythUpdate: options?.skipPythUpdate
|
|
4782
|
+
});
|
|
4778
4783
|
}
|
|
4779
4784
|
async getPendingRewards(address) {
|
|
4780
4785
|
return getPendingRewards(this.client, address);
|