From 377f75807fc8ead0b89b2d3bebd592e5af7998fe Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Mon, 17 Jun 2024 12:29:46 +0100 Subject: [PATCH 1/5] feat: add feature test for 0042-LIQF-109 --- .../features/amm/0042-LIQF-109.feature | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 core/integration/features/amm/0042-LIQF-109.feature diff --git a/core/integration/features/amm/0042-LIQF-109.feature b/core/integration/features/amm/0042-LIQF-109.feature new file mode 100644 index 0000000000..9ac92a8468 --- /dev/null +++ b/core/integration/features/amm/0042-LIQF-109.feature @@ -0,0 +1,143 @@ +Feature: Test vAMM implied commitment is working as expected + + Background: + Given the average block duration is "1" + And the margin calculator named "margin-calculator-1": + | search factor | initial factor | release factor | + | 1.2 | 1.5 | 1.7 | + And the log normal risk model named "log-normal-risk-model": + | risk aversion | tau | mu | r | sigma | + | 0.001 | 0.0011407711613050422 | 0 | 0.9 | 3.0 | + And the liquidity monitoring parameters: + | name | triggering ratio | time window | scaling factor | + | lqm-params | 1.00 | 20s | 1 | + + And the following network parameters are set: + | name | value | + | market.value.windowLength | 60s | + | network.markPriceUpdateMaximumFrequency | 0s | + | limits.markets.maxPeggedOrders | 6 | + | market.auction.minimumDuration | 1 | + | market.fee.factors.infrastructureFee | 0.001 | + | market.fee.factors.makerFee | 0.004 | + | spam.protection.max.stopOrdersPerMarket | 5 | + | market.liquidity.equityLikeShareFeeFraction | 1 | + | market.amm.minCommitmentQuantum | 1 | + | market.liquidity.bondPenaltyParameter | 0.2 | + | market.liquidity.stakeToCcyVolume | 1 | + | market.liquidity.successorLaunchWindowLength | 1h | + | market.liquidity.sla.nonPerformanceBondPenaltySlope | 0 | + | market.liquidity.sla.nonPerformanceBondPenaltyMax | 0.6 | + | validators.epoch.length | 10s | + | market.liquidity.earlyExitPenalty | 0.25 | + | market.liquidity.maximumLiquidityFeeFactorLevel | 0.25 | + | market.liquidity.providersFeeCalculationTimeStep | 9s | + #risk factor short:3.5569036 + #risk factor long:0.801225765 + And the following assets are registered: + | id | decimal places | + | USD | 0 | + And the fees configuration named "fees-config-1": + | maker fee | infrastructure fee | + | 0.0004 | 0.001 | + + And the liquidity sla params named "SLA-22": + | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor | + | 0.05 | 1 | 1 | 1.0 | + + And the markets: + | id | quote name | asset | liquidity monitoring | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | + | ETH/MAR22 | USD | USD | lqm-params | log-normal-risk-model | margin-calculator-1 | 2 | fees-config-1 | default-none | default-eth-for-future | 1e0 | 0 | SLA-22 | + + Given the parties deposit on asset's general account the following amount: + | party | asset | amount | + | lp1 | USD | 1000000 | + | lp2 | USD | 1000000 | + | lp3 | USD | 1000000 | + | party1 | USD | 1000000 | + | party2 | USD | 1000000 | + | party3 | USD | 1000000 | + | party4 | USD | 1000000 | + | party5 | USD | 1000000 | + | vamm1 | USD | 1000000 | + | vamm2 | USD | 1000000 | + + When the parties submit the following liquidity provision: + | id | party | market id | commitment amount | fee | lp type | + | lp_1 | lp1 | ETH/MAR22 | 10000 | 0.02 | submission | + | lp_2 | lp2 | ETH/MAR22 | 10000 | 0.02 | submission | + + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | reference | + | lp1 | ETH/MAR22 | buy | 20 | 40 | 0 | TYPE_LIMIT | TIF_GTC | lp1-b | + | party1 | ETH/MAR22 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | | + | party2 | ETH/MAR22 | sell | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | | + | lp1 | ETH/MAR22 | sell | 20 | 160 | 0 | TYPE_LIMIT | TIF_GTC | lp1-s | + + When the opening auction period ends for market "ETH/MAR22" + Then the following trades should be executed: + | buyer | price | size | seller | + | party1 | 100 | 1 | party2 | + + Then the network moves ahead "1" epochs + And the current epoch is "1" + + @VAMM + Scenario: 0042-LIQF-109: A vAMM which was active on the market with an average of `10000` liquidity units (`price * volume`) provided for half the epoch, and then `0` for the second half of the epoch (as the price was out of the vAMM's configured range), and where the `market.liquidity.stakeToCcyVolume` value is `100`, will have an implied commitment of `50`. + + #first check the virtual stake if vamm1 provide AMM within SLA range for the whole epoch + Then the parties submit the following AMM: + | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | + | vamm1 | ETH/MAR22 | 10000 | 0.05 | 100 | 98 | 102 | 0.03 | + Then the AMM pool status should be: + | party | market id | amount | status | base | lower bound | upper bound | + | vamm1 | ETH/MAR22 | 10000 | STATUS_ACTIVE | 100 | 98 | 102 | + + And set the following AMM sub account aliases: + | party | market id | alias | + | vamm1 | ETH/MAR22 | vamm-party | + + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | reference | + | party1 | ETH/MAR22 | buy | 10 | 100 | 0 | TYPE_LIMIT | TIF_GTC | lp1-b | + | party2 | ETH/MAR22 | sell | 10 | 100 | 1 | TYPE_LIMIT | TIF_GTC | | + + Then the network moves ahead "1" epochs + + And the liquidity provider fee shares for the market "ETH/MAR22" should be: + | party | equity like share | virtual stake | average entry valuation | + | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 4669.0000000000000000 | 24669 | + + + Scenario: 0042-LIQF-109 + #now check the virtual stake if vamm1 only provide AMM within SLA range for the first half of the epoch + Then the parties submit the following AMM: + | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | + | vamm1 | ETH/MAR22 | 10000 | 0.05 | 100 | 98 | 102 | 0.03 | + Then the AMM pool status should be: + | party | market id | amount | status | base | lower bound | upper bound | + | vamm1 | ETH/MAR22 | 10000 | STATUS_ACTIVE | 100 | 98 | 102 | + + And set the following AMM sub account aliases: + | party | market id | alias | + | vamm1 | ETH/MAR22 | vamm-party | + + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | reference | + | party1 | ETH/MAR22 | buy | 10 | 100 | 0 | TYPE_LIMIT | TIF_GTC | lp1-b | + | party2 | ETH/MAR22 | sell | 10 | 100 | 1 | TYPE_LIMIT | TIF_GTC | | + + Then the network moves ahead "5" blocks + + When the parties amend the following AMM: + | party | market id | slippage | base | lower bound | upper bound | lower leverage | upper leverage | + | vamm1 | ETH/MAR22 | 0.1 | 120 | 115 | 125 | 0.25 | 0.25 | + Then the AMM pool status should be: + | party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage | + | vamm1 | ETH/MAR22 | 10000 | STATUS_ACTIVE | 120 | 115 | 125 | 0.25 | 0.25 | + + Then the network moves ahead "7" blocks + + And the liquidity provider fee shares for the market "ETH/MAR22" should be: + | party | equity like share | virtual stake | average entry valuation | + | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 3502.0000000000000000 | 23502 | From bb46a876a6de19387ec83bd88aadff9809e7b443 Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Mon, 17 Jun 2024 12:38:14 +0100 Subject: [PATCH 2/5] feat: update virtual stake --- core/integration/features/amm/0042-LIQF-109.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/integration/features/amm/0042-LIQF-109.feature b/core/integration/features/amm/0042-LIQF-109.feature index 9ac92a8468..3b0d95c42e 100644 --- a/core/integration/features/amm/0042-LIQF-109.feature +++ b/core/integration/features/amm/0042-LIQF-109.feature @@ -127,7 +127,7 @@ Feature: Test vAMM implied commitment is working as expected | party1 | ETH/MAR22 | buy | 10 | 100 | 0 | TYPE_LIMIT | TIF_GTC | lp1-b | | party2 | ETH/MAR22 | sell | 10 | 100 | 1 | TYPE_LIMIT | TIF_GTC | | - Then the network moves ahead "5" blocks + Then the network moves ahead "4" blocks When the parties amend the following AMM: | party | market id | slippage | base | lower bound | upper bound | lower leverage | upper leverage | @@ -136,8 +136,8 @@ Feature: Test vAMM implied commitment is working as expected | party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage | | vamm1 | ETH/MAR22 | 10000 | STATUS_ACTIVE | 120 | 115 | 125 | 0.25 | 0.25 | - Then the network moves ahead "7" blocks + Then the network moves ahead "8" blocks And the liquidity provider fee shares for the market "ETH/MAR22" should be: | party | equity like share | virtual stake | average entry valuation | - | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 3502.0000000000000000 | 23502 | + | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 3268.0000000000000000 | 23268 | From c2656206f8d5f79fa1c8fecb302c1812af095b4c Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Mon, 17 Jun 2024 15:59:48 +0100 Subject: [PATCH 3/5] feat: add FT for AC 0042-LIQF-111 --- .../features/amm/0042-LIQF-109.feature | 80 +++++++++++++++++-- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/core/integration/features/amm/0042-LIQF-109.feature b/core/integration/features/amm/0042-LIQF-109.feature index 3b0d95c42e..b3af0ca034 100644 --- a/core/integration/features/amm/0042-LIQF-109.feature +++ b/core/integration/features/amm/0042-LIQF-109.feature @@ -108,9 +108,41 @@ Feature: Test vAMM implied commitment is working as expected | party | equity like share | virtual stake | average entry valuation | | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 4669.0000000000000000 | 24669 | + Scenario: 0042-LIQF-109 + #now check the virtual stake if vamm1 only provide AMM within SLA range for the first half of the epoch, and second half is lower AMM only + Then the parties submit the following AMM: + | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | + | vamm1 | ETH/MAR22 | 10000 | 0.05 | 100 | 98 | 102 | 0.03 | + Then the AMM pool status should be: + | party | market id | amount | status | base | lower bound | upper bound | + | vamm1 | ETH/MAR22 | 10000 | STATUS_ACTIVE | 100 | 98 | 102 | + + And set the following AMM sub account aliases: + | party | market id | alias | + | vamm1 | ETH/MAR22 | vamm-party | + + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | reference | + | party1 | ETH/MAR22 | buy | 10 | 100 | 0 | TYPE_LIMIT | TIF_GTC | lp1-b | + | party2 | ETH/MAR22 | sell | 10 | 100 | 1 | TYPE_LIMIT | TIF_GTC | | + + Then the network moves ahead "5" blocks + + When the parties amend the following AMM: + | party | market id | slippage | base | lower bound | upper bound | lower leverage | upper leverage | + | vamm1 | ETH/MAR22 | 0.1 | 100 | 90 | | 0.25 | 0.25 | + Then the AMM pool status should be: + | party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage | + | vamm1 | ETH/MAR22 | 10000 | STATUS_ACTIVE | 100 | 90 | | 0.25 | 0.25 | + + Then the network moves ahead "7" blocks + + And the liquidity provider fee shares for the market "ETH/MAR22" should be: + | party | equity like share | virtual stake | average entry valuation | + | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 2334.0000000000000000 | 22334 | Scenario: 0042-LIQF-109 - #now check the virtual stake if vamm1 only provide AMM within SLA range for the first half of the epoch + #now check the virtual stake if vamm1 only provide AMM within SLA range for the first half of the epoch, and second half is outside SLA range Then the parties submit the following AMM: | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | | vamm1 | ETH/MAR22 | 10000 | 0.05 | 100 | 98 | 102 | 0.03 | @@ -127,17 +159,53 @@ Feature: Test vAMM implied commitment is working as expected | party1 | ETH/MAR22 | buy | 10 | 100 | 0 | TYPE_LIMIT | TIF_GTC | lp1-b | | party2 | ETH/MAR22 | sell | 10 | 100 | 1 | TYPE_LIMIT | TIF_GTC | | - Then the network moves ahead "4" blocks + Then the network moves ahead "5" blocks When the parties amend the following AMM: | party | market id | slippage | base | lower bound | upper bound | lower leverage | upper leverage | - | vamm1 | ETH/MAR22 | 0.1 | 120 | 115 | 125 | 0.25 | 0.25 | + | vamm1 | ETH/MAR22 | 0.1 | 100 | 80 | 115 | 0.25 | 0.25 | Then the AMM pool status should be: | party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage | - | vamm1 | ETH/MAR22 | 10000 | STATUS_ACTIVE | 120 | 115 | 125 | 0.25 | 0.25 | + | vamm1 | ETH/MAR22 | 10000 | STATUS_ACTIVE | 100 | 80 | 115 | 0.25 | 0.25 | - Then the network moves ahead "8" blocks + Then the network moves ahead "7" blocks And the liquidity provider fee shares for the market "ETH/MAR22" should be: | party | equity like share | virtual stake | average entry valuation | - | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 3268.0000000000000000 | 23268 | + | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 2625.0000000000000000 | 22625 | + + + Scenario: 0042-LIQF-111:A vAMM which was active on the market with an average of `10000` liquidity units (`price * volume`) provided for half the epoch, and then `5000` for the second half of the epoch (as the price was out of the vAMM's configured range), and where the `market.liquidity.stakeToCcyVolume` value is `100`, will have an implied commitment of `75`. + + Then the parties submit the following AMM: + | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | + | vamm1 | ETH/MAR22 | 10000 | 0.05 | 100 | 98 | 102 | 0.03 | + Then the AMM pool status should be: + | party | market id | amount | status | base | lower bound | upper bound | + | vamm1 | ETH/MAR22 | 10000 | STATUS_ACTIVE | 100 | 98 | 102 | + + And set the following AMM sub account aliases: + | party | market id | alias | + | vamm1 | ETH/MAR22 | vamm-party | + + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | reference | + | party1 | ETH/MAR22 | buy | 10 | 100 | 0 | TYPE_LIMIT | TIF_GTC | lp1-b | + | party2 | ETH/MAR22 | sell | 10 | 100 | 1 | TYPE_LIMIT | TIF_GTC | | + + Then the network moves ahead "5" blocks + + When the parties amend the following AMM: + | party | market id | amount | slippage | base | lower bound | upper bound | lower leverage | upper leverage | + | vamm1 | ETH/MAR22 | 5000 | 0.1 | 100 | 98 | 102 | 0.25 | 0.25 | + Then the AMM pool status should be: + | party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage | + | vamm1 | ETH/MAR22 | 5000 | STATUS_ACTIVE | 100 | 98 | 102 | 0.25 | 0.25 | + + Then the network moves ahead "7" blocks + + And the liquidity provider fee shares for the market "ETH/MAR22" should be: + | party | equity like share | virtual stake | average entry valuation | + | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 2925.0000000000000000 | 22925 | + + From b6103d5b145b48182045c0044345d6cc2006c4db Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Tue, 18 Jun 2024 10:27:59 +0100 Subject: [PATCH 4/5] feat: update AMM for AC 111 --- core/integration/features/amm/0042-LIQF-109.feature | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/integration/features/amm/0042-LIQF-109.feature b/core/integration/features/amm/0042-LIQF-109.feature index b3af0ca034..e28b700937 100644 --- a/core/integration/features/amm/0042-LIQF-109.feature +++ b/core/integration/features/amm/0042-LIQF-109.feature @@ -170,6 +170,8 @@ Feature: Test vAMM implied commitment is working as expected Then the network moves ahead "7" blocks + # Then debug trades + And the liquidity provider fee shares for the market "ETH/MAR22" should be: | party | equity like share | virtual stake | average entry valuation | | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 2625.0000000000000000 | 22625 | @@ -196,16 +198,17 @@ Feature: Test vAMM implied commitment is working as expected Then the network moves ahead "5" blocks When the parties amend the following AMM: - | party | market id | amount | slippage | base | lower bound | upper bound | lower leverage | upper leverage | - | vamm1 | ETH/MAR22 | 5000 | 0.1 | 100 | 98 | 102 | 0.25 | 0.25 | + | party | market id | amount | slippage | base | lower bound | upper bound | + | vamm1 | ETH/MAR22 | 5000 | 0.05 | 100 | 98 | 102 | Then the AMM pool status should be: - | party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage | - | vamm1 | ETH/MAR22 | 5000 | STATUS_ACTIVE | 100 | 98 | 102 | 0.25 | 0.25 | + | party | market id | amount | status | base | lower bound | upper bound | + | vamm1 | ETH/MAR22 | 5000 | STATUS_ACTIVE | 100 | 98 | 102 | Then the network moves ahead "7" blocks + #virtual stake is 75% * 4669 = 3501 And the liquidity provider fee shares for the market "ETH/MAR22" should be: | party | equity like share | virtual stake | average entry valuation | - | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 2925.0000000000000000 | 22925 | + | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 3501.0000000000000000 | 23501 | From bd371af1ccafb54c28b743e7966b58cc603da9d0 Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Tue, 18 Jun 2024 10:32:49 +0100 Subject: [PATCH 5/5] chore: tidy up --- core/integration/features/amm/0042-LIQF-109.feature | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/core/integration/features/amm/0042-LIQF-109.feature b/core/integration/features/amm/0042-LIQF-109.feature index e28b700937..83efe38c86 100644 --- a/core/integration/features/amm/0042-LIQF-109.feature +++ b/core/integration/features/amm/0042-LIQF-109.feature @@ -84,7 +84,6 @@ Feature: Test vAMM implied commitment is working as expected @VAMM Scenario: 0042-LIQF-109: A vAMM which was active on the market with an average of `10000` liquidity units (`price * volume`) provided for half the epoch, and then `0` for the second half of the epoch (as the price was out of the vAMM's configured range), and where the `market.liquidity.stakeToCcyVolume` value is `100`, will have an implied commitment of `50`. - #first check the virtual stake if vamm1 provide AMM within SLA range for the whole epoch Then the parties submit the following AMM: | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | @@ -140,7 +139,8 @@ Feature: Test vAMM implied commitment is working as expected And the liquidity provider fee shares for the market "ETH/MAR22" should be: | party | equity like share | virtual stake | average entry valuation | | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 2334.0000000000000000 | 22334 | - + + @VAMM Scenario: 0042-LIQF-109 #now check the virtual stake if vamm1 only provide AMM within SLA range for the first half of the epoch, and second half is outside SLA range Then the parties submit the following AMM: @@ -170,15 +170,12 @@ Feature: Test vAMM implied commitment is working as expected Then the network moves ahead "7" blocks - # Then debug trades - And the liquidity provider fee shares for the market "ETH/MAR22" should be: | party | equity like share | virtual stake | average entry valuation | | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 2625.0000000000000000 | 22625 | - - + + @VAMM Scenario: 0042-LIQF-111:A vAMM which was active on the market with an average of `10000` liquidity units (`price * volume`) provided for half the epoch, and then `5000` for the second half of the epoch (as the price was out of the vAMM's configured range), and where the `market.liquidity.stakeToCcyVolume` value is `100`, will have an implied commitment of `75`. - Then the parties submit the following AMM: | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | | vamm1 | ETH/MAR22 | 10000 | 0.05 | 100 | 98 | 102 | 0.03 |