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