Skip to content

Commit

Permalink
Refactored env variable doc (#324)
Browse files Browse the repository at this point in the history
* Refactored env variable doc

* Changed logs_actication_message env name
  • Loading branch information
Kayanski authored Feb 14, 2024
1 parent 9ff0fd7 commit 3282160
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 44 deletions.
143 changes: 102 additions & 41 deletions docs/src/contracts/env-variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,108 @@ cw-orch leverages some environment variables to interact with contracts on actua

**IMPORTANT: Before proceeding, ensure that you add `.env` to your `.gitignore`. We are not responsible for any loss of funds due to leaked mnemonics.**

Here are the optional environment variables:

```bash
# .env

# info, debug, trace (if using env_logger for logging)
RUST_LOG=info

# Where the contract wasms are located (used by ArtifactsDir::env())
ARTIFACTS_DIR="../artifacts"

# Optional - Path.
# Sets the location of the state file for your deployments (default: ~./cw-orchestrator/state.json)
# `folder/file.json` will resolve to `~/.cw-orchestrator/folder/file.json`
# `./folder/file.json` will resolve `$pwd/folder/file.json`
# `../folder/file.json` will resolve `$pwd/../folder/file.json`
# `/usr/var/file.json` will resolve to `/usr/var/file.json`
STATE_FILE="./my_state.json"

# Mnemonics of the account that will be used to sign transactions
# Can optionally be set on DaemonBuilder as well.
MAIN_MNEMONIC="" # Necessary if interacting with a cw-orch-daemon on mainnet
TEST_MNEMONIC="" # Necessary if interacting with a cw-orch-daemon on testnet
LOCAL_MNEMONIC="" # Necessary if interacting with a cw-orch-daemon locally


## Additional configuration variables. These are optional. We show default values here:
# Optional - Float. This allows changing the gas buffer applied after tx simulation
CW_ORCH_GAS_BUFFER = 1.3
# Optional - Integer. This changes the number of tx queries before it fails if it doesn't find any result
CW_ORCH_MAX_TX_QUERY_RETRIES = 50
# Optional - Integer. Minimum block speed in seconds. Useful when the block speeds are varying a lot
CW_ORCH_MIN_BLOCK_SPEED = 1
# Optional - String. If equals to "true", will serialize the blockchain messages as json (for easy copying) instead of Rust Debug formatting
CW_ORCH_SERIALIZE_JSON = "false"
# Optional - Integer. This allows setting a minimum of gas used when broadcasting transactions
CW_ORCH_MIN_GAS = 100000
# Optional - boolean. Disable the "Enable Logs" message.
CW_ORCH_DISABLE_ENABLE_LOGS_MESSAGE = "false"
```

## Mnemonics

You can provide mnemonics directly to the `Daemon` using the following environment variables. Those variables will be used if the `mnemonic` setter is not used. See the [Daemon page](../integrations/daemon.md#configuration) for more detailed information on mnemonic usage.

- `MAIN_MNEMONIC` will be used when working with a Mainnet (`PHOENIX_1`, `OSMOSIS_1`...)
- `TEST_MNEMONIC` will be used when working with a Testnet (`PISCO_1`, `UNI_6`...)
- `LOCAL_MNEMONIC` will be used when working locally (`LOCAL_JUNO`...)

**Only 24-word mnemonics are supported at this time.** If you're experienced with keychain and private key management we'd really appreciate your help in adding support for other formats. Please reach out to us on <a href="https://discord.gg/uch3Tq3aym" target="_blank">Discord</a> if you're interested in helping out.

## Saving and Loading State

### STATE_FILE_ENV_NAME

Optional, accepted values: Path to a valid file
Default value: `~./cw-orchestrator/state.json`

This environment variable indicates the location of the state file that `cw-orch` will use to save on-chain state (addresses and code ids). Here is the behavior of this env variable :

- `folder/file.json` will resolve to `~/.cw-orchestrator/folder/file.json`
- `./folder/file.json` will resolve `$pwd/folder/file.json`
- `../folder/file.json` will resolve `$pwd/../folder/file.json`
- `/usr/var/file.json` will resolve to `/usr/var/file.json`

### ARTIFACTS_DIR

Optional, accepted values: Path to a valid directory

Path where the wasms will be fetched. This is used by `ArtifactsDir::env()` inside the code.
This is used in case you are using different tools than what is produced by <a href="https://github.com/CosmWasm/rust-optimizer" target="_blank">rust-optimizer</a>. Prefer using the following macro if you are using `wasm`s produced by `rust-optimizer` :

```rust,ignore
artifacts_dir_from_workspace!()
.find_wasm_path("contract_name")
.unwrap()
```

## Transaction options

### CW_ORCH_GAS_BUFFER

Optional, accepted values: float

This allows changing the gas buffer applied after tx simulation. Use this in case a transaction is blocked for insufficient gas reasons.

### CW_ORCH_MIN_GAS

Optional, accepted values: integer

Minimum gas amount for every transaction. Useful when transaction still won't pass even when setting a high gas_buffer or for mixed transaction scripts.

### CW_ORCH_MAX_TX_QUERY_RETRIES

Optional, accepted values: integer
Defaults to `50`.

Changes the number of tx queries (~1 query per block) before it fails if it doesn't find any result. Useful if the chain is slow or if the transaction has low gas price.

### CW_ORCH_MIN_BLOCK_SPEED

Optional, accepted value: integer in seconds
Defaults to `1`.

Minimum block speed in seconds. This is used internally by `cw-orch` when broadcasting transactions. Useful when the block speeds are varying a lot

### CW_ORCH_DISABLE_WALLET_BALANCE_ASSERTION

Optional, accepted values: `true`, `false`
Defaults to `false`

By default, `cw-orch` verifies that the account has sufficient balance to pay for gas fees. If it detects that the balance is too low, it propmts the user to fill up their wallet with gas tokens and allows for retrying at the press of a button.

If set to `true`, it won't check the user has enough balance before broadcasting transactions.

### CW_ORCH_DISABLE_MANUAL_INTERACTION

Optional, accepted values: `true`, `false`
Defaults to `false`

Some actions require user-intervention. If set to true, this disables those interventions. Useful when working in scripts that can't handle user-intervention.

Supported actions :

- Balance checks. When set to `true`, if the gas token balance is too low to submit a transaction, it will error. See [Disable balance assertion](#cw_orch_disable_wallet_balance_assertion).
- Deployment checks. When set to `true`, if no deployment file is detected when deploying a structure using the `Deploy::multi_deploy` function, it will deploy to all provided chains without asking for approval.

## Logging

### RUST_LOG

Optional, accepted values : `debug`, `error`, `info`, `warn`, `trace`

`RUST_LOG` defines the Log level for the application. This is actually a `Rust` flag that we use inside `cw-orch`. If working with this environment variable, don't forget to also initialize a logger at the beginning of you application to be able to see the output. You can work with <a href="https://crates.io/crates/pretty_env_logger/" target="_blank">pretty_env_logger</a> for instance.

### CW_ORCH_SERIALIZE_JSON

Optional, accepted values : `false`, `true`

If equals to `true`, in the output logs, cw-orch will serialize the contract messages (instantiate, execute, query,... ) as JSON. This replaces the standard Rust Debug formatting and allows for easy copying and sharing of the executed messages.

### CW_ORCH_DISABLE_LOGS_ACTIVATION_MESSAGE

Optional, accepted values : `false`, `true`

By default if the logs are not enabled, `cw-orch` wil print a warning message to invite users to activate the logging capabilities of cw-orch. if equals to `true`, this env variable disables the warning message.
2 changes: 1 addition & 1 deletion docs/src/integrations/daemon.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Here are the available options and fields you can use in the builder object:
- `deployment_id` (*optional*) is used when loading and saving blockchain state (addresses and code-ids). It is useful when you have multiple instances of the same contract on a single chain. It will allow you to keep those multiple instances in the same state file without overriding state.<a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.deployment_id" target="_blank">Documentation Link</a>
- `handle` (*required*) is the `tokio` runtime handled used to await async functions. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.handle" target="_blank">Documentation Link</a>
- `mnemonic` (*optional*) is the mnemonic that will be used to create the sender associated with the resulting `Daemon` Object. It is not compatible with the `sender` method. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.mnemonic" target="_blank">Documentation Link</a>
- `sender` (*optional*) is the sender that will be uses with the `resulting` Daemon Object. It is not compatible with the `mnemonic` method. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.mnemonic" target="_blank">Documentation Link</a>()
- `sender` (*optional*) is the sender that will be uses with the `resulting` Daemon Object. It is not compatible with the `mnemonic` method. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.mnemonic" target="_blank">Documentation Link</a>
- `authz_granter` (*optional*) allows you to use the authz module. If this field is specified, the sender will send transactions wrapped inside an authz message sent by the specified `granter`. <a href="https://docs.cosmos.network/v0.46/modules/authz/" target="_blank">More info on the authz module</a>. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.authz_granter" target="_blank">Documentation Link</a>
- `fee_granter` (*optional*) allows you to use the fee-grant module. If this field is specified, the sender will try to pay for transactions using the specified `granter`. <a href="https://docs.cosmos.network/v0.46/modules/feegrant/" target="_blank">More info on the fee grant module</a>. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.fee_granter" target="_blank">Documentation Link</a>
- `hd_index` (*optional*) allows to set the index of the HD path for the account associated with the `Daemon` object. <a href="https://hub.cosmos.network/main/resources/hd-wallets.html" target="_blank">More info on the derivation path and index</a>. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.hd_index" target="_blank">Documentation Link</a>
Expand Down
5 changes: 3 additions & 2 deletions packages/cw-orch-core/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ pub const SERIALIZE_ENV_NAME: &str = "CW_ORCH_SERIALIZE_JSON";
pub const DISABLE_WALLET_BALANCE_ASSERTION_ENV_NAME: &str =
"CW_ORCH_DISABLE_WALLET_BALANCE_ASSERTION";
pub const DISABLE_MANUAL_INTERACTION_ENV_NAME: &str = "CW_ORCH_DISABLE_MANUAL_INTERACTION";
pub const DISABLE_ENABLE_LOGS_MESSAGE_ENV_NAME: &str = "CW_ORCH_DISABLE_ENABLE_LOGS_MESSAGE";
pub const DISABLE_LOGS_ACTIVATION_MESSAGE_ENV_NAME: &str =
"CW_ORCH_DISABLE_LOGS_ACTIVATION_MESSAGE";
pub const MAIN_MNEMONIC_ENV_NAME: &str = "MAIN_MNEMONIC";
pub const TEST_MNEMONIC_ENV_NAME: &str = "TEST_MNEMONIC";
pub const LOCAL_MNEMONIC_ENV_NAME: &str = "LOCAL_MNEMONIC";
Expand Down Expand Up @@ -167,7 +168,7 @@ impl CwOrchEnvVars {
if let Ok(str_value) = env::var(DISABLE_MANUAL_INTERACTION_ENV_NAME) {
env_values.disable_manual_interaction = str_value.parse()?;
}
if let Ok(str_value) = env::var(DISABLE_ENABLE_LOGS_MESSAGE_ENV_NAME) {
if let Ok(str_value) = env::var(DISABLE_LOGS_ACTIVATION_MESSAGE_ENV_NAME) {
env_values.disable_logs_message = str_value.parse()?;
}
if let Ok(str_value) = env::var(MAIN_MNEMONIC_ENV_NAME) {
Expand Down

0 comments on commit 3282160

Please sign in to comment.