diff --git a/Cargo.lock b/Cargo.lock index 0baaa3489..a7a13282d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -768,7 +768,6 @@ dependencies = [ "cw-multi-test", "cw-orch", "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", "cw20", ] @@ -1018,7 +1017,6 @@ dependencies = [ "cosmwasm-std", "cw-multi-test", "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", ] [[package]] diff --git a/contracts/app/andromeda-app-contract/src/contract.rs b/contracts/app/andromeda-app-contract/src/contract.rs index 49f3ef655..898228199 100644 --- a/contracts/app/andromeda-app-contract/src/contract.rs +++ b/contracts/app/andromeda-app-contract/src/contract.rs @@ -1,14 +1,16 @@ -use crate::reply::on_component_instantiation; -use crate::state::{add_app_component, create_cross_chain_message, ADO_ADDRESSES, APP_NAME}; +use crate::{ + reply::on_component_instantiation, + state::{add_app_component, create_cross_chain_message, ADO_ADDRESSES, APP_NAME}, +}; use andromeda_app::app::{ExecuteMsg, InstantiateMsg, QueryMsg}; -use andromeda_std::ado_contract::ADOContract; -use andromeda_std::amp::AndrAddr; -use andromeda_std::common::context::ExecuteContext; -use andromeda_std::common::reply::ReplyId; -use andromeda_std::os::vfs::{convert_component_name, ExecuteMsg as VFSExecuteMsg}; use andromeda_std::{ - ado_base::InstantiateMsg as BaseInstantiateMsg, ado_base::MigrateMsg, common::encode_binary, + ado_base::{InstantiateMsg as BaseInstantiateMsg, MigrateMsg}, + ado_contract::ADOContract, + amp::AndrAddr, + andr_execute_fn, + common::{encode_binary, reply::ReplyId}, error::ContractError, + os::vfs::{convert_component_name, ExecuteMsg as VFSExecuteMsg}, }; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; @@ -165,23 +167,8 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result Result { - let ctx = ExecuteContext::new(deps, info, env); - match msg { - ExecuteMsg::AMPReceive(pkt) => { - ADOContract::default().execute_amp_receive(ctx, pkt, handle_execute) - } - _ => handle_execute(ctx, msg), - } -} - -pub fn handle_execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result { +#[andr_execute_fn] +pub fn execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result { match msg { ExecuteMsg::AddAppComponent { component } => { execute::handle_add_app_component(ctx, component) diff --git a/contracts/app/andromeda-app-contract/src/execute.rs b/contracts/app/andromeda-app-contract/src/execute.rs index 02eb31540..bc17b27fc 100644 --- a/contracts/app/andromeda-app-contract/src/execute.rs +++ b/contracts/app/andromeda-app-contract/src/execute.rs @@ -34,11 +34,6 @@ pub fn handle_add_app_component( !matches!(component.component_type, ComponentType::CrossChain(..)), ContractError::CrossChainComponentsCurrentlyDisabled {} ); - let contract = ADOContract::default(); - ensure!( - contract.is_contract_owner(ctx.deps.storage, sender)?, - ContractError::Unauthorized {} - ); let idx = add_app_component(ctx.deps.storage, &component)?; ensure!(idx < 50, ContractError::TooManyAppComponents {}); diff --git a/contracts/data-storage/andromeda-primitive/Cargo.toml b/contracts/data-storage/andromeda-primitive/Cargo.toml index 8e8d64d98..7ce9092f4 100644 --- a/contracts/data-storage/andromeda-primitive/Cargo.toml +++ b/contracts/data-storage/andromeda-primitive/Cargo.toml @@ -30,7 +30,6 @@ testing = ["cw-multi-test", "andromeda-testing"] cosmwasm-std = { workspace = true } cosmwasm-schema = { workspace = true } cw-storage-plus = { workspace = true } -cw-utils = { workspace = true } cw20 = { workspace = true } andromeda-std = { workspace = true, features = ["rates"] } diff --git a/contracts/data-storage/andromeda-primitive/src/contract.rs b/contracts/data-storage/andromeda-primitive/src/contract.rs index 22683111f..f77ca198b 100644 --- a/contracts/data-storage/andromeda-primitive/src/contract.rs +++ b/contracts/data-storage/andromeda-primitive/src/contract.rs @@ -1,17 +1,20 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError}; +use cosmwasm_std::{ensure, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError}; +use crate::execute::update_restriction; use andromeda_data_storage::primitive::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use andromeda_std::ado_base::rates::{Rate, RatesMessage}; use andromeda_std::{ ado_base::{InstantiateMsg as BaseInstantiateMsg, MigrateMsg}, ado_contract::ADOContract, - common::{context::ExecuteContext, encode_binary}, + andr_execute_fn, + common::encode_binary, error::ContractError, }; use crate::{ - execute::handle_execute, + execute::{delete_value, set_value}, query::{all_keys, get_type, get_value, owner_keys}, state::RESTRICTION, }; @@ -44,19 +47,25 @@ pub fn instantiate( Ok(resp) } -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn execute( - deps: DepsMut, - env: Env, - info: MessageInfo, - msg: ExecuteMsg, -) -> Result { - let ctx = ExecuteContext::new(deps, info, env); - match msg { - ExecuteMsg::AMPReceive(pkt) => { - ADOContract::default().execute_amp_receive(ctx, pkt, handle_execute) - } - _ => handle_execute(ctx, msg), +#[andr_execute_fn] +pub fn execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result { + let action = msg.as_ref().to_string(); + match msg.clone() { + ExecuteMsg::UpdateRestriction { restriction } => update_restriction(ctx, restriction), + ExecuteMsg::SetValue { key, value } => set_value(ctx, key, value, action), + ExecuteMsg::DeleteValue { key } => delete_value(ctx, key), + ExecuteMsg::Rates(rates_message) => match rates_message { + RatesMessage::SetRate { rate, .. } => match rate { + Rate::Local(local_rate) => { + // Percent rates aren't applicable in this case, so we enforce Flat rates + ensure!(local_rate.value.is_flat(), ContractError::InvalidRate {}); + ADOContract::default().execute(ctx, msg) + } + Rate::Contract(_) => ADOContract::default().execute(ctx, msg), + }, + RatesMessage::RemoveRate { .. } => ADOContract::default().execute(ctx, msg), + }, + _ => ADOContract::default().execute(ctx, msg), } } diff --git a/contracts/data-storage/andromeda-primitive/src/execute.rs b/contracts/data-storage/andromeda-primitive/src/execute.rs index 7cf61a6c6..f63ebda7e 100644 --- a/contracts/data-storage/andromeda-primitive/src/execute.rs +++ b/contracts/data-storage/andromeda-primitive/src/execute.rs @@ -1,59 +1,22 @@ -use andromeda_data_storage::primitive::{ExecuteMsg, Primitive, PrimitiveRestriction}; +use crate::{ + query::{get_key_or_default, has_key_permission}, + state::{DATA, KEY_OWNER, RESTRICTION}, +}; +use andromeda_data_storage::primitive::{Primitive, PrimitiveRestriction}; use andromeda_std::{ - ado_base::rates::{Rate, RatesMessage}, ado_contract::ADOContract, - common::{actions::call_action, context::ExecuteContext, rates::get_tax_amount, Funds}, + common::{context::ExecuteContext, rates::get_tax_amount, Funds}, error::ContractError, }; use cosmwasm_std::{ coin, ensure, BankMsg, Coin, CosmosMsg, Deps, MessageInfo, Response, StdError, SubMsg, Uint128, }; -use cw_utils::nonpayable; - -use crate::{ - query::{get_key_or_default, has_key_permission}, - state::{DATA, KEY_OWNER, RESTRICTION}, -}; - -pub fn handle_execute(mut ctx: ExecuteContext, msg: ExecuteMsg) -> Result { - let action = msg.as_ref().to_string(); - call_action( - &mut ctx.deps, - &ctx.info, - &ctx.env, - &ctx.amp_ctx, - msg.as_ref(), - )?; - - match msg.clone() { - ExecuteMsg::UpdateRestriction { restriction } => update_restriction(ctx, restriction), - ExecuteMsg::SetValue { key, value } => set_value(ctx, key, value, action), - ExecuteMsg::DeleteValue { key } => delete_value(ctx, key), - ExecuteMsg::Rates(rates_message) => match rates_message { - RatesMessage::SetRate { rate, .. } => match rate { - Rate::Local(local_rate) => { - // Percent rates aren't applicable in this case, so we enforce Flat rates - ensure!(local_rate.value.is_flat(), ContractError::InvalidRate {}); - ADOContract::default().execute(ctx, msg) - } - Rate::Contract(_) => ADOContract::default().execute(ctx, msg), - }, - RatesMessage::RemoveRate { .. } => ADOContract::default().execute(ctx, msg), - }, - _ => ADOContract::default().execute(ctx, msg), - } -} pub fn update_restriction( ctx: ExecuteContext, restriction: PrimitiveRestriction, ) -> Result { - nonpayable(&ctx.info)?; let sender = ctx.info.sender; - ensure!( - ADOContract::default().is_owner_or_operator(ctx.deps.storage, sender.as_ref())?, - ContractError::Unauthorized {} - ); RESTRICTION.save(ctx.deps.storage, &restriction)?; Ok(Response::new() .add_attribute("method", "update_restriction") @@ -108,7 +71,6 @@ pub fn set_value( } pub fn delete_value(ctx: ExecuteContext, key: Option) -> Result { - nonpayable(&ctx.info)?; let sender = ctx.info.sender; let key = get_key_or_default(&key); diff --git a/contracts/ecosystem/andromeda-vault/Cargo.toml b/contracts/ecosystem/andromeda-vault/Cargo.toml index e62dfee0f..7f3914f57 100644 --- a/contracts/ecosystem/andromeda-vault/Cargo.toml +++ b/contracts/ecosystem/andromeda-vault/Cargo.toml @@ -15,8 +15,6 @@ cosmwasm-std = { workspace = true } cosmwasm-schema = { workspace = true } cw-storage-plus = { workspace = true } -cw-utils = { workspace = true } - andromeda-ecosystem = { workspace = true } andromeda-std = { workspace = true } diff --git a/contracts/ecosystem/andromeda-vault/src/contract.rs b/contracts/ecosystem/andromeda-vault/src/contract.rs index 67d4b8dcc..75c9149ad 100644 --- a/contracts/ecosystem/andromeda-vault/src/contract.rs +++ b/contracts/ecosystem/andromeda-vault/src/contract.rs @@ -5,7 +5,7 @@ use andromeda_ecosystem::vault::{ use andromeda_std::ado_base::ownership::ContractOwnerResponse; use andromeda_std::ado_contract::ADOContract; use andromeda_std::amp::{AndrAddr, Recipient}; -use andromeda_std::common::actions::call_action; +use andromeda_std::andr_execute_fn; use andromeda_std::common::context::ExecuteContext; use andromeda_std::common::encode_binary; use andromeda_std::{ @@ -19,8 +19,6 @@ use cosmwasm_std::{ ContractResult, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, Order, QueryRequest, Reply, ReplyOn, Response, StdError, SubMsg, SystemResult, Uint128, WasmMsg, WasmQuery, }; -use cw_utils::nonpayable; - // version info for migration info const CONTRACT_NAME: &str = "crates.io:andromeda-vault"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -58,31 +56,8 @@ pub fn reply(_deps: DepsMut, _env: Env, msg: Reply) -> Result Result { - let ctx = ExecuteContext::new(deps, info, env); - - match msg { - ExecuteMsg::AMPReceive(pkt) => { - ADOContract::default().execute_amp_receive(ctx, pkt, handle_execute) - } - _ => handle_execute(ctx, msg), - } -} - -pub fn handle_execute(mut ctx: ExecuteContext, msg: ExecuteMsg) -> Result { - call_action( - &mut ctx.deps, - &ctx.info, - &ctx.env, - &ctx.amp_ctx, - msg.as_ref(), - )?; +#[andr_execute_fn] +pub fn execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result { match msg { ExecuteMsg::Deposit { recipient, msg } => execute_deposit(ctx, recipient, msg), ExecuteMsg::WithdrawVault { @@ -216,8 +191,6 @@ pub fn execute_withdraw( strategy: Option, ) -> Result { let ExecuteContext { info, deps, .. } = ctx; - nonpayable(&info)?; - ensure!( !withdrawals.is_empty(), ContractError::InvalidTokensToWithdraw { @@ -339,13 +312,7 @@ fn execute_update_strategy( strategy: StrategyType, address: AndrAddr, ) -> Result { - let ExecuteContext { - deps, env, info, .. - } = ctx; - ensure!( - ADOContract::default().is_contract_owner(deps.storage, info.sender.as_ref())?, - ContractError::Unauthorized {} - ); + let ExecuteContext { deps, env, .. } = ctx; let strategy_addr = address.get_raw_address(&deps.as_ref())?; //The vault contract must be an operator for the given contract in order to enable withdrawals diff --git a/packages/andromeda-app/src/app.rs b/packages/andromeda-app/src/app.rs index 9ee9372e3..0dcc0e890 100644 --- a/packages/andromeda-app/src/app.rs +++ b/packages/andromeda-app/src/app.rs @@ -311,6 +311,7 @@ pub struct InstantiateMsg { #[andr_exec] #[cw_serde] pub enum ExecuteMsg { + #[attrs(restricted)] AddAppComponent { component: AppComponent, }, diff --git a/packages/andromeda-data-storage/src/primitive.rs b/packages/andromeda-data-storage/src/primitive.rs index e5100f6e5..de98cec53 100644 --- a/packages/andromeda-data-storage/src/primitive.rs +++ b/packages/andromeda-data-storage/src/primitive.rs @@ -18,12 +18,10 @@ pub enum ExecuteMsg { value: Primitive, }, /// If key is not specified the default key will be used. - DeleteValue { - key: Option, - }, - UpdateRestriction { - restriction: PrimitiveRestriction, - }, + #[attrs(nonpayable)] + DeleteValue { key: Option }, + #[attrs(restricted, nonpayable)] + UpdateRestriction { restriction: PrimitiveRestriction }, } #[andr_query] diff --git a/packages/andromeda-ecosystem/src/vault.rs b/packages/andromeda-ecosystem/src/vault.rs index 360195634..063fa2948 100644 --- a/packages/andromeda-ecosystem/src/vault.rs +++ b/packages/andromeda-ecosystem/src/vault.rs @@ -101,11 +101,13 @@ pub struct InstantiateMsg {} #[andr_exec] #[cw_serde] pub enum ExecuteMsg { + #[attrs(nonpayable)] WithdrawVault { recipient: Option, withdrawals: Vec, strategy: Option, }, + #[attrs(restriced)] UpdateStrategy { strategy: StrategyType, address: AndrAddr,