@t2000/sdk 0.8.3 → 0.8.4

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/index.js CHANGED
@@ -575,6 +575,20 @@ function addOracleUpdate(tx, config, pool) {
575
575
  ]
576
576
  });
577
577
  }
578
+ function addOracleUpdatesForPositions(tx, config, pools, states, primaryPool) {
579
+ const updated = /* @__PURE__ */ new Set();
580
+ addOracleUpdate(tx, config, primaryPool);
581
+ updated.add(primaryPool.id);
582
+ for (const state of states) {
583
+ if (updated.has(state.assetId)) continue;
584
+ const pool = pools.find((p) => p.id === state.assetId);
585
+ if (!pool) continue;
586
+ const feed = config.oracle.feeds?.find((f2) => f2.assetId === pool.id);
587
+ if (!feed) continue;
588
+ addOracleUpdate(tx, config, pool);
589
+ updated.add(pool.id);
590
+ }
591
+ }
578
592
  function rateToApy(rawRate) {
579
593
  if (!rawRate || rawRate === "0") return 0;
580
594
  return Number(BigInt(rawRate)) / 10 ** RATE_DECIMALS * 100;
@@ -687,7 +701,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
687
701
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
688
702
  const tx = new Transaction();
689
703
  tx.setSender(address);
690
- addOracleUpdate(tx, config, pool);
704
+ addOracleUpdatesForPositions(tx, config, pools, states, pool);
691
705
  const [balance] = tx.moveCall({
692
706
  target: `${config.package}::incentive_v3::withdraw_v2`,
693
707
  arguments: [
@@ -718,10 +732,15 @@ async function buildBorrowTx(client, address, amount, options = {}) {
718
732
  const asset = options.asset ?? "USDC";
719
733
  const assetInfo = SUPPORTED_ASSETS[asset];
720
734
  const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
721
- const [config, pool] = await Promise.all([getConfig(), getPool(asset)]);
735
+ const [config, pool, pools, states] = await Promise.all([
736
+ getConfig(),
737
+ getPool(asset),
738
+ getPools(),
739
+ getUserState(client, address)
740
+ ]);
722
741
  const tx = new Transaction();
723
742
  tx.setSender(address);
724
- addOracleUpdate(tx, config, pool);
743
+ addOracleUpdatesForPositions(tx, config, pools, states, pool);
725
744
  const [balance] = tx.moveCall({
726
745
  target: `${config.package}::incentive_v3::borrow_v2`,
727
746
  arguments: [