-
Notifications
You must be signed in to change notification settings - Fork 14
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
Feat: RPC lp total balances #4951
Conversation
8bc505b
to
7be1a16
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4951 +/- ##
======================================
- Coverage 72% 71% -0%
======================================
Files 434 434
Lines 75556 75583 +27
Branches 75556 75583 +27
======================================
- Hits 54048 53849 -199
- Misses 18660 18867 +207
- Partials 2848 2867 +19 ☔ View full report in Codecov by Sentry. |
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.
otherwise boost stuff looks good, didn't look at the other stuff
Actually, I just realized I am not keeping into account range_orders here! Will update this! |
@@ -389,6 +389,13 @@ macro_rules! assets { | |||
}) | |||
} | |||
} | |||
|
|||
impl scale_info::prelude::ops::Add<AssetMap<crate::AssetAmount>> for AssetMap<crate::AssetAmount> { |
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.
nit: it's a bit strange to import this via scale_info...
impl scale_info::prelude::ops::Add<AssetMap<crate::AssetAmount>> for AssetMap<crate::AssetAmount> { | |
impl core::ops::Add<AssetMap<crate::AssetAmount>> for AssetMap<crate::AssetAmount> { |
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 seem to remember @AlastairHolmes mentioning that LP balances might no be accurately reflected by the pool_orders
method. Might be worth him taking a look too.
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.
Looks fine to me - as mentioned above it's worth @AlastairHolmes taking a look to make sure the pool info is accurate.
The internal state on polkadot.js isn't right, but these functions are correct. |
for ask in pool_orders.limit_orders.asks { | ||
*result.index_mut(base_asset) = result | ||
.index(base_asset) | ||
.saturating_add(ask.sell_amount.saturated_into::<u128>()); |
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.
u128 -> AssetAmount
@@ -389,6 +389,37 @@ macro_rules! assets { | |||
}) | |||
} | |||
} | |||
|
|||
impl<N: sp_arithmetic::traits::Saturating> sp_arithmetic::traits::Saturating for AssetMap<N> { |
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.
🥇
state-chain/custom-rpc/src/lib.rs
Outdated
.map_err(to_rpc_error) | ||
.and_then(|result| { | ||
result | ||
.map(|free_balances| free_balances.map(Into::into)) |
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.
.map(|free_balances| free_balances.map(Into::into)) | |
.map(|total_balances| total_balances.map(Into::into)) |
state-chain/runtime/src/lib.rs
Outdated
@@ -1262,6 +1262,23 @@ impl_runtime_apis! { | |||
fn cf_free_balances(account_id: AccountId) -> Result<AssetMap<AssetAmount>, DispatchErrorWithMessage> { | |||
LiquidityProvider::free_balances(&account_id).map_err(Into::into) | |||
} | |||
fn cf_lp_total_balances(account_id: AccountId) -> Result<AssetMap<AssetAmount>, DispatchErrorWithMessage> { | |||
let free_balances = LiquidityProvider::free_balances(&account_id).map_err(Into::<DispatchErrorWithMessage>::into)?; |
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.
You don't need this map_err and Into, you can just use ?
I believe.
|
||
impl<T: Config<I>, I: 'static> BoostApi for Pallet<T, I> { | ||
type AccountId = T::AccountId; | ||
fn boost_pool_account_balances(who: &Self::AccountId) -> Vec<(Asset, AssetAmount)> { |
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.
This could use AssetMap
, and AssetMap::from_fn
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.
There are maps for each chain
99d3dc3
to
3eedcb4
Compare
addressed the latest comments, PR should be ready now 👍 |
3eedcb4
to
844a437
Compare
…-ccm-checker * origin/wip/solana-api: Feat/solana ccm gas limit (#5048) feat: return early if no client ready on retry limited requests (#5057) feature/PRO-1378/validator-gas-refund (#4962) chore: fix bug in merge that caused tests to fail chore: build binaries on Mac M2 Runner 🍎 (#5005) chore: remove unused spec versioned migration util (#5054) test: update integration tests feat(docker images): add `chainflip-node` probe scripts 🩺 (#5033) Feat: Make FoK constants configurable (#5024) fix: cp .so files to /usr/lib (#5051) chore: run gas_limit test by default fix: allow validators to deregister once they no longer have relevant key material (#5045) Feat: RPC lp total balances (#4951) fix: rpath name on 1.4.5 dylib (#5046) chore: remove cp dylibs from post check (#5044) feat: add primary/secondary label to RPC_RETRIER_TOTAL_REQUESTS metric (#5015) feat: smart retrier endpoint selection (#4984) refactor: move collected network fee to swapping pallet (#5014) feat: consistent broker api address strings (#5030) # Conflicts: # foreign-chains/solana/sol-prim/src/consts.rs # state-chain/chains/src/sol/api.rs # state-chain/pallets/cf-swapping/src/lib.rs # state-chain/pallets/cf-swapping/src/mock.rs # state-chain/runtime/src/lib.rs
Pull Request
Closes: PRO-1418
Checklist
Please conduct a thorough self-review before opening the PR.
Summary
Created a new RPC (cf_lp_total_balances) which exposes the total balances of an LP (free_balances + open_order_balances + boosted_balances)
Non-Breaking changes