@n1xyz/nord-ts 0.0.19 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/api/client.d.ts +14 -0
  2. package/dist/api/client.js +45 -0
  3. package/dist/bridge/client.d.ts +151 -0
  4. package/dist/bridge/client.js +434 -0
  5. package/dist/bridge/const.d.ts +23 -0
  6. package/dist/bridge/const.js +47 -0
  7. package/dist/bridge/index.d.ts +4 -0
  8. package/dist/bridge/index.js +23 -0
  9. package/dist/bridge/types.d.ts +120 -0
  10. package/dist/bridge/types.js +18 -0
  11. package/dist/bridge/utils.d.ts +64 -0
  12. package/dist/bridge/utils.js +131 -0
  13. package/dist/const.d.ts +8 -0
  14. package/dist/const.js +30 -0
  15. package/dist/gen/common.d.ts +68 -0
  16. package/dist/gen/common.js +215 -0
  17. package/dist/gen/nord.d.ts +882 -0
  18. package/dist/gen/nord.js +6520 -0
  19. package/dist/gen/openapi.d.ts +2244 -0
  20. package/dist/gen/openapi.js +6 -0
  21. package/dist/idl/bridge.d.ts +569 -0
  22. package/dist/idl/bridge.js +8 -0
  23. package/dist/idl/bridge.json +1506 -0
  24. package/dist/idl/index.d.ts +607 -0
  25. package/dist/idl/index.js +8 -0
  26. package/dist/index.d.ts +5 -0
  27. package/dist/index.js +21 -0
  28. package/dist/nord/api/actions.d.ts +135 -0
  29. package/dist/nord/api/actions.js +313 -0
  30. package/dist/nord/api/core.d.ts +16 -0
  31. package/dist/nord/api/core.js +93 -0
  32. package/dist/nord/api/market.d.ts +36 -0
  33. package/dist/nord/api/market.js +96 -0
  34. package/dist/nord/api/metrics.d.ts +67 -0
  35. package/dist/nord/api/metrics.js +229 -0
  36. package/dist/nord/api/queries.d.ts +46 -0
  37. package/dist/nord/api/queries.js +109 -0
  38. package/dist/nord/client/Nord.d.ts +282 -0
  39. package/dist/nord/client/Nord.js +531 -0
  40. package/dist/nord/client/NordUser.d.ts +340 -0
  41. package/dist/nord/client/NordUser.js +652 -0
  42. package/dist/nord/index.d.ts +7 -0
  43. package/dist/nord/index.js +31 -0
  44. package/dist/nord/models/Subscriber.d.ts +37 -0
  45. package/dist/nord/models/Subscriber.js +25 -0
  46. package/dist/nord/utils/NordError.d.ts +35 -0
  47. package/dist/nord/utils/NordError.js +49 -0
  48. package/dist/types.d.ts +260 -0
  49. package/dist/types.js +103 -0
  50. package/dist/utils.d.ts +98 -0
  51. package/dist/utils.js +237 -0
  52. package/dist/websocket/NordWebSocketClient.d.ts +68 -0
  53. package/dist/websocket/NordWebSocketClient.js +343 -0
  54. package/dist/websocket/events.d.ts +19 -0
  55. package/dist/websocket/events.js +2 -0
  56. package/dist/websocket/index.d.ts +2 -0
  57. package/dist/websocket/index.js +5 -0
  58. package/package.json +7 -1
  59. package/src/gen/.gitkeep +0 -0
  60. package/src/gen/nord.ts +7593 -0
  61. package/src/gen/openapi.ts +2245 -0
  62. package/.claude/settings.local.json +0 -11
  63. package/.local/qa.ts +0 -77
  64. package/.local/test-atomic.ts +0 -112
  65. package/.prettierignore +0 -2
  66. package/check.sh +0 -4
  67. package/default.nix +0 -47
  68. package/eslint.config.mjs +0 -66
  69. package/tests/utils.spec.ts +0 -121
  70. package/tsconfig.eslint.json +0 -12
  71. package/tsconfig.json +0 -24
