Skip to content
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
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 = "v0.12.2"
version = "v0.12.3"
description = "StakeWise Python utils"
authors = ["StakeWise Labs <info@stakewise.io>"]
license = "GPL-3.0-or-later"
Expand Down
9 changes: 9 additions & 0 deletions sw_utils/protocol_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from decimal import Decimal

from web3 import Web3
from web3.types import Wei

Expand Down Expand Up @@ -41,6 +43,12 @@ def build_protocol_config(
)
force_withdrawals_period = config_data.get('force_withdrawals_period', 24 * 60 * 60)

# Default value is based on historical APR, 0.23% adjustment
default_os_token_redeem_multiplier = Decimal('1.0023')
os_token_redeem_multiplier = Decimal(
config_data.get('os_token_redeem_multiplier', default_os_token_redeem_multiplier)
)

return ProtocolConfig(
oracles=oracles,
rewards_threshold=rewards_threshold or 0,
Expand All @@ -60,4 +68,5 @@ def build_protocol_config(
force_withdrawals_period=force_withdrawals_period,
os_token_vaults_exit_limit_bps=os_token_vaults_exit_limit_bps,
os_token_vaults=os_token_vaults,
os_token_redeem_multiplier=os_token_redeem_multiplier,
)
31 changes: 18 additions & 13 deletions sw_utils/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import random
import string
from decimal import Decimal
from secrets import randbits

from eth_typing import ChecksumAddress
from eth_typing import ChecksumAddress, HexStr
from faker import Faker
from faker.providers import BaseProvider
from py_ecc.bls import G2ProofOfPossession
Expand All @@ -25,27 +26,29 @@ def eth_address(self) -> ChecksumAddress:
account = w3.eth.account.create()
return account.address

def eth_proof(self) -> str:
# 32 bytes
return '0x' + ''.join(random.choices('abcdef' + string.digits, k=64))
def eth_proof(self) -> HexStr:
return Web3.to_hex(random.randbytes(32))

def validator_signature(self) -> str:
def merkle_root(self) -> HexStr:
return self.eth_proof()

def validator_signature(self) -> HexStr:
# BLS signature, 96 bytes
return '0x' + ''.join(random.choices('abcdef' + string.digits, k=192))
return Web3.to_hex(random.randbytes(96))

def account_signature(self) -> str:
def account_signature(self) -> HexStr:
# ECDSA signature, 65 bytes
return '0x' + ''.join(random.choices('abcdef' + string.digits, k=130))
return Web3.to_hex(random.randbytes(65))

def validator_public_key(self) -> str:
def validator_public_key(self) -> HexStr:
# 48 bytes
return '0x' + ''.join(random.choices('abcdef' + string.digits, k=96))
return Web3.to_hex(random.randbytes(48))

def ecies_public_key(self) -> str:
def ecies_public_key(self) -> HexStr:
# 64 bytes
return '0x' + ''.join(random.choices('abcdef' + string.digits, k=128))
return Web3.to_hex(random.randbytes(64))

def account_public_key(self) -> str:
def account_public_key(self) -> HexStr:
# ECIES public key, 64 bytes
return self.ecies_public_key()

Expand Down Expand Up @@ -87,6 +90,7 @@ def get_mocked_protocol_config(
vault_fee_max_bps: int = 1500, # 15%
os_token_vaults_exit_limit_bps: int = 10_000, # 100%
os_token_vaults: list[str] | None = None,
os_token_redeem_multiplier: Decimal = Decimal('1.0023'), # ~0.23% adjustment
) -> ProtocolConfig:
return ProtocolConfig(
oracles=oracles
Expand Down Expand Up @@ -116,4 +120,5 @@ def get_mocked_protocol_config(
validators_threshold=validators_threshold,
os_token_vaults_exit_limit_bps=os_token_vaults_exit_limit_bps,
os_token_vaults=os_token_vaults or [],
os_token_redeem_multiplier=os_token_redeem_multiplier,
)
4 changes: 4 additions & 0 deletions sw_utils/typings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from decimal import Decimal
from typing import Literal, NewType, TypeAlias

from eth_keys.datatypes import PublicKey
Expand Down Expand Up @@ -77,6 +78,9 @@ class ProtocolConfig:
# List of vaults used to determine osToken reward rate
os_token_vaults: list[ChecksumAddress]

# Multiplier to adjust redemption assets to account for potential osToken rate increase
os_token_redeem_multiplier: Decimal

# Keeper settings
validators_threshold: int = 0
rewards_threshold: int = 0