How a BorrowX loan works
One example throughout: 2,000 tUSDC against 1.2 tETH at $3,200.

A loan's life
Allow
Let the contract move your collateral (ERC-20 allowance).
Lock and borrow
One transaction locks collateral and sends the loan.
Accrue
Interest adds up every second.
Repay
In parts or at once, interest first.
Unlock
Debt at zero: withdraw your collateral.
Price falls too far, or the grace period ends: a liquidator closes the loan.
Collateral and limits
Borrow up to the max LTV. Past the liquidation threshold, collateral can be sold.
| Collateral | Reference price | Max LTV | Liquidation threshold |
|---|---|---|---|
| tETH | $3,200.00 | 75% | 82% |
| tWBTC | $64,000.00 | 70% | 78% |
| tLINK | $14.50 | 55% | 65% |
Health factor and the safety runway
health = collateral value × liquidation threshold ÷ debt
- 1.2 tETH × $3,200 = $3,840 of collateral
- $3,840 × 0.82 = $3,148.80 of borrowing power
- $3,148.80 ÷ 2,000 = health 1.57, Safe
- Sold below
- $2,032.52
- At risk below
- $3,048.78
Liquidation price: 2,000 ÷ (1.2 × 0.82) = $2,032.52, a 36% fall.
Interest, fixed or variable
Simple interest on what you still owe, every second.
interest = principal owed × APR × time ÷ 365 days
- Fixed: today's variable rate + 1.25 points, locked.
- Variable: tUSDC 5.40%, tDAI 5.10%, +2.00 points when the pool is busy.
- 2,000 × 5.15% × 90 ÷ 365 ≈ 25.40 tUSDC (90 days, Steady discount).
Due dates are enforced
30, 90 or 180 days, then a 3-day grace period. After that, a liquidator can close the loan.
Liquidation, step by step
tETH falls to $1,900: health 1,900 × 1.2 × 0.82 ÷ 2,000 = 0.93.
- A liquidator repays your 2,000 tUSDC debt.
- It receives the debt + 5% in tETH: 2,100 ÷ 1,900 = 1.105 tETH.
- The other 0.095 tETH is yours, and you keep the 2,000 tUSDC.
The demo closes the whole loan at once; real protocols often liquidate part.
Borrower levels
A simulated credit score, built from your loans in this demo.
New
Standard rates.
Steady
1 on-time repayment: 0.25 points off.
Trusted
3 on-time repayments: 0.50 points off, +5 points max LTV.
A liquidation sends you back to New.
For developers
The demo's data layer (src/lib/demo) mirrors the contract interface, so wagmi and viem can replace it. Runs standalone or plugs into a pool such as VaultLend.
Show the contract interface
interface IBorrowX {
function openLoan(address collateral, uint256 collateralAmount,
address asset, uint256 amount,
uint32 termDays, bool fixedRate) external returns (uint256 loanId);
function repay(uint256 loanId, uint256 amount) external; // interest first
function addCollateral(uint256 loanId, uint256 amount) external;
function withdrawCollateral(uint256 loanId) external; // after full repayment
function healthFactor(uint256 loanId) external view returns (uint256); // 1e18 = 1.00
function liquidate(uint256 loanId) external; // health < 1e18 or grace over
}