Skip to content

Commit

Permalink
Merge pull request #104 from invariant-labs/refactor-liquidity-calcul…
Browse files Browse the repository at this point in the history
…ations

refactor liquidity calculations
  • Loading branch information
wojciech-cichocki authored Dec 6, 2024
2 parents f9c9f95 + 8d7e905 commit 886b66d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
13 changes: 9 additions & 4 deletions eclipse/src/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ export const createSnapshotForNetwork = async (network: Network) => {
fee: pool.fee,
tickSpacing: pool.tickSpacing,
});
const [address, volumes, liq, fees] = await Promise.all([
const [address, volumes, fees, dataX, dataY] = await Promise.all([
pair.getAddress(market.program.programId),
market.getVolume(pair),
market.getPairLiquidityValues(pair),
market.getGlobalFee(pair),
connection.getParsedAccountInfo(pool.tokenXReserve),
connection.getParsedAccountInfo(pool.tokenYReserve),
]);

poolsDict[address.toString()] = pool;
Expand Down Expand Up @@ -190,8 +191,12 @@ export const createSnapshotForNetwork = async (network: Network) => {
}

try {
liquidityX = liq.liquidityX;
liquidityY = liq.liquidityY;
liquidityX = new BN(
(dataX?.value?.data as any).parsed.info.tokenAmount.amount
);
liquidityY = new BN(
(dataY?.value?.data as any).parsed.info.tokenAmount.amount
);
} catch {
liquidityX = new BN("0");
liquidityY = new BN("0");
Expand Down
26 changes: 19 additions & 7 deletions solana/src/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@ export const createSnapshotForNetwork = async (network: Network) => {

const jupPrices = await getJupPricesData(Object.keys(tokensData));

const coingeckoIds = tokensPriceViaCoingecko.map(token => token.coingeckoId)
const coingeckoAddresses = tokensPriceViaCoingecko.map(token => token.address)
const coingeckoPrices = await getTokensPrices(coingeckoIds, coingeckoAddresses)
const coingeckoIds = tokensPriceViaCoingecko.map(
(token) => token.coingeckoId
);
const coingeckoAddresses = tokensPriceViaCoingecko.map(
(token) => token.address
);
const coingeckoPrices = await getTokensPrices(
coingeckoIds,
coingeckoAddresses
);

Object.entries(coingeckoPrices).forEach(([address, price]) => {
jupPrices[address] = price.toString()
jupPrices[address] = price.toString();
});

const connection = provider.connection;
Expand Down Expand Up @@ -112,9 +119,14 @@ export const createSnapshotForNetwork = async (network: Network) => {
}

try {
const liq = await market.getPairLiquidityValues(pair);
liquidityX = liq.liquidityX;
liquidityY = liq.liquidityY;
const dataX = await connection.getParsedAccountInfo(pool.tokenXReserve);
const dataY = await connection.getParsedAccountInfo(pool.tokenYReserve);
liquidityX = new BN(
(dataX?.value?.data as any).parsed.info.tokenAmount.amount
);
liquidityY = new BN(
(dataY?.value?.data as any).parsed.info.tokenAmount.amount
);
} catch {
liquidityX = new BN("0");
liquidityY = new BN("0");
Expand Down

0 comments on commit 886b66d

Please sign in to comment.