Skip to content

Commit

Permalink
Merge pull request DefiLlama#231 from dtmkeng/feat/civfund
Browse files Browse the repository at this point in the history
Feat/civfund
  • Loading branch information
vrtnd authored Aug 17, 2022
2 parents efaf316 + e9e8993 commit 85f6c21
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/adaptors/civfund/abi.json
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"
}
}
65 changes: 65 additions & 0 deletions src/adaptors/civfund/index.js
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/',
};

0 comments on commit 85f6c21

Please sign in to comment.