Skip to content

Update new pools #1919

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

Merged
merged 3 commits into from
Jun 16, 2025
Merged
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
105 changes: 101 additions & 4 deletions src/adaptors/aerodrome-slipstream/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const sdk = require('@defillama/sdk');
const axios = require('axios');

const { request, gql } = require('graphql-request');
const utils = require('../utils');

const abiSugar = require('./abiSugar.json');
Expand All @@ -10,11 +10,91 @@ const AERO = '0x940181a94A35A4569E4529A3CDfB74e38FD98631';
const sugar = '0x92294D631E995f1dd9CeE4097426e6a71aB87Bcf';
const sugarHelper = '0x6d2D739bf37dFd93D804523c2dfA948EAf32f8E1';
const nullAddress = '0x0000000000000000000000000000000000000000';
const PROJECT = 'aerodrome-slipstream';
const CHAIN = 'base';
const SUBGRAPH = sdk.graph.modifyEndpoint('GENunSHWLBXm59mBSgPzQ8metBEp9YDfdqwFr91Av1UM');

const tickWidthMappings = {1: 5, 50: 5, 100: 15, 200: 10, 2000: 2};

const getApy = async () => {
const query = gql`
{
pools(first: 1000, orderBy: totalValueLockedUSD, orderDirection: desc, block: {number: <PLACEHOLDER>}) {
id
reserve0: totalValueLockedToken0
reserve1: totalValueLockedToken1
volumeUSD
feeTier
token0 {
symbol
id
}
token1 {
symbol
id
}
}
}
`;

const queryPrior = gql`
{
pools(first: 1000 orderBy: totalValueLockedUSD orderDirection: desc, block: {number: <PLACEHOLDER>}) {
id
volumeUSD
}
}
`;

async function getPoolVolumes(timestamp = null) {
const [block, blockPrior] = await utils.getBlocks(CHAIN, timestamp, [
SUBGRAPH,
]);

const [_, blockPrior7d] = await utils.getBlocks(
CHAIN,
timestamp,
[SUBGRAPH],
604800
);

// pull data
let dataNow = await request(SUBGRAPH, query.replace('<PLACEHOLDER>', block));
dataNow = dataNow.pools;

// pull 24h offset data to calculate fees from swap volume
let queryPriorC = queryPrior;
let dataPrior = await request(
SUBGRAPH,
queryPriorC.replace('<PLACEHOLDER>', blockPrior)
);
dataPrior = dataPrior.pools;

// 7d offset
const dataPrior7d = (
await request(SUBGRAPH, queryPriorC.replace('<PLACEHOLDER>', blockPrior7d))
).pools;

// calculate tvl
dataNow = await utils.tvl(dataNow, CHAIN);
// calculate apy
dataNow = dataNow.map((el) => utils.apy(el, dataPrior, dataPrior7d, 'v3'));

const pools = {}
for (const p of dataNow.filter(p => p.volumeUSD1d >= 0 && (!isNaN(p.apy1d) || !isNaN(p.apy7d)))) {
const poolAddress = utils.formatAddress(p.id);
pools[poolAddress] = {
pool: poolAddress,
apyBase: p.apy1d,
apyBase7d: p.apy7d,
volumeUsd1d: p.volumeUSD1d,
volumeUsd7d: p.volumeUSD7d,
}
}

return pools;
}

const getGaugeApy = async () => {
const chunkSize = 400;
let currentOffset = 1650; // Ignore older non-Slipstream pools
let unfinished = true;
Expand Down Expand Up @@ -154,7 +234,7 @@ const getApy = async () => {
return {
pool: p.lp,
chain: utils.formatChain('base'),
project: 'aerodrome-slipstream',
project: PROJECT,
symbol: s,
tvlUsd,
apyReward,
Expand All @@ -168,7 +248,24 @@ const getApy = async () => {
return pools.filter((p) => utils.keepFinite(p));
};

async function main(timestamp = null) {
const poolsApy = await getGaugeApy();
const poolsVolumes = await getPoolVolumes(timestamp);

return poolsApy.map(pool => {
const poolAddress = utils.formatAddress(pool.id);
return {
...pool,

apyBase: poolsVolumes[poolAddress] ? poolsVolumes[poolAddress].apyBase : undefined,
apyBase7d: poolsVolumes[poolAddress] ? poolsVolumes[poolAddress].apyBase7d : undefined,
volumeUsd1d: poolsVolumes[poolAddress] ? poolsVolumes[poolAddress].volumeUsd1d : undefined,
volumeUsd7d: poolsVolumes[poolAddress] ? poolsVolumes[poolAddress].volumeUsd7d : undefined,
}
});
}

module.exports = {
timetravel: false,
apy: getApy,
apy: main,
};
135 changes: 116 additions & 19 deletions src/adaptors/aerodrome-v1/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,104 @@
const sdk = require('@defillama/sdk');
const axios = require('axios');

const { request, gql } = require('graphql-request');
const utils = require('../utils');

const abiPoolsFactory = require('./abiPoolsFactory.json');

const abiPool = require('./abiPool.json');
const abiGauge = require('./abiGauge.json');
const abiVoter = require('./abiVoter.json');
const abiPoolsFactory = require('./abiPoolsFactory.json');

const poolsFactory = '0x420DD381b31aEf6683db6B902084cB0FFECe40Da';
const voter = '0x16613524e02ad97eDfeF371bC883F2F5d6C480A5';
const AERO = '0x940181a94A35A4569E4529A3CDfB74e38FD98631';

const getApy = async () => {
const PROJECT = 'aerodrome-v1';
const CHAIN = 'base';
const SUBGRAPH = sdk.graph.modifyEndpoint('7uEwiKmfbRQqV8Ec9nvdKrMFVFQv5qaM271gdBvHtywj');

const query = gql`
{
pairs(first: 1000, orderBy: reserveUSD, orderDirection: desc, block: {number: <PLACEHOLDER>}) {
id
reserve0
reserve1
volumeUSD
feeTier: token0Fee
token0 {
symbol
id
}
token1 {
symbol
id
}
}
}
`;

const queryPrior = gql`
{
pairs (first: 1000 orderBy: reserveUSD orderDirection: desc, block: {number: <PLACEHOLDER>}) {
id
volumeUSD
}
}
`;

async function getPoolVolumes(timestamp = null) {
const [block, blockPrior] = await utils.getBlocks(CHAIN, timestamp, [
SUBGRAPH,
]);

const [_, blockPrior7d] = await utils.getBlocks(
CHAIN,
timestamp,
[SUBGRAPH],
604800
);

// pull data
let dataNow = await request(SUBGRAPH, query.replace('<PLACEHOLDER>', block));
dataNow = dataNow.pairs;

// pull 24h offset data to calculate fees from swap volume
let queryPriorC = queryPrior;
let dataPrior = await request(
SUBGRAPH,
queryPriorC.replace('<PLACEHOLDER>', blockPrior)
);
dataPrior = dataPrior.pairs;

// 7d offset
const dataPrior7d = (
await request(SUBGRAPH, queryPriorC.replace('<PLACEHOLDER>', blockPrior7d))
).pairs;

// calculate tvl
dataNow = await utils.tvl(dataNow, CHAIN);
// calculate apy
dataNow = dataNow.map((el) => utils.apy(el, dataPrior, dataPrior7d, 'v3'));

const pools = {}
for (const p of dataNow.filter(p => p.volumeUSD1d >= 0 && (!isNaN(p.apy1d) || !isNaN(p.apy7d)))) {
pools[p.id] = {
pool: p.id,
apyBase: p.apy1d,
apyBase7d: p.apy7d,
volumeUsd1d: p.volumeUSD1d,
volumeUsd7d: p.volumeUSD7d,
}
}

return pools;
}

const getGaugeApy = async () => {
const allPoolsLength = (
await sdk.api.abi.call({
target: poolsFactory,
abi: abiPoolsFactory.find((m) => m.name === 'allPoolsLength'),
chain: 'base',
chain: CHAIN,
})
).output;

Expand All @@ -29,7 +109,7 @@ const getApy = async () => {
params: [i],
})),
abi: abiPoolsFactory.find((m) => m.name === 'allPools'),
chain: 'base',
chain: CHAIN,
})
).output.map((o) => o.output);

Expand All @@ -39,7 +119,7 @@ const getApy = async () => {
target: i,
})),
abi: abiPool.find((m) => m.name === 'metadata'),
chain: 'base',
chain: CHAIN,
})
).output.map((o) => o.output);

