arbsep; conf/

This commit is contained in:
Tim
2024-06-30 19:29:47 -04:00
parent bb2d84a1e7
commit dbf1929175
19 changed files with 103 additions and 68 deletions

View File

@@ -45,10 +45,12 @@ class Blockchain:
Ethereum = Blockchain(1, 'Ethereum')
Goerli = Blockchain(5, 'Goerli')
Sepolia = Blockchain( 11155111, 'Sepolia')
Polygon = Blockchain(137, 'Polygon') # POS not zkEVM
Mumbai = Blockchain(80001, 'Mumbai')
BSC = Blockchain(56, 'BSC')
Arbitrum = Blockchain(42161, 'Arbitrum', 3, batch_size=2000)
Arbitrum = Blockchain(42161, 'Arbitrum', 1, batch_size=2000)
ArbitrumSepolia = Blockchain(421614, 'Arbitrum Sepolia', 1, batch_size=2000)
Mockchain = Blockchain(31337, 'Mockchain', 3, batch_size=2000)
Alpha = Blockchain(1337, 'Dexorder Alpha', 3, batch_size=1000)

View File

@@ -31,7 +31,6 @@ from dexorder.util.async_util import maywait
log = logging.getLogger('dexorder')
LOTSA_GAS = 10_000_000
_token_infos = {}
source_w3 = None
@@ -122,7 +121,7 @@ async def main():
delay = max(0.010, config.polling)
update_once = config.polling <= 0
global source_w3
source_w3 = await create_w3(config.mirror_source_rpc_url)
source_w3 = await create_w3(config.mirror_source_rpc_url, name='source')
pools = (config.mirror_pools or [])
if not pools:
log.error('must configure mirror_pools')
@@ -130,11 +129,9 @@ async def main():
if config.account is None:
# Dev Account #5
config.account = '0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba'
await blockchain.connect()
current_blockstate.set(FinalizedBlockState())
await blockchain.connect(autosign=True, name='target') # autosign on the target chain
mirror_addr = config.mirror_env
log.info(f'Initializing with MirrorEnv {mirror_addr}')
if mirror_addr is None:
mirror_addr = os.environ.get('MIRRORENV')
if mirror_addr is None:
@@ -142,6 +139,7 @@ async def main():
if mirror_addr is None:
log.error('must configure mirror_env or set envioronment MIRRORENV')
return
log.debug(f'Using MirrorEnv at {mirror_addr}')
mirrorenv = ContractProxy(mirror_addr, 'MirrorEnv')
pool_infos = [await get_pool_info(pool) for pool in pools]
@@ -152,19 +150,24 @@ async def main():
for t in tokens:
info = await get_token_info(t)
try:
tx = await mirrorenv.transact.mirrorToken(info, gas=LOTSA_GAS)
# anvil had trouble estimating the gas, so we hardcode it.
tx = await mirrorenv.transact.mirrorToken(info, gas=1_000_000)
except Exception:
log.exception(f'Failed to mirror token {t}')
exit(1)
txs.append(tx.wait())
await asyncio.gather(*txs)
log.info('Tokens deployed')
results = await asyncio.gather(*txs)
if any(result['status'] != 1 for result in results):
log.error('Mirroring a token reverted.')
exit(1)
log.info(f'Tokens deployed {results}')
log.debug(f'Mirroring pools {", ".join(pools)}')
txs = []
for pool, info in zip(pools, pool_infos):
try:
tx = await mirrorenv.transact.mirrorPool(info, gas=LOTSA_GAS)
# anvil had trouble estimating the gas, so we hardcode it.
tx = await mirrorenv.transact.mirrorPool(info, gas=5_500_000)
except Exception:
log.exception(f'Failed to mirror pool {pool}')
exit(1)
@@ -196,7 +199,8 @@ async def main():
price = await get_pool_price(pool)
if price != last_prices.get(pool):
try:
tx = await mirrorenv.transact.updatePool(pool, price, gas=LOTSA_GAS)
# anvil had trouble estimating the gas, so we hardcode it.
tx = await mirrorenv.transact.updatePool(pool, price, gas=1_000_000) # this is a B.S. gas number
await tx.wait()
last_prices[pool] = price
log.debug(f'Mirrored {pool} {price}')

