53 lines
2.3 KiB
TypeScript
53 lines
2.3 KiB
TypeScript
/** Dedicated bundled entry point. Importing it does not start a host or import a strategy. */
|
|
import { loadedNativeIdentity } from '@stock-bot/engine';
|
|
import type { PaperDeployment } from '@stock-bot/stock-config/paper-deployments';
|
|
import type { StrategyVersionPackage } from '@stock-bot/types';
|
|
import type { CanonicalExecutionRepository } from '../execution/canonical-paper';
|
|
import { importRetainedProgram } from '../strategies/retained-program';
|
|
import { CanonicalPaperRuntime } from './CanonicalPaperRuntime';
|
|
import { retainedPaperDeployment } from './paper-deployment-custody';
|
|
import { verifyPaperHostBuild } from './paper-host-identity';
|
|
|
|
/** Caller must have verified the immutable operator promotion and current permission before calling. */
|
|
export async function createPromotedPaperRuntime(options: {
|
|
deployment: PaperDeployment;
|
|
pkg: StrategyVersionPackage;
|
|
repository: CanonicalExecutionRepository;
|
|
now?: () => number;
|
|
}) {
|
|
const deployment = retainedPaperDeployment(options.deployment);
|
|
await verifyPaperHostBuild(deployment.preview.host, import.meta.url);
|
|
if (
|
|
loadedNativeIdentity.engineWrapperSha256 !== deployment.preview.host.engineWrapperSha256 ||
|
|
loadedNativeIdentity.engineBinarySha256 !== deployment.preview.host.engineBinarySha256
|
|
) {
|
|
throw new Error(
|
|
'Loaded native identity differs from paper promotion; restart with immutable build artifacts'
|
|
);
|
|
}
|
|
if (
|
|
options.pkg.artifact.sha256 !== deployment.preview.strategy.artifactSha256 ||
|
|
options.pkg.dependencyLock.sha256 !== deployment.preview.strategy.dependencyLockSha256
|
|
) {
|
|
throw new Error('Paper host artifact does not match the operator promotion');
|
|
}
|
|
const program = await importRetainedProgram(
|
|
options.pkg,
|
|
deployment.preview.configuration.strategies[0]
|
|
);
|
|
const runtime = new CanonicalPaperRuntime({
|
|
repository: options.repository,
|
|
programs: [program],
|
|
now: options.now,
|
|
deployment: {
|
|
deploymentId: deployment.id,
|
|
promotionHash: deployment.promotionHash,
|
|
strategyVersionId: deployment.preview.strategy.versionId,
|
|
artifactSha256: deployment.preview.strategy.artifactSha256,
|
|
dependencyLockSha256: deployment.preview.strategy.dependencyLockSha256,
|
|
host: deployment.preview.host,
|
|
},
|
|
});
|
|
await runtime.initialize(deployment.preview.configuration);
|
|
return runtime;
|
|
}
|