|
1 | 1 | import json
|
2 |
| -from os import path |
3 |
| -from typing import Dict |
| 2 | +import os |
4 | 3 |
|
5 |
| -from eth_typing import Address |
| 4 | +from eth_typing import ChecksumAddress |
6 | 5 | from web3 import Web3
|
7 | 6 | from web3.contract import Contract
|
8 | 7 |
|
9 |
| -current_dir = path.dirname(__file__) |
| 8 | +from reporting.settings import ( |
| 9 | + POOL_CONTRACT_ADDRESS, |
| 10 | + REWARD_ETH_CONTRACT_ADDRESS, |
| 11 | + STAKED_ETH_CONTRACT_ADDRESS, |
| 12 | + BALANCE_REPORTERS_CONTRACT_ADDRESS |
| 13 | +) |
10 | 14 |
|
11 | 15 |
|
12 |
| -def _load_abi(filename: str) -> Dict: |
13 |
| - with open(path.join(current_dir, 'abi', filename), 'r') as f: |
14 |
| - return json.load(f) |
| 16 | +def get_staked_eth_contract(w3: Web3) -> Contract: |
| 17 | + """:returns instance of `StakedEthToken` contract.""" |
| 18 | + current_dir = os.path.dirname(__file__) |
| 19 | + with open(os.path.join(current_dir, 'abi/IStakedEthToken.json')) as f: |
| 20 | + abi = json.load(f) |
15 | 21 |
|
| 22 | + return w3.eth.contract(abi=abi, address=STAKED_ETH_CONTRACT_ADDRESS) |
16 | 23 |
|
17 |
| -def get_settings_contract(w3: Web3, contract_address: Address) -> Contract: |
18 |
| - return w3.eth.contract( |
19 |
| - abi=_load_abi('ISettings.json'), |
20 |
| - address=contract_address |
21 |
| - ) |
22 | 24 |
|
| 25 | +def get_reward_eth_contract(w3: Web3) -> Contract: |
| 26 | + """:returns instance of `RewardEthToken` contract.""" |
| 27 | + current_dir = os.path.dirname(__file__) |
| 28 | + with open(os.path.join(current_dir, 'abi/IRewardEthToken.json')) as f: |
| 29 | + abi = json.load(f) |
| 30 | + |
| 31 | + return w3.eth.contract(abi=abi, address=REWARD_ETH_CONTRACT_ADDRESS) |
23 | 32 |
|
24 |
| -def get_validators_contract(w3: Web3, contract_address: Address) -> Contract: |
25 |
| - return w3.eth.contract( |
26 |
| - abi=_load_abi('IValidators.json'), |
27 |
| - address=contract_address |
28 |
| - ) |
29 | 33 |
|
| 34 | +def get_pool_contract(w3: Web3) -> Contract: |
| 35 | + """:returns instance of `Pool` contract.""" |
| 36 | + current_dir = os.path.dirname(__file__) |
| 37 | + with open(os.path.join(current_dir, 'abi/IPool.json')) as f: |
| 38 | + abi = json.load(f) |
30 | 39 |
|
31 |
| -def get_reward_eth_token_contract(w3: Web3, contract_address: Address) -> Contract: |
32 | 40 | return w3.eth.contract(
|
33 |
| - abi=_load_abi('IRewardEthToken.json'), |
34 |
| - address=contract_address |
| 41 | + abi=abi, |
| 42 | + address=POOL_CONTRACT_ADDRESS |
35 | 43 | )
|
36 | 44 |
|
37 | 45 |
|
38 |
| -def get_staked_eth_token_contract(w3: Web3, contract_address: Address) -> Contract: |
39 |
| - return w3.eth.contract( |
40 |
| - abi=_load_abi('IStakedEthToken.json'), |
41 |
| - address=contract_address |
42 |
| - ) |
| 46 | +def get_ownable_pausable_contract(w3: Web3, contract_address: ChecksumAddress) -> Contract: |
| 47 | + """:returns instance of `OwnablePausable` contract.""" |
| 48 | + current_dir = os.path.dirname(__file__) |
| 49 | + with open(os.path.join(current_dir, 'abi/OwnablePausableUpgradeable.json')) as f: |
| 50 | + abi = json.load(f) |
| 51 | + |
| 52 | + return w3.eth.contract(abi=abi, address=contract_address) |
| 53 | + |
43 | 54 |
|
| 55 | +def get_balance_reporters_contract(w3: Web3) -> Contract: |
| 56 | + """:returns instance of `Balance Reporters` contract.""" |
| 57 | + current_dir = os.path.dirname(__file__) |
| 58 | + with open(os.path.join(current_dir, 'abi/IBalanceReporters.json')) as f: |
| 59 | + abi = json.load(f) |
44 | 60 |
|
45 |
| -def get_balance_reporters_contract(w3: Web3, contract_address: Address) -> Contract: |
46 | 61 | return w3.eth.contract(
|
47 |
| - abi=_load_abi('IBalanceReporters.json'), |
48 |
| - address=contract_address |
| 62 | + abi=abi, |
| 63 | + address=BALANCE_REPORTERS_CONTRACT_ADDRESS |
49 | 64 | )
|
0 commit comments