Skip to content

Commit

Permalink
Update sylvia so all execute messages payable
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed May 30, 2024
1 parent 17c5701 commit 6dcb123
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mesh-virtual-staking = { path = "./contracts/consumer/virtual-staking" }

# sylvia = "0.10.1"
# from branch update/clean-add-cw-orch
sylvia = { git = "https://github.com/AbstractSDK/sylvia.git", rev = "a4168a242d444cc97d6a6363304d99d630dcbef3", features = ["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"
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
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
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;
54 changes: 54 additions & 0 deletions contracts/provider/vault/src/orch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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::{ContractExecMsg, ContractQueryMsg, ContractSudoMsg, InstantiateMsg};
use cw_orch::prelude::*;

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

#[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
fn wrapper() -> Box<dyn MockContract<Empty>> {
Box::new(ContractWrapper::new_with_empty(execute, instantiate, query))
}
}

// 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);
}

0 comments on commit 6dcb123

Please sign in to comment.