Skip to content

Commit

Permalink
Workflow fixes (#52)
Browse files Browse the repository at this point in the history
* wip

* finish verify workflow

* finish todos and save workflow config to registry

* remove some todos

* add sleep after each msg to chain on cosmos cosmwasm

* fix workflow to work

* address keyne comments

* fix

* fix domain parsing

* indent

---------

Co-authored-by: Steve Degosserie <[email protected]>
  • Loading branch information
Art3miX and stiiifff authored Oct 8, 2024
1 parent 7bd7c76 commit 72e45b8
Show file tree
Hide file tree
Showing 15 changed files with 320 additions and 237 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ sha2 = "0.10.8"
thiserror = "1.0.63"

# our contracts
valence-authorization = { path = "contracts/authorization", features = ["library"] }
valence-base-account = { path = "contracts/accounts/base_account", features = ["library"] }
valence-processor = { path = "contracts/processor", features = ["library"] }
valence-workflow-registry = { path = "contracts/workflow-registry", features = ["library"] }
valence-astroport-lper = { path = "contracts/services/astroport-lper", features = ["library"] }
valence-authorization = { path = "contracts/authorization", features = ["library"] }
valence-base-account = { path = "contracts/accounts/base_account", features = ["library"] }
valence-processor = { path = "contracts/processor", features = ["library"] }
valence-splitter-service = { path = "contracts/services/splitter", features = ["library"] }
valence-test-dynamic-ratio = { path = "contracts/testing/test-dynamic-ratio", features = ["library"] }
valence-test-service = { path = "contracts/testing/test-service", features = ["library"] }
valence-workflow-registry = { path = "contracts/workflow-registry", features = ["library"] }
valence-astroport-lper = { path = "contracts/services/astroport-lper", features = ["library"] }
valence-forwarder-service = { path = "contracts/services/forwarder", features = ["library"] }
valence-astroport-withdrawer = { path = "contracts/services/astroport-withdrawer", features = ["library"] }
valence-reverse-splitter-service = { path = "contracts/services/reverse-splitter", features = ["library"] }
valence-splitter-service = { path = "contracts/services/splitter", features = ["library"] }
valence-test-dynamic-ratio = { path = "contracts/testing/test-dynamic-ratio", features = ["library"] }
valence-test-service = { path = "contracts/testing/test-service", features = ["library"] }

# our packages
valence-account-utils = { path = "packages/account-utils" }
Expand Down
1 change: 1 addition & 0 deletions packages/service-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_json_binary, Addr, CosmosMsg, StdError, StdResult, WasmMsg};

pub mod denoms {
pub use cw_denom::{CheckedDenom, DenomError, UncheckedDenom};
}
Expand Down
11 changes: 6 additions & 5 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ shift

if [[ "$CHAIN" == 'neutron' || "$CHAIN" == 'ntrn' ]]; then
BINARY="neutrond"
GAS_PRICES="0.055untrn"
GAS_PRICES="0.1untrn"
OWNER_ADDR="neutron1tl0w0djc5y53aqfr60a794f02drwktpujm5xxe"
ADMIN_ADDR="neutron1tl0w0djc5y53aqfr60a794f02drwktpujm5xxe"

Expand All @@ -17,10 +17,11 @@ else
echo "Unknown chain"
fi

TESTNET_NODE="https://neutron-testnet-rpc.polkachu.com:443"
TESTNET_CHAIN_ID="pion-1"
TESTNET_INFO="--node https://neutron-testnet-rpc.polkachu.com:443 --chain-id pion-1"
LOCAL_IC_INFO="--node http://0.0.0.0:45791 --chain-id localneutron-1"

EXECUTE_FLAGS="--gas-prices $GAS_PRICES --gas auto --gas-adjustment 1.5 --output json --node $TESTNET_NODE --chain-id $TESTNET_CHAIN_ID -y"
TESTNET_EXECUTE_FLAGS="--gas-prices $GAS_PRICES --gas auto --gas-adjustment 1.5 --output json $TESTNET_INFO -y"
LOCAL_IC_EXECUTE_FLAGS="--gas-prices $GAS_PRICES --gas auto --gas-adjustment 1.5 --output json $LOCAL_IC_INFO -y"

