feat: 获取统计数据
This commit is contained in:
parent
5b915e6413
commit
eacfbf4406
|
|
@ -90,7 +90,8 @@
|
||||||
"name": "_poolInfo",
|
"name": "_poolInfo",
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{ "internalType": "uint256", "name": "accHCCPerShare", "type": "uint256" },
|
{ "internalType": "uint256", "name": "accHCCPerShare", "type": "uint256" },
|
||||||
{ "internalType": "uint256", "name": "totalAmount", "type": "uint256" }
|
{ "internalType": "uint256", "name": "totalAmount", "type": "uint256" },
|
||||||
|
{ "internalType": "uint256", "name": "num", "type": "uint256" }
|
||||||
],
|
],
|
||||||
"stateMutability": "view",
|
"stateMutability": "view",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,8 @@
|
||||||
"name": "_poolInfo",
|
"name": "_poolInfo",
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{ "internalType": "uint256", "name": "accHCCPerShare", "type": "uint256" },
|
{ "internalType": "uint256", "name": "accHCCPerShare", "type": "uint256" },
|
||||||
{ "internalType": "uint256", "name": "totalAmount", "type": "uint256" }
|
{ "internalType": "uint256", "name": "totalAmount", "type": "uint256" },
|
||||||
|
{ "internalType": "uint256", "name": "num", "type": "uint256" }
|
||||||
],
|
],
|
||||||
"stateMutability": "view",
|
"stateMutability": "view",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import holderAbi from 'config/abi/holder.json'
|
||||||
import tokens from './tokens'
|
import tokens from './tokens'
|
||||||
import { BoardConfig } from './types'
|
import { BoardConfig } from './types'
|
||||||
|
|
||||||
const bordsList: BoardConfig[] = [
|
const boardsList: BoardConfig[] = [
|
||||||
{
|
{
|
||||||
pid: 1,
|
pid: 1,
|
||||||
name: 'Board',
|
name: 'Board',
|
||||||
|
|
@ -13,6 +13,7 @@ const bordsList: BoardConfig[] = [
|
||||||
tokenAddresses: tokens.hcc.address,
|
tokenAddresses: tokens.hcc.address,
|
||||||
tokenDecimals: 18,
|
tokenDecimals: 18,
|
||||||
contractAddress: addresses.boardChef,
|
contractAddress: addresses.boardChef,
|
||||||
|
contractRewardAddress: addresses.boardRewardChef,
|
||||||
abi: boardAbi,
|
abi: boardAbi,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -23,8 +24,9 @@ const bordsList: BoardConfig[] = [
|
||||||
tokenAddresses: tokens.hcc.address,
|
tokenAddresses: tokens.hcc.address,
|
||||||
tokenDecimals: 18,
|
tokenDecimals: 18,
|
||||||
contractAddress: addresses.holderChef,
|
contractAddress: addresses.holderChef,
|
||||||
|
contractRewardAddress: addresses.holderRewardChef,
|
||||||
abi: holderAbi,
|
abi: holderAbi,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
export default bordsList
|
export default boardsList
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,21 @@ export default {
|
||||||
56: '0x6ab8463a4185b80905e05a9ff80a2d6b714b9e95',
|
56: '0x6ab8463a4185b80905e05a9ff80a2d6b714b9e95',
|
||||||
},
|
},
|
||||||
boardChef: {
|
boardChef: {
|
||||||
97: '0x7e64aac0806597cb2efddf7c001e59d6b4e9cb15',
|
97: '0xcf5411e9bd61bbd68ddf08e8a3f7680af8993cd0',
|
||||||
56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 节点董事会合约
|
56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 节点董事会合约
|
||||||
},
|
},
|
||||||
|
boardRewardChef: {
|
||||||
|
97: '0x2937a050705009270c9b5bc096d57d519ab7c39b',
|
||||||
|
56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 节点董事会分红合约
|
||||||
|
},
|
||||||
holderChef: {
|
holderChef: {
|
||||||
97: '0x4cbbb9e9569a208c9975574675ba24eccea342b3',
|
97: '0x20b74dfb41172fdce43758c014959b5e2586d2cf',
|
||||||
56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 持币人
|
56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 持币人
|
||||||
},
|
},
|
||||||
|
holderRewardChef: {
|
||||||
|
97: '0x46271393dd6f2c8798a44f857888aa6a85af3527',
|
||||||
|
56: '0x46271393dd6f2c8798a44f857888aa6a85af3527', // NEED CHANGE 持币人分红
|
||||||
|
},
|
||||||
referralChef: {
|
referralChef: {
|
||||||
97: '0x8a5dc1e8262d6a3de664624fdc13a533ba64e60d',
|
97: '0x8a5dc1e8262d6a3de664624fdc13a533ba64e60d',
|
||||||
56: '0x88F46EF2Ee08494D84942DCA3bd24cDEf7C88Ae2', // NEED CHANGE 邀请或则军团长
|
56: '0x88F46EF2Ee08494D84942DCA3bd24cDEf7C88Ae2', // NEED CHANGE 邀请或则军团长
|
||||||
|
|
|
||||||
|
|
@ -186,5 +186,7 @@ export interface BoardConfig {
|
||||||
tokenAddresses: Address
|
tokenAddresses: Address
|
||||||
tokenDecimals: number
|
tokenDecimals: number
|
||||||
contractAddress: Address
|
contractAddress: Address
|
||||||
|
contractRewardAddress: Address
|
||||||
abi: any
|
abi: any
|
||||||
|
// rewardAbi: any
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { useDispatch } from 'react-redux'
|
||||||
import boardsConfig from 'config/constants/boards'
|
import boardsConfig from 'config/constants/boards'
|
||||||
import tokens from 'config/constants/tokens'
|
import tokens from 'config/constants/tokens'
|
||||||
import { getAddress, getBoardAddress } from 'utils/addressHelpers'
|
import { getAddress, getBoardAddress } from 'utils/addressHelpers'
|
||||||
import { getDecimalAmountNumber } from 'utils/formatBalance'
|
import { getBalanceAmount } from 'utils/formatBalance'
|
||||||
import boardABI from 'config/abi/board.json'
|
import boardABI from 'config/abi/board.json'
|
||||||
import erc20ABI from 'config/abi/erc20.json'
|
import erc20ABI from 'config/abi/erc20.json'
|
||||||
import multicall from 'utils/multicall'
|
import multicall from 'utils/multicall'
|
||||||
|
|
@ -51,47 +51,55 @@ const Boards: React.FC = () => {
|
||||||
const [totalAmount, setTotalAmount] = useState(0)
|
const [totalAmount, setTotalAmount] = useState(0)
|
||||||
// 分红总额
|
// 分红总额
|
||||||
const [shareOutBonus, setShareOutBonus] = useState(0)
|
const [shareOutBonus, setShareOutBonus] = useState(0)
|
||||||
// 获取资金池总额
|
// // 获取资金池总额
|
||||||
const getCapital = async () => {
|
// const getCapital = async () => {
|
||||||
console.log(boardsConfig)
|
// const calls = boardsConfig.map((board) => {
|
||||||
const calls = boardsConfig.map((board) => {
|
// const contractAddress = getAddress(board.contractAddress)
|
||||||
const contractAddress = getAddress(board.contractAddress)
|
// return {
|
||||||
return {
|
// address: contractAddress,
|
||||||
address: contractAddress,
|
// name: '_poolInfo',
|
||||||
name: '_poolInfo',
|
// }
|
||||||
}
|
// })
|
||||||
})
|
// let total = 0
|
||||||
let total = 0
|
// const boardsPoolInfo = await multicall(boardABI, calls)
|
||||||
const boardsPoolInfo = await multicall(boardABI, calls)
|
// boardsPoolInfo.forEach((item) => {
|
||||||
boardsPoolInfo.forEach((item) => {
|
// total += new BigNumber(item.totalAmount._hex).toNumber()
|
||||||
total += new BigNumber(item.totalAmount._hex).toNumber()
|
// })
|
||||||
})
|
// setTotalAmount(total)
|
||||||
setTotalAmount(total)
|
// }
|
||||||
}
|
|
||||||
// 获取分红总额
|
// 获取分红总额
|
||||||
const fetchBoardShares = async () => {
|
const fetchBoardShares = async () => {
|
||||||
const calls = boardsConfig.map((board) => {
|
const boardsData = await Promise.all(
|
||||||
const contractAddress = getAddress(board.tokenAddresses)
|
boardsConfig.map(async (boardConfig) => {
|
||||||
return {
|
const [boardPoolInfo] = await multicall(boardConfig.abi, [
|
||||||
address: contractAddress,
|
{
|
||||||
|
address: getAddress(boardConfig.contractAddress),
|
||||||
|
name: '_poolInfo',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
const [waitWithdrawAmount] = await multicall(erc20ABI, [
|
||||||
|
{
|
||||||
|
address: getAddress(boardConfig.tokenAddresses),
|
||||||
name: 'balanceOf',
|
name: 'balanceOf',
|
||||||
params: ['0x2937a050705009270c9b5bc096d57d519ab7c39b'],
|
params: [getAddress(boardConfig.contractRewardAddress)],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
return {
|
||||||
|
totalAmount: getBalanceAmount(new BigNumber(boardPoolInfo.totalAmount._hex)).toNumber(),
|
||||||
|
num: new BigNumber(boardPoolInfo?.num?._hex).toNumber(),
|
||||||
|
waitWithdrawAmount: getBalanceAmount(new BigNumber(waitWithdrawAmount.balance._hex)).toNumber(),
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
let total = 0
|
)
|
||||||
const sharesRed = await multicall(erc20ABI, calls)
|
console.log(boardsData)
|
||||||
sharesRed.forEach((item) => {
|
|
||||||
total += new BigNumber(item.balance._hex).div(new BigNumber(10).pow(18)).toNumber()
|
|
||||||
})
|
|
||||||
setShareOutBonus(total)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(fetchBoardsPublicDataAsync())
|
dispatch(fetchBoardsPublicDataAsync())
|
||||||
|
fetchBoardShares()
|
||||||
if (account) {
|
if (account) {
|
||||||
dispatch(fetchBoardUserDataAsync(account))
|
dispatch(fetchBoardUserDataAsync(account))
|
||||||
getCapital()
|
// getCapital()
|
||||||
fetchBoardShares()
|
|
||||||
}
|
}
|
||||||
}, [account, dispatch, fastRefresh])
|
}, [account, dispatch, fastRefresh])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue