diff --git a/Cargo.lock b/Cargo.lock index d1dfb537..7251589c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -612,6 +612,7 @@ dependencies = [ "cw-storage-plus", "cw2", "cw20", + "lido-helpers", "lido-staking-base", "neutron-sdk", "prost", @@ -660,6 +661,46 @@ dependencies = [ "cw-storage-plus", "cw2", "cw20", + "lido-helpers", + "lido-staking-base", + "neutron-sdk", + "prost", + "prost-types", + "protobuf", + "schemars", + "serde", + "serde-json-wasm 1.0.0", + "tendermint-proto", + "thiserror", +] + +[[package]] +name = "lido-helpers" +version = "1.0.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-multi-test 0.20.0", + "cw-storage-plus", + "neutron-sdk", +] + +[[package]] +name = "lido-hook-tester" +version = "1.0.0" +dependencies = [ + "base64", + "cosmos-sdk-proto", + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-multi-test 0.20.0", + "cw-storage-plus", + "cw2", + "cw20", + "lido-helpers", + "lido-puppeteer-base", "lido-staking-base", "neutron-sdk", "prost", @@ -685,6 +726,7 @@ dependencies = [ "cw-storage-plus", "cw2", "cw20", + "lido-helpers", "lido-puppeteer-base", "lido-staking-base", "neutron-sdk", @@ -710,6 +752,7 @@ dependencies = [ "cw-storage-plus", "cw2", "cw20", + "lido-helpers", "lido-puppeteer-base", "lido-staking-base", "neutron-sdk", @@ -736,7 +779,7 @@ dependencies = [ "cw-storage-plus", "cw2", "cw20", - "lido-staking-base", + "lido-helpers", "neutron-sdk", "prost", "prost-types", @@ -757,6 +800,7 @@ dependencies = [ "cosmwasm-storage", "cw-multi-test 0.20.0", "cw-storage-plus", + "lido-puppeteer-base", "neutron-sdk", ] @@ -816,6 +860,7 @@ dependencies = [ "cw-storage-plus", "cw-utils", "cw2", + "lido-helpers", "lido-staking-base", "neutron-sdk", "thiserror", @@ -834,6 +879,7 @@ dependencies = [ "cw-storage-plus", "cw2", "cw20", + "lido-helpers", "lido-staking-base", "neutron-sdk", "prost", diff --git a/Cargo.toml b/Cargo.toml index 54f42d1a..5a4337f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,11 @@ members = [ "contracts/token", "contracts/validators-set", "contracts/strategy", + "contracts/hook-tester", "contracts/core", "packages/puppeteer-base", "packages/base", + "packages/helpers", ] resolver = "2" @@ -45,6 +47,7 @@ bech32 = { version = "0.9.1" } lido-puppeteer-base = { path = "./packages/puppeteer-base", default-features = false } lido-staking-base = { path = "./packages/base", default-features = false } +lido-helpers = { path = "./packages/helpers", default-features = false } thiserror = "1.0.50" [profile.release] diff --git a/contracts/core/Cargo.toml b/contracts/core/Cargo.toml index 803c4350..6bbc22fe 100644 --- a/contracts/core/Cargo.toml +++ b/contracts/core/Cargo.toml @@ -40,6 +40,7 @@ serde = { workspace = true } serde-json-wasm = { workspace = true } thiserror = { workspace = true } lido-staking-base = { workspace = true } +lido-helpers = { workspace = true } neutron-sdk = { workspace = true } [dev-dependencies] diff --git a/contracts/core/src/contract.rs b/contracts/core/src/contract.rs index 9d1a3a01..2ac9bc7d 100644 --- a/contracts/core/src/contract.rs +++ b/contracts/core/src/contract.rs @@ -4,7 +4,7 @@ use cosmwasm_std::{ Deps, DepsMut, Env, MessageInfo, Response, StdResult, Uint128, WasmMsg, }; use cw2::set_contract_version; -use lido_staking_base::helpers::answer::response; +use lido_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; diff --git a/contracts/factory/Cargo.toml b/contracts/factory/Cargo.toml index 46b2d641..55c8da52 100644 --- a/contracts/factory/Cargo.toml +++ b/contracts/factory/Cargo.toml @@ -40,6 +40,7 @@ serde = { workspace = true } serde-json-wasm = { workspace = true } thiserror = { workspace = true } lido-staking-base = { workspace = true } +lido-helpers = { workspace = true } neutron-sdk = { workspace = true } [dev-dependencies] diff --git a/contracts/factory/src/contract.rs b/contracts/factory/src/contract.rs index 64ae1d99..03a4ca61 100644 --- a/contracts/factory/src/contract.rs +++ b/contracts/factory/src/contract.rs @@ -8,10 +8,9 @@ use cosmwasm_std::{ Deps, DepsMut, Env, HexBinary, MessageInfo, Response, StdResult, WasmMsg, }; use cw2::set_contract_version; +use lido_helpers::answer::response; +use lido_staking_base::msg::core::InstantiateMsg as CoreInstantiateMsg; use lido_staking_base::msg::token::InstantiateMsg as TokenInstantiateMsg; -use lido_staking_base::{ - helpers::answer::response, msg::core::InstantiateMsg as CoreInstantiateMsg, -}; use neutron_sdk::{ bindings::{msg::NeutronMsg, query::NeutronQuery}, NeutronResult, diff --git a/contracts/hook-tester/.cargo/config b/contracts/hook-tester/.cargo/config new file mode 100644 index 00000000..e98cb3dc --- /dev/null +++ b/contracts/hook-tester/.cargo/config @@ -0,0 +1,2 @@ +[alias] +schema = "run --bin lido-hook-tester-shema" diff --git a/contracts/hook-tester/Cargo.toml b/contracts/hook-tester/Cargo.toml new file mode 100644 index 00000000..40b6c78a --- /dev/null +++ b/contracts/hook-tester/Cargo.toml @@ -0,0 +1,49 @@ +[package] +authors = ["Sergey Ratiashvili "] +description = "Contract to test puppeteer and hooks" +edition = "2021" +name = "lido-hook-tester" +version = "1.0.0" + +exclude = [ + # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. + "contract.wasm", + "hash.txt", +] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[dependencies] +base64 = { workspace = true } +cosmos-sdk-proto = { workspace = true } +neutron-sdk = { workspace = true } +prost = { workspace = true } +prost-types = { workspace = true } +protobuf = { workspace = true } +tendermint-proto = { workspace = true } + +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } +cw2 = { workspace = true } +cw20 = { workspace = true } +schemars = { workspace = true } +serde = { workspace = true } +thiserror = { workspace = true } +serde-json-wasm = { workspace = true } +lido-staking-base = { workspace = true } +lido-helpers = { workspace = true } +lido-puppeteer-base = { workspace = true } + +[dev-dependencies] +cosmwasm-storage = { workspace = true } +cw-multi-test = { workspace = true } diff --git a/contracts/hook-tester/README.md b/contracts/hook-tester/README.md new file mode 100644 index 00000000..ddf07411 --- /dev/null +++ b/contracts/hook-tester/README.md @@ -0,0 +1 @@ +# LIDO Hook Tester \ No newline at end of file diff --git a/contracts/hook-tester/src/bin/lido-hook-tester-schema.rs b/contracts/hook-tester/src/bin/lido-hook-tester-schema.rs new file mode 100644 index 00000000..47184506 --- /dev/null +++ b/contracts/hook-tester/src/bin/lido-hook-tester-schema.rs @@ -0,0 +1,15 @@ +use cosmwasm_schema::write_api; + +use lido_hook_tester::{ + msg::{ExecuteMsg, InstantiateMsg, MigrateMsg}, + state::QueryMsg, +}; + +fn main() { + write_api! { + instantiate: InstantiateMsg, + query: QueryMsg, + execute: ExecuteMsg, + migrate: MigrateMsg + } +} diff --git a/contracts/hook-tester/src/contract.rs b/contracts/hook-tester/src/contract.rs new file mode 100644 index 00000000..838dd547 --- /dev/null +++ b/contracts/hook-tester/src/contract.rs @@ -0,0 +1,216 @@ +use cosmwasm_std::{ + attr, entry_point, to_json_binary, CosmosMsg, DepsMut, Env, MessageInfo, Response, Uint128, + WasmMsg, +}; +use lido_helpers::answer::response; +use lido_staking_base::{ + msg::hook_tester::{ExecuteMsg, InstantiateMsg}, + state::hook_tester::{Config, CONFIG}, +}; +use neutron_sdk::{ + bindings::{msg::NeutronMsg, query::NeutronQuery}, + NeutronResult, +}; + +use crate::error::ContractResult; + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + _env: Env, + _info: MessageInfo, + msg: InstantiateMsg, +) -> NeutronResult { + let attrs = vec![ + attr("action", "instantiate"), + attr("puppeteer_addr", &msg.puppeteer_addr), + ]; + CONFIG.save( + deps.storage, + &Config { + puppeteer_addr: msg.puppeteer_addr, + }, + )?; + Ok(response("instantiate", "hook-tester", attrs)) +} + +// #[cfg_attr(not(feature = "library"), entry_point)] +// pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult {} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + env: Env, + _info: MessageInfo, + msg: ExecuteMsg, +) -> ContractResult> { + match msg { + ExecuteMsg::Delegate { + validator, + amount, + timeout, + } => execute_delegate(deps, env, validator, amount, timeout), + ExecuteMsg::Undelegate { + validator, + amount, + timeout, + } => execute_undelegate(deps, env, validator, amount, timeout), + ExecuteMsg::Redelegate { + validator_from, + validator_to, + amount, + timeout, + } => execute_redelegate(deps, env, validator_from, validator_to, amount, timeout), + ExecuteMsg::TokenizeShare { + validator, + amount, + timeout, + } => execute_tokenize_share(deps, env, validator, amount, timeout), + ExecuteMsg::RedeemShare { + validator, + amount, + denom, + timeout, + } => execute_redeem_share(deps, env, validator, amount, denom, timeout), + } +} + +fn execute_delegate( + deps: DepsMut, + env: Env, + validator: String, + amount: Uint128, + timeout: Option, +) -> ContractResult> { + let config = CONFIG.load(deps.storage)?; + let attrs = vec![ + attr("action", "delegate"), + attr("validator", validator.clone()), + attr("amount", amount.to_string()), + ]; + let msg = CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: config.puppeteer_addr, + msg: to_json_binary(&lido_staking_base::msg::puppeteer::ExecuteMsg::Delegate { + validator, + amount, + timeout, + reply_to: env.contract.address.to_string(), + })?, + funds: vec![], + }); + Ok(response("execute-delegate", "hook-tester", attrs).add_message(msg)) +} + +fn execute_undelegate( + deps: DepsMut, + env: Env, + validator: String, + amount: Uint128, + timeout: Option, +) -> ContractResult> { + let config = CONFIG.load(deps.storage)?; + let attrs = vec![ + attr("action", "undelegate"), + attr("validator", validator.clone()), + attr("amount", amount.to_string()), + ]; + let msg = CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: config.puppeteer_addr, + msg: to_json_binary(&lido_staking_base::msg::puppeteer::ExecuteMsg::Undelegate { + validator, + amount, + timeout, + reply_to: env.contract.address.to_string(), + })?, + funds: vec![], + }); + Ok(response("execute-undelegate", "hook-tester", attrs).add_message(msg)) +} + +fn execute_redelegate( + deps: DepsMut, + env: Env, + validator_from: String, + validator_to: String, + amount: Uint128, + timeout: Option, +) -> ContractResult> { + let config = CONFIG.load(deps.storage)?; + let attrs = vec![ + attr("action", "redelegate"), + attr("validator_from", validator_from.clone()), + attr("validator_to", validator_to.clone()), + attr("amount", amount.to_string()), + ]; + let msg = CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: config.puppeteer_addr, + msg: to_json_binary(&lido_staking_base::msg::puppeteer::ExecuteMsg::Redelegate { + validator_from, + validator_to, + amount, + timeout, + reply_to: env.contract.address.to_string(), + })?, + funds: vec![], + }); + Ok(response("execute-redelegate", "hook-tester", attrs).add_message(msg)) +} + +fn execute_tokenize_share( + deps: DepsMut, + env: Env, + validator: String, + amount: Uint128, + timeout: Option, +) -> ContractResult> { + let config = CONFIG.load(deps.storage)?; + let attrs = vec![ + attr("action", "tokenize_share"), + attr("validator", validator.clone()), + attr("amount", amount.to_string()), + ]; + let msg = CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: config.puppeteer_addr, + msg: to_json_binary( + &lido_staking_base::msg::puppeteer::ExecuteMsg::TokenizeShare { + validator, + amount, + timeout, + reply_to: env.contract.address.to_string(), + }, + )?, + funds: vec![], + }); + Ok(response("execute-tokenize-share", "hook-tester", attrs).add_message(msg)) +} + +fn execute_redeem_share( + deps: DepsMut, + env: Env, + validator: String, + amount: Uint128, + denom: String, + timeout: Option, +) -> ContractResult> { + let config = CONFIG.load(deps.storage)?; + let attrs = vec![ + attr("action", "redeem_share"), + attr("validator", validator.clone()), + attr("amount", amount.to_string()), + attr("denom", denom.clone()), + ]; + let msg = CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: config.puppeteer_addr, + msg: to_json_binary( + &lido_staking_base::msg::puppeteer::ExecuteMsg::RedeemShare { + validator, + amount, + denom, + timeout, + reply_to: env.contract.address.to_string(), + }, + )?, + funds: vec![], + }); + Ok(response("execute-redeem-share", "hook-tester", attrs).add_message(msg)) +} diff --git a/contracts/hook-tester/src/error.rs b/contracts/hook-tester/src/error.rs new file mode 100644 index 00000000..8eff4bc1 --- /dev/null +++ b/contracts/hook-tester/src/error.rs @@ -0,0 +1,24 @@ +use cosmwasm_std::{OverflowError, StdError}; +use neutron_sdk::NeutronError; + +use thiserror::Error; + +#[derive(Error, Debug, PartialEq)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + #[error("{0}")] + NeutronError(#[from] NeutronError), + + #[error("Invalid Funds: {reason}")] + InvalidFunds { reason: String }, + + #[error("{0}")] + OverflowError(#[from] OverflowError), + + #[error("Unauthorized")] + Unauthorized {}, +} + +pub type ContractResult = Result; diff --git a/contracts/hook-tester/src/lib.rs b/contracts/hook-tester/src/lib.rs new file mode 100644 index 00000000..ed729875 --- /dev/null +++ b/contracts/hook-tester/src/lib.rs @@ -0,0 +1,2 @@ +pub mod contract; +pub mod error; diff --git a/contracts/puppeteer-authz/Cargo.toml b/contracts/puppeteer-authz/Cargo.toml index e3b67744..06c0511e 100644 --- a/contracts/puppeteer-authz/Cargo.toml +++ b/contracts/puppeteer-authz/Cargo.toml @@ -45,6 +45,7 @@ serde-json-wasm = { workspace = true } lido-puppeteer-base = { workspace = true } lido-staking-base = { workspace = true } +lido-helpers = { workspace = true } [dev-dependencies] cosmwasm-storage = { version = "1.0" } diff --git a/contracts/puppeteer-authz/src/contract.rs b/contracts/puppeteer-authz/src/contract.rs index 44bdd308..f85f0278 100644 --- a/contracts/puppeteer-authz/src/contract.rs +++ b/contracts/puppeteer-authz/src/contract.rs @@ -10,7 +10,7 @@ use cosmwasm_std::{ }; use cosmwasm_std::{Binary, DepsMut, Env, MessageInfo, Response, StdResult}; use cw2::set_contract_version; -use lido_staking_base::helpers::answer::response; +use lido_helpers::answer::response; use neutron_sdk::{ bindings::{ msg::{IbcFee, NeutronMsg}, diff --git a/contracts/puppeteer/Cargo.toml b/contracts/puppeteer/Cargo.toml index 96ef1b47..ce10277f 100644 --- a/contracts/puppeteer/Cargo.toml +++ b/contracts/puppeteer/Cargo.toml @@ -40,6 +40,7 @@ schemars = { workspace = true } serde = { workspace = true } serde-json-wasm = { workspace = true } lido-staking-base = { workspace = true } +lido-helpers = { workspace = true } lido-puppeteer-base = { workspace = true } [dev-dependencies] diff --git a/contracts/puppeteer/src/contract.rs b/contracts/puppeteer/src/contract.rs index a5ff8369..95861469 100644 --- a/contracts/puppeteer/src/contract.rs +++ b/contracts/puppeteer/src/contract.rs @@ -10,7 +10,11 @@ use cosmwasm_std::{ }; use cosmwasm_std::{Binary, DepsMut, Env, MessageInfo, Response, StdResult}; use cw2::set_contract_version; -use lido_staking_base::helpers::answer::response; +use lido_helpers::answer::response; +use lido_staking_base::{ + msg::puppeteer::{ExecuteMsg, InstantiateMsg, MigrateMsg}, + state::puppeteer::Config, +}; use neutron_sdk::{ bindings::{ msg::{IbcFee, NeutronMsg}, @@ -32,14 +36,12 @@ use lido_puppeteer_base::{ use prost::Message; use crate::{ - msg::{ExecuteMsg, InstantiateMsg, MigrateMsg}, proto::cosmos::base::v1beta1::Coin as ProtoCoin, proto::liquidstaking::staking::v1beta1::{ MsgBeginRedelegate, MsgBeginRedelegateResponse, MsgDelegateResponse, MsgRedeemTokensforShares, MsgRedeemTokensforSharesResponse, MsgTokenizeShares, MsgTokenizeSharesResponse, MsgUndelegateResponse, }, - state::Config, }; pub type Puppeteer<'a> = PuppeteerBase<'a, Config>; diff --git a/contracts/puppeteer/src/lib.rs b/contracts/puppeteer/src/lib.rs index 40655591..635a32ff 100644 --- a/contracts/puppeteer/src/lib.rs +++ b/contracts/puppeteer/src/lib.rs @@ -1,4 +1,2 @@ pub mod contract; -pub mod msg; pub mod proto; -pub mod state; diff --git a/contracts/token/Cargo.toml b/contracts/token/Cargo.toml index 27bb7857..7dbd9c85 100644 --- a/contracts/token/Cargo.toml +++ b/contracts/token/Cargo.toml @@ -15,6 +15,7 @@ library = [] [dependencies] cosmwasm-std = { workspace = true } lido-staking-base = { workspace = true } +lido-helpers = { workspace = true } cosmwasm-schema = { workspace = true } cw-storage-plus = { workspace = true } cw2 = { workspace = true } diff --git a/contracts/token/src/contract.rs b/contracts/token/src/contract.rs index 126bc685..8879c764 100644 --- a/contracts/token/src/contract.rs +++ b/contracts/token/src/contract.rs @@ -2,9 +2,8 @@ use cosmwasm_std::{ attr, ensure_eq, ensure_ne, entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, SubMsg, Uint128, }; - +use lido_helpers::answer::{attr_coin, response}; use lido_staking_base::{ - helpers::answer::{attr_coin, response}, msg::token::{ConfigResponse, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, state::token::{CORE_ADDRESS, DENOM}, }; diff --git a/contracts/validators-set/Cargo.toml b/contracts/validators-set/Cargo.toml index 28bdaea2..4cffaf1c 100644 --- a/contracts/validators-set/Cargo.toml +++ b/contracts/validators-set/Cargo.toml @@ -23,26 +23,27 @@ backtraces = ["cosmwasm-std/backtraces"] library = [] [dependencies] -cosmos-sdk-proto = { workspace = true } -prost = { workspace = true } -prost-types = { workspace = true } -protobuf = { workspace = true } -tendermint-proto = { workspace = true } -thiserror = { workspace = true } - -cosmwasm-schema = { workspace = true } -cosmwasm-std = { workspace = true } -cw-storage-plus = { workspace = true } -cw-ownable = { workspace = true } -cw2 = { workspace = true } -cw20 = { workspace = true } -schemars = { workspace = true } -serde = { workspace = true } -serde-json-wasm = { workspace = true } - -neutron-sdk = { workspace = true } +cosmos-sdk-proto = { workspace = true } +prost = { workspace = true } +prost-types = { workspace = true } +protobuf = { workspace = true } +tendermint-proto = { workspace = true } +thiserror = { workspace = true } + +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } +cw-ownable = { workspace = true } +cw2 = { workspace = true } +cw20 = { workspace = true } +schemars = { workspace = true } +serde = { workspace = true } +serde-json-wasm = { workspace = true } + +neutron-sdk = { workspace = true } lido-staking-base = { workspace = true } +lido-helpers = { workspace = true } [dev-dependencies] -cosmwasm-storage = { workspace = true } -cw-multi-test = { workspace = true } +cosmwasm-storage = { workspace = true } +cw-multi-test = { workspace = true } diff --git a/contracts/validators-set/src/contract.rs b/contracts/validators-set/src/contract.rs index 716f15c4..a2d2908d 100644 --- a/contracts/validators-set/src/contract.rs +++ b/contracts/validators-set/src/contract.rs @@ -1,7 +1,7 @@ use cosmwasm_std::{attr, ensure_eq, entry_point, to_json_binary, Addr, Deps, Order}; use cosmwasm_std::{Binary, DepsMut, Env, MessageInfo, Response, StdResult}; use cw2::set_contract_version; -use lido_staking_base::helpers::answer::response; +use lido_helpers::answer::response; use neutron_sdk::bindings::msg::NeutronMsg; use neutron_sdk::bindings::query::NeutronQuery; diff --git a/packages/base/Cargo.toml b/packages/base/Cargo.toml index 0d9efc55..166f572b 100644 --- a/packages/base/Cargo.toml +++ b/packages/base/Cargo.toml @@ -27,6 +27,7 @@ cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } neutron-sdk = { workspace = true } +lido-puppeteer-base = { workspace = true } [dev-dependencies] cosmwasm-storage = { workspace = true } diff --git a/packages/base/src/lib.rs b/packages/base/src/lib.rs index a801d48d..685329d1 100644 --- a/packages/base/src/lib.rs +++ b/packages/base/src/lib.rs @@ -1,3 +1,2 @@ -pub mod helpers; pub mod msg; pub mod state; diff --git a/packages/base/src/msg/hook_tester.rs b/packages/base/src/msg/hook_tester.rs new file mode 100644 index 00000000..717e21c3 --- /dev/null +++ b/packages/base/src/msg/hook_tester.rs @@ -0,0 +1,38 @@ +use cosmwasm_schema::cw_serde; +use cosmwasm_std::Uint128; + +#[cw_serde] +pub struct InstantiateMsg { + pub puppeteer_addr: String, +} + +#[cw_serde] +pub enum ExecuteMsg { + Delegate { + validator: String, + amount: Uint128, + timeout: Option, + }, + Undelegate { + validator: String, + amount: Uint128, + timeout: Option, + }, + Redelegate { + validator_from: String, + validator_to: String, + amount: Uint128, + timeout: Option, + }, + TokenizeShare { + validator: String, + amount: Uint128, + timeout: Option, + }, + RedeemShare { + validator: String, + amount: Uint128, + denom: String, + timeout: Option, + }, +} diff --git a/packages/base/src/msg/mod.rs b/packages/base/src/msg/mod.rs index fc69d71e..089c5360 100644 --- a/packages/base/src/msg/mod.rs +++ b/packages/base/src/msg/mod.rs @@ -1,2 +1,4 @@ pub mod core; +pub mod hook_tester; +pub mod puppeteer; pub mod token; diff --git a/contracts/puppeteer/src/msg.rs b/packages/base/src/msg/puppeteer.rs similarity index 80% rename from contracts/puppeteer/src/msg.rs rename to packages/base/src/msg/puppeteer.rs index d53c1c3f..c7f1e9fd 100644 --- a/contracts/puppeteer/src/msg.rs +++ b/packages/base/src/msg/puppeteer.rs @@ -1,7 +1,12 @@ -use cosmwasm_schema::cw_serde; +use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::Uint128; -use lido_puppeteer_base::msg::ExecuteMsg as BaseExecuteMsg; +use lido_puppeteer_base::{ + msg::{DelegationsResponse, ExecuteMsg as BaseExecuteMsg}, + state::{State, Transfer}, +}; + +use crate::state::puppeteer::Config; #[cw_serde] pub struct InstantiateMsg { @@ -83,3 +88,16 @@ impl ExecuteMsg { #[cw_serde] pub struct MigrateMsg {} + +#[cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + #[returns(Config)] + Config {}, + #[returns(State)] + State {}, + #[returns(Vec)] + InterchainTransactions {}, + #[returns(DelegationsResponse)] + Delegations {}, +} diff --git a/packages/base/src/state/hook_tester.rs b/packages/base/src/state/hook_tester.rs new file mode 100644 index 00000000..d6d0aaf6 --- /dev/null +++ b/packages/base/src/state/hook_tester.rs @@ -0,0 +1,9 @@ +use cosmwasm_schema::cw_serde; +use cw_storage_plus::Item; + +#[cw_serde] +pub struct Config { + pub puppeteer_addr: String, +} + +pub const CONFIG: Item = Item::new("config"); diff --git a/packages/base/src/state/mod.rs b/packages/base/src/state/mod.rs index fc69d71e..089c5360 100644 --- a/packages/base/src/state/mod.rs +++ b/packages/base/src/state/mod.rs @@ -1,2 +1,4 @@ pub mod core; +pub mod hook_tester; +pub mod puppeteer; pub mod token; diff --git a/contracts/puppeteer/src/state.rs b/packages/base/src/state/puppeteer.rs similarity index 54% rename from contracts/puppeteer/src/state.rs rename to packages/base/src/state/puppeteer.rs index f3bd8f1f..cabc9f95 100644 --- a/contracts/puppeteer/src/state.rs +++ b/packages/base/src/state/puppeteer.rs @@ -1,10 +1,7 @@ -use cosmwasm_schema::{cw_serde, QueryResponses}; +use cosmwasm_schema::cw_serde; use cosmwasm_std::Addr; -use lido_puppeteer_base::{ - msg::DelegationsResponse, - state::{BaseConfig, State, Transfer}, -}; +use lido_puppeteer_base::state::BaseConfig; #[cw_serde] pub struct Config { @@ -29,16 +26,3 @@ impl BaseConfig for Config { self.update_period } } - -#[cw_serde] -#[derive(QueryResponses)] -pub enum QueryMsg { - #[returns(Config)] - Config {}, - #[returns(State)] - State {}, - #[returns(Vec)] - InterchainTransactions {}, - #[returns(DelegationsResponse)] - Delegations {}, -} diff --git a/packages/helpers/Cargo.toml b/packages/helpers/Cargo.toml new file mode 100644 index 00000000..3c51995a --- /dev/null +++ b/packages/helpers/Cargo.toml @@ -0,0 +1,33 @@ +[package] +authors = ["Sergey Ratiashvili "] +description = "Package for Lido Puppeteer Base" +edition = "2021" +name = "lido-helpers" +version = "1.0.0" + +exclude = [ + # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. + "contract.wasm", + "hash.txt", +] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[dependencies] +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } +neutron-sdk = { workspace = true } + +[dev-dependencies] +cosmwasm-storage = { workspace = true } +cw-multi-test = { workspace = true } diff --git a/packages/base/src/helpers/answer.rs b/packages/helpers/src/answer.rs similarity index 100% rename from packages/base/src/helpers/answer.rs rename to packages/helpers/src/answer.rs diff --git a/packages/base/src/helpers/mod.rs b/packages/helpers/src/lib.rs similarity index 100% rename from packages/base/src/helpers/mod.rs rename to packages/helpers/src/lib.rs diff --git a/packages/puppeteer-base/Cargo.toml b/packages/puppeteer-base/Cargo.toml index 20b3d9c6..92bbac63 100644 --- a/packages/puppeteer-base/Cargo.toml +++ b/packages/puppeteer-base/Cargo.toml @@ -41,7 +41,7 @@ cw20 = { workspace = true } schemars = { workspace = true } serde = { workspace = true } serde-json-wasm = { workspace = true } -lido-staking-base = { workspace = true } +lido-helpers = { workspace = true } [dev-dependencies] diff --git a/packages/puppeteer-base/src/execute.rs b/packages/puppeteer-base/src/execute.rs index b943e789..d9762a9f 100644 --- a/packages/puppeteer-base/src/execute.rs +++ b/packages/puppeteer-base/src/execute.rs @@ -2,7 +2,7 @@ use cosmwasm_std::{ attr, ensure_eq, Coin as CosmosCoin, CosmosMsg, DepsMut, Env, MessageInfo, Response, StdError, StdResult, SubMsg, Uint128, }; -use lido_staking_base::helpers::answer::response; +use lido_helpers::answer::response; use neutron_sdk::{ bindings::{ msg::{IbcFee, NeutronMsg}, diff --git a/packages/puppeteer-base/src/reply.rs b/packages/puppeteer-base/src/reply.rs index 48991968..1d44d139 100644 --- a/packages/puppeteer-base/src/reply.rs +++ b/packages/puppeteer-base/src/reply.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{attr, DepsMut, Env, Reply, Response, StdError, StdResult}; -use lido_staking_base::helpers::answer::response; +use lido_helpers::answer::response; use neutron_sdk::bindings::msg::MsgSubmitTxResponse; use serde::{de::DeserializeOwned, Serialize};