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

XCS + Registries integration: IBC forward generation using registries #4694

Merged
merged 21 commits into from
Mar 24, 2023
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
working-directory: ${{ matrix.contract.workdir }}
run: >
docker run --rm -v "$(pwd)":/code \
-e REGISTRY_CONTRACT=osmo14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sq2r9g9 \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.12.10
Expand Down
34 changes: 24 additions & 10 deletions cosmwasm/Cargo.lock

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

2 changes: 2 additions & 0 deletions cosmwasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
'contracts/*',
'packages/*'
]

[workspace.package]
Expand Down Expand Up @@ -36,3 +37,4 @@ serde-json-wasm = "0.5.0"
serde-cw-value = "0.7.0"
bech32 = "0.9.1"
cw-utils = "1.0.0"
itertools = "0.10"
11 changes: 1 addition & 10 deletions cosmwasm/contracts/crosschain-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,10 @@ cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
bech32 = { workspace = true }
cw-utils = { workspace = true }
serde-json-wasm = { workspace = true }
sha2 = "0.10.6"
hex = "0.4.3"
prost = {version = "0.11.2", default-features = false, features = ["prost-derive"]}
osmosis-std-derive = "0.13.2"
itertools = "0.10.5"

crosschain-swaps = { path = "../crosschain-swaps", features = ["imported"]}
registry = { path = "../../packages/registry"}

[dev-dependencies]
cw-multi-test = "0.16.2"
12 changes: 9 additions & 3 deletions cosmwasm/contracts/crosschain-registry/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use cw2::set_contract_version;
use crate::error::ContractError;
use crate::msg::{ExecuteMsg, GetAddressFromAliasResponse, InstantiateMsg, QueryMsg};
use crate::state::{Config, CONFIG, CONTRACT_ALIAS_MAP};
use crate::{execute, query, Registries};
use crate::{execute, query};
use registry::Registry;

// version info for migration
const CONTRACT_NAME: &str = "crates.io:crosschain-registry";
Expand Down Expand Up @@ -60,15 +61,17 @@ pub fn execute(
ExecuteMsg::UnwrapCoin {
receiver,
into_chain,
with_memo,
} => {
let registries = Registries::new(deps.as_ref(), env.contract.address.to_string())?;
let registries = Registry::new(deps.as_ref(), env.contract.address.to_string())?;
let coin = cw_utils::one_coin(&info)?;
let transfer_msg = registries.unwrap_coin_into(
coin,
receiver,
into_chain.as_deref(),
env.contract.address.to_string(),
env.block.time,
with_memo,
)?;
deps.api.debug(&format!("transfer_msg: {transfer_msg:?}"));
Ok(Response::new()
Expand Down Expand Up @@ -113,6 +116,9 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::GetDenomTrace { ibc_denom } => {
to_binary(&query::query_denom_trace_from_ibc_denom(deps, ibc_denom)?)
}
QueryMsg::GetChainNameFromBech32Prefix { prefix } => {
to_binary(&query::query_chain_name_from_bech32_prefix(deps, prefix)?)
}
}
}

Expand Down Expand Up @@ -327,7 +333,7 @@ mod test {
new_channel_id: None,
}],
};
let result = execute(deps.as_mut(), mock_env(), info_creator.clone(), msg);
let result = execute(deps.as_mut(), mock_env(), info_creator, msg);
assert!(result.is_ok());

// Retrieve osmo<>juno link again, but this time it should be enabled
Expand Down
85 changes: 1 addition & 84 deletions cosmwasm/contracts/crosschain-registry/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,90 +1,7 @@
use cosmwasm_std::StdError;
use registry::RegistryError;
use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
pub enum RegistryError {
#[error("{0}")]
Std(#[from] StdError),

// Validation errors
#[error("Invalid channel id: {0}")]
InvalidChannelId(String),

#[error("error {action} {addr}")]
Bech32Error {
action: String,
addr: String,
#[source]
source: bech32::Error,
},

#[error("serialization error: {error}")]
SerialiaztionError { error: String },

#[error("denom {denom:?} is not an IBC denom")]
InvalidIBCDenom { denom: String },

#[error("No deom trace found for: {denom:?}")]
NoDenomTrace { denom: String },

#[error("Invalid denom trace: {error}")]
InvalidDenomTrace { error: String },

#[error("Invalid path {path:?} for denom {denom:?}")]
InvalidDenomTracePath { path: String, denom: String },

#[error("Invalid transfer port {port:?}")]
InvalidTransferPort { port: String },

#[error("Invalid multihop length {length:?}. Must be >={min}")]
InvalidMultiHopLengthMin { length: usize, min: usize },

#[error("Invalid multihop length {length:?}. Must be <={max}")]
InvalidMultiHopLengthMax { length: usize, max: usize },

#[error(
"receiver prefix for {receiver} must match the bech32 prefix of the destination chain {chain}"
)]
InvalidReceiverPrefix { receiver: String, chain: String },

// Registry loading errors
#[error("contract alias does not exist: {alias:?}")]
AliasDoesNotExist { alias: String },

#[error("no authorized address found for source chain: {source_chain:?}")]
ChainAuthorizedAddressDoesNotExist { source_chain: String },

#[error("chain channel link does not exist: {source_chain:?} -> {destination_chain:?}")]
ChainChannelLinkDoesNotExist {
source_chain: String,
destination_chain: String,
},

#[error("channel chain link does not exist: {channel_id:?} on {source_chain:?} -> chain")]
ChannelChainLinkDoesNotExist {
channel_id: String,
source_chain: String,
},

#[error("channel chain link does not exist: {channel_id:?} on {source_chain:?} -> chain")]
ChannelToChainChainLinkDoesNotExist {
channel_id: String,
source_chain: String,
},

#[error("native denom link does not exist: {native_denom:?}")]
NativeDenomLinkDoesNotExist { native_denom: String },

#[error("bech32 prefix does not exist for chain: {chain}")]
Bech32PrefixDoesNotExist { chain: String },
}

impl From<RegistryError> for StdError {
fn from(e: RegistryError) -> Self {
StdError::generic_err(e.to_string())
}
}

#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Expand Down
Loading