@nadohq/shared 0.1.0-alpha.46 → 0.1.0-alpha.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/encoding/encoding.cjs +21 -0
  2. package/dist/encoding/encoding.cjs.map +1 -1
  3. package/dist/encoding/encoding.d.cts +26 -2
  4. package/dist/encoding/encoding.d.ts +26 -2
  5. package/dist/encoding/encoding.js +24 -1
  6. package/dist/encoding/encoding.js.map +1 -1
  7. package/dist/encoding/index.d.cts +2 -2
  8. package/dist/encoding/index.d.ts +2 -2
  9. package/dist/index.d.cts +2 -2
  10. package/dist/index.d.ts +2 -2
  11. package/dist/types/index.d.cts +1 -1
  12. package/dist/types/index.d.ts +1 -1
  13. package/dist/types/orderAppendixTypes.cjs.map +1 -1
  14. package/dist/types/orderAppendixTypes.d.cts +21 -1
  15. package/dist/types/orderAppendixTypes.d.ts +21 -1
  16. package/dist/utils/orders/appendix/orderAppendix.test.cjs +54 -0
  17. package/dist/utils/orders/appendix/orderAppendix.test.cjs.map +1 -1
  18. package/dist/utils/orders/appendix/orderAppendix.test.js +54 -0
  19. package/dist/utils/orders/appendix/orderAppendix.test.js.map +1 -1
  20. package/dist/utils/orders/appendix/packOrderAppendix.cjs +5 -1
  21. package/dist/utils/orders/appendix/packOrderAppendix.cjs.map +1 -1
  22. package/dist/utils/orders/appendix/packOrderAppendix.js +5 -1
  23. package/dist/utils/orders/appendix/packOrderAppendix.js.map +1 -1
  24. package/dist/utils/orders/appendix/types.cjs.map +1 -1
  25. package/dist/utils/orders/appendix/types.d.cts +6 -4
  26. package/dist/utils/orders/appendix/types.d.ts +6 -4
  27. package/dist/utils/orders/appendix/unpackOrderAppendix.cjs +19 -3
  28. package/dist/utils/orders/appendix/unpackOrderAppendix.cjs.map +1 -1
  29. package/dist/utils/orders/appendix/unpackOrderAppendix.js +19 -3
  30. package/dist/utils/orders/appendix/unpackOrderAppendix.js.map +1 -1
  31. package/package.json +2 -2
  32. package/src/encoding/encoding.ts +43 -1
  33. package/src/types/orderAppendixTypes.ts +21 -0
  34. package/src/utils/orders/appendix/orderAppendix.test.ts +58 -0
  35. package/src/utils/orders/appendix/packOrderAppendix.ts +5 -1
  36. package/src/utils/orders/appendix/types.ts +7 -5
  37. package/src/utils/orders/appendix/unpackOrderAppendix.ts +18 -2
@@ -20,12 +20,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/encoding/encoding.ts
21
21
  var encoding_exports = {};
22
22
  __export(encoding_exports, {
23
+ SlowModeTxType: () => SlowModeTxType,
24
+ encodeClaimBuilderFeeTx: () => encodeClaimBuilderFeeTx,
23
25
  encodeSignedOrder: () => encodeSignedOrder,
24
26
  encodeSignedWithdrawCollateralTx: () => encodeSignedWithdrawCollateralTx
25
27
  });
26
28
  module.exports = __toCommonJS(encoding_exports);
27
29
  var import_viem = require("viem");
28
30
  var import_utils = require("../utils/index.cjs");
