@t2000/sdk 0.14.1 → 0.15.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.
@@ -1,4 +1,4 @@
1
- export { A as AdapterCapability, n as AdapterPositions, o as AdapterTxResult, C as CetusAdapter, r as HealthInfo, L as LendingAdapter, j as LendingRates, N as NaviAdapter, t as PerpsAdapter, x as ProtocolDescriptor, y as ProtocolRegistry, K as SuilendAdapter, b as SwapAdapter, O as SwapQuote, V as allDescriptors, X as cetusDescriptor, _ as naviDescriptor, a1 as sentinelDescriptor, a4 as suilendDescriptor } from '../index-B14ZyQZt.cjs';
1
+ export { A as AdapterCapability, o as AdapterPositions, p as AdapterTxResult, C as CetusAdapter, s as HealthInfo, L as LendingAdapter, k as LendingRates, N as NaviAdapter, u as PerpsAdapter, y as ProtocolDescriptor, z as ProtocolRegistry, O as SuilendAdapter, b as SwapAdapter, Q as SwapQuote, X as allDescriptors, Y as cetusDescriptor, $ as naviDescriptor, a2 as sentinelDescriptor, a5 as suilendDescriptor } from '../index-BykavuDO.cjs';
2
2
  import '@mysten/sui/transactions';
3
3
  import '@mysten/sui/jsonRpc';
4
4
  import '@mysten/sui/keypairs/ed25519';
@@ -1,4 +1,4 @@
1
- export { A as AdapterCapability, n as AdapterPositions, o as AdapterTxResult, C as CetusAdapter, r as HealthInfo, L as LendingAdapter, j as LendingRates, N as NaviAdapter, t as PerpsAdapter, x as ProtocolDescriptor, y as ProtocolRegistry, K as SuilendAdapter, b as SwapAdapter, O as SwapQuote, V as allDescriptors, X as cetusDescriptor, _ as naviDescriptor, a1 as sentinelDescriptor, a4 as suilendDescriptor } from '../index-B14ZyQZt.js';
1
+ export { A as AdapterCapability, o as AdapterPositions, p as AdapterTxResult, C as CetusAdapter, s as HealthInfo, L as LendingAdapter, k as LendingRates, N as NaviAdapter, u as PerpsAdapter, y as ProtocolDescriptor, z as ProtocolRegistry, O as SuilendAdapter, b as SwapAdapter, Q as SwapQuote, X as allDescriptors, Y as cetusDescriptor, $ as naviDescriptor, a2 as sentinelDescriptor, a5 as suilendDescriptor } from '../index-BykavuDO.js';
2
2
  import '@mysten/sui/transactions';
3
3
  import '@mysten/sui/jsonRpc';
4
4
  import '@mysten/sui/keypairs/ed25519';
@@ -39,7 +39,7 @@ var SUPPORTED_ASSETS = {
39
39
  displayName: "SUI"
40
40
  },
