LTV Validation
Call client.quote.calculateLtv(...) before creating a Simple Loan. This lets your app reject invalid amount pairs before it asks the protocol to create a loan.
const ltv = client.quote.calculateLtv(
{
collateralPoolId,
borrowPoolId,
collateralAmount,
borrowAmount,
},
pools,
prices
);
if (ltv.validationErrors.length > 0) {
throw new Error(ltv.validationErrors.map((error) => error.message).join(" "));
}
Amounts must use each asset's smallest unit. BTC uses satoshis. USDC and USDT use token base units based on the selected pool decimals.
The SDK also validates minimum borrow amounts. BTC borrows must be at least 5_100n sats. USDC and USDT borrows must be at least 1_000_000n base units. Use getMinimumBorrowAmount(asset) to display the same minimum before the user submits.
Pools expose sameAssetBorrowing and sameAssetBorrowingDustThreshold. When same-asset borrowing is disabled, same-asset collateral must be strictly below the base-unit dust threshold; equality is rejected. The quote helpers, client.simpleLoans.create(...), and client.lending.prepareBorrow(...) enforce this policy.