code.vegaprotocol.io/vega@v0.79.0/core/integration/features/amm/0090-VAMM-031.feature (about) 1 Feature: vAMM behaviour when a market settles 2 3 Background: 4 Given the average block duration is "1" 5 And the margin calculator named "margin-calculator-1": 6 | search factor | initial factor | release factor | 7 | 1.2 | 1.5 | 1.7 | 8 And the log normal risk model named "log-normal-risk-model": 9 | risk aversion | tau | mu | r | sigma | 10 | 0.001 | 0.0011407711613050422 | 0 | 0.9 | 3.0 | 11 And the liquidity monitoring parameters: 12 | name | triggering ratio | time window | scaling factor | 13 | lqm-params | 1.00 | 20s | 1 | 14 15 And the following network parameters are set: 16 | name | value | 17 | market.value.windowLength | 60s | 18 | network.markPriceUpdateMaximumFrequency | 0s | 19 | limits.markets.maxPeggedOrders | 6 | 20 | market.auction.minimumDuration | 1 | 21 | market.fee.factors.infrastructureFee | 0.001 | 22 | market.fee.factors.makerFee | 0.004 | 23 | spam.protection.max.stopOrdersPerMarket | 5 | 24 | market.liquidity.equityLikeShareFeeFraction | 1 | 25 | market.amm.minCommitmentQuantum | 1 | 26 | market.liquidity.bondPenaltyParameter | 0.2 | 27 | market.liquidity.stakeToCcyVolume | 1 | 28 | market.liquidity.successorLaunchWindowLength | 1h | 29 | market.liquidity.sla.nonPerformanceBondPenaltySlope | 0.1 | 30 | market.liquidity.sla.nonPerformanceBondPenaltyMax | 0.6 | 31 | validators.epoch.length | 10s | 32 | market.liquidity.earlyExitPenalty | 0.25 | 33 | market.liquidity.maximumLiquidityFeeFactorLevel | 0.25 | 34 #risk factor short:3.5569036 35 #risk factor long:0.801225765 36 And the following assets are registered: 37 | id | decimal places | 38 | USD | 0 | 39 And the fees configuration named "fees-config-1": 40 | maker fee | infrastructure fee | 41 | 0.0004 | 0.001 | 42 43 And the liquidity sla params named "SLA-22": 44 | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor | 45 | 0.5 | 0.6 | 1 | 1.0 | 46 47 And the oracle spec for settlement data filtering data from "0xCAFECAFE" named "ethMar22Oracle": 48 | property | type | binding | 49 | prices.ETH.value | TYPE_INTEGER | settlement data | 50 And the oracle spec for trading termination filtering data from "0xCAFECAFE" named "ethMar22Oracle": 51 | property | type | binding | 52 | trading.terminated | TYPE_BOOLEAN | trading termination | 53 And the settlement data decimals for the oracle named "ethMar22Oracle" is given in "0" decimal places 54 55 And the markets: 56 | 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 | 57 | ETH/MAR22 | USD | USD | lqm-params | log-normal-risk-model | margin-calculator-1 | 2 | fees-config-1 | default-none | ethMar22Oracle | 1e0 | 0 | SLA-22 | 58 59 # Setting up the accounts and vAMM submission now is part of the background, because we'll be running scenarios 0090-VAMM-006 through 0090-VAMM-014 on this setup 60 Given the parties deposit on asset's general account the following amount: 61 | party | asset | amount | 62 | lp1 | USD | 1000000 | 63 | lp2 | USD | 1000000 | 64 | lp3 | USD | 1000000 | 65 | party1 | USD | 1000000 | 66 | party2 | USD | 1000000 | 67 | party3 | USD | 1000000 | 68 | party4 | USD | 1000000 | 69 | party5 | USD | 1000000 | 70 | vamm1 | USD | 30000 | 71 72 When the parties submit the following liquidity provision: 73 | id | party | market id | commitment amount | fee | lp type | 74 | lp_1 | lp1 | ETH/MAR22 | 600 | 0.02 | submission | 75 | lp_2 | lp2 | ETH/MAR22 | 400 | 0.015 | submission | 76 Then the network moves ahead "4" blocks 77 And the current epoch is "0" 78 79 And the parties place the following orders: 80 | party | market id | side | volume | price | resulting trades | type | tif | reference | 81 | lp1 | ETH/MAR22 | buy | 20 | 40 | 0 | TYPE_LIMIT | TIF_GTC | lp1-b | 82 | party5 | ETH/MAR22 | buy | 20 | 90 | 0 | TYPE_LIMIT | TIF_GTC | lp1-b | 83 | party1 | ETH/MAR22 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | | 84 | party2 | ETH/MAR22 | sell | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | | 85 | party3 | ETH/MAR22 | sell | 10 | 110 | 0 | TYPE_LIMIT | TIF_GTC | | 86 | lp1 | ETH/MAR22 | sell | 10 | 160 | 0 | TYPE_LIMIT | TIF_GTC | lp1-s | 87 When the opening auction period ends for market "ETH/MAR22" 88 Then the following trades should be executed: 89 | buyer | price | size | seller | 90 | party1 | 100 | 1 | party2 | 91 92 And the market data for the market "ETH/MAR22" should be: 93 | mark price | trading mode | target stake | supplied stake | open interest | ref price | mid price | static mid price | 94 | 100 | TRADING_MODE_CONTINUOUS | 39 | 1000 | 1 | 100 | 100 | 100 | 95 When the parties submit the following AMM: 96 | party | market id | amount | slippage | base | lower bound | upper bound | lower leverage | upper leverage | proposed fee | 97 | vamm1 | ETH/MAR22 | 30000 | 0.1 | 100 | 85 | 150 | 4 | 4 | 0.01 | 98 Then the AMM pool status should be: 99 | party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage | 100 | vamm1 | ETH/MAR22 | 30000 | STATUS_ACTIVE | 100 | 85 | 150 | 4 | 4 | 101 102 And set the following AMM sub account aliases: 103 | party | market id | alias | 104 | vamm1 | ETH/MAR22 | vamm1-id | 105 And the following transfers should happen: 106 | from | from account | to | to account | market id | amount | asset | is amm | type | 107 | vamm1 | ACCOUNT_TYPE_GENERAL | vamm1-id | ACCOUNT_TYPE_GENERAL | | 30000 | USD | true | TRANSFER_TYPE_AMM_LOW | 108 109 @VAMM 110 Scenario Outline: 0090-VAMM-031: When an AMM is active on a market at time of settlement with a position in a well collateralised state, the market can settle successfully and then all funds on the AMM key are transferred back to the main party's account. 111 When the parties place the following orders: 112 | party | market id | side | volume | price | resulting trades | type | tif | 113 | party4 | ETH/MAR22 | buy | 1 | 105 | 1 | TYPE_LIMIT | TIF_GTC | 114 # see the trades that make the vAMM go short 115 Then the following trades should be executed: 116 | buyer | price | size | seller | is amm | 117 | party4 | 100 | 1 | vamm1-id | true | 118 119 When the network moves ahead "1" blocks 120 Then the market data for the market "ETH/MAR22" should be: 121 | mark price | trading mode | mid price | static mid price | supplied stake | 122 | 100 | TRADING_MODE_CONTINUOUS | 101 | 101 | 1000 | 123 And the parties should have the following profit and loss: 124 | party | volume | unrealised pnl | realised pnl | is amm | 125 | party4 | 1 | 0 | 0 | | 126 | vamm1-id | -1 | 0 | 0 | true | 127 And the AMM pool status should be: 128 | party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage | 129 | vamm1 | ETH/MAR22 | 30000 | STATUS_ACTIVE | 100 | 85 | 150 | 4 | 4 | 130 131 # No terminate && settle the market 132 When the oracles broadcast data signed with "0xCAFECAFE": 133 | name | value | 134 | trading.terminated | true | 135 Then the network moves ahead "1" blocks 136 And the parties should have the following account balances: 137 | party | asset | market id | general | margin | is amm | 138 | vamm1 | USD | | 0 | | | 139 | vamm1-id | USD | ETH/MAR22 | 29791 | 210 | true | 140 141 When the oracles broadcast data signed with "0xCAFECAFE": 142 | name | value | 143 | prices.ETH.value | <settle price> | 144 Then the market state should be "STATE_SETTLED" for the market "ETH/MAR22" 145 And then the network moves ahead "1" blocks 146 147 # verify the that the margin balance is released, and then the correct balance if transferred from the pool account back to the party. 148 And the following transfers should happen: 149 | from | from account | to | to account | market id | amount | asset | is amm | type | 150 | | ACCOUNT_TYPE_FEES_MAKER | vamm1-id | ACCOUNT_TYPE_GENERAL | ETH/MAR22 | 1 | USD | true | TRANSFER_TYPE_MAKER_FEE_RECEIVE | 151 | vamm1-id | ACCOUNT_TYPE_MARGIN | vamm1-id | ACCOUNT_TYPE_GENERAL | ETH/MAR22 | <margin> | USD | true | TRANSFER_TYPE_MARGIN_HIGH | 152 | vamm1-id | ACCOUNT_TYPE_GENERAL | vamm1 | ACCOUNT_TYPE_GENERAL | | <amm balance> | USD | true | TRANSFER_TYPE_AMM_RELEASE | 153 And the parties should have the following account balances: 154 | party | asset | market id | general | margin | is amm | 155 | vamm1 | USD | | <general balance> | | | 156 | vamm1-id | USD | ETH/MAR22 | 0 | 0 | true | 157 158 # Different scenario's involving a final settlement: break even, profit and loss. 159 Examples: 160 | settle price | margin | amm balance | general balance | 161 | 105 | 205 | 29997 | 29997 | # settle price < market price: +1 from fees +1 from final settlement 162 | 107 | 203 | 29995 | 29995 | # settle price > market price: +1 from fees, -1 from final settlement 163 | 104 | 206 | 29998 | 29998 | # settle price < market price: +1 from fees +2 from final settlement 164 | 106 | 204 | 29996 | 29996 | # settle price = market price: +1 from fees 165 | 108 | 202 | 29994 | 29994 | # settle price > market price: +1 from fees, -2 from final settlement