@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.
- package/dist/adapters/index.cjs +30 -10
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +30 -10
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +30 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -11,6 +11,7 @@ var promises = require('fs/promises');
|
|
|
11
11
|
var path = require('path');
|
|
12
12
|
var os = require('os');
|
|
13
13
|
var bcs = require('@mysten/sui/bcs');
|
|
14
|
+
var pythSuiJs = require('@pythnetwork/pyth-sui-js');
|
|
14
15
|
var aggregatorSdk = require('@cetusprotocol/aggregator-sdk');
|
|
15
16
|
|
|
16
17
|
// src/t2000.ts
|
|
@@ -510,6 +511,7 @@ var NAVI_BALANCE_DECIMALS = 9;
|
|
|
510
511
|
var CONFIG_API = "https://open-api.naviprotocol.io/api/navi/config?env=prod";
|
|
511
512
|
var POOLS_API = "https://open-api.naviprotocol.io/api/navi/pools?env=prod";
|
|
512
513
|
var PACKAGE_API = "https://open-api.naviprotocol.io/api/package";
|
|
514
|
+
var PYTH_HERMES_URL = "https://hermes.pyth.network/";
|
|
513
515
|
var packageCache = null;
|
|
514
516
|
function toBigInt(v) {
|
|
515
517
|
if (typeof v === "bigint") return v;
|
|
@@ -604,14 +606,32 @@ function addOracleUpdate(tx, config, pool) {
|
|
|
604
606
|
]
|
|
605
607
|
});
|
|
606
608
|
}
|
|
607
|
-
function
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
609
|
+
async function refreshStableOracles(tx, client, config, pools) {
|
|
610
|
+
const stableTypes = STABLE_ASSETS.map((a) => SUPPORTED_ASSETS[a].type);
|
|
611
|
+
const stablePools = pools.filter((p) => {
|
|
612
|
+
const ct = p.suiCoinType || p.coinType || "";
|
|
613
|
+
return stableTypes.some((t) => matchesCoinType(ct, t));
|
|
614
|
+
});
|
|
615
|
+
const feeds = (config.oracle.feeds ?? []).filter(
|
|
616
|
+
(f2) => stablePools.some((p) => p.id === f2.assetId)
|
|
617
|
+
);
|
|
618
|
+
if (feeds.length === 0) return;
|
|
619
|
+
const pythFeedIds = feeds.map((f2) => f2.pythPriceFeedId).filter(Boolean);
|
|
620
|
+
if (pythFeedIds.length > 0 && config.oracle.pythStateId && config.oracle.wormholeStateId) {
|
|
621
|
+
try {
|
|
622
|
+
const connection = new pythSuiJs.SuiPriceServiceConnection(PYTH_HERMES_URL);
|
|
623
|
+
const priceUpdateData = await connection.getPriceFeedsUpdateData(pythFeedIds);
|
|
624
|
+
const pythClient = new pythSuiJs.SuiPythClient(
|
|
625
|
+
client,
|
|
626
|
+
config.oracle.pythStateId,
|
|
627
|
+
config.oracle.wormholeStateId
|
|
628
|
+
);
|
|
629
|
+
await pythClient.updatePriceFeeds(tx, priceUpdateData, pythFeedIds);
|
|
630
|
+
} catch {
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
for (const pool of stablePools) {
|
|
613
634
|
addOracleUpdate(tx, config, pool);
|
|
614
|
-
updated.add(feed.assetId);
|
|
615
635
|
}
|
|
616
636
|
}
|
|
617
637
|
function rateToApy(rawRate) {
|
|
@@ -727,7 +747,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
727
747
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
728
748
|
const tx = new transactions.Transaction();
|
|
729
749
|
tx.setSender(address);
|
|
730
|
-
|
|
750
|
+
await refreshStableOracles(tx, client, config, pools);
|
|
731
751
|
const [balance] = tx.moveCall({
|
|
732
752
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
733
753
|
arguments: [
|
|
@@ -765,7 +785,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
765
785
|
const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
|
|
766
786
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
767
787
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
768
|
-
|
|
788
|
+
await refreshStableOracles(tx, client, config, pools);
|
|
769
789
|
const [balance] = tx.moveCall({
|
|
770
790
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
771
791
|
arguments: [
|
|
@@ -853,7 +873,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
853
873
|
]);
|
|
854
874
|
const tx = new transactions.Transaction();
|
|
855
875
|
tx.setSender(address);
|
|
856
|
-
|
|
876
|
+
await refreshStableOracles(tx, client, config, pools);
|
|
857
877
|
const [balance] = tx.moveCall({
|
|
858
878
|
target: `${config.package}::incentive_v3::borrow_v2`,
|
|
859
879
|
arguments: [
|