Skip to content

Commit 9399d76

Browse files
authored
Merge pull request #2166 from aurafinance/aura-adapter-v2
Aura adaptor changes
2 parents 64ff766 + a27be22 commit 9399d76

23 files changed

+903
-8381
lines changed

src/adaptors/aura/abis.js

Lines changed: 0 additions & 7951 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"inputs": [],
4+
"name": "getPoolId",
5+
"outputs": [
6+
{
7+
"internalType": "bytes32",
8+
"name": "",
9+
"type": "bytes32"
10+
}
11+
],
12+
"stateMutability": "view",
13+
"type": "function"
14+
}
15+
]
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[
2+
{
3+
"inputs": [],
4+
"name": "poolLength",
5+
"outputs": [
6+
{
7+
"internalType": "uint256",
8+
"name": "",
9+
"type": "uint256"
10+
}
11+
],
12+
"stateMutability": "view",
13+
"type": "function"
14+
},
15+
{
16+
"inputs": [
17+
{
18+
"internalType": "uint256",
19+
"name": "",
20+
"type": "uint256"
21+
}
22+
],
23+
"name": "poolInfo",
24+
"outputs": [
25+
{
26+
"internalType": "address",
27+
"name": "lptoken",
28+
"type": "address"
29+
},
30+
{
31+
"internalType": "address",
32+
"name": "token",
33+
"type": "address"
34+
},
35+
{
36+
"internalType": "address",
37+
"name": "gauge",
38+
"type": "address"
39+
},
40+
{
41+
"internalType": "address",
42+
"name": "crvRewards",
43+
"type": "address"
44+
},
45+
{
46+
"internalType": "address",
47+
"name": "stash",
48+
"type": "address"
49+
},
50+
{
51+
"internalType": "bool",
52+
"name": "shutdown",
53+
"type": "bool"
54+
}
55+
],
56+
"stateMutability": "view",
57+
"type": "function"
58+
}
59+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"inputs": [],
4+
"name": "mintRate",
5+
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
6+
"stateMutability": "view",
7+
"type": "function"
8+
}
9+
]

