//引入web3
const Web3 = require('web3');
const util = require('ethereumjs-util');
//部署合约的abi
const BPoolABI = require('./BPoolABI.json');
const ERC20ABI = require("./ERC20.json")
// const BigNumber = require('bignumber.js')
const web3 = new Web3('https://mainnet.infura.io/v3/45192e3bb296499a93ef0a73c0eb159a');
//部署到链上的合约的地址
const factoryAddress = '0x9424B1412450D0f8Fc2255FAf6046b98213B76Bd';
const BPoolAddress = '0x165a50Bc092f6870DC111C349baE5Fc35147ac86';
web3.eth.getTransactionCount('0x9424B1412450D0f8Fc2255FAf6046b98213B76Bd').then(console.log);
async function PoolsMassege(){
//创建一个存放所有池的地址的数组
var addressPoll = new Array();
var sender = "9424B1412450D0f8Fc2255FAf6046b98213B76Bd";
for(let nonce = 1; nonce<3; nonce++) {
var address = util.generateAddress(Buffer.from(sender,"hex"),nonce).toString("hex");
let result = await web3.eth.getTransactionCount(`0x${address}`);
if (result == 1) {
var addressPoll_01 = '0x'+address;
//allPool:为返回的数据长度
var allPool = addressPoll.push(addressPoll_01);
} else {
console.log('null_poll:0x'+ address);
}
}
let Pools = [];
for(let item of addressPoll) {
let MyContract = new web3.eth.Contract(BPoolABI, item);
let isPublicSwap = await MyContract.methods.isPublicSwap().call();
let SwapFee = await MyContract.methods.getSwapFee().call();
//在该池中存在的 Tonken 数
let NumTokens = await MyContract.methods.getNumTokens().call();
//获取池子中具体的 Token
let CurrentTokens = await MyContract.methods.getCurrentTokens().call();
let getTotalDenormalizedWeight = await MyContract.methods.getTotalDenormalizedWeight().call();
//获取池的控制者地址
let getController = await MyContract.methods.getController().call();
//池的最终确定,不可更改
let isFinalized = await MyContract.methods.isFinalized().call();
let token=[];
for (const tokenID of CurrentTokens) {
try {
//通过 ERC20 的 ABI 创建实例获取其余遵循 ERC20 规则的币的相关信息,(MKR币不遵循)
let MyContract_01 = new web3.eth.Contract(ERC20ABI, tokenID);
//获取该 Toten 的余额
let getBalance = await MyContract.methods.getBalance(tokenID).call();
//获取该 Token 的精度
let decimals = await MyContract_01.methods.decimals().call();
let id = item +"-"+ tokenID;
获取规约前的权重
let DenormalizedWeight = await MyContract.methods.getDenormalizedWeight(tokenID).call();
//获取规约后的权重,所有令牌的组合归一化权重总和将为1。(注:由于除法精度损失,实际和可能为1加减几微)
let NormalizedWeight = await MyContract.methods.getNormalizedWeight(tokenID).call();
//获取 Token 的名字
var symbol = await MyContract_01.methods.symbol().call();
//绑定 Token(令牌) 具有有效的余额和权重。
let isBound = await MyContract.methods.isBound(tokenID).call();
token.push({
"addrrs":tokenID,
"Balance":getBalance,
"id":id,
"DenormalizedWeight":DenormalizedWeight,
"NormalizedWeight":NormalizedWeight,
"decimals":decimals,
"symbol":symbol,
"isBound":isBound
})
} catch (error) {
console.log(error);
}
}
let Pools_obj = {
"poll_id": item,
"PublicSwap":isPublicSwap,
"SwapFee":SwapFee,
"NumTokens":NumTokens,
"TokensList":CurrentTokens,
"Tokens":token,
"Weight":getTotalDenormalizedWeight,
"PoolController":getController,
"isFinalized":isFinalized,
}
Pools.push(Pools_obj);
}
console.log(JSON.stringify(Pools));
}
PoolsMassege();
Balancer以太坊主网项目的数据抓取
最新推荐文章于 2022-11-03 19:51:41 发布