Skip to content

An ERC-721 NFT Contract with option to lend and borrow. Submitted for Advanced Smart Contracts Course.

License

Notifications You must be signed in to change notification settings

pradeepp88/ERC-721-Lending-Contract

Repository files navigation

DBNFT - An ERC-721 Lending Contract

DBNFT is an ERC-721 Contract for digital collectibles. The contract is designed to be integrated with either a web application or a mobile App. It allows the user to create and interact with ERC-721 tokens. This contract is aimed for artists who wish to convert their digital creations into NFTs and monetize them by either selling or lending the NFT. The NFT stores the ownership and lending data within the token itself.

DeFi Components

The token is designed with following characteristics to benefit from the DeFi industry (staking or yield farming) and also to avoid misuse of the tokens when interacting with the contract.

Lend/Borrow option:

  • Only the owner of the token can list the token for loan.
  • When the token is loaned, the token is transferred to the borrower with complete access to transfer the token to any other DeFi protocol. But the data stored in the token cannot be modified. The token also holds the borrower address, time of borrowing and the duration.
  • The loan amount is calculated based on the compound interest formula calculated every second. The borrower has to pay this loan amount in addition to the refundable deposit of twice the value of token upfront, before having access to the token. When the borrower returns the token, the deposit is returned back to them.

  • The owner of the token cannot claim access to the token during the loan period. They can however liquidate the token and get the security deposit from the borrower, if the borrower fails to return the token before the committed time.

  • If the borrower fails to return the token by the committed time, they will forfeit their security deposit.

Buy/Sell option:

  • When the token is sold, the ownership is completely transferred by modifying the ownership details in the token. The buyer is free to use the token as they wish.

Smart Contract Functions

Mint NFT

Creates a new NFT with:

  • ID
  • Description

  • Address of Owner

  • Adress of Borrower

  • Status for Buy/Sell - FOR_SALE and NOT_FOR_SALE

  • Status for Loan - FOR_LOAN, ON_LOAN, LIQUIDATED

List NFT for Sale

The owner of token can list his NFT for Sale with an option to update the value of token. This option will transfer his token to Contract until someone buys from it.

BuyNFT

Anyone can buy a NFT listed for sale by calling this function and transferring the token value.

List NFT for Loan

The owner of token can list his NFT for loan. This option will transfer his token to the Contract until someone borrows from it.

Borrow NFT

Anyone can borrow the NFT listed for loan by calling this function and transferring the loan amount. The loan amount can be obtained by calling the calcLoan function.

Testing

All the functions are tested and the contract has 100% coverage. image

Security Considerations

All the contracts are written in latest version of Solidity 0.8.0. So the mathematical overflow checks are already available by default with this version. In addition to this, the following security features are integrated into the smart contract architecture.

  • Check Effect Interactions: All the interactions in the functions follow CEI pattern to avoid re-entrancy.
  • Guard Check: The two main functions: Buy/Sell and Lend/Borrow is managed by their individual status controlled by the state variable of the contract. Every interaction starts with checking the status of the contract. This will restrict the unwanted behaviour of the contract.
  • Safe Transfer: Transfer function has been used for transferring the amounts and balances. For liquidating the contract, PushoverPull method has been used which increases security.

About

An ERC-721 NFT Contract with option to lend and borrow. Submitted for Advanced Smart Contracts Course.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published