All checks were successful
deploy / deploy (push) Successful in 32s
Proof: Adds a durable quote outcome attribution model, refreshes it from submitted execution results plus inventory snapshots, and updates dashboard lifecycle rows so submitted, blocked, rejected, not-filled, and completed states are separated by durable evidence. Lowers the approved live strategy edge threshold to 1.49%. Assumptions: Exact asset-unit inventory deltas inside the attribution window are acceptable as heuristic settlement evidence for the active BTC/EURe NEAR Intents path when the uncertainty is stored and shown. Deadline-plus-inventory non-fill is inferred until venue terminal events are persisted. Still fake: No venue-native terminal fill event or per-trade fee/cost ledger is stored yet; heuristic completed and not-filled records remain explicitly labeled as inferred where applicable, and realized net PnL is still not claimed.
166 lines
5 KiB
JavaScript
166 lines
5 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { deriveQuoteOutcomeRecords } from '../src/core/quote-outcomes.mjs';
|
|
|
|
const BTC = {
|
|
assetId: 'nep141:btc.omft.near',
|
|
symbol: 'BTC',
|
|
decimals: 8,
|
|
};
|
|
const EURE = {
|
|
assetId: 'nep141:eure.omft.near',
|
|
symbol: 'EURe',
|
|
decimals: 18,
|
|
};
|
|
|
|
function submittedResult(quoteId, observedAt = '2026-04-02T18:13:30.000Z') {
|
|
return {
|
|
observed_at: observedAt,
|
|
payload: {
|
|
quote_id: quoteId,
|
|
command_id: `cmd-${quoteId}`,
|
|
decision_id: `decision-${quoteId}`,
|
|
status: 'submitted',
|
|
result_code: 'quote_response_ok',
|
|
},
|
|
};
|
|
}
|
|
|
|
function exactOutCommand(quoteId) {
|
|
return {
|
|
observed_at: '2026-04-02T18:13:29.000Z',
|
|
payload: {
|
|
quote_id: quoteId,
|
|
command_id: `cmd-${quoteId}`,
|
|
decision_id: `decision-${quoteId}`,
|
|
pair: `${BTC.assetId}->${EURE.assetId}`,
|
|
direction: 'eure_to_btc',
|
|
request_kind: 'exact_out',
|
|
asset_in: BTC.assetId,
|
|
asset_out: EURE.assetId,
|
|
amount_out: '21000021200021200022',
|
|
quote_output: {
|
|
amount_in: '37014',
|
|
},
|
|
min_deadline_ms: 60000,
|
|
},
|
|
};
|
|
}
|
|
|
|
function inventorySnapshot(observedAt, spendable) {
|
|
return {
|
|
observed_at: observedAt,
|
|
payload: {
|
|
inventory_id: `inventory-${observedAt}`,
|
|
synced_at: observedAt,
|
|
spendable,
|
|
},
|
|
};
|
|
}
|
|
|
|
test('quote outcome completes only when exact submitted quote delta is observed', () => {
|
|
const [outcome] = deriveQuoteOutcomeRecords({
|
|
submissions: [submittedResult('quote-settled')],
|
|
commands: [exactOutCommand('quote-settled')],
|
|
inventorySnapshots: [
|
|
inventorySnapshot('2026-04-02T18:13:00.000Z', {
|
|
[BTC.assetId]: '0',
|
|
[EURE.assetId]: '100000000000000000000',
|
|
}),
|
|
inventorySnapshot('2026-04-02T18:13:33.000Z', {
|
|
[BTC.assetId]: '37014',
|
|
[EURE.assetId]: '78999978799978799978',
|
|
}),
|
|
],
|
|
btcAsset: BTC,
|
|
eureAsset: EURE,
|
|
now: '2026-04-02T18:14:00.000Z',
|
|
});
|
|
|
|
assert.equal(outcome.outcome_status, 'completed');
|
|
assert.equal(outcome.attribution_status, 'heuristic_match');
|
|
assert.equal(outcome.attributed_inventory_delta.delta_units[BTC.assetId], '37014');
|
|
assert.equal(outcome.attributed_inventory_delta.delta_units[EURE.assetId], '-21000021200021200022');
|
|
});
|
|
|
|
test('submitted quote without settlement stays submitted before the deadline window expires', () => {
|
|
const [outcome] = deriveQuoteOutcomeRecords({
|
|
submissions: [submittedResult('quote-submitted', '2026-04-02T18:13:30.000Z')],
|
|
commands: [exactOutCommand('quote-submitted')],
|
|
inventorySnapshots: [
|
|
inventorySnapshot('2026-04-02T18:13:00.000Z', {
|
|
[BTC.assetId]: '0',
|
|
[EURE.assetId]: '100000000000000000000',
|
|
}),
|
|
],
|
|
btcAsset: BTC,
|
|
eureAsset: EURE,
|
|
now: '2026-04-02T18:13:45.000Z',
|
|
});
|
|
|
|
assert.equal(outcome.outcome_status, 'submitted');
|
|
assert.equal(outcome.attribution_status, 'unattributed');
|
|
assert.equal(outcome.attributed_inventory_delta, null);
|
|
});
|
|
|
|
test('submitted quote without settlement becomes not filled only after deadline and later inventory evidence', () => {
|
|
const [outcome] = deriveQuoteOutcomeRecords({
|
|
submissions: [submittedResult('quote-not-filled', '2026-04-02T18:13:30.000Z')],
|
|
commands: [exactOutCommand('quote-not-filled')],
|
|
inventorySnapshots: [
|
|
inventorySnapshot('2026-04-02T18:13:00.000Z', {
|
|
[BTC.assetId]: '0',
|
|
[EURE.assetId]: '100000000000000000000',
|
|
}),
|
|
inventorySnapshot('2026-04-02T18:15:40.000Z', {
|
|
[BTC.assetId]: '0',
|
|
[EURE.assetId]: '100000000000000000000',
|
|
}),
|
|
],
|
|
btcAsset: BTC,
|
|
eureAsset: EURE,
|
|
now: '2026-04-02T18:15:40.000Z',
|
|
});
|
|
|
|
assert.equal(outcome.outcome_status, 'not_filled');
|
|
assert.equal(outcome.outcome_reason, 'deadline_elapsed_without_settlement');
|
|
assert.equal(outcome.outcome_observed_at, '2026-04-02T18:15:40.000Z');
|
|
assert.equal(outcome.payload.evidence.latest_inventory_observed_at, '2026-04-02T18:15:40.000Z');
|
|
assert.equal(outcome.attributed_inventory_delta, null);
|
|
});
|
|
|
|
test('ambiguous inventory movement is not counted as completed settlement', () => {
|
|
const outcomes = deriveQuoteOutcomeRecords({
|
|
submissions: [
|
|
submittedResult('quote-a', '2026-04-02T18:13:30.000Z'),
|
|
submittedResult('quote-b', '2026-04-02T18:13:31.000Z'),
|
|
],
|
|
commands: [
|
|
exactOutCommand('quote-a'),
|
|
exactOutCommand('quote-b'),
|
|
],
|
|
inventorySnapshots: [
|
|
inventorySnapshot('2026-04-02T18:13:00.000Z', {
|
|
[BTC.assetId]: '0',
|
|
[EURE.assetId]: '100000000000000000000',
|
|
}),
|
|
inventorySnapshot('2026-04-02T18:13:33.000Z', {
|
|
[BTC.assetId]: '37014',
|
|
[EURE.assetId]: '78999978799978799978',
|
|
}),
|
|
],
|
|
btcAsset: BTC,
|
|
eureAsset: EURE,
|
|
now: '2026-04-02T18:14:00.000Z',
|
|
});
|
|
|
|
assert.deepEqual(
|
|
outcomes.map((entry) => entry.outcome_status),
|
|
['awaiting_outcome', 'awaiting_outcome'],
|
|
);
|
|
assert.deepEqual(
|
|
outcomes.map((entry) => entry.attribution_status),
|
|
['ambiguous', 'ambiguous'],
|
|
);
|
|
});
|