Skip to content

Commit

Permalink
change to MeshCustomMSg
Browse files Browse the repository at this point in the history
  • Loading branch information
neitdung committed Jul 22, 2024
1 parent 4794d46 commit db00b31
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
24 changes: 12 additions & 12 deletions contracts/provider/native-staking-proxy/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cw2::set_contract_version;
use cw_storage_plus::Item;

use cw_utils::{must_pay, nonpayable};
use mesh_bindings::{ProviderCustomMsg, ProviderMsg};
use mesh_bindings::MeshCustomMsg;
use sylvia::types::{ExecCtx, InstantiateCtx, QueryCtx};
use sylvia::{contract, schemars};

Expand All @@ -27,7 +27,7 @@ pub struct NativeStakingProxyContract<'a> {
#[cfg_attr(not(feature = "library"), sylvia::entry_points)]
#[contract]
#[sv::error(ContractError)]
#[sv::custom(msg=ProviderCustomMsg)]
#[sv::custom(msg=MeshCustomMsg)]
impl NativeStakingProxyContract<'_> {
pub const fn new() -> Self {
Self {
Expand All @@ -45,7 +45,7 @@ impl NativeStakingProxyContract<'_> {
denom: String,
owner: String,
validator: String,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
) -> Result<Response<MeshCustomMsg>, ContractError> {
let config = Config {
denom,
parent: ctx.info.sender.clone(),
Expand Down Expand Up @@ -78,7 +78,7 @@ impl NativeStakingProxyContract<'_> {
/// Stakes the tokens from `info.funds` to the given validator.
/// Can only be called by the parent contract
#[sv::msg(exec)]
fn stake(&self, ctx: ExecCtx, validator: String) -> Result<Response<ProviderCustomMsg>, ContractError> {
fn stake(&self, ctx: ExecCtx, validator: String) -> Result<Response<MeshCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.parent, ctx.info.sender, ContractError::Unauthorized {});

Expand All @@ -99,7 +99,7 @@ impl NativeStakingProxyContract<'_> {
ctx: ExecCtx,
validator: Option<String>,
amount: Coin,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
) -> Result<Response<MeshCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.parent, ctx.info.sender, ContractError::Unauthorized {});

Expand Down Expand Up @@ -188,7 +188,7 @@ impl NativeStakingProxyContract<'_> {
src_validator: String,
dst_validator: String,
amount: Coin,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
) -> Result<Response<MeshCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.owner, ctx.info.sender, ContractError::Unauthorized {});

Expand All @@ -215,7 +215,7 @@ impl NativeStakingProxyContract<'_> {
ctx: ExecCtx,
proposal_id: u64,
vote: VoteOption,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
) -> Result<Response<MeshCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.owner, ctx.info.sender, ContractError::Unauthorized {});

Expand All @@ -232,7 +232,7 @@ impl NativeStakingProxyContract<'_> {
ctx: ExecCtx,
proposal_id: u64,
vote: Vec<WeightedVoteOption>,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
) -> Result<Response<MeshCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.owner, ctx.info.sender, ContractError::Unauthorized {});

Expand All @@ -249,7 +249,7 @@ impl NativeStakingProxyContract<'_> {
/// send the tokens to the caller.
/// NOTE: must make sure not to release unbonded tokens
#[sv::msg(exec)]
fn withdraw_rewards(&self, ctx: ExecCtx) -> Result<Response<ProviderCustomMsg>, ContractError> {
fn withdraw_rewards(&self, ctx: ExecCtx) -> Result<Response<MeshCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.owner, ctx.info.sender, ContractError::Unauthorized {});

Expand Down Expand Up @@ -278,7 +278,7 @@ impl NativeStakingProxyContract<'_> {
ctx: ExecCtx,
validator: String,
amount: Coin,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
) -> Result<Response<MeshCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.owner, ctx.info.sender, ContractError::Unauthorized {});

Expand All @@ -290,15 +290,15 @@ impl NativeStakingProxyContract<'_> {
ContractError::InvalidDenom(amount.denom)
);

let msg = ProviderMsg::Unstake { validator, amount };
let msg = MeshCustomMsg::Unstake { validator, amount };
Ok(Response::new().add_message(msg))
}

/// Releases any tokens that have fully unbonded from a previous unstake.
/// This will go back to the parent via `release_proxy_stake`.
/// Errors if the proxy doesn't have any liquid tokens
#[sv::msg(exec)]
fn release_unbonded(&self, ctx: ExecCtx) -> Result<Response<ProviderCustomMsg>, ContractError> {
fn release_unbonded(&self, ctx: ExecCtx) -> Result<Response<MeshCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.owner, ctx.info.sender, ContractError::Unauthorized {});

Expand Down
11 changes: 0 additions & 11 deletions packages/bindings/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ impl From<MeshCustomMsg> for CosmosMsg<MeshCustomMsg> {
fn from(msg: MeshCustomMsg) -> CosmosMsg<MeshCustomMsg> {
CosmosMsg::Custom(msg)
}

pub fn unstake(denom: &str, validator: &str, amount: impl Into<Uint128>) -> ProviderMsg {
let coin = Coin {
amount: amount.into(),
denom: denom.into(),
};
ProviderMsg::Unstake {
validator: validator.to_string(),
amount: coin,
}
}
}

impl CustomMsg for MeshCustomMsg {}
1 change: 1 addition & 0 deletions packages/virtual-staking-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl Module for VirtualStakingModule {
}
MeshCustomMsg::Deposit { delegator: _, amount: _ } => todo!(),
MeshCustomMsg::Withdraw { delegator: _, amount: _ } => todo!(),
MeshCustomMsg::Unstake { validator: _, amount: _ } => todo!(),
}
}

Expand Down

0 comments on commit db00b31

Please sign in to comment.