Castle Crush (Reward Share)
This is a guide on how to the reNFT's SDK to interact with our Reward Share contracts.
Lending a Card
import { JsonRpcProvider } from '@ethersproject/providers';
import { parseFixed } from '@ethersproject/bignumber';
import { Wallet } from '@ethersproject/wallet';
import {
Whoopi,
PaymentToken,
RESOLVERS,
getRenftContract,
DEPLOYMENT_WHOOPI_AVALANCHE_MAINNET_V0,
NETWORK_RESOLVERS,
} from '@renft/sdk';
const provider = new JsonRpcProvider('https://api.avax-test.network/ext/bc/C/rpc');
const privKey = '';
const wallet = new Wallet(privKey);
await wallet.connect(provider);
const castleCrushNftAddress = "0xeA4E79F0a40A9A468a5159499b738dc6b1332447";
const whoopi = getRenftContract({
deployment: DEPLOYMENT_WHOOPI_AVALANCHE_MAINNET_V0,
signer: wallet,
});
const { network: { type: networkType } } = DEPLOYMENT_WHOOPI_AVALANCHE_MAINNET_V0;
// Network Resolvers define the contract addresses that various ERC-20
// tokens have been deployed to on each network. Note that not all
// ERC-20s have been deployed to every network. For cases where a token
// is missing, it will take the value of PaymentToken.SENTINEL; an
// internal value we use to represent a missing token.
const paymentTokenResolvers = NETWORK_RESOLVERS[networkType];
// Which tokenIds we'd like to rent out from our wallet.
const tokenId = [210, 200];
// ! Note that if allowedRenters is empty, you must set upfrontRentFee to
// ! a non zero value.
const upfrontRentFee = [
parseFixed("1", paymentTokenResolvers[PaymentToken.USDC]).toString(),
parseFixed("1", paymentTokenResolvers[PaymentToken.USDC]).toString()
];
// ! you can't use SENTINEL as a payment token, even though
// ! you don't want to set an upfront rent fee. Just use any
// ! payment token in such a case.
const paymentToken = [PaymentToken.USDC, PaymentToken.USDC];
// Which addresses get to benefit from the terms of the rental?
const revShareBeneficiaries = [
["0x000000045232fe75A3C7db3e5B03B0Ab6166F425", "0x465DCa9995D6c2a81A9Be80fBCeD5a770dEE3daE"],
["0x465DCa9995D6c2a81A9Be80fBCeD5a770dEE3daE", "0xeA4E79F0a40A9A468a5159499b738dc6b1332447"]
];
// ! portions sum cannot be 100 here. At lend, we don't know who will rent,
// ! and the renter is always a mandatory part in rev share. We are not setting
// ! the renter here at lend time. Therefore, 100 - sum(portions) is what
// ! gets eventually assigned to the renter.
const revSharePortions = [
[50, 40], // 10% is how much the renter will get on this lending
[90, 5] // 5% is how much ther renter will get on this lending
];
// * means 1 and 2 cycles respectively for each token being rented.
const maxRentDuration = [1, 2];
const txn = await whoopi.lend(
castleCrushNftAddress,
tokenId,
upfrontRentFee,
revShareBeneficiaries,
revSharePortions,
maxRentDuration,
paymentToken,
undefined,
// ! uncomment this if it does not allow you to execute because it predicts that
// ! the transaction will fail
// { gasLimit: 1000000 }
);
const receipt = await txn.wait();Renting a Card
Stopping a Lending
How do rentings terminate?
Paying Rewards
Last updated