@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/adapters/index.js
CHANGED
|
@@ -351,18 +351,14 @@ function addOracleUpdate(tx, config, pool) {
|
|
|
351
351
|
]
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
|
-
function
|
|
354
|
+
function addOracleUpdatesForAllPools(tx, config, pools) {
|
|
355
355
|
const updated = /* @__PURE__ */ new Set();
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (updated.has(state.assetId)) continue;
|
|
360
|
-
const pool = pools.find((p) => p.id === state.assetId);
|
|
356
|
+
for (const feed of config.oracle.feeds ?? []) {
|
|
357
|
+
if (updated.has(feed.assetId)) continue;
|
|
358
|
+
const pool = pools.find((p) => p.id === feed.assetId);
|
|
361
359
|
if (!pool) continue;
|
|
362
|
-
const feed = config.oracle.feeds?.find((f2) => f2.assetId === pool.id);
|
|
363
|
-
if (!feed) continue;
|
|
364
360
|
addOracleUpdate(tx, config, pool);
|
|
365
|
-
updated.add(
|
|
361
|
+
updated.add(feed.assetId);
|
|
366
362
|
}
|
|
367
363
|
}
|
|
368
364
|
function rateToApy(rawRate) {
|
|
@@ -403,11 +399,12 @@ async function getUserState(client, address) {
|
|
|
403
399
|
});
|
|
404
400
|
const decoded = decodeDevInspect(result, bcs.vector(UserStateInfo));
|
|
405
401
|
if (!decoded) return [];
|
|
406
|
-
|
|
402
|
+
const mapped = decoded.map((s) => ({
|
|
407
403
|
assetId: s.asset_id,
|
|
408
404
|
supplyBalance: toBigInt(s.supply_balance),
|
|
409
405
|
borrowBalance: toBigInt(s.borrow_balance)
|
|
410
|
-
}))
|
|
406
|
+
}));
|
|
407
|
+
return mapped.filter((s) => s.supplyBalance !== 0n || s.borrowBalance !== 0n);
|
|
411
408
|
}
|
|
412
409
|
async function fetchCoins(client, owner, coinType) {
|
|
413
410
|
const all = [];
|
|
@@ -477,7 +474,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
477
474
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
478
475
|
const tx = new Transaction();
|
|
479
476
|
tx.setSender(address);
|
|
480
|
-
|
|
477
|
+
addOracleUpdatesForAllPools(tx, config, pools);
|
|
481
478
|
const [balance] = tx.moveCall({
|
|
482
479
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
483
480
|
arguments: [
|
|
@@ -515,7 +512,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
515
512
|
const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
|
|
516
513
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
517
514
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
518
|
-
|
|
515
|
+
addOracleUpdatesForAllPools(tx, config, pools);
|
|
519
516
|
const [balance] = tx.moveCall({
|
|
520
517
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
521
518
|
arguments: [
|
|
@@ -596,15 +593,14 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
596
593
|
const asset = options.asset ?? "USDC";
|
|
597
594
|
const assetInfo = SUPPORTED_ASSETS[asset];
|
|
598
595
|
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
599
|
-
const [config, pool, pools
|
|
596
|
+
const [config, pool, pools] = await Promise.all([
|
|
600
597
|
getConfig(),
|
|
601
598
|
getPool(asset),
|
|
602
|
-
getPools()
|
|
603
|
-
getUserState(client, address)
|
|
599
|
+
getPools()
|
|
604
600
|
]);
|
|
605
601
|
const tx = new Transaction();
|
|
606
602
|
tx.setSender(address);
|
|
607
|
-
|
|
603
|
+
addOracleUpdatesForAllPools(tx, config, pools);
|
|
608
604
|
const [balance] = tx.moveCall({
|
|
609
605
|
target: `${config.package}::incentive_v3::borrow_v2`,
|
|
610
606
|
arguments: [
|