@skate-org/amm-evm-v2 0.4.1

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 (46) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +33 -0
  3. package/dist/chain-clients.d.ts +42 -0
  4. package/dist/chain-clients.d.ts.map +1 -0
  5. package/dist/devConfig.d.ts +23 -0
  6. package/dist/devConfig.d.ts.map +1 -0
  7. package/dist/errors.d.ts +53 -0
  8. package/dist/errors.d.ts.map +1 -0
  9. package/dist/events/index.d.ts +4 -0
  10. package/dist/events/index.d.ts.map +1 -0
  11. package/dist/events/kernel.d.ts +25 -0
  12. package/dist/events/kernel.d.ts.map +1 -0
  13. package/dist/events/periphery.d.ts +21 -0
  14. package/dist/events/periphery.d.ts.map +1 -0
  15. package/dist/events/watch.d.ts +23 -0
  16. package/dist/events/watch.d.ts.map +1 -0
  17. package/dist/index.cjs +997 -0
  18. package/dist/index.cjs.map +1 -0
  19. package/dist/index.d.cts +8 -0
  20. package/dist/index.d.ts +8 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +952 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/kernel/index.d.ts +3 -0
  25. package/dist/kernel/index.d.ts.map +1 -0
  26. package/dist/kernel/reader.d.ts +77 -0
  27. package/dist/kernel/reader.d.ts.map +1 -0
  28. package/dist/kernel/tickBitmap.d.ts +30 -0
  29. package/dist/kernel/tickBitmap.d.ts.map +1 -0
  30. package/dist/math/fullMath.d.ts +28 -0
  31. package/dist/math/fullMath.d.ts.map +1 -0
  32. package/dist/math/index.d.ts +5 -0
  33. package/dist/math/index.d.ts.map +1 -0
  34. package/dist/math/liquidityMath.d.ts +18 -0
  35. package/dist/math/liquidityMath.d.ts.map +1 -0
  36. package/dist/math/sqrtPriceMath.d.ts +62 -0
  37. package/dist/math/sqrtPriceMath.d.ts.map +1 -0
  38. package/dist/math/tickMath.d.ts +36 -0
  39. package/dist/math/tickMath.d.ts.map +1 -0
  40. package/dist/periphery/index.d.ts +3 -0
  41. package/dist/periphery/index.d.ts.map +1 -0
  42. package/dist/periphery/reader.d.ts +75 -0
  43. package/dist/periphery/reader.d.ts.map +1 -0
  44. package/dist/periphery/submit.d.ts +63 -0
  45. package/dist/periphery/submit.d.ts.map +1 -0
  46. package/package.json +41 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # @skate-org/amm-evm-v2
2
+
3
+ ## 0.4.1 — 2026-04-29
4
+
5
+ - Flip DEV MegaETH RPC default to `https://mainnet.megaeth.com/rpc` (the
6
+ carrot.megaeth.com endpoint is no longer the canonical DEV RPC).
7
+ - Extend DEV smoke to exercise `readPool` (kernel) and `readPeripheryPool`
8
+ (Arbitrum) against real contracts.
9
+
10
+ ## 0.4.0 — 2026-04-25
11
+
12
+ - Phase 4: kernel + periphery event-decoding framework. `decodeKernel*`
13
+ / `decodePeriphery*` helpers; `watch*` event subscription utilities.
14
+
15
+ ## 0.3.0 — 2026-04-23
16
+
17
+ - Phase 3: `readPool`, `readPeripheryPool`, `readPosition` reader helpers;
18
+ uniswap-v3 tick math; action submitters.
19
+
20
+ ## 0.2.0 — 2026-04-22
21
+
22
+ - `createPublicClient` factory; `createDevConfig` for DEV mode tuples.
23
+
24
+ ## 0.1.0 — 2026-04-21
25
+
26
+ - Initial scaffold: viem chain definitions, RPC defaults, `chain-clients.ts`.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @skate-org/amm-evm-v2
2
+
3
+ EVM clients for the Skate AMM v2 SDK: viem chain definitions, kernel +
4
+ periphery readers, uniswap-v3 tick math, action submitters, and the
5
+ event-decoding framework.
6
+
7
+ ## Surface
8
+
9
+ - `createPublicClient(chain, mode?)` — viem `PublicClient` factory with
10
+ Skate's RPC defaults baked in.
11
+ - `createDevConfig({...})` — produces the DEV `{ mode, config }` tuple.
12
+ - **Readers:** `readPool` (kernel side), `readPeripheryPool` (periphery
13
+ side), `readPosition`.
14
+ - **Math:** uniswap-v3 tick / sqrt-price helpers.
15
+ - **Events:** `decodeKernel*`, `decodePeriphery*`, `watch*` subscription
16
+ helpers.
17
+ - **Submitters:** kernel + periphery action submission helpers.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pnpm add @skate-org/amm-evm-v2
23
+ ```
24
+
25
+ Peer deps: `@skate-org/amm-core-v2`, `@skate-org/amm-bindings`, `viem`.
26
+
27
+ ## DEV defaults (as of 2026-04-29)
28
+
29
+ - MegaETH RPC: `https://mainnet.megaeth.com/rpc`
30
+ - Kernel manager: `0x17B7207837e8884f7f687f1f4057751BDAf70a01`
31
+ - USDC/USDT kernel pool: `0x2c23334eE3b030e6bacEDEDf7C511eEA08Cf7E7e`
32
+
33
+ See `CHANGELOG.md` for version history.
@@ -0,0 +1,42 @@
1
+ import { type Chain, type PublicClient, type Transport } from "viem";
2
+ import { CHAIN, type EnvModeWithConfig } from "@skate-org/amm-core-v2";
3
+ /**
4
+ * MegaETH chain definition — `@public`.
5
+ *
6
+ * Exported for callers who need to build their own viem `WalletClient` or
7
+ * `PublicClient` against the same chain the SDK uses internally (e.g. wallet
8
+ * integrations that construct a `WalletClient` ahead of calling
9
+ * `submitAction`). Prefer {@link getKernelPublicClient} when you just need a
10
+ * read client.
11
+ *
12
+ * viem ships a `megaeth` chain at id 4326, but with a different default RPC
13
+ * than the one Skate uses for kernel reads. Define locally so we control the
14
+ * RPC URL + block-explorer metadata and don't inherit unrelated op-stack
15
+ * contract addresses.
16
+ */
17
+ export declare const megaethChain: Chain;
18
+ /**
19
+ * Return a fresh `PublicClient` bound to the MegaETH kernel chain.
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).
25
+ *
26
+ * Pure — no singletons, no caching. Pass a custom `transport` to override
27
+ * the default RPC (useful for tests and custom RPC providers).
28
+ */
29
+ export declare function getKernelPublicClient(mode: EnvModeWithConfig, transport?: Transport): PublicClient;
30
+ /**
31
+ * Return a fresh `PublicClient` for a source EVM chain (e.g. Arbitrum).
32
+ *
33
+ * Throws a descriptive `Error` when:
34
+ * - `chain` is not an EVM chain (per `vmTypeFromChain`); or
35
+ * - no viem chain definition is registered for `chain`; or
36
+ * - no default RPC URL is configured for `chain` and no `transport` override
37
+ * was provided.
38
+ *
39
+ * Pure — no singletons, no caching.
40
+ */
41
+ export declare function getSourcePublicClient(chain: CHAIN, mode: EnvModeWithConfig, transport?: Transport): PublicClient;
42
+ //# sourceMappingURL=chain-clients.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,23 @@
1
+ import type { DevModeConfig } from "@skate-org/amm-core-v2";
2
+ /** Default DEV api endpoint — matches Phase 1's api client default. */
3
+ export declare const DEFAULT_DEV_API_ENDPOINT = "https://dev.api.skatechain.org/amm-action-v2";
4
+ /**
5
+ * Convenience factory for the `{ mode: "DEV"; config: DevModeConfig }` tuple.
6
+ *
7
+ * Reduces ceremony at call sites that want to override a single field (e.g.,
8
+ * `rpcEndpoints`) without reconstructing the full object:
9
+ *
10
+ * ```ts
11
+ * const mode = createDevConfig({
12
+ * rpcEndpoints: { [CHAIN.MEGAETH]: "https://my-private-megaeth/rpc" },
13
+ * });
14
+ * submitAction(wallet, params, mode);
15
+ * ```
16
+ *
17
+ * Pass nothing to use all defaults.
18
+ */
19
+ export declare function createDevConfig(overrides?: Partial<DevModeConfig>): {
20
+ mode: "DEV";
21
+ config: DevModeConfig;
22
+ };
23
+ //# sourceMappingURL=devConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devConfig.d.ts","sourceRoot":"","sources":["../src/devConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,uEAAuE;AACvE,eAAO,MAAM,wBAAwB,iDACW,CAAC;AAEjD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC7B,SAAS,GAAE,OAAO,CAAC,aAAa,CAAM,GACrC;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CAUxC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Shared error types for the `@skate-org/amm-evm-v2` package.
3
+ *
4
+ * `EvmReadError` / `EvmWriteError` extend `SdkError` (from core) so callers
5
+ * can `instanceof SdkError` to catch any SDK-origin error without needing
6
+ * to know the specific subclass.
7
+ */
8
+ import { SdkError } from "@skate-org/amm-core-v2";
9
+ /** SDK-level error thrown when an EVM read reverts or decodes badly. */
10
+ export declare class EvmReadError extends SdkError {
11
+ readonly name: string;
12
+ readonly functionName: string;
13
+ constructor(functionName: string, message: string, options?: ErrorOptions);
14
+ }
15
+ /**
16
+ * SDK-level error thrown when an EVM write (broadcast) fails.
17
+ *
18
+ * Symmetric with {@link EvmReadError}, but covers the write path: viem's
19
+ * `TransactionExecutionError`, `UserRejectedRequestError`,
20
+ * `ChainMismatchError`, `ChainDisconnectedError`, as well as submitter
21
+ * pre-flight guards (e.g. wrong-chain, missing account).
22
+ */
23
+ export declare class EvmWriteError extends SdkError {
24
+ readonly name: string;
25
+ readonly functionName: string;
26
+ constructor(functionName: string, message: string, options?: ErrorOptions);
27
+ }
28
+ /**
29
+ * Wrap any error from an EVM read into `EvmReadError`. Viem always wraps
30
+ * revert-path errors in `ContractFunctionExecutionError` (see
31
+ * `viem/utils/errors/getContractError`), so we check both the outer name and
32
+ * the `.cause` chain for `ContractFunctionRevertedError` /
33
+ * `ContractFunctionZeroDataError`.
34
+ *
35
+ * Shared by `kernel/reader.ts` and `periphery/reader.ts` — depends only on
36
+ * `EvmReadError` and generic Error inspection (no reader-module imports), so
37
+ * it is safe from circular-import concerns.
38
+ */
39
+ export declare function wrapReadError(err: unknown, functionName: string): EvmReadError;
40
+ /**
41
+ * Wrap any error from an EVM write-path call (typically
42
+ * `WalletClient.sendTransaction`) into `EvmWriteError`.
43
+ *
44
+ * Any thrown error reaching a submitter is treated as a write failure. If
45
+ * we later want to differentiate known viem write errors
46
+ * (`TransactionExecutionError`, `UserRejectedRequestError`,
47
+ * `ChainMismatchError`, `ChainDisconnectedError`) from unknown errors —
48
+ * e.g. to prefix the message or re-throw unknowns raw — that dispatch goes
49
+ * here. Keeping the single-return shape until a concrete caller need
50
+ * surfaces.
51
+ */
52
+ export declare function wrapWriteError(err: unknown, functionName: string): EvmWriteError;
53
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,wEAAwE;AACxE,qBAAa,YAAa,SAAQ,QAAQ;IACxC,SAAkB,IAAI,EAAE,MAAM,CAAkB;IAChD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;gBAElB,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAI1E;AAED;;;;;;;GAOG;AACH,qBAAa,aAAc,SAAQ,QAAQ;IACzC,SAAkB,IAAI,EAAE,MAAM,CAAmB;IACjD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;gBAElB,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAI1E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,OAAO,EACZ,YAAY,EAAE,MAAM,GACnB,YAAY,CAmBd;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,OAAO,EACZ,YAAY,EAAE,MAAM,GACnB,aAAa,CAMf"}
@@ -0,0 +1,4 @@
1
+ export * from "./kernel";
2
+ export * from "./periphery";
3
+ export * from "./watch";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { type Log } from "viem";
2
+ /**
3
+ * Event names emitted by the Skate kernel's `KernelEventEmitter`, sourced
4
+ * directly from `@skate-org/amm-bindings`.
5
+ */
6
+ export type KernelEventName = "Burn" | "Collect" | "CollectProtocol" | "IncreaseObservationCardinalityNext" | "Initialize" | "Mint" | "PeripheryPoolAdded" | "PeripheryPoolChanged" | "PoolCreated" | "PoolDescriptionUpdated" | "SetFeeProtocol" | "Swap";
7
+ /** Exhaustive list of known kernel event names — same values as {@link KernelEventName}. */
8
+ export declare const KERNEL_EVENT_NAMES: readonly KernelEventName[];
9
+ /**
10
+ * A decoded kernel event — the event name, its named args, and the original
11
+ * viem `Log` for context (tx hash, block number, etc.).
12
+ */
13
+ export interface KernelParsedEvent {
14
+ eventName: KernelEventName;
15
+ args: Record<string, unknown>;
16
+ log: Log;
17
+ }
18
+ /**
19
+ * Decode a viem `Log` emitted by the Skate kernel's `KernelEventEmitter`.
20
+ *
21
+ * Throws {@link EvmReadError} if the log's topic0 is not a known kernel event
22
+ * or if ABI decoding fails.
23
+ */
24
+ export declare function parseKernelEventLog(log: Log): KernelParsedEvent;
25
+ //# sourceMappingURL=kernel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../src/events/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAIhD;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,SAAS,GACT,iBAAiB,GACjB,oCAAoC,GACpC,YAAY,GACZ,MAAM,GACN,oBAAoB,GACpB,sBAAsB,GACtB,aAAa,GACb,wBAAwB,GACxB,gBAAgB,GAChB,MAAM,CAAC;AAEX,4FAA4F;AAC5F,eAAO,MAAM,kBAAkB,EAAE,SAAS,eAAe,EAaxD,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,eAAe,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,GAAG,EAAE,GAAG,CAAC;CACV;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,GAAG,iBAAiB,CAuB/D"}
@@ -0,0 +1,21 @@
1
+ import { type Log } from "viem";
2
+ /**
3
+ * Event names emitted by `PeripheryEventEmitter` on the source chain.
4
+ */
5
+ export type PeripheryEventName = "AmountSettled" | "Burned" | "LiquidityDecreased" | "LiquidityIncreased" | "MintSettled" | "Minted" | "PoolCreated" | "PoolDeployed" | "Swapped" | "TransferredTo";
6
+ /** Exhaustive list of known periphery event names. */
7
+ export declare const PERIPHERY_EVENT_NAMES: readonly PeripheryEventName[];
8
+ /** A decoded periphery event — name, named args, and the original viem `Log`. */
9
+ export interface PeripheryParsedEvent {
10
+ eventName: PeripheryEventName;
11
+ args: Record<string, unknown>;
12
+ log: Log;
13
+ }
14
+ /**
15
+ * Decode a viem `Log` emitted by `PeripheryEventEmitter` on a source chain.
16
+ *
17
+ * Throws {@link EvmReadError} if the log's topic0 is not a known periphery
18
+ * event or if ABI decoding fails.
19
+ */
20
+ export declare function parsePeripheryEventLog(log: Log): PeripheryParsedEvent;
21
+ //# sourceMappingURL=periphery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"periphery.d.ts","sourceRoot":"","sources":["../../src/events/periphery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAIhD;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,eAAe,GACf,QAAQ,GACR,oBAAoB,GACpB,oBAAoB,GACpB,aAAa,GACb,QAAQ,GACR,aAAa,GACb,cAAc,GACd,SAAS,GACT,eAAe,CAAC;AAEpB,sDAAsD;AACtD,eAAO,MAAM,qBAAqB,EAAE,SAAS,kBAAkB,EAW9D,CAAC;AAEF,iFAAiF;AACjF,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,kBAAkB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,GAAG,EAAE,GAAG,CAAC;CACV;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,CAuBrE"}
@@ -0,0 +1,23 @@
1
+ import type { Address, PublicClient } from "viem";
2
+ import { type KernelParsedEvent } from "./kernel";
3
+ import { type PeripheryParsedEvent } from "./periphery";
4
+ export interface EventSubscriptionOptions<E> {
5
+ /** Called for each decoded event. */
6
+ onEvent: (event: E) => void;
7
+ /** Called when a log fails to decode (subscription stays alive). */
8
+ onError?: (err: unknown) => void;
9
+ }
10
+ /**
11
+ * Subscribe to kernel events emitted by the `KernelEventEmitter` contract
12
+ * at `address`. Returns an unsubscribe function.
13
+ *
14
+ * Decode failures are surfaced via `opts.onError` (if provided) rather than
15
+ * throwing — the subscription continues.
16
+ */
17
+ export declare function watchKernelEvents(client: PublicClient, address: Address, opts: EventSubscriptionOptions<KernelParsedEvent>): () => void;
18
+ /**
19
+ * Subscribe to periphery events emitted by `PeripheryEventEmitter` at
20
+ * `address` on the source chain the `client` is connected to.
21
+ */
22
+ export declare function watchPeripheryEvents(client: PublicClient, address: Address, opts: EventSubscriptionOptions<PeripheryParsedEvent>): () => void;
23
+ //# sourceMappingURL=watch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/events/watch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAO,YAAY,EAAE,MAAM,MAAM,CAAC;AAKvD,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,qCAAqC;IACrC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,oEAAoE;IACpE,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,wBAAwB,CAAC,iBAAiB,CAAC,GAChD,MAAM,IAAI,CAcZ;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,wBAAwB,CAAC,oBAAoB,CAAC,GACnD,MAAM,IAAI,CAcZ"}