@artblocks/abx-sdk 0.1.0-alpha.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 (86) hide show
  1. package/LICENSE +21 -0
  2. package/dist/abi/generated.d.ts +6185 -0
  3. package/dist/abi/generated.d.ts.map +1 -0
  4. package/dist/abi/generated.js +28 -0
  5. package/dist/abi/generated.js.map +1 -0
  6. package/dist/abi/index.d.ts +3227 -0
  7. package/dist/abi/index.d.ts.map +1 -0
  8. package/dist/abi/index.js +38 -0
  9. package/dist/abi/index.js.map +1 -0
  10. package/dist/chains.d.ts +27 -0
  11. package/dist/chains.d.ts.map +1 -0
  12. package/dist/chains.js +71 -0
  13. package/dist/chains.js.map +1 -0
  14. package/dist/chunks.d.ts +168 -0
  15. package/dist/chunks.d.ts.map +1 -0
  16. package/dist/chunks.js +232 -0
  17. package/dist/chunks.js.map +1 -0
  18. package/dist/clients.d.ts +42 -0
  19. package/dist/clients.d.ts.map +1 -0
  20. package/dist/clients.js +90 -0
  21. package/dist/clients.js.map +1 -0
  22. package/dist/create2.d.ts +42 -0
  23. package/dist/create2.d.ts.map +1 -0
  24. package/dist/create2.js +47 -0
  25. package/dist/create2.js.map +1 -0
  26. package/dist/deploy.d.ts +192 -0
  27. package/dist/deploy.d.ts.map +1 -0
  28. package/dist/deploy.js +231 -0
  29. package/dist/deploy.js.map +1 -0
  30. package/dist/deployments.d.ts +60 -0
  31. package/dist/deployments.d.ts.map +1 -0
  32. package/dist/deployments.js +81 -0
  33. package/dist/deployments.js.map +1 -0
  34. package/dist/deps.d.ts +109 -0
  35. package/dist/deps.d.ts.map +1 -0
  36. package/dist/deps.js +103 -0
  37. package/dist/deps.js.map +1 -0
  38. package/dist/env.d.ts +2 -0
  39. package/dist/env.d.ts.map +1 -0
  40. package/dist/env.js +45 -0
  41. package/dist/env.js.map +1 -0
  42. package/dist/fastlz.d.ts +20 -0
  43. package/dist/fastlz.d.ts.map +1 -0
  44. package/dist/fastlz.js +123 -0
  45. package/dist/fastlz.js.map +1 -0
  46. package/dist/generator.d.ts +129 -0
  47. package/dist/generator.d.ts.map +1 -0
  48. package/dist/generator.js +81 -0
  49. package/dist/generator.js.map +1 -0
  50. package/dist/index.d.ts +31 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +20 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/ops.d.ts +379 -0
  55. package/dist/ops.d.ts.map +1 -0
  56. package/dist/ops.js +811 -0
  57. package/dist/ops.js.map +1 -0
  58. package/dist/probe.d.ts +30 -0
  59. package/dist/probe.d.ts.map +1 -0
  60. package/dist/probe.js +74 -0
  61. package/dist/probe.js.map +1 -0
  62. package/dist/reconstruct.d.ts +97 -0
  63. package/dist/reconstruct.d.ts.map +1 -0
  64. package/dist/reconstruct.js +597 -0
  65. package/dist/reconstruct.js.map +1 -0
  66. package/dist/spine.d.ts +110 -0
  67. package/dist/spine.d.ts.map +1 -0
  68. package/dist/spine.js +0 -0
  69. package/dist/spine.js.map +1 -0
  70. package/dist/token.d.ts +33 -0
  71. package/dist/token.d.ts.map +1 -0
  72. package/dist/token.js +66 -0
  73. package/dist/token.js.map +1 -0
  74. package/dist/tokendata.d.ts +50 -0
  75. package/dist/tokendata.d.ts.map +1 -0
  76. package/dist/tokendata.js +178 -0
  77. package/dist/tokendata.js.map +1 -0
  78. package/dist/traits.d.ts +38 -0
  79. package/dist/traits.d.ts.map +1 -0
  80. package/dist/traits.js +92 -0
  81. package/dist/traits.js.map +1 -0
  82. package/dist/types.d.ts +145 -0
  83. package/dist/types.d.ts.map +1 -0
  84. package/dist/types.js +2 -0
  85. package/dist/types.js.map +1 -0
  86. package/package.json +53 -0
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Canonical, shared ABX infrastructure — shipped as constants, keyed by EIP-155 chainId.
3
+ *
4
+ * The clone **factories** (trust anchors) and the stateless singletons (renderer, chunk store,
5
+ * minter, seed source) are deployed as public goods and recorded here, so the toolkit resolves
6
+ * them with zero local state — no per-user cache, no `config.json`. This is what lets the CLI be
7
+ * stateless about which infrastructure to use.
8
+ *
9
+ * DETERMINISTIC ADDRESSES: everything except the generator is deployed through the keyless CREATE2
10
+ * proxy (`0x4e59b44847b379578588920cA78FbF26c0B4956C`) with canonical salts (see
11
+ * `contracts/script/AbxSalts.sol`), so a given contract has the **same address on every chain** —
12
+ * that's why `CANONICAL` below is a single record, spread into each chain. Adding a chain deploys
13
+ * the same salts + initcode → the same addresses (computable before the first tx). The one
14
+ * exception is the **generator**: its constructor bakes chain-specific immutables (per-chain
15
+ * runtime-asset pointers + dependency registry), so it's recorded per chain.
16
+ *
17
+ * Precedence for every address is **explicit override → env → this manifest**:
18
+ * - override: a `--factory` / `--renderer` / `--chunk-store` flag (advanced / one-off)
19
+ * - env: `ABX_FACTORY` / `ABX_RENDERER` / `ABX_CHUNK_STORE` (a chain you run that isn't
20
+ * shipped yet, or a private deployment — the operator declares it, the tool never writes it)
21
+ * - manifest: the canonical address below
22
+ *
23
+ * ALPHA SCOPE: the initial npm alpha ships **testnet only** — Base Sepolia (the default,
24
+ * chainId 84532) and Sepolia (11155111). Mainnet entries are intentionally absent until the
25
+ * canonical set is deployed + funded on mainnet (Distribution roadmap step 4).
26
+ *
27
+ * Changing a contract → redeploy → repoint here: see contracts/README.md#changing-a-contract.
28
+ */
29
+ import type { Address } from 'viem';
30
+ export interface ChainDeployment {
31
+ factory?: Address;
32
+ seriesFactory?: Address;
33
+ seriesCodeFactory?: Address;
34
+ renderer?: Address;
35
+ chunkStore?: Address;
36
+ fixedPriceMinter?: Address;
37
+ seedSource?: Address;
38
+ generator?: Address;
39
+ }
40
+ export declare const DEPLOYMENTS: Record<number, ChainDeployment>;
41
+ /** The canonical deployment record for a chain (empty if the chain isn't shipped yet). */
42
+ export declare function getDeployment(chainId: number): ChainDeployment;
43
+ export declare function resolveFactory(chainId: number, override?: string): Address | undefined;
44
+ export declare function resolveSeriesFactory(chainId: number, override?: string): Address | undefined;
45
+ export declare function resolveRenderer(chainId: number, override?: string): Address | undefined;
46
+ export declare function resolveChunkStore(chainId: number, override?: string): Address | undefined;
47
+ export declare function resolveFixedPriceMinter(chainId: number, override?: string): Address | undefined;
48
+ export declare function resolveSeriesCodeFactory(chainId: number, override?: string): Address | undefined;
49
+ export declare function resolveSeedSource(chainId: number, override?: string): Address | undefined;
50
+ export declare function resolveGenerator(chainId: number, override?: string): Address | undefined;
51
+ /**
52
+ * The known `name@version` resolution roots per chain — Art Blocks' DependencyRegistryV0
53
+ * (specs/protocol/dependency-registry.md). ABX points at it and speaks its READ interface;
54
+ * we never deploy our own. The pointer a collection stores is soft and non-validating, so
55
+ * a chain with no entry simply deploys without one (the resolver falls back to its built-in
56
+ * CDN map) — never a blocker.
57
+ */
58
+ export declare const AB_DEPENDENCY_REGISTRY: Record<number, Address>;
59
+ export declare function resolveDependencyRegistry(chainId: number, override?: string): Address | undefined;
60
+ //# sourceMappingURL=deployments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deployments.d.ts","sourceRoot":"","sources":["../src/deployments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAElC,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAqBD,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAevD,CAAC;AAEF,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAE9D;AAOD,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAEtF;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAE5F;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAEvF;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAEzF;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAE/F;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAEhG;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAEzF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAExF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAG1D,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAEjG"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The cross-chain-identical set — CREATE2 (keyless proxy + `AbxSalts`), so these addresses are the
3
+ * SAME on every chain. Factory addresses list their EIP-1167 implementation; the implementations are
4
+ * identical cross-chain too (a factory does exactly one CREATE at nonce 1 from its own — identical —
5
+ * address). The renderer is spec v3 (artifacts manifest + authorship/rights contractURI fields).
6
+ * SeriesCode's delegatecalled write-path libraries are also CREATE2-deterministic and identical
7
+ * everywhere: AbxParamsLib 0x7DAa26bADD99812a77384B461b6375e0c04F2865,
8
+ * AbxCodeLib 0xCd12078E81A3BDEACdcd57AE390f4D59F832766B.
9
+ */
10
+ const CANONICAL = {
11
+ factory: '0xB9eEE39DB7D03E0b94CE403F69E928e2a5F134Ca', // impl 0xf1F0893897CC19e75d829fa550a5228c5119cA39
12
+ seriesFactory: '0x9d97C00100351682e6625961e033b6F43E60639A', // impl 0x58D8b9F7ABa3043734cBeBfaa9c46875070E16ed
13
+ seriesCodeFactory: '0x77f61Ead461f368dbF3788EeFe9693bA5a73Bd87', // impl 0xfd2034B6af517AD019f0dD7b007F07eF358D4053
14
+ renderer: '0x837A5cF907E7a6727B08acfE2A865F2bD5C50b1D', // spec v3
15
+ chunkStore: '0x03d3a962602093a937B96ee9C0b5C54cec3e701E',
16
+ fixedPriceMinter: '0xd970A2c936FFbb2130c2e4Ddf4245FF92465fEA5',
17
+ seedSource: '0x53eDFD2047e00C133378DEb430183DEE285E652e',
18
+ };
19
+ export const DEPLOYMENTS = {
20
+ // Sepolia (testnet) — CANONICAL infra + its own generator. Generator wired to AB's Sepolia
21
+ // dependency registry; default gateways ipfs.io / arweave.net.
22
+ 11155111: {
23
+ ...CANONICAL,
24
+ generator: '0x819D26830E1FbD1a3b383EcA1C24bc2770000910',
25
+ },
26
+ // Base Sepolia (testnet) — same CANONICAL infra; its own generator (no AB DependencyRegistry on
27
+ // this chain, so deployed with defaultDependencyRegistry = address(0); collections point at
28
+ // their own). Runtime asset pointers (SSTORE2): abxJsPointer 0x4525c352EFaeb3F3124399706Ec33B95f2230410,
29
+ // gunzipScriptPointer 0xa8Bc1339781deEbeb1eC949cD0641eb53D1044a6.
30
+ 84532: {
31
+ ...CANONICAL,
32
+ generator: '0x229337CA6A442b266BD43B7C70F0f24A2E378cB2',
33
+ },
34
+ };
35
+ /** The canonical deployment record for a chain (empty if the chain isn't shipped yet). */
36
+ export function getDeployment(chainId) {
37
+ return DEPLOYMENTS[chainId] ?? {};
38
+ }
39
+ // override → env → manifest. Returns undefined when none of the three has a value.
40
+ function pick(override, env, manifest) {
41
+ return (override ?? env ?? manifest);
42
+ }
43
+ export function resolveFactory(chainId, override) {
44
+ return pick(override, process.env.ABX_FACTORY, getDeployment(chainId).factory);
45
+ }
46
+ export function resolveSeriesFactory(chainId, override) {
47
+ return pick(override, process.env.ABX_SERIES_FACTORY, getDeployment(chainId).seriesFactory);
48
+ }
49
+ export function resolveRenderer(chainId, override) {
50
+ return pick(override, process.env.ABX_RENDERER, getDeployment(chainId).renderer);
51
+ }
52
+ export function resolveChunkStore(chainId, override) {
53
+ return pick(override, process.env.ABX_CHUNK_STORE, getDeployment(chainId).chunkStore);
54
+ }
55
+ export function resolveFixedPriceMinter(chainId, override) {
56
+ return pick(override, process.env.ABX_FIXED_PRICE_MINTER, getDeployment(chainId).fixedPriceMinter);
57
+ }
58
+ export function resolveSeriesCodeFactory(chainId, override) {
59
+ return pick(override, process.env.ABX_SERIES_CODE_FACTORY, getDeployment(chainId).seriesCodeFactory);
60
+ }
61
+ export function resolveSeedSource(chainId, override) {
62
+ return pick(override, process.env.ABX_SEED_SOURCE, getDeployment(chainId).seedSource);
63
+ }
64
+ export function resolveGenerator(chainId, override) {
65
+ return pick(override, process.env.ABX_GENERATOR, getDeployment(chainId).generator);
66
+ }
67
+ /**
68
+ * The known `name@version` resolution roots per chain — Art Blocks' DependencyRegistryV0
69
+ * (specs/protocol/dependency-registry.md). ABX points at it and speaks its READ interface;
70
+ * we never deploy our own. The pointer a collection stores is soft and non-validating, so
71
+ * a chain with no entry simply deploys without one (the resolver falls back to its built-in
72
+ * CDN map) — never a blocker.
73
+ */
74
+ export const AB_DEPENDENCY_REGISTRY = {
75
+ 1: '0x37861f95882ACDba2cCD84F5bFc4598e2ECDDdAF', // mainnet
76
+ 11155111: '0x5Fcc415BCFb164C5F826B5305274749BeB684e9b', // Sepolia
77
+ };
78
+ export function resolveDependencyRegistry(chainId, override) {
79
+ return pick(override, process.env.ABX_DEPENDENCY_REGISTRY, AB_DEPENDENCY_REGISTRY[chainId]);
80
+ }
81
+ //# sourceMappingURL=deployments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deployments.js","sourceRoot":"","sources":["../src/deployments.ts"],"names":[],"mappings":"AAyCA;;;;;;;;GAQG;AACH,MAAM,SAAS,GAAG;IAChB,OAAO,EAAE,4CAA4C,EAAE,kDAAkD;IACzG,aAAa,EAAE,4CAA4C,EAAE,kDAAkD;IAC/G,iBAAiB,EAAE,4CAA4C,EAAE,kDAAkD;IACnH,QAAQ,EAAE,4CAA4C,EAAE,UAAU;IAClE,UAAU,EAAE,4CAA4C;IACxD,gBAAgB,EAAE,4CAA4C;IAC9D,UAAU,EAAE,4CAA4C;CACH,CAAC;AAExD,MAAM,CAAC,MAAM,WAAW,GAAoC;IAC1D,2FAA2F;IAC3F,+DAA+D;IAC/D,QAAQ,EAAE;QACR,GAAG,SAAS;QACZ,SAAS,EAAE,4CAA4C;KACxD;IACD,gGAAgG;IAChG,4FAA4F;IAC5F,yGAAyG;IACzG,kEAAkE;IAClE,KAAK,EAAE;QACL,GAAG,SAAS;QACZ,SAAS,EAAE,4CAA4C;KACxD;CACF,CAAC;AAEF,0FAA0F;AAC1F,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,OAAO,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;AACpC,CAAC;AAED,mFAAmF;AACnF,SAAS,IAAI,CAAC,QAA4B,EAAE,GAAuB,EAAE,QAA6B;IAChG,OAAO,CAAC,QAAQ,IAAI,GAAG,IAAI,QAAQ,CAAwB,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,QAAiB;IAC/D,OAAO,IAAI,CAA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,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,QAAiB;IACjE,OAAO,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC;AACrF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAA4B;IAC7D,CAAC,EAAE,4CAA4C,EAAE,UAAU;IAC3D,QAAQ,EAAE,4CAA4C,EAAE,UAAU;CACnE,CAAC;AAEF,MAAM,UAAU,yBAAyB,CAAC,OAAe,EAAE,QAAiB;IAC1E,OAAO,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC;AAC9F,CAAC"}
package/dist/deps.d.ts ADDED
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Dependencies extension helpers — the vocabulary of a code project's ordered library
3
+ * declarations (`IAbxDependencies`): `(Resolution, bytes32 ref)` pairs, index 0 = the
4
+ * runtime by convention.
5
+ *
6
+ * Two ref shapes, auto-detectable from the human form:
7
+ * - `name@version` (e.g. `p5@1.0.0` — AB registry naming convention) → `Resolution.Registry`;
8
+ * encoded as readable-ASCII bytes32, left-aligned + zero-padded (a Solidity `bytes32`
9
+ * string literal) — resolved through the collection's soft `dependencyRegistry()` pointer.
10
+ * - `0x` + 40 hex (a raw data contract) → `Resolution.OnChain`; the address left-aligned
11
+ * in bytes32 — read directly, never through a registry.
12
+ *
13
+ * Also speaks the AB-compatible registry READ interface (`IDependencyRegistryV0`,
14
+ * specs/protocol/dependency-registry.md): `getDependencyDetails(bytes32)` is the
15
+ * load-bearing read behind the CLI's best-effort selection-time check.
16
+ */
17
+ import { type Address, type Hex } from 'viem';
18
+ /** `IAbxDependencies.Resolution` — index-aligned with the Solidity enum. */
19
+ export declare const DEP_RESOLUTION: {
20
+ readonly registry: 0;
21
+ readonly onchain: 1;
22
+ };
23
+ export type DepResolution = (typeof DEP_RESOLUTION)[keyof typeof DEP_RESOLUTION];
24
+ /** One parsed dependency ref: the enum value + the bytes32 the contract stores + the human form. */
25
+ export interface ParsedDependencyRef {
26
+ resolution: DepResolution;
27
+ ref: Hex;
28
+ display: string;
29
+ }
30
+ /** Encode a registry `name@version` as its readable-ASCII bytes32 (left-aligned, zero-padded —
31
+ * exactly `bytes32("p5@1.0.0")` in Solidity). Validates the AB naming convention: printable
32
+ * non-space ASCII, ≤ 32 bytes, exactly one `@` with a non-empty name and version. */
33
+ export declare function encodeDependencyName(nameAndVersion: string): Hex;
34
+ /**
35
+ * Parse a human `--dep` ref into its `(Resolution, bytes32)` pair — the one auto-detection
36
+ * rule: `0x` + 40 hex ⇒ `OnChain` (address left-aligned in bytes32); anything else must be a
37
+ * valid registry `name@version` ⇒ `Registry`.
38
+ */
39
+ export declare function parseDependencyRef(input: string): ParsedDependencyRef;
40
+ /** The reverse read: an evented `(resolution, bytes32)` back to its human form (the twin of
41
+ * the reconstruction fold's decode — registry ⇒ the tag, onchain ⇒ the address). */
42
+ export declare function decodeDependencyRef(resolution: DepResolution, ref: Hex): string;
43
+ /** The load-bearing read of AB's `IDependencyRegistryV0` — the exact upstream signature
44
+ * (any registry ABX consumers read from speaks this shape; see the dependency-registry spec). */
45
+ export declare const dependencyRegistryReadAbi: readonly [{
46
+ readonly type: "function";
47
+ readonly name: "getDependencyDetails";
48
+ readonly stateMutability: "view";
49
+ readonly inputs: readonly [{
50
+ readonly name: "dependencyNameAndVersion";
51
+ readonly type: "bytes32";
52
+ }];
53
+ readonly outputs: readonly [{
54
+ readonly name: "nameAndVersion";
55
+ readonly type: "string";
56
+ }, {
57
+ readonly name: "licenseType";
58
+ readonly type: "string";
59
+ }, {
60
+ readonly name: "preferredCDN";
61
+ readonly type: "string";
62
+ }, {
63
+ readonly name: "additionalCDNCount";
64
+ readonly type: "uint24";
65
+ }, {
66
+ readonly name: "preferredRepository";
67
+ readonly type: "string";
68
+ }, {
69
+ readonly name: "additionalRepositoryCount";
70
+ readonly type: "uint24";
71
+ }, {
72
+ readonly name: "dependencyWebsite";
73
+ readonly type: "string";
74
+ }, {
75
+ readonly name: "availableOnChain";
76
+ readonly type: "bool";
77
+ }, {
78
+ readonly name: "scriptCount";
79
+ readonly type: "uint24";
80
+ }];
81
+ }];
82
+ /** What the selection-time check cares about from a registry record. */
83
+ export interface RegistryDependencyDetails {
84
+ nameAndVersion: string;
85
+ licenseType: string;
86
+ preferredCDN: string;
87
+ availableOnChain: boolean;
88
+ scriptCount: number;
89
+ }
90
+ /** The one read this module needs — structurally satisfied by a viem `PublicClient` or a test mock. */
91
+ export interface DependencyReadClient {
92
+ readContract(args: {
93
+ address: Address;
94
+ abi: readonly unknown[];
95
+ functionName: string;
96
+ args: readonly unknown[];
97
+ }): Promise<unknown>;
98
+ }
99
+ /**
100
+ * Read one dependency's registry record. Returns `null` when the registry doesn't know the
101
+ * ref — AB's registry doesn't revert for an unknown dependency: it ECHOES the requested
102
+ * `nameAndVersion` back with every other field zero-valued (verified against Sepolia), so
103
+ * existence is "any substantive field set" (license is required at registration upstream,
104
+ * so a real record always has at least that — e.g. `js@na` is license-only). Any
105
+ * transport/revert error propagates — the caller decides whether that means "not found"
106
+ * (a revert) or "check unavailable" (RPC down); this stays a pure read.
107
+ */
108
+ export declare function readRegistryDependency(client: DependencyReadClient, registry: Address, ref: Hex): Promise<RegistryDependencyDetails | null>;
109
+ //# sourceMappingURL=deps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../src/deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAgB,KAAK,OAAO,EAAE,KAAK,GAAG,EAAC,MAAM,MAAM,CAAC;AAG3D,4EAA4E;AAC5E,eAAO,MAAM,cAAc;;;CAAqC,CAAC;AACjE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO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ered library
3
+ * declarations (`IAbxDependencies`): `(Resolution, bytes32 ref)` pairs, index 0 = the
4
+ * runtime by convention.
5
+ *
6
+ * Two ref shapes, auto-detectable from the human form:
7
+ * - `name@version` (e.g. `p5@1.0.0` — AB registry naming convention) → `Resolution.Registry`;
8
+ * encoded as readable-ASCII bytes32, left-aligned + zero-padded (a Solidity `bytes32`
9
+ * string literal) — resolved through the collection's soft `dependencyRegistry()` pointer.
10
+ * - `0x` + 40 hex (a raw data contract) → `Resolution.OnChain`; the address left-aligned
11
+ * in bytes32 — read directly, never through a registry.
12
+ *
13
+ * Also speaks the AB-compatible registry READ interface (`IDependencyRegistryV0`,
14
+ * specs/protocol/dependency-registry.md): `getDependencyDetails(bytes32)` is the
15
+ * load-bearing read behind the CLI's best-effort selection-time check.
16
+ */
17
+ import { padHex, toHex } from 'viem';
18
+ import { decodeTag } from './spine.js';
19
+ /** `IAbxDependencies.Resolution` — index-aligned with the Solidity enum. */
20
+ export const DEP_RESOLUTION = { registry: 0, onchain: 1 };
21
+ // Printable non-space ASCII — what a readable bytes32 tag can carry unambiguously
22
+ // (trailing spaces are stripped by the tag decode, so a space anywhere is refused).
23
+ const PRINTABLE_ASCII = /^[\x21-\x7E]+$/;
24
+ /** Encode a registry `name@version` as its readable-ASCII bytes32 (left-aligned, zero-padded —
25
+ * exactly `bytes32("p5@1.0.0")` in Solidity). Validates the AB naming convention: printable
26
+ * non-space ASCII, ≤ 32 bytes, exactly one `@` with a non-empty name and version. */
27
+ export function encodeDependencyName(nameAndVersion) {
28
+ const tag = nameAndVersion.trim();
29
+ if (!PRINTABLE_ASCII.test(tag)) {
30
+ throw new Error(`dependency ref '${nameAndVersion}' must be printable non-space ASCII (a registry ref is a readable bytes32)`);
31
+ }
32
+ if (tag.length > 32) {
33
+ throw new Error(`dependency ref '${tag}' is ${tag.length} bytes — a bytes32 ref holds at most 32`);
34
+ }
35
+ const at = tag.indexOf('@');
36
+ if (at <= 0 || at !== tag.lastIndexOf('@') || at === tag.length - 1) {
37
+ throw new Error(`dependency ref '${tag}' must be name@version with exactly one '@' (e.g. p5@1.0.0), or a 0x… data-contract address`);
38
+ }
39
+ return toHex(tag, { size: 32 });
40
+ }
41
+ /**
42
+ * Parse a human `--dep` ref into its `(Resolution, bytes32)` pair — the one auto-detection
43
+ * rule: `0x` + 40 hex ⇒ `OnChain` (address left-aligned in bytes32); anything else must be a
44
+ * valid registry `name@version` ⇒ `Registry`.
45
+ */
46
+ export function parseDependencyRef(input) {
47
+ const t = input.trim();
48
+ if (/^0x[0-9a-fA-F]{40}$/.test(t)) {
49
+ const addr = t.toLowerCase();
50
+ return { resolution: DEP_RESOLUTION.onchain, ref: padHex(addr, { size: 32, dir: 'right' }), display: addr };
51
+ }
52
+ return { resolution: DEP_RESOLUTION.registry, ref: encodeDependencyName(t), display: t };
53
+ }
54
+ /** The reverse read: an evented `(resolution, bytes32)` back to its human form (the twin of
55
+ * the reconstruction fold's decode — registry ⇒ the tag, onchain ⇒ the address). */
56
+ export function decodeDependencyRef(resolution, ref) {
57
+ return resolution === DEP_RESOLUTION.onchain ? '0x' + ref.slice(2, 42) : decodeTag(ref);
58
+ }
59
+ // ── the AB-compatible registry read (IDependencyRegistryV0) ───────────────────
60
+ /** The load-bearing read of AB's `IDependencyRegistryV0` — the exact upstream signature
61
+ * (any registry ABX consumers read from speaks this shape; see the dependency-registry spec). */
62
+ export const dependencyRegistryReadAbi = [
63
+ {
64
+ type: 'function',
65
+ name: 'getDependencyDetails',
66
+ stateMutability: 'view',
67
+ inputs: [{ name: 'dependencyNameAndVersion', type: 'bytes32' }],
68
+ outputs: [
69
+ { name: 'nameAndVersion', type: 'string' },
70
+ { name: 'licenseType', type: 'string' },
71
+ { name: 'preferredCDN', type: 'string' },
72
+ { name: 'additionalCDNCount', type: 'uint24' },
73
+ { name: 'preferredRepository', type: 'string' },
74
+ { name: 'additionalRepositoryCount', type: 'uint24' },
75
+ { name: 'dependencyWebsite', type: 'string' },
76
+ { name: 'availableOnChain', type: 'bool' },
77
+ { name: 'scriptCount', type: 'uint24' },
78
+ ],
79
+ },
80
+ ];
81
+ /**
82
+ * Read one dependency's registry record. Returns `null` when the registry doesn't know the
83
+ * ref — AB's registry doesn't revert for an unknown dependency: it ECHOES the requested
84
+ * `nameAndVersion` back with every other field zero-valued (verified against Sepolia), so
85
+ * existence is "any substantive field set" (license is required at registration upstream,
86
+ * so a real record always has at least that — e.g. `js@na` is license-only). Any
87
+ * transport/revert error propagates — the caller decides whether that means "not found"
88
+ * (a revert) or "check unavailable" (RPC down); this stays a pure read.
89
+ */
90
+ export async function readRegistryDependency(client, registry, ref) {
91
+ const out = (await client.readContract({
92
+ address: registry,
93
+ abi: dependencyRegistryReadAbi,
94
+ functionName: 'getDependencyDetails',
95
+ args: [ref],
96
+ }));
97
+ const [nameAndVersion, licenseType, preferredCDN, , preferredRepository, , website, availableOnChain, scriptCount] = out;
98
+ const exists = Boolean(licenseType || preferredCDN || preferredRepository || website || availableOnChain || Number(scriptCount) > 0);
99
+ if (!nameAndVersion || !exists)
100
+ return null;
101
+ return { nameAndVersion, licenseType, preferredCDN, availableOnChain, scriptCount: Number(scriptCount) };
102
+ }
103
+ //# sourceMappingURL=deps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deps.js","sourceRoot":"","sources":["../src/deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAC,MAAM,EAAE,KAAK,EAAyB,MAAM,MAAM,CAAC;AAC3D,OAAO,EAAC,SAAS,EAAC,MAAM,YAAY,CAAC;AAErC,4EAA4E;AAC5E,MAAM,CAAC,MAAM,cAAc,GAAG,EAAC,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAU,CAAC;AAUjE,kFAAkF;AAClF,oFAAoF;AACpF,MAAM,eAAe,GAAG,gBAAgB,CAAC;AAEzC;;sFAEsF;AACtF,MAAM,UAAU,oBAAoB,CAAC,cAAsB;IACzD,MAAM,GAAG,GAAG,cA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AAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC;QACrC,OAAO,EAAE,QAAQ;QACjB,GAAG,EAAE,yBAAyB;QAC9B,YAAY,EAAE,sBAAsB;QACpC,IAAI,EAAE,CAAC,GAAG,CAAC;KACZ,CAAC,CAA8E,CAAC;IACjF,MAAM,CAAC,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,AAAD,EAAG,mBAAmB,EAAE,AAAD,EAAG,OAAO,EAAE,gBAAgB,EAAE,WAAW,CAAC,GAAG,GAAG,CAAC;IACzH,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,IAAI,YAAY,IAAI,mBAAmB,IAAI,OAAO,IAAI,gBAAgB,IAAI,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;IACrI,IAAI,CAAC,cAAc,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAC5C,OAAO,EAAC,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,EAAC,CAAC;AACzG,CAAC"}
package/dist/env.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function loadDotEnv(startDir?: string): void;
2
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAWA,wBAAgB,UAAU,CAAC,QAAQ,GAAE,MAAsB,GAAG,IAAI,CAcjE"}
package/dist/env.js ADDED
@@ -0,0 +1,45 @@
1
+ import { readFileSync, existsSync } from 'node:fs';
2
+ import { dirname, resolve } from 'node:path';
3
+ /**
4
+ * Minimal, dependency-free .env loader. Walks up from `startDir` to the repo
5
+ * root looking for a `.env`, and sets any keys not already present in the
6
+ * environment. Deliberately tiny — the toolkit must run with `pnpm install`
7
+ * and nothing else.
8
+ */
9
+ let loaded = false;
10
+ export function loadDotEnv(startDir = process.cwd()) {
11
+ if (loaded)
12
+ return;
13
+ loaded = true;
14
+ let dir = resolve(startDir);
15
+ for (let i = 0; i < 8; i++) {
16
+ const candidate = resolve(dir, '.env');
17
+ if (existsSync(candidate)) {
18
+ parseInto(readFileSync(candidate, 'utf8'));
19
+ return;
20
+ }
21
+ const parent = dirname(dir);
22
+ if (parent === dir)
23
+ break;
24
+ dir = parent;
25
+ }
26
+ }
27
+ function parseInto(content) {
28
+ for (const rawLine of content.split('\n')) {
29
+ const line = rawLine.trim();
30
+ if (!line || line.startsWith('#'))
31
+ continue;
32
+ const eq = line.indexOf('=');
33
+ if (eq === -1)
34
+ continue;
35
+ const key = line.slice(0, eq).trim();
36
+ let value = line.slice(eq + 1).trim();
37
+ if ((value.startsWith('"') && value.endsWith('"')) ||
38
+ (value.startsWith("'") && value.endsWith("'"))) {
39
+ value = value.slice(1, -1);
40
+ }
41
+ if (key && process.env[key] === undefined)
42
+ process.env[key] = value;
43
+ }
44
+ }
45
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,UAAU,EAAC,MAAM,SAAS,CAAC;AACjD,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,WAAW,CAAC;AAE3C;;;;;GAKG;AACH,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,MAAM,UAAU,UAAU,CAAC,WAAmB,OAAO,CAAC,GAAG,EAAE;IACzD,IAAI,MAAM;QAAE,OAAO;IACnB,MAAM,GAAG,IAAI,CAAC;IACd,IAAI,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACvC,IAAI,UAAU,CAAC,SAAS,CA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AAK,CAAC;IACtE,CAAC;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * FastLZ (level 1) — a pure, dependency-free codec whose output is byte-compatible with
3
+ * Solady `LibZip.flzDecompress` (the on-chain decompressor the `AbxChunkStore` reader uses).
4
+ *
5
+ * We encode off-chain (cheaper than compressing on-chain) and the reader decompresses on
6
+ * read, so a FastLZ chunk stays fully on-chain-renderable — the compression is purely a
7
+ * storage-gas optimization, invisible above the reader. The token never sees FastLZ; it's
8
+ * an internal codec of the chunk store.
9
+ *
10
+ * Token format (what flzDecompress expects):
11
+ * - literal run: control byte `c` (top 3 bits 0, so `c` in 0..31) ⇒ `c+1` literal bytes follow.
12
+ * - short match: top 3 bits `t` in 1..6 ⇒ length `t+2` (3..8); distance-1 = `((c&0x1f)<<8)|next`.
13
+ * - long match: top 3 bits == 7 ⇒ length `9 + lenByte` (9..264); distance-1 = `((c&0x1f)<<8)|distByte`.
14
+ * Min match length 3, max back-distance 8192.
15
+ */
16
+ /** Compress `input` to a FastLZ stream `LibZip.flzDecompress` (and our reader) will inflate. */
17
+ export declare function flzCompress(input: Uint8Array): Uint8Array;
18
+ /** Inflate a FastLZ stream — the JS mirror of `LibZip.flzDecompress` (for tests + off-chain serve). */
19
+ export declare function flzDecompress(input: Uint8Array): Uint8Array;
20
+ //# sourceMappingURL=fastlz.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fastlz.d.ts","sourceRoot":"","sources":["../src/fastlz.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAcH,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAgEzD;AAED,uGAAuG;AACvG,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CA6B3D"}
package/dist/fastlz.js ADDED
@@ -0,0 +1,123 @@
1
+ /**
2
+ * FastLZ (level 1) — a pure, dependency-free codec whose output is byte-compatible with
3
+ * Solady `LibZip.flzDecompress` (the on-chain decompressor the `AbxChunkStore` reader uses).
4
+ *
5
+ * We encode off-chain (cheaper than compressing on-chain) and the reader decompresses on
6
+ * read, so a FastLZ chunk stays fully on-chain-renderable — the compression is purely a
7
+ * storage-gas optimization, invisible above the reader. The token never sees FastLZ; it's
8
+ * an internal codec of the chunk store.
9
+ *
10
+ * Token format (what flzDecompress expects):
11
+ * - literal run: control byte `c` (top 3 bits 0, so `c` in 0..31) ⇒ `c+1` literal bytes follow.
12
+ * - short match: top 3 bits `t` in 1..6 ⇒ length `t+2` (3..8); distance-1 = `((c&0x1f)<<8)|next`.
13
+ * - long match: top 3 bits == 7 ⇒ length `9 + lenByte` (9..264); distance-1 = `((c&0x1f)<<8)|distByte`.
14
+ * Min match length 3, max back-distance 8192.
15
+ */
16
+ const MAX_DISTANCE = 8192;
17
+ const MAX_MATCH = 264; // 9 + 255 (one extended-length byte)
18
+ const MIN_MATCH = 3;
19
+ const MAX_LITERAL_RUN = 32;
20
+ const HASH_SIZE = 8192;
21
+ function hash3(b, p) {
22
+ const v = (b[p] << 16) | (b[p + 1] << 8) | b[p + 2];
23
+ // 32-bit multiplicative hash → top 13 bits.
24
+ return (Math.imul(v, 0x9e3779b1) >>> 19) & (HASH_SIZE - 1);
25
+ }
26
+ /** Compress `input` to a FastLZ stream `LibZip.flzDecompress` (and our reader) will inflate. */
27
+ export function flzCompress(input) {
28
+ const n = input.length;
29
+ if (n === 0)
30
+ return new Uint8Array(0);
31
+ const out = [];
32
+ const table = new Int32Array(HASH_SIZE).fill(-1);
33
+ let anchor = 0; // first byte of the pending literal run
34
+ let p = 0;
35
+ const emitLiterals = (from, to) => {
36
+ let i = from;
37
+ while (i < to) {
38
+ const run = Math.min(MAX_LITERAL_RUN, to - i);
39
+ out.push(run - 1); // control byte 0..31
40
+ for (let k = 0; k < run; k++)
41
+ out.push(input[i + k]);
42
+ i += run;
43
+ }
44
+ };
45
+ while (p + MIN_MATCH <= n) {
46
+ const h = hash3(input, p);
47
+ const ref = table[h];
48
+ table[h] = p;
49
+ const dist = ref >= 0 ? p - ref : 0;
50
+ if (ref >= 0 &&
51
+ dist >= 1 &&
52
+ dist <= MAX_DISTANCE &&
53
+ input[ref] === input[p] &&
54
+ input[ref + 1] === input[p + 1] &&
55
+ input[ref + 2] === input[p + 2]) {
56
+ let len = MIN_MATCH;
57
+ const maxLen = Math.min(MAX_MATCH, n - p);
58
+ while (len < maxLen && input[ref + len] === input[p + len])
59
+ len++;
60
+ emitLiterals(anchor, p);
61
+ const dm1 = dist - 1;
62
+ if (len <= 8) {
63
+ out.push(((len - 2) << 5) | (dm1 >> 8)); // t = len-2 in 1..6
64
+ out.push(dm1 & 0xff);
65
+ }
66
+ else {
67
+ out.push((7 << 5) | (dm1 >> 8));
68
+ out.push(len - 9); // 0..255
69
+ out.push(dm1 & 0xff);
70
+ }
71
+ // index the consumed region (better matches downstream), then jump past it.
72
+ const end = p + len;
73
+ let q = p + 1;
74
+ while (q < end && q + MIN_MATCH <= n) {
75
+ table[hash3(input, q)] = q;
76
+ q++;
77
+ }
78
+ p = end;
79
+ anchor = end;
80
+ }
81
+ else {
82
+ p++;
83
+ }
84
+ }
85
+ emitLiterals(anchor, n); // tail literals (incl. the last <3 bytes that can't start a match)
86
+ return Uint8Array.from(out);
87
+ }
88
+ /** Inflate a FastLZ stream — the JS mirror of `LibZip.flzDecompress` (for tests + off-chain serve). */
89
+ export function flzDecompress(input) {
90
+ const n = input.length;
91
+ const out = [];
92
+ let i = 0;
93
+ while (i < n) {
94
+ const c = input[i];
95
+ const t = c >> 5;
96
+ if (t === 0) {
97
+ const count = c + 1; // literal run
98
+ for (let k = 0; k < count; k++)
99
+ out.push(input[i + 1 + k]);
100
+ i += 2 + c;
101
+ }
102
+ else {
103
+ const extended = t === 7;
104
+ let len;
105
+ let dm1;
106
+ if (!extended) {
107
+ len = 2 + t;
108
+ dm1 = ((c & 0x1f) << 8) + input[i + 1];
109
+ i += 2;
110
+ }
111
+ else {
112
+ len = 9 + input[i + 1];
113
+ dm1 = ((c & 0x1f) << 8) + input[i + 2];
114
+ i += 3;
115
+ }
116
+ const start = out.length - (dm1 + 1);
117
+ for (let k = 0; k < len; k++)
118
+ out.push(out[start + k]); // overlap-safe (RLE)
119
+ }
120
+ }
121
+ return Uint8Array.from(out);
122
+ }
123
+ //# sourceMappingURL=fastlz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fastlz.js","sourceRoot":"","sources":["../src/fastlz.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,SAAS,GAAG,GAAG,CAAC,CAAC,qCAAqC;AAC5D,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,SAAS,KAAK,CAAC,CAAa,EAAE,CAAS;IACrC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACpD,4CAA4C;IAC5C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,WAAW,CAAC,KAAiB;IAC3C,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IACvB,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAEtC,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC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