@skate-org/amm-core-v2 2.0.0-beta.10 → 2.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @skate-org/amm-core-v2
2
2
 
3
+ ## 2.0.0-beta.12 — 2026-05-30
4
+
5
+ Hotfix: `normalizeAmount` / `deNormalizeAmount` now handle
6
+ `decimal > NORMALIZED_DECIMAL` instead of throwing `RangeError`
7
+ (was: `BigInt(NORMALIZED_DECIMAL - decimal)` → negative exponent in
8
+ `10n ** ...`).
9
+
10
+ For `decimal > 18` (e.g. some SPL mints use 24), `normalizeAmount`
11
+ scales DOWN with truncation; `deNormalizeAmount` scales UP. Also
12
+ guards `decimal < 0` and non-integer inputs explicitly.
13
+
14
+ ## 2.0.0-beta.11 — 2026-05-30
15
+
16
+ Adds v1-compat math helpers to close the parity gap surfaced by the
17
+ backend v1 → v2 port of the quote lambdas. All new surface; no
18
+ breaking changes.
19
+
20
+ - `math/kernel.ts` (new module): `NORMALIZED_DECIMAL = 18`,
21
+ `normalizeAmount(amount, decimal)`, `deNormalizeAmount(amount, decimal)`.
22
+ Mirrors the kernel-side 18-decimal normalization done by every periphery
23
+ contract.
24
+ - `math/tickMath.ts`: `getPriceAtTick(tick)`, `getTickAtPrice(price)`,
25
+ `TICK_VALUE = 1.0001`, `PRICE_ZERO`, `PRICE_INF`, `MIN_SQRT_PRICE_X96`,
26
+ `MAX_SQRT_PRICE_X96` (the `_X96` consts alias `{MIN,MAX}_SQRT_PRICE_LIMIT`
27
+ for source compat with `@skate-org/skate-app-amm`).
28
+ - `math/liquidityMath.ts`: `getLiquidityForAmount0`,
29
+ `getLiquidityForAmount1` (uniswap-v3 periphery `LiquidityAmounts.sol`).
30
+ `Q96` is now exported (was module-private in `sqrtPriceMath.ts`).
31
+ - `math/kernel.ts` is re-exported from the public barrel via `math/index.ts`.
32
+
3
33
  ## 2.0.0-beta.10 — 2026-05-29
4
34
 
5
35
  Closes the remaining STAGING / PRODUCTION gap left in beta.9: kernel
package/README.md CHANGED
@@ -11,7 +11,7 @@ Zero heavy runtime deps. Pure TypeScript.
11
11
  - `EnvMode`, `DevModeConfig`, `EnvModeWithConfig`, `normalizeMode`
12
12
  - `Token`, `TokenPair`
13
13
  - `ActionStatus`, `TaskPhase`, `TaskFunctionMeta`
14
- - Kernel addresses: `KernelManagerAddress`, `KernelEventEmitterAddress` (DEV-only STAGING/PRODUCTION throw `SdkError` until v2 deploys there)
14
+ - Kernel addresses: `KernelManagerAddress`, `KernelEventEmitterAddress` (STAGING + PRODUCTION alias DEV as of `2.0.0-beta.10`)
15
15
  - Kernel chain config: `KERNEL_CHAIN_BY_MODE`, `KernelChain(mode)` — defaults every env to `CHAIN.MEGAETH`
16
16
  - Periphery deployment: `PERIPHERY_DEV`, `PeripheryManagerAddress`,
17
17
  `PeripheryEventEmitterAddress`, `SkateGatewayAddress`, `ActionBoxAddress`
