Skip to content

Commit 319be8e

Browse files
authored
refactor(x/oracle): move to time based prices (#2060)
Signed-off-by: Artur Troian <troian@users.noreply.github.com> Co-authored-by: Artur Troian <troian@users.noreply.github.com>
1 parent 5505bfd commit 319be8e

71 files changed

Lines changed: 1881 additions & 1497 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
sudo rm -rf .cache/goreleaser
3838
make release
3939
env:
40-
GORELEASER_RELEASE: true
40+
BUILDOPTS: release
4141
GORELEASER_MOUNT_CONFIG: true
4242
# using PAT as homebrew is located in different repo
4343
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,11 @@ release:
215215
prerelease: auto
216216
mode: replace
217217
draft: false
218+
219+
changelog:
220+
use: github
221+
sort: asc
222+
filters:
223+
exclude:
224+
- "^docs:"
225+
- "^test:"

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ members = [
99
version = "0.0.1"
1010
authors = ["Artur Troian <troian.ap@gmail.com>"]
1111
edition = "2021"
12-
rust-version = "1.93.0"
12+
rust-version = "1.86.0"
1313

1414
[profile.release]
1515
opt-level = 3

_docs/pyth-integration.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,12 @@ cat > oracle-params-proposal.json << 'EOF'
693693
"summary": "Add the pyth contract address to authorized sources and configure oracle parameters for Pyth integration.",
694694
"messages": [
695695
{
696-
"@type": "/akash.oracle.v1.MsgUpdateParams",
696+
"@type": "/akash.oracle.v2.MsgUpdateParams",
697697
"authority": "akash10d07y265gmmuvt4z0w9aw880jnsr700jhe7z0f",
698698
"params": {
699699
"sources": ["<pyth-contract-address>"],
700700
"min_price_sources": 1,
701-
"max_price_staleness_blocks": 60,
701+
"max_price_staleness_period": 60,
702702
"twap_window": 180,
703703
"max_price_deviation_bps": 150,
704704
"feed_contracts_params": [
@@ -734,7 +734,7 @@ akash tx gov submit-proposal oracle-params-proposal.json \
734734
|------------------------------|----------|----------------------------------|-----------------|
735735
| `sources` | []String | Authorized contract addresses | `[]` |
736736
| `min_price_sources` | u32 | Minimum sources for valid price | `1` |
737-
| `max_price_staleness_blocks` | i64 | Max age in blocks (~6s/block) | `60` (~6 min) |
737+
| `max_price_staleness_period` | i64 | Max age in seconds (~6s/block) | `60` |
738738
| `twap_window` | i64 | TWAP calculation window (blocks) | `180` (~18 min) |
739739
| `max_price_deviation_bps` | u64 | Max deviation in basis points | `150` (1.5%) |
740740

@@ -757,7 +757,7 @@ cat > guardian-update-proposal.json << 'EOF'
757757
"summary": "Update guardian addresses to Wormhole Guardian Set 5",
758758
"messages": [
759759
{
760-
"@type": "/akash.oracle.v1.MsgUpdateParams",
760+
"@type": "/akash.oracle.v2.MsgUpdateParams",
761761
"authority": "akash10d07y265gmmuvt4z0w9aw880jnsr700jhe7z0f",
762762
"params": {
763763
"feed_contracts_params": [
@@ -885,7 +885,7 @@ journalctl -u hermes-client -f
885885
|----------------------------------|-----------------------------------|---------------------------------------------------------------|
886886
| `Unsupported query type: custom` | Node missing custom Akash querier | Upgrade to node v2.x+ with custom querier support |
887887
| `unauthorized oracle provider` | Contract not in `sources` param | Add contract address via governance proposal |
888-
| `price timestamp is too old` | Stale price data | Submit fresher price update or increase `staleness_threshold` |
888+
| `price timestamp is too old` | Stale price data | Submit fresher price update or increase `max_price_staleness_period` |
889889
| `VAA verification failed` | Invalid guardian signatures | Verify guardian set matches current Wormhole mainnet |
890890
| `source not authorized` | Missing from oracle sources | Update oracle params via governance |
891891
| `price timestamp is from future` | Clock skew | Check publisher/relayer clock synchronization |

_run/init.sh

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ configure_genesis() {
100100
done
101101
guardian_json+="]"
102102

103+
# shellcheck disable=SC2002
103104
cat "${GENESIS_PATH}.orig" | \
104105
jq -M '.app_state.gov.voting_params.voting_period = "60s"' \
105106
| jq -M '.app_state.gov.params.voting_period = "60s"' \
@@ -109,9 +110,12 @@ configure_genesis() {
109110
| jq -M '.app_state.wasm.params.instantiate_default_permission = "Everybody"' \
110111
| jq -M --argjson guardians "$guardian_json" --arg feed_id "$AKT_PRICE_FEED_ID" '
111112
.app_state.oracle.params.min_price_sources = 1 |
112-
.app_state.oracle.params.max_price_staleness_blocks = 100 |
113-
.app_state.oracle.params.twap_window = 50 |
114-
.app_state.oracle.params.max_price_deviation_bps = 1000' \
113+
.app_state.oracle.params.max_price_staleness_period = "60s" |
114+
.app_state.oracle.params.twap_window = "30s" |
115+
.app_state.oracle.params.max_price_deviation_bps = 1000 |
116+
.app_state.oracle.params.price_retention = "86400s" |
117+
.app_state.oracle.params.prune_epoch = "hour" |
118+
.app_state.oracle.params.max_prune_per_epoch = 1000' \
115119
> "${GENESIS_PATH}"
116120

117121
log "Genesis configuration complete"
@@ -236,7 +240,7 @@ EOF
236240
{
237241
"admin": "$admin_addr",
238242
"wormhole_contract": "$wormhole_addr",
239-
"update_fee": "1000000",
243+
"update_fee": "1000",
240244
"price_feed_id": "$AKT_PRICE_FEED_ID",
241245
"data_sources": [
242246
{
@@ -258,8 +262,8 @@ EOF
258262
pyth_addr=$(akash query wasm list-contract-by-code "$pyth_code_id" -o json | jq -r '.contracts[-1]')
259263
log "Pyth contract address: $pyth_addr"
260264

261-
# Register Pyth as authorized oracle source
262-
register_oracle_source "$pyth_addr"
265+
# Register Pyth as authorized oracle source and fund BME vault via gov proposal
266+
register_oracle_source "$pyth_addr" "$admin_addr"
263267

264268
# Write configuration for Hermes
265269
write_hermes_config "$pyth_addr"
@@ -271,37 +275,37 @@ EOF
271275

272276
register_oracle_source() {
273277
local pyth_addr=$1
274-
log "Registering Pyth contract as authorized oracle source..."
278+
local admin_addr=$2
279+
log "Registering Pyth contract as authorized oracle source and funding BME vault..."
275280

276-
# Build guardian addresses JSON array for the proposal
277-
local guardian_json="["
278-
for i in "${!GUARDIAN_ADDRESSES[@]}"; do
279-
if [ "$i" -gt 0 ]; then
280-
guardian_json+=","
281-
fi
282-
guardian_json+="\"${GUARDIAN_ADDRESSES[$i]}\""
283-
done
284-
guardian_json+="]"
285-
286-
# Create proposal JSON
281+
# Create proposal JSON with both oracle params and BME vault funding
287282
cat > /tmp/oracle-params.json <<EOF
288283
{
289284
"messages": [
290285
{
291-
"@type": "/akash.oracle.v1.MsgUpdateParams",
286+
"@type": "/akash.oracle.v2.MsgUpdateParams",
292287
"authority": "akash10d07y265gmmuvt4z0w9aw880jnsr700jhe7z0f",
293288
"params": {
294289
"sources": ["$pyth_addr"],
295290
"min_price_sources": 1,
296-
"max_price_staleness_blocks": 100,
297-
"twap_window": 50,
298-
"max_price_deviation_bps": 1000
291+
"max_price_staleness_period": "60s",
292+
"twap_window": "30s",
293+
"max_price_deviation_bps": 1000,
294+
"price_retention": "86400s",
295+
"prune_epoch": "hour",
296+
"max_prune_per_epoch": 1000
299297
}
298+
},
299+
{
300+
"@type": "/akash.bme.v1.MsgFundVault",
301+
"authority": "akash10d07y265gmmuvt4z0w9aw880jnsr700jhe7z0f",
302+
"amount": {"denom": "${CHAIN_TOKEN_DENOM}", "amount": "1000000000000"},
303+
"source": "$(akash keys show main -a)"
300304
}
301305
],
302306
"deposit": "10000000uakt",
303-
"title": "Register Pyth Contract",
304-
"summary": "Authorize pyth contract as oracle source"
307+
"title": "Register Pyth Contract and Fund BME Vault",
308+
"summary": "Authorize pyth contract as oracle source and seed BME vault with initial AKT"
305309
}
306310
EOF
307311

_run/node/deployment.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ profiles:
4040
attributes:
4141
region: us-west
4242
pricing:
43-
web:
44-
denom: uakt
43+
web:
44+
denom: uact
4545
amount: 1000
4646

4747
deployment:
@@ -52,4 +52,4 @@ deployment:
5252
bew:
5353
westcoast:
5454
profile: web
55-
count: 1
55+
count: 1

_run/node/price-feeder.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
set -euo pipefail
1111

1212
# Configuration
13-
AKASH_CHAIN_ID="${AKASH_CHAIN_ID:=testnet-8}"
14-
AKASH_NODE="${AKASH_NODE:=https://testnetrpc.akashnet.net:443}"
13+
AKASH_CHAIN_ID="${AKASH_CHAIN_ID:=local}"
14+
#AKASH_NODE="${AKASH_NODE:=https://testnetrpc.akashnet.net:443}"
1515
AKASH_KEYRING_BACKEND="${AKASH_KEYRING_BACKEND:=test}"
16-
AKASH_FROM="${AKASH_FROM:=price-feeder}"
16+
AKASH_FROM="${AKASH_FROM:=hermes}"
1717
UPDATE_INTERVAL=10 # seconds between updates
1818

1919
# Pyth configuration
@@ -77,7 +77,7 @@ check_balance() {
7777
local balance
7878

7979
address=$(akash keys show "$AKASH_FROM" -a )
80-
balance=$(akash query bank balances "$address" -o json 2>/dev/null | jq -r '.balances[] | select(.denom=="uakt") | .amount // "0"')
80+
balance=$(akash query bank balances "$address" -o json 2>/dev/null | jq -r '.balances[] | select(.denom=="akt") | .amount // "0"')
8181

8282
if [ -z "$balance" ] || [ "$balance" -lt 100000 ]; then
8383
log "WARN" "Low balance: ${balance:-0}uakt (recommend >100000uakt for gas)"
@@ -143,6 +143,7 @@ submit_price_to_oracle() {
143143
--gas-adjustment 1.5 \
144144
--gas-prices 0.025uakt \
145145
--yes \
146+
--from="${AKASH_FROM}" \
146147
-o json 2>&1)
147148

148149
local exit_code=$?

_run/node/prop.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
{
22
"messages": [
33
{
4-
"@type": "/akash.oracle.v1.MsgUpdateParams",
4+
"@type": "/akash.oracle.v2.MsgUpdateParams",
55
"authority": "akash10d07y265gmmuvt4z0w9aw880jnsr700jhe7z0f",
66
"params": {
77
"sources": [
8-
"akash1xcfl5u6g2yprvpr4q8j2pp5h6l5ys3nuf529qa"
8+
"akash1kwngmq9s7mfs6x7aes5t0jcm5yvmd7367jm3ke"
99
],
1010
"min_price_sources": 1,
11-
"max_price_staleness_blocks": "60",
12-
"twap_window": "50",
13-
"max_price_deviation_bps": "150",
14-
"feed_contracts_params": [
15-
{
16-
"@type": "/akash.oracle.v1.PythContractParams",
17-
"akt_price_feed_id": "0x4ea5bb4d2f5900cc2e97ba534240950740b4d3b89fe712a94a7304fd2fd92702"
18-
}
19-
]
11+
"max_price_staleness_period": "60s",
12+
"twap_window": "30s",
13+
"max_price_deviation_bps": "1000",
14+
"feed_contracts_params": [],
15+
"price_retention": "86400s",
16+
"prune_epoch": "hour",
17+
"max_prune_per_epoch": "1000",
18+
"max_future_time_drift": "10s"
2019
}
2120
}
2221
],

app/ante.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
5353
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
5454
ante.NewValidateSigCountDecorator(options.AccountKeeper),
5555
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
56-
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
56+
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler, options.SigVerifyOptions...),
5757
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
5858
}
5959

0 commit comments

Comments
 (0)