-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPerpOrder.ts
58 lines (44 loc) · 1.45 KB
/
PerpOrder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { makeAutoObservable } from "mobx";
import { BN } from "@compolabs/spark-orderbook-ts-sdk";
import { DEFAULT_DECIMALS } from "@constants";
import { toCurrency } from "@utils/toCurrency";
import { FuelNetwork } from "@blockchain";
import { Token } from "./Token";
interface PerpOrderParams {
id: string;
baseSize: BN;
baseTokenAddress: string;
orderPrice: BN;
trader: string;
}
export class PerpOrder {
readonly baseToken: Token;
readonly id: string;
readonly baseSize: BN;
readonly orderPrice: BN;
readonly trader: string;
constructor(params: PerpOrderParams) {
const bcNetwork = FuelNetwork.getInstance();
this.baseToken = bcNetwork.getTokenByAssetId(params.baseTokenAddress);
this.id = params.id;
this.baseSize = params.baseSize;
this.orderPrice = params.orderPrice;
this.trader = params.trader;
makeAutoObservable(this);
}
get symbol(): string {
return `${this.baseToken.symbol}-PERP`;
}
get baseSizeFormatted(): string {
return BN.formatUnits(this.baseSize, this.baseToken.decimals).toSignificant(2);
}
get baseSizeValueFormatted(): string {
const valueInUsd = BN.formatUnits(this.baseSize, this.baseToken.decimals).multipliedBy(
BN.formatUnits(this.orderPrice, DEFAULT_DECIMALS),
);
return toCurrency(valueInUsd.toSignificant(2));
}
get orderPriceFormatted(): string {
return toCurrency(BN.formatUnits(this.orderPrice, DEFAULT_DECIMALS).toSignificant(2));
}
}