arbsep; conf/
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,9 +1,8 @@
|
||||
venv
|
||||
*secret*
|
||||
!/.secret-mock.toml
|
||||
**secret**
|
||||
!/conf/mock/.secret-mock.toml
|
||||
dexorder.toml
|
||||
logging.toml
|
||||
/contract
|
||||
__pycache__
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
docker run --network=host --ulimit memlock=-1 docker.dragonflydb.io/dragonflydb/dragonfly:latest --proactor_threads 1 --maxmemory 256MiB --hz=1 --dbfilename '' "$@"
|
||||
17
bin/generate_private_key.py
Normal file
17
bin/generate_private_key.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import os
|
||||
from eth_keys import keys
|
||||
|
||||
# Generating a private key
|
||||
private_key_hex = os.urandom(32)
|
||||
private_key = keys.PrivateKey(private_key_hex)
|
||||
|
||||
# Getting the public key
|
||||
public_key = private_key.public_key
|
||||
|
||||
# compute the Ethereum address from the public key
|
||||
address = public_key.to_checksum_address()
|
||||
|
||||
print(f"key='{hex(private_key)[2:]}' # {address}")
|
||||
# print("Private key:", private_key)
|
||||
# print("Public key:", public_key)
|
||||
# print("Address:", address)
|
||||
@@ -1 +0,0 @@
|
||||
alembic downgrade -1 && alembic upgrade head && ./bin/df.sh
|
||||
@@ -1,8 +1,6 @@
|
||||
account = 'test1' # Dev Account #1
|
||||
rpc_url = 'http://alpharpc:8545'
|
||||
ws_url = 'ws://alpharpc:8545'
|
||||
db_url = 'postgresql://dexorder:redroxed@postgres/dexorder'
|
||||
redis_url = 'redis://redis:6379'
|
||||
account = '${accounts.gas}'
|
||||
rpc_url = '${rpcurls.arbsep_alchemy}'
|
||||
ws_url = '${rpcurls.arbsep_alchemy_ws}'
|
||||
|
||||
mirror_pools = [
|
||||
# Arbitrum Pools
|
||||
@@ -26,6 +24,3 @@ mirror_pools = [
|
||||
# '0xb4CB800910B228ED3d0834cF79D697127BBB00e5', # WETH/USDC
|
||||
|
||||
]
|
||||
|
||||
[deployments]
|
||||
1337 = 'alpha'
|
||||
@@ -1,59 +1,59 @@
|
||||
aiohttp==3.9.1
|
||||
aiohttp==3.9.5
|
||||
aiosignal==1.3.1
|
||||
alembic==1.13.1
|
||||
alembic==1.13.2
|
||||
antlr4-python3-runtime==4.9.3
|
||||
async-lru==2.0.4
|
||||
attrs==23.2.0
|
||||
bitarray==2.9.2
|
||||
cachetools==5.3.3
|
||||
certifi==2023.11.17
|
||||
certifi==2024.2.2
|
||||
charset-normalizer==3.3.2
|
||||
cytoolz==0.12.2
|
||||
ckzg==1.0.1
|
||||
cytoolz==0.12.3
|
||||
defaultlist==1.0.0
|
||||
eth-account==0.10.0
|
||||
eth-bloom==3.0.0
|
||||
eth-hash==0.6.0
|
||||
eth-keyfile==0.7.0
|
||||
eth-keys==0.5.0
|
||||
eth-rlp==1.0.0
|
||||
eth-typing==4.0.0
|
||||
eth-utils==3.0.0
|
||||
eth_abi==5.0.0
|
||||
eth-account==0.11.2
|
||||
eth-bloom==3.0.1
|
||||
eth-hash==0.7.0
|
||||
eth-keyfile==0.8.1
|
||||
eth-keys==0.5.1
|
||||
eth-rlp==1.0.1
|
||||
eth-typing==4.2.2
|
||||
eth-utils==4.1.0
|
||||
eth_abi==5.1.0
|
||||
frozenlist==1.4.1
|
||||
greenlet==3.0.3
|
||||
hexbytes==0.3.1
|
||||
hiredis==2.3.2
|
||||
idna==3.6
|
||||
jsonschema==4.20.0
|
||||
idna==3.7
|
||||
jsonschema==4.21.1
|
||||
jsonschema-specifications==2023.12.1
|
||||
lru-dict==1.2.0
|
||||
Mako==1.3.0
|
||||
MarkupSafe==2.1.3
|
||||
Mako==1.3.3
|
||||
MarkupSafe==2.1.5
|
||||
msgpack-python==0.5.6
|
||||
multidict==6.0.4
|
||||
multidict==6.0.5
|
||||
omegaconf==2.3.0
|
||||
orjson==3.10.0
|
||||
parsimonious==0.9.0
|
||||
protobuf==4.25.2
|
||||
orjson==3.10.5
|
||||
parsimonious==0.10.0
|
||||
protobuf==5.26.1
|
||||
psycopg2-binary==2.9.9
|
||||
pycryptodome==3.20.0
|
||||
python-dateutil==2.9.0.post0
|
||||
pytz==2024.1
|
||||
pyunormalize==15.1.0
|
||||
PyYAML==6.0.1
|
||||
redis==5.0.3
|
||||
referencing==0.32.1
|
||||
regex==2023.12.25
|
||||
redis==5.0.7
|
||||
referencing==0.35.0
|
||||
regex==2024.4.28
|
||||
requests==2.31.0
|
||||
rlp==4.0.0
|
||||
rpds-py==0.17.1
|
||||
rlp==4.0.1
|
||||
rpds-py==0.18.0
|
||||
six==1.16.0
|
||||
socket.io-emitter==0.1.5.1
|
||||
sortedcontainers==2.4.0
|
||||
SQLAlchemy==2.0.29
|
||||
toolz==0.12.0
|
||||
typing_extensions==4.9.0
|
||||
urllib3==2.1.0
|
||||
web3==6.16.0
|
||||
SQLAlchemy==2.0.31
|
||||
toolz==0.12.1
|
||||
typing_extensions==4.11.0
|
||||
urllib3==2.2.1
|
||||
web3==6.20.0
|
||||
websockets==12.0
|
||||
yarl==1.9.4
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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}')
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
Reference in New Issue
Block a user