-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix review suggests and add all txs example
- Loading branch information
Showing
23 changed files
with
514 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use std::str::FromStr; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use wasm_bindgen::JsValue; | ||
use zklink_sdk_types::basic_types::{BigUint, ZkLinkAddress}; | ||
use zklink_sdk_types::tx_builder::ForcedExitBuilder as TxForcedExitBuilder; | ||
use zklink_sdk_types::tx_type::forced_exit::ForcedExit as ForcedExitTx; | ||
|
||
#[wasm_bindgen] | ||
pub struct ForcedExit { | ||
inner: ForcedExitTx, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl ForcedExit { | ||
pub fn get_inner_tx(&self) -> Result<JsValue, JsValue> { | ||
Ok(serde_wasm_bindgen::to_value(&self.inner)?) | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub struct ForcedExitBuilder { | ||
inner: TxForcedExitBuilder, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl ForcedExitBuilder { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new( | ||
to_chain_id: u8, | ||
initiator_account_id: u32, | ||
initiator_sub_account_id: u8, | ||
target_sub_account_id: u8, | ||
target: String, | ||
l2_source_token: u32, | ||
l1_target_token: u32, | ||
exit_amount: String, | ||
initiator_nonce: u32, | ||
ts: u32, | ||
) -> Result<ForcedExitBuilder, JsValue> { | ||
let inner = TxForcedExitBuilder { | ||
to_chain_id: to_chain_id.into(), | ||
initiator_account_id: initiator_account_id.into(), | ||
initiator_sub_account_id: initiator_sub_account_id.into(), | ||
target: ZkLinkAddress::from_hex(&target)?, | ||
l2_source_token: l2_source_token.into(), | ||
timestamp: ts.into(), | ||
l1_target_token: l1_target_token.into(), | ||
initiator_nonce: initiator_nonce.into(), | ||
target_sub_account_id: target_sub_account_id.into(), | ||
exit_amount: BigUint::from_str(&exit_amount).unwrap(), | ||
}; | ||
Ok(ForcedExitBuilder { inner }) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn build(self) -> ForcedExit { | ||
ForcedExit { | ||
inner: ForcedExitTx::new(self.inner), | ||
} | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_name=newForcedExit)] | ||
pub fn new_forced_exit(builder: ForcedExitBuilder) -> ForcedExit { | ||
builder.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
pub mod change_pubkey; | ||
pub mod forced_exit; | ||
pub mod order_matching; | ||
pub mod transfer; | ||
pub mod withdraw; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use std::str::FromStr; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use wasm_bindgen::JsValue; | ||
use zklink_sdk_types::basic_types::BigUint; | ||
use zklink_sdk_types::tx_builder::OrderMatchingBuilder as TxOrderMatchingBuilder; | ||
use zklink_sdk_types::tx_type::order_matching::{ | ||
Order as OrderTx, OrderMatching as OrderMatchingTx, | ||
}; | ||
#[wasm_bindgen] | ||
pub struct Order { | ||
inner: OrderTx, | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub struct OrderMatching { | ||
inner: OrderMatchingTx, | ||
} | ||
#[wasm_bindgen] | ||
impl Order { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new( | ||
account_id: u32, | ||
sub_account_id: u8, | ||
slot_id: u32, | ||
nonce: u32, | ||
base_token_id: u32, | ||
quote_token_id: u32, | ||
amount: String, | ||
price: String, | ||
is_sell: bool, | ||
fee_ratio1: u8, | ||
fee_ratio2: u8, | ||
) -> Order { | ||
Order { | ||
inner: OrderTx { | ||
account_id: account_id.into(), | ||
sub_account_id: sub_account_id.into(), | ||
slot_id: slot_id.into(), | ||
nonce: nonce.into(), | ||
base_token_id: base_token_id.into(), | ||
quote_token_id: quote_token_id.into(), | ||
amount: BigUint::from_str(&amount).unwrap(), | ||
price: BigUint::from_str(&price).unwrap(), | ||
is_sell: is_sell as u8, | ||
fee_ratio1, | ||
fee_ratio2, | ||
signature: Default::default(), | ||
}, | ||
} | ||
} | ||
|
||
pub fn get_inner_order(&self) -> Result<JsValue, JsValue> { | ||
Ok(serde_wasm_bindgen::to_value(&self.inner)?) | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl OrderMatching { | ||
pub fn get_inner_tx(&self) -> Result<JsValue, JsValue> { | ||
Ok(serde_wasm_bindgen::to_value(&self.inner)?) | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub struct OrderMatchingBuilder { | ||
inner: TxOrderMatchingBuilder, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl OrderMatchingBuilder { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new( | ||
account_id: u32, | ||
sub_account_id: u8, | ||
taker: JsValue, | ||
maker: JsValue, | ||
fee: String, | ||
fee_token: u32, | ||
expect_base_amount: String, | ||
expect_quote_amount: String, | ||
) -> Result<OrderMatchingBuilder, JsValue> { | ||
let maker: OrderTx = serde_wasm_bindgen::from_value(maker)?; | ||
let taker: OrderTx = serde_wasm_bindgen::from_value(taker)?; | ||
let inner = TxOrderMatchingBuilder { | ||
account_id: account_id.into(), | ||
sub_account_id: sub_account_id.into(), | ||
taker, | ||
fee: BigUint::from_str(&fee).unwrap(), | ||
fee_token: fee_token.into(), | ||
expect_base_amount: BigUint::from_str(&expect_base_amount).unwrap(), | ||
maker, | ||
expect_quote_amount: BigUint::from_str(&expect_quote_amount).unwrap(), | ||
}; | ||
Ok(OrderMatchingBuilder { inner }) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn build(self) -> OrderMatching { | ||
OrderMatching { | ||
inner: OrderMatchingTx::new(self.inner), | ||
} | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_name=newOrderMatching)] | ||
pub fn new_order_matching(builder: OrderMatchingBuilder) -> OrderMatching { | ||
builder.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use std::str::FromStr; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use wasm_bindgen::JsValue; | ||
use zklink_sdk_types::basic_types::{BigUint, ZkLinkAddress}; | ||
use zklink_sdk_types::tx_builder::WithdrawBuilder as TxWithdrawBuilder; | ||
use zklink_sdk_types::tx_type::withdraw::Withdraw as WithdrawTx; | ||
|
||
#[wasm_bindgen] | ||
pub struct Withdraw { | ||
inner: WithdrawTx, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl Withdraw { | ||
pub fn get_inner_tx(&self) -> Result<JsValue, JsValue> { | ||
Ok(serde_wasm_bindgen::to_value(&self.inner)?) | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub struct WithdrawBuilder { | ||
inner: TxWithdrawBuilder, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl WithdrawBuilder { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new( | ||
account_id: u32, | ||
sub_account_id: u8, | ||
to_chain_id: u8, | ||
to_address: String, | ||
l2_source_token: u32, | ||
fee: String, | ||
fast_withdraw: bool, | ||
withdraw_fee_ratio: u16, | ||
l1_target_token: u32, | ||
amount: String, | ||
nonce: u32, | ||
ts: u32, | ||
) -> Result<WithdrawBuilder, JsValue> { | ||
let inner = TxWithdrawBuilder { | ||
account_id: account_id.into(), | ||
sub_account_id: sub_account_id.into(), | ||
to_chain_id: to_chain_id.into(), | ||
to_address: ZkLinkAddress::from_hex(&to_address)?, | ||
l2_source_token: l2_source_token.into(), | ||
fee: BigUint::from_str(&fee).unwrap(), | ||
nonce: nonce.into(), | ||
fast_withdraw, | ||
withdraw_fee_ratio, | ||
timestamp: ts.into(), | ||
amount: BigUint::from_str(&amount).unwrap(), | ||
l1_target_token: l1_target_token.into(), | ||
}; | ||
Ok(WithdrawBuilder { inner }) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn build(self) -> Withdraw { | ||
Withdraw { | ||
inner: WithdrawTx::new(self.inner), | ||
} | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_name=newWithdraw)] | ||
pub fn new_withdraw(builder: WithdrawBuilder) -> Withdraw { | ||
builder.build() | ||
} |
Oops, something went wrong.