@reyaxyz/common 0.362.1 → 0.363.0

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 (104) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/exposure/command.js +8 -22
  3. package/dist/commands/exposure/command.js.map +1 -1
  4. package/dist/incentives-api-types.js.map +1 -1
  5. package/dist/services/getNativeToken.js +1 -0
  6. package/dist/services/getNativeToken.js.map +1 -1
  7. package/dist/services/getSocketAddresses.js +1 -0
  8. package/dist/services/getSocketAddresses.js.map +1 -1
  9. package/dist/trading-api-types.js.map +1 -1
  10. package/dist/transactions/abis/Errors.json +1638 -34
  11. package/dist/transactions/abis/OrdersGateway.json +729 -123
  12. package/dist/transactions/abis/PassivePerpProxy.json +542 -0
  13. package/dist/transactions/buildMulticallTx.js.map +1 -1
  14. package/dist/transactions/consts.js +1 -2
  15. package/dist/transactions/consts.js.map +1 -1
  16. package/dist/transactions/contractAddresses.js +45 -5
  17. package/dist/transactions/contractAddresses.js.map +1 -1
  18. package/dist/transactions/sign.js +237 -111
  19. package/dist/transactions/sign.js.map +1 -1
  20. package/dist/types/commands/exposure/command.d.ts +8 -7
  21. package/dist/types/commands/exposure/command.d.ts.map +1 -1
  22. package/dist/types/incentives-api-types.d.ts +61 -5
  23. package/dist/types/incentives-api-types.d.ts.map +1 -1
  24. package/dist/types/services/getNativeToken.d.ts.map +1 -1
  25. package/dist/types/services/getSocketAddresses.d.ts.map +1 -1
  26. package/dist/types/trading-api-types.d.ts +200 -32
  27. package/dist/types/trading-api-types.d.ts.map +1 -1
  28. package/dist/types/transactions/buildMulticallTx.d.ts +1 -0
  29. package/dist/types/transactions/buildMulticallTx.d.ts.map +1 -1
  30. package/dist/types/transactions/consts.d.ts +0 -1
  31. package/dist/types/transactions/consts.d.ts.map +1 -1
  32. package/dist/types/transactions/contractAddresses.d.ts +0 -1
  33. package/dist/types/transactions/contractAddresses.d.ts.map +1 -1
  34. package/dist/types/transactions/sign.d.ts +113 -9
  35. package/dist/types/transactions/sign.d.ts.map +1 -1
  36. package/dist/types/types.d.ts +61 -65
  37. package/dist/types/types.d.ts.map +1 -1
  38. package/dist/types/utils/calculate.d.ts.map +1 -1
  39. package/dist/types/utils/consts.d.ts +2 -2
  40. package/dist/types/utils/consts.d.ts.map +1 -1
  41. package/dist/types/utils/error-sanitizer.d.ts +15 -0
  42. package/dist/types/utils/error-sanitizer.d.ts.map +1 -0
  43. package/dist/types/utils/index.d.ts +3 -0
  44. package/dist/types/utils/index.d.ts.map +1 -1
  45. package/dist/types/utils/network.d.ts.map +1 -1
  46. package/dist/types/utils/number.d.ts +5 -0
  47. package/dist/types/utils/number.d.ts.map +1 -1
  48. package/dist/types/utils/realized-balance.d.ts +54 -0
  49. package/dist/types/utils/realized-balance.d.ts.map +1 -0
  50. package/dist/types/utils/throttled-error.d.ts +42 -0
  51. package/dist/types/utils/throttled-error.d.ts.map +1 -0
  52. package/dist/types/utils/token/normalize.d.ts +2 -1
  53. package/dist/types/utils/token/normalize.d.ts.map +1 -1
  54. package/dist/types/utils/token/token-info-getters.d.ts.map +1 -1
  55. package/dist/types/utils/token/token-info.d.ts.map +1 -1
  56. package/dist/types.js +25 -11
  57. package/dist/types.js.map +1 -1
  58. package/dist/utils/calculate.js +18 -9
  59. package/dist/utils/calculate.js.map +1 -1
  60. package/dist/utils/consts.js +2 -7
  61. package/dist/utils/consts.js.map +1 -1
  62. package/dist/utils/error-sanitizer.js +135 -0
  63. package/dist/utils/error-sanitizer.js.map +1 -0
  64. package/dist/utils/index.js +3 -0
  65. package/dist/utils/index.js.map +1 -1
  66. package/dist/utils/network.js +4 -0
  67. package/dist/utils/network.js.map +1 -1
  68. package/dist/utils/number.js +96 -1
  69. package/dist/utils/number.js.map +1 -1
  70. package/dist/utils/realized-balance.js +126 -0
  71. package/dist/utils/realized-balance.js.map +1 -0
  72. package/dist/utils/throttled-error.js +60 -0
  73. package/dist/utils/throttled-error.js.map +1 -0
  74. package/dist/utils/token/normalize.js +2 -2
  75. package/dist/utils/token/normalize.js.map +1 -1
  76. package/dist/utils/token/token-info-getters.js +80 -5
  77. package/dist/utils/token/token-info-getters.js.map +1 -1
  78. package/dist/utils/token/token-info.js +7 -0
  79. package/dist/utils/token/token-info.js.map +1 -1
  80. package/package.json +3 -3
  81. package/src/commands/exposure/command.ts +8 -38
  82. package/src/incentives-api-types.ts +60 -5
  83. package/src/services/getNativeToken.ts +1 -0
  84. package/src/services/getSocketAddresses.ts +1 -0
  85. package/src/trading-api-types.ts +258 -39
  86. package/src/transactions/abis/Errors.json +5478 -3874
  87. package/src/transactions/abis/OrdersGateway.json +730 -124
  88. package/src/transactions/abis/PassivePerpProxy.json +542 -0
  89. package/src/transactions/buildMulticallTx.ts +4 -0
  90. package/src/transactions/consts.ts +0 -1
  91. package/src/transactions/contractAddresses.ts +42 -7
  92. package/src/transactions/sign.ts +306 -150
  93. package/src/types.ts +98 -83
  94. package/src/utils/calculate.ts +21 -8
  95. package/src/utils/consts.ts +4 -16
  96. package/src/utils/error-sanitizer.ts +137 -0
  97. package/src/utils/index.ts +3 -0
  98. package/src/utils/network.ts +4 -0
  99. package/src/utils/number.ts +110 -0
  100. package/src/utils/realized-balance.ts +163 -0
  101. package/src/utils/throttled-error.ts +85 -0
  102. package/src/utils/token/normalize.ts +6 -1
  103. package/src/utils/token/token-info-getters.ts +104 -6
  104. package/src/utils/token/token-info.ts +42 -0
