Skip to content

Commit

Permalink
Merge pull request #11115 from vegaprotocol/0042-LIQF-even-more
Browse files Browse the repository at this point in the history
chore: 0042-LIQF-069 0042-LIQF-070 0042-LIQF-071
  • Loading branch information
wwestgarth authored Apr 15, 2024
2 parents 52b1372 + 2b3dc9f commit cd22c8f
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ Feature: Test liquidity provider reward distribution; Should also cover liquidit
Given the simple risk model named "simple-risk-model-1":
| long | short | max move up | min move down | probability of trading |
| 0.1 | 0.1 | 500 | 500 | 0.1 |
And the fees configuration named "fees-config-1":
| maker fee | infrastructure fee |
| 0.0004 | 0.001 |
And the price monitoring named "price-monitoring":
| horizon | probability | auction extension |
| 1 | 0.99 | 3 |
And the fees configuration named "fees-config-1":
| maker fee | infrastructure fee | liquidity fee method | liquidity fee constant |
| 0.0004 | 0.001 | METHOD_CONSTANT | 0.08 |
And the fees configuration named "fees-config-2":
| maker fee | infrastructure fee | liquidity fee method | liquidity fee constant |
| 0.0004 | 0.001 | METHOD_CONSTANT | 0.01 |
And the fees configuration named "fees-config-3":
| maker fee | infrastructure fee | liquidity fee method | liquidity fee constant |
| 0.0004 | 0.001 | METHOD_WEIGHTED_AVERAGE | 0.01 |
And the fees configuration named "fees-config-4":
| maker fee | infrastructure fee | liquidity fee method | liquidity fee constant |
| 0.0004 | 0.001 | METHOD_MARGINAL_COST | 0.01 |


Given the following assets are registered:
| id | decimal places |
Expand All @@ -36,7 +46,7 @@ Feature: Test liquidity provider reward distribution; Should also cover liquidit

And the spot markets:
| id | name | base asset | quote asset | risk model | auction duration | fees | price monitoring | sla params | liquidity monitoring |
| BTC/ETH | BTC/ETH | BTC | ETH | simple-risk-model-1 | 2 | fees-config-1 | price-monitoring | SLA | lqm-params |
| BTC/ETH | BTC/ETH | BTC | ETH | simple-risk-model-1 | 2 | fees-config-4 | price-monitoring | SLA | lqm-params |

Given the average block duration is "1"

Expand Down Expand Up @@ -250,4 +260,87 @@ Feature: Test liquidity provider reward distribution; Should also cover liquidit
Then the liquidity fee factor should be "0.002" for the market "BTC/ETH"

When the network moves ahead "1" blocks
Then the liquidity fee factor should be "0.001" for the market "BTC/ETH"
Then the liquidity fee factor should be "0.001" for the market "BTC/ETH"

Scenario: 004 Liquidity fee setting to METHOD_CONSTANT(0042-LIQF-070), METHOD_MARGINAL_COST (0042-LIQF-071), and METHOD_WEIGHTED_AVERAGE(0042-LIQF-069)
# setup accounts
Given the parties deposit on asset's general account the following amount:
| party | asset | amount |
| lp1 | BTC | 1000000000 |
| lp2 | BTC | 1000000000 |
| party1 | BTC | 100000000 |
| party2 | BTC | 100000000 |
| lp1 | ETH | 1000000000 |
| lp2 | ETH | 1000000000 |
| party1 | ETH | 100000000 |
| party2 | ETH | 100000000 |

And the parties submit the following liquidity provision:
| id | party | market id | commitment amount | fee | lp type |
| lp1 | lp1 | BTC/ETH | 800 | 0.005 | submission |
| lp2 | lp2 | BTC/ETH | 300 | 0.004 | submission |

And the parties place the following pegged iceberg orders:
| party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
| lp1 | BTC/ETH | 12 | 1 | buy | BID | 12 | 2 |
| lp1 | BTC/ETH | 12 | 1 | buy | MID | 12 | 1 |
| lp1 | BTC/ETH | 12 | 1 | sell | ASK | 12 | 2 |
| lp1 | BTC/ETH | 12 | 1 | sell | MID | 12 | 1 |

