Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: Cw orch "support" #191

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
447 changes: 439 additions & 8 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ mesh-converter = { path = "./contracts/consumer/converter" }
mesh-simple-price-feed = { path = "./contracts/consumer/simple-price-feed" }
mesh-virtual-staking = { path = "./contracts/consumer/virtual-staking" }

sylvia = "0.10.1"
# sylvia = "0.10.1"
# from branch update/clean-add-cw-orch
sylvia = { git = "https://github.com/AbstractSDK/sylvia.git", rev = "76ed9ace11ce79f541d94e5d03eb9d0b9deed509", features = ["orch"] }
# need this fork of cw-orch as well...
cw-orch = { git = "https://github.com/abstractsdk/cw-orchestrator", branch = "update/relax-bound-on-derive" }
# cw-orch = "0.22.1"

cosmwasm-schema = "1.5.4"
cosmwasm-std = { version = "1.5.4", features = ["ibc3", "cosmwasm_1_3"] }
Expand All @@ -43,6 +48,7 @@ thiserror = "1.0.59"
semver = "1.0.22"
itertools = "0.12.1"


# dev deps
anyhow = "1"
cw-multi-test = "0.20"
Expand Down
2 changes: 2 additions & 0 deletions contracts/consumer/converter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

cw-orch = { workspace = true}

[dev-dependencies]
mesh-burn = { workspace = true }
mesh-simple-price-feed = { workspace = true, features = ["mt"] }
Expand Down
2 changes: 2 additions & 0 deletions contracts/consumer/remote-price-feed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

cw-orch = { workspace = true}

[dev-dependencies]
cw-multi-test = { workspace = true }
test-case = { workspace = true }
Expand Down
6 changes: 6 additions & 0 deletions contracts/consumer/remote-price-feed/src/price_keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pub struct PriceKeeper {
pub price_info_ttl_in_secs: Item<'static, u64>,
}

impl Default for PriceKeeper {
fn default() -> Self {
Self::new()
}
}

