Skip to content

Commit 457cdc5

Browse files
committed
refactor(contracts): split upgraded pyth contracts
Adds pyth-vaa for router-signed VAA verification and pyth-pro for price feed updates. This keeps existing pyth and wormhole contracts unchanged while giving the upgraded Pyth deployment fresh contract names. pyth-pro queries pyth-vaa for VerifyVAA, then validates the PNAU Merkle proof and relays the AKT/USD price to x/oracle. The local deployment script stores pyth-vaa before pyth-pro and registers pyth-pro as the oracle source. Signed-off-by: Joseph Chalabi <chalabi.joseph@gmail.com>
1 parent 3f952dc commit 457cdc5

32 files changed

Lines changed: 2997 additions & 437 deletions

Cargo.lock

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ resolver = "2"
33
members = [
44
"contracts/wormhole",
55
"contracts/pyth",
6+
"contracts/pyth-vaa",
7+
"contracts/pyth-pro",
68
]
79

810
[workspace.package]

_run/init.sh

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ if [[ -z "$CONTRACTS_DIR" ]]; then
2222
exit 1
2323
fi
2424

25-
PYTH_WASM="${CONTRACTS_DIR}/artifacts/pyth.wasm"
25+
PYTH_VAA_WASM="${CONTRACTS_DIR}/artifacts/pyth_vaa.wasm"
26+
PYTH_PRO_WASM="${CONTRACTS_DIR}/artifacts/pyth_pro.wasm"
2627

2728
HERMES_MNEMONIC="wire museum tragic inmate final lady illegal father whisper margin sea cool soul half moon nut tissue strategy ladder come glory opera device elbow"
2829

