@t2000/sdk 0.9.4 → 0.9.6
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/README.md +10 -3
- package/dist/adapters/index.cjs +13 -17
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +13 -17
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +14 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -127,6 +127,7 @@ function mapMoveAbortCode(code) {
|
|
|
127
127
|
10: "Already at current version",
|
|
128
128
|
// NAVI Protocol abort codes
|
|
129
129
|
1502: "Oracle price is stale \u2014 try again in a moment",
|
|
130
|
+
1503: "Oracle validation failed during withdrawal \u2014 try again in a moment",
|
|
130
131
|
1600: "Health factor too low \u2014 withdrawal would risk liquidation",
|
|
131
132
|
1605: "Asset borrowing is disabled or at capacity on this protocol",
|
|
132
133
|
// Cetus DEX abort codes
|
|
@@ -603,18 +604,14 @@ function addOracleUpdate(tx, config, pool) {
|
|
|
603
604
|
]
|
|
604
605
|
});
|
|
605
606
|
}
|
|
606
|
-
function
|
|
607
|
+
function addOracleUpdatesForAllPools(tx, config, pools) {
|
|
607
608
|
const updated = /* @__PURE__ */ new Set();
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
if (updated.has(state.assetId)) continue;
|
|
612
|
-
const pool = pools.find((p) => p.id === state.assetId);
|
|
609
|
+
for (const feed of config.oracle.feeds ?? []) {
|
|
610
|
+
if (updated.has(feed.assetId)) continue;
|
|
611
|
+
const pool = pools.find((p) => p.id === feed.assetId);
|
|
613
612
|
if (!pool) continue;
|
|
614
|
-
const feed = config.oracle.feeds?.find((f2) => f2.assetId === pool.id);
|
|
615
|
-
if (!feed) continue;
|
|
616
613
|
addOracleUpdate(tx, config, pool);
|
|
617
|
-
updated.add(
|
|
614
|
+
updated.add(feed.assetId);
|
|
618
615
|
}
|
|
619
616
|
}
|
|
620
617
|
function rateToApy(rawRate) {
|
|
@@ -655,11 +652,12 @@ async function getUserState(client, address) {
|
|
|
655
652
|
});
|
|
656
653
|
const decoded = decodeDevInspect(result, bcs.bcs.vector(UserStateInfo));
|
|
657
654
|
if (!decoded) return [];
|
|
658
|
-
|
|
655
|
+
const mapped = decoded.map((s) => ({
|
|
659
656
|
assetId: s.asset_id,
|
|
660
657
|
supplyBalance: toBigInt(s.supply_balance),
|
|
661
658
|
borrowBalance: toBigInt(s.borrow_balance)
|
|
662
|
-
}))
|
|
659
|
+
}));
|
|
660
|
+
return mapped.filter((s) => s.supplyBalance !== 0n || s.borrowBalance !== 0n);
|
|
663
661
|
}
|
|
664
662
|
async function fetchCoins(client, owner, coinType) {
|
|
665
663
|
const all = [];
|
|
@@ -729,7 +727,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
729
727
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
730
728
|
const tx = new transactions.Transaction();
|
|
731
729
|
tx.setSender(address);
|
|
732
|
-
|
|
730
|
+
addOracleUpdatesForAllPools(tx, config, pools);
|
|
733
731
|
const [balance] = tx.moveCall({
|
|
734
732
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
735
733
|
arguments: [
|
|
@@ -767,7 +765,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
767
765
|
const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
|
|
768
766
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
769
767
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
770
|
-
|
|
768
|
+
addOracleUpdatesForAllPools(tx, config, pools);
|
|
771
769
|
const [balance] = tx.moveCall({
|
|
772
770
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
773
771
|
arguments: [
|
|
@@ -848,15 +846,14 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
848
846
|
const asset = options.asset ?? "USDC";
|
|
849
847
|
const assetInfo = SUPPORTED_ASSETS[asset];
|
|
850
848
|
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
851
|
-
const [config, pool, pools
|
|
849
|
+
const [config, pool, pools] = await Promise.all([
|
|
852
850
|
getConfig(),
|
|
853
851
|
getPool(asset),
|
|
854
|
-
getPools()
|
|
855
|
-
getUserState(client, address)
|
|
852
|
+
getPools()
|
|
856
853
|
]);
|
|
857
854
|
const tx = new transactions.Transaction();
|
|
858
855
|
tx.setSender(address);
|
|
859
|
-
|
|
856
|
+
addOracleUpdatesForAllPools(tx, config, pools);
|
|
860
857
|
const [balance] = tx.moveCall({
|
|
861
858
|
target: `${config.package}::incentive_v3::borrow_v2`,
|
|
862
859
|
arguments: [
|