@nadohq/shared 0.1.0-alpha.30 → 0.1.0-alpha.32
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/types/orderAppendixTypes.cjs.map +1 -1
- package/dist/types/orderAppendixTypes.d.cts +4 -0
- package/dist/types/orderAppendixTypes.d.ts +4 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.cjs +50 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.cjs.map +1 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.d.cts +26 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.d.ts +26 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.js +31 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.js.map +1 -0
- package/dist/utils/orders/appendix/orderAppendix.test.cjs +5 -5
- package/dist/utils/orders/appendix/orderAppendix.test.cjs.map +1 -1
- package/dist/utils/orders/appendix/orderAppendix.test.js +5 -5
- package/dist/utils/orders/appendix/orderAppendix.test.js.map +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.cjs +2 -2
- package/dist/utils/orders/appendix/packOrderAppendix.cjs.map +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.js +2 -2
- package/dist/utils/orders/appendix/packOrderAppendix.js.map +1 -1
- package/dist/utils/orders/appendix/unpackOrderAppendix.cjs +2 -1
- package/dist/utils/orders/appendix/unpackOrderAppendix.cjs.map +1 -1
- package/dist/utils/orders/appendix/unpackOrderAppendix.js +2 -1
- package/dist/utils/orders/appendix/unpackOrderAppendix.js.map +1 -1
- package/package.json +6 -2
- package/src/types/orderAppendixTypes.ts +4 -0
- package/src/utils/orders/appendix/appendixIsolatedValue.ts +49 -0
- package/src/utils/orders/appendix/orderAppendix.test.ts +5 -5
- package/src/utils/orders/appendix/packOrderAppendix.ts +2 -2
- package/src/utils/orders/appendix/unpackOrderAppendix.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/orderAppendixTypes.ts"],"sourcesContent":["import { BigDecimalish } from '../utils/math';\nimport { OrderExecutionType } from './OrderExecutionType';\n\n/**\n * Encodes whether the order will be sent to the trigger service\n */\nexport type OrderAppendixTriggerType =\n | 'price'\n | 'twap'\n // TWAP with specified order amounts, which will be specified in the Trigger Order itself\n | 'twap_custom_amounts';\n\n/**\n * Fields associated with a TWAP trigger order.\n */\nexport interface OrderAppendixTwapFields {\n /**\n * Number of TWAP orders to be placed.\n */\n numOrders: number;\n /**\n * Maximum slippage on each TWAP order, based on the oracle price at time of order execution.\n * Ex: 0.01 means 1% slippage.\n */\n slippageFrac: number;\n}\n\n/**\n * Fields associated with an isolated order\n */\nexport interface OrderAppendixIsolatedFields {\n /**\n * Amount of margin to transfer into the isolated position.\n */\n margin: BigDecimalish;\n}\n\n/**\n * All the fields encoded by the order appendix\n */\nexport interface OrderAppendix {\n reduceOnly?: boolean;\n orderExecutionType: OrderExecutionType;\n /**\n * Specify the type of trigger that will be used for the order if the order will be sent to the trigger service.\n */\n triggerType?: OrderAppendixTriggerType;\n /**\n * Specify if the order is for an isolated position\n * An order CANNOT be both a TWAP order and an isolated order.\n */\n isolated?: OrderAppendixIsolatedFields;\n /**\n * Specify if the order is a TWAP order\n * An order CANNOT be both a TWAP order and an isolated order.\n */\n twap?: OrderAppendixTwapFields;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/types/orderAppendixTypes.ts"],"sourcesContent":["import { BigDecimalish } from '../utils/math';\nimport { OrderExecutionType } from './OrderExecutionType';\n\n/**\n * Encodes whether the order will be sent to the trigger service\n */\nexport type OrderAppendixTriggerType =\n | 'price'\n | 'twap'\n // TWAP with specified order amounts, which will be specified in the Trigger Order itself\n | 'twap_custom_amounts';\n\n/**\n * Fields associated with a TWAP trigger order.\n */\nexport interface OrderAppendixTwapFields {\n /**\n * Number of TWAP orders to be placed.\n */\n numOrders: number;\n /**\n * Maximum slippage on each TWAP order, based on the oracle price at time of order execution.\n * Ex: 0.01 means 1% slippage.\n */\n slippageFrac: number;\n}\n\n/**\n * Fields associated with an isolated order\n */\nexport interface OrderAppendixIsolatedFields {\n /**\n * Amount of margin to transfer into the isolated position.\n *\n * Implementation Note:\n * Packed appendix uses precision of 6 decimals on backend.\n * SDK automatically converts to/from x18 during packing/unpacking.\n */\n margin: BigDecimalish;\n}\n\n/**\n * All the fields encoded by the order appendix\n */\nexport interface OrderAppendix {\n reduceOnly?: boolean;\n orderExecutionType: OrderExecutionType;\n /**\n * Specify the type of trigger that will be used for the order if the order will be sent to the trigger service.\n */\n triggerType?: OrderAppendixTriggerType;\n /**\n * Specify if the order is for an isolated position\n * An order CANNOT be both a TWAP order and an isolated order.\n */\n isolated?: OrderAppendixIsolatedFields;\n /**\n * Specify if the order is a TWAP order\n * An order CANNOT be both a TWAP order and an isolated order.\n */\n twap?: OrderAppendixTwapFields;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -26,6 +26,10 @@ interface OrderAppendixTwapFields {
|
|
|
26
26
|
interface OrderAppendixIsolatedFields {
|
|
27
27
|
/**
|
|
28
28
|
* Amount of margin to transfer into the isolated position.
|
|
29
|
+
*
|
|
30
|
+
* Implementation Note:
|
|
31
|
+
* Packed appendix uses precision of 6 decimals on backend.
|
|
32
|
+
* SDK automatically converts to/from x18 during packing/unpacking.
|
|
29
33
|
*/
|
|
30
34
|
margin: BigDecimalish;
|
|
31
35
|
}
|
|
@@ -26,6 +26,10 @@ interface OrderAppendixTwapFields {
|
|
|
26
26
|
interface OrderAppendixIsolatedFields {
|
|
27
27
|
/**
|
|
28
28
|
* Amount of margin to transfer into the isolated position.
|
|
29
|
+
*
|
|
30
|
+
* Implementation Note:
|
|
31
|
+
* Packed appendix uses precision of 6 decimals on backend.
|
|
32
|
+
* SDK automatically converts to/from x18 during packing/unpacking.
|
|
29
33
|
*/
|
|
30
34
|
margin: BigDecimalish;
|
|
31
35
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/utils/orders/appendix/appendixIsolatedValue.ts
|
|
21
|
+
var appendixIsolatedValue_exports = {};
|
|
22
|
+
__export(appendixIsolatedValue_exports, {
|
|
23
|
+
packIsolatedOrderAppendixValue: () => packIsolatedOrderAppendixValue,
|
|
24
|
+
unpackIsolatedOrderAppendixValue: () => unpackIsolatedOrderAppendixValue
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(appendixIsolatedValue_exports);
|
|
27
|
+
var import_math = require("../../math/index.cjs");
|
|
28
|
+
var import_bitMaskValue = require("./bitMaskValue.cjs");
|
|
29
|
+
var APPENDIX_V1_ISO_MARGIN_DECIMALS = 6;
|
|
30
|
+
var MARGIN_DECIMAL_ADJUSTMENT = import_math.NADO_PRODUCT_DECIMALS - APPENDIX_V1_ISO_MARGIN_DECIMALS;
|
|
31
|
+
function packIsolatedOrderAppendixValue({
|
|
32
|
+
margin
|
|
33
|
+
}) {
|
|
34
|
+
return (0, import_bitMaskValue.bitMaskValue)(
|
|
35
|
+
(0, import_math.toBigInt)((0, import_math.removeDecimals)(margin, MARGIN_DECIMAL_ADJUSTMENT)),
|
|
36
|
+
64
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
function unpackIsolatedOrderAppendixValue(value) {
|
|
40
|
+
const margin = (0, import_bitMaskValue.bitMaskValue)(value, 64);
|
|
41
|
+
return {
|
|
42
|
+
margin: (0, import_math.toBigInt)((0, import_math.addDecimals)(margin, MARGIN_DECIMAL_ADJUSTMENT))
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
packIsolatedOrderAppendixValue,
|
|
48
|
+
unpackIsolatedOrderAppendixValue
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=appendixIsolatedValue.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/appendixIsolatedValue.ts"],"sourcesContent":["import { OrderAppendixIsolatedFields } from '../../../types';\nimport {\n addDecimals,\n NADO_PRODUCT_DECIMALS,\n removeDecimals,\n toBigInt,\n} from '../../math';\nimport { bitMaskValue } from './bitMaskValue';\n\nconst APPENDIX_V1_ISO_MARGIN_DECIMALS = 6;\n\n/* Appendix v1 uses x6 precision, so we need to adjust precision to/from SDK's usual precision */\nconst MARGIN_DECIMAL_ADJUSTMENT =\n NADO_PRODUCT_DECIMALS - APPENDIX_V1_ISO_MARGIN_DECIMALS;\n\n/**\n * Packs the provided margin into a single 64-bit bigint.\n *\n * Bit layout (MSB → LSB):\n * | margin_x6 |\n * |-----------|\n * | 63..0 |\n * | 64 bits |\n *\n */\nexport function packIsolatedOrderAppendixValue({\n margin,\n}: OrderAppendixIsolatedFields): bigint {\n return bitMaskValue(\n toBigInt(removeDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),\n 64,\n );\n}\n\n/**\n * Unpacks a 64-bit bigint into its component fields for Isolated orders.\n *\n * @param value 64-bit bigint to unpack\n * @returns Object with:\n * - margin_x6: bigint, from bits 63..0\n */\nexport function unpackIsolatedOrderAppendixValue(\n value: bigint,\n): OrderAppendixIsolatedFields {\n const margin = bitMaskValue(value, 64);\n return {\n margin: toBigInt(addDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAKO;AACP,0BAA6B;AAE7B,IAAM,kCAAkC;AAGxC,IAAM,4BACJ,oCAAwB;AAYnB,SAAS,+BAA+B;AAAA,EAC7C;AACF,GAAwC;AACtC,aAAO;AAAA,QACL,0BAAS,4BAAe,QAAQ,yBAAyB,CAAC;AAAA,IAC1D;AAAA,EACF;AACF;AASO,SAAS,iCACd,OAC6B;AAC7B,QAAM,aAAS,kCAAa,OAAO,EAAE;AACrC,SAAO;AAAA,IACL,YAAQ,0BAAS,yBAAY,QAAQ,yBAAyB,CAAC;AAAA,EACjE;AACF;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { OrderAppendixIsolatedFields } from '../../../types/orderAppendixTypes.cjs';
|
|
2
|
+
import '../../math/bigDecimal.cjs';
|
|
3
|
+
import 'bignumber.js';
|
|
4
|
+
import '../../../types/OrderExecutionType.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Packs the provided margin into a single 64-bit bigint.
|
|
8
|
+
*
|
|
9
|
+
* Bit layout (MSB → LSB):
|
|
10
|
+
* | margin_x6 |
|
|
11
|
+
* |-----------|
|
|
12
|
+
* | 63..0 |
|
|
13
|
+
* | 64 bits |
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
declare function packIsolatedOrderAppendixValue({ margin, }: OrderAppendixIsolatedFields): bigint;
|
|
17
|
+
/**
|
|
18
|
+
* Unpacks a 64-bit bigint into its component fields for Isolated orders.
|
|
19
|
+
*
|
|
20
|
+
* @param value 64-bit bigint to unpack
|
|
21
|
+
* @returns Object with:
|
|
22
|
+
* - margin_x6: bigint, from bits 63..0
|
|
23
|
+
*/
|
|
24
|
+
declare function unpackIsolatedOrderAppendixValue(value: bigint): OrderAppendixIsolatedFields;
|
|
25
|
+
|
|
26
|
+
export { packIsolatedOrderAppendixValue, unpackIsolatedOrderAppendixValue };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { OrderAppendixIsolatedFields } from '../../../types/orderAppendixTypes.js';
|
|
2
|
+
import '../../math/bigDecimal.js';
|
|
3
|
+
import 'bignumber.js';
|
|
4
|
+
import '../../../types/OrderExecutionType.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Packs the provided margin into a single 64-bit bigint.
|
|
8
|
+
*
|
|
9
|
+
* Bit layout (MSB → LSB):
|
|
10
|
+
* | margin_x6 |
|
|
11
|
+
* |-----------|
|
|
12
|
+
* | 63..0 |
|
|
13
|
+
* | 64 bits |
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
declare function packIsolatedOrderAppendixValue({ margin, }: OrderAppendixIsolatedFields): bigint;
|
|
17
|
+
/**
|
|
18
|
+
* Unpacks a 64-bit bigint into its component fields for Isolated orders.
|
|
19
|
+
*
|
|
20
|
+
* @param value 64-bit bigint to unpack
|
|
21
|
+
* @returns Object with:
|
|
22
|
+
* - margin_x6: bigint, from bits 63..0
|
|
23
|
+
*/
|
|
24
|
+
declare function unpackIsolatedOrderAppendixValue(value: bigint): OrderAppendixIsolatedFields;
|
|
25
|
+
|
|
26
|
+
export { packIsolatedOrderAppendixValue, unpackIsolatedOrderAppendixValue };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "../../../chunk-5WRI5ZAA.js";
|
|
2
|
+
|
|
3
|
+
// src/utils/orders/appendix/appendixIsolatedValue.ts
|
|
4
|
+
import {
|
|
5
|
+
addDecimals,
|
|
6
|
+
NADO_PRODUCT_DECIMALS,
|
|
7
|
+
removeDecimals,
|
|
8
|
+
toBigInt
|
|
9
|
+
} from "../../math/index.js";
|
|
10
|
+
import { bitMaskValue } from "./bitMaskValue.js";
|
|
11
|
+
var APPENDIX_V1_ISO_MARGIN_DECIMALS = 6;
|
|
12
|
+
var MARGIN_DECIMAL_ADJUSTMENT = NADO_PRODUCT_DECIMALS - APPENDIX_V1_ISO_MARGIN_DECIMALS;
|
|
13
|
+
function packIsolatedOrderAppendixValue({
|
|
14
|
+
margin
|
|
15
|
+
}) {
|
|
16
|
+
return bitMaskValue(
|
|
17
|
+
toBigInt(removeDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),
|
|
18
|
+
64
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
function unpackIsolatedOrderAppendixValue(value) {
|
|
22
|
+
const margin = bitMaskValue(value, 64);
|
|
23
|
+
return {
|
|
24
|
+
margin: toBigInt(addDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT))
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
packIsolatedOrderAppendixValue,
|
|
29
|
+
unpackIsolatedOrderAppendixValue
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=appendixIsolatedValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/appendixIsolatedValue.ts"],"sourcesContent":["import { OrderAppendixIsolatedFields } from '../../../types';\nimport {\n addDecimals,\n NADO_PRODUCT_DECIMALS,\n removeDecimals,\n toBigInt,\n} from '../../math';\nimport { bitMaskValue } from './bitMaskValue';\n\nconst APPENDIX_V1_ISO_MARGIN_DECIMALS = 6;\n\n/* Appendix v1 uses x6 precision, so we need to adjust precision to/from SDK's usual precision */\nconst MARGIN_DECIMAL_ADJUSTMENT =\n NADO_PRODUCT_DECIMALS - APPENDIX_V1_ISO_MARGIN_DECIMALS;\n\n/**\n * Packs the provided margin into a single 64-bit bigint.\n *\n * Bit layout (MSB → LSB):\n * | margin_x6 |\n * |-----------|\n * | 63..0 |\n * | 64 bits |\n *\n */\nexport function packIsolatedOrderAppendixValue({\n margin,\n}: OrderAppendixIsolatedFields): bigint {\n return bitMaskValue(\n toBigInt(removeDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),\n 64,\n );\n}\n\n/**\n * Unpacks a 64-bit bigint into its component fields for Isolated orders.\n *\n * @param value 64-bit bigint to unpack\n * @returns Object with:\n * - margin_x6: bigint, from bits 63..0\n */\nexport function unpackIsolatedOrderAppendixValue(\n value: bigint,\n): OrderAppendixIsolatedFields {\n const margin = bitMaskValue(value, 64);\n return {\n margin: toBigInt(addDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),\n };\n}\n"],"mappings":";;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAE7B,IAAM,kCAAkC;AAGxC,IAAM,4BACJ,wBAAwB;AAYnB,SAAS,+BAA+B;AAAA,EAC7C;AACF,GAAwC;AACtC,SAAO;AAAA,IACL,SAAS,eAAe,QAAQ,yBAAyB,CAAC;AAAA,IAC1D;AAAA,EACF;AACF;AASO,SAAS,iCACd,OAC6B;AAC7B,QAAM,SAAS,aAAa,OAAO,EAAE;AACrC,SAAO;AAAA,IACL,QAAQ,SAAS,YAAY,QAAQ,yBAAyB,CAAC;AAAA,EACjE;AACF;","names":[]}
|
|
@@ -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: 12345678901000000000000n }
|
|
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(227737579102942800187821658369n);
|
|
102
|
+
(0, import_globals.expect)(unpacked.isolated?.margin).toBe(appendix.isolated?.margin);
|
|
103
103
|
});
|
|
104
104
|
(0, import_globals.it)("should handle TWAP fields", () => {
|
|
105
105
|
const appendix = {
|
|
@@ -125,9 +125,9 @@ var import_unpackOrderAppendix = require("./unpackOrderAppendix.cjs");
|
|
|
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(18446744000000000000n);
|
|
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(340282365561237229015142145n);
|
|
131
131
|
});
|
|
132
132
|
(0, import_globals.it)("should handle max values for all fields for TWAP orders", () => {
|
|
133
133
|
const appendix = {
|
|
@@ -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(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:
|
|
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: 12345678901000000000000n },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(227737579102942800187821658369n);\n expect(unpacked.isolated?.margin).toBe(appendix.isolated?.margin);\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(18446744000000000000n);\n expect(unpacked.twap).toBe(undefined);\n expect(packed).toBe(340282365561237229015142145n);\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,iCAAoC;AAAA,IAEpC,yBAAS,mCAAmC,MAAM;AAChD,yBAAG,oEAAoE,MAAM;AAC3E,UAAM,WAA0B;AAAA,MAC9B,oBAAoB;AAAA,MACpB,aAAa;AAAA,IACf;AACA,UAAM,aAAS,4CAAkB,QAAQ;AACzC,UAAM,eAAW,gDAAoB,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,aAAS,4CAAkB,QAAQ;AACzC,UAAM,eAAW,gDAAoB,MAAM;AAC3C,+BAAO,MAAM,EAAE,KAAK,KAAK;A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
|
|
@@ -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: 12345678901000000000000n }
|
|
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(227737579102942800187821658369n);
|
|
69
|
+
(0, import_globals.expect)(unpacked.isolated?.margin).toBe(appendix.isolated?.margin);
|
|
70
70
|
});
|
|
71
71
|
(0, import_globals.it)("should handle TWAP fields", () => {
|
|
72
72
|
const appendix = {
|
|
@@ -92,9 +92,9 @@ import { unpackOrderAppendix } from "./unpackOrderAppendix.js";
|
|
|
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(18446744000000000000n);
|
|
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(340282365561237229015142145n);
|
|
98
98
|
});
|
|
99
99
|
(0, import_globals.it)("should handle max values for all fields for TWAP orders", () => {
|
|
100
100
|
const appendix = {
|
|
@@ -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(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:
|
|
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: 12345678901000000000000n },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(packed).toBe(227737579102942800187821658369n);\n expect(unpacked.isolated?.margin).toBe(appendix.isolated?.margin);\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(18446744000000000000n);\n expect(unpacked.twap).toBe(undefined);\n expect(packed).toBe(340282365561237229015142145n);\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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Aa;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":[]}
|
|
@@ -23,7 +23,7 @@ __export(packOrderAppendix_exports, {
|
|
|
23
23
|
packOrderAppendix: () => packOrderAppendix
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(packOrderAppendix_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_appendixIsolatedValue = require("./appendixIsolatedValue.cjs");
|
|
27
27
|
var import_appendixTwapValue = require("./appendixTwapValue.cjs");
|
|
28
28
|
var import_bitMaskValue = require("./bitMaskValue.cjs");
|
|
29
29
|
function mapOrderAppendixToBitValues(appendix) {
|
|
@@ -32,7 +32,7 @@ function mapOrderAppendixToBitValues(appendix) {
|
|
|
32
32
|
return (0, import_appendixTwapValue.packTwapOrderAppendixValue)(appendix.twap);
|
|
33
33
|
}
|
|
34
34
|
if (appendix.isolated) {
|
|
35
|
-
return (0,
|
|
35
|
+
return (0, import_appendixIsolatedValue.packIsolatedOrderAppendixValue)(appendix.isolated);
|
|
36
36
|
}
|
|
37
37
|
return 0n;
|
|
38
38
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/orders/appendix/packOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/packOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { packIsolatedOrderAppendixValue } from './appendixIsolatedValue';\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 packIsolatedOrderAppendixValue(appendix.isolated);\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;A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|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../../../chunk-5WRI5ZAA.js";
|
|
2
2
|
|
|
3
3
|
// src/utils/orders/appendix/packOrderAppendix.ts
|
|
4
|
-
import {
|
|
4
|
+
import { packIsolatedOrderAppendixValue } from "./appendixIsolatedValue.js";
|
|
5
5
|
import { packTwapOrderAppendixValue } from "./appendixTwapValue.js";
|
|
6
6
|
import { bitMaskValue } from "./bitMaskValue.js";
|
|
7
7
|
function mapOrderAppendixToBitValues(appendix) {
|
|
@@ -10,7 +10,7 @@ function mapOrderAppendixToBitValues(appendix) {
|
|
|
10
10
|
return packTwapOrderAppendixValue(appendix.twap);
|
|
11
11
|
}
|
|
12
12
|
if (appendix.isolated) {
|
|
13
|
-
return
|
|
13
|
+
return packIsolatedOrderAppendixValue(appendix.isolated);
|
|
14
14
|
}
|
|
15
15
|
return 0n;
|
|
16
16
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/orders/appendix/packOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/packOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { packIsolatedOrderAppendixValue } from './appendixIsolatedValue';\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 packIsolatedOrderAppendixValue(appendix.isolated);\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,sCAAsC;AAC/C,SAAS,kCAAkC;AAC3C,SAAS,oBAAoB;AAG7B,SAAS,4BACP,UACyB;AACzB,QAAM,SAAS,MAAM;AACnB,QAAI,SAAS,MAAM;AACjB,aAAO,2BAA2B,SAAS,IAAI;AAAA,IACjD;AACA,QAAI,SAAS,UAAU;AACrB,aAAO,+BAA+B,SAAS,QAAQ;AAAA,IACzD;AACA,WAAO;AAAA,EACT,GAAG;AACH,QAAM,WAAW,MAAM;AACrB,YAAQ,SAAS,aAAa;AAAA,MAC5B,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT;AACE,eAAO;AAAA,IACX;AAAA,EACF,GAAG;AACH,QAAM,aAAa,MAAM;AACvB,YAAQ,SAAS,oBAAoB;AAAA,MACnC,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,IACX;AAAA,EACF,GAAG;AAEH,SAAO;AAAA,IACL;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,YAAY,SAAS,aAAa,IAAI;AAAA,IACtC;AAAA,IACA,UAAU,SAAS,WAAW,IAAI;AAAA,IAClC,SAAS;AAAA,EACX;AACF;AAMO,SAAS,kBAAkB,UAAiC;AACjE,QAAM,OAAO,4BAA4B,QAAQ;AAGjD,MAAI,SAAS,aAAa,KAAK,OAAO,EAAE;AACxC,WAAU,UAAU,MAAO,aAAa,KAAK,UAAU,EAAE;AACzD,WAAU,UAAU,KAAM,aAAa,KAAK,SAAS,CAAC;AACtD,WAAU,UAAU,KAAM,aAAa,KAAK,YAAY,CAAC;AACzD,WAAU,UAAU,KAAM,aAAa,KAAK,WAAW,CAAC;AACxD,WAAU,UAAU,KAAM,aAAa,KAAK,UAAU,CAAC;AACvD,WAAU,UAAU,KAAM,aAAa,KAAK,SAAS,CAAC;AACtD,SAAO;AACT;","names":[]}
|
|
@@ -24,6 +24,7 @@ __export(unpackOrderAppendix_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(unpackOrderAppendix_exports);
|
|
26
26
|
var import_math = require("../../math/index.cjs");
|
|
27
|
+
var import_appendixIsolatedValue = require("./appendixIsolatedValue.cjs");
|
|
27
28
|
var import_appendixTwapValue = require("./appendixTwapValue.cjs");
|
|
28
29
|
var import_bitMaskValue = require("./bitMaskValue.cjs");
|
|
29
30
|
function mapBitValuesToAppendix(bits) {
|
|
@@ -57,7 +58,7 @@ function mapBitValuesToAppendix(bits) {
|
|
|
57
58
|
})();
|
|
58
59
|
const isolatedFields = (() => {
|
|
59
60
|
if (bits.isolated) {
|
|
60
|
-
return
|
|
61
|
+
return (0, import_appendixIsolatedValue.unpackIsolatedOrderAppendixValue)(bits.value);
|
|
61
62
|
}
|
|
62
63
|
return void 0;
|
|
63
64
|
})();
|
|
@@ -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
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/unpackOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { BigDecimalish, toBigInt } from '../../math';\nimport { unpackIsolatedOrderAppendixValue } from './appendixIsolatedValue';\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 unpackIsolatedOrderAppendixValue(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,mCAAiD;AACjD,+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,iBAAO,+DAAiC,KAAK,KAAK;AAAA,IACpD;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":[]}
|
|
@@ -2,6 +2,7 @@ import "../../../chunk-5WRI5ZAA.js";
|
|
|
2
2
|
|
|
3
3
|
// src/utils/orders/appendix/unpackOrderAppendix.ts
|
|
4
4
|
import { toBigInt } from "../../math/index.js";
|
|
5
|
+
import { unpackIsolatedOrderAppendixValue } from "./appendixIsolatedValue.js";
|
|
5
6
|
import { unpackTwapOrderAppendixValue } from "./appendixTwapValue.js";
|
|
6
7
|
import { bitMaskValue } from "./bitMaskValue.js";
|
|
7
8
|
function mapBitValuesToAppendix(bits) {
|
|
@@ -35,7 +36,7 @@ function mapBitValuesToAppendix(bits) {
|
|
|
35
36
|
})();
|
|
36
37
|
const isolatedFields = (() => {
|
|
37
38
|
if (bits.isolated) {
|
|
38
|
-
return
|
|
39
|
+
return unpackIsolatedOrderAppendixValue(bits.value);
|
|
39
40
|
}
|
|
40
41
|
return void 0;
|
|
41
42
|
})();
|
|
@@ -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
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/orders/appendix/unpackOrderAppendix.ts"],"sourcesContent":["import { OrderAppendix } from '../../../types/orderAppendixTypes';\nimport { BigDecimalish, toBigInt } from '../../math';\nimport { unpackIsolatedOrderAppendixValue } from './appendixIsolatedValue';\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 unpackIsolatedOrderAppendixValue(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,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M,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.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Shared utilities, types, and contract helpers for Nado SDK",
|
|
@@ -36,6 +36,10 @@
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
|
+
"react-native": "./dist/index.js",
|
|
40
|
+
"main": "./dist/index.cjs",
|
|
41
|
+
"module": "./dist/index.js",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
39
43
|
"peerDependencies": {
|
|
40
44
|
"bignumber.js": "^9.3.0",
|
|
41
45
|
"viem": "*"
|
|
@@ -45,5 +49,5 @@
|
|
|
45
49
|
"bignumber.js": "^9.3.0",
|
|
46
50
|
"viem": "*"
|
|
47
51
|
},
|
|
48
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "af3e125a5791069b1af98481cd36397ffb405951"
|
|
49
53
|
}
|
|
@@ -31,6 +31,10 @@ export interface OrderAppendixTwapFields {
|
|
|
31
31
|
export interface OrderAppendixIsolatedFields {
|
|
32
32
|
/**
|
|
33
33
|
* Amount of margin to transfer into the isolated position.
|
|
34
|
+
*
|
|
35
|
+
* Implementation Note:
|
|
36
|
+
* Packed appendix uses precision of 6 decimals on backend.
|
|
37
|
+
* SDK automatically converts to/from x18 during packing/unpacking.
|
|
34
38
|
*/
|
|
35
39
|
margin: BigDecimalish;
|
|
36
40
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { OrderAppendixIsolatedFields } from '../../../types';
|
|
2
|
+
import {
|
|
3
|
+
addDecimals,
|
|
4
|
+
NADO_PRODUCT_DECIMALS,
|
|
5
|
+
removeDecimals,
|
|
6
|
+
toBigInt,
|
|
7
|
+
} from '../../math';
|
|
8
|
+
import { bitMaskValue } from './bitMaskValue';
|
|
9
|
+
|
|
10
|
+
const APPENDIX_V1_ISO_MARGIN_DECIMALS = 6;
|
|
11
|
+
|
|
12
|
+
/* Appendix v1 uses x6 precision, so we need to adjust precision to/from SDK's usual precision */
|
|
13
|
+
const MARGIN_DECIMAL_ADJUSTMENT =
|
|
14
|
+
NADO_PRODUCT_DECIMALS - APPENDIX_V1_ISO_MARGIN_DECIMALS;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Packs the provided margin into a single 64-bit bigint.
|
|
18
|
+
*
|
|
19
|
+
* Bit layout (MSB → LSB):
|
|
20
|
+
* | margin_x6 |
|
|
21
|
+
* |-----------|
|
|
22
|
+
* | 63..0 |
|
|
23
|
+
* | 64 bits |
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
export function packIsolatedOrderAppendixValue({
|
|
27
|
+
margin,
|
|
28
|
+
}: OrderAppendixIsolatedFields): bigint {
|
|
29
|
+
return bitMaskValue(
|
|
30
|
+
toBigInt(removeDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),
|
|
31
|
+
64,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Unpacks a 64-bit bigint into its component fields for Isolated orders.
|
|
37
|
+
*
|
|
38
|
+
* @param value 64-bit bigint to unpack
|
|
39
|
+
* @returns Object with:
|
|
40
|
+
* - margin_x6: bigint, from bits 63..0
|
|
41
|
+
*/
|
|
42
|
+
export function unpackIsolatedOrderAppendixValue(
|
|
43
|
+
value: bigint,
|
|
44
|
+
): OrderAppendixIsolatedFields {
|
|
45
|
+
const margin = bitMaskValue(value, 64);
|
|
46
|
+
return {
|
|
47
|
+
margin: toBigInt(addDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -60,12 +60,12 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
60
60
|
orderExecutionType: 'default',
|
|
61
61
|
triggerType: 'price',
|
|
62
62
|
|
|
63
|
-
isolated: { margin:
|
|
63
|
+
isolated: { margin: 12345678901000000000000n },
|
|
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(227737579102942800187821658369n);
|
|
68
|
+
expect(unpacked.isolated?.margin).toBe(appendix.isolated?.margin);
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
it('should handle TWAP fields', () => {
|
|
@@ -93,9 +93,9 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
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(18446744000000000000n);
|
|
97
97
|
expect(unpacked.twap).toBe(undefined);
|
|
98
|
-
expect(packed).toBe(
|
|
98
|
+
expect(packed).toBe(340282365561237229015142145n);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
it('should handle max values for all fields for TWAP orders', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OrderAppendix } from '../../../types/orderAppendixTypes';
|
|
2
|
-
import {
|
|
2
|
+
import { packIsolatedOrderAppendixValue } from './appendixIsolatedValue';
|
|
3
3
|
import { packTwapOrderAppendixValue } from './appendixTwapValue';
|
|
4
4
|
import { bitMaskValue } from './bitMaskValue';
|
|
5
5
|
import { PackedOrderAppendixBits } from './types';
|
|
@@ -12,7 +12,7 @@ function mapOrderAppendixToBitValues(
|
|
|
12
12
|
return packTwapOrderAppendixValue(appendix.twap);
|
|
13
13
|
}
|
|
14
14
|
if (appendix.isolated) {
|
|
15
|
-
return
|
|
15
|
+
return packIsolatedOrderAppendixValue(appendix.isolated);
|
|
16
16
|
}
|
|
17
17
|
return 0n;
|
|
18
18
|
})();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OrderAppendix } from '../../../types/orderAppendixTypes';
|
|
2
2
|
import { BigDecimalish, toBigInt } from '../../math';
|
|
3
|
+
import { unpackIsolatedOrderAppendixValue } from './appendixIsolatedValue';
|
|
3
4
|
import { unpackTwapOrderAppendixValue } from './appendixTwapValue';
|
|
4
5
|
import { bitMaskValue } from './bitMaskValue';
|
|
5
6
|
import { PackedOrderAppendixBits } from './types';
|
|
@@ -35,7 +36,7 @@ function mapBitValuesToAppendix(bits: PackedOrderAppendixBits): OrderAppendix {
|
|
|
35
36
|
})();
|
|
36
37
|
const isolatedFields = (() => {
|
|
37
38
|
if (bits.isolated) {
|
|
38
|
-
return
|
|
39
|
+
return unpackIsolatedOrderAppendixValue(bits.value);
|
|
39
40
|
}
|
|
40
41
|
return undefined;
|
|
41
42
|
})();
|