Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor adapters #56

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
848 changes: 414 additions & 434 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

44 changes: 17 additions & 27 deletions src/adapters/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ import { LbeV2Types } from "../types/lbe-v2";
import { PoolV1, PoolV2, StablePool } from "../types/pool";
import { TxHistory } from "../types/tx.internal";

export type PaginationByPage = {
page?: number
count?: number
order?: "asc" | "desc"
}

export type PaginationByCursor = {
cursor?: string
count?: number
order?: "asc" | "desc"
}

export type Pagination = PaginationByPage | PaginationByCursor

export type GetPoolByIdParams = {
id: string;
};
Expand All @@ -21,15 +35,6 @@ export type GetPoolPriceParams = {
decimalsB?: number;
};

export type GetPoolsParams = {
page?: number;
cursor?: string;
};

export type GetStablePoolHistoryParams = {
lpAsset: Asset;
};

export type GetStablePoolPriceParams = {
pool: StablePool.State;
assetAIndex: number;
Expand All @@ -40,15 +45,6 @@ export type GetV1PoolHistoryParams = {
id: string;
};

export type GetV2PoolHistoryParams =
| {
assetA: Asset;
assetB: Asset;
}
| {
lpAsset: Asset;
};

export type GetV2PoolPriceParams = {
pool: PoolV2.State;
decimalsA?: number;
Expand Down Expand Up @@ -81,9 +77,9 @@ export interface Adapter {
/**
* @returns The latest pools or empty array if current page is after last page
*/
getV1Pools(params: GetPoolsParams): Promise<PoolV1.State[]>;
getV1Pools(pagination: Pagination): Promise<PoolV1.State[]>;

getV1PoolHistory(params: GetV1PoolHistoryParams): Promise<TxHistory[]>;
getV1PoolHistory(pagination: Pagination, params: GetV1PoolHistoryParams): Promise<TxHistory[]>;

/**
* Get pool price.
Expand All @@ -98,15 +94,13 @@ export interface Adapter {
getAllV2Pools(): Promise<{ pools: PoolV2.State[]; errors: unknown[] }>;

getV2Pools(
params: GetPoolsParams
pagination: Pagination
): Promise<{ pools: PoolV2.State[]; errors: unknown[] }>;

getV2PoolByPair(assetA: Asset, assetB: Asset): Promise<PoolV2.State | null>;

getV2PoolByLp(lpAsset: Asset): Promise<PoolV2.State | null>;

getV2PoolHistory(params: GetV2PoolHistoryParams): Promise<PoolV2.State[]>;

/**
* Get pool price.
* @param {Object} params - The parameters to calculate pool price.
Expand Down Expand Up @@ -136,10 +130,6 @@ export interface Adapter {

getStablePoolByNFT(nft: Asset): Promise<StablePool.State | null>;

getStablePoolHistory(
params: GetStablePoolHistoryParams
): Promise<StablePool.State[]>;

/**
* Get stable pool price.
*
Expand Down
Loading
Loading