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