Skip to content

Commit

Permalink
feat: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ratik committed Dec 14, 2023
1 parent 17047b4 commit 73cd18d
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 92 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions contracts/core/src/bin/lido-core-schema.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 6 additions & 11 deletions contracts/core/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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");

Expand All @@ -25,7 +20,7 @@ pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: CoreInstantiateMsg,
msg: InstantiateMsg,
) -> NeutronResult<Response> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

Expand Down
2 changes: 0 additions & 2 deletions contracts/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
pub mod contract;
pub mod error;
pub mod msg;
pub mod state;
3 changes: 2 additions & 1 deletion contracts/factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
11 changes: 7 additions & 4 deletions contracts/token/src/bin/lido-token-schema.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
36 changes: 10 additions & 26 deletions contracts/token/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -35,28 +38,9 @@ pub enum ContractError {

pub type ContractResult<T> = Result<T, ContractError>;

#[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<Addr> = Item::new("core");
const DENOM: Item<String> = Item::new("denom");

const CREATE_DENOM_REPLY_ID: u64 = 1;

fn response<A: Into<Attribute>>(
Expand All @@ -79,7 +63,7 @@ pub fn instantiate(
deps: DepsMut<NeutronQuery>,
_env: Env,
_info: MessageInfo,
msg: TokenInstantiateMsg,
msg: InstantiateMsg,
) -> ContractResult<Response<NeutronMsg>> {
cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

Expand All @@ -104,14 +88,14 @@ pub fn execute(
deps: DepsMut<NeutronQuery>,
_env: Env,
info: MessageInfo,
msg: TokenExecuteMsg,
msg: ExecuteMsg,
) -> ContractResult<Response<NeutronMsg>> {
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),
}
}

Expand Down
20 changes: 10 additions & 10 deletions contracts/token/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
},
Expand Down Expand Up @@ -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(),
},
Expand All @@ -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(),
},
Expand Down Expand Up @@ -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(),
},
Expand All @@ -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!(
Expand All @@ -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!(
Expand All @@ -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!(
Expand All @@ -306,7 +306,7 @@ fn burn() {
deps.as_mut(),
mock_env(),
mock_info("core", &[coin(140, "denom")]),
crate::TokenExecuteMsg::Burn {},
crate::ExecuteMsg::Burn {},
)
.unwrap();

Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/src/testcases/interceptor-authz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Interchain interceptor with AuthZ support', () => {

beforeAll(async () => {
context.park = await setupPark(
'interceptor-authz',
'interceptorauthz',
['neutron', 'gaia'],
true,
);
Expand Down
1 change: 1 addition & 0 deletions packages/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ library = []
[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }


[dev-dependencies]
Expand Down
1 change: 1 addition & 0 deletions packages/base/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod msg;
pub mod state;
21 changes: 0 additions & 21 deletions packages/base/src/msg.rs

This file was deleted.

29 changes: 18 additions & 11 deletions contracts/core/src/msg.rs → packages/base/src/msg/core.rs
Original file line number Diff line number Diff line change
@@ -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<CoreInstantiateMsg> 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]
Expand All @@ -31,3 +27,14 @@ pub enum ExecuteMsg {
}
#[cw_serde]
pub enum MigrateMsg {}

impl From<InstantiateMsg> 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,
}
}
}
2 changes: 2 additions & 0 deletions packages/base/src/msg/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod core;
pub mod token;
16 changes: 16 additions & 0 deletions packages/base/src/msg/token.rs
Original file line number Diff line number Diff line change
@@ -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 {}
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/base/src/state/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod core;
pub mod token;
18 changes: 18 additions & 0 deletions packages/base/src/state/token.rs
Original file line number Diff line number Diff line change
@@ -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<Addr> = Item::new("core");
pub const DENOM: Item<String> = Item::new("denom");

0 comments on commit 73cd18d

Please sign in to comment.