@t2000/sdk 0.9.6 → 0.9.7

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.
@@ -2,6 +2,7 @@
2
2
 
3
3
  var transactions = require('@mysten/sui/transactions');
4
4
  var bcs = require('@mysten/sui/bcs');
5
+ var pythSuiJs = require('@pythnetwork/pyth-sui-js');
5
6
  var aggregatorSdk = require('@cetusprotocol/aggregator-sdk');
6
7
  var utils = require('@mysten/sui/utils');
7
8
 
@@ -259,6 +260,7 @@ var NAVI_BALANCE_DECIMALS = 9;
259
260
  var CONFIG_API = "https://open-api.naviprotocol.io/api/navi/config?env=prod";
260
261
  var POOLS_API = "https://open-api.naviprotocol.io/api/navi/pools?env=prod";
261
262
  var PACKAGE_API = "https://open-api.naviprotocol.io/api/package";
263
+ var PYTH_HERMES_URL = "https://hermes.pyth.network/";
262
264
  var packageCache = null;
263
265
  function toBigInt(v) {
264
266
  if (typeof v === "bigint") return v;
@@ -353,14 +355,32 @@ function addOracleUpdate(tx, config, pool) {
353
355
  ]
354
356
  });
355
357
  }
356
- function addOracleUpdatesForAllPools(tx, config, pools) {
357
- const updated = /* @__PURE__ */ new Set();
358
- for (const feed of config.oracle.feeds ?? []) {
359
- if (updated.has(feed.assetId)) continue;
360
- const pool = pools.find((p) => p.id === feed.assetId);
361
- if (!pool) continue;
358
+ async function refreshStableOracles(tx, client, config, pools) {
359
+ const stableTypes = STABLE_ASSETS.map((a) => SUPPORTED_ASSETS[a].type);
360
+ const stablePools = pools.filter((p) => {
361
+ const ct = p.suiCoinType || p.coinType || "";
362
+ return stableTypes.some((t) => matchesCoinType(ct, t));
363
+ });
364
+ const feeds = (config.oracle.feeds ?? []).filter(
365
+ (f2) => stablePools.some((p) => p.id === f2.assetId)
366
+ );
367
+ if (feeds.length === 0) return;
368
+ const pythFeedIds = feeds.map((f2) => f2.pythPriceFeedId).filter(Boolean);
369
+ if (pythFeedIds.length > 0 && config.oracle.pythStateId && config.oracle.wormholeStateId) {
370
+ try {
371
+ const connection = new pythSuiJs.SuiPriceServiceConnection(PYTH_HERMES_URL);
372
+ const priceUpdateData = await connection.getPriceFeedsUpdateData(pythFeedIds);
373
+ const pythClient = new pythSuiJs.SuiPythClient(
374
+ client,
375
+ config.oracle.pythStateId,
376
+ config.oracle.wormholeStateId
377
+ );
378
+ await pythClient.updatePriceFeeds(tx, priceUpdateData, pythFeedIds);
379
+ } catch {
380
+ }
381
+ }
382
+ for (const pool of stablePools) {
362
383
  addOracleUpdate(tx, config, pool);
363
- updated.add(feed.assetId);
364
384
  }
365
385
  }
366
386
  function rateToApy(rawRate) {
@@ -476,7 +496,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
476
496
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
477
497
  const tx = new transactions.Transaction();
478
498
  tx.setSender(address);
479
- addOracleUpdatesForAllPools(tx, config, pools);
499
+ await refreshStableOracles(tx, client, config, pools);
480
500
  const [balance] = tx.moveCall({
481
501
  target: `${config.package}::incentive_v3::withdraw_v2`,
482
502
  arguments: [
@@ -514,7 +534,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
514
534
  const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
515
535
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
516
536
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
517
- addOracleUpdatesForAllPools(tx, config, pools);
537
+ await refreshStableOracles(tx, client, config, pools);
518
538
  const [balance] = tx.moveCall({
519
539
  target: `${config.package}::incentive_v3::withdraw_v2`,
520
540
  arguments: [
@@ -602,7 +622,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
602
622
  ]);
603
623
  const tx = new transactions.Transaction();
604
624
  tx.setSender(address);
605
- addOracleUpdatesForAllPools(tx, config, pools);
625
+ await refreshStableOracles(tx, client, config, pools);
606
626
  const [balance] = tx.moveCall({
607
627
  target: `${config.package}::incentive_v3::borrow_v2`,
608
628
  arguments: [