-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor update_price.py * Add price network config, add sender execution endpoint * Del price/networks.py, fix comment * Add comment in .env.example * Fix lint
- Loading branch information
1 parent
c97b069
commit 3f4c3ea
Showing
20 changed files
with
885 additions
and
571 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import logging | ||
|
||
from eth_account import Account | ||
from eth_account.signers.local import LocalAccount | ||
from web3 import Web3 | ||
from web3.middleware import construct_sign_and_send_raw_middleware | ||
|
||
from src.common.settings import HOT_WALLET_PRIVATE_KEY | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_execution_client(endpoint: str, account: LocalAccount | None = None) -> Web3: | ||
client = Web3(Web3.HTTPProvider(endpoint)) | ||
if account: | ||
client.middleware_onion.add(construct_sign_and_send_raw_middleware(account)) | ||
return client | ||
|
||
|
||
hot_wallet_account = Account().from_key(HOT_WALLET_PRIVATE_KEY) | ||
logger.info('Wallet address: %s', hot_wallet_account.address) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import json | ||
import logging | ||
|
||
from eth_typing import ChecksumAddress | ||
from web3 import Web3 | ||
from web3.contract.contract import ContractEvents, ContractFunctions | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ContractWrapper: | ||
def __init__(self, abi_path: str, address: ChecksumAddress, client: Web3): | ||
self.address = address | ||
self.contract = client.eth.contract(address=address, abi=self._load_abi(abi_path)) | ||
|
||
def _load_abi(self, abi_path: str) -> dict: | ||
with open(abi_path, encoding='utf-8') as f: | ||
return json.load(f) | ||
|
||
@property | ||
def functions(self) -> ContractFunctions: | ||
return self.contract.functions | ||
|
||
@property | ||
def events(self) -> ContractEvents: | ||
return self.contract.events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from dataclasses import dataclass | ||
from enum import Enum | ||
|
||
from eth_typing import ChecksumAddress, HexAddress, HexStr | ||
from web3 import Web3 | ||
|
||
EMPTY_ADDR_HEX = HexAddress(HexStr('0x' + '00' * 20)) | ||
ZERO_CHECKSUM_ADDRESS = Web3.to_checksum_address(EMPTY_ADDR_HEX) # noqa | ||
|
||
|
||
class Network(Enum): | ||
MAINNET = 'mainnet' | ||
HOLESKY = 'holesky' | ||
GNOSIS = 'gnosis' | ||
CHIADO = 'chiado' | ||
SEPOLIA = 'sepolia' | ||
|
||
|
||
@dataclass | ||
class PriceNetworkConfig: | ||
# TARGET_CHAIN is not what eth_chainId returns. | ||
# It is internal id used in PriceFeedSender contract. | ||
TARGET_CHAIN: int | ||
# PriceFeedReceiver contract address on target network | ||
TARGET_ADDRESS: ChecksumAddress | ||
# PriceFeed contract address on target network | ||
TARGET_PRICE_FEED_CONTRACT_ADDRESS: ChecksumAddress | ||
# PriceFeedSender contract address on sender network | ||
PRICE_FEED_SENDER_CONTRACT_ADDRESS: ChecksumAddress | ||
|
||
|
||
@dataclass | ||
class NetworkConfig: | ||
VAULT_USER_LTV_TRACKER_CONTRACT_ADDRESS: ChecksumAddress | ||
PRICE_NETWORK_CONFIG: PriceNetworkConfig | None = None | ||
|
||
|
||
NETWORKS: dict[Network, NetworkConfig] = { | ||
Network.MAINNET: NetworkConfig( | ||
VAULT_USER_LTV_TRACKER_CONTRACT_ADDRESS=Web3.to_checksum_address( | ||
'0xe0Ae8B04922d6e3fA06c2496A94EF2875EFcC7BB' | ||
), | ||
PRICE_NETWORK_CONFIG=( | ||
PriceNetworkConfig( | ||
# TARGET_CHAIN is not what eth_chainId returns. | ||
# It is internal id used in PriceFeedSender contract. | ||
TARGET_CHAIN=23, | ||
# PriceFeedReceiver contract address on Arbitrum | ||
TARGET_ADDRESS=Web3.to_checksum_address( | ||
'0xbd335c16c94be8c4dd073ae376ddf78bec1858df' | ||
), | ||
# PriceFeed contract address on Arbitrum | ||
TARGET_PRICE_FEED_CONTRACT_ADDRESS=Web3.to_checksum_address( | ||
'0xba74737a078c05500dd98c970909e4a3b90c35c6' | ||
), | ||
# PriceFeedSender contract address on Mainnet | ||
PRICE_FEED_SENDER_CONTRACT_ADDRESS=Web3.to_checksum_address( | ||
'0xf7d4e7273e5015c96728a6b02f31c505ee184603' | ||
), | ||
) | ||
), | ||
), | ||
Network.HOLESKY: NetworkConfig( | ||
VAULT_USER_LTV_TRACKER_CONTRACT_ADDRESS=Web3.to_checksum_address( | ||
'0x8f48130b9b96B58035b4A9389eCDaBC00d59d0c8' | ||
), | ||
), | ||
Network.GNOSIS: NetworkConfig( | ||
VAULT_USER_LTV_TRACKER_CONTRACT_ADDRESS=Web3.to_checksum_address( | ||
'0xdEa72c54f63470349CE2dC12f8232FE00241abE6' | ||
), | ||
), | ||
Network.CHIADO: NetworkConfig( | ||
VAULT_USER_LTV_TRACKER_CONTRACT_ADDRESS=Web3.to_checksum_address( | ||
'0xe0Ae8B04922d6e3fA06c2496A94EF2875EFcC7BB' | ||
), | ||
), | ||
Network.SEPOLIA: NetworkConfig( | ||
VAULT_USER_LTV_TRACKER_CONTRACT_ADDRESS=ZERO_CHECKSUM_ADDRESS, | ||
PRICE_NETWORK_CONFIG=( | ||
PriceNetworkConfig( | ||
# TARGET_CHAIN is not what eth_chainId returns. | ||
# It is internal id used in PriceFeedSender contract. | ||
TARGET_CHAIN=10003, | ||
# PriceFeedReceiver contract address on Arbitrum Sepolia | ||
TARGET_ADDRESS=Web3.to_checksum_address( | ||
'0x744836a91f5151c6ef730eb7e07c232997debaaa' | ||
), | ||
# PriceFeed contract address on Arbitrum Sepolia | ||
TARGET_PRICE_FEED_CONTRACT_ADDRESS=Web3.to_checksum_address( | ||
'0x4026affabd9032bcc87fa05c02f088905f3dc09b' | ||
), | ||
# PriceFeedSender contract address on Sepolia | ||
PRICE_FEED_SENDER_CONTRACT_ADDRESS=Web3.to_checksum_address( | ||
'0xe572a8631a49ec4c334812bb692beecf934ac4e9' | ||
), | ||
) | ||
), | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from decouple import config | ||
|
||
from src.common.networks import NETWORKS, Network | ||
|
||
EXECUTION_ENDPOINT: str = config('EXECUTION_ENDPOINT', default='') | ||
HOT_WALLET_PRIVATE_KEY: str = config('HOT_WALLET_PRIVATE_KEY') | ||
|
||
NETWORK: Network = config('NETWORK', cast=Network) | ||
network_config = NETWORKS[NETWORK] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
from decouple import config | ||
from eth_typing import ChecksumAddress | ||
from web3 import Web3 | ||
|
||
from .networks import NETWORKS, Network | ||
|
||
NETWORK = config('NETWORK', cast=Network) | ||
EXECUTION_ENDPOINT = config('EXECUTION_ENDPOINT') | ||
HOT_WALLET_PRIVATE_KEY = config('HOT_WALLET_PRIVATE_KEY') | ||
|
||
VAULT = config('VAULT', cast=Web3.to_checksum_address) | ||
VAULT: ChecksumAddress = config('VAULT', cast=Web3.to_checksum_address) | ||
|
||
# graph | ||
GRAPH_API_URL = config('GRAPH_API_URL') | ||
GRAPH_API_TIMEOUT = config('GRAPH_API_TIMEOUT', default='10', cast=int) | ||
|
||
network_config = NETWORKS[NETWORK] | ||
GRAPH_API_URL: str = config('GRAPH_API_URL') | ||
GRAPH_API_TIMEOUT: int = config('GRAPH_API_TIMEOUT', default='10', cast=int) |
Empty file.
Oops, something went wrong.