UNPKG

@nftsafe/sdk

Version:

Lend and rent any ERC721s and ERC1155s on supported mainnet and testnet.

88 lines (87 loc) 3.51 kB
import { BigNumber } from 'ethers'; import BigNumberJS from 'bignumber.js'; import { NFTStandard, PaymentToken } from './types'; /** * hexchar is 0 to 15 which is 2 ** 4 - 1. * This means that hexchar (aka nibble) is half a byte, * since byte is 8 bits. This function converts number * of bytes to number of nibbles. * * e.g. 2 bytes is 4 nibbles * * @param byteCount * @returns number of nibbles that represent the byteCount bytes */ export declare const bytesToNibbles: (byteCount: number) => number; /** * (21.42, 32) -> 0x0015002A * * (1.2, 32) -> 0x00010002 * * Notice how the whole decimal part is reprsented by the first 4 nibbles, * whereas the decimal part is represented by the second part, i.e. the * last 4 nibbles * * @param number * @param bitsize * @returns number's padded (of bitsize total length) hex format */ export declare const toPaddedHex: (number: number, bitsize: number) => string; declare type IObjectKeysValues = string[] | BigNumber[] | boolean[] | number[] | PaymentToken[] | string[][] | string[][][] | number[][] | [string, number][]; interface IObjectKeys { [key: string]: IObjectKeysValues | undefined; } interface PrepareBatch extends IObjectKeys { nftStandards: NFTStandard[]; nftAddresses: string[]; tokenIds: BigNumber[]; lendAmounts?: BigNumber[]; rentAmounts?: BigNumber[]; maxRentDurations?: number[]; minRentDurations?: number[]; dailyRentPrices?: string[]; collateralPrices?: string[]; paymentOptions?: PaymentToken[]; rentDurations?: number[]; lendingIds?: BigNumber[]; rentingIds?: BigNumber[]; allowedRenters?: string[][][]; } interface PrepareRevenueShareBatch extends IObjectKeys { nftStandards?: NFTStandard[]; nftAddresses: string[]; tokenIds: BigNumber[]; lendAmounts?: BigNumber[]; rentAmounts?: BigNumber[]; maxRentDurations?: number[]; paymentOptions?: PaymentToken[]; rentDurations?: number[]; lendingIds?: BigNumber[]; rentingIds?: BigNumber[]; upfrontFee?: string[]; revenueShareInfo?: string[][] | number[][]; allowedRenters?: string[][]; revenueAmounts?: BigNumber[]; renters?: string[]; revenueTokenAddress?: string[]; } /** * To spend as little gas as possible, arguments must follow a particular format * when passed to the contract. This function prepares whatever inputs you want * to send, and returns the inputs in an optimal format. * * This algorithm's time complexity is pretty awful. But, it will never run on * large arrays, so it doesn't really matter. * @param args */ export declare const prepareBatch: (args: PrepareBatch) => PrepareBatch; export declare const prepareRevenueShareBatch: (args: PrepareRevenueShareBatch) => PrepareRevenueShareBatch; export declare const convertToSpecificByteString: (number: number, byteSize: number) => string; export declare const numberToByte4: (number: number) => string; export declare const numberToByte8: (number: number) => string; export declare const numberToByte16: (number: number) => string; export declare const numberToByte32: (number: number) => string; export declare const byteToNumber: (number: string) => number; export declare const bigNumberToWei: (amount: string | number, decimal?: string | number) => BigNumberJS; export declare const bigNumberToEther: (amount: string | number, decimal?: string | number) => BigNumberJS; export {};