src/adaptors/aura/config.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Chain-specific configuration
2+
const CHAIN_CONFIG = {
3+
ethereum: {
4+
llamaChainName: 'Ethereum',
5+
balancerChainName: 'MAINNET',
6+
booster: '0xA57b8d98dAE62B26Ec3bcC4a365338157060B234',
7+
chainId: 1,
8+
tokens: {
9+
AURA: '0xc0c293ce456ff0ed870add98a0828dd4d2903dbf',
10+
BAL: '0xba100000625a3754423978a60c9317c58a424e3d',
11+
},
12+
subgraph:
13+
'https://subgraph.satsuma-prod.com/65b10f149401/1xhub-ltd/aura-finance-mainnet/api',
14+
},
15+
arbitrum: {
16+
llamaChainName: 'Arbitrum',
17+
balancerChainName: 'ARBITRUM',
18+
booster: '0x98Ef32edd24e2c92525E59afc4475C1242a30184',
19+
chainId: 42161,
20+
l2Coordinator: '0xeC1c780A275438916E7CEb174D80878f29580606',
21+
tokens: {
22+
AURA: '0x1509706a6c66ca549ff0cb464de88231ddbe213b',
23+
BAL: '0x040d1edc9569d4bab2d15287dc5a4f10f56a56b8',
24+
},
25+
subgraph:
26+
'https://subgraph.satsuma-prod.com/65b10f149401/1xhub-ltd/aura-finance-arbitrum/api',
27+
},
28+
base: {
29+
llamaChainName: 'Base',
30+
balancerChainName: 'BASE',
31+
booster: '0x98Ef32edd24e2c92525E59afc4475C1242a30184',
32+
chainId: 8453,
33+
l2Coordinator: '0x8b2970c237656d3895588B99a8bFe977D5618201',
34+
tokens: {
35+
AURA: '0x1509706a6c66ca549ff0cb464de88231ddbe213b',
36+
BAL: '0x4158734d47fc9692176b5085e0f52ee0da5d47f1',
37+
},
38+
subgraph:
39+
'https://subgraph.satsuma-prod.com/65b10f149401/1xhub-ltd/aura-finance-base/api',
40+
},
41+
avalanche: {
42+
llamaChainName: 'Avalanche',
43+
balancerChainName: 'AVALANCHE',
44+
sdkChainName: 'avax',
45+
booster: '0x98Ef32edd24e2c92525E59afc4475C1242a30184',
46+
chainId: 43114,
47+
l2Coordinator: '0x8b2970c237656d3895588B99a8bFe977D5618201',
48+
tokens: {
49+
AURA: '0x1509706a6c66ca549ff0cb464de88231ddbe213b',
50+
BAL: '0xe15bcb9e0ea69e6ab9fa080c4c4a5632896298c3',
51+
},
52+
subgraph:
53+
'https://subgraph.satsuma-prod.com/65b10f149401/1xhub-ltd/aura-finance-avalanche/api',
54+
},
55+
gnosis: {
56+
llamaChainName: 'xDai',
57+
balancerChainName: 'GNOSIS',
58+
sdkChainName: 'xdai',
59+
booster: '0x98Ef32edd24e2c92525E59afc4475C1242a30184',
60+
chainId: 100,
61+
l2Coordinator: '0x8b2970c237656d3895588B99a8bFe977D5618201',
62+
tokens: {
63+
AURA: '0x1509706a6c66ca549ff0cb464de88231ddbe213b',
64+
BAL: '0x7ef541e2a22058048904fe5744f9c7e4c57af717',
65+
},
66+
subgraph:
67+
'https://subgraph.satsuma-prod.com/65b10f149401/1xhub-ltd/aura-finance-gnosis/api',
68+
},
69+
optimism: {
70+
llamaChainName: 'Optimism',
71+
balancerChainName: 'OPTIMISM',
72+
booster: '0x98Ef32edd24e2c92525E59afc4475C1242a30184',
73+
chainId: 10,
74+
l2Coordinator: '0xeC1c780A275438916E7CEb174D80878f29580606',
75+
tokens: {
76+
AURA: '0x1509706a6c66ca549ff0cb464de88231ddbe213b',
77+
BAL: '0xfe8b128ba8c78aabc59d4c64cee7ff28e9379921',
78+
},
79+
subgraph:
80+
'https://subgraph.satsuma-prod.com/65b10f149401/1xhub-ltd/aura-finance-optimism/api',
81+
},
82+
polygon: {
83+
llamaChainName: 'Polygon',
84+
balancerChainName: 'POLYGON',
85+
booster: '0x98Ef32edd24e2c92525E59afc4475C1242a30184',
86+
chainId: 137,
87+
l2Coordinator: '0x8b2970c237656d3895588B99a8bFe977D5618201',
88+
tokens: {
89+
AURA: '0x1509706a6c66ca549ff0cb464de88231ddbe213b',
90+
BAL: '0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3',
91+
},
92+
subgraph:
93+
'https://subgraph.satsuma-prod.com/65b10f149401/1xhub-ltd/aura-finance-polygon/api',
94+
},
95+
};
96+
97+
module.exports = {
98+
CHAIN_CONFIG,
99+
};

