@d8x/perpetuals-sdk 0.1.13 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/cjs/abi/testnet/IPerpetualManager.json +414 -224
  2. package/dist/cjs/abi/testnet/LimitOrderBook.json +200 -18
  3. package/dist/cjs/abi/zkevmTestnet/IPerpetualManager.json +5215 -0
  4. package/dist/cjs/abi/zkevmTestnet/LimitOrderBook.json +1075 -0
  5. package/dist/cjs/abi/zkevmTestnet/LimitOrderBookFactory.json +135 -0
  6. package/dist/cjs/config/defaultConfig.json +7 -7
  7. package/dist/cjs/nodeSDKTypes.d.ts +4 -4
  8. package/dist/cjs/nodeSDKTypes.js.map +1 -1
  9. package/dist/cjs/orderReferrerTool.d.ts +12 -5
  10. package/dist/cjs/orderReferrerTool.js +96 -22
  11. package/dist/cjs/orderReferrerTool.js.map +1 -1
  12. package/dist/cjs/perpetualDataHandler.d.ts +1 -1
  13. package/dist/cjs/perpetualDataHandler.js +17 -13
  14. package/dist/cjs/perpetualDataHandler.js.map +1 -1
  15. package/dist/cjs/version.d.ts +1 -1
  16. package/dist/cjs/version.js +1 -1
  17. package/dist/cjs/version.js.map +1 -1
  18. package/dist/cjs/writeAccessHandler.js +1 -1
  19. package/dist/cjs/writeAccessHandler.js.map +1 -1
  20. package/dist/esm/abi/testnet/IPerpetualManager.json +414 -224
  21. package/dist/esm/abi/testnet/LimitOrderBook.json +200 -18
  22. package/dist/esm/abi/zkevmTestnet/IPerpetualManager.json +5215 -0
  23. package/dist/esm/abi/zkevmTestnet/LimitOrderBook.json +1075 -0
  24. package/dist/esm/abi/zkevmTestnet/LimitOrderBookFactory.json +135 -0
  25. package/dist/esm/config/defaultConfig.json +7 -7
  26. package/dist/esm/nodeSDKTypes.d.ts +4 -4
  27. package/dist/esm/nodeSDKTypes.js.map +1 -1
  28. package/dist/esm/orderReferrerTool.d.ts +12 -5
  29. package/dist/esm/orderReferrerTool.js +97 -23
  30. package/dist/esm/orderReferrerTool.js.map +1 -1
  31. package/dist/esm/perpetualDataHandler.d.ts +1 -1
  32. package/dist/esm/perpetualDataHandler.js +17 -13
  33. package/dist/esm/perpetualDataHandler.js.map +1 -1
  34. package/dist/esm/version.d.ts +1 -1
  35. package/dist/esm/version.js +1 -1
  36. package/dist/esm/version.js.map +1 -1
  37. package/dist/esm/writeAccessHandler.js +1 -1
  38. package/dist/esm/writeAccessHandler.js.map +1 -1
  39. package/package.json +1 -2
