@infy-protocol/sdk
v0.0.5
Published
Lend and rent any ERC721s and ERC1155s on supported mainnet and testnet.
Downloads
10
Maintainers
Readme
Welcome to Infy SDK
Lend and rent any ERC721s and ERC1155s on supported mainnet and testnet.
Infy SDK allows you to lend and rent ERC 721 and ERC 1155 NFTs in collateralized and collateral free way.
Install
yarn add @infy-protocol/sdk
or Add "@infy-protocol/sdk": "latest-version"
to your package.json
How to access:
import-module in your in page import { SupportedChainIds, ContractType, GetNetworkDetailsByChainId, CONTRACT_TYPE_LIST,SupportedChainIds, ALL_SUPPORTED_CHAIN_IDS ....} from "@infy-protocol/sdk"
Get Contract and Network details:
SDK provider the "NetworkConfig" JSON to get the Contract addresses, Subgraph URL, Chain information, and the Blockchain supporting utils
NetworkConfig =
{
chainid: {
name: string,
chainId: number,
shortName: string,
chain: string,
networkId: number,
nativeCurrency: {},
rpc: string[],
faucets: string[],
explorers: { name: string, url: string, standard: string },
infoURL: string,
logoURL: string,
collateralizedContractAddresses: string[],
collateralFreeContractAddresses: string[],
revenueSharedNFTRentalsContractAddresses: string[];
revenueSharedConfiguratorContractAddresses: string[];
e721ContractAddresses: string[], // Testnet
e721BContractAddresses: string[], // Testnet
e1155ContractAddresses: string[], // Testnet
e1155BContractAddresses: string[], // Testnet
wETHContractAddresses: string[],
daiContractAddresses: string[],
usdcContractAddresses: string[],
usdtContractAddresses: string[],
tUSDContractAddresses: string[],
utilsContractAddresses: string[],
subgraphs: {
collateralized: string,
collateralFree: string,
revenueSharedNFTRentals: string;
e721: string, // Testnet and Moralis unsupported chains
e1155: string // Testnet and Moralis unsupported chains
},
moralisDetails: { isSupported: boolean, lookupValue: string },
chainApiId: string,
isSupported: boolean,
isTestnet: boolean
}
}
How to use:
import sdk import { NetworkConfig, SupportedChainIds, ContractType, GetNetworkDetailsByChainId } from "@infy-protocol/sdk";
Now you can use it
const GetNetworkDetailsByChainId = (networkId: SupportedChainIds): TypeNetworkDetails => { return NetworkConfig[networkId] } const polygonContactDetails = GetNetworkDetailsByChainId(137) Or const polygonContactDetails = NetworkConfig[137]
- polygonContactDetails.collateralizedContractAddresses[0]
- polygonContactDetails.collateralFreeContractAddresses[0]
- polygonContactDetails.revenueSharedNFTRentalsContractAddresses[0] .... To get subgraph endpoint
- polygonContactDetails.subgraphs.collateralized
- polygonContactDetails.subgraphs.collateralFree
- polygonContactDetails.subgraphs.revenueSharedNFTRentals ....
Supported Chains:
The "SupportedChainIds" enum is available in SDK to help you
Supported Payment Tokens:
The "getPaymentOption" method of "RevenueShared contract will return token address by passing index. Note: index is starting from 1 and it will return ZERO_ADDRESS(0x0000000000000000000000000000000000000000) for unlisted index;
Supporting NFT Standard:
The "NFTStandard" enum avaialble in sdk
Create Infy contract object :
The "ContractType" enum which is already present in SDK will help you to get the specific type of contract.
- Collateralized Contract: const object = new CollateralizedNFTRentals(signer, Number(chainId));
- Collateral Free Contract: const object = new CollateralFreeNFTRentals(signer, Number(chainId));
- Revenue share Contract: const object = new RevenueSharedNFTRentals(signer, Number(chainId));
Call to contract methods:
Collateralized and CollateralFree Contract
- Here, in arguments all individual elements should be in the form of List
object.lend( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendAmounts: BigNumber[], maxRentDurations: number[], minRentDurations: number[], dailyRentPrices: string[], paymentOptions: number[], collateralPrices: string[], allowedRenters: string[][][] );
object.stopLending( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[] );
object.rent( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[], rentDurations: number[], rentAmounts: BigNumber[] );
object.stopRenting( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[], rentingIds: BigNumber[] );
object.claimRentOrCollateral( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[], rentingIds: BigNumber[] );
Let"s see how sdk format data and some data types
Later SDK will use "prepareBatch" methods of SDK"s utils file to convert it into formatted value
Let"s see for lend call how SDK converts data into formatted data by using "prepareBatch" method
lend( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendAmounts: BigNumber[], maxRentDurations: number[], minRentDurations: number[], dailyRentPrices: BigNumber[], paymentOptions: number[], collateralPrices: BigNumber[], allowedRenters: string[][][] ): Promise { const args = prepareBatch({ nftStandards: nftStandards.map(nft => Number(nft)), nftAddresses: nftAddresses.map(nft => String(nft).toLowerCase()), tokenIds: tokenIds.map(id => BigNumber.from(id)), lendAmounts: lendAmounts.map(amt => BigNumber.from(amt)), maxRentDurations: maxRentDurations.map(x => Number(x)), minRentDurations: minRentDurations.map(x => Number(x)), dailyRentPrices: dailyRentPrices.map(value => BigNumber.from(value)), paymentOptions, collateralPrices: collateralPrices.map(value => BigNumber.from(BigNumber.from(value)) ), allowedRenters: allowedRenters, });
return await this.contract.lend( args.nftStandards, args.nftAddresses, args.tokenIds, args.lendAmounts, args.maxRentDurations, args.minRentDurations, args.dailyRentPrices, args.paymentOptions, args.collateralPrices, args.allowedRenters ); }
Example:
User entred value: dailyRentPrices = 6 WETH , collateralPrices = 20 WETH , and decimal =18
dailyRentPrices = bigNumberToWei(6, 18); // output: 6000000000000000000 collateralPrices = bigNumberToWei(20, 18) // output: 20000000000000000000
dailyRentPrices =bigNumberToEther(6000000000000000000, 18); // output: 6 collateralPrices = bigNumberToEther(20000000000000000000, 18) // output: 20
Note: dailyRentPrices & collateralPrices must be passed to sdk method in WEI according to selected payment token decimal.
Revenue Shared Contract
object.lend( nftStandard: NFTStandard[], nftAddress: string[], tokenId: BigNumber[], lendAmount: BigNumber[], upfrontFee: BigNumber[], maxRentDuration: number[], revenueShareInfo: [string[], number[]][], allowedRenter: string[][][], paymentOption: number[] );
object.rent( nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[], rentDurations: number[], rentAmounts: BigNumber[] );
object.stopRenting( nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[], rentingIds: BigNumber[] );
object.stopLending( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[] );
object.shareRevenue( nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[], revenueAmounts: BigNumber[], renters: string[], revenueTokenAddress: string[] );
Let"s see how sdk format data and some data types
lend( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendAmounts: BigNumber[], upfrontFees: BigNumber[], maxRentDurations: number[], revenueShareInfos: [string[], number[]][], allowedRenters: string[][][], paymentOptions: number[] ): Promise {
const args = prepareRevenueShareBatch({ nftStandards: nftStandards.map(nft => Number(nft)), nftAddresses: nftAddresses.map(nft => String(nft).toLowerCase()), tokenIds: tokenIds.map(id => BigNumber.from(id)), lendAmounts: lendAmounts.map(amt => BigNumber.from(amt)), upfrontFees: upfrontFees.map(value => BigNumber.from(value)), maxRentDurations: maxRentDurations.map(x => Number(x)), revenueShareInfos, allowedRenters, paymentOptions, });
const tupleFomattedData = args.nftAddresses.map((address, index) => [
args.nftStandards?.[index],
address,
args.tokenIds[index],
args.lendAmounts?.[index],
args.upfrontFees?.[index],
args.maxRentDurations?.[index],
args.revenueShareInfos?.[index],
args.allowedRenters?.[index],
args.paymentOptions?.[index],
]);
return await this.contract.lend(tupleFomattedData);
}
Example:
User entred value: upfrontFees = 6 WETH, decimal =18
upfrontFees = bigNumberToWei(6,18); // output: 6000000000000000000 upfrontFees =bigNumberToEther(6000000000000000000,18); // output: 6
Note: upfrontFees must be passed to the SDK method in WEI according to the selected payment token decimal.
Note: Good to have below validation
- the "nftStandards" should be one of the available in "NFTStandard" type of SDK. For instance, NFTStandard.E721 and NFTStandard.E1155
- The "maxRentDurations" must be grater than "minRentDurations".
- The "paymentOptions" need to pass the index as a number
- The "collateralPrices" value should be ZERO for the CollateralFree contract.
- The "allowedRenters" should be empty array for allowing all the user to rent.
POLYGON_MAINNET:
CollateralizedContractAddresses: ["0xCf311a6606c909Cc5E048FE1f3FF1e63dEec6a26"], CollateralFreeContractAddresses: ["0x4fF4C17F24d03Faf9d5097D7E71310AeF71a0f70"], RevenueSharedNFTRentalsContractAddresses: ["0x9C5dA47ED0281aF302ED1E77a1B961ed980d5385"], RevenueSharedConfiguratorContractAddresses: ["0x4a1BDD3a5BBAb4312432b1b507d67Bce6baC8B22"], subgraphs: { collateralized: "https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-collateralized-polygon", collateralFree: "https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-collateral-free-polygon", revenueSharedNFTRentals: "https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-revenue-share-polygon", }
POLYGON_TESTNET:
CollateralizedContractAddresses: ["0xDA0b94C237b435cbeA5Dd5aD44cc6F235aaE5855"], CollateralFreeContractAddresses: ["0x8f5138FDe08Be9061612086f4bCA472a563544c4"], RevenueSharedNFTRentalsContractAddresses: ["0x9352a6007F186c11FBC1daBc9fFFFA62Ea9eb9f3"], RevenueSharedConfiguratorContractAddresses: ["0x418258c4412bC13b3C877374BCE70890d456Cc1e"], subgraphs: { collateralized: "https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-collateralized-mumbai", collateralFree: "https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-collateral-free-mumbai", revenueSharedNFTRentals: "https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-revenue-share-mumbai", }
BINANCE_MAINNET:
CollateralizedContractAddresses: ["0x4dA60d2646a8ed5461457012f5cd7b87905E9e55"], CollateralFreeContractAddresses: ["0x858feeb9D751A07aF2D7b5ad7fa996B30261a891"], RevenueSharedNFTRentalsContractAddresses: ["0xEc12AB0306A3bbDa93aACC2BE931F8A8343bCEA3"], RevenueSharedConfiguratorContractAddresses: ["0x8F975d55b8b20D6e53264A4730998C14fE5b8C25"], subgraphs: { collateralized: "https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-collateralized-bsc", collateralFree: "https://thegraph.com/explorer/subgraph/dudhatparesh/infy-collateral-free-bsc", revenueSharedNFTRentals: "https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-revenue-share-bsc", }