@t2000/sdk 0.9.4 → 0.9.6

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 CHANGED
@@ -232,7 +232,7 @@ Every operation (send, save, borrow, repay, withdraw) routes through a 3-step ga
232
232
 
233
233
  Every transaction result includes a `gasMethod` field (`'self-funded'` | `'auto-topup'` | `'sponsored'`) indicating which strategy was used.
234
234
 
235
- **Architecture:** Each protocol operation (NAVI, Suilend, Cetus, send) exposes a `buildXxxTx()` function that returns a `Transaction` without executing it. `executeWithGas()` then handles execution with the fallback chain. This separation ensures gas management is consistent across all operations.
235
+ **Architecture:** Each protocol operation (NAVI, Suilend, Cetus, send) exposes both `buildXxxTx()` (standalone transaction) and `addXxxToTx()` (composable PTB) functions. Multi-step operations (save with auto-convert, withdraw with auto-swap, rebalance) compose multiple protocol calls into a single atomic PTB. `executeWithGas()` handles execution with the gas fallback chain. If any step within a PTB fails, the entire transaction reverts — no funds left in intermediate states.
236
236
 
237
237
  ## Configuration
238
238
 
@@ -275,7 +275,7 @@ Common error codes: `INSUFFICIENT_BALANCE` · `INVALID_ADDRESS` · `INVALID_AMOU
275
275
  ## Testing
276
276
 
277
277
  ```bash
278
- # Run all SDK unit tests (262 tests)
278
+ # Run all SDK unit tests (367 tests)
279
279
  pnpm --filter @t2000/sdk test
280
280
  ```
281
281
 
@@ -291,6 +291,13 @@ pnpm --filter @t2000/sdk test
291
291
  | `send.test.ts` | Send transaction building and validation |
292
292
  | `manager.test.ts` | Gas resolution chain (self-fund, auto-topup, sponsored fallback) |
293
293
  | `autoTopUp.test.ts` | Auto-topup threshold logic and swap execution |
294
+ | `compliance.test.ts` | Adapter contract compliance (49 checks across all adapters) |
295
+ | `registry.test.ts` | Best rates, multi-protocol routing, quote aggregation |
296
+ | `cetus.test.ts` | Cetus swap adapter (metadata, quotes, transaction building) |
297
+ | `suilend.test.ts` | Suilend adapter (rates, positions, obligation lifecycle) |
298
+ | `t2000.integration.test.ts` | End-to-end flows (save, withdraw, borrow, repay, rebalance, auto-swap) |
299
+ | `protocolFee.test.ts` | Protocol fee calculation and collection |
300
+ | `sentinel.test.ts` | Sentinel attack flow, listing, fee parsing |
294
301
  | `serialization.test.ts` | Transaction JSON serialization roundtrip |
295
302
 
296
303
  ## Protocol Fees
@@ -299,7 +306,7 @@ pnpm --filter @t2000/sdk test
299
306
  |-----------|-----|-------|
300
307
  | Save (deposit) | 0.10% | Protocol fee on deposit |
301
308
  | Borrow | 0.05% | Protocol fee on loan |
302
- | Swap | **Free** | Only standard Cetus pool fees |
309
+ | Swap (internal) | **Free** | Cetus pool fees only; used internally by rebalance/auto-convert |
303
310
  | Withdraw | Free | |
304
311
  | Repay | Free | |
305
312
  | Send | Free | |
@@ -353,18 +353,14 @@ function addOracleUpdate(tx, config, pool) {
353
353
  ]
354
354
  });
355
355
  }
356
- function addOracleUpdatesForPositions(tx, config, pools, states, primaryPool) {
356
+ function addOracleUpdatesForAllPools(tx, config, pools) {
357
357
  const updated = /* @__PURE__ */ new Set();
358
- addOracleUpdate(tx, config, primaryPool);
359
- updated.add(primaryPool.id);
360
- for (const state of states) {
361
- if (updated.has(state.assetId)) continue;
362
- const pool = pools.find((p) => p.id === state.assetId);
358
+ for (const feed of config.oracle.feeds ?? []) {
359
+ if (updated.has(feed.assetId)) continue;
360
+ const pool = pools.find((p) => p.id === feed.assetId);
363
361
  if (!pool) continue;
364
- const feed = config.oracle.feeds?.find((f2) => f2.assetId === pool.id);
365
- if (!feed) continue;
366
362
  addOracleUpdate(tx, config, pool);
367
- updated.add(pool.id);
363
+ updated.add(feed.assetId);
368
364
  }
369
365
  }
370
366
  function rateToApy(rawRate) {
@@ -405,11 +401,12 @@ async function getUserState(client, address) {
405
401
  });
406
402
  const decoded = decodeDevInspect(result, bcs.bcs.vector(UserStateInfo));
407
403
  if (!decoded) return [];
408
- return decoded.map((s) => ({
404
+ const mapped = decoded.map((s) => ({
409
405
  assetId: s.asset_id,
410
406
  supplyBalance: toBigInt(s.supply_balance),
411
407
  borrowBalance: toBigInt(s.borrow_balance)
412
- })).filter((s) => s.supplyBalance !== 0n || s.borrowBalance !== 0n);
408
+ }));
409
+ return mapped.filter((s) => s.supplyBalance !== 0n || s.borrowBalance !== 0n);
413
410
  }
414
411
  async function fetchCoins(client, owner, coinType) {
415
412
  const all = [];
@@ -479,7 +476,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
479
476
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
480
477
  const tx = new transactions.Transaction();
481
478
  tx.setSender(address);
482
- addOracleUpdatesForPositions(tx, config, pools, states, pool);
479
+ addOracleUpdatesForAllPools(tx, config, pools);
483
480
  const [balance] = tx.moveCall({
484
481
  target: `${config.package}::incentive_v3::withdraw_v2`,
485
482
  arguments: [
@@ -517,7 +514,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
517
514
  const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
518
515
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
519
516
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
520
- addOracleUpdatesForPositions(tx, config, pools, states, pool);
517
+ addOracleUpdatesForAllPools(tx, config, pools);
521
518
  const [balance] = tx.moveCall({
522
519
  target: `${config.package}::incentive_v3::withdraw_v2`,
523
520
  arguments: [
@@ -598,15 +595,14 @@ async function buildBorrowTx(client, address, amount, options = {}) {
598
595
  const asset = options.asset ?? "USDC";
599
596
  const assetInfo = SUPPORTED_ASSETS[asset];
600
597
  const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
601
- const [config, pool, pools, states] = await Promise.all([
598
+ const [config, pool, pools] = await Promise.all([
602
599
  getConfig(),
603
600
  getPool(asset),
604
- getPools(),
605
- getUserState(client, address)
601
+ getPools()
606
602
  ]);
607
603
  const tx = new transactions.Transaction();
608
604
  tx.setSender(address);
609
- addOracleUpdatesForPositions(tx, config, pools, states, pool);
605
+ addOracleUpdatesForAllPools(tx, config, pools);
610
606
  const [balance] = tx.moveCall({
611
607
  target: `${config.package}::incentive_v3::borrow_v2`,
612
608
  arguments: [