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

Membrane destinations #8

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
482 changes: 371 additions & 111 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ wynd-stake = { git = "https://github.com/wynddao/wynddao.git", tag = "v1.7.0", f
wyndex-factory = { git = "https://github.com/wynddao/wynddex.git", tag = "v2.2.0" }
outpost-utils = { path = "./packages/utils" }
wynd-helpers = { path = "./packages/wynd-helpers" }
membrane-helpers = { path = "./packages/membrane-helpers" }
terraswap-helpers = { path = "./packages/terraswap-helpers" }
# wyndex-stake = { git = "https://github.com/wynddao/wynddex.git", tag = "v2.2.0" }
osmosis-std = "0.21.0"

osmosis-helpers = { path = "./packages/osmosis-helpers" }
# mars-types = { git = "https://github.com/mars-protocol/contracts.git", version = "2.0.0" }

white-whale = { git = "https://github.com/White-Whale-Defi-Platform/white-whale-core.git", tag = "v1.4.0-juno-1-token_factory-hotfix" }
cw-grant-spec = { git = "https://github.com/kakucodes/authzpp", version = "0.3.2" }
Expand All @@ -59,14 +57,9 @@ withdraw-rewards-tax-grant = { git = "https://github.com/kakucodes/authzpp", ver
balance-token-swap = { git = "https://github.com/racoon-supply-rac/balance-dao", features = [
"library",
] }
# stake-easy = { git = "https://github.com/arufa-research/stakeeasy-juno-contracts", features = [
# "library",
# ], package = "staking-contract" }

bond-router = { git = "https://github.com/wynddao/wynd-lsd", features = [
"library",
] }

furnace = { git = "https://github.com/deving-zone-community/community-furnace.git", features = [
"library",
] }
Expand Down
1 change: 1 addition & 0 deletions contracts/osmodca/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ cw-orch = { workspace = true, optional = true }
terraswap-helpers = { workspace = true }
white-whale = { workspace = true }
osmosis-helpers = { workspace = true }
membrane-helpers = { workspace = true }


[dev-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions contracts/osmodca/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub enum ContractError {
#[error("Osmosis Helper Error: &{0}")]
OsmosisHelperError(#[from] osmosis_helpers::errors::OsmosisHelperError),

#[error("Membrane Helper Error: &{0}")]
MembraneHelperError(#[from] membrane_helpers::errors::MembraneHelperError),

#[error("Semver parsing error: {0}")]
SemVer(String),

Expand Down
12 changes: 9 additions & 3 deletions contracts/osmodca/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::iter;

use cosmwasm_std::{coin, Addr, Attribute, Decimal, Deps, DepsMut, Env, Event, MessageInfo, Response, SubMsg, Timestamp};
use membrane_helpers::msg_gen::stake_mbrn_msgs;
use osmosis_destinations::{
comp_prefs::{OsmosisCompPrefs, OsmosisDestinationProject, OsmosisLsd, OsmosisPoolSettings},
dest_project_gen::{mint_milk_tia_msgs, stake_ion_msgs, stake_mbrn_msgs},
dest_project_gen::{mint_milk_tia_msgs, stake_ion_msgs},
pools::MultipleStoredPools,
};
use osmosis_helpers::{
Expand Down Expand Up @@ -182,7 +183,7 @@ pub fn prefs_to_msgs(
denoms: project_addrs.destination_projects.denoms.clone(),
},
"uosmo",
target_asset.clone(),
&target_asset,
)?;

Ok(DestProjectMsgs {
Expand Down Expand Up @@ -220,7 +221,7 @@ pub fn prefs_to_msgs(
},
user_addr,
&coin(comp_token_amount.u128(), "uosmo"),
target_asset.clone(),
&target_asset,
current_timestamp.clone(),
)?;

Expand Down Expand Up @@ -390,6 +391,11 @@ pub fn prefs_to_msgs(
token_min_amount_1,
current_timestamp.clone(),
)?),
OsmosisDestinationProject::DepositCollateral { as_asset, protocol } => unimplemented!(),
OsmosisDestinationProject::RepayDebt {
ltv_ratio_threshold,
protocol,
} => unimplemented!(),
OsmosisDestinationProject::Unallocated {} => Ok(DestProjectMsgs::default()),
_ => unimplemented!(),
}
Expand Down
15 changes: 13 additions & 2 deletions contracts/osmodca/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ use crate::{
use cosmwasm_std::{Addr, Coin, Decimal, Deps, StdResult, Timestamp, Uint128};
use cw_grant_spec::grantable_trait::{dedupe_grant_reqs, GrantStructure, Grantable};
use cw_grant_spec::grants::{AuthorizationType, GrantBase, GrantRequirement, RevokeRequirement};
use osmosis_destinations::comp_prefs::{OsmosisDestinationProject, OsmosisLsd, OsmosisPoolSettings};
use osmosis_destinations::grants::{membrane_stake_grant, mint_milk_tia_grant, stake_ion_grants};
use membrane_helpers::grants::membrane_stake_grant;
use osmosis_destinations::comp_prefs::{
OsmosisDepositCollateral, OsmosisDestinationProject, OsmosisLsd, OsmosisPoolSettings,
};
use osmosis_destinations::grants::{mint_milk_tia_grant, stake_ion_grants};
use osmosis_helpers::osmosis_lp::{join_cl_pool_grants, join_classic_pool_grants};
use osmosis_helpers::osmosis_swap::osmosis_swap_grants;
use outpost_utils::comp_prefs::TakeRate;
Expand Down Expand Up @@ -207,6 +210,14 @@ pub fn gen_comp_pref_grants(
pool_id: _,
pool_settings: OsmosisPoolSettings::ConcentratedLiquidity { .. },
} => join_cl_pool_grants(base),
OsmosisDestinationProject::DepositCollateral {
as_asset,
protocol: OsmosisDepositCollateral::Membrane { position_id, and_then },
} => unimplemented!(),
OsmosisDestinationProject::RepayDebt {
ltv_ratio_threshold,
protocol,
} => unimplemented!(),
}
});

Expand Down
1 change: 1 addition & 0 deletions contracts/osmostake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ terraswap-helpers = { workspace = true }
white-whale = { workspace = true }
osmosis-helpers = { workspace = true }
withdraw-rewards-tax-grant = { workspace = true }
membrane-helpers = { workspace = true }


[dev-dependencies]
Expand Down
55 changes: 46 additions & 9 deletions contracts/osmostake/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,68 @@
use crate::error::ContractError;
use crate::msg::{CompPrefsWithAddresses, ExecuteMsg, InstantiateMsg, MigrateMsg, OsmostakeCompoundPrefs, QueryMsg};
use crate::state::{ADMIN, AUTHORIZED_ADDRS, KNOWN_DENOMS, KNOWN_OSMO_POOLS, KNOWN_USDC_POOLS, PROJECT_ADDRS, TAKE_RATE};
use crate::state::{
SubmsgData, ADMIN, AUTHORIZED_ADDRS, KNOWN_DENOMS, KNOWN_OSMO_POOLS, KNOWN_USDC_POOLS, PROJECT_ADDRS, SUBMSG_DATA,
TAKE_RATE,
};
use crate::{execute, queries};
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::Event;
use cosmwasm_std::{
to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult, Timestamp,
};
use cw2::{get_contract_version, set_contract_version};
use cw_grant_spec::grantable_trait::{GrantStructure, Grantable};
use membrane_helpers::utils::membrane_mint_cdt;
use osmosis_destinations::pools::PoolForEach;

use outpost_utils::comp_prefs::TakeRate;
use outpost_utils::helpers::DestProjectMsgs;
use semver::Version;

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:ac-outpost-osmostake";
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 {
pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractError> {
let mut msgs = 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 {}),
}
Reply { id: 0, .. } => Ok(DestProjectMsgs::default()),
Reply { id, result: _result } => match SUBMSG_DATA.may_load(deps.as_ref().storage, &id) {
Ok(Some(SubmsgData::BondGamms { pool_id: _pool_id })) => {
// TODO: Implement the BondGamms submsg
Ok(DestProjectMsgs::default())
}
Ok(Some(SubmsgData::MintCdt {
user_addr,
position_id,
and_then,
})) => {
let project_addrs = PROJECT_ADDRS.load(deps.as_ref().storage)?;

let mut cdt_msgs = membrane_mint_cdt(
&deps.querier,
&project_addrs.destination_projects.projects.membrane,
&project_addrs.destination_projects.denoms.cdt,
&user_addr,
position_id,
and_then,
env.block.time,
)?;

cdt_msgs.append_events(vec![Event::new("mint_cdt_reply")
.add_attribute("user_addr", user_addr.to_string())
.add_attribute("position_id", position_id.to_string())]);

Ok(cdt_msgs)
}
_ => Err(ContractError::SubMsgReplyIdNotFound { reply_id: msg.id }),
},
}?;

msgs.prepend_events(vec![Event::new("reply").add_attribute("id", msg.id.to_string())]);

Ok(msgs.to_response(&env.contract.address)?)
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down Expand Up @@ -144,7 +181,7 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, Co
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> Result<Response, ContractError> {
pub fn execute(deps: &mut DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::UpdateProjectAddresses(addresses) => {
if info.sender != ADMIN.load(deps.storage)? {
Expand Down
6 changes: 6 additions & 0 deletions contracts/osmostake/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub enum ContractError {
#[error("Osmosis Helper Error: &{0}")]
OsmosisHelperError(#[from] osmosis_helpers::errors::OsmosisHelperError),

#[error("Membrane Helper Error: &{0}")]
MembraneHelperError(#[from] membrane_helpers::errors::MembraneHelperError),

#[error("Semver parsing error: {0}")]
SemVer(String),

Expand Down Expand Up @@ -62,6 +65,9 @@ pub enum ContractError {

#[error("Contract Migration Version Mismatch: expected higher than {expected}, receieved {received}")]
MigrationVersionMismatch { expected: String, received: String },

#[error("Submessage reply id not found {reply_id}")]
SubMsgReplyIdNotFound { reply_id: u64 },
}

impl From<semver::Error> for ContractError {
Expand Down
Loading
Loading