From e91317cbbc0bbcde55c01cb417e8faf7307263dd Mon Sep 17 00:00:00 2001 From: "munkhzulnee@gmail.com" Date: Fri, 16 Aug 2024 16:13:26 +0800 Subject: [PATCH] CD-2472 support for getting max LTVs of collections --- package.json | 2 +- src/api.ts | 12 ++++++++++++ src/sdk.ts | 12 ++++++++++++ src/types.ts | 24 ++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index df4da5b..d758d21 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.2.0", + "version": "0.2.1", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/api.ts b/src/api.ts index 77d459f..11b5473 100644 --- a/src/api.ts +++ b/src/api.ts @@ -3,6 +3,7 @@ import { IConfigs, ICreateAcceptance, IFulfillOffer, + IGetCollectionsMaxLtvs, IGetCollectionTopBid, IOffer, IPlan, @@ -36,6 +37,17 @@ export class CyanAPI { return await this.fetchData('/v2/configs'); } + /** + * Retrieve the maximum LTVs for the given plan type and chain across all supported collections + */ + public async getMaxLtvs(args: IGetCollectionsMaxLtvs['params']): Promise { + const { planType, chain } = args; + const queryParams = new URLSearchParams({ + planType: planType.toString(), + }); + return await this.fetchData(`/v2/collections/${chain}/max-ltv?${queryParams}`); + } + /** * Creates acceptance signature */ diff --git a/src/sdk.ts b/src/sdk.ts index b237f37..dd4b03e 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -29,6 +29,8 @@ import { IOffer, ICurrency, ItemType, + IGetCollectionsMaxLtvs, + PlanTypes, } from './types'; import { generateBnplOptions, @@ -441,6 +443,16 @@ export class CyanSDK { return topBids; } + /** + * Retrieve the maximum LTVs for the given plan type across all supported collections + * @param {string} planType - The plan type + * @returns {Promise} The maximum LTVs by currency address + */ + public async getMaxLtvs(planType: 'bnpl' | 'pawn'): Promise { + const chain = await this._getChain(); + return await this.api.getMaxLtvs({ chain, planType: PlanTypes[planType] }); + } + /** * Fulfill bid offer of the plan * @param {IPlan} plan - Plan object to sell diff --git a/src/types.ts b/src/types.ts index b5dbab4..8097489 100644 --- a/src/types.ts +++ b/src/types.ts @@ -10,6 +10,30 @@ export type ICyanSDKConstructor = { export const chains = ['mainnet', 'goerli', 'sepolia', 'polygon', 'mumbai', 'arbitrum', 'bsc', 'optimism'] as const; export type IChain = typeof chains[keyof typeof chains]; +export const PlanTypes = { + bnpl: 0, + pawn: 1, +} as const; +export type IPlanType = typeof PlanTypes[keyof typeof PlanTypes]; + +type IGetCollectionsMaxLtvsParams = { + planType: IPlanType; + chain: IChain; +}; + +type ICollectionsWithMaxLtvs = { + address: string; + maxLtvs: { + currencyAddress: string; + maxLtv: number; + }[]; +}[]; + +export type IGetCollectionsMaxLtvs = { + params: IGetCollectionsMaxLtvsParams; + result: ICollectionsWithMaxLtvs; +}; + const statusType = { Pending: 0, Funded: 1,