@nadohq/shared 0.1.0-alpha.31 → 0.1.0-alpha.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/orderAppendixTypes.ts"],"sourcesContent":["import { BigDecimalish } from '../utils/math';\nimport { OrderExecutionType } from './OrderExecutionType';\n\n/**\n * Encodes whether the order will be sent to the trigger service\n */\nexport type OrderAppendixTriggerType =\n | 'price'\n | 'twap'\n // TWAP with specified order amounts, which will be specified in the Trigger Order itself\n | 'twap_custom_amounts';\n\n/**\n * Fields associated with a TWAP trigger order.\n */\nexport interface OrderAppendixTwapFields {\n /**\n * Number of TWAP orders to be placed.\n */\n numOrders: number;\n /**\n * Maximum slippage on each TWAP order, based on the oracle price at time of order execution.\n * Ex: 0.01 means 1% slippage.\n */\n slippageFrac: number;\n}\n\n/**\n * Fields associated with an isolated order\n */\nexport interface OrderAppendixIsolatedFields {\n /**\n * Amount of margin to transfer into the isolated position.\n */\n margin: BigDecimalish;\n}\n\n/**\n * All the fields encoded by the order appendix\n */\nexport interface OrderAppendix {\n reduceOnly?: boolean;\n orderExecutionType: OrderExecutionType;\n /**\n * Specify the type of trigger that will be used for the order if the order will be sent to the trigger service.\n */\n triggerType?: OrderAppendixTriggerType;\n /**\n * Specify if the order is for an isolated position\n * An order CANNOT be both a TWAP order and an isolated order.\n */\n isolated?: OrderAppendixIsolatedFields;\n /**\n * Specify if the order is a TWAP order\n * An order CANNOT be both a TWAP order and an isolated order.\n */\n twap?: OrderAppendixTwapFields;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/types/orderAppendixTypes.ts"],"sourcesContent":["import { BigDecimalish } from '../utils/math';\nimport { OrderExecutionType } from './OrderExecutionType';\n\n/**\n * Encodes whether the order will be sent to the trigger service\n */\nexport type OrderAppendixTriggerType =\n | 'price'\n | 'twap'\n // TWAP with specified order amounts, which will be specified in the Trigger Order itself\n | 'twap_custom_amounts';\n\n/**\n * Fields associated with a TWAP trigger order.\n */\nexport interface OrderAppendixTwapFields {\n /**\n * Number of TWAP orders to be placed.\n */\n numOrders: number;\n /**\n * Maximum slippage on each TWAP order, based on the oracle price at time of order execution.\n * Ex: 0.01 means 1% slippage.\n */\n slippageFrac: number;\n}\n\n/**\n * Fields associated with an isolated order\n */\nexport interface OrderAppendixIsolatedFields {\n /**\n * Amount of margin to transfer into the isolated position.\n *\n * Implementation Note:\n * Packed appendix uses precision of 6 decimals on backend.\n * SDK automatically converts to/from x18 during packing/unpacking.\n */\n margin: BigDecimalish;\n}\n\n/**\n * All the fields encoded by the order appendix\n */\nexport interface OrderAppendix {\n reduceOnly?: boolean;\n orderExecutionType: OrderExecutionType;\n /**\n * Specify the type of trigger that will be used for the order if the order will be sent to the trigger service.\n */\n triggerType?: OrderAppendixTriggerType;\n /**\n * Specify if the order is for an isolated position\n * An order CANNOT be both a TWAP order and an isolated order.\n */\n isolated?: OrderAppendixIsolatedFields;\n /**\n * Specify if the order is a TWAP order\n * An order CANNOT be both a TWAP order and an isolated order.\n */\n twap?: OrderAppendixTwapFields;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -26,6 +26,10 @@ interface OrderAppendixTwapFields {
26
26
  interface OrderAppendixIsolatedFields {
27
27
  /**
28
28
  * Amount of margin to transfer into the isolated position.
29
+ *
30
+ * Implementation Note:
31
+ * Packed appendix uses precision of 6 decimals on backend.
32
+ * SDK automatically converts to/from x18 during packing/unpacking.
29
33
  */
30
34
  margin: BigDecimalish;
31
35
  }
