@t2000/sdk 0.16.6 → 0.16.8

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
@@ -2127,12 +2127,13 @@ var SuilendAdapter = class {
2127
2127
  if (!reserve) throw new T2000Error("ASSET_NOT_SUPPORTED", `${assetInfo.displayName} reserve not found on Suilend`);
2128
2128
  const caps = await this.fetchObligationCaps(address);
2129
2129
  if (caps.length === 0) throw new T2000Error("NO_COLLATERAL", "No Suilend position found");
2130
- const positions = await this.getPositions(address);
2131
- const deposited = positions.supplies.find((s) => s.asset === assetKey)?.amount ?? 0;
2130
+ const obligation = await this.fetchObligation(caps[0].obligationId);
2131
+ const dep = obligation.deposits.find((d) => d.reserveIdx === reserve.arrayIndex);
2132
+ const ratio = cTokenRatio(reserve);
2133
+ const deposited = dep ? dep.ctokenAmount * ratio / 10 ** reserve.mintDecimals : 0;
2132
2134
  const effectiveAmount = Math.min(amount, deposited);
2133
2135
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on Suilend`);
2134
- const ratio = cTokenRatio(reserve);
2135
- const ctokenAmount = Math.ceil(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
2136
+ const ctokenAmount = dep && effectiveAmount >= deposited * 0.999 ? dep.ctokenAmount : Math.floor(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
2136
2137
  const tx = new Transaction();
2137
2138
  tx.setSender(address);
2138
2139
  const [ctokens] = tx.moveCall({
@@ -2173,12 +2174,13 @@ var SuilendAdapter = class {
2173
2174
  if (!reserve) throw new T2000Error("ASSET_NOT_SUPPORTED", `${assetInfo.displayName} reserve not found on Suilend`);
2174
2175
  const caps = await this.fetchObligationCaps(address);
2175
2176
  if (caps.length === 0) throw new T2000Error("NO_COLLATERAL", "No Suilend position found");
2176
- const positions = await this.getPositions(address);
2177
- const deposited = positions.supplies.find((s) => s.asset === assetKey)?.amount ?? 0;
2177
+ const obligation = await this.fetchObligation(caps[0].obligationId);
2178
+ const dep = obligation.deposits.find((d) => d.reserveIdx === reserve.arrayIndex);
2179
+ const ratio = cTokenRatio(reserve);
2180
+ const deposited = dep ? dep.ctokenAmount * ratio / 10 ** reserve.mintDecimals : 0;
2178
2181
  const effectiveAmount = Math.min(amount, deposited);
2179
2182
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on Suilend`);
2180
- const ratio = cTokenRatio(reserve);
2181
- const ctokenAmount = Math.ceil(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
2183
+ const ctokenAmount = dep && effectiveAmount >= deposited * 0.999 ? dep.ctokenAmount : Math.floor(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
2182
2184
  const [ctokens] = tx.moveCall({
2183
2185
  target: `${pkg}::lending_market::withdraw_ctokens`,
2184
2186
  typeArguments: [LENDING_MARKET_TYPE, assetInfo.type],