diff --git a/Cargo.lock b/Cargo.lock index bb176c3f..1bae864c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -773,6 +773,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cw-multi-test 0.20.0", + "cw-storage-plus", ] [[package]] diff --git a/contracts/core/src/bin/lido-core-schema.rs b/contracts/core/src/bin/lido-core-schema.rs index 7bc67351..eb460abc 100644 --- a/contracts/core/src/bin/lido-core-schema.rs +++ b/contracts/core/src/bin/lido-core-schema.rs @@ -1,13 +1,12 @@ use cosmwasm_schema::write_api; -use lido_core::{ - msg::{ExecuteMsg, MigrateMsg}, - state::QueryMsg, +use lido_staking_base::{ + msg::core::{ExecuteMsg, InstantiateMsg, MigrateMsg}, + state::core::QueryMsg, }; -use lido_staking_base::msg::CoreInstantiateMsg; fn main() { write_api! { - instantiate: CoreInstantiateMsg, + instantiate: InstantiateMsg, query: QueryMsg, execute: ExecuteMsg, migrate: MigrateMsg diff --git a/contracts/core/src/contract.rs b/contracts/core/src/contract.rs index 5590cd42..bbef1fd2 100644 --- a/contracts/core/src/contract.rs +++ b/contracts/core/src/contract.rs @@ -1,22 +1,17 @@ -use std::str::FromStr; - +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, }; - use cw2::set_contract_version; -use lido_staking_base::msg::{CoreInstantiateMsg, TokenExecuteMsg}; +use lido_staking_base::msg::core::{ExecuteMsg, InstantiateMsg}; +use lido_staking_base::msg::token::ExecuteMsg as TokenExecuteMsg; +use lido_staking_base::state::core::{QueryMsg, CONFIG}; use neutron_sdk::{ bindings::{msg::NeutronMsg, query::NeutronQuery}, NeutronResult, }; - -use crate::{ - error::{ContractError, ContractResult}, - msg::ExecuteMsg, - state::{QueryMsg, CONFIG}, -}; +use std::str::FromStr; const CONTRACT_NAME: &str = concat!("crates.io:lido-neutron-contracts__", env!("CARGO_PKG_NAME")); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -25,7 +20,7 @@ pub fn instantiate( deps: DepsMut, _env: Env, _info: MessageInfo, - msg: CoreInstantiateMsg, + msg: InstantiateMsg, ) -> NeutronResult { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; diff --git a/contracts/core/src/lib.rs b/contracts/core/src/lib.rs index a5abdbb0..ed729875 100644 --- a/contracts/core/src/lib.rs +++ b/contracts/core/src/lib.rs @@ -1,4 +1,2 @@ pub mod contract; pub mod error; -pub mod msg; -pub mod state; diff --git a/contracts/factory/src/contract.rs b/contracts/factory/src/contract.rs index a5e0dcac..54ba4f54 100644 --- a/contracts/factory/src/contract.rs +++ b/contracts/factory/src/contract.rs @@ -7,7 +7,8 @@ use cosmwasm_std::{ Deps, DepsMut, Env, HexBinary, MessageInfo, Response, StdError, StdResult, WasmMsg, }; use cw2::set_contract_version; -use lido_staking_base::msg::{CoreInstantiateMsg, TokenInstantiateMsg}; +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}; const CONTRACT_NAME: &str = concat!("crates.io:lido-neutron-contracts__", env!("CARGO_PKG_NAME")); diff --git a/contracts/token/src/bin/lido-token-schema.rs b/contracts/token/src/bin/lido-token-schema.rs index d57efe2f..555f2cf1 100644 --- a/contracts/token/src/bin/lido-token-schema.rs +++ b/contracts/token/src/bin/lido-token-schema.rs @@ -1,12 +1,15 @@ use cosmwasm_schema::write_api; -use lido_staking_base::msg::{TokenExecuteMsg, TokenInstantiateMsg}; -use lido_token::{MigrateMsg, QueryMsg}; + +use lido_staking_base::{ + msg::token::{ExecuteMsg, InstantiateMsg, MigrateMsg}, + state::token::QueryMsg, +}; fn main() { write_api! { - instantiate: TokenInstantiateMsg, + instantiate: InstantiateMsg, query: QueryMsg, - execute: TokenExecuteMsg, + execute: ExecuteMsg, migrate: MigrateMsg } } diff --git a/contracts/token/src/lib.rs b/contracts/token/src/lib.rs index 8a1f2a25..6a543a1d 100644 --- a/contracts/token/src/lib.rs +++ b/contracts/token/src/lib.rs @@ -1,9 +1,12 @@ use cosmwasm_std::{ - attr, ensure_eq, ensure_ne, to_json_binary, Addr, Attribute, Binary, Deps, DepsMut, Env, Event, + attr, ensure_eq, ensure_ne, to_json_binary, Attribute, Binary, Deps, DepsMut, Env, Event, MessageInfo, Reply, Response, StdError, SubMsg, Uint128, }; -use cw_storage_plus::Item; -use lido_staking_base::msg::{TokenExecuteMsg, TokenInstantiateMsg}; + +use lido_staking_base::{ + msg::token::{ExecuteMsg, InstantiateMsg, MigrateMsg}, + state::token::{ConfigResponse, QueryMsg, CORE_ADDRESS, DENOM}, +}; use neutron_sdk::{ bindings::{msg::NeutronMsg, query::NeutronQuery}, query::token_factory::query_full_denom, @@ -35,28 +38,9 @@ pub enum ContractError { pub type ContractResult = Result; -#[cosmwasm_schema::cw_serde] -#[derive(cosmwasm_schema::QueryResponses)] -pub enum QueryMsg { - #[returns(ConfigResponse)] - Config {}, -} - -#[cosmwasm_schema::cw_serde] -pub struct ConfigResponse { - pub core_address: String, - pub denom: String, -} - -#[cosmwasm_schema::cw_serde] -pub enum MigrateMsg {} - const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); -const CORE_ADDRESS: Item = Item::new("core"); -const DENOM: Item = Item::new("denom"); - const CREATE_DENOM_REPLY_ID: u64 = 1; fn response>( @@ -79,7 +63,7 @@ pub fn instantiate( deps: DepsMut, _env: Env, _info: MessageInfo, - msg: TokenInstantiateMsg, + msg: InstantiateMsg, ) -> ContractResult> { cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; @@ -104,14 +88,14 @@ pub fn execute( deps: DepsMut, _env: Env, info: MessageInfo, - msg: TokenExecuteMsg, + msg: ExecuteMsg, ) -> ContractResult> { let core = CORE_ADDRESS.load(deps.storage)?; ensure_eq!(info.sender, core, ContractError::Unauthorized); match msg { - TokenExecuteMsg::Mint { amount, receiver } => mint(deps, amount, receiver), - TokenExecuteMsg::Burn {} => burn(deps, info), + ExecuteMsg::Mint { amount, receiver } => mint(deps, amount, receiver), + ExecuteMsg::Burn {} => burn(deps, info), } } diff --git a/contracts/token/src/tests.rs b/contracts/token/src/tests.rs index dbdf8bbc..3b94f1eb 100644 --- a/contracts/token/src/tests.rs +++ b/contracts/token/src/tests.rs @@ -4,7 +4,7 @@ use cosmwasm_std::{ to_json_binary, Addr, ContractResult, CosmosMsg, Event, OwnedDeps, Querier, QuerierResult, QueryRequest, Reply, ReplyOn, SubMsgResult, SystemError, Uint128, }; -use lido_staking_base::msg::TokenInstantiateMsg; +use lido_staking_base::msg::token::InstantiateMsg; use neutron_sdk::{ bindings::{msg::NeutronMsg, query::NeutronQuery}, query::token_factory::FullDenomResponse, @@ -27,7 +27,7 @@ fn instantiate() { deps.as_mut(), mock_env(), mock_info("admin", &[]), - TokenInstantiateMsg { + InstantiateMsg { core_address: "core".to_string(), subdenom: "subdenom".to_string(), }, @@ -150,7 +150,7 @@ fn mint_zero() { deps.as_mut(), mock_env(), mock_info("core", &[]), - crate::TokenExecuteMsg::Mint { + crate::ExecuteMsg::Mint { amount: Uint128::zero(), receiver: "receiver".to_string(), }, @@ -173,7 +173,7 @@ fn mint() { deps.as_mut(), mock_env(), mock_info("core", &[]), - crate::TokenExecuteMsg::Mint { + crate::ExecuteMsg::Mint { amount: Uint128::new(220), receiver: "receiver".to_string(), }, @@ -211,7 +211,7 @@ fn mint_stranger() { deps.as_mut(), mock_env(), mock_info("stranger", &[]), - crate::TokenExecuteMsg::Mint { + crate::ExecuteMsg::Mint { amount: Uint128::new(220), receiver: "receiver".to_string(), }, @@ -235,7 +235,7 @@ fn burn_zero() { deps.as_mut(), mock_env(), mock_info("core", &[]), - crate::TokenExecuteMsg::Burn {}, + crate::ExecuteMsg::Burn {}, ) .unwrap_err(); assert_eq!( @@ -258,7 +258,7 @@ fn burn_multiple_coins() { deps.as_mut(), mock_env(), mock_info("core", &[coin(20, "coin1"), coin(10, "denom")]), - crate::TokenExecuteMsg::Burn {}, + crate::ExecuteMsg::Burn {}, ) .unwrap_err(); assert_eq!( @@ -281,7 +281,7 @@ fn burn_invalid_coin() { deps.as_mut(), mock_env(), mock_info("core", &[coin(20, "coin1")]), - crate::TokenExecuteMsg::Burn {}, + crate::ExecuteMsg::Burn {}, ) .unwrap_err(); assert_eq!( @@ -306,7 +306,7 @@ fn burn() { deps.as_mut(), mock_env(), mock_info("core", &[coin(140, "denom")]), - crate::TokenExecuteMsg::Burn {}, + crate::ExecuteMsg::Burn {}, ) .unwrap(); @@ -340,7 +340,7 @@ fn burn_stranger() { deps.as_mut(), mock_env(), mock_info("stranger", &[coin(160, "denom")]), - crate::TokenExecuteMsg::Burn {}, + crate::ExecuteMsg::Burn {}, ) .unwrap_err(); diff --git a/integration_tests/src/testcases/interceptor-authz.test.ts b/integration_tests/src/testcases/interceptor-authz.test.ts index a497cb00..9c3bffa9 100644 --- a/integration_tests/src/testcases/interceptor-authz.test.ts +++ b/integration_tests/src/testcases/interceptor-authz.test.ts @@ -49,7 +49,7 @@ describe('Interchain interceptor with AuthZ support', () => { beforeAll(async () => { context.park = await setupPark( - 'interceptor-authz', + 'interceptorauthz', ['neutron', 'gaia'], true, ); diff --git a/packages/base/Cargo.toml b/packages/base/Cargo.toml index e1e18bc5..e922d147 100644 --- a/packages/base/Cargo.toml +++ b/packages/base/Cargo.toml @@ -25,6 +25,7 @@ library = [] [dependencies] cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } [dev-dependencies] diff --git a/packages/base/src/lib.rs b/packages/base/src/lib.rs index d0e87a0d..685329d1 100644 --- a/packages/base/src/lib.rs +++ b/packages/base/src/lib.rs @@ -1 +1,2 @@ pub mod msg; +pub mod state; diff --git a/packages/base/src/msg.rs b/packages/base/src/msg.rs deleted file mode 100644 index 7b4d9c00..00000000 --- a/packages/base/src/msg.rs +++ /dev/null @@ -1,21 +0,0 @@ -use cosmwasm_schema::cw_serde; -use cosmwasm_std::Uint128; - -#[cw_serde] -pub enum TokenExecuteMsg { - Mint { amount: Uint128, receiver: String }, - Burn {}, -} -#[cw_serde] -pub struct TokenInstantiateMsg { - pub core_address: String, - pub subdenom: String, -} - -#[cw_serde] -pub struct CoreInstantiateMsg { - pub token_contract: String, - pub puppeteer_contract: String, - pub strategy_contract: String, - pub owner: String, -} diff --git a/contracts/core/src/msg.rs b/packages/base/src/msg/core.rs similarity index 68% rename from contracts/core/src/msg.rs rename to packages/base/src/msg/core.rs index 2306edaf..c03f9392 100644 --- a/contracts/core/src/msg.rs +++ b/packages/base/src/msg/core.rs @@ -1,18 +1,14 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::Uint128; -use lido_staking_base::msg::CoreInstantiateMsg; -use crate::state::Config; +use crate::state::core::Config; -impl From for Config { - fn from(val: CoreInstantiateMsg) -> Self { - Config { - token_contract: val.token_contract, - puppeteer_contract: val.puppeteer_contract, - strategy_contract: val.strategy_contract, - owner: val.owner, - } - } +#[cw_serde] +pub struct InstantiateMsg { + pub token_contract: String, + pub puppeteer_contract: String, + pub strategy_contract: String, + pub owner: String, } #[cw_serde] @@ -31,3 +27,14 @@ pub enum ExecuteMsg { } #[cw_serde] pub enum MigrateMsg {} + +impl From for Config { + fn from(val: InstantiateMsg) -> Self { + Config { + token_contract: val.token_contract, + puppeteer_contract: val.puppeteer_contract, + strategy_contract: val.strategy_contract, + owner: val.owner, + } + } +} diff --git a/packages/base/src/msg/mod.rs b/packages/base/src/msg/mod.rs new file mode 100644 index 00000000..fc69d71e --- /dev/null +++ b/packages/base/src/msg/mod.rs @@ -0,0 +1,2 @@ +pub mod core; +pub mod token; diff --git a/packages/base/src/msg/token.rs b/packages/base/src/msg/token.rs new file mode 100644 index 00000000..d6f98a42 --- /dev/null +++ b/packages/base/src/msg/token.rs @@ -0,0 +1,16 @@ +use cosmwasm_schema::cw_serde; +use cosmwasm_std::Uint128; + +#[cw_serde] +pub enum ExecuteMsg { + Mint { amount: Uint128, receiver: String }, + Burn {}, +} +#[cw_serde] +pub struct InstantiateMsg { + pub core_address: String, + pub subdenom: String, +} + +#[cosmwasm_schema::cw_serde] +pub enum MigrateMsg {} diff --git a/contracts/core/src/state.rs b/packages/base/src/state/core.rs similarity index 100% rename from contracts/core/src/state.rs rename to packages/base/src/state/core.rs diff --git a/packages/base/src/state/mod.rs b/packages/base/src/state/mod.rs new file mode 100644 index 00000000..fc69d71e --- /dev/null +++ b/packages/base/src/state/mod.rs @@ -0,0 +1,2 @@ +pub mod core; +pub mod token; diff --git a/packages/base/src/state/token.rs b/packages/base/src/state/token.rs new file mode 100644 index 00000000..6af60a57 --- /dev/null +++ b/packages/base/src/state/token.rs @@ -0,0 +1,18 @@ +use cosmwasm_std::Addr; +use cw_storage_plus::Item; + +#[cosmwasm_schema::cw_serde] +#[derive(cosmwasm_schema::QueryResponses)] +pub enum QueryMsg { + #[returns(ConfigResponse)] + Config {}, +} + +#[cosmwasm_schema::cw_serde] +pub struct ConfigResponse { + pub core_address: String, + pub denom: String, +} + +pub const CORE_ADDRESS: Item = Item::new("core"); +pub const DENOM: Item = Item::new("denom");