When the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| party1 | BTC/ETH | buy | 1 | 900 | 0 | TYPE_LIMIT | TIF_GTC |
| party1 | BTC/ETH | buy | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | BTC/ETH | sell | 1 | 1100 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | BTC/ETH | sell | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |

Then the opening auction period ends for market "BTC/ETH"

# update to method constant value 0.08 (0042-LIQF-070)
When the spot markets are updated:
| id | liquidity monitoring | linear slippage factor | quadratic slippage factor | liquidity fee settings |
| BTC/ETH | lqm-params | 1e-3 | 0 | fees-config-1 |

When the network moves ahead "1" blocks

And the following trades should be executed:
| buyer | price | size | seller |
| party1 | 1000 | 10 | party2 |

And the market data for the market "BTC/ETH" should be:
| mark price | trading mode | min bound | max bound | target stake | supplied stake |
| 1000 | TRADING_MODE_CONTINUOUS | 500 | 1500 | 825 | 1100 |

And the liquidity fee factor should be "0.08" for the market "BTC/ETH"


# update to constant 0.01
When the spot markets are updated:
| id | liquidity monitoring | linear slippage factor | quadratic slippage factor | liquidity fee settings |
| BTC/ETH | lqm-params | 1e-3 | 0 | fees-config-2 |
Then the network moves ahead "2" blocks
And the liquidity fee factor should be "0.01" for the market "BTC/ETH"

# update to weighted average (0042-LIQF-069)
When the spot markets are updated:
| id | liquidity monitoring | linear slippage factor | quadratic slippage factor | liquidity fee settings |
| BTC/ETH | lqm-params | 1e-3 | 0 | fees-config-3 |
Then the network moves ahead "1" blocks
And the liquidity fee factor should be "0.0047272727272727" for the market "BTC/ETH"

When the parties submit the following liquidity provision:
| id | party | market id | commitment amount | fee | lp type |
| lp1 | lp1 | BTC/ETH | 800 | 0.006 | amendment |
Then the network moves ahead "1" blocks
And the liquidity fee factor should be "0.0054545454545455" for the market "BTC/ETH"

# update to marginal cost (0042-LIQF-071)
When the spot markets are updated:
| id | liquidity monitoring | linear slippage factor | quadratic slippage factor | liquidity fee settings |
| BTC/ETH | lqm-params | 1e-3 | 0 | fees-config-4 |

When the parties submit the following liquidity provision:
| id | party | market id | commitment amount | fee | lp type |
| lp1 | lp1 | BTC/ETH | 800 | 0.0375 | amendment |
Then the network moves ahead "1" blocks
And the liquidity fee factor should be "0.0375" for the market "BTC/ETH"
19 changes: 19 additions & 0 deletions core/integration/steps/the_spot_markets.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ func spotMarketUpdate(config *market.Config, existing *types.Market, row spotMar
update.Changes.SLAParams = types.LiquiditySLAParamsFromProto(slaParams)
}

update.Changes.LiquidityFeeSettings = existing.Fees.LiquidityFeeSettings
if liquidityFeeSettings, ok := row.tryLiquidityFeeSettings(); ok {
settings, err := config.FeesConfig.Get(liquidityFeeSettings)
if err != nil {
panic(err)
}
s := types.LiquidityFeeSettingsFromProto(settings.LiquidityFeeSettings)
existing.Fees.LiquidityFeeSettings = s
update.Changes.LiquidityFeeSettings = s
}

// risk model
if rm, ok := row.riskModel(); ok {
tip := existing.TradableInstrument.IntoProto()
Expand Down Expand Up @@ -394,6 +405,14 @@ func (r spotMarketUpdateRow) liquidityMonitoring() (string, bool) {
return "", false
}

func (r spotMarketUpdateRow) tryLiquidityFeeSettings() (string, bool) {
if r.row.HasColumn("liquidity fee settings") {
s := r.row.MustStr("liquidity fee settings")
return s, true
}
return "", false
}

func (r spotMarketUpdateRow) slaParams() (string, bool) {
if r.row.HasColumn("sla params") {
lm := r.row.MustStr("sla params")
Expand Down

0 comments on commit cd22c8f

Please sign in to comment.