Skip to content

Commit

Permalink
MsgSend allow to the abstract account 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Buckram123 committed Jan 25, 2024
1 parent 47e5915 commit f2caeaf
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 40 deletions.
Binary file modified artifacts/app.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f334310c60b8f4440d4d56ffaa73d1ee68ae70ed9354da486666180f2874ee27 app-x86_64.wasm
cc57a30ca0ebc7085d47bad1af7ae09b33e2d28d6fce4b5abd40b84d1be231b5 app-x86_64.wasm
2 changes: 1 addition & 1 deletion artifacts/checksums_intermediate.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4ec4d2bf2f978997cbf8bf02d11800cd07b6082bec5ca1d2962605f5ed7bda5d app.wasm
5a1718aadb67696180d66770b62149e2e69115431a3002e1918d8068e9c7f248 app.wasm
2 changes: 0 additions & 2 deletions contracts/savings-app/src/handlers/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ fn swap_msg(
Ok(trigger_swap_msg
.messages
.into_iter()
// filter out bank messages
.filter(|m| !matches!(m, CosmosMsg::Bank(_)))
.map(|m| wrap_authz(m, sender.clone(), env))
.collect())
}
Expand Down
29 changes: 16 additions & 13 deletions contracts/savings-app/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use cosmwasm_std::{CosmosMsg, Deps, Env, WasmMsg};
use osmosis_std::{
cosmwasm_to_proto_coins,
shim::Any,
types::{cosmos::authz::v1beta1::MsgExec, cosmwasm::wasm::v1::MsgExecuteContract},
types::{
cosmos::{authz::v1beta1::MsgExec, bank::v1beta1::MsgSend},
cosmwasm::wasm::v1::MsgExecuteContract,
},
};

use prost::Message;
Expand Down Expand Up @@ -37,18 +40,18 @@ pub fn wrap_authz(
not_supported => unimplemented!("{not_supported:?}"),
},
CosmosMsg::Stargate { type_url, value } => (type_url.clone(), value.into()),
// CosmosMsg::Bank(bank_msg) => match bank_msg {
// cosmwasm_std::BankMsg::Send { to_address, amount } => (
// MsgSend::TYPE_URL.to_string(),
// MsgSend {
// from_address: sender.to_string(),
// to_address,
// amount: cosmwasm_to_proto_coins(amount),
// }
// .encode_to_vec(),
// ),
// not_supported => unimplemented!("{not_supported:?}"),
// },
CosmosMsg::Bank(bank_msg) => match bank_msg {
cosmwasm_std::BankMsg::Send { to_address, amount } => (
MsgSend::TYPE_URL.to_string(),
MsgSend {
from_address: sender.to_string(),
to_address,
amount: cosmwasm_to_proto_coins(amount),
}
.encode_to_vec(),
),
not_supported => unimplemented!("{not_supported:?}"),
},
not_supported => unimplemented!("{not_supported:?}"),
};

Expand Down
7 changes: 2 additions & 5 deletions contracts/savings-app/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
contract::App,
state::{Config, Position},
};
use crate::{contract::App, state::Position};
use abstract_dex_adapter::msg::DexName;
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Coin, Uint128};
Expand Down Expand Up @@ -53,7 +50,7 @@ pub enum AppExecuteMsg {
#[cfg_attr(feature = "interface", impl_into(QueryMsg))]
#[derive(QueryResponses)]
pub enum AppQueryMsg {
#[returns(Config)]
#[returns(crate::state::Config)]
Config {},
#[returns(AssetsBalanceResponse)]
Balance {},
Expand Down
52 changes: 34 additions & 18 deletions contracts/savings-app/tests/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use abstract_client::Namespace;
use abstract_core::adapter::AdapterBaseMsg;
use abstract_core::adapter::BaseExecuteMsg;
use abstract_core::objects::pool_id::PoolAddressBase;
use abstract_core::objects::AccountId;
use abstract_core::objects::AssetEntry;
use abstract_core::objects::PoolMetadata;
use abstract_core::objects::PoolType;
Expand Down Expand Up @@ -35,6 +36,7 @@ use cw_orch::osmosis_test_tube::osmosis_test_tube::osmosis_std::types::cosmos::b
use cw_orch::osmosis_test_tube::osmosis_test_tube::Runner;
use cw_orch::osmosis_test_tube::osmosis_test_tube::osmosis_std::types::osmosis::concentratedliquidity::v1beta1::MsgWithdrawPosition;
use cw_orch::prelude::*;
use osmosis_std::types::cosmos::bank::v1beta1::SendAuthorization;
use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::CreateConcentratedLiquidityPoolsProposal;
use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::MsgAddToPosition;
use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::MsgCollectIncentives;
Expand Down Expand Up @@ -298,6 +300,10 @@ fn give_authorizations(
savings_app: &Application<OsmosisTestTube, app::AppInterface<OsmosisTestTube>>,
) -> Result<(), anyhow::Error> {
let chain = savings_app.get_chain();
let abs = Abstract::load_from(chain.clone())?;
let dex_fee_account = AbstractAccount::new(&abs, AccountId::local(0));
let dex_fee_addr = dex_fee_account.proxy.addr_str()?;

let app = chain.app.borrow();
let authorization_urls = [
MsgCreatePosition::TYPE_URL,
Expand All @@ -324,24 +330,34 @@ fn give_authorizations(
chain.sender.as_ref(),
)?;
}
// TODO: keeping it separate since we may want to be more restrictive on this one
// let _: ExecuteResponse<MsgGrantResponse> = app.execute(
// MsgGrant {
// granter: chain.sender().to_string(),
// grantee: savings_app.addr_str().unwrap(),
// grant: Some(Grant {
// authorization: Some(
// GenericAuthorization {
// msg: MsgSend::TYPE_URL.to_string(),
// }
// .to_any(),
// ),
// expiration: None,
// }),
// },
// MsgGrant::TYPE_URL,
// chain.sender.as_ref(),
// )?;
// Dex fees
let _: ExecuteResponse<MsgGrantResponse> = app.execute(
MsgGrant {
granter: chain.sender().to_string(),
grantee: savings_app.addr_str().unwrap(),
grant: Some(Grant {
authorization: Some(
SendAuthorization {
spend_limit: vec![
osmosis_std::types::cosmos::base::v1beta1::Coin {
denom: factory_denom(chain, USDC),
amount: LOTS.to_string(),
},
osmosis_std::types::cosmos::base::v1beta1::Coin {
denom: factory_denom(chain, USDT),
amount: LOTS.to_string(),
},
],
allow_list: vec![dex_fee_addr],
}
.to_any(),
),
expiration: None,
}),
},
MsgGrant::TYPE_URL,
chain.sender.as_ref(),
)?;

Ok(())
}
Expand Down

0 comments on commit f2caeaf

Please sign in to comment.