@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.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Transaction } from '@mysten/sui/transactions';
|
|
2
2
|
import { bcs } from '@mysten/sui/bcs';
|
|
3
|
-
import { SuiPriceServiceConnection, SuiPythClient } from '@pythnetwork/pyth-sui-js';
|
|
4
3
|
import { AggregatorClient, Env } from '@cetusprotocol/aggregator-sdk';
|
|
5
4
|
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
6
5
|
|
|
@@ -258,7 +257,6 @@ var NAVI_BALANCE_DECIMALS = 9;
|
|
|
258
257
|
var CONFIG_API = "https://open-api.naviprotocol.io/api/navi/config?env=prod";
|
|
259
258
|
var POOLS_API = "https://open-api.naviprotocol.io/api/navi/pools?env=prod";
|
|
260
259
|
var PACKAGE_API = "https://open-api.naviprotocol.io/api/package";
|
|
261
|
-
var PYTH_HERMES_URL = "https://hermes.pyth.network/";
|
|
262
260
|
var packageCache = null;
|
|
263
261
|
function toBigInt(v) {
|
|
264
262
|
if (typeof v === "bigint") return v;
|
|
@@ -353,31 +351,12 @@ function addOracleUpdate(tx, config, pool) {
|
|
|
353
351
|
]
|
|
354
352
|
});
|
|
355
353
|
}
|
|
356
|
-
|
|
354
|
+
function refreshStableOracles(tx, config, pools) {
|
|
357
355
|
const stableTypes = STABLE_ASSETS.map((a) => SUPPORTED_ASSETS[a].type);
|
|
358
356
|
const stablePools = pools.filter((p) => {
|
|
359
357
|
const ct = p.suiCoinType || p.coinType || "";
|
|
360
358
|
return stableTypes.some((t) => matchesCoinType(ct, t));
|
|
361
359
|
});
|
|
362
|
-
const feeds = (config.oracle.feeds ?? []).filter(
|
|
363
|
-
(f2) => stablePools.some((p) => p.id === f2.assetId)
|
|
364
|
-
);
|
|
365
|
-
if (feeds.length === 0) return;
|
|
366
|
-
const pythFeedIds = feeds.map((f2) => f2.pythPriceFeedId).filter(Boolean);
|
|
367
|
-
if (pythFeedIds.length > 0 && config.oracle.pythStateId && config.oracle.wormholeStateId) {
|
|
368
|
-
try {
|
|
369
|
-
const connection = new SuiPriceServiceConnection(PYTH_HERMES_URL);
|
|
370
|
-
const priceUpdateData = await connection.getPriceFeedsUpdateData(pythFeedIds);
|
|
371
|
-
const pythClient = new SuiPythClient(
|
|
372
|
-
client,
|
|
373
|
-
config.oracle.pythStateId,
|
|
374
|
-
config.oracle.wormholeStateId
|
|
375
|
-
);
|
|
376
|
-
await pythClient.updatePriceFeeds(tx, priceUpdateData, pythFeedIds);
|
|
377
|
-
} catch (err) {
|
|
378
|
-
console.error("[t2000] Pyth oracle push failed, falling back to cached prices:", err.message ?? err);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
360
|
for (const pool of stablePools) {
|
|
382
361
|
addOracleUpdate(tx, config, pool);
|
|
383
362
|
}
|
|
@@ -494,12 +473,11 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
494
473
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
495
474
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
496
475
|
if (rawAmount <= 0) {
|
|
497
|
-
throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount
|
|
476
|
+
throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount rounds to zero \u2014 balance is dust`);
|
|
498
477
|
}
|
|
499
|
-
console.error(`[t2000] withdraw: asset=${asset} poolId=${pool.id} amount=${amount} deposited=${deposited} effective=${effectiveAmount} raw=${rawAmount} supplyBal=${assetState?.supplyBalance} index=${pool.currentSupplyIndex}`);
|
|
500
478
|
const tx = new Transaction();
|
|
501
479
|
tx.setSender(address);
|
|
502
|
-
|
|
480
|
+
refreshStableOracles(tx, config, pools);
|
|
503
481
|
const [balance] = tx.moveCall({
|
|
504
482
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
505
483
|
arguments: [
|
|
@@ -538,10 +516,13 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
538
516
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
539
517
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
540
518
|
if (rawAmount <= 0) {
|
|
541
|
-
|
|
519
|
+
const [coin2] = tx.moveCall({
|
|
520
|
+
target: "0x2::coin::zero",
|
|
521
|
+
typeArguments: [pool.suiCoinType]
|
|
522
|
+
});
|
|
523
|
+
return { coin: coin2, effectiveAmount: 0 };
|
|
542
524
|
}
|
|
543
|
-
|
|
544
|
-
await refreshStableOracles(tx, client, config, pools);
|
|
525
|
+
refreshStableOracles(tx, config, pools);
|
|
545
526
|
const [balance] = tx.moveCall({
|
|
546
527
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
547
528
|
arguments: [
|
|
@@ -629,7 +610,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
629
610
|
]);
|
|
630
611
|
const tx = new Transaction();
|
|
631
612
|
tx.setSender(address);
|
|
632
|
-
|
|
613
|
+
refreshStableOracles(tx, config, pools);
|
|
633
614
|
const [balance] = tx.moveCall({
|
|
634
615
|
target: `${config.package}::incentive_v3::borrow_v2`,
|
|
635
616
|
arguments: [
|