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