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

exp/orderbook: Expand path payment algorithm to search liquidity pools. #3921

Merged
merged 47 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6b65325
Add a way to simulate exchanging calculation on LPs
Shaptic Sep 2, 2021
620af03
Implement liquidity pool exchange calculation with math/bits
Shaptic Sep 7, 2021
e4caa3c
Add a way to predict LP exchange needs
Shaptic Sep 15, 2021
3582a6c
Drop unused methods from graph
Shaptic Sep 14, 2021
0ac3d51
Introduce TradeOpportunity interface for both offers + LPs
Shaptic Sep 9, 2021
17605af
TDD to allow searching through liquidity pools
Shaptic Sep 14, 2021
13194a6
Stop specifying buy/sell asset in `tradingPair` for LPs
Shaptic Sep 14, 2021
aa16c9b
Attempting to get DFS to path through LPs correctly
Shaptic Sep 15, 2021
06cce56
Add a LP path payment test that actually passes :o
Shaptic Sep 15, 2021
aeaf69c
Amend DFS to pass in non-LP cases
Shaptic Sep 15, 2021
732674e
Drop the TradeOpportunity usage on edgeSet
Shaptic Sep 15, 2021
a968a58
Iterate through interleaved set of LPs/offers
Shaptic Sep 15, 2021
3ccf4e5
Avoid LP loops by tracking visited IDs
Shaptic Sep 15, 2021
22be276
Make creating the graph a little more ergonomic
Shaptic Sep 16, 2021
ddfe215
Rename: 'trade opportunity' to 'venue' to match CAP lingo
Shaptic Sep 16, 2021
752ae91
Drop edges() method entirely
Shaptic Sep 16, 2021
e248380
Store a mapping of assets to pools for efficient graph exploration
Shaptic Sep 16, 2021
28e66b2
Add new test case with more LPs and non-linear ratios
Shaptic Sep 16, 2021
d9c0e25
Break apart test cases into sub-tests
Shaptic Sep 16, 2021
73ee3d2
Store LP IDs in a set for faster lookups
Shaptic Sep 16, 2021
5365179
Drop more unused methods
Shaptic Sep 16, 2021
9424081
Split benchmarks, simplify test code
Shaptic Sep 16, 2021
0378123
Add test for interleaving LPs and offers
Shaptic Sep 17, 2021
bbc1b53
Drop debugging code
Shaptic Sep 17, 2021
742d564
Drop unused vars
Shaptic Sep 17, 2021
7eeb915
Various comment clarifications, etc. for easier reviewing
Shaptic Sep 17, 2021
3e54345
Speed up path-finding by avoiding edges to visited nodes (#3933)
tamirms Sep 17, 2021
331cbe9
Fix mocking on renamed method
Shaptic Sep 18, 2021
4b769f0
Move venue processing into consumeOffers
Shaptic Sep 20, 2021
f03dc0a
Clean up test cases and add FixedPath test skeleton
Shaptic Sep 21, 2021
c627663
Abstract out processVenues into a state-agnostic helper function and …
Shaptic Sep 21, 2021
497dcb9
Merge branch 'amm' into trade-opportunities
Shaptic Sep 21, 2021
d55da0a
Drop duplicate function, likely from bad merge
Shaptic Sep 21, 2021
91bda35
Integrate venues deeper into the graph for performance
Shaptic Sep 22, 2021
39c53a0
Update ingestion to match new function signature
Shaptic Sep 22, 2021
77bbd86
Drop various debugging bits, add clarifying comments
Shaptic Sep 22, 2021
831c908
Integrate pool batch processing deeper into the graph
Shaptic Sep 24, 2021
345cfad
Slightly refactor path collection code for readability
Shaptic Sep 24, 2021
67e6464
Fix / add test cases and stop a full error if no venues (it isn't one)
Shaptic Sep 24, 2021
08d7d02
Add changelog entry
Shaptic Sep 24, 2021
5f366f1
Make pool errors constant to make them easier to compare against
Shaptic Sep 24, 2021
176405b
Simplify some test cases to use testify's assertions
Shaptic Sep 24, 2021
cd60906
Refactor the interface to avoid the awkward `chooseVenue()` method.
Shaptic Sep 24, 2021
29c63c1
Just do a normal positiveMin / regular max without generalizing
Shaptic Sep 27, 2021
dc735b3
Merge branch 'amm' into trade-opportunities
Shaptic Sep 27, 2021
49c81a6
Drop the 'no venues' error for simpler logic
Shaptic Sep 27, 2021
89a9288
Update mocks to match new method signatures
Shaptic Sep 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions exp/orderbook/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ const (
)

type orderBookOperation struct {
operationType int
offerID xdr.Int64
offer *xdr.OfferEntry
liquidityPoolAssets tradingPair
liquidityPool *xdr.LiquidityPoolEntry
operationType int
offerID xdr.Int64
offer *xdr.OfferEntry
liquidityPool *xdr.LiquidityPoolEntry
}

type orderBookBatchedUpdates struct {
Expand All @@ -44,15 +43,10 @@ func (tx *orderBookBatchedUpdates) addOffer(offer xdr.OfferEntry) *orderBookBatc
}

// addLiquidityPool will queue an operation to add the given liquidity pool to the order book graph
func (tx *orderBookBatchedUpdates) addLiquidityPool(liquidityPool xdr.LiquidityPoolEntry) *orderBookBatchedUpdates {
params := liquidityPool.Body.MustConstantProduct().Params
func (tx *orderBookBatchedUpdates) addLiquidityPool(pool xdr.LiquidityPoolEntry) *orderBookBatchedUpdates {
tx.operations = append(tx.operations, orderBookOperation{
operationType: addLiquidityPoolOperationType,
liquidityPool: &liquidityPool,
liquidityPoolAssets: tradingPair{
buyingAsset: params.AssetA.String(),
sellingAsset: params.AssetB.String(),
},
liquidityPool: &pool,
})

return tx
Expand All @@ -69,10 +63,10 @@ func (tx *orderBookBatchedUpdates) removeOffer(offerID xdr.Int64) *orderBookBatc
}

// removeLiquidityPool will queue an operation to remove the given liquidity pool from the order book
func (tx *orderBookBatchedUpdates) removeLiquidityPool(liquidityPoolAssets tradingPair) *orderBookBatchedUpdates {
func (tx *orderBookBatchedUpdates) removeLiquidityPool(pool xdr.LiquidityPoolEntry) *orderBookBatchedUpdates {
tx.operations = append(tx.operations, orderBookOperation{
operationType: removeLiquidityPoolOperationType,
liquidityPoolAssets: liquidityPoolAssets,
operationType: removeLiquidityPoolOperationType,
liquidityPool: &pool,
})

return tx
Expand All @@ -96,23 +90,23 @@ func (tx *orderBookBatchedUpdates) apply(ledger uint32) error {
for _, operation := range tx.operations {
switch operation.operationType {
case addOfferOperationType:
if err := tx.orderbook.add(*operation.offer); err != nil {
if err := tx.orderbook.addOffer(*operation.offer); err != nil {
panic(errors.Wrap(err, "could not apply update in batch"))
}
case removeOfferOperationType:
if _, ok := tx.orderbook.tradingPairForOffer[operation.offerID]; !ok {
continue
}
if err := tx.orderbook.remove(operation.offerID); err != nil {
if err := tx.orderbook.removeOffer(operation.offerID); err != nil {
panic(errors.Wrap(err, "could not apply update in batch"))
}

case addLiquidityPoolOperationType:
tx.orderbook.liquidityPools[operation.liquidityPoolAssets] = *operation.liquidityPool
tx.orderbook.addPool(*operation.liquidityPool)

case removeLiquidityPoolOperationType:
if _, ok := tx.orderbook.liquidityPools[operation.liquidityPoolAssets]; !ok {
panic(errors.New("liquidity pool not present in orderbook graph"))
}
delete(tx.orderbook.liquidityPools, operation.liquidityPoolAssets)
tx.orderbook.removePool(*operation.liquidityPool)

default:
panic(errors.New("invalid operation type"))
}
Expand Down
Loading