Skip to content
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

Merged
merged 20 commits into from
Jul 16, 2024
Merged

Feat: RPC lp total balances #4951

merged 20 commits into from
Jul 16, 2024

Conversation

marcellorigotti
Copy link
Contributor

Pull Request

Closes: PRO-1418

Checklist

Please conduct a thorough self-review before opening the PR.

  • I am confident that the code works.
  • I have updated documentation where appropriate.

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

engine-runner-bin/build.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 1.75439% with 168 lines in your changes missing coverage. Please review.

Project coverage is 71%. Comparing base (5db2502) to head (844a437).
Report is 1 commits behind head on main.

Files Patch % Lines
state-chain/primitives/src/chains/assets.rs 0% 67 Missing ⚠️
state-chain/pallets/cf-pools/src/lib.rs 0% 29 Missing ⚠️
state-chain/pallets/cf-ingress-egress/src/lib.rs 0% 22 Missing ⚠️
state-chain/chains/src/benchmarking_value.rs 0% 18 Missing ⚠️
state-chain/custom-rpc/src/lib.rs 0% 15 Missing ⚠️
state-chain/runtime/src/lib.rs 0% 0 Missing and 14 partials ⚠️
state-chain/traits/src/liquidity.rs 0% 3 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@marcellorigotti marcellorigotti changed the title Feature/pro 1418 Feat: RPC lp total balances Jun 11, 2024
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/runtime/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@kylezs kylezs left a 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

@marcellorigotti
Copy link
Contributor Author

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> {
Copy link
Collaborator

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...

Suggested change
impl scale_info::prelude::ops::Add<AssetMap<crate::AssetAmount>> for AssetMap<crate::AssetAmount> {
impl core::ops::Add<AssetMap<crate::AssetAmount>> for AssetMap<crate::AssetAmount> {

Copy link
Collaborator

@dandanlen dandanlen left a 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.

state-chain/traits/src/liquidity.rs Outdated Show resolved Hide resolved
state-chain/traits/src/liquidity.rs Outdated Show resolved Hide resolved
state-chain/primitives/src/chains/assets.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@dandanlen dandanlen left a 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.

state-chain/runtime/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-pools/src/lib.rs Outdated Show resolved Hide resolved
@AlastairHolmes
Copy link
Contributor

AlastairHolmes commented Jun 17, 2024

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.

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

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

Choose a reason for hiding this comment

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

🥇

.map_err(to_rpc_error)
.and_then(|result| {
result
.map(|free_balances| free_balances.map(Into::into))
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
.map(|free_balances| free_balances.map(Into::into))
.map(|total_balances| total_balances.map(Into::into))

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

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

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

Copy link
Contributor

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

@marcellorigotti
Copy link
Contributor Author

addressed the latest comments, PR should be ready now 👍

@marcellorigotti marcellorigotti added this pull request to the merge queue Jul 16, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 16, 2024
@marcellorigotti marcellorigotti added this pull request to the merge queue Jul 16, 2024
Merged via the queue into main with commit bbc7649 Jul 16, 2024
47 checks passed
@marcellorigotti marcellorigotti deleted the feature/pro-1418 branch July 16, 2024 13:11
syan095 added a commit that referenced this pull request Jul 23, 2024
…-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
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