New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DEX tasks and endpoints #125
Conversation
c030a86
to
445e88e
Compare
445e88e
to
113a608
Compare
indexer/entity/src/dex_mean_price.rs
Outdated
#[sea_orm(table_name = "DexMeanPrice")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, column_type = "BigInteger")] | ||
pub id: i64, | ||
#[sea_orm(column_type = "BigInteger")] | ||
pub tx_id: i64, | ||
#[sea_orm(column_type = "BigInteger")] | ||
pub address_id: i64, | ||
pub dex: i32, | ||
#[sea_orm(column_type = "BigInteger", nullable)] | ||
pub asset1_id: Option<i64>, | ||
#[sea_orm(column_type = "BigInteger", nullable)] | ||
pub asset2_id: Option<i64>, | ||
#[sea_orm(column_type = "BigUnsigned")] | ||
pub amount1: u64, | ||
#[sea_orm(column_type = "BigUnsigned")] | ||
pub amount2: u64, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the benefit of representing the mean price as a separate table with separate logic instead of a materialized view? Maybe there is a good reason for this, and if so we should write it down somewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We split tables because data represents different approaches. The mean price is the theoretical price for an asset, swap is the real price.
But there is no problem with merging tables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but why can't the theoretical price be a (maybe materialized) view instead merging tables or having separate tables? It'd be nice to outline the tradeoffs and why one is picked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have merged tables and crate views for the webserver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
view removed. Everything is routed from joined tables
01c4f9e
to
d52c25c
Compare
d52c25c
to
095f0ec
Compare
return { | ||
swap: swap.map(result => ({ | ||
tx_hash: result.tx_hash.toString('hex'), | ||
dex: valueToDex(result.dex || '-1'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be careful with using ||
because for example, 0
is falsy in javascript. If you're doing a null-check, it's better to use ??
I mention this here, but this applies to a few places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is only because views return type or null
value.
There is no option that the value will be really null.
7487ff8
to
2cb5ab2
Compare
Store swap from DEXes (WingRiders, MinSwap, SundaeSwap)
Store mean values from DEXes
All assets amounts are without decimal places
Add endpoints
mean price - show the mean price after each exchange.
It is only a ratio between asset amounts (without fees, etc..)
swap price - show all real swap prices
the last price - show the final price from all active DEXes