|
1 | 1 | const { sumTokens2, sumTokensExport, } = require('../helper/unwrapLPs')
|
2 |
| -const Helper = require("./Helper.js"); |
3 |
| -const { farms: { MasterChefAddress, LockStakingAddress }, abi, token: { XWIN } } = require('./Helper.js'); |
4 |
| - |
5 |
| -async function tvl(api) { |
6 |
| - const vaults = [ |
7 |
| - ...Object.values(Helper.Strategies), |
8 |
| - ...Object.values(Helper.PublicVault), |
9 |
| - ...Object.values(Helper.PrivateVault), |
10 |
| - ] |
11 |
| - const bals = await api.multiCall({ abi: 'uint256:getVaultValues', calls: vaults}) |
12 |
| - const tokens = await api.multiCall({ abi: 'address:baseToken', calls: vaults}) |
13 |
| - api.addTokens(tokens, bals) |
| 2 | +const { getConfig } = require('../helper/cache') |
| 3 | +const { farms: { MasterChefAddress, LockStakingAddress }, abi, token: { XWIN } } = require('./Helper.js'); |
| 4 | + |
| 5 | +const PrivateURL = "https://us-central1-xwinfinance-main.cloudfunctions.net/getPrivateVaults" |
| 6 | + |
| 7 | +const config = { |
| 8 | + bsc: { |
| 9 | + portfolioURL: "https://s3.ap-northeast-1.amazonaws.com/download.xwin.finance/v2-config/bsc/xwinfundv2.json", |
| 10 | + strategyUrl: 'https://s3.ap-northeast-1.amazonaws.com/download.xwin.finance/v2-config/bsc/xwinstrategies.json', |
| 11 | + privateKey: 'BNB', |
| 12 | + }, |
| 13 | + arbitrum: { |
| 14 | + portfolioURL: "https://s3.ap-northeast-1.amazonaws.com/download.xwin.finance/v2-config/arb/xwinfundv2.json", |
| 15 | + strategyUrl: "https://s3.ap-northeast-1.amazonaws.com/download.xwin.finance/v2-config/arb/xwinstrategies.json", |
| 16 | + privateKey: 'ARB', |
| 17 | + }, |
| 18 | + polygon: { |
| 19 | + strategyUrl: "https://s3.ap-northeast-1.amazonaws.com/download.xwin.finance/v2-config/polygon/xwinstrategies.json", |
| 20 | + privateKey: 'Polygon', |
| 21 | + }, |
14 | 22 | }
|
15 | 23 |
|
| 24 | +Object.keys(config).forEach(chain => { |
| 25 | + const { portfolioURL, strategyUrl, privateKey, } = config[chain] |
| 26 | + module.exports[chain] = { |
| 27 | + tvl: async (api) => { |
| 28 | + const vaults = (await getConfig('xWinFinance/vaults/' + api.chain, strategyUrl)).map(i => i.contractaddress) |
| 29 | + const privateVaults = await getConfig('xWinFinance/privateVaults', PrivateURL) |
| 30 | + |
| 31 | + vaults.push(...privateVaults[privateKey]) |
| 32 | + if (portfolioURL) { |
| 33 | + const portfolioVaults = await getConfig('xWinFinance/portfolioVaults/' + api.chain, portfolioURL) |
| 34 | + vaults.push(...portfolioVaults.map(i => i.contractaddress)) |
| 35 | + } |
| 36 | + |
| 37 | + const bals = await api.multiCall({ abi: 'uint256:getVaultValues', calls: vaults }) |
| 38 | + const tokens = await api.multiCall({ abi: 'address:baseToken', calls: vaults }) |
| 39 | + const decimals = await api.multiCall({ abi: 'erc20:decimals', calls: tokens }) |
| 40 | + |
| 41 | + |
| 42 | + //Get Vault Values returns 18 decimals even if the base token is not |
| 43 | + //For loop that removes the extra zeros if the base token is not 18 decimals. |
| 44 | + bals.forEach((bal, i) => bals[i] = bal / 10 ** (18 - decimals[i])) |
| 45 | + |
| 46 | + api.addTokens(tokens, bals) |
| 47 | + } |
| 48 | + } |
| 49 | +}) |
| 50 | + |
16 | 51 | async function pool2(api) {
|
17 |
| - const data = await api.fetchList({ lengthAbi: abi.poolLength, itemAbi: abi.poolInfoMaster, target: MasterChefAddress, }) |
| 52 | + const data = await api.fetchList({ lengthAbi: abi.poolLength, itemAbi: abi.poolInfoMaster, target: MasterChefAddress, }) |
18 | 53 | return sumTokens2({ api, owner: MasterChefAddress, tokens: data.map(i => i[0]), resolveLP: true, blacklistedTokens: [XWIN, LockStakingAddress] })
|
19 | 54 | }
|
20 | 55 |
|
21 |
| -module.exports = { |
22 |
| - bsc: { |
23 |
| - tvl, |
24 |
| - pool2, |
25 |
| - staking: sumTokensExport({ owners: [MasterChefAddress, LockStakingAddress], tokens: [XWIN]}) |
26 |
| - }, |
27 |
| -}; |
| 56 | +module.exports.bsc.pool2 = pool2 |
| 57 | +module.exports.bsc.staking = sumTokensExport({ owners: [MasterChefAddress, LockStakingAddress], tokens: [XWIN] }) |
0 commit comments