################################################
################### Registry ###################
Expand All @@ -33,7 +34,7 @@ if [[ "$COMMAND" == 'registry' ]]; then
}')

$BINARY tx wasm init $CODE_ID_REGISTRY "$init_msg" --label "Valence workflow registry" \
--admin $OWNER_ADDR --from $OWNER_ADDR $EXECUTE_FLAGS
--admin $OWNER_ADDR --from $OWNER_ADDR $TESTNET_EXECUTE_FLAGS

else
echo "Unknown command"
Expand Down
23 changes: 18 additions & 5 deletions scripts/upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,31 @@ else
ADDRESSES="$OWNER_ADDR,$AUCTIONS_MANAGER_ADDR,$INIT_BY"
fi

TESTNET_NODE="https://neutron-testnet-rpc.polkachu.com:443"
TESTNET_CHAIN_ID="pion-1"
TESTNET_INFO="--node https://neutron-testnet-rpc.polkachu.com:443 --chain-id pion-1"
LOCAL_IC_INFO="--node http://0.0.0.0:45791 --chain-id localneutron-1"

TESTNET_EXECUTE_FLAGS="--gas-prices $GAS_PRICES --gas auto --gas-adjustment 1.5 --output json $TESTNET_INFO -y"
LOCAL_IC_EXECUTE_FLAGS="--gas-prices $GAS_PRICES --gas auto --gas-adjustment 1.5 --output json $LOCAL_IC_INFO -y"

EXECUTE_FLAGS="--gas-prices $GAS_PRICES --gas auto --gas-adjustment 1.5 --output json --instantiate-anyof-addresses $ADDRESSES --node $TESTNET_NODE --chain-id $TESTNET_CHAIN_ID -y"
ACCOUNT_EXECUTE_FLAGS="--gas-prices $GAS_PRICES --gas auto --gas-adjustment 1.5 --output json -y"
ARTIFACTS_PATH="../artifacts"

# File names
REGISTRY_FILE_NAME="$ARTIFACTS_PATH/valence_workflow_registry.wasm"
AUTH_FILE_NAME="$ARTIFACTS_PATH/valence_authorization.wasm"
PROCESSOR_FILE_NAME="$ARTIFACTS_PATH/valence_processor.wasm"
BASE_ACCOUNT_FILE_NAME="$ARTIFACTS_PATH/valence_base_account.wasm"
FORWARDER_FILE_NAME="$ARTIFACTS_PATH/valence_forwarder_service.wasm"

if [[ "$COMMAND" == 'registry' ]]; then
$BINARY tx wasm s $REGISTRY_FILE_NAME --from $OWNER_ADDR $EXECUTE_FLAGS
$BINARY tx wasm s $REGISTRY_FILE_NAME --from $OWNER_ADDR $TESTNET_EXECUTE_FLAGS
elif [[ "$COMMAND" == 'auth' ]]; then
$BINARY tx wasm s $AUTH_FILE_NAME --from $OWNER_ADDR $TESTNET_EXECUTE_FLAGS
elif [[ "$COMMAND" == 'processor' ]]; then
$BINARY tx wasm s $PROCESSOR_FILE_NAME --from $OWNER_ADDR $TESTNET_EXECUTE_FLAGS
elif [[ "$COMMAND" == 'base_account' ]]; then
$BINARY tx wasm s $BASE_ACCOUNT_FILE_NAME --from $OWNER_ADDR $TESTNET_EXECUTE_FLAGS
elif [[ "$COMMAND" == 'forwarder' ]]; then
$BINARY tx wasm s $FORWARDER_FILE_NAME --from $OWNER_ADDR $TESTNET_EXECUTE_FLAGS
else
echo "Unknown command"
fi
1 change: 1 addition & 0 deletions workflow-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ valence-account-utils = { workspace = true }
valence-authorization = { workspace = true }
valence-processor = { workspace = true }
valence-workflow-registry = { workspace = true }
valence-forwarder-service = { workspace = true }