@@ -1,11 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(rg:*)",
5
- "Bash(grep:*)",
6
- "Bash(npm run build:*)",
7
- "Bash(bun run:*)"
8
- ],
9
- "deny": []
10
- }
11
- }
package/.local/qa.ts DELETED
@@ -1,77 +0,0 @@
1
- // quick script i use to qa sdk against deployed instance. this
2
- // will no longer be needed once we have proper integration tests.
3
-
4
- import { Nord, NordUser } from "../src";
5
-
6
- const nord = await Nord.initNord({
7
- bridgeVk: "rbrpQMMPaVLSG3hTPZj2GLKxGLbPM2q7gDxc7BTync6",
8
- initWebSockets: false,
9
- solanaUrl: "https://api.devnet.solana.com",
10
- webServerUrl: "https://zo-devnet-rc.n1.xyz",
11
- });
12
-
13
- const poky = await nord.getUser({
14
- pubkey: "GSPX6qX4bs8oTU3n5A1Xx8q9MPiGFyxWhMtuVvpZNK52",
15
- });
16
-
17
- console.log("user", poky);
18
-
19
- if (!poky) {
20
- throw new Error("No user found");
21
- }
22
-
23
- console.log("account", await nord.getAccount(poky.accountIds[0]));
24
- console.log("timestamp", await nord.getTimestamp());
25
- console.log("actionNonce", await nord.getActionNonce());
26
- console.log("lastActionId", await nord.getLastActionId());
27
- console.log("info", await nord.getInfo());
28
-
29
- console.log(
30
- "marketStats",
31
- await nord.getMarketStats({
32
- marketId: 1,
33
- }),
34
- );
35
-
36
- console.log(
37
- "orderbook",
38
- await nord.getOrderbook({
39
- market_id: 1,
40
- }),
41
- );
42
-
43
- const since = new Date();
44
- since.setMinutes(0);
45
-
46
- console.log(
47
- "trades",
48
- await nord.getTrades({
49
- takerId: poky.accountIds[0],
50
- sinceRcf3339: since.toISOString(),
51
- untilRfc3339: new Date().toISOString(),
52
- pageId: "0",
53
- }),
54
- );
55
-
56
- console.log(
57
- "recentActions",
58
- await nord.queryRecentActions({
59
- from: 6,
60
- to: 6,
61
- }),
62
- );
63
-
64
- console.log("action", await nord.queryAction({ action_id: 0 }));
65
- console.log("action", await nord.queryAction({ action_id: 1 }));
66
- console.log("action", await nord.queryAction({ action_id: 2 }));
67
- console.log("action", await nord.queryAction({ action_id: 5 }));
68
- console.log("action", await nord.queryAction({ action_id: 100 }));
69
-
70
- const user = NordUser.fromPrivateKey(
71
- nord,
72
- new Uint8Array(JSON.parse(process.env.PRIVATE_KEY!)),
73
- );
74
-
75
- console.log("deposit", await user.deposit({ amount: 2.0, tokenId: 0 }));
76
- await user.refreshSession();
77
- console.log("withdraw", await user.withdraw({ amount: 2.0, tokenId: 0 }));
@@ -1,112 +0,0 @@
1
- import { NordWebSocketClient } from "../src/websocket/NordWebSocketClient";
2
-
3
- /**
4
- * All event types that we track in the counters object. Keeping this
5
- * union type explicit lets TypeScript validate that we use the same
6
- * keys everywhere and prevents typos.
7
- */
8
- export type CounterKeys =
9
- | "trade"
10
- | "delta"
11
- | "account"
12
- | "error"
13
- | "disconnected";
14
-
15
- interface Endpoint {
16
- /** WebSocket endpoint URL */
17
- url: string;
18
- /** Streams we want to subscribe to once connected (can be empty) */
19
- streams: string[];
20
- }
21
-
22
- /**
23
- * Web‑socket endpoints to test. Keep this list short & focused so the smoke
24
- * test finishes quickly inside CI.
25
- */
26
- const endpoints: Endpoint[] = [
27
- // {
28
- // url: "wss://staging.n1.xyz/ws/",
29
- // streams: [], // no runtime subscribe call needed
30
- // },
31
-
32
- // {
33
- // url: `wss://staging.n1.xyz/ws/account@${process.env.NORD_ACCOUNT_ID ?? "3"}`,
34
- // streams: [],
35
- // },
36
-
37
- {
38
- url: `wss://zo-devnet-rc.n1.xyz/ws/trades@ETHPERP`,
39
- streams: ["trades@ETHPERP"],
40
- },
41
- ];
42
-
43
- /** How long each endpoint should be observed for (default: 15 s) */
44
- // const TEST_DURATION_MS = Number(process.env.TEST_DURATION_MS ?? 15_000);
45
- const TEST_DURATION_MS = 15_000;
46
-
47
- /**
48
- * Simple message counters for every event type the client can emit.
49
- * This is mutated by the event handlers during the test run.
50
- */
51
- const counters: Record<CounterKeys, number> = {
52
- trade: 0,
53
- delta: 0,
54
- account: 0,
55
- error: 0,
56
- disconnected: 0,
57
- };
58
-
59
- /**
60
- * Connect to a single endpoint, wait for activity, then verify we received the
61
- * expected events.
62
- */
63
- async function smokeTest(endpoint: Endpoint): Promise<void> {
64
- console.log(`🛰️ Connecting to ${endpoint.url} …`);
65
- const client = new NordWebSocketClient(endpoint.url);
66
- client.connect();
67
-
68
- client.on("connected", () => {
69
- console.log("✅ connected");
70
- });
71
-
72
- client.on("disconnected", () => {
73
- console.log("⚠️ disconnected");
74
- counters.disconnected++;
75
- });
76
-
77
- client.on("error", (err: unknown) => {
78
- console.error("❌ error:", err);
79
- counters.error++;
80
- });
81
-
82
- client.on("trades", (m) => {
83
- console.log({ m });
84
- counters.trade++;
85
- });
86
- client.on("deltas", (m) => {
87
- console.log({ m });
88
- counters.delta++;
89
- });
90
- client.on("accounts", (m) => {
91
- console.log({ m });
92
- counters.account++;
93
- });
94
-
95
- // Wait a bit, then close and report
96
- await new Promise((resolve) => setTimeout(resolve, TEST_DURATION_MS));
97
- client.close();
98
- }
99
-
100
- (async () => {
101
- try {
102
- for (const ep of endpoints) {
103
- await smokeTest(ep);
104
- }
105
- console.log("\n🎉 All websocket endpoints responded as expected:");
106
- console.table(counters);
107
- } catch (e) {
108
- console.error("\n🔴 Smoke test failed:", (e as Error).message);
109
- console.table(counters);
110
- process.exitCode = 1;
111
- }
112
- })();
package/.prettierignore DELETED
@@ -1,2 +0,0 @@
1
- src/gen/*
2
- src/idl/*.json
package/check.sh DELETED
@@ -1,4 +0,0 @@
1
- npm install
2
- npm build
3
- npm run test
4
- npm run ci
package/default.nix DELETED
@@ -1,47 +0,0 @@
1
- { inputs, ... }:
2
- {
3
- perSystem =
4
- {
5
- pkgs,
6
- self',
7
- system,
8
- ...
9
- }:
10
- {
11
- packages = {
12
- nord-ts-proto =
13
- let
14
- ts-proto = inputs.n1.packages.${system}.ts-proto;
15
- in
16
- pkgs.writeShellApplication {
17
- name = "nord-ts-proto";
18
- runtimeInputs = [ pkgs.protobuf ];
19
- text = ''
20
- if [ $# -ne 2 ]; then
21
- echo >&2 "usage: $(basename "$0") <proto-file> <out-dir>"
22
- exit 1
23
- fi
24
- readonly PROTO_FILE="$1"
25
- readonly OUT_DIR="$2"
26
- protoc \
27
- --plugin="${ts-proto}/bin/protoc-gen-ts_proto" \
28
- --ts_proto_opt=forceLong=bigint \
29
- --ts_proto_opt=esModuleInterop=true \
30
- --ts_proto_opt=oneof=unions-value \
31
- --ts_proto_opt=unrecognizedEnum=false \
32
- --ts_proto_out="$OUT_DIR" \
33
- --proto_path="$(dirname "$PROTO_FILE")" \
34
- "$PROTO_FILE"
35
- '';
36
- };
37
- nord-ts-check = pkgs.writeShellApplication {
38
- name = "ts-check";
39
- runtimeInputs = [
40
- pkgs.protobuf
41
- pkgs.pnpm
42
- ];
43
- text = builtins.readFile ./check.sh;
44
- };
45
- };
46
- };
47
- }
package/eslint.config.mjs DELETED
@@ -1,66 +0,0 @@
1
- import typescriptEslint from "@typescript-eslint/eslint-plugin";
2
- import globals from "globals";
3
- import tsParser from "@typescript-eslint/parser";
4
- import path from "node:path";
5
- import { fileURLToPath } from "node:url";
6
- import js from "@eslint/js";
7
- import { FlatCompat } from "@eslint/eslintrc";
8
-
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = path.dirname(__filename);
11
- const compat = new FlatCompat({
12
- baseDirectory: __dirname,
13
- recommendedConfig: js.configs.recommended,
14
- allConfig: js.configs.all,
15
- });
16
-
17
- export default [
18
- {
19
- ignores: [
20
- "**/dist",
21
- "**/node_modules",
22
- "**/.git",
23
- "**/docs",
24
- "src/gen/*",
25
- "*.mjs",
26
- "*.js",
27
- ],
28
- },
29
- ...compat.extends(
30
- "plugin:@typescript-eslint/eslint-recommended",
31
- "plugin:@typescript-eslint/recommended",
32
- ),
33
- {
34
- plugins: {
35
- "@typescript-eslint": typescriptEslint,
36
- },
37
-
38
- languageOptions: {
39
- globals: {
40
- ...globals.browser,
41
- ...globals.node,
42
- },
43
-
44
- parser: tsParser,
45
- ecmaVersion: "latest",
46
- sourceType: "module",
47
-
48
- parserOptions: {
49
- project: ["./tsconfig.json", "./tsconfig.eslint.json"],
50
- tsconfigRootDir: ".",
51
- },
52
- },
53
-
54
- rules: {
55
- "@typescript-eslint/no-explicit-any": "off",
56
-
57
- "@typescript-eslint/no-unused-vars": [
58
- "warn",
59
- {
60
- argsIgnorePattern: "^_",
61
- varsIgnorePattern: "^_",
62
- },
63
- ],
64
- },
65
- },
66
- ];
@@ -1,121 +0,0 @@
1
- import { describe, it, expect } from "@jest/globals";
2
- import {
3
- toScaledU64,
4
- toScaledU128,
5
- encodeLengthDelimited,
6
- decodeLengthDelimited,
7
- } from "../src/utils";
8
- import Decimal from "decimal.js";
9
- import * as proto from "../src/gen/nord";
10
-
11
- describe("toScaledU64", () => {
12
- // Used as scaling medium
13
- const D64 = Decimal.clone({
14
- precision: 20,
15
- toExpPos: 20,
16
- toExpNeg: -20,
17
- });
18
-
19
- const MaxDec = new D64(2).pow(64).sub(1);
20
- const MaxUint = BigInt(MaxDec.toString());
21
-
22
- const success: Array<[Decimal.Value, number, bigint]> = [
23
- [0, 0, 0n],
24
- [1, 0, 1n],
25
- [123.45, 3, 123450n],
26
- [MaxDec, 0, MaxUint],
27
- [MaxDec.div(1000), 3, MaxUint],
28
- ];
29
-
30
- success.forEach((sample) => {
31
- it(`Convert decimal ${sample[0]}*10^${sample[1]} to bignum ${sample[2]} should succeed`, () => {
32
- expect(toScaledU64(sample[0], sample[1])).toEqual(sample[2]);
33
- });
34
- });
35
-
36
- const failure: Array<[Decimal.Value, number, string]> = [
37
- [-1, 0, "Number is negative"],
38
- [-1000, 2, "Number is negative"],
39
- [0.1, 0, "Precision loss"],
40
- [0.0001, 3, "Precision loss"],
41
- [MaxDec.add(1), 0, "Integer is out of range"],
42
- [MaxDec.add(1).div(1000), 3, "Integer is out of range"],
43
- ];
44
-
45
- failure.forEach((sample) => {
46
- it(`Convert decimal ${sample[0]}/10^${sample[1]} to bignum should fail with ${sample[2]} `, () => {
47
- expect(() => toScaledU64(sample[0], sample[1])).toThrow(sample[2]);
48
- });
49
- });
50
- });
51
-
52
- describe("toScaledU128", () => {
53
- // Used as scaling medium
54
- const D128 = Decimal.clone({
55
- precision: 40,
56
- toExpPos: 40,
57
- toExpNeg: -40,
58
- });
59
-
60
- const MaxDec = new D128(2).pow(128).sub(1);
61
- const MaxUint = BigInt(MaxDec.toString());
62
-
63
- const success: Array<[Decimal.Value, number, bigint]> = [
64
- [0, 0, 0n],
65
- [1, 0, 1n],
66
- [123.45, 3, 123450n],
67
- [MaxDec, 0, MaxUint],
68
- [MaxDec.div(1000), 3, MaxUint],
69
- ];
70
-
71
- success.forEach((sample) => {
72
- it(`Convert decimal ${sample[0]}*10^${sample[1]} to bignum ${sample[2]} should succeed`, () => {
73
- expect(toScaledU128(sample[0], sample[1])).toEqual(sample[2]);
74
- });
75
- });
76
-
77
- const failure: Array<[Decimal.Value, number, string]> = [
78
- [-1, 0, "Number is negative"],
79
- [-1000, 2, "Number is negative"],
80
- [0.1, 0, "Precision loss"],
81
- [0.0001, 3, "Precision loss"],
82
- [MaxDec.add(1), 0, "Integer is out of range"],
83
- [MaxDec.add(1).div(1000), 3, "Integer is out of range"],
84
- ];
85
-
86
- failure.forEach((sample) => {
87
- it(`Convert decimal ${sample[0]}/10^${sample[1]} to bignum should fail with ${sample[2]} `, () => {
88
- expect(() => toScaledU128(sample[0], sample[1])).toThrow(sample[2]);
89
- });
90
- });
91
- });
92
-
93
- describe("proto.Action encode-decode loop", () => {
94
- const action: proto.Action = {
95
- currentTimestamp: 0n,
96
- nonce: 0,
97
- kind: {
98
- $case: "placeOrder",
99
- value: {
100
- sessionId: 42n,
101
- marketId: 9,
102
- fillMode: proto.FillMode.LIMIT,
103
- side: proto.Side.ASK,
104
- isReduceOnly: false,
105
- price: 12n,
106
- size: 39n,
107
- quoteSize: { size: 54n, price: 55n },
108
- senderAccountId: undefined,
109
- delegatorAccountId: undefined,
110
- clientOrderId: 350n,
111
- },
112
- },
113
- };
114
-
115
- it("action encode-decode roundabout should succeed", () => {
116
- const encoded = encodeLengthDelimited(action, proto.Action);
117
- const decoded: proto.Action = decodeLengthDelimited(encoded, proto.Action);
118
-
119
- expect(decoded).toEqual(action);
120
- });
121
- });
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "."
6
- },
7
- "include": [
8
- "src/**/*.ts",
9
- "tests/**/*.ts",
10
- "jest.config.ts"
11
- ]
12
- }
package/tsconfig.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "declaration": true,
4
- "target": "es2020",
5
- "lib": ["es2020", "dom"],
6
- "module": "commonjs",
7
- "rootDir": "./src",
8
- "moduleResolution": "Node",
9
- "outDir": "./dist",
10
- "esModuleInterop": true,
11
- "resolveJsonModule": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "strict": true,
14
- "skipLibCheck": true,
15
- },
16
- "typeAcquisition": {
17
- "include": [
18
- "jest",
19
- "@types/jest"
20
- ]
21
- },
22
- "exclude": ["dist", "**/node_modules/**/*"],
23
- "include": ["./src/**/*"]
24
- }