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

services/horizon: Allow filtering accounts by liquidity pool participation. #3873

Merged
merged 14 commits into from
Aug 31, 2021

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Aug 30, 2021

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

  • Amends the API to include liquidity pool details in account balances.
  • Allows only querying accounts participating in a particular liquidity pool (GET /accounts?liquidity_pool=[...some id...]).

Why

Resolves #3832.

Known limitations

Still needs to be tested, hence why it's in draft.

@Shaptic Shaptic requested a review from a team August 30, 2021 21:38
@Shaptic Shaptic self-assigned this Aug 30, 2021
@Shaptic Shaptic added the amm support cap 38 (automated market makers) in horizon label Aug 30, 2021
@Shaptic Shaptic marked this pull request as ready for review August 30, 2021 22:38
While this is technically less defensive, it's still strictly
correct, because it covers all of the possible cases for this
code block: only pool shares / asset4 / asset12 can be a part of
the switch statement.
@@ -366,6 +366,32 @@ func (q *Q) AccountEntriesForSigner(ctx context.Context, signer string, page db2
return results, nil
}

// AccountEntriesForLiquidityPool returns a list of `AccountEntry` rows that
// have trustlines established with a given liquidity pool ID.
func (q *Q) AccountEntriesForLiquidityPool(ctx context.Context, poolId string, page db2.PageQuery) ([]AccountEntry, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we already have AccountsForLiquidityPool(), do we need to add this function?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed in 1b8eeb9.

"native": xdr.AssetTypeAssetTypeNative,
"credit_alphanum4": xdr.AssetTypeAssetTypeCreditAlphanum4,
"credit_alphanum12": xdr.AssetTypeAssetTypeCreditAlphanum12,
"liquidity_pool_shares": xdr.AssetTypeAssetTypePoolShare,
Copy link
Contributor

Choose a reason for hiding this comment

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

AssetTypeMap is used to validate asset query parameters for a bunch of different endpoints in horizon including the trades and path finding endpoints. Not all horizon endpoints should accept pool share asset types. For example pool shares are not transferrable therefore it doesn't make sense to do path payments where the source or destination asset is a pool share.

I think we should treat the endpoints which accept pool shares asset parameters as a special case rather than making all asset parameters validate pool shares as ok

Copy link
Contributor

Choose a reason for hiding this comment

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

I removed it in 1b8eeb9 however I think AssetTypeMap should be a general usage map that's mapping all types. If there are actions that doesn't allow liquidity pools we should probably add an extra validation there. We should probably do it after future net deploy.

Copy link
Contributor

@bartekn bartekn left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Will fix bugs if any in #3868.

@bartekn bartekn merged commit 50e83d4 into stellar:amm Aug 31, 2021
@tamirms
Copy link
Contributor

tamirms commented Aug 31, 2021

thanks @bartekn , looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amm support cap 38 (automated market makers) in horizon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants