Skip to content

Commit

Permalink
Add support for multiple ls token aprs for aura apys (#1258)
Browse files Browse the repository at this point in the history
* add support for multiple ls token aprs for aura apys

* add cbeth apy too
  • Loading branch information
seguido authored Oct 5, 2023
1 parent 9e945f0 commit 18c3629
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
42 changes: 30 additions & 12 deletions src/api/stats/common/balancer/getAuraApys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ interface Pool {
tokens: Token[];
beefyFee?: number;
status?: string;
lsIndex?: number;
lsIndex?: number | number[];
cmpIndex?: number;
composable?: boolean;
bptIndex?: number;
vaultPoolId?: number;
lsUrl?: string;
dataPath?: string;
lsUrl?: string | string[];
dataPath?: string | string[];
lsAprFactor?: number | number[];
balancerChargesFee?: boolean;
includesComposableAaveTokens?: boolean;
aaveUnderlying?: Underlying[];
Expand Down Expand Up @@ -159,18 +160,35 @@ const getPoolApy = async (
qty.push(amt);
}

let response: JSON;
//Normalize ls Data to always handle arrays
const lsUrls = Array.isArray(pool.lsUrl) ? pool.lsUrl : [pool.lsUrl];
const dataPaths = Array.isArray(pool.dataPath) ? pool.dataPath : [pool.dataPath];
const lsIndexes = Array.isArray(pool.lsIndex) ? pool.lsIndex : [pool.lsIndex];
//Coinbase's returned APR is already in %, we need to normalize it by multiplying by 100
const lsAprFactors = pool.lsAprFactor
? Array.isArray(pool.lsAprFactor)
? pool.lsAprFactor
: [pool.lsAprFactor]
: [1];

let lsApr: number = 0;
try {
response = await fetch(pool.lsUrl).then(res => res.json());
lsApr = await jp.query(response, pool.dataPath);
} catch (e) {
console.error(`Balancer: Liquid Staking URL Fetch Error ${pool.name}`);
const lsResponses: JSON[] = await Promise.all(
lsUrls.map(url => fetch(url).then(res => res.json()))
);
const lsAprs: number[] = lsResponses
.map((res, i) => jp.query(res, dataPaths[i]))
.map((apr, i) => apr * lsAprFactors[i]);
lsApr = lsAprs.reduce((acum, cur) => acum + cur, 0);
lsAprs.forEach((apr, i) => {
aprFixed +=
(apr * qty[lsIndexes[i]].dividedBy(totalQty).toNumber()) /
100 /
(pool.balancerChargesFee ? 2 : 1);
});
} catch (err) {
console.error(`Aura: Liquid Staking URL Fetch Error ${pool.name}`);
}

pool.balancerChargesFee
? (aprFixed = (lsApr * qty[pool.lsIndex].dividedBy(totalQty).toNumber()) / 100 / 2)
: (aprFixed = (lsApr * qty[pool.lsIndex].dividedBy(totalQty).toNumber()) / 100);
}

let compApr = new BigNumber(0);
Expand Down
11 changes: 8 additions & 3 deletions src/data/arbitrum/auraLpPools.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,14 @@
"composable": true,
"bptIndex": 1,
"vaultPoolId": "0x4a2f6ae7f3e5d715689530873ec35593dc28951b000000000000000000000481",
"lsIndex": 1,
"lsUrl": "https://eth-api.lido.fi/v1/protocol/steth/apr/sma",
"dataPath": "$.data.smaApr",
"lsIndex": [0, 1, 2],
"lsUrl": [
"https://api.exchange.coinbase.com/wrapped-assets/CBETH",
"https://eth-api.lido.fi/v1/protocol/steth/apr/sma",
"https://api.rocketpool.net/api/apr"
],
"dataPath": ["$.apy", "$.data.smaApr", "$.yearlyAPR"],
"lsAprFactor": [100, 1, 1],
"balancerChargesFee": true,
"decimals": "1e18",
"rewards": [
Expand Down

0 comments on commit 18c3629

Please sign in to comment.