@@ -1,5 +1,16 @@
1
1
  "use strict";
2
- var _a, _b, _c;
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var _a, _b, _c, _d, _e;
3
14
  Object.defineProperty(exports, "__esModule", { value: true });
4
15
  exports.getAddress = exports.ContractType = void 0;
5
16
  var types_1 = require("../types");
@@ -8,7 +19,6 @@ var ContractType;
8
19
  ContractType["CORE_PROXY"] = "core_proxy";
9
20
  ContractType["PASSIVE_POOL_PROXY"] = "passive_pool_proxy";
10
21
  ContractType["PERIPHERY_PROXY"] = "periphery_proxy";
11
- ContractType["CONDITIONAL_ORDERS_PROXY"] = "conditional_orders_proxy";
12
22
  ContractType["ORDERS_GATEWAY_PROXY"] = "orders_gateway_proxy";
13
23
  ContractType["PASSIVE_PERP_PROXY"] = "passive_perp_proxy";
14
24
  ContractType["ORACLE_ADAPTERS_PROXY"] = "oracle_adapters_proxy";
@@ -16,12 +26,11 @@ var ContractType;
16
26
  ContractType["REYA_SBTS"] = "reya_sbts";
17
27
  ContractType["REYA_TGE_DISTRIBUTION"] = "reya_tge_distribution";
18
28
  })(ContractType || (exports.ContractType = ContractType = {}));
