Skip to content

Commit a23f606

Browse files
feat(zkgm): cleanup and restart from version 0
1 parent 4f894d6 commit a23f606

File tree

5 files changed

+39
-349
lines changed

5 files changed

+39
-349
lines changed

cosmwasm/ibc-union/app/ucs03-zkgm/src/com.rs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloy::{primitives::U256, sol_types::SolValue};
1+
use alloy::primitives::U256;
22

33
pub const INSTR_VERSION_0: u8 = 0x00;
44
pub const INSTR_VERSION_1: u8 = 0x01;
@@ -54,19 +54,6 @@ alloy::sol! {
5454
Instruction[] instructions;
5555
}
5656

57-
#[derive(Debug)]
58-
struct FungibleAssetOrderV0 {
59-
bytes sender;
60-
bytes receiver;
61-
bytes base_token;
62-
uint256 base_amount;
63-
string base_token_symbol;
64-
string base_token_name;
65-
uint256 base_token_path;
66-
bytes quote_token;
67-
uint256 quote_amount;
68-
}
69-
7057
#[derive(Debug, PartialEq)]
7158
struct FungibleAssetOrder {
7259
bytes sender;
@@ -97,38 +84,3 @@ alloy::sol! {
9784
bytes market_maker;
9885
}
9986
}
100-
101-
impl From<FungibleAssetOrderV0> for FungibleAssetOrder {
102-
fn from(value: FungibleAssetOrderV0) -> Self {
103-
FungibleAssetOrder {
104-
sender: value.sender,
105-
receiver: value.receiver,
106-
base_token: value.base_token,
107-
base_amount: value.base_amount,
108-
base_token_symbol: value.base_token_symbol,
109-
base_token_name: value.base_token_name,
110-
base_token_decimals: 0,
111-
base_token_path: value.base_token_path,
112-
quote_token: value.quote_token,
113-
quote_amount: value.quote_amount,
114-
}
115-
}
116-
}
117-
118-
pub fn decode_fungible_asset(
119-
instruction: &Instruction,
120-
) -> Result<FungibleAssetOrder, alloy::sol_types::Error> {
121-
match instruction.version {
122-
INSTR_VERSION_0 => {
123-
FungibleAssetOrderV0::abi_decode_params(&instruction.operand, true).map(Into::into)
124-
}
125-
INSTR_VERSION_1 => FungibleAssetOrder::abi_decode_params(&instruction.operand, true),
126-
_ => panic!("the protocol must handle an incorrect version"),
127-
}
128-
}
129-
130-
pub fn decode_fungible_asset_order_from_v0(
131-
data: &[u8],
132-
) -> Result<FungibleAssetOrder, alloy::sol_types::Error> {
133-
FungibleAssetOrderV0::abi_decode_params(data, true).map(Into::into)
134-
}

cosmwasm/ibc-union/app/ucs03-zkgm/src/contract.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ use unionlabs_cosmwasm_upgradable::UpgradeMsg;
2424

