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: Mesh security v2 #202

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
274 changes: 142 additions & 132 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions contracts/consumer/converter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ thiserror = { workspace = true }
mesh-burn = { workspace = true }
mesh-simple-price-feed = { workspace = true, features = ["mt"] }
mesh-virtual-staking = { workspace = true, features = ["mt"] }

cw-multi-test = { workspace = true }
test-case = { workspace = true }
derivative = { workspace = true }
Expand Down
8 changes: 6 additions & 2 deletions contracts/consumer/converter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl ConverterContract<'_> {
discount: Decimal,
remote_denom: String,
virtual_staking_code_id: u64,
tombstoned_unbond_enable: bool,
admin: Option<String>,
max_retrieve: u16,
) -> Result<custom::Response, ContractError> {
Expand All @@ -98,8 +99,11 @@ impl ConverterContract<'_> {
ctx.deps.api.addr_validate(admin)?;
}

let msg =
to_json_binary(&mesh_virtual_staking::contract::sv::InstantiateMsg { max_retrieve })?;
let msg = to_json_binary(&mesh_virtual_staking::contract::sv::InstantiateMsg {
max_retrieve,
tombstoned_unbond_enable,
})?;

// Instantiate virtual staking contract
let init_msg = WasmMsg::Instantiate {
admin,
Expand Down
41 changes: 23 additions & 18 deletions contracts/consumer/converter/src/multitest.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
mod virtual_staking_mock;

use cosmwasm_std::{coin, coins, Addr, Decimal, StdError, Uint128, Validator};
use cw_multi_test::{no_init, AppBuilder};
use mesh_apis::converter_api::sv::mt::ConverterApiProxy;
use mesh_apis::converter_api::RewardInfo;
use mesh_simple_price_feed::contract::sv::mt::CodeId as PriceFeedCodeId;
use mesh_simple_price_feed::contract::SimplePriceFeedContract;
use mesh_virtual_staking::contract::sv::mt::{
CodeId as VirtualStakingCodeId, VirtualStakingContractProxy,
};
use mesh_virtual_staking::contract::VirtualStakingContract;
use sylvia::multitest::{App, Proxy};
use virtual_staking_mock::sv::mt::CodeId as VirtualStakingCodeId;
use virtual_staking_mock::VirtualStakingMock;

use crate::contract::sv::mt::CodeId as ConverterCodeId;
use crate::contract::sv::mt::ConverterContractProxy;
use crate::contract::{custom, ConverterContract};
use crate::error::ContractError;
use crate::error::ContractError::Unauthorized;
use crate::multitest::virtual_staking_mock::sv::mt::VirtualStakingMockProxy;

const JUNO: &str = "ujuno";

Expand All @@ -31,7 +30,7 @@ struct SetupArgs<'a> {
struct SetupResponse<'a> {
price_feed: Proxy<'a, MtApp, SimplePriceFeedContract<'a>>,
converter: Proxy<'a, MtApp, ConverterContract<'a>>,
virtual_staking: Proxy<'a, MtApp, VirtualStakingMock<'a>>,
virtual_staking: Proxy<'a, MtApp, VirtualStakingContract<'a>>,
}

fn new_app() -> App<MtApp> {
Expand Down Expand Up @@ -62,6 +61,7 @@ fn setup<'a>(app: &'a App<MtApp>, args: SetupArgs<'a>) -> SetupResponse<'a> {
discount,
JUNO.to_owned(),
virtual_staking_code.code_id(),
true,
Some(admin.to_owned()),
50,
)
Expand Down Expand Up @@ -153,18 +153,18 @@ fn ibc_stake_and_unstake() {
// no one is staked
let val1 = "Val Kilmer";
let val2 = "Valley Girl";
assert!(virtual_staking.all_stake().unwrap().stakes.is_empty());
assert!(virtual_staking.get_all_stake().unwrap().stakes.is_empty());
assert_eq!(
virtual_staking
.stake(val1.to_string())
.get_stake(val1.to_string())
.unwrap()
.stake
.u128(),
0
);
assert_eq!(
virtual_staking
.stake(val2.to_string())
.get_stake(val2.to_string())
.unwrap()
.stake
.u128(),
Expand All @@ -187,25 +187,28 @@ fn ibc_stake_and_unstake() {
.call(owner)
.unwrap();

// new epoch to update all stake values
virtual_staking.test_handle_epoch().call(owner).unwrap();

// and check the stakes (1000 * 0.6 * 0.5 = 300) (2000 * 0.6 * 0.5 = 600)
assert_eq!(
virtual_staking
.stake(val1.to_string())
.get_stake(val1.to_string())
.unwrap()
.stake
.u128(),
300
);
assert_eq!(
virtual_staking
.stake(val2.to_string())
.get_stake(val2.to_string())
.unwrap()
.stake
.u128(),
600
);
assert_eq!(
virtual_staking.all_stake().unwrap().stakes,
virtual_staking.get_all_stake().unwrap().stakes,
vec![
(val1.to_string(), Uint128::new(300)),
(val2.to_string(), Uint128::new(600)),
Expand Down Expand Up @@ -239,18 +242,18 @@ fn ibc_stake_and_burn() {
// no one is staked
let val1 = "Val Kilmer";
let val2 = "Valley Girl";
assert!(virtual_staking.all_stake().unwrap().stakes.is_empty());
assert!(virtual_staking.get_all_stake().unwrap().stakes.is_empty());
assert_eq!(
virtual_staking
.stake(val1.to_string())
.get_stake(val1.to_string())
.unwrap()
.stake
.u128(),
0
);
assert_eq!(
virtual_staking
.stake(val2.to_string())
.get_stake(val2.to_string())
.unwrap()
.stake
.u128(),
Expand All @@ -273,25 +276,27 @@ fn ibc_stake_and_burn() {
.call(owner)
.unwrap();

// new epoch to update all stake values
virtual_staking.test_handle_epoch().call(owner).unwrap();
// and check the stakes (1000 * 0.6 * 0.5 = 300) (2000 * 0.6 * 0.5 = 600)
assert_eq!(
virtual_staking
.stake(val1.to_string())
.get_stake(val1.to_string())
.unwrap()
.stake
.u128(),
300
);
assert_eq!(
virtual_staking
.stake(val2.to_string())
.get_stake(val2.to_string())
.unwrap()
.stake
.u128(),
600
);
assert_eq!(
virtual_staking.all_stake().unwrap().stakes,
virtual_staking.get_all_stake().unwrap().stakes,
vec![
(val1.to_string(), Uint128::new(300)),
(val2.to_string(), Uint128::new(600)),
Expand Down
Loading
Loading