diff --git a/contracts/core/src/contract.rs b/contracts/core/src/contract.rs index 8bbc0a6a..9d1a3a01 100644 --- a/contracts/core/src/contract.rs +++ b/contracts/core/src/contract.rs @@ -1,17 +1,16 @@ use crate::error::{ContractError, ContractResult}; use cosmwasm_std::{ - attr, ensure_eq, ensure_ne, entry_point, to_json_binary, Binary, CosmosMsg, Decimal, Deps, - DepsMut, Env, MessageInfo, Response, StdResult, Uint128, WasmMsg, + attr, ensure_eq, ensure_ne, entry_point, to_json_binary, Attribute, Binary, CosmosMsg, Decimal, + Deps, DepsMut, Env, MessageInfo, Response, StdResult, Uint128, WasmMsg, }; use cw2::set_contract_version; +use lido_staking_base::helpers::answer::response; use lido_staking_base::msg::core::{ExecuteMsg, InstantiateMsg, QueryMsg}; use lido_staking_base::msg::token::ExecuteMsg as TokenExecuteMsg; use lido_staking_base::state::core::CONFIG; -use neutron_sdk::{ - bindings::{msg::NeutronMsg, query::NeutronQuery}, - NeutronResult, -}; +use neutron_sdk::bindings::{msg::NeutronMsg, query::NeutronQuery}; use std::str::FromStr; +use std::vec; const CONTRACT_NAME: &str = concat!("crates.io:lido-neutron-contracts__", env!("CARGO_PKG_NAME")); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -21,11 +20,17 @@ pub fn instantiate( _env: Env, _info: MessageInfo, msg: InstantiateMsg, -) -> NeutronResult { +) -> ContractResult> { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - CONFIG.save(deps.storage, &msg.into())?; - Ok(Response::default()) + CONFIG.save(deps.storage, &msg.clone().into())?; + let attrs: Vec = vec![ + attr("token_contract", msg.token_contract), + attr("puppeteer_contract", msg.puppeteer_contract), + attr("strategy_contract", msg.strategy_contract), + attr("owner", msg.owner), + ]; + Ok(response("instantiate", CONTRACT_NAME, attrs)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -116,8 +121,7 @@ fn execute_bond( })?, funds: vec![], })]; - - Ok(Response::default().add_messages(msgs).add_attributes(attrs)) + Ok(response("execute-bond", CONTRACT_NAME, attrs).add_messages(msgs)) } fn check_denom(_denom: String) -> ContractResult<()> { @@ -155,7 +159,7 @@ fn execute_update_config( attrs.push(attr("owner", owner)); } CONFIG.save(deps.storage, &config)?; - Ok(Response::default().add_attributes(attrs)) + Ok(response("execute-update_config", CONTRACT_NAME, attrs)) } fn execute_unbond( diff --git a/contracts/factory/src/contract.rs b/contracts/factory/src/contract.rs index 54ba4f54..64ae1d99 100644 --- a/contracts/factory/src/contract.rs +++ b/contracts/factory/src/contract.rs @@ -1,15 +1,21 @@ use crate::{ + error::ContractResult, msg::{ExecuteMsg, InstantiateMsg, QueryMsg}, state::{Config, State, CONFIG, STATE}, }; use cosmwasm_std::{ attr, entry_point, instantiate2_address, to_json_binary, Binary, CodeInfoResponse, CosmosMsg, - Deps, DepsMut, Env, HexBinary, MessageInfo, Response, StdError, StdResult, WasmMsg, + Deps, DepsMut, Env, HexBinary, MessageInfo, Response, StdResult, WasmMsg, }; use cw2::set_contract_version; -use lido_staking_base::msg::core::InstantiateMsg as CoreInstantiateMsg; use lido_staking_base::msg::token::InstantiateMsg as TokenInstantiateMsg; -use neutron_sdk::{bindings::query::NeutronQuery, NeutronResult}; +use lido_staking_base::{ + helpers::answer::response, msg::core::InstantiateMsg as CoreInstantiateMsg, +}; +use neutron_sdk::{ + bindings::{msg::NeutronMsg, query::NeutronQuery}, + NeutronResult, +}; const CONTRACT_NAME: &str = concat!("crates.io:lido-neutron-contracts__", env!("CARGO_PKG_NAME")); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -20,20 +26,28 @@ pub fn instantiate( _env: Env, info: MessageInfo, msg: InstantiateMsg, -) -> NeutronResult { +) -> ContractResult> { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; CONFIG.save( deps.storage, &Config { - salt: msg.salt, + salt: msg.salt.to_string(), token_code_id: msg.token_code_id, core_code_id: msg.core_code_id, owner: info.sender.to_string(), - subdenom: msg.subdenom, + subdenom: msg.subdenom.to_string(), }, )?; - Ok(Response::default()) + + let attrs = vec![ + attr("salt", msg.salt), + attr("token_code_id", msg.token_code_id.to_string()), + attr("core_code_id", msg.core_code_id.to_string()), + attr("owner", info.sender), + attr("subdenom", msg.subdenom), + ]; + Ok(response("instantiate", CONTRACT_NAME, attrs)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -49,13 +63,17 @@ pub fn execute( env: Env, info: MessageInfo, msg: ExecuteMsg, -) -> NeutronResult { +) -> ContractResult> { match msg { ExecuteMsg::Init {} => execute_init(deps, env, info), } } -fn execute_init(deps: DepsMut, env: Env, _info: MessageInfo) -> NeutronResult { +fn execute_init( + deps: DepsMut, + env: Env, + _info: MessageInfo, +) -> ContractResult> { let config = CONFIG.load(deps.storage)?; let canonical_self_address = deps.api.addr_canonicalize(env.contract.address.as_str())?; let mut attrs = vec![attr("action", "init")]; @@ -65,11 +83,10 @@ fn execute_init(deps: DepsMut, env: Env, _info: MessageInfo) -> NeutronResult NeutronResult NeutronResult { diff --git a/contracts/factory/src/error.rs b/contracts/factory/src/error.rs index 19407370..ac50d00c 100644 --- a/contracts/factory/src/error.rs +++ b/contracts/factory/src/error.rs @@ -1,11 +1,23 @@ -use cosmwasm_std::Instantiate2AddressError; +use cosmwasm_std::{Instantiate2AddressError, StdError}; +use neutron_sdk::NeutronError; +use thiserror::Error; + +#[derive(Error, Debug, PartialEq)] pub enum ContractError { - Instantiate2Address { - err: Instantiate2AddressError, - code_id: u64, - }, + #[error("{0}")] + Std(#[from] StdError), + + #[error("{0}")] + NeutronError(#[from] NeutronError), + #[error("Could not calculcate instantiate2 address: {0}")] + Instantiate2AddressError(#[from] Instantiate2AddressError), + #[error("Unauthorized")] Unauthorized {}, + #[error("Unimplemented")] Unimplemented {}, + #[error("Unknown")] Unknown {}, } + +pub type ContractResult = Result;