@@ -26,6 +26,10 @@ interface OrderAppendixTwapFields {
26
26
  interface OrderAppendixIsolatedFields {
27
27
  /**
28
28
  * Amount of margin to transfer into the isolated position.
29
+ *
30
+ * Implementation Note:
31
+ * Packed appendix uses precision of 6 decimals on backend.
32
+ * SDK automatically converts to/from x18 during packing/unpacking.
29
33
  */
30
34
  margin: BigDecimalish;
31
35
  }
@@ -26,16 +26,20 @@ __export(appendixIsolatedValue_exports, {
26
26
  module.exports = __toCommonJS(appendixIsolatedValue_exports);
27
27
  var import_math = require("../../math/index.cjs");
28
28
  var import_bitMaskValue = require("./bitMaskValue.cjs");
29
- var marginDecimalAdjustmentMultiplier = 10n ** 12n;
29
+ var APPENDIX_V1_ISO_MARGIN_DECIMALS = 6;
30
+ var MARGIN_DECIMAL_ADJUSTMENT = import_math.NADO_PRODUCT_DECIMALS - APPENDIX_V1_ISO_MARGIN_DECIMALS;
30
31
  function packIsolatedOrderAppendixValue({
31
32
  margin
32
33
  }) {
33
- return (0, import_bitMaskValue.bitMaskValue)((0, import_math.toBigInt)(margin) / marginDecimalAdjustmentMultiplier, 64);
34
+ return (0, import_bitMaskValue.bitMaskValue)(
35
+ (0, import_math.toBigInt)((0, import_math.removeDecimals)(margin, MARGIN_DECIMAL_ADJUSTMENT)),
36
+ 64
37
+ );
34
38
  }
35
39
  function unpackIsolatedOrderAppendixValue(value) {
36
40
  const margin = (0, import_bitMaskValue.bitMaskValue)(value, 64);
37
41
  return {
38
- margin: margin * marginDecimalAdjustmentMultiplier
42
+ margin: (0, import_math.toBigInt)((0, import_math.addDecimals)(margin, MARGIN_DECIMAL_ADJUSTMENT))
39
43
  };
40
44
  }
41
45
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/utils/orders/appendix/appendixIsolatedValue.ts"],"sourcesContent":["import { OrderAppendixIsolatedFields } from '../../../types';\nimport { toBigInt } from '../../math';\nimport { bitMaskValue } from './bitMaskValue';\n\n/**\n * Appendix uses margin_x6, so we div/mul to align to our SDK's usual x18.\n */\nconst marginDecimalAdjustmentMultiplier = 10n ** 12n;\n\n/**\n * Packs the provided margin into a single 64-bit bigint.\n *\n * Bit layout (MSB → LSB):\n * | margin_x6 |\n * |-----------|\n * | 63..0 |\n * | 64 bits |\n *\n */\nexport function packIsolatedOrderAppendixValue({\n margin,\n}: OrderAppendixIsolatedFields): bigint {\n return bitMaskValue(toBigInt(margin) / marginDecimalAdjustmentMultiplier, 64);\n}\n\n/**\n * Unpacks a 64-bit bigint into its component fields for Isolated orders.\n *\n * @param value 64-bit bigint to unpack\n * @returns Object with:\n * - margin_x6: bigint, from bits 63..0\n */\nexport function unpackIsolatedOrderAppendixValue(\n value: bigint,\n): OrderAppendixIsolatedFields {\n const margin = bitMaskValue(value, 64);\n return {\n margin: margin * marginDecimalAdjustmentMultiplier,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAyB;AACzB,0BAA6B;AAK7B,IAAM,oCAAoC,OAAO;AAY1C,SAAS,+BAA+B;AAAA,EAC7C;AACF,GAAwC;AACtC,aAAO,sCAAa,sBAAS,MAAM,IAAI,mCAAmC,EAAE;AAC9E;AASO,SAAS,iCACd,OAC6B;AAC7B,QAAM,aAAS,kCAAa,OAAO,EAAE;AACrC,SAAO;AAAA,IACL,QAAQ,SAAS;AAAA,EACnB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/utils/orders/appendix/appendixIsolatedValue.ts"],"sourcesContent":["import { OrderAppendixIsolatedFields } from '../../../types';\nimport {\n addDecimals,\n NADO_PRODUCT_DECIMALS,\n removeDecimals,\n toBigInt,\n} from '../../math';\nimport { bitMaskValue } from './bitMaskValue';\n\nconst APPENDIX_V1_ISO_MARGIN_DECIMALS = 6;\n\n/* Appendix v1 uses x6 precision, so we need to adjust precision to/from SDK's usual precision */\nconst MARGIN_DECIMAL_ADJUSTMENT =\n NADO_PRODUCT_DECIMALS - APPENDIX_V1_ISO_MARGIN_DECIMALS;\n\n/**\n * Packs the provided margin into a single 64-bit bigint.\n *\n * Bit layout (MSB → LSB):\n * | margin_x6 |\n * |-----------|\n * | 63..0 |\n * | 64 bits |\n *\n */\nexport function packIsolatedOrderAppendixValue({\n margin,\n}: OrderAppendixIsolatedFields): bigint {\n return bitMaskValue(\n toBigInt(removeDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),\n 64,\n );\n}\n\n/**\n * Unpacks a 64-bit bigint into its component fields for Isolated orders.\n *\n * @param value 64-bit bigint to unpack\n * @returns Object with:\n * - margin_x6: bigint, from bits 63..0\n */\nexport function unpackIsolatedOrderAppendixValue(\n value: bigint,\n): OrderAppendixIsolatedFields {\n const margin = bitMaskValue(value, 64);\n return {\n margin: toBigInt(addDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAKO;AACP,0BAA6B;AAE7B,IAAM,kCAAkC;AAGxC,IAAM,4BACJ,oCAAwB;AAYnB,SAAS,+BAA+B;AAAA,EAC7C;AACF,GAAwC;AACtC,aAAO;AAAA,QACL,0BAAS,4BAAe,QAAQ,yBAAyB,CAAC;AAAA,IAC1D;AAAA,EACF;AACF;AASO,SAAS,iCACd,OAC6B;AAC7B,QAAM,aAAS,kCAAa,OAAO,EAAE;AACrC,SAAO;AAAA,IACL,YAAQ,0BAAS,yBAAY,QAAQ,yBAAyB,CAAC;AAAA,EACjE;AACF;","names":[]}
@@ -1,18 +1,27 @@
1
1
  import "../../../chunk-5WRI5ZAA.js";
2
2
 
3
3
  // src/utils/orders/appendix/appendixIsolatedValue.ts
4
- import { toBigInt } from "../../math/index.js";
4
+ import {
5
+ addDecimals,
6
+ NADO_PRODUCT_DECIMALS,
7
+ removeDecimals,
8
+ toBigInt
9
+ } from "../../math/index.js";
5
10
  import { bitMaskValue } from "./bitMaskValue.js";
6
- var marginDecimalAdjustmentMultiplier = 10n ** 12n;
11
+ var APPENDIX_V1_ISO_MARGIN_DECIMALS = 6;
12
+ var MARGIN_DECIMAL_ADJUSTMENT = NADO_PRODUCT_DECIMALS - APPENDIX_V1_ISO_MARGIN_DECIMALS;
7
13
  function packIsolatedOrderAppendixValue({
8
14
  margin
9
15
  }) {
10
- return bitMaskValue(toBigInt(margin) / marginDecimalAdjustmentMultiplier, 64);
16
+ return bitMaskValue(
17
+ toBigInt(removeDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),
18
+ 64
19
+ );
11
20
  }
12
21
  function unpackIsolatedOrderAppendixValue(value) {
13
22
  const margin = bitMaskValue(value, 64);
14
23
  return {
15
- margin: margin * marginDecimalAdjustmentMultiplier
24
+ margin: toBigInt(addDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT))
16
25
  };
17
26
  }
18
27
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/utils/orders/appendix/appendixIsolatedValue.ts"],"sourcesContent":["import { OrderAppendixIsolatedFields } from '../../../types';\nimport { toBigInt } from '../../math';\nimport { bitMaskValue } from './bitMaskValue';\n\n/**\n * Appendix uses margin_x6, so we div/mul to align to our SDK's usual x18.\n */\nconst marginDecimalAdjustmentMultiplier = 10n ** 12n;\n\n/**\n * Packs the provided margin into a single 64-bit bigint.\n *\n * Bit layout (MSB → LSB):\n * | margin_x6 |\n * |-----------|\n * | 63..0 |\n * | 64 bits |\n *\n */\nexport function packIsolatedOrderAppendixValue({\n margin,\n}: OrderAppendixIsolatedFields): bigint {\n return bitMaskValue(toBigInt(margin) / marginDecimalAdjustmentMultiplier, 64);\n}\n\n/**\n * Unpacks a 64-bit bigint into its component fields for Isolated orders.\n *\n * @param value 64-bit bigint to unpack\n * @returns Object with:\n * - margin_x6: bigint, from bits 63..0\n */\nexport function unpackIsolatedOrderAppendixValue(\n value: bigint,\n): OrderAppendixIsolatedFields {\n const margin = bitMaskValue(value, 64);\n return {\n margin: margin * marginDecimalAdjustmentMultiplier,\n };\n}\n"],"mappings":";;;AACA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAK7B,IAAM,oCAAoC,OAAO;AAY1C,SAAS,+BAA+B;AAAA,EAC7C;AACF,GAAwC;AACtC,SAAO,aAAa,SAAS,MAAM,IAAI,mCAAmC,EAAE;AAC9E;AASO,SAAS,iCACd,OAC6B;AAC7B,QAAM,SAAS,aAAa,OAAO,EAAE;AACrC,SAAO;AAAA,IACL,QAAQ,SAAS;AAAA,EACnB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/utils/orders/appendix/appendixIsolatedValue.ts"],"sourcesContent":["import { OrderAppendixIsolatedFields } from '../../../types';\nimport {\n addDecimals,\n NADO_PRODUCT_DECIMALS,\n removeDecimals,\n toBigInt,\n} from '../../math';\nimport { bitMaskValue } from './bitMaskValue';\n\nconst APPENDIX_V1_ISO_MARGIN_DECIMALS = 6;\n\n/* Appendix v1 uses x6 precision, so we need to adjust precision to/from SDK's usual precision */\nconst MARGIN_DECIMAL_ADJUSTMENT =\n NADO_PRODUCT_DECIMALS - APPENDIX_V1_ISO_MARGIN_DECIMALS;\n\n/**\n * Packs the provided margin into a single 64-bit bigint.\n *\n * Bit layout (MSB → LSB):\n * | margin_x6 |\n * |-----------|\n * | 63..0 |\n * | 64 bits |\n *\n */\nexport function packIsolatedOrderAppendixValue({\n margin,\n}: OrderAppendixIsolatedFields): bigint {\n return bitMaskValue(\n toBigInt(removeDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),\n 64,\n );\n}\n\n/**\n * Unpacks a 64-bit bigint into its component fields for Isolated orders.\n *\n * @param value 64-bit bigint to unpack\n * @returns Object with:\n * - margin_x6: bigint, from bits 63..0\n */\nexport function unpackIsolatedOrderAppendixValue(\n value: bigint,\n): OrderAppendixIsolatedFields {\n const margin = bitMaskValue(value, 64);\n return {\n margin: toBigInt(addDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),\n };\n}\n"],"mappings":";;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAE7B,IAAM,kCAAkC;AAGxC,IAAM,4BACJ,wBAAwB;AAYnB,SAAS,+BAA+B;AAAA,EAC7C;AACF,GAAwC;AACtC,SAAO;AAAA,IACL,SAAS,eAAe,QAAQ,yBAAyB,CAAC;AAAA,IAC1D;AAAA,EACF;AACF;AASO,SAAS,iCACd,OAC6B;AAC7B,QAAM,SAAS,aAAa,OAAO,EAAE;AACrC,SAAO;AAAA,IACL,QAAQ,SAAS,YAAY,QAAQ,yBAAyB,CAAC;AAAA,EACjE;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nadohq/shared",
3
- "version": "0.1.0-alpha.31",
3
+ "version": "0.1.0-alpha.32",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Shared utilities, types, and contract helpers for Nado SDK",
@@ -36,6 +36,10 @@
36
36
  }
37
37
  }
38
38
  },
39
+ "react-native": "./dist/index.js",
40
+ "main": "./dist/index.cjs",
41
+ "module": "./dist/index.js",
42
+ "types": "./dist/index.d.ts",
39
43
  "peerDependencies": {
40
44
  "bignumber.js": "^9.3.0",
41
45
  "viem": "*"
@@ -45,5 +49,5 @@
45
49
  "bignumber.js": "^9.3.0",
46
50
  "viem": "*"
47
51
  },
48
- "gitHead": "5491b8de4e6422d04a5ef9cd5ef736afdba8fa66"
52
+ "gitHead": "af3e125a5791069b1af98481cd36397ffb405951"
49
53
  }
@@ -31,6 +31,10 @@ export interface OrderAppendixTwapFields {
31
31
  export interface OrderAppendixIsolatedFields {
32
32
  /**
33
33
  * Amount of margin to transfer into the isolated position.
34
+ *
35
+ * Implementation Note:
36
+ * Packed appendix uses precision of 6 decimals on backend.
37
+ * SDK automatically converts to/from x18 during packing/unpacking.
34
38
  */
35
39
  margin: BigDecimalish;
36
40
  }
@@ -1,11 +1,17 @@
1
1
  import { OrderAppendixIsolatedFields } from '../../../types';
2
- import { toBigInt } from '../../math';
2
+ import {
3
+ addDecimals,
4
+ NADO_PRODUCT_DECIMALS,
5
+ removeDecimals,
6
+ toBigInt,
7
+ } from '../../math';
3
8
  import { bitMaskValue } from './bitMaskValue';
4
9
 
5
- /**
6
- * Appendix uses margin_x6, so we div/mul to align to our SDK's usual x18.
7
- */
8
- const marginDecimalAdjustmentMultiplier = 10n ** 12n;
10
+ const APPENDIX_V1_ISO_MARGIN_DECIMALS = 6;
11
+
12
+ /* Appendix v1 uses x6 precision, so we need to adjust precision to/from SDK's usual precision */
13
+ const MARGIN_DECIMAL_ADJUSTMENT =
14
+ NADO_PRODUCT_DECIMALS - APPENDIX_V1_ISO_MARGIN_DECIMALS;
9
15
 
10
16
  /**
11
17
  * Packs the provided margin into a single 64-bit bigint.
@@ -20,7 +26,10 @@ const marginDecimalAdjustmentMultiplier = 10n ** 12n;
20
26
  export function packIsolatedOrderAppendixValue({
21
27
  margin,
22
28
  }: OrderAppendixIsolatedFields): bigint {
23
- return bitMaskValue(toBigInt(margin) / marginDecimalAdjustmentMultiplier, 64);
29
+ return bitMaskValue(
30
+ toBigInt(removeDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),
31
+ 64,
32
+ );
24
33
  }
25
34
 
26
35
  /**
@@ -35,6 +44,6 @@ export function unpackIsolatedOrderAppendixValue(
35
44
  ): OrderAppendixIsolatedFields {
36
45
  const margin = bitMaskValue(value, 64);
37
46
  return {
38
- margin: margin * marginDecimalAdjustmentMultiplier,
47
+ margin: toBigInt(addDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),
39
48
  };
40
49
  }