Skip to content

Commit

Permalink
Merge branch 'main' into update/separate-daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
Buckram123 committed Aug 17, 2023
2 parents a9528e8 + 9ad7d57 commit 43529ba
Show file tree
Hide file tree
Showing 33 changed files with 466 additions and 73 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ jobs:
uses: ATiltedTree/setup-rust@v1
with:
rust-version: stable
continue-on-error: true
- name: Delete rustup cache
run: rm -rf ~/.rustup
if: ${{ steps.rustup.outcome }} != "success"
- name: Setup Rust (again)
if: ${{ steps.rustup.outcome }} != "success"
uses: ATiltedTree/setup-rust@v1
with:
rust-version: stable

- name: Setup | Just
id: just
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["cw-orch", "cw-orch-daemon", "packages/*", "contracts/*"]
resolver = "2"

[workspace.package]
version = "0.13.3"
version = "0.13.3"
authors = ["CyberHoward <cyberhoward@protonmail.com>"]
edition = "2021"
license = "GPL-3.0-only"
Expand Down
3 changes: 3 additions & 0 deletions contracts/mock_contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ serde_json = "1.0.79"
thiserror = { version = "1.0.21" }
cosmwasm-schema = "1.2"
cw-orch = { path = "../../cw-orch", optional = true }

[dev-dependencies]
mock-contract = { path = ".", features = ["interface"] }
34 changes: 31 additions & 3 deletions contracts/mock_contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{
to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult,
};
use serde::Serialize;

#[cw_serde]
pub struct InstantiateMsg {}

