Private CLI workflow for reviewed depowit operations

This commit is contained in:
2026-10-22 02:09:07 -04:00
parent 05aead39ae
commit 12f80fdc53
7 changed files with 231 additions and 2 deletions
+49 -2
View File
@@ -7,11 +7,21 @@ import { importSqliteCustody } from '../server/market/custody-import.ts';
import { PostgresCustody } from '../server/market/postgres-custody.ts';
import { IS_MAINNET } from '../shared/network.ts';
import { resolveCustodyIncident } from '../server/market/custody-incident.ts';
import { loadMoneroDepositReviewApproval, loadMoneroDepositReviewPolicy } from '../server/market/monero-deposit-review-config.ts';
import { parseCustodyDbArguments } from '../server/market/custody-db-args.ts';
import { prepareDepositCreditReview, postReviewedDepositPendingCredit, prepareDepositCreditReleaseReview,
releaseReviewedDepositCredit, reconcileDepositCreditReorgHolds, prepareDepositReorgResolution,
resolveReleasedDepositReorgHold, type DepositCreditApproval, type DepositCreditReleaseApproval,
type DepositReorgResolutionApproval } from '../server/market/monero-deposit-credit.ts';
// Explicit operator task, never invoked by node startup. No passwords or database URLs printed.
if (IS_MAINNET) throw new Error('Only sandbox financial schema operations are implemented');
const [action, argument] = process.argv.slice(2);
if (!['migrate', 'grant-runtime', 'grant-monero-credit-runtime', 'import-sqlite', 'audit', 'resolve-integrity'].includes(action)) throw new Error('Expected migrate, grant-runtime ROLE, grant-monero-credit-runtime ROLE, import-sqlite DATA_DIR, audit, or resolve-integrity EVIDENCE_UUID');
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', 'grant-runtime', 'grant-monero-credit-runtime', 'import-sqlite', 'audit', 'resolve-integrity'];
const { action, argument, extraArgument } = parseCustodyDbArguments(commandArgs);
if (!custodyActions.includes(action) && !depositActions.includes(action)) throw new Error('Unsupported custody operation');
try {
const config = await postgresConfig();
if (action === 'audit') {
@@ -27,6 +37,43 @@ try {
console.log('Separate reviewed pending-credit coordinator grants applied; no credentials printed and no live deposits enabled.');
}
if (action === 'resolve-integrity') console.log(JSON.stringify(await resolveCustodyIncident(pool, argument ?? '')));
if (depositActions.includes(action)) {
const policy = await loadMoneroDepositReviewPolicy();
if (action === 'deposit-prepare-credit') {
if (!argument || !extraArgument) throw new Error('Expected deposit-prepare-credit WALLET_FINGERPRINT OBSERVATION_ID');
console.log(JSON.stringify(await prepareDepositCreditReview(pool, argument, extraArgument, policy)));
}
if (action === 'deposit-stage-credit') {
if (!argument || extraArgument) throw new Error('Expected deposit-stage-credit APPROVAL_JSON_FILE');
const approval = await loadMoneroDepositReviewApproval(argument);
// The coordinator validates the exact approval schema/signature before any write.
console.log(JSON.stringify(await postReviewedDepositPendingCredit(pool, approval as DepositCreditApproval, policy)));
}
if (action === 'deposit-prepare-release') {
if (!argument || extraArgument) throw new Error('Expected deposit-prepare-release CREDIT_UUID');
console.log(JSON.stringify(await prepareDepositCreditReleaseReview(pool, argument, policy)));
}
if (action === 'deposit-release') {
if (!argument || extraArgument) throw new Error('Expected deposit-release APPROVAL_JSON_FILE');
const approval = await loadMoneroDepositReviewApproval(argument);
// The coordinator validates the exact approval schema/signature before any write.
console.log(JSON.stringify(await releaseReviewedDepositCredit(pool, approval as DepositCreditReleaseApproval, policy)));
}
if (action === 'deposit-reconcile-holds') {
if (!argument || extraArgument) throw new Error('Expected deposit-reconcile-holds WALLET_FINGERPRINT');
console.log(JSON.stringify({ holdsCreated: await reconcileDepositCreditReorgHolds(pool, argument) }));
}
if (action === 'deposit-prepare-resolve-hold') {
if (!argument || !extraArgument) throw new Error('Expected deposit-prepare-resolve-hold CREDIT_UUID HOLD_UUID');
console.log(JSON.stringify(await prepareDepositReorgResolution(pool, argument, extraArgument, policy)));
}
if (action === 'deposit-resolve-hold') {
if (!argument || extraArgument) throw new Error('Expected deposit-resolve-hold APPROVAL_JSON_FILE');
const approval = await loadMoneroDepositReviewApproval(argument);
// The coordinator validates the exact approval schema/signature before any write.
console.log(JSON.stringify(await resolveReleasedDepositReorgHold(pool, approval as DepositReorgResolutionApproval, policy)));
}
}
if (action === 'import-sqlite') {
if (!argument) throw new Error('Stopped source node DATA_DIR required');
const directory = resolve(argument);