Merge pull request #7 from pyth-network/p2w-configurability
p2w_autoattest configurability, add p2w-relay missing WASM-s, change 1882 from upstream
This commit is contained in:
commit
5a1ba5126b
|
@ -12,19 +12,20 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
|
||||||
from pyth_utils import *
|
from pyth_utils import *
|
||||||
|
|
||||||
P2W_ADDRESS = os.environ.get(
|
P2W_SOL_ADDRESS = os.environ.get("P2W_SOL_ADDRESS", "P2WH424242424242424242424242424242424242424")
|
||||||
"P2W_ADDRESS", "P2WH424242424242424242424242424242424242424"
|
|
||||||
)
|
|
||||||
P2W_ATTEST_INTERVAL = float(os.environ.get("P2W_ATTEST_INTERVAL", 5))
|
P2W_ATTEST_INTERVAL = float(os.environ.get("P2W_ATTEST_INTERVAL", 5))
|
||||||
P2W_OWNER_KEYPAIR = os.environ.get(
|
P2W_OWNER_KEYPAIR = os.environ.get("P2W_OWNER_KEYPAIR", "/usr/src/solana/keys/p2w_owner.json")
|
||||||
"P2W_OWNER_KEYPAIR", f'{"/usr/src/solana/keys/p2w_owner.json"}'
|
|
||||||
)
|
|
||||||
P2W_ATTESTATIONS_PORT = int(os.environ.get("P2W_ATTESTATIONS_PORT", 4343))
|
P2W_ATTESTATIONS_PORT = int(os.environ.get("P2W_ATTESTATIONS_PORT", 4343))
|
||||||
|
P2W_INITIALIZE_SOL_CONTRACT = os.environ.get("P2W_INITIALIZE_SOL_CONTRACT", None)
|
||||||
|
|
||||||
|
PYTH_PRICE_ACCOUNT = os.environ.get("PYTH_PRICE_ACCOUNT", None)
|
||||||
|
PYTH_PRODUCT_ACCOUNT = os.environ.get("PYTH_PRODUCT_ACCOUNT", None)
|
||||||
|
|
||||||
PYTH_ACCOUNTS_HOST = "pyth"
|
PYTH_ACCOUNTS_HOST = "pyth"
|
||||||
PYTH_ACCOUNTS_PORT = 4242
|
PYTH_ACCOUNTS_PORT = 4242
|
||||||
|
|
||||||
WORMHOLE_ADDRESS = os.environ.get("WORMHOLE_ADDRESS", "Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o")
|
WORMHOLE_ADDRESS = os.environ.get("WORMHOLE_ADDRESS", "Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o")
|
||||||
|
|
||||||
ATTESTATIONS = {
|
ATTESTATIONS = {
|
||||||
"pendingSeqnos": [],
|
"pendingSeqnos": [],
|
||||||
}
|
}
|
||||||
|
@ -59,117 +60,74 @@ def serve_attestations():
|
||||||
httpd = HTTPServer(server_address, P2WAutoattestStatusEndpoint)
|
httpd = HTTPServer(server_address, P2WAutoattestStatusEndpoint)
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
|
if P2W_INITIALIZE_SOL_CONTRACT is not None:
|
||||||
|
# Get actor pubkeys
|
||||||
|
P2W_OWNER_ADDRESS = sol_run_or_die(
|
||||||
|
"address", ["--keypair", P2W_OWNER_KEYPAIR], capture_output=True).stdout.strip()
|
||||||
|
PYTH_OWNER_ADDRESS = sol_run_or_die(
|
||||||
|
"address", ["--keypair", PYTH_PROGRAM_KEYPAIR], capture_output=True).stdout.strip()
|
||||||
|
|
||||||
# Get actor pubkeys
|
init_result = run_or_die([
|
||||||
P2W_OWNER_ADDRESS = sol_run_or_die(
|
|
||||||
"address", ["--keypair", P2W_OWNER_KEYPAIR], capture_output=True
|
|
||||||
).stdout.strip()
|
|
||||||
PYTH_OWNER_ADDRESS = sol_run_or_die(
|
|
||||||
"address", ["--keypair", PYTH_PROGRAM_KEYPAIR], capture_output=True
|
|
||||||
).stdout.strip()
|
|
||||||
|
|
||||||
|
|
||||||
# Top up pyth2wormhole owner
|
|
||||||
if SOL_AIRDROP_AMT > 0:
|
|
||||||
sol_run_or_die("airdrop", [
|
|
||||||
str(SOL_AIRDROP_AMT),
|
|
||||||
"--keypair", P2W_OWNER_KEYPAIR,
|
|
||||||
"--commitment", "finalized",
|
|
||||||
], capture_output=True)
|
|
||||||
|
|
||||||
# Initialize pyth2wormhole
|
|
||||||
init_result = run_or_die(
|
|
||||||
[
|
|
||||||
"pyth2wormhole-client",
|
"pyth2wormhole-client",
|
||||||
"--log-level",
|
"--log-level", "4",
|
||||||
"4",
|
"--p2w-addr", P2W_SOL_ADDRESS,
|
||||||
"--p2w-addr",
|
"--rpc-url", SOL_RPC_URL,
|
||||||
P2W_ADDRESS,
|
"--payer", P2W_OWNER_KEYPAIR,
|
||||||
"--rpc-url",
|
|
||||||
SOL_RPC_URL,
|
|
||||||
"--payer",
|
|
||||||
P2W_OWNER_KEYPAIR,
|
|
||||||
"init",
|
"init",
|
||||||
"--wh-prog",
|
"--wh-prog", WORMHOLE_ADDRESS,
|
||||||
WORMHOLE_ADDRESS,
|
"--owner", P2W_OWNER_ADDRESS,
|
||||||
"--owner",
|
"--pyth-owner", PYTH_OWNER_ADDRESS,
|
||||||
P2W_OWNER_ADDRESS,
|
], capture_output=True, die=False)
|
||||||
"--pyth-owner",
|
|
||||||
PYTH_OWNER_ADDRESS,
|
|
||||||
],
|
|
||||||
capture_output=True,
|
|
||||||
die=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
if init_result.returncode != 0:
|
if init_result.returncode != 0:
|
||||||
print("NOTE: pyth2wormhole-client init failed, retrying with set_config")
|
print("NOTE: pyth2wormhole-client init failed, retrying with set_config")
|
||||||
run_or_die(
|
run_or_die([
|
||||||
[
|
|
||||||
"pyth2wormhole-client",
|
"pyth2wormhole-client",
|
||||||
"--log-level",
|
"--log-level", "4",
|
||||||
"4",
|
"--p2w-addr", P2W_SOL_ADDRESS,
|
||||||
"--p2w-addr",
|
"--rpc-url", SOL_RPC_URL,
|
||||||
P2W_ADDRESS,
|
"--payer", P2W_OWNER_KEYPAIR,
|
||||||
"--rpc-url",
|
|
||||||
SOL_RPC_URL,
|
|
||||||
"--payer",
|
|
||||||
P2W_OWNER_KEYPAIR,
|
|
||||||
"set-config",
|
"set-config",
|
||||||
"--owner",
|
"--owner", P2W_OWNER_KEYPAIR,
|
||||||
P2W_OWNER_KEYPAIR,
|
"--new-owner", P2W_OWNER_ADDRESS,
|
||||||
"--new-owner",
|
"--new-wh-prog", WORMHOLE_ADDRESS,
|
||||||
P2W_OWNER_ADDRESS,
|
"--new-pyth-owner", PYTH_OWNER_ADDRESS,
|
||||||
"--new-wh-prog",
|
], capture_output=True)
|
||||||
WORMHOLE_ADDRESS,
|
|
||||||
"--new-pyth-owner",
|
|
||||||
PYTH_OWNER_ADDRESS,
|
|
||||||
],
|
|
||||||
capture_output=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Retrieve current price/product pubkeys from the pyth publisher
|
# Retrieve current price/product pubkeys from the pyth publisher if not provided in envs
|
||||||
conn = HTTPConnection(PYTH_ACCOUNTS_HOST, PYTH_ACCOUNTS_PORT)
|
if PYTH_PRICE_ACCOUNT is None or PYTH_PRODUCT_ACCOUNT is None:
|
||||||
|
conn = HTTPConnection(PYTH_ACCOUNTS_HOST, PYTH_ACCOUNTS_PORT)
|
||||||
|
|
||||||
conn.request("GET", "/")
|
conn.request("GET", "/")
|
||||||
|
|
||||||
res = conn.getresponse()
|
res = conn.getresponse()
|
||||||
|
|
||||||
pyth_accounts = None
|
pyth_accounts = None
|
||||||
|
|
||||||
if res.getheader("Content-Type") == "application/json":
|
if res.getheader("Content-Type") == "application/json":
|
||||||
pyth_accounts = json.load(res)
|
pyth_accounts = json.load(res)
|
||||||
else:
|
else:
|
||||||
print(f"Bad Content type {res.getheader('Content-Type')}", file=sys.stderr)
|
print(f"Bad Content type {res.getheader('Content-Type')}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
price_addr = pyth_accounts["price"]
|
PYTH_PRICE_ACCOUNT = pyth_accounts["price"]
|
||||||
product_addr = pyth_accounts["product"]
|
PYTH_PRODUCT_ACCOUNT = pyth_accounts["product"]
|
||||||
|
print(f"Retrieved Pyth accounts from endpoint: {pyth_accounts}")
|
||||||
|
|
||||||
nonce = 0
|
nonce = 0
|
||||||
attest_result = run_or_die(
|
attest_result = run_or_die([
|
||||||
[
|
"pyth2wormhole-client",
|
||||||
"pyth2wormhole-client",
|
"--log-level", "4",
|
||||||
"--log-level",
|
"--p2w-addr", P2W_SOL_ADDRESS,
|
||||||
"4",
|
"--rpc-url", SOL_RPC_URL,
|
||||||
"--p2w-addr",
|
"--payer", P2W_OWNER_KEYPAIR,
|
||||||
P2W_ADDRESS,
|
"attest",
|
||||||
"--rpc-url",
|
"--price", PYTH_PRICE_ACCOUNT,
|
||||||
SOL_RPC_URL,
|
"--product", PYTH_PRODUCT_ACCOUNT,
|
||||||
"--payer",
|
"--nonce", str(nonce),
|
||||||
P2W_OWNER_KEYPAIR,
|
], capture_output=True)
|
||||||
"attest",
|
|
||||||
"--price",
|
|
||||||
price_addr,
|
|
||||||
"--product",
|
|
||||||
product_addr,
|
|
||||||
"--nonce",
|
|
||||||
str(nonce),
|
|
||||||
],
|
|
||||||
capture_output=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
print("p2w_autoattest ready to roll.")
|
print("p2w_autoattest ready to roll.")
|
||||||
print(f"ACCOUNTS: {pyth_accounts}")
|
|
||||||
print(f"Attest Interval: {P2W_ATTEST_INTERVAL}")
|
print(f"Attest Interval: {P2W_ATTEST_INTERVAL}")
|
||||||
|
|
||||||
# Serve p2w endpoint
|
# Serve p2w endpoint
|
||||||
|
@ -184,27 +142,17 @@ seqno_regex = re.compile(r"^Sequence number: (\d+)")
|
||||||
|
|
||||||
nonce = 1
|
nonce = 1
|
||||||
while True:
|
while True:
|
||||||
attest_result = run_or_die(
|
attest_result = run_or_die([
|
||||||
[
|
"pyth2wormhole-client",
|
||||||
"pyth2wormhole-client",
|
"--log-level", "4",
|
||||||
"--log-level",
|
"--p2w-addr", P2W_SOL_ADDRESS,
|
||||||
"4",
|
"--rpc-url", SOL_RPC_URL,
|
||||||
"--p2w-addr",
|
"--payer", P2W_OWNER_KEYPAIR,
|
||||||
P2W_ADDRESS,
|
"attest",
|
||||||
"--rpc-url",
|
"--price", PYTH_PRICE_ACCOUNT,
|
||||||
SOL_RPC_URL,
|
"--product", PYTH_PRODUCT_ACCOUNT,
|
||||||
"--payer",
|
"--nonce", str(nonce),
|
||||||
P2W_OWNER_KEYPAIR,
|
], capture_output=True)
|
||||||
"attest",
|
|
||||||
"--price",
|
|
||||||
price_addr,
|
|
||||||
"--product",
|
|
||||||
product_addr,
|
|
||||||
"--nonce",
|
|
||||||
str(nonce),
|
|
||||||
],
|
|
||||||
capture_output=True,
|
|
||||||
)
|
|
||||||
matches = seqno_regex.match(attest_result.stdout)
|
matches = seqno_regex.match(attest_result.stdout)
|
||||||
|
|
||||||
if matches is not None:
|
if matches is not None:
|
||||||
|
|
Loading…
Reference in New Issue