#[cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::ExecuteFns))]
pub enum ExecuteMsg<T = String> {
pub enum ExecuteMsg<T = String>
where
T: Serialize,
{
FirstMessage {},
#[cfg_attr(feature = "interface", payable)]
SecondMessage {
Expand All @@ -27,14 +31,17 @@ pub enum ExecuteMsg<T = String> {
#[cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))]
#[derive(QueryResponses)]
pub enum QueryMsg {
pub enum QueryMsg<T = String>
where
T: Serialize,
{
#[returns(String)]
/// test-doc-comment
FirstQuery {},
#[returns(String)]
SecondQuery {
/// test doc-comment
t: String,
t: T,
},
}

Expand Down Expand Up @@ -93,3 +100,24 @@ pub fn migrate(_deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult<Response
))
}
}

#[cfg(test)]
mod test {
use super::MockContract as LocalMockContract;
use super::*;
use cw_orch::prelude::*;
#[test]
fn compiles() -> Result<(), CwOrchError> {
// We need to check we can still call the execute msgs conveniently
let sender = Addr::unchecked("sender");
let mock = Mock::new(&sender);
let contract = LocalMockContract::new("mock-contract", mock.clone());

contract.upload()?;
contract.instantiate(&InstantiateMsg {}, None, None)?;
contract.first_message()?;
contract.second_message("s".to_string(), &[]).unwrap_err();

Ok(())
}
}
10 changes: 8 additions & 2 deletions cw-orch-daemon/src/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use secp256k1::All;

use super::{sender::Sender, DaemonError};

const GAS_BUFFER: f64 = 1.2;
const GAS_BUFFER: f64 = 1.3;
const BUFFER_THRESHOLD: u64 = 200_000;
const SMALL_GAS_BUFFER: f64 = 1.4;

/// Struct used to build a raw transaction and broadcast it with a sender.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -98,7 +100,11 @@ impl TxBuilder {
.await?;
log::debug!("Simulated gas needed {:?}", sim_gas_used);

let gas_expected = sim_gas_used as f64 * GAS_BUFFER;
let gas_expected = if sim_gas_used < BUFFER_THRESHOLD {
sim_gas_used as f64 * SMALL_GAS_BUFFER
} else {
sim_gas_used as f64 * GAS_BUFFER
};
let fee_amount = gas_expected
* (wallet.daemon_state.chain_data.fees.fee_tokens[0].fixed_min_gas_price + 0.00001);

Expand Down
10 changes: 7 additions & 3 deletions cw-orch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ daemon = [
"dep:cw-orch-daemon",
]
eth = ["daemon", "cw-orch-core/eth", "cw-orch-daemon?/eth"]
osmosis-test-tube = ["dep:osmosis-test-tube", "cw-orch-core/osmosis-test-tube"]
osmosis-test-tube = [
"dep:osmosis-test-tube",
"dep:osmosis-std",
"cw-orch-core/osmosis-test-tube",
]

[dependencies]
# Default deps
Expand Down Expand Up @@ -77,8 +81,8 @@ cosmrs = { version = "0.14.0", features = [
tonic = { version = "0.9.2", optional = true, features = ["tls", "tls-roots"] }

# Test Tube env deps
osmosis-test-tube = { workspace = true, optional = true }

osmosis-test-tube = { version = "=17.0.0-rc0", optional = true }
osmosis-std = { version = "=0.17.0-rc0", optional = true }
# Env deps
cw-orch-core = { workspace = true }
cw-orch-mock = { workspace = true }
Expand Down
75 changes: 52 additions & 23 deletions cw-orch/src/osmosis_test_tube/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ use crate::contract::WasmPath;
use crate::prelude::Uploadable;
use cosmwasm_std::{Binary, BlockInfo, Coin, Timestamp, Uint128};
use cw_multi_test::AppResponse;
use osmosis_test_tube::osmosis_std::cosmwasm_to_proto_coins;
use osmosis_test_tube::Account;
use osmosis_test_tube::Bank;
use osmosis_test_tube::Gamm;
use osmosis_test_tube::Module;
use osmosis_test_tube::SigningAccount;
use osmosis_test_tube::Wasm;
use std::str::FromStr;

use osmosis_test_tube::osmosis_std::types::cosmos::bank::v1beta1::{
MsgSend, QueryAllBalancesRequest, QueryBalanceRequest,
// This should be the way to import stuff.
// But apparently osmosis-test-tube doesn't have the same dependencies as the test-tube package
// use osmosis_test_tube::osmosis_std::{
// types::cosmos::bank::v1beta1::{
// QueryAllBalancesRequest, QueryBalanceRequest, MsgSend
// },
// cosmwasm_to_proto_coins
// };

// So we need this fix (not ideal)
use osmosis_std::{
cosmwasm_to_proto_coins,
types::cosmos::bank::v1beta1::{MsgSend, QueryAllBalancesRequest, QueryBalanceRequest},
};
use osmosis_test_tube::{Account, Bank, Gamm, Module, SigningAccount, Wasm};
use std::str::FromStr;

use osmosis_test_tube::OsmosisTestApp;
use std::{cell::RefCell, fmt::Debug, rc::Rc};
Expand Down Expand Up @@ -45,13 +60,13 @@ pub use osmosis_test_tube;
/// let account = tube.init_account(coins(1_000_000_000, "uatom")).unwrap();
///
/// // query the balance
/// let balance: Uint128 = tube.query_balance(&account.borrow().address(), "uatom").unwrap();
/// let balance: Uint128 = tube.query_balance(&account.address(), "uatom").unwrap();
/// assert_eq!(balance.u128(), 1_000_000_000u128);
/// ```
#[derive(Clone)]
pub struct OsmosisTestTube<S: StateInterface = MockState> {
/// Address used for the operations.
pub sender: Rc<RefCell<SigningAccount>>,
pub sender: Rc<SigningAccount>,
/// Inner mutable state storage for contract addresses and code-ids
pub state: Rc<RefCell<S>>,
/// Inner mutable cw-multi-test app backend
Expand All @@ -63,24 +78,25 @@ impl<S: StateInterface> OsmosisTestTube<S> {
pub fn init_account(
&self,
amount: Vec<cosmwasm_std::Coin>,
) -> Result<Rc<RefCell<SigningAccount>>, CwOrchError> {
) -> Result<Rc<SigningAccount>, CwOrchError> {
self.app
.borrow()
.init_account(&amount)
.map_err(Into::into)
.map(|a| Rc::new(RefCell::new(a)))
.map(Rc::new)
}

/// Creates accounts and sets their balance
pub fn init_accounts(
&self,
amount: Vec<cosmwasm_std::Coin>,
account_n: u64,
) -> Result<Vec<SigningAccount>, CwOrchError> {
) -> Result<Vec<Rc<SigningAccount>>, CwOrchError> {
self.app
.borrow()
.init_accounts(&amount, account_n)
.map_err(Into::into)
.map(|s| s.into_iter().map(Rc::new).collect())
}

/// Creates accounts and sets their balance
Expand All @@ -91,11 +107,11 @@ impl<S: StateInterface> OsmosisTestTube<S> {
) -> Result<AppResponse, CwOrchError> {
let send_response = Bank::new(&*self.app.borrow()).send(
MsgSend {
from_address: self.sender.borrow().address(),
from_address: self.sender.address(),
to_address: to,
amount: cosmwasm_to_proto_coins(amount),
},
&self.sender.borrow(),
&self.sender,
)?;

Ok(AppResponse {
Expand All @@ -108,7 +124,7 @@ impl<S: StateInterface> OsmosisTestTube<S> {
pub fn create_pool(&self, liquidity: Vec<Coin>) -> Result<u64, CwOrchError> {
// create balancer pool with basic configuration
let pool_id = Gamm::new(&*self.app.borrow())
.create_basic_pool(&liquidity, &self.sender.borrow())
.create_basic_pool(&liquidity, &self.sender)
.unwrap()
.data
.pool_id;
Expand Down Expand Up @@ -171,7 +187,7 @@ impl<S: StateInterface> OsmosisTestTube<S> {
let sender = app.borrow().init_account(&init_coins).unwrap();

Self {
sender: Rc::new(RefCell::new(sender)),
sender: Rc::new(sender),
state,
app,
}
Expand All @@ -191,10 +207,10 @@ impl<S: StateInterface> TxHandler for OsmosisTestTube<S> {
type Error = CwOrchError;
type ContractSource = WasmPath;
type Response = AppResponse;
type Sender = Rc<RefCell<SigningAccount>>;
type Sender = Rc<SigningAccount>;

fn sender(&self) -> Addr {
Addr::unchecked(self.sender.borrow().address())
Addr::unchecked(self.sender.address())
}

fn set_sender(&mut self, sender: Self::Sender) {
Expand All @@ -203,11 +219,8 @@ impl<S: StateInterface> TxHandler for OsmosisTestTube<S> {

fn upload(&self, contract: &impl Uploadable) -> Result<Self::Response, CwOrchError> {
let wasm_contents = std::fs::read(contract.wasm().path())?;
let upload_response = Wasm::new(&*self.app.borrow()).store_code(
&wasm_contents,
None,
&self.sender.borrow(),
)?;
let upload_response =
Wasm::new(&*self.app.borrow()).store_code(&wasm_contents, None, &self.sender)?;

Ok(AppResponse {
data: Some(Binary(upload_response.raw_data)),
Expand All @@ -225,7 +238,7 @@ impl<S: StateInterface> TxHandler for OsmosisTestTube<S> {
contract_address.as_ref(),
exec_msg,
coins,
&self.sender.borrow(),
&self.sender,
)?;

Ok(AppResponse {
Expand All @@ -248,7 +261,7 @@ impl<S: StateInterface> TxHandler for OsmosisTestTube<S> {
admin.map(|a| a.to_string()).as_deref(),
label,
coins,
&self.sender.borrow(),
&self.sender,
)?;

Ok(AppResponse {
Expand Down Expand Up @@ -299,3 +312,19 @@ impl<S: StateInterface> TxHandler for OsmosisTestTube<S> {
})
}
}

// impl<T: CwOrchExecute<OsmosisTestTube> + ContractInstance<OsmosisTestTube> + Clone>
// CallAs<OsmosisTestTube> for T
// {
// type Sender = Rc<SigningAccount>;

// fn set_sender(&mut self, sender: &Self::Sender) {
// self.as_instance_mut().chain.sender = sender.clone();
// }

// fn call_as(&self, sender: &Self::Sender) -> Self {
// let mut contract = self.clone();
// contract.set_sender(sender);
// contract
// }
// }
18 changes: 18 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@
- [Project Wrapper]()
- [Colloboration]()

[//]: # (# Integrations)

[//]: # (- [cw-multi-test]&#40;&#41;)

[//]: # (- [test-tube]&#40;&#41;)

[//]: # (- [live-chains]&#40;&#41;)

- [Supported Chains](./chains/index.md)
- [Archway](./chains/archway.md)
- [Injective](./chains/injective.md)
- [Juno](./chains/juno.md)
- [Kujira](./chains/kujira.md)
- [Neutron](./chains/neutron.md)
- [Osmosis](./chains/osmosis.md)
- [Sei](./chains/sei.md)
- [Terra](./chains/terra.md)

# Extras

- [CI/CD](./ci-cd.md)
Expand Down
18 changes: 18 additions & 0 deletions docs/src/chains/archway.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Archway

Archway is a smart contract platform that directly rewards developers for their contributions. With built-in incentives, Archway equips developers with tools to craft and deploy scalable cross-chain dApps. As these dApps enhance the network's value, developers enjoy further rewards.

[Archway Website](https://archway.io/)

## Usage
See how to setup your main function in the [main function](../single_contract/scripting.md#main-function) section. Update the network passed into the `Daemon` builder to be `networks::ARCHWAY_1`.

```rust,ignore
{{#include ../../../cw-orch/src/daemon/networks/archway.rs:archway}}
```


## References

- [Archway Documentation](https://docs.archway.io/)
- [Archway Discord](https://discord.gg/archwayhq)
10 changes: 10 additions & 0 deletions docs/src/chains/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Supported Chains

Cw-Orchestrator currently has support for the chains in the following subsections.

## Support a new CosmWasm Chain
If you would like to add support for another chain, please feel free to [open a PR](https://github.com/AbstractSDK/cw-orchestrator/compare)!


## Issues
Each of the gRPC endpoints has been battle-tested for deployments. If you find any issues, please [open an issue](https://github.com/AbstractSDK/cw-orchestrator/issues/new)!
20 changes: 20 additions & 0 deletions docs/src/chains/injective.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Injective

Injective is a unique blockchain tailored for finance, offering out-of-the-box modules like a fully decentralized orderbook. As an open smart contracts platform, it hosts a suite of decentralized apps designed for optimal user experience. Dive into Injective and unlock efficient capital allocation in decentralized financial markets.

[Visit Injective's Website](https://injective.com/)

## Usage
To interact with contracts on Injective, first enable the `eth` feature for cw-orchestrator. Injective supports EVM-based addresses, and this will enable their use within cw-orchestrator.

See how to setup your main function in the [main function](../single_contract/scripting.md#main-function) section. Update the network passed into the `Daemon` builder to be `networks::INJECTIVE_1`.
```rust,ignore
{{#include ../../../cw-orch/src/daemon/networks/injective.rs:injective}}
```



## References

- [Injective Documentation](https://docs.injective.network/)
- [Injective Discord](https://discord.gg/injective)
Loading

0 comments on commit 43529ba

Please sign in to comment.