@@ -1 +1 @@
1
- {"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../src/deployment/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAmBjC,eAAO,MAAM,yBAAyB,+CAA+C,CAAC;AAkBtF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAIjE,CAAC;AAEF,uDAAuD;AACvD,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,CAEhD;AAED;2EAC2E;AAC3E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,MAAM,EAAE,CAElE;AAED;uDACuD;AACvD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,MAAM,EAAE,CAEvE"}
1
+ {"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../src/deployment/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAqBjC,eAAO,MAAM,yBAAyB,+CAA+C,CAAC;AAkBtF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAIjE,CAAC;AAEF,uDAAuD;AACvD,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,CAEhD;AAED;2EAC2E;AAC3E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,MAAM,EAAE,CAElE;AAED;uDACuD;AACvD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,MAAM,EAAE,CAEvE"}
package/dist/index.cjs CHANGED
@@ -30,20 +30,26 @@ __export(index_exports, {
30
30
  KernelEventEmitterAddress: () => KernelEventEmitterAddress,
31
31
  KernelManagerAddress: () => KernelManagerAddress,
32
32
  MAX_SQRT_PRICE_LIMIT: () => MAX_SQRT_PRICE_LIMIT,
33
+ MAX_SQRT_PRICE_X96: () => MAX_SQRT_PRICE_X96,
33
34
  MAX_SQRT_RATIO: () => MAX_SQRT_RATIO,
34
35
  MAX_TICK: () => MAX_TICK,
35
36
  MIN_SQRT_PRICE_LIMIT: () => MIN_SQRT_PRICE_LIMIT,
37
+ MIN_SQRT_PRICE_X96: () => MIN_SQRT_PRICE_X96,
36
38
  MIN_SQRT_RATIO: () => MIN_SQRT_RATIO,
37
39
  MIN_TICK: () => MIN_TICK,
40
+ NORMALIZED_DECIMAL: () => NORMALIZED_DECIMAL,
38
41
  PERIPHERY_DEV: () => PERIPHERY_DEV,
39
42
  PERIPHERY_PRODUCTION: () => PERIPHERY_PRODUCTION,
40
43
  PERIPHERY_STAGING: () => PERIPHERY_STAGING,
41
44
  POOL_INFO_Dev: () => POOL_INFO_Dev,
42
45
  POOL_INFO_Production: () => POOL_INFO_Production,
43
46
  POOL_INFO_Staging: () => POOL_INFO_Staging,
47
+ PRICE_INF: () => PRICE_INF,
48
+ PRICE_ZERO: () => PRICE_ZERO,
44
49
  PeripheryDeploymentFor: () => PeripheryDeploymentFor,
45
50
  PeripheryEventEmitterAddress: () => PeripheryEventEmitterAddress,
46
51
  PeripheryManagerAddress: () => PeripheryManagerAddress,
52
+ Q96: () => Q96,
47
53
  SUI_DEPLOYMENT_DEV: () => SUI_DEPLOYMENT_DEV,
48
54
  SUI_DEPLOYMENT_PRODUCTION: () => SUI_DEPLOYMENT_PRODUCTION,
49
55
  SUI_DEPLOYMENT_STAGING: () => SUI_DEPLOYMENT_STAGING,
@@ -60,6 +66,7 @@ __export(index_exports, {
60
66
  SkateGatewayAddress: () => SkateGatewayAddress,
61
67
  SuiDeploymentFor: () => SuiDeploymentFor,
62
68
  SvmDeploymentFor: () => SvmDeploymentFor,
69
+ TICK_VALUE: () => TICK_VALUE,
63
70
  TaskPhase: () => TaskPhase,
64
71
  VM: () => VM,
65
72
  addDelta: () => addDelta,
@@ -68,6 +75,7 @@ __export(index_exports, {
68
75
  bufferFromBase58: () => bufferFromBase58,
69
76
  bytes32ToBase58: () => bytes32ToBase58,
70
77
  bytes32ToEvmAddress: () => bytes32ToEvmAddress,
78
+ deNormalizeAmount: () => deNormalizeAmount,
71
79
  evmAddressToBytes32: () => evmAddressToBytes32,
72
80
  findTokensBySymbol: () => findTokensBySymbol,
73
81
  fromBytes32Address: () => fromBytes32Address,
@@ -78,6 +86,8 @@ __export(index_exports, {
78
86
  getAmount1Delta: () => getAmount1Delta,
79
87
  getAmount1DeltaSigned: () => getAmount1DeltaSigned,
80
88
  getBlockExplorer: () => getBlockExplorer,
89
+ getLiquidityForAmount0: () => getLiquidityForAmount0,
90
+ getLiquidityForAmount1: () => getLiquidityForAmount1,
81
91
  getNextSqrtPriceFromAmount0RoundingUp: () => getNextSqrtPriceFromAmount0RoundingUp,
82
92
  getNextSqrtPriceFromAmount1RoundingDown: () => getNextSqrtPriceFromAmount1RoundingDown,
83
93
  getNextSqrtPriceFromInput: () => getNextSqrtPriceFromInput,
@@ -85,16 +95,19 @@ __export(index_exports, {
85
95
  getOtherTokensInPairs: () => getOtherTokensInPairs,
86
96
  getPeripheryDetailsByKernelPoolAndChainId: () => getPeripheryDetailsByKernelPoolAndChainId,
87
97
  getPoolInfoByKey: () => getPoolInfoByKey,
98
+ getPriceAtTick: () => getPriceAtTick,
88
99
  getSqrtRatioAtTick: () => getSqrtRatioAtTick,
89
100
  getSupportedChains: () => getSupportedChains,
90
101
  getSupportedPairs: () => getSupportedPairs,
91
102
  getSupportedTokens: () => getSupportedTokens,
103
+ getTickAtPrice: () => getTickAtPrice,
92
104
  getTickAtSqrtRatio: () => getTickAtSqrtRatio,
93
105
  getTokenSymbol: () => getTokenSymbol,
94
106
  hexToBase58: () => hexToBase58,
95
107
  kernelPoolToPoolKey: () => kernelPoolToPoolKey,
96
108
  mulDiv: () => mulDiv,
97
109
  mulDivRoundingUp: () => mulDivRoundingUp,
110
+ normalizeAmount: () => normalizeAmount,
98
111
  normalizeMode: () => normalizeMode,
99
112
  skateAdapter: () => skate_exports,
100
113
  svmBytes32Base58ToEvmAddress: () => svmBytes32Base58ToEvmAddress,
@@ -240,8 +253,8 @@ var TaskPhase = /* @__PURE__ */ ((TaskPhase2) => {
240
253
  })(TaskPhase || {});
241
254
 
242
255
  // src/deployment/kernel.ts
243
- var KERNEL_MANAGER_Dev = "0x17B7207837e8884f7f687f1f4057751BDAf70a01";
244
- var KERNEL_EVENT_EMITTER_Dev = "0x8989b3ecb65f250ab7A0DC03589B0Cc8b8b04b81";
256
+ var KERNEL_MANAGER = "0x17B7207837e8884f7f687f1f4057751BDAf70a01";
257
+ var KERNEL_EVENT_EMITTER = "0x8989b3ecb65f250ab7A0DC03589B0Cc8b8b04b81";
245
258
  var KERNEL_POOL_USDC_USDT_Dev = "0x2c23334eE3b030e6bacEDEDf7C511eEA08Cf7E7e";
246
259
  var KERNEL_CHAIN_BY_MODE = {
247
260
  DEV: 4326 /* MEGAETH */,
@@ -252,10 +265,10 @@ function KernelChain(mode) {
252
265
  return KERNEL_CHAIN_BY_MODE[mode];
253
266
  }
254
267
  function KernelManagerAddress(_mode) {
255
- return KERNEL_MANAGER_Dev;
268
+ return KERNEL_MANAGER;
256
269
  }
257
270
  function KernelEventEmitterAddress(_mode) {
258
- return KERNEL_EVENT_EMITTER_Dev;
271
+ return KERNEL_EVENT_EMITTER;
259
272
  }
260
273
 
261
274
  // src/deployment/periphery.ts
@@ -746,6 +759,11 @@ var MIN_SQRT_RATIO = 4295128739n;
746
759
  var MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342n;
747
760
  var MIN_SQRT_PRICE_LIMIT = MIN_SQRT_RATIO + 1n;
748
761
  var MAX_SQRT_PRICE_LIMIT = MAX_SQRT_RATIO - 1n;
762
+ var MIN_SQRT_PRICE_X96 = MIN_SQRT_PRICE_LIMIT;
763
+ var MAX_SQRT_PRICE_X96 = MAX_SQRT_PRICE_LIMIT;
764
+ var TICK_VALUE = 1.0001;
765
+ var PRICE_ZERO = 0;
766
+ var PRICE_INF = 2 ** 32 - 1;
749
767
  function getSqrtRatioAtTick(tick) {
750
768
  if (!Number.isInteger(tick)) {
751
769
  throw new Error("TickMath: tick must be an integer");
@@ -874,6 +892,17 @@ function toInt24(x) {
874
892
  const signed = truncated >= 1n << 23n ? truncated - (1n << 24n) : truncated;
875
893
  return Number(signed);
876
894
  }
895
+ function getPriceAtTick(tick) {
896
+ const sqrtPriceX96 = getSqrtRatioAtTick(tick);
897
+ const Q962 = 1n << 96n;
898
+ return (Number(sqrtPriceX96) / Number(Q962)) ** 2;
899
+ }
900
+ function getTickAtPrice(price) {
901
+ if (price < 0) {
902
+ throw new Error(`getTickAtPrice: invalid price=${price}`);
903
+ }
904
+ return Math.round(Math.log(price) / Math.log(TICK_VALUE));
905
+ }
877
906
 
878
907
  // src/math/fullMath.ts
879
908
  var MAX_UINT2562 = (1n << 256n) - 1n;
@@ -1081,6 +1110,41 @@ function addDelta(x, y) {
1081
1110
  }
1082
1111
  return z;
1083
1112
  }
1113
+ function getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0) {
1114
+ if (sqrtRatioAX96 > sqrtRatioBX96) {
1115
+ [sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
1116
+ }
1117
+ return amount0 * sqrtRatioAX96 * sqrtRatioBX96 / (Q96 * (sqrtRatioBX96 - sqrtRatioAX96));
1118
+ }
1119
+ function getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1) {
1120
+ if (sqrtRatioAX96 > sqrtRatioBX96) {
1121
+ [sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
1122
+ }
1123
+ return amount1 * Q96 / (sqrtRatioBX96 - sqrtRatioAX96);
1124
+ }
1125
+
1126
+ // src/math/kernel.ts
1127
+ var NORMALIZED_DECIMAL = 18;
1128
+ function normalizeAmount(amount, decimal) {
1129
+ if (decimal === NORMALIZED_DECIMAL) return amount;
1130
+ if (!Number.isInteger(decimal) || decimal < 0) {
1131
+ throw new Error(`normalizeAmount: invalid decimal=${decimal}`);
1132
+ }
1133
+ if (decimal < NORMALIZED_DECIMAL) {
1134
+ return amount * 10n ** BigInt(NORMALIZED_DECIMAL - decimal);
1135
+ }
1136
+ return amount / 10n ** BigInt(decimal - NORMALIZED_DECIMAL);
1137
+ }
1138
+ function deNormalizeAmount(amount, decimal) {
1139
+ if (decimal === NORMALIZED_DECIMAL) return amount;
1140
+ if (!Number.isInteger(decimal) || decimal < 0) {
1141
+ throw new Error(`deNormalizeAmount: invalid decimal=${decimal}`);
1142
+ }
1143
+ if (decimal < NORMALIZED_DECIMAL) {
1144
+ return amount / 10n ** BigInt(NORMALIZED_DECIMAL - decimal);
1145
+ }
1146
+ return amount * 10n ** BigInt(decimal - NORMALIZED_DECIMAL);
1147
+ }
1084
1148
  // Annotate the CommonJS export names for ESM import in node:
1085
1149
  0 && (module.exports = {
1086
1150
  ActionBoxAddress,
@@ -1093,20 +1157,26 @@ function addDelta(x, y) {
1093
1157
  KernelEventEmitterAddress,
1094
1158
  KernelManagerAddress,
1095
1159
  MAX_SQRT_PRICE_LIMIT,
1160
+ MAX_SQRT_PRICE_X96,
1096
1161
  MAX_SQRT_RATIO,
1097
1162
  MAX_TICK,
1098
1163
  MIN_SQRT_PRICE_LIMIT,
1164
+ MIN_SQRT_PRICE_X96,
1099
1165
  MIN_SQRT_RATIO,
1100
1166
  MIN_TICK,
1167
+ NORMALIZED_DECIMAL,
1101
1168
  PERIPHERY_DEV,
1102
1169
  PERIPHERY_PRODUCTION,
1103
1170
  PERIPHERY_STAGING,
1104
1171
  POOL_INFO_Dev,
1105
1172
  POOL_INFO_Production,
1106
1173
  POOL_INFO_Staging,
1174
+ PRICE_INF,
1175
+ PRICE_ZERO,
1107
1176
  PeripheryDeploymentFor,
1108
1177
  PeripheryEventEmitterAddress,
1109
1178
  PeripheryManagerAddress,
1179
+ Q96,
1110
1180
  SUI_DEPLOYMENT_DEV,
1111
1181
  SUI_DEPLOYMENT_PRODUCTION,
1112
1182
  SUI_DEPLOYMENT_STAGING,
@@ -1123,6 +1193,7 @@ function addDelta(x, y) {
1123
1193
  SkateGatewayAddress,
1124
1194
  SuiDeploymentFor,
1125
1195
  SvmDeploymentFor,
1196
+ TICK_VALUE,
1126
1197
  TaskPhase,
1127
1198
  VM,
1128
1199
  addDelta,
@@ -1131,6 +1202,7 @@ function addDelta(x, y) {
1131
1202
  bufferFromBase58,
1132
1203
  bytes32ToBase58,
1133
1204
  bytes32ToEvmAddress,
1205
+ deNormalizeAmount,
1134
1206
  evmAddressToBytes32,
1135
1207
  findTokensBySymbol,
1136
1208
  fromBytes32Address,
@@ -1141,6 +1213,8 @@ function addDelta(x, y) {
1141
1213
  getAmount1Delta,
1142
1214
  getAmount1DeltaSigned,
1143
1215
  getBlockExplorer,
1216
+ getLiquidityForAmount0,
1217
+ getLiquidityForAmount1,
1144
1218
  getNextSqrtPriceFromAmount0RoundingUp,
1145
1219
  getNextSqrtPriceFromAmount1RoundingDown,
1146
1220
  getNextSqrtPriceFromInput,
@@ -1148,16 +1222,19 @@ function addDelta(x, y) {
1148
1222
  getOtherTokensInPairs,
1149
1223
  getPeripheryDetailsByKernelPoolAndChainId,
1150
1224
  getPoolInfoByKey,
1225
+ getPriceAtTick,
1151
1226
  getSqrtRatioAtTick,
1152
1227
  getSupportedChains,
1153
1228
  getSupportedPairs,
1154
1229
  getSupportedTokens,
1230
+ getTickAtPrice,
1155
1231
  getTickAtSqrtRatio,
1156
1232
  getTokenSymbol,
1157
1233
  hexToBase58,
1158
1234
  kernelPoolToPoolKey,
1159
1235
  mulDiv,
1160
1236
  mulDivRoundingUp,
1237
+ normalizeAmount,
1161
1238
  normalizeMode,
1162
1239
  skateAdapter,
1163
1240
  svmBytes32Base58ToEvmAddress,