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

Added disconnect script #547

Merged
merged 6 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 0 additions & 1 deletion framework/Cargo.lock

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

30 changes: 30 additions & 0 deletions framework/packages/abstract-interface/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@
connect_one_way_to(remote_abstr, self, interchain)?;
Ok(())
}

/// This is used for completely removing a connection between two Abstract connections.
pub fn disconnect_from(
&self,
remote_abstr: &Abstract<Chain>,
) -> Result<(), AbstractInterfaceError> {
disconnect_one_way_from(self, remote_abstr)?;
disconnect_one_way_from(remote_abstr, self)?;
Ok(())
}

Check warning on line 97 in framework/packages/abstract-interface/src/ibc.rs

View check run for this annotation

Codecov / codecov/patch

framework/packages/abstract-interface/src/ibc.rs#L90-L97

Added lines #L90 - L97 were not covered by tests
}

impl AbstractIbc<Daemon> {
Expand Down Expand Up @@ -144,6 +154,26 @@
Ok(())
}

pub fn disconnect_one_way_from<Chain: IbcQueryHandler>(
abstr_client: &Abstract<Chain>,
abstr_host: &Abstract<Chain>,
) -> Result<(), AbstractInterfaceError> {
// First we get the chain names to remove them from host and client
let chain1_id = abstr_client.ibc.client.environment().chain_id();
let chain1_name = TruncatedChainId::from_chain_id(&chain1_id);

let chain2_id = abstr_host.ibc.client.environment().chain_id();
let chain2_name = TruncatedChainId::from_chain_id(&chain2_id);

// First, we remove on the client
abstr_client.ibc.client.remove_host(chain2_name.clone())?;

Check warning on line 169 in framework/packages/abstract-interface/src/ibc.rs

View check run for this annotation

Codecov / codecov/patch

framework/packages/abstract-interface/src/ibc.rs#L157-L169

Added lines #L157 - L169 were not covered by tests

// Then we remove on the host
abstr_host.ibc.host.remove_chain_proxy(chain1_name)?;

Check warning on line 172 in framework/packages/abstract-interface/src/ibc.rs

View check run for this annotation

Codecov / codecov/patch

framework/packages/abstract-interface/src/ibc.rs#L172

Added line #L172 was not covered by tests

Ok(())
}

Check warning on line 175 in framework/packages/abstract-interface/src/ibc.rs

View check run for this annotation

Codecov / codecov/patch

framework/packages/abstract-interface/src/ibc.rs#L174-L175

Added lines #L174 - L175 were not covered by tests

pub fn list_ibc_infrastructures<Chain: CwEnv>(
chain: Chain,
) -> abstract_std::ibc_client::ListIbcInfrastructureResponse {
Expand Down
53 changes: 26 additions & 27 deletions framework/packages/abstract-std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
authors = { workspace = true }
authors = { workspace = true }
description = "Abstract contract interfaces and storage layouts"
edition = { workspace = true }
license = { workspace = true }
name = "abstract-std"
readme = "README.md"
repository = "https://github.com/AbstractSDK/abstract"
version = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
name = "abstract-std"
readme = "README.md"
repository = "https://github.com/AbstractSDK/abstract"
version = { workspace = true }

[lints]
workspace = true
Expand All @@ -15,25 +15,24 @@ workspace = true
# for quicker tests, cargo test --lib

[dependencies]
anybuf = { workspace = true }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true, features = ["iterator"] }
cosmwasm-std = { workspace = true, features = ["iterator"] }
cw-address-like = { workspace = true }
cw-asset = { workspace = true }
cw-blob = { workspace = true }
cw-clearable = { workspace = true }
cw-controllers = { workspace = true }
cw-orch = { workspace = true }
cw-ownable = { workspace = true }
cw-asset = { workspace = true }
cw-blob = { workspace = true }
cw-clearable = { workspace = true }
cw-controllers = { workspace = true }
cw-orch = { workspace = true }
cw-ownable = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
cw2 = { workspace = true }
cw20 = { workspace = true }
schemars = { workspace = true }
semver = { workspace = true, features = ["serde"] }
serde = { workspace = true }
sha2 = { version = "0.10.8", default-features = false }
thiserror = { workspace = true }
cw-utils = { workspace = true }
cw2 = { workspace = true }
cw20 = { workspace = true }
schemars = { workspace = true }
semver = { workspace = true, features = ["serde"] }
serde = { workspace = true }
sha2 = { version = "0.10.8", default-features = false }
thiserror = { workspace = true }