View File

@@ -18,17 +18,17 @@ from ..configuration.resolve import resolve_ws_url
from ..contract import get_contract_data
async def connect(rpc_url=None, account=None, autosign=False):
async def connect(rpc_url=None, account=NARG, autosign=False, name='default'):
"""
connects to the rpc_url and configures context vars
"""
w3 = await create_w3(rpc_url, account, autosign)
w3 = await create_w3(rpc_url, account, autosign, name)
current_w3.set(w3)
current_chain.set(Blockchain.get(await w3.eth.chain_id))
return w3
async def create_w3(rpc_url=None, account=NARG, autosign=False):
async def create_w3(rpc_url=None, account=NARG, autosign=False, name='default'):
# todo create a proxy w3 that rotates among rpc urls
# self.w3s = tuple(await create_w3(url) for url in rpc_url_or_tag)
# chain_id = self.w3s[0].eth.chain_id
@@ -42,12 +42,17 @@ async def create_w3(rpc_url=None, account=NARG, autosign=False):
w3.middleware_onion.remove('attrdict')
w3.middleware_onion.add(clean_input_async, 'clean_input')
w3.eth.Contract = _make_contract(w3.eth)
has_account = False
if autosign:
a = Account.get(account)
if a is not None:
# noinspection PyTypeChecker
w3.middleware_onion.add(await async_construct_sign_and_send_raw_middleware(a))
w3.eth.default_account = a.address
has_account = True
log.info(f'{name} w3 configured with autosign')
if not has_account:
log.info(f'No account set for {name} w3')
return w3

View File

@@ -20,10 +20,9 @@ def load_config():
result:ConfigDict = OmegaConf.merge(
schema,
load_accounts(),
from_toml('pool.toml'),
from_toml('.secret.toml'),
from_toml('dexorder.toml'),
from_toml('config.toml'),
from_toml('.secret.toml'),
from_env()
)
return result

View File

@@ -2,6 +2,7 @@ import json
import os
from eth_abi.exceptions import InsufficientDataBytes
from eth_utils import to_checksum_address
from web3.exceptions import BadFunctionCallOutput, ContractLogicError
from .abi import abis
@@ -35,7 +36,7 @@ def get_deployment_address(deployment_name, contract_name, *, chain_id=None):
data = json.load(file)
for tx in data.get('transactions',[]):
if tx.get('contractName') == contract_name:
return tx['contractAddress']
return to_checksum_address(tx['contractAddress'])
return None

View File

@@ -16,7 +16,6 @@ _dexorder = {}
def _load_chain(chain_id: int):
deployment_tag = config.deployments.get(str(chain_id), 'latest')
try:
with open(f'../contract/broadcast/Deploy.sol/{chain_id}/run-latest.json', 'rt') as file:
deployment = json.load(file)
@@ -30,7 +29,7 @@ def _load_chain(chain_id: int):
_dexorder[chain_id] = DexorderContract(addr)
log.info(f'Dexorder {addr}')
except FileNotFoundError:
log.warning(f'Could not find deployment for chain {chain_id} "{deployment_tag}"')
log.warning(f'Could not find deployment for chain {chain_id}')
def get_by_chain(d):

View File

@@ -7,7 +7,7 @@ from web3.contract.contract import ContractEvents
from web3.exceptions import LogTopicError, MismatchedABI
from web3.types import EventData
from dexorder import config, current_w3, NARG
from dexorder import config, current_w3
from dexorder.base.chain import current_chain
from dexorder.util import topic
from dexorder.util.async_util import Maywaitable, maywait

File diff suppressed because one or more lines are too long