Skip to content

Commit

Permalink
Merge pull request #77 from invariant-labs/add-supported-tokens-eclipse
Browse files Browse the repository at this point in the history
add supported tokens to eclipse
  • Loading branch information
wojciech-cichocki authored Oct 31, 2024
2 parents bb5dda0 + adbf398 commit 10c7154
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
2 changes: 1 addition & 1 deletion svm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@invariant-labs/sdk": "0.9.67",
"@invariant-labs/sdk-eclipse": "^0.0.21",
"@invariant-labs/sdk-eclipse": "^0.0.28",
"@invariant-labs/staker-sdk": "0.2.11",
"@project-serum/anchor": "0.21.0",
"@solana/spl-token": "0.1.6",
Expand Down
15 changes: 15 additions & 0 deletions svm/src/eclipse/full-snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PoolStatsDataWithString,
PoolWithAddress,
printBN,
supportedTokens,
TimeData,
TokenStatsDataWithString,
} from "../utils";
Expand Down Expand Up @@ -248,6 +249,20 @@ export const createSnapshotForNetwork = async (network: Network) => {
tvl24.change = ((tvl24.value - prevTvl24) / prevTvl24) * 100;
fees24.change = ((fees24.value - prevFees24) / prevFees24) * 100;

if (network === Network.MAIN) {
for (const supportedToken of Object.keys(supportedTokens)) {
const result = await market.getCurrentTokenStats(
supportedToken,
"So11111111111111111111111111111111111111112",
tokensPricesData["7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"].price
);

if (!("error" in result) && tokensDataObject[supportedToken]) {
tokensDataObject[supportedToken].price = +result.priceUsd;
}
}
}

fs.writeFileSync(
fileName,
JSON.stringify({
Expand Down
44 changes: 40 additions & 4 deletions svm/src/eclipse/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getUsdValue24,
PoolSnapshot,
PoolStatsData,
supportedTokens,
TokenData,
} from "../utils";

Expand Down Expand Up @@ -79,6 +80,24 @@ export const createSnapshotForNetwork = async (network: Network) => {

let poolsData: any[] = [];

const supportedTokensWithPrices = {};

if (network === Network.MAIN) {
for (const supportedToken of Object.keys(supportedTokens)) {
const result = await market.getCurrentTokenStats(
supportedToken,
"So11111111111111111111111111111111111111112",
coingeckoPrices["ethereum"]
);

if (!("error" in result)) {
supportedTokensWithPrices[supportedToken] = +result.priceUsd;
}

tokensData[supportedToken] = supportedTokens[supportedToken];
}
}

for (let pool of allPools) {
const pair = new Pair(pool.tokenX, pool.tokenY, {
fee: pool.fee.v,
Expand All @@ -94,19 +113,27 @@ export const createSnapshotForNetwork = async (network: Network) => {
poolsDict[address.toString()] = pool;

let lastSnapshot: PoolSnapshot | undefined;
const tokenXData = tokensData?.[pool.tokenX.toString()] ?? {
let tokenXData = tokensData?.[pool.tokenX.toString()] ?? {
decimals: 0,
};
const tokenYData = tokensData?.[pool.tokenY.toString()] ?? {
let tokenYData = tokensData?.[pool.tokenY.toString()] ?? {
decimals: 0,
};
const tokenXPrice = tokenXData.coingeckoId
let tokenXPrice = tokenXData.coingeckoId
? coingeckoPrices[tokenXData.coingeckoId] ?? 0
: 0;
const tokenYPrice = tokenYData.coingeckoId
let tokenYPrice = tokenYData.coingeckoId
? coingeckoPrices[tokenYData.coingeckoId] ?? 0
: 0;

if (Object.keys(supportedTokens).includes(pool.tokenX.toString())) {
tokenXPrice = supportedTokensWithPrices[pool.tokenX.toString()];
}

if (Object.keys(supportedTokens).includes(pool.tokenY.toString())) {
tokenYPrice = supportedTokensWithPrices[pool.tokenY.toString()];
}

if (snaps?.[address.toString()]) {
lastSnapshot =
snaps[address.toString()].snapshots[
Expand Down Expand Up @@ -231,6 +258,15 @@ export const createSnapshotForNetwork = async (network: Network) => {
};
}

snaps[address].tokenX = {
address: xAddress,
decimals: tokensData?.[xAddress]?.decimals ?? 0,
};
snaps[address].tokenY = {
address: yAddress,
decimals: tokensData?.[yAddress]?.decimals ?? 0,
};

snaps[address].snapshots.push({
timestamp,
...stats,
Expand Down
9 changes: 9 additions & 0 deletions svm/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,12 @@ export const getEclipseTokensData = (
return {};
}
};

export const supportedTokens = {
LaihKXA47apnS599tyEyasY2REfEzBNe4heunANhsMx: {
decimals: 5,
},
trbts2EsWyMdnCjsHUFBKLtgudmBD7Rfbz8zCg1s4EK: {
decimals: 9,
},
};

0 comments on commit 10c7154

Please sign in to comment.