41
41
  BTC: {
42
- type: "0xaafb102dd0902f5055cadecd687fb5b71ca82ef0e0285d90afde828ec58ca96b::btc::BTC",
42
+ type: "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC",
43
43
  decimals: 8,
44
44
  symbol: "BTC",
45
45
  displayName: "Bitcoin"
@@ -171,7 +171,11 @@ var ProtocolRegistry = class {
171
171
  }
172
172
  async allRatesAcrossAssets() {
173
173
  const results = [];
174
- for (const asset of STABLE_ASSETS) {
174
+ const allAssets = [...STABLE_ASSETS, ...Object.keys(INVESTMENT_ASSETS)];
175
+ const seen = /* @__PURE__ */ new Set();
176
+ for (const asset of allAssets) {
177
+ if (seen.has(asset)) continue;
178
+ seen.add(asset);
175
179
  for (const adapter of this.lending.values()) {
176
180
  if (!adapter.supportedAssets.includes(asset)) continue;
177
181
  try {
@@ -336,16 +340,23 @@ function resolvePoolSymbol(pool) {
336
340
  }
337
341
  return pool.token?.symbol ?? "UNKNOWN";
338
342
  }
343
+ function resolveAssetInfo(asset) {
344
+ if (asset in SUPPORTED_ASSETS) {
345
+ const info = SUPPORTED_ASSETS[asset];
346
+ return { type: info.type, decimals: info.decimals, displayName: info.displayName };
347
+ }
348
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `Unknown asset: ${asset}`);
349
+ }
339
350
  async function getPool(asset = "USDC") {
340
351
  const pools = await getPools();
341
- const targetType = SUPPORTED_ASSETS[asset].type;
352
+ const { type: targetType, displayName } = resolveAssetInfo(asset);
342
353
  const pool = pools.find(
343
354
  (p) => matchesCoinType(p.suiCoinType || p.coinType || "", targetType)
344
355
  );
345
356
  if (!pool) {
346
357
  throw new T2000Error(
347
358
  "ASSET_NOT_SUPPORTED",
348
- `${SUPPORTED_ASSETS[asset].displayName} pool not found on NAVI. Try: ${STABLE_ASSETS.filter((a) => a !== asset).join(", ")}`
359
+ `${displayName} pool not found on NAVI`
349
360
  );
350
361
  }
351
362
  return pool;
@@ -368,13 +379,14 @@ function addOracleUpdate(tx, config, pool) {
368
379
  ]
369
380
  });
370
381
  }
371
- function refreshStableOracles(tx, config, pools) {
372
- const stableTypes = STABLE_ASSETS.map((a) => SUPPORTED_ASSETS[a].type);
373
- const stablePools = pools.filter((p) => {
382
+ function refreshOracles(tx, config, pools, opts) {
383
+ const assetsToRefresh = NAVI_SUPPORTED_ASSETS;
384
+ const targetTypes = assetsToRefresh.map((a) => SUPPORTED_ASSETS[a].type);
385
+ const matchedPools = pools.filter((p) => {
374
386
  const ct = p.suiCoinType || p.coinType || "";
375
- return stableTypes.some((t) => matchesCoinType(ct, t));
387
+ return targetTypes.some((t) => matchesCoinType(ct, t));
376
388
  });
377
- for (const pool of stablePools) {
389
+ for (const pool of matchedPools) {
378
390
  addOracleUpdate(tx, config, pool);
379
391
  }
380
392
  }
@@ -448,7 +460,7 @@ async function buildSaveTx(client, address, amount, options = {}) {
448
460
  throw new T2000Error("INVALID_AMOUNT", "Save amount must be a positive number");
449
461
  }
450
462
  const asset = options.asset ?? "USDC";
451
- const assetInfo = SUPPORTED_ASSETS[asset];
463
+ const assetInfo = resolveAssetInfo(asset);
452
464
  const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
453
465
  const [config, pool] = await Promise.all([getConfig(), getPool(asset)]);
454
466
  const coins = await fetchCoins(client, address, assetInfo.type);
@@ -477,7 +489,7 @@ async function buildSaveTx(client, address, amount, options = {}) {
477
489
  }
478
490
  async function buildWithdrawTx(client, address, amount, options = {}) {
479
491
  const asset = options.asset ?? "USDC";
480
- const assetInfo = SUPPORTED_ASSETS[asset];
492
+ const assetInfo = resolveAssetInfo(asset);
481
493
  const [config, pool, pools, states] = await Promise.all([
482
494
  getConfig(),
483
495
  getPool(asset),
@@ -494,7 +506,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
494
506
  }
495
507
  const tx = new Transaction();
496
508
  tx.setSender(address);
497
- refreshStableOracles(tx, config, pools);
509
+ refreshOracles(tx, config, pools);
498
510
  const [balance] = tx.moveCall({
499
511
  target: `${config.package}::incentive_v3::withdraw_v2`,
500
512
  arguments: [
@@ -520,7 +532,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
520
532
  }
521
533
  async function addWithdrawToTx(tx, client, address, amount, options = {}) {
522
534
  const asset = options.asset ?? "USDC";
523
- const assetInfo = SUPPORTED_ASSETS[asset];
535
+ const assetInfo = resolveAssetInfo(asset);
524
536
  const [config, pool, pools, states] = await Promise.all([
525
537
  getConfig(),
526
538
  getPool(asset),
@@ -539,7 +551,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
539
551
  });
540
552
  return { coin: coin2, effectiveAmount: 0 };
541
553
  }
542
- refreshStableOracles(tx, config, pools);
554
+ refreshOracles(tx, config, pools);
543
555
  const [balance] = tx.moveCall({
544
556
  target: `${config.package}::incentive_v3::withdraw_v2`,
545
557
  arguments: [
@@ -588,7 +600,7 @@ async function addSaveToTx(tx, _client, _address, coin, options = {}) {
588
600
  typeArguments: [pool.suiCoinType]
589
601
  });
590
602
  }
591
- async function addRepayToTx(tx, client, _address, coin, options = {}) {
603
+ async function addRepayToTx(tx, _client, _address, coin, options = {}) {
592
604
  const asset = options.asset ?? "USDC";
593
605
  const [config, pool] = await Promise.all([getConfig(), getPool(asset)]);
594
606
  addOracleUpdate(tx, config, pool);
@@ -618,7 +630,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
618
630
  throw new T2000Error("INVALID_AMOUNT", "Borrow amount must be a positive number");
619
631
  }
620
632
  const asset = options.asset ?? "USDC";
621
- const assetInfo = SUPPORTED_ASSETS[asset];
633
+ const assetInfo = resolveAssetInfo(asset);
622
634
  const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
623
635
  const [config, pool, pools] = await Promise.all([
624
636
  getConfig(),
@@ -627,7 +639,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
627
639
  ]);
628
640
  const tx = new Transaction();
629
641
  tx.setSender(address);
630
- refreshStableOracles(tx, config, pools);
642
+ refreshOracles(tx, config, pools);
631
643
  const [balance] = tx.moveCall({
632
644
  target: `${config.package}::incentive_v3::borrow_v2`,
633
645
  arguments: [
@@ -659,7 +671,7 @@ async function buildRepayTx(client, address, amount, options = {}) {
659
671
  throw new T2000Error("INVALID_AMOUNT", "Repay amount must be a positive number");
660
672
  }
661
673
  const asset = options.asset ?? "USDC";
662
- const assetInfo = SUPPORTED_ASSETS[asset];
674
+ const assetInfo = resolveAssetInfo(asset);
663
675
  const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
664
676
  const [config, pool] = await Promise.all([getConfig(), getPool(asset)]);
665
677
  const coins = await fetchCoins(client, address, assetInfo.type);
@@ -758,11 +770,12 @@ async function getHealthFactor(client, addressOrKeypair) {
758
770
  liquidationThreshold: liqThreshold
759
771
  };
760
772
  }
773
+ var NAVI_SUPPORTED_ASSETS = [...STABLE_ASSETS, "SUI", "ETH"];
761
774
  async function getRates(client) {
762
775
  try {
763
776
  const pools = await getPools();
764
777
  const result = {};
765
- for (const asset of STABLE_ASSETS) {
778
+ for (const asset of NAVI_SUPPORTED_ASSETS) {
766
779
  const targetType = SUPPORTED_ASSETS[asset].type;
767
780
  const pool = pools.find((p) => matchesCoinType(p.suiCoinType || p.coinType || "", targetType));
768
781
  if (!pool) continue;
@@ -851,7 +864,7 @@ var NaviAdapter = class {
851
864
  name = "NAVI Protocol";
852
865
  version = "1.0.0";
853
866
  capabilities = ["save", "withdraw", "borrow", "repay"];
854
- supportedAssets = [...STABLE_ASSETS];
867
+ supportedAssets = [...STABLE_ASSETS, "SUI", "ETH"];
855
868
  supportsSameAssetBorrow = true;
856
869
  client;
857
870
  async init(client) {
@@ -878,23 +891,23 @@ var NaviAdapter = class {
878
891
  return getHealthFactor(this.client, address);
879
892
  }
880
893
  async buildSaveTx(address, amount, asset, options) {
881
- const stableAsset = normalizeAsset(asset);
882
- const tx = await buildSaveTx(this.client, address, amount, { ...options, asset: stableAsset });
894
+ const normalized = normalizeAsset(asset);
895
+ const tx = await buildSaveTx(this.client, address, amount, { ...options, asset: normalized });
883
896
  return { tx };
884
897
  }
885
898
  async buildWithdrawTx(address, amount, asset) {
886
- const stableAsset = normalizeAsset(asset);
887
- const result = await buildWithdrawTx(this.client, address, amount, { asset: stableAsset });
899
+ const normalized = normalizeAsset(asset);
900
+ const result = await buildWithdrawTx(this.client, address, amount, { asset: normalized });
888
901
  return { tx: result.tx, effectiveAmount: result.effectiveAmount };
889
902
  }
890
903
  async buildBorrowTx(address, amount, asset, options) {
891
- const stableAsset = normalizeAsset(asset);
892
- const tx = await buildBorrowTx(this.client, address, amount, { ...options, asset: stableAsset });
904
+ const normalized = normalizeAsset(asset);
905
+ const tx = await buildBorrowTx(this.client, address, amount, { ...options, asset: normalized });
893
906
  return { tx };
894
907
  }
895
908
  async buildRepayTx(address, amount, asset) {
896
- const stableAsset = normalizeAsset(asset);
897
- const tx = await buildRepayTx(this.client, address, amount, { asset: stableAsset });
909
+ const normalized = normalizeAsset(asset);
910
+ const tx = await buildRepayTx(this.client, address, amount, { asset: normalized });
898
911
  return { tx };
899
912
  }
900
913
  async maxWithdraw(address, _asset) {
@@ -904,16 +917,16 @@ var NaviAdapter = class {
904
917
  return maxBorrowAmount(this.client, address);
905
918
  }
906
919
  async addWithdrawToTx(tx, address, amount, asset) {
907
- const stableAsset = normalizeAsset(asset);
908
- return addWithdrawToTx(tx, this.client, address, amount, { asset: stableAsset });
920
+ const normalized = normalizeAsset(asset);
921
+ return addWithdrawToTx(tx, this.client, address, amount, { asset: normalized });
909
922
  }
910
923
  async addSaveToTx(tx, address, coin, asset, options) {
911
- const stableAsset = normalizeAsset(asset);
912
- return addSaveToTx(tx, this.client, address, coin, { ...options, asset: stableAsset });
924
+ const normalized = normalizeAsset(asset);
925
+ return addSaveToTx(tx, this.client, address, coin, { ...options, asset: normalized });
913
926
  }
914
927
  async addRepayToTx(tx, address, coin, asset) {
915
- const stableAsset = normalizeAsset(asset);
916
- return addRepayToTx(tx, this.client, address, coin, { asset: stableAsset });
928
+ const normalized = normalizeAsset(asset);
929
+ return addRepayToTx(tx, this.client, address, coin, { asset: normalized });
917
930
  }
918
931
  };
919
932
  var DEFAULT_SLIPPAGE_BPS = 300;
@@ -1224,7 +1237,7 @@ var SuilendAdapter = class {
1224
1237
  name = "Suilend";
1225
1238
  version = "2.0.0";
1226
1239
  capabilities = ["save", "withdraw", "borrow", "repay"];
1227
- supportedAssets = [...STABLE_ASSETS];
1240
+ supportedAssets = [...STABLE_ASSETS, "SUI", "ETH", "BTC"];
1228
1241
  supportsSameAssetBorrow = false;
1229
1242
  client;
1230
1243
  publishedAt = null;