src/adaptors/aura/constants.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Common time and calculation constants
2+
const COMMON_CONFIG = {
3+
SECONDS_PER_YEAR: 365 * 24 * 60 * 60,
4+
QUEUED_REWARDS_EXTENSION: 7 * 24 * 60 * 60,
5+
DEFAULT_TOKEN_DECIMALS: 18,
6+
AIP_42_ENABLED: true, // 40% reduction applied to most pools (AIP-42)
7+
};
8+
9+
// Balancer V3 API endpoint
10+
const BALANCER_API_ENDPOINT = 'https://api-v3.balancer.fi/graphql';
11+
12+
module.exports = {
13+
COMMON_CONFIG,
14+
BALANCER_API_ENDPOINT,
15+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { getPoolCount, fetchPoolInfo } = require('./rpc/booster');
2+
3+
/**
4+
* Get all active (non-shutdown) pools from the booster contract
5+
*/
6+
async function getActivePools(chainName, chainConfig) {
7+
if (!chainConfig?.booster) return [];
8+
9+
const poolLength = await getPoolCount(chainConfig.booster, chainName);
10+
const allPoolsRaw = await fetchPoolInfo(
11+
chainConfig.booster,
12+
poolLength,
13+
chainName
14+
);
15+
16+
return allPoolsRaw.flatMap(({ output }, index) =>
17+
output && !output.shutdown ? [{ ...output, poolIndex: index }] : []
18+
);
19+
}
20+
21+
module.exports = {
22+
getActivePools,
23+
};
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const { getPoolIds } = require('./rpc/balancer-pool');
2+
const { getBalancerPoolsData } = require('./subgraph/balancer-pools');
3+
4+
/**
5+
* Get Balancer pool data with processed APRs, staking rewards, and underlying tokens
6+
*/
7+
async function getBalancerData(activePools, sdkChainName, chainConfig) {
8+
const poolIdResults = await getPoolIds(
9+
activePools.map((pool) => pool.lptoken),
10+
sdkChainName
11+
);
12+
13+
const balancerPoolsDataMap = await getBalancerPoolsData(
14+
activePools.map((pool, i) =>
15+
poolIdResults[i]?.success && poolIdResults[i]?.output
16+
? poolIdResults[i].output
17+
: pool.lptoken
18+
),
19+
chainConfig.balancerChainName
20+
);
21+
22+
return activePools.reduce((acc, pool, i) => {
23+
const balancerPoolId =
24+
poolIdResults[i]?.success && poolIdResults[i]?.output
25+
? poolIdResults[i].output
26+
: pool.lptoken;
27+
const poolData = balancerPoolsDataMap[balancerPoolId.toLowerCase()];
28+
if (!poolData) return acc;
29+
30+
const apyBase = poolData.dynamicData?.aprItems
31+
? poolData.dynamicData.aprItems.reduce((aprAcc, item) => {
32+
const aprValue = item.apr * 100 || 0;
33+
34+
if (
35+
item.type === 'SWAP_FEE' ||
36+
item.type === 'SWAP_FEE_24H' ||
37+
item.type === 'IB_YIELD'
38+
) {
39+
aprAcc += aprValue;
40+
}
41+
42+
return aprAcc;
43+
}, 0)
44+
: 0;
45+
46+
acc[pool.poolIndex] = {
47+
apyBase,
48+
underlyingTokens:
49+
poolData.poolTokens?.flatMap((token) =>
50+
token.underlyingToken && token.useUnderlyingForAddRemove
51+
? [token.address, token.underlyingToken.address]
52+
: [token.address]
53+
) || [],
54+
};
55+
56+
return acc;
57+
}, {});
58+
}
59+
60+
module.exports = {
61+
getBalancerData,
62+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const { getTotalSupplies } = require('./rpc/erc20');
2+
const utils = require('../../utils');
3+
4+
/**
5+
* Get TVL for Aura pools
6+
*/
7+
async function getPoolTvls(pools, chainName) {
8+
if (!pools?.length) return {};
9+
10+
try {
11+
const [totalSupplyResults, tokenPrices] = await Promise.all([
12+
getTotalSupplies(
13+
pools.map((pool) => pool.token),
14+
chainName
15+
),
16+
utils
17+
.getData(
18+
`https://coins.llama.fi/prices/current/${pools
19+
.map((pool) => `${chainName}:${pool.lptoken}`)
20+
.join(',')
21+
.toLowerCase()}`
22+
)
23+
.then((data) => data.coins),
24+
]);
25+
26+
return pools.reduce((acc, pool, index) => {
27+
const priceKey = `${chainName}:${pool.lptoken.toLowerCase()}`;
28+
const price = tokenPrices[priceKey]?.price;
29+
const totalSupply = totalSupplyResults[index]?.output;
30+
31+
acc[pool.poolIndex] =
32+
price && totalSupply ? (Number(totalSupply) / 1e18) * price : 0;
33+
34+
return acc;
35+
}, {});
36+
} catch {
37+
return {};
38+
}
39+
}
40+
41+
module.exports = {
42+
getPoolTvls,
43+
};

0 commit comments

Comments
 (0)