Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improving minting flow #674

Merged
merged 7 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions vega_sim/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,7 @@ def list_accounts(
pub_key: Optional[str] = None,
asset_id: Optional[str] = None,
market_id: Optional[str] = None,
account_types: Optional[vega_protos.vega.AccountType] = None,
asset_decimals_map: Optional[Dict[str, int]] = None,
) -> List[AccountData]:
"""Output money in general accounts/margin accounts/bond accounts (if exists)
Expand All @@ -1726,6 +1727,7 @@ def list_accounts(
data_client=data_client,
party_id=pub_key,
asset_id=asset_id,
account_types=account_types,
market_id=market_id,
)

Expand Down Expand Up @@ -2369,9 +2371,6 @@ def list_transfers(
for transfer_node in transfer_nodes:
transfer = transfer_node.transfer

if transfer.status == events_protos.Transfer.Status.STATUS_REJECTED:
continue

if transfer.asset not in asset_dp:
asset_dp[transfer.asset] = get_asset_decimals(
asset_id=transfer.asset, data_client=data_client
Expand Down
3 changes: 3 additions & 0 deletions vega_sim/api/data_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def list_accounts(
data_client: vac.VegaTradingDataClientV2,
asset_id: Optional[str] = None,
market_id: Optional[str] = None,
account_types: Optional[vega_protos.vega.AccountType] = None,
party_id: Optional[str] = None,
) -> List[data_node_protos_v2.trading_data.AccountBalance]:
"""
Expand All @@ -162,6 +163,8 @@ def list_accounts(
account_filter.asset_id = asset_id
if market_id is not None:
account_filter.market_ids.extend([market_id])
if account_types is not None:
account_filter.account_types.extend(account_types)
return unroll_v2_pagination(
base_request=data_node_protos_v2.trading_data.ListAccountsRequest(
filter=account_filter
Expand Down
5 changes: 4 additions & 1 deletion vega_sim/api/faucet.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

def mint(pub_key: str, asset: str, amount: int, faucet_url: str) -> None:
url = BASE_MINT_URL.format(faucet_url=faucet_url)
# Request a proportion of the maximum faucet amount - this allows for
# cases where requesting the maximum amount would have floating point
# imprecision and the request rejected.
payload = {
"party": pub_key,
"amount": str(int(amount)),
"amount": str(int(0.99 * amount)),
"asset": asset,
}
for i in range(20):
Expand Down
25 changes: 3 additions & 22 deletions vega_sim/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
from vega_sim.null_service import VegaServiceNull
from vega_sim.service import VegaService

from vega_sim.service import VegaFaucetError

logger = logging.getLogger(__name__)

MarketState = namedtuple(
Expand Down Expand Up @@ -304,16 +302,8 @@ def step(self, vega: VegaService) -> None:
if self.random_agent_ordering
else self.agents
):
# TODO: Remove this once fauceting error has been investigated
try:
agent.step(vega)
except VegaFaucetError:
logger.exception(
f"Agent {agent.name()} failed to step. Funds from faucet never"
" received."
)
# Mint forwards blocks, wait for catchup
vega.wait_for_total_catchup()
agent.step(vega)
vega.wait_for_total_catchup()


class MarketEnvironmentWithState(MarketEnvironment):
Expand Down Expand Up @@ -431,16 +421,7 @@ def step(self, vega: VegaService) -> None:
if self.random_agent_ordering
else self.agents
):
# TODO: Remove this once fauceting error has been investigated
try:
agent.step(state)
except VegaFaucetError:
logger.exception(
f"Agent {agent.name()} failed to step. Funds from faucet never"
" received."
)
# Mint forwards blocks, wait for catchup
vega.wait_for_total_catchup()
agent.step(state)


class NetworkEnvironment(MarketEnvironmentWithState):
Expand Down
8 changes: 3 additions & 5 deletions vega_sim/local_data_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,12 @@ def initialise_market_data(
def initialise_transfer_monitoring(
self,
):
base_transfers = []

base_transfers.extend(
data.list_transfers(data_client=self._trading_data_client)
)
base_transfers = data.list_transfers(data_client=self._trading_data_client)

with self.transfers_lock:
for t in base_transfers:
if t.status == events_protos.Transfer.Status.STATUS_REJECTED:
continue
self._transfer_state_from_feed.setdefault(t.party_to, {})[t.id] = t

def initialise_network_parameters(self):
Expand Down
12 changes: 0 additions & 12 deletions vega_sim/null_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,19 +1028,7 @@ def start(self, block_on_startup: bool = True) -> None:

# Initialise the data-cache
self.data_cache

# Create the VegaService key and mint assets to the treasury
governance_asset = self.get_asset(
self.find_asset_id(symbol="VOTE", enabled=True, raise_on_missing=True)
)
self.wallet.create_key(wallet_name=self.WALLET_NAME, name=self.KEY_NAME)
self.mint(
wallet_name=self.WALLET_NAME,
key_name=self.KEY_NAME,
asset=governance_asset.id,
amount=governance_asset.details.builtin_asset.max_faucet_amount_mint,
from_faucet=True,
)

# Class internal as at some point the host may vary as well as the port
@staticmethod
Expand Down
2 changes: 0 additions & 2 deletions vega_sim/scenario/common/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,6 @@ def step(self, vega_state: VegaState):
asset=self.asset_id,
amount=self.initial_asset_mint,
key_name=self.key_name,
raise_error=False,
)
self.vega.wait_for_total_catchup()

Expand Down Expand Up @@ -3271,7 +3270,6 @@ def step(self, vega_state: VegaState):
asset=self.asset_id,
amount=self.initial_asset_mint,
key_name=self.key_name,
raise_error=False,
)

# Ensure volume maximising range is at least 100bps wide to
Expand Down
4 changes: 0 additions & 4 deletions vega_sim/scenario/fuzzed_markets/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ def check_balance(self, asset_id: str, amount: float):
wallet_name=self.wallet_name,
asset=asset_id,
amount=amount,
raise_error=False,
)


Expand Down Expand Up @@ -364,7 +363,6 @@ def step(self, vega_state):
wallet_name=self.wallet_name,
amount=self.initial_asset_mint,
asset=self.asset_id,
raise_error=False,
)
self.close_outs += 1
self.commitment_amount = 0
Expand Down Expand Up @@ -466,7 +464,6 @@ def step(self, vega_state):
wallet_name=self.wallet_name,
amount=self.initial_asset_mint,
asset=self.asset_id,
raise_error=False,
)
self.close_outs += 1
self.commitment_amount = 0
Expand Down Expand Up @@ -639,7 +636,6 @@ def step(self, vega_state):
wallet_name=self.wallet_name,
amount=self.initial_asset_mint,
asset=self.asset_id,
raise_error=False,
)
return

Expand Down
Loading
Loading