Core protocol changes for launch readiness: - OptimizerV3: binary bear/bull mapping from (staking%, avgTax) — avoids exploitable AW 30-90 kill zone. Bear: AS=30%, AW=100, CI=0, DD=0.3e18. Bull: AS=100%, AW=20, CI=0, DD=1e18. UUPS upgradeable with __gap[48]. - Directional VWAP: only records prices on ETH inflow (buys), preventing sell-side dilution of price memory - Floor formula: unified max(scarcity, mirror, clamp) — VWAP mirror uses distance from adjusted VWAP as floor distance, no branching - PriceOracle (M-1 fix): correct fallback TWAP divisor (60000s, not 300s) - Access control (M-2 fix): deployer-only guard on one-time setters - Recenter rate limit (M-3 fix): 60-second cooldown for open recenters - Safe fallback params: recenter() optimizer-failure defaults changed from exploitable CI=50%/AW=50 to safe bear-mode CI=0/AW=100 - Recentered event for monitoring and indexing - VERSION bump to 2, kraiken-lib COMPATIBLE_CONTRACT_VERSIONS updated Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
75 lines
2.4 KiB
TypeScript
75 lines
2.4 KiB
TypeScript
import {
|
|
runAllHealthChecks,
|
|
formatHealthCheckError,
|
|
} from './health-checks.js';
|
|
import { readFileSync } from 'fs';
|
|
import { join } from 'path';
|
|
|
|
const DEFAULT_RPC_URL = 'http://localhost:8081/api/rpc';
|
|
const DEFAULT_WEBAPP_URL = 'http://localhost:8081';
|
|
const DEFAULT_GRAPHQL_URL = 'http://localhost:8081/api/graphql';
|
|
|
|
export interface ContractAddresses {
|
|
Kraiken: string;
|
|
Stake: string;
|
|
LiquidityManager: string;
|
|
OptimizerProxy?: string;
|
|
}
|
|
|
|
export interface StackConfig {
|
|
rpcUrl: string;
|
|
webAppUrl: string;
|
|
graphqlUrl: string;
|
|
contracts: ContractAddresses;
|
|
}
|
|
|
|
/**
|
|
* Load contract addresses from deployments file
|
|
*/
|
|
function loadContractAddresses(): ContractAddresses {
|
|
try {
|
|
const deploymentsPath = join(process.cwd(), 'onchain', 'deployments-local.json');
|
|
const deploymentsJson = readFileSync(deploymentsPath, 'utf-8');
|
|
const deployments = JSON.parse(deploymentsJson);
|
|
return deployments.contracts;
|
|
} catch (error) {
|
|
console.error('Failed to load contract addresses from deployments-local.json:', error);
|
|
throw new Error('Cannot run tests without deployed contract addresses');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get stack configuration from environment variables.
|
|
* Tests should NOT start their own stack - they require a pre-existing healthy stack.
|
|
*/
|
|
export function getStackConfig(): StackConfig {
|
|
return {
|
|
rpcUrl: process.env.STACK_RPC_URL ?? DEFAULT_RPC_URL,
|
|
webAppUrl: process.env.STACK_WEBAPP_URL ?? DEFAULT_WEBAPP_URL,
|
|
graphqlUrl: process.env.STACK_GRAPHQL_URL ?? DEFAULT_GRAPHQL_URL,
|
|
contracts: loadContractAddresses(),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Validate that a healthy stack exists and is functional.
|
|
* If validation fails, the test run should exit immediately.
|
|
*
|
|
* Tests do NOT manage stack lifecycle - stack must be started externally via:
|
|
* ./scripts/dev.sh start
|
|
*/
|
|
export async function validateStackHealthy(config: StackConfig): Promise<void> {
|
|
const results = await runAllHealthChecks(config);
|
|
|
|
const failures = results.filter(r => !r.success);
|
|
if (failures.length > 0) {
|
|
const errorMessage = formatHealthCheckError(results);
|
|
console.error('\n❌ Stack health validation failed');
|
|
console.error('Tests require a pre-existing healthy stack.');
|
|
console.error('Start the stack with: ./scripts/dev.sh start\n');
|
|
console.error(errorMessage);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('✅ Stack health validation passed');
|
|
}
|