Skip to content

Commit

Permalink
Merge pull request DefiLlama#424 from WePiggy/main
Browse files Browse the repository at this point in the history
add arbitrum
  • Loading branch information
0xngmi authored Sep 1, 2021
2 parents 8c39544 + 39c68fe commit deb8de2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
14 changes: 14 additions & 0 deletions projects/config/wepiggy/abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,19 @@
"payable": false,
"stateMutability": "view",
"type": "function"
},
"oracle":
{
"inputs": [],
"name": "oracle",
"outputs": [
{
"internalType": "contract IPriceOracle",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
}
32 changes: 25 additions & 7 deletions projects/wepiggy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,46 @@ const abi = require('./config/wepiggy/abi.json');
const contracts = {
ethereum: {
comptroller: '0x0C8c1ab017c3C0c8A48dD9F1DB2F59022D190f0b',
oracle: '0xe212829Ca055eD63279753971672c693C6C6d088',
gas:{
pToken:"0x27A94869341838D5783368a8503FdA5fbCd7987c",
decimals:18,
},
},
okexchain: {
comptroller: '0xaa87715e858b482931eb2f6f92e504571588390b',
oracle: '0x4c78015679fabe22f6e02ce8102afbf7d93794ea',
gas:{
pToken:"0x621ce6596e0b9ccf635316bfe7fdbc80c3029bec",
decimals:18,
},
},
bsc: {
comptroller: '0x8c925623708A94c7DE98a8e83e8200259fF716E0',
oracle: '0x4C78015679FabE22F6e02Ce8102AFbF7d93794eA',
gas:{
pToken:"0x33A32f0ad4AA704e28C93eD8Ffa61d50d51622a7",
decimals:18,
},
},
polygon: {
comptroller: '0xFfceAcfD39117030314A07b2C86dA36E51787948',
oracle: '0x4C78015679FabE22F6e02Ce8102AFbF7d93794eA',
gas:{
pToken:"0xC1B02E52e9512519EDF99671931772E452fb4399",
decimals:18,
},
},
heco: {
comptroller: '0x3401D01E31BB6DefcFc7410c312C0181E19b9dd5',
oracle: '0x4C78015679FabE22F6e02Ce8102AFbF7d93794eA',
gas:{
pToken:"0x75DCd2536a5f414B8F90Bb7F2F3c015a26dc8c79",
decimals:18,
},
},
arbitrum: {
comptroller: '0xaa87715E858b482931eB2f6f92E504571588390b',
gas:{
pToken:"0x17933112E9780aBd0F27f2B7d9ddA9E840D43159",
decimals:18,
},
},
};

// ask comptroller for all markets array
Expand All @@ -56,6 +58,17 @@ async function getAllMarkets(block, chain, comptroller) {
return markets;
}

// ask comptroller for oracle
async function getOracle(block, chain, comptroller) {
const { output: oracle } = await sdk.api.abi.call({
target: comptroller,
abi: abi['oracle'],
block,
chain: chain,
});
return oracle;
}

async function getUnderlyingDecimals(block, chain, token) {
// if (token === '0x27A94869341838D5783368a8503FdA5fbCd7987c') {
// return { underlying: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', decimals: 18 }; //pETH => WETH
Expand Down Expand Up @@ -103,12 +116,13 @@ async function getCash(block, chain, token) {
function fetchChain(chain) {
return async () => {
let tvl = new BigNumber('0');
let { comptroller, oracle } = contracts[chain];
let { comptroller } = contracts[chain];
let block = null;
// const { block } = await sdk.api.util.lookupBlock(timestamp, {
// chain: chain,
// });
let allMarkets = await getAllMarkets(block, chain, comptroller);
let oracle = await getOracle(block, chain, comptroller);

await Promise.all(
allMarkets.map(async token => {
Expand All @@ -131,7 +145,8 @@ async function fetch() {
(await fetchChain('okexchain')()) +
(await fetchChain('bsc')()) +
(await fetchChain('polygon')()) +
(await fetchChain('heco')());
(await fetchChain('heco')()) +
(await fetchChain('arbitrum')());
return tvl;
}

Expand All @@ -151,6 +166,9 @@ module.exports = {
heco: {
fetch: fetchChain('heco'),
},
arbitrum: {
fetch: fetchChain('arbitrum'),
},
fetch,
methodology: `TVL is comprised of tokens deposited to the protocol as collateral, similar to Compound Finance and other lending protocols the borrowed tokens are not counted as TVL.`
};

0 comments on commit deb8de2

Please sign in to comment.