Skip to content

Commit

Permalink
refactor adapters (#56)
Browse files Browse the repository at this point in the history
* refactor adapters

Signed-off-by: Nguyen Le Vu Long <[email protected]>

* fix test

Signed-off-by: Nguyen Le Vu Long <[email protected]>

---------

Signed-off-by: Nguyen Le Vu Long <[email protected]>
  • Loading branch information
longngn authored Jan 23, 2025
1 parent 7389fab commit 070f501
Show file tree
Hide file tree
Showing 7 changed files with 788 additions and 854 deletions.
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

0 comments on commit 070f501

Please sign in to comment.