8000 sSCRT staking by DrPresident · Pull Request #120 · securesecrets/shade · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sSCRT staking #120

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

Merged
merged 16 commits into from
Oct 30, 2021
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
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "contracts/snip20"]
path = contracts/snip20
url = git@github.com:enigmampc/snip20-reference-impl.git
branch = master
Empty file removed Cargo.lock
Empty file.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"contracts/treasury",
"contracts/oracle",
"contracts/snip20",
"contracts/scrt_staking",

# Mock contracts
"contracts/mock_band",
Expand Down
4 changes: 2 additions & 2 deletions contractlib/secretlib/secretlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def list_contract_by_code(code):


def execute_contract(contract, msg, user='a', backend='test', amount=None, compute=True):
command = ['secretcli', 'tx', 'compute', 'execute', contract, msg, '--from', user, '--gas', GAS, '-y']
command = ['secretcli', 'tx', 'compute', 'execute', contract, json.dumps(msg), '--from', user, '--gas', GAS, '-y']

if backend is not None:
command += ['--keyring-backend', backend]
Expand All @@ -108,7 +108,7 @@ def compute_hash(hash):


def query_contract(contract, msg):
command = ['secretcli', 'query', 'compute', 'query', contract, msg]
command = ['secretcli', 'query', 'compute', 'query', contract, json.dumps(msg)]
out = run_command(command)
try:
return json.loads(out)
Expand Down
5 changes: 5 additions & 0 deletions contracts/scrt_staking/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
unit-test = "test --lib --features backtraces"
integration-test = "test --test integration"
schema = "run --example schema"
52 changes: 52 additions & 0 deletions contracts/scrt_staking/.circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: 2.1

jobs:
build:
docker:
- image: rust:1.43.1
steps:
- checkout
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
- run:
name: Add wasm32 target
command: rustup target add wasm32-unknown-unknown
- run:
name: Build
command: cargo wasm --locked
- run:
name: Unit tests
env: RUST_BACKTRACE=1
command: cargo unit-test --locked
- run:
name: Integration tests
command: cargo integration-test --locked
- run:
name: Format source code
command: cargo fmt
- run:
name: Build and run schema generator
command: cargo schema --locked
- run:
name: Ensure checked-in source code and schemas are up-to-date
command: |
CHANGES_IN_REPO=$(git status --porcelain)
if [[ -n "$CHANGES_IN_REPO" ]]; then
echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:"
git status && git --no-pager diff
exit 1
fi
- save_cache:
paths:
- /usr/local/cargo/registry
- target/debug/.fingerprint
- target/debug/build
- target/debug/deps
- target/wasm32-unknown-unknown/release/.fingerprint
- target/wasm32-unknown-unknown/release/build
- target/wasm32-unknown-unknown/release/deps
key: v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
45 changes: 45 additions & 0 deletions contracts/scrt_staking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "scrt_staking"
version = "0.1.0"
authors = ["Jack Swenson <jacksonswenson22@gmail.com>"]
edition = "2018"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"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]
default = []
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
debug-print = ["cosmwasm-std/debug-print"]

[dependencies]
cosmwasm-schema = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print" }
cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print", features = ["staking"] }

cosmwasm-storage = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print" }
secret-toolkit = { git = "https://github.com/enigmampc/secret-toolkit", branch = "debug-print"}
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
68 changes: 68 additions & 0 deletions contracts/scrt_staking/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.PHONY: check
check:
cargo check

.PHONY: clippy
clippy:
cargo clippy

PHONY: test
test: unit-test

.PHONY: unit-test
unit-test:
cargo test

# This is a local build with debug-prints activated. Debug prints only show up
# in the local development chain (see the `start-server` command below)
# and mainnet won't accept contracts built with the feature enabled.
.PHONY: build _build
build: _build compress-wasm
_build:
RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --features="debug-print"

# This is a build suitable for uploading to mainnet.
# Calls to `debug_print` get removed by the compiler.
.PHONY: build-mainnet _build-mainnet
build-mainnet: _build-mainnet compress-wasm
_build-mainnet:
RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown

# like build-mainnet, but slower and more deterministic
.PHONY: build-mainnet-reproducible
build-mainnet-reproducible:
docker run --rm -v "$$(pwd)":/contract \
--mount type=volume,source="$$(basename "$$(pwd)")_cache",target=/contract/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
enigmampc/secret-contract-optimizer:1.0.3

.PHONY: compress-wasm
compress-wasm:
cp ./target/wasm32-unknown-unknown/release/*.wasm ./contract.wasm
@## The following line is not necessary, may work only on linux (extra size optimization)
@# wasm-opt -Os ./contract.wasm -o ./contract.wasm
cat ./contract.wasm | gzip -9 > ./contract.wasm.gz

.PHONY: schema
schema:
cargo run --example schema

# Run local development chain with four funded accounts (named a, b, c, and d)
.PHONY: start-server
start-server: # CTRL+C to stop
docker run -it --rm \
-p 26657:26657 -p 26656:26656 -p 1317:1317 \
-v $$(pwd):/root/code \
--name secretdev enigmampc/secret-network-sw-dev:v1.0.4-3

# This relies on running `start-server` in another console
# You can run other commands on the secretcli inside the dev image
# by using `docker exec secretdev secretcli`.
.PHONY: store-contract-local
store-contract-local:
docker exec secretdev secretcli tx compute store -y --from a --gas 1000000 /root/code/contract.wasm.gz

.PHONY: clean
clean:
cargo clean
-rm -f ./contract.wasm ./contract.wasm.gz
65 changes: 65 additions & 0 deletions contracts/scrt_staking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# sSCRT Staking Contract
* [Introduction](#Introduction)
* [Sections](#Sections)
* [Init](#Init)
* [Admin](#Admin)
* Messages< 10000 /td>
* [UpdateConfig](#UpdateConfig)
* [Receive](#Receive)
* [Unbond](#Unbond)
* [Claim](#Claim)
* Queries
* [GetConfig](#GetConfig)
* [Delegations](#Delegations)
* [Delegation](#Delegation)
# Introduction
The sSCRT Staking contract receives sSCRT, redeems it for SCRT, then stakes it with a validator that falls within the criteria it has been configured with. The configured `treasury` will receive all funds from claiming rewards/unbonding.

# Sections

## Init
##### Request
|Name |Type |Description | optional |
|----------|----------|-------------------------------------------------------------------------------------------------------------------|----------|
|owner | HumanAddr | contract owner/admin; a valid bech32 address;
|treasury | HumanAddre | contract designated to receive all outgoing funds
|sscrt | Contract | sSCRT Snip-20 contract to accept for redemption/staking, all other funds will error
|validator_bounds | ValidatorBounds | criteria defining an acceptable validator to stake with

## Admin

### Messages
#### UpdateConfig
Updates the given values
##### Request
|Name |Type |Description | optional |
|----------|----------|-------------------------------------------------------------------------------------------------------------------|----------|
|owner | HumanAddr | contract owner/admin; a valid bech32 address;
|treasury | HumanAddre | contract designated to receive all outgoing funds
|sscrt | Contract | sSCRT Snip-20 contract to accept for redemption/staking, all other funds will error
|validator_bounds | ValidatorBounds | criteria defining an acceptable validator to stake with

##### Response
```json
{
"update_config": {
"status": "success"
}
}
```


### Queries

#### GetConfig
Gets the contract's configuration variables
##### Response
```json
{
"config": {
"config": {
"owner": "Owner address",
}
}
}
```
15 changes: 15 additions & 0 deletions contracts/scrt_staking/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# stable
newline_style = "unix"
hard_tabs = false
tab_spaces = 4

# unstable... should we require `rustup run nightly cargo fmt` ?
# or just update the style guide when they are stable?
#fn_single_line = true
#format_code_in_doc_comments = true
#overflow_delimited_expr = true
#reorder_impl_items = true
#struct_field_align_threshold = 20
#struct_lit_single_line = true
#report_todo = "Always"

Loading
0