Skip to content

Commit

Permalink
Merge pull request #3 from LoTerra/adapt-contract
Browse files Browse the repository at this point in the history
Adapt contract
  • Loading branch information
0xantman authored Apr 24, 2021
2 parents 991eae2 + 42d4e9b commit 8d6bab0
Show file tree
Hide file tree
Showing 20 changed files with 750 additions and 310 deletions.
4 changes: 4 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
unit-test = "test --lib --features backtraces"
schema = "run --example schema"
56 changes: 56 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: 2.1

jobs:
build:
docker:
- image: rust:1.44.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: Add fmt and clippy
command: rustup component add rustfmt clippy
- run:
name: Unit tests
env: RUST_BACKTRACE=1
command: cargo unit-test --locked
- run:
name: Format source code
command: cargo fmt -- --check
- run:
name: Lint
command: cargo clippy -- -D warnings
- run:
name: Build and run schema generator
command: cargo schema --locked
- run:
name: Build
command: cargo wasm --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" }}

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "loterra-staking-contract"
version = "0.1.0"
authors = ["MSNTCS <mohammad@terra.money>"]
authors = ["MSNTCS <mohammad@terra.money>", "0xantman <antho74830@gmail.com>"]
edition = "2018"

exclude = [
Expand Down
12 changes: 7 additions & 5 deletions examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use reward_querier::{
AccruedRewardsResponse, ConfigResponse, HandleMsg, HolderResponse, HoldersResponse, InitMsg,
QueryMsg, StateResponse,
};

use loterra_staking_contract::claim::*;
use loterra_staking_contract::msg::*;

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!(InitMsg), &out_dir);
export_schema(&schema_for!(HandleMsg), &out_dir);
export_schema(&schema_for!(InitMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(ConfigResponse), &out_dir);
export_schema(&schema_for!(StateResponse), &out_dir);
export_schema(&schema_for!(AccruedRewardsResponse), &out_dir);
export_schema(&schema_for!(HolderResponse), &out_dir);
export_schema(&schema_for!(HoldersResponse), &out_dir);
export_schema(&schema_for!(MigrateMsg), &out_dir);
export_schema(&schema_for!(Claim), &out_dir);
export_schema(&schema_for!(ClaimsResponse), &out_dir);
}
67 changes: 67 additions & 0 deletions schema/claim.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Claim",
"type": "object",
"required": [
"amount",
"release_at"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"release_at": {
"$ref": "#/definitions/Expiration"
}
},
"definitions": {
"Expiration": {
"description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)",
"anyOf": [
{
"description": "AtHeight will expire when `env.block.height` >= height",
"type": "object",
"required": [
"at_height"
],
"properties": {
"at_height": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
},
{
"description": "AtTime will expire when `env.block.time` >= time",
"type": "object",
"required": [
"at_time"
],
"properties": {
"at_time": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
},
{
"description": "Never will never expire. Used to express the empty variant",
"type": "object",
"required": [
"never"
],
"properties": {
"never": {
"type": "object"
}
}
}
]
},
"Uint128": {
"type": "string"
}
}
}
81 changes: 81 additions & 0 deletions schema/claims_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ClaimsResponse",
"type": "object",
"required": [
"claims"
],
"properties": {
"claims": {
"type": "array",
"items": {
"$ref": "#/definitions/Claim"
}
}
},
"definitions": {
"Claim": {
"type": "object",
"required": [
"amount",
"release_at"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"release_at": {
"$ref": "#/definitions/Expiration"
}
}
},
"Expiration": {
"description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)",
"anyOf": [
{
"description": "AtHeight will expire when `env.block.height` >= height",
"type": "object",
"required": [
"at_height"
],
"properties": {
"at_height": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
},
{
"description": "AtTime will expire when `env.block.time` >= time",
"type": "object",
"required": [
"at_time"
],
"properties": {
"at_time": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
},
{
"description": "Never will never expire. Used to express the empty variant",
"type": "object",
"required": [
"never"
],
"properties": {
"never": {
"type": "object"
}
}
}
]
},
"Uint128": {
"type": "string"
}
}
}
12 changes: 9 additions & 3 deletions schema/config_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
"title": "ConfigResponse",
"type": "object",
"required": [
"hub_contract",
"reward_denom"
"cw20_token_addr",
"reward_denom",
"unbonding_period"
],
"properties": {
"hub_contract": {
"cw20_token_addr": {
"$ref": "#/definitions/HumanAddr"
},
"reward_denom": {
"type": "string"
},
"unbonding_period": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"definitions": {
Expand Down
58 changes: 31 additions & 27 deletions schema/handle_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,50 @@
"title": "HandleMsg",
"anyOf": [
{
"description": "Owner's operations Swap all of the balances to uusd.",
"description": "Owner's operations Update the global index",
"type": "object",
"required": [
"swap_to_reward_denom"
"update_global_index"
],
"properties": {
"swap_to_reward_denom": {
"update_global_index": {
"type": "object"
}
}
},
{
"description": "Update the global index",
"description": "Staking operations Bond stake user staking balance Withdraw rewards to pending rewards Set current reward index to global index",
"type": "object",
"required": [
"update_global_index"
"bond_stake"
],
"properties": {
"update_global_index": {
"type": "object"
"bond_stake": {
"type": "object",
"required": [
"amount"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
}
}
}
}
},
{
"description": "bAsset's operations Increase user staking balance Withdraw rewards to pending rewards Set current reward index to global index",
"description": "Unbound user staking balance Withdraw rewards to pending rewards Set current reward index to global index",
"type": "object",
"required": [
"increase_balance"
"unbond_stake"
],
"properties": {
"increase_balance": {
"unbond_stake": {
"type": "object",
"required": [
"address",
"amount"
],
"properties": {
"address": {
"$ref": "#/definitions/HumanAddr"
},
"amount": {
"$ref": "#/definitions/Uint128"
}
Expand All @@ -51,31 +55,31 @@
}
},
{
"description": "Decrease user staking balance Withdraw rewards to pending rewards Set current reward index to global index",
"description": "Unbound user staking balance Withdraws released stake",
"type": "object",
"required": [
"decrease_balance"
"withdraw_stake"
],
"properties": {
"decrease_balance": {
"withdraw_stake": {
"type": "object",
"required": [
"address",
"amount"
],
"properties": {
"address": {
"$ref": "#/definitions/HumanAddr"
},
"amount": {
"$ref": "#/definitions/Uint128"
"cap": {
"anyOf": [
{
"$ref": "#/definitions/Uint128"
},
{
"type": "null"
}
]
}
}
}
}
},
{
"description": "User's operations return the accrued reward in uusd to the user.",
"description": "User's operations return the accrued reward in usdt to the user.",
"type": "object",
"required": [
"claim_rewards"
Expand Down
Loading

0 comments on commit 8d6bab0

Please sign in to comment.