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

fix(zkgm): cosmwasm: sovereign minter #4103

Merged
merged 3 commits into from
Mar 21, 2025
Merged
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
62 changes: 24 additions & 38 deletions cosmwasm/cw20-token-minter/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use alloy::{primitives::U256, sol_types::SolValue};
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{
entry_point, instantiate2_address, to_json_binary, to_json_string, wasm_execute, BankMsg,
Binary, CodeInfoResponse, Coin, DenomMetadataResponse, Deps, DepsMut, Env, Event, MessageInfo,
QueryRequest, Response, StdResult, WasmMsg,
entry_point, instantiate2_address, to_json_binary, wasm_execute, BankMsg, Binary,
CodeInfoResponse, Coin, DenomMetadataResponse, Deps, DepsMut, Env, MessageInfo, QueryRequest,
Response, StdResult, WasmMsg,
};
use cw20::{Cw20QueryMsg, TokenInfoResponse};
use ibc_union_spec::ChannelId;
use ucs03_zkgm_token_minter_api::{
ExecuteMsg, LocalTokenMsg, MetadataResponse, PredictWrappedTokenResponse, QueryMsg,
WrappedTokenMsg, DISPATCH_EVENT, DISPATCH_EVENT_ATTR,
WrappedTokenMsg,
};
use unionlabs::{ethereum::keccak256, primitives::H256};

@@ -131,36 +131,27 @@ pub fn execute(
denom,
amount,
mint_to_address,
} => {
let msg = wasm_execute(
denom,
&cw20::Cw20ExecuteMsg::Mint {
recipient: mint_to_address,
amount,
},
vec![],
)?;
Response::new().add_message(msg)
}
} => Response::new().add_message(wasm_execute(
denom,
&cw20::Cw20ExecuteMsg::Mint {
recipient: mint_to_address,
amount,
},
vec![],
)?),
WrappedTokenMsg::BurnTokens {
denom,
amount,
sender,
..
} => {
let msg = wasm_execute(
denom,
&cw20::Cw20ExecuteMsg::BurnFrom {
owner: sender.to_string(),
amount,
},
vec![],
)?;
Response::new().add_event(
Event::new(DISPATCH_EVENT)
.add_attribute(DISPATCH_EVENT_ATTR, to_json_string(&vec![msg])?),
)
}
} => Response::new().add_message(wasm_execute(
denom,
&cw20::Cw20ExecuteMsg::BurnFrom {
owner: sender.to_string(),
amount,
},
vec![],
)?),
},
ExecuteMsg::Local(msg) => match msg {
LocalTokenMsg::Escrow {
@@ -179,19 +170,15 @@ pub fn execute(
save_native_token(deps, &denom);
Response::new()
} else {
let msg = wasm_execute(
Response::new().add_message(wasm_execute(
denom,
&cw20::Cw20ExecuteMsg::TransferFrom {
owner: from,
recipient,
amount,
},
vec![],
)?;
// We are delegating the TransferFrom to zkgm so it is capable
Response::new().add_event(
Event::new("dispatch").add_attribute("msg", to_json_string(&vec![msg])?),
)
)?)
}
}
LocalTokenMsg::Unescrow {
@@ -205,12 +192,11 @@ pub fn execute(
amount: vec![Coin { denom, amount }],
})
} else {
let msg = wasm_execute(
Response::new().add_message(wasm_execute(
denom,
&cw20::Cw20ExecuteMsg::Transfer { recipient, amount },
vec![],
)?;
Response::new().add_message(msg)
)?)
}
}
},
39 changes: 5 additions & 34 deletions cosmwasm/ibc-union/app/ucs03-zkgm/src/contract.rs
Original file line number Diff line number Diff line change
@@ -13,9 +13,7 @@ use ibc_union_msg::{
msg::{MsgSendPacket, MsgWriteAcknowledgement},
};
use ibc_union_spec::{path::BatchPacketsPath, ChannelId, Packet};
use ucs03_zkgm_token_minter_api::{
LocalTokenMsg, Metadata, MetadataResponse, WrappedTokenMsg, DISPATCH_EVENT, DISPATCH_EVENT_ATTR,
};
use ucs03_zkgm_token_minter_api::{LocalTokenMsg, Metadata, MetadataResponse, WrappedTokenMsg};
use unionlabs::{
ethereum::keccak256,
primitives::{Bytes, H256},
@@ -42,7 +40,6 @@ pub const PROTOCOL_VERSION: &str = "ucs03-zkgm-0";

pub const EXECUTE_REPLY_ID: u64 = 0x1337;
pub const TOKEN_INIT_REPLY_ID: u64 = 0xbeef;
pub const ESCROW_REPLY_ID: u64 = 0xcafe;
pub const FORWARD_REPLY_ID: u64 = 0xbabe;
pub const MULTIPLEX_REPLY_ID: u64 = 0xface;
pub const MM_FILL_REPLY_ID: u64 = 0xdead;
@@ -1286,36 +1283,6 @@ fn execute_fungible_asset_order(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(deps: DepsMut, env: Env, reply: Reply) -> Result<Response, ContractError> {
match reply.id {
// This reply is triggered after we escrow tokens in the token minter contract.
// We need to handle this reply to process any dispatch events that the token minter might have
// emitted during the escrow operation. These events can contain additional messages that need
// to be executed as part of the token transfer process, such as updating balances or
// performing additional token operations.
ESCROW_REPLY_ID => {
let Some(dispatch) = reply
.result
.into_result()
.expect("only if success")
.events
.into_iter()
.find(|e| e.ty == format!("wasm-{DISPATCH_EVENT}"))
else {
return Ok(Response::new());
};

let Some(attr) = dispatch
.attributes
.into_iter()
.find(|a| a.key == DISPATCH_EVENT_ATTR)
else {
return Ok(Response::new());
};

match serde_json_wasm::from_str::<Vec<WasmMsg>>(&attr.value) {
Ok(msgs) => Ok(Response::new().add_messages(msgs)),
Err(_) => Ok(Response::new()),
}
}
// This reply is triggered after we execute a packet.
// We need to handle this reply to process the acknowledgement that was generated during
// packet execution. This is a critical part of the IBC protocol - after a packet is
@@ -1894,6 +1861,10 @@ pub fn query(deps: Deps, _: Env, msg: QueryMsg) -> Result<Binary, ContractError>
wrapped_token: token.as_bytes().into(),
})?)
}
QueryMsg::GetMinter {} => {
let minter = TOKEN_MINTER.load(deps.storage)?;
Ok(to_json_binary(&minter)?)
}
}
}

1 change: 1 addition & 0 deletions cosmwasm/ibc-union/app/ucs03-zkgm/src/msg.rs
Original file line number Diff line number Diff line change
@@ -95,6 +95,7 @@ pub enum QueryMsg {
/// Base token denom
token: Bytes,
},
GetMinter {},
}

#[cw_serde]
3 changes: 0 additions & 3 deletions cosmwasm/ucs03-zkgm-token-minter-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -3,9 +3,6 @@ use cosmwasm_std::{Addr, Binary, Uint128};
use enumorph::Enumorph;
use ibc_union_spec::ChannelId;

pub const DISPATCH_EVENT: &str = "dispatch";
pub const DISPATCH_EVENT_ATTR: &str = "msg";

#[cw_serde]
pub enum LocalTokenMsg {
Escrow {