All checks were successful
deploy / deploy (push) Successful in 33s
Proof: Adds repo-owned EURe-to-BTC request preflight, signing, gated live submission, durable request/result/outcome persistence, dashboard request lifecycle rows, and tests proving submitted/relay accepted are not completed without inventory movement. Assumptions: The NEAR Intents solver relay quote, publish_intent, and get_status JSON-RPC methods accept signed raw_ed25519 token_diff payloads with quote_hashes; live validation remains bounded to 5 EUR per attempt, at most five attempts, and 200 bps slippage. Still fake: Venue-native terminal fill linkage and fee-complete realized PnL are still unavailable; request completion is attributed from durable inventory deltas unless the venue later exposes a linked settlement id.
94 lines
3.3 KiB
JavaScript
94 lines
3.3 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { KeyPair } from 'near-api-js';
|
|
|
|
import {
|
|
buildIntentNonce,
|
|
buildIntentRequestSubmission,
|
|
buildQuoteResponseSubmission,
|
|
} from '../src/venues/near-intents/signing.mjs';
|
|
|
|
test('intent nonce uses verifier salt prefix and 32 byte base64 payload', () => {
|
|
const nonce = buildIntentNonce('252812b3');
|
|
const decoded = Buffer.from(nonce, 'base64');
|
|
|
|
assert.equal(decoded.length, 32);
|
|
assert.equal(decoded.subarray(0, 4).toString('hex'), '252812b3');
|
|
});
|
|
|
|
test('quote response signing builds token_diff payload for solver submission', () => {
|
|
const signer = KeyPair.fromRandom('ed25519');
|
|
const submission = buildQuoteResponseSubmission({
|
|
command: {
|
|
quote_id: 'quote-1',
|
|
asset_in: 'nep141:btc.omft.near',
|
|
asset_out: 'nep141:eure.omft.near',
|
|
request_kind: 'exact_in',
|
|
amount_in: '5000',
|
|
amount_out: null,
|
|
min_deadline_ms: '60000',
|
|
quote_output: {
|
|
amount_out: '4900000000000000000',
|
|
},
|
|
},
|
|
signerAccountId: 'solver.near',
|
|
signer,
|
|
verifierContract: 'intents.near',
|
|
currentSaltHex: '252812b3',
|
|
now: Date.parse('2026-04-02T10:00:00.000Z'),
|
|
});
|
|
|
|
assert.equal(submission.quote_id, 'quote-1');
|
|
assert.equal(submission.signed_data.standard, 'raw_ed25519');
|
|
const payload = JSON.parse(submission.signed_data.payload);
|
|
assert.equal(payload.signer_id, 'solver.near');
|
|
assert.equal(payload.intents[0].diff['nep141:btc.omft.near'], '5000');
|
|
assert.equal(payload.intents[0].diff['nep141:eure.omft.near'], '-4900000000000000000');
|
|
});
|
|
|
|
|
|
test('request signing builds taker token_diff payload for EURe to BTC submission', () => {
|
|
const signer = {
|
|
getPublicKey() {
|
|
return { toString: () => 'ed25519:test-public-key' };
|
|
},
|
|
sign() {
|
|
return { signature: Uint8Array.from({ length: 64 }, () => 7) };
|
|
},
|
|
};
|
|
const submission = buildIntentRequestSubmission({
|
|
request: {
|
|
request_id: 'request-1',
|
|
source_asset_id: 'nep141:eure.omft.near',
|
|
destination_asset_id: 'nep141:btc.omft.near',
|
|
source_amount_units: '5000000000000000000',
|
|
selected_quote: {
|
|
quote_hash: 'quote-hash-1',
|
|
amount_out: '10000',
|
|
},
|
|
deadline_at: '2026-04-12T10:01:00.000Z',
|
|
},
|
|
signerAccountId: 'solver.near',
|
|
signer,
|
|
verifierContract: 'intents.near',
|
|
currentSaltHex: '252812b3',
|
|
nonce: 'fixed-nonce',
|
|
});
|
|
|
|
assert.deepEqual(submission.quote_hashes, ['quote-hash-1']);
|
|
assert.equal(submission.destination_amount_units, '10000');
|
|
assert.equal(submission.nonce, 'fixed-nonce');
|
|
assert.equal(submission.signed_data.standard, 'raw_ed25519');
|
|
assert.equal(submission.signed_data.public_key, 'ed25519:test-public-key');
|
|
assert.match(submission.signed_data.signature, /^ed25519:/);
|
|
|
|
const payload = JSON.parse(submission.signed_data.payload);
|
|
assert.equal(payload.signer_id, 'solver.near');
|
|
assert.equal(payload.verifying_contract, 'intents.near');
|
|
assert.equal(payload.deadline, '2026-04-12T10:01:00.000Z');
|
|
assert.equal(payload.nonce, 'fixed-nonce');
|
|
assert.equal(payload.intents[0].intent, 'token_diff');
|
|
assert.equal(payload.intents[0].diff['nep141:eure.omft.near'], '-5000000000000000000');
|
|
assert.equal(payload.intents[0].diff['nep141:btc.omft.near'], '10000');
|
|
});
|