19
- var addresses = (_a = {},
29
+ var remoteAddresses = (_a = {},
20
30
  _a[types_1.ReyaChainId.reyaCronos] = (_b = {},
21
31
  _b[ContractType.CORE_PROXY] = '0xc6fb022962e1426f4e0ec9d2f8861c57926e9f72',
22
32
  _b[ContractType.PASSIVE_POOL_PROXY] = '0x9a3a664987b88790a6fdc1632e3b607813fd94ff',
23
33
  _b[ContractType.PERIPHERY_PROXY] = '0x94ccae812f1647696754412082dd6684c2366a7f',
24
- _b[ContractType.CONDITIONAL_ORDERS_PROXY] = '0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5',
25
34
  _b[ContractType.ORDERS_GATEWAY_PROXY] = '0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5',
26
35
  _b[ContractType.PASSIVE_PERP_PROXY] = '0x9ec177fed042ef2307928be2f5cdbf663b20244b',
27
36
  _b[ContractType.ORACLE_ADAPTERS_PROXY] = '0xc501a2356703cd351703d68963c6f4136120f7cf',
@@ -33,7 +42,6 @@ var addresses = (_a = {},
33
42
  _c[ContractType.CORE_PROXY] = '0xa763b6a5e09378434406c003dae6487fbbdc1a80',
34
43
  _c[ContractType.PASSIVE_POOL_PROXY] = '0xb4b77d6180cc14472a9a7bdff01cc2459368d413',
35
44
  _c[ContractType.PERIPHERY_PROXY] = '0xcd2869d1eb1bc8991bc55de9e9b779e912faf736',
36
- _c[ContractType.CONDITIONAL_ORDERS_PROXY] = '0xfc8c96be87da63cecddbf54abfa7b13ee8044739',
37
45
  _c[ContractType.ORDERS_GATEWAY_PROXY] = '0xfc8c96be87da63cecddbf54abfa7b13ee8044739',
38
46
  _c[ContractType.PASSIVE_PERP_PROXY] = '0x27e5cb712334e101b3c232eb0be198baaa595f5f',
39
47
  _c[ContractType.ORACLE_ADAPTERS_PROXY] = '0x32edabc058c1207fe0ec5f8557643c28e4ff379e',
@@ -42,7 +50,39 @@ var addresses = (_a = {},
42
50
  _c[ContractType.REYA_TGE_DISTRIBUTION] = '0x0000000000000000000000000000000000000000',
43
51
  _c),
44
52
  _a);
53
+ var addresses = __assign(__assign({}, remoteAddresses), (_d = {}, _d[types_1.ReyaChainId.reyaLocal] = {}, _d));
54
+ // Map stores the resolved env-var VALUES (not the var names) so that
55
+ // webpack / Next.js `DefinePlugin` can statically inline them into
56
+ // browser bundles.
57
+ //
58
+ // DefinePlugin only inlines literal `process.env.NAME` access — a
59
+ // dynamic `process.env[varName]` lookup is opaque to its source-text
60
+ // pass and stays `undefined` in the browser. Keeping the four
61
+ // `process.env.*` accesses as static literals in this object literal
62
+ // is what makes the override work in both Node (real `process.env` at
63
+ // runtime) and browser (DefinePlugin-substituted constants at build
64
+ // time). See PR #2660 / Daniel's comment for the discovery context.
65
+ //
66
+ // New entries must use the same static-literal pattern; do NOT
67
+ // introduce a dynamic `process.env[someVar]` lookup downstream.
68
+ var CONTRACT_ADDRESS_ENV_OVERRIDES = (_e = {},
69
+ _e[ContractType.CORE_PROXY] = process.env.CORE_PROXY_ADDRESS,
70
+ _e[ContractType.PASSIVE_PERP_PROXY] = process.env.PASSIVE_PERP_PROXY_ADDRESS,
71
+ _e[ContractType.ORDERS_GATEWAY_PROXY] = process.env.ORDERS_GATEWAY_PROXY_ADDRESS,
72
+ _e[ContractType.PERIPHERY_PROXY] = process.env.PERIPHERY_PROXY_ADDRESS,
73
+ _e[ContractType.ORACLE_ADAPTERS_PROXY] = process.env.ORACLE_ADAPTERS_PROXY_ADDRESS,
74
+ _e[ContractType.PASSIVE_POOL_PROXY] = process.env.PASSIVE_POOL_PROXY_ADDRESS,
75
+ _e);
45
76
  var getAddress = function (chainId, contractName) {
77
+ // Normalize env-overridden addresses to lowercase. The hardcoded fallback
78
+ // map below stores lowercased values, and downstream comparisons (e.g.
79
+ // transaction-whitelist.ts uses `convertToAddress(target) === OG_ADDRESS`,
80
+ // which lowercases the runtime target) assume that invariant. Without
81
+ // this, a checksummed env value silently fails every comparison and the
82
+ // OG-aware settlement path gets bypassed.
83
+ var override = CONTRACT_ADDRESS_ENV_OVERRIDES[contractName];
84
+ if (override)
85
+ return override.toLowerCase();
46
86
  var keyChainId = chainId.toString();
47
87
  if (!Object.keys(addresses).includes(keyChainId)) {
48
88
  throw new Error("Unspecified addresses for chain id ".concat(keyChainId));
@@ -1 +1 @@
1
- {"version":3,"file":"contractAddresses.js","sourceRoot":"/","sources":["transactions/contractAddresses.ts"],"names":[],"mappings":";;;;AAAA,kCAAgD;AAEhD,IAAY,YAWX;AAXD,WAAY,YAAY;IACtB,yCAAyB,CAAA;IACzB,yDAAyC,CAAA;IACzC,mDAAmC,CAAA;IACnC,qEAAqD,CAAA;IACrD,6DAA6C,CAAA;IAC7C,yDAAyC,CAAA;IACzC,+DAA+C,CAAA;IAC/C,uCAAuB,CAAA;IACvB,uCAAuB,CAAA;IACvB,+DAA+C,CAAA;AACjD,CAAC,EAXW,YAAY,4BAAZ,YAAY,QAWvB;AAED,IAAM,SAAS;IACb,GAAC,mBAAW,CAAC,UAAU;QACrB,GAAC,YAAY,CAAC,UAAU,IAAG,4CAA4C;QACvE,GAAC,YAAY,CAAC,kBAAkB,IAC9B,4CAA4C;QAC9C,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C3D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,kCAA2B,YAAY,cAAW,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,gBAAgB,CAAC,YAAY,CAAC,CAAC;AACxC,CAAC,CAAC;AAhBW,QAAA,UAAU,cAgBrB","sourcesContent":["import { Address, ReyaChainId } from '../types';\n\nexport enum ContractType {\n CORE_PROXY = 'core_proxy',\n PASSIVE_POOL_PROXY = 'passive_pool_proxy',\n PERIPHERY_PROXY = 'periphery_proxy',\n CONDITIONAL_ORDERS_PROXY = 'conditional_orders_proxy',\n ORDERS_GATEWAY_PROXY = 'orders_gateway_proxy',\n PASSIVE_PERP_PROXY = 'passive_perp_proxy',\n ORACLE_ADAPTERS_PROXY = 'oracle_adapters_proxy',\n MULTICALL = 'multicall',\n REYA_SBTS = 'reya_sbts',\n REYA_TGE_DISTRIBUTION = 'reya_tge_distribution',\n}\n\nconst addresses: Record<ReyaChainId, Record<ContractType, Address>> = {\n [ReyaChainId.reyaCronos]: {\n [ContractType.CORE_PROXY]: '0xc6fb022962e1426f4e0ec9d2f8861c57926e9f72',\n [ContractType.PASSIVE_POOL_PROXY]:\n '0x9a3a664987b88790a6fdc1632e3b607813fd94ff',\n [ContractType.PERIPHERY_PROXY]:\n '0x94ccae812f1647696754412082dd6684c2366a7f',\n [ContractType.CONDITIONAL_ORDERS_PROXY]:\n '0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5',\n [ContractType.ORDERS_GATEWAY_PROXY]:\n '0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5',\n [ContractType.PASSIVE_PERP_PROXY]:\n '0x9ec177fed042ef2307928be2f5cdbf663b20244b',\n [ContractType.ORACLE_ADAPTERS_PROXY]:\n '0xc501a2356703cd351703d68963c6f4136120f7cf',\n [ContractType.MULTICALL]: '0x5abde4f0af8eaf3c9967f7fa126e59a103357b5c',\n [ContractType.REYA_SBTS]: '0xc0092ea9179ace93b0cd8910958e335575562722',\n [ContractType.REYA_TGE_DISTRIBUTION]:\n '0x16917248669fa64340e6517538e419588e9684c3',\n },\n [ReyaChainId.reyaNetwork]: {\n [ContractType.CORE_PROXY]: '0xa763b6a5e09378434406c003dae6487fbbdc1a80',\n [ContractType.PASSIVE_POOL_PROXY]:\n '0xb4b77d6180cc14472a9a7bdff01cc2459368d413',\n [ContractType.PERIPHERY_PROXY]:\n '0xcd2869d1eb1bc8991bc55de9e9b779e912faf736',\n [ContractType.CONDITIONAL_ORDERS_PROXY]:\n '0xfc8c96be87da63cecddbf54abfa7b13ee8044739',\n [ContractType.ORDERS_GATEWAY_PROXY]:\n '0xfc8c96be87da63cecddbf54abfa7b13ee8044739',\n [ContractType.PASSIVE_PERP_PROXY]:\n '0x27e5cb712334e101b3c232eb0be198baaa595f5f',\n [ContractType.ORACLE_ADAPTERS_PROXY]:\n '0x32edabc058c1207fe0ec5f8557643c28e4ff379e',\n [ContractType.MULTICALL]: '0xed28d27dfca47ad2513c9f2e2d3c098c2ea5a47f',\n [ContractType.REYA_SBTS]: '0x14d7c1efc024e118df70b241afbd2447d37f1ed6',\n [ContractType.REYA_TGE_DISTRIBUTION]:\n '0x0000000000000000000000000000000000000000',\n },\n};\nexport const getAddress = (\n chainId: number,\n contractName: ContractType,\n): Address => {\n const keyChainId = chainId.toString();\n\n if (!Object.keys(addresses).includes(keyChainId)) {\n throw new Error(`Unspecified addresses for chain id ${keyChainId}`);\n }\n\n const networkAddresses = addresses[chainId as ReyaChainId];\n if (!Object.keys(networkAddresses).includes(contractName)) {\n throw new Error(`Unspecified address for ${contractName} contract`);\n }\n\n return networkAddresses[contractName];\n};\n"]}
1
+ {"version":3,"file":"contractAddresses.js","sourceRoot":"/","sources":["transactions/contractAddresses.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kCAAgD;AAEhD,IAAY,YAUX;AAVD,WAAY,YAAY;IACt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B,CAAC,CAAC;IAC3D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,kCAA2B,YAAY,cAAW,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,gBAAgB,CAAC,YAAY,CAAE,CAAC;AACzC,CAAC,CAAC;AAzBW,QAAA,UAAU,cAyBrB","sourcesContent":["import { Address, ReyaChainId } from '../types';\n\nexport enum ContractType {\n CORE_PROXY = 'core_proxy',\n PASSIVE_POOL_PROXY = 'passive_pool_proxy',\n PERIPHERY_PROXY = 'periphery_proxy',\n ORDERS_GATEWAY_PROXY = 'orders_gateway_proxy',\n PASSIVE_PERP_PROXY = 'passive_perp_proxy',\n ORACLE_ADAPTERS_PROXY = 'oracle_adapters_proxy',\n MULTICALL = 'multicall',\n REYA_SBTS = 'reya_sbts',\n REYA_TGE_DISTRIBUTION = 'reya_tge_distribution',\n}\n\ntype RemoteReyaChainId = Exclude<ReyaChainId, ReyaChainId.reyaLocal>;\n\nconst remoteAddresses = {\n [ReyaChainId.reyaCronos]: {\n [ContractType.CORE_PROXY]: '0xc6fb022962e1426f4e0ec9d2f8861c57926e9f72',\n [ContractType.PASSIVE_POOL_PROXY]:\n '0x9a3a664987b88790a6fdc1632e3b607813fd94ff',\n [ContractType.PERIPHERY_PROXY]:\n '0x94ccae812f1647696754412082dd6684c2366a7f',\n [ContractType.ORDERS_GATEWAY_PROXY]:\n '0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5',\n [ContractType.PASSIVE_PERP_PROXY]:\n '0x9ec177fed042ef2307928be2f5cdbf663b20244b',\n [ContractType.ORACLE_ADAPTERS_PROXY]:\n '0xc501a2356703cd351703d68963c6f4136120f7cf',\n [ContractType.MULTICALL]: '0x5abde4f0af8eaf3c9967f7fa126e59a103357b5c',\n [ContractType.REYA_SBTS]: '0xc0092ea9179ace93b0cd8910958e335575562722',\n [ContractType.REYA_TGE_DISTRIBUTION]:\n '0x16917248669fa64340e6517538e419588e9684c3',\n },\n [ReyaChainId.reyaNetwork]: {\n [ContractType.CORE_PROXY]: '0xa763b6a5e09378434406c003dae6487fbbdc1a80',\n [ContractType.PASSIVE_POOL_PROXY]:\n '0xb4b77d6180cc14472a9a7bdff01cc2459368d413',\n [ContractType.PERIPHERY_PROXY]:\n '0xcd2869d1eb1bc8991bc55de9e9b779e912faf736',\n [ContractType.ORDERS_GATEWAY_PROXY]:\n '0xfc8c96be87da63cecddbf54abfa7b13ee8044739',\n [ContractType.PASSIVE_PERP_PROXY]:\n '0x27e5cb712334e101b3c232eb0be198baaa595f5f',\n [ContractType.ORACLE_ADAPTERS_PROXY]:\n '0x32edabc058c1207fe0ec5f8557643c28e4ff379e',\n [ContractType.MULTICALL]: '0xed28d27dfca47ad2513c9f2e2d3c098c2ea5a47f',\n [ContractType.REYA_SBTS]: '0x14d7c1efc024e118df70b241afbd2447d37f1ed6',\n [ContractType.REYA_TGE_DISTRIBUTION]:\n '0x0000000000000000000000000000000000000000',\n },\n} satisfies Record<RemoteReyaChainId, Record<ContractType, Address>>;\n\nconst addresses: Record<ReyaChainId, Partial<Record<ContractType, Address>>> = {\n ...remoteAddresses,\n [ReyaChainId.reyaLocal]: {},\n};\n// Map stores the resolved env-var VALUES (not the var names) so that\n// webpack / Next.js `DefinePlugin` can statically inline them into\n// browser bundles.\n//\n// DefinePlugin only inlines literal `process.env.NAME` access — a\n// dynamic `process.env[varName]` lookup is opaque to its source-text\n// pass and stays `undefined` in the browser. Keeping the four\n// `process.env.*` accesses as static literals in this object literal\n// is what makes the override work in both Node (real `process.env` at\n// runtime) and browser (DefinePlugin-substituted constants at build\n// time). See PR #2660 / Daniel's comment for the discovery context.\n//\n// New entries must use the same static-literal pattern; do NOT\n// introduce a dynamic `process.env[someVar]` lookup downstream.\nconst CONTRACT_ADDRESS_ENV_OVERRIDES: Partial<Record<ContractType, string>> = {\n [ContractType.CORE_PROXY]: process.env.CORE_PROXY_ADDRESS,\n [ContractType.PASSIVE_PERP_PROXY]: process.env.PASSIVE_PERP_PROXY_ADDRESS,\n [ContractType.ORDERS_GATEWAY_PROXY]: process.env.ORDERS_GATEWAY_PROXY_ADDRESS,\n [ContractType.PERIPHERY_PROXY]: process.env.PERIPHERY_PROXY_ADDRESS,\n [ContractType.ORACLE_ADAPTERS_PROXY]:\n process.env.ORACLE_ADAPTERS_PROXY_ADDRESS,\n [ContractType.PASSIVE_POOL_PROXY]: process.env.PASSIVE_POOL_PROXY_ADDRESS,\n};\n\nexport const getAddress = (\n chainId: number,\n contractName: ContractType,\n): Address => {\n // Normalize env-overridden addresses to lowercase. The hardcoded fallback\n // map below stores lowercased values, and downstream comparisons (e.g.\n // transaction-whitelist.ts uses `convertToAddress(target) === OG_ADDRESS`,\n // which lowercases the runtime target) assume that invariant. Without\n // this, a checksummed env value silently fails every comparison and the\n // OG-aware settlement path gets bypassed.\n const override = CONTRACT_ADDRESS_ENV_OVERRIDES[contractName];\n if (override) return override.toLowerCase() as Address;\n\n const keyChainId = chainId.toString();\n\n if (!Object.keys(addresses).includes(keyChainId)) {\n throw new Error(`Unspecified addresses for chain id ${keyChainId}`);\n }\n\n const networkAddresses = addresses[chainId as ReyaChainId];\n if (!Object.keys(networkAddresses).includes(contractName)) {\n throw new Error(`Unspecified address for ${contractName} contract`);\n }\n\n return networkAddresses[contractName]!;\n};\n"]}
@@ -36,10 +36,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.signManagePermissionBySig = exports.signRevokePermission = exports.signVote = exports.signGrantPermission = exports.signCancelConditionalOrder = exports.signMassCancel = exports.signOrderCancel = exports.isConditionalOrderSignatureValid = exports.signOrdersGatewayOrder = exports.createOrdersGatewayOrderNonce = exports.getReyaDomain = exports.signPoolRemoveLiquidity = exports.signCoreCommands = exports.convertEthersSignatureToEIP712Signature = void 0;
39
+ exports.signManagePermissionBySig = exports.signMECancelAllAfter = exports.signMEMassCancel = exports.signMEOrderCancel = exports.signRevokePermission = exports.signVote = exports.signGrantPermission = exports.isOrderSignatureValid = exports.signOrder = exports.fullPositionStopQuantity = exports.FULL_POSITION_STOP_SENTINEL = exports.orderTypes = exports.signMassCancel = exports.signOrderCancel = exports.cancelAllAfterTypes = exports.massCancelTypes = exports.orderCancelTypes = exports.getReyaDomain = exports.signPoolRemoveLiquidity = exports.signCoreCommands = exports.convertEthersSignatureToEIP712Signature = void 0;
40
40
  var ethers_1 = require("ethers");
41
41
  var contractAddresses_1 = require("./contractAddresses");
42
- var types_1 = require("../types");
43
42
  function convertEthersSignatureToEIP712Signature(signature, deadline) {
44
43
  return {
45
44
  v: signature.v,
@@ -159,101 +158,26 @@ function getReyaDomain(verifyingContract) {
159
158
  };
160
159
  }
161
160
  exports.getReyaDomain = getReyaDomain;
162
- var conditionalOrderTypes = {
163
- ConditionalOrder: [
164
- { name: 'verifyingChainId', type: 'uint256' },
165
- { name: 'deadline', type: 'uint256' },
166
- { name: 'order', type: 'ConditionalOrderDetails' },
167
- ],
168
- ConditionalOrderDetails: [
169
- { name: 'accountId', type: 'uint128' },
170
- { name: 'marketId', type: 'uint128' },
171
- { name: 'exchangeId', type: 'uint128' },
172
- { name: 'counterpartyAccountIds', type: 'uint128[]' },
173
- { name: 'orderType', type: 'uint8' },
174
- { name: 'inputs', type: 'bytes' },
175
- { name: 'signer', type: 'address' },
176
- { name: 'nonce', type: 'uint256' },
177
- ],
178
- };
179
- function createOrdersGatewayOrderNonce(accountId, marketId, timestampMs) {
180
- // Validate the input ranges
181
- if (marketId < 0 || marketId >= Math.pow(2, 32))
182
- throw new Error('marketId is out of range');
183
- if (accountId < 0 || accountId >= Math.pow(2, 128))
184
- throw new Error('accountId is out of range');
185
- if (timestampMs < 0 || timestampMs >= Math.pow(2, 64))
186
- throw new Error('timestamp is out of range');
187
- var hashUint256 = (BigInt(accountId) << BigInt(98)) |
188
- (BigInt(timestampMs) << BigInt(32)) |
189
- BigInt(marketId);
190
- return hashUint256;
191
- }
192
- exports.createOrdersGatewayOrderNonce = createOrdersGatewayOrderNonce;
193
- function signOrdersGatewayOrder(signer, reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, orderType, inputs, deadline, creationTimestampMs, customNonce) {
194
- return __awaiter(this, void 0, void 0, function () {
195
- var nonce, signature, _a, _b;
196
- var _c, _d;
197
- return __generator(this, function (_e) {
198
- switch (_e.label) {
199
- case 0:
200
- nonce = customNonce !== null && customNonce !== void 0 ? customNonce : createOrdersGatewayOrderNonce(accountId, marketId, creationTimestampMs);
201
- _a = signReyaTypedData;
202
- _b = [signer,
203
- (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY),
204
- conditionalOrderTypes];
205
- _c = {
206
- verifyingChainId: reyaChainId,
207
- deadline: BigInt(deadline)
208
- };
209
- _d = {
210
- accountId: accountId,
211
- marketId: marketId,
212
- exchangeId: exchangeId,
213
- counterpartyAccountIds: counterpartyAccountIds,
214
- orderType: orderType,
215
- inputs: inputs
216
- };
217
- return [4 /*yield*/, signer.getAddress()];
218
- case 1: return [4 /*yield*/, _a.apply(void 0, _b.concat([(_c.order = (_d.signer = _e.sent(),
219
- _d.nonce = nonce,
220
- _d),
221
- _c)]))];
222
- case 2:
223
- signature = _e.sent();
224
- return [2 /*return*/, {
225
- serializedSignature: signature.serialized,
226
- nonce: nonce,
227
- signature: convertEthersSignatureToEIP712Signature(signature, deadline),
228
- }];
229
- }
230
- });
231
- });
232
- }
233
- exports.signOrdersGatewayOrder = signOrdersGatewayOrder;
234
- function isConditionalOrderSignatureValid(signerAddress, signature, reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, orderType, inputs, nonce, deadline) {
235
- // Encode the data for recovering the address
236
- var domain = getReyaDomain((0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.CONDITIONAL_ORDERS_PROXY));
237
- var value = {
238
- verifyingChainId: reyaChainId,
239
- deadline: BigInt(deadline),
240
- order: {
241
- accountId: accountId,
242
- marketId: marketId,
243
- exchangeId: exchangeId,
244
- counterpartyAccountIds: counterpartyAccountIds,
245
- orderType: orderType,
246
- inputs: inputs,
247
- signer: signerAddress,
248
- nonce: nonce,
249
- },
250
- };
251
- // Recover the address
252
- var recoveredAddress = (0, ethers_1.verifyTypedData)(domain, conditionalOrderTypes, value, signature);
253
- return recoveredAddress.toLowerCase() === signerAddress.toLowerCase();
254
- }
255
- exports.isConditionalOrderSignatureValid = isConditionalOrderSignatureValid;
256
- var orderCancelTypes = {
161
+ // PRO-126 Bug 5 retired the legacy `ConditionalOrderDetails` typehash +
162
+ // `signOrdersGatewayOrder` / `isConditionalOrderSignatureValid` /
163
+ // `createOrdersGatewayOrderNonce` helpers. The on-chain
164
+ // `OrdersGateway.execute` selector that consumed those signatures is
165
+ // gone; every order class now signs the new flat `OrderDetails` schema
166
+ // via `signOrder` further down this file.
167
+ // The three cancel-side typed-data schemas below are EXPORTED as the single
168
+ // source of truth for signer AND verifier — common-backend's
169
+ // `recover{OrderCancel,MassCancel,CancelAllAfter}Signer` import them from
170
+ // here (like `orderTypes` for the Order struct). They used to be duplicated
171
+ // module-private consts on each side; any drift (field rename / width /
172
+ // reorder) silently breaks 100% of signature recovery for that request
173
+ // class, so exactly one copy may exist.
174
+ /**
175
+ * EIP-712 typed-data structures for the OrderCancel signature scheme used by
176
+ * the matching engine for order cancellations. The signer signs over a value
177
+ * of shape
178
+ * `{ verifyingChainId, deadline, cancel: { accountId, marketId, orderId, clOrdId, nonce } }`.
179
+ */
180
+ exports.orderCancelTypes = {
257
181
  OrderCancel: [
258
182
  { name: 'verifyingChainId', type: 'uint64' },
259
183
  { name: 'deadline', type: 'uint64' },
@@ -267,7 +191,12 @@ var orderCancelTypes = {
267
191
  { name: 'nonce', type: 'uint64' },
268
192
  ],
269
193
  };
270
- var massCancelTypes = {
194
+ /**
195
+ * EIP-712 typed-data structures for the MassCancel signature scheme used by
196
+ * the matching engine for mass cancellations. The signer signs over a value
197
+ * of shape `{ verifyingChainId, deadline, massCancel: { accountId, marketId, nonce } }`.
198
+ */
199
+ exports.massCancelTypes = {
271
200
  MassCancel: [
272
201
  { name: 'verifyingChainId', type: 'uint64' },
273
202
  { name: 'deadline', type: 'uint64' },
@@ -279,12 +208,31 @@ var massCancelTypes = {
279
208
  { name: 'nonce', type: 'uint64' },
280
209
  ],
281
210
  };
211
+ /**
212
+ * EIP-712 typed-data structures for the CancelAllAfter signature scheme used
213
+ * by the matching engine for the cancel-on-disconnect dead-man's-switch. The
214
+ * signer signs over a value of shape
215
+ * `{ verifyingChainId, deadline, cancelAllAfter: { accountId, timeoutMs, nonce } }`.
216
+ * uint64 throughout, matching the OrderCancel / MassCancel family.
217
+ */
218
+ exports.cancelAllAfterTypes = {
219
+ CancelAllAfter: [
220
+ { name: 'verifyingChainId', type: 'uint64' },
221
+ { name: 'deadline', type: 'uint64' },
222
+ { name: 'cancelAllAfter', type: 'CancelAllAfterDetails' },
223
+ ],
224
+ CancelAllAfterDetails: [
225
+ { name: 'accountId', type: 'uint64' },
226
+ { name: 'timeoutMs', type: 'uint64' },
227
+ { name: 'nonce', type: 'uint64' },
228
+ ],
229
+ };
282
230
  function signOrderCancel(signer, reyaChainId, accountId, marketId, orderId, clOrdId, nonce, deadline) {
283
231
  return __awaiter(this, void 0, void 0, function () {
284
232
  var signature;
285
233
  return __generator(this, function (_a) {
286
234
  switch (_a.label) {
287
- case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY), orderCancelTypes, {
235
+ case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY), exports.orderCancelTypes, {
288
236
  verifyingChainId: reyaChainId,
289
237
  deadline: deadline,
290
238
  cancel: {
@@ -312,7 +260,7 @@ function signMassCancel(signer, reyaChainId, accountId, marketId, nonce, deadlin
312
260
  var signature;
313
261
  return __generator(this, function (_a) {
314
262
  switch (_a.label) {
315
- case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY), massCancelTypes, {
263
+ case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY), exports.massCancelTypes, {
316
264
  verifyingChainId: reyaChainId,
317
265
  deadline: deadline,
318
266
  massCancel: {
@@ -333,24 +281,134 @@ function signMassCancel(signer, reyaChainId, accountId, marketId, nonce, deadlin
333
281
  });
334
282
  }
335
283
  exports.signMassCancel = signMassCancel;
336
- function signCancelConditionalOrder(signer, orderId) {
284
+ // -----------------------------------------------------------------------------
285
+ // perpOB: EIP-712 typed data for the flat `Order` / `OrderDetails` struct
286
+ // -----------------------------------------------------------------------------
287
+ // Matches the post-audit on-chain redesign in
288
+ // reya-network/feat/perpOB (orders-gateway/src/libraries/DataTypes.sol +
289
+ // ConditionalOrderHashing.sol). PRO-126 Bug 5 retired the legacy
290
+ // `conditionalOrderTypes` / `signOrdersGatewayOrder` / `isConditionalOrderSignatureValid`
291
+ // surface that this struct replaced — every order class (spot + perp,
292
+ // IOC + GTC + TP + SL) now signs against `OrderDetails` here.
293
+ //
294
+ // Contract: Order envelope + flat OrderDetails inner struct. Two distinct time
295
+ // values are signed:
296
+ // - envelope `deadline` -> signature validity, enforced by API at entry
297
+ // - inner `expiresAfter` -> order lifetime, enforced on-chain at execution
298
+ // Convention: callers should set `deadline <= expiresAfter` when `expiresAfter > 0`.
299
+ // See reya-api-specs/docs/eip712.md for the canonical description.
300
+ exports.orderTypes = {
301
+ Order: [
302
+ { name: 'verifyingChainId', type: 'uint256' },
303
+ { name: 'deadline', type: 'uint256' },
304
+ { name: 'order', type: 'OrderDetails' },
305
+ ],
306
+ OrderDetails: [
307
+ { name: 'accountId', type: 'uint128' },
308
+ { name: 'marketId', type: 'uint128' },
309
+ { name: 'exchangeId', type: 'uint128' },
310
+ { name: 'orderType', type: 'uint8' },
311
+ { name: 'quantity', type: 'int256' },
312
+ { name: 'limitPrice', type: 'uint256' },
313
+ { name: 'triggerPrice', type: 'uint256' },
314
+ { name: 'timeInForce', type: 'uint8' },
315
+ { name: 'clientOrderId', type: 'uint64' },
316
+ { name: 'reduceOnly', type: 'bool' },
317
+ { name: 'postOnly', type: 'bool' },
318
+ { name: 'expiresAfter', type: 'uint256' },
319
+ { name: 'signer', type: 'address' },
320
+ { name: 'nonce', type: 'uint256' },
321
+ ],
322
+ };
323
+ /**
324
+ * Full-position stop sentinel — `type(int256).max` (2^255 − 1), mirroring
325
+ * `FULL_POSITION_STOP_SENTINEL` in the OrdersGateway (reya-network #738). A
326
+ * STOP_LOSS / TAKE_PROFIT signs quantity `±sentinel` (the sign carries the
327
+ * close side: −sentinel sells out a long, +sentinel buys back a short); the
328
+ * chain enforces the iff — a stop with any other quantity (including the old
329
+ * quantity-0 encoding) reverts, and the sentinel magnitude is reserved (a
330
+ * non-stop signing it reverts). Raw int256 value, NOT E18-scaled. Signer and
331
+ * verifier must derive it from THIS constant so they can never drift.
332
+ */
333
+ exports.FULL_POSITION_STOP_SENTINEL = (BigInt(1) << BigInt(255)) - BigInt(1);
334
+ /** The signed quantity for a full-position stop: sign carries the close side. */
335
+ function fullPositionStopQuantity(isBuy) {
336
+ return isBuy ? exports.FULL_POSITION_STOP_SENTINEL : -exports.FULL_POSITION_STOP_SENTINEL;
337
+ }
338
+ exports.fullPositionStopQuantity = fullPositionStopQuantity;
339
+ function signOrder(signer, reyaChainId, params) {
340
+ var _a;
337
341
  return __awaiter(this, void 0, void 0, function () {
338
- var message;
339
- return __generator(this, function (_a) {
340
- switch (_a.label) {
342
+ var signature, _b, _c;
343
+ var _d, _e;
344
+ return __generator(this, function (_f) {
345
+ switch (_f.label) {
341
346
  case 0:
342
- message = {
343
- orderId: orderId,
344
- status: types_1.ConditionalOrderStatus.CANCELLED,
345
- actionType: 'changeStatus',
347
+ _b = signReyaTypedData;
348
+ _c = [signer,
349
+ (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY),
350
+ exports.orderTypes];
351
+ _d = {
352
+ verifyingChainId: reyaChainId,
353
+ deadline: BigInt(params.deadline)
354
+ };
355
+ _e = {
356
+ accountId: params.accountId,
357
+ marketId: params.marketId,
358
+ exchangeId: params.exchangeId,
359
+ orderType: params.orderType,
360
+ quantity: params.quantity,
361
+ limitPrice: params.limitPrice,
362
+ triggerPrice: params.triggerPrice,
363
+ timeInForce: params.timeInForce,
364
+ clientOrderId: params.clientOrderId,
365
+ reduceOnly: params.reduceOnly,
366
+ postOnly: (_a = params.postOnly) !== null && _a !== void 0 ? _a : false,
367
+ expiresAfter: params.expiresAfter
346
368
  };
347
- return [4 /*yield*/, signer.signMessage(JSON.stringify(message))];
348
- case 1: return [2 /*return*/, _a.sent()];
369
+ return [4 /*yield*/, signer.getAddress()];
370
+ case 1: return [4 /*yield*/, _b.apply(void 0, _c.concat([(_d.order = (_e.signer = _f.sent(),
371
+ _e.nonce = params.nonce,
372
+ _e),
373
+ _d)]))];
374
+ case 2:
375
+ signature = _f.sent();
376
+ return [2 /*return*/, {
377
+ serializedSignature: signature.serialized,
378
+ signature: convertEthersSignatureToEIP712Signature(signature, params.deadline),
379
+ }];
349
380
  }
350
381
  });
351
382
  });
352
383
  }
353
- exports.signCancelConditionalOrder = signCancelConditionalOrder;
384
+ exports.signOrder = signOrder;
385
+ function isOrderSignatureValid(signerAddress, signature, reyaChainId, params) {
386
+ var _a;
387
+ var domain = getReyaDomain((0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY));
388
+ var value = {
389
+ verifyingChainId: reyaChainId,
390
+ deadline: BigInt(params.deadline),
391
+ order: {
392
+ accountId: params.accountId,
393
+ marketId: params.marketId,
394
+ exchangeId: params.exchangeId,
395
+ orderType: params.orderType,
396
+ quantity: params.quantity,
397
+ limitPrice: params.limitPrice,
398
+ triggerPrice: params.triggerPrice,
399
+ timeInForce: params.timeInForce,
400
+ clientOrderId: params.clientOrderId,
401
+ reduceOnly: params.reduceOnly,
402
+ postOnly: (_a = params.postOnly) !== null && _a !== void 0 ? _a : false,
403
+ expiresAfter: params.expiresAfter,
404
+ signer: signerAddress,
405
+ nonce: params.nonce,
406
+ },
407
+ };
408
+ var recoveredAddress = (0, ethers_1.verifyTypedData)(domain, exports.orderTypes, value, signature);
409
+ return recoveredAddress.toLowerCase() === signerAddress.toLowerCase();
410
+ }
411
+ exports.isOrderSignatureValid = isOrderSignatureValid;
354
412
  function signGrantPermission(signer, reyaChainId, accountId, permission, user, nonce, deadline) {
355
413
  return __awaiter(this, void 0, void 0, function () {
356
414
  var signature;
@@ -443,6 +501,74 @@ function signRevokePermission(signer, reyaChainId, accountId, permission, user,
443
501
  });
444
502
  }
445
503
  exports.signRevokePermission = signRevokePermission;
504
+ function signMEOrderCancel(signer, reyaChainId, accountId, marketId, orderId, clOrdId, nonce, deadline) {
505
+ return __awaiter(this, void 0, void 0, function () {
506
+ var signature;
507
+ return __generator(this, function (_a) {
508
+ switch (_a.label) {
509
+ case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY), exports.orderCancelTypes, {
510
+ verifyingChainId: reyaChainId,
511
+ deadline: BigInt(deadline),
512
+ cancel: {
513
+ accountId: accountId,
514
+ marketId: marketId,
515
+ orderId: orderId,
516
+ clOrdId: clOrdId,
517
+ nonce: nonce,
518
+ },
519
+ })];
520
+ case 1:
521
+ signature = _a.sent();
522
+ return [2 /*return*/, signature.serialized];
523
+ }
524
+ });
525
+ });
526
+ }
527
+ exports.signMEOrderCancel = signMEOrderCancel;
528
+ function signMEMassCancel(signer, reyaChainId, accountId, marketId, nonce, deadline) {
529
+ return __awaiter(this, void 0, void 0, function () {
530
+ var signature;
531
+ return __generator(this, function (_a) {
532
+ switch (_a.label) {
533
+ case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY), exports.massCancelTypes, {
534
+ verifyingChainId: reyaChainId,
535
+ deadline: BigInt(deadline),
536
+ massCancel: {
537
+ accountId: accountId,
538
+ marketId: marketId,
539
+ nonce: nonce,
540
+ },
541
+ })];
542
+ case 1:
543
+ signature = _a.sent();
544
+ return [2 /*return*/, signature.serialized];
545
+ }
546
+ });
547
+ });
548
+ }
549
+ exports.signMEMassCancel = signMEMassCancel;
550
+ function signMECancelAllAfter(signer, reyaChainId, accountId, timeoutMs, nonce, deadline) {
551
+ return __awaiter(this, void 0, void 0, function () {
552
+ var signature;
553
+ return __generator(this, function (_a) {
554
+ switch (_a.label) {
555
+ case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY), exports.cancelAllAfterTypes, {
556
+ verifyingChainId: reyaChainId,
557
+ deadline: BigInt(deadline),
558
+ cancelAllAfter: {
559
+ accountId: accountId,
560
+ timeoutMs: timeoutMs,
561
+ nonce: nonce,
562
+ },
563
+ })];
564
+ case 1:
565
+ signature = _a.sent();
566
+ return [2 /*return*/, signature.serialized];
567
+ }
568
+ });
569
+ });
570
+ }
571
+ exports.signMECancelAllAfter = signMECancelAllAfter;
446
572
  var signManagePermissionBySig = function (signer, signerAddress, reyaChainId, targetAddress, permissionState, deadline) { return __awaiter(void 0, void 0, void 0, function () {
447
573
  var signature;
448
574
  return __generator(this, function (_a) {