@nadohq/shared 0.1.0-alpha.22 → 0.1.0-alpha.29
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.
- package/dist/utils/orders/appendix/appendixTwapValue.cjs +3 -4
- package/dist/utils/orders/appendix/appendixTwapValue.cjs.map +1 -1
- package/dist/utils/orders/appendix/appendixTwapValue.d.cts +11 -13
- package/dist/utils/orders/appendix/appendixTwapValue.d.ts +11 -13
- package/dist/utils/orders/appendix/appendixTwapValue.js +3 -4
- package/dist/utils/orders/appendix/appendixTwapValue.js.map +1 -1
- package/dist/utils/orders/appendix/orderAppendix.test.cjs +11 -12
- package/dist/utils/orders/appendix/orderAppendix.test.cjs.map +1 -1
- package/dist/utils/orders/appendix/orderAppendix.test.js +11 -12
- package/dist/utils/orders/appendix/orderAppendix.test.js.map +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.cjs +3 -3
- package/dist/utils/orders/appendix/packOrderAppendix.cjs.map +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.js +3 -3
- package/dist/utils/orders/appendix/packOrderAppendix.js.map +1 -1
- package/dist/utils/orders/appendix/types.cjs.map +1 -1
- package/dist/utils/orders/appendix/types.d.cts +2 -2
- package/dist/utils/orders/appendix/types.d.ts +2 -2
- package/dist/utils/orders/appendix/unpackOrderAppendix.cjs +3 -3
- package/dist/utils/orders/appendix/unpackOrderAppendix.cjs.map +1 -1
- package/dist/utils/orders/appendix/unpackOrderAppendix.js +3 -3
- package/dist/utils/orders/appendix/unpackOrderAppendix.js.map +1 -1
- package/package.json +2 -2
- package/src/utils/orders/appendix/appendixTwapValue.ts +14 -19
- package/src/utils/orders/appendix/orderAppendix.test.ts +10 -11
- package/src/utils/orders/appendix/packOrderAppendix.ts +4 -4
- package/src/utils/orders/appendix/types.ts +5 -5
- package/src/utils/orders/appendix/unpackOrderAppendix.ts +4 -4
|
@@ -31,12 +31,11 @@ function packTwapOrderAppendixValue({
|
|
|
31
31
|
}) {
|
|
32
32
|
const numOrdersBigInt = (0, import_math.toBigInt)(numOrders);
|
|
33
33
|
const slippageX6BigInt = (0, import_math.toBigInt)((0, import_math.addDecimals)(slippageFrac, 6));
|
|
34
|
-
return (numOrdersBigInt & 0xffffffffn) <<
|
|
35
|
-
0n & 0xffffffffn;
|
|
34
|
+
return (numOrdersBigInt & 0xffffffffn) << 32n | slippageX6BigInt & 0xffffffffn;
|
|
36
35
|
}
|
|
37
36
|
function unpackTwapOrderAppendixValue(value) {
|
|
38
|
-
const numOrders = value >>
|
|
39
|
-
const slippageX6 = value
|
|
37
|
+
const numOrders = value >> 32n & 0xffffffffn;
|
|
38
|
+
const slippageX6 = value & 0xffffffffn;
|
|
40
39
|
return {
|
|
41
40
|
numOrders: Number(numOrders),
|
|
42
41
|
slippageFrac: (0, import_math.removeDecimals)(slippageX6, 6).toNumber()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/orders/appendix/appendixTwapValue.ts"],"sourcesContent":["import { OrderAppendixTwapFields } from '../../../types/orderAppendixTypes';\nimport { addDecimals, removeDecimals, toBigInt } from '../../math';\n\n/**\n * Packs the provided fields into a single
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/appendixTwapValue.ts"],"sourcesContent":["import { OrderAppendixTwapFields } from '../../../types/orderAppendixTypes';\nimport { addDecimals, removeDecimals, toBigInt } from '../../math';\n\n/**\n * Packs the provided fields into a single 64-bit bigint.\n *\n * Bit layout (MSB → LSB):\n * | times | slippage_x6 |\n * |-----------|-------------|\n * | 63..32 | 31..0 |\n * | 32 bits | 32 bits |\n *\n * - `times` occupies bits 63..32 (most significant 32 bits)\n * - `slippage_x6` occupies bits 31..0 (least significant 32 bits)\n */\nexport function packTwapOrderAppendixValue({\n numOrders,\n slippageFrac,\n}: OrderAppendixTwapFields): bigint {\n const numOrdersBigInt = toBigInt(numOrders);\n const slippageX6BigInt = toBigInt(addDecimals(slippageFrac, 6));\n\n return (\n ((numOrdersBigInt & 0xffffffffn) << 32n) | (slippageX6BigInt & 0xffffffffn)\n );\n}\n\n/**\n * Unpacks a 64-bit bigint into its component fields for TWAP orders.\n *\n * @param value 64-bit bigint to unpack\n * @returns Object with:\n * - times: number, from bits 63..32\n * - slippage_x6: number, from bits 31..0\n */\nexport function unpackTwapOrderAppendixValue(\n value: bigint,\n): OrderAppendixTwapFields {\n const numOrders = (value >> 32n) & 0xffffffffn;\n const slippageX6 = value & 0xffffffffn;\n\n return {\n numOrders: Number(numOrders),\n slippageFrac: removeDecimals(slippageX6, 6).toNumber(),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAsD;AAc/C,SAAS,2BAA2B;AAAA,EACzC;AAAA,EACA;AACF,GAAoC;AAClC,QAAM,sBAAkB,sBAAS,SAAS;AAC1C,QAAM,uBAAmB,0BAAS,yBAAY,cAAc,CAAC,CAAC;AAE9D,UACI,kBAAkB,gBAAgB,MAAQ,mBAAmB;AAEnE;AAUO,SAAS,6BACd,OACyB;AACzB,QAAM,YAAa,SAAS,MAAO;AACnC,QAAM,aAAa,QAAQ;AAE3B,SAAO;AAAA,IACL,WAAW,OAAO,SAAS;AAAA,IAC3B,kBAAc,4BAAe,YAAY,CAAC,EAAE,SAAS;AAAA,EACvD;AACF;","names":[]}
|
|
@@ -4,27 +4,25 @@ import 'bignumber.js';
|
|
|
4
4
|
import '../../../types/OrderExecutionType.cjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Packs the provided fields into a single
|
|
7
|
+
* Packs the provided fields into a single 64-bit bigint.
|
|
8
8
|
*
|
|
9
9
|
* Bit layout (MSB → LSB):
|
|
10
|
-
* | times | slippage_x6 |
|
|
11
|
-
*
|
|
12
|
-
* |
|
|
13
|
-
* | 32 bits | 32 bits |
|
|
10
|
+
* | times | slippage_x6 |
|
|
11
|
+
* |-----------|-------------|
|
|
12
|
+
* | 63..32 | 31..0 |
|
|
13
|
+
* | 32 bits | 32 bits |
|
|
14
14
|
*
|
|
15
|
-
* - `times` occupies bits
|
|
16
|
-
* - `slippage_x6` occupies bits
|
|
17
|
-
* - `reserved` occupies bits 31..0 (least significant 32 bits)
|
|
15
|
+
* - `times` occupies bits 63..32 (most significant 32 bits)
|
|
16
|
+
* - `slippage_x6` occupies bits 31..0 (least significant 32 bits)
|
|
18
17
|
*/
|
|
19
18
|
declare function packTwapOrderAppendixValue({ numOrders, slippageFrac, }: OrderAppendixTwapFields): bigint;
|
|
20
19
|
/**
|
|
21
|
-
* Unpacks a
|
|
20
|
+
* Unpacks a 64-bit bigint into its component fields for TWAP orders.
|
|
22
21
|
*
|
|
23
|
-
* @param value
|
|
22
|
+
* @param value 64-bit bigint to unpack
|
|
24
23
|
* @returns Object with:
|
|
25
|
-
* - times: number, from bits
|
|
26
|
-
* - slippage_x6: number, from bits
|
|
27
|
-
* - reserved: number, from bits 31..0
|
|
24
|
+
* - times: number, from bits 63..32
|
|
25
|
+
* - slippage_x6: number, from bits 31..0
|
|
28
26
|
*/
|
|
29
27
|
declare function unpackTwapOrderAppendixValue(value: bigint): OrderAppendixTwapFields;
|
|
30
28
|
|
|
@@ -4,27 +4,25 @@ import 'bignumber.js';
|
|
|
4
4
|
import '../../../types/OrderExecutionType.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Packs the provided fields into a single
|
|
7
|
+
* Packs the provided fields into a single 64-bit bigint.
|
|
8
8
|
*
|
|
9
9
|
* Bit layout (MSB → LSB):
|
|
10
|
-
* | times | slippage_x6 |
|
|
11
|
-
*
|
|
12
|
-
* |
|
|
13
|
-
* | 32 bits | 32 bits |
|
|
10
|
+
* | times | slippage_x6 |
|
|
11
|
+
* |-----------|-------------|
|
|
12
|
+
* | 63..32 | 31..0 |
|
|
13
|
+
* | 32 bits | 32 bits |
|
|
14
14
|
*
|
|
15
|
-
* - `times` occupies bits
|
|
16
|
-
* - `slippage_x6` occupies bits
|
|
17
|
-
* - `reserved` occupies bits 31..0 (least significant 32 bits)
|
|
15
|
+
* - `times` occupies bits 63..32 (most significant 32 bits)
|
|
16
|
+
* - `slippage_x6` occupies bits 31..0 (least significant 32 bits)
|
|
18
17
|
*/
|
|
19
18
|
declare function packTwapOrderAppendixValue({ numOrders, slippageFrac, }: OrderAppendixTwapFields): bigint;
|
|
20
19
|
/**
|
|
21
|
-
* Unpacks a
|
|
20
|
+
* Unpacks a 64-bit bigint into its component fields for TWAP orders.
|
|
22
21
|
*
|
|
23
|
-
* @param value
|
|
22
|
+
* @param value 64-bit bigint to unpack
|
|
24
23
|
* @returns Object with:
|
|
25
|
-
* - times: number, from bits
|
|
26
|
-
* - slippage_x6: number, from bits
|
|
27
|
-
* - reserved: number, from bits 31..0
|
|
24
|
+
* - times: number, from bits 63..32
|
|
25
|
+
* - slippage_x6: number, from bits 31..0
|
|
28
26
|
*/
|
|
29
27
|
declare function unpackTwapOrderAppendixValue(value: bigint): OrderAppendixTwapFields;
|
|
30
28
|
|
|
@@ -8,12 +8,11 @@ function packTwapOrderAppendixValue({
|
|
|
8
8
|
}) {
|
|
9
9
|
const numOrdersBigInt = toBigInt(numOrders);
|
|
10
10
|
const slippageX6BigInt = toBigInt(addDecimals(slippageFrac, 6));
|
|
11
|
-
return (numOrdersBigInt & 0xffffffffn) <<
|
|
12
|
-
0n & 0xffffffffn;
|
|
11
|
+
return (numOrdersBigInt & 0xffffffffn) << 32n | slippageX6BigInt & 0xffffffffn;
|
|
13
12
|
}
|
|
14
13
|
function unpackTwapOrderAppendixValue(value) {
|
|
15
|
-
const numOrders = value >>
|
|
16
|
-
const slippageX6 = value
|
|
14
|
+
const numOrders = value >> 32n & 0xffffffffn;
|
|
15
|
+
const slippageX6 = value & 0xffffffffn;
|
|
17
16
|
return {
|
|
18
17
|
numOrders: Number(numOrders),
|
|
19
18
|
slippageFrac: removeDecimals(slippageX6, 6).toNumber()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/orders/appendix/appendixTwapValue.ts"],"sourcesContent":["import { OrderAppendixTwapFields } from '../../../types/orderAppendixTypes';\nimport { addDecimals, removeDecimals, toBigInt } from '../../math';\n\n/**\n * Packs the provided fields into a single
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/appendixTwapValue.ts"],"sourcesContent":["import { OrderAppendixTwapFields } from '../../../types/orderAppendixTypes';\nimport { addDecimals, removeDecimals, toBigInt } from '../../math';\n\n/**\n * Packs the provided fields into a single 64-bit bigint.\n *\n * Bit layout (MSB → LSB):\n * | times | slippage_x6 |\n * |-----------|-------------|\n * | 63..32 | 31..0 |\n * | 32 bits | 32 bits |\n *\n * - `times` occupies bits 63..32 (most significant 32 bits)\n * - `slippage_x6` occupies bits 31..0 (least significant 32 bits)\n */\nexport function packTwapOrderAppendixValue({\n numOrders,\n slippageFrac,\n}: OrderAppendixTwapFields): bigint {\n const numOrdersBigInt = toBigInt(numOrders);\n const slippageX6BigInt = toBigInt(addDecimals(slippageFrac, 6));\n\n return (\n ((numOrdersBigInt & 0xffffffffn) << 32n) | (slippageX6BigInt & 0xffffffffn)\n );\n}\n\n/**\n * Unpacks a 64-bit bigint into its component fields for TWAP orders.\n *\n * @param value 64-bit bigint to unpack\n * @returns Object with:\n * - times: number, from bits 63..32\n * - slippage_x6: number, from bits 31..0\n */\nexport function unpackTwapOrderAppendixValue(\n value: bigint,\n): OrderAppendixTwapFields {\n const numOrders = (value >> 32n) & 0xffffffffn;\n const slippageX6 = value & 0xffffffffn;\n\n return {\n numOrders: Number(numOrders),\n slippageFrac: removeDecimals(slippageX6, 6).toNumber(),\n };\n}\n"],"mappings":";;;AACA,SAAS,aAAa,gBAAgB,gBAAgB;AAc/C,SAAS,2BAA2B;AAAA,EACzC;AAAA,EACA;AACF,GAAoC;AAClC,QAAM,kBAAkB,SAAS,SAAS;AAC1C,QAAM,mBAAmB,SAAS,YAAY,cAAc,CAAC,CAAC;AAE9D,UACI,kBAAkB,gBAAgB,MAAQ,mBAAmB;AAEnE;AAUO,SAAS,6BACd,OACyB;AACzB,QAAM,YAAa,SAAS,MAAO;AACnC,QAAM,aAAa,QAAQ;AAE3B,SAAO;AAAA,IACL,WAAW,OAAO,SAAS;AAAA,IAC3B,cAAc,eAAe,YAAY,CAAC,EAAE,SAAS;AAAA,EACvD;AACF;","names":[]}
|
|
@@ -50,7 +50,7 @@ var import_unpackOrderAppendix = require("./unpackOrderAppendix.cjs");
|
|
|
50
50
|
};
|
|
51
51
|
const packed = (0, import_packOrderAppendix.packOrderAppendix)(appendix);
|
|
52
52
|
const unpacked = (0, import_unpackOrderAppendix.unpackOrderAppendix)(packed);
|
|
53
|
-
(0, import_globals.expect)(packed).toBe(
|
|
53
|
+
(0, import_globals.expect)(packed).toBe(4097n);
|
|
54
54
|
(0, import_globals.expect)(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);
|
|
55
55
|
(0, import_globals.expect)(unpacked.triggerType).toBe(appendix.triggerType);
|
|
56
56
|
(0, import_globals.expect)(unpacked.reduceOnly).toBeFalsy();
|
|
@@ -63,7 +63,7 @@ var import_unpackOrderAppendix = require("./unpackOrderAppendix.cjs");
|
|
|
63
63
|
};
|
|
64
64
|
const packed = (0, import_packOrderAppendix.packOrderAppendix)(appendix);
|
|
65
65
|
const unpacked = (0, import_unpackOrderAppendix.unpackOrderAppendix)(packed);
|
|
66
|
-
(0, import_globals.expect)(packed).toBe(
|
|
66
|
+
(0, import_globals.expect)(packed).toBe(6145n);
|
|
67
67
|
(0, import_globals.expect)(unpacked.reduceOnly).toBe(true);
|
|
68
68
|
});
|
|
69
69
|
(0, import_globals.it)("should handle all orderExecutionType values", () => {
|
|
@@ -94,12 +94,12 @@ var import_unpackOrderAppendix = require("./unpackOrderAppendix.cjs");
|
|
|
94
94
|
const appendix = {
|
|
95
95
|
orderExecutionType: "default",
|
|
96
96
|
triggerType: "price",
|
|
97
|
-
isolated: { margin:
|
|
97
|
+
isolated: { margin: 1234567890123n }
|
|
98
98
|
};
|
|
99
99
|
const packed = (0, import_packOrderAppendix.packOrderAppendix)(appendix);
|
|
100
100
|
const unpacked = (0, import_unpackOrderAppendix.unpackOrderAppendix)(packed);
|
|
101
|
-
(0, import_globals.expect)(packed).toBe(
|
|
102
|
-
(0, import_globals.expect)(unpacked.isolated?.margin).toBe(
|
|
101
|
+
(0, import_globals.expect)(packed).toBe(22773757910718555132477485093121n);
|
|
102
|
+
(0, import_globals.expect)(unpacked.isolated?.margin).toBe(1234567890123n);
|
|
103
103
|
});
|
|
104
104
|
(0, import_globals.it)("should handle TWAP fields", () => {
|
|
105
105
|
const appendix = {
|
|
@@ -109,7 +109,7 @@ var import_unpackOrderAppendix = require("./unpackOrderAppendix.cjs");
|
|
|
109
109
|
};
|
|
110
110
|
const packed = (0, import_packOrderAppendix.packOrderAppendix)(appendix);
|
|
111
111
|
const unpacked = (0, import_unpackOrderAppendix.unpackOrderAppendix)(packed);
|
|
112
|
-
(0, import_globals.expect)(packed).toBe(
|
|
112
|
+
(0, import_globals.expect)(packed).toBe(792281717376363744483197591553n);
|
|
113
113
|
(0, import_globals.expect)(unpacked.twap).toMatchObject({ numOrders: 10, slippageFrac: 5e-3 });
|
|
114
114
|
});
|
|
115
115
|
(0, import_globals.it)("should handle max values for all fields for iso orders", () => {
|
|
@@ -117,17 +117,17 @@ var import_unpackOrderAppendix = require("./unpackOrderAppendix.cjs");
|
|
|
117
117
|
orderExecutionType: "post_only",
|
|
118
118
|
triggerType: void 0,
|
|
119
119
|
reduceOnly: true,
|
|
120
|
-
isolated: { margin:
|
|
121
|
-
// 2^
|
|
120
|
+
isolated: { margin: 18446744073709551615n }
|
|
121
|
+
// 2^64-1
|
|
122
122
|
};
|
|
123
123
|
const packed = (0, import_packOrderAppendix.packOrderAppendix)(appendix);
|
|
124
124
|
const unpacked = (0, import_unpackOrderAppendix.unpackOrderAppendix)(packed);
|
|
125
125
|
(0, import_globals.expect)(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);
|
|
126
126
|
(0, import_globals.expect)(unpacked.triggerType).toBe(appendix.triggerType);
|
|
127
127
|
(0, import_globals.expect)(unpacked.reduceOnly).toBe(appendix.reduceOnly);
|
|
128
|
-
(0, import_globals.expect)(unpacked.isolated?.margin).toBe(
|
|
128
|
+
(0, import_globals.expect)(unpacked.isolated?.margin).toBe(18446744073709551615n);
|
|
129
129
|
(0, import_globals.expect)(unpacked.twap).toBe(void 0);
|
|
130
|
-
(0, import_globals.expect)(packed).toBe(
|
|
130
|
+
(0, import_globals.expect)(packed).toBe(340282366920938463444927863358058663681n);
|
|
131
131
|
});
|
|
132
132
|
(0, import_globals.it)("should handle max values for all fields for TWAP orders", () => {
|
|
133
133
|
const appendix = {
|
|
@@ -135,7 +135,6 @@ var import_unpackOrderAppendix = require("./unpackOrderAppendix.cjs");
|
|
|
135
135
|
triggerType: "twap_custom_amounts",
|
|
136
136
|
reduceOnly: true,
|
|
137
137
|
twap: {
|
|
138
|
-
// max 32-bit unsigned int
|
|
139
138
|
numOrders: 4294967295,
|
|
140
139
|
slippageFrac: 1e-6
|
|
141
140
|
}
|
|
@@ -147,7 +146,7 @@ var import_unpackOrderAppendix = require("./unpackOrderAppendix.cjs");
|
|
|
147
146
|
(0, import_globals.expect)(unpacked.reduceOnly).toBe(appendix.reduceOnly);
|
|
148
147
|
(0, import_globals.expect)(unpacked.twap?.slippageFrac).toBe(1e-6);
|
|
149
148
|
(0, import_globals.expect)(unpacked.twap?.numOrders).toBe(4294967295);
|
|
150
|
-
(0, import_globals.expect)(packed).toBe(
|
|
149
|
+
(0, import_globals.expect)(packed).toBe(340282366841710300967557013911933828609n);
|
|
151
150
|
});
|
|
152
151
|
});
|
|
153
152
|
/*! Bundled license information:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../node_modules/@jest/globals/build/index.js","../../../../src/utils/orders/appendix/orderAppendix.test.ts"],"sourcesContent":["/*!\n * /**\n * * Copyright (c) Meta Platforms, Inc. and affiliates.\n * *\n * * This source code is licensed under the MIT license found in the\n * * LICENSE file in the root directory of this source tree.\n * * /\n */\n/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\nvar __webpack_exports__ = {};\n\n\n/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\n\nthrow new Error('Do not import `@jest/globals` outside of the Jest test environment');\nmodule.exports = __webpack_exports__;\n/******/ })()\n;","import { describe, expect, it } from '@jest/globals';\nimport { OrderAppendix, OrderExecutionType } from '../../../types';\nimport { packOrderAppendix } from './packOrderAppendix';\nimport { unpackOrderAppendix } from './unpackOrderAppendix';\n\ndescribe('OrderAppendix packing/unpacking', () => {\n it('should pack and unpack an order appendix without iso/twap values', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: 'price',\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(
|
|
1
|
+
{"version":3,"sources":["../../../../../../node_modules/@jest/globals/build/index.js","../../../../src/utils/orders/appendix/orderAppendix.test.ts"],"sourcesContent":["/*!\n * /**\n * * Copyright (c) Meta Platforms, Inc. and affiliates.\n * *\n * * This source code is licensed under the MIT license found in the\n * * LICENSE file in the root directory of this source tree.\n * * /\n */\n/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\nvar __webpack_exports__ = {};\n\n\n/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\n\nthrow new Error('Do not import `@jest/globals` outside of the Jest test environment');\nmodule.exports = __webpack_exports__;\n/******/ })()\n;","import { describe, expect, it } from '@jest/globals';\nimport { OrderAppendix, OrderExecutionType } from '../../../types';\nimport { packOrderAppendix } from './packOrderAppendix';\nimport { unpackOrderAppendix } from './unpackOrderAppendix';\n\ndescribe('OrderAppendix packing/unpacking', () => {\n it('should pack and unpack an order appendix without iso/twap values', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: 'price',\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(4097n);\n expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);\n expect(unpacked.triggerType).toBe(appendix.triggerType);\n expect(unpacked.reduceOnly).toBeFalsy();\n });\n\n it('should handle reduceOnly true', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: 'price',\n reduceOnly: true,\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(6145n);\n expect(unpacked.reduceOnly).toBe(true);\n });\n\n it('should handle all orderExecutionType values', () => {\n const types: OrderExecutionType[] = ['default', 'ioc', 'fok', 'post_only'];\n for (const type of types) {\n const appendix: OrderAppendix = {\n orderExecutionType: type,\n triggerType: 'price',\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.orderExecutionType).toBe(type);\n }\n });\n\n it('should handle all triggerType values', () => {\n const triggers = ['price', 'twap', 'twap_custom_amounts'] as const;\n for (const trigger of triggers) {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: trigger,\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.triggerType).toBe(trigger);\n }\n });\n\n it('should handle isolated margin', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: 'price',\n\n isolated: { margin: 1234567890123n },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(22773757910718555132477485093121n);\n expect(unpacked.isolated?.margin).toBe(1234567890123n);\n });\n\n it('should handle TWAP fields', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: 'twap',\n\n twap: { numOrders: 10, slippageFrac: 0.005 },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(792281717376363744483197591553n);\n expect(unpacked.twap).toMatchObject({ numOrders: 10, slippageFrac: 0.005 });\n });\n\n it('should handle max values for all fields for iso orders', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'post_only',\n triggerType: undefined,\n reduceOnly: true,\n isolated: { margin: 18446744073709551615n }, // 2^64-1\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);\n expect(unpacked.triggerType).toBe(appendix.triggerType);\n expect(unpacked.reduceOnly).toBe(appendix.reduceOnly);\n expect(unpacked.isolated?.margin).toBe(18446744073709551615n);\n expect(unpacked.twap).toBe(undefined);\n expect(packed).toBe(340282366920938463444927863358058663681n);\n });\n\n it('should handle max values for all fields for TWAP orders', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'post_only',\n triggerType: 'twap_custom_amounts',\n reduceOnly: true,\n twap: {\n numOrders: 4294967295,\n slippageFrac: 0.000001,\n },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);\n expect(unpacked.triggerType).toBe(appendix.triggerType);\n expect(unpacked.reduceOnly).toBe(appendix.reduceOnly);\n expect(unpacked.twap?.slippageFrac).toBe(0.000001);\n expect(unpacked.twap?.numOrders).toBe(4294967295);\n expect(packed).toBe(340282366841710300967557013911933828609n);\n });\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,oDAAAA,UAAAC,SAAA;AAAA;AAQS,KAAC,MAAM;AACN;AACV,UAAI,sBAAsB,CAAC;AAY3B,YAAM,IAAI,MAAM,oEAAoE;AACpF,MAAAA,QAAO,UAAU;AAAA,IACR,GAAG;AAAA;AAAA;;;ACxBZ,qBAAqC;AAErC,+BAAkC;AAClC,iC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AAwC;AAAA,EAC9D,CAAC;AAED,yBAAG,2DAA2D,MAAM;AAClE,UAAM,WAA0B;AAAA,MAC9B,oBAAoB;AAAA,MACpB,aAAa;AAAA,MACb,YAAY;AAAA,MACZ,MAAM;AAAA,QACJ,WAAW;AAAA,QACX,cAAc;AAAA,MAChB;AAAA,IACF;AACA,UAAM,aAAS,4CAAkB,QAAQ;AACzC,UAAM,eAAW,gDAAoB,MAAM;AAC3C,+BAAO,SAAS,kBAAkB,EAAE,KAAK,SAAS,kBAAkB;AACpE,+BAAO,SAAS,WAAW,EAAE,KAAK,SAAS,WAAW;AACtD,+BAAO,SAAS,UAAU,EAAE,KAAK,SAAS,UAAU;AACpD,+BAAO,SAAS,MAAM,YAAY,EAAE,KAAK,IAAQ;AACjD,+BAAO,SAAS,MAAM,SAAS,EAAE,KAAK,UAAU;AAChD,+BAAO,MAAM,EAAE,KAAK,wCAAwC;AAAA,EAC9D,CAAC;AACH,CAAC;","names":["exports","module"]}
|
|
@@ -17,7 +17,7 @@ import { unpackOrderAppendix } from "./unpackOrderAppendix.js";
|
|
|
17
17
|
};
|
|
18
18
|
const packed = packOrderAppendix(appendix);
|
|
19
19
|
const unpacked = unpackOrderAppendix(packed);
|
|
20
|
-
(0, import_globals.expect)(packed).toBe(
|
|
20
|
+
(0, import_globals.expect)(packed).toBe(4097n);
|
|
21
21
|
(0, import_globals.expect)(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);
|
|
22
22
|
(0, import_globals.expect)(unpacked.triggerType).toBe(appendix.triggerType);
|
|
23
23
|
(0, import_globals.expect)(unpacked.reduceOnly).toBeFalsy();
|
|
@@ -30,7 +30,7 @@ import { unpackOrderAppendix } from "./unpackOrderAppendix.js";
|
|
|
30
30
|
};
|
|
31
31
|
const packed = packOrderAppendix(appendix);
|
|
32
32
|
const unpacked = unpackOrderAppendix(packed);
|
|
33
|
-
(0, import_globals.expect)(packed).toBe(
|
|
33
|
+
(0, import_globals.expect)(packed).toBe(6145n);
|
|
34
34
|
(0, import_globals.expect)(unpacked.reduceOnly).toBe(true);
|
|
35
35
|
});
|
|
36
36
|
(0, import_globals.it)("should handle all orderExecutionType values", () => {
|
|
@@ -61,12 +61,12 @@ import { unpackOrderAppendix } from "./unpackOrderAppendix.js";
|
|
|
61
61
|
const appendix = {
|
|
62
62
|
orderExecutionType: "default",
|
|
63
63
|
triggerType: "price",
|
|
64
|
-
isolated: { margin:
|
|
64
|
+
isolated: { margin: 1234567890123n }
|
|
65
65
|
};
|
|
66
66
|
const packed = packOrderAppendix(appendix);
|
|
67
67
|
const unpacked = unpackOrderAppendix(packed);
|
|
68
|
-
(0, import_globals.expect)(packed).toBe(
|
|
69
|
-
(0, import_globals.expect)(unpacked.isolated?.margin).toBe(
|
|
68
|
+
(0, import_globals.expect)(packed).toBe(22773757910718555132477485093121n);
|
|
69
|
+
(0, import_globals.expect)(unpacked.isolated?.margin).toBe(1234567890123n);
|
|
70
70
|
});
|
|
71
71
|
(0, import_globals.it)("should handle TWAP fields", () => {
|
|
72
72
|
const appendix = {
|
|
@@ -76,7 +76,7 @@ import { unpackOrderAppendix } from "./unpackOrderAppendix.js";
|
|
|
76
76
|
};
|
|
77
77
|
const packed = packOrderAppendix(appendix);
|
|
78
78
|
const unpacked = unpackOrderAppendix(packed);
|
|
79
|
-
(0, import_globals.expect)(packed).toBe(
|
|
79
|
+
(0, import_globals.expect)(packed).toBe(792281717376363744483197591553n);
|
|
80
80
|
(0, import_globals.expect)(unpacked.twap).toMatchObject({ numOrders: 10, slippageFrac: 5e-3 });
|
|
81
81
|
});
|
|
82
82
|
(0, import_globals.it)("should handle max values for all fields for iso orders", () => {
|
|
@@ -84,17 +84,17 @@ import { unpackOrderAppendix } from "./unpackOrderAppendix.js";
|
|
|
84
84
|
orderExecutionType: "post_only",
|
|
85
85
|
triggerType: void 0,
|
|
86
86
|
reduceOnly: true,
|
|
87
|
-
isolated: { margin:
|
|
88
|
-
// 2^
|
|
87
|
+
isolated: { margin: 18446744073709551615n }
|
|
88
|
+
// 2^64-1
|
|
89
89
|
};
|
|
90
90
|
const packed = packOrderAppendix(appendix);
|
|
91
91
|
const unpacked = unpackOrderAppendix(packed);
|
|
92
92
|
(0, import_globals.expect)(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);
|
|
93
93
|
(0, import_globals.expect)(unpacked.triggerType).toBe(appendix.triggerType);
|
|
94
94
|
(0, import_globals.expect)(unpacked.reduceOnly).toBe(appendix.reduceOnly);
|
|
95
|
-
(0, import_globals.expect)(unpacked.isolated?.margin).toBe(
|
|
95
|
+
(0, import_globals.expect)(unpacked.isolated?.margin).toBe(18446744073709551615n);
|
|
96
96
|
(0, import_globals.expect)(unpacked.twap).toBe(void 0);
|
|
97
|
-
(0, import_globals.expect)(packed).toBe(
|
|
97
|
+
(0, import_globals.expect)(packed).toBe(340282366920938463444927863358058663681n);
|
|
98
98
|
});
|
|
99
99
|
(0, import_globals.it)("should handle max values for all fields for TWAP orders", () => {
|
|
100
100
|
const appendix = {
|
|
@@ -102,7 +102,6 @@ import { unpackOrderAppendix } from "./unpackOrderAppendix.js";
|
|
|
102
102
|
triggerType: "twap_custom_amounts",
|
|
103
103
|
reduceOnly: true,
|
|
104
104
|
twap: {
|
|
105
|
-
// max 32-bit unsigned int
|
|
106
105
|
numOrders: 4294967295,
|
|
107
106
|
slippageFrac: 1e-6
|
|
108
107
|
}
|
|
@@ -114,7 +113,7 @@ import { unpackOrderAppendix } from "./unpackOrderAppendix.js";
|
|
|
114
113
|
(0, import_globals.expect)(unpacked.reduceOnly).toBe(appendix.reduceOnly);
|
|
115
114
|
(0, import_globals.expect)(unpacked.twap?.slippageFrac).toBe(1e-6);
|
|
116
115
|
(0, import_globals.expect)(unpacked.twap?.numOrders).toBe(4294967295);
|
|
117
|
-
(0, import_globals.expect)(packed).toBe(
|
|
116
|
+
(0, import_globals.expect)(packed).toBe(340282366841710300967557013911933828609n);
|
|
118
117
|
});
|
|
119
118
|
});
|
|
120
119
|
//# sourceMappingURL=orderAppendix.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/orders/appendix/orderAppendix.test.ts"],"sourcesContent":["import { describe, expect, it } from '@jest/globals';\nimport { OrderAppendix, OrderExecutionType } from '../../../types';\nimport { packOrderAppendix } from './packOrderAppendix';\nimport { unpackOrderAppendix } from './unpackOrderAppendix';\n\ndescribe('OrderAppendix packing/unpacking', () => {\n it('should pack and unpack an order appendix without iso/twap values', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: 'price',\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/orderAppendix.test.ts"],"sourcesContent":["import { describe, expect, it } from '@jest/globals';\nimport { OrderAppendix, OrderExecutionType } from '../../../types';\nimport { packOrderAppendix } from './packOrderAppendix';\nimport { unpackOrderAppendix } from './unpackOrderAppendix';\n\ndescribe('OrderAppendix packing/unpacking', () => {\n it('should pack and unpack an order appendix without iso/twap values', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: 'price',\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(4097n);\n expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);\n expect(unpacked.triggerType).toBe(appendix.triggerType);\n expect(unpacked.reduceOnly).toBeFalsy();\n });\n\n it('should handle reduceOnly true', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: 'price',\n reduceOnly: true,\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(6145n);\n expect(unpacked.reduceOnly).toBe(true);\n });\n\n it('should handle all orderExecutionType values', () => {\n const types: OrderExecutionType[] = ['default', 'ioc', 'fok', 'post_only'];\n for (const type of types) {\n const appendix: OrderAppendix = {\n orderExecutionType: type,\n triggerType: 'price',\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.orderExecutionType).toBe(type);\n }\n });\n\n it('should handle all triggerType values', () => {\n const triggers = ['price', 'twap', 'twap_custom_amounts'] as const;\n for (const trigger of triggers) {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: trigger,\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.triggerType).toBe(trigger);\n }\n });\n\n it('should handle isolated margin', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: 'price',\n\n isolated: { margin: 1234567890123n },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(22773757910718555132477485093121n);\n expect(unpacked.isolated?.margin).toBe(1234567890123n);\n });\n\n it('should handle TWAP fields', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n triggerType: 'twap',\n\n twap: { numOrders: 10, slippageFrac: 0.005 },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(792281717376363744483197591553n);\n expect(unpacked.twap).toMatchObject({ numOrders: 10, slippageFrac: 0.005 });\n });\n\n it('should handle max values for all fields for iso orders', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'post_only',\n triggerType: undefined,\n reduceOnly: true,\n isolated: { margin: 18446744073709551615n }, // 2^64-1\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);\n expect(unpacked.triggerType).toBe(appendix.triggerType);\n expect(unpacked.reduceOnly).toBe(appendix.reduceOnly);\n expect(unpacked.isolated?.margin).toBe(18446744073709551615n);\n expect(unpacked.twap).toBe(undefined);\n expect(packed).toBe(340282366920938463444927863358058663681n);\n });\n\n it('should handle max values for all fields for TWAP orders', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'post_only',\n triggerType: 'twap_custom_amounts',\n reduceOnly: true,\n twap: {\n numOrders: 4294967295,\n slippageFrac: 0.000001,\n },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);\n expect(unpacked.triggerType).toBe(appendix.triggerType);\n expect(unpacked.reduceOnly).toBe(appendix.reduceOnly);\n expect(unpacked.twap?.slippageFrac).toBe(0.000001);\n expect(unpacked.twap?.numOrders).toBe(4294967295);\n expect(packed).toBe(340282366841710300967557013911933828609n);\n });\n});\n"],"mappings":";;;;;;;;AAAA,qBAAqC;AAErC,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AAAA,IAEpC,yBAAS,mCAAmC,MAAM;AAChD,yBAAG,oEAAoE,MAAM;AAC3E,UAAM,WAA0B;AAAA,MAC9B,oBAAoB;AAAA,MACpB,aAAa;AAAA,IACf;AACA,UAAM,SAAS,kBAAkB,QAAQ;AACzC,UAAM,WAAW,oBAAoB,MAAM;AAC3C,+BAAO,MAAM,EAAE,KAAK,KAAK;AACzB,+BAAO,SAAS,kBAAkB,EAAE,KAAK,SAAS,kBAAkB;AACpE,+BAAO,SAAS,WAAW,EAAE,KAAK,SAAS,WAAW;AACtD,+BAAO,SAAS,UAAU,EAAE,UAAU;AAAA,EACxC,CAAC;AAED,yBAAG,iCAAiC,MAAM;AACxC,UAAM,WAA0B;AAAA,MAC9B,oBAAoB;AAAA,MACpB,aAAa;AAAA,MACb,YAAY;AAAA,IACd;AACA,UAAM,SAAS,kBAAkB,QAAQ;AACzC,UAAM,WAAW,oBAAoB,MAAM;AAC3C,+BAAO,MAAM,EAAE,KAAK,KAAK;AACzB,+BAAO,SAAS,UAAU,EAAE,KAAK,IAAI;AAAA,EACvC,CAAC;AAED,yBAAG,+CAA+C,MAAM;AACtD,UAAM,QAA8B,CAAC,WAAW,OAAO,OAAO,WAAW;AACzE,eAAW,QAAQ,OAAO;AACxB,YAAM,WAA0B;AAAA,QAC9B,oBAAoB;A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;AAAA,MACZ,UAAU,EAAE,QAAQ,sBAAsB;AAAA;AAAA,IAC5C;AACA,UAAM,SAAS,kBAAkB,QAAQ;AACzC,UAAM,WAAW,oBAAoB,MAAM;AAC3C,+BAAO,SAAS,kBAAkB,EAAE,KAAK,SAAS,kBAAkB;AACpE,+BAAO,SAAS,WAAW,EAAE,KAAK,SAAS,WAAW;AACtD,+BAAO,SAAS,UAAU,EAAE,KAAK,SAAS,UAAU;AACpD,+BAAO,SAAS,UAAU,MAAM,EAAE,KAAK,qBAAqB;AAC5D,+BAAO,SAAS,IAAI,EAAE,KAAK,MAAS;AACpC,+BAAO,MAAM,EAAE,KAAK,wCAAwC;AAAA,EAC9D,CAAC;AAED,yBAAG,2DAA2D,MAAM;AAClE,UAAM,WAA0B;AAAA,MAC9B,oBAAoB;AAAA,MACpB,aAAa;AAAA,MACb,YAAY;AAAA,MACZ,MAAM;AAAA,QACJ,WAAW;AAAA,QACX,cAAc;AAAA,MAChB;AAAA,IACF;AACA,UAAM,SAAS,kBAAkB,QAAQ;AACzC,UAAM,WAAW,oBAAoB,MAAM;AAC3C,+BAAO,SAAS,kBAAkB,EAAE,KAAK,SAAS,kBAAkB;AACpE,+BAAO,SAAS,WAAW,EAAE,KAAK,SAAS,WAAW;AACtD,+BAAO,SAAS,UAAU,EAAE,KAAK,SAAS,UAAU;AACpD,+BAAO,SAAS,MAAM,YAAY,EAAE,KAAK,IAAQ;AACjD,+BAAO,SAAS,MAAM,SAAS,EAAE,KAAK,UAAU;AAChD,+BAAO,MAAM,EAAE,KAAK,wCAAwC;AAAA,EAC9D,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -67,13 +67,13 @@ function mapOrderAppendixToBitValues(appendix) {
|
|
|
67
67
|
reduceOnly: appendix.reduceOnly ? 1 : 0,
|
|
68
68
|
orderType,
|
|
69
69
|
isolated: appendix.isolated ? 1 : 0,
|
|
70
|
-
version:
|
|
70
|
+
version: 1
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
function packOrderAppendix(appendix) {
|
|
74
74
|
const bits = mapOrderAppendixToBitValues(appendix);
|
|
75
|
-
let packed = (0, import_bitMaskValue.bitMaskValue)(bits.value,
|
|
76
|
-
packed = packed <<
|
|
75
|
+
let packed = (0, import_bitMaskValue.bitMaskValue)(bits.value, 64);
|
|
76
|
+
packed = packed << 50n | (0, import_bitMaskValue.bitMaskValue)(bits.reserved, 50);
|
|
77
77
|
packed = packed << 2n | (0, import_bitMaskValue.bitMaskValue)(bits.trigger, 2);
|
|
78
78
|
packed = packed << 1n | (0, import_bitMaskValue.bitMaskValue)(bits.reduceOnly, 1);
|
|
79
79
|
packed = packed << 2n | (0, import_bitMaskValue.bitMaskValue)(bits.orderType, 2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/orders/appendix/packOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { toBigInt } from '../../math/toBigInt';\nimport { packTwapOrderAppendixValue } from './appendixTwapValue';\nimport { bitMaskValue } from './bitMaskValue';\nimport { PackedOrderAppendixBits } from './types';\n\nfunction mapOrderAppendixToBitValues(\n appendix: OrderAppendix,\n): PackedOrderAppendixBits {\n const value = (() => {\n if (appendix.twap) {\n return packTwapOrderAppendixValue(appendix.twap);\n }\n if (appendix.isolated) {\n return toBigInt(appendix.isolated.margin);\n }\n return 0n;\n })();\n const trigger = (() => {\n switch (appendix.triggerType) {\n case 'price':\n return 1;\n case 'twap':\n return 2;\n case 'twap_custom_amounts':\n return 3;\n default:\n return 0;\n }\n })();\n const orderType = (() => {\n switch (appendix.orderExecutionType) {\n case 'default':\n return 0;\n case 'ioc':\n return 1;\n case 'fok':\n return 2;\n case 'post_only':\n return 3;\n }\n })();\n\n return {\n value,\n reserved: 0,\n trigger,\n reduceOnly: appendix.reduceOnly ? 1 : 0,\n orderType,\n isolated: appendix.isolated ? 1 : 0,\n version:
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/packOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { toBigInt } from '../../math/toBigInt';\nimport { packTwapOrderAppendixValue } from './appendixTwapValue';\nimport { bitMaskValue } from './bitMaskValue';\nimport { PackedOrderAppendixBits } from './types';\n\nfunction mapOrderAppendixToBitValues(\n appendix: OrderAppendix,\n): PackedOrderAppendixBits {\n const value = (() => {\n if (appendix.twap) {\n return packTwapOrderAppendixValue(appendix.twap);\n }\n if (appendix.isolated) {\n return toBigInt(appendix.isolated.margin);\n }\n return 0n;\n })();\n const trigger = (() => {\n switch (appendix.triggerType) {\n case 'price':\n return 1;\n case 'twap':\n return 2;\n case 'twap_custom_amounts':\n return 3;\n default:\n return 0;\n }\n })();\n const orderType = (() => {\n switch (appendix.orderExecutionType) {\n case 'default':\n return 0;\n case 'ioc':\n return 1;\n case 'fok':\n return 2;\n case 'post_only':\n return 3;\n }\n })();\n\n return {\n value,\n reserved: 0,\n trigger,\n reduceOnly: appendix.reduceOnly ? 1 : 0,\n orderType,\n isolated: appendix.isolated ? 1 : 0,\n version: 1,\n };\n}\n\n/**\n * Pack the OrderAppendix fields into a single bigint.\n * @param appendix\n */\nexport function packOrderAppendix(appendix: OrderAppendix): bigint {\n const bits = mapOrderAppendixToBitValues(appendix);\n\n // Ensure value is within 64 bits\n let packed = bitMaskValue(bits.value, 64);\n packed = (packed << 50n) | bitMaskValue(bits.reserved, 50);\n packed = (packed << 2n) | bitMaskValue(bits.trigger, 2);\n packed = (packed << 1n) | bitMaskValue(bits.reduceOnly, 1);\n packed = (packed << 2n) | bitMaskValue(bits.orderType, 2);\n packed = (packed << 1n) | bitMaskValue(bits.isolated, 1);\n packed = (packed << 8n) | bitMaskValue(bits.version, 8);\n return packed;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAyB;AACzB,+BAA2C;AAC3C,0BAA6B;AAG7B,SAAS,4BACP,UACyB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Only: appendix.reduceOnly ? 1 : 0,
|
|
46
46
|
orderType,
|
|
47
47
|
isolated: appendix.isolated ? 1 : 0,
|
|
48
|
-
version:
|
|
48
|
+
version: 1
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
function packOrderAppendix(appendix) {
|
|
52
52
|
const bits = mapOrderAppendixToBitValues(appendix);
|
|
53
|
-
let packed = bitMaskValue(bits.value,
|
|
54
|
-
packed = packed <<
|
|
53
|
+
let packed = bitMaskValue(bits.value, 64);
|
|
54
|
+
packed = packed << 50n | bitMaskValue(bits.reserved, 50);
|
|
55
55
|
packed = packed << 2n | bitMaskValue(bits.trigger, 2);
|
|
56
56
|
packed = packed << 1n | bitMaskValue(bits.reduceOnly, 1);
|
|
57
57
|
packed = packed << 2n | bitMaskValue(bits.orderType, 2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/orders/appendix/packOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { toBigInt } from '../../math/toBigInt';\nimport { packTwapOrderAppendixValue } from './appendixTwapValue';\nimport { bitMaskValue } from './bitMaskValue';\nimport { PackedOrderAppendixBits } from './types';\n\nfunction mapOrderAppendixToBitValues(\n appendix: OrderAppendix,\n): PackedOrderAppendixBits {\n const value = (() => {\n if (appendix.twap) {\n return packTwapOrderAppendixValue(appendix.twap);\n }\n if (appendix.isolated) {\n return toBigInt(appendix.isolated.margin);\n }\n return 0n;\n })();\n const trigger = (() => {\n switch (appendix.triggerType) {\n case 'price':\n return 1;\n case 'twap':\n return 2;\n case 'twap_custom_amounts':\n return 3;\n default:\n return 0;\n }\n })();\n const orderType = (() => {\n switch (appendix.orderExecutionType) {\n case 'default':\n return 0;\n case 'ioc':\n return 1;\n case 'fok':\n return 2;\n case 'post_only':\n return 3;\n }\n })();\n\n return {\n value,\n reserved: 0,\n trigger,\n reduceOnly: appendix.reduceOnly ? 1 : 0,\n orderType,\n isolated: appendix.isolated ? 1 : 0,\n version:
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/packOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { toBigInt } from '../../math/toBigInt';\nimport { packTwapOrderAppendixValue } from './appendixTwapValue';\nimport { bitMaskValue } from './bitMaskValue';\nimport { PackedOrderAppendixBits } from './types';\n\nfunction mapOrderAppendixToBitValues(\n appendix: OrderAppendix,\n): PackedOrderAppendixBits {\n const value = (() => {\n if (appendix.twap) {\n return packTwapOrderAppendixValue(appendix.twap);\n }\n if (appendix.isolated) {\n return toBigInt(appendix.isolated.margin);\n }\n return 0n;\n })();\n const trigger = (() => {\n switch (appendix.triggerType) {\n case 'price':\n return 1;\n case 'twap':\n return 2;\n case 'twap_custom_amounts':\n return 3;\n default:\n return 0;\n }\n })();\n const orderType = (() => {\n switch (appendix.orderExecutionType) {\n case 'default':\n return 0;\n case 'ioc':\n return 1;\n case 'fok':\n return 2;\n case 'post_only':\n return 3;\n }\n })();\n\n return {\n value,\n reserved: 0,\n trigger,\n reduceOnly: appendix.reduceOnly ? 1 : 0,\n orderType,\n isolated: appendix.isolated ? 1 : 0,\n version: 1,\n };\n}\n\n/**\n * Pack the OrderAppendix fields into a single bigint.\n * @param appendix\n */\nexport function packOrderAppendix(appendix: OrderAppendix): bigint {\n const bits = mapOrderAppendixToBitValues(appendix);\n\n // Ensure value is within 64 bits\n let packed = bitMaskValue(bits.value, 64);\n packed = (packed << 50n) | bitMaskValue(bits.reserved, 50);\n packed = (packed << 2n) | bitMaskValue(bits.trigger, 2);\n packed = (packed << 1n) | bitMaskValue(bits.reduceOnly, 1);\n packed = (packed << 2n) | bitMaskValue(bits.orderType, 2);\n packed = (packed << 1n) | bitMaskValue(bits.isolated, 1);\n packed = (packed << 8n) | bitMaskValue(bits.version, 8);\n return packed;\n}\n"],"mappings":";;;AACA,SAAS,gBAAgB;AACzB,SAAS,kCAAkC;AAC3C,SAAS,oBAAoB;AAG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/appendix/types.ts"],"sourcesContent":["/**\n * Bit layout for OrderAppendix packing (MSB → LSB):\n *\n * | value | reserved | trigger | reduceOnly | orderType | isolated | version |\n * |-----------|----------|---------|------------|-----------|----------|---------|\n * | 127..
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/types.ts"],"sourcesContent":["/**\n * Bit layout for OrderAppendix packing (MSB → LSB):\n *\n * | value | reserved | trigger | reduceOnly | orderType | isolated | version |\n * |-----------|----------|---------|------------|-----------|----------|---------|\n * | 127..64 | 63..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |\n * | 64 bits | 50 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |\n */\nexport interface PackedOrderAppendixBits {\n value: bigint; // 64 bits\n reserved: number; // 50 bits, set to 0\n trigger: number; // 2 bits\n reduceOnly: number; // 1 bit\n orderType: number; // 2 bits\n isolated: number; // 1 bit\n version: number; // 8 bits, set to 1\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* | value | reserved | trigger | reduceOnly | orderType | isolated | version |
|
|
5
5
|
* |-----------|----------|---------|------------|-----------|----------|---------|
|
|
6
|
-
* | 127..
|
|
7
|
-
* |
|
|
6
|
+
* | 127..64 | 63..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |
|
|
7
|
+
* | 64 bits | 50 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |
|
|
8
8
|
*/
|
|
9
9
|
interface PackedOrderAppendixBits {
|
|
10
10
|
value: bigint;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* | value | reserved | trigger | reduceOnly | orderType | isolated | version |
|
|
5
5
|
* |-----------|----------|---------|------------|-----------|----------|---------|
|
|
6
|
-
* | 127..
|
|
7
|
-
* |
|
|
6
|
+
* | 127..64 | 63..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |
|
|
7
|
+
* | 64 bits | 50 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |
|
|
8
8
|
*/
|
|
9
9
|
interface PackedOrderAppendixBits {
|
|
10
10
|
value: bigint;
|
|
@@ -86,9 +86,9 @@ function unpackOrderAppendix(packed) {
|
|
|
86
86
|
temp >>= 1n;
|
|
87
87
|
const trigger = Number((0, import_bitMaskValue.bitMaskValue)(temp, 2));
|
|
88
88
|
temp >>= 2n;
|
|
89
|
-
const reserved = Number((0, import_bitMaskValue.bitMaskValue)(temp,
|
|
90
|
-
temp >>=
|
|
91
|
-
const value = (0, import_bitMaskValue.bitMaskValue)(temp,
|
|
89
|
+
const reserved = Number((0, import_bitMaskValue.bitMaskValue)(temp, 50));
|
|
90
|
+
temp >>= 50n;
|
|
91
|
+
const value = (0, import_bitMaskValue.bitMaskValue)(temp, 64);
|
|
92
92
|
return mapBitValuesToAppendix({
|
|
93
93
|
value,
|
|
94
94
|
reserved,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/orders/appendix/unpackOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { BigDecimalish, toBigInt } from '../../math';\nimport { unpackTwapOrderAppendixValue } from './appendixTwapValue';\nimport { bitMaskValue } from './bitMaskValue';\nimport { PackedOrderAppendixBits } from './types';\n\nfunction mapBitValuesToAppendix(bits: PackedOrderAppendixBits): OrderAppendix {\n const triggerType = (() => {\n switch (bits.trigger) {\n case 1:\n return 'price';\n case 2:\n return 'twap';\n case 3:\n return 'twap_custom_amounts';\n default:\n return undefined;\n }\n })();\n const orderExecutionType = (() => {\n switch (bits.orderType) {\n case 0:\n return 'default';\n case 1:\n return 'ioc';\n case 2:\n return 'fok';\n case 3:\n return 'post_only';\n default:\n throw new Error(\n `[mapBitValuesToAppendix] Unknown order type: ${bits.orderType}`,\n );\n }\n })();\n const isolatedFields = (() => {\n if (bits.isolated) {\n return { margin: bits.value };\n }\n return undefined;\n })();\n const twapFields = (() => {\n if (triggerType === 'twap' || triggerType === 'twap_custom_amounts') {\n return unpackTwapOrderAppendixValue(bits.value);\n }\n })();\n\n return {\n reduceOnly: !!bits.reduceOnly,\n orderExecutionType,\n triggerType,\n isolated: isolatedFields,\n twap: twapFields,\n };\n}\n\n/**\n * Unpack the OrderAppendix fields from a packed bigint.\n * @param packed\n */\nexport function unpackOrderAppendix(packed: BigDecimalish): OrderAppendix {\n let temp = toBigInt(packed);\n // Bitmasks lowest 8 bits for version\n const version = Number(bitMaskValue(temp, 8));\n // Shift out the version bits\n temp >>= 8n;\n // Repeat for the rest of the fields\n const isolated = Number(bitMaskValue(temp, 1));\n temp >>= 1n;\n const orderType = Number(bitMaskValue(temp, 2));\n temp >>= 2n;\n const reduceOnly = Number(bitMaskValue(temp, 1));\n temp >>= 1n;\n const trigger = Number(bitMaskValue(temp, 2));\n temp >>= 2n;\n const reserved = Number(bitMaskValue(temp,
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/unpackOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { BigDecimalish, toBigInt } from '../../math';\nimport { unpackTwapOrderAppendixValue } from './appendixTwapValue';\nimport { bitMaskValue } from './bitMaskValue';\nimport { PackedOrderAppendixBits } from './types';\n\nfunction mapBitValuesToAppendix(bits: PackedOrderAppendixBits): OrderAppendix {\n const triggerType = (() => {\n switch (bits.trigger) {\n case 1:\n return 'price';\n case 2:\n return 'twap';\n case 3:\n return 'twap_custom_amounts';\n default:\n return undefined;\n }\n })();\n const orderExecutionType = (() => {\n switch (bits.orderType) {\n case 0:\n return 'default';\n case 1:\n return 'ioc';\n case 2:\n return 'fok';\n case 3:\n return 'post_only';\n default:\n throw new Error(\n `[mapBitValuesToAppendix] Unknown order type: ${bits.orderType}`,\n );\n }\n })();\n const isolatedFields = (() => {\n if (bits.isolated) {\n return { margin: bits.value };\n }\n return undefined;\n })();\n const twapFields = (() => {\n if (triggerType === 'twap' || triggerType === 'twap_custom_amounts') {\n return unpackTwapOrderAppendixValue(bits.value);\n }\n })();\n\n return {\n reduceOnly: !!bits.reduceOnly,\n orderExecutionType,\n triggerType,\n isolated: isolatedFields,\n twap: twapFields,\n };\n}\n\n/**\n * Unpack the OrderAppendix fields from a packed bigint.\n * @param packed\n */\nexport function unpackOrderAppendix(packed: BigDecimalish): OrderAppendix {\n let temp = toBigInt(packed);\n // Bitmasks lowest 8 bits for version\n const version = Number(bitMaskValue(temp, 8));\n // Shift out the version bits\n temp >>= 8n;\n // Repeat for the rest of the fields\n const isolated = Number(bitMaskValue(temp, 1));\n temp >>= 1n;\n const orderType = Number(bitMaskValue(temp, 2));\n temp >>= 2n;\n const reduceOnly = Number(bitMaskValue(temp, 1));\n temp >>= 1n;\n const trigger = Number(bitMaskValue(temp, 2));\n temp >>= 2n;\n const reserved = Number(bitMaskValue(temp, 50));\n temp >>= 50n;\n // The remaining bits are the value, which should be 64 bits\n const value = bitMaskValue(temp, 64);\n\n return mapBitValuesToAppendix({\n value,\n reserved,\n trigger,\n reduceOnly,\n orderType,\n isolated,\n version,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAwC;AACxC,+BAA6C;AAC7C,0BAA6B;AAG7B,SAAS,uBAAuB,MAA8C;AAC5E,QAAM,eAAe,MAAM;AACzB,YAAQ,KAAK,SAAS;AAAA,MACpB,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT;AACE,eAAO;AAAA,IACX;AAAA,EACF,GAAG;AACH,QAAM,sBAAsB,MAAM;AAChC,YAAQ,KAAK,WAAW;AAAA,MACtB,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT;AACE,cAAM,IAAI;AAAA,UACR,gDAAgD,KAAK,SAAS;AAAA,QAChE;AAAA,IACJ;AAAA,EACF,GAAG;AACH,QAAM,kBAAkB,MAAM;AAC5B,QAAI,KAAK,UAAU;AACjB,aAAO,EAAE,QAAQ,KAAK,MAAM;AAAA,IAC9B;AACA,WAAO;AAAA,EACT,GAAG;AACH,QAAM,cAAc,MAAM;AACxB,QAAI,gBAAgB,UAAU,gBAAgB,uBAAuB;AACnE,iBAAO,uDAA6B,KAAK,KAAK;AAAA,IAChD;AAAA,EACF,GAAG;AAEH,SAAO;AAAA,IACL,YAAY,CAAC,CAAC,KAAK;AAAA,IACnB;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,MAAM;AAAA,EACR;AACF;AAMO,SAAS,oBAAoB,QAAsC;AACxE,MAAI,WAAO,sBAAS,MAAM;AAE1B,QAAM,UAAU,WAAO,kCAAa,MAAM,CAAC,CAAC;AAE5C,WAAS;AAET,QAAM,WAAW,WAAO,kCAAa,MAAM,CAAC,CAAC;AAC7C,WAAS;AACT,QAAM,YAAY,WAAO,kCAAa,MAAM,CAAC,CAAC;AAC9C,WAAS;AACT,QAAM,aAAa,WAAO,kCAAa,MAAM,CAAC,CAAC;AAC/C,WAAS;AACT,QAAM,UAAU,WAAO,kCAAa,MAAM,CAAC,CAAC;AAC5C,WAAS;AACT,QAAM,WAAW,WAAO,kCAAa,MAAM,EAAE,CAAC;AAC9C,WAAS;AAET,QAAM,YAAQ,kCAAa,MAAM,EAAE;AAEnC,SAAO,uBAAuB;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -64,9 +64,9 @@ function unpackOrderAppendix(packed) {
|
|
|
64
64
|
temp >>= 1n;
|
|
65
65
|
const trigger = Number(bitMaskValue(temp, 2));
|
|
66
66
|
temp >>= 2n;
|
|
67
|
-
const reserved = Number(bitMaskValue(temp,
|
|
68
|
-
temp >>=
|
|
69
|
-
const value = bitMaskValue(temp,
|
|
67
|
+
const reserved = Number(bitMaskValue(temp, 50));
|
|
68
|
+
temp >>= 50n;
|
|
69
|
+
const value = bitMaskValue(temp, 64);
|
|
70
70
|
return mapBitValuesToAppendix({
|
|
71
71
|
value,
|
|
72
72
|
reserved,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/orders/appendix/unpackOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { BigDecimalish, toBigInt } from '../../math';\nimport { unpackTwapOrderAppendixValue } from './appendixTwapValue';\nimport { bitMaskValue } from './bitMaskValue';\nimport { PackedOrderAppendixBits } from './types';\n\nfunction mapBitValuesToAppendix(bits: PackedOrderAppendixBits): OrderAppendix {\n const triggerType = (() => {\n switch (bits.trigger) {\n case 1:\n return 'price';\n case 2:\n return 'twap';\n case 3:\n return 'twap_custom_amounts';\n default:\n return undefined;\n }\n })();\n const orderExecutionType = (() => {\n switch (bits.orderType) {\n case 0:\n return 'default';\n case 1:\n return 'ioc';\n case 2:\n return 'fok';\n case 3:\n return 'post_only';\n default:\n throw new Error(\n `[mapBitValuesToAppendix] Unknown order type: ${bits.orderType}`,\n );\n }\n })();\n const isolatedFields = (() => {\n if (bits.isolated) {\n return { margin: bits.value };\n }\n return undefined;\n })();\n const twapFields = (() => {\n if (triggerType === 'twap' || triggerType === 'twap_custom_amounts') {\n return unpackTwapOrderAppendixValue(bits.value);\n }\n })();\n\n return {\n reduceOnly: !!bits.reduceOnly,\n orderExecutionType,\n triggerType,\n isolated: isolatedFields,\n twap: twapFields,\n };\n}\n\n/**\n * Unpack the OrderAppendix fields from a packed bigint.\n * @param packed\n */\nexport function unpackOrderAppendix(packed: BigDecimalish): OrderAppendix {\n let temp = toBigInt(packed);\n // Bitmasks lowest 8 bits for version\n const version = Number(bitMaskValue(temp, 8));\n // Shift out the version bits\n temp >>= 8n;\n // Repeat for the rest of the fields\n const isolated = Number(bitMaskValue(temp, 1));\n temp >>= 1n;\n const orderType = Number(bitMaskValue(temp, 2));\n temp >>= 2n;\n const reduceOnly = Number(bitMaskValue(temp, 1));\n temp >>= 1n;\n const trigger = Number(bitMaskValue(temp, 2));\n temp >>= 2n;\n const reserved = Number(bitMaskValue(temp,
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/unpackOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { BigDecimalish, toBigInt } from '../../math';\nimport { unpackTwapOrderAppendixValue } from './appendixTwapValue';\nimport { bitMaskValue } from './bitMaskValue';\nimport { PackedOrderAppendixBits } from './types';\n\nfunction mapBitValuesToAppendix(bits: PackedOrderAppendixBits): OrderAppendix {\n const triggerType = (() => {\n switch (bits.trigger) {\n case 1:\n return 'price';\n case 2:\n return 'twap';\n case 3:\n return 'twap_custom_amounts';\n default:\n return undefined;\n }\n })();\n const orderExecutionType = (() => {\n switch (bits.orderType) {\n case 0:\n return 'default';\n case 1:\n return 'ioc';\n case 2:\n return 'fok';\n case 3:\n return 'post_only';\n default:\n throw new Error(\n `[mapBitValuesToAppendix] Unknown order type: ${bits.orderType}`,\n );\n }\n })();\n const isolatedFields = (() => {\n if (bits.isolated) {\n return { margin: bits.value };\n }\n return undefined;\n })();\n const twapFields = (() => {\n if (triggerType === 'twap' || triggerType === 'twap_custom_amounts') {\n return unpackTwapOrderAppendixValue(bits.value);\n }\n })();\n\n return {\n reduceOnly: !!bits.reduceOnly,\n orderExecutionType,\n triggerType,\n isolated: isolatedFields,\n twap: twapFields,\n };\n}\n\n/**\n * Unpack the OrderAppendix fields from a packed bigint.\n * @param packed\n */\nexport function unpackOrderAppendix(packed: BigDecimalish): OrderAppendix {\n let temp = toBigInt(packed);\n // Bitmasks lowest 8 bits for version\n const version = Number(bitMaskValue(temp, 8));\n // Shift out the version bits\n temp >>= 8n;\n // Repeat for the rest of the fields\n const isolated = Number(bitMaskValue(temp, 1));\n temp >>= 1n;\n const orderType = Number(bitMaskValue(temp, 2));\n temp >>= 2n;\n const reduceOnly = Number(bitMaskValue(temp, 1));\n temp >>= 1n;\n const trigger = Number(bitMaskValue(temp, 2));\n temp >>= 2n;\n const reserved = Number(bitMaskValue(temp, 50));\n temp >>= 50n;\n // The remaining bits are the value, which should be 64 bits\n const value = bitMaskValue(temp, 64);\n\n return mapBitValuesToAppendix({\n value,\n reserved,\n trigger,\n reduceOnly,\n orderType,\n isolated,\n version,\n });\n}\n"],"mappings":";;;AACA,SAAwB,gBAAgB;AACxC,SAAS,oCAAoC;AAC7C,SAAS,oBAAoB;AAG7B,SAAS,uBAAuB,MAA8C;AAC5E,QAAM,eAAe,MAAM;AACzB,YAAQ,KAAK,SAAS;AAAA,MACpB,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT;AACE,eAAO;AAAA,IACX;AAAA,EACF,GAAG;AACH,QAAM,sBAAsB,MAAM;AAChC,YAAQ,KAAK,WAAW;AAAA,MACtB,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT;AACE,cAAM,IAAI;AAAA,UACR,gDAAgD,KAAK,SAAS;AAAA,QAChE;AAAA,IACJ;AAAA,EACF,GAAG;AACH,QAAM,kBAAkB,MAAM;AAC5B,QAAI,KAAK,UAAU;AACjB,aAAO,EAAE,QAAQ,KAAK,MAAM;AAAA,IAC9B;AACA,WAAO;AAAA,EACT,GAAG;AACH,QAAM,cAAc,MAAM;AACxB,QAAI,gBAAgB,UAAU,gBAAgB,uBAAuB;AACnE,aAAO,6BAA6B,KAAK,KAAK;AAAA,IAChD;AAAA,EACF,GAAG;AAEH,SAAO;AAAA,IACL,YAAY,CAAC,CAAC,KAAK;AAAA,IACnB;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,MAAM;AAAA,EACR;AACF;AAMO,SAAS,oBAAoB,QAAsC;AACxE,MAAI,OAAO,SAAS,MAAM;AAE1B,QAAM,UAAU,OAAO,aAAa,MAAM,CAAC,CAAC;AAE5C,WAAS;AAET,QAAM,WAAW,OAAO,aAAa,MAAM,CAAC,CAAC;AAC7C,WAAS;AACT,QAAM,YAAY,OAAO,aAAa,MAAM,CAAC,CAAC;AAC9C,WAAS;AACT,QAAM,aAAa,OAAO,aAAa,MAAM,CAAC,CAAC;AAC/C,WAAS;AACT,QAAM,UAAU,OAAO,aAAa,MAAM,CAAC,CAAC;AAC5C,WAAS;AACT,QAAM,WAAW,OAAO,aAAa,MAAM,EAAE,CAAC;AAC9C,WAAS;AAET,QAAM,QAAQ,aAAa,MAAM,EAAE;AAEnC,SAAO,uBAAuB;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nadohq/shared",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.29",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Shared utilities, types, and contract helpers for Nado SDK",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"bignumber.js": "^9.3.0",
|
|
46
46
|
"viem": "*"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "038f80941895e4dffbf4a68bc4f46e6926d110de"
|
|
49
49
|
}
|
|
@@ -2,17 +2,16 @@ import { OrderAppendixTwapFields } from '../../../types/orderAppendixTypes';
|
|
|
2
2
|
import { addDecimals, removeDecimals, toBigInt } from '../../math';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Packs the provided fields into a single
|
|
5
|
+
* Packs the provided fields into a single 64-bit bigint.
|
|
6
6
|
*
|
|
7
7
|
* Bit layout (MSB → LSB):
|
|
8
|
-
* | times | slippage_x6 |
|
|
9
|
-
*
|
|
10
|
-
* |
|
|
11
|
-
* | 32 bits | 32 bits |
|
|
8
|
+
* | times | slippage_x6 |
|
|
9
|
+
* |-----------|-------------|
|
|
10
|
+
* | 63..32 | 31..0 |
|
|
11
|
+
* | 32 bits | 32 bits |
|
|
12
12
|
*
|
|
13
|
-
* - `times` occupies bits
|
|
14
|
-
* - `slippage_x6` occupies bits
|
|
15
|
-
* - `reserved` occupies bits 31..0 (least significant 32 bits)
|
|
13
|
+
* - `times` occupies bits 63..32 (most significant 32 bits)
|
|
14
|
+
* - `slippage_x6` occupies bits 31..0 (least significant 32 bits)
|
|
16
15
|
*/
|
|
17
16
|
export function packTwapOrderAppendixValue({
|
|
18
17
|
numOrders,
|
|
@@ -22,27 +21,23 @@ export function packTwapOrderAppendixValue({
|
|
|
22
21
|
const slippageX6BigInt = toBigInt(addDecimals(slippageFrac, 6));
|
|
23
22
|
|
|
24
23
|
return (
|
|
25
|
-
((numOrdersBigInt & 0xffffffffn) <<
|
|
26
|
-
((slippageX6BigInt & 0xffffffffn) << 32n) |
|
|
27
|
-
// The last reserved 32 bits are set to 0
|
|
28
|
-
(0n & 0xffffffffn)
|
|
24
|
+
((numOrdersBigInt & 0xffffffffn) << 32n) | (slippageX6BigInt & 0xffffffffn)
|
|
29
25
|
);
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
/**
|
|
33
|
-
* Unpacks a
|
|
29
|
+
* Unpacks a 64-bit bigint into its component fields for TWAP orders.
|
|
34
30
|
*
|
|
35
|
-
* @param value
|
|
31
|
+
* @param value 64-bit bigint to unpack
|
|
36
32
|
* @returns Object with:
|
|
37
|
-
* - times: number, from bits
|
|
38
|
-
* - slippage_x6: number, from bits
|
|
39
|
-
* - reserved: number, from bits 31..0
|
|
33
|
+
* - times: number, from bits 63..32
|
|
34
|
+
* - slippage_x6: number, from bits 31..0
|
|
40
35
|
*/
|
|
41
36
|
export function unpackTwapOrderAppendixValue(
|
|
42
37
|
value: bigint,
|
|
43
38
|
): OrderAppendixTwapFields {
|
|
44
|
-
const numOrders = (value >>
|
|
45
|
-
const slippageX6 =
|
|
39
|
+
const numOrders = (value >> 32n) & 0xffffffffn;
|
|
40
|
+
const slippageX6 = value & 0xffffffffn;
|
|
46
41
|
|
|
47
42
|
return {
|
|
48
43
|
numOrders: Number(numOrders),
|
|
@@ -11,7 +11,7 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
11
11
|
};
|
|
12
12
|
const packed = packOrderAppendix(appendix);
|
|
13
13
|
const unpacked = unpackOrderAppendix(packed);
|
|
14
|
-
expect(packed).toBe(
|
|
14
|
+
expect(packed).toBe(4097n);
|
|
15
15
|
expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);
|
|
16
16
|
expect(unpacked.triggerType).toBe(appendix.triggerType);
|
|
17
17
|
expect(unpacked.reduceOnly).toBeFalsy();
|
|
@@ -25,7 +25,7 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
25
25
|
};
|
|
26
26
|
const packed = packOrderAppendix(appendix);
|
|
27
27
|
const unpacked = unpackOrderAppendix(packed);
|
|
28
|
-
expect(packed).toBe(
|
|
28
|
+
expect(packed).toBe(6145n);
|
|
29
29
|
expect(unpacked.reduceOnly).toBe(true);
|
|
30
30
|
});
|
|
31
31
|
|
|
@@ -60,12 +60,12 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
60
60
|
orderExecutionType: 'default',
|
|
61
61
|
triggerType: 'price',
|
|
62
62
|
|
|
63
|
-
isolated: { margin:
|
|
63
|
+
isolated: { margin: 1234567890123n },
|
|
64
64
|
};
|
|
65
65
|
const packed = packOrderAppendix(appendix);
|
|
66
66
|
const unpacked = unpackOrderAppendix(packed);
|
|
67
|
-
expect(packed).toBe(
|
|
68
|
-
expect(unpacked.isolated?.margin).toBe(
|
|
67
|
+
expect(packed).toBe(22773757910718555132477485093121n);
|
|
68
|
+
expect(unpacked.isolated?.margin).toBe(1234567890123n);
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
it('should handle TWAP fields', () => {
|
|
@@ -77,7 +77,7 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
77
77
|
};
|
|
78
78
|
const packed = packOrderAppendix(appendix);
|
|
79
79
|
const unpacked = unpackOrderAppendix(packed);
|
|
80
|
-
expect(packed).toBe(
|
|
80
|
+
expect(packed).toBe(792281717376363744483197591553n);
|
|
81
81
|
expect(unpacked.twap).toMatchObject({ numOrders: 10, slippageFrac: 0.005 });
|
|
82
82
|
});
|
|
83
83
|
|
|
@@ -86,16 +86,16 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
86
86
|
orderExecutionType: 'post_only',
|
|
87
87
|
triggerType: undefined,
|
|
88
88
|
reduceOnly: true,
|
|
89
|
-
isolated: { margin:
|
|
89
|
+
isolated: { margin: 18446744073709551615n }, // 2^64-1
|
|
90
90
|
};
|
|
91
91
|
const packed = packOrderAppendix(appendix);
|
|
92
92
|
const unpacked = unpackOrderAppendix(packed);
|
|
93
93
|
expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);
|
|
94
94
|
expect(unpacked.triggerType).toBe(appendix.triggerType);
|
|
95
95
|
expect(unpacked.reduceOnly).toBe(appendix.reduceOnly);
|
|
96
|
-
expect(unpacked.isolated?.margin).toBe(
|
|
96
|
+
expect(unpacked.isolated?.margin).toBe(18446744073709551615n);
|
|
97
97
|
expect(unpacked.twap).toBe(undefined);
|
|
98
|
-
expect(packed).toBe(
|
|
98
|
+
expect(packed).toBe(340282366920938463444927863358058663681n);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
it('should handle max values for all fields for TWAP orders', () => {
|
|
@@ -104,7 +104,6 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
104
104
|
triggerType: 'twap_custom_amounts',
|
|
105
105
|
reduceOnly: true,
|
|
106
106
|
twap: {
|
|
107
|
-
// max 32-bit unsigned int
|
|
108
107
|
numOrders: 4294967295,
|
|
109
108
|
slippageFrac: 0.000001,
|
|
110
109
|
},
|
|
@@ -116,6 +115,6 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
116
115
|
expect(unpacked.reduceOnly).toBe(appendix.reduceOnly);
|
|
117
116
|
expect(unpacked.twap?.slippageFrac).toBe(0.000001);
|
|
118
117
|
expect(unpacked.twap?.numOrders).toBe(4294967295);
|
|
119
|
-
expect(packed).toBe(
|
|
118
|
+
expect(packed).toBe(340282366841710300967557013911933828609n);
|
|
120
119
|
});
|
|
121
120
|
});
|
|
@@ -48,7 +48,7 @@ function mapOrderAppendixToBitValues(
|
|
|
48
48
|
reduceOnly: appendix.reduceOnly ? 1 : 0,
|
|
49
49
|
orderType,
|
|
50
50
|
isolated: appendix.isolated ? 1 : 0,
|
|
51
|
-
version:
|
|
51
|
+
version: 1,
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -59,9 +59,9 @@ function mapOrderAppendixToBitValues(
|
|
|
59
59
|
export function packOrderAppendix(appendix: OrderAppendix): bigint {
|
|
60
60
|
const bits = mapOrderAppendixToBitValues(appendix);
|
|
61
61
|
|
|
62
|
-
// Ensure value is within
|
|
63
|
-
let packed = bitMaskValue(bits.value,
|
|
64
|
-
packed = (packed <<
|
|
62
|
+
// Ensure value is within 64 bits
|
|
63
|
+
let packed = bitMaskValue(bits.value, 64);
|
|
64
|
+
packed = (packed << 50n) | bitMaskValue(bits.reserved, 50);
|
|
65
65
|
packed = (packed << 2n) | bitMaskValue(bits.trigger, 2);
|
|
66
66
|
packed = (packed << 1n) | bitMaskValue(bits.reduceOnly, 1);
|
|
67
67
|
packed = (packed << 2n) | bitMaskValue(bits.orderType, 2);
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* | value | reserved | trigger | reduceOnly | orderType | isolated | version |
|
|
5
5
|
* |-----------|----------|---------|------------|-----------|----------|---------|
|
|
6
|
-
* | 127..
|
|
7
|
-
* |
|
|
6
|
+
* | 127..64 | 63..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |
|
|
7
|
+
* | 64 bits | 50 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |
|
|
8
8
|
*/
|
|
9
9
|
export interface PackedOrderAppendixBits {
|
|
10
|
-
value: bigint; //
|
|
11
|
-
reserved: number; //
|
|
10
|
+
value: bigint; // 64 bits
|
|
11
|
+
reserved: number; // 50 bits, set to 0
|
|
12
12
|
trigger: number; // 2 bits
|
|
13
13
|
reduceOnly: number; // 1 bit
|
|
14
14
|
orderType: number; // 2 bits
|
|
15
15
|
isolated: number; // 1 bit
|
|
16
|
-
version: number; // 8 bits, set to
|
|
16
|
+
version: number; // 8 bits, set to 1
|
|
17
17
|
}
|
|
@@ -73,10 +73,10 @@ export function unpackOrderAppendix(packed: BigDecimalish): OrderAppendix {
|
|
|
73
73
|
temp >>= 1n;
|
|
74
74
|
const trigger = Number(bitMaskValue(temp, 2));
|
|
75
75
|
temp >>= 2n;
|
|
76
|
-
const reserved = Number(bitMaskValue(temp,
|
|
77
|
-
temp >>=
|
|
78
|
-
// The remaining bits are the value, which should be
|
|
79
|
-
const value = bitMaskValue(temp,
|
|
76
|
+
const reserved = Number(bitMaskValue(temp, 50));
|
|
77
|
+
temp >>= 50n;
|
|
78
|
+
// The remaining bits are the value, which should be 64 bits
|
|
79
|
+
const value = bitMaskValue(temp, 64);
|
|
80
80
|
|
|
81
81
|
return mapBitValuesToAppendix({
|
|
82
82
|
value,
|