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

Support for automated market makers (CAP-38). #693

Merged
merged 20 commits into from
Sep 2, 2021
Merged

Support for automated market makers (CAP-38). #693

merged 20 commits into from
Sep 2, 2021

Conversation

marcelosalloum
Copy link
Contributor

@marcelosalloum marcelosalloum commented Aug 31, 2021

This release adds support for Automated Market Makers. For details, you can refer to CAP-38 for XDR changes and this document for detailed changes to the Horizon API.

Add

  • Introduced a LiquidityPoolCallBuilder to make calls to a new endpoint:

    • /liquidity_pools[?reserves=...] - a collection of liquidity pools, optionally filtered by one or more assets (#682)
    • /liquidity_pools/:id - a specific liquidity pool (#687)
  • Expanded the TransactionCallBuilder, OperationCallBuilder, and EffectsCallBuilders to apply to specific liquidity pools (#689). This corresponds to the following new endpoints:

    • /liquidity_pools/:id/transactions
    • /liquidity_pools/:id/operations
    • /liquidity_pools/:id/effects
  • Expanded the TradesCallBuilder to support fetching liquidity pool trades and accepts a new trade_type filter (#685):

    • /trades?trade_type={orderbook,liquidity_pools}
    • A liquidity pool trade contains the following fields:
      • liquidity_pool_fee_bp: LP fee expressed in basis points, and either
      • base_liquidity_pool_id or counter_liquidity_pool_id
  • Added new effects related to liquidity pools (#690):

    • DepositLiquidityEffect
    • WithdrawLiquidityEffect
    • LiquidityPoolTradeEffect
    • LiquidityPoolCreatedEffect
    • LiquidityPoolRemovedEffect
    • LiquidityPoolRevokedEffect
  • Added new responses related to liquidity pool operations (#692):

    • DepositLiquidityOperationResponse
    • WithdrawLiquidityOperationResponse

Updates

  • Updated the underlying stellar-base library to v6.0.1 to include CAP-38 changes (#681).

  • Updated AccountResponse to include liquidity pool shares in its balances field (#688).

  • Updated AccountCallBuilder to allow filtering based on participation in a certain liquidity pool (#688), corresponding to the following new filter:

    • /accounts?reserves=[...list of assets...]
  • Updated RevokeSponsorshipOperationResponse to contain an optional attribute trustline_liquidity_pool_id, for when a liquidity pool trustline is revoked (#690).

Breaking changes

  • A TradeRecord can now correspond to two different types of trades and has changed (#685):

    • Orderbook (the existing structure)
      • counter_offer_id and base_offer_id only show up in these records
    • LiquidityPool (new)
      • base_account xor counter_account will appear in these records
    • price fields changed from numbers to strings
    • The links to base and counter can now point to either an account or a liquidity pool
  • An account's balances array can now include a new type (#688):

    • asset_type can now be liquidity_pool_shares
    • The following fields are not included in pool share balances:
      • buying_liabilities
      • selling_liabilities
      • asset_code
      • asset_issue
  • The ChangeTrustOperationResponse has changed (#688, #692):

    • asset_type can now be liquidity_pool_shares
    • asset_code, asset_issuer, and trustee are now optional
    • liquidity_pool_id is a new optional field
  • The trustline effects (TrustlineCreated, TrustlineUpdated, TrustlineRevoked) have changed (#690):

    • the asset type can now be liquidity_pool_shares
    • they can optionally include a liquidity_pool_id
  • Trustline sponsorship effects (TrustlineSponsorshipCreated, TrustlineSponsorshipUpdated, TrustlineSponsorshipRemoved) have been updated (#690):

    • the asset field is now optional, and is replaced by
    • the liquidity_pool_id field for liquidity pools

marcelosalloum and others added 12 commits August 26, 2021 12:53
…ce `/lib` is in stellar-base's `.gitignore`, yarn install doesn't work properly with the github module version and we need to run an extra step manually, as explained in the CHANGELOG.
* Add call builder for liquidity pools, w/ filters by reserve asset
### What

Add GitHub Actions to run tests for every PR.

### Why

So all AMM related PRs we're merging into [v9.0.0](https://github.com/stellar/js-stellar-sdk/tree/v9.0.0) will need to pass the CI tests.
…ounts balance response (#688)

Support `/accounts?liquidity_pool={:pool_id}` and update the response from `/accounts/{:acc_id}`

### Update

- A new type of trustline called `liquidity_pool_shares` was added, which is included in the account `balances` array and causes a breaking change (see below) ([#688](#688)).
- Clients can now filter the results from the `/accounts` endpoint based on participation in a certain liquidity pool ([#688](#688)).

### Breaking Changes

- The `balances` array from an account response now supports liquidity pool balances ([#688](#688)).
  - the `asset_type` field can now be `liquidity_pool_shares`.
  - `buying_liabilities`, `selling_liabilities`, `asset_code`, and `asset_issuer` are omitted from the response for pool shares because they are not relevant to liquidity pools.
- Update the `ChangeTrustOperationResponse` interface so it can conform to a change in a liquidity pool trustline ([#688](#688)).
  - `asset_type` can now be `liquidity_pool_shares`.
  - `asset_code` and `asset_issuer` are now optional.
  - Added `liquidity_pool_id` as an optional field.
… pool. (#689)

Co-authored-by: Marcelo Salloum dos Santos <marcelo@stellar.org>
### Add

- New effect types: `DepositLiquidityEffect`, `WithdrawLiquidityEffect`, `LiquidityPoolTradeEffect`, `LiquidityPoolCreatedEffect`, `LiquidityPoolRemovedEffect` and `LiquidityPoolRevokedEffect`.

### Breaking changes

- Trustline created/updated/revoked effects' asset type can now be `liquidity_pool_shares`.
- Trustline sponsorship effects have been updated so the `asset` becomes optional and is replaced with `liquidity_pool_id` for liquidity pools.
### Add

- Add operations `DepositLiquidityOperationResponse` and `WithdrawLiquidityOperationResponse`.

### Breaking Changes

- The `trustee` attribute was made optional in the `ChangeTrustOperationResponse`.
Shaptic and others added 2 commits August 31, 2021 15:02
* Provides more precise error type
One of my biggest take-aways from Google's technical writing course
was "use more lists." I've tried to incorporate that here, breaking
down changes into specific items.

Another big change was being more specific and precise with the
data structures in the SDK that have been updated. For example, we
now list the effects that changed directly, specify fields that
have changed more explicitly, and call out specific endpoints that
we've introduced and their respective call builders.

Co-authored-by: Marcelo Salloum dos Santos <marcelo@stellar.org>
@Shaptic Shaptic marked this pull request as ready for review August 31, 2021 22:05
@Shaptic Shaptic changed the title [v9.0.0] Update SDK to include CAP-38 definitions and the new version of stellar-base [v9.0.0] Release support for automated market makers (CAP-38). Aug 31, 2021
@Shaptic Shaptic requested a review from a team September 1, 2021 01:57
@Shaptic Shaptic mentioned this pull request Sep 1, 2021
14 tasks
@Shaptic Shaptic linked an issue Sep 1, 2021 that may be closed by this pull request
14 tasks
@Shaptic Shaptic added the amm label Sep 1, 2021
Copy link
Contributor

@paulbellamy paulbellamy left a comment

Choose a reason for hiding this comment

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

Just a quick look, but seems fine to me.

Shaptic and others added 3 commits September 2, 2021 09:08
* Update payment call builder to use helper method
* Update two more builders to use helper
* Simplify sequence number code since strings are strings

Co-authored-by: Marcelo Salloum dos Santos <marcelo@stellar.org>
Co-authored-by: Marcelo Salloum dos Santos <marcelo@stellar.org>
@Shaptic Shaptic changed the title [v9.0.0] Release support for automated market makers (CAP-38). Support for automated market makers (CAP-38). Sep 2, 2021
src/effect_call_builder.ts Outdated Show resolved Hide resolved
last_modified_ledger: number;
is_authorized: boolean;
is_authorized_to_maintain_liabilities: boolean;
is_clawback_enabled: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

a pool share trustline can be sponsored so I think we need a sponsor?: string here

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch, will be fixed by #702 👍

src/server_api.ts Outdated Show resolved Hide resolved
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

src/server.ts Show resolved Hide resolved
src/transaction_call_builder.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@tamirms tamirms left a comment

Choose a reason for hiding this comment

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

looks great! I left a few comments for some issues which should be easy to fix

* Add sponsor field to pool share balances
* Refactor ledger filter to always convert to a string
* Drop the Horizon-deprecated offer_id field
@Shaptic Shaptic merged commit e924deb into master Sep 2, 2021
@Shaptic Shaptic deleted the v9.0.0 branch September 2, 2021 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Liquidity Pool JS SDK Updates
5 participants