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: allow admin to update unstaking duration for stake cw20 #142

Merged
merged 16 commits into from
Jan 28, 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
10 changes: 7 additions & 3 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
- name: Install latest nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.51.0
toolchain: nightly
target: wasm32-unknown-unknown
override: true

- name: Run tests
uses: actions-rs/cargo@v1
with:
toolchain: nightly
command: test
args: --locked
env:
Expand All @@ -31,6 +32,7 @@ jobs:
- name: Compile WASM contract
uses: actions-rs/cargo@v1
with:
toolchain: nightly
command: wasm
args: --locked
env:
Expand All @@ -47,19 +49,21 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.51.0
toolchain: nightly
override: true
components: rustfmt, clippy

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
toolchain: nightly
command: fmt
args: --all -- --check

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
toolchain: nightly
command: clippy
args: --all-targets -- -D warnings

Expand Down
59 changes: 30 additions & 29 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/cw3-dao/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub fn instantiate(
admin: Some(env.contract.address.to_string()),
label,
msg: to_binary(&stake_cw20_gov::msg::InstantiateMsg {
admin: env.contract.address,
unstaking_duration,
token_address: cw20_addr.addr(),
})?,
Expand Down Expand Up @@ -665,6 +666,7 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
admin: Some(env.contract.address.to_string()),
label: env.contract.address.to_string(),
msg: to_binary(&stake_cw20_gov::msg::InstantiateMsg {
admin: env.contract.address,
unstaking_duration,
token_address: cw20_addr,
})?,
Expand Down
1 change: 1 addition & 0 deletions contracts/cw3-dao/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct InstantiateMsg {

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
#[allow(clippy::large_enum_variant)]
pub enum GovTokenMsg {
// Instantiate a new cw20 token with the DAO as minter
InstantiateNewCw20 {
Expand Down
1 change: 1 addition & 0 deletions contracts/stake-cw20-gov/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cw20 = { version = "0.11" }
stake-cw20 = { path = "../stake-cw20", version = "0.2.0", features = ["library"] }
cw20-base = { version = "0.11", features = ["library"] }
cw-storage-plus = { version = "0.11" }
cw-utils = { version = "0.11" }
cosmwasm-std = { version = "1.0.0-beta" }
schemars = "0.8.6"
serde = { version = "1.0.130", default-features = false, features = ["derive"] }
Expand Down
68 changes: 68 additions & 0 deletions contracts/stake-cw20-gov/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,43 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"update_config"
],
"properties": {
"update_config": {
"type": "object",
"required": [
"admin"
],
"properties": {
"admin": {
"$ref": "#/definitions/Addr"
},
"duration": {
"anyOf": [
{
"$ref": "#/definitions/Duration"
},
{
"type": "null"
}
]
}
}
}
},
"additionalProperties": false
}
],
"definitions": {
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
},
"Binary": {
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>",
"type": "string"
Expand All @@ -92,6 +126,40 @@
}
}
},
"Duration": {
"description": "Duration is a delta of time. You can add it to a BlockInfo or Expiration to move that further in the future. Note that an height-based Duration and a time-based Expiration cannot be combined",
"oneOf": [
{
"type": "object",
"required": [
"height"
],
"properties": {
"height": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
},
{
"description": "Time in seconds",
"type": "object",
"required": [
"time"
],
"properties": {
"time": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
}
]
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
Expand Down
6 changes: 3 additions & 3 deletions contracts/stake-cw20-gov/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@
"additionalProperties": false
},
{
"description": "Returns the unstaking duration for the contract.",
"description": "Returns the config for the contract.",
"type": "object",
"required": [
"unstaking_duration"
"get_config"
],
"properties": {
"unstaking_duration": {
"get_config": {
"type": "object"
}
},
Expand Down
8 changes: 5 additions & 3 deletions contracts/stake-cw20-gov/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub fn execute(
ExecuteMsg::Receive(msg) => execute_receive(deps, env, info, msg),
ExecuteMsg::Unstake { amount } => execute_unstake(deps, env, info, amount),
ExecuteMsg::Claim {} => stake_cw20::contract::execute_claim(deps, env, info),
ExecuteMsg::UpdateConfig { admin, duration } => {
stake_cw20::contract::execute_update_config(info, deps, admin, duration)
}
ExecuteMsg::DelegateVotes { recipient } => {
execute_delegate_votes(deps, env, info, recipient)
}
Expand Down Expand Up @@ -148,9 +151,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::StakedBalanceAtHeight { address, height } => to_binary(
&stake_cw20::contract::query_staked_balance_at_height(deps, env, address, height)?,
),
QueryMsg::UnstakingDuration {} => {
to_binary(&stake_cw20::contract::query_unstaking_duration(deps)?)
}
QueryMsg::GetConfig {} => to_binary(&stake_cw20::contract::query_config(deps)?),
QueryMsg::Claims { address } => {
to_binary(&stake_cw20::contract::query_claims(deps, address)?)
}
Expand Down Expand Up @@ -238,6 +239,7 @@ mod tests {
fn instantiate_staking(app: &mut App, cw20: Addr) -> Addr {
let staking_code_id = app.store_code(contract_staking_gov());
let msg = crate::msg::InstantiateMsg {
admin: Addr::unchecked("owner"),
token_address: cw20,
unstaking_duration: None,
};
Expand Down
Loading