## Stringify function names
function_name = { version = "0.3.0" }
Expand All @@ -43,7 +42,7 @@ workspace-hack = { version = "0.1", path = "../../workspace-hack" }

[dev-dependencies]
abstract-testing = { path = "../abstract-testing" }
anyhow = { workspace = true }
coverage-helper = { workspace = true }
cw20-base = { workspace = true }
rstest = { workspace = true }
anyhow = { workspace = true }
coverage-helper = { workspace = true }
cw20-base = { workspace = true }
rstest = { workspace = true }
8 changes: 1 addition & 7 deletions interchain/scripts/src/bin/full_deploy.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
use abstract_interface::{Abstract, AccountI};
use abstract_std::objects::gov_type::GovernanceDetails;
use std::{
fs::{self, File},
io::BufReader,
net::TcpStream,
};

use abstract_scripts::{assert_wallet_balance, DeploymentStatus, SUPPORTED_CHAINS};
use abstract_scripts::{assert_wallet_balance, SUPPORTED_CHAINS};

use clap::Parser;
use cw_orch::{daemon::networks::parse_network, prelude::*};
use reqwest::Url;
use tokio::runtime::Runtime;

pub const ABSTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down
85 changes: 85 additions & 0 deletions interchain/scripts/src/bin/ibc_disconnect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use abstract_interface::Abstract;
use clap::Parser;
use cw_orch::daemon::DaemonState;
use cw_orch::prelude::*;

use networks::parse_network;

fn get_daemon(
chain: ChainInfo,
mnemonic: Option<String>,
deployment_id: Option<String>,
state: Option<DaemonState>,
) -> cw_orch::anyhow::Result<Daemon> {
let mut builder = DaemonBuilder::new(chain);
if let Some(state) = state {
builder.state(state);
}
if let Some(mnemonic) = mnemonic {
builder.mnemonic(mnemonic);
}
if let Some(deployment_id) = deployment_id {
builder.deployment_id(deployment_id);
}
Ok(builder.build()?)
}

pub fn get_deployment_id(src_chain: &ChainInfo, dst_chain: &ChainInfo) -> String {
format!("{}-->{}", src_chain.chain_id, dst_chain.chain_id)
}

fn connect(
Kayanski marked this conversation as resolved.
Show resolved Hide resolved
(src_chain, src_mnemonic): (ChainInfo, Option<String>),
(dst_chain, dst_mnemonic): (ChainInfo, Option<String>),
) -> cw_orch::anyhow::Result<()> {
let src_daemon = get_daemon(src_chain.clone(), src_mnemonic.clone(), None, None)?;
let dst_daemon = get_daemon(
dst_chain.clone(),
dst_mnemonic,
None,
Some(src_daemon.state()),
)?;

let src_abstract = Abstract::load_from(src_daemon.clone())?;
let dst_abstract = Abstract::load_from(dst_daemon.clone())?;
src_abstract.disconnect_from(&dst_abstract)?;

Ok(())
}

#[derive(Parser, Default, Debug)]
#[command(author, version, about, long_about = None)]
struct Arguments {
#[arg(short, long)]
src: String,

#[arg(short, long)]
dst: String,
}

fn main() {
dotenv::dotenv().unwrap();
env_logger::init();

let args = Arguments::parse();

// let networks = vec![abstract_scripts::ROLLKIT_TESTNET];

Kayanski marked this conversation as resolved.
Show resolved Hide resolved
let src_network = parse_network(&args.src).unwrap();
let dst_network = parse_network(&args.dst).unwrap();

if let Err(ref err) = connect((src_network, None), (dst_network, None)) {
Kayanski marked this conversation as resolved.
Show resolved Hide resolved
log::error!("{}", err);
err.chain()
.skip(1)
.for_each(|cause| log::error!("because: {}", cause));

// The backtrace is not always generated. Try to run this example
// with `$env:RUST_BACKTRACE=1`.
// if let Some(backtrace) = e.backtrace() {
// log::debug!("backtrace: {:?}", backtrace);
// }

::std::process::exit(1);
}
}
Loading