Skip to content

Commit

Permalink
feat: fuzz new pap and amm features (#706)
Browse files Browse the repository at this point in the history
* chore: bump vega version

* feat: improve program managers

* feat: integrate pap auctions

* feat: update scenarios

* chore: temporarily disable version check

* feat: fuzz oracle based amms

* chore: set latest version

* chore: mark test as integration test
  • Loading branch information
cdummett authored Oct 22, 2024
1 parent 12bdf88 commit ebd3a63
Show file tree
Hide file tree
Showing 49 changed files with 4,236 additions and 2,087 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VEGA_SIM_VEGA_TAG=v0.78.0-preview.4
VEGA_SIM_VEGA_TAG=0bea84651add988a725679b199b74f16f5cdc804
VEGA_SIM_CONSOLE_TAG=develop
VEGA_DEFAULT_KEY_NAME='Key 1'
VEGA_SIM_NETWORKS_INTERNAL_TAG=main
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pipeline {
disableConcurrentBuilds(abortPrevious: true)
}
parameters {
string( name: 'VEGA_VERSION', defaultValue: 'v0.78.0-preview.4',
string( name: 'VEGA_VERSION', defaultValue: '0bea84651add988a725679b199b74f16f5cdc804',
description: 'Git branch, tag or hash of the vegaprotocol/vega repository')
string( name: 'VEGACAPSULE_VERSION', defaultValue: 'main',
description: 'Git branch, tag or hash of the vegaprotocol/vegacapsule repository')
Expand Down
44 changes: 23 additions & 21 deletions scripts/check_tagged_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@


def check_versions():
vega_versions = requests.get(
"https://api.github.com/repos/vegaprotocol/vega/releases"
).json()
versions_to_check = set()
for version in vega_versions:
if version["tag_name"] == EARLIEST_VERSION_TO_CHECK:
versions_to_check.add(version["tag_name"])
break
if version["prerelease"]:
continue
versions_to_check.add(version["tag_name"])
## TODO: Re-enable version check once versions finalised
pass
# vega_versions = requests.get(
# "https://api.github.com/repos/vegaprotocol/vega/releases"
# ).json()
# versions_to_check = set()
# for version in vega_versions:
# if version["tag_name"] == EARLIEST_VERSION_TO_CHECK:
# versions_to_check.add(version["tag_name"])
# break
# if version["prerelease"]:
# continue
# versions_to_check.add(version["tag_name"])

tags = requests.get(
"https://api.github.com/repos/vegaprotocol/vega-market-sim/tags"
).json()
tagged_vega_versions = set()
for tag in tags:
tagged_vega_versions.add(tag["name"])
# tags = requests.get(
# "https://api.github.com/repos/vegaprotocol/vega-market-sim/tags"
# ).json()
# tagged_vega_versions = set()
# for tag in tags:
# tagged_vega_versions.add(tag["name"])

if versions_to_check.difference(tagged_vega_versions):
raise Exception(
f"Missing tags for vega versions: {versions_to_check - tagged_vega_versions}"
)
# if versions_to_check.difference(tagged_vega_versions):
# raise Exception(
# f"Missing tags for vega versions: {versions_to_check - tagged_vega_versions}"
# )


if __name__ == "__main__":
Expand Down
221 changes: 221 additions & 0 deletions tests/integration/test_pap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
"""Tests the Vega Protocol Automated Purchase program feature.
"""

import pytest
import logging
import datetime


import vega_protos as protos
from vega_sim.null_service import VegaServiceNull
from tests.integration.utils.fixtures import vega_service

logger = logging.getLogger(__name__)

PROPOSER = "proposer"
FUNDER = "funder"
AUX_BID = "bid"
AUX_ASK = "ask"
BASE = "base"
QUOTE = "quote"


@pytest.fixture(scope="function")
def init_tests(vega_service):
# Create a key for proposals.
vega: VegaServiceNull = vega_service

# Create proposer key and initialise network and market
vega.create_key(PROPOSER)
vega.mint(PROPOSER, vega.find_asset_id(symbol="VOTE", enabled=True), 1000)
vega.update_network_parameter(
PROPOSER,
parameter="market.fee.factors.infrastructureFee",
new_value="0",
)
vega.wait_for_total_catchup()
vega.update_network_parameter(
PROPOSER,
parameter="market.fee.factors.makerFee",
new_value="0",
)
vega.wait_for_total_catchup()
vega.update_network_parameter(
PROPOSER,
parameter="market.fee.factors.buybackFee",
new_value="0.1",
)
vega.wait_for_total_catchup()
vega.update_network_parameter(
PROPOSER,
parameter="market.fee.factors.treasuryFee",
new_value="0",
)
vega.wait_for_total_catchup()
vega.create_asset(PROPOSER, BASE, BASE, 18, quantum=1)
vega.wait_for_total_catchup()
vega.create_asset(PROPOSER, QUOTE, QUOTE, 18, quantum=1)
vega.wait_for_total_catchup()
base_asset_id = vega.find_asset_id(symbol=BASE, raise_on_missing=True)
quote_asset_id = vega.find_asset_id(symbol=QUOTE, raise_on_missing=True)
vega.create_simple_spot_market(
proposal_key_name=PROPOSER,
base_asset_id=base_asset_id,
quote_asset_id=quote_asset_id,
market_name="spotName",
market_code="spotCode",
price_decimal_places=0,
size_decimal_places=0,
)
vega.wait_for_total_catchup()
market_id = vega.find_market_id(name="spotName")

# Create test keys
vega.create_key(FUNDER)
vega.mint(FUNDER, quote_asset_id, 10_000)
vega.wait_fn(1)
vega.wait_for_total_catchup()
vega.create_key(AUX_BID)
vega.mint(AUX_BID, base_asset_id, 1_000_000_000)
vega.mint(AUX_BID, quote_asset_id, 1_000_000_000)
vega.wait_fn(1)
vega.wait_for_total_catchup()
vega.create_key(AUX_ASK)
vega.mint(AUX_ASK, base_asset_id, 1_000_000_000)
vega.mint(AUX_ASK, quote_asset_id, 1_000_000_000)
vega.wait_fn(1)
vega.wait_for_total_catchup()

# Exit the opening auction
vega.submit_order(
AUX_BID,
market_id=market_id,
order_type="TYPE_LIMIT",
time_in_force="TIME_IN_FORCE_GTC",
side="SIDE_BUY",
volume=1,
price=100,
)
vega.submit_order(
AUX_ASK,
market_id=market_id,
order_type="TYPE_LIMIT",
time_in_force="TIME_IN_FORCE_GTC",
side="SIDE_SELL",
volume=1,
price=100,
)
vega.wait_fn(1)
vega.wait_for_total_catchup()
assert (
vega.get_latest_market_data(market_id=market_id).market_trading_mode
== protos.vega.markets.Market.TradingMode.TRADING_MODE_CONTINUOUS
)
# Exit the opening auction
vega.submit_order(
AUX_BID,
market_id=market_id,
order_type="TYPE_LIMIT",
time_in_force="TIME_IN_FORCE_GTC",
side="SIDE_BUY",
volume=1000,
price=100,
)
vega.submit_order(
AUX_ASK,
market_id=market_id,
order_type="TYPE_LIMIT",
time_in_force="TIME_IN_FORCE_GTC",
side="SIDE_SELL",
volume=1000,
price=100,
)
vega.wait_fn(1)
vega.wait_for_total_catchup()
vega.update_network_parameter(
PROPOSER,
parameter="market.fee.factors.buybackFee",
new_value="0",
)
vega.wait_for_total_catchup()
yield vega, market_id, base_asset_id, quote_asset_id


@pytest.mark.integration
def test_new_pap(init_tests):
vega: VegaServiceNull
vega, market_id, base_asset_id, quote_asset_id = init_tests

vega.new_protocol_automated_purchase_program(
proposal_key=PROPOSER,
market_id=market_id,
asset_id=quote_asset_id,
from_account_type=protos.vega.vega.AccountType.ACCOUNT_TYPE_BUY_BACK_FEES,
to_account_type=protos.vega.vega.AccountType.ACCOUNT_TYPE_NETWORK_TREASURY,
oracle_offset_factor=1,
price_oracle_name="priceOracle",
price_oracle_signer=vega.wallet.public_key(PROPOSER),
price_oracle_decimals=0,
snapshot_frequency=datetime.timedelta(seconds=10),
auction_frequency=datetime.timedelta(seconds=10),
auction_duration=datetime.timedelta(seconds=60),
minimum_auction_size=1,
maximum_auction_size=1_000,
oracle_price_staleness_tolerance=datetime.timedelta(minutes=1),
)
vega.wait_fn(1)
vega.submit_oracle_data(
key_name=PROPOSER,
name="priceOracle",
type=protos.vega.data.v1.spec.PropertyKey.Type.TYPE_INTEGER,
value=100,
decimals=0,
)

for i in range(20):
vega.wait_fn(1)
vega.wait_for_total_catchup()
market = vega.get_latest_market_data(market_id=market_id)
if (
market.market_trading_mode
== protos.vega.markets.Market.TradingMode.TRADING_MODE_PROTOCOL_AUTOMATED_PURCHASE_AUCTION
):
break
if (
market.market_trading_mode
!= protos.vega.markets.Market.TradingMode.TRADING_MODE_PROTOCOL_AUTOMATED_PURCHASE_AUCTION
):
raise Exception("market did not enter automated auction")

vega.submit_order(
AUX_ASK,
market_id=market_id,
order_type="TYPE_LIMIT",
time_in_force="TIME_IN_FORCE_GTC",
side="SIDE_SELL",
volume=1000,
price=100,
)
vega.wait_fn(60)
vega.wait_for_total_catchup()

market = vega.get_latest_market_data(market_id=market_id)
if (
market.market_trading_mode
!= protos.vega.markets.Market.TradingMode.TRADING_MODE_CONTINUOUS
):
assert (
market.market_trading_mode
== protos.vega.markets.Market.TradingMode.TRADING_MODE_CONTINUOUS
)
assert (
len(
vega.list_accounts(
asset_id=base_asset_id,
account_types=[
protos.vega.vega.AccountType.ACCOUNT_TYPE_NETWORK_TREASURY
],
)
)
> 0
)
17 changes: 16 additions & 1 deletion tests/vega_query/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
logger = logging.getLogger(__name__)

DEFAULT_NETWORK = Network.NETWORK_TESTNET
DEFAULT_PORT_DATA_NODE = None


@fixture(scope="session")
def tds():
client = TradingDataService(network=DEFAULT_NETWORK)
client = TradingDataService(
network=DEFAULT_NETWORK, port_data_node=DEFAULT_PORT_DATA_NODE
)
yield client


Expand Down Expand Up @@ -106,3 +109,15 @@ def end_timestamp(tds: TradingDataService) -> int:
@fixture(scope="session")
def amms(tds: TradingDataService) -> List[protos.vega.events.v1.events.AMM]:
return tds.list_amms(max_pages=1)


@fixture(scope="session")
def epoch(tds: TradingDataService) -> protos.vega.vega.Epoch:
return tds.get_epoch()


@fixture(scope="session")
def sets(
tds: TradingDataService,
) -> List[protos.data_node.api.v2.trading_data.ReferralSet]:
return tds.list_referral_sets(max_pages=1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from vega_query.service.service_trading_data import TradingDataService
from tests.vega_query.fixtures import tds

import vega_protos.protos as protos


@pytest.mark.vega_query
def test_get_current_referral_program(tds: TradingDataService):
program = tds.get_current_referral_program()
if program is not None:
assert isinstance(program, protos.data_node.api.v2.trading_data.ReferralProgram)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from vega_query.service.service_trading_data import TradingDataService
from tests.vega_query.fixtures import tds

import vega_protos.protos as protos


@pytest.mark.vega_query
def test_get_latest_volume_discount_program(tds: TradingDataService):
program = tds.get_current_volume_discount_program()
if program is not None:
assert isinstance(
program, protos.data_node.api.v2.trading_data.VolumeDiscountProgram
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from vega_query.service.service_trading_data import TradingDataService
from tests.vega_query.fixtures import tds

import vega_protos.protos as protos


@pytest.mark.vega_query
def test_get_latest_volume_rebate_program(tds: TradingDataService):
program = tds.get_current_volume_rebate_program()
if program is not None:
assert isinstance(
program, protos.data_node.api.v2.trading_data.VolumeRebateProgram
)
26 changes: 26 additions & 0 deletions tests/vega_query/service/service_trading_data/test_get_epoch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from vega_query.service.service_trading_data import TradingDataService
from tests.vega_query.fixtures import tds, epoch

import vega_protos.protos as protos


@pytest.mark.vega_query
def test_get_epoch(tds: TradingDataService):
epoch = tds.get_epoch()
assert isinstance(epoch, protos.vega.vega.Epoch)


@pytest.mark.vega_query
def test_get_epoch_id(tds: TradingDataService, epoch: protos.vega.vega.Epoch):
id = epoch.seq
epoch = tds.get_epoch(id=id)
assert epoch.seq == id


@pytest.mark.vega_query
def test_get_epoch_block(tds: TradingDataService, epoch: protos.vega.vega.Epoch):
block = epoch.timestamps.first_block
epoch = tds.get_epoch(block=block)
assert epoch.timestamps.first_block == block
Empty file.
Loading

0 comments on commit ebd3a63

Please sign in to comment.