Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: band price feed mock #9

Merged
merged 6 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
659 changes: 486 additions & 173 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions contracts/price-feed/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --lib --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example schema"
64 changes: 64 additions & 0 deletions contracts/price-feed/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[package]
name = "neutron-price-feed-mock"
version = "0.1.0"
authors = ["nhpd <dmitry.klpv@gmail.com>"]
edition = "2021"

exclude = [
"contract.wasm",
"hash.txt",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false
overflow-checks = true

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.12.6
"""

[dependencies]

cosmwasm-schema = "1.2.1"
cosmwasm-std = "1.2.1"
cosmwasm-storage = "1.1.3"
cw-storage-plus = "1.0.1"
cw2 = "1.0.1"
cw-band = "0.1.1"
neutron-sdk = { git = "https://github.com/neutron-org/neutron-sdk", default-features = false, version = "0.1.0"}
base64 = "0.21.0"
protobuf = { version = "3.2.0", features = ["with-bytes"] }
prost = "0.11"
prost-types = "0.11"
schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
cosmos-sdk-proto = { version = "0.16.0", default-features = false }
thiserror = { version = "1.0.31" }
obi = "0.0.2"
owasm-kit = "0.3.0"
strum = "0.24.1"
strum_macros = "0.24.3"

[dev-dependencies]
cw-multi-test = "0.16.2"
19 changes: 19 additions & 0 deletions contracts/price-feed/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use neutron_price_feed_mock::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use neutron_price_feed_mock::state::{PriceFeedRate, ReferenceData};

fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(PriceFeedRate), &out_dir);
export_schema(&schema_for!(ReferenceData), &out_dir);
}
148 changes: 148 additions & 0 deletions contracts/price-feed/hermes/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# This config is for connecting neutron-devnet-1 with band-laozi-testnet6

# The global section has parameters that apply globally to the relayer operation.
[global]

# Specify the verbosity for the relayer logging output. Default: 'info'
# Valid options are 'error', 'warn', 'info', 'debug', 'trace'.
log_level = 'trace'

# Specify the mode to be used by the relayer. [Required]
[mode]

# Specify the client mode.
[mode.clients]

# Whether or not to enable the client workers. [Required]
enabled = true

# Whether or not to enable periodic refresh of clients. [Default: true]
# Note: Even if this is disabled, clients will be refreshed automatically if
# there is activity on a connection or channel they are involved with.
refresh = true

# Whether or not to enable misbehaviour detection for clients. [Default: false]
misbehaviour = true

# Specify the connections mode.
[mode.connections]

# Whether or not to enable the connection workers for handshake completion. [Required]
enabled = true

# Specify the channels mode.
[mode.channels]

# Whether or not to enable the channel workers for handshake completion. [Required]
enabled = true

# Specify the packets mode.
[mode.packets]

# Whether or not to enable the packet workers. [Required]
enabled = true

# Parametrize the periodic packet clearing feature.
# Interval (in number of blocks) at which pending packets
# should be eagerly cleared. A value of '0' will disable
# periodic packet clearing. [Default: 100]
clear_interval = 100

# Whether or not to clear packets on start. [Default: false]
clear_on_start = true

# Toggle the transaction confirmation mechanism.
# The tx confirmation mechanism periodically queries the `/tx_search` RPC
# endpoint to check that previously-submitted transactions
# (to any chain in this config file) have delivered successfully.
# Experimental feature. Affects telemetry if set to false.
# [Default: true]
tx_confirmation = true

# The REST section defines parameters for Hermes' built-in RESTful API.
# https://hermes.informal.systems/rest.html
[rest]

# Whether or not to enable the REST service. Default: false
enabled = true

# Specify the IPv4/6 host over which the built-in HTTP server will serve the RESTful
# API requests. Default: 127.0.0.1
host = '127.0.0.1'

# Specify the port over which the built-in HTTP server will serve the restful API
# requests. Default: 3000
port = 3000


# The telemetry section defines parameters for Hermes' built-in telemetry capabilities.
# https://hermes.informal.systems/telemetry.html
[telemetry]

# Whether or not to enable the telemetry service. Default: false
enabled = false

# Specify the IPv4/6 host over which the built-in HTTP server will serve the metrics
# gathered by the telemetry service. Default: 127.0.0.1
host = '127.0.0.1'

# Specify the port over which the built-in HTTP server will serve the metrics gathered
# by the telemetry service. Default: 3001
port = 3001

[[chains]]
id = 'baryon-1'
rpc_addr = 'https://rpc.baryon.ntrn.info'
grpc_addr = 'http://grpc.baryon.ntrn.info:80'
websocket_addr = 'wss://rpc.baryon.ntrn.info/websocket'
rpc_timeout = '10s'
account_prefix = 'neutron'
key_name = 'neutron-ibc-relayer'
store_prefix = 'ibc'
default_gas = 5000000
max_gas = 15000000
gas_price = { price = 0.004, denom = 'untrn' }
gas_multiplier = 1.1
max_msg_num = 30
max_tx_size = 2097152
clock_drift = '20s'
max_block_time = '10s'
trusting_period = '14days'
unbonding_period = '20days'
trust_threshold = { numerator = '1', denominator = '3' }
address_type = { derivation = 'cosmos' }

[chains.packet_filter]
policy = 'allow'
list = [
['wasm.neutron10xfkreu04sazan0lf3ujcsx5qnnupvqw0r8umyrhxcl7qtveduysvq5x3h', 'channel-27'],
]


[[chains]]
id = 'laozi-mainnet'
rpc_addr = 'http://rpc.laozi1.bandchain.org:80/'
grpc_addr = 'https://laozi1.bandchain.org'
websocket_addr = 'ws://rpc.laozi1.bandchain.org/websocket'
rpc_timeout = '10s'
account_prefix = 'band'
key_name = 'band-laozi'
store_prefix = 'ibc'
default_gas = 100000
max_gas = 15000000
gas_price = { price = 0.0025, denom = 'uband' }
gas_multiplier = 1.1
max_msg_num = 30
max_tx_size = 180000
clock_drift = '5s'
max_block_time = '10s'
# TODO: what's the correct period?
trusting_period = '14days'
trust_threshold = { numerator = '1', denominator = '3' }
address_type = { derivation = 'cosmos' }

[chains.packet_filter]
policy = 'allow'
list = [
['oracle', 'channel=channel-132'],
]
4 changes: 4 additions & 0 deletions contracts/price-feed/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# stable
newline_style = "unix"
hard_tabs = false
tab_spaces = 4
70 changes: 70 additions & 0 deletions contracts/price-feed/schema/execute_msg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"oneOf": [
{
"type": "object",
"required": [
"request"
],
"properties": {
"request": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"set_rate"
],
"properties": {
"set_rate": {
"type": "object",
"required": [
"rate",
"symbol"
],
"properties": {
"rate": {
"$ref": "#/definitions/PriceFeedRate"
},
"symbol": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"definitions": {
"PriceFeedRate": {
"type": "object",
"required": [
"rate",
"request_id",
"resolve_time"
],
"properties": {
"rate": {
"$ref": "#/definitions/Uint64"
},
"request_id": {
"$ref": "#/definitions/Uint64"
},
"resolve_time": {
"$ref": "#/definitions/Uint64"
}
},
"additionalProperties": false
},
"Uint64": {
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
"type": "string"
}
}
}
6 changes: 6 additions & 0 deletions contracts/price-feed/schema/instantiate_msg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"additionalProperties": false
}
28 changes: 28 additions & 0 deletions contracts/price-feed/schema/price_feed_rate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "PriceFeedRate",
"type": "object",
"required": [
"rate",
"request_id",
"resolve_time"
],
"properties": {
"rate": {
"$ref": "#/definitions/Uint64"
},
"request_id": {
"$ref": "#/definitions/Uint64"
},
"resolve_time": {
"$ref": "#/definitions/Uint64"
}
},
"additionalProperties": false,
"definitions": {
"Uint64": {
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
"type": "string"
}
}
}
32 changes: 32 additions & 0 deletions contracts/price-feed/schema/query_msg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"oneOf": [
{
"type": "object",
"required": [
"get_error"
],
"properties": {
"get_error": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"get_rate"
],
"properties": {
"get_rate": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
Loading