Skip to content

Commit

Permalink
Fix harvest params (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise authored Jan 11, 2024
1 parent 9045319 commit 97f22e2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/common/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ async def get_registered_validators_public_keys(
)
return [Web3.to_hex(event['args']['publicKey']) for event in events]

async def mev_escrow(self) -> ChecksumAddress:
return await self.contract.functions.mevEscrow().call()


class V2PoolContract(ContractWrapper):
abi_path = 'abi/IV2Pool.json'
Expand Down
29 changes: 21 additions & 8 deletions src/common/ipfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from web3.types import Wei

from src.common.clients import ipfs_fetch_client
from src.common.contracts import vault_contract
from src.common.typings import HarvestParams
from src.config.settings import settings

logger = logging.getLogger(__name__)

Expand All @@ -14,19 +16,30 @@ async def fetch_harvest_params(
vault_address: ChecksumAddress, ipfs_hash: str, rewards_root: bytes
) -> HarvestParams | None:
ipfs_data = await ipfs_fetch_client.fetch_json(ipfs_hash)
mev_escrow = await vault_contract.mev_escrow()

for vault_data in ipfs_data['vaults']: # type: ignore
if vault_address == Web3.to_checksum_address(vault_data['vault']):
if vault_address != Web3.to_checksum_address(vault_data['vault']):
continue

if mev_escrow == settings.network_config.SHARED_MEV_ESCROW_CONTRACT_ADDRESS:
# shared mev vault
unlocked_mev_reward = Wei(vault_data['unlocked_mev_reward'])
reward = Wei(
vault_data['consensus_reward']
+ unlocked_mev_reward
+ vault_data.get('locked_mev_reward', 0)
)
return HarvestParams(
rewards_root=rewards_root,
reward=reward,
unlocked_mev_reward=unlocked_mev_reward,
proof=[Web3.to_bytes(hexstr=x) for x in vault_data['proof']],
+ vault_data['locked_mev_reward']
)
else:
# own mev vault
unlocked_mev_reward = Wei(0)
reward = Wei(vault_data['consensus_reward'])

return HarvestParams(
rewards_root=rewards_root,
reward=reward,
unlocked_mev_reward=unlocked_mev_reward,
proof=[Web3.to_bytes(hexstr=x) for x in vault_data['proof']],
)

return None
8 changes: 8 additions & 0 deletions src/config/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class NetworkConfig:
SHAPELLA_FORK_VERSION: bytes
SHAPELLA_EPOCH: int
MULTICALL_CONTRACT_ADDRESS: ChecksumAddress
SHARED_MEV_ESCROW_CONTRACT_ADDRESS: ChecksumAddress

@property
def SHAPELLA_FORK(self) -> ConsensusFork:
Expand Down Expand Up @@ -92,6 +93,9 @@ def IS_SUPPORT_V2_MIGRATION(self) -> bool:
MULTICALL_CONTRACT_ADDRESS=Web3.to_checksum_address(
'0xcA11bde05977b3631167028862bE2a173976CA11'
),
SHARED_MEV_ESCROW_CONTRACT_ADDRESS=Web3.to_checksum_address(
'0x48319f97E5Da1233c21c48b80097c0FB7a20Ff86'
),
),
HOLESKY: NetworkConfig(
SYMBOL='HolETH',
Expand Down Expand Up @@ -123,6 +127,9 @@ def IS_SUPPORT_V2_MIGRATION(self) -> bool:
MULTICALL_CONTRACT_ADDRESS=Web3.to_checksum_address(
'0xcA11bde05977b3631167028862bE2a173976CA11'
),
SHARED_MEV_ESCROW_CONTRACT_ADDRESS=Web3.to_checksum_address(
'0xc98F25BcAA6B812a07460f18da77AF8385be7b56'
),
),
GNOSIS: NetworkConfig(
SYMBOL='xDAI',
Expand Down Expand Up @@ -155,5 +162,6 @@ def IS_SUPPORT_V2_MIGRATION(self) -> bool:
MULTICALL_CONTRACT_ADDRESS=Web3.to_checksum_address(
'0xcA11bde05977b3631167028862bE2a173976CA11'
),
SHARED_MEV_ESCROW_CONTRACT_ADDRESS=Web3.to_checksum_address(EMPTY_ADDR_HEX),
),
}

0 comments on commit 97f22e2

Please sign in to comment.