@t2000/sdk 0.9.5 → 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/dist/adapters/index.cjs +17 -23
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +17 -23
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +17 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -602,18 +602,14 @@ function addOracleUpdate(tx, config, pool) {
|
|
|
602
602
|
]
|
|
603
603
|
});
|
|
604
604
|
}
|
|
605
|
-
function
|
|
605
|
+
function addOracleUpdatesForAllPools(tx, config, pools) {
|
|
606
606
|
const updated = /* @__PURE__ */ new Set();
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
if (updated.has(state.assetId)) continue;
|
|
611
|
-
const pool = pools.find((p) => p.id === state.assetId);
|
|
607
|
+
for (const feed of config.oracle.feeds ?? []) {
|
|
608
|
+
if (updated.has(feed.assetId)) continue;
|
|
609
|
+
const pool = pools.find((p) => p.id === feed.assetId);
|
|
612
610
|
if (!pool) continue;
|
|
613
|
-
const feed = config.oracle.feeds?.find((f2) => f2.assetId === pool.id);
|
|
614
|
-
if (!feed) continue;
|
|
615
611
|
addOracleUpdate(tx, config, pool);
|
|
616
|
-
updated.add(
|
|
612
|
+
updated.add(feed.assetId);
|
|
617
613
|
}
|
|
618
614
|
}
|
|
619
615
|
function rateToApy(rawRate) {
|
|
@@ -641,7 +637,7 @@ function compoundBalance(rawBalance, currentIndex) {
|
|
|
641
637
|
const result = (rawBalance * BigInt(currentIndex) + half) / scale;
|
|
642
638
|
return Number(result) / 10 ** NAVI_BALANCE_DECIMALS;
|
|
643
639
|
}
|
|
644
|
-
async function getUserState(client, address
|
|
640
|
+
async function getUserState(client, address) {
|
|
645
641
|
const config = await getConfig();
|
|
646
642
|
const tx = new Transaction();
|
|
647
643
|
tx.moveCall({
|
|
@@ -659,7 +655,6 @@ async function getUserState(client, address, includeZero = false) {
|
|
|
659
655
|
supplyBalance: toBigInt(s.supply_balance),
|
|
660
656
|
borrowBalance: toBigInt(s.borrow_balance)
|
|
661
657
|
}));
|
|
662
|
-
if (includeZero) return mapped;
|
|
663
658
|
return mapped.filter((s) => s.supplyBalance !== 0n || s.borrowBalance !== 0n);
|
|
664
659
|
}
|
|
665
660
|
async function fetchCoins(client, owner, coinType) {
|
|
@@ -717,20 +712,20 @@ async function buildSaveTx(client, address, amount, options = {}) {
|
|
|
717
712
|
async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
718
713
|
const asset = options.asset ?? "USDC";
|
|
719
714
|
const assetInfo = SUPPORTED_ASSETS[asset];
|
|
720
|
-
const [config, pool, pools,
|
|
715
|
+
const [config, pool, pools, states] = await Promise.all([
|
|
721
716
|
getConfig(),
|
|
722
717
|
getPool(asset),
|
|
723
718
|
getPools(),
|
|
724
|
-
getUserState(client, address
|
|
719
|
+
getUserState(client, address)
|
|
725
720
|
]);
|
|
726
|
-
const assetState =
|
|
721
|
+
const assetState = states.find((s) => s.assetId === pool.id);
|
|
727
722
|
const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex) : 0;
|
|
728
723
|
const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
|
|
729
724
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
730
725
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
731
726
|
const tx = new Transaction();
|
|
732
727
|
tx.setSender(address);
|
|
733
|
-
|
|
728
|
+
addOracleUpdatesForAllPools(tx, config, pools);
|
|
734
729
|
const [balance] = tx.moveCall({
|
|
735
730
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
736
731
|
arguments: [
|
|
@@ -757,18 +752,18 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
757
752
|
async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
758
753
|
const asset = options.asset ?? "USDC";
|
|
759
754
|
const assetInfo = SUPPORTED_ASSETS[asset];
|
|
760
|
-
const [config, pool, pools,
|
|
755
|
+
const [config, pool, pools, states] = await Promise.all([
|
|
761
756
|
getConfig(),
|
|
762
757
|
getPool(asset),
|
|
763
758
|
getPools(),
|
|
764
|
-
getUserState(client, address
|
|
759
|
+
getUserState(client, address)
|
|
765
760
|
]);
|
|
766
|
-
const assetState =
|
|
761
|
+
const assetState = states.find((s) => s.assetId === pool.id);
|
|
767
762
|
const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex) : 0;
|
|
768
763
|
const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
|
|
769
764
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
770
765
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
771
|
-
|
|
766
|
+
addOracleUpdatesForAllPools(tx, config, pools);
|
|
772
767
|
const [balance] = tx.moveCall({
|
|
773
768
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
774
769
|
arguments: [
|
|
@@ -849,15 +844,14 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
849
844
|
const asset = options.asset ?? "USDC";
|
|
850
845
|
const assetInfo = SUPPORTED_ASSETS[asset];
|
|
851
846
|
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
852
|
-
const [config, pool, pools
|
|
847
|
+
const [config, pool, pools] = await Promise.all([
|
|
853
848
|
getConfig(),
|
|
854
849
|
getPool(asset),
|
|
855
|
-
getPools()
|
|
856
|
-
getUserState(client, address, true)
|
|
850
|
+
getPools()
|
|
857
851
|
]);
|
|
858
852
|
const tx = new Transaction();
|
|
859
853
|
tx.setSender(address);
|
|
860
|
-
|
|
854
|
+
addOracleUpdatesForAllPools(tx, config, pools);
|
|
861
855
|
const [balance] = tx.moveCall({
|
|
862
856
|
target: `${config.package}::incentive_v3::borrow_v2`,
|
|
863
857
|
arguments: [
|