@mysten-incubation/devstack 0.4.0 → 0.6.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.
- package/README.md +9 -10
- package/dashboard-ui/assets/{grpc-CpkDu4SA.js → grpc-s7Ztk9wv.js} +1 -1
- package/dashboard-ui/assets/{index-jLPRmjst.js → index-DrOd0m4F.js} +2 -2
- package/dashboard-ui/index.html +1 -1
- package/dist/contracts/routable.d.mts +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/orchestrators/boot.mjs +2 -1
- package/dist/orchestrators/boot.mjs.map +1 -1
- package/dist/orchestrators/router/file-provider.mjs +11 -8
- package/dist/orchestrators/router/file-provider.mjs.map +1 -1
- package/dist/orchestrators/router/service.mjs +2 -2
- package/dist/orchestrators/router/service.mjs.map +1 -1
- package/dist/plugins/deepbook/index.d.mts +36 -6
- package/dist/plugins/deepbook/index.mjs +52 -16
- package/dist/plugins/deepbook/index.mjs.map +1 -1
- package/dist/plugins/seal/codegen.d.mts +5 -0
- package/dist/plugins/seal/codegen.mjs +53 -10
- package/dist/plugins/seal/codegen.mjs.map +1 -1
- package/dist/plugins/seal/index.d.mts +64 -19
- package/dist/plugins/seal/index.mjs +26 -36
- package/dist/plugins/seal/index.mjs.map +1 -1
- package/dist/plugins/seal/mode/fork-known.d.mts +0 -2
- package/dist/plugins/seal/mode/fork-known.mjs +11 -22
- package/dist/plugins/seal/mode/fork-known.mjs.map +1 -1
- package/dist/plugins/seal/mode/live.d.mts +36 -13
- package/dist/plugins/seal/mode/live.mjs +104 -43
- package/dist/plugins/seal/mode/live.mjs.map +1 -1
- package/dist/plugins/seal/mode/local-keygen.mjs +2 -1
- package/dist/plugins/seal/mode/local-keygen.mjs.map +1 -1
- package/dist/plugins/seal/registry-publish.d.mts +15 -3
- package/dist/plugins/seal/registry-publish.mjs.map +1 -1
- package/dist/plugins/sui/index.d.mts +10 -10
- package/dist/plugins/walrus/client-services.d.mts +1 -0
- package/dist/plugins/walrus/client-services.mjs +115 -0
- package/dist/plugins/walrus/client-services.mjs.map +1 -0
- package/dist/plugins/walrus/deploy.mjs +11 -5
- package/dist/plugins/walrus/deploy.mjs.map +1 -1
- package/dist/plugins/walrus/errors.d.mts +1 -1
- package/dist/plugins/walrus/errors.mjs.map +1 -1
- package/dist/plugins/walrus/index.d.mts +138 -9
- package/dist/plugins/walrus/index.mjs +72 -20
- package/dist/plugins/walrus/index.mjs.map +1 -1
- package/dist/plugins/walrus/mode/known-deploy.d.mts +5 -1
- package/dist/plugins/walrus/mode/known-deploy.mjs +14 -11
- package/dist/plugins/walrus/mode/known-deploy.mjs.map +1 -1
- package/dist/plugins/walrus/mode/local-cluster.d.mts +14 -1
- package/dist/plugins/walrus/mode/local-cluster.mjs +54 -12
- package/dist/plugins/walrus/mode/local-cluster.mjs.map +1 -1
- package/dist/plugins/walrus/routable.mjs +12 -15
- package/dist/plugins/walrus/routable.mjs.map +1 -1
- package/dist/plugins/walrus/snapshot.mjs +3 -2
- package/dist/plugins/walrus/snapshot.mjs.map +1 -1
- package/dist/plugins/walrus/storage-nodes.mjs +31 -33
- package/dist/plugins/walrus/storage-nodes.mjs.map +1 -1
- package/dist/substrate/runtime/config-validation.mjs +1 -1
- package/images/walrus/Dockerfile +17 -4
- package/images/walrus/deploy-walrus.sh +7 -4
- package/images/walrus/run-walrus-client-service.sh +103 -0
- package/package.json +2 -2
- package/dist/plugins/seal/service.mjs +0 -17
- package/dist/plugins/seal/service.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["coinFromPackage","builtinCoin","localOpts"],"sources":["../../../src/plugins/deepbook/index.ts"],"sourcesContent":["// Deepbook plugin — barrel + factories.\n//\n// Architecture: Deepbook is a task plugin that resolves a managed\n// local deployment, a known deployment, or explicit caller-supplied\n// override ids, then emits bindings.\n//\n// Mode discipline:\n//\n// - `deepbook(opts)` — explicit mode selection.\n// Localnet can default to local when\n// passed local options.\n// - `deepbookFor(network).local` — local-branch managed deployment.\n// - `deepbookFor(network).override` — local-branch override for\n// caller-supplied deployment ids.\n// - `deepbookFor(network).known` — known-deployment branch (live +\n// fork networks; wraps an already-\n// deployed canonical instance).\n//\n// During `start`, the plugin emits (via the typed `ctx.*` verbs):\n//\n// Local mode:\n// 1. `ctx.snapshotExtra` — `deepbook/<name>` subtree.\n// 2. `ctx.codegen` — `deepbook-network` bindings.\n//\n// Override mode:\n// 1. `ctx.snapshotExtra` — identity guard only.\n// 2. `ctx.codegen` — `deepbook-network` bindings.\n//\n// Known mode:\n// 1. `ctx.snapshotExtra` — identity guard only.\n// 2. `ctx.codegen` — `deepbook-network` bindings (mode='known').\n//\n// Resource id: `deepbook/<name>`. Plugin key: `deepbook:<name>`.\n\nimport { Effect } from 'effect';\n\nimport { defineModeNamespace } from '../../api/mode-narrowed-factory.ts';\nimport { definePlugin, resource, type ResourceValueOf } from '../../api/define-plugin.ts';\nimport type { SnapshotableDecl } from '../../contracts/snapshotable.ts';\nimport { PluginContext } from '../../substrate/plugin-ctx.ts';\nimport { CacheService } from '../../substrate/runtime/cache/index.ts';\nimport { setCurrentPluginPhase } from '../../substrate/runtime/current-plugin.ts';\nimport { passthroughOrWrap } from '../../substrate/runtime/passthrough-or-wrap.ts';\nimport { IdentityContext } from '../../substrate/runtime/paths.ts';\nimport { suiResource } from '../sui/index.ts';\nimport type { AccountValue } from '../account/index.ts';\nimport {\n\tbuiltin as builtinCoin,\n\tfromPackage as coinFromPackage,\n\ttype CoinValue,\n} from '../coin/index.ts';\nimport type { LocalPackageResolved } from '../package/index.ts';\n\nimport { deepbookPluginKey } from './plugin-key.ts';\nimport {\n\tDEEPBOOK_ERROR_TAGS,\n\tdeepbookConfigError,\n\tdeepbookPluginError,\n\ttype DeepbookConfigError,\n\ttype DeepbookError,\n\ttype DeepbookPluginError,\n} from './errors.ts';\nimport {\n\tmakeDeepbookCodegenable,\n\tmakeDeepbookStaticCodegen,\n\ttype DeepbookBindings,\n} from './codegen.ts';\nimport { LOCAL_NETWORK_NAME } from '../../api/inference-network.ts';\nimport {\n\tmakeDeepbookDeepFundingContribution,\n\tmakeDeepbookDeepFundingStrategy,\n\ttype DeepbookDeepFundingStrategy,\n} from './faucet-strategy.ts';\nimport { makeKnownSnapshotable, makeLocalSnapshotable } from './snapshot.ts';\nimport {\n\tcreateDeepbookPools,\n\tseedDeepbookPools,\n\ttype DeepbookDeployment,\n\ttype ResolvedDeepbookPoolSpec,\n} from './deploy.ts';\nimport { initLocalPythFeeds } from './pyth/index.ts';\nimport type {\n\tAccountMemberAlias,\n\tDeepbookPackageMember,\n\tDeepbookPool,\n\tDeepbookPoolSpec,\n\tPythHandle,\n\tPythOptions,\n} from './types.ts';\n\n// ---------------------------------------------------------------------------\n// Resource — the resolved value all consumers read\n// ---------------------------------------------------------------------------\n\nexport type DeepbookResourceId<Name extends string> = `deepbook/${Name}`;\n\nconst makeDeepbookResource = <Name extends string>(name: Name) =>\n\tresource<DeepbookResourceId<Name>, DeepbookResolved>(\n\t\t`deepbook/${name}` as DeepbookResourceId<Name>,\n\t);\n\n/** The deepbook resolved value. Mode-asymmetric:\n *\n * - `adminCapId` is `null` for known-deployment mode.\n * - `margin` / `serverUrl` / `indexerUrl` are `null` when the\n * corresponding sub-feature is not enabled.\n * - `hasSeedLiquidity` is `true` when one or more pools placed seed\n * orders at boot (it is NOT a market-maker process state). */\nexport interface DeepbookResolved {\n\treadonly mode: 'local' | 'override' | 'known';\n\treadonly network: string;\n\treadonly packageId: string;\n\treadonly registryId: string;\n\treadonly adminCapId: string | null;\n\treadonly deepTreasuryId: string | null;\n\treadonly pools: ReadonlyArray<DeepbookPool>;\n\treadonly pyth: PythHandle | null;\n\treadonly margin: {\n\t\treadonly packageId: string;\n\t\treadonly registryId: string;\n\t} | null;\n\treadonly serverUrl: string | null;\n\treadonly indexerUrl: string | null;\n\t/** `true` when one or more pools placed seed orders at boot. This reflects\n\t * \"a pool was seeded with liquidity\", NOT a running market-maker process. */\n\treadonly hasSeedLiquidity: boolean;\n\treadonly deepFundingStrategy: DeepbookDeepFundingStrategy | null;\n}\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\nexport interface DeepbookCommonOptions {\n\treadonly name?: string;\n}\n\n/** Override mode wraps an explicitly supplied deployment. It does not\n * publish or manage DeepBook locally. */\nexport interface DeepbookOverrideOptions extends DeepbookCommonOptions {\n\treadonly packageId: string;\n\treadonly registryId: string;\n\treadonly adminCapId: string;\n\treadonly network?: string;\n}\n\n/** Local mode wraps an explicitly supplied local DeepBook package.\n *\n * Explicit-config discipline: `publisher`, `package`, and `pools` are all\n * REQUIRED — the caller publishes the DeepBook Move tree, funds a publisher,\n * and declares the pools. There is no zero-arg auto-synthesis; an\n * under-specified `deepbook({ mode: 'local' })` fails fast with a tagged\n * config error (see the guard in `resolveLocalOptions`). `pyth` stays\n * optional — pass it to seed local mock price feeds, omit it for a\n * feed-less DeX. */\nexport interface DeepbookLocalOptions<\n\tPublisher extends AccountMemberAlias = AccountMemberAlias,\n\tPackage extends DeepbookPackageMember = DeepbookPackageMember,\n\tPools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tPyth extends PythOptions | undefined = undefined,\n> extends DeepbookCommonOptions {\n\t/** Publisher account — Direct Member Ref (locked API decision). Required. */\n\treadonly publisher: Publisher;\n\t/** Published DeepBook package member. The package must capture the\n\t * `registry::Registry` and `registry::DeepbookAdminCap` object ids.\n\t * Required. */\n\treadonly package: Package;\n\t/** Optional local mock-Pyth package + feed setup. Omit for a feed-less\n\t * local DeX. */\n\treadonly pyth?: Pyth;\n\t/** Capture key for the package-created `registry::Registry`. */\n\treadonly registryIdKey?: string;\n\t/** Capture key for the package-created `registry::DeepbookAdminCap`. */\n\treadonly adminCapIdKey?: string;\n\t/** Optional capture key for a DEEP treasury object used by SDK bindings. */\n\treadonly deepTreasuryIdKey?: string;\n\t/** Pools to create after the DeepBook package publishes. OPTIONAL: when\n\t * omitted, a single unseeded (empty-book) `DEEP/SUI` pool is synthesized\n\t * (the DEEP coin comes from `package`, SUI is built-in — no extra package\n\t * needed), so a minimal `deepbook({ mode:'local', publisher, package })`\n\t * boots a usable DeX. Pass `[]` explicitly for a known-empty deployment, or your own\n\t * pools for full control. */\n\treadonly pools?: Pools;\n}\n\nexport type DeepbookKnownNetwork = 'mainnet' | 'testnet';\n\ninterface DeepbookKnownCommonOptions extends DeepbookCommonOptions {\n\t/** Optional network override (defaults to the configured network). */\n\treadonly network?: string;\n}\n\ninterface DeepbookKnownNetworkOptions extends DeepbookKnownCommonOptions {\n\treadonly network: DeepbookKnownNetwork;\n\treadonly packageId?: string;\n\treadonly registryId?: string;\n}\n\ninterface DeepbookKnownExplicitOptions extends DeepbookKnownCommonOptions {\n\treadonly packageId: string;\n\treadonly registryId: string;\n\treadonly network?: DeepbookKnownNetwork;\n}\n\nexport type DeepbookKnownOptions = DeepbookKnownNetworkOptions | DeepbookKnownExplicitOptions;\n\nexport type DeepbookOptions<\n\tPublisher extends AccountMemberAlias = AccountMemberAlias,\n\tPyth extends PythOptions | undefined = PythOptions | undefined,\n> =\n\t| ({\n\t\t\treadonly mode: 'local';\n\t } & DeepbookLocalOptions<\n\t\t\tPublisher,\n\t\t\tDeepbookPackageMember,\n\t\t\tReadonlyArray<DeepbookPoolSpec>,\n\t\t\tPyth\n\t >)\n\t| ({ readonly mode: 'override' } & DeepbookOverrideOptions)\n\t| ({ readonly mode: 'known' } & DeepbookKnownOptions);\n\n// ---------------------------------------------------------------------------\n// Plugin construction — override\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_NAME = 'deepbook';\n\nconst KNOWN_DEEPBOOK_DEPLOYMENTS: Record<\n\tDeepbookKnownNetwork,\n\t{\n\t\treadonly network: string;\n\t\treadonly packageId: string;\n\t\treadonly registryId: string;\n\t\treadonly deepTreasuryId: string;\n\t\treadonly pyth: PythHandle;\n\t}\n> = {\n\ttestnet: {\n\t\tnetwork: 'testnet',\n\t\tpackageId: '0x22be4cade64bf2d02412c7e8d0e8beea2f78828b948118d46735315409371a3c',\n\t\tregistryId: '0x7c256edbda983a2cd6f946655f4bf3f00a41043993781f8674a7046e8c0e11d1',\n\t\tdeepTreasuryId: '0x69fffdae0075f8f71f4fa793549c11079266910e8905169845af1f5d00e09dcb',\n\t\tpyth: {\n\t\t\tpackageId: null,\n\t\t\tstateId: '0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c',\n\t\t\twormholeStateId: '0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790',\n\t\t\tfeeds: [],\n\t\t},\n\t},\n\tmainnet: {\n\t\tnetwork: 'mainnet',\n\t\tpackageId: '0xf48222c4e057fa468baf136bff8e12504209d43850c5778f76159292a96f621e',\n\t\tregistryId: '0xaf16199a2dff736e9f07a845f23c5da6df6f756eddb631aed9d24a93efc4549d',\n\t\tdeepTreasuryId: '0x032abf8948dda67a271bcc18e776dbbcfb0d58c8d288a700ff0d5521e57a1ffe',\n\t\tpyth: {\n\t\t\tpackageId: null,\n\t\t\tstateId: '0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8',\n\t\t\twormholeStateId: '0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c',\n\t\t\tfeeds: [],\n\t\t},\n\t},\n};\n\ntype PoolCoinRefs<Pools extends ReadonlyArray<DeepbookPoolSpec>> =\n\tPools[number] extends DeepbookPoolSpec<infer Base, infer Quote> ? Base | Quote : never;\ntype PoolCoinRefTuple<Pools extends ReadonlyArray<DeepbookPoolSpec>> = Pools extends readonly []\n\t? readonly []\n\t: readonly PoolCoinRefs<Pools>[];\n\ntype PythRefs<Pyth extends PythOptions | undefined> =\n\tPyth extends PythOptions<infer Package, infer Pusher> ? readonly [Pusher, Package] : readonly [];\n\ntype LocalDependsOn<\n\tPublisher extends AccountMemberAlias,\n\tPackage extends DeepbookPackageMember,\n\tPools extends ReadonlyArray<DeepbookPoolSpec>,\n\tPyth extends PythOptions | undefined,\n> = readonly [\n\ttypeof suiResource,\n\tPublisher,\n\tPackage,\n\t...PythRefs<Pyth>,\n\t...PoolCoinRefTuple<Pools>,\n];\n\nconst poolCoinRefs = <Pools extends ReadonlyArray<DeepbookPoolSpec>>(\n\tpools: Pools,\n): ReadonlyArray<PoolCoinRefs<Pools>> =>\n\tpools.flatMap((pool) => [pool.base.coin, pool.quote.coin]) as unknown as ReadonlyArray<\n\t\tPoolCoinRefs<Pools>\n\t>;\n\nconst pythRefs = <Pyth extends PythOptions | undefined>(pyth: Pyth): PythRefs<Pyth> =>\n\t(pyth === undefined ? [] : [pyth.pusher, pyth.package]) as unknown as PythRefs<Pyth>;\n\nconst localDependsOn = <\n\tPublisher extends AccountMemberAlias,\n\tPackage extends DeepbookPackageMember,\n\tPools extends ReadonlyArray<DeepbookPoolSpec>,\n\tPyth extends PythOptions | undefined,\n>(\n\topts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n): LocalDependsOn<Publisher, Package, Pools, Pyth> =>\n\t[\n\t\tsuiResource,\n\t\topts.publisher,\n\t\topts.package,\n\t\t...pythRefs(opts.pyth),\n\t\t...poolCoinRefs((opts.pools ?? []) as Pools),\n\t] as unknown as LocalDependsOn<Publisher, Package, Pools, Pyth>;\n\nconst requireCapturedId = (\n\tpkg: LocalPackageResolved,\n\tkey: string,\n\tkind: 'registryId' | 'adminCapId',\n): Effect.Effect<string, DeepbookPluginError> => {\n\tconst value = pkg.captured[key];\n\tif (typeof value === 'string' && value.length > 0) {\n\t\treturn Effect.succeed(value);\n\t}\n\treturn Effect.fail(\n\t\tdeepbookPluginError(\n\t\t\t'publish',\n\t\t\t`deepbook local package '${pkg.name}' is missing captured ${kind} '${key}'.`,\n\t\t),\n\t);\n};\n\nconst requirePoolCoinValue = (\n\tcoinValuesByRefId: ReadonlyMap<string, CoinValue>,\n\tpoolName: string,\n\tside: 'base' | 'quote',\n\tcoinRefId: string,\n): Effect.Effect<CoinValue, DeepbookConfigError> => {\n\tconst value = coinValuesByRefId.get(coinRefId);\n\tif (value === undefined) {\n\t\t// Compose-time bug — `dependsOn`/`poolCoinRefs` dropped this coin.\n\t\t// Surface a typed config error naming the missing coin id rather\n\t\t// than letting a double-cast `undefined` slip into the resolved\n\t\t// pool spec. Lands on the typed E channel (not a sync throw, which\n\t\t// inside Effect.gen would become an uncaught DEFECT that\n\t\t// `passthroughOrWrap` could not see); `DeepbookConfigError` is in\n\t\t// `DEEPBOOK_ERROR_TAGS`, so the outer pipeline passes it through\n\t\t// untouched.\n\t\treturn Effect.fail(\n\t\t\tdeepbookConfigError(\n\t\t\t\t'pools',\n\t\t\t\t`deepbook: pool '${poolName}' ${side} coin '${coinRefId}' was not resolved by the dependency tuple.`,\n\t\t\t\t'This is a compose-time bug — ensure the coin member is included in `dependsOn`/`poolCoinRefs`.',\n\t\t\t),\n\t\t);\n\t}\n\treturn Effect.succeed(value);\n};\n\nconst resolvePoolSpecs = (\n\tpools: ReadonlyArray<DeepbookPoolSpec>,\n\tcoinValuesByRefId: ReadonlyMap<string, CoinValue>,\n): Effect.Effect<ReadonlyArray<ResolvedDeepbookPoolSpec>, DeepbookConfigError> =>\n\tEffect.forEach(pools, (pool) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst base = yield* requirePoolCoinValue(\n\t\t\t\tcoinValuesByRefId,\n\t\t\t\tpool.name,\n\t\t\t\t'base',\n\t\t\t\tpool.base.coin.id,\n\t\t\t);\n\t\t\tconst quote = yield* requirePoolCoinValue(\n\t\t\t\tcoinValuesByRefId,\n\t\t\t\tpool.name,\n\t\t\t\t'quote',\n\t\t\t\tpool.quote.coin.id,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tname: pool.name,\n\t\t\t\tbase: pool.base.key,\n\t\t\t\tquote: pool.quote.key,\n\t\t\t\tbaseCoinType: base.fullCoinType,\n\t\t\t\tquoteCoinType: quote.fullCoinType,\n\t\t\t\t...(base.fundingStrategy === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { baseFundingStrategy: base.fundingStrategy }),\n\t\t\t\t...(quote.fundingStrategy === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { quoteFundingStrategy: quote.fundingStrategy }),\n\t\t\t\ttickSize: pool.tickSize,\n\t\t\t\tlotSize: pool.lotSize,\n\t\t\t\tminSize: pool.minSize,\n\t\t\t\twhitelisted: pool.whitelisted ?? true,\n\t\t\t\tstablePool: pool.stablePool ?? false,\n\t\t\t\t...(pool.seed === undefined ? {} : { seed: pool.seed }),\n\t\t\t};\n\t\t}),\n\t);\n\nconst assertUniquePoolNames = (name: string, pools: ReadonlyArray<DeepbookPoolSpec>) => {\n\tconst seen = new Set<string>();\n\tfor (const pool of pools) {\n\t\tif (seen.has(pool.name)) {\n\t\t\tthrow deepbookConfigError(\n\t\t\t\t'pools',\n\t\t\t\t`deepbook({mode:'local', name:'${name}'}) has duplicate pool '${pool.name}'.`,\n\t\t\t\t'Give each local DeepBook pool a unique SDK key.',\n\t\t\t);\n\t\t}\n\t\tseen.add(pool.name);\n\t\tfor (const order of pool.seed?.orders ?? []) {\n\t\t\tif (order.quantity < pool.minSize) {\n\t\t\t\tthrow deepbookConfigError(\n\t\t\t\t\t'pools',\n\t\t\t\t\t`deepbook({mode:'local', name:'${name}'}) seed order for pool '${pool.name}' is below minSize.`,\n\t\t\t\t\t'Use a seed order quantity greater than or equal to the pool minSize.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (order.quantity % pool.lotSize !== 0n) {\n\t\t\t\tthrow deepbookConfigError(\n\t\t\t\t\t'pools',\n\t\t\t\t\t`deepbook({mode:'local', name:'${name}'}) seed order for pool '${pool.name}' is not lot-aligned.`,\n\t\t\t\t\t'Use a seed order quantity divisible by the pool lotSize.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (order.price % pool.tickSize !== 0n) {\n\t\t\t\tthrow deepbookConfigError(\n\t\t\t\t\t'pools',\n\t\t\t\t\t`deepbook({mode:'local', name:'${name}'}) seed order for pool '${pool.name}' is not tick-aligned.`,\n\t\t\t\t\t'Use a seed order price divisible by the pool tickSize.',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst buildOverridePlugin = (opts: DeepbookOverrideOptions) => {\n\tconst name = opts.name ?? DEFAULT_NAME;\n\tif (!opts.packageId || !opts.registryId || !opts.adminCapId) {\n\t\tthrow deepbookConfigError(\n\t\t\t'packageId',\n\t\t\t`deepbook({mode:'override', name:'${name}'}) requires packageId, registryId, and adminCapId.`,\n\t\t\t`Pass explicit deployment ids or use deepbook({mode:'known', network:'testnet'}).`,\n\t\t);\n\t}\n\tconst deepbookResource = makeDeepbookResource(name);\n\tconst snap = makeKnownSnapshotable({ name });\n\n\treturn definePlugin({\n\t\tid: deepbookResource.id,\n\t\tdependsOn: [suiResource] as const,\n\t\trole: 'task',\n\t\tsection: 'service',\n\t\tpluginKey: deepbookPluginKey(name),\n\t\t// Override mode's deployment ids are DECLARED config — bake them as\n\t\t// literals in the committed tree (mirrors `knownPackage`).\n\t\tstaticCodegen: () => [\n\t\t\tmakeDeepbookStaticCodegen({\n\t\t\t\tname,\n\t\t\t\tnetwork: opts.network ?? LOCAL_NETWORK_NAME,\n\t\t\t\tknown: {\n\t\t\t\t\tpackageId: opts.packageId,\n\t\t\t\t\tregistryId: opts.registryId,\n\t\t\t\t},\n\t\t\t}),\n\t\t],\n\t\t// `deps` auto-infers the resolved `[sui]` tuple from the\n\t\t// `[suiResource] as const` dependency. `ctx` arrives via the\n\t\t// `PluginContext` service.\n\t\tstart: () =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst ctx = yield* PluginContext;\n\t\t\t\tconst identity = yield* IdentityContext;\n\t\t\t\tconst network = opts.network ?? identity.network;\n\t\t\t\tconst resolved: DeepbookResolved = {\n\t\t\t\t\tmode: 'override',\n\t\t\t\t\tnetwork,\n\t\t\t\t\tpackageId: opts.packageId,\n\t\t\t\t\tregistryId: opts.registryId,\n\t\t\t\t\tadminCapId: opts.adminCapId,\n\t\t\t\t\tdeepTreasuryId: null,\n\t\t\t\t\tpools: [],\n\t\t\t\t\tpyth: null,\n\t\t\t\t\tmargin: null,\n\t\t\t\t\tserverUrl: null,\n\t\t\t\t\tindexerUrl: null,\n\t\t\t\t\thasSeedLiquidity: false,\n\t\t\t\t\tdeepFundingStrategy: null,\n\t\t\t\t};\n\t\t\t\t// Emit contributions inline: snapshot -> codegen. `resolved` is\n\t\t\t\t// the just-computed value; `snap` is the override-mode\n\t\t\t\t// identity-guard snapshotable in scope. No DEEP funding.\n\t\t\t\tconst bindings: DeepbookBindings = {\n\t\t\t\t\tname,\n\t\t\t\t\tnetwork: resolved.network,\n\t\t\t\t\tpackageId: resolved.packageId,\n\t\t\t\t\tregistryId: resolved.registryId,\n\t\t\t\t\tadminCapId: resolved.adminCapId,\n\t\t\t\t\tdeepTreasuryId: resolved.deepTreasuryId,\n\t\t\t\t\tpools: [],\n\t\t\t\t\tpyth: null,\n\t\t\t\t\tmargin: null,\n\t\t\t\t\tserverUrl: null,\n\t\t\t\t\tindexerUrl: null,\n\t\t\t\t};\n\t\t\t\tctx.snapshotExtra(snap);\n\t\t\t\tctx.codegen(makeDeepbookCodegenable(bindings));\n\t\t\t\treturn resolved;\n\t\t\t}),\n\t});\n};\n\n/** Concrete local options after the explicit-config guard: `publisher`,\n * `package`, and `pools` are guaranteed present. */\ntype ResolvedLocalOptions = DeepbookLocalOptions<\n\tAccountMemberAlias,\n\tDeepbookPackageMember,\n\tReadonlyArray<DeepbookPoolSpec>,\n\tPythOptions | undefined\n> & {\n\treadonly publisher: AccountMemberAlias;\n\treadonly package: DeepbookPackageMember;\n\treadonly pools: ReadonlyArray<DeepbookPoolSpec>;\n};\n\n/** Default local pool synthesized when `pools` is omitted: a single whitelisted\n * `DEEP/SUI` pool. DEEP is the deepbook package's own coin (no extra package to\n * publish), SUI is built-in, so this needs nothing beyond the `package` the\n * caller already passes — and NO seed, so it requires no DEEP minting (i.e. no\n * `deepTreasuryIdKey`) and works for a bare `deepbook({ publisher, package })`.\n * The pool is created with an empty book; pass explicit `pools` with a `seed`\n * (see `examples/deepbook-trader`) for pre-populated liquidity. */\nconst defaultLocalPools = (pkg: DeepbookPackageMember): ReadonlyArray<DeepbookPoolSpec> => [\n\t{\n\t\tname: 'DEEP_SUI',\n\t\tbase: { key: 'DEEP', coin: coinFromPackage(pkg, 'DEEP') },\n\t\tquote: { key: 'SUI', coin: builtinCoin('sui') },\n\t\ttickSize: 1_000_000n,\n\t\tlotSize: 1_000_000n,\n\t\tminSize: 10_000_000n,\n\t\twhitelisted: true,\n\t\tstablePool: false,\n\t},\n];\n\n/** Fail-fast guard for local mode: `publisher` and `package` are REQUIRED — a\n * publish tx needs a signer and the DeepBook Move package must be published\n * (capturing `registry::Registry` + `registry::DeepbookAdminCap`). `pools` is\n * OPTIONAL: omit it for a default unseeded (empty-book) `DEEP/SUI` pool (a\n * minimal usable DeX), pass `[]` for a pool-less deployment, or declare your own. `pyth`\n * stays optional (omit for a feed-less DeX). Missing a required field raises a\n * tagged `DeepbookConfigError` naming what to pass. */\nconst resolveLocalOptions = (\n\topts: DeepbookLocalOptions<\n\t\tAccountMemberAlias,\n\t\tDeepbookPackageMember,\n\t\tReadonlyArray<DeepbookPoolSpec>,\n\t\tPythOptions | undefined\n\t>,\n): ResolvedLocalOptions => {\n\tconst name = opts.name ?? DEFAULT_NAME;\n\tconst missing: string[] = [];\n\tif (!opts.publisher) {\n\t\tmissing.push('publisher');\n\t}\n\tif (!opts.package) {\n\t\tmissing.push('package');\n\t}\n\tif (missing.length > 0) {\n\t\tthrow deepbookConfigError(\n\t\t\tmissing[0] as string,\n\t\t\t`deepbook({mode:'local', name:'${name}'}) requires explicit ${missing.join(', ')}.`,\n\t\t\t`Publish the DeepBook Move package and pass at least { publisher, package } ` +\n\t\t\t\t`(see examples/deepbook-trader). Pools default to an unseeded (empty-book) DEEP/SUI pool.`,\n\t\t);\n\t}\n\t// Default to a single unseeded (empty-book) DEEP/SUI pool when none are declared.\n\tconst pools = opts.pools ?? defaultLocalPools(opts.package);\n\treturn { ...opts, pools } as ResolvedLocalOptions;\n};\n\nconst buildLocalPlugin = <\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\trawOpts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n) => {\n\tconst opts = resolveLocalOptions(\n\t\trawOpts as DeepbookLocalOptions<\n\t\t\tAccountMemberAlias,\n\t\t\tDeepbookPackageMember,\n\t\t\tReadonlyArray<DeepbookPoolSpec>,\n\t\t\tPythOptions | undefined\n\t\t>,\n\t);\n\tconst name = opts.name ?? DEFAULT_NAME;\n\tassertUniquePoolNames(name, opts.pools);\n\n\tconst deepbookResource = makeDeepbookResource(name);\n\t// Runtime `dependsOn` carries the caller's explicit member refs so\n\t// `defineDevstack`'s dependency-closure expander pulls the publisher /\n\t// package / coin / pyth members into the stack. The STATIC type stays keyed\n\t// to the caller's narrow generics so explicit callers keep their exact\n\t// closure (no generic `coin:`/`package:` provider demands).\n\tconst dependsOn = localDependsOn(opts) as unknown as LocalDependsOn<\n\t\tPublisher,\n\t\tPackage,\n\t\tPools,\n\t\tPyth\n\t>;\n\n\treturn definePlugin({\n\t\tid: deepbookResource.id,\n\t\tdependsOn,\n\t\trole: 'task',\n\t\tsection: 'service',\n\t\tpluginKey: deepbookPluginKey(name),\n\t\t// Stack-free codegen: a local deployment's ids / pools / pyth feeds\n\t\t// are LOADED CONFIG DATA -- the committed `deepbook.ts` stub emits\n\t\t// `requireValue(dep, 'deepbook:<name>', '<key>')`, never a baked id.\n\t\tstaticCodegen: () => [makeDeepbookStaticCodegen({ name, network: LOCAL_NETWORK_NAME })],\n\t\t// `deps` auto-infers from the runtime-built `dependsOn`; it\n\t\t// resolves to a heterogeneous tuple the body re-narrows via the\n\t\t// `as unknown as` cast below. `ctx` arrives via the\n\t\t// `PluginContext` service.\n\t\tstart: (deps) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst ctx = yield* PluginContext;\n\t\t\t\tconst identity = yield* IdentityContext;\n\t\t\t\tconst [sui, publisher, deepbookPackage, ...extraValues] = deps as unknown as readonly [\n\t\t\t\t\tResourceValueOf<typeof suiResource>,\n\t\t\t\t\tAccountValue,\n\t\t\t\t\tLocalPackageResolved,\n\t\t\t\t\t...(AccountValue | LocalPackageResolved | CoinValue)[],\n\t\t\t\t];\n\t\t\t\tconst pythValueCount = opts.pyth === undefined ? 0 : 2;\n\t\t\t\tconst pythValues = extraValues.slice(0, pythValueCount);\n\t\t\t\tconst coinValues = extraValues.slice(pythValueCount) as CoinValue[];\n\n\t\t\t\tyield* setCurrentPluginPhase('reading deployment captures');\n\n\t\t\t\tconst registryId = yield* requireCapturedId(\n\t\t\t\t\tdeepbookPackage,\n\t\t\t\t\topts.registryIdKey ?? 'registryId',\n\t\t\t\t\t'registryId',\n\t\t\t\t);\n\t\t\t\tconst adminCapId = yield* requireCapturedId(\n\t\t\t\t\tdeepbookPackage,\n\t\t\t\t\topts.adminCapIdKey ?? 'adminCapId',\n\t\t\t\t\t'adminCapId',\n\t\t\t\t);\n\t\t\t\tconst deepTreasuryId =\n\t\t\t\t\topts.deepTreasuryIdKey === undefined\n\t\t\t\t\t\t? null\n\t\t\t\t\t\t: (deepbookPackage.captured[opts.deepTreasuryIdKey] ?? null);\n\t\t\t\tconst deployment: DeepbookDeployment = {\n\t\t\t\t\tpackageId: deepbookPackage.packageId,\n\t\t\t\t\tregistryId,\n\t\t\t\t\tadminCapId,\n\t\t\t\t\tdeepTreasuryId,\n\t\t\t\t};\n\t\t\t\tconst poolRefs = poolCoinRefs(opts.pools);\n\t\t\t\tconst coinValuesByRefId = new Map<string, CoinValue>();\n\t\t\t\tfor (let i = 0; i < poolRefs.length; i += 1) {\n\t\t\t\t\tconst ref = poolRefs[i];\n\t\t\t\t\tconst value = coinValues[i];\n\t\t\t\t\tif (ref !== undefined && value !== undefined) {\n\t\t\t\t\t\tcoinValuesByRefId.set(ref.id, value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst poolSpecs = yield* resolvePoolSpecs(opts.pools, coinValuesByRefId);\n\t\t\t\tconst artifactPublisher = yield* CacheService;\n\t\t\t\tyield* setCurrentPluginPhase(\n\t\t\t\t\topts.pyth === undefined ? 'creating pools' : 'initializing Pyth feeds',\n\t\t\t\t);\n\t\t\t\tconst pyth =\n\t\t\t\t\topts.pyth === undefined\n\t\t\t\t\t\t? null\n\t\t\t\t\t\t: yield* initLocalPythFeeds(\n\t\t\t\t\t\t\t\tartifactPublisher,\n\t\t\t\t\t\t\t\tsui.sdk,\n\t\t\t\t\t\t\t\tsui.chainId,\n\t\t\t\t\t\t\t\tpythValues[0] as AccountValue,\n\t\t\t\t\t\t\t\t{ packageId: (pythValues[1] as LocalPackageResolved).packageId },\n\t\t\t\t\t\t\t\topts.pyth.feeds,\n\t\t\t\t\t\t\t);\n\t\t\t\tyield* setCurrentPluginPhase('creating pools');\n\t\t\t\tconst poolResult = yield* createDeepbookPools(\n\t\t\t\t\tartifactPublisher,\n\t\t\t\t\tsui.sdk,\n\t\t\t\t\tsui.chainId,\n\t\t\t\t\tpublisher,\n\t\t\t\t\tdeployment,\n\t\t\t\t\tpoolSpecs,\n\t\t\t\t);\n\t\t\t\tyield* setCurrentPluginPhase('seeding pools');\n\t\t\t\tconst seedResults = yield* seedDeepbookPools(\n\t\t\t\t\tartifactPublisher,\n\t\t\t\t\tsui.sdk,\n\t\t\t\t\tsui.chainId,\n\t\t\t\t\tpublisher,\n\t\t\t\t\tdeployment,\n\t\t\t\t\tpoolSpecs,\n\t\t\t\t\tpoolResult.pools,\n\t\t\t\t);\n\t\t\t\tyield* setCurrentPluginPhase(null);\n\n\t\t\t\tconst resolved: DeepbookResolved = {\n\t\t\t\t\tmode: 'local',\n\t\t\t\t\tnetwork: identity.network,\n\t\t\t\t\tpackageId: deployment.packageId,\n\t\t\t\t\tregistryId: deployment.registryId,\n\t\t\t\t\tadminCapId: deployment.adminCapId,\n\t\t\t\t\tdeepTreasuryId,\n\t\t\t\t\tpools: poolResult.pools,\n\t\t\t\t\tpyth,\n\t\t\t\t\tmargin: null,\n\t\t\t\t\tserverUrl: null,\n\t\t\t\t\tindexerUrl: null,\n\t\t\t\t\thasSeedLiquidity: seedResults.length > 0,\n\t\t\t\t\tdeepFundingStrategy: null,\n\t\t\t\t};\n\t\t\t\t// Emit contributions inline: snapshot -> codegen. `resolved` is\n\t\t\t\t// the just-computed value; the snapshotable is the local-mode\n\t\t\t\t// `deepbook/<name>` subtree. No DEEP funding (null in local).\n\t\t\t\tconst snap: SnapshotableDecl = makeLocalSnapshotable({ name });\n\t\t\t\tconst bindings: DeepbookBindings = {\n\t\t\t\t\tname,\n\t\t\t\t\tnetwork: resolved.network,\n\t\t\t\t\tpackageId: resolved.packageId,\n\t\t\t\t\tregistryId: resolved.registryId,\n\t\t\t\t\tadminCapId: resolved.adminCapId,\n\t\t\t\t\tdeepTreasuryId: resolved.deepTreasuryId,\n\t\t\t\t\tpools: resolved.pools.map((p) => ({\n\t\t\t\t\t\tname: p.name,\n\t\t\t\t\t\tpoolId: p.poolId,\n\t\t\t\t\t\tbase: p.base,\n\t\t\t\t\t\tquote: p.quote,\n\t\t\t\t\t\tbaseCoinType: p.baseCoinType,\n\t\t\t\t\t\tquoteCoinType: p.quoteCoinType,\n\t\t\t\t\t})),\n\t\t\t\t\tpyth: resolved.pyth\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tpackageId: resolved.pyth.packageId,\n\t\t\t\t\t\t\t\tstateId: resolved.pyth.stateId,\n\t\t\t\t\t\t\t\twormholeStateId: resolved.pyth.wormholeStateId,\n\t\t\t\t\t\t\t\tfeeds: resolved.pyth.feeds.map((feed) => ({\n\t\t\t\t\t\t\t\t\tsymbol: feed.symbol,\n\t\t\t\t\t\t\t\t\tfeedId: feed.feedId,\n\t\t\t\t\t\t\t\t\tpriceInfoObjectId: feed.priceInfoObjectId,\n\t\t\t\t\t\t\t\t\tprice: feed.price.toString(),\n\t\t\t\t\t\t\t\t\texpo: feed.expo,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: null,\n\t\t\t\t\tmargin: resolved.margin,\n\t\t\t\t\tserverUrl: resolved.serverUrl,\n\t\t\t\t\tindexerUrl: resolved.indexerUrl,\n\t\t\t\t};\n\t\t\t\tctx.snapshotExtra(snap);\n\t\t\t\tctx.codegen(makeDeepbookCodegenable(bindings));\n\t\t\t\treturn resolved;\n\t\t\t}).pipe(\n\t\t\t\t// The body's aggregate E channel includes substrate Effects\n\t\t\t\t// whose error shape is unknown to TS (ArtifactPublisher\n\t\t\t\t// produce bodies, dependency reads). `Effect.catchTags`\n\t\t\t\t// would need a statically-known tagged union; the\n\t\t\t\t// substrate's `passthroughOrWrap` runtime-checks the `_tag`\n\t\t\t\t// against `DEEPBOOK_ERROR_TAGS`, passing typed deepbook\n\t\t\t\t// errors through untouched and wrapping everything else\n\t\t\t\t// under `'publish'` so cascade attribution stays with the\n\t\t\t\t// plugin.\n\t\t\t\tpassthroughOrWrap.for<DeepbookError>()(DEEPBOOK_ERROR_TAGS, (err) =>\n\t\t\t\t\tdeepbookPluginError('publish', `deepbook acquire failed: ${String(err)}`, {\n\t\t\t\t\t\tcause: err,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t),\n\t});\n};\n\nfunction buildLocalPluginPublic<\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec>,\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\topts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n): DeepbookLocalMember<Publisher, Package, Pools, Pyth>;\nfunction buildLocalPluginPublic<\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec>,\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(opts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>) {\n\treturn buildLocalPlugin(opts);\n}\n\n// ---------------------------------------------------------------------------\n// Plugin construction — known\n// ---------------------------------------------------------------------------\n\nconst buildKnownPlugin = (opts: DeepbookKnownOptions) => {\n\tconst name = opts.name ?? DEFAULT_NAME;\n\tconst known = opts.network ? KNOWN_DEEPBOOK_DEPLOYMENTS[opts.network] : null;\n\tconst packageId = opts.packageId ?? known?.packageId;\n\tconst registryId = opts.registryId ?? known?.registryId;\n\tif (!packageId || !registryId) {\n\t\tthrow deepbookConfigError(\n\t\t\t'packageId',\n\t\t\t`deepbook({mode:'known', name:'${name}'}) requires packageId and registryId, or network:'mainnet'|'testnet'.`,\n\t\t\t`Pass explicit ids or use deepbook({mode:'known', network:'testnet'}).`,\n\t\t);\n\t}\n\tconst deepbookResource = makeDeepbookResource(name);\n\tconst snap = makeKnownSnapshotable({ name });\n\n\treturn definePlugin({\n\t\tid: deepbookResource.id,\n\t\tdependsOn: [suiResource] as const,\n\t\trole: 'task',\n\t\tsection: 'service',\n\t\tpluginKey: deepbookPluginKey(name),\n\t\t// Known mode's deployment ids (package / registry / deep-treasury) and\n\t\t// its declared testnet/mainnet Pyth ids are DECLARED config — bake them\n\t\t// as literals in the committed tree (mirrors `knownPackage`).\n\t\tstaticCodegen: () => [\n\t\t\tmakeDeepbookStaticCodegen({\n\t\t\t\tname,\n\t\t\t\tnetwork: opts.network ?? known?.network ?? LOCAL_NETWORK_NAME,\n\t\t\t\tknown: {\n\t\t\t\t\tpackageId,\n\t\t\t\t\tregistryId,\n\t\t\t\t\tdeepTreasuryId: known?.deepTreasuryId ?? null,\n\t\t\t\t\tpyth: known?.pyth\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tpackageId: known.pyth.packageId,\n\t\t\t\t\t\t\t\tstateId: known.pyth.stateId,\n\t\t\t\t\t\t\t\twormholeStateId: known.pyth.wormholeStateId,\n\t\t\t\t\t\t\t\tfeeds: known.pyth.feeds.map((feed) => ({\n\t\t\t\t\t\t\t\t\tsymbol: feed.symbol,\n\t\t\t\t\t\t\t\t\tfeedId: feed.feedId,\n\t\t\t\t\t\t\t\t\tpriceInfoObjectId: feed.priceInfoObjectId,\n\t\t\t\t\t\t\t\t\tprice: feed.price.toString(),\n\t\t\t\t\t\t\t\t\texpo: feed.expo,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: null,\n\t\t\t\t},\n\t\t\t}),\n\t\t],\n\t\t// `deps` auto-infers the resolved `[sui]` tuple from the\n\t\t// `[suiResource] as const` dependency. `ctx` arrives via the\n\t\t// `PluginContext` service.\n\t\tstart: (deps) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst ctx = yield* PluginContext;\n\t\t\t\tconst identity = yield* IdentityContext;\n\t\t\t\tconst [sui] = deps;\n\t\t\t\tconst network = opts.network ?? known?.network ?? identity.network;\n\t\t\t\tconst resolved: DeepbookResolved = {\n\t\t\t\t\tmode: 'known',\n\t\t\t\t\tnetwork,\n\t\t\t\t\tpackageId,\n\t\t\t\t\tregistryId,\n\t\t\t\t\tadminCapId: null,\n\t\t\t\t\tdeepTreasuryId: known?.deepTreasuryId ?? null,\n\t\t\t\t\tpools: [],\n\t\t\t\t\tpyth: known?.pyth ?? null,\n\t\t\t\t\tmargin: null,\n\t\t\t\t\tserverUrl: null,\n\t\t\t\t\tindexerUrl: null,\n\t\t\t\t\thasSeedLiquidity: false,\n\t\t\t\t\t// DEEP funding is a testnet-deepbook concern — gate on the\n\t\t\t\t\t// network name alone. (The old `&& String(chain) === 'sui:testnet'`\n\t\t\t\t\t// conjunct compared a genesis-digest chainId against a network\n\t\t\t\t\t// literal and was dead for every non-literal `chain` value.)\n\t\t\t\t\tdeepFundingStrategy:\n\t\t\t\t\t\topts.network === 'testnet'\n\t\t\t\t\t\t\t? makeDeepbookDeepFundingStrategy({ suiSdk: sui.sdk })\n\t\t\t\t\t\t\t: null,\n\t\t\t\t};\n\t\t\t\t// Emit contributions inline: snapshot -> codegen -> (optional\n\t\t\t\t// DEEP funding strategy). `resolved` is the just-computed value;\n\t\t\t\t// `snap` is the known-mode identity-guard snapshotable in scope.\n\t\t\t\t// The DEEP funding contributor is emitted only when\n\t\t\t\t// `resolved.deepFundingStrategy` is non-null.\n\t\t\t\tconst bindings: DeepbookBindings = {\n\t\t\t\t\tname,\n\t\t\t\t\tnetwork: resolved.network,\n\t\t\t\t\tpackageId: resolved.packageId,\n\t\t\t\t\tregistryId: resolved.registryId,\n\t\t\t\t\tadminCapId: null,\n\t\t\t\t\tdeepTreasuryId: resolved.deepTreasuryId,\n\t\t\t\t\tpools: [],\n\t\t\t\t\tpyth: resolved.pyth\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tpackageId: resolved.pyth.packageId,\n\t\t\t\t\t\t\t\tstateId: resolved.pyth.stateId,\n\t\t\t\t\t\t\t\twormholeStateId: resolved.pyth.wormholeStateId,\n\t\t\t\t\t\t\t\tfeeds: resolved.pyth.feeds.map((feed) => ({\n\t\t\t\t\t\t\t\t\tsymbol: feed.symbol,\n\t\t\t\t\t\t\t\t\tfeedId: feed.feedId,\n\t\t\t\t\t\t\t\t\tpriceInfoObjectId: feed.priceInfoObjectId,\n\t\t\t\t\t\t\t\t\tprice: feed.price.toString(),\n\t\t\t\t\t\t\t\t\texpo: feed.expo,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: null,\n\t\t\t\t\tmargin: null,\n\t\t\t\t\tserverUrl: null,\n\t\t\t\t\tindexerUrl: null,\n\t\t\t\t};\n\t\t\t\tctx.snapshotExtra(snap);\n\t\t\t\tctx.codegen(makeDeepbookCodegenable(bindings));\n\t\t\t\tif (resolved.deepFundingStrategy != null) {\n\t\t\t\t\tctx.provides(makeDeepbookDeepFundingContribution(resolved.deepFundingStrategy));\n\t\t\t\t}\n\t\t\t\treturn resolved;\n\t\t\t}),\n\t});\n};\n\n// ---------------------------------------------------------------------------\n// Default option resolution (env-driven)\n// ---------------------------------------------------------------------------\n\nconst resolveDefaultMode = <\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\topts?: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n): DeepbookOptions<Publisher, Pyth> => {\n\tconst env = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process\n\t\t?.env?.DEVSTACK_NETWORK;\n\tif (env === undefined || env === 'localnet') {\n\t\t// Local DeepBook: default to local mode on localnet. The caller must\n\t\t// supply explicit `{ publisher, package, pools }`; `resolveLocalOptions`\n\t\t// fails fast otherwise (no auto-synthesis).\n\t\treturn { mode: 'local', ...opts } as DeepbookOptions<Publisher, Pyth>;\n\t}\n\t// Non-local default: refuse — known mode requires explicit\n\t// packageId/registryId. The user passes them via\n\t// `deepbookFor(network).known({...})` or `deepbook({mode:'known',...})`.\n\tthrow deepbookConfigError(\n\t\t'mode',\n\t\t`deepbook(): cannot auto-default to known mode on network='${env}'.`,\n\t\t`Use deepbookFor(network).known({packageId, registryId, ...}).`,\n\t);\n};\n\n// ---------------------------------------------------------------------------\n// User-facing factories\n// ---------------------------------------------------------------------------\n\n/** Env-driven factory. Defaults to local mode on localnet when passed local\n * options. Explicit `override` and `known` modes bypass env inference. */\ntype DeepbookLocalMember<\n\tPublisher extends AccountMemberAlias,\n\tPackage extends DeepbookPackageMember,\n\tPools extends ReadonlyArray<DeepbookPoolSpec>,\n\tPyth extends PythOptions | undefined = undefined,\n> = ReturnType<typeof buildLocalPlugin<Publisher, Package, Pools, Pyth>>;\ntype DeepbookOverrideMember = ReturnType<typeof buildOverridePlugin>;\ntype DeepbookKnownMember = ReturnType<typeof buildKnownPlugin>;\n\n// Local DeepBook requires explicit `{ publisher, package, pools }`. There is\n// no zero-arg/synthesized overload — an under-specified call fails fast (see\n// `resolveLocalOptions`).\nexport function deepbookCore<\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\topts: { readonly mode: 'local' } & DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n): DeepbookLocalMember<Publisher, Package, Pools, Pyth>;\nexport function deepbookCore(\n\topts: { readonly mode: 'override' } & DeepbookOverrideOptions,\n): DeepbookOverrideMember;\nexport function deepbookCore(\n\topts: { readonly mode: 'known' } & DeepbookKnownOptions,\n): DeepbookKnownMember;\nexport function deepbookCore<\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\topts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n): DeepbookLocalMember<Publisher, Package, Pools, Pyth>;\nexport function deepbookCore<\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\topts?: DeepbookLocalOptions<Publisher, Package, Pools, Pyth> | DeepbookOptions<Publisher, Pyth>,\n):\n\t| DeepbookLocalMember<Publisher, Package, Pools, Pyth>\n\t| DeepbookOverrideMember\n\t| DeepbookKnownMember {\n\tconst resolved: DeepbookOptions<Publisher, Pyth> =\n\t\topts !== undefined && 'mode' in opts\n\t\t\t? (opts as DeepbookOptions<Publisher, Pyth>)\n\t\t\t: resolveDefaultMode(\n\t\t\t\t\topts as DeepbookLocalOptions<Publisher, Package, Pools, Pyth> | undefined,\n\t\t\t\t);\n\tswitch (resolved.mode) {\n\t\tcase 'local': {\n\t\t\tconst localOpts = resolved as { readonly mode: 'local' } & DeepbookLocalOptions<\n\t\t\t\tPublisher,\n\t\t\t\tPackage,\n\t\t\t\tPools,\n\t\t\t\tPyth\n\t\t\t>;\n\t\t\t// Explicit-config path only; `buildLocalPlugin` -> `resolveLocalOptions`\n\t\t\t// fails fast when `publisher`/`package`/`pools` are missing.\n\t\t\treturn buildLocalPluginPublic(localOpts) as DeepbookLocalMember<\n\t\t\t\tPublisher,\n\t\t\t\tPackage,\n\t\t\t\tPools,\n\t\t\t\tPyth\n\t\t\t>;\n\t\t}\n\t\tcase 'override':\n\t\t\treturn buildOverridePlugin(resolved);\n\t\tcase 'known':\n\t\t\treturn buildKnownPlugin(resolved);\n\t}\n}\n\n/** Mode-narrowed factory namespace.\n *\n * Usage:\n * const local = { mode: 'local', network: 'localnet' } as const;\n * deepbookFor(local).local({publisher, package, pools}) // OK\n * deepbookFor(local).override({packageId, registryId, adminCapId}) // OK\n * deepbookFor(local).known({...}) // OK\n *\n * const fork = { mode: 'fork', network: 'mainnet-fork', upstream: 'mainnet' } as const;\n * deepbookFor(fork).local({...}) // COMPILE ERROR\n * deepbookFor(fork).override({...}) // COMPILE ERROR\n *\n * The fork branch has NO `.local` or `.override` entry — `deepbookFor(forkNetwork).local`\n * is a compile-time refusal. */\nexport const deepbookFor = defineModeNamespace({\n\tlocal: {\n\t\tlocal: <\n\t\t\tconst Publisher extends AccountMemberAlias,\n\t\t\tconst Package extends DeepbookPackageMember,\n\t\t\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\t\t\tconst Pyth extends PythOptions | undefined = undefined,\n\t\t>(\n\t\t\topts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n\t\t) => buildLocalPluginPublic(opts),\n\t\toverride: (opts: DeepbookOverrideOptions) => buildOverridePlugin(opts),\n\t\tknown: (opts: DeepbookKnownOptions) => buildKnownPlugin(opts),\n\t},\n\tlive: {\n\t\tknown: (opts: DeepbookKnownOptions) => buildKnownPlugin(opts),\n\t},\n\tfork: {\n\t\t// `.override` intentionally absent — compile-time refusal.\n\t\tknown: (opts: DeepbookKnownOptions) => buildKnownPlugin(opts),\n\t},\n});\n\nexport { deepbookCore as deepbook };\n\n// ---------------------------------------------------------------------------\n// Re-exports for advanced callers\n// ---------------------------------------------------------------------------\n\nexport {\n\tDEEPBOOK_DEEP_FAUCET_STRATEGY_KEY,\n\tDEEPBOOK_TESTNET_DEEP_COIN_TYPE,\n} from './faucet-strategy.ts';\nexport {\n\ttype DeepbookError,\n\ttype DeepbookPluginError,\n\ttype DeepbookConfigError,\n\ttype DeepbookPhase,\n} from './errors.ts';\nexport type { DeepbookBindings } from './codegen.ts';\nexport type {\n\tAccountMemberAlias,\n\tCoinMemberAlias,\n\tDeepbookPackageMember,\n\tDeepbookPool,\n\tDeepbookPoolCoin,\n\tDeepbookPoolSeedLiquidity,\n\tDeepbookPoolSeedOrder,\n\tDeepbookPoolSpec,\n} from './types.ts';\nexport {\n\tDEEP_PRICE_FEED_ID,\n\tpythPriceFeedId,\n\tSUI_PRICE_FEED_ID,\n\tUSDC_PRICE_FEED_ID,\n} from './types.ts';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgGA,MAAM,wBAA6C,SAClD,SACC,YAAY,MACb;AA8HD,MAAM,eAAe;AAErB,MAAM,6BASF;CACH,SAAS;EACR,SAAS;EACT,WAAW;EACX,YAAY;EACZ,gBAAgB;EAChB,MAAM;GACL,WAAW;GACX,SAAS;GACT,iBAAiB;GACjB,OAAO,CAAC;EACT;CACD;CACA,SAAS;EACR,SAAS;EACT,WAAW;EACX,YAAY;EACZ,gBAAgB;EAChB,MAAM;GACL,WAAW;GACX,SAAS;GACT,iBAAiB;GACjB,OAAO,CAAC;EACT;CACD;AACD;AAwBA,MAAM,gBACL,UAEA,MAAM,SAAS,SAAS,CAAC,KAAK,KAAK,MAAM,KAAK,MAAM,IAAI,CAAC;AAI1D,MAAM,YAAkD,SACtD,SAAS,KAAA,IAAY,CAAC,IAAI,CAAC,KAAK,QAAQ,K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ACtB,MAAM,WACL,SAAS,KAAA,KAAa,UAAU,OAC5B,OACD,mBACA,IACD;CACH,QAAQ,SAAS,MAAjB;EACC,KAAK,SASJ,OAAO,uBAAuBC,QAAS;EAOxC,KAAK,YACJ,OAAO,oBAAoB,QAAQ;EACpC,KAAK,SACJ,OAAO,iBAAiB,QAAQ;CAClC;AACD;;;;;;;;;;;;;;;AAgBA,MAAa,cAAc,oBAAoB;CAC9C,OAAO;EACN,QAMC,SACI,uBAAuB,IAAI;EAChC,WAAW,SAAkC,oBAAoB,IAAI;EACrE,QAAQ,SAA+B,iBAAiB,IAAI;CAC7D;CACA,MAAM,EACL,QAAQ,SAA+B,iBAAiB,IAAI,EAC7D;CACA,MAAM,EAEL,QAAQ,SAA+B,iBAAiB,IAAI,EAC7D;AACD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["coinFromPackage","builtinCoin","localOpts"],"sources":["../../../src/plugins/deepbook/index.ts"],"sourcesContent":["// Deepbook plugin — barrel + factories.\n//\n// Architecture: Deepbook is a task plugin that resolves a managed\n// local deployment, a known deployment, or explicit caller-supplied\n// override ids, then emits bindings.\n//\n// Mode discipline:\n//\n// - `deepbook(opts)` — explicit mode selection.\n// Localnet can default to local when\n// passed local options.\n// - `deepbookFor(network).local` — local-branch managed deployment.\n// - `deepbookFor(network).override` — local-branch override for\n// caller-supplied deployment ids.\n// - `deepbookFor(network).known` — known-deployment branch (live +\n// fork networks; wraps an already-\n// deployed canonical instance).\n//\n// During `start`, the plugin emits (via the typed `ctx.*` verbs):\n//\n// Local mode:\n// 1. `ctx.snapshotExtra` — `deepbook/<name>` subtree.\n// 2. `ctx.codegen` — `deepbook-network` bindings.\n//\n// Override mode:\n// 1. `ctx.snapshotExtra` — identity guard only.\n// 2. `ctx.codegen` — `deepbook-network` bindings.\n//\n// Known mode:\n// 1. `ctx.snapshotExtra` — identity guard only.\n// 2. `ctx.codegen` — `deepbook-network` bindings (mode='known').\n//\n// Resource id: `deepbook/<name>`. Plugin key: `deepbook:<name>`.\n\nimport { Effect } from 'effect';\nimport {\n\tmainnetPackageIds,\n\tmainnetPythConfigs,\n\ttestnetPackageIds,\n\ttestnetPythConfigs,\n} from '@mysten/deepbook-v3';\n\nimport { defineModeNamespace } from '../../api/mode-narrowed-factory.ts';\nimport { definePlugin, resource, type ResourceValueOf } from '../../api/define-plugin.ts';\nimport type { SnapshotableDecl } from '../../contracts/snapshotable.ts';\nimport { PluginContext } from '../../substrate/plugin-ctx.ts';\nimport { CacheService } from '../../substrate/runtime/cache/index.ts';\nimport { setCurrentPluginPhase } from '../../substrate/runtime/current-plugin.ts';\nimport { passthroughOrWrap } from '../../substrate/runtime/passthrough-or-wrap.ts';\nimport { IdentityContext } from '../../substrate/runtime/paths.ts';\nimport { suiResource } from '../sui/index.ts';\nimport type { AccountValue } from '../account/index.ts';\nimport {\n\tbuiltin as builtinCoin,\n\tfromPackage as coinFromPackage,\n\ttype CoinValue,\n} from '../coin/index.ts';\nimport type { LocalPackageResolved } from '../package/index.ts';\n\nimport { deepbookPluginKey } from './plugin-key.ts';\nimport {\n\tDEEPBOOK_ERROR_TAGS,\n\tdeepbookConfigError,\n\tdeepbookPluginError,\n\ttype DeepbookConfigError,\n\ttype DeepbookError,\n\ttype DeepbookPluginError,\n} from './errors.ts';\nimport {\n\tmakeDeepbookCodegenable,\n\tmakeDeepbookStaticCodegen,\n\ttype DeepbookBindings,\n} from './codegen.ts';\nimport { LOCAL_NETWORK_NAME } from '../../api/inference-network.ts';\nimport {\n\tmakeDeepbookDeepFundingContribution,\n\tmakeDeepbookDeepFundingStrategy,\n\ttype DeepbookDeepFundingStrategy,\n} from './faucet-strategy.ts';\nimport { makeKnownSnapshotable, makeLocalSnapshotable } from './snapshot.ts';\nimport {\n\tcreateDeepbookPools,\n\tseedDeepbookPools,\n\ttype DeepbookDeployment,\n\ttype ResolvedDeepbookPoolSpec,\n} from './deploy.ts';\nimport { initLocalPythFeeds } from './pyth/index.ts';\nimport type {\n\tAccountMemberAlias,\n\tDeepbookPackageMember,\n\tDeepbookPool,\n\tDeepbookPoolSpec,\n\tPythHandle,\n\tPythOptions,\n} from './types.ts';\n\n// ---------------------------------------------------------------------------\n// Resource — the resolved value all consumers read\n// ---------------------------------------------------------------------------\n\nexport type DeepbookResourceId<Name extends string> = `deepbook/${Name}`;\n\nconst makeDeepbookResource = <Name extends string>(name: Name) =>\n\tresource<DeepbookResourceId<Name>, DeepbookResolved>(\n\t\t`deepbook/${name}` as DeepbookResourceId<Name>,\n\t);\n\n/** The deepbook resolved value. Mode-asymmetric:\n *\n * - `adminCapId` is `null` for known-deployment mode.\n * - `margin` / `serverUrl` / `indexerUrl` are `null` when the\n * corresponding sub-feature is not enabled.\n * - `hasSeedLiquidity` is `true` when one or more pools placed seed\n * orders at boot (it is NOT a market-maker process state). */\nexport interface DeepbookResolved {\n\treadonly mode: 'local' | 'override' | 'known';\n\treadonly network: string;\n\treadonly packageId: string;\n\treadonly registryId: string;\n\treadonly adminCapId: string | null;\n\treadonly deepTreasuryId: string | null;\n\treadonly pools: ReadonlyArray<DeepbookPool>;\n\treadonly pyth: PythHandle | null;\n\treadonly margin: {\n\t\treadonly packageId: string;\n\t\treadonly registryId: string;\n\t} | null;\n\treadonly serverUrl: string | null;\n\treadonly indexerUrl: string | null;\n\t/** `true` when one or more pools placed seed orders at boot. This reflects\n\t * \"a pool was seeded with liquidity\", NOT a running market-maker process. */\n\treadonly hasSeedLiquidity: boolean;\n\treadonly deepFundingStrategy: DeepbookDeepFundingStrategy | null;\n}\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\nexport interface DeepbookCommonOptions {\n\treadonly name?: string;\n}\n\n/** Override mode wraps an explicitly supplied deployment. It does not\n * publish or manage DeepBook locally. */\nexport interface DeepbookOverrideOptions extends DeepbookCommonOptions {\n\treadonly packageId: string;\n\treadonly registryId: string;\n\treadonly adminCapId: string;\n\treadonly network?: string;\n}\n\n/** Local mode wraps an explicitly supplied local DeepBook package.\n *\n * Explicit-config discipline: `publisher`, `package`, and `pools` are all\n * REQUIRED — the caller publishes the DeepBook Move tree, funds a publisher,\n * and declares the pools. There is no zero-arg auto-synthesis; an\n * under-specified `deepbook({ mode: 'local' })` fails fast with a tagged\n * config error (see the guard in `resolveLocalOptions`). `pyth` stays\n * optional — pass it to seed local mock price feeds, omit it for a\n * feed-less DeX. */\nexport interface DeepbookLocalOptions<\n\tPublisher extends AccountMemberAlias = AccountMemberAlias,\n\tPackage extends DeepbookPackageMember = DeepbookPackageMember,\n\tPools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tPyth extends PythOptions | undefined = undefined,\n> extends DeepbookCommonOptions {\n\t/** Publisher account — Direct Member Ref (locked API decision). Required. */\n\treadonly publisher: Publisher;\n\t/** Published DeepBook package member. The package must capture the\n\t * `registry::Registry` and `registry::DeepbookAdminCap` object ids.\n\t * Required. */\n\treadonly package: Package;\n\t/** Optional local mock-Pyth package + feed setup. Omit for a feed-less\n\t * local DeX. */\n\treadonly pyth?: Pyth;\n\t/** Capture key for the package-created `registry::Registry`. */\n\treadonly registryIdKey?: string;\n\t/** Capture key for the package-created `registry::DeepbookAdminCap`. */\n\treadonly adminCapIdKey?: string;\n\t/** Optional capture key for a DEEP treasury object used by SDK bindings. */\n\treadonly deepTreasuryIdKey?: string;\n\t/** Pools to create after the DeepBook package publishes. OPTIONAL: when\n\t * omitted, a single unseeded (empty-book) `DEEP/SUI` pool is synthesized\n\t * (the DEEP coin comes from `package`, SUI is built-in — no extra package\n\t * needed), so a minimal `deepbook({ mode:'local', publisher, package })`\n\t * boots a usable DeX. Pass `[]` explicitly for a known-empty deployment, or your own\n\t * pools for full control. */\n\treadonly pools?: Pools;\n}\n\nexport type DeepbookKnownNetwork = 'mainnet' | 'testnet';\n\ninterface DeepbookKnownCommonOptions extends DeepbookCommonOptions {\n\t/** Optional network override (defaults to the configured network). */\n\treadonly network?: string;\n}\n\ninterface DeepbookKnownNetworkOptions extends DeepbookKnownCommonOptions {\n\treadonly network: DeepbookKnownNetwork;\n\treadonly packageId?: string;\n\treadonly registryId?: string;\n}\n\ninterface DeepbookKnownExplicitOptions extends DeepbookKnownCommonOptions {\n\treadonly packageId: string;\n\treadonly registryId: string;\n\treadonly network?: DeepbookKnownNetwork;\n}\n\nexport type DeepbookKnownOptions = DeepbookKnownNetworkOptions | DeepbookKnownExplicitOptions;\n\n/** Per-network factory options for `deepbookFor(net).testnet()`/`.mainnet()`.\n * The `network` is injected by the namespace method, so the caller only\n * supplies optional per-field overrides (`packageId`/`registryId`/`name`).\n * Plugin-INTERNAL — deliberately NOT re-exported from `src/index.ts`. */\ntype DeepbookKnownByNetworkOptions = Omit<DeepbookKnownNetworkOptions, 'network'>;\n\nexport type DeepbookOptions<\n\tPublisher extends AccountMemberAlias = AccountMemberAlias,\n\tPyth extends PythOptions | undefined = PythOptions | undefined,\n> =\n\t| ({\n\t\t\treadonly mode: 'local';\n\t } & DeepbookLocalOptions<\n\t\t\tPublisher,\n\t\t\tDeepbookPackageMember,\n\t\t\tReadonlyArray<DeepbookPoolSpec>,\n\t\t\tPyth\n\t >)\n\t| ({ readonly mode: 'override' } & DeepbookOverrideOptions)\n\t| ({ readonly mode: 'known' } & DeepbookKnownOptions);\n\n// ---------------------------------------------------------------------------\n// Plugin construction — override\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_NAME = 'deepbook';\n\n// Known-deployment ids are DERIVED from the `@mysten/deepbook-v3` SDK\n// constants rather than hand-copied, so they can never drift from the SDK\n// (a stale mainnet packageId is exactly what this guards against). Future\n// SDK bumps flow through automatically. DeepBook ships testnet + mainnet\n// only — there is no devnet deployment.\n//\n// We surface only the core ids the plugin needs. The SDK's MARGIN_*/\n// LIQUIDATION_* package ids and its coin/pool maps are intentionally NOT\n// re-exported here (out of scope); consumers that need them import from\n// `@mysten/deepbook-v3` directly.\nconst KNOWN_DEEPBOOK_DEPLOYMENTS: Record<\n\tDeepbookKnownNetwork,\n\t{\n\t\treadonly network: string;\n\t\treadonly packageId: string;\n\t\treadonly registryId: string;\n\t\treadonly deepTreasuryId: string;\n\t\treadonly pyth: PythHandle;\n\t}\n> = {\n\ttestnet: {\n\t\tnetwork: 'testnet',\n\t\tpackageId: testnetPackageIds.DEEPBOOK_PACKAGE_ID,\n\t\tregistryId: testnetPackageIds.REGISTRY_ID,\n\t\tdeepTreasuryId: testnetPackageIds.DEEP_TREASURY_ID,\n\t\tpyth: {\n\t\t\tpackageId: null,\n\t\t\tstateId: testnetPythConfigs.pythStateId,\n\t\t\twormholeStateId: testnetPythConfigs.wormholeStateId,\n\t\t\tfeeds: [],\n\t\t},\n\t},\n\tmainnet: {\n\t\tnetwork: 'mainnet',\n\t\tpackageId: mainnetPackageIds.DEEPBOOK_PACKAGE_ID,\n\t\tregistryId: mainnetPackageIds.REGISTRY_ID,\n\t\tdeepTreasuryId: mainnetPackageIds.DEEP_TREASURY_ID,\n\t\tpyth: {\n\t\t\tpackageId: null,\n\t\t\tstateId: mainnetPythConfigs.pythStateId,\n\t\t\twormholeStateId: mainnetPythConfigs.wormholeStateId,\n\t\t\tfeeds: [],\n\t\t},\n\t},\n};\n\ntype PoolCoinRefs<Pools extends ReadonlyArray<DeepbookPoolSpec>> =\n\tPools[number] extends DeepbookPoolSpec<infer Base, infer Quote> ? Base | Quote : never;\ntype PoolCoinRefTuple<Pools extends ReadonlyArray<DeepbookPoolSpec>> = Pools extends readonly []\n\t? readonly []\n\t: readonly PoolCoinRefs<Pools>[];\n\ntype PythRefs<Pyth extends PythOptions | undefined> =\n\tPyth extends PythOptions<infer Package, infer Pusher> ? readonly [Pusher, Package] : readonly [];\n\ntype LocalDependsOn<\n\tPublisher extends AccountMemberAlias,\n\tPackage extends DeepbookPackageMember,\n\tPools extends ReadonlyArray<DeepbookPoolSpec>,\n\tPyth extends PythOptions | undefined,\n> = readonly [\n\ttypeof suiResource,\n\tPublisher,\n\tPackage,\n\t...PythRefs<Pyth>,\n\t...PoolCoinRefTuple<Pools>,\n];\n\nconst poolCoinRefs = <Pools extends ReadonlyArray<DeepbookPoolSpec>>(\n\tpools: Pools,\n): ReadonlyArray<PoolCoinRefs<Pools>> =>\n\tpools.flatMap((pool) => [pool.base.coin, pool.quote.coin]) as unknown as ReadonlyArray<\n\t\tPoolCoinRefs<Pools>\n\t>;\n\nconst pythRefs = <Pyth extends PythOptions | undefined>(pyth: Pyth): PythRefs<Pyth> =>\n\t(pyth === undefined ? [] : [pyth.pusher, pyth.package]) as unknown as PythRefs<Pyth>;\n\nconst localDependsOn = <\n\tPublisher extends AccountMemberAlias,\n\tPackage extends DeepbookPackageMember,\n\tPools extends ReadonlyArray<DeepbookPoolSpec>,\n\tPyth extends PythOptions | undefined,\n>(\n\topts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n): LocalDependsOn<Publisher, Package, Pools, Pyth> =>\n\t[\n\t\tsuiResource,\n\t\topts.publisher,\n\t\topts.package,\n\t\t...pythRefs(opts.pyth),\n\t\t...poolCoinRefs((opts.pools ?? []) as Pools),\n\t] as unknown as LocalDependsOn<Publisher, Package, Pools, Pyth>;\n\nconst requireCapturedId = (\n\tpkg: LocalPackageResolved,\n\tkey: string,\n\tkind: 'registryId' | 'adminCapId',\n): Effect.Effect<string, DeepbookPluginError> => {\n\tconst value = pkg.captured[key];\n\tif (typeof value === 'string' && value.length > 0) {\n\t\treturn Effect.succeed(value);\n\t}\n\treturn Effect.fail(\n\t\tdeepbookPluginError(\n\t\t\t'publish',\n\t\t\t`deepbook local package '${pkg.name}' is missing captured ${kind} '${key}'.`,\n\t\t),\n\t);\n};\n\nconst requirePoolCoinValue = (\n\tcoinValuesByRefId: ReadonlyMap<string, CoinValue>,\n\tpoolName: string,\n\tside: 'base' | 'quote',\n\tcoinRefId: string,\n): Effect.Effect<CoinValue, DeepbookConfigError> => {\n\tconst value = coinValuesByRefId.get(coinRefId);\n\tif (value === undefined) {\n\t\t// Compose-time bug — `dependsOn`/`poolCoinRefs` dropped this coin.\n\t\t// Surface a typed config error naming the missing coin id rather\n\t\t// than letting a double-cast `undefined` slip into the resolved\n\t\t// pool spec. Lands on the typed E channel (not a sync throw, which\n\t\t// inside Effect.gen would become an uncaught DEFECT that\n\t\t// `passthroughOrWrap` could not see); `DeepbookConfigError` is in\n\t\t// `DEEPBOOK_ERROR_TAGS`, so the outer pipeline passes it through\n\t\t// untouched.\n\t\treturn Effect.fail(\n\t\t\tdeepbookConfigError(\n\t\t\t\t'pools',\n\t\t\t\t`deepbook: pool '${poolName}' ${side} coin '${coinRefId}' was not resolved by the dependency tuple.`,\n\t\t\t\t'This is a compose-time bug — ensure the coin member is included in `dependsOn`/`poolCoinRefs`.',\n\t\t\t),\n\t\t);\n\t}\n\treturn Effect.succeed(value);\n};\n\nconst resolvePoolSpecs = (\n\tpools: ReadonlyArray<DeepbookPoolSpec>,\n\tcoinValuesByRefId: ReadonlyMap<string, CoinValue>,\n): Effect.Effect<ReadonlyArray<ResolvedDeepbookPoolSpec>, DeepbookConfigError> =>\n\tEffect.forEach(pools, (pool) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst base = yield* requirePoolCoinValue(\n\t\t\t\tcoinValuesByRefId,\n\t\t\t\tpool.name,\n\t\t\t\t'base',\n\t\t\t\tpool.base.coin.id,\n\t\t\t);\n\t\t\tconst quote = yield* requirePoolCoinValue(\n\t\t\t\tcoinValuesByRefId,\n\t\t\t\tpool.name,\n\t\t\t\t'quote',\n\t\t\t\tpool.quote.coin.id,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tname: pool.name,\n\t\t\t\tbase: pool.base.key,\n\t\t\t\tquote: pool.quote.key,\n\t\t\t\tbaseCoinType: base.fullCoinType,\n\t\t\t\tquoteCoinType: quote.fullCoinType,\n\t\t\t\t...(base.fundingStrategy === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { baseFundingStrategy: base.fundingStrategy }),\n\t\t\t\t...(quote.fundingStrategy === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { quoteFundingStrategy: quote.fundingStrategy }),\n\t\t\t\ttickSize: pool.tickSize,\n\t\t\t\tlotSize: pool.lotSize,\n\t\t\t\tminSize: pool.minSize,\n\t\t\t\twhitelisted: pool.whitelisted ?? true,\n\t\t\t\tstablePool: pool.stablePool ?? false,\n\t\t\t\t...(pool.seed === undefined ? {} : { seed: pool.seed }),\n\t\t\t};\n\t\t}),\n\t);\n\nconst assertUniquePoolNames = (name: string, pools: ReadonlyArray<DeepbookPoolSpec>) => {\n\tconst seen = new Set<string>();\n\tfor (const pool of pools) {\n\t\tif (seen.has(pool.name)) {\n\t\t\tthrow deepbookConfigError(\n\t\t\t\t'pools',\n\t\t\t\t`deepbook({mode:'local', name:'${name}'}) has duplicate pool '${pool.name}'.`,\n\t\t\t\t'Give each local DeepBook pool a unique SDK key.',\n\t\t\t);\n\t\t}\n\t\tseen.add(pool.name);\n\t\tfor (const order of pool.seed?.orders ?? []) {\n\t\t\tif (order.quantity < pool.minSize) {\n\t\t\t\tthrow deepbookConfigError(\n\t\t\t\t\t'pools',\n\t\t\t\t\t`deepbook({mode:'local', name:'${name}'}) seed order for pool '${pool.name}' is below minSize.`,\n\t\t\t\t\t'Use a seed order quantity greater than or equal to the pool minSize.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (order.quantity % pool.lotSize !== 0n) {\n\t\t\t\tthrow deepbookConfigError(\n\t\t\t\t\t'pools',\n\t\t\t\t\t`deepbook({mode:'local', name:'${name}'}) seed order for pool '${pool.name}' is not lot-aligned.`,\n\t\t\t\t\t'Use a seed order quantity divisible by the pool lotSize.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (order.price % pool.tickSize !== 0n) {\n\t\t\t\tthrow deepbookConfigError(\n\t\t\t\t\t'pools',\n\t\t\t\t\t`deepbook({mode:'local', name:'${name}'}) seed order for pool '${pool.name}' is not tick-aligned.`,\n\t\t\t\t\t'Use a seed order price divisible by the pool tickSize.',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst buildOverridePlugin = (opts: DeepbookOverrideOptions) => {\n\tconst name = opts.name ?? DEFAULT_NAME;\n\tif (!opts.packageId || !opts.registryId || !opts.adminCapId) {\n\t\tthrow deepbookConfigError(\n\t\t\t'packageId',\n\t\t\t`deepbook({mode:'override', name:'${name}'}) requires packageId, registryId, and adminCapId.`,\n\t\t\t`Pass explicit deployment ids or use deepbook({mode:'known', network:'testnet'}).`,\n\t\t);\n\t}\n\tconst deepbookResource = makeDeepbookResource(name);\n\tconst snap = makeKnownSnapshotable({ name });\n\n\treturn definePlugin({\n\t\tid: deepbookResource.id,\n\t\tdependsOn: [suiResource] as const,\n\t\trole: 'task',\n\t\tsection: 'service',\n\t\tpluginKey: deepbookPluginKey(name),\n\t\t// Override mode's deployment ids are DECLARED config — bake them as\n\t\t// literals in the committed tree (mirrors `knownPackage`).\n\t\tstaticCodegen: () => [\n\t\t\tmakeDeepbookStaticCodegen({\n\t\t\t\tname,\n\t\t\t\tnetwork: opts.network ?? LOCAL_NETWORK_NAME,\n\t\t\t\tknown: {\n\t\t\t\t\tpackageId: opts.packageId,\n\t\t\t\t\tregistryId: opts.registryId,\n\t\t\t\t},\n\t\t\t}),\n\t\t],\n\t\t// `deps` auto-infers the resolved `[sui]` tuple from the\n\t\t// `[suiResource] as const` dependency. `ctx` arrives via the\n\t\t// `PluginContext` service.\n\t\tstart: () =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst ctx = yield* PluginContext;\n\t\t\t\tconst identity = yield* IdentityContext;\n\t\t\t\tconst network = opts.network ?? identity.network;\n\t\t\t\tconst resolved: DeepbookResolved = {\n\t\t\t\t\tmode: 'override',\n\t\t\t\t\tnetwork,\n\t\t\t\t\tpackageId: opts.packageId,\n\t\t\t\t\tregistryId: opts.registryId,\n\t\t\t\t\tadminCapId: opts.adminCapId,\n\t\t\t\t\tdeepTreasuryId: null,\n\t\t\t\t\tpools: [],\n\t\t\t\t\tpyth: null,\n\t\t\t\t\tmargin: null,\n\t\t\t\t\tserverUrl: null,\n\t\t\t\t\tindexerUrl: null,\n\t\t\t\t\thasSeedLiquidity: false,\n\t\t\t\t\tdeepFundingStrategy: null,\n\t\t\t\t};\n\t\t\t\t// Emit contributions inline: snapshot -> codegen. `resolved` is\n\t\t\t\t// the just-computed value; `snap` is the override-mode\n\t\t\t\t// identity-guard snapshotable in scope. No DEEP funding.\n\t\t\t\tconst bindings: DeepbookBindings = {\n\t\t\t\t\tname,\n\t\t\t\t\tnetwork: resolved.network,\n\t\t\t\t\tpackageId: resolved.packageId,\n\t\t\t\t\tregistryId: resolved.registryId,\n\t\t\t\t\tadminCapId: resolved.adminCapId,\n\t\t\t\t\tdeepTreasuryId: resolved.deepTreasuryId,\n\t\t\t\t\tpools: [],\n\t\t\t\t\tpyth: null,\n\t\t\t\t\tmargin: null,\n\t\t\t\t\tserverUrl: null,\n\t\t\t\t\tindexerUrl: null,\n\t\t\t\t};\n\t\t\t\tctx.snapshotExtra(snap);\n\t\t\t\tctx.codegen(makeDeepbookCodegenable(bindings));\n\t\t\t\treturn resolved;\n\t\t\t}),\n\t});\n};\n\n/** Concrete local options after the explicit-config guard: `publisher`,\n * `package`, and `pools` are guaranteed present. */\ntype ResolvedLocalOptions = DeepbookLocalOptions<\n\tAccountMemberAlias,\n\tDeepbookPackageMember,\n\tReadonlyArray<DeepbookPoolSpec>,\n\tPythOptions | undefined\n> & {\n\treadonly publisher: AccountMemberAlias;\n\treadonly package: DeepbookPackageMember;\n\treadonly pools: ReadonlyArray<DeepbookPoolSpec>;\n};\n\n/** Default local pool synthesized when `pools` is omitted: a single whitelisted\n * `DEEP/SUI` pool. DEEP is the deepbook package's own coin (no extra package to\n * publish), SUI is built-in, so this needs nothing beyond the `package` the\n * caller already passes — and NO seed, so it requires no DEEP minting (i.e. no\n * `deepTreasuryIdKey`) and works for a bare `deepbook({ publisher, package })`.\n * The pool is created with an empty book; pass explicit `pools` with a `seed`\n * (see `examples/deepbook-trader`) for pre-populated liquidity. */\nconst defaultLocalPools = (pkg: DeepbookPackageMember): ReadonlyArray<DeepbookPoolSpec> => [\n\t{\n\t\tname: 'DEEP_SUI',\n\t\tbase: { key: 'DEEP', coin: coinFromPackage(pkg, 'DEEP') },\n\t\tquote: { key: 'SUI', coin: builtinCoin('sui') },\n\t\ttickSize: 1_000_000n,\n\t\tlotSize: 1_000_000n,\n\t\tminSize: 10_000_000n,\n\t\twhitelisted: true,\n\t\tstablePool: false,\n\t},\n];\n\n/** Fail-fast guard for local mode: `publisher` and `package` are REQUIRED — a\n * publish tx needs a signer and the DeepBook Move package must be published\n * (capturing `registry::Registry` + `registry::DeepbookAdminCap`). `pools` is\n * OPTIONAL: omit it for a default unseeded (empty-book) `DEEP/SUI` pool (a\n * minimal usable DeX), pass `[]` for a pool-less deployment, or declare your own. `pyth`\n * stays optional (omit for a feed-less DeX). Missing a required field raises a\n * tagged `DeepbookConfigError` naming what to pass. */\nconst resolveLocalOptions = (\n\topts: DeepbookLocalOptions<\n\t\tAccountMemberAlias,\n\t\tDeepbookPackageMember,\n\t\tReadonlyArray<DeepbookPoolSpec>,\n\t\tPythOptions | undefined\n\t>,\n): ResolvedLocalOptions => {\n\tconst name = opts.name ?? DEFAULT_NAME;\n\tconst missing: string[] = [];\n\tif (!opts.publisher) {\n\t\tmissing.push('publisher');\n\t}\n\tif (!opts.package) {\n\t\tmissing.push('package');\n\t}\n\tif (missing.length > 0) {\n\t\tthrow deepbookConfigError(\n\t\t\tmissing[0] as string,\n\t\t\t`deepbook({mode:'local', name:'${name}'}) requires explicit ${missing.join(', ')}.`,\n\t\t\t`Publish the DeepBook Move package and pass at least { publisher, package } ` +\n\t\t\t\t`(see examples/deepbook-trader). Pools default to an unseeded (empty-book) DEEP/SUI pool.`,\n\t\t);\n\t}\n\t// Default to a single unseeded (empty-book) DEEP/SUI pool when none are declared.\n\tconst pools = opts.pools ?? defaultLocalPools(opts.package);\n\treturn { ...opts, pools } as ResolvedLocalOptions;\n};\n\nconst buildLocalPlugin = <\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\trawOpts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n) => {\n\tconst opts = resolveLocalOptions(\n\t\trawOpts as DeepbookLocalOptions<\n\t\t\tAccountMemberAlias,\n\t\t\tDeepbookPackageMember,\n\t\t\tReadonlyArray<DeepbookPoolSpec>,\n\t\t\tPythOptions | undefined\n\t\t>,\n\t);\n\tconst name = opts.name ?? DEFAULT_NAME;\n\tassertUniquePoolNames(name, opts.pools);\n\n\tconst deepbookResource = makeDeepbookResource(name);\n\t// Runtime `dependsOn` carries the caller's explicit member refs so\n\t// `defineDevstack`'s dependency-closure expander pulls the publisher /\n\t// package / coin / pyth members into the stack. The STATIC type stays keyed\n\t// to the caller's narrow generics so explicit callers keep their exact\n\t// closure (no generic `coin:`/`package:` provider demands).\n\tconst dependsOn = localDependsOn(opts) as unknown as LocalDependsOn<\n\t\tPublisher,\n\t\tPackage,\n\t\tPools,\n\t\tPyth\n\t>;\n\n\treturn definePlugin({\n\t\tid: deepbookResource.id,\n\t\tdependsOn,\n\t\trole: 'task',\n\t\tsection: 'service',\n\t\tpluginKey: deepbookPluginKey(name),\n\t\t// Stack-free codegen: a local deployment's ids / pools / pyth feeds\n\t\t// are LOADED CONFIG DATA -- the committed `deepbook.ts` stub emits\n\t\t// `requireValue(dep, 'deepbook:<name>', '<key>')`, never a baked id.\n\t\tstaticCodegen: () => [makeDeepbookStaticCodegen({ name, network: LOCAL_NETWORK_NAME })],\n\t\t// `deps` auto-infers from the runtime-built `dependsOn`; it\n\t\t// resolves to a heterogeneous tuple the body re-narrows via the\n\t\t// `as unknown as` cast below. `ctx` arrives via the\n\t\t// `PluginContext` service.\n\t\tstart: (deps) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst ctx = yield* PluginContext;\n\t\t\t\tconst identity = yield* IdentityContext;\n\t\t\t\tconst [sui, publisher, deepbookPackage, ...extraValues] = deps as unknown as readonly [\n\t\t\t\t\tResourceValueOf<typeof suiResource>,\n\t\t\t\t\tAccountValue,\n\t\t\t\t\tLocalPackageResolved,\n\t\t\t\t\t...(AccountValue | LocalPackageResolved | CoinValue)[],\n\t\t\t\t];\n\t\t\t\tconst pythValueCount = opts.pyth === undefined ? 0 : 2;\n\t\t\t\tconst pythValues = extraValues.slice(0, pythValueCount);\n\t\t\t\tconst coinValues = extraValues.slice(pythValueCount) as CoinValue[];\n\n\t\t\t\tyield* setCurrentPluginPhase('reading deployment captures');\n\n\t\t\t\tconst registryId = yield* requireCapturedId(\n\t\t\t\t\tdeepbookPackage,\n\t\t\t\t\topts.registryIdKey ?? 'registryId',\n\t\t\t\t\t'registryId',\n\t\t\t\t);\n\t\t\t\tconst adminCapId = yield* requireCapturedId(\n\t\t\t\t\tdeepbookPackage,\n\t\t\t\t\topts.adminCapIdKey ?? 'adminCapId',\n\t\t\t\t\t'adminCapId',\n\t\t\t\t);\n\t\t\t\tconst deepTreasuryId =\n\t\t\t\t\topts.deepTreasuryIdKey === undefined\n\t\t\t\t\t\t? null\n\t\t\t\t\t\t: (deepbookPackage.captured[opts.deepTreasuryIdKey] ?? null);\n\t\t\t\tconst deployment: DeepbookDeployment = {\n\t\t\t\t\tpackageId: deepbookPackage.packageId,\n\t\t\t\t\tregistryId,\n\t\t\t\t\tadminCapId,\n\t\t\t\t\tdeepTreasuryId,\n\t\t\t\t};\n\t\t\t\tconst poolRefs = poolCoinRefs(opts.pools);\n\t\t\t\tconst coinValuesByRefId = new Map<string, CoinValue>();\n\t\t\t\tfor (let i = 0; i < poolRefs.length; i += 1) {\n\t\t\t\t\tconst ref = poolRefs[i];\n\t\t\t\t\tconst value = coinValues[i];\n\t\t\t\t\tif (ref !== undefined && value !== undefined) {\n\t\t\t\t\t\tcoinValuesByRefId.set(ref.id, value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst poolSpecs = yield* resolvePoolSpecs(opts.pools, coinValuesByRefId);\n\t\t\t\tconst artifactPublisher = yield* CacheService;\n\t\t\t\tyield* setCurrentPluginPhase(\n\t\t\t\t\topts.pyth === undefined ? 'creating pools' : 'initializing Pyth feeds',\n\t\t\t\t);\n\t\t\t\tconst pyth =\n\t\t\t\t\topts.pyth === undefined\n\t\t\t\t\t\t? null\n\t\t\t\t\t\t: yield* initLocalPythFeeds(\n\t\t\t\t\t\t\t\tartifactPublisher,\n\t\t\t\t\t\t\t\tsui.sdk,\n\t\t\t\t\t\t\t\tsui.chainId,\n\t\t\t\t\t\t\t\tpythValues[0] as AccountValue,\n\t\t\t\t\t\t\t\t{ packageId: (pythValues[1] as LocalPackageResolved).packageId },\n\t\t\t\t\t\t\t\topts.pyth.feeds,\n\t\t\t\t\t\t\t);\n\t\t\t\tyield* setCurrentPluginPhase('creating pools');\n\t\t\t\tconst poolResult = yield* createDeepbookPools(\n\t\t\t\t\tartifactPublisher,\n\t\t\t\t\tsui.sdk,\n\t\t\t\t\tsui.chainId,\n\t\t\t\t\tpublisher,\n\t\t\t\t\tdeployment,\n\t\t\t\t\tpoolSpecs,\n\t\t\t\t);\n\t\t\t\tyield* setCurrentPluginPhase('seeding pools');\n\t\t\t\tconst seedResults = yield* seedDeepbookPools(\n\t\t\t\t\tartifactPublisher,\n\t\t\t\t\tsui.sdk,\n\t\t\t\t\tsui.chainId,\n\t\t\t\t\tpublisher,\n\t\t\t\t\tdeployment,\n\t\t\t\t\tpoolSpecs,\n\t\t\t\t\tpoolResult.pools,\n\t\t\t\t);\n\t\t\t\tyield* setCurrentPluginPhase(null);\n\n\t\t\t\tconst resolved: DeepbookResolved = {\n\t\t\t\t\tmode: 'local',\n\t\t\t\t\tnetwork: identity.network,\n\t\t\t\t\tpackageId: deployment.packageId,\n\t\t\t\t\tregistryId: deployment.registryId,\n\t\t\t\t\tadminCapId: deployment.adminCapId,\n\t\t\t\t\tdeepTreasuryId,\n\t\t\t\t\tpools: poolResult.pools,\n\t\t\t\t\tpyth,\n\t\t\t\t\tmargin: null,\n\t\t\t\t\tserverUrl: null,\n\t\t\t\t\tindexerUrl: null,\n\t\t\t\t\thasSeedLiquidity: seedResults.length > 0,\n\t\t\t\t\tdeepFundingStrategy: null,\n\t\t\t\t};\n\t\t\t\t// Emit contributions inline: snapshot -> codegen. `resolved` is\n\t\t\t\t// the just-computed value; the snapshotable is the local-mode\n\t\t\t\t// `deepbook/<name>` subtree. No DEEP funding (null in local).\n\t\t\t\tconst snap: SnapshotableDecl = makeLocalSnapshotable({ name });\n\t\t\t\tconst bindings: DeepbookBindings = {\n\t\t\t\t\tname,\n\t\t\t\t\tnetwork: resolved.network,\n\t\t\t\t\tpackageId: resolved.packageId,\n\t\t\t\t\tregistryId: resolved.registryId,\n\t\t\t\t\tadminCapId: resolved.adminCapId,\n\t\t\t\t\tdeepTreasuryId: resolved.deepTreasuryId,\n\t\t\t\t\tpools: resolved.pools.map((p) => ({\n\t\t\t\t\t\tname: p.name,\n\t\t\t\t\t\tpoolId: p.poolId,\n\t\t\t\t\t\tbase: p.base,\n\t\t\t\t\t\tquote: p.quote,\n\t\t\t\t\t\tbaseCoinType: p.baseCoinType,\n\t\t\t\t\t\tquoteCoinType: p.quoteCoinType,\n\t\t\t\t\t})),\n\t\t\t\t\tpyth: resolved.pyth\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tpackageId: resolved.pyth.packageId,\n\t\t\t\t\t\t\t\tstateId: resolved.pyth.stateId,\n\t\t\t\t\t\t\t\twormholeStateId: resolved.pyth.wormholeStateId,\n\t\t\t\t\t\t\t\tfeeds: resolved.pyth.feeds.map((feed) => ({\n\t\t\t\t\t\t\t\t\tsymbol: feed.symbol,\n\t\t\t\t\t\t\t\t\tfeedId: feed.feedId,\n\t\t\t\t\t\t\t\t\tpriceInfoObjectId: feed.priceInfoObjectId,\n\t\t\t\t\t\t\t\t\tprice: feed.price.toString(),\n\t\t\t\t\t\t\t\t\texpo: feed.expo,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: null,\n\t\t\t\t\tmargin: resolved.margin,\n\t\t\t\t\tserverUrl: resolved.serverUrl,\n\t\t\t\t\tindexerUrl: resolved.indexerUrl,\n\t\t\t\t};\n\t\t\t\tctx.snapshotExtra(snap);\n\t\t\t\tctx.codegen(makeDeepbookCodegenable(bindings));\n\t\t\t\treturn resolved;\n\t\t\t}).pipe(\n\t\t\t\t// The body's aggregate E channel includes substrate Effects\n\t\t\t\t// whose error shape is unknown to TS (ArtifactPublisher\n\t\t\t\t// produce bodies, dependency reads). `Effect.catchTags`\n\t\t\t\t// would need a statically-known tagged union; the\n\t\t\t\t// substrate's `passthroughOrWrap` runtime-checks the `_tag`\n\t\t\t\t// against `DEEPBOOK_ERROR_TAGS`, passing typed deepbook\n\t\t\t\t// errors through untouched and wrapping everything else\n\t\t\t\t// under `'publish'` so cascade attribution stays with the\n\t\t\t\t// plugin.\n\t\t\t\tpassthroughOrWrap.for<DeepbookError>()(DEEPBOOK_ERROR_TAGS, (err) =>\n\t\t\t\t\tdeepbookPluginError('publish', `deepbook acquire failed: ${String(err)}`, {\n\t\t\t\t\t\tcause: err,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t),\n\t});\n};\n\nfunction buildLocalPluginPublic<\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec>,\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\topts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n): DeepbookLocalMember<Publisher, Package, Pools, Pyth>;\nfunction buildLocalPluginPublic<\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec>,\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(opts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>) {\n\treturn buildLocalPlugin(opts);\n}\n\n// ---------------------------------------------------------------------------\n// Plugin construction — known\n// ---------------------------------------------------------------------------\n\nconst buildKnownPlugin = (opts: DeepbookKnownOptions) => {\n\tconst name = opts.name ?? DEFAULT_NAME;\n\tconst known = opts.network ? KNOWN_DEEPBOOK_DEPLOYMENTS[opts.network] : null;\n\tconst packageId = opts.packageId ?? known?.packageId;\n\tconst registryId = opts.registryId ?? known?.registryId;\n\tif (!packageId || !registryId) {\n\t\tthrow deepbookConfigError(\n\t\t\t'packageId',\n\t\t\t`deepbook({mode:'known', name:'${name}'}) requires packageId and registryId, or network:'mainnet'|'testnet'.`,\n\t\t\t`Pass explicit ids or use deepbook({mode:'known', network:'testnet'}).`,\n\t\t);\n\t}\n\tconst deepbookResource = makeDeepbookResource(name);\n\tconst snap = makeKnownSnapshotable({ name });\n\n\treturn definePlugin({\n\t\tid: deepbookResource.id,\n\t\tdependsOn: [suiResource] as const,\n\t\trole: 'task',\n\t\tsection: 'service',\n\t\tpluginKey: deepbookPluginKey(name),\n\t\t// Known mode's deployment ids (package / registry / deep-treasury) and\n\t\t// its declared testnet/mainnet Pyth ids are DECLARED config — bake them\n\t\t// as literals in the committed tree (mirrors `knownPackage`).\n\t\tstaticCodegen: () => [\n\t\t\tmakeDeepbookStaticCodegen({\n\t\t\t\tname,\n\t\t\t\tnetwork: opts.network ?? known?.network ?? LOCAL_NETWORK_NAME,\n\t\t\t\tknown: {\n\t\t\t\t\tpackageId,\n\t\t\t\t\tregistryId,\n\t\t\t\t\tdeepTreasuryId: known?.deepTreasuryId ?? null,\n\t\t\t\t\tpyth: known?.pyth\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tpackageId: known.pyth.packageId,\n\t\t\t\t\t\t\t\tstateId: known.pyth.stateId,\n\t\t\t\t\t\t\t\twormholeStateId: known.pyth.wormholeStateId,\n\t\t\t\t\t\t\t\tfeeds: known.pyth.feeds.map((feed) => ({\n\t\t\t\t\t\t\t\t\tsymbol: feed.symbol,\n\t\t\t\t\t\t\t\t\tfeedId: feed.feedId,\n\t\t\t\t\t\t\t\t\tpriceInfoObjectId: feed.priceInfoObjectId,\n\t\t\t\t\t\t\t\t\tprice: feed.price.toString(),\n\t\t\t\t\t\t\t\t\texpo: feed.expo,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: null,\n\t\t\t\t},\n\t\t\t}),\n\t\t],\n\t\t// `deps` auto-infers the resolved `[sui]` tuple from the\n\t\t// `[suiResource] as const` dependency. `ctx` arrives via the\n\t\t// `PluginContext` service.\n\t\tstart: (deps) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst ctx = yield* PluginContext;\n\t\t\t\tconst identity = yield* IdentityContext;\n\t\t\t\tconst [sui] = deps;\n\t\t\t\tconst network = opts.network ?? known?.network ?? identity.network;\n\t\t\t\tconst resolved: DeepbookResolved = {\n\t\t\t\t\tmode: 'known',\n\t\t\t\t\tnetwork,\n\t\t\t\t\tpackageId,\n\t\t\t\t\tregistryId,\n\t\t\t\t\tadminCapId: null,\n\t\t\t\t\tdeepTreasuryId: known?.deepTreasuryId ?? null,\n\t\t\t\t\tpools: [],\n\t\t\t\t\tpyth: known?.pyth ?? null,\n\t\t\t\t\tmargin: null,\n\t\t\t\t\tserverUrl: null,\n\t\t\t\t\tindexerUrl: null,\n\t\t\t\t\thasSeedLiquidity: false,\n\t\t\t\t\t// DEEP funding is a testnet-deepbook concern — gate on the\n\t\t\t\t\t// network name alone. (The old `&& String(chain) === 'sui:testnet'`\n\t\t\t\t\t// conjunct compared a genesis-digest chainId against a network\n\t\t\t\t\t// literal and was dead for every non-literal `chain` value.)\n\t\t\t\t\tdeepFundingStrategy:\n\t\t\t\t\t\topts.network === 'testnet'\n\t\t\t\t\t\t\t? makeDeepbookDeepFundingStrategy({ suiSdk: sui.sdk })\n\t\t\t\t\t\t\t: null,\n\t\t\t\t};\n\t\t\t\t// Emit contributions inline: snapshot -> codegen -> (optional\n\t\t\t\t// DEEP funding strategy). `resolved` is the just-computed value;\n\t\t\t\t// `snap` is the known-mode identity-guard snapshotable in scope.\n\t\t\t\t// The DEEP funding contributor is emitted only when\n\t\t\t\t// `resolved.deepFundingStrategy` is non-null.\n\t\t\t\tconst bindings: DeepbookBindings = {\n\t\t\t\t\tname,\n\t\t\t\t\tnetwork: resolved.network,\n\t\t\t\t\tpackageId: resolved.packageId,\n\t\t\t\t\tregistryId: resolved.registryId,\n\t\t\t\t\tadminCapId: null,\n\t\t\t\t\tdeepTreasuryId: resolved.deepTreasuryId,\n\t\t\t\t\tpools: [],\n\t\t\t\t\tpyth: resolved.pyth\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tpackageId: resolved.pyth.packageId,\n\t\t\t\t\t\t\t\tstateId: resolved.pyth.stateId,\n\t\t\t\t\t\t\t\twormholeStateId: resolved.pyth.wormholeStateId,\n\t\t\t\t\t\t\t\tfeeds: resolved.pyth.feeds.map((feed) => ({\n\t\t\t\t\t\t\t\t\tsymbol: feed.symbol,\n\t\t\t\t\t\t\t\t\tfeedId: feed.feedId,\n\t\t\t\t\t\t\t\t\tpriceInfoObjectId: feed.priceInfoObjectId,\n\t\t\t\t\t\t\t\t\tprice: feed.price.toString(),\n\t\t\t\t\t\t\t\t\texpo: feed.expo,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: null,\n\t\t\t\t\tmargin: null,\n\t\t\t\t\tserverUrl: null,\n\t\t\t\t\tindexerUrl: null,\n\t\t\t\t};\n\t\t\t\tctx.snapshotExtra(snap);\n\t\t\t\tctx.codegen(makeDeepbookCodegenable(bindings));\n\t\t\t\tif (resolved.deepFundingStrategy != null) {\n\t\t\t\t\tctx.provides(makeDeepbookDeepFundingContribution(resolved.deepFundingStrategy));\n\t\t\t\t}\n\t\t\t\treturn resolved;\n\t\t\t}),\n\t});\n};\n\n// ---------------------------------------------------------------------------\n// Default option resolution (env-driven)\n// ---------------------------------------------------------------------------\n\nconst resolveDefaultMode = <\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\topts?: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n): DeepbookOptions<Publisher, Pyth> => {\n\tconst env = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process\n\t\t?.env?.DEVSTACK_NETWORK;\n\tif (env === undefined || env === 'localnet') {\n\t\t// Local DeepBook: default to local mode on localnet. The caller must\n\t\t// supply explicit `{ publisher, package, pools }`; `resolveLocalOptions`\n\t\t// fails fast otherwise (no auto-synthesis).\n\t\treturn { mode: 'local', ...opts } as DeepbookOptions<Publisher, Pyth>;\n\t}\n\t// Non-local default: refuse — known mode requires explicit\n\t// packageId/registryId. The user passes them via\n\t// `deepbookFor(network).known({...})` or `deepbook({mode:'known',...})`.\n\tthrow deepbookConfigError(\n\t\t'mode',\n\t\t`deepbook(): cannot auto-default to known mode on network='${env}'.`,\n\t\t`Use deepbookFor(network).known({packageId, registryId, ...}).`,\n\t);\n};\n\n// ---------------------------------------------------------------------------\n// User-facing factories\n// ---------------------------------------------------------------------------\n\n/** Env-driven factory. Defaults to local mode on localnet when passed local\n * options. Explicit `override` and `known` modes bypass env inference. */\ntype DeepbookLocalMember<\n\tPublisher extends AccountMemberAlias,\n\tPackage extends DeepbookPackageMember,\n\tPools extends ReadonlyArray<DeepbookPoolSpec>,\n\tPyth extends PythOptions | undefined = undefined,\n> = ReturnType<typeof buildLocalPlugin<Publisher, Package, Pools, Pyth>>;\ntype DeepbookOverrideMember = ReturnType<typeof buildOverridePlugin>;\ntype DeepbookKnownMember = ReturnType<typeof buildKnownPlugin>;\n\n// Local DeepBook requires explicit `{ publisher, package, pools }`. There is\n// no zero-arg/synthesized overload — an under-specified call fails fast (see\n// `resolveLocalOptions`).\nexport function deepbookCore<\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\topts: { readonly mode: 'local' } & DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n): DeepbookLocalMember<Publisher, Package, Pools, Pyth>;\nexport function deepbookCore(\n\topts: { readonly mode: 'override' } & DeepbookOverrideOptions,\n): DeepbookOverrideMember;\nexport function deepbookCore(\n\topts: { readonly mode: 'known' } & DeepbookKnownOptions,\n): DeepbookKnownMember;\nexport function deepbookCore<\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\topts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n): DeepbookLocalMember<Publisher, Package, Pools, Pyth>;\nexport function deepbookCore<\n\tconst Publisher extends AccountMemberAlias,\n\tconst Package extends DeepbookPackageMember,\n\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\tconst Pyth extends PythOptions | undefined = undefined,\n>(\n\topts?: DeepbookLocalOptions<Publisher, Package, Pools, Pyth> | DeepbookOptions<Publisher, Pyth>,\n):\n\t| DeepbookLocalMember<Publisher, Package, Pools, Pyth>\n\t| DeepbookOverrideMember\n\t| DeepbookKnownMember {\n\tconst resolved: DeepbookOptions<Publisher, Pyth> =\n\t\topts !== undefined && 'mode' in opts\n\t\t\t? (opts as DeepbookOptions<Publisher, Pyth>)\n\t\t\t: resolveDefaultMode(\n\t\t\t\t\topts as DeepbookLocalOptions<Publisher, Package, Pools, Pyth> | undefined,\n\t\t\t\t);\n\tswitch (resolved.mode) {\n\t\tcase 'local': {\n\t\t\tconst localOpts = resolved as { readonly mode: 'local' } & DeepbookLocalOptions<\n\t\t\t\tPublisher,\n\t\t\t\tPackage,\n\t\t\t\tPools,\n\t\t\t\tPyth\n\t\t\t>;\n\t\t\t// Explicit-config path only; `buildLocalPlugin` -> `resolveLocalOptions`\n\t\t\t// fails fast when `publisher`/`package`/`pools` are missing.\n\t\t\treturn buildLocalPluginPublic(localOpts) as DeepbookLocalMember<\n\t\t\t\tPublisher,\n\t\t\t\tPackage,\n\t\t\t\tPools,\n\t\t\t\tPyth\n\t\t\t>;\n\t\t}\n\t\tcase 'override':\n\t\t\treturn buildOverridePlugin(resolved);\n\t\tcase 'known':\n\t\t\treturn buildKnownPlugin(resolved);\n\t}\n}\n\n/** Mode-narrowed factory namespace.\n *\n * Usage:\n * const local = { mode: 'local', network: 'localnet' } as const;\n * deepbookFor(local).local({publisher, package, pools}) // OK\n * deepbookFor(local).override({packageId, registryId, adminCapId}) // OK\n * deepbookFor(local).testnet() // OK (known testnet)\n * deepbookFor(local).known({packageId, registryId}) // OK (raw-id override)\n *\n * const live = { mode: 'live', chainId: 'sui:testnet' } as const;\n * deepbookFor(live).mainnet() // OK (known mainnet)\n *\n * const fork = { mode: 'fork', network: 'mainnet-fork', upstream: 'mainnet' } as const;\n * deepbookFor(fork).local({...}) // COMPILE ERROR\n * deepbookFor(fork).override({...}) // COMPILE ERROR\n *\n * Per-network methods (`.testnet`/`.mainnet`) inject the network into\n * `buildKnownPlugin`; `.known(...)` is now the raw-id explicit-override form\n * only (`DeepbookKnownExplicitOptions`) — the `network`-in-`.known()` path was\n * HARD CUT. The fork branch has NO `.local` or `.override` entry —\n * `deepbookFor(forkNetwork).local` is a compile-time refusal. */\nexport const deepbookFor = defineModeNamespace({\n\tlocal: {\n\t\tlocal: <\n\t\t\tconst Publisher extends AccountMemberAlias,\n\t\t\tconst Package extends DeepbookPackageMember,\n\t\t\tconst Pools extends ReadonlyArray<DeepbookPoolSpec> = readonly [],\n\t\t\tconst Pyth extends PythOptions | undefined = undefined,\n\t\t>(\n\t\t\topts: DeepbookLocalOptions<Publisher, Package, Pools, Pyth>,\n\t\t) => buildLocalPluginPublic(opts),\n\t\toverride: (opts: DeepbookOverrideOptions) => buildOverridePlugin(opts),\n\t\tknown: (opts: DeepbookKnownExplicitOptions) => buildKnownPlugin(opts),\n\t\ttestnet: (opts: DeepbookKnownByNetworkOptions = {}) =>\n\t\t\tbuildKnownPlugin({ network: 'testnet', ...opts }),\n\t\tmainnet: (opts: DeepbookKnownByNetworkOptions = {}) =>\n\t\t\tbuildKnownPlugin({ network: 'mainnet', ...opts }),\n\t},\n\tlive: {\n\t\tknown: (opts: DeepbookKnownExplicitOptions) => buildKnownPlugin(opts),\n\t\ttestnet: (opts: DeepbookKnownByNetworkOptions = {}) =>\n\t\t\tbuildKnownPlugin({ network: 'testnet', ...opts }),\n\t\tmainnet: (opts: DeepbookKnownByNetworkOptions = {}) =>\n\t\t\tbuildKnownPlugin({ network: 'mainnet', ...opts }),\n\t},\n\tfork: {\n\t\t// `.override` intentionally absent — compile-time refusal.\n\t\tknown: (opts: DeepbookKnownExplicitOptions) => buildKnownPlugin(opts),\n\t\ttestnet: (opts: DeepbookKnownByNetworkOptions = {}) =>\n\t\t\tbuildKnownPlugin({ network: 'testnet', ...opts }),\n\t\tmainnet: (opts: DeepbookKnownByNetworkOptions = {}) =>\n\t\t\tbuildKnownPlugin({ network: 'mainnet', ...opts }),\n\t},\n});\n\nexport { deepbookCore as deepbook };\n\n// ---------------------------------------------------------------------------\n// Re-exports for advanced callers\n// ---------------------------------------------------------------------------\n\nexport {\n\tDEEPBOOK_DEEP_FAUCET_STRATEGY_KEY,\n\tDEEPBOOK_TESTNET_DEEP_COIN_TYPE,\n} from './faucet-strategy.ts';\nexport {\n\ttype DeepbookError,\n\ttype DeepbookPluginError,\n\ttype DeepbookConfigError,\n\ttype DeepbookPhase,\n} from './errors.ts';\nexport type { DeepbookBindings } from './codegen.ts';\nexport type {\n\tAccountMemberAlias,\n\tCoinMemberAlias,\n\tDeepbookPackageMember,\n\tDeepbookPool,\n\tDeepbookPoolCoin,\n\tDeepbookPoolSeedLiquidity,\n\tDeepbookPoolSeedOrder,\n\tDeepbookPoolSpec,\n} from './types.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AU,OAAsC,CAAC,MAChD,iBAAiB;GAAE,SAAS;GAAW,GAAG;EAAK,CAAC;CAClD;CACA,MAAM;EACL,QAAQ,SAAuC,iBAAiB,IAAI;EACpE,UAAU,OAAsC,CAAC,MAChD,iBAAiB;GAAE,SAAS;GAAW,GAAG;EAAK,CAAC;EACjD,UAAU,OAAsC,CAAC,MAChD,iBAAiB;GAAE,SAAS;GAAW,GAAG;EAAK,CAAC;CAClD;CACA,MAAM;EAEL,QAAQ,SAAuC,iBAAiB,IAAI;EACpE,UAAU,OAAsC,CAAC,MAChD,iBAAiB;GAAE,SAAS;GAAW,GAAG;EAAK,CAAC;EACjD,UAAU,OAAsC,CAAC,MAChD,iBAAiB;GAAE,SAAS;GAAW,GAAG;EAAK,CAAC;CAClD;AACD,CAAC"}
|
|
@@ -7,6 +7,11 @@ interface SealBindings {
|
|
|
7
7
|
readonly objectId: string;
|
|
8
8
|
readonly keyServerUrl: string;
|
|
9
9
|
readonly serverConfigs: ReadonlyArray<SealKeyServerEntry>;
|
|
10
|
+
/** Whether the SDK should verify the key servers (true on live /
|
|
11
|
+
* fork-known, false on local-keygen). Declared config — known at
|
|
12
|
+
* factory time, emitted as a plain boolean literal (never a
|
|
13
|
+
* `requireValue`, since it's not a secret). */
|
|
14
|
+
readonly verifyKeyServers: boolean;
|
|
10
15
|
readonly mode: 'local-keygen' | 'live' | 'fork-known';
|
|
11
16
|
}
|
|
12
17
|
//#endregion
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { keyedBucketSpec, liveBucketCodegen, staticBucketCodegen } from "../../contracts/config-bindings.mjs";
|
|
2
2
|
//#region src/plugins/seal/codegen.ts
|
|
3
|
+
/** Static-codegen TS type for the `serverConfigs` field — mirrors
|
|
4
|
+
* `SealKeyServerEntry` (the structural literal so the committed `seal.ts`
|
|
5
|
+
* carries the concrete type with NO emitted import). The `apiKey?` slot is
|
|
6
|
+
* kept in the TYPE so a consumer can inject the secret at runtime, but devstack
|
|
7
|
+
* never emits a `apiKey` VALUE (see `stripApiKey`). */
|
|
8
|
+
const SERVER_CONFIGS_TS_TYPE = "ReadonlyArray<{ readonly objectId: string; readonly weight: number; readonly apiKeyName?: string; readonly apiKey?: string; readonly aggregatorUrl?: string }>";
|
|
9
|
+
/** Defense-in-depth: drop any `apiKey` from an emitted `serverConfigs` array.
|
|
10
|
+
* devstack NEVER carries the secret committee apiKey value — both the committed
|
|
11
|
+
* `seal.ts` and the browser-injected `deployment.json` (the `values` channel)
|
|
12
|
+
* are world-readable. `validateLiveInputs` already refuses to accept an apiKey,
|
|
13
|
+
* so this is belt-and-suspenders at the codegen boundary. The app injects the
|
|
14
|
+
* apiKey into `serverConfigs` at runtime, keyed by the emitted non-secret
|
|
15
|
+
* `apiKeyName`. */
|
|
16
|
+
const stripApiKey = (serverConfigs) => serverConfigs.map((entry) => {
|
|
17
|
+
const rest = { ...entry };
|
|
18
|
+
delete rest.apiKey;
|
|
19
|
+
return rest;
|
|
20
|
+
});
|
|
3
21
|
/** Build the seal instance's config-binding spec for `name`. `name` / `mode`
|
|
4
22
|
* are structural literals. For a `local-keygen` instance the object id / URL
|
|
5
23
|
* are dynamically-deployed (`requireValue(dep, …)`) and `serverConfigs` is a runtime
|
|
@@ -31,7 +49,12 @@ const sealBucketSpec = (structural) => {
|
|
|
31
49
|
{
|
|
32
50
|
key: "serverConfigs",
|
|
33
51
|
variant: "literal",
|
|
34
|
-
value: known.serverConfigs
|
|
52
|
+
value: stripApiKey(known.serverConfigs)
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
key: "verifyKeyServers",
|
|
56
|
+
variant: "literal",
|
|
57
|
+
value: known.verifyKeyServers
|
|
35
58
|
}
|
|
36
59
|
] : [
|
|
37
60
|
{
|
|
@@ -59,8 +82,14 @@ const sealBucketSpec = (structural) => {
|
|
|
59
82
|
{
|
|
60
83
|
key: "serverConfigs",
|
|
61
84
|
variant: "resolved",
|
|
62
|
-
tsType:
|
|
63
|
-
live: (s) => s.serverConfigs
|
|
85
|
+
tsType: SERVER_CONFIGS_TS_TYPE,
|
|
86
|
+
live: (s) => stripApiKey(s.serverConfigs)
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
key: "verifyKeyServers",
|
|
90
|
+
variant: "resolved",
|
|
91
|
+
tsType: "boolean",
|
|
92
|
+
live: (s) => s.verifyKeyServers
|
|
64
93
|
}
|
|
65
94
|
];
|
|
66
95
|
return keyedBucketSpec({
|
|
@@ -70,13 +99,27 @@ const sealBucketSpec = (structural) => {
|
|
|
70
99
|
fields
|
|
71
100
|
});
|
|
72
101
|
};
|
|
73
|
-
/** Build the LIVE Codegenable contribution for a seal instance.
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
102
|
+
/** Build the LIVE Codegenable contribution for a seal instance.
|
|
103
|
+
*
|
|
104
|
+
* Live / fork-known deployments resolve their ids at factory time, so they
|
|
105
|
+
* are DECLARED config — pass `known` so they bake as literals (the SAME branch
|
|
106
|
+
* the static codegen uses). This keeps the two derivations consistent AND
|
|
107
|
+
* keeps the known `serverConfigs` OUT of the world-readable `values` channel
|
|
108
|
+
* entirely (literals don't ride `values`). Only `local-keygen`'s
|
|
109
|
+
* dynamically-deployed ids flow through the resolved/`values` channel. */
|
|
110
|
+
const makeSealCodegenable = (bindings) => {
|
|
111
|
+
const known = bindings.mode === "local-keygen" ? void 0 : {
|
|
112
|
+
objectId: bindings.objectId,
|
|
113
|
+
keyServerUrl: bindings.keyServerUrl,
|
|
114
|
+
serverConfigs: bindings.serverConfigs,
|
|
115
|
+
verifyKeyServers: bindings.verifyKeyServers
|
|
116
|
+
};
|
|
117
|
+
return liveBucketCodegen(sealBucketSpec({
|
|
118
|
+
name: bindings.name,
|
|
119
|
+
mode: bindings.mode,
|
|
120
|
+
known
|
|
121
|
+
}), bindings);
|
|
122
|
+
};
|
|
80
123
|
/** Build the STATIC (stack-free) Codegenable contribution for a seal
|
|
81
124
|
* instance. Emits `requireValue(dep, 'seal:<name>', '<key>')` for the runtime
|
|
82
125
|
* fields; the committed `seal.ts` carries no baked object id / endpoint URL. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.mjs","names":[],"sources":["../../../src/plugins/seal/codegen.ts"],"sourcesContent":["// Seal plugin — Codegenable contribution, via the UNIFIED config-binding\n// declaration.\n//\n// The seal plugin contributes ONE codegen shape — the `seal-key-server`\n// config the user-facing bindings consume to construct a `SealClient`.\n//\n// ONE declaration, TWO derivations (see `contracts/config-bindings.ts`). Every\n// seal instance folds into a single `generated/seal.ts` exporting\n// `export const seal = { <name>: SealBindings, ... }` (sibling-keyed bucket):\n// - LIVE (boot): bakes the resolved key-server object id / URL / configs\n// AND feeds the generic deployment `values` channel.\n// - STATIC (committed tree): emits `requireValue(dep, 'seal:<name>', '<key>')`\n// so the committed `seal.ts` carries NO baked object id / endpoint URL.\n//\n// STRUCTURAL fields (`name`, `mode`) stay literals; the object id, key-server\n// URL, and `serverConfigs` committee (an array blob) are RUNTIME (loaded\n// config data), resolved at app build/dev time.\n\nimport type { CodegenableDecl } from '../../contracts/codegenable.ts';\nimport {\n\tkeyedBucketSpec,\n\tliveBucketCodegen,\n\tstaticBucketCodegen,\n\ttype BucketField,\n\ttype SiblingBucketSpec,\n} from '../../contracts/config-bindings.ts';\nimport type { JsonValue } from '../../orchestrators/codegen/deployment.ts';\nimport type { SealKeyServerEntry } from './registry-publish.ts';\n\n/** Codegen-emitted shape for seal. */\nexport interface SealBindings {\n\treadonly name: string;\n\treadonly objectId: string;\n\treadonly keyServerUrl: string;\n\treadonly serverConfigs: ReadonlyArray<SealKeyServerEntry>;\n\treadonly mode: 'local-keygen' | 'live' | 'fork-known';\n}\n\n/** User-declared known seal ids, available at factory time. The `live` and\n * `fork-known` modes resolve their `{objectId, keyServerUrl, serverConfigs}`\n * tuple at factory time (DECLARED config), so the committed `seal.ts` bakes\n * them as LITERALS. Absent for `local-keygen` (dev-deployed) whose key-server\n * ids/URL are dynamic. */\nexport interface SealKnownIds {\n\treadonly objectId: string;\n\treadonly keyServerUrl: string;\n\treadonly serverConfigs: ReadonlyArray<SealKeyServerEntry>;\n}\n\n/** Static-config shape a seal instance knows BEFORE acquire — the\n * structural names the stack-free `staticCodegen` hook needs. When `known`\n * is present (live / fork-known), its declared ids are baked as literals;\n * otherwise (local-keygen) every id resolves at app build/dev time. */\nexport interface SealStaticConfig {\n\treadonly name: string;\n\treadonly mode: SealBindings['mode'];\n\treadonly known?: SealKnownIds;\n}\n\ntype SealLiveState = SealBindings;\n\n/** Build the seal instance's config-binding spec for `name`. `name` / `mode`\n * are structural literals. For a `local-keygen` instance the object id / URL\n * are dynamically-deployed (`requireValue(dep, …)`) and `serverConfigs` is a runtime\n * committee blob; for a `live` / `fork-known` instance these are DECLARED\n * config, baked as literals. */\nconst sealBucketSpec = (structural: SealStaticConfig): SiblingBucketSpec<SealLiveState> => {\n\tconst known = structural.known;\n\tconst fields: ReadonlyArray<BucketField<SealLiveState>> =\n\t\tknown !== undefined\n\t\t\t? [\n\t\t\t\t\t{ key: 'name', variant: 'literal', value: structural.name },\n\t\t\t\t\t{ key: 'mode', variant: 'literal', value: structural.mode },\n\t\t\t\t\t{ key: 'objectId', variant: 'literal', value: known.objectId },\n\t\t\t\t\t{ key: 'keyServerUrl', variant: 'literal', value: known.keyServerUrl },\n\t\t\t\t\t{\n\t\t\t\t\t\tkey: 'serverConfigs',\n\t\t\t\t\t\tvariant: 'literal',\n\t\t\t\t\t\tvalue: known.serverConfigs
|
|
1
|
+
{"version":3,"file":"codegen.mjs","names":[],"sources":["../../../src/plugins/seal/codegen.ts"],"sourcesContent":["// Seal plugin — Codegenable contribution, via the UNIFIED config-binding\n// declaration.\n//\n// The seal plugin contributes ONE codegen shape — the `seal-key-server`\n// config the user-facing bindings consume to construct a `SealClient`.\n//\n// ONE declaration, TWO derivations (see `contracts/config-bindings.ts`). Every\n// seal instance folds into a single `generated/seal.ts` exporting\n// `export const seal = { <name>: SealBindings, ... }` (sibling-keyed bucket):\n// - LIVE (boot): bakes the resolved key-server object id / URL / configs\n// AND feeds the generic deployment `values` channel.\n// - STATIC (committed tree): emits `requireValue(dep, 'seal:<name>', '<key>')`\n// so the committed `seal.ts` carries NO baked object id / endpoint URL.\n//\n// STRUCTURAL fields (`name`, `mode`) stay literals; the object id, key-server\n// URL, and `serverConfigs` committee (an array blob) are RUNTIME (loaded\n// config data), resolved at app build/dev time.\n\nimport type { CodegenableDecl } from '../../contracts/codegenable.ts';\nimport {\n\tkeyedBucketSpec,\n\tliveBucketCodegen,\n\tstaticBucketCodegen,\n\ttype BucketField,\n\ttype SiblingBucketSpec,\n} from '../../contracts/config-bindings.ts';\nimport type { JsonValue } from '../../orchestrators/codegen/deployment.ts';\nimport type { SealKeyServerEntry } from './registry-publish.ts';\n\n/** Static-codegen TS type for the `serverConfigs` field — mirrors\n * `SealKeyServerEntry` (the structural literal so the committed `seal.ts`\n * carries the concrete type with NO emitted import). The `apiKey?` slot is\n * kept in the TYPE so a consumer can inject the secret at runtime, but devstack\n * never emits a `apiKey` VALUE (see `stripApiKey`). */\nconst SERVER_CONFIGS_TS_TYPE =\n\t'ReadonlyArray<{ readonly objectId: string; readonly weight: number; readonly apiKeyName?: string; readonly apiKey?: string; readonly aggregatorUrl?: string }>';\n\n/** Defense-in-depth: drop any `apiKey` from an emitted `serverConfigs` array.\n * devstack NEVER carries the secret committee apiKey value — both the committed\n * `seal.ts` and the browser-injected `deployment.json` (the `values` channel)\n * are world-readable. `validateLiveInputs` already refuses to accept an apiKey,\n * so this is belt-and-suspenders at the codegen boundary. The app injects the\n * apiKey into `serverConfigs` at runtime, keyed by the emitted non-secret\n * `apiKeyName`. */\nconst stripApiKey = (serverConfigs: ReadonlyArray<SealKeyServerEntry>): JsonValue =>\n\tserverConfigs.map((entry) => {\n\t\tconst rest: Record<string, unknown> = { ...entry };\n\t\tdelete rest.apiKey;\n\t\treturn rest;\n\t}) as unknown as JsonValue;\n\n/** Codegen-emitted shape for seal. */\nexport interface SealBindings {\n\treadonly name: string;\n\treadonly objectId: string;\n\treadonly keyServerUrl: string;\n\treadonly serverConfigs: ReadonlyArray<SealKeyServerEntry>;\n\t/** Whether the SDK should verify the key servers (true on live /\n\t * fork-known, false on local-keygen). Declared config — known at\n\t * factory time, emitted as a plain boolean literal (never a\n\t * `requireValue`, since it's not a secret). */\n\treadonly verifyKeyServers: boolean;\n\treadonly mode: 'local-keygen' | 'live' | 'fork-known';\n}\n\n/** User-declared known seal ids, available at factory time. The `live` and\n * `fork-known` modes resolve their `{objectId, keyServerUrl, serverConfigs}`\n * tuple at factory time (DECLARED config), so the committed `seal.ts` bakes\n * them as LITERALS. Absent for `local-keygen` (dev-deployed) whose key-server\n * ids/URL are dynamic. */\nexport interface SealKnownIds {\n\treadonly objectId: string;\n\treadonly keyServerUrl: string;\n\treadonly serverConfigs: ReadonlyArray<SealKeyServerEntry>;\n\treadonly verifyKeyServers: boolean;\n}\n\n/** Static-config shape a seal instance knows BEFORE acquire — the\n * structural names the stack-free `staticCodegen` hook needs. When `known`\n * is present (live / fork-known), its declared ids are baked as literals;\n * otherwise (local-keygen) every id resolves at app build/dev time. */\nexport interface SealStaticConfig {\n\treadonly name: string;\n\treadonly mode: SealBindings['mode'];\n\treadonly known?: SealKnownIds;\n}\n\ntype SealLiveState = SealBindings;\n\n/** Build the seal instance's config-binding spec for `name`. `name` / `mode`\n * are structural literals. For a `local-keygen` instance the object id / URL\n * are dynamically-deployed (`requireValue(dep, …)`) and `serverConfigs` is a runtime\n * committee blob; for a `live` / `fork-known` instance these are DECLARED\n * config, baked as literals. */\nconst sealBucketSpec = (structural: SealStaticConfig): SiblingBucketSpec<SealLiveState> => {\n\tconst known = structural.known;\n\tconst fields: ReadonlyArray<BucketField<SealLiveState>> =\n\t\tknown !== undefined\n\t\t\t? [\n\t\t\t\t\t{ key: 'name', variant: 'literal', value: structural.name },\n\t\t\t\t\t{ key: 'mode', variant: 'literal', value: structural.mode },\n\t\t\t\t\t{ key: 'objectId', variant: 'literal', value: known.objectId },\n\t\t\t\t\t{ key: 'keyServerUrl', variant: 'literal', value: known.keyServerUrl },\n\t\t\t\t\t{\n\t\t\t\t\t\tkey: 'serverConfigs',\n\t\t\t\t\t\tvariant: 'literal',\n\t\t\t\t\t\t// Bake objectId / weight / aggregatorUrl / apiKeyName as literals.\n\t\t\t\t\t\t// Any apiKey is stripped — devstack never carries the secret; the\n\t\t\t\t\t\t// app injects it at runtime keyed by apiKeyName.\n\t\t\t\t\t\tvalue: stripApiKey(known.serverConfigs),\n\t\t\t\t\t},\n\t\t\t\t\t// Declared config: a plain boolean literal (not a secret, so never\n\t\t\t\t\t// a `requireValue`). True on live / fork-known.\n\t\t\t\t\t{ key: 'verifyKeyServers', variant: 'literal', value: known.verifyKeyServers },\n\t\t\t\t]\n\t\t\t: [\n\t\t\t\t\t{ key: 'name', variant: 'literal', value: structural.name },\n\t\t\t\t\t{ key: 'mode', variant: 'literal', value: structural.mode },\n\t\t\t\t\t{ key: 'objectId', variant: 'resolved', tsType: 'string', live: (s) => s.objectId },\n\t\t\t\t\t{\n\t\t\t\t\t\tkey: 'keyServerUrl',\n\t\t\t\t\t\tvariant: 'resolved',\n\t\t\t\t\t\ttsType: 'string',\n\t\t\t\t\t\tlive: (s) => s.keyServerUrl,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tkey: 'serverConfigs',\n\t\t\t\t\t\tvariant: 'resolved',\n\t\t\t\t\t\t// Inline structural literal mirroring `SealKeyServerEntry` so the\n\t\t\t\t\t\t// committed `seal.ts` carries the concrete type (no emitted import).\n\t\t\t\t\t\t// `stripApiKey` guards the world-readable `values` channel — the\n\t\t\t\t\t\t// resolved blob must never carry a secret apiKey.\n\t\t\t\t\t\ttsType: SERVER_CONFIGS_TS_TYPE,\n\t\t\t\t\t\tlive: (s) => stripApiKey(s.serverConfigs),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tkey: 'verifyKeyServers',\n\t\t\t\t\t\tvariant: 'resolved',\n\t\t\t\t\t\ttsType: 'boolean',\n\t\t\t\t\t\tlive: (s) => s.verifyKeyServers,\n\t\t\t\t\t},\n\t\t\t\t];\n\treturn keyedBucketSpec({ bucket: 'seal.ts', kind: 'seal', key: structural.name, fields });\n};\n\n/** Build the LIVE Codegenable contribution for a seal instance.\n *\n * Live / fork-known deployments resolve their ids at factory time, so they\n * are DECLARED config — pass `known` so they bake as literals (the SAME branch\n * the static codegen uses). This keeps the two derivations consistent AND\n * keeps the known `serverConfigs` OUT of the world-readable `values` channel\n * entirely (literals don't ride `values`). Only `local-keygen`'s\n * dynamically-deployed ids flow through the resolved/`values` channel. */\nexport const makeSealCodegenable = (bindings: SealBindings): CodegenableDecl => {\n\tconst known: SealKnownIds | undefined =\n\t\tbindings.mode === 'local-keygen'\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tobjectId: bindings.objectId,\n\t\t\t\t\tkeyServerUrl: bindings.keyServerUrl,\n\t\t\t\t\tserverConfigs: bindings.serverConfigs,\n\t\t\t\t\tverifyKeyServers: bindings.verifyKeyServers,\n\t\t\t\t};\n\treturn liveBucketCodegen(\n\t\tsealBucketSpec({ name: bindings.name, mode: bindings.mode, known }),\n\t\tbindings,\n\t);\n};\n\n/** Build the STATIC (stack-free) Codegenable contribution for a seal\n * instance. Emits `requireValue(dep, 'seal:<name>', '<key>')` for the runtime\n * fields; the committed `seal.ts` carries no baked object id / endpoint URL. */\nexport const makeSealStaticCodegen = (config: SealStaticConfig): CodegenableDecl =>\n\tstaticBucketCodegen(sealBucketSpec(config));\n"],"mappings":";;;;;;;AAkCA,MAAM,yBACL;;;;;;;;AASD,MAAM,eAAe,kBACpB,cAAc,KAAK,UAAU;CAC5B,MAAM,OAAgC,EAAE,GAAG,MAAM;CACjD,OAAO,KAAK;CACZ,OAAO;AACR,CAAC;;;;;;AA6CF,MAAM,kBAAkB,eAAmE;CAC1F,MAAM,QAAQ,WAAW;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ions } from "../sui/mode/spec.mjs";
|
|
|
4
4
|
import { SuiClient } from "../sui/mode/shared.mjs";
|
|
5
5
|
import { AccountValue } from "../account/service.mjs";
|
|
6
6
|
import { AccountResourceId } from "../account/index.mjs";
|
|
7
|
+
import { SealAnyError, SealConfigError, SealError } from "./errors.mjs";
|
|
7
8
|
import { SealKeyManager } from "./key-manager.mjs";
|
|
8
9
|
import { SealKeyServer, SealKeyServerEntry, SealKnownResolved, SealLocalKeygenResolved, SealResolved } from "./registry-publish.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import { KnownNetwork } from "./mode/live.mjs";
|
|
10
|
+
import { KnownNetwork, SealServerKind } from "./mode/live.mjs";
|
|
11
11
|
import { ForkUpstream } from "./mode/fork-known.mjs";
|
|
12
12
|
import { SealBindings } from "./codegen.mjs";
|
|
13
13
|
//#region src/plugins/seal/index.d.ts
|
|
@@ -42,17 +42,38 @@ interface SealLocalKeygenOptions<Signer extends SealSignerMember = SealSignerMem
|
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
/** Live-mode options (testnet / mainnet).
|
|
45
|
+
/** Live-mode options (testnet / mainnet).
|
|
46
|
+
*
|
|
47
|
+
* Zero-config `testnet()` resolves BOTH independent servers;
|
|
48
|
+
* `mainnet()` resolves the committee (which requires credentials — declare
|
|
49
|
+
* the non-secret `apiKeyName`). `{ server: 'committee' }` opts a testnet
|
|
50
|
+
* stack into the committee aggregator. `serverConfigs` is the raw verbatim
|
|
51
|
+
* override. `verifyKeyServers` defaults to the SDK default (true) on live /
|
|
52
|
+
* known — omit it; only local-keygen forces it false. This default also
|
|
53
|
+
* applies to a verbatim `serverConfigs` override: for a private / unregistered
|
|
54
|
+
* key server (whose on-chain registration can't be verified), pass
|
|
55
|
+
* `verifyKeyServers: false` explicitly.
|
|
56
|
+
*
|
|
57
|
+
* NOTE: devstack never carries the secret committee `apiKey` value (committed
|
|
58
|
+
* config + the browser-injected `deployment.json` are world-readable). Pass
|
|
59
|
+
* `apiKeyName` (the header name) and inject the apiKey at runtime when you
|
|
60
|
+
* construct `SealClient`. */
|
|
46
61
|
interface SealLiveOptions extends SealCommonOptions {
|
|
47
62
|
readonly network?: KnownNetwork;
|
|
48
|
-
readonly
|
|
49
|
-
readonly
|
|
63
|
+
readonly server?: SealServerKind;
|
|
64
|
+
readonly apiKeyName?: string;
|
|
65
|
+
readonly verifyKeyServers?: boolean;
|
|
66
|
+
readonly serverConfigs?: ReadonlyArray<SealKeyServerEntry>;
|
|
50
67
|
}
|
|
51
|
-
/** Fork-known-mode options.
|
|
68
|
+
/** Fork-known-mode options. The `*-fork` network routes to the wrapped
|
|
69
|
+
* upstream's known deployment; `server` / `apiKeyName` mirror the live
|
|
70
|
+
* selectors (the secret apiKey is injected by the app at runtime, never
|
|
71
|
+
* carried by devstack). */
|
|
52
72
|
interface SealForkKnownOptions extends SealCommonOptions {
|
|
53
73
|
readonly upstream: ForkUpstream;
|
|
54
|
-
readonly
|
|
55
|
-
readonly
|
|
74
|
+
readonly server?: SealServerKind;
|
|
75
|
+
readonly apiKeyName?: string;
|
|
76
|
+
readonly verifyKeyServers?: boolean;
|
|
56
77
|
}
|
|
57
78
|
type SealOptions<Signer extends SealSignerMember = SealSignerMember> = ({
|
|
58
79
|
readonly mode: 'local-keygen';
|
|
@@ -73,7 +94,21 @@ declare const seal: <const Signer extends SealSignerMember = SealSignerMember>(o
|
|
|
73
94
|
readonly mode: SuiOptions["mode"];
|
|
74
95
|
}>;
|
|
75
96
|
readonly signer: Signer;
|
|
76
|
-
} ? T extends Readonly<Record<string, AnyResourceRef>> ? readonly T[keyof T][] : readonly [] : never : never> | Plugin<`seal:${string}`,
|
|
97
|
+
} ? T extends Readonly<Record<string, AnyResourceRef>> ? readonly T[keyof T][] : readonly [] : never : never> | Plugin<`seal:${string}`, {
|
|
98
|
+
serverConfigs: readonly SealKeyServerEntry[];
|
|
99
|
+
keyServerUrl: string;
|
|
100
|
+
objectId: string;
|
|
101
|
+
verifyKeyServers: boolean;
|
|
102
|
+
mode: "live";
|
|
103
|
+
manager: null;
|
|
104
|
+
}, readonly []> | Plugin<`seal:${string}`, {
|
|
105
|
+
serverConfigs: readonly SealKeyServerEntry[];
|
|
106
|
+
keyServerUrl: string;
|
|
107
|
+
objectId: string;
|
|
108
|
+
verifyKeyServers: boolean;
|
|
109
|
+
mode: "fork-known";
|
|
110
|
+
manager: null;
|
|
111
|
+
}, readonly []>;
|
|
77
112
|
/** Mode-narrowed factory namespace.
|
|
78
113
|
*
|
|
79
114
|
* Usage:
|
|
@@ -105,29 +140,39 @@ declare const sealFor: ModeNamespace<{
|
|
|
105
140
|
};
|
|
106
141
|
live: {
|
|
107
142
|
testnet: (opts?: Omit<SealLiveOptions, "network">) => Plugin<`seal:${string}`, {
|
|
108
|
-
|
|
109
|
-
manager: null;
|
|
110
|
-
serverConfigs: ReadonlyArray<SealKeyServerEntry>;
|
|
143
|
+
serverConfigs: readonly SealKeyServerEntry[];
|
|
111
144
|
keyServerUrl: string;
|
|
112
145
|
objectId: string;
|
|
113
|
-
|
|
114
|
-
mainnet: (opts?: Omit<SealLiveOptions, "network">) => Plugin<`seal:${string}`, {
|
|
146
|
+
verifyKeyServers: boolean;
|
|
115
147
|
mode: "live";
|
|
116
148
|
manager: null;
|
|
117
|
-
|
|
149
|
+
}, readonly []>;
|
|
150
|
+
mainnet: (opts?: Omit<SealLiveOptions, "network">) => Plugin<`seal:${string}`, {
|
|
151
|
+
serverConfigs: readonly SealKeyServerEntry[];
|
|
118
152
|
keyServerUrl: string;
|
|
119
153
|
objectId: string;
|
|
120
|
-
|
|
121
|
-
custom: (opts: Required<Pick<SealLiveOptions, "objectId" | "keyServerUrl">> & SealLiveOptions) => Plugin<`seal:${string}`, {
|
|
154
|
+
verifyKeyServers: boolean;
|
|
122
155
|
mode: "live";
|
|
123
156
|
manager: null;
|
|
124
|
-
|
|
157
|
+
}, readonly []>;
|
|
158
|
+
custom: (opts: Required<Pick<SealLiveOptions, "serverConfigs">> & SealLiveOptions) => Plugin<`seal:${string}`, {
|
|
159
|
+
serverConfigs: readonly SealKeyServerEntry[];
|
|
125
160
|
keyServerUrl: string;
|
|
126
161
|
objectId: string;
|
|
162
|
+
verifyKeyServers: boolean;
|
|
163
|
+
mode: "live";
|
|
164
|
+
manager: null;
|
|
127
165
|
}, readonly []>;
|
|
128
166
|
};
|
|
129
167
|
fork: {
|
|
130
|
-
forkKnown: (opts: SealForkKnownOptions) => Plugin<`seal:${string}`,
|
|
168
|
+
forkKnown: (opts: SealForkKnownOptions) => Plugin<`seal:${string}`, {
|
|
169
|
+
serverConfigs: readonly SealKeyServerEntry[];
|
|
170
|
+
keyServerUrl: string;
|
|
171
|
+
objectId: string;
|
|
172
|
+
verifyKeyServers: boolean;
|
|
173
|
+
mode: "fork-known";
|
|
174
|
+
manager: null;
|
|
175
|
+
}, readonly []>;
|
|
131
176
|
};
|
|
132
177
|
}>;
|
|
133
178
|
//#endregion
|