Skip to content

Commit

Permalink
Merge pull request #4 from LoTerra/receive-cw20-stake
Browse files Browse the repository at this point in the history
HandleBond works with cw20receive
  • Loading branch information
0xantman authored Apr 24, 2021
2 parents 8d6bab0 + da3c35a commit 99ac4a7
Show file tree
Hide file tree
Showing 7 changed files with 1,041 additions and 998 deletions.
1 change: 1 addition & 0 deletions examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn main() {
remove_schemas(&out_dir).unwrap();

export_schema(&schema_for!(HandleMsg), &out_dir);
export_schema(&schema_for!(ReceiveMsg), &out_dir);
export_schema(&schema_for!(InitMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(ConfigResponse), &out_dir);
Expand Down
64 changes: 43 additions & 21 deletions schema/handle_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,7 @@
}
},
{
"description": "Staking operations Bond stake user staking balance Withdraw rewards to pending rewards Set current reward index to global index",
"type": "object",
"required": [
"bond_stake"
],
"properties": {
"bond_stake": {
"type": "object",
"required": [
"amount"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
}
}
}
}
},
{
"description": "Unbound user staking balance Withdraw rewards to pending rewards Set current reward index to global index",
"description": "Staking operations Unbound user staking balance Withdraw rewards to pending rewards Set current reward index to global index",
"type": "object",
"required": [
"unbond_stake"
Expand Down Expand Up @@ -101,9 +81,51 @@
}
}
}
},
{
"description": "This accepts a properly-encoded ReceiveMsg from a cw20 contract",
"type": "object",
"required": [
"receive"
],
"properties": {
"receive": {
"$ref": "#/definitions/Cw20ReceiveMsg"
}
}
}
],
"definitions": {
"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"
},
"Cw20ReceiveMsg": {
"description": "Cw20ReceiveMsg should be de/serialized under `Receive()` variant in a HandleMsg",
"type": "object",
"required": [
"amount",
"sender"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
},
"sender": {
"$ref": "#/definitions/HumanAddr"
}
}
},
"HumanAddr": {
"type": "string"
},
Expand Down
18 changes: 18 additions & 0 deletions schema/receive_msg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ReceiveMsg",
"anyOf": [
{
"description": "Bond stake user staking balance Withdraw rewards to pending rewards Set current reward index to global index",
"type": "object",
"required": [
"bond_stake"
],
"properties": {
"bond_stake": {
"type": "object"
}
}
}
]
}
4 changes: 2 additions & 2 deletions src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::global::handle_update_global_index;
use crate::state::{read_config, read_state, store_config, store_state, Config, State};
use crate::user::{
handle_bond, handle_claim_rewards, handle_unbound, handle_withdraw_stake,
handle_claim_rewards, handle_receive, handle_unbound, handle_withdraw_stake,
query_accrued_rewards, query_holder, query_holders,
};
use cosmwasm_std::{
Expand Down Expand Up @@ -44,9 +44,9 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
match msg {
HandleMsg::ClaimRewards { recipient } => handle_claim_rewards(deps, env, recipient),
HandleMsg::UpdateGlobalIndex {} => handle_update_global_index(deps, env),
HandleMsg::BondStake { amount } => handle_bond(deps, env, amount),
HandleMsg::UnbondStake { amount } => handle_unbound(deps, env, amount),
HandleMsg::WithdrawStake { cap } => handle_withdraw_stake(deps, env, cap),
HandleMsg::Receive(msg) => handle_receive(deps, env, msg),
}
}

Expand Down
17 changes: 13 additions & 4 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use cosmwasm_std::{Decimal, HumanAddr, Uint128};
use cw20::Cw20ReceiveMsg;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InitMsg {
Expand All @@ -24,10 +25,6 @@ pub enum HandleMsg {
/// Staking operations
///////////////////

/// Bond stake user staking balance
/// Withdraw rewards to pending rewards
/// Set current reward index to global index
BondStake { amount: Uint128 },
/// Unbound user staking balance
/// Withdraw rewards to pending rewards
/// Set current reward index to global index
Expand All @@ -43,6 +40,18 @@ pub enum HandleMsg {

/// return the accrued reward in usdt to the user.
ClaimRewards { recipient: Option<HumanAddr> },

/// This accepts a properly-encoded ReceiveMsg from a cw20 contract
Receive(Cw20ReceiveMsg),
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ReceiveMsg {
/// Bond stake user staking balance
/// Withdraw rewards to pending rewards
/// Set current reward index to global index
BondStake {},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
Expand Down
Loading

0 comments on commit 99ac4a7

Please sign in to comment.