@t2000/sdk 0.16.6 → 0.16.7

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.
@@ -1488,12 +1488,13 @@ var SuilendAdapter = class {
1488
1488
  if (!reserve) throw new T2000Error("ASSET_NOT_SUPPORTED", `${assetInfo.displayName} reserve not found on Suilend`);
1489
1489
  const caps = await this.fetchObligationCaps(address);
1490
1490
  if (caps.length === 0) throw new T2000Error("NO_COLLATERAL", "No Suilend position found");
1491
- const positions = await this.getPositions(address);
1492
- const deposited = positions.supplies.find((s) => s.asset === assetKey)?.amount ?? 0;
1491
+ const obligation = await this.fetchObligation(caps[0].obligationId);
1492
+ const dep = obligation.deposits.find((d) => d.reserveIdx === reserve.arrayIndex);
1493
+ const ratio = cTokenRatio(reserve);
1494
+ const deposited = dep ? dep.ctokenAmount * ratio / 10 ** reserve.mintDecimals : 0;
1493
1495
  const effectiveAmount = Math.min(amount, deposited);
1494
1496
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on Suilend`);
1495
- const ratio = cTokenRatio(reserve);
1496
- const ctokenAmount = Math.ceil(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
1497
+ const ctokenAmount = dep && effectiveAmount >= deposited * 0.999 ? dep.ctokenAmount : Math.floor(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
1497
1498
  const tx = new transactions.Transaction();
1498
1499
  tx.setSender(address);
1499
1500
  const [ctokens] = tx.moveCall({
@@ -1534,12 +1535,13 @@ var SuilendAdapter = class {
1534
1535
  if (!reserve) throw new T2000Error("ASSET_NOT_SUPPORTED", `${assetInfo.displayName} reserve not found on Suilend`);
1535
1536
  const caps = await this.fetchObligationCaps(address);
1536
1537
  if (caps.length === 0) throw new T2000Error("NO_COLLATERAL", "No Suilend position found");
1537
- const positions = await this.getPositions(address);
1538
- const deposited = positions.supplies.find((s) => s.asset === assetKey)?.amount ?? 0;
1538
+ const obligation = await this.fetchObligation(caps[0].obligationId);
1539
+ const dep = obligation.deposits.find((d) => d.reserveIdx === reserve.arrayIndex);
1540
+ const ratio = cTokenRatio(reserve);
1541
+ const deposited = dep ? dep.ctokenAmount * ratio / 10 ** reserve.mintDecimals : 0;
1539
1542
  const effectiveAmount = Math.min(amount, deposited);
1540
1543
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on Suilend`);
1541
- const ratio = cTokenRatio(reserve);
1542
- const ctokenAmount = Math.ceil(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
1544
+ const ctokenAmount = dep && effectiveAmount >= deposited * 0.999 ? dep.ctokenAmount : Math.floor(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
1543
1545
  const [ctokens] = tx.moveCall({
1544
1546
  target: `${pkg}::lending_market::withdraw_ctokens`,
1545
1547
  typeArguments: [LENDING_MARKET_TYPE, assetInfo.type],