@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/dist/index.js CHANGED
@@ -125,6 +125,7 @@ function mapMoveAbortCode(code) {
125
125
  10: "Already at current version",
126
126
  // NAVI Protocol abort codes
127
127
  1502: "Oracle price is stale \u2014 try again in a moment",
128
+ 1503: "Oracle validation failed during withdrawal \u2014 try again in a moment",
128
129
  1600: "Health factor too low \u2014 withdrawal would risk liquidation",
129
130
  1605: "Asset borrowing is disabled or at capacity on this protocol",
130
131
  // Cetus DEX abort codes
@@ -601,18 +602,14 @@ function addOracleUpdate(tx, config, pool) {
601
602
  ]
602
603
  });
603
604
  }
604
- function addOracleUpdatesForPositions(tx, config, pools, states, primaryPool) {
605
+ function addOracleUpdatesForAllPools(tx, config, pools) {
605
606
  const updated = /* @__PURE__ */ new Set();
606
- addOracleUpdate(tx, config, primaryPool);
607
- updated.add(primaryPool.id);
608
- for (const state of states) {
609
- if (updated.has(state.assetId)) continue;
610
- const pool = pools.find((p) => p.id === state.assetId);
607
+ for (const feed of config.oracle.feeds ?? []) {
608
+ if (updated.has(feed.assetId)) continue;
609
+ const pool = pools.find((p) => p.id === feed.assetId);
611
610
  if (!pool) continue;
612
- const feed = config.oracle.feeds?.find((f2) => f2.assetId === pool.id);
613
- if (!feed) continue;
614
611
  addOracleUpdate(tx, config, pool);
615
- updated.add(pool.id);
612
+ updated.add(feed.assetId);
616
613
  }
617
614
  }
618
615
  function rateToApy(rawRate) {
@@ -653,11 +650,12 @@ async function getUserState(client, address) {
653
650
  });
654
651
  const decoded = decodeDevInspect(result, bcs.vector(UserStateInfo));
655
652
  if (!decoded) return [];
656
- return decoded.map((s) => ({
653
+ const mapped = decoded.map((s) => ({
657
654
  assetId: s.asset_id,
658
655
  supplyBalance: toBigInt(s.supply_balance),
659
656
  borrowBalance: toBigInt(s.borrow_balance)
660
- })).filter((s) => s.supplyBalance !== 0n || s.borrowBalance !== 0n);
657
+ }));
658
+ return mapped.filter((s) => s.supplyBalance !== 0n || s.borrowBalance !== 0n);
661
659
  }
662
660
  async function fetchCoins(client, owner, coinType) {
663
661
  const all = [];
@@ -727,7 +725,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
727
725
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
728
726
  const tx = new Transaction();
729
727
  tx.setSender(address);
730
- addOracleUpdatesForPositions(tx, config, pools, states, pool);
728
+ addOracleUpdatesForAllPools(tx, config, pools);
731
729
  const [balance] = tx.moveCall({
732
730
  target: `${config.package}::incentive_v3::withdraw_v2`,
733
731
  arguments: [
@@ -765,7 +763,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
765
763
  const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
766
764
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
767
765
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
768
- addOracleUpdatesForPositions(tx, config, pools, states, pool);
766
+ addOracleUpdatesForAllPools(tx, config, pools);
769
767
  const [balance] = tx.moveCall({
770
768
  target: `${config.package}::incentive_v3::withdraw_v2`,
771
769
  arguments: [
@@ -846,15 +844,14 @@ async function buildBorrowTx(client, address, amount, options = {}) {
846
844
  const asset = options.asset ?? "USDC";
847
845
  const assetInfo = SUPPORTED_ASSETS[asset];
848
846
  const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
849
- const [config, pool, pools, states] = await Promise.all([
847
+ const [config, pool, pools] = await Promise.all([
850
848
  getConfig(),
851
849
  getPool(asset),
852
- getPools(),
853
- getUserState(client, address)
850
+ getPools()
854
851
  ]);
855
852
  const tx = new Transaction();
856
853
  tx.setSender(address);
857
- addOracleUpdatesForPositions(tx, config, pools, states, pool);
854
+ addOracleUpdatesForAllPools(tx, config, pools);
858
855
  const [balance] = tx.moveCall({
859
856
  target: `${config.package}::incentive_v3::borrow_v2`,
860
857
  arguments: [