Separate identity-only pilot custody foundation
This commit is contained in:
+24
-5
@@ -7,11 +7,13 @@ import { migrateCustody, grantCustodyRuntime, grantMoneroObserverRuntime,
|
||||
import { initializeMainnetCustodyIdentity, parseMainnetCustodianId } from '../server/market/mainnet-custody-identity.ts';
|
||||
import { importSqliteCustody } from '../server/market/custody-import.ts';
|
||||
import { PostgresCustody } from '../server/market/postgres-custody.ts';
|
||||
import { IS_MAINNET } from '../shared/network.ts';
|
||||
import { IS_MAINNET, IS_PILOT } from '../shared/network.ts';
|
||||
import { initializePilotCustodyIdentity, parsePilotCustodianId } from '../server/market/pilot-custody-identity.ts';
|
||||
import { resolveCustodyIncident } from '../server/market/custody-incident.ts';
|
||||
import { loadMoneroDepositReviewApproval, loadMoneroDepositReviewPolicy } from '../server/market/monero-deposit-review-config.ts';
|
||||
import { assertCustodyDbActionAllowedOnNetwork, assertMainnetSchemaMigrationAcknowledged,
|
||||
assertMainnetCustodyOperationAcknowledged, parseCustodyDbArguments } from '../server/market/custody-db-args.ts';
|
||||
assertMainnetCustodyOperationAcknowledged, assertPilotCustodyActionAllowed, assertPilotSchemaMigrationAcknowledged,
|
||||
assertPilotCustodyIdentityAcknowledged, parseCustodyDbArguments } from '../server/market/custody-db-args.ts';
|
||||
import { prepareDepositCreditReview, postReviewedDepositPendingCredit, prepareDepositCreditReleaseReview,
|
||||
releaseReviewedDepositCredit, reconcileDepositCreditReorgHolds, prepareDepositReorgResolution,
|
||||
resolveReleasedDepositReorgHold, type DepositCreditApproval, type DepositCreditReleaseApproval,
|
||||
@@ -21,14 +23,19 @@ import { prepareDepositCreditReview, postReviewedDepositPendingCredit, prepareDe
|
||||
const commandArgs = process.argv.slice(2);
|
||||
const depositActions = ['deposit-prepare-credit', 'deposit-stage-credit', 'deposit-prepare-release', 'deposit-release',
|
||||
'deposit-reconcile-holds', 'deposit-prepare-resolve-hold', 'deposit-resolve-hold'];
|
||||
const custodyActions = ['migrate', 'migrate-mainnet-schema', 'initialize-mainnet-custody-identity', 'grant-runtime', 'grant-monero-observer-runtime',
|
||||
const custodyActions = ['migrate', 'migrate-mainnet-schema', 'initialize-mainnet-custody-identity', 'migrate-pilot-schema',
|
||||
'initialize-pilot-custody-identity', 'grant-runtime', 'grant-monero-observer-runtime',
|
||||
'grant-monero-withdrawal-runtime',
|
||||
'grant-monero-deposit-allocator-runtime', 'grant-monero-credit-runtime',
|
||||
'import-sqlite', 'audit', 'resolve-integrity'];
|
||||
const { action, argument, extraArgument } = parseCustodyDbArguments(commandArgs);
|
||||
assertCustodyDbActionAllowedOnNetwork(action, IS_MAINNET);
|
||||
assertPilotCustodyActionAllowed(action, IS_PILOT);
|
||||
assertMainnetSchemaMigrationAcknowledged(action, process.env.WIKIDECK_MAINNET_SCHEMA_MIGRATION);
|
||||
assertMainnetCustodyOperationAcknowledged(action, process.env.WIKIDECK_MAINNET_CUSTODY_OPERATIONS);
|
||||
assertPilotSchemaMigrationAcknowledged(action, process.env.WIKIDECK_PILOT_SCHEMA_MIGRATION);
|
||||
assertPilotCustodyIdentityAcknowledged(action, process.env.WIKIDECK_PILOT_CUSTODY_IDENTITY,
|
||||
process.env.WIKIDECK_PILOT_CUSTODY_OPERATIONS);
|
||||
if (action === 'initialize-mainnet-custody-identity' && process.env.WIKIDECK_MAINNET_CUSTODY_IDENTITY !== 'initialize-mainnet-custody-v1') {
|
||||
throw new Error('Mainnet custody identity initialization requires WIKIDECK_MAINNET_CUSTODY_IDENTITY=initialize-mainnet-custody-v1');
|
||||
}
|
||||
@@ -41,11 +48,13 @@ try {
|
||||
} else {
|
||||
const pool = new Pool(config);
|
||||
try {
|
||||
if (action === 'migrate' || action === 'migrate-mainnet-schema') {
|
||||
if (action === 'migrate' || action === 'migrate-mainnet-schema' || action === 'migrate-pilot-schema') {
|
||||
await migrateCustody(pool);
|
||||
console.log(action === 'migrate-mainnet-schema'
|
||||
? 'Mainnet custody schema verified/migrated; no runtime grants, deposits, or payments enabled.'
|
||||
: 'Custody PostgreSQL schema verified/migrated. No funds activated.');
|
||||
: action === 'migrate-pilot-schema'
|
||||
? 'Pilot custody schema verified/migrated; no pilot identity, runtime grants, deposits, or payments enabled.'
|
||||
: 'Custody PostgreSQL schema verified/migrated. No funds activated.');
|
||||
}
|
||||
if (action === 'initialize-mainnet-custody-identity') {
|
||||
if (!IS_MAINNET || extraArgument) throw new Error('Expected mainnet initialize-mainnet-custody-identity CUSTODIAN_UUID');
|
||||
@@ -53,6 +62,16 @@ try {
|
||||
console.log(JSON.stringify({ initialized: true, network: identity.network, chainId: identity.chainId,
|
||||
custodianId: identity.id, crediting: 'reviewed-pending-only', withdrawals: 'disabled' }));
|
||||
}
|
||||
if (action === 'initialize-pilot-custody-identity') {
|
||||
if (!IS_PILOT || process.env.WIKIDECK_PILOT_MODE !== 'private-mock-only' || extraArgument) {
|
||||
throw new Error('Expected pilot profile, private-mock-only mode, and one custodian UUID');
|
||||
}
|
||||
const identity = await initializePilotCustodyIdentity(pool, parsePilotCustodianId(argument ?? ''));
|
||||
console.log(JSON.stringify({ initialized: true, marketNetwork: identity.marketNetwork,
|
||||
marketChainId: identity.marketChainId, moneroNetwork: identity.moneroNetwork,
|
||||
custodianId: identity.custodianId, activation: identity.activationStatus,
|
||||
deposits: 'disabled', withdrawals: 'disabled' }));
|
||||
}
|
||||
if (action === 'grant-runtime') { await grantCustodyRuntime(pool, argument ?? ''); console.log('Runtime grants applied; no credentials printed.'); }
|
||||
if (action === 'grant-monero-observer-runtime') {
|
||||
await grantMoneroObserverRuntime(pool, argument ?? '');
|
||||
|
||||
@@ -8,4 +8,4 @@ try {
|
||||
console.error(JSON.stringify({ component: 'monero-daemon-probe', ready: false,
|
||||
reason: error instanceof Error ? error.message : 'Probe failed' }));
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user