# Borrowing mechanism

After pledging an NFT, the Zumer protocol will calculate the largest possible borrow value (liquidity) for the user. Unless interacting with our helper contract, all assets obtained will be in ERC-20. Currently Zumer supports WETH.
$L = min(\text{floor price}, 30_{MA}) * LTV * \text{number of NFTs pledged} - \text{borrow value}$
To obtain the current liquidity for an address:
// contract: Comptroller.sol
// @notice Calculate the liquidation amount given the ZNft token Id
// @param borrower The borrower that owns the tokenId ZNft
// @param ZBondBorrowed The ZBond that the borrower borrows from
// @param tokenId The ZNft collateral tokenId
// @param ZNft The ZNft used as collateral
function calculateLiquidationAmount(
uint256 tokenId,
) external view override returns (uint256)
When a user has positive liquidity, they can borrow from the zBond contract. Note that, different from most of the DeFi lending protocols, the liquidity is calculated separately for each NFT project. (e.g., with 1 BAYC valued at 50 ETH pledged, the user can only borrow 50 ETH in the BAYC's zBond pool. They cannot borrow from Doodle's zBond pool, unless they have pledged Doodle in the zDoodle contract.)
To borrow, users need to call the borrow function, where the users specify how long the loan term is, and the total amount of assets to borrow. When borrowing, the users will automatically pay an upfront underwriting fee. Currently, the underwriting fee is sitting at 5% per loan.
To borrow when there's enough liquidity:
// contract: ZBond.sol
// @notice A caller can borrow underlying tokens from this ZBond
// @param amount The amount the caller would like to borrow
// @param duration The duration of the loan
function borrow(uint256 amount, uint256 duration)

### Paying back the loan

For each loan, the borrower has to pay back to the protocol a minimum payment at least every 30 days. The duration of the minimum payment is subject to change depending on how our community feels about the frequency. The minimum payment is the interest accrued at the block where repayBorrow() is called. Additionally, at the end of the loan term, the user has to pay back all of the borrowed amount plus interest.
To check the address' current loan balance:
// @notice Gets the borrower's current borrow balance
// @param borrower The borrow address of which current borrow balance is to be calculated
// @return The borrower's current borrow balance, including accrued interest based on the current block
function getAccountCurrentBorrowBalance(address borrower) public view override returns (uint256)
To check the address' loan balance at maturity:
// @notice Gets the borrower's borrow balance at the time of maturity
// @param borrower The borrow address of which current borrow balance is to be calculated
// @return The borrower's borrow balance at the time of maturity, including accrued interest that will have accrued
function getAccountBorrowBalanceAtMaturity(address borrower) public view override returns (uint256)
To repay loan:
// @notice A caller can repay his debt
// @param amount The amount of underlying token that the caller would like to repay
// Note that if the amount is type(uint256).max, it means to pay off all outstanding balance at the
// time the tx is being mined.
// This design is for situations when the front end sends the tx to repay the total outstanding
// balance at the time the user interacts with the DAPP, while the tx is only confirmed
// some time later, by then more interests will have been accrued and the intended full repayment will not
// be fulfilled due to the tiny amount of 'dust' interests accrued.
function repayBorrow(uint256 amount)

### Interest rate calculation

Zumer protocol has a unique way of determining the interest rate. The total interest rate for a loan position is determined by two parts: Credit Cost and Funding Ratio.

### Credit Cost

Each project has a flat interest rate, depending on how risky a project is. We have 3 tiers of interest rates for projects ranging from risky, normal, and safe. This stable interest rate depending on the project is called the Credit Cost.

### Funding Ratio

All projects share a varying interest ratio determined by how long the loan term is. We call this interest ratio the Funding Ratio. The longer a loan term is, the higher the Funding Rate. This pattern is to discourage longer-than-needed loan terms so that the lenders' funds can be at lower risk when extreme market movement happens. The parameters for the funding rate can be changed