Skip to content

Commit f52c09b

Browse files
committed
fix(zkgm): fungible asset order field order
Signed-off-by: aeryz <[email protected]>
1 parent 832aab9 commit f52c09b

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

aptos/ucs03-zkgm/sources/fungible_asset_order.move

+13-13
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ module zkgm::fungible_asset_order {
7171
base_amount: u256,
7272
base_token_symbol: String,
7373
base_token_name: String,
74+
base_token_decimals: u8,
7475
base_token_path: u256,
7576
quote_token: vector<u8>,
76-
quote_amount: u256,
77-
decimals: u8
77+
quote_amount: u256
7878
}
7979

8080
public fun new(
@@ -84,10 +84,10 @@ module zkgm::fungible_asset_order {
8484
base_amount: u256,
8585
base_token_symbol: String,
8686
base_token_name: String,
87+
base_token_decimals: u8,
8788
base_token_path: u256,
8889
quote_token: vector<u8>,
89-
quote_amount: u256,
90-
decimals: u8
90+
quote_amount: u256
9191
): FungibleAssetOrder {
9292
FungibleAssetOrder {
9393
sender,
@@ -96,10 +96,10 @@ module zkgm::fungible_asset_order {
9696
base_amount,
9797
base_token_symbol,
9898
base_token_name,
99+
base_token_decimals,
99100
base_token_path,
100101
quote_token,
101-
quote_amount,
102-
decimals
102+
quote_amount
103103
}
104104
}
105105

@@ -127,6 +127,10 @@ module zkgm::fungible_asset_order {
127127
&order.base_token_name
128128
}
129129

130+
public fun base_token_decimals(order: &FungibleAssetOrder): u8 {
131+
order.base_token_decimals
132+
}
133+
130134
public fun base_token_path(order: &FungibleAssetOrder): u256 {
131135
order.base_token_path
132136
}
@@ -139,10 +143,6 @@ module zkgm::fungible_asset_order {
139143
order.quote_amount
140144
}
141145

142-
public fun decimals(order: &FungibleAssetOrder): u8 {
143-
order.decimals
144-
}
145-
146146
public fun encode(order: &FungibleAssetOrder): vector<u8> {
147147
let buf = vector::empty();
148148

@@ -176,11 +176,11 @@ module zkgm::fungible_asset_order {
176176
// base_token_name offset
177177
zkgm_ethabi::encode_uint<u64>(&mut buf, dyn_offset);
178178
dyn_offset = dyn_offset + vector::length(&base_token_name);
179+
zkgm_ethabi::encode_uint<u8>(&mut buf, order.base_token_decimals);
179180
zkgm_ethabi::encode_uint<u256>(&mut buf, order.base_token_path);
180181
// quote_token offset
181182
zkgm_ethabi::encode_uint<u64>(&mut buf, dyn_offset);
182183
zkgm_ethabi::encode_uint<u256>(&mut buf, order.quote_amount);
183-
zkgm_ethabi::encode_uint<u8>(&mut buf, order.decimals);
184184

185185
vector::append(&mut buf, sender);
186186
vector::append(&mut buf, receiver);
@@ -201,10 +201,10 @@ module zkgm::fungible_asset_order {
201201
base_amount: zkgm_ethabi::decode_uint(buf, &mut index),
202202
base_token_symbol: zkgm_ethabi::decode_string_from_offset(buf, &mut index),
203203
base_token_name: zkgm_ethabi::decode_string_from_offset(buf, &mut index),
204+
base_token_decimals: (zkgm_ethabi::decode_uint(buf, &mut index) as u8),
204205
base_token_path: zkgm_ethabi::decode_uint(buf, &mut index),
205206
quote_token: zkgm_ethabi::decode_bytes_from_offset(buf, &mut index),
206-
quote_amount: zkgm_ethabi::decode_uint(buf, &mut index),
207-
decimals: (zkgm_ethabi::decode_uint(buf, &mut index) as u8)
207+
quote_amount: zkgm_ethabi::decode_uint(buf, &mut index)
208208
}
209209
}
210210

aptos/ucs03-zkgm/sources/zkgm.move

+3-3
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,10 @@ module zkgm::ibc_app {
451451
base_amount,
452452
symbol,
453453
name,
454+
zkgm::fa_coin::decimals_with_metadata(asset),
454455
origin,
455456
quote_token,
456-
quote_amount,
457-
zkgm::fa_coin::decimals_with_metadata(asset)
457+
quote_amount
458458
);
459459
let operand = fungible_asset_order::encode(&fungible_asset_order);
460460
let zkgm_pack =
@@ -911,7 +911,7 @@ module zkgm::ibc_app {
911911
if (!is_deployed(wrapped_address)) {
912912
let token_name = *fungible_asset_order::base_token_name(&order);
913913
let token_symbol = *fungible_asset_order::base_token_symbol(&order);
914-
deploy_token(salt, token_name, token_symbol, fungible_asset_order::decimals(&order));
914+
deploy_token(salt, token_name, token_symbol, fungible_asset_order::base_token_decimals(&order));
915915
let value =
916916
update_channel_path(
917917
path, ibc::packet::destination_channel_id(&ibc_packet)

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ alloy::sol! {
7070
uint256 base_amount;
7171
string base_token_symbol;
7272
string base_token_name;
73+
uint8 base_token_decimals;
7374
uint256 base_token_path;
7475
bytes quote_token;
7576
uint256 quote_amount;
76-
uint8 decimals;
7777
}
7878

79+
#[derive(Debug)]
7980
struct Ack {
8081
uint256 tag;
8182
bytes inner_ack;
@@ -85,6 +86,7 @@ alloy::sol! {
8586
bytes[] acknowledgements;
8687
}
8788

89+
#[derive(Debug)]
8890
struct FungibleAssetOrderAck {
8991
uint256 fill_type;
9092
bytes market_maker;
@@ -100,10 +102,10 @@ impl From<FungibleAssetOrderV0> for FungibleAssetOrder {
100102
base_amount: value.base_amount,
101103
base_token_symbol: value.base_token_symbol,
102104
base_token_name: value.base_token_name,
105+
base_token_decimals: 0,
103106
base_token_path: value.base_token_path,
104107
quote_token: value.quote_token,
105108
quote_amount: value.quote_amount,
106-
decimals: 0,
107109
}
108110
}
109111
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ fn execute_fungible_asset_order(
791791
metadata: Metadata {
792792
name: order.base_token_name,
793793
symbol: order.base_token_symbol,
794-
decimals: order.decimals,
794+
decimals: order.base_token_decimals,
795795
},
796796
path: path.to_be_bytes_vec().into(),
797797
channel: packet.destination_channel_id,
@@ -1084,7 +1084,7 @@ fn transfer(
10841084
let MetadataResponse {
10851085
name: base_token_name,
10861086
symbol: base_token_symbol,
1087-
decimals,
1087+
decimals: base_token_decimals,
10881088
} = deps.querier.query::<MetadataResponse>(&QueryRequest::Wasm(
10891089
cosmwasm_std::WasmQuery::Smart {
10901090
contract_addr: minter.to_string(),
@@ -1113,14 +1113,14 @@ fn transfer(
11131113
base_amount: base_amount.u128().try_into().expect("u256>u128"),
11141114
base_token_symbol,
11151115
base_token_name,
1116+
base_token_decimals,
11161117
base_token_path: origin
11171118
.map(|x| alloy::primitives::U256::from_be_bytes(x.to_be_bytes()))
11181119
.unwrap_or(alloy::primitives::U256::ZERO),
11191120
quote_token: Vec::from(quote_token).into(),
11201121
quote_amount: alloy::primitives::U256::from_be_bytes(
11211122
quote_amount.to_be_bytes(),
11221123
),
1123-
decimals,
11241124
}
11251125
.abi_encode_params()
11261126
.into(),

0 commit comments

Comments
 (0)