我想计算 BNB 中 BEP20 代币的价格。我检查了 poocoin 和 pancakeswap 他们是如何计算价格的。正如我所看到的,他们通过 web3.js 不断地调用 bsc-dataseed,但我还没有找到解决方案。
我的调查现状:
- 他们不断调用数据种子(webrpc)以获取最新的块号:
// Request params
{
"jsonrp": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}
- 在他们收到最新的块后,他们立即使用以下参数开始另一个调用
{
"jsonrpc": "2.0",
"id": 53,
"method": "eth_call",
"params": [
{
"to": "0x1ee38d535d541c55c9dae27b12edf090c608e6fb",
"data": "0x252dba420000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000580000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000006800000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000078000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000880000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000009800000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a800000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000b800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000c800000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000d800000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000e800000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000000f8000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001080000000000000000000000000000000000000000000000000000000000000110000000000000000000000000003ff6c83226cdb10c7a42a2c54c67d63a135ab69000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac0000000000000000000000000000000000000000000000000000000000000000000000000000000003fc20bdafdac6b2ae8f7f5f885f0819c2b968f0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac0000000000000000000000000000000000000000000000000000000000000000000000000000000008b018585d4949ae4714f057b66b8b033408bfa6000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac0000000000000000000000000000000000000000000000000000000000000000000000000000000012c8db147721ac1e3e54e9ff73d99ef0ee4b1725000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac000000000000000000000000000000000000000000000000000000000000000000000000000000001b96b92314c44b159149f7e0303511fb2fc4774f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac0000000000000000000000000000000000000000000000000000000000000000000000000000000020bcc3b8a0091ddac2d0bc30f68e6cbb97de59cd000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac000000000000000000000000000000000000000000000000000000000000000000000000000000002c5d712cf39eaebc1ef2d1281eb48a70dcd34d49000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac000000000000000000000000000000000000000000000000000000000000000000000000000000003ab77e40340ab084c3e23be8e5a6f7afed9d41dc000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac000000000000000000000000000000000000000000000000000000000000000000000000000000003b872e6b1633f060680cf9c277b43dd1e254e564000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac0000000000000000000000000000000000000000000000000000000000000000000000000000000056c77d59e82f33c712f919d09fceddf49660a829000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac000000000000000000000000000000000000000000000000000000000000000000000000000000006f656513f6e8eae19b6dc30cd372dd6ba4b5543a000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac0000000000000000000000000000000000000000000000000000000000000000000000000000000070d8929d04b60af4fb9b58713ebcf18765ade422000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac000000000000000000000000000000000000000000000000000000000000000000000000000000007246d6ea86d34af343f03cc1eb952a4f98467a4e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac000000000000000000000000000000000000000000000000000000000000000000000000000000007380e10f5c5f9dff4857de3cf9c39bb16f4c6dcf000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac000000000000000000000000000000000000000000000000000000000000000000000000000000007561eee90e24f3b348e1087a005f78b4c8453524000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac0000000000000000000000000000000000000000000000000000000000000000000000000000000088c4bcf826410a81b58bc9b79a17641b443dc52e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac0000000000000000000000000000000000000000000000000000000000000000000000000000000092ee07c591c26775b4d31259d5417e00553e857c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac000000000000000000000000000000000000000000000000000000000000000000000000000000009adc6fb78cefa07e13e9294f150c1e8c1dd566c0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000cc6b11de64dce6e5052a84b67cbbfd210ed530f7000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000d1f12370b2ba1c79838337648f820a87edf5e1e6000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000b3c4217ab2b265bf8c69718d280e3708b5e50577000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000b8875e207ee8096a929d543c9981c9586992eacb000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000c15fa3e22c912a276550f3e5fe3b0deb87b55acd000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000cee09ae86a78ce0cea3a4ea8cced5d41c0468e67000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000d9a0d1f5e02de2403f68bb71a15f8847a854b494000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000e7cc44de50b54906a9c1c48240650be2766481fc000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000fb7deb2236815222113d949d935cca4901531677000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000fa3107bca2ff6db4131bcd62b598cb00d9087f58000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000"
},
"latest"
]
}
据我所知,这0x1ee38d535d541c55c9dae27b12edf090c608e6fb
是一份包含该multicall
方法的合同。数据的前 10 个字符(0x252dba42)是aggregate
方法。但是数据的剩余部分是什么?
这是aggregate
方法的合同 ABI:
{
"constant": true,
"inputs": [
{
"components": [
{"name": "target","type": "address"},
{"name": "callData","type": "bytes"}
],
"name": "calls",
"type": "tuple[]"
}
],
"name": "aggregate",
"outputs": [
{
"name": "blockNumber",
"type": "uint256"
},
{
"name": "returnData",
"type": "bytes[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
问题:
需要第二个电话吗?
如何根据这些数据计算价格?
你知道更简单的方法吗?