Castle Crush (Reward Share)
This is a guide on how to the reNFT's SDK to interact with our Reward Share contracts.
This tutorial was written for SDK version
6.0.0
.
The reNFT SDK is written in TypeScript. You can install the SDK by running yarn add @renft/sdk
from your Command Line Interface (CLI).
In the following section, we'll talk about Whoopi; a smart contract which enables reward-sharing rental cycles for the players of Castle Crush on the Avalanche network.
Lending a Card
During a lending, the Whoopi contract takes custody of the Castle Crush NFT instead of sending it to the renter directly. This means, similarly to Sylvester, it operates using non-collateralized lending (i.e. the renter doesn't have to put up some form of deposit in case they don't feel like returning the token).
Upon creation of the lending, the NFT resides in the contract for as long as the lending is active.
⚠️ If there is no active renting, the lender may choose to terminate the lending early. However, if there is an active renting, the lender must wait for it to conclude.
Since Whoopi takes custody of the NFT, lenders are required to approve the NFT for handling by the smart contract. You can find an example of how to manage the approval process here.
Once a lender has authorized permission for the smart contract to trustlessly manage rentals, the lender can begin renting out various gnarly cards in their collection. In the following snippet, we'll walk through the flow of lending out two cards from Castle Crush:
Renting a Card
To initialize a rental, the renter must approve the PaymentToken
defined in the lending to be operated by the Whoopi contract on their behalf. To enable this, check out the following example on authorizing payment tokens.
Once the renter has approved the required PaymentToken
, and they possess at least the upfrontRentFee
amount of the token defined in the Lending to initialize a rental, they may proceed.
In the following example, let's see how a wallet with a sufficient PaymentToken
balance may initialize the rental of two tokens that have been made available by a lending:
Stopping a Lending
A lender may only stop a lending if there is no active renting associated with the lending. This enables renters to enjoy the full terms of their rental.
It is this property of the transaction, where a lending may only be stopped after a rental is over, why it is vital to set a maxRentDuration
.
A maxRentDuration
places an upper-limit on the maximum number of cycles that a token can be rented out for.
For example, if maxRentDuration
is set to 3
, it would mean that anyone in the marketplace would be allowed to rent the lending for up to 3
consecutive cycles before the window of opportunity is over. As a lender, you do not need to approve anything for this process, since this is all managed autonomously on the smart contract.
Once the terms of the lending period is over, or the lending isn't actively being rented out, a lender is free to call the stop lending function:
How do rentings terminate?
Unlike our other protocols, stopping a renting is managed internally, automatically via the reNFT bot. 🤖
Renters don't have to do anything!
In fact, only reNFT's bot possesses the capability to terminate the rentals. It performs this operation at midnight, after the completion of each Castle Crush lending cycle. This saves on costly expensive transactions for everyone.
The bot analyzes all of the rentings once-an-hour, meaning that it is possible that it will stop the renting with up to, but not exceeding, a one hour delay. This means sometimes you'll need to be a little patient.
Paying Rewards
Similarly to renting, a lender must ensure that the Castle Crush contract is approved to spend their ERC-20 reward token.
When paying rewards, a lender will transfer a lump sum per lending (along with the renters' addresses) and the smart contract will calculate handle the reward splitting as per the conditions of the original lending. This helps reward revenue share parties, and enforces the correct distribution of value to the pre-agreed shares on a given lending. Simple!
To learn about how to query for the on-chain data in a decentralized way, you can continue reading here.
Last updated