forked from DefiLlama/yield-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DefiLlama#231 from dtmkeng/feat/civfund
Feat/civfund
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"poolLength": { | ||
"inputs": [], | ||
"name": "poolLength", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
"token0": { | ||
"constant": true, | ||
"inputs": [], | ||
"name": "token0", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
"token1": { | ||
"constant": true, | ||
"inputs": [], | ||
"name": "token0", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const sdk = require('@defillama/sdk'); | ||
const { default: BigNumber } = require('bignumber.js'); | ||
const superagent = require('superagent'); | ||
const utils = require('../utils'); | ||
const ABI = require('./abi.json'); | ||
|
||
const CIV_TOKEN = '0x37fE0f067FA808fFBDd12891C0858532CFE7361d'; | ||
const MASTERCHEF_ADDRESS = '0x8a774F790aBEAEF97b118112c790D0dcccA61099'; | ||
const POOLS_ONE_TOKEN = [ | ||
'0x73a83269b9bbafc427e76be0a2c1a1db2a26f4c2', | ||
'0x37fe0f067fa808ffbdd12891c0858532cfe7361d' | ||
]; | ||
const API_POOL_DATA = (poolId) => `https://api.civfund.org/getPoolData/${poolId}/?chainId=1`; | ||
|
||
const getApy = async () => { | ||
const poolLength = await sdk.api.abi.call({ | ||
target: MASTERCHEF_ADDRESS, | ||
chain: 'ethereum', | ||
abi: ABI.poolLength, | ||
}); | ||
|
||
const poolRes = await Promise.all([...Array(Number(poolLength.output)).keys()].map((i) => utils.getData(API_POOL_DATA(i)))); | ||
const [underlyingToken0, underlyingToken1] = await Promise.all( | ||
['token0', 'token1'].map((method) => | ||
sdk.api.abi.multiCall({ | ||
abi: ABI[method], | ||
calls: poolRes.filter(e => !POOLS_ONE_TOKEN.includes(e.lpToken)).map(({lpToken}) => ({ | ||
target: lpToken, | ||
})), | ||
chain: 'ethereum', | ||
requery: true, | ||
}) | ||
) | ||
); | ||
let tokens0 = underlyingToken0.output.map((res) => res.output); | ||
let tokens1 = underlyingToken1.output.map((res) => res.output); | ||
|
||
tokens0 = [ | ||
...POOLS_ONE_TOKEN, | ||
...tokens0, | ||
]; | ||
tokens1 = [undefined, undefined, ...tokens0]; | ||
|
||
const poolApy = poolRes.map((pool, i) => { | ||
const apy = pool.roiPerYearPerc; | ||
return { | ||
pool: `ethereum:${pool.lpToken}`, | ||
chain: utils.formatChain('ethereum'), | ||
project: 'civfund', | ||
symbol: `${pool.symbol1}${pool.symbol2 ? '-' + pool.symbol2 : ''}`, | ||
tvlUsd: Number(pool.tvlUSD), | ||
apy, | ||
underlyingTokens: !pool.symbol2 ? [pool.lpToken] : [tokens0[i], tokens1[i]], | ||
rewardTokens: ['0x73a83269b9bbafc427e76be0a2c1a1db2a26f4c2'] // ONE | ||
} | ||
}); | ||
|
||
return poolApy; | ||
}; | ||
|
||
module.exports = { | ||
timetravel: false, | ||
apy: getApy, | ||
url: 'https://civfund.org/', | ||
}; |