@t2000/sdk 0.9.8 → 0.10.0
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 +10 -29
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +10 -29
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +15 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
package/dist/adapters/index.cjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
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');
|
|
6
5
|
var aggregatorSdk = require('@cetusprotocol/aggregator-sdk');
|
|
7
6
|
var utils = require('@mysten/sui/utils');
|
|
8
7
|
|
|
@@ -260,7 +259,6 @@ var NAVI_BALANCE_DECIMALS = 9;
|
|
|
260
259
|
var CONFIG_API = "https://open-api.naviprotocol.io/api/navi/config?env=prod";
|
|
261
260
|
var POOLS_API = "https://open-api.naviprotocol.io/api/navi/pools?env=prod";
|
|
262
261
|
var PACKAGE_API = "https://open-api.naviprotocol.io/api/package";
|
|
263
|
-
var PYTH_HERMES_URL = "https://hermes.pyth.network/";
|
|
264
262
|
var packageCache = null;
|
|
265
263
|
function toBigInt(v) {
|
|
266
264
|
if (typeof v === "bigint") return v;
|
|
@@ -355,31 +353,12 @@ function addOracleUpdate(tx, config, pool) {
|
|
|
355
353
|
]
|
|
356
354
|
});
|
|
357
355
|
}
|
|
358
|
-
|
|
356
|
+
function refreshStableOracles(tx, config, pools) {
|
|
359
357
|
const stableTypes = STABLE_ASSETS.map((a) => SUPPORTED_ASSETS[a].type);
|
|
360
358
|
const stablePools = pools.filter((p) => {
|
|
361
359
|
const ct = p.suiCoinType || p.coinType || "";
|
|
362
360
|
return stableTypes.some((t) => matchesCoinType(ct, t));
|
|
363
361
|
});
|
|
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 (err) {
|
|
380
|
-
console.error("[t2000] Pyth oracle push failed, falling back to cached prices:", err.message ?? err);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
362
|
for (const pool of stablePools) {
|
|
384
363
|
addOracleUpdate(tx, config, pool);
|
|
385
364
|
}
|
|
@@ -496,12 +475,11 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
496
475
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
497
476
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
498
477
|
if (rawAmount <= 0) {
|
|
499
|
-
throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount
|
|
478
|
+
throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount rounds to zero \u2014 balance is dust`);
|
|
500
479
|
}
|
|
501
|
-
console.error(`[t2000] withdraw: asset=${asset} poolId=${pool.id} amount=${amount} deposited=${deposited} effective=${effectiveAmount} raw=${rawAmount} supplyBal=${assetState?.supplyBalance} index=${pool.currentSupplyIndex}`);
|
|
502
480
|
const tx = new transactions.Transaction();
|
|
503
481
|
tx.setSender(address);
|
|
504
|
-
|
|
482
|
+
refreshStableOracles(tx, config, pools);
|
|
505
483
|
const [balance] = tx.moveCall({
|
|
506
484
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
507
485
|
arguments: [
|
|
@@ -540,10 +518,13 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
540
518
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
541
519
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
542
520
|
if (rawAmount <= 0) {
|
|
543
|
-
|
|
521
|
+
const [coin2] = tx.moveCall({
|
|
522
|
+
target: "0x2::coin::zero",
|
|
523
|
+
typeArguments: [pool.suiCoinType]
|
|
524
|
+
});
|
|
525
|
+
return { coin: coin2, effectiveAmount: 0 };
|
|
544
526
|
}
|
|
545
|
-
|
|
546
|
-
await refreshStableOracles(tx, client, config, pools);
|
|
527
|
+
refreshStableOracles(tx, config, pools);
|
|
547
528
|
const [balance] = tx.moveCall({
|
|
548
529
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
549
530
|
arguments: [
|
|
@@ -631,7 +612,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
631
612
|
]);
|
|
632
613
|
const tx = new transactions.Transaction();
|
|
633
614
|
tx.setSender(address);
|
|
634
|
-
|
|
615
|
+
refreshStableOracles(tx, config, pools);
|
|
635
616
|
const [balance] = tx.moveCall({
|
|
636
617
|
target: `${config.package}::incentive_v3::borrow_v2`,
|
|
637
618
|
arguments: [
|