unrip/src/core/assets.mjs
philipp 41b9ec680b
Some checks failed
deploy / deploy (push) Failing after 1m35s
Implement funded NEAR Intents trade loop
Proof: first non-mocked tradeable loop for one pair using funded NEAR Intents inventory, Kafka, and PostgreSQL.

Assumptions: solver-side execution is performed by signed token_diff quote responses over the Solver Relay; EURe is treated as 1:1 with EUR; k3s runtime uses unrip-dev.near as the named signer account.

Still fake: signer key is not yet registered on intents.near, strategy and executor remain disarmed by default, and no live mainnet quote response has been submitted from this repo yet.
2026-04-02 10:01:15 +02:00

55 lines
1.8 KiB
JavaScript

export function pairKey(assetIn, assetOut) {
return `${assetIn}->${assetOut}`;
}
export function classifyPairDirection({ assetIn, assetOut, btcAssetId, eureAssetId }) {
if (assetIn === btcAssetId && assetOut === eureAssetId) return 'btc_to_eure';
if (assetIn === eureAssetId && assetOut === btcAssetId) return 'eure_to_btc';
return 'unsupported';
}
export function isActivePair(assetIn, assetOut, config) {
return (
(assetIn === config.tradingBtc.assetId && assetOut === config.tradingEure.assetId)
|| (assetIn === config.tradingEure.assetId && assetOut === config.tradingBtc.assetId)
);
}
export function unitsToNumber(amount, decimals) {
if (amount == null) return 0;
const raw = String(amount).trim();
if (!raw) return 0;
const negative = raw.startsWith('-');
const digits = negative ? raw.slice(1) : raw;
const padded = digits.padStart(decimals + 1, '0');
const head = padded.slice(0, padded.length - decimals);
const tail = decimals > 0 ? padded.slice(-decimals) : '';
const rendered = decimals > 0 ? `${head}.${tail}` : head;
const numeric = Number(rendered);
return negative ? -numeric : numeric;
}
export function numberToUnits(value, decimals, { mode = 'round' } = {}) {
const factor = 10 ** decimals;
const scaled = value * factor;
if (mode === 'floor') return String(Math.max(0, Math.floor(scaled)));
if (mode === 'ceil') return String(Math.max(0, Math.ceil(scaled)));
return String(Math.max(0, Math.round(scaled)));
}
export function bigintAmount(amount) {
return BigInt(String(amount || '0'));
}
export function formatNumber(value, digits = 8) {
if (!Number.isFinite(value)) return null;
return value.toFixed(digits);
}
export function mapToSortedObject(record = {}) {
return Object.fromEntries(
Object.entries(record).sort(([left], [right]) => left.localeCompare(right)),
);
}