@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.
@@ -367,6 +367,20 @@ function addOracleUpdate(tx, config, pool) {
367
367
  ]
368
368
  });
369
369
  }
370
+ function addOracleUpdatesForPositions(tx, config, pools, states, primaryPool) {
371
+ const updated = /* @__PURE__ */ new Set();
372
+ addOracleUpdate(tx, config, primaryPool);
373
+ updated.add(primaryPool.id);
374
+ for (const state of states) {
375
+ if (updated.has(state.assetId)) continue;
376
+ const pool = pools.find((p) => p.id === state.assetId);
377
+ if (!pool) continue;
378
+ const feed = config.oracle.feeds?.find((f2) => f2.assetId === pool.id);
379
+ if (!feed) continue;
380
+ addOracleUpdate(tx, config, pool);
381
+ updated.add(pool.id);
382
+ }
383
+ }
370
384
  function rateToApy(rawRate) {
371
385
  if (!rawRate || rawRate === "0") return 0;
372
386
  return Number(BigInt(rawRate)) / 10 ** RATE_DECIMALS * 100;
@@ -479,7 +493,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
479
493
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
480
494
  const tx = new transactions.Transaction();
481
495
  tx.setSender(address);
482
- addOracleUpdate(tx, config, pool);
496
+ addOracleUpdatesForPositions(tx, config, pools, states, pool);
483
497
  const [balance] = tx.moveCall({
484
498
  target: `${config.package}::incentive_v3::withdraw_v2`,
485
499
  arguments: [
@@ -510,10 +524,15 @@ async function buildBorrowTx(client, address, amount, options = {}) {
510
524
  const asset = options.asset ?? "USDC";
511
525
  const assetInfo = SUPPORTED_ASSETS[asset];
512
526
  const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
513
- const [config, pool] = await Promise.all([getConfig(), getPool(asset)]);
527
+ const [config, pool, pools, states] = await Promise.all([
528
+ getConfig(),
529
+ getPool(asset),
530
+ getPools(),
531
+ getUserState(client, address)
532
+ ]);
514
533
  const tx = new transactions.Transaction();
515
534
  tx.setSender(address);
516
- addOracleUpdate(tx, config, pool);
535
+ addOracleUpdatesForPositions(tx, config, pools, states, pool);
517
536
  const [balance] = tx.moveCall({
518
537
  target: `${config.package}::incentive_v3::borrow_v2`,
519
538
  arguments: [