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