Eth bridge indexer metrics + coinmarketcap API to fetch a price.#159
Eth bridge indexer metrics + coinmarketcap API to fetch a price.#159RustNinja wants to merge 32 commits into
Conversation
…packet-indexer fee collector indexer + send packet indexer
introduced DatabaseFeeCollector to save the fee collected/withdrawn
parse and use event of send packet to store into db
…-api Introduce coinmarketcap api to fetch a price and add metrics fee usd.
| input TEXT NOT NULL, | ||
| max_fee_per_gas TEXT, | ||
| max_priority_fee_per_gas TEXT, | ||
| method TEXT NOT NULL, |
There was a problem hiding this comment.
How do we store multiple method calls?
There was a problem hiding this comment.
introduced call_batch_methods column as a vec of method's selectors called by relayer to call_batch solidity fn.
|
|
||
| let fee_collector_address : ethabi::Address = "0x6f11fb4d4178c5d5e3ee4bc7820d8cfed0b59ce7".parse().unwrap(); | ||
| let fee_collector_address_vec = Box::new(vec![fee_collector_address]); | ||
| let f: &'static mut Vec<ethabi::Address> = Box::leak(fee_collector_address_vec); |
There was a problem hiding this comment.
Try to avoid using leak (use .clone() for example)
There was a problem hiding this comment.
clone does not work here.
|
|
||
| for i in transactions{ | ||
| all_txs.insert(i.hash.clone(), i.clone()); | ||
| if i.from_address.eq_ignore_ascii_case("0x6c57e54C379b5716999ae9AAE4917c9B35AC2CB9") && i.to_address.eq_ignore_ascii_case("0xd856f0f9efa054896fe3596e05978bbe686de131"){ |
There was a problem hiding this comment.
Parse the Address from string and compare
| } | ||
|
|
||
| // relayer_txs.retain(|x| x.from_address.eq_ignore_ascii_case("0x6c57e54C379b5716999ae9AAE4917c9B35AC2CB9")); | ||
| relayer_txs.sort_by(|a, b| a.block_number.cmp(&b.block_number)); |
| relayer_txs.sort_by(|a, b| a.block_number.cmp(&b.block_number)); | ||
| println!("Relayer txs len: {:?}", relayer_txs.len()); | ||
| if relayer_txs.len() > 0 { | ||
| println!("Relayer txs: {:?}", relayer_txs[0]); |
There was a problem hiding this comment.
| println!("Relayer txs: {:?}", relayer_txs[0]); | |
| println!("Relayer txs: {:?}", relayer_txs); |
There was a problem hiding this comment.
too much logs. going to remove.
| // `from_tos` is `block_numbers` shrinked to pairs of `(from_block, to_block)` | ||
| // e.g. block numbers = [1, 2, 3, 5, 6, 7, 8, 10], from_tos = [(1,3), (5,8), (10, 10)] | ||
| let from_tos: Vec<(i64, i64)> = block_numbers.iter().fold(vec![], |mut acc, block_number| { | ||
| if acc.is_empty() { | ||
| acc.push((*block_number, *block_number)); | ||
| return acc | ||
| } | ||
|
|
||
| let last_from_to = acc.last_mut().unwrap(); | ||
|
|
||
| if last_from_to.1 + 1 == *block_number { | ||
| last_from_to.1 = *block_number; | ||
| } else { | ||
| acc.push((*block_number, *block_number)); | ||
| } | ||
|
|
||
| acc | ||
| }); |
There was a problem hiding this comment.
Extract this code to a separate function to avoid duplication
…thods parse call batch methods to store into db actions from relayer.
introduce args for metric indexer config instead of hardcoded variables
Add block number to fee collector, fix bug with decoding, extract to fn
| `TODO: programs and flags.` | ||
|
|
||
| 5. Usage | ||
| `DATABASE_URL="pg://postgres:password@localhost/postgres" REDIS_URL="redis://localhost:6379" cargo run --package evm-indexer --bin evm-indexer -- --chain=mainnet --start-block=19789739 --rpcs=https://geth-execution-0.ethereum-mainnet.sre-scratchpad-349209.composablenodes.tech:443 --contract-addresses=0xd856f0f9efa054896fe3596e05978bbe686de131 --ibc-core-address=0xd856f0f9efa054896fe3596e05978bbe686de131 --relayer-address=0x6c57e54C379b5716999ae9AAE4917c9B35AC2CB9 --fee-collector-address=0x6f11fb4d4178c5d5e3ee4bc7820d8cfed0b59ce7 --ics20-transfer-bank-address=0x148acd3cd4d6a17cd2abbecd0745b09b62c64f84 --coinmarketcap-api-key=449a42d7-b66f-4b85-b957-cc6599b8c1e6` |
There was a problem hiding this comment.
real key. without any funds. 10k monthly credits calls.
example.
repo is private. you can substitute with your key if you wish
| //price-performance-stats is not allowed for free plan | ||
| // let mut url = Url::parse("https://pro-api.coinmarketcap.com/v2/cryptocurrency/price-performance-stats/latest").unwrap(); | ||
| //only quotes/latest is allowed for free plan | ||
| let mut url = Url::parse("https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest").unwrap(); |
There was a problem hiding this comment.
maybe, this should be configurable? not hardcodeded, in case coinmarketcap changes endpoint
There was a problem hiding this comment.
there are so many params for this indexer to set as a dependency.
if endpoint will change then the code probably will not work at all and need to change the logic inside of source code.
Eth bridge indexer metrics + coinmarketcap API to fetch a price.
todo:
get latest pricetoget price on date