aho-corasick = "1.1"
serde_json_any_key = "2"
Expand Down
24 changes: 17 additions & 7 deletions workflow-manager/conf/chains.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
[chains]

[chains.cosmos-hub]
name = "cosmos-hub"
rpc = "https://rpc.cosmos.network:443"
grpc = "https://cosmos-testnet-grpc.polkachu.com:14990"
prefix = "cosmos"
gas_price = "0.025"
gas_denom = "uatom"
# [chains.cosmos-hub]
# name = "cosmos-hub"
# rpc = "https://rpc.cosmos.network:443"
# grpc = "https://cosmos-testnet-grpc.polkachu.com:14990"
# prefix = "cosmos"
# gas_price = "0.025"
# gas_denom = "uatom"
# coin_type = "118"

[chains.juno]
name = "juno"
rpc = "http://0.0.0.0:34125"
grpc = "http://0.0.0.0:46547"
prefix = "juno"
gas_price = "0.1"
gas_denom = "ujuno"
coin_type = "118"

[chains.neutron]
Expand All @@ -18,3 +27,4 @@ prefix = "neutron"
gas_price = "0.055"
gas_denom = "untrn"
coin_type = "118"

8 changes: 5 additions & 3 deletions workflow-manager/conf/contracts.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[contracts]

[contracts.code_ids.neutron]
authorization = 7217
processor = 7218
base_account = 7219
forwarder = 7222

polytone_proxy = 1
base_account = 5987
processor = 4
authorization = 5
splitter = 6049
reverse_splitter = 3

Expand Down
31 changes: 16 additions & 15 deletions workflow-manager/src/domain/cosmos_cw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
helpers::{addr_canonicalize, addr_humanize},
service::{ServiceConfig, ServiceError},
workflow_config::WorkflowConfig,
MAIN_CHAIN, NEUTRON_DOMAIN,
NEUTRON_CHAIN,
};
use anyhow::{anyhow, Context};
use async_trait::async_trait;
Expand All @@ -35,6 +35,7 @@ use tokio::time::sleep;
use super::{Connector, ConnectorResult, POLYTONE_TIMEOUT};

const MNEMONIC: &str = "margin moon alcohol assume tube bullet long cook edit delay boat camp stone coyote gather design aisle comfort width sound innocent long dumb jungle";
// const MNEMONIC: &str = "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry";

#[derive(Clone, PartialEq, ::prost::Message)]
pub struct QueryBuildAddressRequest {
Expand Down Expand Up @@ -121,7 +122,7 @@ impl CosmosCosmwasmConnector {
))?;

