Enforce native protocol inventory rules
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
* - For each pmmPool / pmmPoolsVolatile[]: role in {defense, public_routing, truu_routing},
|
||||
* feeBps and k present, base/quote (or tokenIn/tokenOut) exist in cwTokens or anchorAddresses.
|
||||
* TRUU must be listed under anchorAddresses when used as quote (e.g. mainnet chain 1).
|
||||
* - Any row marked live/routingVisible/publicRoutingEnabled must use a native protocol contract,
|
||||
* not a placeholder scaffold or aggregator-only/non-native lane.
|
||||
*
|
||||
* Exit code: 0 if valid, 1 if invalid (and prints errors to stderr).
|
||||
*/
|
||||
@@ -16,11 +18,27 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const CONFIG_DIR = path.join(__dirname, '..', 'config');
|
||||
const DEPLOYMENT_STATUS_PATH = path.join(CONFIG_DIR, 'deployment-status.json');
|
||||
let DEPLOYMENT_STATUS_PATH = path.join(CONFIG_DIR, 'deployment-status.json');
|
||||
|
||||
const PHASE1_CW = ['cWUSDT', 'cWUSDC'];
|
||||
const VALID_ROLES = ['defense', 'public_routing', 'truu_routing'];
|
||||
const VALID_REFERENCE_PROTOCOLS = ['uniswap_v3', 'balancer', 'curve', '1inch'];
|
||||
const VALID_NATIVE_REFERENCE_PROTOCOLS = ['uniswap_v3', 'balancer', 'curve'];
|
||||
|
||||
function looksPlaceholderAddress(address) {
|
||||
if (!address || typeof address !== 'string') return false;
|
||||
const normalized = address.toLowerCase();
|
||||
if (!/^0x[0-9a-f]{40}$/.test(normalized)) return false;
|
||||
if (normalized === '0x0000000000000000000000000000000000000000') return true;
|
||||
const body = normalized.slice(2);
|
||||
const placeholderPrefixes = ['d0', '71', 'ba', 'c7'];
|
||||
const zeroCount = body.split('0').length - 1;
|
||||
return placeholderPrefixes.some((prefix) => body.startsWith(prefix)) && zeroCount >= 24;
|
||||
}
|
||||
|
||||
function isLiveRow(row) {
|
||||
return row?.live === true || row?.routingVisible === true || row?.publicRoutingEnabled === true;
|
||||
}
|
||||
|
||||
function loadJson(p) {
|
||||
return JSON.parse(fs.readFileSync(p, 'utf8'));
|
||||
@@ -50,6 +68,12 @@ function validatePoolEntries(chainId, pools, listLabel, knownTokens, errors) {
|
||||
if (z === '0x0000000000000000000000000000000000000000') {
|
||||
errors.push(`Chain ${chainId} ${listLabel}[${i}]: poolAddress must not be zero when set`);
|
||||
}
|
||||
if (pool.publicRoutingEnabled === true && looksPlaceholderAddress(z)) {
|
||||
errors.push(`Chain ${chainId} ${listLabel}[${i}]: live public routing poolAddress must use a native protocol contract, not a placeholder scaffold (${addr})`);
|
||||
}
|
||||
}
|
||||
if (pool.publicRoutingEnabled === true && pool.venue && pool.venue !== 'dodo_pmm') {
|
||||
errors.push(`Chain ${chainId} ${listLabel}[${i}]: public routing rows must use the native dodo_pmm venue, not "${pool.venue}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,6 +145,14 @@ function main() {
|
||||
}
|
||||
if (!referenceVenuesByFamily.has(venue.familyKey)) referenceVenuesByFamily.set(venue.familyKey, []);
|
||||
referenceVenuesByFamily.get(venue.familyKey).push(venue);
|
||||
if (isLiveRow(venue)) {
|
||||
if (!VALID_NATIVE_REFERENCE_PROTOCOLS.includes(venue.protocol)) {
|
||||
errors.push(`Chain ${chainId} gasReferenceVenues[${i}]: live/routingVisible rows must use a native protocol contract, not "${venue.protocol}"`);
|
||||
}
|
||||
if (looksPlaceholderAddress(venue.venueAddress)) {
|
||||
errors.push(`Chain ${chainId} gasReferenceVenues[${i}]: live/routingVisible venueAddress must use a native protocol contract, not a placeholder scaffold (${venue.venueAddress})`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const [familyKey, venues] of referenceVenuesByFamily.entries()) {
|
||||
@@ -146,4 +178,33 @@ function main() {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
main();
|
||||
function resolveInputPath(argv) {
|
||||
const candidate = argv[2];
|
||||
if (!candidate || candidate === '-h' || candidate === '--help') {
|
||||
return DEPLOYMENT_STATUS_PATH;
|
||||
}
|
||||
return path.isAbsolute(candidate) ? candidate : path.join(process.cwd(), candidate);
|
||||
}
|
||||
|
||||
function printUsage() {
|
||||
process.stdout.write('Usage: node scripts/validate-deployment-status.cjs [path/to/deployment-status.json]\n');
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
const argv = process.argv;
|
||||
if (argv[2] === '-h' || argv[2] === '--help') {
|
||||
printUsage();
|
||||
process.exit(0);
|
||||
}
|
||||
if (argv[2]) {
|
||||
DEPLOYMENT_STATUS_PATH = resolveInputPath(argv);
|
||||
}
|
||||
main();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
looksPlaceholderAddress,
|
||||
isLiveRow,
|
||||
validatePoolEntries,
|
||||
main,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user