Skip to content

Commit

Permalink
snip20-stake completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-1857 committed Jan 9, 2024
1 parent d97694a commit 6196466
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
28 changes: 13 additions & 15 deletions contracts/staking/snip20-stake/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::msg::{
ExecuteAnswer, GetHooksResponse, InstantiateAnswer, ListStakersResponse, QueryMsg,
Snip20ReceiveMsg, StakedValueResponse, StakerBalanceResponse, TotalValueResponse,
};
use crate::msg::{ExecuteMsg, InstantiateMsg, ReceiveMsg, ResponseStatus::Success};
use crate::msg::{ExecuteMsg,InstantiateMsg, ReceiveMsg, ResponseStatus::Success};
use crate::state::{
Config, BALANCE, CLAIMS, CONFIG, HOOKS, MAX_CLAIMS, STAKED_BALANCES, STAKED_TOTAL,
};
Expand Down Expand Up @@ -45,20 +45,18 @@ pub fn instantiate(
// though this provides some protection against mistakes where the
// wrong address is provided.
let token_address = deps.api.addr_validate(&msg.token_address)?;
// let _: secret_toolkit::snip20::TokenInfoResponse = deps
// .querier
// .query_wasm_smart(
// env.contract.code_hash.clone(),
// &token_address,
// &secret_toolkit::snip20::QueryMsg::TokenInfo {},
// )
// .map_err(|_| ContractError::InvalidSnip20 {})?;
let _: secret_toolkit::snip20::TokenInfoResponse = deps
.querier
.query_wasm_smart(
msg.token_code_hash.clone(),
&token_address,
&secret_toolkit::snip20::QueryMsg::TokenInfo {},
)
.map_err(|_| ContractError::InvalidSnip20 {})?;

validate_duration(msg.unstaking_duration)?;
let config = Config {
token_address,
unstaking_duration: msg.unstaking_duration,
};

let config=Config { token_address, token_code_hash: msg.token_code_hash.clone(), unstaking_duration: msg.unstaking_duration };
CONFIG.save(deps.storage, &config)?;

// Initialize state to zero. We do this instead of using
Expand Down Expand Up @@ -240,7 +238,7 @@ pub fn execute_unstake(
};
let wasm_msg = cosmwasm_std::WasmMsg::Execute {
contract_addr: config.token_address.to_string(),
code_hash: env.contract.code_hash,
code_hash: config.token_code_hash,
msg: to_binary(&snip_send_msg)?,
funds: vec![],
};
Expand Down Expand Up @@ -294,7 +292,7 @@ pub fn execute_claim(
};
let wasm_msg = cosmwasm_std::WasmMsg::Execute {
contract_addr: config.token_address.to_string(),
code_hash: env.contract.code_hash,
code_hash: config.token_code_hash,
msg: to_binary(&cw_send_msg)?,
funds: vec![],
};
Expand Down
1 change: 1 addition & 0 deletions contracts/staking/snip20-stake/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct InstantiateMsg {
// Owner can update all configs including changing the owner. This will generally be a DAO.
pub owner: Option<String>,
pub token_address: String,
pub token_code_hash : String,
pub unstaking_duration: Option<Duration>,
}

Expand Down
5 changes: 3 additions & 2 deletions contracts/staking/snip20-stake/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct Config {
pub token_address: Addr,
pub token_code_hash: String,
pub unstaking_duration: Option<Duration>,
}

pub const CONFIG: Item<Config> = Item::new("config_v2");
pub const CONFIG: Item<Config> = Item::new("config");
pub const STAKED_TOTAL: Item<Uint128> = Item::new("total_staked");
pub const BALANCE: Item<Uint128> = Item::new("balance");
pub static STAKED_BALANCES: Keymap<Addr, Uint128> = Keymap::new(b"staked_balances");
pub static STAKED_BALANCES: Keymap<Addr, Uint128> = Keymap::new(b"staked_balances");

// Hooks to contracts that will receive staking and unstaking messages
pub const HOOKS: Hooks = Hooks::new("hooks");
Expand Down
3 changes: 2 additions & 1 deletion snip20-reference-impl/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ pub fn instantiate(

ViewingKey::set_seed(deps.storage, &prng_seed_hashed);

Ok(Response::default())

Ok(Response::new().set_data(to_binary(&env.contract.code_hash)?))
}

fn get_address_position(
Expand Down

0 comments on commit 6196466

Please sign in to comment.