impl PriceKeeper {
pub const fn new() -> Self {
Self {
Expand Down
2 changes: 2 additions & 0 deletions contracts/consumer/simple-price-feed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

cw-orch = { workspace = true}

[dev-dependencies]
cw-multi-test = { workspace = true }
test-case = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions contracts/consumer/virtual-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cw-utils = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
cw-orch = { workspace = true}

[dev-dependencies]
mesh-simple-price-feed = { workspace = true, features = ["mt", "fake-custom"] }
Expand Down
2 changes: 2 additions & 0 deletions contracts/osmosis-price-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ serde = { workspace = true }
sylvia = { workspace = true }
thiserror = { workspace = true }
osmosis-std = { workspace = true }

cw-orch = { workspace = true}
2 changes: 2 additions & 0 deletions contracts/provider/external-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

cw-orch = { workspace = true}

[dev-dependencies]
sylvia = { workspace = true, features = ["mt"] }
cw-multi-test = { workspace = true }
Expand Down
6 changes: 6 additions & 0 deletions contracts/provider/external-staking/src/crdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ pub struct CrdtState<'a> {
validators: Map<'a, &'a str, ValidatorState>,
}

impl<'a> Default for CrdtState<'a> {
fn default() -> Self {
Self::new()
}
}

impl<'a> CrdtState<'a> {
pub const fn new() -> Self {
CrdtState {
Expand Down
2 changes: 2 additions & 0 deletions contracts/provider/native-staking-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

cw-orch = { workspace = true}

[dev-dependencies]
sylvia = { workspace = true, features = ["mt"] }
cw-multi-test = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions contracts/provider/native-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

cw-orch = { workspace = true}

[dev-dependencies]
sylvia = { workspace = true, features = ["mt"] }
cw-multi-test = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions contracts/provider/vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

cw-orch = { workspace = true}
anyhow = { workspace = true }

[dev-dependencies]
sylvia = { workspace = true, features = ["mt"] }
cw-multi-test = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions contracts/provider/vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct VaultContract<'a> {
}

#[cfg_attr(not(feature = "library"), sylvia::entry_points)]
// #[sylvia::entry_points]
#[contract]
#[sv::error(ContractError)]
#[sv::messages(vault_api as VaultApi)]
Expand Down
3 changes: 3 additions & 0 deletions contracts/provider/vault/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ pub mod error;
pub mod msg;
#[cfg(test)]
mod multitest;
pub mod orch;
mod state;
#[cfg(test)]
mod test;
pub mod txs;
124 changes: 124 additions & 0 deletions contracts/provider/vault/src/orch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// This contains all code we needed to manually add to make it work well with cw-orch
// In the future, hopefully some of this can me auto-generated. But let's get it to work now.

// use crate::contract::entry_points::{execute, instantiate, query};
// use crate::contract::sv::mt;

use crate::contract::sv::{ContractExecMsg, ContractQueryMsg, ContractSudoMsg, InstantiateMsg};
use cw_orch::prelude::*;

// Maybe uploadable can be autogenerated?
// But this is fine to include in the client code

#[cfg(any(feature = "mt", test))]
impl<'a> MockContract<Empty> for crate::contract::VaultContract<'a> {
fn execute(
&self,
deps: cosmwasm_std::DepsMut<Empty>,
env: cosmwasm_std::Env,
info: cosmwasm_std::MessageInfo,
msg: Vec<u8>,
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
sylvia::cw_multi_test::Contract::execute(self, deps, env, info, msg)
}

fn instantiate(
&self,
deps: cosmwasm_std::DepsMut<Empty>,
env: cosmwasm_std::Env,
info: cosmwasm_std::MessageInfo,
msg: Vec<u8>,
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
sylvia::cw_multi_test::Contract::instantiate(self, deps, env, info, msg)
}

fn query(
&self,
deps: cosmwasm_std::Deps<Empty>,
env: cosmwasm_std::Env,
msg: Vec<u8>,
) -> anyhow::Result<cosmwasm_std::Binary> {
sylvia::cw_multi_test::Contract::query(self, deps, env, msg)
}

fn sudo(
&self,
deps: cosmwasm_std::DepsMut<Empty>,
env: cosmwasm_std::Env,
msg: Vec<u8>,
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
sylvia::cw_multi_test::Contract::sudo(self, deps, env, msg)
}

fn reply(
&self,
deps: cosmwasm_std::DepsMut<Empty>,
env: cosmwasm_std::Env,
msg: cosmwasm_std::Reply,
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
sylvia::cw_multi_test::Contract::reply(self, deps, env, msg)
}

fn migrate(
&self,
deps: cosmwasm_std::DepsMut<Empty>,
env: cosmwasm_std::Env,
msg: Vec<u8>,
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
sylvia::cw_multi_test::Contract::migrate(self, deps, env, msg)
}
}

#[cw_orch::interface(InstantiateMsg, ContractExecMsg, ContractQueryMsg, Empty)]
pub struct MeshVault;

impl<Chain> Uploadable for MeshVault<Chain> {
/// Return the path to the wasm file corresponding to the contract
fn wasm(_chain: &ChainInfoOwned) -> WasmPath {
artifacts_dir_from_workspace!()
.find_wasm_path("mesh_vault")
.unwrap()
}

/// Returns a CosmWasm contract wrapper
#[cfg(any(feature = "mt", test))]
fn wrapper() -> Box<dyn MockContract<Empty>> {
let c = crate::contract::VaultContract::new();
Box::new(c)
}

#[cfg(not(any(feature = "mt", test)))]
fn wrapper() -> Box<dyn MockContract<Empty>> {
panic!("Multitest only implemented in tests or with 'mt' feature");
}
}

// Autogenerating these Froms caused all kinds of rust compiler issues.
// For now, I will just manually implement them to show what could work.
// The following is done in Sylvia, ideally the other (interface) variants could be added there too:
// impl From<ExecMsg> for ContractExecMsg

// Since we know the regular structure here, this may be easy enough to
// generate inside the `sv::messages` macro rather than the `contract` macro, eg.
// #[sv::messages(cw20_marketing as Marketing)]
// #[sv::messages(cw20_minting as Minting)]

use mesh_apis::vault_api::sv::{VaultApiExecMsg, VaultApiQueryMsg, VaultApiSudoMsg};

impl From<VaultApiExecMsg> for ContractExecMsg {
fn from(msg: VaultApiExecMsg) -> Self {
ContractExecMsg::VaultApi(msg)
}
}

impl From<VaultApiQueryMsg> for ContractQueryMsg {
fn from(msg: VaultApiQueryMsg) -> Self {
ContractQueryMsg::VaultApi(msg)
}
}

impl From<VaultApiSudoMsg> for ContractSudoMsg {
fn from(msg: VaultApiSudoMsg) -> Self {
ContractSudoMsg::VaultApi(msg)
}
}
38 changes: 38 additions & 0 deletions contracts/provider/vault/src/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use cosmwasm_std::coin;
// use cw_orch::environment::IndexResponse;
use cw_orch::prelude::*;

use crate::orch::MeshVault;

use crate::contract::sv::{ExecMsgFns, InstantiateMsg, QueryMsgFns};

// TODO: shared variable
const BECH_PREFIX: &str = "osmo";

#[test]
fn happy_path_works() {
let denom = "uosmo";
let chain = MockBech32::new(BECH_PREFIX);
chain
.add_balance(&chain.sender(), vec![coin(1_000_000, denom)])
.unwrap();

let contract = MeshVault::new("vault", chain.clone());
contract.upload().unwrap();
let msg = InstantiateMsg {
denom: denom.to_string(),
local_staking: None,
};
contract.instantiate(&msg, None, None).unwrap();

let cfg = contract.config().unwrap();
println!("{:?}", cfg);

let account = contract.account(chain.sender().into()).unwrap();
assert_eq!(account.bonded.u128(), 0u128);

contract.bond(&[coin(400_000, denom)]).unwrap();

let account = contract.account(chain.sender().into()).unwrap();
assert_eq!(account.bonded.u128(), 400_000u128);
}
2 changes: 2 additions & 0 deletions packages/apis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ semver = { workspace = true }
serde = { workspace = true }
sylvia = { workspace = true }
thiserror = { workspace = true }

cw-orch = { workspace = true }
Loading