Skip to content

Commit

Permalink
updated junostake to have revoke spec logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kakucodes committed Oct 24, 2023
1 parent 6c9fecb commit 897db1a
Show file tree
Hide file tree
Showing 11 changed files with 461 additions and 427 deletions.
502 changes: 283 additions & 219 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ cosmwasm-std = { version = "1.1.3", default-features = false, features = [
"staking",
] }
cosmwasm-storage = "1.1.3"
cw-orch = { git = "https://github.com/AbstractSDK/cw-orchestrator", features = [
"daemon",
] }
cw-orch = { version = "0.16.4", features = ["daemon"] }
cw-storage-plus = "1.0.1"
cw-multi-test = "0.16.5"
cw2 = "1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion contracts/junostake/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ymos-junostake-outpost"
version = { workspace = true }
authors = ["Marc <[email protected]>"]
version = { workspace = true }
edition = { workspace = true }
description = "Yieldmos Juno Staking Outpost"

Expand Down
32 changes: 29 additions & 3 deletions contracts/junostake/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::error::ContractError;
use crate::msg::{CompPrefsWithAddresses, ExecuteMsg, InstantiateMsg, JunostakeCompoundPrefs, QueryMsg};
use crate::msg::{CompPrefsWithAddresses, ExecuteMsg, InstantiateMsg, JunostakeCompoundPrefs, MigrateMsg, QueryMsg};
use crate::state::{ADMIN, AUTHORIZED_ADDRS, PROJECT_ADDRS};
use crate::{execute, queries};
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult};
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult};
use cw2::{get_contract_version, set_contract_version};
use cw_grant_spec::grantable_trait::{GrantStructure, Grantable};
use semver::Version;
Expand All @@ -13,6 +13,16 @@ use semver::Version;
const CONTRACT_NAME: &str = "crates.io:ac-outpost-junostake";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(_deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractError> {
match msg {
// an id of 0 means we don't care about the response
Reply { id: 0, .. } => Ok(Response::default()),
// TODO handle non-zero ids
_ => Err(ContractError::Unauthorized {}),
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
#[cfg_attr(feature = "interface", cw_orch::interface_entry_point)]
pub fn instantiate(deps: DepsMut, _env: Env, info: MessageInfo, msg: InstantiateMsg) -> Result<Response, ContractError> {
Expand Down Expand Up @@ -40,20 +50,36 @@ pub fn instantiate(deps: DepsMut, _env: Env, info: MessageInfo, msg: Instantiate

#[cfg_attr(not(feature = "library"), entry_point)]
#[cfg_attr(feature = "interface", cw_orch::interface_entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: InstantiateMsg) -> Result<Response, ContractError> {
pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
let version: Version = CONTRACT_VERSION.parse()?;
let storage_version: Version = get_contract_version(deps.storage)?.version.parse()?;

if storage_version < version {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
}

if let MigrateMsg {
project_addresses: Some(addresses),
} = msg
{
PROJECT_ADDRS.save(deps.storage, &addresses)?
}

Ok(Response::default())
}

#[cfg_attr(not(feature = "library"), entry_point)]
#[cfg_attr(feature = "interface", cw_orch::interface_entry_point)]
pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::UpdateProjectAddresses(addresses) => {
if info.sender != ADMIN.load(deps.storage)? {
return Err(ContractError::Unauthorized {});
}
PROJECT_ADDRS.save(deps.storage, &addresses)?;

Ok(Response::default())
}
ExecuteMsg::AddAuthorizedCompounder(address) => {
if info.sender != ADMIN.load(deps.storage)? {
return Err(ContractError::Unauthorized {});
Expand Down
59 changes: 49 additions & 10 deletions contracts/junostake/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::iter;

use cosmos_sdk_proto::cosmos::{bank::v1beta1::MsgSend, base::v1beta1::Coin, staking::v1beta1::MsgDelegate};
use cosmwasm_std::{
coin, to_binary, Addr, Attribute, BlockInfo, Decimal, DepsMut, Env, MessageInfo, QuerierWrapper, Response, Timestamp,
to_binary, Addr, Attribute, BlockInfo, Decimal, DepsMut, Env, MessageInfo, QuerierWrapper, ReplyOn, Response, SubMsg,
Uint128,
};
use outpost_utils::{
Expand All @@ -14,7 +14,7 @@ use outpost_utils::{
},
msg_gen::{create_exec_contract_msg, create_exec_msg, CosmosProtoMsg},
};
use terraswap_helpers::terraswap_swap::{create_swap_msg, create_terraswap_swap_msg_with_simulation};
use terraswap_helpers::terraswap_swap::create_terraswap_swap_msg_with_simulation;

use withdraw_rewards_tax_grant::{client::WithdrawRewardsTaxClient, msg::SimulateExecuteResponse};

Expand All @@ -39,7 +39,7 @@ use crate::{
#[derive(Default)]
pub struct DestProjectMsgs {
pub msgs: Vec<CosmosProtoMsg>,
pub sub_msgs: Vec<Vec<CosmosProtoMsg>>,
pub sub_msgs: Vec<(u64, Vec<CosmosProtoMsg>, ReplyOn)>,
pub attributes: Vec<Attribute>,
}

Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn compound(
.simulate_with_contract_execute(deps.querier, tax_fee)?;

// the list of all the compounding msgs to broadcast on behalf of the user based on their comp prefs
let sub_msgs = prefs_to_msgs(
let all_msgs = prefs_to_msgs(
&project_addresses,
&env.block,
staking_denom.to_string(),
Expand All @@ -87,22 +87,46 @@ pub fn compound(
deps.querier,
)?;

let msgs = sub_msgs.iter().fold(DestProjectMsgs::default(), |mut acc, msg| {
let combined_msgs = all_msgs.iter().fold(DestProjectMsgs::default(), |mut acc, msg| {
acc.msgs.append(&mut msg.msgs.clone());
acc.sub_msgs.append(&mut msg.sub_msgs.clone());
acc.attributes.append(&mut msg.attributes.clone());
acc
});

// the final exec message that will be broadcast and contains all the sub msgs
let exec_msg = create_exec_msg(&env.contract.address, msgs.msgs)?;
let exec_msg = create_exec_msg(&env.contract.address, combined_msgs.msgs)?;

Ok(Response::default()
let resp = Response::default()
.add_attribute("action", "outpost compound")
.add_message(withdraw_msg)
.add_attribute("subaction", "withdraw rewards")
.add_message(exec_msg)
.add_attributes(msgs.attributes))
.add_submessages(
combined_msgs
.sub_msgs
.into_iter()
.filter_map(|sub_msg| {
if let (Ok(exec_msg), false) = (
create_exec_msg(&env.contract.address, sub_msg.1.clone()),
sub_msg.1.is_empty(),
) {
Some((sub_msg.0, exec_msg, sub_msg.2))
} else {
None
}
})
.map(|(id, msg, reply_on)| SubMsg {
msg,
gas_limit: None,
id,
reply_on,
})
.collect::<Vec<SubMsg>>(),
)
.add_attributes(combined_msgs.attributes);

Ok(resp)
}

/// Converts the user's compound preferences into a list of
Expand Down Expand Up @@ -190,7 +214,7 @@ pub fn prefs_to_msgs(
dao_addresses.cw20.clone(),
&target_address,
&cw20::Cw20ExecuteMsg::Send {
contract: dao_addresses.cw20,
contract: dao_addresses.staking,
amount: expected_dao_token_amount,
msg: to_binary(&cw20_stake::msg::ReceiveMsg::Stake {})?,
},
Expand Down Expand Up @@ -505,7 +529,22 @@ pub fn prefs_to_msgs(
amount: comp_token_amount.into(),
}]),
)?)],
sub_msgs: vec![],
sub_msgs: vec![
// (
// // disregard the result of the balance dao swap in case it fails
// 0u64,
// vec![CosmosProtoMsg::ExecuteContract(create_exec_contract_msg(
// project_addresses.destination_projects.balance_dao.clone(),
// target_address,
// &balance_token_swap::msg::ExecuteMsg::Swap {},
// Some(vec![Coin {
// denom: staking_denom.clone(),
// amount: comp_token_amount.into(),
// }]),
// )?)],
// ReplyOn::Error,
// )
],
attributes: vec![
Attribute {
key: "subaction".to_string(),
Expand Down
6 changes: 5 additions & 1 deletion contracts/junostake/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ pub struct InstantiateMsg {
}

#[cw_serde]
pub struct MigrateMsg {}
pub struct MigrateMsg {
pub project_addresses: Option<ContractAddresses>,
}

#[cw_serde]
#[derive(QueryResponses)]
Expand Down Expand Up @@ -51,6 +53,7 @@ pub enum ExecuteMsg {
AddAuthorizedCompounder(String),
RemoveAuthorizedCompounder(String),
Compound(JunostakeCompoundPrefs),
UpdateProjectAddresses(ContractAddresses),
}

#[cw_serde]
Expand All @@ -75,6 +78,7 @@ pub struct ContractAddresses {
}

#[cw_serde]
#[derive(Default)]
pub struct AuthzppAddresses {
pub withdraw_tax: String,
// pub allowlist_send: String,
Expand Down
Loading

0 comments on commit 897db1a

Please sign in to comment.