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

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,24 @@
1
1
  # @skate-org/amm-core-v2
2
2
 
3
+ ## 2.0.0-beta.11 — 2026-05-30
4
+
5
+ Adds v1-compat math helpers to close the parity gap surfaced by the
6
+ backend v1 → v2 port of the quote lambdas. All new surface; no
7
+ breaking changes.
8
+
9
+ - `math/kernel.ts` (new module): `NORMALIZED_DECIMAL = 18`,
10
+ `normalizeAmount(amount, decimal)`, `deNormalizeAmount(amount, decimal)`.
11
+ Mirrors the kernel-side 18-decimal normalization done by every periphery
12
+ contract.
13
+ - `math/tickMath.ts`: `getPriceAtTick(tick)`, `getTickAtPrice(price)`,
14
+ `TICK_VALUE = 1.0001`, `PRICE_ZERO`, `PRICE_INF`, `MIN_SQRT_PRICE_X96`,
15
+ `MAX_SQRT_PRICE_X96` (the `_X96` consts alias `{MIN,MAX}_SQRT_PRICE_LIMIT`
16
+ for source compat with `@skate-org/skate-app-amm`).
17
+ - `math/liquidityMath.ts`: `getLiquidityForAmount0`,
18
+ `getLiquidityForAmount1` (uniswap-v3 periphery `LiquidityAmounts.sol`).
19
+ `Q96` is now exported (was module-private in `sqrtPriceMath.ts`).
20
+ - `math/kernel.ts` is re-exported from the public barrel via `math/index.ts`.
21
+
3
22
  ## 2.0.0-beta.10 — 2026-05-29
4
23
 
5
24
  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,35 @@ 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)) {
1131
+ throw new Error(`normalizeAmount: non-integer decimal=${decimal}`);
1132
+ }
1133
+ return amount * 10n ** BigInt(NORMALIZED_DECIMAL - decimal);
1134
+ }
1135
+ function deNormalizeAmount(amount, decimal) {
1136
+ if (decimal === NORMALIZED_DECIMAL) return amount;
1137
+ if (!Number.isInteger(decimal)) {
1138
+ throw new Error(`deNormalizeAmount: non-integer decimal=${decimal}`);
1139
+ }
1140
+ return amount / 10n ** BigInt(NORMALIZED_DECIMAL - decimal);
1141
+ }
1084
1142
  // Annotate the CommonJS export names for ESM import in node:
1085
1143
  0 && (module.exports = {
1086
1144
  ActionBoxAddress,
@@ -1093,20 +1151,26 @@ function addDelta(x, y) {
1093
1151
  KernelEventEmitterAddress,
1094
1152
  KernelManagerAddress,
1095
1153
  MAX_SQRT_PRICE_LIMIT,
1154
+ MAX_SQRT_PRICE_X96,
1096
1155
  MAX_SQRT_RATIO,
1097
1156
  MAX_TICK,
1098
1157
  MIN_SQRT_PRICE_LIMIT,
1158
+ MIN_SQRT_PRICE_X96,
1099
1159
  MIN_SQRT_RATIO,
1100
1160
  MIN_TICK,
1161
+ NORMALIZED_DECIMAL,
1101
1162
  PERIPHERY_DEV,
1102
1163
  PERIPHERY_PRODUCTION,
1103
1164
  PERIPHERY_STAGING,
1104
1165
  POOL_INFO_Dev,
1105
1166
  POOL_INFO_Production,
1106
1167
  POOL_INFO_Staging,
1168
+ PRICE_INF,
1169
+ PRICE_ZERO,
1107
1170
  PeripheryDeploymentFor,
1108
1171
  PeripheryEventEmitterAddress,
1109
1172
  PeripheryManagerAddress,
1173
+ Q96,
1110
1174
  SUI_DEPLOYMENT_DEV,
1111
1175
  SUI_DEPLOYMENT_PRODUCTION,
1112
1176
  SUI_DEPLOYMENT_STAGING,
@@ -1123,6 +1187,7 @@ function addDelta(x, y) {
1123
1187
  SkateGatewayAddress,
1124
1188
  SuiDeploymentFor,
1125
1189
  SvmDeploymentFor,
1190
+ TICK_VALUE,
1126
1191
  TaskPhase,
1127
1192
  VM,
1128
1193
  addDelta,
@@ -1131,6 +1196,7 @@ function addDelta(x, y) {
1131
1196
  bufferFromBase58,
1132
1197
  bytes32ToBase58,
1133
1198
  bytes32ToEvmAddress,
1199
+ deNormalizeAmount,
1134
1200
  evmAddressToBytes32,
1135
1201
  findTokensBySymbol,
1136
1202
  fromBytes32Address,
@@ -1141,6 +1207,8 @@ function addDelta(x, y) {
1141
1207
  getAmount1Delta,
1142
1208
  getAmount1DeltaSigned,
1143
1209
  getBlockExplorer,
1210
+ getLiquidityForAmount0,
1211
+ getLiquidityForAmount1,
1144
1212
  getNextSqrtPriceFromAmount0RoundingUp,
1145
1213
  getNextSqrtPriceFromAmount1RoundingDown,
1146
1214
  getNextSqrtPriceFromInput,
@@ -1148,16 +1216,19 @@ function addDelta(x, y) {
1148
1216
  getOtherTokensInPairs,
1149
1217
  getPeripheryDetailsByKernelPoolAndChainId,
1150
1218
  getPoolInfoByKey,
1219
+ getPriceAtTick,
1151
1220
  getSqrtRatioAtTick,
1152
1221
  getSupportedChains,
1153
1222
  getSupportedPairs,
1154
1223
  getSupportedTokens,
1224
+ getTickAtPrice,
1155
1225
  getTickAtSqrtRatio,
1156
1226
  getTokenSymbol,
1157
1227
  hexToBase58,
1158
1228
  kernelPoolToPoolKey,
1159
1229
  mulDiv,
1160
1230
  mulDivRoundingUp,
1231
+ normalizeAmount,
1161
1232
  normalizeMode,
1162
1233
  skateAdapter,
1163
1234
  svmBytes32Base58ToEvmAddress,