Skip to content

Commit

Permalink
Merge pull request #197 from decentrio/feat/native-immediate-unbonding
Browse files Browse the repository at this point in the history
feat: native immediate unbonding
  • Loading branch information
vuong177 authored Sep 5, 2024
2 parents 84d6b2a + c77d510 commit d9e27c8
Show file tree
Hide file tree
Showing 10 changed files with 572 additions and 31 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/provider/external-staking/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cosmwasm_std::{coin, coins, to_json_binary, Decimal, Uint128};
use cw_multi_test::App as MtApp;
use mesh_native_staking::contract::sv::mt::CodeId as NativeStakingCodeId;
use mesh_native_staking::contract::sv::InstantiateMsg as NativeStakingInstantiateMsg;
use mesh_native_staking_proxy::contract::sv::mt::CodeId as NativeStakingProxyCodeId;
use mesh_native_staking_proxy::mock::sv::mt::CodeId as NativeStakingProxyCodeId;
use mesh_vault::mock::sv::mt::{CodeId as VaultCodeId, VaultMockProxy};
use mesh_vault::mock::VaultMock;
use mesh_vault::msg::{LocalStakingInfo, StakingInitInfo};
Expand Down
1 change: 1 addition & 0 deletions contracts/provider/native-staking-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mt = ["library", "sylvia/mt"]
[dependencies]
mesh-apis = { workspace = true }
mesh-burn = { workspace = true }
mesh-bindings = { workspace = true }

sylvia = { workspace = true }
cosmwasm-schema = { workspace = true }
Expand Down
30 changes: 20 additions & 10 deletions contracts/provider/native-staking-proxy/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cw2::set_contract_version;
use cw_storage_plus::Item;

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

Expand All @@ -26,6 +27,7 @@ pub struct NativeStakingProxyContract<'a> {
#[cfg_attr(not(feature = "library"), sylvia::entry_points)]
#[contract]
#[sv::error(ContractError)]
#[sv::custom(msg=ProviderCustomMsg)]
impl NativeStakingProxyContract<'_> {
pub const fn new() -> Self {
Self {
Expand All @@ -43,7 +45,7 @@ impl NativeStakingProxyContract<'_> {
denom: String,
owner: String,
validator: String,
) -> Result<Response, ContractError> {
) -> Result<Response<ProviderCustomMsg>, ContractError> {
let config = Config {
denom,
parent: ctx.info.sender.clone(),
Expand Down Expand Up @@ -76,7 +78,11 @@ 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, ContractError> {
fn stake(
&self,
ctx: ExecCtx,
validator: String,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.parent, ctx.info.sender, ContractError::Unauthorized {});

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

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

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

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

Expand All @@ -247,7 +253,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, ContractError> {
fn withdraw_rewards(&self, ctx: ExecCtx) -> Result<Response<ProviderCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.owner, ctx.info.sender, ContractError::Unauthorized {});

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

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

let msg = StakingMsg::Undelegate { validator, amount };
let msg = ProviderMsg::Unstake {
delegator: ctx.info.sender.to_string(),
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, ContractError> {
fn release_unbonded(&self, ctx: ExecCtx) -> Result<Response<ProviderCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.owner, ctx.info.sender, ContractError::Unauthorized {});

Expand Down
1 change: 1 addition & 0 deletions contracts/provider/native-staking-proxy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod contract;
pub mod error;
pub mod mock;
pub mod msg;
#[cfg(test)]
mod multitest;
Expand Down
Loading

0 comments on commit d9e27c8

Please sign in to comment.