@t2000/sdk 0.8.1 → 0.8.3

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.
@@ -231,9 +231,12 @@ var ProtocolRegistry = class {
231
231
  function stableToRaw(amount, decimals) {
232
232
  return BigInt(Math.round(amount * 10 ** decimals));
233
233
  }
234
- new Map(
234
+ var ASSET_LOOKUP = new Map(
235
235
  Object.keys(SUPPORTED_ASSETS).map((k) => [k.toUpperCase(), k])
236
236
  );
237
+ function normalizeAsset(input) {
238
+ return ASSET_LOOKUP.get(input.toUpperCase()) ?? input;
239
+ }
237
240
 
238
241
  // src/protocols/protocolFee.ts
239
242
  var FEE_RATES = {
@@ -325,6 +328,13 @@ function matchesCoinType(poolType, targetType) {
325
328
  const targetSuffix = targetType.split("::").slice(1).join("::").toLowerCase();
326
329
  return poolSuffix === targetSuffix;
327
330
  }
331
+ function resolvePoolSymbol(pool) {
332
+ const coinType = pool.suiCoinType || pool.coinType || "";
333
+ for (const [key, info] of Object.entries(SUPPORTED_ASSETS)) {
334
+ if (matchesCoinType(coinType, info.type)) return key;
335
+ }
336
+ return pool.token?.symbol ?? "UNKNOWN";
337
+ }
328
338
  async function getPool(asset = "USDC") {
329
339
  const pools = await getPools();
330
340
  const targetType = SUPPORTED_ASSETS[asset].type;
@@ -661,7 +671,7 @@ async function getPositions(client, addressOrKeypair) {
661
671
  for (const state of states) {
662
672
  const pool = pools.find((p) => p.id === state.assetId);
663
673
  if (!pool) continue;
664
- const symbol = pool.token?.symbol ?? "UNKNOWN";
674
+ const symbol = resolvePoolSymbol(pool);
665
675
  const supplyBal = compoundBalance(state.supplyBalance, pool.currentSupplyIndex);
666
676
  const borrowBal = compoundBalance(state.borrowBalance, pool.currentBorrowIndex);
667
677
  if (supplyBal > 1e-4) {
@@ -738,10 +748,10 @@ var NaviAdapter = class {
738
748
  }
739
749
  async getRates(asset) {
740
750
  const rates = await getRates(this.client);
741
- const key = asset.toUpperCase();
742
- const r = rates[key];
751
+ const normalized = normalizeAsset(asset);
752
+ const r = rates[normalized];
743
753
  if (!r) throw new T2000Error("ASSET_NOT_SUPPORTED", `NAVI does not support ${asset}`);
744
- return { asset, saveApy: r.saveApy, borrowApy: r.borrowApy };
754
+ return { asset: normalized, saveApy: r.saveApy, borrowApy: r.borrowApy };
745
755
  }
746
756
  async getPositions(address) {
747
757
  const result = await getPositions(this.client, address);
@@ -754,22 +764,22 @@ var NaviAdapter = class {
754
764
  return getHealthFactor(this.client, address);
755
765
  }
756
766
  async buildSaveTx(address, amount, asset, options) {
757
- const stableAsset = asset?.toUpperCase() === "USDC" ? "USDC" : asset;
767
+ const stableAsset = normalizeAsset(asset);
758
768
  const tx = await buildSaveTx(this.client, address, amount, { ...options, asset: stableAsset });
759
769
  return { tx };
760
770
  }
761
771
  async buildWithdrawTx(address, amount, asset) {
762
- const stableAsset = asset?.toUpperCase() === "USDC" ? "USDC" : asset;
772
+ const stableAsset = normalizeAsset(asset);
763
773
  const result = await buildWithdrawTx(this.client, address, amount, { asset: stableAsset });
764
774
  return { tx: result.tx, effectiveAmount: result.effectiveAmount };
765
775
  }
766
776
  async buildBorrowTx(address, amount, asset, options) {
767
- const stableAsset = asset?.toUpperCase() === "USDC" ? "USDC" : asset;
777
+ const stableAsset = normalizeAsset(asset);
768
778
  const tx = await buildBorrowTx(this.client, address, amount, { ...options, asset: stableAsset });
769
779
  return { tx };
770
780
  }
771
781
  async buildRepayTx(address, amount, asset) {
772
- const stableAsset = asset?.toUpperCase() === "USDC" ? "USDC" : asset;
782
+ const stableAsset = normalizeAsset(asset);
773
783
  const tx = await buildRepayTx(this.client, address, amount, { asset: stableAsset });
774
784
  return { tx };
775
785
  }