@@ -0,0 +1,135 @@
1
+ [
2
+ {
3
+ "anonymous": false,
4
+ "inputs": [
5
+ {
6
+ "indexed": true,
7
+ "internalType": "address",
8
+ "name": "previousOwner",
9
+ "type": "address"
10
+ },
11
+ {
12
+ "indexed": true,
13
+ "internalType": "address",
14
+ "name": "newOwner",
15
+ "type": "address"
16
+ }
17
+ ],
18
+ "name": "OwnershipTransferred",
19
+ "type": "event"
20
+ },
21
+ {
22
+ "anonymous": false,
23
+ "inputs": [
24
+ {
25
+ "indexed": true,
26
+ "internalType": "uint24",
27
+ "name": "perpetualId",
28
+ "type": "uint24"
29
+ },
30
+ {
31
+ "indexed": false,
32
+ "internalType": "address",
33
+ "name": "perpManagerAddress",
34
+ "type": "address"
35
+ },
36
+ {
37
+ "indexed": false,
38
+ "internalType": "address",
39
+ "name": "limitOrderBookAddress",
40
+ "type": "address"
41
+ }
42
+ ],
43
+ "name": "PerpetualLimitOrderBookDeployed",
44
+ "type": "event"
45
+ },
46
+ {
47
+ "inputs": [
48
+ {
49
+ "internalType": "address",
50
+ "name": "_perpetualManagerAddr",
51
+ "type": "address"
52
+ },
53
+ {
54
+ "internalType": "uint24",
55
+ "name": "_perpetualId",
56
+ "type": "uint24"
57
+ }
58
+ ],
59
+ "name": "deployLimitOrderBookProxy",
60
+ "outputs": [],
61
+ "stateMutability": "nonpayable",
62
+ "type": "function"
63
+ },
64
+ {
65
+ "inputs": [
66
+ {
67
+ "internalType": "uint24",
68
+ "name": "_perpetualId",
69
+ "type": "uint24"
70
+ }
71
+ ],
72
+ "name": "getOrderBookAddress",
73
+ "outputs": [
74
+ {
75
+ "internalType": "address",
76
+ "name": "",
77
+ "type": "address"
78
+ }
79
+ ],
80
+ "stateMutability": "view",
81
+ "type": "function"
82
+ },
83
+ {
84
+ "inputs": [
85
+ {
86
+ "internalType": "uint24",
87
+ "name": "",
88
+ "type": "uint24"
89
+ }
90
+ ],
91
+ "name": "orderBooks",
92
+ "outputs": [
93
+ {
94
+ "internalType": "address",
95
+ "name": "",
96
+ "type": "address"
97
+ }
98
+ ],
99
+ "stateMutability": "view",
100
+ "type": "function"
101
+ },
102
+ {
103
+ "inputs": [],
104
+ "name": "owner",
105
+ "outputs": [
106
+ {
107
+ "internalType": "address",
108
+ "name": "",
109
+ "type": "address"
110
+ }
111
+ ],
112
+ "stateMutability": "view",
113
+ "type": "function"
114
+ },
115
+ {
116
+ "inputs": [],
117
+ "name": "renounceOwnership",
118
+ "outputs": [],
119
+ "stateMutability": "nonpayable",
120
+ "type": "function"
121
+ },
122
+ {
123
+ "inputs": [
124
+ {
125
+ "internalType": "address",
126
+ "name": "newOwner",
127
+ "type": "address"
128
+ }
129
+ ],
130
+ "name": "transferOwnership",
131
+ "outputs": [],
132
+ "stateMutability": "nonpayable",
133
+ "type": "function"
134
+ }
135
+ ]
@@ -2,8 +2,8 @@
2
2
  {
3
3
  "name": "testnet",
4
4
  "chainId": 80001,
5
- "version": 1.5,
6
- "proxyAddr": "0xaB6AD25eE5CA28E7d7b16A33A33897aE34BF9e67",
5
+ "version": 6,
6
+ "proxyAddr": "0xDEDf0dd46757cE93E0D9439F78382c0c68cF76C2",
7
7
  "nodeURL": "https://polygon-mumbai.blockpi.network/v1/rpc/public",
8
8
  "priceFeedConfigNetwork": "testnet",
9
9
  "proxyABILocation": "testnet/IPerpetualManager.json",
@@ -34,14 +34,14 @@
34
34
  "limitOrderBookABILocation": "central-park/LimitOrderBook.json"
35
35
  },
36
36
  {
37
- "name": "Polygon zkEVM Testnet",
37
+ "name": "zkevmTestnet",
38
38
  "chainId": 1442,
39
39
  "version": 0,
40
- "proxyAddr": "",
40
+ "proxyAddr": "0xb56b81e40e1cDB77bb5Db6C0283e25C27DAE1Be6",
41
41
  "nodeURL": "https://rpc.public.zkevm-test.net ",
42
42
  "priceFeedConfigNetwork": "testnet",
43
- "proxyABILocation": "",
44
- "limitOrderBookFactoryABILocation": "",
45
- "limitOrderBookABILocation": ""
43
+ "proxyABILocation": "zkevmTestnet/IPerpetualManager.json",
44
+ "limitOrderBookFactoryABILocation": "zkevmTestnet/LimitOrderBookFactory.json",
45
+ "limitOrderBookABILocation": "zkevmTestnet/LimitOrderBook.json"
46
46
  }
47
47
  ]