Ok(CosmosCosmwasmConnector {
is_main_chain: chain_info.name == MAIN_CHAIN,
is_main_chain: chain_info.name == *NEUTRON_CHAIN,
wallet,
code_ids: code_ids.clone(),
chain_name: chain_info.name.clone(),
Expand All @@ -133,7 +134,7 @@ impl CosmosCosmwasmConnector {
#[async_trait]
impl Connector for CosmosCosmwasmConnector {
async fn reserve_workflow_id(&mut self) -> ConnectorResult<u64> {
if self.chain_name != NEUTRON_DOMAIN.get_chain_name() {
if self.chain_name != *NEUTRON_CHAIN {
return Err(CosmosCosmwasmError::Error(anyhow::anyhow!(
"Should only be implemented on neutron connector"
))
Expand Down Expand Up @@ -313,7 +314,7 @@ impl Connector for CosmosCosmwasmConnector {
async fn instantiate_account(
&mut self,
workflow_id: u64,
auth_addr: String,
processor_addr: String,
data: &InstantiateAccountData,
) -> ConnectorResult<()> {
let code_id = *self
Expand All @@ -324,7 +325,7 @@ impl Connector for CosmosCosmwasmConnector {

let msg: Vec<u8> = match &data.info.ty {
AccountType::Base { admin } => to_vec(&valence_account_utils::msg::InstantiateMsg {
admin: admin.clone().unwrap_or_else(|| auth_addr.clone()),
admin: admin.clone().unwrap_or_else(|| processor_addr.clone()),
approved_services: data.approved_services.clone(),
})
.map_err(CosmosCosmwasmError::SerdeJsonError)?,
Expand All @@ -333,7 +334,7 @@ impl Connector for CosmosCosmwasmConnector {

let m = MsgInstantiateContract2 {
sender: self.wallet.account_address.clone(),
admin: auth_addr,
admin: processor_addr,
code_id,
label: format!("workflow-{}|account-{}", workflow_id, data.id),
msg,
Expand Down Expand Up @@ -694,12 +695,11 @@ impl Connector for CosmosCosmwasmConnector {

async fn query_workflow_registry(
&mut self,
main_domain: &str,
id: u64,
) -> ConnectorResult<valence_workflow_registry_utils::WorkflowResponse> {
if self.chain_name != main_domain {
if self.chain_name != NEUTRON_CHAIN {
return Err(CosmosCosmwasmError::Error(anyhow::anyhow!(
"Adding external domain is only possible on main domain in authorization contract"
"workflow registry only exists on neutron chain"
))
.into());
}
Expand Down Expand Up @@ -730,7 +730,7 @@ impl Connector for CosmosCosmwasmConnector {
}

async fn verify_account(&mut self, account_addr: String) -> ConnectorResult<()> {
let contract_name = self.get_contract_name_by_code_id(account_addr).await?;
let contract_name = self.get_contract_name_by_address(account_addr).await?;

// Loop over account types and see if any matches the contract name of the code id
// error if it doesn't match, else return ()
Expand All @@ -747,7 +747,7 @@ impl Connector for CosmosCosmwasmConnector {
.context("'verify_service' Service address is empty")
.map_err(CosmosCosmwasmError::Error)?;

let contract_name = self.get_contract_name_by_code_id(service_addr).await?;
let contract_name = self.get_contract_name_by_address(service_addr).await?;

Ok(ServiceConfig::VARIANTS
.iter()
Expand All @@ -758,7 +758,7 @@ impl Connector for CosmosCosmwasmConnector {
}

async fn verify_processor(&mut self, processor_addr: String) -> ConnectorResult<()> {
let contract_name = self.get_contract_name_by_code_id(processor_addr).await?;
let contract_name = self.get_contract_name_by_address(processor_addr).await?;

// Make sure the code id is of name processor
if contract_name != "processor" {
Expand All @@ -772,7 +772,7 @@ impl Connector for CosmosCosmwasmConnector {
}

async fn verify_bridge_account(&mut self, bridge_addr: String) -> ConnectorResult<()> {
// If the address have a code id, it means it was instantiated.
// If the address has a code id, it means it was instantiated.
self.get_code_id_of_addr(bridge_addr)
.await
.map(|_| ())
Expand All @@ -799,7 +799,7 @@ impl Connector for CosmosCosmwasmConnector {
}

async fn save_workflow_config(&mut self, config: WorkflowConfig) -> ConnectorResult<()> {
if self.chain_name != NEUTRON_DOMAIN.get_chain_name() {
if self.chain_name != *NEUTRON_CHAIN {
return Err(CosmosCosmwasmError::Error(anyhow::anyhow!(
"Should only be implemented on neutron connector"
))
Expand Down Expand Up @@ -1054,7 +1054,8 @@ impl CosmosCosmwasmConnector {
.code_id)
}

pub async fn get_contract_name_by_code_id(
// We query the chain for the code id of the address, and look this code id into our list of code ids to get the contract name
pub async fn get_contract_name_by_address(
&mut self,
addr: String,
) -> Result<String, CosmosCosmwasmError> {
Expand Down
Loading

0 comments on commit 72e45b8

Please sign in to comment.