Expand All @@ -49,7 +129,7 @@ const getApy = async () => {
target: i,
})),
abi: abiPool.find((m) => m.name === 'symbol'),
chain: 'base',
chain: CHAIN,
})
).output.map((o) => o.output);

Expand All @@ -60,7 +140,7 @@ const getApy = async () => {
params: [i],
})),
abi: abiVoter.find((m) => m.name === 'gauges'),
chain: 'base',
chain: CHAIN,
})
).output.map((o) => o.output);

Expand All @@ -70,15 +150,15 @@ const getApy = async () => {
target: i,
})),
abi: abiGauge.find((m) => m.name === 'rewardRate'),
chain: 'base',
chain: CHAIN,
permitFailure: true,
})
).output.map((o) => o.output);

const poolSupply = (
await sdk.api.abi.multiCall({
calls: allPools.map((i) => ({ target: i })),
chain: 'base',
chain: CHAIN,
abi: 'erc20:totalSupply',
permitFailure: true,
})
Expand All @@ -90,7 +170,7 @@ const getApy = async () => {
target: i,
})),
abi: abiGauge.find((m) => m.name === 'totalSupply'),
chain: 'base',
chain: CHAIN,
permitFailure: true,
})
).output.map((o) => o.output);
Expand All @@ -111,7 +191,7 @@ const getApy = async () => {
for (const p of [...Array(pages).keys()]) {
x = tokens
.slice(p * maxSize, maxSize * (p + 1))
.map((i) => `base:${i}`)
.map((i) => `${CHAIN}:${i}`)
.join(',')
.replaceAll('/', '');
pricesA = [
Expand All @@ -130,8 +210,8 @@ const getApy = async () => {
const r0 = poolMeta.r0 / poolMeta.dec0;
const r1 = poolMeta.r1 / poolMeta.dec1;

const p0 = prices[`base:${poolMeta.t0}`]?.price;
const p1 = prices[`base:${poolMeta.t1}`]?.price;
const p0 = prices[`${CHAIN}:${poolMeta.t0}`]?.price;
const p1 = prices[`${CHAIN}:${poolMeta.t1}`]?.price;

const tvlUsd = r0 * p0 + r1 * p1;

Expand All @@ -146,27 +226,44 @@ const getApy = async () => {
}

const apyReward =
(((rewardRate[i] / 1e18) * 86400 * 365 * prices[`base:${AERO}`]?.price) /
(((rewardRate[i] / 1e18) * 86400 * 365 * prices[`${CHAIN}:${AERO}`]?.price) /
tvlUsd) * stakedSupplyRatio *
100;

return {
pool: p,
chain: utils.formatChain('base'),
project: 'aerodrome-v1',
chain: utils.formatChain(CHAIN),
project: PROJECT,
symbol: utils.formatSymbol(s.split('-')[1]),
tvlUsd,
apyReward,
rewardTokens: apyReward ? [AERO] : [],
underlyingTokens: [poolMeta.t0, poolMeta.t1],
url: `https://aerodrome.finance/deposit?token0=${poolMeta.t0}&token1=${poolMeta.t1}&type=-1&chain0=8453&chain1=8453&factory=0x420DD381b31aEf6683db6B902084cB0FFECe40Da`,
};
});

return pools.filter((p) => utils.keepFinite(p));
};

async function main(timestamp = null) {
const poolsApy = await getGaugeApy();
const poolsVolumes = await getPoolVolumes(timestamp);

return poolsApy.map(pool => {
return {
...pool,

apyBase: poolsVolumes[pool.id] ? poolsVolumes[pool.id].apyBase : undefined,
apyBase7d: poolsVolumes[pool.id] ? poolsVolumes[pool.id].apyBase7d : undefined,
volumeUsd1d: poolsVolumes[pool.id] ? poolsVolumes[pool.id].volumeUsd1d : undefined,
volumeUsd7d: poolsVolumes[pool.id] ? poolsVolumes[pool.id].volumeUsd7d : undefined,
}
});
}

module.exports = {
timetravel: false,
apy: getApy,
apy: main,
url: 'https://aerodrome.finance/liquidity',
};
2 changes: 1 addition & 1 deletion src/adaptors/fluid-dex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const main = async (unixTimestamp) => {
yieldPools.push({
chain: utils.formatChain(chain),
project: PROJECT,
pool: p.pool,
pool: `${chain}-${p.pool}`, // there are same pools addresses
symbol: utils.formatSymbol(`${p.token0.symbol}-${p.token1.symbol}`),
underlyingTokens: [p.token0.address, p.token1.address],
tvlUsd: p.tvlUsd,
Expand Down
Loading
Loading