> Agents can also search and read this documentation through its [MCP server](https://docs.niftyapes.money/~gitbook/mcp).

# What is NiftyApes?

We're reinventing lending, borrowing, and debt markets and we're starting with your JPEGs.

## The Basics

**NiftyApes** is a system of smart contracts that enables NFT owners to access instant liquidity using the NFTs they own as collateral.

The **NiftyApes** smart contracts are flexible, and allow lenders to create loan offers with any combination of Principal (e.g. amount offered), Duration, and APR.&#x20;

Automatic, always-on loan auctions drive towards fair market values of the assets along a risk-adjusted timeline.

Lending via the **NiftyApes** smart contracts is designed to be a win-win-win game.&#x20;

* **Borrower's Win** by having access to instant liquidity and competition for their loan over the loan's lifespan.&#x20;
* **Lenders Win** by enabling an infinite number of standing offers and accessible liquidity with minimal opportunity cost or fragmentation. Additionally, the protocol guarantees minimum profitability and originator premiums for the lenders who do the work of locking liquidity, extending open offers, and identifying a market price.&#x20;
* **The Ecosystem Wins** with pricing data. As the NiftyApes offer-book fills up, a risk-adjusted pricing model emerges for all served assets. This data is on-chain and accessible by everyone. Additionally, **NiftyApes** has committed to programmatically donating 1% of protocol fees to the Regen Collective, which funnels capital to regen and public good projects in the ecosystem.

We're making debt a public good, enabling both borrowers and lenders to benefit from market competition.

{% embed url="<https://discord.gg/Ge8Zwy6syQ>" %}

## Why do lenders care?

Lenders can create an infinite number of lending offers, for an infinite number of assets in 2 clicks with **zero liquidity fragmentation.**

Plus, **NiftyApes** is building on top of [Compound](https://compound.finance), meaning that even when your liquidity isn't earning interest in active loans, you're still earning an industry-standard APR.

{% content-ref url="/pages/AAnPNQIQGUGUBXcmtTF2" %}
[Lenders dApp Guide](https://docs.niftyapes.money/lenders-dapp-guide/lender-quick-start-guide)
{% endcontent-ref %}

## Why do borrowers care?

Borrowers get access to instant liquidity to borrow, using their NFTs as collateral with as few as **1 transaction.**

**Flexibility is the ultimate luxury:** these loans auto-upgrade over the entire lifetime of the loan, but borrowers can also refinance without friction or fees!&#x20;

{% content-ref url="/pages/QQeqV27Qcpf540RVEV7H" %}
[Borrowers dApp Guide](https://docs.niftyapes.money/borrowers-dapp-guide/borrow-page)
{% endcontent-ref %}


# Whitepaper

![](https://media.giphy.com/media/3oEjI9FCQQpk0NOrra/giphy.gif)

*We needed to move it into it's own Gitbook. Click below to jump over to the full document.*

{% content-ref url="/spaces/l5VaZRatGZapQgFwuCI9" %}
[NiftyApes: Whitepaper](https://whitepaper.niftyapes.money/)
{% endcontent-ref %}


# The NiftyApe Manifesto

🍌 In Praise of the Noble Banana 🍌

## **The future is bananas.**

For thousands of years, wealthy incumbents have dictated our financial systems. But a shift towards the memes of production have created a make-or-break moment in human history. As rules of ownership shift and lines of code become communal goods, we can copy-and-paste 5,000 years of outdated and inequitable terms. Or we can evolve our systems to upgrade our future.

## **Where others see red, we see yellow.**&#x20;

Consider the lessons of the noble banana. What most people consider bananas are actually a modern innovation: a genetic code forked by folks who saw the time was ripe for change. Bananas teach us that thoughtful evolution can lead to a delicious revolution.&#x20;

Bananas invert your thinking. Green means stop; yellow means go; red means you may want to get your banana checked out. Fun fact: when most people eat bananas, they do so backwards. It’s actually easier to open bananas from the back end, not the stem. We learned it from watching some apes. Absurdity is an excellent teacher.&#x20;

## **It's time to take this sh!t seriously.**

We're building towards a permissionless and interoperable future, where individuals can flourish on equitable terms with former incumbents. We may poke fun at ourselves and our industry, but we don't monkey around when it comes to our mission. If we throw something at the wall, it's going to do more than stick—it's going to make an extremely potent point, and it's going to look dope doing it too.&#x20;

##


# How Does NiftyApes Work?

A quick overview of how lending and borrowing works on NiftyApes

## Level Set

**NiftyApes** is a protocol where Borrowers lock their non-fungible tokens (also known as NFTs or ERC-721s) as collateral in order to borrow fungible tokens like Ethereum's native token Ether and whitelisted ERC20 tokens like [MakerDAO's DAI](https://makerdao.com/en/).

## How It Starts

1. Lenders lock their tokens (Ether or DAI) into the protocol.
2. Next, lenders sign a meta-transaction containing the details of the loan offer. The offer includes...
   1. The NFT collection (contract address) or specific assets (contract address + token number).
   2. The amount of liquidity offered.
   3. The interest rate&#x20;
   4. The duration of the loan in days.
   5. An example offer looks like this
      1. **50 Ether**, at **15% APR,** for **120 days** for any **Bored Ape**
3. Borrowers connect their wallet to the NiftyApes dApp and view the offers available against the NFTs they own.
4. Borrowers hit the "Money Button" which simultaneously escrows their collateral in the NiftyApes smart contract and transfers the liquidity in a single transaction.

What happens next is powered by the unique NiftyApes mechanism, "Harberger-Style Lending Auctions."&#x20;

## Harberger-Style Lending Auctions Explained

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FEqmnmOFFtn9hBDTsOMXW%2Fimage.png?alt=media\&token=231f90aa-7984-49cb-a49f-3f1785765a18)

**Lender 1** has a lot of capital, and they're comfortable with a modest LTV and a respectable APR on any Bored Ape. They set an open offer of **50Ξ** for **90 days** at **15% APR**  for *all* Bored Apes.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FGAxM76AJu7Gwnk02GdfR%2Fimage.png?alt=media\&token=f4194d31-e7ab-48e7-af7f-b359eb6e9d5d)

**Lender 2**, has less capital, higher risk tolerance, and a bullish thesis on Bored Apes with the **3d** + **Toga** attribute, so they set a more aggressive offer on Bored Ape #6974.

![Every offer is presented and executable in the NiftyApes offer-book, but the front-end will sort the most liquidity, at the cheapest APR, for the longest time first.](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FTBo9suFIZakbuPboOnLt%2Fimage.png?alt=media\&token=6bd7882d-a11c-4abe-b03d-b5d8d70f75f7)

The owner of BAYC #6974 connects their wallet on the **NiftyApes** platform. They see the "Top Loan," the best offer based on **NiftyApe**'s *lightly* opinionated front-end.

![Instant liquidity for Borrowers, extremely flexible flexible mechanisms for lenders, & pricing data for the market](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2Fw3nA6POsPtg6GsWm2rdD%2Fimage.png?alt=media\&token=d1d413b4-102c-4979-a08e-c7f522292877)

Over the life of the loan, the Bored Apes Yacht Club's price increases but the active loan has not responded to the collateral's increase in value.

**Lender 3** decides to bid on the active loan.

![The borrower's terms are immediately upgraded. Any extra funds offered in the new loan can be drawn down by the Borrower.](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FJCoyILb7RW3LUKQv0lTn%2Fimage.png?alt=media\&token=13a9f6ee-812c-4543-9041-97fe77fc12ba)

**Lender 3** refinances the loan automatically with better terms. **Lender 3**'s liquidity goes to pay the Prinicipal **Lender 2** loaned to **the Borrower. Lender 3** also pays a **0.50% premium** to refinance the active loan + any outstanding interest accrued.&#x20;

New lenders can provide better terms, lower APR or extra funds many times over the lifespan of the loan.


# Refinance Guide

A loan can be refinanced by any party at any time. This encourages the terms of the loan to trend toward true market valuation as the LTV of the loan improves.\
\
Lenders compete for loans with better LTVs and borrowers experience automatic refinancing with better terms over the life of their loan. This results in a more equitable and value optimal debt market.

## **Refinancing by Borrower**

Borrowers can accept any offer in the order book and refinance at any time as long as the new offer amount is equal to or greater than the remaining principal plus interest earned by the lender and protocol so far.&#x20;

All remaining payments and interest will accrue to the new lender.

## **Refinancing by Lender**

A lender can refinance a loan at any time as long as the terms of the offer are at parity plus “1” of the current loan, and as long the lender has a sufficient balance to fill the loan amount.

The refinancing lender will need to pay the principal borrowed, interest earned so far, and a premium to buy out the loan.&#x20;

Current lenders do not need to pay any premiums or supply additional capital. All remaining payments and interest will accrue to the new lender.

## **Refinancing Premiums**

Four premiums have been implemented in the protocol's refinancing flow to drive value to borrowers and create a positive-sum game for lenders.

The majority of these premiums are paid to lenders when their offers are being refinanced on NiftyApes. The premiums implemented in the protocol are upgradable and, in the future, may be set according to community governance. \
\
Premiums only occur when an actor takes a greedy action. The protocol remains strictly unopinionated but influences actors to take or refrain from certain actions via incentives.

### **Loan Origination Premium**

The first time a loan is refinanced, an origination fee of 00.50% (or 50 Basis Points) of the Principal amount loaned is paid by the Refinancer to the Loan Originator.

This is to compensate the Loan Originator for the initial work of pricing the asset and providing on-demand capital to borrowers.

**Example Origination Fee**

A loan is originated at

***100Ξ** for **10,000 Seconds** at **10% interest rate*** == **00.50Ξ origination fee**

### **Term Premium**

Lenders can refinance any loan at any time if they provide terms at parity plus 1. Offers with improvements of as little as plus 1 second duration, plus 1 WEI principal, or minus 1 WEI interestRatePerSecond will result in a successful refinance. However, the protocol compares the refinance terms with the current loan to see if there is a combined improvement of plus 00.25% (25 basis points) in aggregate between the Principle, Duration, and Interest terms.

If the refinance offer fails this check, a flat premium equal to 25 basis points of the Principal is charged to the Refinancer as a **Term Premium**.

### **Example Refinance**

| **Current Loan** | **Refinance Offer** | **%% Change** |
| ---------------- | ------------------- | ------------- |
| 100 Eth          | 100.10 ETH          | *+00.10%*     |
| 10,000 seconds   | 10,010 Seconds      | *+00.10%*     |
| 10% Interest     | 9.96% Interest      | *+00.04%*     |

*Net Improvement: +00.24%*

**Term Premium:** 00.25% of Principal, e.g. **0.25 ETH**

The Term Premium is sent to the Protocol treasury.&#x20;

### **Interest Premium**

Lenders are guaranteed a minimum of 00.25% interest earned on any loan they serve, regardless of whether they originate or refinance the loan.

When a refinance offer is made, the protocol checks the amount of interest earned so far by the Current Lender. The delta between the amount earned and the 00.25% minimum must be paid by the Refinancer in order to assume control of the loan.

Once the Refinance has occurred the Interest Premium is reset for the new Lender, as they are now entitled a minimum of 00.25% interest earned on the loan they serve.&#x20;

This creates a Dutch Auction on each active loan refinancing. As more interest accumulates, the Interest Premium declines closer and closer to 0. Refinancers must weigh the declining Interest Premium with the competition to refinance.

#### **Example Interest Premium**

***Current Loan***\
**100Ξ** for **10,000 Seconds** at **10%** interest rate

***Interest Earned***\
**0.001Ξ** interest charged per second

***Interest Premium***

**At second 0**, the interest premium is **00.25Ξ**\
**At second 100** the interest premium is **\~00.15Ξ**\
**At second 250**, the interest premium is **00.00​Ξ**

### **Default Premium**

Since a lender can refinance any loan at any time, as a loan goes to default each individual lender has an incentive of the true market value (tmv), minus the principal (p) of the loan, minus interest earned by the lender (lie) and protocol (pie), minus the 00.25% default premium (prem), minus gas costs (gas). We anticipate a bottom-of-the-stack MEV auction to be the last lender in the last block of the active loan in order to gain this default profit incentive. Since this is a greedy action the protocol will charge a 00.25% default premium. If a lender participates in the MEV auction but fails to be the last lender they will be refinanced and have a max cost of the default premium + gas.&#x20;

#### **Example Profit Incentive**

***Asset tmv = 200*****Ξ**

&#x20;**p = 100Ξ**

**lie = 9.9999Ξ**

**pie = 0.25Ξ**

**prem = 0.25Ξ**

**gas = 0.0025Ξ**

**Profit Incentive =&#x20;*****200*****Ξ - 100Ξ - 9.9999Ξ - 0.25Ξ - 0.25Ξ - 0.0025Ξ = 89.4976Ξ**\
\
This creates a strong incentive for lenders to be the last lender in a defaulting loan with a tmv that is greater than the repayment cost.&#x20;

## **Improved Term Drawdown & Liquidity Slashing**

As loans are refinanced, a borrower may have access to more liquidity than was originally available when the loan was initiated. The NiftyApes smart contract does not automatically enforce draw down of more capital because it would force a higher interest payment to be made by the borrower. However, a borrower may choose to draw down more value from the loan if desired.\
\
If a borrower attempts to draw down additional capital but the refinancing lender has not maintained sufficient liquidity to serve their refinancing offer, the remaining available balance of the lender will be added to the amount drawn on the loan and the current interest earned on the loan (the lenders profit) will be slashed. Lenders can only be slashed if the last action taken on the loan is a lender refinance, they can only be slashed once on a given set of terms, and they will begin to accrue interest again after being slashed. This incentivizes the lender to maintain sufficient liquidity on the protocol to serve their refinanced loan offers while also allowing the lender to utilize their liquidity across many loans, i.e. creating more offers than total liquidity they have deposited in the protocol.  Rather than enforcing fractional reserve requirements, the protocol incentivizes lenders to maintain reasonable liquidity reserves for refinanced loans in order to not be slashed.&#x20;

\
A borrower may also experience a better interest rate or longer duration on their loan after refinancing. A lower interest rate is in the clear best interest of the borrower to automatically accept and update. Likewise, a longer duration does not enforce a higher interest payment. The interest rate per second does not change and the borrower would pay more interest if they utilize the additional time, but if they repay their loan at the original loan duration they would pay no additional interest. \ <br>


# Contracts & Security

## Contracts

NiftyApes is a system of smart contracts that enables borrowing and lending with NFTs as collateral with permissionless refinancing. These contracts are Liquidity.sol, Offers.sol, Lending.sol, and SigLending.sol. Together they enable Harberger Style Lending Auctions the new financial mechanism created by NiftyApes.

## Audits

NiftyApes has completed three audits with Quantstamp and Sherlock, with a fourth scheduled with Sherlock at the end of 2022.&#x20;

* [Quantstamp Audit, 2022-04-14](https://drive.google.com/file/d/1r0xVvFwOugYUuAYIuIM7WH97exQlo_2Q/view?usp=sharing)&#x20;
* [Sherlock Audit, 2022-06-10](https://drive.google.com/file/d/1V60yAkZjeW6voyUOM73Ik9X-wkUKZZ9y/view?usp=sharing)
* [Quantstamp Audit, 2022-09-14](https://drive.google.com/file/d/1Ni04qYuWuLAEArzR325G8_hPZ_MrCi5T/view?usp=sharing)
* Sherlock Audit, coming Q2.2023

## Q: Why does NiftyApes use upgradeable proxy contracts? <a href="#q-why-does-benddao-use-upgradeable-proxy-contracts" id="q-why-does-benddao-use-upgradeable-proxy-contracts"></a>

The current smart contracts are twice-audited and carefully tested. But we also recognize that they're a V1. The upgradable proxy is meant to a final backstop, a hand-brake the team can pull in case of emergencies.&#x20;

Our vision is to deploy a V2 of the smart contracts that are truly permissionless and unstoppable.&#x20;

## Q: I worry about the rug pull, what has NiftyApes done to mitigate that? <a href="#q-i-worry-about-the-rug-pull-what-if-benddao-rug-pull" id="q-i-worry-about-the-rug-pull-what-if-benddao-rug-pull"></a>

A rug pull in crypto is when the team suddenly abandons a project and sells or removes all its liquidity from the protocol.&#x20;

NiftyApes *cannot* drain the liquidity staked in the protocol.&#x20;

Liquidity can *only* be removed from the protocol by the party who originally provided liquidity, or by a borrower with an active offer from the lender and owns the corresponding asset. The borrower cannot draw liquidity without locking the corresponding NFT in escrow.

Have more questions? [Join the Discord and let us know what we missed!](https://discord.gg/Ge8Zwy6syQ)


# Liquidity.sol

The deployed addresses for Liquidity.sol are:&#x20;

Rinkeby:\
\`Mainnet:

**ILquidity.sol**

Interface of the Liquidity.sol contract. Does not include restricted or optional functions. To view the full interface visit: link to interface on github. &#x20;

**Functions**

> `getCAsset(asset)`\
> `getCAssetBalance(account, cAsset)`\
> `supplyErc20(asset, amount)`\
> `supplyCErc20(cAsset, amount)`\
> `withdrawErc20(asset, amount)`\
> `withdrawCErc20(cAsset, amount)`\
> `supplyEth()`\
> `withdrawEth(amount)`\
> `assetAmountToCAssetAmount(asset, amount)`\
> `cAssetAmountToAssetAmount(cAsset, amount)`

**Events**

> `Erc20Supplied(liquidityProvider, asset, tokenAmount, cTokenAmount)`\
> `CErc20Supplied(liquidityProvider, cAsset, cTokenAmount)`\
> `Erc20Withdrawn(liquidityProvider, asset, tokenAmount, cTokenAmount)`\
> `CErc20Withdrawn(liquidityProvider, cAsset, cTokenAmount )`\
> `EthSupplied(liquidityProvider, amount, cTokenAmount);`\
> `EthWithdrawn(liquidityProvider, amount, cTokenAmount);`

**`Details`**

> `getCAsset(asset) -> address`\
> Returns the address of the cAsset associated to the underlying asset.

> `getCAssetBalance(account, cAsset) -> uint256`\
> Returns the cAsset balance of an account. This can be combined with cAssetAmountToAssetAmount() to get the accounts underlying balance.

> `supplyErc20(asset, amount) -> uint256`
>
> Returns the amount of cTokens minted and added to the lenders balance.
>
> Emits a Erc20Supplied() event.

> `supplyCErc20(cAsset, amount) -> uint256`
>
> Returns the amount of cTokens added to the lenders balance.
>
> Emits a CErc20Supplied() event.

> `withdrawErc20(asset, amount) - uint256`
>
> Returns the amount of cTokens`burned`and subtracted from the lenders balance.
>
> Emits a Erc20Withdrawn() event

> `withdrawCErc20(cAsset, amount) - uint256`
>
> Returns the amount of cTokens subtracted from the lenders balance.
>
> Emits a CErc20Withdrawn() event.

> `supplyEth() - > uint256`
>
> Returns the amount of cTokens minted and added to the lenders balance.
>
> Emits a EthSupplied() event.&#x20;

> `withdrawEth(amount) -> uint256`
>
> Returns the amount of cTokens`burned`and subtracted from the lenders balance.
>
> Emits a EthWithdrawn() event.

> `assetAmountToCAssetAmount(asset, amount) -> uint256`\
> Returns the amount of cAsset to be expected in a conversion from an underlying amount.

> `cAssetAmountToAssetAmount(cAsset, amount) -> uint256`
>
> Returns the amount of asset to be expected in a conversion from a cAsset amount. This function rounds at the 10th decimal and provides a slightly rounded, less-than-whole-number value. This results from Compound's cTokens having 8 decimal values.


# Offers.sol

The deployed addresses for Offers.sol are:&#x20;

Rinkeby:\
Mainnet:

**IOffers.sol**

Interface of the Offers.sol contract. Does not include restricted or optional functions. To view the full interface visit: link to interface on github. &#x20;

**Structs**

```
struct Offer { 
    // offer creator 
    address creator; 
    // offer loan duration 
    uint32 duration; 
    // the expiration timestamp of the offer in a unix timestamp in seconds 
    uint32 expiration; 
    // is loan offer fixed terms or open for auction 
    bool fixedTerms; 
    // is offer for single NFT or for every NFT in a collection 
    bool floorTerm; 
    // whether or not this offer was made by a lender or a borrower 
    bool lenderOffer; 
    // offer NFT contract address 
    address nftContractAddress; 
    // offer NFT ID 
    uint256 nftId; // ignored if floorTerm is true 
    // offer asset type 
    address asset; 
    // offer loan amount 
    uint128 amount; 
    // offer interest rate per second. (Amount * InterestRate) / MAX-BPS / Duration 
    uint96 interestRatePerSecond; 
}
```

**Functions**

> `getOfferHash(offer)`
>
> `getOfferSigner(offer, signature)`\
> `getOfferSignatureStatus(signature)`\
> `withdrawOfferSignature(offer, signature)`\
> `getOffer(nftContractAddress, nftId, offerHash, floorTerm)`\
> `createOffer(offer)`\
> `removeOffer(nftContractAddress, nftId, offerHash, floorTerm)`

**Events**

> `NewOffer(creator, nftContractAddress, nftId, offer, offerHash)`\
> `OfferRemoved(creator, nftContractAddress, nftId, offer, offerHash)`\
> `OfferSignatureUsed(nftContractAddress, nftId, offer, signature)`

**Details**

> `getOfferHash(offer) -> bytes32`&#x20;
>
> Returns the hash of an offer.

> `getOfferSigner(offer, signature) -> address`
>
> Returns the address of the signer of a signature.

> `getOfferSignatureStatus(signature) -> bool`
>
> Returns true if a given signature has been revoked otherwise false.

> `withdrawOfferSignature(offer, signature)`
>
> Withdraws a signature based offer and ensures it cannot be executed on-chain.

> `getOffer(nftContractAddress, nftId, offerHash, floorTerm) -> Offer`
>
> Returns an offer from the on-chain offer book.

> `createOffer(offer) -> bytes32`
>
> Returns the offerHash of the offer created.
>
> Emits a NewOffer() event.

> `removeOffer(nftContractAddress, nftId, offerHash, floorTerm)`\
> Removes an offer from the on-chain offer book, ensuring it cannot be executed.
>
> Emits an OfferRemoved() event.


# Lending.sol

The deployed addresses for Lending.sol are:&#x20;

Rinkeby:\
Mainnet:

**ILending.sol**

Interface of the Lending.sol contract. Does not include restricted or optional functions. To view the full interface visit: link to interface on github. &#x20;

**Structs**

```
``
```

**Functions**

> `getLoanAuction(nftContractAddress, nftId)`
>
> `executeLoanByBorrower(nftContractAddress, nftId, offerHash, floorTerm)`
>
> `executeLoanByLender(nftContractAddress, nftId, offerHash, floorTerm)`
>
> `refinanceByBorrower(nftContractAddress, nftId, floorTerm, offerHash, expectedLastUpdatedTimestamp)`
>
> `refinanceByLender(offer, expectedLastUpdatedTimestamp)`
>
> `drawLoanAmount( nftContractAddress, nftId, drawAmount)`
>
> `repayLoan(nftContractAddress, nftId)`
>
> `repayLoanForAccount(nftContractAddress, nftId, expectedLoanBeginTimestamp)`
>
> `partialRepayLoan(nftContractAddress, nftId, amount)`
>
> `seizeAsset(nftContractAddress, nftId)`
>
> `ownerOf(nftContractAddress, nftId)`
>
> `calculateInterestAccrued(nftContractAddress, nftId)`
>
> `calculateInterestPerSecond(amount, interestBps, duration)`
>
> `checkSufficientInterestAccumulated(nftContractAddress, nftId)`
>
> `checkSufficientTerms(nftContractAddress, nftId, amount, interestRatePerSecond, duration)`

**Events**

> `LoanExecuted(nftContractAddress, nftId, offer)`
>
> `Refinance(nftContractAddress, nftId, offer)`
>
> `AmountDrawn(nftContractAddress, nftId, drawAmount, totalDrawn)`
>
> `LoanRepaid(lender, borrower, nftContractAddress, nftId, asset, totalPayment)`
>
> `PartialRepayment(lender, borrower, nftContractAddress, nftId, asset, amount)`
>
> `AssetSeized(lender, borrower, nftContractAddress, nftId)`

**Details**

> `getLoanAuction(nftContractAddress, nftId) -> LoanAuction`
>
> Returns a LoanAuction struct

> `executeLoanByBorrower(nftContractAddress, nftId, offerHash, floorTerm)`
>
> Executes a LoanAuction given an offerHash of an offer in the on-chain offerbook. Must be called by the owner of a valid NFT.&#x20;
>
> Emits a LoanExecuted() event.

> `executeLoanByLender(nftContractAddress, nftId, offerHash, floorTerm)`
>
> Executes a LoanAuction given an offerHash of an offer in the on-chain offerbook.\
> Emits a LoanExecuted() event.

> `refinanceByBorrower(nftContractAddress, nftId, floorTerm, offerHash, expectedLastUpdatedTimestamp)`
>
> Refinances a LoanAuction given an offerHash of an offer in the on-chain offerbook. Must be called by the owner of the borrowed NFT.\
> Emits Refinance() and AmountDrawn() events.

> `refinanceByLender(offer, expectedLastUpdatedTimestamp)`
>
> Refinances a LoanAuction given an offer.&#x20;
>
> Emits a Refinance() event.

> `drawLoanAmount( nftContractAddress, nftId, drawAmount)`
>
> Enables a borrower to draw more value from their loan if a refinance has offered a larger amount. \
> Emits an AmountDrawn() event.

> `repayLoan(nftContractAddress, nftId)`
>
> Enables a borrower to repay their loan in full. \
> Emits a LoanRepaid() event.

> `partialRepayLoan(nftContractAddress, nftId, amount)`
>
> Enables a borrower to make a partial payment toward the principle of their loan.\
> Emits a PartialRepayment() event.

> `seizeAsset(nftContractAddress, nftId)`
>
> Enables a lender to seize an asset from a loan that has gone past its duration without being repaid in full.\
> Emits an AssetSeized() event.&#x20;

> `ownerOf(nftContractAddress, nftId) -> address`
>
> Returns the true owner of the NFT.

> `calculateInterestAccrued(nftContractAddress, nftId) -> uint256, uint256`
>
> Returns the lenderInterest and protocolInterest accrued during the current segment of interest.

> `calculateInterestPerSecond(amount, interestBps, duration) -> uint96`
>
> Returns the interestRatePerSecond given a set of terms.

> `checkSufficientInterestAccumulated(nftContractAddress, nftId) -> uint256`
>
> Returns the delta between the required accumulated interest and the current accumulated interest.

> `checkSufficientTerms(nftContractAddress, nftId, amount, interestRatePerSecond, duration) -> bool`
>
> Returns whether the terms are in aggregate sufficiently better than the current terms of the loan.


# SigLending.sol

The deployed addresses for SigLending.sol are:&#x20;

Rinkeby:\
Mainnet:

**ISigLending.sol**

Interface of the SigLending.sol contract. Does not include restricted or optional functions. To view the full interface visit: link to interface on github. &#x20;

**Functions**

> `function executeLoanByBorrowerSignature(offer, signature, nftId)`
>
> `function executeLoanByLenderSignature(offer, signature)`
>
> `function refinanceByBorrowerSignature(offer, signature, nftId, expectedLastUpdatedTimestamp)`

**Details**

> `function executeLoanByBorrowerSignature(offer, signature, nftId)`
>
> Enables a loan to be executed via a signature based offer
>
> Emits a LoanExecuted() event.

> `function executeLoanByLenderSignature(offer, signature)`
>
> Enables a loan to be executed via a signature based offer
>
> Emits a LoanExecuted() event.

> `function refinanceByBorrowerSignature(offer, signature, nftId, expectedLastUpdatedTimestamp )`
>
> Enables a loan to be refinanced via a signature based offer
>
> Emits Refinance() and AmountDrawn() events.


# Loan Default FAQ

## What happens when a loan defaults?

When the loan duration expires, the loan is considered to be in-default.

The Harberger-Style Lending Auction ends, and refinancing is no longer possible by either Lenders or the Borrower.

**The only possible outcomes of a defaulted loan are:**

1. The Borrower repays the Principal + Interest
2. The Lender seizes the NFT collateral that backed the original loan

## What can borrowers do?

Pay back the loan! Just because a loan is in default does not mean a borrower can not repay it to save their NFT from being seized.

Click on the “Repay” button on the defaulted Loan Card to make the repayment, or repay directly to the **`Lending.sol`** smart contract calling the **Repay Loan** function, `repayLoan(nftContractAddress, nftId)`.

<figure><img src="https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FzCBtx0TWJCW2laJMtAwo%2Fimage.png?alt=media&amp;token=487b019f-63eb-4fc1-aebc-40da52b3456a" alt=""><figcaption></figcaption></figure>

### Do I have to repay from the same wallet I borrowed from?

No. Borrowers can make a **full repayment** from any wallet. After repayment has been received, the the NFT will then be returned to the wallet that initiated the loan (currently only available interacting directly with the smart contracts).

### How much time do I have to make a full repayment after default?

Borrowers can make a full repayment up until the Lender calls the **Seize Asset** function.

Once the NFT has been seized by the Lender, and the Borrower loses their NFT collateral and the loan is considered "closed."

## What can lenders do?

Lenders have the opportunity to seize the NFT offered as collateral for their loan. This is in exchange for the principal amount of money lost in the loan.

Lenders can seize the asset the block after expiration by calling the Seize Asset function `seizeAsset(nftContractAddress, nftId)` either on the NiftyApes Lender Dashboard or by interacting directly with the NiftyApes **`Lending.sol`** smart contract

<figure><img src="https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FiFPOMglQrfwHRfWPRRzD%2Fimage.png?alt=media&amp;token=06ac1f1f-4c85-44e1-b48c-1379c366e469" alt=""><figcaption></figcaption></figure>

### Do I have to make the Seize Asset call from the same wallet that made the loan offer?

No. Lenders can make thie call from any wallet address (currently only available interacting directly with the smart contract).&#x20;

Once the call has been initiated be deposited into the Lender’s originating wallet address.

Have more questions? [Join the Discord and let us know what we missed!](https://discord.gg/Ge8Zwy6syQ)


# Lender Quick-Start Guide

From 0-to-Lending in less than 5 minutes.

{% embed url="<https://vimeo.com/764708833>" %}

## Intro

Welcome to the NiftyApes Quickstart Video.

In this short video I will demonstrate how you can go from zero to lending in about 5 minutes.

If you have any questions, ideas, or feedback for us, don't hesitate to reach out! You can find us on [Discord](https://discord.gg/Ge8Zwy6syQ) or [Twitter](https://twitter.com/niftyapes).

## Connect Wallet

It's worth calling out that I am demo-ing this on fork of Mainnet running on Hardhat.

For you to use the NiftyApes dApp please make sure you are set to Mainnet or the Goerli testnet.

## Adding Liquidity

In order to create offers, I first have to deposit liquidity. As you can see here, I have a dashboard displaying my total balance (which is zero) as well as what is available and what's in use.

Available is the liquidity I can use to create offers and withdraw. Available liquidity is still earning me interest in Compound.

In-Use is liquidity currently earning me interest in active loans against NFTs.

I'll click deposit either here... Sign the transaction... And perfect. My liquidity has been deposited.

In order to withdraw any available liquidity, I just need to flip the tab to "Withdraw" and select the appropriate amount...

## Creating Offers

Next, navigate to Create Offers. This is where I set collection-wide offers on any NFT collection in existence.

For your convenience, we've hard-coded the top 25 NFT collections, like Bored Apes or Moon Birds into the navigation screen.

If I have an NFT collection I want to add that is not listed, I can also copy/paste the collection's contract address. Here's the contract address for QQL's Mint Pass.

0xc73B17179Bf0C59cD5860Bb25247D1D1092c1088

I'm going to make a couple of offers on Bored Apes...

1. Let's go with an industry standard 30% LTV first. I'm going to hit "draft offer" just to auto-fill with the top offer. I'm going to set it to be good for 30 days, and 30 loans
2. Next, let's go with something a little crazier..and do a 80% LTV for 2 days... This offer is based on the current floor. I'll set this one to expire for 7 days. After 7 days, I can check the floor price and reinitiate the offer here. And because I want to control my exposure on these high LTV loans, I'm going to limit the number of uses here to just 5 loans.

As you can see, both of my offers are represented in the offer book.

And there you have it and I am officially Lending on the NiftyApes protocol.

Anyone with a Bored Ape can use my offer on a collateralized loan.


# Manage Liquidity Page

Lenders can add, withdraw, and monitor their liquidity on the Manage Liquidity page.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FCQjcKJDHXtcAhc8MGqjf%2Fimage.png?alt=media\&token=741feead-0599-4234-a406-279ba9d9ee34)

## Depositing and Withdrawing Liquidity

<img src="https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FGPbiRl7TfA9STGNsxKlF%2Fimage.png?alt=media&amp;token=a39f1a6d-b2de-459b-abc6-9225d63c1bb9" alt="" data-size="original">\
\
Liquidity can be Deposited and Withdrawn via the ☝️ Widget on the right side of the screen.

{% hint style="info" %}
Liquidity already in-use in loans cannot be withdrawn until the loan is repaid. \
\
That means the maximum amount you can withdraw from the protocol is the **Available Balance** (displayed on in table on the left side).\
\
![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FAJeYvTGXgHyt7TiBhTjE%2Fimage.png?alt=media\&token=d30757a9-162d-47ea-85fc-7592ace59e73)
{% endhint %}

For ease-of-use, we've provided a table at the bottom of the liquidity page that logs every balance change related to the wallet address you have connected.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FOLRDeDMC1i7nrLVeVgZ2%2Fimage.png?alt=media\&token=956d9552-f248-4c0d-b351-230d8eb1ee8d)


# Create Offers Page

Lenders can create collection-wide offers on the **Create Offers** screen.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FYNz6uBoyuXGzGBrg5DhA%2Fimage.png?alt=media\&token=af0a13f4-54ea-4592-a0f4-40c4b90d59b8)

## Selecting the Collection

Select a popular collection from the **collection dropdown.**&#x20;

Don't see the collection you want to offer liquidity to? Copy & paste the unique collection's Ethereum contract address into the Search Bar instead.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FByO9Hgm6T1ydSMQV8t5z%2Fimage.png?alt=media\&token=bcb71598-3a99-4459-9394-624769067af0)

## The Offer Details

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FfpECxh5cX9YpXFthu1iU%2Fimage.png?alt=media\&token=b8094a7c-8199-43d9-a599-2bb6d8a7c1b7)

Create a collection offer by first setting your terms. We display all offers in the NiftyApes offerbook so you can see how your offer compares to every other offer in the ecosystem.

As you edit your offer, NiftyApes displays your **draft-offer** as it appears in the offerbook to  perspective borrowers.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FSzDIOAUwP8U02PvIIAQT%2Fimage.png?alt=media\&token=4b049a0a-19e7-415c-bfac-d351c90b3dab)

**Offers are automatically set with a 30 day expiration date**. This means they will expire and are invalid after after the 30 day period. Lenders can chose shorter or longer periods for the offers to auto-expire, depending on each lender's risk tolerance.

{% hint style="info" %}
**Offer Depth** is the amount of liquidity behind each offer. Once an offer has used all of the Lender's backing liquidity it is hidden from the offerbook.&#x20;

***E.g.** An offer for **Any Bored Ape** for 50Ξ that has a liquidity depth of 100Ξ can only lend to two Bored Ape owners at a time. Any additional borrowers will have to use another offer with backing liquidity.*
{% endhint %}

## The Easy Button

Lenders who want to easily create the best offer in the offerbook can hit the Easy Button in the Offer widget. This automatically creates the top offer in the offerbook (displayed below).&#x20;

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FE5dnSZGmUOWK1R7kvY7z%2Fimage.png?alt=media\&token=22a33615-7014-46b9-b19b-78e75e4b3607)

## Creating the Offer

Once the lender is satisfied with the offer terms, the lender can click the Create Offer button. This initiates an on-chain transaction and storing the offer in the NiftyApes offerbook.

## Cancelling The Offer

Offers can be cancelled on the [Lender Dashboard.](https://docs.niftyapes.money/lenders-dapp-guide/lender-dashboard)

Once a lender has clicked "Cancel," the lender must approve a transaction setting the offer to cancelled. Once an offer is cancelled, it *cannot* be used by a borrower.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FzAC9GmiIg2d8D8Gy4yma%2Fimage.png?alt=media\&token=59db99b4-955a-4e22-acf3-96f3072b034e)


# Lender Dashboard

Lenders can get an account overview on the Lender Dashboard. There they can [Cancel Offers](https://docs.niftyapes.money/lenders-dapp-guide/lender-dashboard/canceling-offers) and [Seize Defaulted Assets](https://docs.niftyapes.money/lenders-dapp-guide/lender-dashboard/seizing-assets-from-loan-defaults).

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FQUEC4Ea7D2l70QiykeIZ%2Fimage.png?alt=media\&token=724d8241-5a44-4fec-8ba0-5619000b7c87)


# Seizing Assets from Loan Defaults

If a loan has been defaulted on, a lender is able to seize the collateral as repayment for the principal and interest owed by the borrower.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FMUsv3S2pR0gEhXHjx8Ke%2Fimage.png?alt=media\&token=964e38b6-a32d-4125-a4eb-79d86ed00012)

This view is available on the Lender Dashboard.

By clicking Seize Asset, the Lender submits a transaction that transfers the NFT collateral to their wallet.

For more information, check out the [Loan Default FAQ](https://docs.niftyapes.money/overview/loan-default-faq)


# Canceling Offers

Lenders can cancel offers directly on the Lender Dashboard by clicking the "Cancel" button next to their active offers.&#x20;

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FLRYHwuSTf9X7lqqfRAom%2Fimage.png?alt=media\&token=26ce33c8-d6a3-4603-a9cf-06b810668a6c)

Once a lender has clicked "Cancel," the lender must approve a transaction to update the offer as cancelled.&#x20;

Once an offer is cancelled, it *cannot* be used by a borrower.


# Borrow Page

Borrowers can connect their wallet to view what loan offers are available for their NFTs on NiftyApes.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FhksVnhaKypZaruYbNvyw%2Fimage.png?alt=media\&token=afd9ee7b-d112-43cd-8558-1e9792207512)

NFTs without offers are also displayed.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FUJEB8dtadaJlLDHUJgdL%2Fimage.png?alt=media\&token=81bd8a61-9f4c-4258-882e-0ff7b5e237d0)

The NiftyApes frontend is lightly opinionated. That means we're displaying what the dApp determines to be the top offer on NiftyApes, surfacing the **Lowest APRs** first.&#x20;

Borrowers can also view **all offers** available to each asset by clicking on the **"View All Offers"** link on each NF&#x54;**,** and sort offers based on **Amount,** **Duration,** or **APR**.

![Any offer in the offerbook can be borrowed against as the lender has enough liquidity to serve it. All offers without backing liquidity are hidden from the borrower. ](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FgoRrQYKrq0Vo0tys1Bza%2Fimage.png?alt=media\&token=013f9c4c-6740-4fb3-9077-a1f6ef7d7199)


# Initiating the Loan

Borrowers can initiate the loan from either the top-level or Offer Book Details page.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FwOckAcs0sH7jAmKk07n1%2Fimage.png?alt=media\&token=48bd3902-c9ec-42f4-8b4e-1c75a2865a19)

Once clicked, the borrower is taken to a loan details page. Here, the terms of the loan are displayed as well as an estimation of the *total* interest the borrower could owe at the end of the loan.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2F80V2gHjadJLEL3C2e1EZ%2Fimage.png?alt=media\&token=f884882f-3617-446f-bacb-9103fc9a6d4e)

Borrowers will first be prompted to approve the NiftyApes smart contracts to transfer their NFT token.&#x20;

Once the approval transaction is confirmed, they are able to initiate the loan.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FDm75bcQAKs3MDPBrNbvY%2Fimage.png?alt=media\&token=3c93df53-9bd6-4314-9aa9-836fe00704f9)

When the loan is executed, the collateral is locked in the NiftyApes smart contract, and the liquidity  is sent to the borrower's wallet in a single transaction.

Borrowers can view all active loans from the [Borrower Dashboard](https://docs.niftyapes.money/borrowers-dapp-guide/borrower-dashboard).


# Repaying a Loan

Time has almost run out! Everything you need to know to save your NFT from default.

Borrowers can make repayments from either the [Borrower Dashboard](https://docs.niftyapes.money/borrowers-dapp-guide/borrower-dashboard) or the Borrow screen.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FxTWkOy6tmBZIwYHcN07E%2Fimage.png?alt=media\&token=7523f274-38f6-4733-8583-de01c1fd89ae)

Borrowers click the "Repay Loan" button to make a repayment. The Repayment amount is calculated as the **Principal** + **Interest Accrued**.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FcNkzY1OPB8Vy5RevHkb7%2Fimage.png?alt=media\&token=915fb35f-bc60-40ad-bb92-760b85b671a5)

Any amount less than a full repayment (Principal Borrowed + Interest Accrued) will count as a partial repayment. The borrower can make partial repayments to reduce the amount of principal owed at the end of the loan, as well as the interest accrued over the remaining duration of the loan.

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FAgd3ujaDCshZtOJFS8ZO%2Fimage.png?alt=media\&token=6ae37875-331b-449b-8e4b-3c2360cc5162)

Once the loan is repaid, the collateral NFT is returned to the borrower's wallet and the loan is updated as **Repaid** on the [Borrower's Dashboard](https://docs.niftyapes.money/borrowers-dapp-guide/borrower-dashboard).

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FxC9cQoKXAaLA7NagOjFN%2Fimage.png?alt=media\&token=f6656c2d-7db9-45f3-b681-6e7822d078a5)


# Defaulting on a Loan

If the borrower does not pay back the principal + interest at the end of the loan duration, the lender has the option of [seizing the asset.](https://docs.niftyapes.money/lenders-dapp-guide/lender-dashboard/seizing-assets-from-loan-defaults)

![](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2F6xCiHKZlx7jcfL12kjNm%2Fimage.png?alt=media\&token=6ef2f021-6a59-4ae3-a473-4a6dbd72049d)

Borrowers can repay their loan and reclaim their collateral up until the transaction block when a Lender initiates the SeizeAsset call to the NiftyApes smart contract.

{% content-ref url="/pages/60NuRRhdsJDoeN0aG2TB" %}
[Loan Default FAQ](https://docs.niftyapes.money/overview/loan-default-faq)
{% endcontent-ref %}


# Borrower Dashboard

Borrowers can view a summary of their account, as well as a list of all active loans on the Borrower Dashboard.

![Borrowers can initiate a loan repayment on either the Borrow or Dashboard screen. ](https://3101901544-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fai9iiM3lynt9siXMc0yj%2Fuploads%2FrYMtBu5hJthnU5GxmPZX%2Fimage.png?alt=media\&token=f7829a91-e36d-4864-9771-f7effad1c926)


