diff --git a/CHANGELOG.md b/CHANGELOG.md index 844f6964..95f0660d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,3 +18,8 @@ Unreleased - Add Rust and Golang unit tests, add wasm tests - Add example code in folder `examples` - Add Makefile to build the bindings and lint the code. +- Add `l2_hash` field in `Deposit`. Replace the original `eth_hash` semantics. + +### Changed +- Changed the `eth_hash` field to `Option` in `Deposit`. +- Renamed the `eth_hash` field to `l2_hash` in `Fullexit`. \ No newline at end of file diff --git a/binding_tests/interface_test.go b/binding_tests/interface_test.go index ccf83a94..d762b928 100644 --- a/binding_tests/interface_test.go +++ b/binding_tests/interface_test.go @@ -188,7 +188,7 @@ func TestSignOrderMatching(t *testing.T) { func TestDeposit(t *testing.T) { fromAddress := sdk.ZkLinkAddress("0xAFAFf3aD1a0425D792432D9eCD1c3e26Ef2C42E9") toAddress := sdk.ZkLinkAddress("0xAFAFf3aD1a0425D792432D9eCD1c3e26Ef2C42E9") - ethHash := "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + l2Hash := "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" builder := sdk.DepositBuilder { fromAddress, toAddress, @@ -198,7 +198,8 @@ func TestDeposit(t *testing.T) { sdk.TokenId(4), *big.NewInt(100), 100, - ethHash, + l2Hash, + nil, } tx := sdk.NewDeposit(builder) assert.NotNil(t, tx) diff --git a/binding_tests/types_test.go b/binding_tests/types_test.go index 7bbca892..8d5a2f1d 100644 --- a/binding_tests/types_test.go +++ b/binding_tests/types_test.go @@ -16,7 +16,7 @@ func TestTypeDeposit(t *testing.T) { l1_source_token := sdk.TokenId(2) amount := *big.NewInt(123) serial_id := uint64(123) - eth_hash := "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + l2_hash := "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" builder := sdk.DepositBuilder{ from_address, to_address, @@ -26,7 +26,8 @@ func TestTypeDeposit(t *testing.T) { l1_source_token, amount, serial_id, - eth_hash, + l2_hash, + nil, } deposit := sdk.NewDeposit(builder); bytes := deposit.GetBytes() diff --git a/bindings/sdk/src/ffi.udl b/bindings/sdk/src/ffi.udl index 03274e09..f335d538 100644 --- a/bindings/sdk/src/ffi.udl +++ b/bindings/sdk/src/ffi.udl @@ -111,7 +111,8 @@ dictionary DepositBuilder { TokenId l1_source_token; BigUint amount; u64 serial_id; - H256 eth_hash; + H256 l2_hash; + H256 ?eth_hash; }; @@ -154,7 +155,7 @@ dictionary FullExitBuilder { sequence contract_prices; sequence margin_prices; u64 serial_id; - H256 eth_hash; + H256 l2_hash; }; diff --git a/types/src/tx_builder.rs b/types/src/tx_builder.rs index 6738d848..0986a75f 100644 --- a/types/src/tx_builder.rs +++ b/types/src/tx_builder.rs @@ -90,7 +90,8 @@ pub struct DepositBuilder { pub l1_source_token: TokenId, pub amount: BigUint, pub serial_id: u64, - pub eth_hash: H256, + pub l2_hash: H256, + pub eth_hash: Option, } impl DepositBuilder { @@ -105,6 +106,7 @@ impl DepositBuilder { l1_source_token: self.l1_source_token, amount: self.amount, serial_id: self.serial_id, + l2_hash: self.l2_hash, eth_hash: self.eth_hash, } } @@ -192,7 +194,7 @@ pub struct FullExitBuilder { pub contract_prices: Vec, pub margin_prices: Vec, pub serial_id: u64, - pub eth_hash: H256, + pub l2_hash: H256, } impl FullExitBuilder { @@ -210,7 +212,7 @@ impl FullExitBuilder { margin_prices: self.margin_prices, }, serial_id: self.serial_id, - eth_hash: self.eth_hash, + l2_hash: self.l2_hash, } } } diff --git a/types/src/tx_type/deposit.rs b/types/src/tx_type/deposit.rs index d95fd667..ee196f87 100644 --- a/types/src/tx_type/deposit.rs +++ b/types/src/tx_type/deposit.rs @@ -35,7 +35,10 @@ pub struct Deposit { pub amount: BigUint, /// serial id for unique tx_hash pub serial_id: u64, - pub eth_hash: H256, + /// Transaction hash of linea/zksync/starket etc + pub l2_hash: H256, + /// Transaction hash of ethereum, exist when deposit going from Ethereum bridge to linea/zksync/starket etc + pub eth_hash: Option, } impl Deposit { @@ -50,7 +53,7 @@ impl GetBytes for Deposit { let bytes_len = self.bytes_len(); let mut out = Vec::with_capacity(bytes_len); out.extend_from_slice(&self.serial_id.to_be_bytes()); - out.extend_from_slice(self.eth_hash.as_bytes()); + out.extend_from_slice(self.l2_hash.as_bytes()); assert_eq!(out.len(), bytes_len); out } @@ -72,7 +75,7 @@ mod test { fn test_deposit_get_bytes() { let address = ZkLinkAddress::from_str("0xAFAFf3aD1a0425D792432D9eCD1c3e26Ef2C42E9").unwrap(); - let eth_hash = + let l2_hash = H256::from_str("0xe35f3a39d542f6d276c2f203e8fd64fcb8bf5db062b71ccacf45d5ecd9d456f3") .unwrap(); let builder = DepositBuilder { @@ -84,7 +87,8 @@ mod test { l1_source_token: TokenId(18), amount: BigUint::from(100u32), serial_id: 32001, - eth_hash, + eth_hash: None, + l2_hash, }; let deposit = builder.build(); let bytes = deposit.get_bytes(); diff --git a/types/src/tx_type/full_exit.rs b/types/src/tx_type/full_exit.rs index bbcc4087..28b06152 100644 --- a/types/src/tx_type/full_exit.rs +++ b/types/src/tx_type/full_exit.rs @@ -29,7 +29,8 @@ pub struct FullExit { #[validate] pub oracle_prices: OraclePrices, pub serial_id: u64, - pub eth_hash: H256, + /// Transaction hash of linea/zksync/starket etc + pub l2_hash: H256, } impl FullExit { @@ -44,7 +45,7 @@ impl GetBytes for FullExit { let bytes_len = self.bytes_len(); let mut out = Vec::with_capacity(bytes_len); out.extend(self.serial_id.to_be_bytes()); - out.extend_from_slice(self.eth_hash.as_bytes()); + out.extend_from_slice(self.l2_hash.as_bytes()); assert_eq!(out.len(), bytes_len); out } @@ -65,7 +66,7 @@ mod test { fn test_full_exit_get_bytes() { let address = ZkLinkAddress::from_str("0xAFAFf3aD1a0425D792432D9eCD1c3e26Ef2C42E9").unwrap(); - let eth_hash = + let l2_hash = H256::from_str("0xe35f3a39d542f6d276c2f203e8fd64fcb8bf5db062b71ccacf45d5ecd9d456f3") .unwrap(); let default_oracle_price = OraclePrices::default(); @@ -79,7 +80,7 @@ mod test { contract_prices: default_oracle_price.contract_prices, margin_prices: default_oracle_price.margin_prices, serial_id: 100, - eth_hash, + l2_hash, }; let full_exit = builder.build(); let bytes = full_exit.get_bytes();