Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Commit

Permalink
[QUANT-950] Use Base 18 in Post Order Payload (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahabro authored Sep 7, 2023
1 parent 4031aef commit 3adfd48
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@firefly-exchange/bluefin-client-sui",
"version": "0.0.14",
"version": "0.0.15",
"description": "The Bluefin client Library allows traders to sign, create, retrieve and listen to orders on Bluefin Exchange.",
"main": "dist/index.js",
"scripts": {
Expand Down
18 changes: 9 additions & 9 deletions src/bluefinClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import { WebSockets } from "./exchange/WebSocket";
import { generateRandomNumber, readFile } from "../utils/utils";
import { ContractCalls } from "./exchange/contractService";
import { ResponseSchema } from "./exchange/contractErrorHandling.service";
import { Networks } from "./constants";
import { Networks, POST_ORDER_BASE } from "./constants";

// import { Contract } from "ethers";

Expand Down Expand Up @@ -441,7 +441,7 @@ export class BluefinClient {
orderType: order.orderType,
triggerPrice:
order.orderType === ORDER_TYPE.STOP_MARKET ||
order.orderType === ORDER_TYPE.LIMIT
order.orderType === ORDER_TYPE.LIMIT
? order.triggerPrice || 0
: 0,
postOnly: orderToSign.postOnly,
Expand Down Expand Up @@ -470,10 +470,10 @@ export class BluefinClient {
symbol: params.symbol,
userAddress: params.maker,
orderType: params.orderType,
price: toBigNumberStr(params.price),
triggerPrice: toBigNumberStr(params.triggerPrice || "0"),
quantity: toBigNumberStr(params.quantity),
leverage: toBigNumberStr(params.leverage),
price: toBigNumberStr(params.price, POST_ORDER_BASE),
triggerPrice: toBigNumberStr(params.triggerPrice || "0", POST_ORDER_BASE),
quantity: toBigNumberStr(params.quantity, POST_ORDER_BASE),
leverage: toBigNumberStr(params.leverage, POST_ORDER_BASE),
side: params.side,
reduceOnly: params.reduceOnly,
salt: params.salt,
Expand Down Expand Up @@ -519,7 +519,7 @@ export class BluefinClient {
*/
createOrderCancellationSignature = async (
params: OrderCancelSignatureRequest
): Promise<SigPK> => {
): Promise<string> => {
// TODO: serialize correctly, this is the default method from suiet wallet docs
// const serialized = new TextEncoder().encode(JSON.stringify(params));
// return this.signer.signData(serialized);
Expand All @@ -535,7 +535,7 @@ export class BluefinClient {
orderHashes: params.hashes,
});
}
return signature;
return `${signature?.signature}${signature?.publicKey}`;
} catch {
throw Error("Siging cancelled by user");
}
Expand Down Expand Up @@ -574,7 +574,7 @@ export class BluefinClient {
const signature = await this.createOrderCancellationSignature(params);
const response = await this.placeCancelOrder({
...params,
signature: `${signature?.signature}${signature?.publicKey}`,
signature: signature,
});
return response;
};
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ export const DEFAULT_PRECISION = 6;
export const SUI_NETWROK = "sui";

export const EXTRA_FEES = 10000;

export const POST_ORDER_BASE = 18;
4 changes: 2 additions & 2 deletions tests/bluefinClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe("BluefinClient", () => {
const cancellationResponse = await clientSubAccount.placeCancelOrder({
symbol,
hashes: [response.response.data.hash],
signature: `${cancelSignature.signature}${cancelSignature.publicKey}`,
signature: cancelSignature,
parentAddress: testAcctPubAddr.toLowerCase(),
});

Expand Down Expand Up @@ -513,7 +513,7 @@ describe("BluefinClient", () => {
const cancellationResponse = await client.placeCancelOrder({
symbol,
hashes: [response.response.data.hash],
signature: `${cancelSignature.signature}${cancelSignature.publicKey}`,
signature: cancelSignature,
});

expect(cancellationResponse.ok).to.be.equal(true);
Expand Down

0 comments on commit 3adfd48

Please sign in to comment.