Skip to content

Commit

Permalink
Add factory for protocol config
Browse files Browse the repository at this point in the history
  • Loading branch information
cyc60 committed Feb 5, 2024
1 parent a189cd5 commit ba5edbd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sw-utils"
version = "0.6.1"
version = "0.6.2"
description = "StakeWise Python utils"
authors = ["StakeWise Labs <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down
4 changes: 2 additions & 2 deletions sw_utils/protocol_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from sw_utils.typings import Oracle, ProtocolConfig


async def build_protocol_config(
config_data: dict, rewards_threshold: int | None = None, validators_threshold: int | None = None
def build_protocol_config(
config_data: dict, rewards_threshold: int = 0, validators_threshold: int = 0
) -> ProtocolConfig:
oracles = []
for oracle in config_data['oracles']:
Expand Down
2 changes: 1 addition & 1 deletion sw_utils/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .factories import faker
from .factories import faker, get_mocked_protocol_config
41 changes: 41 additions & 0 deletions sw_utils/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from web3 import Web3
from web3.types import Wei

from sw_utils.typings import Oracle, ProtocolConfig

w3 = Web3()
faker = Faker()

Expand Down Expand Up @@ -40,3 +42,42 @@ def wei_amount(self, start: int = 10, stop: int = 1000) -> Wei:


faker.add_provider(Web3Provider)


# pylint: disable=too-many-arguments
def get_mocked_protocol_config(
oracles: list[Oracle],
oracles_count: int = 1,
rewards_threshold: int = 1,
validators_threshold: int = 1,
exit_signature_recover_threshold: int = 1,
exit_signature_epoch: int = 0,
validators_approval_batch_limit: int = 100,
validators_exit_rotation_batch_limit: int = 1000,
signature_validity_period: int = 60,
until_force_exit_epochs: int = 1000,
validators_exit_queued_assets_bps: int = 500, # 5%
validator_min_active_epochs: int = 2250, # 10 days
vault_fee_max_bps: int = 1500, # 15%
) -> ProtocolConfig:
return ProtocolConfig(
oracles=oracles
or [
Oracle(public_key=faker.eth_public_key(), endpoints=[f'https://example{i}.com'])
for i in range(oracles_count)
],
supported_relays=[
'http://relay',
],
vault_fee_max_bps=vault_fee_max_bps,
validator_min_active_epochs=validator_min_active_epochs,
validators_exit_queued_assets_bps=validators_exit_queued_assets_bps,
validators_approval_batch_limit=validators_approval_batch_limit,
validators_exit_rotation_batch_limit=validators_exit_rotation_batch_limit,
exit_signature_epoch=exit_signature_epoch,
exit_signature_recover_threshold=exit_signature_recover_threshold,
signature_validity_period=signature_validity_period,
until_force_exit_epochs=until_force_exit_epochs,
rewards_threshold=rewards_threshold,
validators_threshold=validators_threshold,
)
4 changes: 2 additions & 2 deletions sw_utils/typings.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ class ProtocolConfig:

exit_signature_recover_threshold: int

validators_threshold: int | None = None
rewards_threshold: int | None = None
validators_threshold: int = 0
rewards_threshold: int = 0

0 comments on commit ba5edbd

Please sign in to comment.