Skip to content

Commit

Permalink
pindexer: implement override for hardcoded values in app views (#4936)
Browse files Browse the repository at this point in the history
## Describe your changes

This adds two flags:

```
 --indexing-denom <INDEXING_DENOM>
            The denom to use for indexing related components, of the form passet1... [default:
            passet1w6e7fvgxsy6ccy3m8q0eqcuyw6mh3yzqu3uq9h58nu8m8mku359spvulf6
```

for setting the denom used for indexing (instead of USDC)

and

```
--dex-ex-min-liquidity <DEX_EX_MIN_LIQUIDITY>
            The minimum liquidity for the indexing denom in the dex explorer app view [default:
            100000000]
```
for overriding the minimum liquidity in terms of that asset for a pair
to be considered in the aggregate dex explorer summary.

Closes #4920.

For testing, we can try running this against the testnet with different
values.

## Checklist before requesting a review

- [x] I have added guiding text to explain how a reviewer should test
these changes.

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

  > indexing
  • Loading branch information
cronokirby authored Feb 14, 2025
1 parent 41c9a80 commit 8ef6294
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
5 changes: 3 additions & 2 deletions crates/bin/pindexer/src/dex_ex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ mod summary {
now AS (
SELECT price, liquidity
FROM snapshots
WHERE time >= $3
ORDER BY time ASC
WHERE time <= $3
ORDER BY time DESC
LIMIT 1
),
sums AS (
Expand Down Expand Up @@ -549,6 +549,7 @@ mod summary {
SELECT asset_start as asset, price
FROM dex_ex_pairs_summary
WHERE asset_end = $1
AND liquidity >= $2
UNION VALUES ($1, 1.0)
),
converted_pairs_summary AS (
Expand Down
24 changes: 7 additions & 17 deletions crates/bin/pindexer/src/indexer_ext.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
use std::str::FromStr;

pub trait IndexerExt: Sized {
fn with_default_penumbra_app_views(self) -> Self;
fn with_default_penumbra_app_views(self, options: &crate::Options) -> Self;
}

impl IndexerExt for cometindex::Indexer {
fn with_default_penumbra_app_views(self) -> Self {
fn with_default_penumbra_app_views(self, options: &crate::Options) -> Self {
self.with_index(Box::new(crate::block::Block {}))
.with_index(Box::new(crate::stake::ValidatorSet {}))
.with_index(Box::new(crate::stake::Slashings {}))
.with_index(Box::new(crate::stake::DelegationTxs {}))
.with_index(Box::new(crate::stake::UndelegationTxs {}))
.with_index(Box::new(crate::governance::GovernanceProposals {}))
.with_index(Box::new(crate::dex_ex::Component::new(
penumbra_sdk_asset::asset::Id::from_str(
// USDC
"passet1w6e7fvgxsy6ccy3m8q0eqcuyw6mh3yzqu3uq9h58nu8m8mku359spvulf6",
)
.expect("should be able to parse passet"),
1000.0 * 1_000_000.0,
options.indexing_denom,
options.dex_ex_min_liquidity as f64,
)))
.with_index(Box::new(crate::supply::Component::new()))
.with_index(Box::new(crate::ibc::Component::new()))
.with_index(Box::new(crate::insights::Component::new(
penumbra_sdk_asset::asset::Id::from_str(
// USDC
"passet1w6e7fvgxsy6ccy3m8q0eqcuyw6mh3yzqu3uq9h58nu8m8mku359spvulf6",
)
.ok(),
)))
.with_index(Box::new(crate::insights::Component::new(Some(
options.indexing_denom,
))))
}
}
18 changes: 17 additions & 1 deletion crates/bin/pindexer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pub use cometindex::{opt::Options, AppView, ContextualizedEvent, Indexer, PgPool, PgTransaction};
pub use cometindex::{AppView, ContextualizedEvent, Indexer, PgPool, PgTransaction};

mod indexer_ext;
pub use indexer_ext::IndexerExt;
use penumbra_sdk_asset::asset;
pub mod block;
pub mod dex_ex;
pub mod ibc;
Expand All @@ -11,3 +12,18 @@ pub mod stake;
pub mod supply;

pub mod governance;

#[derive(clap::Parser, Clone, Debug)]
pub struct Options {
#[clap(flatten)]
pub cometindex: cometindex::opt::Options,
/// The denom to use for indexing related components, of the form passet1...
#[clap(
long,
default_value = "passet1w6e7fvgxsy6ccy3m8q0eqcuyw6mh3yzqu3uq9h58nu8m8mku359spvulf6"
)]
pub indexing_denom: asset::Id,
/// The minimum liquidity for the indexing denom in the dex explorer app view.
#[clap(long, default_value = "100000000")]
pub dex_ex_min_liquidity: u128,
}
5 changes: 3 additions & 2 deletions crates/bin/pindexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use pindexer::{Indexer, IndexerExt as _, Options};

#[tokio::main]
async fn main() -> Result<()> {
Indexer::new(Options::parse())
let opts = Options::parse();
Indexer::new(opts.cometindex.clone())
.with_default_tracing()
.with_default_penumbra_app_views()
.with_default_penumbra_app_views(&opts)
.run()
.await?;

Expand Down

0 comments on commit 8ef6294

Please sign in to comment.