2525
use crate::{
2626
com::{
27-
decode_fungible_asset, Ack, Batch, BatchAck, Forward, FungibleAssetOrder,
28-
FungibleAssetOrderAck, Instruction, Multiplex, ZkgmPacket, ACK_ERR_ONLY_MAKER,
29-
FILL_TYPE_MARKETMAKER, FILL_TYPE_PROTOCOL, FORWARD_SALT_MAGIC, INSTR_VERSION_0,
30-
INSTR_VERSION_1, OP_BATCH, OP_FORWARD, OP_FUNGIBLE_ASSET_ORDER, OP_MULTIPLEX,
31-
TAG_ACK_FAILURE, TAG_ACK_SUCCESS,
27+
Ack, Batch, BatchAck, Forward, FungibleAssetOrder, FungibleAssetOrderAck, Instruction,
28+
Multiplex, ZkgmPacket, ACK_ERR_ONLY_MAKER, FILL_TYPE_MARKETMAKER, FILL_TYPE_PROTOCOL,
29+
FORWARD_SALT_MAGIC, INSTR_VERSION_0, OP_BATCH, OP_FORWARD, OP_FUNGIBLE_ASSET_ORDER,
30+
OP_MULTIPLEX, TAG_ACK_FAILURE, TAG_ACK_SUCCESS,
3231
},
3332
msg::{EurekaMsg, ExecuteMsg, InitMsg, PredictWrappedTokenResponse, QueryMsg},
3433
state::{
@@ -314,12 +313,12 @@ fn timeout_internal(
314313
) -> Result<Response, ContractError> {
315314
match instruction.opcode {
316315
OP_FUNGIBLE_ASSET_ORDER => {
317-
if instruction.version > INSTR_VERSION_1 {
316+
if instruction.version > INSTR_VERSION_0 {
318317
return Err(ContractError::UnsupportedVersion {
319318
version: instruction.version,
320319
});
321320
}
322-
let order = decode_fungible_asset(&instruction)?;
321+
let order = FungibleAssetOrder::abi_decode_params(&instruction.operand, true)?;
323322
refund(deps, path, packet.source_channel_id, order)
324323
}
325324
OP_BATCH => {
@@ -477,12 +476,12 @@ fn acknowledge_internal(
477476
) -> Result<Response, ContractError> {
478477
match instruction.opcode {
479478
OP_FUNGIBLE_ASSET_ORDER => {
480-
if instruction.version > INSTR_VERSION_1 {
479+
if instruction.version > INSTR_VERSION_0 {
481480
return Err(ContractError::UnsupportedVersion {
482481
version: instruction.version,
483482
});
484483
}
485-
let order = decode_fungible_asset(&instruction)?;
484+
let order = FungibleAssetOrder::abi_decode_params(&instruction.operand, true)?;
486485
let order_ack = if successful {
487486
Some(FungibleAssetOrderAck::abi_decode_params(&ack, true)?)
488487
} else {
@@ -764,12 +763,12 @@ fn execute_internal(
764763
) -> Result<Response, ContractError> {
765764
match instruction.opcode {
766765
OP_FUNGIBLE_ASSET_ORDER => {
767-
if instruction.version > INSTR_VERSION_1 {
766+
if instruction.version > INSTR_VERSION_0 {
768767
return Err(ContractError::UnsupportedVersion {
769768
version: instruction.version,
770769
});
771770
}
772-
let order = decode_fungible_asset(&instruction)?;
771+
let order = FungibleAssetOrder::abi_decode_params(&instruction.operand, true)?;
773772
execute_fungible_asset_order(
774773
deps,
775774
env,
@@ -1424,12 +1423,12 @@ pub fn verify_internal(
14241423
) -> Result<(), ContractError> {
14251424
match instruction.opcode {
14261425
OP_FUNGIBLE_ASSET_ORDER => {
1427-
if instruction.version != INSTR_VERSION_1 {
1426+
if instruction.version != INSTR_VERSION_0 {
14281427
return Err(ContractError::UnsupportedVersion {
14291428
version: instruction.version,
14301429
});
14311430
}
1432-
let order = decode_fungible_asset(instruction)?;
1431+
let order = FungibleAssetOrder::abi_decode_params(&instruction.operand, true)?;
14331432
verify_fungible_asset_order(deps, info, channel_id, path, &order, response)
14341433
}
14351434
OP_BATCH => {
@@ -1779,7 +1778,7 @@ fn transfer(
17791778
salt: salt.into(),
17801779
path: U256::ZERO,
17811780
instruction: Instruction {
1782-
version: INSTR_VERSION_1,
1781+
version: INSTR_VERSION_0,
17831782
opcode: OP_FUNGIBLE_ASSET_ORDER,
17841783
operand: FungibleAssetOrder {
17851784
sender: info.sender.as_bytes().to_vec().into(),

0 commit comments

Comments
 (0)