Skip to content

Commit

Permalink
Getting max LTVs of supported collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Naranbayar authored Aug 16, 2024
2 parents 4c0b1c6 + e91317c commit 8bbdd79
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.2.0",
"version": "0.2.1",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
12 changes: 12 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
IConfigs,
ICreateAcceptance,
IFulfillOffer,
IGetCollectionsMaxLtvs,
IGetCollectionTopBid,
IOffer,
IPlan,
Expand Down Expand Up @@ -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<IGetCollectionsMaxLtvs['result']> {
const { planType, chain } = args;
const queryParams = new URLSearchParams({
planType: planType.toString(),
});
return await this.fetchData(`/v2/collections/${chain}/max-ltv?${queryParams}`);
}

/**
* Creates acceptance signature
*/
Expand Down
12 changes: 12 additions & 0 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
IOffer,
ICurrency,
ItemType,
IGetCollectionsMaxLtvs,
PlanTypes,
} from './types';
import {
generateBnplOptions,
Expand Down Expand Up @@ -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<IGetCollectionsMaxLtvs['result']>} The maximum LTVs by currency address
*/
public async getMaxLtvs(planType: 'bnpl' | 'pawn'): Promise<IGetCollectionsMaxLtvs['result']> {
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
Expand Down
24 changes: 24 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8bbdd79

Please sign in to comment.