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: new lp interface (PRO-760 PRO-743 PRO-686) #3886

Merged
merged 52 commits into from
Sep 5, 2023

Conversation

AlastairHolmes
Copy link
Contributor

@AlastairHolmes AlastairHolmes commented Aug 23, 2023

Replaces the burn and mint functions with update and set position functions and adds order ids.

  • "set" removes all liquidity associated with a order id and adds back specified amount (optionally changing the tick/tick range associated with the order id).
  • "update" will increase or decrease the amount of liquidity associated with a order id (and optionally move the existing liquidity to a new tick/tick range).

Bouncer has not yet being updated to use the new functions and so will fail.

I have removed some existing rpcs, I intend to replace them with improved versions.

Also need to add auto sweeping although this is not hard any longer.

@AlastairHolmes AlastairHolmes requested a review from a team as a code owner August 23, 2023 12:58
@AlastairHolmes AlastairHolmes requested review from niklasnatter, zoheb391, kylezs and martin-chainflip and removed request for a team August 23, 2023 12:58
@codecov
Copy link

codecov bot commented Aug 23, 2023

Codecov Report

Merging #3886 (33081bb) into main (a5205b9) will decrease coverage by 0%.
Report is 2 commits behind head on main.
The diff coverage is 52%.

@@          Coverage Diff           @@
##            main   #3886    +/-   ##
======================================
- Coverage     73%     72%    -0%     
======================================
  Files        367     366     -1     
  Lines      56037   56698   +661     
  Branches   56037   56698   +661     
