Skip to content

Commit

Permalink
Merge pull request #11609 from vegaprotocol/vamm-092
Browse files Browse the repository at this point in the history
feat: add feature tests for vamm with SLA penalty
  • Loading branch information
jeremyletang authored Aug 22, 2024
2 parents 650dc75 + f4ded2a commit 635a7de
Showing 1 changed file with 157 additions and 0 deletions.
157 changes: 157 additions & 0 deletions core/integration/features/amm/0090-VAMM-092.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
Feature: check VAMM when SLA bond penalty is due

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 | 1000 |
| market.liquidity.bondPenaltyParameter | 0.2 |
| market.liquidity.stakeToCcyVolume | 1 |
| market.liquidity.successorLaunchWindowLength | 1h |
| market.liquidity.sla.nonPerformanceBondPenaltySlope | 0.1 |
| market.liquidity.sla.nonPerformanceBondPenaltyMax | 0.6 |
| validators.epoch.length | 10s |
| market.liquidity.earlyExitPenalty | 0.25 |
| market.liquidity.maximumLiquidityFeeFactorLevel | 0.25 |
#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.5 | 0.6 | 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 |

Scenario: set up AMM
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 | 30000 |

When the parties submit the following liquidity provision:
| id | party | market id | commitment amount | fee | lp type |
| lp_1 | lp1 | ETH/MAR22 | 600 | 0.02 | submission |
| lp_2 | lp2 | ETH/MAR22 | 400 | 0.015 | submission |
Then the network moves ahead "4" blocks
And the current epoch is "0"

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 | 10 | 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 |

And the market data for the market "ETH/MAR22" should be:
| mark price | trading mode | target stake | supplied stake | open interest | ref price | mid price | static mid price |
| 100 | TRADING_MODE_CONTINUOUS | 39 | 1000 | 1 | 100 | 100 | 100 |
When the parties submit the following AMM:
| party | market id | amount | slippage | base | lower bound | upper bound | lower leverage | upper leverage | proposed fee |
| vamm1 | ETH/MAR22 | 30000 | 0.1 | 100 | 85 | 150 | 4 | 4 | 0.01 |
Then the AMM pool status should be:
| party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage |
| vamm1 | ETH/MAR22 | 30000 | STATUS_ACTIVE | 100 | 85 | 150 | 4 | 4 |

And set the following AMM sub account aliases:
| party | market id | alias |
| vamm1 | ETH/MAR22 | vamm1-id |
And the following transfers should happen:
| from | from account | to | to account | market id | amount | asset | is amm | type |
| vamm1 | ACCOUNT_TYPE_GENERAL | vamm1-id | ACCOUNT_TYPE_GENERAL | | 30000 | USD | true | TRANSFER_TYPE_AMM_LOW |

Then the parties should have the following account balances:
| party | asset | market id | general |
| 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | USD | ETH/MAR22 | 30000 |

Then the parties should have the following account balances:
| party | asset | market id | margin | general | bond |
| lp1 | USD | ETH/MAR22 | 960 | 998440 | 600 |
| lp2 | USD | ETH/MAR22 | 0 | 999600 | 400 |
| 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | USD | ETH/MAR22 | 0 | 30000 | |

Then the network moves ahead "8" blocks

Then the parties should have the following account balances:
| party | asset | market id | margin | general | bond |
| lp1 | USD | ETH/MAR22 | 960 | 998440 | 540 |
| lp2 | USD | ETH/MAR22 | 0 | 999600 | 360 |
| 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | USD | ETH/MAR22 | 0 | 30000 | |

#0042-LIQF-092:All vAMMs active on a market at the end of an epoch receive SLA bonus rebalancing payments with `0` penalty fraction.
#both lp1 and lp2 got SLA penalty while vamm1 did not
Then the following transfers should happen:
| from | to | from account | to account | market id | amount | asset |
| lp1 | market | ACCOUNT_TYPE_BOND | ACCOUNT_TYPE_INSURANCE | ETH/MAR22 | 60 | USD |
| lp2 | market | ACCOUNT_TYPE_BOND | ACCOUNT_TYPE_INSURANCE | ETH/MAR22 | 40 | USD |

Then the network moves ahead "8" blocks

When the parties cancel the following AMM:
| party | market id | method |
| vamm1 | ETH/MAR22 | METHOD_IMMEDIATE |

Then the parties should have the following account balances:
| party | asset | market id | general |
| vamm1 | USD | ETH/MAR22 | 30000 |

Then the network moves ahead "4" blocks
#0042-LIQF-093:A vAMM active on a market during an epoch, which was cancelled prior to the end of an epoch, receives SLA bonus rebalancing payments with `0` penalty fraction.
#both lp1 and lp2 got SLA penalty while vamm1 did not, and asset has been released from alias back to vamm1
Then the following transfers should happen:
| from | to | from account | to account | market id | amount | asset |
| lp1 | market | ACCOUNT_TYPE_BOND | ACCOUNT_TYPE_INSURANCE | ETH/MAR22 | 54 | USD |
| lp2 | market | ACCOUNT_TYPE_BOND | ACCOUNT_TYPE_INSURANCE | ETH/MAR22 | 36 | USD |

When the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| party4 | ETH/MAR22 | buy | 4 | 120 | 0 | TYPE_LIMIT | TIF_GTC |

#0042-LIQF-094:A vAMMs cancelled in a previous epoch does not receive anything and is not considered during SLA rebalancing at the end of an epoch
Then the network moves ahead "12" blocks

Then the following transfers should happen:
| from | to | from account | to account | market id | amount | asset |
| lp1 | market | ACCOUNT_TYPE_BOND | ACCOUNT_TYPE_INSURANCE | ETH/MAR22 | 48 | USD |
| lp2 | market | ACCOUNT_TYPE_BOND | ACCOUNT_TYPE_INSURANCE | ETH/MAR22 | 32 | USD |

Then the parties should have the following account balances:
| party | asset | market id | general |
| vamm1 | USD | ETH/MAR22 | 30000 |

0 comments on commit 635a7de

Please sign in to comment.