fix(exchanges): restore type-check safety net and repair dead balance guards

tsconfig compiled docs/ (vendored ccxt samples) and @types/react was missing,
so 269 tsc errors buried the real ones. Scoping the project and adding the
missing type packages left 42 genuine errors in src/, which exposed two bugs:

- lighter: assertSpotBalance's buy branch and createOrder's spot-sell guard
  compared the {available, wallet} object against a number, so both guards
  were dead. Introduce SpotAssetBalance with a precomputed 'effective' field
  (Extract Class) and route all three call sites through it.
- offset-maker: the below-min-sell branch logged 'skip sell' but pushed the
  SELL order anyway, and pushed a possibly-null price. Both branches now
  match their working sibling.

Also: widen LighterOrder's is_ask/reduce_only to BooleanFlag (the wire format
flags.ts already parses), extract sellableBase (Extract Function, 3 copies),
delete two scripts importing a module that does not exist, add a typecheck
script. tsc --noEmit: 269 -> 0 errors; 218 tests still pass.
This commit is contained in:
discountry
2026-07-29 20:27:40 +08:00
parent 9f3e50045a
commit 7acb3c3b82
13 changed files with 116 additions and 90 deletions
-16
View File
@@ -1,16 +0,0 @@
import { LighterPrivateKey } from "../src/exchanges/lighter/crypto/schnorr";
import { bytesToHex } from "../src/exchanges/lighter/bytes";
function derive(keyHex: string): string {
const normalized = keyHex.startsWith("0x") ? keyHex.slice(2) : keyHex;
const key = LighterPrivateKey.fromHex(normalized);
return bytesToHex(key.publicKey().toBytes());
}
const input = process.argv[2];
if (!input) {
console.error("usage: bun run scripts/derive-public.ts <hex>");
process.exit(1);
}
console.log(derive(input));
-21
View File
@@ -1,21 +0,0 @@
import "dotenv/config";
import { LighterPrivateKey } from "../src/exchanges/lighter/crypto/schnorr";
import { bytesToHex } from "../src/exchanges/lighter/bytes";
function main(): void {
const raw = process.env.LIGHTER_API_PRIVATE_KEY;
if (!raw) {
throw new Error("LIGHTER_API_PRIVATE_KEY env var is required");
}
const normalized = raw.startsWith("0x") ? raw.slice(2) : raw;
const key = LighterPrivateKey.fromHex(normalized);
const publicKeyHex = bytesToHex(key.publicKey().toBytes());
const apiKeyIndex = process.env.LIGHTER_API_KEY_INDEX ?? "(not set)";
console.log(JSON.stringify({
apiKeyIndex,
publicKeyHex,
}, null, 2));
}
main();