Some checks failed
CI/CD Pipeline / Solidity Contracts (push) Failing after 52s
CI/CD Pipeline / Security Scanning (push) Successful in 2m40s
CI/CD Pipeline / Lint and Format (push) Failing after 49s
CI/CD Pipeline / Terraform Validation (push) Failing after 24s
CI/CD Pipeline / Kubernetes Validation (push) Successful in 27s
Deploy ChainID 138 / Deploy ChainID 138 (push) Has been cancelled
Validation / validate-genesis (push) Has been cancelled
Validation / validate-terraform (push) Has been cancelled
Validation / validate-kubernetes (push) Has been cancelled
Verify Deployment / Verify Deployment (push) Has been cancelled
Validation / validate-smart-contracts (push) Failing after 14s
Validation / validate-security (push) Failing after 1m20s
Validation / validate-documentation (push) Failing after 18s
Add canonical btc-l1-ledger config, /btc/contracts API, Python chain138-oracle service, and production deploy scripts so secure.omdnl.org can serve live cBTC, DODO, and PMM pool addresses with headroom-aware mint gating. Co-authored-by: Cursor <cursoragent@cursor.com>
76 lines
3.1 KiB
JavaScript
76 lines
3.1 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.resolveLiveBtcUsd = resolveLiveBtcUsd;
|
|
const axios_1 = __importDefault(require("axios"));
|
|
const price_service_1 = require("./price-service");
|
|
const btc_ledger_config_1 = require("../btc-ledger-config");
|
|
const CHAIN_138 = 138;
|
|
function cbtcAddress() {
|
|
try {
|
|
return (0, btc_ledger_config_1.loadBtcLedgerConfig)().token.address.toLowerCase();
|
|
}
|
|
catch {
|
|
return '0xe94260c555ac1d9d3cc9e1632883452ebdf0082e';
|
|
}
|
|
}
|
|
/**
|
|
* Resolve live BTC/USD for settlement. Rejects unresolved/stale prices —
|
|
* production must not fall back to the $90k repo snapshot.
|
|
*/
|
|
async function resolveLiveBtcUsd() {
|
|
const base = (0, price_service_1.resolveChain138OracleBase)();
|
|
const key = process.env.OMNL_API_KEY || '';
|
|
const headers = { Accept: 'application/json' };
|
|
if (key)
|
|
headers.Authorization = `Bearer ${key}`;
|
|
const url = `${base}/api/v1/prices/metamask/v2/chains/${CHAIN_138}/spot-prices` +
|
|
`?tokenAddresses=${cbtcAddress()}&vsCurrency=usd`;
|
|
let data;
|
|
try {
|
|
const res = await axios_1.default.get(url, { headers, timeout: 30000 });
|
|
data = res.data;
|
|
}
|
|
catch (err) {
|
|
if (axios_1.default.isAxiosError(err)) {
|
|
const status = err.response?.status;
|
|
const body = err.response?.data;
|
|
const detail = typeof body === 'string'
|
|
? body.slice(0, 400)
|
|
: body != null
|
|
? JSON.stringify(body).slice(0, 400)
|
|
: err.message;
|
|
throw new Error(`Live BTC/USD fetch failed${status != null ? ` HTTP ${status}` : ''}: ${detail}`);
|
|
}
|
|
throw err;
|
|
}
|
|
const map = (data ?? {});
|
|
const addr = cbtcAddress();
|
|
const row = map[addr] ?? map[addr.toLowerCase()];
|
|
const rate = row?.usd ?? row?.USD;
|
|
if (!(typeof rate === 'number' && Number.isFinite(rate) && rate > 0)) {
|
|
throw new Error('Live BTC/USD price unresolved — settlement blocked (OMNL_REQUIRE_LIVE_BTC_PRICE). ' +
|
|
'Ensure chain138-oracle (CHAIN138_ORACLE_URL) or token-aggregation FX refresh is reachable.');
|
|
}
|
|
// Guard against known static repo fallback used in non-production
|
|
const requireLive = process.env.OMNL_REQUIRE_LIVE_BTC_PRICE === '1' || process.env.NODE_ENV === 'production';
|
|
if (requireLive && Math.abs(rate - 90000) < 0.01) {
|
|
// Allow only if explicitly overridden via env canonical
|
|
const envOverride = Number(process.env.CHAIN138_CANONICAL_PRICE_USD_BTC ||
|
|
process.env.CANONICAL_PRICE_USD_BTC ||
|
|
process.env.BTC_PRICE_USD ||
|
|
'');
|
|
if (!(envOverride > 0 && Math.abs(envOverride - 90000) < 0.01)) {
|
|
throw new Error('BTC/USD appears to be repo-fallback ($90000) — live oracle required for production settlement');
|
|
}
|
|
}
|
|
return {
|
|
btcUsdRate: rate,
|
|
source: 'chain138-oracle/metamask-spot-prices',
|
|
asOf: new Date().toISOString(),
|
|
tokenAddress: addr,
|
|
};
|
|
}
|