> For the complete documentation index, see [llms.txt](https://docs.niftyapes.money/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.niftyapes.money/overview/contracts-and-security/lending.sol.md).

# 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.
