Skip to content

Conversation

@RustNinja
Copy link
Contributor

@RustNinja RustNinja commented May 8, 2024

Eth bridge indexer metrics + coinmarketcap API to fetch a price.

todo:

RustNinja and others added 20 commits May 6, 2024 22:52
…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.
@RustNinja RustNinja requested a review from vmarkushin May 8, 2024 17:57
@RustNinja RustNinja changed the base branch from main to vmarkushin/test-succint May 8, 2024 17:57
@RustNinja RustNinja changed the title Eth bridge metrics + coinmarketcap API to fetch a price. Eth bridge indexer metrics + coinmarketcap API to fetch a price. May 8, 2024
input TEXT NOT NULL,
max_fee_per_gas TEXT,
max_priority_fee_per_gas TEXT,
method TEXT NOT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we store multiple method calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid using leak (use .clone() for example)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parse the Address from string and compare

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

// 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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use .sort_by_key

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]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println!("Relayer txs: {:?}", relayer_txs[0]);
println!("Relayer txs: {:?}", relayer_txs);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too much logs. going to remove.

Comment on lines 230 to 247
// `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
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this code to a separate function to avoid duplication

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

RustNinja and others added 3 commits May 9, 2024 22:33
…thods

parse call batch methods to store into db actions from relayer.
introduce args for metric indexer config instead of hardcoded variables
@RustNinja RustNinja requested review from blasrodri and vmarkushin May 9, 2024 21:39
`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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a real api-key ?

Copy link
Contributor Author

@RustNinja RustNinja May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

real key. without any funds. 10k monthly credits calls.
example.
repo is private. you can substitute with your key if you wish

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

//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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe, this should be configurable? not hardcodeded, in case coinmarketcap changes endpoint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@RustNinja RustNinja requested a review from rjonczy May 10, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants