Skip to content

Commit

Permalink
add some missing features(feat #58) (#59)
Browse files Browse the repository at this point in the history
* add BigIntSerdeWrapper and BigIntSerdeAsRadix10Str

* add some response structs

* refactor verify_signature function

* fix: format and clippy

* refactor: add internal_signature function and reuse it

* refactor: move contract module to tx_type module

* refactor: rename fee_ratio to fee_rate

* refactor: ZkSignatureTrait trait function signature

* test: fix go test
  • Loading branch information
RequiemOfSoul authored and nick-zkp committed Nov 10, 2023
1 parent bbfe83a commit cd2bd7b
Show file tree
Hide file tree
Showing 23 changed files with 329 additions and 176 deletions.
12 changes: 6 additions & 6 deletions binding_tests/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func TestSignOrderMatching(t *testing.T) {
)
taker, err = taker.CreateSignedOrder(zklink_signer)
assert.Nil(t, err)
assert.NotNil(t, taker.Signature())
fmt.Printf("taker signature:%v\n", taker.Signature())
assert.NotNil(t, taker.GetSignature())
fmt.Printf("taker signature:%v\n", taker.GetSignature())

maker := sdk.NewOrder(
sdk.AccountId(2),
Expand All @@ -164,8 +164,8 @@ func TestSignOrderMatching(t *testing.T) {
)
maker, err = maker.CreateSignedOrder(zklink_signer)
assert.Nil(t, err)
assert.NotNil(t, maker.Signature())
fmt.Printf("maker signature:%v\n", maker.Signature())
assert.NotNil(t, maker.GetSignature())
fmt.Printf("maker signature:%v\n", maker.GetSignature())

builder := sdk.OrderMatchingBuilder{
sdk.AccountId(3),
Expand Down Expand Up @@ -320,8 +320,8 @@ func TestContractMatching(t *testing.T) {
Size: *big.NewInt(100),
Price: *big.NewInt(100),
Direction: false,
MakerFeeRatio: 10,
TakerFeeRatio: 20,
MakerFeeRate: 10,
TakerFeeRate: 20,
HasSubsidy: false,
}
taker := sdk.NewContract(contract_builder)
Expand Down
30 changes: 15 additions & 15 deletions bindings/sdk/src/ffi.udl
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ dictionary ContractBuilder {
BigUint size;
BigUint price;
boolean direction;
u8 taker_fee_ratio;
u8 maker_fee_ratio;
u8 taker_fee_rate;
u8 maker_fee_rate;
boolean has_subsidy;
};

Expand Down Expand Up @@ -253,7 +253,7 @@ interface Deposit {

interface Withdraw {
constructor(WithdrawBuilder builder);
ZkLinkSignature signature();
ZkLinkSignature get_signature();
sequence<u8> get_bytes();
sequence<u8> tx_hash();
string json_str();
Expand All @@ -271,7 +271,7 @@ interface Withdraw {

interface ChangePubKey {
constructor(ChangePubKeyBuilder builder);
ZkLinkSignature signature();
ZkLinkSignature get_signature();
sequence<u8> get_bytes();
sequence<u8> tx_hash();
string json_str();
Expand All @@ -285,7 +285,7 @@ interface ChangePubKey {

interface ForcedExit {
constructor(ForcedExitBuilder builder);
ZkLinkSignature signature();
ZkLinkSignature get_signature();
sequence<u8> get_bytes();
sequence<u8> tx_hash();
string json_str();
Expand All @@ -310,7 +310,7 @@ interface FullExit {

interface Transfer {
constructor(TransferBuilder builder);
ZkLinkSignature signature();
ZkLinkSignature get_signature();
sequence<u8> get_bytes();
sequence<u8> tx_hash();
string json_str();
Expand Down Expand Up @@ -339,11 +339,11 @@ interface Order {
BigUint price,
boolean is_sell,
boolean has_subsidy,
u8 fee_ratio1,
u8 fee_ratio2,
u8 fee_rate1,
u8 fee_rate2,
ZkLinkSignature ?signature
);
ZkLinkSignature signature();
ZkLinkSignature get_signature();
sequence<u8> get_bytes();
string json_str();
boolean is_valid();
Expand All @@ -359,7 +359,7 @@ interface OrderMatching {
sequence<u8> tx_hash();
string json_str();
boolean is_valid();
ZkLinkSignature signature();
ZkLinkSignature get_signature();
boolean is_signature_valid();
[Throws=ZkSignerError]
OrderMatching create_signed_tx(ZkLinkSigner signer);
Expand All @@ -370,7 +370,7 @@ interface Contract {
constructor(ContractBuilder builder);
boolean is_long();
boolean is_short();
ZkLinkSignature signature();
ZkLinkSignature get_signature();
boolean is_signature_valid();
sequence<u8> get_bytes();
};
Expand All @@ -391,7 +391,7 @@ interface AutoDeleveraging {
sequence<u8> tx_hash();
string json_str();
boolean is_valid();
ZkLinkSignature signature();
ZkLinkSignature get_signature();
boolean is_signature_valid();
ZkLinkTx to_zklink_tx();
[Throws=ZkSignerError]
Expand All @@ -404,7 +404,7 @@ interface ContractMatching {
sequence<u8> tx_hash();
string json_str();
boolean is_valid();
ZkLinkSignature signature();
ZkLinkSignature get_signature();
boolean is_signature_valid();
ZkLinkTx to_zklink_tx();
[Throws=ZkSignerError]
Expand All @@ -417,7 +417,7 @@ interface Funding {
sequence<u8> tx_hash();
string json_str();
boolean is_valid();
ZkLinkSignature signature();
ZkLinkSignature get_signature();
boolean is_signature_valid();
ZkLinkTx to_zklink_tx();
[Throws=ZkSignerError]
Expand All @@ -430,7 +430,7 @@ interface Liquidation {
sequence<u8> tx_hash();
string json_str();
boolean is_valid();
ZkLinkSignature signature();
ZkLinkSignature get_signature();
boolean is_signature_valid();
ZkLinkTx to_zklink_tx();
[Throws=ZkSignerError]
Expand Down
6 changes: 3 additions & 3 deletions bindings/wasm/src/tx_types/order_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ impl Order {
amount: String,
price: String,
is_sell: bool,
maker_fee_ratio: u8,
taker_fee_ratio2: u8,
maker_fee_rate: u8,
taker_fee_rate: u8,
has_subsidy: bool,
) -> Order {
Order {
Expand All @@ -43,7 +43,7 @@ impl Order {
amount: BigUint::from_str(&amount).unwrap(),
price: BigUint::from_str(&price).unwrap(),
is_sell: is_sell as u8,
fee_rates: [maker_fee_ratio, taker_fee_ratio2],
fee_rates: [maker_fee_rate, taker_fee_rate],
has_subsidy: has_subsidy as u8,
signature: Default::default(),
},
Expand Down
Loading

0 comments on commit cd2bd7b

Please sign in to comment.