======================================
+ Hits       40631   40855   +224     
- Misses     13345   13757   +412     
- Partials    2061    2086    +25     
Files Changed Coverage Δ
api/lib/src/lp.rs 0% <0%> (ø)
api/lib/src/queries.rs 0% <ø> (ø)
state-chain/custom-rpc/src/lib.rs 0% <0%> (ø)
state-chain/pallets/cf-pools/src/weights.rs 0% <0%> (ø)
state-chain/traits/src/liquidity.rs 62% <0%> (ø)
state-chain/runtime/src/lib.rs 39% <14%> (-1%) ⬇️
state-chain/amm/src/common.rs 88% <32%> (-9%) ⬇️
state-chain/pallets/cf-pools/src/lib.rs 51% <47%> (-13%) ⬇️
state-chain/amm/src/lib.rs 54% <50%> (-11%) ⬇️
state-chain/amm/src/range_orders.rs 83% <66%> (-5%) ⬇️
... and 10 more

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -105,7 +297,7 @@ pub mod pallet {
/// The STABLE_ASSET is always PoolSide::Asset1
Copy link
Contributor

Choose a reason for hiding this comment

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

This is no longer true, but will show up as the documentation for this storage item.

@AlastairHolmes AlastairHolmes enabled auto-merge (squash) September 4, 2023 09:07
@AlastairHolmes AlastairHolmes changed the title feat: new lp interface feat: new lp interface (PRO-760 PRO-743 PRO-686) Sep 4, 2023
@linear
Copy link

linear bot commented Sep 4, 2023

PRO-760 Check range order before burn

Now that we have getRangeOrders, we can re-implement the check that makes sure we have the required liquidity before sending the burn extrinsic.

Also we need to fix a mistake where the burn_range_order function is using AssetAmount instead of Liquidity.

PRO-686 [LP-API] `burn_all_limit_orders` and `burn_all_range_orders`

It should be possible for an LP to burn all their orders instead of having to explicitly burn each one.

PRO-743 Move LP queries into runtime rpc

We should move anything that accesses storage directly (via StorageApi) in the LP api into a dedicated rpc endpoint in the node, and access the state via these runtime rpc calls.

As part of this, we should use dedicated rpc return types instead of defining serialize/deserialize on the amm's Pool types.

@AlastairHolmes AlastairHolmes merged commit 2fd4893 into main Sep 5, 2023
@AlastairHolmes AlastairHolmes deleted the feat/new-lp-interface branch September 5, 2023 09:47
dandanlen pushed a commit that referenced this pull request Sep 6, 2023
* Revert "feat: RPC call for amount_to_liquidity (#3835)"

This reverts commit dbfe96a.

* rename collected structures

* Add PositionInfo

squash

* cut out inner_liquidity_to_amounts

squash

squash

* cut out inner_amounts_to_liquidity

* amm range orders mint and burn by Size

* output operation liquidity delta

* remove unneeded trait impls

* move sqrt_price_to_price

* current_price rpc

* add nicer swap and position functions

* remove pool rpcs

* remove deser and ser impls

* amm pool new function

* current_price doesn't use traits

* make private/hide unneeded interfaces

* pub amount in PositionInfo

* cutout error translation functions

* desired -> maximum

* rename RangeOrderSize to OldRangeOrderSize

* new interfaces

* new implementations

* handle order ids

* spelling and add safe mode checks

* update bouncer for new lp-interface

* bouncer linting

* fix range_order bouncer command

* bouncer linting

* lp api returns

* required asset ratio rpc

* lp rpc

* Use "order" not "position"

* use u256

* utilities

squash

squash

* use new utilities

* pools function

pool_info and pools functions

* pool_orders

* pool_range_order_liquidity_value

* rpcs

* _asset

* fix

* move debit down

* bought_amount

* LiquidityTooLarge

* remove old test

* remove range_order iszero check

* basic comments

---------

Co-authored-by: Roy Yang <roy@chainflip.io>
Co-authored-by: Martin Rieke <martin@chainflip.io>
dandanlen pushed a commit that referenced this pull request Sep 6, 2023
* Revert "feat: RPC call for amount_to_liquidity (#3835)"

This reverts commit dbfe96a.

* rename collected structures

* Add PositionInfo

squash

* cut out inner_liquidity_to_amounts

squash

squash

* cut out inner_amounts_to_liquidity

* amm range orders mint and burn by Size

* output operation liquidity delta

* remove unneeded trait impls

* move sqrt_price_to_price

* current_price rpc

* add nicer swap and position functions

* remove pool rpcs

* remove deser and ser impls

* amm pool new function

* current_price doesn't use traits

* make private/hide unneeded interfaces

* pub amount in PositionInfo

* cutout error translation functions

* desired -> maximum

* rename RangeOrderSize to OldRangeOrderSize

* new interfaces

* new implementations

* handle order ids

* spelling and add safe mode checks

* update bouncer for new lp-interface

* bouncer linting

* fix range_order bouncer command

* bouncer linting

* lp api returns

* required asset ratio rpc

* lp rpc

* Use "order" not "position"

* use u256

* utilities

squash

squash

* use new utilities

* pools function

pool_info and pools functions

* pool_orders

* pool_range_order_liquidity_value

* rpcs

* _asset

* fix

* move debit down

* bought_amount

* LiquidityTooLarge

* remove old test

* remove range_order iszero check

* basic comments

---------

Co-authored-by: Roy Yang <roy@chainflip.io>
Co-authored-by: Martin Rieke <martin@chainflip.io>
syan095 added a commit that referenced this pull request Sep 8, 2023
…on-integration

* origin/main:
  fix: scale encoding skip phantom data (#3967)
  chore: make platform team code owner of CI settings.toml and localnet (#3957)
  fix: prefer finalize_signed_extrinsic in engine (#3956)
  fix: CanonicalAssetPair encoding issue (#3958)
  chore(bouncer): Update sdk to 0.0.40 (#3945)
  fix: tweak cli generate-keys output (#3943)
  chore: add `preinst` script unit tests 🧪 (#3942)
  Better LP/Broker API RPC Errors (#3931)
  fix: update substrate ref to use Kademlia fix (#3941)
  doc: update funding readme with redemption restrictions (#3914)
  feat: PRO-474 broadcast safe mode (#3902)
  feat: more forgiving dot address parsing (#3938)
  fix: duplicate logging (#3939)
  feat: new lp interface (#3886)

# Conflicts:
#	Cargo.lock
#	state-chain/cf-integration-tests/Cargo.toml
#	state-chain/cf-integration-tests/src/authorities.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.

5 participants