31
+ var SlowModeTxType = /* @__PURE__ */ ((SlowModeTxType2) => {
32
+ SlowModeTxType2[SlowModeTxType2["DepositCollateral"] = 1] = "DepositCollateral";
33
+ SlowModeTxType2[SlowModeTxType2["WithdrawCollateral"] = 2] = "WithdrawCollateral";
34
+ SlowModeTxType2[SlowModeTxType2["LinkSigner"] = 13] = "LinkSigner";
35
+ SlowModeTxType2[SlowModeTxType2["ClaimBuilderFee"] = 31] = "ClaimBuilderFee";
36
+ return SlowModeTxType2;
37
+ })(SlowModeTxType || {});
29
38
  function encodeSignedWithdrawCollateralTx(signed) {
30
39
  return (0, import_viem.encodeAbiParameters)(
31
40
  (0, import_viem.parseAbiParameters)(
@@ -65,8 +74,20 @@ function encodeSignedOrder(signed) {
65
74
  ]
66
75
  );
67
76
  }
77
+ function encodeClaimBuilderFeeTx(params) {
78
+ const txBytes = (0, import_viem.encodeAbiParameters)(
79
+ (0, import_viem.parseAbiParameters)("bytes32 sender, uint32 builderId"),
80
+ [params.sender, params.builderId]
81
+ );
82
+ return (0, import_viem.encodePacked)(
83
+ ["uint8", "bytes"],
84
+ [31 /* ClaimBuilderFee */, txBytes]
85
+ );
86
+ }
68
87
  // Annotate the CommonJS export names for ESM import in node:
69
88
  0 && (module.exports = {
89
+ SlowModeTxType,
90
+ encodeClaimBuilderFeeTx,
70
91
  encodeSignedOrder,
71
92
  encodeSignedWithdrawCollateralTx
72
93
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/encoding/encoding.ts"],"sourcesContent":["import { encodeAbiParameters, parseAbiParameters } from 'viem';\nimport {\n EIP712WithdrawCollateralParams,\n SignedEIP712OrderParams,\n SignedTx,\n} from '../eip712';\nimport { addDecimals, toBigInt } from '../utils';\n\nexport function encodeSignedWithdrawCollateralTx(\n signed: SignedTx<EIP712WithdrawCollateralParams>,\n) {\n return encodeAbiParameters(\n parseAbiParameters(\n '(tuple(address sender, string subaccountName, uint32 productId, uint128 amount, uint64 nonce), bytes signature)',\n ),\n [\n [\n [\n signed.tx.subaccountOwner,\n signed.tx.subaccountName,\n signed.tx.productId,\n signed.tx.amount,\n signed.tx.nonce,\n ],\n signed.signature,\n ],\n ],\n );\n}\n\nexport function encodeSignedOrder(signed: SignedEIP712OrderParams) {\n return encodeAbiParameters(\n parseAbiParameters(\n '(tuple(tuple(address sender, string subaccountName, int128 priceX18, int128 amount, uint64 expiration, uint64 nonce), bytes signature))',\n ),\n [\n [\n [\n signed.order.subaccountOwner,\n signed.order.subaccountName,\n toBigInt(addDecimals(signed.order.price)),\n signed.order.amount,\n signed.order.expiration,\n signed.order.nonce,\n ],\n signed.signature,\n ],\n ],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwD;AAMxD,mBAAsC;AAE/B,SAAS,iCACd,QACA;AACA,aAAO;AAAA,QACL;AAAA,MACE;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,QACE;AAAA,UACE,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,QACZ;AAAA,QACA,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,kBAAkB,QAAiC;AACjE,aAAO;AAAA,QACL;AAAA,MACE;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,QACE;AAAA,UACE,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,cACb,2BAAS,0BAAY,OAAO,MAAM,KAAK,CAAC;AAAA,UACxC,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,QACf;AAAA,QACA,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/encoding/encoding.ts"],"sourcesContent":["import {\n encodeAbiParameters,\n encodePacked,\n parseAbiParameters,\n type Hex,\n} from 'viem';\nimport {\n EIP712WithdrawCollateralParams,\n SignedEIP712OrderParams,\n SignedTx,\n} from '../eip712';\nimport { addDecimals, toBigInt } from '../utils';\n\n/**\n * Transaction type identifiers for slow mode transactions.\n */\nexport enum SlowModeTxType {\n DepositCollateral = 1,\n WithdrawCollateral = 2,\n LinkSigner = 13,\n ClaimBuilderFee = 31,\n}\n\nexport function encodeSignedWithdrawCollateralTx(\n signed: SignedTx<EIP712WithdrawCollateralParams>,\n) {\n return encodeAbiParameters(\n parseAbiParameters(\n '(tuple(address sender, string subaccountName, uint32 productId, uint128 amount, uint64 nonce), bytes signature)',\n ),\n [\n [\n [\n signed.tx.subaccountOwner,\n signed.tx.subaccountName,\n signed.tx.productId,\n signed.tx.amount,\n signed.tx.nonce,\n ],\n signed.signature,\n ],\n ],\n );\n}\n\nexport function encodeSignedOrder(signed: SignedEIP712OrderParams) {\n return encodeAbiParameters(\n parseAbiParameters(\n '(tuple(tuple(address sender, string subaccountName, int128 priceX18, int128 amount, uint64 expiration, uint64 nonce), bytes signature))',\n ),\n [\n [\n [\n signed.order.subaccountOwner,\n signed.order.subaccountName,\n toBigInt(addDecimals(signed.order.price)),\n signed.order.amount,\n signed.order.expiration,\n signed.order.nonce,\n ],\n signed.signature,\n ],\n ],\n );\n}\n\nexport interface ClaimBuilderFeeParams {\n /** The sender subaccount as bytes32 */\n sender: Hex;\n /** The builder ID to claim fees for */\n builderId: number;\n}\n\n/**\n * Encodes a ClaimBuilderFee slow mode transaction.\n *\n * Format: [tx_type_byte] + [abi_encoded_params]\n *\n * @param params - The claim builder fee parameters\n * @returns The encoded transaction bytes ready to submit via endpoint.submitSlowModeTransaction\n */\nexport function encodeClaimBuilderFeeTx(params: ClaimBuilderFeeParams): Hex {\n const txBytes = encodeAbiParameters(\n parseAbiParameters('bytes32 sender, uint32 builderId'),\n [params.sender, params.builderId],\n );\n\n return encodePacked(\n ['uint8', 'bytes'],\n [SlowModeTxType.ClaimBuilderFee, txBytes],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAKO;AAMP,mBAAsC;AAK/B,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gCAAA,uBAAoB,KAApB;AACA,EAAAA,gCAAA,wBAAqB,KAArB;AACA,EAAAA,gCAAA,gBAAa,MAAb;AACA,EAAAA,gCAAA,qBAAkB,MAAlB;AAJU,SAAAA;AAAA,GAAA;AAOL,SAAS,iCACd,QACA;AACA,aAAO;AAAA,QACL;AAAA,MACE;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,QACE;AAAA,UACE,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,QACZ;AAAA,QACA,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,kBAAkB,QAAiC;AACjE,aAAO;AAAA,QACL;AAAA,MACE;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,QACE;AAAA,UACE,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,cACb,2BAAS,0BAAY,OAAO,MAAM,KAAK,CAAC;AAAA,UACxC,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,QACf;AAAA,QACA,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAiBO,SAAS,wBAAwB,QAAoC;AAC1E,QAAM,cAAU;AAAA,QACd,gCAAmB,kCAAkC;AAAA,IACrD,CAAC,OAAO,QAAQ,OAAO,SAAS;AAAA,EAClC;AAEA,aAAO;AAAA,IACL,CAAC,SAAS,OAAO;AAAA,IACjB,CAAC,0BAAgC,OAAO;AAAA,EAC1C;AACF;","names":["SlowModeTxType"]}
@@ -1,11 +1,35 @@
1
+ import { Hex } from 'viem';
1
2
  import { SignedEIP712OrderParams, SignedTx, EIP712WithdrawCollateralParams } from '../eip712/signatureParamTypes.cjs';
2
- import 'viem';
3
3
  import '../types/subaccountTypes.cjs';
4
4
  import '../types/bytes.cjs';
5
5
  import '../utils/math/bigDecimal.cjs';
6
6
  import 'bignumber.js';
7
7
 
8
+ /**
9
+ * Transaction type identifiers for slow mode transactions.
10
+ */
11
+ declare enum SlowModeTxType {
12
+ DepositCollateral = 1,
13
+ WithdrawCollateral = 2,
14
+ LinkSigner = 13,
15
+ ClaimBuilderFee = 31
16
+ }
8
17
  declare function encodeSignedWithdrawCollateralTx(signed: SignedTx<EIP712WithdrawCollateralParams>): `0x${string}`;
9
18
  declare function encodeSignedOrder(signed: SignedEIP712OrderParams): `0x${string}`;
19
+ interface ClaimBuilderFeeParams {
20
+ /** The sender subaccount as bytes32 */
21
+ sender: Hex;
22
+ /** The builder ID to claim fees for */
23
+ builderId: number;
24
+ }
25
+ /**
26
+ * Encodes a ClaimBuilderFee slow mode transaction.
27
+ *
28
+ * Format: [tx_type_byte] + [abi_encoded_params]
29
+ *
30
+ * @param params - The claim builder fee parameters
31
+ * @returns The encoded transaction bytes ready to submit via endpoint.submitSlowModeTransaction
32
+ */
33
+ declare function encodeClaimBuilderFeeTx(params: ClaimBuilderFeeParams): Hex;
10
34
 
11
- export { encodeSignedOrder, encodeSignedWithdrawCollateralTx };
35
+ export { type ClaimBuilderFeeParams, SlowModeTxType, encodeClaimBuilderFeeTx, encodeSignedOrder, encodeSignedWithdrawCollateralTx };
@@ -1,11 +1,35 @@
1
+ import { Hex } from 'viem';
1
2
  import { SignedEIP712OrderParams, SignedTx, EIP712WithdrawCollateralParams } from '../eip712/signatureParamTypes.js';
2
- import 'viem';
3
3
  import '../types/subaccountTypes.js';
4
4
  import '../types/bytes.js';
5
5
  import '../utils/math/bigDecimal.js';
6
6
  import 'bignumber.js';
7
7
 
8
+ /**
9
+ * Transaction type identifiers for slow mode transactions.
10
+ */
11
+ declare enum SlowModeTxType {
12
+ DepositCollateral = 1,
13
+ WithdrawCollateral = 2,
14
+ LinkSigner = 13,
15
+ ClaimBuilderFee = 31
16
+ }
8
17
  declare function encodeSignedWithdrawCollateralTx(signed: SignedTx<EIP712WithdrawCollateralParams>): `0x${string}`;
9
18
  declare function encodeSignedOrder(signed: SignedEIP712OrderParams): `0x${string}`;
19
+ interface ClaimBuilderFeeParams {
20
+ /** The sender subaccount as bytes32 */
21
+ sender: Hex;
22
+ /** The builder ID to claim fees for */
23
+ builderId: number;
24
+ }
25
+ /**
26
+ * Encodes a ClaimBuilderFee slow mode transaction.
27
+ *
28
+ * Format: [tx_type_byte] + [abi_encoded_params]
29
+ *
30
+ * @param params - The claim builder fee parameters
31
+ * @returns The encoded transaction bytes ready to submit via endpoint.submitSlowModeTransaction
32
+ */
33
+ declare function encodeClaimBuilderFeeTx(params: ClaimBuilderFeeParams): Hex;
10
34
 
11
- export { encodeSignedOrder, encodeSignedWithdrawCollateralTx };
35
+ export { type ClaimBuilderFeeParams, SlowModeTxType, encodeClaimBuilderFeeTx, encodeSignedOrder, encodeSignedWithdrawCollateralTx };
@@ -1,8 +1,19 @@
1
1
  import "../chunk-5WRI5ZAA.js";
2
2
 
3
3
  // src/encoding/encoding.ts
4
- import { encodeAbiParameters, parseAbiParameters } from "viem";
4
+ import {
5
+ encodeAbiParameters,
6
+ encodePacked,
7
+ parseAbiParameters
8
+ } from "viem";
5
9
  import { addDecimals, toBigInt } from "../utils/index.js";
10
+ var SlowModeTxType = /* @__PURE__ */ ((SlowModeTxType2) => {
11
+ SlowModeTxType2[SlowModeTxType2["DepositCollateral"] = 1] = "DepositCollateral";
12
+ SlowModeTxType2[SlowModeTxType2["WithdrawCollateral"] = 2] = "WithdrawCollateral";
13
+ SlowModeTxType2[SlowModeTxType2["LinkSigner"] = 13] = "LinkSigner";
14
+ SlowModeTxType2[SlowModeTxType2["ClaimBuilderFee"] = 31] = "ClaimBuilderFee";
15
+ return SlowModeTxType2;
16
+ })(SlowModeTxType || {});
6
17
  function encodeSignedWithdrawCollateralTx(signed) {
7
18
  return encodeAbiParameters(
8
19
  parseAbiParameters(
@@ -42,7 +53,19 @@ function encodeSignedOrder(signed) {
42
53
  ]
43
54
  );
44
55
  }
56
+ function encodeClaimBuilderFeeTx(params) {
57
+ const txBytes = encodeAbiParameters(
58
+ parseAbiParameters("bytes32 sender, uint32 builderId"),
59
+ [params.sender, params.builderId]
60
+ );
61
+ return encodePacked(
62
+ ["uint8", "bytes"],
63
+ [31 /* ClaimBuilderFee */, txBytes]
64
+ );
65
+ }
45
66
  export {
67
+ SlowModeTxType,
68
+ encodeClaimBuilderFeeTx,
46
69
  encodeSignedOrder,
47
70
  encodeSignedWithdrawCollateralTx
48
71
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/encoding/encoding.ts"],"sourcesContent":["import { encodeAbiParameters, parseAbiParameters } from 'viem';\nimport {\n EIP712WithdrawCollateralParams,\n SignedEIP712OrderParams,\n SignedTx,\n} from '../eip712';\nimport { addDecimals, toBigInt } from '../utils';\n\nexport function encodeSignedWithdrawCollateralTx(\n signed: SignedTx<EIP712WithdrawCollateralParams>,\n) {\n return encodeAbiParameters(\n parseAbiParameters(\n '(tuple(address sender, string subaccountName, uint32 productId, uint128 amount, uint64 nonce), bytes signature)',\n ),\n [\n [\n [\n signed.tx.subaccountOwner,\n signed.tx.subaccountName,\n signed.tx.productId,\n signed.tx.amount,\n signed.tx.nonce,\n ],\n signed.signature,\n ],\n ],\n );\n}\n\nexport function encodeSignedOrder(signed: SignedEIP712OrderParams) {\n return encodeAbiParameters(\n parseAbiParameters(\n '(tuple(tuple(address sender, string subaccountName, int128 priceX18, int128 amount, uint64 expiration, uint64 nonce), bytes signature))',\n ),\n [\n [\n [\n signed.order.subaccountOwner,\n signed.order.subaccountName,\n toBigInt(addDecimals(signed.order.price)),\n signed.order.amount,\n signed.order.expiration,\n signed.order.nonce,\n ],\n signed.signature,\n ],\n ],\n );\n}\n"],"mappings":";;;AAAA,SAAS,qBAAqB,0BAA0B;AAMxD,SAAS,aAAa,gBAAgB;AAE/B,SAAS,iCACd,QACA;AACA,SAAO;AAAA,IACL;AAAA,MACE;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,QACE;AAAA,UACE,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,QACZ;AAAA,QACA,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,kBAAkB,QAAiC;AACjE,SAAO;AAAA,IACL;AAAA,MACE;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,QACE;AAAA,UACE,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,UACb,SAAS,YAAY,OAAO,MAAM,KAAK,CAAC;AAAA,UACxC,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,QACf;AAAA,QACA,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/encoding/encoding.ts"],"sourcesContent":["import {\n encodeAbiParameters,\n encodePacked,\n parseAbiParameters,\n type Hex,\n} from 'viem';\nimport {\n EIP712WithdrawCollateralParams,\n SignedEIP712OrderParams,\n SignedTx,\n} from '../eip712';\nimport { addDecimals, toBigInt } from '../utils';\n\n/**\n * Transaction type identifiers for slow mode transactions.\n */\nexport enum SlowModeTxType {\n DepositCollateral = 1,\n WithdrawCollateral = 2,\n LinkSigner = 13,\n ClaimBuilderFee = 31,\n}\n\nexport function encodeSignedWithdrawCollateralTx(\n signed: SignedTx<EIP712WithdrawCollateralParams>,\n) {\n return encodeAbiParameters(\n parseAbiParameters(\n '(tuple(address sender, string subaccountName, uint32 productId, uint128 amount, uint64 nonce), bytes signature)',\n ),\n [\n [\n [\n signed.tx.subaccountOwner,\n signed.tx.subaccountName,\n signed.tx.productId,\n signed.tx.amount,\n signed.tx.nonce,\n ],\n signed.signature,\n ],\n ],\n );\n}\n\nexport function encodeSignedOrder(signed: SignedEIP712OrderParams) {\n return encodeAbiParameters(\n parseAbiParameters(\n '(tuple(tuple(address sender, string subaccountName, int128 priceX18, int128 amount, uint64 expiration, uint64 nonce), bytes signature))',\n ),\n [\n [\n [\n signed.order.subaccountOwner,\n signed.order.subaccountName,\n toBigInt(addDecimals(signed.order.price)),\n signed.order.amount,\n signed.order.expiration,\n signed.order.nonce,\n ],\n signed.signature,\n ],\n ],\n );\n}\n\nexport interface ClaimBuilderFeeParams {\n /** The sender subaccount as bytes32 */\n sender: Hex;\n /** The builder ID to claim fees for */\n builderId: number;\n}\n\n/**\n * Encodes a ClaimBuilderFee slow mode transaction.\n *\n * Format: [tx_type_byte] + [abi_encoded_params]\n *\n * @param params - The claim builder fee parameters\n * @returns The encoded transaction bytes ready to submit via endpoint.submitSlowModeTransaction\n */\nexport function encodeClaimBuilderFeeTx(params: ClaimBuilderFeeParams): Hex {\n const txBytes = encodeAbiParameters(\n parseAbiParameters('bytes32 sender, uint32 builderId'),\n [params.sender, params.builderId],\n );\n\n return encodePacked(\n ['uint8', 'bytes'],\n [SlowModeTxType.ClaimBuilderFee, txBytes],\n );\n}\n"],"mappings":";;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAMP,SAAS,aAAa,gBAAgB;AAK/B,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gCAAA,uBAAoB,KAApB;AACA,EAAAA,gCAAA,wBAAqB,KAArB;AACA,EAAAA,gCAAA,gBAAa,MAAb;AACA,EAAAA,gCAAA,qBAAkB,MAAlB;AAJU,SAAAA;AAAA,GAAA;AAOL,SAAS,iCACd,QACA;AACA,SAAO;AAAA,IACL;AAAA,MACE;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,QACE;AAAA,UACE,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,UACV,OAAO,GAAG;AAAA,QACZ;AAAA,QACA,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,kBAAkB,QAAiC;AACjE,SAAO;AAAA,IACL;AAAA,MACE;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,QACE;AAAA,UACE,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,UACb,SAAS,YAAY,OAAO,MAAM,KAAK,CAAC;AAAA,UACxC,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,UACb,OAAO,MAAM;AAAA,QACf;AAAA,QACA,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAiBO,SAAS,wBAAwB,QAAoC;AAC1E,QAAM,UAAU;AAAA,IACd,mBAAmB,kCAAkC;AAAA,IACrD,CAAC,OAAO,QAAQ,OAAO,SAAS;AAAA,EAClC;AAEA,SAAO;AAAA,IACL,CAAC,SAAS,OAAO;AAAA,IACjB,CAAC,0BAAgC,OAAO;AAAA,EAC1C;AACF;","names":["SlowModeTxType"]}
@@ -1,6 +1,6 @@
1
- export { encodeSignedOrder, encodeSignedWithdrawCollateralTx } from './encoding.cjs';
2
- import '../eip712/signatureParamTypes.cjs';
1
+ export { ClaimBuilderFeeParams, SlowModeTxType, encodeClaimBuilderFeeTx, encodeSignedOrder, encodeSignedWithdrawCollateralTx } from './encoding.cjs';
3
2
  import 'viem';
3
+ import '../eip712/signatureParamTypes.cjs';
4
4
  import '../types/subaccountTypes.cjs';
5
5
  import '../types/bytes.cjs';
6
6
  import '../utils/math/bigDecimal.cjs';
@@ -1,6 +1,6 @@
1
- export { encodeSignedOrder, encodeSignedWithdrawCollateralTx } from './encoding.js';
2
- import '../eip712/signatureParamTypes.js';
1
+ export { ClaimBuilderFeeParams, SlowModeTxType, encodeClaimBuilderFeeTx, encodeSignedOrder, encodeSignedWithdrawCollateralTx } from './encoding.js';
3
2
  import 'viem';
3
+ import '../eip712/signatureParamTypes.js';
4
4
  import '../types/subaccountTypes.js';
5
5
  import '../types/bytes.js';
6
6
  import '../utils/math/bigDecimal.js';
package/dist/index.d.cts CHANGED
@@ -20,7 +20,7 @@ export { getSignedTransactionRequest } from './eip712/getSignedTransactionReques
20
20
  export { getOrderDigest } from './eip712/orderDigest.cjs';
21
21
  export { SignableRequestType, SignableRequestTypeToParams } from './eip712/signableRequestType.cjs';
22
22
  export { EIP712BurnNlpParams, EIP712CancelOrdersParams, EIP712CancelProductOrdersParams, EIP712LeaderboardAuthenticationParams, EIP712LinkSignerParams, EIP712LiquidateSubaccountParams, EIP712ListTriggerOrdersParams, EIP712MintNlpParams, EIP712OrderParams, EIP712TransferQuoteParams, EIP712WithdrawCollateralParams, SignedEIP712OrderParams, SignedTx } from './eip712/signatureParamTypes.cjs';
23
- export { encodeSignedOrder, encodeSignedWithdrawCollateralTx } from './encoding/encoding.cjs';
23
+ export { ClaimBuilderFeeParams, SlowModeTxType, encodeClaimBuilderFeeTx, encodeSignedOrder, encodeSignedWithdrawCollateralTx } from './encoding/encoding.cjs';
24
24
  export { ApproveDepositAllowanceParams, approveDepositAllowance } from './execute/approveDepositAllowance.cjs';
25
25
  export { DepositCollateralParams, depositCollateral } from './execute/depositCollateral.cjs';
26
26
  export { Balance, BalanceHealthContributions, BalanceSide, BalanceWithProduct, PerpBalance, PerpBalanceWithProduct, SpotBalance, SpotBalanceWithProduct } from './types/balanceTypes.cjs';
@@ -29,7 +29,7 @@ export { ALL_CHAIN_ENVS, ChainEnv, LOCAL_CHAIN_ENVS, MAINNET_CHAIN_ENVS, TESTNET
29
29
  export { HealthGroup, HealthStatus, HealthStatusByType, HealthType } from './types/healthTypes.cjs';
30
30
  export { Market, MarketWithProduct, PerpMarket, SpotMarket } from './types/marketTypes.cjs';
31
31
  export { NadoContracts, WithContract, WithContracts } from './types/nadoContractTypes.cjs';
32
- export { OrderAppendix, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields } from './types/orderAppendixTypes.cjs';
32
+ export { OrderAppendix, OrderAppendixBuilderFields, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields } from './types/orderAppendixTypes.cjs';
33
33
  export { OrderExecutionType } from './types/OrderExecutionType.cjs';
34
34
  export { PerpProduct, Product, ProductEngineType, SpotProduct, toProductEngineType } from './types/productTypes.cjs';
35
35
  export { Subaccount, SubaccountBytes32, SubaccountNameBytes12 } from './types/subaccountTypes.cjs';
package/dist/index.d.ts CHANGED
@@ -20,7 +20,7 @@ export { getSignedTransactionRequest } from './eip712/getSignedTransactionReques
20
20
  export { getOrderDigest } from './eip712/orderDigest.js';
21
21
  export { SignableRequestType, SignableRequestTypeToParams } from './eip712/signableRequestType.js';
22
22
  export { EIP712BurnNlpParams, EIP712CancelOrdersParams, EIP712CancelProductOrdersParams, EIP712LeaderboardAuthenticationParams, EIP712LinkSignerParams, EIP712LiquidateSubaccountParams, EIP712ListTriggerOrdersParams, EIP712MintNlpParams, EIP712OrderParams, EIP712TransferQuoteParams, EIP712WithdrawCollateralParams, SignedEIP712OrderParams, SignedTx } from './eip712/signatureParamTypes.js';
23
- export { encodeSignedOrder, encodeSignedWithdrawCollateralTx } from './encoding/encoding.js';
23
+ export { ClaimBuilderFeeParams, SlowModeTxType, encodeClaimBuilderFeeTx, encodeSignedOrder, encodeSignedWithdrawCollateralTx } from './encoding/encoding.js';
24
24
  export { ApproveDepositAllowanceParams, approveDepositAllowance } from './execute/approveDepositAllowance.js';
25
25
  export { DepositCollateralParams, depositCollateral } from './execute/depositCollateral.js';
26
26
  export { Balance, BalanceHealthContributions, BalanceSide, BalanceWithProduct, PerpBalance, PerpBalanceWithProduct, SpotBalance, SpotBalanceWithProduct } from './types/balanceTypes.js';
@@ -29,7 +29,7 @@ export { ALL_CHAIN_ENVS, ChainEnv, LOCAL_CHAIN_ENVS, MAINNET_CHAIN_ENVS, TESTNET
29
29
  export { HealthGroup, HealthStatus, HealthStatusByType, HealthType } from './types/healthTypes.js';
30
30
  export { Market, MarketWithProduct, PerpMarket, SpotMarket } from './types/marketTypes.js';
31
31
  export { NadoContracts, WithContract, WithContracts } from './types/nadoContractTypes.js';
32
- export { OrderAppendix, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields } from './types/orderAppendixTypes.js';
32
+ export { OrderAppendix, OrderAppendixBuilderFields, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields } from './types/orderAppendixTypes.js';
33
33
  export { OrderExecutionType } from './types/OrderExecutionType.js';
34
34
  export { PerpProduct, Product, ProductEngineType, SpotProduct, toProductEngineType } from './types/productTypes.js';
35
35
  export { Subaccount, SubaccountBytes32, SubaccountNameBytes12 } from './types/subaccountTypes.js';
@@ -4,7 +4,7 @@ export { ALL_CHAIN_ENVS, ChainEnv, LOCAL_CHAIN_ENVS, MAINNET_CHAIN_ENVS, TESTNET
4
4
  export { HealthGroup, HealthStatus, HealthStatusByType, HealthType } from './healthTypes.cjs';
5
5
  export { Market, MarketWithProduct, PerpMarket, SpotMarket } from './marketTypes.cjs';
6
6
  export { NadoContracts, WithContract, WithContracts } from './nadoContractTypes.cjs';
7
- export { OrderAppendix, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields } from './orderAppendixTypes.cjs';
7
+ export { OrderAppendix, OrderAppendixBuilderFields, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields } from './orderAppendixTypes.cjs';
8
8
  export { OrderExecutionType } from './OrderExecutionType.cjs';
9
9
  export { PerpProduct, Product, ProductEngineType, SpotProduct, toProductEngineType } from './productTypes.cjs';
10
10
  export { Subaccount, SubaccountBytes32, SubaccountNameBytes12 } from './subaccountTypes.cjs';
@@ -4,7 +4,7 @@ export { ALL_CHAIN_ENVS, ChainEnv, LOCAL_CHAIN_ENVS, MAINNET_CHAIN_ENVS, TESTNET
4
4
  export { HealthGroup, HealthStatus, HealthStatusByType, HealthType } from './healthTypes.js';
5
5
  export { Market, MarketWithProduct, PerpMarket, SpotMarket } from './marketTypes.js';
6
6
  export { NadoContracts, WithContract, WithContracts } from './nadoContractTypes.js';
7
- export { OrderAppendix, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields } from './orderAppendixTypes.js';
7
+ export { OrderAppendix, OrderAppendixBuilderFields, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields } from './orderAppendixTypes.js';
8
8
  export { OrderExecutionType } from './OrderExecutionType.js';
9
9
  export { PerpProduct, Product, ProductEngineType, SpotProduct, toProductEngineType } from './productTypes.js';
10
10
  export { Subaccount, SubaccountBytes32, SubaccountNameBytes12 } from './subaccountTypes.js';
@@ -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 * 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":[]}
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 * Fields for specifying a builder (fee recipient) for the order\n */\nexport interface OrderAppendixBuilderFields {\n /**\n * The builder ID (registered builder identifier)\n */\n builderId: number;\n /**\n * The builder fee rate. This is a raw 10-bit integer (0-1023) where each unit = 0.1 bps.\n * The actual fee is calculated on notional value: builder_fee = price * amount * rate\n */\n builderFeeRate: number;\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 * Specify the builder for fee sharing.\n * Builder ID is encoded in bits 48-63 (16 bits).\n * Builder fee rate is encoded in bits 38-47 (10 bits).\n */\n builder?: OrderAppendixBuilderFields;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -33,6 +33,20 @@ interface OrderAppendixIsolatedFields {
33
33
  */
34
34
  margin: BigDecimalish;
35
35
  }
36
+ /**
37
+ * Fields for specifying a builder (fee recipient) for the order
38
+ */
39
+ interface OrderAppendixBuilderFields {
40
+ /**
41
+ * The builder ID (registered builder identifier)
42
+ */
43
+ builderId: number;
44
+ /**
45
+ * The builder fee rate. This is a raw 10-bit integer (0-1023) where each unit = 0.1 bps.
46
+ * The actual fee is calculated on notional value: builder_fee = price * amount * rate
47
+ */
48
+ builderFeeRate: number;
49
+ }
36
50
  /**
37
51
  * All the fields encoded by the order appendix
38
52
  */
@@ -53,6 +67,12 @@ interface OrderAppendix {
53
67
  * An order CANNOT be both a TWAP order and an isolated order.
54
68
  */
55
69
  twap?: OrderAppendixTwapFields;
70
+ /**
71
+ * Specify the builder for fee sharing.
72
+ * Builder ID is encoded in bits 48-63 (16 bits).
73
+ * Builder fee rate is encoded in bits 38-47 (10 bits).
74
+ */
75
+ builder?: OrderAppendixBuilderFields;
56
76
  }
57
77
 
58
- export type { OrderAppendix, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields };
78
+ export type { OrderAppendix, OrderAppendixBuilderFields, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields };
@@ -33,6 +33,20 @@ interface OrderAppendixIsolatedFields {
33
33
  */
34
34
  margin: BigDecimalish;
35
35
  }
36
+ /**
37
+ * Fields for specifying a builder (fee recipient) for the order
38
+ */
39
+ interface OrderAppendixBuilderFields {
40
+ /**
41
+ * The builder ID (registered builder identifier)
42
+ */
43
+ builderId: number;
44
+ /**
45
+ * The builder fee rate. This is a raw 10-bit integer (0-1023) where each unit = 0.1 bps.
46
+ * The actual fee is calculated on notional value: builder_fee = price * amount * rate
47
+ */
48
+ builderFeeRate: number;
49
+ }
36
50
  /**
37
51
  * All the fields encoded by the order appendix
38
52
  */
@@ -53,6 +67,12 @@ interface OrderAppendix {
53
67
  * An order CANNOT be both a TWAP order and an isolated order.
54
68
  */
55
69
  twap?: OrderAppendixTwapFields;
70
+ /**
71
+ * Specify the builder for fee sharing.
72
+ * Builder ID is encoded in bits 48-63 (16 bits).
73
+ * Builder fee rate is encoded in bits 38-47 (10 bits).
74
+ */
75
+ builder?: OrderAppendixBuilderFields;
56
76
  }
57
77
 
58
- export type { OrderAppendix, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields };
78
+ export type { OrderAppendix, OrderAppendixBuilderFields, OrderAppendixIsolatedFields, OrderAppendixTriggerType, OrderAppendixTwapFields };
@@ -148,6 +148,60 @@ var import_unpackOrderAppendix = require("./unpackOrderAppendix.cjs");
148
148
  (0, import_globals.expect)(unpacked.twap?.numOrders).toBe(4294967295);
149
149
  (0, import_globals.expect)(packed).toBe(340282366841710300967557013911933828609n);
150
150
  });
151
+ (0, import_globals.it)("should handle builder fields", () => {
152
+ const appendix = {
153
+ orderExecutionType: "default",
154
+ builder: { builderId: 123, builderFeeRate: 500 }
155
+ };
156
+ const packed = (0, import_packOrderAppendix.packOrderAppendix)(appendix);
157
+ const unpacked = (0, import_unpackOrderAppendix.unpackOrderAppendix)(packed);
158
+ (0, import_globals.expect)(unpacked.builder?.builderId).toBe(123);
159
+ (0, import_globals.expect)(unpacked.builder?.builderFeeRate).toBe(500);
160
+ });
161
+ (0, import_globals.it)("should handle builder with zero fee rate", () => {
162
+ const appendix = {
163
+ orderExecutionType: "default",
164
+ builder: { builderId: 42, builderFeeRate: 0 }
165
+ };
166
+ const packed = (0, import_packOrderAppendix.packOrderAppendix)(appendix);
167
+ const unpacked = (0, import_unpackOrderAppendix.unpackOrderAppendix)(packed);
168
+ (0, import_globals.expect)(unpacked.builder?.builderId).toBe(42);
169
+ (0, import_globals.expect)(unpacked.builder?.builderFeeRate).toBe(0);
170
+ });
171
+ (0, import_globals.it)("should handle builder with max values", () => {
172
+ const appendix = {
173
+ orderExecutionType: "default",
174
+ builder: { builderId: 65535, builderFeeRate: 1023 }
175
+ // 16 bits, 10 bits max
176
+ };
177
+ const packed = (0, import_packOrderAppendix.packOrderAppendix)(appendix);
178
+ const unpacked = (0, import_unpackOrderAppendix.unpackOrderAppendix)(packed);
179
+ (0, import_globals.expect)(unpacked.builder?.builderId).toBe(65535);
180
+ (0, import_globals.expect)(unpacked.builder?.builderFeeRate).toBe(1023);
181
+ });
182
+ (0, import_globals.it)("should handle builder combined with other flags", () => {
183
+ const appendix = {
184
+ orderExecutionType: "ioc",
185
+ reduceOnly: true,
186
+ triggerType: "price",
187
+ builder: { builderId: 5, builderFeeRate: 100 }
188
+ };
189
+ const packed = (0, import_packOrderAppendix.packOrderAppendix)(appendix);
190
+ const unpacked = (0, import_unpackOrderAppendix.unpackOrderAppendix)(packed);
191
+ (0, import_globals.expect)(unpacked.orderExecutionType).toBe("ioc");
192
+ (0, import_globals.expect)(unpacked.reduceOnly).toBe(true);
193
+ (0, import_globals.expect)(unpacked.triggerType).toBe("price");
194
+ (0, import_globals.expect)(unpacked.builder?.builderId).toBe(5);
195
+ (0, import_globals.expect)(unpacked.builder?.builderFeeRate).toBe(100);
196
+ });
197
+ (0, import_globals.it)("should not return builder fields when builderId is 0", () => {
198
+ const appendix = {
199
+ orderExecutionType: "default"
200
+ };
201
+ const packed = (0, import_packOrderAppendix.packOrderAppendix)(appendix);
202
+ const unpacked = (0, import_unpackOrderAppendix.unpackOrderAppendix)(packed);
203
+ (0, import_globals.expect)(unpacked.builder).toBeUndefined();
204
+ });
151
205
  });
152
206
  /*! Bundled license information:
153
207
 
@@ -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: 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,WAA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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"]}
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 it('should handle builder fields', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n builder: { builderId: 123, builderFeeRate: 500 },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.builder?.builderId).toBe(123);\n expect(unpacked.builder?.builderFeeRate).toBe(500);\n });\n\n it('should handle builder with zero fee rate', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n builder: { builderId: 42, builderFeeRate: 0 },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.builder?.builderId).toBe(42);\n expect(unpacked.builder?.builderFeeRate).toBe(0);\n });\n\n it('should handle builder with max values', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n builder: { builderId: 65535, builderFeeRate: 1023 }, // 16 bits, 10 bits max\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.builder?.builderId).toBe(65535);\n expect(unpacked.builder?.builderFeeRate).toBe(1023);\n });\n\n it('should handle builder combined with other flags', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'ioc',\n reduceOnly: true,\n triggerType: 'price',\n builder: { builderId: 5, builderFeeRate: 100 },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.orderExecutionType).toBe('ioc');\n expect(unpacked.reduceOnly).toBe(true);\n expect(unpacked.triggerType).toBe('price');\n expect(unpacked.builder?.builderId).toBe(5);\n expect(unpacked.builder?.builderFeeRate).toBe(100);\n });\n\n it('should not return builder fields when builderId is 0', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.builder).toBeUndefined();\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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S,SAAS,EAAE,KAAK,KAAK;AAC9C,+BAAO,SAAS,SAAS,cAAc,EAAE,KAAK,IAAI;AAAA,EACpD,CAAC;AAED,yBAAG,mDAAmD,MAAM;AAC1D,UAAM,WAA0B;AAAA,MAC9B,oBAAoB;AAAA,MACpB,YAAY;AAAA,MACZ,aAAa;AAAA,MACb,SAAS,EAAE,WAAW,GAAG,gBAAgB,IAAI;AAAA,IAC/C;AACA,UAAM,aAAS,4CAAkB,QAAQ;AACzC,UAAM,eAAW,gDAAoB,MAAM;AAC3C,+BAAO,SAAS,kBAAkB,EAAE,KAAK,KAAK;AAC9C,+BAAO,SAAS,UAAU,EAAE,KAAK,IAAI;AACrC,+BAAO,SAAS,WAAW,EAAE,KAAK,OAAO;AACzC,+BAAO,SAAS,SAAS,SAAS,EAAE,KAAK,CAAC;AAC1C,+BAAO,SAAS,SAAS,cAAc,EAAE,KAAK,GAAG;AAAA,EACnD,CAAC;AAED,yBAAG,wDAAwD,MAAM;AAC/D,UAAM,WAA0B;AAAA,MAC9B,oBAAoB;AAAA,IACtB;AACA,UAAM,aAAS,4CAAkB,QAAQ;AACzC,UAAM,eAAW,gDAAoB,MAAM;AAC3C,+BAAO,SAAS,OAAO,EAAE,cAAc;AAAA,EACzC,CAAC;AACH,CAAC;","names":["exports","module"]}
@@ -115,5 +115,59 @@ import { unpackOrderAppendix } from "./unpackOrderAppendix.js";
115
115
  (0, import_globals.expect)(unpacked.twap?.numOrders).toBe(4294967295);
116
116
  (0, import_globals.expect)(packed).toBe(340282366841710300967557013911933828609n);
117
117
  });
118
+ (0, import_globals.it)("should handle builder fields", () => {
119
+ const appendix = {
120
+ orderExecutionType: "default",
121
+ builder: { builderId: 123, builderFeeRate: 500 }
122
+ };
123
+ const packed = packOrderAppendix(appendix);
124
+ const unpacked = unpackOrderAppendix(packed);
125
+ (0, import_globals.expect)(unpacked.builder?.builderId).toBe(123);
126
+ (0, import_globals.expect)(unpacked.builder?.builderFeeRate).toBe(500);
127
+ });
128
+ (0, import_globals.it)("should handle builder with zero fee rate", () => {
129
+ const appendix = {
130
+ orderExecutionType: "default",
131
+ builder: { builderId: 42, builderFeeRate: 0 }
132
+ };
133
+ const packed = packOrderAppendix(appendix);
134
+ const unpacked = unpackOrderAppendix(packed);
135
+ (0, import_globals.expect)(unpacked.builder?.builderId).toBe(42);
136
+ (0, import_globals.expect)(unpacked.builder?.builderFeeRate).toBe(0);
137
+ });
138
+ (0, import_globals.it)("should handle builder with max values", () => {
139
+ const appendix = {
140
+ orderExecutionType: "default",
141
+ builder: { builderId: 65535, builderFeeRate: 1023 }
142
+ // 16 bits, 10 bits max
143
+ };
144
+ const packed = packOrderAppendix(appendix);
145
+ const unpacked = unpackOrderAppendix(packed);
146
+ (0, import_globals.expect)(unpacked.builder?.builderId).toBe(65535);
147
+ (0, import_globals.expect)(unpacked.builder?.builderFeeRate).toBe(1023);
148
+ });
149
+ (0, import_globals.it)("should handle builder combined with other flags", () => {
150
+ const appendix = {
151
+ orderExecutionType: "ioc",
152
+ reduceOnly: true,
153
+ triggerType: "price",
154
+ builder: { builderId: 5, builderFeeRate: 100 }
155
+ };
156
+ const packed = packOrderAppendix(appendix);
157
+ const unpacked = unpackOrderAppendix(packed);
158
+ (0, import_globals.expect)(unpacked.orderExecutionType).toBe("ioc");
159
+ (0, import_globals.expect)(unpacked.reduceOnly).toBe(true);
160
+ (0, import_globals.expect)(unpacked.triggerType).toBe("price");
161
+ (0, import_globals.expect)(unpacked.builder?.builderId).toBe(5);
162
+ (0, import_globals.expect)(unpacked.builder?.builderFeeRate).toBe(100);
163
+ });
164
+ (0, import_globals.it)("should not return builder fields when builderId is 0", () => {
165
+ const appendix = {
166
+ orderExecutionType: "default"
167
+ };
168
+ const packed = packOrderAppendix(appendix);
169
+ const unpacked = unpackOrderAppendix(packed);
170
+ (0, import_globals.expect)(unpacked.builder).toBeUndefined();
171
+ });
118
172
  });
119
173
  //# 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(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,IA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BAA4B;AAAA,EAClD,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":[]}
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 it('should handle builder fields', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n builder: { builderId: 123, builderFeeRate: 500 },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.builder?.builderId).toBe(123);\n expect(unpacked.builder?.builderFeeRate).toBe(500);\n });\n\n it('should handle builder with zero fee rate', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n builder: { builderId: 42, builderFeeRate: 0 },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.builder?.builderId).toBe(42);\n expect(unpacked.builder?.builderFeeRate).toBe(0);\n });\n\n it('should handle builder with max values', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n builder: { builderId: 65535, builderFeeRate: 1023 }, // 16 bits, 10 bits max\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.builder?.builderId).toBe(65535);\n expect(unpacked.builder?.builderFeeRate).toBe(1023);\n });\n\n it('should handle builder combined with other flags', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'ioc',\n reduceOnly: true,\n triggerType: 'price',\n builder: { builderId: 5, builderFeeRate: 100 },\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.orderExecutionType).toBe('ioc');\n expect(unpacked.reduceOnly).toBe(true);\n expect(unpacked.triggerType).toBe('price');\n expect(unpacked.builder?.builderId).toBe(5);\n expect(unpacked.builder?.builderFeeRate).toBe(100);\n });\n\n it('should not return builder fields when builderId is 0', () => {\n const appendix: OrderAppendix = {\n orderExecutionType: 'default',\n };\n const packed = packOrderAppendix(appendix);\n const unpacked = unpackOrderAppendix(packed);\n expect(unpacked.builder).toBeUndefined();\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,WA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AS,cAAc,EAAE,KAAK,GAAG;AAAA,EACnD,CAAC;AAED,yBAAG,wDAAwD,MAAM;AAC/D,UAAM,WAA0B;AAAA,MAC9B,oBAAoB;AAAA,IACtB;AACA,UAAM,SAAS,kBAAkB,QAAQ;AACzC,UAAM,WAAW,oBAAoB,MAAM;AAC3C,+BAAO,SAAS,OAAO,EAAE,cAAc;AAAA,EACzC,CAAC;AACH,CAAC;","names":[]}
@@ -62,6 +62,8 @@ function mapOrderAppendixToBitValues(appendix) {
62
62
  })();
63
63
  return {
64
64
  value,
65
+ builderId: appendix.builder?.builderId ?? 0,
66
+ builderFeeRate: appendix.builder?.builderFeeRate ?? 0,
65
67
  reserved: 0,
66
68
  trigger,
67
69
  reduceOnly: appendix.reduceOnly ? 1 : 0,
@@ -73,7 +75,9 @@ function mapOrderAppendixToBitValues(appendix) {
73
75
  function packOrderAppendix(appendix) {
74
76
  const bits = mapOrderAppendixToBitValues(appendix);
75
77
  let packed = (0, import_bitMaskValue.bitMaskValue)(bits.value, 64);
76
- packed = packed << 50n | (0, import_bitMaskValue.bitMaskValue)(bits.reserved, 50);
78
+ packed = packed << 16n | (0, import_bitMaskValue.bitMaskValue)(bits.builderId, 16);
79
+ packed = packed << 10n | (0, import_bitMaskValue.bitMaskValue)(bits.builderFeeRate, 10);
80
+ packed = packed << 24n | (0, import_bitMaskValue.bitMaskValue)(bits.reserved, 24);
77
81
  packed = packed << 2n | (0, import_bitMaskValue.bitMaskValue)(bits.trigger, 2);
78
82
  packed = packed << 1n | (0, import_bitMaskValue.bitMaskValue)(bits.reduceOnly, 1);
79
83
  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 { 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;AAAA;AACA,mCAA+C;AAC/C,+BAA2C;AAC3C,0BAA6B;AAG7B,SAAS,4BACP,UACyB;AACzB,QAAM,SAAS,MAAM;AACnB,QAAI,SAAS,MAAM;AACjB,iBAAO,qDAA2B,SAAS,IAAI;AAAA,IACjD;AACA,QAAI,SAAS,UAAU;AACrB,iBAAO,6DAA+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,aAAS,kCAAa,KAAK,OAAO,EAAE;AACxC,WAAU,UAAU,UAAO,kCAAa,KAAK,UAAU,EAAE;AACzD,WAAU,UAAU,SAAM,kCAAa,KAAK,SAAS,CAAC;AACtD,WAAU,UAAU,SAAM,kCAAa,KAAK,YAAY,CAAC;AACzD,WAAU,UAAU,SAAM,kCAAa,KAAK,WAAW,CAAC;AACxD,WAAU,UAAU,SAAM,kCAAa,KAAK,UAAU,CAAC;AACvD,WAAU,UAAU,SAAM,kCAAa,KAAK,SAAS,CAAC;AACtD,SAAO;AACT;","names":[]}
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 builderId: appendix.builder?.builderId ?? 0,\n builderFeeRate: appendix.builder?.builderFeeRate ?? 0,\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 << 16n) | bitMaskValue(bits.builderId, 16);\n packed = (packed << 10n) | bitMaskValue(bits.builderFeeRate, 10);\n packed = (packed << 24n) | bitMaskValue(bits.reserved, 24);\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,mCAA+C;AAC/C,+BAA2C;AAC3C,0BAA6B;AAG7B,SAAS,4BACP,UACy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AU,SAAM,kCAAa,KAAK,UAAU,CAAC;AACvD,WAAU,UAAU,SAAM,kCAAa,KAAK,SAAS,CAAC;AACtD,SAAO;AACT;","names":[]}
@@ -40,6 +40,8 @@ function mapOrderAppendixToBitValues(appendix) {
40
40
  })();
41
41
  return {
42
42
  value,
43
+ builderId: appendix.builder?.builderId ?? 0,
44
+ builderFeeRate: appendix.builder?.builderFeeRate ?? 0,
43
45
  reserved: 0,
44
46
  trigger,
45
47
  reduceOnly: appendix.reduceOnly ? 1 : 0,
@@ -51,7 +53,9 @@ function mapOrderAppendixToBitValues(appendix) {
51
53
  function packOrderAppendix(appendix) {
52
54
  const bits = mapOrderAppendixToBitValues(appendix);
53
55
  let packed = bitMaskValue(bits.value, 64);
54
- packed = packed << 50n | bitMaskValue(bits.reserved, 50);
56
+ packed = packed << 16n | bitMaskValue(bits.builderId, 16);
57
+ packed = packed << 10n | bitMaskValue(bits.builderFeeRate, 10);
58
+ packed = packed << 24n | bitMaskValue(bits.reserved, 24);
55
59
  packed = packed << 2n | bitMaskValue(bits.trigger, 2);
56
60
  packed = packed << 1n | bitMaskValue(bits.reduceOnly, 1);
57
61
  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 { 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":[]}
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 builderId: appendix.builder?.builderId ?? 0,\n builderFeeRate: appendix.builder?.builderFeeRate ?? 0,\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 << 16n) | bitMaskValue(bits.builderId, 16);\n packed = (packed << 10n) | bitMaskValue(bits.builderFeeRate, 10);\n packed = (packed << 24n) | bitMaskValue(bits.reserved, 24);\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,WAAW,SAAS,SAAS,aAAa;AAAA,IAC1C,gBAAgB,SAAS,SAAS,kBAAkB;AAAA,IACpD,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,WAAW,EAAE;AAC1D,WAAU,UAAU,MAAO,aAAa,KAAK,gBAAgB,EAAE;AAC/D,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":[]}
@@ -1 +1 @@
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":[]}
1
+ {"version":3,"sources":["../../../../src/utils/orders/appendix/types.ts"],"sourcesContent":["/**\n * Bit layout for OrderAppendix packing (MSB → LSB):\n *\n * | value | builderId | builderFeeRate | reserved | trigger | reduceOnly | orderType | isolated | version |\n * |-----------|-----------|----------------|----------|---------|------------|-----------|----------|---------|\n * | 127..64 | 63..48 | 47..38 | 37..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |\n * | 64 bits | 16 bits | 10 bits | 24 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |\n */\nexport interface PackedOrderAppendixBits {\n value: bigint; // 64 bits\n builderId: number; // 16 bits\n builderFeeRate: number; // 10 bits\n reserved: number; // 24 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":[]}
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * Bit layout for OrderAppendix packing (MSB → LSB):
3
3
  *
4
- * | value | reserved | trigger | reduceOnly | orderType | isolated | version |
5
- * |-----------|----------|---------|------------|-----------|----------|---------|
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 |
4
+ * | value | builderId | builderFeeRate | reserved | trigger | reduceOnly | orderType | isolated | version |
5
+ * |-----------|-----------|----------------|----------|---------|------------|-----------|----------|---------|
6
+ * | 127..64 | 63..48 | 47..38 | 37..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |
7
+ * | 64 bits | 16 bits | 10 bits | 24 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |
8
8
  */
9
9
  interface PackedOrderAppendixBits {
10
10
  value: bigint;
11
+ builderId: number;
12
+ builderFeeRate: number;
11
13
  reserved: number;
12
14
  trigger: number;
13
15
  reduceOnly: number;
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * Bit layout for OrderAppendix packing (MSB → LSB):
3
3
  *
4
- * | value | reserved | trigger | reduceOnly | orderType | isolated | version |
5
- * |-----------|----------|---------|------------|-----------|----------|---------|
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 |
4
+ * | value | builderId | builderFeeRate | reserved | trigger | reduceOnly | orderType | isolated | version |
5
+ * |-----------|-----------|----------------|----------|---------|------------|-----------|----------|---------|
6
+ * | 127..64 | 63..48 | 47..38 | 37..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |
7
+ * | 64 bits | 16 bits | 10 bits | 24 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |
8
8
  */
9
9
  interface PackedOrderAppendixBits {
10
10
  value: bigint;
11
+ builderId: number;
12
+ builderFeeRate: number;
11
13
  reserved: number;
12
14
  trigger: number;
13
15
  reduceOnly: number;
@@ -67,12 +67,22 @@ function mapBitValuesToAppendix(bits) {
67
67
  return (0, import_appendixTwapValue.unpackTwapOrderAppendixValue)(bits.value);
68
68
  }
69
69
  })();
70
+ const builderFields = (() => {
71
+ if (bits.builderId) {
72
+ return {
73
+ builderId: bits.builderId,
74
+ builderFeeRate: bits.builderFeeRate
75
+ };
76
+ }
77
+ return void 0;
78
+ })();
70
79
  return {
71
80
  reduceOnly: !!bits.reduceOnly,
72
81
  orderExecutionType,
73
82
  triggerType,
74
83
  isolated: isolatedFields,
75
- twap: twapFields
84
+ twap: twapFields,
85
+ builder: builderFields
76
86
  };
77
87
  }
78
88
  function unpackOrderAppendix(packed) {
@@ -87,11 +97,17 @@ function unpackOrderAppendix(packed) {
87
97
  temp >>= 1n;
88
98
  const trigger = Number((0, import_bitMaskValue.bitMaskValue)(temp, 2));
89
99
  temp >>= 2n;
90
- const reserved = Number((0, import_bitMaskValue.bitMaskValue)(temp, 50));
91
- temp >>= 50n;
100
+ const reserved = Number((0, import_bitMaskValue.bitMaskValue)(temp, 24));
101
+ temp >>= 24n;
102
+ const builderFeeRate = Number((0, import_bitMaskValue.bitMaskValue)(temp, 10));
103
+ temp >>= 10n;
104
+ const builderId = Number((0, import_bitMaskValue.bitMaskValue)(temp, 16));
105
+ temp >>= 16n;
92
106
  const value = (0, import_bitMaskValue.bitMaskValue)(temp, 64);
93
107
  return mapBitValuesToAppendix({
94
108
  value,
109
+ builderId,
110
+ builderFeeRate,
95
111
  reserved,
96
112
  trigger,
97
113
  reduceOnly,
@@ -1 +1 @@
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":[]}
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 const builderFields = (() => {\n if (bits.builderId) {\n return {\n builderId: bits.builderId,\n builderFeeRate: bits.builderFeeRate,\n };\n }\n return undefined;\n })();\n\n return {\n reduceOnly: !!bits.reduceOnly,\n orderExecutionType,\n triggerType,\n isolated: isolatedFields,\n twap: twapFields,\n builder: builderFields,\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, 24));\n temp >>= 24n;\n const builderFeeRate = Number(bitMaskValue(temp, 10));\n temp >>= 10n;\n const builderId = Number(bitMaskValue(temp, 16));\n temp >>= 16n;\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 builderId,\n builderFeeRate,\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;AACH,QAAM,iBAAiB,MAAM;AAC3B,QAAI,KAAK,WAAW;AAClB,aAAO;AAAA,QACL,WAAW,KAAK;AAAA,QAChB,gBAAgB,KAAK;AAAA,MACvB;AAAA,IACF;AACA,WAAO;AAAA,EACT,GAAG;AAEH,SAAO;AAAA,IACL,YAAY,CAAC,CAAC,KAAK;AAAA,IACnB;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,MAAM;AAAA,IACN,SAAS;AAAA,EACX;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;AACT,QAAM,iBAAiB,WAAO,kCAAa,MAAM,EAAE,CAAC;AACpD,WAAS;AACT,QAAM,YAAY,WAAO,kCAAa,MAAM,EAAE,CAAC;AAC/C,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,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -45,12 +45,22 @@ function mapBitValuesToAppendix(bits) {
45
45
  return unpackTwapOrderAppendixValue(bits.value);
46
46
  }
47
47
  })();
48
+ const builderFields = (() => {
49
+ if (bits.builderId) {
50
+ return {
51
+ builderId: bits.builderId,
52
+ builderFeeRate: bits.builderFeeRate
53
+ };
54
+ }
55
+ return void 0;
56
+ })();
48
57
  return {
49
58
  reduceOnly: !!bits.reduceOnly,
50
59
  orderExecutionType,
51
60
  triggerType,
52
61
  isolated: isolatedFields,
53
- twap: twapFields
62
+ twap: twapFields,
63
+ builder: builderFields
54
64
  };
55
65
  }
56
66
  function unpackOrderAppendix(packed) {
@@ -65,11 +75,17 @@ function unpackOrderAppendix(packed) {
65
75
  temp >>= 1n;
66
76
  const trigger = Number(bitMaskValue(temp, 2));
67
77
  temp >>= 2n;
68
- const reserved = Number(bitMaskValue(temp, 50));
69
- temp >>= 50n;
78
+ const reserved = Number(bitMaskValue(temp, 24));
79
+ temp >>= 24n;
80
+ const builderFeeRate = Number(bitMaskValue(temp, 10));
81
+ temp >>= 10n;
82
+ const builderId = Number(bitMaskValue(temp, 16));
83
+ temp >>= 16n;
70
84
  const value = bitMaskValue(temp, 64);
71
85
  return mapBitValuesToAppendix({
72
86
  value,
87
+ builderId,
88
+ builderFeeRate,
73
89
  reserved,
74
90
  trigger,
75
91
  reduceOnly,
@@ -1 +1 @@
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,SAAwB,gBAAgB;AACxC,SAAS,wCAAwC;AACjD,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,iCAAiC,KAAK,KAAK;AAAA,IACpD;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":[]}
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 const builderFields = (() => {\n if (bits.builderId) {\n return {\n builderId: bits.builderId,\n builderFeeRate: bits.builderFeeRate,\n };\n }\n return undefined;\n })();\n\n return {\n reduceOnly: !!bits.reduceOnly,\n orderExecutionType,\n triggerType,\n isolated: isolatedFields,\n twap: twapFields,\n builder: builderFields,\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, 24));\n temp >>= 24n;\n const builderFeeRate = Number(bitMaskValue(temp, 10));\n temp >>= 10n;\n const builderId = Number(bitMaskValue(temp, 16));\n temp >>= 16n;\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 builderId,\n builderFeeRate,\n reserved,\n trigger,\n reduceOnly,\n orderType,\n isolated,\n version,\n });\n}\n"],"mappings":";;;AACA,SAAwB,gBAAgB;AACxC,SAAS,wCAAwC;AACjD,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,iCAAiC,KAAK,KAAK;AAAA,IACpD;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;AACH,QAAM,iBAAiB,MAAM;AAC3B,QAAI,KAAK,WAAW;AAClB,aAAO;AAAA,QACL,WAAW,KAAK;AAAA,QAChB,gBAAgB,KAAK;AAAA,MACvB;AAAA,IACF;AACA,WAAO;AAAA,EACT,GAAG;AAEH,SAAO;AAAA,IACL,YAAY,CAAC,CAAC,KAAK;AAAA,IACnB;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,MAAM;AAAA,IACN,SAAS;AAAA,EACX;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;AACT,QAAM,iBAAiB,OAAO,aAAa,MAAM,EAAE,CAAC;AACpD,WAAS;AACT,QAAM,YAAY,OAAO,aAAa,MAAM,EAAE,CAAC;AAC/C,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,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.46",
3
+ "version": "0.1.0-alpha.47",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Shared utilities, types, and contract helpers for Nado SDK",
@@ -52,5 +52,5 @@
52
52
  "bignumber.js": "^9.3.0",
53
53
  "viem": "workspace:*"
54
54
  },
55
- "gitHead": "b27f1064e530c10aadbf8d386ee24e7f330d0a1f"
55
+ "gitHead": "93c4298d459c79383eccad8893b90e0a730e7671"
56
56
  }
@@ -1,4 +1,9 @@
1
- import { encodeAbiParameters, parseAbiParameters } from 'viem';
1
+ import {
2
+ encodeAbiParameters,
3
+ encodePacked,
4
+ parseAbiParameters,
5
+ type Hex,
6
+ } from 'viem';
2
7
  import {
3
8
  EIP712WithdrawCollateralParams,
4
9
  SignedEIP712OrderParams,
@@ -6,6 +11,16 @@ import {
6
11
  } from '../eip712';
7
12
  import { addDecimals, toBigInt } from '../utils';
8
13
 
14
+ /**
15
+ * Transaction type identifiers for slow mode transactions.
16
+ */
17
+ export enum SlowModeTxType {
18
+ DepositCollateral = 1,
19
+ WithdrawCollateral = 2,
20
+ LinkSigner = 13,
21
+ ClaimBuilderFee = 31,
22
+ }
23
+
9
24
  export function encodeSignedWithdrawCollateralTx(
10
25
  signed: SignedTx<EIP712WithdrawCollateralParams>,
11
26
  ) {
@@ -48,3 +63,30 @@ export function encodeSignedOrder(signed: SignedEIP712OrderParams) {
48
63
  ],
49
64
  );
50
65
  }
66
+
67
+ export interface ClaimBuilderFeeParams {
68
+ /** The sender subaccount as bytes32 */
69
+ sender: Hex;
70
+ /** The builder ID to claim fees for */
71
+ builderId: number;
72
+ }
73
+
74
+ /**
75
+ * Encodes a ClaimBuilderFee slow mode transaction.
76
+ *
77
+ * Format: [tx_type_byte] + [abi_encoded_params]
78
+ *
79
+ * @param params - The claim builder fee parameters
80
+ * @returns The encoded transaction bytes ready to submit via endpoint.submitSlowModeTransaction
81
+ */
82
+ export function encodeClaimBuilderFeeTx(params: ClaimBuilderFeeParams): Hex {
83
+ const txBytes = encodeAbiParameters(
84
+ parseAbiParameters('bytes32 sender, uint32 builderId'),
85
+ [params.sender, params.builderId],
86
+ );
87
+
88
+ return encodePacked(
89
+ ['uint8', 'bytes'],
90
+ [SlowModeTxType.ClaimBuilderFee, txBytes],
91
+ );
92
+ }
@@ -39,6 +39,21 @@ export interface OrderAppendixIsolatedFields {
39
39
  margin: BigDecimalish;
40
40
  }
41
41
 
42
+ /**
43
+ * Fields for specifying a builder (fee recipient) for the order
44
+ */
45
+ export interface OrderAppendixBuilderFields {
46
+ /**
47
+ * The builder ID (registered builder identifier)
48
+ */
49
+ builderId: number;
50
+ /**
51
+ * The builder fee rate. This is a raw 10-bit integer (0-1023) where each unit = 0.1 bps.
52
+ * The actual fee is calculated on notional value: builder_fee = price * amount * rate
53
+ */
54
+ builderFeeRate: number;
55
+ }
56
+
42
57
  /**
43
58
  * All the fields encoded by the order appendix
44
59
  */
@@ -59,4 +74,10 @@ export interface OrderAppendix {
59
74
  * An order CANNOT be both a TWAP order and an isolated order.
60
75
  */
61
76
  twap?: OrderAppendixTwapFields;
77
+ /**
78
+ * Specify the builder for fee sharing.
79
+ * Builder ID is encoded in bits 48-63 (16 bits).
80
+ * Builder fee rate is encoded in bits 38-47 (10 bits).
81
+ */
82
+ builder?: OrderAppendixBuilderFields;
62
83
  }
@@ -117,4 +117,62 @@ describe('OrderAppendix packing/unpacking', () => {
117
117
  expect(unpacked.twap?.numOrders).toBe(4294967295);
118
118
  expect(packed).toBe(340282366841710300967557013911933828609n);
119
119
  });
120
+
121
+ it('should handle builder fields', () => {
122
+ const appendix: OrderAppendix = {
123
+ orderExecutionType: 'default',
124
+ builder: { builderId: 123, builderFeeRate: 500 },
125
+ };
126
+ const packed = packOrderAppendix(appendix);
127
+ const unpacked = unpackOrderAppendix(packed);
128
+ expect(unpacked.builder?.builderId).toBe(123);
129
+ expect(unpacked.builder?.builderFeeRate).toBe(500);
130
+ });
131
+
132
+ it('should handle builder with zero fee rate', () => {
133
+ const appendix: OrderAppendix = {
134
+ orderExecutionType: 'default',
135
+ builder: { builderId: 42, builderFeeRate: 0 },
136
+ };
137
+ const packed = packOrderAppendix(appendix);
138
+ const unpacked = unpackOrderAppendix(packed);
139
+ expect(unpacked.builder?.builderId).toBe(42);
140
+ expect(unpacked.builder?.builderFeeRate).toBe(0);
141
+ });
142
+
143
+ it('should handle builder with max values', () => {
144
+ const appendix: OrderAppendix = {
145
+ orderExecutionType: 'default',
146
+ builder: { builderId: 65535, builderFeeRate: 1023 }, // 16 bits, 10 bits max
147
+ };
148
+ const packed = packOrderAppendix(appendix);
149
+ const unpacked = unpackOrderAppendix(packed);
150
+ expect(unpacked.builder?.builderId).toBe(65535);
151
+ expect(unpacked.builder?.builderFeeRate).toBe(1023);
152
+ });
153
+
154
+ it('should handle builder combined with other flags', () => {
155
+ const appendix: OrderAppendix = {
156
+ orderExecutionType: 'ioc',
157
+ reduceOnly: true,
158
+ triggerType: 'price',
159
+ builder: { builderId: 5, builderFeeRate: 100 },
160
+ };
161
+ const packed = packOrderAppendix(appendix);
162
+ const unpacked = unpackOrderAppendix(packed);
163
+ expect(unpacked.orderExecutionType).toBe('ioc');
164
+ expect(unpacked.reduceOnly).toBe(true);
165
+ expect(unpacked.triggerType).toBe('price');
166
+ expect(unpacked.builder?.builderId).toBe(5);
167
+ expect(unpacked.builder?.builderFeeRate).toBe(100);
168
+ });
169
+
170
+ it('should not return builder fields when builderId is 0', () => {
171
+ const appendix: OrderAppendix = {
172
+ orderExecutionType: 'default',
173
+ };
174
+ const packed = packOrderAppendix(appendix);
175
+ const unpacked = unpackOrderAppendix(packed);
176
+ expect(unpacked.builder).toBeUndefined();
177
+ });
120
178
  });
@@ -43,6 +43,8 @@ function mapOrderAppendixToBitValues(
43
43
 
44
44
  return {
45
45
  value,
46
+ builderId: appendix.builder?.builderId ?? 0,
47
+ builderFeeRate: appendix.builder?.builderFeeRate ?? 0,
46
48
  reserved: 0,
47
49
  trigger,
48
50
  reduceOnly: appendix.reduceOnly ? 1 : 0,
@@ -61,7 +63,9 @@ export function packOrderAppendix(appendix: OrderAppendix): bigint {
61
63
 
62
64
  // Ensure value is within 64 bits
63
65
  let packed = bitMaskValue(bits.value, 64);
64
- packed = (packed << 50n) | bitMaskValue(bits.reserved, 50);
66
+ packed = (packed << 16n) | bitMaskValue(bits.builderId, 16);
67
+ packed = (packed << 10n) | bitMaskValue(bits.builderFeeRate, 10);
68
+ packed = (packed << 24n) | bitMaskValue(bits.reserved, 24);
65
69
  packed = (packed << 2n) | bitMaskValue(bits.trigger, 2);
66
70
  packed = (packed << 1n) | bitMaskValue(bits.reduceOnly, 1);
67
71
  packed = (packed << 2n) | bitMaskValue(bits.orderType, 2);
@@ -1,14 +1,16 @@
1
1
  /**
2
2
  * Bit layout for OrderAppendix packing (MSB → LSB):
3
3
  *
4
- * | value | reserved | trigger | reduceOnly | orderType | isolated | version |
5
- * |-----------|----------|---------|------------|-----------|----------|---------|
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 |
4
+ * | value | builderId | builderFeeRate | reserved | trigger | reduceOnly | orderType | isolated | version |
5
+ * |-----------|-----------|----------------|----------|---------|------------|-----------|----------|---------|
6
+ * | 127..64 | 63..48 | 47..38 | 37..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |
7
+ * | 64 bits | 16 bits | 10 bits | 24 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |
8
8
  */
9
9
  export interface PackedOrderAppendixBits {
10
10
  value: bigint; // 64 bits
11
- reserved: number; // 50 bits, set to 0
11
+ builderId: number; // 16 bits
12
+ builderFeeRate: number; // 10 bits
13
+ reserved: number; // 24 bits, set to 0
12
14
  trigger: number; // 2 bits
13
15
  reduceOnly: number; // 1 bit
14
16
  orderType: number; // 2 bits
@@ -45,6 +45,15 @@ function mapBitValuesToAppendix(bits: PackedOrderAppendixBits): OrderAppendix {
45
45
  return unpackTwapOrderAppendixValue(bits.value);
46
46
  }
47
47
  })();
48
+ const builderFields = (() => {
49
+ if (bits.builderId) {
50
+ return {
51
+ builderId: bits.builderId,
52
+ builderFeeRate: bits.builderFeeRate,
53
+ };
54
+ }
55
+ return undefined;
56
+ })();
48
57
 
49
58
  return {
50
59
  reduceOnly: !!bits.reduceOnly,
@@ -52,6 +61,7 @@ function mapBitValuesToAppendix(bits: PackedOrderAppendixBits): OrderAppendix {
52
61
  triggerType,
53
62
  isolated: isolatedFields,
54
63
  twap: twapFields,
64
+ builder: builderFields,
55
65
  };
56
66
  }
57
67
 
@@ -74,13 +84,19 @@ export function unpackOrderAppendix(packed: BigDecimalish): OrderAppendix {
74
84
  temp >>= 1n;
75
85
  const trigger = Number(bitMaskValue(temp, 2));
76
86
  temp >>= 2n;
77
- const reserved = Number(bitMaskValue(temp, 50));
78
- temp >>= 50n;
87
+ const reserved = Number(bitMaskValue(temp, 24));
88
+ temp >>= 24n;
89
+ const builderFeeRate = Number(bitMaskValue(temp, 10));
90
+ temp >>= 10n;
91
+ const builderId = Number(bitMaskValue(temp, 16));
92
+ temp >>= 16n;
79
93
  // The remaining bits are the value, which should be 64 bits
80
94
  const value = bitMaskValue(temp, 64);
81
95
 
82
96
  return mapBitValuesToAppendix({
83
97
  value,
98
+ builderId,
99
+ builderFeeRate,
84
100
  reserved,
85
101
  trigger,
86
102
  reduceOnly,