Add optional refresh parameter for whirlpoolclient (#17)
This commit is contained in:
parent
0ea0bb2d53
commit
72666c9153
|
@ -10,12 +10,12 @@ import { WhirlpoolImpl } from "./whirlpool-impl";
|
||||||
export class WhirlpoolClientImpl implements WhirlpoolClient {
|
export class WhirlpoolClientImpl implements WhirlpoolClient {
|
||||||
constructor(readonly ctx: WhirlpoolContext, readonly fetcher: AccountFetcher) {}
|
constructor(readonly ctx: WhirlpoolContext, readonly fetcher: AccountFetcher) {}
|
||||||
|
|
||||||
public async getPool(poolAddress: Address): Promise<Whirlpool> {
|
public async getPool(poolAddress: Address, refresh = false): Promise<Whirlpool> {
|
||||||
const account = await this.fetcher.getPool(poolAddress, true);
|
const account = await this.fetcher.getPool(poolAddress, refresh);
|
||||||
if (!account) {
|
if (!account) {
|
||||||
throw new Error(`Unable to fetch Whirlpool at address at ${poolAddress}`);
|
throw new Error(`Unable to fetch Whirlpool at address at ${poolAddress}`);
|
||||||
}
|
}
|
||||||
const tokenInfos = await getTokenInfos(this.fetcher, account);
|
const tokenInfos = await getTokenInfos(this.fetcher, account, false);
|
||||||
return new WhirlpoolImpl(
|
return new WhirlpoolImpl(
|
||||||
this.ctx,
|
this.ctx,
|
||||||
this.fetcher,
|
this.fetcher,
|
||||||
|
@ -26,8 +26,8 @@ export class WhirlpoolClientImpl implements WhirlpoolClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getPosition(positionAddress: Address): Promise<Position> {
|
public async getPosition(positionAddress: Address, refresh = false): Promise<Position> {
|
||||||
const account = await this.fetcher.getPosition(positionAddress, true);
|
const account = await this.fetcher.getPosition(positionAddress, refresh);
|
||||||
if (!account) {
|
if (!account) {
|
||||||
throw new Error(`Unable to fetch Position at address at ${positionAddress}`);
|
throw new Error(`Unable to fetch Position at address at ${positionAddress}`);
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,18 @@ export class WhirlpoolClientImpl implements WhirlpoolClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTokenInfos(fetcher: AccountFetcher, data: WhirlpoolData): Promise<TokenInfo[]> {
|
async function getTokenInfos(
|
||||||
|
fetcher: AccountFetcher,
|
||||||
|
data: WhirlpoolData,
|
||||||
|
refresh: boolean
|
||||||
|
): Promise<TokenInfo[]> {
|
||||||
const mintA = data.tokenMintA;
|
const mintA = data.tokenMintA;
|
||||||
const infoA = await fetcher.getMintInfo(mintA);
|
const infoA = await fetcher.getMintInfo(mintA, refresh);
|
||||||
if (!infoA) {
|
if (!infoA) {
|
||||||
throw new Error(`Unable to fetch MintInfo for mint - ${mintA}`);
|
throw new Error(`Unable to fetch MintInfo for mint - ${mintA}`);
|
||||||
}
|
}
|
||||||
const mintB = data.tokenMintB;
|
const mintB = data.tokenMintB;
|
||||||
const infoB = await fetcher.getMintInfo(mintB);
|
const infoB = await fetcher.getMintInfo(mintB, refresh);
|
||||||
if (!infoB) {
|
if (!infoB) {
|
||||||
throw new Error(`Unable to fetch MintInfo for mint - ${mintB}`);
|
throw new Error(`Unable to fetch MintInfo for mint - ${mintB}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,14 @@ export interface WhirlpoolClient {
|
||||||
* @param poolAddress the address of the Whirlpool account
|
* @param poolAddress the address of the Whirlpool account
|
||||||
* @return a Whirlpool object to interact with
|
* @return a Whirlpool object to interact with
|
||||||
*/
|
*/
|
||||||
getPool: (poolAddress: Address) => Promise<Whirlpool>;
|
getPool: (poolAddress: Address, refresh?: boolean) => Promise<Whirlpool>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a Position object to interact with the Position account at the given address.
|
* Get a Position object to interact with the Position account at the given address.
|
||||||
* @param positionAddress the address of the Position account
|
* @param positionAddress the address of the Position account
|
||||||
* @return a Position object to interact with
|
* @return a Position object to interact with
|
||||||
*/
|
*/
|
||||||
getPosition: (positionAddress: Address) => Promise<Position>;
|
getPosition: (positionAddress: Address, refresh?: boolean) => Promise<Position>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue