Integrate with Cyan in ~1hr!
https://github.com/usecyan/sdk
Install Cyan SDK
npm install @usecyan/sdk
yarn add @usecyan/sdk
Usage
Initialize the SDK instance with an API key, your current web3 provider, and Host URI
import {Cyan} from '@usecyan/sdk'
const apiKey = process.env.CYAN_API_KEY
const provider ... // your web3 provider
const host = 'https://testnet-api.usecyan.com'
const cyan = await Cyan.initiate({apiKey, provider, host})
Method references
configure
This method is responsible for downloading and storing configs from the Cyan API. You need to call this method before starting to use the SDK. However, if you have already initialized the SDK using the initiate
method, then there is no need to call this method.
async configure(): Promise<IConfigs>
priceBnplsStep1
Performs the first step of pricing BNPLs and generating options from the response.
async priceBnplsStep1(
currencyAddress: string,
items: Array<IItem | IItemWithPrice>
): Promise<{
items: (IItemWithPrice & { interestRate: number })[];
options: IOption[];
}>
priceBnplsStep2
Performs the second step of pricing BNPLs.
- Params: (ICreatePlanParams, IItemWithPrice)
- Returns:
IPricedItemWithPlan
async priceBnplsStep2(args: {
wallet: string;
items: IItemWithPrice[];
option: IOption;
currencyAddress: string;
autoRepayStatus: 0 | 1;
}): Promise<Errored<ICreatePlanParams & { isChanged: boolean; marketName: string }>[]>
pricePawnsStep1
Performs the first step of pricing Pawns and generating options from the response. (IItemWithPrice, IOption)
async pricePawnsStep1(
currencyAddress: string,
items: Array<IItem | IItemWithPrice>
): Promise<{
items: (IItemWithPrice & { interestRate: number })[];
options: IOption[];
}>
pricePawnsStep2
Performs the second step of pricing Pawns.
- Params: (ICreatePlanParams, IItemWithPrice)
- Returns:
IPricedItemWithPlan
async pricePawnsStep2(args: {
wallet: string;
items: IItemWithPrice[];
option: IOption;
currencyAddress: string;
autoRepayStatus: 0 | 1;
}): Promise<Errored<ICreatePlanParams & { isChanged: boolean; marketName: string }>[]>
acceptPlanInfo
Accepts payment plans by signing a typed data message and sending it to the API. (ICreatePlanParams)
async acceptPlans(plans: ICreatePlanParams[]): Promise<void>
checkAndAllowCurrencyForPlan
Checks if the user has allowed the Payment Plan Contract to spend the specified amount of the given currency, and approves it if not.
async checkAndAllowCurrencyForPlan(currencyAddress: string, amount: BigNumber): Promise<void>
getApproval
Approve Payment Plan Contract to spend a specific ERC721 or ERC1155 token on behalf of the signer.
async getApproval(address: string, tokenId: string, tokenType?: INftType): Promise<void>
createBnpls
Creates BNPL (Buy Now Pay Later) plans by calling the createBNPL
function of the payment plan contract. (ICreatePlanParams)
async createBnpls(
currencyAddress: string, // The address of the currency to use for the BNPL plans.
plans: ICreatePlanParams[], // An array of objects containing the parameters for each plan to create.
useOriginalWallet: boolean = true // Whether to pay the downpayment using the original wallet or not (only works for native currency)
): Promise<ContractTransaction>
createPawn
Creates pawn plans by calling the createPawn
function of the payment plan contract. (ICreatePlanParams)
async createPawns(plans: ICreatePlanParams[]): Promise<ContractTransaction>
getPaymentInfo
Get the following payment information for a payment plan
async getPaymentInfo(
plan: IPlan, // The payment plan object
isEarlyRepayment: boolean = false // Optional flag to indicate if this is early repayment or not
): Promise<{
payAmountForCollateral: string;
payAmountForInterest: string;
payAmountForService: string;
currentPayment: string;
dueDate?: Date;
}>
pay
Pays the next payment for a payment plan
async pay(plan: IPlan): Promise<ContractTransaction>
payEarly
Pays all the remaining payment for a payment plan
async payEarly(plan: IPlan): Promise<ContractTransaction>
payBulk
Pays multiple payment plans in bulk. If isEarlyPayment
is set to true
, the function pays all the remaining amounts for the specified payment plans.
async payBulk(plans: IPlan[], isEarlyPayment: boolean, releaseWallet?: string): Promise<ContractTransaction>
fulfillOffer
Fulfills an offer on a payment plan.
async fulfillOffer(plan: IPlan, offer: IOffer): Promise<ContractTransaction>
getUserPlans
Retrieve BNPL or Pawn plans, by user, which are Activated, Funded, or in Pending status.
async getUserPlans(address: string): Promise<IPlan[]>
getCyanWallet
Returns an instance of the CyanWallet contract for the current user.
async getCyanWallet(): Promise<CyanWallet>
getTopBids
Returns the top bids for a specific collection and token.
async getTopBids(collectionAddress: string, tokenId?: string): Promise<IOffer[]>
createCyanWallet
Creates a new CyanWallet for the current user if it does not exist, or returns the existing one.
async createCyanWallet(): Promise<ContractTransaction>
getPaymentPlanContract
Retrieves the PaymentPlanV2 contract instance for the current chain. (Typically, there is no need to utilize this method. However, if direct interaction with the contract is necessary, invoking this method will provide the currently active instance of PaymentPlanContract.)
async getPaymentPlanContract(): Promise<PaymentPlanV2>