Skip to content

feat: add stpol metrics #2058

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
58 changes: 0 additions & 58 deletions src/adaptors/stake.link-index/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ const getData = async (url, query = null) => {
};

const SUBGRAPH_URL =
'https://api.studio.thegraph.com/query/72555/stakedotlink-ethereum/version/latest';
'https://graph-readonly.linkpool.pro/subgraphs/name/stakedotlink-ethereum-production';

const query = `
{
totalRewardAmounts {
totalRewardSTLINK
totalRewardSTPOL
__typename
}
totalCounts {
linkStakingDistributionCount
polStakingDistributionCount
__typename
}
linkStakingDistributions(
Expand All @@ -42,6 +44,22 @@ const query = `
ts
__typename
}
polStakingDistributions(
first: 1
skip: 0
orderBy: ts
orderDirection: desc
where: {isUpdatedWithBurnAmount: true}
) {
reward_rate
reward_amount
total_staked
fees
fee_percentage
tx_hash
ts
__typename
}
}
`;

Expand All @@ -54,6 +72,11 @@ const pools = [
address: '0xb8b295df2cd735b15BE5Eb419517Aa626fc43cD5',
priceId: 'chainlink',
},
{
symbol: 'stPOL',
address: '0x2ff4390dB61F282Ef4E6D4612c776b809a541753',
priceId: 'polygon-ecosystem-token',
},
];

const fetchPrice = async (tokenId) => {
Expand All @@ -70,16 +93,32 @@ const fetchPool = async (pool) => {
const price = await fetchPrice(priceId);
const response = await getData(SUBGRAPH_URL, JSON.stringify({ query }));

if (
!response ||
!response.data ||
!response.data.linkStakingDistributions ||
!response.data.linkStakingDistributions[0]
) {
if (!response || !response.data) {
throw new Error('Invalid data structure received from subgraph');
}

const distribution = response.data.linkStakingDistributions[0];
// Determine which distribution data to use based on symbol
let distribution;
if (symbol === 'stLINK') {
if (
!response.data.linkStakingDistributions ||
!response.data.linkStakingDistributions[0]
) {
throw new Error('Invalid LINK staking distribution data');
}
distribution = response.data.linkStakingDistributions[0];
} else if (symbol === 'stPOL') {
if (
!response.data.polStakingDistributions ||
!response.data.polStakingDistributions[0]
) {
throw new Error('Invalid POL staking distribution data');
}
distribution = response.data.polStakingDistributions[0];
} else {
throw new Error(`Unsupported symbol: ${symbol}`);
}

const apy = parseFloat(distribution.reward_rate);
const totalStakedInWei = distribution.total_staked;
const totalStaked = parseFloat(ethers.utils.formatEther(totalStakedInWei));
Expand All @@ -88,7 +127,7 @@ const fetchPool = async (pool) => {
return {
pool: `${address}-${CHAIN_NAME}`.toLowerCase(),
chain: CHAIN_NAME,
project: 'stake.link-liquid',
project: 'stake.link-liquid-staking',
symbol,
tvlUsd: tvl,
apyBase: apy,
Expand Down
Loading