mirror of
https://github.com/alexgo-io/DefiLlama-Adapters.git
synced 2026-01-12 16:53:02 +08:00
refactoring of DefiLlama adpeter, added ABIs for each contact type, and config json for ovens/pies/pools
This commit is contained in:
1
projects/config/piedao/abi/IBCP.json
Normal file
1
projects/config/piedao/abi/IBCP.json
Normal file
File diff suppressed because one or more lines are too long
1
projects/config/piedao/abi/IBPT.json
Normal file
1
projects/config/piedao/abi/IBPT.json
Normal file
File diff suppressed because one or more lines are too long
1
projects/config/piedao/abi/ISLP.json
Normal file
1
projects/config/piedao/abi/ISLP.json
Normal file
File diff suppressed because one or more lines are too long
1
projects/config/piedao/abi/IStakedPieDAO.json
Normal file
1
projects/config/piedao/abi/IStakedPieDAO.json
Normal file
File diff suppressed because one or more lines are too long
1
projects/config/piedao/abi/IStakedToken.json
Normal file
1
projects/config/piedao/abi/IStakedToken.json
Normal file
File diff suppressed because one or more lines are too long
1
projects/config/piedao/abi/IStakingAll.json
Normal file
1
projects/config/piedao/abi/IStakingAll.json
Normal file
File diff suppressed because one or more lines are too long
1
projects/config/piedao/abi/IStakingBalancer.json
Normal file
1
projects/config/piedao/abi/IStakingBalancer.json
Normal file
File diff suppressed because one or more lines are too long
1
projects/config/piedao/abi/IStakingUniswap.json
Normal file
1
projects/config/piedao/abi/IStakingUniswap.json
Normal file
File diff suppressed because one or more lines are too long
1
projects/config/piedao/abi/IUniswap.json
Normal file
1
projects/config/piedao/abi/IUniswap.json
Normal file
File diff suppressed because one or more lines are too long
@@ -1,330 +0,0 @@
|
||||
{
|
||||
"available": [
|
||||
"0x8d1ce361eb68e9e05573443c407d4a3bed23b033",
|
||||
"0x0327112423f3a68efdf1fcf402f6c5cb9f7c33fd",
|
||||
"0x78f225869c08d478c34e5f645d07a87d3fe8eb78",
|
||||
"0x9a48bd0ec040ea4f1d3147c025cd4076a2e71e3e",
|
||||
"0xad6a626ae2b43dcb1b39430ce496d2fa0365ba9c"
|
||||
],
|
||||
"selectable": [
|
||||
"0x8d1ce361eb68e9e05573443c407d4a3bed23b033",
|
||||
"0xad6a626ae2b43dcb1b39430ce496d2fa0365ba9c",
|
||||
"0x0327112423f3a68efdf1fcf402f6c5cb9f7c33fd",
|
||||
"0x9a48bd0ec040ea4f1d3147c025cd4076a2e71e3e",
|
||||
"0x78f225869c08d478c34e5f645d07a87d3fe8eb78"
|
||||
],
|
||||
"default": "0xad6a626ae2b43dcb1b39430ce496d2fa0365ba9c",
|
||||
"0x0327112423f3a68efdf1fcf402f6c5cb9f7c33fd": {
|
||||
"symbol": "BTC++",
|
||||
"useRecipe": false,
|
||||
"swapFees": "0.2",
|
||||
"coingeckoId": "piedao-btc",
|
||||
"composition": [
|
||||
{
|
||||
"address": "0x3212b29E33587A00FB1C83346f5dBFA69A458923",
|
||||
"buyLink": "https://tokenlon.im",
|
||||
"color": "#58a4fc",
|
||||
"percentage": 25,
|
||||
"symbol": "imBTC",
|
||||
"coingeckoId": "the-tokenized-bitcoin",
|
||||
"coingeckoImageId": 10702
|
||||
},
|
||||
{
|
||||
"address": "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
||||
"color": "#fd6761",
|
||||
"percentage": 25,
|
||||
"symbol": "wBTC",
|
||||
"coingeckoId": "wrapped-bitcoin",
|
||||
"coingeckoImageId": 7598
|
||||
},
|
||||
{
|
||||
"address": "0x5228a22e72ccC52d415EcFd199F99D0665E7733b",
|
||||
"color": "#6beab1",
|
||||
"percentage": 25,
|
||||
"symbol": "pBTC",
|
||||
"coingeckoId": "ptokens-btc",
|
||||
"coingeckoImageId": 10805
|
||||
},
|
||||
{
|
||||
"address": "0xfE18be6b3Bd88A2D2A7f928d00292E7a9963CfC6",
|
||||
"color": "#c4ccce",
|
||||
"percentage": 25,
|
||||
"symbol": "sBTC",
|
||||
"coingeckoId": "sbtc",
|
||||
"coingeckoImageId": 8838
|
||||
}
|
||||
],
|
||||
"docs": "https://raw.githubusercontent.com/pie-dao/docs/master/current-pies/btc%2B%2B.md"
|
||||
},
|
||||
"0x9a48bd0ec040ea4f1d3147c025cd4076a2e71e3e": {
|
||||
"symbol": "USD++",
|
||||
"useRecipe": true,
|
||||
"swapFees": "0",
|
||||
"coingeckoId": "piedao-usd",
|
||||
"tradingViewFormula": "(0.4722*KRAKEN:USDCUSD+0.2042*KRAKEN:DAIUSD+0.2858*BITTREX:TUSDUSD+0.0378*KUCOIN:SUSDUSDT)",
|
||||
"mapDynamicTradingViewFormula": {
|
||||
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48": "KRAKEN:USDCUSD",
|
||||
"0x6B175474E89094C44Da98b954EedeAC495271d0F": "KRAKEN:DAIUSD",
|
||||
"0x0000000000085d4780B73119b644AE5ecd22b376": "BITTREX:TUSDUSD",
|
||||
"0x57Ab1ec28D129707052df4dF418D58a2D46d5f51": "KUCOIN:SUSDUSDT"
|
||||
},
|
||||
"composition": [
|
||||
{
|
||||
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
||||
"percentage": 47.22,
|
||||
"decimals": 6,
|
||||
"color": "#58a4fc",
|
||||
"symbol": "USDC",
|
||||
"coingeckoId": "usd-coin",
|
||||
"coingeckoImageId": 6319
|
||||
},
|
||||
{
|
||||
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
||||
"percentage": 20.42,
|
||||
"color": "#fd6761",
|
||||
"symbol": "DAI",
|
||||
"coingeckoId": "dai",
|
||||
"coingeckoImageId": 9956
|
||||
},
|
||||
{
|
||||
"address": "0x0000000000085d4780B73119b644AE5ecd22b376",
|
||||
"percentage": 28.58,
|
||||
"color": "#6beab1",
|
||||
"symbol": "TUSD",
|
||||
"coingeckoId": "true-usd",
|
||||
"coingeckoImageId": 3449
|
||||
},
|
||||
{
|
||||
"address": "0x57Ab1ec28D129707052df4dF418D58a2D46d5f51",
|
||||
"percentage": 3.78,
|
||||
"color": "#c4ccce",
|
||||
"symbol": "sUSD",
|
||||
"coingeckoId": "nusd",
|
||||
"coingeckoImageId": 5013
|
||||
}
|
||||
],
|
||||
"docs": "https://raw.githubusercontent.com/pie-dao/docs/master/current-pies/usd%2B%2B.md",
|
||||
"landingLinks": [
|
||||
{
|
||||
"label": "Tutorial: How to Mint USD++",
|
||||
"url": "https://medium.com/piedao/how-to-mint-usd-70501ad3db4e?source=collection_home---6------0-----------------------"
|
||||
},
|
||||
{
|
||||
"label": "Latest rebalance proposal",
|
||||
"url": "https://forum.piedao.org/t/usd-v2-the-stablecoin-basket/116/6?u=alexintosh"
|
||||
}
|
||||
]
|
||||
},
|
||||
"0x78f225869c08d478c34e5f645d07a87d3fe8eb78": {
|
||||
"symbol": "DEFI+L",
|
||||
"mapDynamicTradingViewFormula": {
|
||||
"0xc00e94Cb662C3520282E6f5717214004A7f26888": "KRAKEN:COMPUSD",
|
||||
"0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9": "GEMINI:AAVEUSD",
|
||||
"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984": "COINBASE:UNIUSD",
|
||||
"0x514910771AF9Ca656af840dff83E8264EcF986CA": "KRAKEN:LINKUSD",
|
||||
"0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2": "COINBASE:MKRUSD",
|
||||
"0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F": "KRAKEN:SNXUSD",
|
||||
"0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e": "COINBASE:YFIUSD"
|
||||
},
|
||||
"tradingViewFormula": "0.000944414144968332KRAKEN:COMPUSD+0.00322590157401873GEMINI:AAVEUSD+0.0436834437086093COINBASE:UNIUSD+0.0201081196581197KRAKEN:LINKUSD+0.000186657761947165COINBASE:MKRUSD+0.0327670984455959KRAKEN:SNXUSD+0.00000988602128292323*COINBASE:YFIUSD",
|
||||
"useRecipe": true,
|
||||
"coingeckoId": "piedao-defi-large-cap",
|
||||
"swapFees": "0.1",
|
||||
"composition": [
|
||||
{
|
||||
"symbol": "COMP",
|
||||
"decimals": 18,
|
||||
"color": "#01D395",
|
||||
"coingeckoId": "compound-governance-token",
|
||||
"address": "0xc00e94Cb662C3520282E6f5717214004A7f26888",
|
||||
"coingeckoImageId": 10775,
|
||||
"percentage": 10.74
|
||||
},
|
||||
{
|
||||
"symbol": "Aave",
|
||||
"color": "#AE56A0",
|
||||
"coingeckoImageId": 1365,
|
||||
"coingeckoId": "aave",
|
||||
"address": "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9",
|
||||
"decimals": 18,
|
||||
"percentage": 16.19
|
||||
},
|
||||
{
|
||||
"symbol": "UNI",
|
||||
"color": "#FD1782",
|
||||
"coingeckoImageId": 12504,
|
||||
"coingeckoId": "uniswap",
|
||||
"address": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
|
||||
"decimals": 18,
|
||||
"percentage": 13.19
|
||||
},
|
||||
{
|
||||
"symbol": "LINK",
|
||||
"coingeckoId": "chainlink",
|
||||
"coingeckoImageId": 877,
|
||||
"color": "#c4ccce",
|
||||
"decimals": 18,
|
||||
"address": "0x514910771AF9Ca656af840dff83E8264EcF986CA",
|
||||
"percentage": 18.82
|
||||
},
|
||||
{
|
||||
"symbol": "MKR",
|
||||
"address": "0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2",
|
||||
"color": "#F4AC36",
|
||||
"coingeckoImageId": 1364,
|
||||
"coingeckoId": "maker",
|
||||
"decimals": 18,
|
||||
"percentage": 10.06
|
||||
},
|
||||
{
|
||||
"symbol": "SNX",
|
||||
"color": "#080221",
|
||||
"coingeckoImageId": 3406,
|
||||
"address": "0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F",
|
||||
"percentage": 12.65,
|
||||
"coingeckoId": "havven",
|
||||
"decimals": 18
|
||||
},
|
||||
{
|
||||
"symbol": "YFI",
|
||||
"color": "#0171F5",
|
||||
"coingeckoImageId": 11849,
|
||||
"coingeckoId": "yearn-finance",
|
||||
"address": "0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e",
|
||||
"percentage": 18.35,
|
||||
"decimals": 18
|
||||
}
|
||||
],
|
||||
"docs": "https://raw.githubusercontent.com/pie-dao/docs/master/current-pies/usd%2B%2B.md"
|
||||
},
|
||||
"0xb167f67353f71ca8b47d713878d69e8264a15ac0": {
|
||||
"symbol": "TDEFI+S",
|
||||
"composition": [
|
||||
{
|
||||
"symbol": "BAL",
|
||||
"color": "#58a4fc",
|
||||
"address": "0xba100000625a3754423978a60c9317c58a424e3D",
|
||||
"percentage": 12.75
|
||||
},
|
||||
{
|
||||
"symbol": "LRC",
|
||||
"color": "#fd6761",
|
||||
"address": "0xBBbbCA6A901c926F240b89EacB641d8Aec7AEafD",
|
||||
"percentage": 27.25
|
||||
},
|
||||
{
|
||||
"symbol": "REN",
|
||||
"color": "#6beab1",
|
||||
"address": "0x408e41876cCCDC0F92210600ef50372656052a38",
|
||||
"percentage": 30
|
||||
},
|
||||
{
|
||||
"symbol": "UMA",
|
||||
"color": "#c4ccce",
|
||||
"address": "0x04Fa0d235C4abf4BcF4787aF4CF447DE572eF828",
|
||||
"percentage": 30
|
||||
}
|
||||
],
|
||||
"docs": "https://raw.githubusercontent.com/pie-dao/docs/master/current-pies/usd%2B%2B.md"
|
||||
},
|
||||
"0xad6a626ae2b43dcb1b39430ce496d2fa0365ba9c": {
|
||||
"symbol": "DEFI+S",
|
||||
"useRecipe": true,
|
||||
"coingeckoId": "piedao-defi-small-cap",
|
||||
"bPool": "0x94743cfaa3fdc62e9693572314b5ee377eba5d11",
|
||||
"swapFees": "0",
|
||||
"mapDynamicTradingViewFormula": {
|
||||
"0xba100000625a3754423978a60c9317c58a424e3D": "FTX:BALUSD",
|
||||
"0xBBbbCA6A901c926F240b89EacB641d8Aec7AEafD": "BINANCE:LRCUSD",
|
||||
"0x408e41876cCCDC0F92210600ef50372656052a38": "BINANCE:RENUSD",
|
||||
"0x04Fa0d235C4abf4BcF4787aF4CF447DE572eF828": "POLONIEX:UMAUSDT",
|
||||
"0x89Ab32156e46F46D02ade3FEcbe5Fc4243B9AAeD": "BINANCE:PNTUSD",
|
||||
"0xec67005c4E498Ec7f55E092bd1d35cbC47C91892": "KRAKEN:MLNUSD"
|
||||
},
|
||||
"tradingViewFormula": "0.014596375542431261*FTX:BALUSD+2.054022092615757*BINANCE:LRCUSD+1.7220962538152524*BINANCE:RENUSD+0.07306242503723467*POLONIEX:UMAUSDT+0.12718946536236797*BINANCE:PNTUSD+0.0015105607305932233*KRAKEN:MLNUSD",
|
||||
"composition": [
|
||||
{
|
||||
"symbol": "BAL",
|
||||
"color": "#58a4fc",
|
||||
"address": "0xba100000625a3754423978a60c9317c58a424e3D",
|
||||
"percentage": 13.75,
|
||||
"coingeckoId": "balancer",
|
||||
"coingeckoImageId": 11683
|
||||
},
|
||||
{
|
||||
"symbol": "LRC",
|
||||
"color": "#fd6761",
|
||||
"address": "0xBBbbCA6A901c926F240b89EacB641d8Aec7AEafD",
|
||||
"percentage": 21.51,
|
||||
"coingeckoId": "loopring",
|
||||
"coingeckoImageId": 913
|
||||
},
|
||||
{
|
||||
"symbol": "REN",
|
||||
"color": "#6beab1",
|
||||
"address": "0x408e41876cCCDC0F92210600ef50372656052a38",
|
||||
"percentage": 27.11,
|
||||
"coingeckoId": "republic-protocol",
|
||||
"coingeckoImageId": 3139
|
||||
},
|
||||
{
|
||||
"symbol": "UMA",
|
||||
"color": "#c4ccce",
|
||||
"address": "0x04Fa0d235C4abf4BcF4787aF4CF447DE572eF828",
|
||||
"percentage": 30,
|
||||
"coingeckoId": "uma",
|
||||
"coingeckoImageId": 10951
|
||||
},
|
||||
{
|
||||
"symbol": "PNT",
|
||||
"color": "#c4ccce",
|
||||
"address": "0x89Ab32156e46F46D02ade3FEcbe5Fc4243B9AAeD",
|
||||
"percentage": 4.42,
|
||||
"coingeckoId": "pnetwork",
|
||||
"coingeckoImageId": 11659
|
||||
},
|
||||
{
|
||||
"symbol": "MLN",
|
||||
"color": "#c4ccce",
|
||||
"address": "0xec67005c4E498Ec7f55E092bd1d35cbC47C91892",
|
||||
"percentage": 3.21,
|
||||
"coingeckoId": "melon",
|
||||
"coingeckoImageId": 605
|
||||
}
|
||||
|
||||
],
|
||||
"docs": "https://raw.githubusercontent.com/pie-dao/docs/master/current-pies/usd%2B%2B.md",
|
||||
"landingLinks": [
|
||||
{
|
||||
"label": "Read more on Medium",
|
||||
"url": "https://medium.com/piedao/announcing-defi-s-67ed53367364"
|
||||
}
|
||||
]
|
||||
},
|
||||
"0x8d1ce361eb68e9e05573443c407d4a3bed23b033": {
|
||||
"symbol": "DEFI++",
|
||||
"useRecipe": true,
|
||||
"useMintOverBuy": true,
|
||||
"swapFees": "1",
|
||||
"composition": [
|
||||
{
|
||||
"symbol": "DEFI+S",
|
||||
"address": "0xad6a626ae2b43dcb1b39430ce496d2fa0365ba9c",
|
||||
"color": "#58a4fc",
|
||||
"coingeckoId": "piedao-defi-small-cap",
|
||||
"percentage": 30,
|
||||
"isPie": true
|
||||
},
|
||||
{
|
||||
"symbol": "DEFI+L",
|
||||
"address": "0x78f225869c08d478c34e5f645d07a87d3fe8eb78",
|
||||
"color": "#6beab1",
|
||||
"coingeckoId": "piedao-defi-large-cap",
|
||||
"coingeckoImageId": 1,
|
||||
"percentage": 70,
|
||||
"isPie": true
|
||||
}
|
||||
],
|
||||
"docs": "https://raw.githubusercontent.com/pie-dao/docs/master/current-pies/usd%2B%2B.md"
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
const utils = require('./helper/utils');
|
||||
const BigNumber = require("bignumber.js");
|
||||
const { returnDecimals, getTokenPricesFromString } = require("./helper/utils");
|
||||
const pieABI = require("./config/piedao/abi/IPie.json");
|
||||
const erc20ABI = require("./config/piedao/abi/ERC20.json");
|
||||
const web3 = require('./config/web3.js');
|
||||
|
||||
let pies = [
|
||||
// DEFI+S
|
||||
"0xad6a626ae2b43dcb1b39430ce496d2fa0365ba9c",
|
||||
// DEFI+L
|
||||
"0x78f225869c08d478c34e5f645d07a87d3fe8eb78",
|
||||
// DEFI++
|
||||
"0x8D1ce361eb68e9E05573443C407D4A3Bed23B033",
|
||||
// USD++
|
||||
"0x9a48bd0ec040ea4f1d3147c025cd4076a2e71e3e",
|
||||
// BTC++
|
||||
"0x0327112423f3a68efdf1fcf402f6c5cb9f7c33fd",
|
||||
// BCP
|
||||
"0xe4f726adc8e89c6a6017f01eada77865db22da14",
|
||||
];
|
||||
|
||||
pies = pies.map((pie) => pie.toLowerCase());
|
||||
|
||||
const stakingPools = {
|
||||
// DOUGH/ETH
|
||||
"0xB9a4Bca06F14A982fcD14907D31DFACaDC8ff88E": {
|
||||
lpType: "balancer",
|
||||
// LP token (BPT)
|
||||
lp: "0xFAE2809935233d4BfE8a56c2355c4A2e7d1fFf1A",
|
||||
// Address in which the underlyings are deposited
|
||||
lpUnderlyingsAddress: "0xFAE2809935233d4BfE8a56c2355c4A2e7d1fFf1A",
|
||||
underlyings: [
|
||||
// WETH
|
||||
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
||||
// DOUGH
|
||||
"0xad32A8e6220741182940c5aBF610bDE99E737b2D"
|
||||
]
|
||||
},
|
||||
// DOUGH/ETH (OLD)
|
||||
"0x8314337d2b13e1A61EadF0FD1686b2134D43762F": {
|
||||
lpType: "balancer",
|
||||
// LP token (BPT)
|
||||
lp: "0xFAE2809935233d4BfE8a56c2355c4A2e7d1fFf1A",
|
||||
// Address in which the underlyings are deposited
|
||||
lpUnderlyingsAddress: "0xFAE2809935233d4BfE8a56c2355c4A2e7d1fFf1A",
|
||||
underlyings: [
|
||||
// WETH
|
||||
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
||||
// DOUGH
|
||||
"0xad32A8e6220741182940c5aBF610bDE99E737b2D"
|
||||
]
|
||||
},
|
||||
// DEFI+S/ETH (OLD)
|
||||
"0x220f25C2105a65425913FE0CF38e7699E3992B97": {
|
||||
lpType: "balancer",
|
||||
// LP token (BPT)
|
||||
lp: "0x35333CF3Db8e334384EC6D2ea446DA6e445701dF",
|
||||
// Address in which the underlyings are deposited
|
||||
lpUnderlyingsAddress: "0x35333CF3Db8e334384EC6D2ea446DA6e445701dF",
|
||||
underlyings: [
|
||||
// WETH
|
||||
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
||||
]
|
||||
},
|
||||
// DEFI+L/ETH (OLD)
|
||||
"0xc1a116cb2d354503f9ec5cb436a3b213f377631d": {
|
||||
lpType: "balancer",
|
||||
// LP token (BPT)
|
||||
lp: "0xa795600590a7da0057469049ab8f1284baed977e",
|
||||
// Address in which the underlyings are deposited
|
||||
lpUnderlyingsAddress: "0xa795600590a7da0057469049ab8f1284baed977e",
|
||||
underlyings: [
|
||||
// WETH
|
||||
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
||||
]
|
||||
},
|
||||
// DEFI+S/ETH
|
||||
"0xFcBB61bcd4909bf4AF708F15AAaa905E0978cAfc": {
|
||||
lpType: "balancer",
|
||||
// LP token (BPT)
|
||||
lp: "0x35333cf3db8e334384ec6d2ea446da6e445701df",
|
||||
// Address in which the underlyings are deposited
|
||||
lpUnderlyingsAddress: "0x35333cf3db8e334384ec6d2ea446da6e445701df",
|
||||
underlyings: [
|
||||
// WETH
|
||||
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
||||
]
|
||||
},
|
||||
// DEFI+L/ETH
|
||||
"0xb8E59ce1359d80E4834228eDd6a3F560e7534438": {
|
||||
lpType: "balancer",
|
||||
// LP token (BPT)
|
||||
lp: "0xa795600590a7da0057469049ab8f1284baed977e",
|
||||
// Address in which the underlyings are deposited
|
||||
lpUnderlyingsAddress: "0xa795600590a7da0057469049ab8f1284baed977e",
|
||||
underlyings: [
|
||||
// WETH
|
||||
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
async function fetch() {
|
||||
const tokenAmounts = {}
|
||||
|
||||
async function pushTokenAmount(token, amount) {
|
||||
// Prevent double counting of TVL by excluding pies
|
||||
if(pies.includes(token.toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(tokenAmounts[token] == undefined) {
|
||||
|
||||
//create empty object
|
||||
tokenAmounts[token] = {
|
||||
decimals: 0,
|
||||
amount: 0,
|
||||
price: 0
|
||||
}
|
||||
|
||||
const decimals = await returnDecimals(token);
|
||||
|
||||
try {
|
||||
price = (await getTokenPricesFromString(token)).data[token.toLowerCase()].usd;
|
||||
} catch {
|
||||
// If no price is found set it to 0
|
||||
price = 0;
|
||||
}
|
||||
|
||||
tokenAmounts[token].decimals = decimals;
|
||||
tokenAmounts[token].price = price;
|
||||
}
|
||||
|
||||
tokenAmounts[token].amount += ((new BigNumber(amount)).div(10 ** tokenAmounts[token].decimals)).toNumber();
|
||||
}
|
||||
|
||||
// Pies
|
||||
for (const pieAddress of pies) {
|
||||
const pie = new web3.eth.Contract(pieABI, pieAddress);
|
||||
|
||||
const totalSupply = await pie.methods.totalSupply().call();
|
||||
const tokensAndAmounts = await pie.methods.calcTokensForAmount(totalSupply).call();
|
||||
|
||||
for(let i = 0; i < tokensAndAmounts.tokens.length; i ++) {
|
||||
const token = tokensAndAmounts.tokens[i];
|
||||
const amount = tokensAndAmounts.amounts[i];
|
||||
await pushTokenAmount(token, amount);
|
||||
}
|
||||
}
|
||||
|
||||
// Staking pools
|
||||
for (const stakingPoolAddress of Object.keys(stakingPools)) {
|
||||
const stakingPool = stakingPools[stakingPoolAddress];
|
||||
|
||||
const lp = new web3.eth.Contract(erc20ABI, stakingPool.lp);
|
||||
|
||||
const lpBalance = new BigNumber(await lp.methods.balanceOf(stakingPoolAddress).call());
|
||||
const lpTotalSupply = new BigNumber(await lp.methods.totalSupply().call());
|
||||
|
||||
if(stakingPool.lpType == "balancer") {
|
||||
for(const underlying of stakingPool.underlyings) {
|
||||
|
||||
const underlyingContract = new web3.eth.Contract(erc20ABI, underlying);
|
||||
const tokenAmount = new BigNumber(await underlyingContract.methods.balanceOf(stakingPool.lpUnderlyingsAddress).call());
|
||||
// console.log(tokenAmount.times(lpBalance).div(lpTotalSupply).toString());
|
||||
await pushTokenAmount(underlying, tokenAmount.times(lpBalance).div(lpTotalSupply));
|
||||
}
|
||||
} else {
|
||||
throw new Error("lpType not supported");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let nav = 0;
|
||||
|
||||
// Sum up nav
|
||||
for (const tokenAddress of Object.keys(tokenAmounts)) {
|
||||
const tokenAmount = tokenAmounts[tokenAddress];
|
||||
|
||||
nav += tokenAmount.amount * tokenAmount.price;
|
||||
}
|
||||
|
||||
return nav;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetch
|
||||
}
|
||||
24
projects/piedao/index.js
Normal file
24
projects/piedao/index.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const PieDAO = require("./pieDAO.js");
|
||||
|
||||
async function fetch() {
|
||||
// creating the PieDAO helper...
|
||||
let pieDAO = new PieDAO();
|
||||
|
||||
// calculating the total for Ovens...
|
||||
await pieDAO.calculateOvens();
|
||||
|
||||
// calculating the total for Pies...
|
||||
await pieDAO.calculatePies();
|
||||
|
||||
// calculating the total for Pools...
|
||||
await pieDAO.calculatePools();
|
||||
|
||||
// finally, returning the total NAV...
|
||||
return pieDAO.calculateNAV();
|
||||
}
|
||||
|
||||
fetch().then(console.log).catch(error => console.error("error", error));
|
||||
|
||||
module.exports = {
|
||||
fetch
|
||||
}
|
||||
6
projects/piedao/ovens.json
Normal file
6
projects/piedao/ovens.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"PLAY": "0x0c4Ff8982C66cD29eA7eA96d985f36aE60b85B1C",
|
||||
"DEFI++": "0x1d616dad84dd0b3ce83e5fe518e90617c7ae3915",
|
||||
"BCP": "0xe3d74df89163a8fa1cba540ff6b339d13d322f61",
|
||||
"YPIE": "0xAedec86DeDe3DEd9562FB00AdA623c0e9bEEb951"
|
||||
}
|
||||
219
projects/piedao/pieDAO.js
Normal file
219
projects/piedao/pieDAO.js
Normal file
@@ -0,0 +1,219 @@
|
||||
const utils = require('../helper/utils');
|
||||
const BigNumber = require("bignumber.js");
|
||||
|
||||
const web3 = require('../config/web3.js');
|
||||
|
||||
const pies_config = require("./pies.json");
|
||||
const ovens_config = require("./ovens.json");
|
||||
const pools_config = require("./pools.json");
|
||||
|
||||
const pieABI = require("../config/piedao/abi/IPie.json");
|
||||
const pieStakingAll = require("../config/piedao/abi/IStakingAll.json");
|
||||
const IStakingBalancer = require("../config/piedao/abi/IStakingBalancer.json");
|
||||
const IStakedToken = require("../config/piedao/abi/IStakedToken.json");
|
||||
const ISLP = require("../config/piedao/abi/ISLP.json");
|
||||
const IBPT = require("../config/piedao/abi/IBPT.json");
|
||||
const IBCP = require("../config/piedao/abi/IBCP.json");
|
||||
const IUniswap = require("../config/piedao/abi/IUniswap.json");
|
||||
const IStakedPieDAO = require("../config/piedao/abi/IStakedPieDAO.json");
|
||||
const IStakingUniswap = require("../config/piedao/abi/IStakingUniswap.json");
|
||||
const erc20ABI = require("../config/piedao/abi/ERC20.json");
|
||||
|
||||
module.exports = class PieDAO {
|
||||
pies = null;
|
||||
ovens = null;
|
||||
pools = null;
|
||||
|
||||
tokenAmounts = {};
|
||||
ovenAmounts = {};
|
||||
|
||||
constructor() {
|
||||
this.pies = pies_config;
|
||||
this.ovens = ovens_config;
|
||||
this.pools = pools_config;
|
||||
}
|
||||
|
||||
async calculatePies() {
|
||||
for (const pie of Object.keys(this.pies)) {
|
||||
const pieAddress = this.pies[pie];
|
||||
const pie_contract = new web3.eth.Contract(pieABI, pieAddress);
|
||||
const totalSupply = await pie_contract.methods.totalSupply().call();
|
||||
const tokensAndAmounts = await pie_contract.methods.calcTokensForAmount(totalSupply).call();
|
||||
|
||||
//console.log("calculatePies", pieAddress);
|
||||
|
||||
for(let i = 0; i < tokensAndAmounts.tokens.length; i ++) {
|
||||
const token = tokensAndAmounts.tokens[i];
|
||||
const amount = tokensAndAmounts.amounts[i];
|
||||
await this.pushTokenAmount(token, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async calculateOvens() {
|
||||
for (const oven of Object.keys(this.ovens)) {
|
||||
const ovenAddress = this.ovens[oven];
|
||||
|
||||
const ovenBalance = await web3.eth.getBalance(ovenAddress);
|
||||
const eth_value = await utils.getPricesfromString("ethereum");
|
||||
this.ovenAmounts[ovenAddress] = (ovenBalance / 1e18) * eth_value.data.ethereum.usd;
|
||||
}
|
||||
}
|
||||
|
||||
async calculatePools() {
|
||||
for (const pool of Object.keys(this.pools)) {
|
||||
const stakingPool = this.pools[pool];
|
||||
const poolAddress = this.pools[pool].address;
|
||||
let stakingContract, underlyingContract, underlyingBalance, underlyingSupply, underlyingAddress, underlyings, symbol = null;
|
||||
|
||||
switch(stakingPool.type) {
|
||||
case "all":
|
||||
stakingContract = new web3.eth.Contract(pieStakingAll, poolAddress);
|
||||
const poolCount = await stakingContract.methods.poolCount().call();
|
||||
|
||||
for(let i = 0; i < poolCount; i++) {
|
||||
underlyingAddress = await stakingContract.methods.getPoolToken(i).call();
|
||||
underlyingContract = new web3.eth.Contract(erc20ABI, underlyingAddress);
|
||||
|
||||
underlyingBalance = new BigNumber(await underlyingContract.methods.balanceOf(underlyingAddress).call());
|
||||
underlyingSupply = new BigNumber(await underlyingContract.methods.totalSupply().call());
|
||||
|
||||
symbol = await underlyingContract.methods.symbol().call();
|
||||
//console.log("calculatePools", stakingPool.type, underlyingAddress, symbol);
|
||||
|
||||
switch(symbol) {
|
||||
case "SLP":
|
||||
underlyingContract = new web3.eth.Contract(ISLP, underlyingAddress);
|
||||
|
||||
underlyings = new Array();
|
||||
underlyings.push(await underlyingContract.methods.token0().call());
|
||||
underlyings.push(await underlyingContract.methods.token1().call());
|
||||
await this.calculateUnderLyings(underlyings, underlyingAddress, underlyingBalance, underlyingSupply);
|
||||
|
||||
break;
|
||||
case "BPT":
|
||||
underlyingContract = new web3.eth.Contract(IBPT, underlyingAddress);
|
||||
|
||||
underlyings = await underlyingContract.methods.getFinalTokens().call();
|
||||
await this.calculateUnderLyings(underlyings, underlyingAddress, underlyingBalance, underlyingSupply);
|
||||
|
||||
break;
|
||||
case "BCP":
|
||||
underlyingContract = new web3.eth.Contract(IBCP, underlyingAddress);
|
||||
|
||||
underlyings = await underlyingContract.methods.getTokens().call();
|
||||
await this.calculateUnderLyings(underlyings, underlyingAddress, underlyingBalance, underlyingSupply);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "balancer":
|
||||
stakingContract = new web3.eth.Contract(IStakingBalancer, poolAddress);
|
||||
underlyingAddress = stakingPool.lp ? stakingPool.lp : await stakingContract.methods.uni().call();
|
||||
//console.log("calculatePools", stakingPool.type, underlyingAddress);
|
||||
|
||||
underlyingContract = new web3.eth.Contract(IStakedToken, underlyingAddress);
|
||||
underlyingBalance = new BigNumber(await underlyingContract.methods.balanceOf(poolAddress).call());
|
||||
underlyingSupply = new BigNumber(await underlyingContract.methods.totalSupply().call());
|
||||
|
||||
underlyings = await underlyingContract.methods.getFinalTokens().call();
|
||||
await this.calculateUnderLyings(underlyings, underlyingAddress, underlyingBalance, underlyingSupply);
|
||||
|
||||
break;
|
||||
|
||||
case "piedao":
|
||||
stakingContract = new web3.eth.Contract(IStakedPieDAO, poolAddress);
|
||||
underlyingAddress = await stakingContract.methods.uni().call();
|
||||
|
||||
underlyingContract = new web3.eth.Contract(IBCP, underlyingAddress);
|
||||
|
||||
underlyingBalance = new BigNumber(await underlyingContract.methods.balanceOf(underlyingAddress).call());
|
||||
underlyingSupply = new BigNumber(await underlyingContract.methods.totalSupply().call());
|
||||
|
||||
symbol = await underlyingContract.methods.symbol().call();
|
||||
//console.log("calculatePools", stakingPool.type, underlyingAddress, symbol);
|
||||
|
||||
underlyings = await underlyingContract.methods.getTokens().call();
|
||||
await this.calculateUnderLyings(underlyings, underlyingAddress, underlyingBalance, underlyingSupply);
|
||||
|
||||
break;
|
||||
|
||||
case "uniswap":
|
||||
stakingContract = new web3.eth.Contract(IStakingUniswap, poolAddress);
|
||||
underlyingAddress = await stakingContract.methods.uni().call();
|
||||
|
||||
underlyingContract = new web3.eth.Contract(IUniswap, underlyingAddress);
|
||||
|
||||
underlyingBalance = new BigNumber(await underlyingContract.methods.balanceOf(underlyingAddress).call());
|
||||
underlyingSupply = new BigNumber(await underlyingContract.methods.totalSupply().call());
|
||||
|
||||
symbol = await underlyingContract.methods.symbol().call();
|
||||
//console.log("calculatePools", stakingPool.type, underlyingAddress, symbol);
|
||||
|
||||
underlyings = new Array();
|
||||
underlyings.push(await underlyingContract.methods.token0().call());
|
||||
underlyings.push(await underlyingContract.methods.token1().call());
|
||||
await this.calculateUnderLyings(underlyings, underlyingAddress, underlyingBalance, underlyingSupply);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async calculateUnderLyings(underlyings, underlyingAddress, underlyingBalance, underlyingSupply) {
|
||||
for(const underlying of underlyings) {
|
||||
const underlyingContract = new web3.eth.Contract(erc20ABI, underlying);
|
||||
const tokenAmount = new BigNumber(await underlyingContract.methods.balanceOf(underlyingAddress).call());
|
||||
await this.pushTokenAmount(underlying, tokenAmount.times(underlyingBalance).div(underlyingSupply));
|
||||
}
|
||||
}
|
||||
|
||||
calculateNAV() {
|
||||
let nav = 0;
|
||||
|
||||
// Sum up nav
|
||||
for (const tokenAddress of Object.keys(this.tokenAmounts)) {
|
||||
const tokenAmount = this.tokenAmounts[tokenAddress];
|
||||
|
||||
nav += tokenAmount.amount * tokenAmount.price;
|
||||
}
|
||||
|
||||
for (const ovenAddress of Object.keys(this.ovenAmounts)) {
|
||||
nav += this.ovenAmounts[ovenAddress];
|
||||
}
|
||||
|
||||
return nav;
|
||||
}
|
||||
|
||||
async pushTokenAmount(token, amount) {
|
||||
// Prevent double counting of TVL by excluding pies
|
||||
/*
|
||||
if(Object.keys(this.pies).find(x => this.pies[x].toLowerCase() == token.toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
if(this.tokenAmounts[token] == undefined) {
|
||||
|
||||
//create empty object
|
||||
this.tokenAmounts[token] = {
|
||||
decimals: 0,
|
||||
amount: 0,
|
||||
price: 0
|
||||
};
|
||||
|
||||
this.tokenAmounts[token].decimals = await utils.returnDecimals(token);
|
||||
|
||||
try {
|
||||
this.tokenAmounts[token].price = (await utils.getTokenPricesFromString(token)).data[token.toLowerCase()].usd;
|
||||
} catch {
|
||||
// If no price is found set it to 0
|
||||
this.tokenAmounts[token].price = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.tokenAmounts[token].amount += ((new BigNumber(amount)).div(10 ** this.tokenAmounts[token].decimals)).toNumber();
|
||||
}
|
||||
}
|
||||
10
projects/piedao/pies.json
Normal file
10
projects/piedao/pies.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"BTC++": "0x0327112423f3a68efdf1fcf402f6c5cb9f7c33fd",
|
||||
"USD++": "0x9a48bd0ec040ea4f1d3147c025cd4076a2e71e3e",
|
||||
"DEFI+S": "0xad6a626ae2b43dcb1b39430ce496d2fa0365ba9c",
|
||||
"DEFI+L": "0x78f225869c08d478c34e5f645d07a87d3fe8eb78",
|
||||
"DEFI++": "0x8D1ce361eb68e9E05573443C407D4A3Bed23B033",
|
||||
"BCP": "0xe4f726adc8e89c6a6017f01eada77865db22da14",
|
||||
"YPIE": "0x17525E4f4Af59fbc29551bC4eCe6AB60Ed49CE31",
|
||||
"PLAY": "0x33e18a092a93ff21ad04746c7da12e35d34dc7c4"
|
||||
}
|
||||
43
projects/piedao/pools.json
Normal file
43
projects/piedao/pools.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"Staked BCP": {
|
||||
"type": "piedao",
|
||||
"address": "0x9EFD60f40e35B3cA7294cC268A35d3e35101BE42"
|
||||
},
|
||||
"Staked DEFI++": {
|
||||
"type": "piedao",
|
||||
"address": "0x59706D38F1452F387563f06b632af7302456fE66"
|
||||
},
|
||||
"Staked YPIE/ETH": {
|
||||
"type": "uniswap",
|
||||
"address": "0x3A05D2394F7241e00F4ae90A1f14D9c9c48A1E9B"
|
||||
},
|
||||
"ALL": {
|
||||
"type": "all",
|
||||
"address": "0x6de77A304609472A4811a0BFD47d8682Aebc29df"
|
||||
},
|
||||
"DOUGH/ETH": {
|
||||
"type": "balancer",
|
||||
"address": "0xB9a4Bca06F14A982fcD14907D31DFACaDC8ff88E"
|
||||
},
|
||||
"DOUGH/ETH (OLD)": {
|
||||
"type": "balancer",
|
||||
"address": "0x8314337d2b13e1A61EadF0FD1686b2134D43762F"
|
||||
},
|
||||
"DEFI+S/ETH": {
|
||||
"type": "balancer",
|
||||
"address": "0xFcBB61bcd4909bf4AF708F15AAaa905E0978cAfc"
|
||||
},
|
||||
"DEFI+S/ETH (OLD)": {
|
||||
"type": "balancer",
|
||||
"address": "0x220f25C2105a65425913FE0CF38e7699E3992B97"
|
||||
},
|
||||
"DEFI+L/ETH": {
|
||||
"type": "balancer",
|
||||
"address": "0xb8E59ce1359d80E4834228eDd6a3F560e7534438"
|
||||
},
|
||||
"DEFI+L/ETH (OLD)": {
|
||||
"type": "balancer",
|
||||
"address": "0xc1a116cb2d354503f9ec5cb436a3b213f377631d",
|
||||
"lp": "0xa795600590a7da0057469049ab8f1284baed977e"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user