@@ -153,7 +153,7 @@ export interface Order {
153
153
  leverage?: number | undefined;
154
154
  deadline?: number | undefined;
155
155
  timestamp: number;
156
- submittedBlock?: number;
156
+ submittedTimestamp?: number;
157
157
  parentChildOrderIds?: [string, string];
158
158
  }
159
159
  export interface TradeEvent {
@@ -178,7 +178,7 @@ export interface TradeEvent {
178
178
  int128 fLeverage; // 0 if deposit and trade separate
179
179
  uint64 iDeadline;
180
180
  uint64 createdTimestamp;
181
- uint64 submittedBlock;
181
+ uint64 submittedTimestamp;
182
182
  }
183
183
  */
184
184
  export interface SmartContractOrder {
@@ -195,7 +195,7 @@ export interface SmartContractOrder {
195
195
  fLeverage: BigNumberish;
196
196
  iDeadline: BigNumberish;
197
197
  createdTimestamp: BigNumberish;
198
- submittedBlock: BigNumberish;
198
+ submittedTimestamp: BigNumberish;
199
199
  }
200
200
  /**
201
201
  * struct ClientOrder {
@@ -212,7 +212,7 @@ export interface SmartContractOrder {
212
212
  int128 fLeverage; // 0 if deposit and trade separate
213
213
  uint64 iDeadline;
214
214
  uint64 createdTimestamp;
215
- //uint64 submittedBlock <- will be set by LimitOrderBook
215
+ //uint64 submittedTimestamp <- will be set by LimitOrderBook
216
216
  bytes32 parentChildDigest1;
217
217
  bytes32 parentChildDigest2;
218
218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,gCAAgC,CAAE,CAAC,CAAC;QACnF,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,gBAAS,MAAM,CAAC,yBAAyB,CAAE,CAAC,CAAC;KACtE;AACH,CAAC;AAND,4BAMC;AAED,IAAI,WAAW,GAAG,OAAO,CAAC,6BAA6B,CAAoB,CAAC;;IAC5E,KAAmB,IAAA,gBAAA,iBAAA,WAAW,CAAA,wCAAA,iEAAE;QAA3B,IAAI,MAAM,wBAAA;QACb,QAAQ,CAAC,MAAM,CAAC,CAAC;KAClB;;;;;;;;;AAEY,QAAA,cAAc,GAAoB,WAAW,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { ethers } from "ethers";
2
- import { NodeSDKConfig, Order, PerpetualStaticInfo, PriceFeedSubmission } from "./nodeSDKTypes";
2
+ import { NodeSDKConfig, Order, PerpetualStaticInfo, PriceFeedSubmission, SmartContractOrder } from "./nodeSDKTypes";
3
3
  import WriteAccessHandler from "./writeAccessHandler";
4
4
  /**
5
5
  * Functions to execute existing conditional orders from the limit order book. This class
@@ -8,7 +8,7 @@ import WriteAccessHandler from "./writeAccessHandler";
8
8
  * @extends WriteAccessHandler
9
9
  */
10
10
  export default class OrderReferrerTool extends WriteAccessHandler {
11
- static BLOCK_DELAY: number;
11
+ static TRADE_DELAY: number;
12
12
  /**
13
13
  * Constructor.
14
14
  * @param {NodeSDKConfig} config Configuration object, see PerpetualDataHandler.readSDKConfig.
@@ -64,6 +64,7 @@ export default class OrderReferrerTool extends WriteAccessHandler {
64
64
  * @returns Transaction object.
65
65
  */
66
66
  executeOrder(symbol: string, orderId: string, referrerAddr?: string, nonce?: number, submission?: PriceFeedSubmission): Promise<ethers.ContractTransaction>;
67
+ executeOrders(symbol: string, orderIds: string[], referrerAddr?: string, nonce?: number, submission?: PriceFeedSubmission): Promise<ethers.ContractTransaction>;
67
68
  /**
68
69
  * All the orders in the order book for a given symbol that are currently open.
69
70
  * @param {string} symbol Symbol of the form ETH-USD-MATIC.
@@ -175,7 +176,7 @@ export default class OrderReferrerTool extends WriteAccessHandler {
175
176
  * main();
176
177
  * @returns true if order can be executed for the current state of the perpetuals
177
178
  */
178
- isTradeable(order: Order, indexPrices?: [number, number]): Promise<boolean>;
179
+ isTradeable(order: Order, blockTimestamp?: number, indexPrices?: [number, number]): Promise<boolean>;
179
180
  /**
180
181
  * Check for a batch of orders on the same perpetual whether they can be traded
181
182
  * @param orders orders belonging to 1 perpetual
@@ -183,7 +184,13 @@ export default class OrderReferrerTool extends WriteAccessHandler {
183
184
  * if not defined.
184
185
  * @returns array of tradeable boolean
185
186
  */
186
- isTradeableBatch(orders: Order[], indexPrices?: [number, number, boolean, boolean]): Promise<boolean[]>;
187
- static _isTradeable(order: Order, tradePrice: number, markPrice: number, block: number, symbolToPerpInfoMap: Map<string, PerpetualStaticInfo>): boolean;
187
+ isTradeableBatch(orders: Order[], blockTimestamp?: number, indexPrices?: [number, number, boolean, boolean]): Promise<boolean[]>;
188
+ protected _isTradeable(order: Order, tradePrice: number, markPrice: number, blockTimestamp: number, symbolToPerpInfoMap: Map<string, PerpetualStaticInfo>): boolean;
189
+ /**
190
+ * Wrapper of static method to use after mappings have been loaded into memory.
191
+ * @param scOrder Perpetual order as received in the proxy events.
192
+ * @returns A user-friendly order struct.
193
+ */
194
+ smartContractOrderToOrder(scOrder: SmartContractOrder): Order;
188
195
  getTransactionCount(blockTag?: ethers.providers.BlockTag): Promise<number>;
189
196
  }
@@ -33,7 +33,10 @@ var OrderReferrerTool = /** @class */ (function (_super) {
33
33
  * @param {string} privateKey Private key of the wallet that executes the conditional orders.
34
34
  */
35
35
  function OrderReferrerTool(config, privateKey) {
36
- return _super.call(this, config, privateKey) || this;
36
+ var _this = _super.call(this, config, privateKey) || this;
37
+ // override parent's gas limit with a lower number
38
+ _this.gasLimit = 3000000;
39
+ return _this;
37
40
  }
38
41
  /**
39
42
  * Executes an order by symbol and ID. This action interacts with the blockchain and incurs gas costs.
@@ -99,6 +102,36 @@ var OrderReferrerTool = /** @class */ (function (_super) {
99
102
  });
100
103
  });
101
104
  };
105
+ OrderReferrerTool.prototype.executeOrders = function (symbol, orderIds, referrerAddr, nonce, submission) {
106
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
107
+ var orderBookSC, options;
108
+ return tslib_1.__generator(this, function (_a) {
109
+ switch (_a.label) {
110
+ case 0:
111
+ if (this.proxyContract == null || this.signer == null) {
112
+ throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
113
+ }
114
+ orderBookSC = this.getOrderBookContract(symbol);
115
+ if (typeof referrerAddr == "undefined") {
116
+ referrerAddr = this.traderAddr;
117
+ }
118
+ if (!(submission == undefined)) return [3 /*break*/, 2];
119
+ return [4 /*yield*/, this.priceFeedGetter.fetchLatestFeedPriceInfoForPerpetual(symbol)];
120
+ case 1:
121
+ submission = _a.sent();
122
+ _a.label = 2;
123
+ case 2:
124
+ options = {
125
+ gasLimit: this.gasLimit,
126
+ nonce: nonce,
127
+ value: this.PRICE_UPDATE_FEE_GWEI * (submission === null || submission === void 0 ? void 0 : submission.priceFeedVaas.length),
128
+ };
129
+ return [4 /*yield*/, orderBookSC.executeOrders(orderIds, referrerAddr, submission === null || submission === void 0 ? void 0 : submission.priceFeedVaas, submission === null || submission === void 0 ? void 0 : submission.timestamps, options)];
130
+ case 3: return [2 /*return*/, _a.sent()];
131
+ }
132
+ });
133
+ });
134
+ };
102
135
  /**
103
136
  * All the orders in the order book for a given symbol that are currently open.
104
137
  * @param {string} symbol Symbol of the form ETH-USD-MATIC.
@@ -288,9 +321,9 @@ var OrderReferrerTool = /** @class */ (function (_super) {
288
321
  * main();
289
322
  * @returns true if order can be executed for the current state of the perpetuals
290
323
  */
291
- OrderReferrerTool.prototype.isTradeable = function (order, indexPrices) {
324
+ OrderReferrerTool.prototype.isTradeable = function (order, blockTimestamp, indexPrices) {
292
325
  return tslib_1.__awaiter(this, void 0, void 0, function () {
293
- var obj, orderPrice, markPrice, block;
326
+ var obj, orderPrice, markPrice, currentBlock;
294
327
  return tslib_1.__generator(this, function (_a) {
295
328
  switch (_a.label) {
296
329
  case 0:
@@ -309,10 +342,16 @@ var OrderReferrerTool = /** @class */ (function (_super) {
309
342
  return [4 /*yield*/, perpetualDataHandler_1.default._queryPerpetualMarkPrice(order.symbol, this.symbolToPerpStaticInfo, this.proxyContract, indexPrices)];
310
343
  case 4:
311
344
  markPrice = _a.sent();
345
+ if (!(blockTimestamp == undefined)) return [3 /*break*/, 7];
312
346
  return [4 /*yield*/, this.provider.getBlockNumber()];
313
347
  case 5:
314
- block = _a.sent();
315
- return [2 /*return*/, OrderReferrerTool._isTradeable(order, orderPrice, markPrice, block, this.symbolToPerpStaticInfo)];
348
+ currentBlock = _a.sent();
349
+ return [4 /*yield*/, this.provider.getBlock(currentBlock)];
350
+ case 6:
351
+ blockTimestamp = (_a.sent()).timestamp;
352
+ _a.label = 7;
353
+ case 7: return [4 /*yield*/, this._isTradeable(order, orderPrice, markPrice, blockTimestamp, this.symbolToPerpStaticInfo)];
354
+ case 8: return [2 /*return*/, _a.sent()];
316
355
  }
317
356
  });
318
357
  });
@@ -324,9 +363,9 @@ var OrderReferrerTool = /** @class */ (function (_super) {
324
363
  * if not defined.
325
364
  * @returns array of tradeable boolean
326
365
  */
327
- OrderReferrerTool.prototype.isTradeableBatch = function (orders, indexPrices) {
366
+ OrderReferrerTool.prototype.isTradeableBatch = function (orders, blockTimestamp, indexPrices) {
328
367
  return tslib_1.__awaiter(this, void 0, void 0, function () {
329
- var obj, orderPrice, markPrice, block;
368
+ var obj, orderPrice, markPrice, currentBlock;
330
369
  var _this = this;
331
370
  return tslib_1.__generator(this, function (_a) {
332
371
  switch (_a.label) {
@@ -359,48 +398,83 @@ var OrderReferrerTool = /** @class */ (function (_super) {
359
398
  return [4 /*yield*/, perpetualDataHandler_1.default._queryPerpetualMarkPrice(orders[0].symbol, this.symbolToPerpStaticInfo, this.proxyContract, [indexPrices[0], indexPrices[1]])];
360
399
  case 4:
361
400
  markPrice = _a.sent();
401
+ if (!(blockTimestamp == undefined)) return [3 /*break*/, 7];
362
402
  return [4 /*yield*/, this.provider.getBlockNumber()];
363
403
  case 5:
364
- block = _a.sent();
365
- return [2 /*return*/, orders.map(function (o, idx) {
366
- return OrderReferrerTool._isTradeable(o, orderPrice[idx], markPrice, block, _this.symbolToPerpStaticInfo);
367
- })];
404
+ currentBlock = _a.sent();
405
+ return [4 /*yield*/, this.provider.getBlock(currentBlock)];
406
+ case 6:
407
+ blockTimestamp = (_a.sent()).timestamp;
408
+ _a.label = 7;
409
+ case 7: return [4 /*yield*/, orders.map(function (o, idx) {
410
+ return _this._isTradeable(o, orderPrice[idx], markPrice, blockTimestamp, _this.symbolToPerpStaticInfo);
411
+ })];
412
+ case 8: return [2 /*return*/, _a.sent()];
368
413
  }
369
414
  });
370
415
  });
371
416
  };
372
- OrderReferrerTool._isTradeable = function (order, tradePrice, markPrice, block, symbolToPerpInfoMap) {
417
+ OrderReferrerTool.prototype._isTradeable = function (order, tradePrice, markPrice, blockTimestamp, symbolToPerpInfoMap) {
373
418
  // check expiration date
374
419
  if (order.deadline != undefined && order.deadline < Date.now() / 1000) {
420
+ console.log("order expired");
375
421
  return false;
376
422
  }
377
- if (order.submittedBlock == undefined || order.submittedBlock + this.BLOCK_DELAY > block) {
423
+ // -1 because order is executed on the next block (+1)
424
+ if (order.submittedTimestamp != undefined &&
425
+ order.submittedTimestamp + OrderReferrerTool.TRADE_DELAY < blockTimestamp - 1) {
426
+ console.log("on hold for ".concat(blockTimestamp - 1 - order.submittedTimestamp - OrderReferrerTool.TRADE_DELAY, " seconds"));
378
427
  return false;
379
428
  }
380
429
  // check order size
381
- if (order.quantity < perpetualDataHandler_1.default._getLotSize(order.symbol, symbolToPerpInfoMap)) {
430
+ var lotSize = perpetualDataHandler_1.default._getLotSize(order.symbol, symbolToPerpInfoMap);
431
+ if (order.quantity < lotSize) {
432
+ // console.log(`order size too small: ${order.quantity} < ${lotSize}`);
382
433
  return false;
383
434
  }
384
435
  // check limit price: fromSmartContractOrder will set it to undefined when not tradeable
385
436
  if (order.limitPrice == undefined) {
437
+ // console.log("limit price undefined");
386
438
  return false;
387
439
  }
388
440
  var limitPrice = order.limitPrice;
389
441
  if ((order.side == nodeSDKTypes_1.BUY_SIDE && tradePrice > limitPrice) || (order.side == nodeSDKTypes_1.SELL_SIDE && tradePrice < limitPrice)) {
442
+ // console.log(`limit price not met: ${limitPrice} ${order.side} @ ${tradePrice}`);
390
443
  return false;
391
444
  }
392
- // do we need to check trigger/stop?
393
- if (order.stopPrice == undefined) {
394
- // nothing to check, order is tradeable
395
- return true;
396
- }
397
- if ((order.side == nodeSDKTypes_1.BUY_SIDE && markPrice < order.stopPrice) ||
398
- (order.side == nodeSDKTypes_1.SELL_SIDE && markPrice > order.stopPrice)) {
445
+ // check stop price
446
+ if (order.stopPrice != undefined &&
447
+ ((order.side == nodeSDKTypes_1.BUY_SIDE && markPrice < order.stopPrice) ||
448
+ (order.side == nodeSDKTypes_1.SELL_SIDE && markPrice > order.stopPrice))) {
449
+ // console.log("stop price not met");
399
450
  return false;
400
451
  }
452
+ //check dependency
453
+ if (order.parentChildOrderIds != undefined &&
454
+ order.parentChildOrderIds[0] == ethers_1.ethers.constants.HashZero &&
455
+ order.parentChildOrderIds[1] != ethers_1.ethers.constants.HashZero) {
456
+ // order has a parent
457
+ var orderBookContract = this.getOrderBookContract(order.symbol);
458
+ return orderBookContract.getOrderStatus(order.parentChildOrderIds[1]).then(function (status) {
459
+ if (status == 2 || status == 3) {
460
+ // console.log("parent not executed/cancelled");
461
+ // parent is open or unknown
462
+ return false;
463
+ }
464
+ return true;
465
+ });
466
+ }
401
467
  // all checks passed -> order is tradeable
402
468
  return true;
403
469
  };
470
+ /**
471
+ * Wrapper of static method to use after mappings have been loaded into memory.
472
+ * @param scOrder Perpetual order as received in the proxy events.
473
+ * @returns A user-friendly order struct.
474
+ */
475
+ OrderReferrerTool.prototype.smartContractOrderToOrder = function (scOrder) {
476
+ return perpetualDataHandler_1.default.fromSmartContractOrder(scOrder, this.symbolToPerpStaticInfo);
477
+ };
404
478
  OrderReferrerTool.prototype.getTransactionCount = function (blockTag) {
405
479
  return tslib_1.__awaiter(this, void 0, void 0, function () {
406
480
  return tslib_1.__generator(this, function (_a) {
@@ -415,7 +489,7 @@ var OrderReferrerTool = /** @class */ (function (_super) {
415
489
  });
416
490
  });
417
491
  };
418
- OrderReferrerTool.BLOCK_DELAY = 2;
492
+ OrderReferrerTool.TRADE_DELAY = 5;
419
493
  return OrderReferrerTool;
420
494
  }(writeAccessHandler_1.default));
421
495
  exports.default = OrderReferrerTool;
@@ -1 +1 @@
1
- {"version":3,"file":"orderReferrerTool.js","sourceRoot":"","sources":["../../src/orderReferrerTool.ts"],"names":[],"mappings":";;;AAAA,iCAA2C;AAC3C,+CAWwB;AACxB,wFAA0D;AAC1D,oFAAsD;AAEtD;;;;;GAKG;AACH;IAA+C,6CAAkB;IAE/D;;;;;;;;;;;;;;;;;;OAkBG;IACH,2BAAmB,MAAqB,EAAE,UAAkB;eAC1D,kBAAM,MAAM,EAAE,UAAU,CAAC;IAC3B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACU,wCAAY,GAAzB,UACE,MAAc,EACd,OAAe,EACf,YAAqB,EACrB,KAAc,EACd,UAAgC;;;;;;wBAEhC,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE;4BACrD,MAAM,KAAK,CAAC,qEAAqE,CAAC,CAAC;yBACpF;wBACK,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;wBACtD,IAAI,OAAO,YAAY,IAAI,WAAW,EAAE;4BACtC,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC;yBAChC;6BACG,CAAA,UAAU,IAAI,SAAS,CAAA,EAAvB,wBAAuB;wBACZ,qBAAM,IAAI,CAAC,eAAe,CAAC,oCAAoC,CAAC,MAAM,CAAC,EAA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hC,UAAiC,OAA2B;QAC1D,OAAO,8BAAoB,CAAC,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAC3F,CAAC;IAEY,+CAAmB,GAAhC,UAAiC,QAAoC;;;;;wBACnE,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE;4BACvB,MAAM,KAAK,CAAC,mDAAmD,CAAC,CAAC;yBAClE;wBACM,qBAAM,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAA;4BAAtD,sBAAO,SAA+C,EAAC;;;;KACxD;IA3bM,6BAAW,GAAG,CAAC,CAAC;IA4bzB,wBAAC;CAAA,AA7bD,CAA+C,4BAAkB,GA6bhE;kBA7boB,iBAAiB"}
@@ -216,5 +216,5 @@ export default class PerpetualDataHandler {
216
216
  * @param traderAccount Trader account
217
217
  * @param perpStaticInfo Symbol to perpetual info map
218
218
  */
219
- protected static checkOrder(order: Order, traderAccount: MarginAccount, perpStaticInfo: Map<string, PerpetualStaticInfo>): void;
219
+ protected static checkOrder(order: Order, perpStaticInfo: Map<string, PerpetualStaticInfo>): void;
220
220
  }
@@ -18,7 +18,6 @@ var PerpetualDataHandler = /** @class */ (function () {
18
18
  this.lobFactoryContract = null;
19
19
  this.provider = null;
20
20
  this.signerOrProvider = null;
21
- console.log("local sdk");
22
21
  this.symbolToPerpStaticInfo = new Map();
23
22
  this.poolStaticInfos = new Array();
24
23
  this.symbolToTokenAddrMap = new Map();
@@ -682,7 +681,7 @@ var PerpetualDataHandler = /** @class */ (function () {
682
681
  leverage: (0, d8XMath_1.ABK64x64ToFloat)(ethers_1.BigNumber.from(order.fLeverage)),
683
682
  deadline: Number(order.iDeadline),
684
683
  timestamp: Number(order.createdTimestamp),
685
- submittedBlock: Number(order.submittedBlock),
684
+ submittedTimestamp: Number(order.submittedTimestamp),
686
685
  };
687
686
  return userOrder;
688
687
  };
@@ -694,6 +693,9 @@ var PerpetualDataHandler = /** @class */ (function () {
694
693
  * @returns SmartContractOrder
695
694
  */
696
695
  PerpetualDataHandler.toSmartContractOrder = function (order, traderAddr, perpStaticInfo) {
696
+ // this revers if order is invalid
697
+ PerpetualDataHandler.checkOrder(order, perpStaticInfo);
698
+ // translate order
697
699
  var flags = PerpetualDataHandler._orderTypeToFlag(order);
698
700
  var brokerSig = order.brokerSignature == undefined ? [] : order.brokerSignature;
699
701
  var perpetualId = PerpetualDataHandler.symbolToPerpetualId(order.symbol, perpStaticInfo);
@@ -734,7 +736,7 @@ var PerpetualDataHandler = /** @class */ (function () {
734
736
  fLeverage: order.leverage == undefined ? ethers_1.BigNumber.from(0) : (0, d8XMath_1.floatToABK64x64)(order.leverage),
735
737
  iDeadline: ethers_1.BigNumber.from(Math.round(iDeadline)),
736
738
  createdTimestamp: ethers_1.BigNumber.from(Math.round(order.timestamp)),
737
- submittedBlock: 0,
739
+ submittedTimestamp: 0,
738
740
  };
739
741
  return smOrder;
740
742
  };
@@ -921,7 +923,7 @@ var PerpetualDataHandler = /** @class */ (function () {
921
923
  }
922
924
  else {
923
925
  if (version === undefined) {
924
- configFile = configFile.sort(function (conf) { return -conf.version; });
926
+ configFile = configFile.sort(function (conf) { return conf.version; });
925
927
  return configFile[0];
926
928
  }
927
929
  else {
@@ -958,7 +960,7 @@ var PerpetualDataHandler = /** @class */ (function () {
958
960
  }
959
961
  else {
960
962
  if (version === undefined) {
961
- configFile = configFile.sort(function (conf) { return -conf.version; });
963
+ configFile = configFile.sort(function (conf) { return conf.version; });
962
964
  return configFile[0];
963
965
  }
964
966
  else {
@@ -1023,20 +1025,22 @@ var PerpetualDataHandler = /** @class */ (function () {
1023
1025
  * @param traderAccount Trader account
1024
1026
  * @param perpStaticInfo Symbol to perpetual info map
1025
1027
  */
1026
- PerpetualDataHandler.checkOrder = function (order, traderAccount, perpStaticInfo) {
1027
- // this throws error if not found
1028
- // let perpetualId = PerpetualDataHandler.symbolToPerpetualId(order.symbol, perpStaticInfo);
1028
+ PerpetualDataHandler.checkOrder = function (order,
1029
+ // traderAccount: MarginAccount,
1030
+ perpStaticInfo) {
1029
1031
  // check side
1030
1032
  if (order.side != nodeSDKTypes_1.BUY_SIDE && order.side != nodeSDKTypes_1.SELL_SIDE) {
1031
1033
  throw Error("order side must be ".concat(nodeSDKTypes_1.BUY_SIDE, " or ").concat(nodeSDKTypes_1.SELL_SIDE));
1032
1034
  }
1033
1035
  // check amount
1034
1036
  var lotSize = perpStaticInfo.get(order.symbol).lotSizeBC;
1035
- var curPos = traderAccount.side == nodeSDKTypes_1.CLOSED_SIDE
1036
- ? 0
1037
- : (traderAccount.side == nodeSDKTypes_1.BUY_SIDE ? 1 : -1) * traderAccount.positionNotionalBaseCCY;
1038
- var newPos = curPos + (order.side == nodeSDKTypes_1.BUY_SIDE ? 1 : -1) * order.quantity;
1039
- if (Math.abs(order.quantity) < lotSize || (Math.abs(newPos) >= lotSize && Math.abs(newPos) < 10 * lotSize)) {
1037
+ // let curPos =
1038
+ // traderAccount.side == CLOSED_SIDE
1039
+ // ? 0
1040
+ // : (traderAccount.side == BUY_SIDE ? 1 : -1) * traderAccount.positionNotionalBaseCCY;
1041
+ // let newPos = curPos + (order.side == BUY_SIDE ? 1 : -1) * order.quantity;
1042
+ // if (Math.abs(order.quantity) < lotSize || (Math.abs(newPos) >= lotSize && Math.abs(newPos) < 10 * lotSize)) {
1043
+ if (Math.abs(order.quantity) < lotSize) {
1040
1044
  throw Error("trade amount too small: ".concat(order.quantity, " ").concat(perpStaticInfo.get(order.symbol).S2Symbol));
1041
1045
  }
1042
1046
  // check limit price