Skip to content

Commit

Permalink
lint the code
Browse files Browse the repository at this point in the history
  • Loading branch information
neitdung committed Jul 28, 2024
1 parent 93a8f64 commit a3f8be5
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 24 deletions.
3 changes: 1 addition & 2 deletions contracts/provider/external-staking/src/multitest/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ pub(crate) trait AppExt {
impl AppExt for App<MtApp> {
#[track_caller]
fn new_with_balances(balances: &[(&str, &[Coin])]) -> Self {

let app =MtApp::new(|router, _api, storage| {
let app = MtApp::new(|router, _api, storage| {
for (addr, coins) in balances {
router
.bank
Expand Down
6 changes: 5 additions & 1 deletion contracts/provider/native-staking-proxy/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,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<ProviderCustomMsg>, 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 Down
2 changes: 1 addition & 1 deletion contracts/provider/native-staking-proxy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod contract;
pub mod error;
pub mod mock;
pub mod msg;
#[cfg(test)]
mod multitest;
pub mod mock;
pub mod native_staking_callback;
mod state;
2 changes: 1 addition & 1 deletion contracts/provider/native-staking-proxy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,4 @@ mod tests {
let res = contract.vote_weighted(ctx, proposal_id, vote);
assert!(matches!(res.unwrap_err(), ContractError::Unauthorized {}));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ impl NativeStakingCallback for NativeStakingContract<'_> {

Ok(Response::new().add_message(msg))
}
}
}
47 changes: 37 additions & 10 deletions contracts/provider/vault/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{
coin, ensure, Addr, Binary, Coin, Decimal, DepsMut, Fraction, Order, Reply, Response,
StdResult, Storage, SubMsg, SubMsgResponse, Uint128, WasmMsg, to_json_binary
coin, ensure, to_json_binary, Addr, Binary, Coin, Decimal, DepsMut, Fraction, Order, Reply,
Response, StdResult, Storage, SubMsg, SubMsgResponse, Uint128, WasmMsg,
};
use cw2::set_contract_version;
use cw_storage_plus::{Bounder, Item, Map};
Expand Down Expand Up @@ -144,7 +144,11 @@ impl VaultContract<'_> {
}

#[sv::msg(exec)]
fn bond(&self, ctx: ExecCtx, amount: Coin) -> Result<Response<ProviderCustomMsg>, ContractError> {
fn bond(
&self,
ctx: ExecCtx,
amount: Coin,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
nonpayable(&ctx.info)?;

let denom = self.config.load(ctx.deps.storage)?.denom;
Expand All @@ -157,7 +161,10 @@ impl VaultContract<'_> {
user.collateral += amount.amount;
self.users.save(ctx.deps.storage, &ctx.info.sender, &user)?;
let amt = amount.amount;
let msg = ProviderMsg::Bond { delegator: ctx.info.sender.clone().into_string(), amount};
let msg = ProviderMsg::Bond {
delegator: ctx.info.sender.clone().into_string(),
amount,
};
let resp = Response::new()
.add_message(msg)
.add_attribute("action", "unbond")
Expand All @@ -168,7 +175,11 @@ impl VaultContract<'_> {
}

#[sv::msg(exec)]
fn unbond(&self, ctx: ExecCtx, amount: Coin) -> Result<Response<ProviderCustomMsg>, ContractError> {
fn unbond(
&self,
ctx: ExecCtx,
amount: Coin,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
nonpayable(&ctx.info)?;

let denom = self.config.load(ctx.deps.storage)?.denom;
Expand All @@ -188,7 +199,10 @@ impl VaultContract<'_> {
user.collateral -= amount.amount;
self.users.save(ctx.deps.storage, &ctx.info.sender, &user)?;
let amt = amount.amount;
let msg = ProviderMsg::Unbond { delegator: ctx.info.sender.clone().into_string(), amount};
let msg = ProviderMsg::Unbond {
delegator: ctx.info.sender.clone().into_string(),
amount,
};
let resp = Response::new()
.add_message(msg)
.add_attribute("action", "unbond")
Expand Down Expand Up @@ -244,7 +258,8 @@ impl VaultContract<'_> {
ctx.info.sender.to_string(),
to_json_binary(&mesh_native_staking::msg::StakeMsg {
validator: validator.to_owned(),

Check failure on line 260 in contracts/provider/vault/src/contract.rs

View workflow job for this annotation

GitHub Actions / Lints

redundant clone
}).unwrap(),
})
.unwrap(),
vec![amount.clone()],

Check failure on line 263 in contracts/provider/vault/src/contract.rs

View workflow job for this annotation

GitHub Actions / Lints

redundant clone
)?;

Expand Down Expand Up @@ -550,7 +565,11 @@ impl VaultContract<'_> {
}

#[sv::msg(reply)]
fn reply(&self, ctx: ReplyCtx, reply: Reply) -> Result<Response<ProviderCustomMsg>, ContractError> {
fn reply(
&self,
ctx: ReplyCtx,
reply: Reply,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
match reply.id {
REPLY_ID_INSTANTIATE => self.reply_init_callback(ctx.deps, reply.result.unwrap()),
_ => Err(ContractError::InvalidReplyId(reply.id)),
Expand Down Expand Up @@ -1143,7 +1162,11 @@ impl VaultApi for VaultContract<'_> {
Ok(resp)
}

fn commit_tx(&self, mut ctx: ExecCtx, tx_id: u64) -> Result<Response<Self::ExecC>, ContractError> {
fn commit_tx(
&self,
mut ctx: ExecCtx,
tx_id: u64,
) -> Result<Response<Self::ExecC>, ContractError> {
self.commit_stake(&mut ctx, tx_id)?;

let resp = Response::new()
Expand All @@ -1154,7 +1177,11 @@ impl VaultApi for VaultContract<'_> {
Ok(resp)
}

fn rollback_tx(&self, mut ctx: ExecCtx, tx_id: u64) -> Result<Response<Self::ExecC>, ContractError> {
fn rollback_tx(
&self,
mut ctx: ExecCtx,
tx_id: u64,
) -> Result<Response<Self::ExecC>, ContractError> {
self.rollback_stake(&mut ctx, tx_id)?;

let resp = Response::new()
Expand Down
2 changes: 1 addition & 1 deletion contracts/provider/vault/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod contract;
pub mod error;
pub mod mock;
pub mod msg;
#[cfg(test)]
pub mod multitest;
pub mod mock;
mod state;
pub mod txs;
3 changes: 2 additions & 1 deletion contracts/provider/vault/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cosmwasm_std::{
coin, ensure, Addr, BankMsg, Binary, Coin, Decimal, DepsMut, Empty, Fraction, Order, Reply, Response, StdResult, Storage, SubMsg, SubMsgResponse, Uint128, WasmMsg
coin, ensure, Addr, BankMsg, Binary, Coin, Decimal, DepsMut, Empty, Fraction, Order, Reply,
Response, StdResult, Storage, SubMsg, SubMsgResponse, Uint128, WasmMsg,
};
use cw2::set_contract_version;
use cw_storage_plus::{Bounder, Item, Map};
Expand Down
2 changes: 1 addition & 1 deletion packages/apis/src/vault_api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_json_binary, Addr, Coin, Response, StdError, Uint128, CustomMsg, WasmMsg};
use cosmwasm_std::{to_json_binary, Addr, Coin, CustomMsg, Response, StdError, Uint128, WasmMsg};
use sylvia::types::ExecCtx;
use sylvia::{interface, schemars};

Expand Down
2 changes: 1 addition & 1 deletion packages/bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod msg;
mod query;

pub use msg::{VirtualStakeCustomMsg, VirtualStakeMsg, ProviderCustomMsg, ProviderMsg};
pub use msg::{ProviderCustomMsg, ProviderMsg, VirtualStakeCustomMsg, VirtualStakeMsg};
pub use query::{
BondStatusResponse, SlashRatioResponse, TokenQuerier, VirtualStakeCustomQuery,
VirtualStakeQuery,
Expand Down
17 changes: 13 additions & 4 deletions packages/bindings/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,16 @@ pub enum ProviderMsg {
/// If these conditions are met, it will instantly unstake
/// amount.amount tokens from the native staking proxy contract.
Unstake { validator: String, amount: Coin },
/// Restake ensures that amount.denom is the native staking denom and
/// Restake ensures that amount.denom is the native staking denom and
/// the calling contract is the native staking proxy contract.
///
/// If these conditions are met, it will instantly restake
/// amount.amount tokens from staking module to local staking contract.
Restake { delegator: String, validator: String, amount: Coin },
Restake {
delegator: String,
validator: String,
amount: Coin,
},
}

impl ProviderMsg {
Expand All @@ -123,7 +127,7 @@ impl ProviderMsg {
amount: coin,
}
}

pub fn unstake(denom: &str, validator: &str, amount: impl Into<Uint128>) -> ProviderMsg {
let coin = Coin {
amount: amount.into(),
Expand All @@ -135,7 +139,12 @@ impl ProviderMsg {
}
}

pub fn restake(denom: &str, delegator: &str, validator: &str, amount: impl Into<Uint128>) -> ProviderMsg {
pub fn restake(
denom: &str,
delegator: &str,
validator: &str,
amount: impl Into<Uint128>,
) -> ProviderMsg {
let coin = Coin {
amount: amount.into(),
denom: denom.into(),
Expand Down

0 comments on commit a3f8be5

Please sign in to comment.