@t2000/sdk 0.16.23 → 0.16.24

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 t2000
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -410,12 +410,17 @@ function normalizeHealthFactor(raw) {
410
410
  const v = raw / 10 ** RATE_DECIMALS;
411
411
  return v > 1e5 ? Infinity : v;
412
412
  }
413
- function compoundBalance(rawBalance, currentIndex) {
413
+ function naviStorageDecimals(poolId, tokenDecimals) {
414
+ if (poolId <= 10) return NAVI_BALANCE_DECIMALS;
415
+ return tokenDecimals;
416
+ }
417
+ function compoundBalance(rawBalance, currentIndex, pool) {
414
418
  if (!rawBalance || !currentIndex || currentIndex === "0") return 0;
415
419
  const scale = BigInt("1" + "0".repeat(RATE_DECIMALS));
416
420
  const half = scale / 2n;
417
421
  const result = (rawBalance * BigInt(currentIndex) + half) / scale;
418
- return Number(result) / 10 ** NAVI_BALANCE_DECIMALS;
422
+ const decimals = pool ? naviStorageDecimals(pool.id, pool.token.decimals) : NAVI_BALANCE_DECIMALS;
423
+ return Number(result) / 10 ** decimals;
419
424
  }
420
425
  async function getUserState(client, address) {
421
426
  const config = await getConfig();
@@ -499,7 +504,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
499
504
  getUserState(client, address)
500
505
  ]);
501
506
  const assetState = states.find((s) => s.assetId === pool.id);
502
- const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex) : 0;
507
+ const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex, pool) : 0;
503
508
  const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
504
509
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
505
510
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
@@ -542,7 +547,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
542
547
  getUserState(client, address)
543
548
  ]);
544
549
  const assetState = states.find((s) => s.assetId === pool.id);
545
- const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex) : 0;
550
+ const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex, pool) : 0;
546
551
  const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
547
552
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
548
553
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
@@ -713,8 +718,8 @@ async function getHealthFactor(client, addressOrKeypair) {
713
718
  for (const state of states) {
714
719
  const pool = pools.find((p) => p.id === state.assetId);
715
720
  if (!pool) continue;
716
- const supplyBal = compoundBalance(state.supplyBalance, pool.currentSupplyIndex);
717
- const borrowBal = compoundBalance(state.borrowBalance, pool.currentBorrowIndex);
721
+ const supplyBal = compoundBalance(state.supplyBalance, pool.currentSupplyIndex, pool);
722
+ const borrowBal = compoundBalance(state.borrowBalance, pool.currentBorrowIndex, pool);
718
723
  const price = pool.token?.price ?? 1;
719
724
  supplied += supplyBal * price;
720
725
  borrowed += borrowBal * price;
@@ -801,8 +806,8 @@ async function getPositions(client, addressOrKeypair) {
801
806
  const pool = pools.find((p) => p.id === state.assetId);
802
807
  if (!pool) continue;
803
808
  const symbol = resolvePoolSymbol(pool);
804
- const supplyBal = compoundBalance(state.supplyBalance, pool.currentSupplyIndex);
805
- const borrowBal = compoundBalance(state.borrowBalance, pool.currentBorrowIndex);
809
+ const supplyBal = compoundBalance(state.supplyBalance, pool.currentSupplyIndex, pool);
810
+ const borrowBal = compoundBalance(state.borrowBalance, pool.currentBorrowIndex, pool);
806
811
  if (supplyBal > 1e-4) {
807
812
  positions.push({
808
813
  protocol: "navi",