Files
discountry 7acb3c3b82 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.
2026-07-29 20:27:40 +08:00

56 lines
1.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { LighterSigner } from "../../src/exchanges/lighter/signer";
import { LIGHTER_ORDER_TYPE, LIGHTER_TIME_IN_FORCE } from "../../src/exchanges/lighter/constants";
describe("LighterSigner", () => {
it("produces deterministic create order signature", async () => {
const signer = new LighterSigner({
accountIndex: 65,
chainId: 300,
apiKeys: {
3: "0xed636277f3753b6c0275f7a28c2678a7f3a95655e09deaebec15179b50c5da7f903152e50f594f7b",
},
});
const signed = await signer.signCreateOrder({
marketIndex: 0,
clientOrderIndex: 123n,
baseAmount: 1000n,
price: 170000,
isAsk: 1,
orderType: LIGHTER_ORDER_TYPE.MARKET,
timeInForce: LIGHTER_TIME_IN_FORCE.IMMEDIATE_OR_CANCEL,
reduceOnly: 0,
triggerPrice: 0,
orderExpiry: 0n,
expiredAt: 1700000000000n,
apiKeyIndex: 3,
nonce: 42n,
});
const payload = JSON.parse(signed.txInfo);
expect(payload.AccountIndex).toBe(65);
expect(payload.ApiKeyIndex).toBe(3);
expect(payload).toMatchObject({
MarketIndex: 0,
ClientOrderIndex: 123,
BaseAmount: 1000,
Price: 170000,
IsAsk: 1,
Type: LIGHTER_ORDER_TYPE.MARKET,
TimeInForce: LIGHTER_TIME_IN_FORCE.IMMEDIATE_OR_CANCEL,
ReduceOnly: 0,
TriggerPrice: 0,
OrderExpiry: 0,
});
expect(typeof payload.Sig).toBe("string");
expect(payload.Sig.length).toBeGreaterThan(0);
if (signed.txHash) {
expect(typeof signed.txHash).toBe("string");
expect(signed.txHash.length).toBeGreaterThan(0);
}
expect(typeof signed.signature).toBe("string");
expect(signed.signature?.length ?? 0).toBeGreaterThan(0);
});
});