Files
smom-dbis-138/packages/settlement-core/dist/m2-token-registry.js
zaragoza444 5229c2d888
Some checks failed
CI/CD Pipeline / Solidity Contracts (push) Failing after 1m13s
CI/CD Pipeline / Lint and Format (push) Has been cancelled
CI/CD Pipeline / Security Scanning (push) Has been cancelled
CI/CD Pipeline / Terraform Validation (push) Has been cancelled
CI/CD Pipeline / Kubernetes Validation (push) Has been cancelled
Deploy ChainID 138 / Deploy ChainID 138 (push) Has been cancelled
HYBX OMNL TypeScript & anchor / token-aggregation build + reconcile artifact (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
Validation / validate-smart-contracts (push) Has been cancelled
Validation / validate-security (push) Has been cancelled
Validation / validate-documentation (push) Has been cancelled
Verify Deployment / Verify Deployment (push) Has been cancelled
fix(omnl): production blockers for M0-M4 settlement stack
Exempt dashboard read APIs from anonymous rate limits, preserve nginx-injected auth, wire chain-mint and DB env through deploy/LXC scripts, resolve M3 token addresses from registry, and harden super-admin seeding.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 06:47:20 -07:00

92 lines
3.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.inferCurrencyCode = inferCurrencyCode;
exports.resolveOmnlLineM2 = resolveOmnlLineM2;
exports.withM2Capabilities = withM2Capabilities;
exports.mergeExchangeTokensWithM2Registry = mergeExchangeTokensWithM2Registry;
exports.findM2TokenByAddress = findM2TokenByAddress;
exports.findM2TokenBySymbol = findM2TokenBySymbol;
exports.findM2TokenByLineId = findM2TokenByLineId;
const money_supply_1 = require("./money-supply");
const CURRENCY_FROM_SYMBOL = {
USD: 'USD',
EUR: 'EUR',
GBP: 'GBP',
AUD: 'AUD',
JPY: 'JPY',
CHF: 'CHF',
CAD: 'CAD',
XAU: 'XAU',
BTC: 'BTC',
ETH: 'ETH',
BNB: 'BNB',
POL: 'POL',
AVAX: 'AVAX',
CRO: 'CRO',
XDAI: 'XDAI',
CELO: 'CELO',
WEMIX: 'WEMIX',
};
function inferCurrencyCode(symbol) {
const s = symbol.toUpperCase();
for (const [key, code] of Object.entries(CURRENCY_FROM_SYMBOL)) {
if (s.includes(key))
return code;
}
if (s.startsWith('C') && s.length > 1) {
for (const [key, code] of Object.entries(CURRENCY_FROM_SYMBOL)) {
if (s.slice(1).includes(key))
return code;
}
}
return 'USD';
}
function resolveOmnlLineM2(currencyCode, symbol) {
const ccy = (currencyCode || inferCurrencyCode(symbol ?? 'USD')).toUpperCase();
return `${ccy}-M2`;
}
function withM2Capabilities(token, overrides = {}) {
const currencyCode = token.currencyCode ?? inferCurrencyCode(token.symbol);
return {
symbol: token.symbol,
name: token.name,
address: token.address,
decimals: token.decimals,
native: token.native,
currencyCode,
moneyLayer: 'M2',
omnlLine: token.omnlLine ?? resolveOmnlLineM2(currencyCode, token.symbol),
loadFromGl: money_supply_1.GL_CODES.M2_BROAD,
swappable: true,
convertible: true,
transferableInternal: true,
transferableExternal: true,
...overrides,
};
}
function mergeExchangeTokensWithM2Registry(baseTokens, registry) {
const byAddress = new Map();
for (const t of registry.tokens) {
byAddress.set(t.address.toLowerCase(), t);
}
for (const t of baseTokens) {
const key = t.address.toLowerCase();
if (!byAddress.has(key)) {
byAddress.set(key, withM2Capabilities(t));
}
}
return Array.from(byAddress.values()).sort((a, b) => a.symbol.localeCompare(b.symbol));
}
function findM2TokenByAddress(registry, address) {
const lower = address.toLowerCase();
return registry.tokens.find((t) => t.address.toLowerCase() === lower);
}
function findM2TokenBySymbol(registry, symbol) {
const s = symbol.trim().toLowerCase();
return registry.tokens.find((t) => t.symbol.toLowerCase() === s);
}
function findM2TokenByLineId(registry, lineId) {
const id = lineId.trim().toUpperCase();
return registry.tokens.find((t) => t.omnlLine.toUpperCase() === id);
}