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

feat: partial upgrade of contracts to CosmWasm 2.0 #1876

Merged
merged 6 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
235 changes: 174 additions & 61 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cosmwasm/token-factory-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ version = "0.1.0"
workspace = true

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cosmwasm-schema = { version = "2.0.0" }
cosmwasm-std = { version = "2.0.0" }
4 changes: 2 additions & 2 deletions cosmwasm/ucs01-relay-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ version = "0.1.0"
workspace = true

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true, features = ["stargate"] }
cosmwasm-schema = { version = "2.0.0" }
cosmwasm-std = { version = "2.0.0", features = ["stargate"] }
ethabi = { workspace = true }
thiserror = { workspace = true }
token-factory-api = { workspace = true }
24 changes: 11 additions & 13 deletions cosmwasm/ucs01-relay-api/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ pub trait TransferProtocol {
Event::new(PACKET_EVENT).add_attribute("memo", &memo)
};

Ok(IbcReceiveResponse::new()
.set_ack(Self::ack_success().try_into()?)
Ok(IbcReceiveResponse::new(Self::ack_success().try_into()?)
.add_event(
packet_event
.add_attributes([
Expand All @@ -284,16 +283,15 @@ pub trait TransferProtocol {

fn receive_error(error: impl Debug) -> IbcReceiveResponse<Self::CustomMsg> {
let error = format!("{:?}", error);
IbcReceiveResponse::new()
.set_ack(
Self::ack_failure(error.clone())
.try_into()
.expect("impossible"),
)
.add_event(Event::new(PACKET_EVENT).add_attributes([
("module", MODULE_NAME),
("success", "false"),
("error", &error),
]))
IbcReceiveResponse::new(
Self::ack_failure(error.clone())
.try_into()
.expect("impossible"),
)
.add_event(Event::new(PACKET_EVENT).add_attributes([
("module", MODULE_NAME),
("success", "false"),
("error", &error),
]))
}
}
10 changes: 5 additions & 5 deletions cosmwasm/ucs01-relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ crate-type = ["cdylib", "rlib"]
library = []

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true, features = ["stargate", "ibc3", "cosmwasm_1_3"] }
cw-controllers = { version = "1.1" }
cw-storage-plus = { workspace = true }
cw2 = { version = "1.1" }
cosmwasm-schema = { version = "2.0.0" }
cosmwasm-std = { version = "2.0.0", features = ["stargate", "cosmwasm_2_0"] }
cw-controllers = { version = "2.0.0" }
cw-storage-plus = { version = "2.0.0" }
cw2 = { version = "2.0.0" }
dlmalloc = { workspace = true, features = ["global"] }
ethabi = { workspace = true }
hex = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions cosmwasm/ucs01-relay/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn execute(
if info.sender != env.contract.address {
Err(ContractError::Unauthorized)
} else {
let normalized_hash = hash.0.try_into().expect("impossible");
let normalized_hash = hash.as_slice().try_into().expect("impossible");
FOREIGN_DENOM_TO_HASH.save(
deps.storage,
(local_endpoint.clone().into(), denom.clone()),
Expand Down Expand Up @@ -180,7 +180,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {

fn query_port(deps: Deps) -> StdResult<PortResponse> {
let query = IbcQuery::PortId {}.into();
let PortIdResponse { port_id } = deps.querier.query(&query)?;
let PortIdResponse { port_id, .. } = deps.querier.query(&query)?;
Ok(PortResponse { port_id })
}

Expand Down
11 changes: 8 additions & 3 deletions cosmwasm/ucs01-relay/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ fn to_response<T>(
..
}: IbcReceiveResponse<T>,
) -> Response<T> {
Response::<T>::new()
let response = Response::<T>::new()
.add_submessages(messages)
.add_attributes(attributes)
.add_events(events)
.set_data(acknowledgement)
.add_events(events);

if let Some(ack) = acknowledgement {
response.set_data(ack)
} else {
response
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down
2 changes: 2 additions & 0 deletions cosmwasm/ucs01-relay/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ impl KeyDeserialize for IbcEndpointKey {
fn from_vec(value: Vec<u8>) -> cosmwasm_std::StdResult<Self::Output> {
<(String, String) as KeyDeserialize>::from_vec(value)
}

const KEY_ELEMS: u16 = todo!();
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved
}

impl<'a> PrimaryKey<'a> for IbcEndpointKey {
Expand Down
10 changes: 10 additions & 0 deletions tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ fn main() -> ExitCode {
for (dep_name, dep) in deps {
match dep {
InheritableDependency::Value(_) => {
if dep_name.as_ref() == "cosmwasm-schema"
|| dep_name.as_ref() == "cosmwasm-std"
|| dep_name.as_ref() == "cw-storage-plus"
{
tracing::warn!(
member = %member.name,
"{dep_name} is being ignored for deduplication checks as we gradually migrate to cosmwasm 2.0"
);
continue;
}
if workspace_dependencies.contains_key(dep_name) {
is_err = true;

Expand Down
2 changes: 1 addition & 1 deletion zerg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ block-message = { workspace = true }
chain-utils = { workspace = true }
clap = { workspace = true, features = ["default", "derive", "env", "error-context"] }
contracts = { workspace = true }
cosmwasm-std = { workspace = true, features = ["stargate", "ibc3", "cosmwasm_1_3"] }
cosmwasm-std = { version = "2.0.0", features = ["stargate", "cosmwasm_1_3"] }
csv = "1.3.0"
ethers = { workspace = true, features = ["rustls", "ws"] }
futures = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion zerg/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ impl Context {

async fn send_from_eth(self, e: unionlabs::events::RecvPacket) {
let transfer =
Ucs01TransferPacket::try_from(cosmwasm_std::Binary(e.packet_data_hex.clone())).unwrap();
Ucs01TransferPacket::try_from(cosmwasm_std::Binary::new(e.packet_data_hex.clone()))
.unwrap();

let wallet = if let Some(wallet) = self
.ethereum_accounts
Expand Down
3 changes: 2 additions & 1 deletion zerg/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ impl Event {
finalization_timestamp: Option<u64>,
) -> Event {
let transfer =
Ucs01TransferPacket::try_from(cosmwasm_std::Binary(e.packet_data_hex.clone())).unwrap();
Ucs01TransferPacket::try_from(cosmwasm_std::Binary::new(e.packet_data_hex.clone()))
.unwrap();

let timed_event = TimedEvent::new(chain_id, execution_timestamp, finalization_timestamp);

Expand Down
Loading