diff --git a/pyproject.toml b/pyproject.toml index 49a00d4..b6a6f6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sw-utils" -version = "v0.12.2" +version = "v0.12.3" description = "StakeWise Python utils" authors = ["StakeWise Labs "] license = "GPL-3.0-or-later" diff --git a/sw_utils/protocol_config.py b/sw_utils/protocol_config.py index 89bf1c0..b4608cd 100644 --- a/sw_utils/protocol_config.py +++ b/sw_utils/protocol_config.py @@ -1,3 +1,5 @@ +from decimal import Decimal + from web3 import Web3 from web3.types import Wei @@ -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, @@ -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, ) diff --git a/sw_utils/tests/factories.py b/sw_utils/tests/factories.py index eac3c09..4b8378f 100644 --- a/sw_utils/tests/factories.py +++ b/sw_utils/tests/factories.py @@ -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 @@ -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() @@ -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 @@ -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, ) diff --git a/sw_utils/typings.py b/sw_utils/typings.py index fc52ba2..b9f5047 100644 --- a/sw_utils/typings.py +++ b/sw_utils/typings.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +from decimal import Decimal from typing import Literal, NewType, TypeAlias from eth_keys.datatypes import PublicKey @@ -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