Skip to main content

Rent

Rent

This Rent contract serves as a middleman and allows owners of NFTs to lock their assets in this smart contract for a fixed epoch period. The contract then mints a new identical "shadow" NFT on a separate smart contract. This "shadow" NFT can be sold and transferred like any other NFT when being rented. However, after the epoch is finished, the "shadow" NFT is destroyed and the original NFT is returned to its original owner. This contract can handle multiple rentals at a time and keeps track of rental instances using a rentId. This contract is great for allowing owners of NFTs to earn income by renting out their assets and incentivizes renters to get a chance to temporarily own a cool NFT.

version

string version

ERC165TAG

bytes4 ERC165TAG

Create

event Create(uint256 rentId, address owner, address renter, uint256 nftId, uint256 timePeriods, uint256 pricePerPeriod, uint256 expireTimePerPeriod)

Pay

event Pay(uint256 rentId, uint256 amountPaid)

End

event End(uint256 rentId, uint256 amountPaid)

Claim

event Claim(address owner, uint256 amountClaimed)

RentalTerms

struct RentalTerms {
uint256 nftId;
address owner;
address renter;
bool ended;
uint256 timePeriods;
uint256 pricePerPeriod;
uint256 expireTimePerPeriod;
}

acceptableToken

address acceptableToken

shadowAddr

address shadowAddr

contractAddr

address contractAddr

numRentals

uint256 numRentals

rentTermsId

mapping(uint256 => struct Rent.RentalTerms) rentTermsId

timePeriodsPaid

mapping(uint256 => uint256) timePeriodsPaid

balances

mapping(address => uint256) balances

constructor

constructor() public

initialize

function initialize(address _admin, address _acceptableToken, address _contractAddr, address _shadowAddr, address _forwarder) external

Initializing the Rent contract

NameTypeDescription
_adminaddressaddress of the launcher, which is this contract
_acceptableTokenaddressaccepted ERC20 token for payment
_contractAddraddresscontract address for original NFT
_shadowAddraddressaddress where "shadow" NFT is minted
_forwarderaddressaddress for trusted forwarder for openGSN

proxyInitialize

function proxyInitialize(address _admin, address _acceptableToken, address _contractAddr, address _shadowAddr, address _forwarder) external

__Rent_init

function __Rent_init(address _admin, address _acceptableToken, address _contractAddr, address _shadowAddr, address _forwarder) internal

__Rent_init_unchained

function __Rent_init_unchained(address _admin, address _acceptableToken, address _contractAddr, address _shadowAddr) internal

createRental

function createRental(struct Rent.RentalTerms rentalTerm) external

Creates a single Rental based on the inputted Rental Term Struct that outlines all of the terms for that specific rental instance. Updates the various mappings and gives the Rental an ID. Increments the number of Rentals handled by this contract

NameTypeDescription
rentalTermstruct Rent.RentalTermsinputted rental term struct

startRent

function startRent(uint256 rentId) external payable

this function can only be called at the very start of a Rental process. It must be called to mint the shadow NFT

Starts the payment process for the Rental with rentId with it's first payment

NameTypeDescription
rentIduint256inputted Rental ID that is used in the mapping to get the corresponding rental term struct

payRent

function payRent(uint256 rentId, uint256 timePeriodsToPay) public payable

function that allows a renter to pay rent for any number of time periods

NameTypeDescription
rentIduint256inputted Rental ID that is used in the mapping to get the corresponding rental term struct
timePeriodsToPayuint256allows the renter to decide how many time periods they want to pay for at once

endRental

function endRental(uint256 rentalId) external payable

this function only updates the boolean for the rent status (ended vs not) and transfers the ownership of the NFT back to its owner. It does not give funds to the owner in ERC20 tokens

this function allows the owner to end the rental at any point in time

NameTypeDescription
rentalIduint256inputted Rental ID that is used in the mapping to get the corresponding rental term struct

ownerClaim

function ownerClaim() external payable

this function enables the owner to claim the balances paid by the renter

getRental

function getRental(uint256 rentId) external view returns (struct Rent.RentalTerms)

gets a rental instance based on the inputted rentId

NameTypeDescription
rentIduint256inputted rental term struct id

getNumRentals

function getNumRentals() external view returns (uint256)

gets the number of rentals created on this contract

getTimePeriodsPaid

function getTimePeriodsPaid(uint256 rentalId) external view returns (uint256)

gets the number of time periods paid by a renter for a specific Rental based on the inputted rentId

NameTypeDescription
rentalIduint256inputted rental term struct id

getTimePeriodsLeftToPay

function getTimePeriodsLeftToPay(uint256 rentalId) external view returns (uint256)

gets how many time periods are left to pay for a specific Rental

NameTypeDescription
rentalIduint256inputted rental term struct id

getBalance

function getBalance(address owner) external view returns (uint256)

gets the total balance that is claimable by an owner

NameTypeDescription
owneraddressowner of a Rental that can call this function to see how much they can claim

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual returns (bool)

ERC165 Support

NameTypeDescription
interfaceIdbytes4hash of the interface testing for
NameTypeDescription
[0]boolbool whether interface is supported