@@ -139,8 +140,15 @@ deploy_contracts() {
139140
admin_addr=$(akash keys show $admin_key -a)
140141

141142
# Check if contract files exist
142-
if [ ! -f "$PYTH_WASM" ]; then
143-
log "ERROR: Pyth contract not found at $PYTH_WASM"
143+
if [ ! -f "$PYTH_VAA_WASM" ]; then
144+
log "ERROR: Pyth VAA contract not found at $PYTH_VAA_WASM"
145+
log "Skipping contract deployment. Build contracts first with: cd contracts && make build"
146+
write_hermes_config "CONTRACT_NOT_DEPLOYED"
147+
return 1
148+
fi
149+
150+
if [ ! -f "$PYTH_PRO_WASM" ]; then
151+
log "ERROR: Pyth Pro contract not found at $PYTH_PRO_WASM"
144152
log "Skipping contract deployment. Build contracts first with: cd contracts && make build"
145153
write_hermes_config "CONTRACT_NOT_DEPLOYED"
146154
return 1
@@ -160,40 +168,66 @@ deploy_contracts() {
160168
local pyth_router_emitter_b64
161169
pyth_router_emitter_b64=$(hex_to_base64 "$PYTH_ROUTER_EXPECTED_EMITTER_ADDRESS")
162170

163-
# Deploy Pyth contract
164-
log "Storing Pyth contract..."
165-
akash tx wasm store "$PYTH_WASM" --from $admin_key
171+
# Deploy Pyth VAA verifier contract
172+
log "Storing Pyth VAA contract..."
173+
akash tx wasm store "$PYTH_VAA_WASM" --from $admin_key
166174

167-
local pyth_code_id
168-
pyth_code_id=$(akash query wasm list-code -o json | jq -r '.code_infos[-1].code_id')
169-
log "Pyth code ID: $pyth_code_id"
175+
local pyth_vaa_code_id
176+
pyth_vaa_code_id=$(akash query wasm list-code -o json | jq -r '.code_infos[-1].code_id')
177+
log "Pyth VAA code ID: $pyth_vaa_code_id"
170178

171-
# Instantiate Pyth contract
172-
local pyth_init_msg
173-
pyth_init_msg=$(cat <<EOF
179+
local pyth_vaa_init_msg
180+
pyth_vaa_init_msg=$(cat <<EOF
174181
{
175182
"admin": "$admin_addr",
176183
"router_verifier": {
177184
"router_set_index": $PYTH_ROUTER_SET_INDEX,
178185
"routers": $router_json,
179186
"expected_emitter_chain": $PYTH_ROUTER_EXPECTED_EMITTER_CHAIN,
180187
"expected_emitter_address": "$pyth_router_emitter_b64"
181-
},
188+
}
189+
}
190+
EOF
191+
)
192+
193+
log "Instantiating Pyth VAA contract..."
194+
akash tx wasm instantiate "$pyth_vaa_code_id" "$pyth_vaa_init_msg" \
195+
--label "pyth-vaa" \
196+
--admin "$admin_addr" \
197+
--from $admin_key
198+
199+
local pyth_vaa_addr
200+
pyth_vaa_addr=$(akash query wasm list-contract-by-code "$pyth_vaa_code_id" -o json | jq -r '.contracts[-1]')
201+
log "Pyth VAA contract address: $pyth_vaa_addr"
202+
203+
# Deploy Pyth Pro price-feed contract
204+
log "Storing Pyth Pro contract..."
205+
akash tx wasm store "$PYTH_PRO_WASM" --from $admin_key
206+
207+
local pyth_pro_code_id
208+
pyth_pro_code_id=$(akash query wasm list-code -o json | jq -r '.code_infos[-1].code_id')
209+
log "Pyth Pro code ID: $pyth_pro_code_id"
210+
211+
local pyth_pro_init_msg
212+
pyth_pro_init_msg=$(cat <<EOF
213+
{
214+
"admin": "$admin_addr",
215+
"pyth_vaa_contract": "$pyth_vaa_addr",
182216
"update_fee": "1000",
183217
"price_feed_id": "$AKT_PRICE_FEED_ID"
184218
}
185219
EOF
186220
)
187221

188-
log "Instantiating Pyth contract..."
189-
akash tx wasm instantiate "$pyth_code_id" "$pyth_init_msg" \
190-
--label "pyth" \
222+
log "Instantiating Pyth Pro contract..."
223+
akash tx wasm instantiate "$pyth_pro_code_id" "$pyth_pro_init_msg" \
224+
--label "pyth-pro" \
191225
--admin "$admin_addr" \
192226
--from $admin_key
193227

194228
local pyth_addr
195-
pyth_addr=$(akash query wasm list-contract-by-code "$pyth_code_id" -o json | jq -r '.contracts[-1]')
196-
log "Pyth contract address: $pyth_addr"
229+
pyth_addr=$(akash query wasm list-contract-by-code "$pyth_pro_code_id" -o json | jq -r '.contracts[-1]')
230+
log "Pyth Pro contract address: $pyth_addr"
197231

198232
# Register Pyth as authorized oracle source and fund BME vault via gov proposal
199233
register_oracle_source "$pyth_addr" "$admin_addr"
@@ -202,13 +236,14 @@ EOF
202236
write_hermes_config "$pyth_addr"
203237

204238
log "Contract deployment complete!"
205-
log " Pyth: $pyth_addr"
239+
log " Pyth VAA: $pyth_vaa_addr"
240+
log " Pyth Pro: $pyth_addr"
206241
}
207242

208243
register_oracle_source() {
209244
local pyth_addr=$1
210245
local admin_addr=$2
211-
log "Registering Pyth contract as authorized oracle source and funding BME vault..."
246+
log "Registering Pyth Pro contract as authorized oracle source and funding BME vault..."
212247

213248
# Create proposal JSON with both oracle params and BME vault funding
214249
cat > /tmp/oracle-params.json <<EOF
@@ -237,7 +272,7 @@ register_oracle_source() {
237272
],
238273
"deposit": "10000000uakt",
239274
"title": "Register Pyth Contract and Fund BME Vault",
240-
"summary": "Authorize pyth contract as oracle source and seed BME vault with initial AKT"
275+
"summary": "Authorize pyth-pro contract as oracle source and seed BME vault with initial AKT"
241276
}
242277
EOF
243278

contracts/pyth-pro/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "pyth-pro"
3+
version = "1.0.1"
4+
authors = ["Artur Troian <troian.ap@gmail.com"]
5+
edition = "2021"
6+
description = "Upgraded Pyth price feed consumer contract for Akash Network"
7+
license = "Apache-2.0"
8+
9+
[lib]
10+
crate-type = ["cdylib", "rlib"]
11+
12+
[features]
13+
default = []
14+
#backtraces = ["cosmwasm-std/backtraces"]
15+
library = []
16+
17+
[dependencies]
18+
cosmwasm-schema = "3.0.2"
19+
cosmwasm-std = { version = "3.0.2", features = ["cosmwasm_2_0"] }
20+
cw-storage-plus = "3.0.1"
21+
hex = "0.4"
22+
schemars = "0.8"
23+
serde = { version = "1.0", default-features = false, features = ["derive"] }
24+
sha3 = "0.10"
25+
thiserror = "1.0"
26+
27+
[dev-dependencies]
28+
cw-multi-test = "3.0.1"

0 commit comments

Comments
 (0)