code.vegaprotocol.io/vega@v0.79.0/core/integration/features/amm/0090-VAMM-035.feature (about) 1 Feature: With two vAMMs existing on the market, and no other orders, both of which have the same fair price, another counterparty placing a large buy order for a given volume, followed by a large sell order for the same volume, results in the vAMMs both taking a position and then returning to 0 position, with a balance increase equal to the maker fees received plus those for the incoming trader crossing the spread. 2 3 Background: 4 Given the average block duration is "1" 5 And the following network parameters are set: 6 | name | value | 7 | market.value.windowLength | 60s | 8 | validators.epoch.length | 10s | 9 | market.value.windowLength | 60s | 10 | network.markPriceUpdateMaximumFrequency | 2s | 11 | limits.markets.maxPeggedOrders | 6 | 12 | market.auction.minimumDuration | 1 | 13 | market.fee.factors.infrastructureFee | 0.001 | 14 | market.fee.factors.makerFee | 0.004 | 15 | spam.protection.max.stopOrdersPerMarket | 5 | 16 | market.liquidity.equityLikeShareFeeFraction | 1 | 17 | market.amm.minCommitmentQuantum | 1 | 18 | market.liquidity.bondPenaltyParameter | 0.2 | 19 | market.liquidity.stakeToCcyVolume | 1 | 20 | market.liquidity.successorLaunchWindowLength | 1h | 21 | market.liquidity.sla.nonPerformanceBondPenaltySlope | 0.1 | 22 | market.liquidity.sla.nonPerformanceBondPenaltyMax | 0.6 | 23 | validators.epoch.length | 10s | 24 | market.liquidity.earlyExitPenalty | 0.25 | 25 | market.liquidity.maximumLiquidityFeeFactorLevel | 0.25 | 26 27 And the following assets are registered: 28 | id | decimal places | 29 | USD | 0 | 30 And the fees configuration named "fees-config-1": 31 | maker fee | infrastructure fee | 32 | 0.0004 | 0.001 | 33 And the markets: 34 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | 35 | ETH/MAR22 | USD | USD | default-log-normal-risk-model | default-margin-calculator | 2 | fees-config-1 | default-none | default-eth-for-future | 1e0 | 0 | default-basic | 36 37 @VAMM 38 Scenario: Double-sided vAMMs 39 Given the parties deposit on asset's general account the following amount: 40 | party | asset | amount | 41 | party1 | USD | 100000 | 42 | party2 | USD | 100000 | 43 | party3 | USD | 100000 | 44 | vamm1 | USD | 100000 | 45 | vamm2 | USD | 100000 | 46 47 When the parties place the following orders: 48 | party | market id | side | volume | price | resulting trades | type | tif | 49 | party1 | ETH/MAR22 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 50 | party1 | ETH/MAR22 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | 51 | party2 | ETH/MAR22 | sell | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | 52 | party2 | ETH/MAR22 | sell | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 53 And the opening auction period ends for market "ETH/MAR22" 54 Then the following trades should be executed: 55 | buyer | price | size | seller | 56 | party1 | 100 | 1 | party2 | 57 And the market data for the market "ETH/MAR22" should be: 58 | mark price | trading mode | 59 | 100 | TRADING_MODE_CONTINUOUS | 60 61 When the parties submit the following AMM: 62 | party | market id | amount | slippage | base | lower bound | upper bound | lower leverage | upper leverage | proposed fee | 63 | vamm1 | ETH/MAR22 | 50000 | 0.1 | 100 | 85 | 115 | 0.25 | 0.3 | 0.01 | 64 | vamm2 | ETH/MAR22 | 100000 | 0.1 | 100 | 85 | 115 | 0.25 | 0.3 | 0.012 | 65 Then the AMM pool status should be: 66 | party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage | 67 | vamm1 | ETH/MAR22 | 50000 | STATUS_ACTIVE | 100 | 85 | 115 | 0.25 | 0.3 | 68 | vamm2 | ETH/MAR22 | 100000 | STATUS_ACTIVE | 100 | 85 | 115 | 0.25 | 0.3 | 69 And set the following AMM sub account aliases: 70 | party | market id | alias | 71 | vamm1 | ETH/MAR22 | vamm1-acc | 72 | vamm2 | ETH/MAR22 | vamm2-acc | 73 And the following transfers should happen: 74 | from | from account | to | to account | market id | amount | asset | is amm | type | 75 | vamm1 | ACCOUNT_TYPE_GENERAL | vamm1-acc | ACCOUNT_TYPE_GENERAL | | 50000 | USD | true | TRANSFER_TYPE_AMM_LOW | 76 | vamm2 | ACCOUNT_TYPE_GENERAL | vamm2-acc | ACCOUNT_TYPE_GENERAL | | 100000 | USD | true | TRANSFER_TYPE_AMM_LOW | 77 78 Then the parties should have the following account balances: 79 | party | asset | market id | margin | general | vesting | vested | 80 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | USD | ETH/MAR22 | 0 | 50000 | | | 81 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | USD | ETH/MAR22 | 0 | 100000 | | | 82 83 When the network moves ahead "11" blocks 84 Then the current epoch is "0" 85 86 When the parties place the following orders: 87 | party | market id | side | volume | price | resulting trades | type | tif | 88 | party1 | ETH/MAR22 | buy | 100 | 0 | 2 | TYPE_MARKET | TIF_FOK | 89 Then the following trades should be executed: 90 | buyer | price | size | seller | 91 | party1 | 101 | 34 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 92 | party1 | 101 | 66 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | 93 94 When the network moves ahead "2" blocks 95 And the parties should have the following profit and loss: 96 | party | volume | unrealised pnl | realised pnl | 97 | party1 | 101 | 1 | 0 | 98 | party2 | -1 | -1 | 0 | 99 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | -34 | 0 | 0 | 100 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | -66 | 0 | 0 | 101 102 When the parties place the following orders: 103 | party | market id | side | volume | price | resulting trades | type | tif | 104 | party2 | ETH/MAR22 | sell | 100 | 0 | 2 | TYPE_MARKET | TIF_FOK | 105 Then debug trades 106 Then the following trades should be executed: 107 | buyer | price | size | seller | 108 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 101 | 34 | party2 | 109 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | 101 | 66 | party2 | 110 111 When the network moves ahead "2" blocks 112 And the parties should have the following profit and loss: 113 | party | volume | unrealised pnl | realised pnl | 114 | party1 | 101 | 1 | 0 | 115 | party2 | -101 | -1 | 0 | 116 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 0 | 0 | 117 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | 0 | 0 | 0 | 118 119 Then the parties should have the following account balances: 120 | party | asset | market id | margin | general | vesting | vested | 121 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | USD | ETH/MAR22 | 0 | 50028 | | | 122 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | USD | ETH/MAR22 | 0 | 100054 | | | 123 124 Scenario: Single-sided vAMMs 125 Given the parties deposit on asset's general account the following amount: 126 | party | asset | amount | 127 | party1 | USD | 100000 | 128 | party2 | USD | 100000 | 129 | party3 | USD | 100000 | 130 | vamm1 | USD | 100000 | 131 | vamm2 | USD | 100000 | 132 133 When the parties place the following orders: 134 | party | market id | side | volume | price | resulting trades | type | tif | 135 | party1 | ETH/MAR22 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 136 | party1 | ETH/MAR22 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | 137 | party2 | ETH/MAR22 | sell | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | 138 | party2 | ETH/MAR22 | sell | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 139 And the opening auction period ends for market "ETH/MAR22" 140 Then the following trades should be executed: 141 | buyer | price | size | seller | 142 | party1 | 100 | 1 | party2 | 143 And the market data for the market "ETH/MAR22" should be: 144 | mark price | trading mode | 145 | 100 | TRADING_MODE_CONTINUOUS | 146 147 When the parties submit the following AMM: 148 | party | market id | amount | slippage | base | lower bound | upper bound | lower leverage | upper leverage | proposed fee | 149 | vamm1 | ETH/MAR22 | 50000 | 0.1 | 100 | | 115 | | 0.3 | 0.01 | 150 | vamm2 | ETH/MAR22 | 100000 | 0.1 | 100 | | 115 | | 0.3 | 0.012 | 151 Then the AMM pool status should be: 152 | party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage | 153 | vamm1 | ETH/MAR22 | 50000 | STATUS_ACTIVE | 100 | | 115 | | 0.3 | 154 | vamm2 | ETH/MAR22 | 100000 | STATUS_ACTIVE | 100 | | 115 | | 0.3 | 155 And set the following AMM sub account aliases: 156 | party | market id | alias | 157 | vamm1 | ETH/MAR22 | vamm1-acc | 158 | vamm2 | ETH/MAR22 | vamm2-acc | 159 And the following transfers should happen: 160 | from | from account | to | to account | market id | amount | asset | is amm | type | 161 | vamm1 | ACCOUNT_TYPE_GENERAL | vamm1-acc | ACCOUNT_TYPE_GENERAL | | 50000 | USD | true | TRANSFER_TYPE_AMM_LOW | 162 | vamm2 | ACCOUNT_TYPE_GENERAL | vamm2-acc | ACCOUNT_TYPE_GENERAL | | 100000 | USD | true | TRANSFER_TYPE_AMM_LOW | 163 164 Then the parties should have the following account balances: 165 | party | asset | market id | margin | general | vesting | vested | 166 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | USD | ETH/MAR22 | 0 | 50000 | | | 167 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | USD | ETH/MAR22 | 0 | 100000 | | | 168 169 When the network moves ahead "11" blocks 170 Then the current epoch is "0" 171 172 When the parties place the following orders: 173 | party | market id | side | volume | price | resulting trades | type | tif | 174 | party1 | ETH/MAR22 | buy | 100 | 0 | 2 | TYPE_MARKET | TIF_FOK | 175 Then the following trades should be executed: 176 | buyer | price | size | seller | 177 | party1 | 101 | 34 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 178 | party1 | 101 | 66 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | 179 180 When the network moves ahead "2" blocks 181 And the parties should have the following profit and loss: 182 | party | volume | unrealised pnl | realised pnl | 183 | party1 | 101 | 1 | 0 | 184 | party2 | -1 | -1 | 0 | 185 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | -34 | 0 | 0 | 186 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | -66 | 0 | 0 | 187 188 When the parties place the following orders: 189 | party | market id | side | volume | price | resulting trades | type | tif | 190 | party2 | ETH/MAR22 | sell | 100 | 0 | 2 | TYPE_MARKET | TIF_FOK | 191 Then debug trades 192 Then the following trades should be executed: 193 | buyer | price | size | seller | 194 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 101 | 34 | party2 | 195 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | 101 | 66 | party2 | 196 197 When the network moves ahead "2" blocks 198 And the parties should have the following profit and loss: 199 | party | volume | unrealised pnl | realised pnl | 200 | party1 | 101 | 1 | 0 | 201 | party2 | -101 | -1 | 0 | 202 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 0 | 0 | 203 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | 0 | 0 | 0 | 204 205 Then the parties should have the following account balances: 206 | party | asset | market id | margin | general | vesting | vested | 207 | 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | USD | ETH/MAR22 | 0 | 50028 | | | 208 | 4582953f1f1dd07603befe97994d6414c0ebb53c7d52c29e866bb3e85d7b30b4 | USD | ETH/MAR22 | 0 | 100054 | | |