bitflow-market-maker-public/test/tokenMeta.test.ts
Bought 1e29d2b543 Initial commit: Bitflow DLMM curve market maker (public edition)
Public, competition-facing build of the Bitflow market maker, scoped to the
two competition pairs: sBTC/USDCx (dlmm_1) and STX/USDCx (dlmm_14).

Both pairs run the same CoinGecko reference feed plus a geometric multi-bin
curve peaked at the active bin (weight = CURVE_DECAY^|offset|). CoinGecko is
used only for divergence/staleness safety and inventory awareness, never as a
quoted price.

Includes the production guards: M2 vol scaling, M2b reposition cooldown,
M4 pull-bids / M6 bid-lean, and the M5 hard-cap de-risk swap, plus the kill
switch, API circuit breaker, gas floor, and deny-mode post-conditions.

Defaults to EXECUTION_MODE=dry_run.
2026-09-09 15:53:05 -07:00

56 lines
2.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { BffTokenMeta, CONFIG, hydrateTokenMetadata } from '../src/config';
const baseContract = CONFIG.BASE_TOKEN_CONTRACT;
const quoteContract = CONFIG.QUOTE_TOKEN_CONTRACT;
describe('hydrateTokenMetadata', () => {
it('fills base/quote asset names + decimals from the BFF', () => {
const tokens: BffTokenMeta[] = [
{ contract_address: baseContract, asset_name: 'sbtc-token', decimals: 8 },
{ contract_address: quoteContract, asset_name: 'usdcx-token', decimals: 6 },
];
const { summary, warnings } = hydrateTokenMetadata(tokens);
expect(CONFIG.BASE_ASSET_NAME).toBe('sbtc-token');
expect(CONFIG.BASE_DECIMALS).toBe(8);
expect(CONFIG.QUOTE_ASSET_NAME).toBe('usdcx-token');
expect(CONFIG.QUOTE_DECIMALS).toBe(6);
expect(summary).toContain('base=sbtc-token/8d');
expect(warnings).toEqual([]);
});
it('falls back to the BFF symbol when asset_name is "unknown" (native-STX wrapper)', () => {
const prevName = CONFIG.BASE_ASSET_NAME;
const prevDec = CONFIG.BASE_DECIMALS;
try {
hydrateTokenMetadata([
{ contract_address: baseContract, asset_name: 'unknown', decimals: 6, symbol: 'STX' },
]);
expect(CONFIG.BASE_ASSET_NAME).toBe('stx');
expect(CONFIG.BASE_DECIMALS).toBe(6);
} finally {
CONFIG.BASE_ASSET_NAME = prevName;
CONFIG.BASE_DECIMALS = prevDec;
}
});
it('adopts the BFF asset name + decimals for a different contract', () => {
const prevName = CONFIG.BASE_ASSET_NAME;
const prevDec = CONFIG.BASE_DECIMALS;
try {
hydrateTokenMetadata([{ contract_address: baseContract, asset_name: 'sbtc-token', decimals: 8 }]);
expect(CONFIG.BASE_ASSET_NAME).toBe('sbtc-token');
expect(CONFIG.BASE_DECIMALS).toBe(8);
} finally {
CONFIG.BASE_ASSET_NAME = prevName;
CONFIG.BASE_DECIMALS = prevDec;
}
});
it('keeps the default and warns when a token is missing from the BFF', () => {
const prevName = CONFIG.BASE_ASSET_NAME;
const { warnings } = hydrateTokenMetadata([]);
expect(CONFIG.BASE_ASSET_NAME).toBe(prevName);
expect(warnings.some((w) => w.includes('not in BFF tokens'))).toBe(true);
});
});