Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

draft-delegator-incentive-contract #90

Merged
merged 16 commits into from
Nov 21, 2022
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
64 changes: 47 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ workflows:
- contract_nois_demo
- contract_nois_proxy
- contract_nois_oracle
- contract_nois_delegator
- package_nois_protocol
- lint
- wasm-build
Expand All @@ -18,6 +19,7 @@ workflows:
- contract_nois_demo
- contract_nois_proxy
- contract_nois_oracle
- contract_nois_delegator
deploy:
jobs:
- build_and_upload_contracts:
Expand All @@ -36,7 +38,7 @@ workflows:
jobs:
contract_nois_demo:
docker:
- image: rust:1.63.0
- image: rust:1.65.0
working_directory: ~/project/contracts/nois-demo
steps:
- checkout:
Expand All @@ -46,7 +48,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-nois-demo-rust:1.63.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-nois-demo-rust:1.65.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
Expand All @@ -59,11 +61,11 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-nois-demo-rust:1.63.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-nois-demo-rust:1.65.0-{{ checksum "~/project/Cargo.lock" }}

contract_nois_proxy:
docker:
- image: rust:1.63.0
- image: rust:1.65.0
working_directory: ~/project/contracts/nois-proxy
steps:
- checkout:
Expand All @@ -73,7 +75,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-nois-proxy-rust:1.63.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-nois-proxy-rust:1.65.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
Expand All @@ -86,11 +88,11 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-nois-proxy-rust:1.63.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-nois-proxy-rust:1.65.0-{{ checksum "~/project/Cargo.lock" }}

contract_nois_oracle:
docker:
- image: rust:1.63.0
- image: rust:1.65.0
working_directory: ~/project/contracts/nois-oracle
steps:
- checkout:
Expand All @@ -100,7 +102,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-nois-oracle-rust:1.63.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-nois-oracle-rust:1.65.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
Expand All @@ -113,11 +115,38 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-nois-oracle-rust:1.63.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-nois-oracle-rust:1.65.0-{{ checksum "~/project/Cargo.lock" }}

contract_nois_delegator:
docker:
- image: rust:1.65.0
working_directory: ~/project/contracts/nois-delegator
steps:
- checkout:
path: ~/project
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-nois-delegator-rust:1.65.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
RUST_BACKTRACE: 1
command: cargo unit-test --locked
- run:
name: Build and run schema generator
command: cargo schema --locked
- save_cache:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-nois-delegator-rust:1.65.0-{{ checksum "~/project/Cargo.lock" }}

package_nois_protocol:
docker:
- image: rust:1.63.0
- image: rust:1.65.0
working_directory: ~/project/packages/nois-protocol
steps:
- checkout:
Expand All @@ -142,15 +171,15 @@ jobs:

lint:
docker:
- image: rust:1.63.0
- image: rust:1.65.0
steps:
- checkout
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version; rustup target list --installed
- restore_cache:
keys:
- cargocache-v2-lint-rust:1.63.0-{{ checksum "Cargo.lock" }}
- cargocache-v2-lint-rust:1.65.0-{{ checksum "Cargo.lock" }}
- run:
name: Add rustfmt component
command: rustup component add rustfmt
Expand All @@ -169,15 +198,15 @@ jobs:
- target/debug/.fingerprint
- target/debug/build
- target/debug/deps
key: cargocache-v2-lint-rust:1.63.0-{{ checksum "Cargo.lock" }}
key: cargocache-v2-lint-rust:1.65.0-{{ checksum "Cargo.lock" }}

# This runs one time on the top level to ensure all contracts compile properly into wasm.
# We don't run the wasm build per contract build, and then reuse a lot of the same dependencies, so this speeds up CI time
# for all the other tests.
# Resulting wasm files are stored to the workspace, so they can be used by the integration test downstream
wasm-build:
docker:
- image: rust:1.63.0
- image: rust:1.65.0
steps:
- checkout:
path: ~/project
Expand All @@ -186,7 +215,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-wasm-rust:1.63.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-wasm-rust:1.65.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Add wasm32 target
command: rustup target add wasm32-unknown-unknown
Expand All @@ -202,14 +231,15 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-wasm-rust:1.63.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-wasm-rust:1.65.0-{{ checksum "~/project/Cargo.lock" }}
- persist_to_workspace:
name: Save wasm contracts for integration test usage
root: ./target/wasm32-unknown-unknown/release
paths:
- nois_demo.wasm
- nois_proxy.wasm
- nois_oracle.wasm
- nois_delegator.wasm

ts-build:
docker:
Expand Down Expand Up @@ -349,7 +379,7 @@ jobs:

build_and_upload_schemas:
docker:
- image: rust:1.63.0
- image: rust:1.65.0
working_directory: ~/project
steps:
- checkout:
Expand Down
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ There are two CosmWasm-enabled blockchains running locally.
## The contracts

- nois-oracle (runs on the randomness chain; one instance globally)
- nois-oracle is the entrypoint to the randomness beacon coming from drand through the drand bots.
- it verifies the randomness before it is stored on chain.
- it initiates the callback messages to consumer DAPPS on randomness consumer chains (juno, stargaze ...) whenever the randomness is available. this callback is sent to the nois-proxy which is deployed on the consumer chain.
- nois-delegator (runs on the randomness chain; one instance globally)
- nois-delegator gets called by nois-oracle to incentivise the fast drand bots upon submissions of the randomness.
- it has an initial nois coin supply that an admin multisig can delegate, unbond or redelegate but cannot withdraw.
- nois-proxy (runs on the app chain; one instance per app chain)
- nois-proxy receives randomness requests from the consumer DAPPs and submits those requests to the nois chain via IBC.
- Once the randomness is available, the nois-proxy receives a callback and forwards it to the DAPP
- nois-demo (runs on the app chain; a demo app)
- nois-demo is a demo/example consumer app used as a test to estimate the value of pi.
- it submits a request to the proxy to get randomness.
- The randomness is then received to the nois-demo as a callback.

The IBC interaction is only between nois-oracle and nois-proxy, such that
the user (nois-demo) does not need to worry about that part.
Expand Down
5 changes: 5 additions & 0 deletions contracts/nois-delegator/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example schema"
38 changes: 38 additions & 0 deletions contracts/nois-delegator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "nois-delegator"
version = "0.7.2"
authors = []
edition = "2021"
publish = false
license = "Apache-2.0"

# 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 quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]

[dependencies]
cosmwasm-std = { version = "1.1.5", features = ["staking"] }
cosmwasm-schema = { version = "1.1.5" }
cw-storage-plus = { version = "0.16.0" }
schemars = "0.8.10"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.23" }

[dev-dependencies]
1 change: 1 addition & 0 deletions contracts/nois-delegator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Nois Delegator
11 changes: 11 additions & 0 deletions contracts/nois-delegator/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cosmwasm_schema::write_api;

use nois_delegator::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
query: QueryMsg,
execute: ExecuteMsg,
}
}
Loading