@skate-org/amm-evm-v2 2.0.0-alpha.4 → 2.0.0-alpha.6

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,32 @@
1
1
  # @skate-org/amm-evm-v2
2
2
 
3
+ ## 2.0.0-alpha.6 — 2026-05-07
4
+
5
+ - `getKernelPublicClient(mode)` now reads the kernel chain from
6
+ `KernelChain(mode)` (the new `KERNEL_CHAIN_BY_MODE` table in core)
7
+ instead of hardcoding `megaethChain`. Default behavior is unchanged
8
+ (every env still resolves to MegaETH today); future per-env kernel-chain
9
+ switches are one-line edits in core.
10
+ - Lens helpers + readers continue to call `KernelManagerAddress(mode)`,
11
+ which now throws for STAGING / PRODUCTION (see `@skate-org/amm-core-v2`
12
+ alpha.6 notes). DEV behavior unchanged.
13
+
14
+ ## 2.0.0-alpha.5 — 2026-05-06
15
+
16
+ - **Kernel lens helpers ported from v1.** Adds `simulateSwap`,
17
+ `simulateMint`, `simulateBurn`, `simulateDecreaseLiquidity` —
18
+ static-call wrappers around `KernelManager.lens{Swap,Mint,Burn,DecreaseLiquidity}`.
19
+ Each returns named fields matching the ABI output (e.g.
20
+ `simulateMint` → `{ amount0Used, amount1Used, liquidityAmount, returnData }`)
21
+ and accepts an optional viem client for test injection. Errors flow
22
+ through the read-path (`EvmReadError`) since lens calls don't write
23
+ state. Same DEV/STAGING/PRODUCTION mode handling as the readers.
24
+ - Internal: extracted `resolveKernelClient` to `kernel/_client.ts` so
25
+ readers and lens helpers share the same client-resolution logic.
26
+ - Internal (tests): extracted the `mockKernelClient` helper to
27
+ `test/_helpers.ts`. Reader and lens test suites now share one
28
+ union-ABI mock transport instead of duplicating the implementation.
29
+
3
30
  ## 2.0.0-alpha.4 — 2026-05-06
4
31
 
5
32
  Lockstep bump — paired with the `SwapQuote` schema fix in
@@ -16,12 +16,12 @@ import { CHAIN, type EnvModeWithConfig } from "@skate-org/amm-core-v2";
16
16
  */
17
17
  export declare const megaethChain: Chain;
18
18
  /**
19
- * Return a fresh `PublicClient` bound to the MegaETH kernel chain.
19
+ * Return a fresh `PublicClient` bound to the kernel chain for `mode`.
20
20
  *
21
- * MegaETH is the kernel chain for all environment modes (DEV/STAGING/
22
- * PRODUCTION) in SDK v2. The `mode` parameter is accepted for API
23
- * symmetry with the rest of the SDK and as a forward-compatible extension
24
- * point (e.g. a future testnet kernel).
21
+ * Today every env (`DEV` / `STAGING` / `PRODUCTION`) resolves to MegaETH —
22
+ * see `KERNEL_CHAIN_BY_MODE` in `@skate-org/amm-core-v2`. Pointing a future
23
+ * env at a different kernel chain is a one-line edit there; this factory
24
+ * reads from that mapping so client + address tables stay in sync.
25
25
  *
26
26
  * Pure — no singletons, no caching. Pass a custom `transport` to override
27
27
  * the default RPC (useful for tests and custom RPC providers).
@@ -1 +1 @@
1
- {"version":3,"file":"chain-clients.d.ts","sourceRoot":"","sources":["../src/chain-clients.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AAEd,OAAO,EAEL,KAAK,EAIL,KAAK,iBAAiB,EACvB,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,EAAE,KAYzB,CAAC;AA4CH;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,iBAAiB,EACvB,SAAS,CAAC,EAAE,SAAS,GACpB,YAAY,CAKd;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,iBAAiB,EACvB,SAAS,CAAC,EAAE,SAAS,GACpB,YAAY,CAsBd"}
1
+ {"version":3,"file":"chain-clients.d.ts","sourceRoot":"","sources":["../src/chain-clients.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AAEd,OAAO,EAEL,KAAK,EAKL,KAAK,iBAAiB,EACvB,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,EAAE,KAYzB,CAAC;AA4CH;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,iBAAiB,EACvB,SAAS,CAAC,EAAE,SAAS,GACpB,YAAY,CAcd;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,iBAAiB,EACvB,SAAS,CAAC,EAAE,SAAS,GACpB,YAAY,CAsBd"}
package/dist/index.cjs CHANGED
@@ -39,6 +39,10 @@ __export(index_exports, {
39
39
  readTick: () => readTick,
40
40
  readTickBitmap: () => readTickBitmap,
41
41
  readUserPoolBalances: () => readUserPoolBalances,
42
+ simulateBurn: () => simulateBurn,
43
+ simulateDecreaseLiquidity: () => simulateDecreaseLiquidity,
44
+ simulateMint: () => simulateMint,
45
+ simulateSwap: () => simulateSwap,
42
46
  submitAction: () => submitAction,
43
47
  submitApproval: () => submitApproval,
44
48
  submitSwap: () => submitSwap,
@@ -83,9 +87,17 @@ function resolveRpcUrl(chain, mode) {
83
87
  return config?.rpcEndpoints?.[chain] ?? DEFAULT_RPC[chain];
84
88
  }
85
89
  function getKernelPublicClient(mode, transport) {
90
+ const { mode: baseMode } = (0, import_amm_core_v2.normalizeMode)(mode);
91
+ const kernelChainId = (0, import_amm_core_v2.KernelChain)(baseMode);
92
+ const chainDef = chainDefFor(kernelChainId);
93
+ if (!chainDef) {
94
+ throw new Error(
95
+ `getKernelPublicClient: no chain definition registered for kernel chain ${kernelChainId} (mode=${baseMode}); update chainDefFor() in chain-clients.ts to support it.`
96
+ );
97
+ }
86
98
  return (0, import_viem.createPublicClient)({
87
- chain: megaethChain,
88
- transport: transport ?? (0, import_viem.http)(resolveRpcUrl(import_amm_core_v2.CHAIN.MEGAETH, mode))
99
+ chain: chainDef,
100
+ transport: transport ?? (0, import_viem.http)(resolveRpcUrl(kernelChainId, mode))
89
101
  });
90
102
  }
91
103
  function getSourcePublicClient(chain, mode, transport) {
@@ -162,11 +174,15 @@ function wrapWriteError(err, functionName) {
162
174
  // src/kernel/reader.ts
163
175
  var import_amm_bindings = require("@skate-org/amm-bindings");
164
176
  var import_amm_core_v23 = require("@skate-org/amm-core-v2");
165
- function resolveClient(mode, client) {
177
+
178
+ // src/kernel/_client.ts
179
+ function resolveKernelClient(mode, client) {
166
180
  return client ?? getKernelPublicClient(mode);
167
181
  }
182
+
183
+ // src/kernel/reader.ts
168
184
  async function readPool(kernelPool, mode, client) {
169
- const c = resolveClient(mode, client);
185
+ const c = resolveKernelClient(mode, client);
170
186
  try {
171
187
  const [slot0, liquidity] = await Promise.all([
172
188
  c.readContract({
@@ -200,7 +216,7 @@ async function readPool(kernelPool, mode, client) {
200
216
  async function readPosition(tokenId, mode, client) {
201
217
  const { mode: baseMode } = (0, import_amm_core_v23.normalizeMode)(mode);
202
218
  const manager = (0, import_amm_core_v23.KernelManagerAddress)(baseMode);
203
- const c = resolveClient(mode, client);
219
+ const c = resolveKernelClient(mode, client);
204
220
  try {
205
221
  const raw = await c.readContract({
206
222
  address: manager,
@@ -227,7 +243,7 @@ async function readPosition(tokenId, mode, client) {
227
243
  }
228
244
  }
229
245
  async function readTickBitmap(kernelPool, wordPos, mode, client) {
230
- const c = resolveClient(mode, client);
246
+ const c = resolveKernelClient(mode, client);
231
247
  try {
232
248
  const word = await c.readContract({
233
249
  address: kernelPool,
@@ -241,7 +257,7 @@ async function readTickBitmap(kernelPool, wordPos, mode, client) {
241
257
  }
242
258
  }
243
259
  async function readTick(kernelPool, tick, mode, client) {
244
- const c = resolveClient(mode, client);
260
+ const c = resolveKernelClient(mode, client);
245
261
  try {
246
262
  const raw = await c.readContract({
247
263
  address: kernelPool,
@@ -264,7 +280,7 @@ async function readTick(kernelPool, tick, mode, client) {
264
280
  }
265
281
  }
266
282
  async function computePositionAmounts(tokenId, mode, client) {
267
- const c = resolveClient(mode, client);
283
+ const c = resolveKernelClient(mode, client);
268
284
  const position = await readPosition(tokenId, mode, c);
269
285
  const { slot0 } = await readPool(position.pool, mode, c);
270
286
  const sqrtLower = (0, import_amm_core_v23.getSqrtRatioAtTick)(position.tickLower);
@@ -319,15 +335,103 @@ function decodeTickBitmapWord(word, wordPos, tickSpacing) {
319
335
  return result;
320
336
  }
321
337
 
322
- // src/periphery/reader.ts
338
+ // src/kernel/lens.ts
323
339
  var import_amm_bindings2 = require("@skate-org/amm-bindings");
324
340
  var import_amm_core_v24 = require("@skate-org/amm-core-v2");
325
- function resolveClient2(chain, mode, client) {
341
+ async function simulateSwap(params, mode, client) {
342
+ const { mode: baseMode } = (0, import_amm_core_v24.normalizeMode)(mode);
343
+ const c = resolveKernelClient(mode, client);
344
+ try {
345
+ const out = await c.simulateContract({
346
+ address: (0, import_amm_core_v24.KernelManagerAddress)(baseMode),
347
+ abi: import_amm_bindings2.KernelManagerABI,
348
+ functionName: "lensSwap",
349
+ args: [
350
+ params.pool,
351
+ params.recipient,
352
+ params.zeroForOne,
353
+ params.amountSpecified,
354
+ params.sqrtPriceLimitX96
355
+ ]
356
+ });
357
+ const [amount0, amount1, sqrtPriceX96After, returnData] = out.result;
358
+ return { amount0, amount1, sqrtPriceX96After, returnData };
359
+ } catch (err) {
360
+ throw wrapReadError(err, "simulateSwap");
361
+ }
362
+ }
363
+ async function simulateMint(params, mode, client) {
364
+ const { mode: baseMode } = (0, import_amm_core_v24.normalizeMode)(mode);
365
+ const c = resolveKernelClient(mode, client);
366
+ try {
367
+ const out = await c.simulateContract({
368
+ address: (0, import_amm_core_v24.KernelManagerAddress)(baseMode),
369
+ abi: import_amm_bindings2.KernelManagerABI,
370
+ functionName: "lensMint",
371
+ args: [
372
+ params.pool,
373
+ params.recipient,
374
+ params.tickLower,
375
+ params.tickUpper,
376
+ params.amount0,
377
+ params.amount1,
378
+ params.data
379
+ ]
380
+ });
381
+ const [amount0Used, amount1Used, liquidityAmount, returnData] = out.result;
382
+ return { amount0Used, amount1Used, liquidityAmount, returnData };
383
+ } catch (err) {
384
+ throw wrapReadError(err, "simulateMint");
385
+ }
386
+ }
387
+ async function simulateBurn(params, mode, client) {
388
+ const { mode: baseMode } = (0, import_amm_core_v24.normalizeMode)(mode);
389
+ const c = resolveKernelClient(mode, client);
390
+ try {
391
+ const out = await c.simulateContract({
392
+ address: (0, import_amm_core_v24.KernelManagerAddress)(baseMode),
393
+ abi: import_amm_bindings2.KernelManagerABI,
394
+ functionName: "lensBurn",
395
+ args: [
396
+ params.pool,
397
+ params.recipient,
398
+ params.tickLower,
399
+ params.tickUpper,
400
+ params.amount
401
+ ]
402
+ });
403
+ const [amount0, amount1, returnData] = out.result;
404
+ return { amount0, amount1, returnData };
405
+ } catch (err) {
406
+ throw wrapReadError(err, "simulateBurn");
407
+ }
408
+ }
409
+ async function simulateDecreaseLiquidity(params, mode, client) {
410
+ const { mode: baseMode } = (0, import_amm_core_v24.normalizeMode)(mode);
411
+ const c = resolveKernelClient(mode, client);
412
+ try {
413
+ const out = await c.simulateContract({
414
+ address: (0, import_amm_core_v24.KernelManagerAddress)(baseMode),
415
+ abi: import_amm_bindings2.KernelManagerABI,
416
+ functionName: "lensDecreaseLiquidity",
417
+ args: [params.tokenId, params.liquidity]
418
+ });
419
+ const [amount0, amount1, returnData] = out.result;
420
+ return { amount0, amount1, returnData };
421
+ } catch (err) {
422
+ throw wrapReadError(err, "simulateDecreaseLiquidity");
423
+ }
424
+ }
425
+
426
+ // src/periphery/reader.ts
427
+ var import_amm_bindings3 = require("@skate-org/amm-bindings");
428
+ var import_amm_core_v25 = require("@skate-org/amm-core-v2");
429
+ function resolveClient(chain, mode, client) {
326
430
  return client ?? getSourcePublicClient(chain, mode);
327
431
  }
328
432
  async function readPeripheryPool(chain, kernelPool, mode, client) {
329
- const { mode: baseMode } = (0, import_amm_core_v24.normalizeMode)(mode);
330
- const details = (0, import_amm_core_v24.getPeripheryDetailsByKernelPoolAndChainId)(
433
+ const { mode: baseMode } = (0, import_amm_core_v25.normalizeMode)(mode);
434
+ const details = (0, import_amm_core_v25.getPeripheryDetailsByKernelPoolAndChainId)(
331
435
  kernelPool,
332
436
  chain,
333
437
  baseMode
@@ -339,7 +443,7 @@ async function readPeripheryPool(chain, kernelPool, mode, client) {
339
443
  );
340
444
  }
341
445
  const address = details.address;
342
- const c = resolveClient2(chain, mode, client);
446
+ const c = resolveClient(chain, mode, client);
343
447
  try {
344
448
  const [
345
449
  balancesAvailableRaw,
@@ -352,37 +456,37 @@ async function readPeripheryPool(chain, kernelPool, mode, client) {
352
456
  ] = await Promise.all([
353
457
  c.readContract({
354
458
  address,
355
- abi: import_amm_bindings2.PeripheryPoolABI,
459
+ abi: import_amm_bindings3.PeripheryPoolABI,
356
460
  functionName: "balancesAvailable"
357
461
  }),
358
462
  c.readContract({
359
463
  address,
360
- abi: import_amm_bindings2.PeripheryPoolABI,
464
+ abi: import_amm_bindings3.PeripheryPoolABI,
361
465
  functionName: "dustAmount0"
362
466
  }),
363
467
  c.readContract({
364
468
  address,
365
- abi: import_amm_bindings2.PeripheryPoolABI,
469
+ abi: import_amm_bindings3.PeripheryPoolABI,
366
470
  functionName: "dustAmount1"
367
471
  }),
368
472
  c.readContract({
369
473
  address,
370
- abi: import_amm_bindings2.PeripheryPoolABI,
474
+ abi: import_amm_bindings3.PeripheryPoolABI,
371
475
  functionName: "token0"
372
476
  }),
373
477
  c.readContract({
374
478
  address,
375
- abi: import_amm_bindings2.PeripheryPoolABI,
479
+ abi: import_amm_bindings3.PeripheryPoolABI,
376
480
  functionName: "token1"
377
481
  }),
378
482
  c.readContract({
379
483
  address,
380
- abi: import_amm_bindings2.PeripheryPoolABI,
484
+ abi: import_amm_bindings3.PeripheryPoolABI,
381
485
  functionName: "fee"
382
486
  }),
383
487
  c.readContract({
384
488
  address,
385
- abi: import_amm_bindings2.PeripheryPoolABI,
489
+ abi: import_amm_bindings3.PeripheryPoolABI,
386
490
  functionName: "kernelPool"
387
491
  })
388
492
  ]);
@@ -405,8 +509,8 @@ async function readPeripheryPool(chain, kernelPool, mode, client) {
405
509
  }
406
510
  }
407
511
  async function readUserPoolBalances(chain, kernelPool, user, mode, client) {
408
- const { mode: baseMode } = (0, import_amm_core_v24.normalizeMode)(mode);
409
- const details = (0, import_amm_core_v24.getPeripheryDetailsByKernelPoolAndChainId)(
512
+ const { mode: baseMode } = (0, import_amm_core_v25.normalizeMode)(mode);
513
+ const details = (0, import_amm_core_v25.getPeripheryDetailsByKernelPoolAndChainId)(
410
514
  kernelPool,
411
515
  chain,
412
516
  baseMode
@@ -417,11 +521,11 @@ async function readUserPoolBalances(chain, kernelPool, user, mode, client) {
417
521
  `no periphery entry for kernelPool=${kernelPool} chain=${chain} mode=${baseMode}`
418
522
  );
419
523
  }
420
- const c = resolveClient2(chain, mode, client);
524
+ const c = resolveClient(chain, mode, client);
421
525
  try {
422
526
  const raw = await c.readContract({
423
527
  address: details.address,
424
- abi: import_amm_bindings2.PeripheryPoolABI,
528
+ abi: import_amm_bindings3.PeripheryPoolABI,
425
529
  functionName: "usersData",
426
530
  args: [user]
427
531
  });
@@ -483,7 +587,7 @@ async function submitApproval(wallet, params, mode) {
483
587
 
484
588
  // src/events/kernel.ts
485
589
  var import_viem2 = require("viem");
486
- var import_amm_bindings3 = require("@skate-org/amm-bindings");
590
+ var import_amm_bindings4 = require("@skate-org/amm-bindings");
487
591
  var KERNEL_EVENT_NAMES = [
488
592
  "Burn",
489
593
  "Collect",
@@ -501,7 +605,7 @@ var KERNEL_EVENT_NAMES = [
501
605
  function parseKernelEventLog(log) {
502
606
  try {
503
607
  const decoded = (0, import_viem2.decodeEventLog)({
504
- abi: import_amm_bindings3.KernelEventEmitterABI,
608
+ abi: import_amm_bindings4.KernelEventEmitterABI,
505
609
  data: log.data,
506
610
  topics: log.topics
507
611
  });
@@ -522,7 +626,7 @@ function parseKernelEventLog(log) {
522
626
 
523
627
  // src/events/periphery.ts
524
628
  var import_viem3 = require("viem");
525
- var import_amm_bindings4 = require("@skate-org/amm-bindings");
629
+ var import_amm_bindings5 = require("@skate-org/amm-bindings");
526
630
  var PERIPHERY_EVENT_NAMES = [
527
631
  "AmountSettled",
528
632
  "Burned",
@@ -538,7 +642,7 @@ var PERIPHERY_EVENT_NAMES = [
538
642
  function parsePeripheryEventLog(log) {
539
643
  try {
540
644
  const decoded = (0, import_viem3.decodeEventLog)({
541
- abi: import_amm_bindings4.PeripheryEventEmitterABI,
645
+ abi: import_amm_bindings5.PeripheryEventEmitterABI,
542
646
  data: log.data,
543
647
  topics: log.topics
544
648
  });
@@ -558,10 +662,10 @@ function parsePeripheryEventLog(log) {
558
662
  }
559
663
 
560
664
  // src/events/watch.ts
561
- var import_amm_bindings5 = require("@skate-org/amm-bindings");
665
+ var import_amm_bindings6 = require("@skate-org/amm-bindings");
562
666
  function watchKernelEvents(client, address, opts) {
563
667
  return client.watchContractEvent({
564
- abi: import_amm_bindings5.KernelEventEmitterABI,
668
+ abi: import_amm_bindings6.KernelEventEmitterABI,
565
669
  address,
566
670
  onLogs: (logs) => {
567
671
  for (const log of logs) {
@@ -576,7 +680,7 @@ function watchKernelEvents(client, address, opts) {
576
680
  }
577
681
  function watchPeripheryEvents(client, address, opts) {
578
682
  return client.watchContractEvent({
579
- abi: import_amm_bindings5.PeripheryEventEmitterABI,
683
+ abi: import_amm_bindings6.PeripheryEventEmitterABI,
580
684
  address,
581
685
  onLogs: (logs) => {
582
686
  for (const log of logs) {
@@ -610,6 +714,10 @@ function watchPeripheryEvents(client, address, opts) {
610
714
  readTick,
611
715
  readTickBitmap,
612
716
  readUserPoolBalances,
717
+ simulateBurn,
718
+ simulateDecreaseLiquidity,
719
+ simulateMint,
720
+ simulateSwap,
613
721
  submitAction,
614
722
  submitApproval,
615
723
  submitSwap,