From 3f2e75084d1b0104deb72579eea4cef971738de1 Mon Sep 17 00:00:00 2001 From: Anshudhar Kumar Singh <53444123+SlayerAnsh@users.noreply.github.com> Date: Tue, 21 May 2024 18:11:25 +0530 Subject: [PATCH] Fix: Instantiate 2 address length (#467) * fix: instantiate2 injective error * Bump version for app-contract and app-package --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- contracts/app/andromeda-app-contract/Cargo.toml | 2 +- packages/andromeda-app/Cargo.toml | 2 +- packages/andromeda-app/src/app.rs | 13 +++++++++++++ packages/andromeda-testing/Cargo.toml | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06f2750c5..d9a21af24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,7 +43,7 @@ dependencies = [ [[package]] name = "andromeda-app" -version = "1.0.0" +version = "1.0.1" dependencies = [ "andromeda-std", "cosmwasm-schema", @@ -54,7 +54,7 @@ dependencies = [ [[package]] name = "andromeda-app-contract" -version = "1.0.0" +version = "1.0.1" dependencies = [ "andromeda-app", "andromeda-std", diff --git a/Cargo.toml b/Cargo.toml index ff810d25a..8902c14e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ andromeda-fungible-tokens = { path = "./packages/andromeda-fungible-tokens", ver andromeda-finance = { path = "./packages/andromeda-finance", version = "1.0.0" } andromeda-data-storage = { path = "./packages/andromeda-data-storage", version = "1.0.0" } andromeda-modules = { path = "./packages/andromeda-modules", version = "1.0.0" } -andromeda-app = { path = "./packages/andromeda-app", version = "1.0.0" } +andromeda-app = { path = "./packages/andromeda-app", version = "1.0.1" } andromeda-ecosystem = { path = "./packages/andromeda-ecosystem", version = "1.0.0" } andromeda-testing = { path = "./packages/andromeda-testing", version = "1.0.0" } diff --git a/contracts/app/andromeda-app-contract/Cargo.toml b/contracts/app/andromeda-app-contract/Cargo.toml index a30997199..d49bba912 100644 --- a/contracts/app/andromeda-app-contract/Cargo.toml +++ b/contracts/app/andromeda-app-contract/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "andromeda-app-contract" -version = "1.0.0" +version = "1.0.1" edition = "2021" rust-version = "1.65.0" diff --git a/packages/andromeda-app/Cargo.toml b/packages/andromeda-app/Cargo.toml index 2903038d0..46711cd38 100644 --- a/packages/andromeda-app/Cargo.toml +++ b/packages/andromeda-app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "andromeda-app" -version = "1.0.0" +version = "1.0.1" edition = "2021" rust-version = "1.65.0" description = "Utility methods and message definitions for the Andromeda App Contract" diff --git a/packages/andromeda-app/src/app.rs b/packages/andromeda-app/src/app.rs index 9a5816c4e..d57822e92 100644 --- a/packages/andromeda-app/src/app.rs +++ b/packages/andromeda-app/src/app.rs @@ -142,6 +142,19 @@ impl AppComponent { let creator = api.addr_canonicalize(parent_addr.as_str())?; let new_addr = instantiate2_address(&checksum, &creator, &salt).unwrap(); + // Instantiate 2 impl uses default cannonical address of 32 bytes (SHA 256). But as mentioned here - + // https://github.com/cosmos/cosmos-sdk/blob/v0.45.8/docs/architecture/adr-028-public-key-addresses.md + // chains can use different length for cannonical address, eg, injective uses 20 (eth based). + // Instead of having fallback for each chain we can use parent address, which itself is a contract. + // Slice the default 32 bytes canonical address to size of parent cannonical address + + let cannonical_parent_addr = api.addr_canonicalize(parent_addr.as_str())?; + let new_addr = new_addr + .as_slice() + .split_at(cannonical_parent_addr.len()) + .0 + .into(); + Ok(Some(api.addr_humanize(&new_addr)?)) } diff --git a/packages/andromeda-testing/Cargo.toml b/packages/andromeda-testing/Cargo.toml index 03627c85b..b9db81607 100644 --- a/packages/andromeda-testing/Cargo.toml +++ b/packages/andromeda-testing/Cargo.toml @@ -22,7 +22,7 @@ prost = "0.9.0" anyhow = "1.0.79" andromeda-non-fungible-tokens = { workspace = true } -andromeda-app = { version = "1.0.0", path = "../andromeda-app" } +andromeda-app = { version = "1.0.1", path = "../andromeda-app" } andromeda-modules = { version = "1.0.0", path = "../andromeda-modules" } andromeda-adodb = { version = "1.0.0", path = "../../contracts/os/andromeda-adodb", features = [ "testing",