-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPerpMarket.ts
62 lines (48 loc) · 1.59 KB
/
PerpMarket.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
59
60
61
62
import { makeAutoObservable } from "mobx";
import { BN } from "@compolabs/spark-orderbook-ts-sdk";
import { FuelNetwork } from "@blockchain";
import { DEFAULT_DECIMALS } from "../constants";
import { Token } from "./Token";
interface PerpMarketParams {
baseTokenAddress: string;
quoteTokenAddress: string;
imRatio: BN;
mmRatio: BN;
status: "Opened" | "Paused" | "Closed";
pausedIndexPrice?: BN;
pausedTimestamp?: number;
closedPrice?: BN;
contractAddress: string;
}
export class PerpMarket {
readonly baseToken: Token;
readonly quoteToken: Token;
readonly contractAddress: string;
readonly imRatio: BN;
readonly mmRatio: BN;
readonly status: "Opened" | "Paused" | "Closed";
readonly pausedIndexPrice?: BN;
readonly pausedTimestamp?: number;
readonly closedPrice?: BN;
price: BN = BN.ZERO;
setPrice = (price: BN) => (this.price = price);
constructor(params: PerpMarketParams) {
const bcNetwork = FuelNetwork.getInstance();
this.baseToken = bcNetwork.getTokenByAssetId(params.baseTokenAddress);
this.quoteToken = bcNetwork.getTokenByAssetId(params.quoteTokenAddress);
this.imRatio = params.imRatio;
this.mmRatio = params.mmRatio;
this.status = params.status;
this.pausedIndexPrice = params.pausedIndexPrice;
this.pausedTimestamp = params.pausedTimestamp;
this.closedPrice = params.closedPrice;
this.contractAddress = params.contractAddress;
makeAutoObservable(this);
}
get symbol(): string {
return `${this.baseToken.symbol}-PERP`;
}
get priceUnits(): BN {
return BN.formatUnits(this.price, DEFAULT_DECIMALS);
}
}