@n1xyz/nord-ts 0.0.1

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 (141) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +20 -0
  3. package/.prettierignore +1 -0
  4. package/README.md +110 -0
  5. package/dist/abis/ERC20_ABI.d.ts +39 -0
  6. package/dist/abis/ERC20_ABI.js +313 -0
  7. package/dist/abis/NORD_GETTERS_FACET_ABI.d.ts +34 -0
  8. package/dist/abis/NORD_GETTERS_FACET_ABI.js +195 -0
  9. package/dist/abis/NORD_RAMP_FACET_ABI.d.ts +35 -0
  10. package/dist/abis/NORD_RAMP_FACET_ABI.js +144 -0
  11. package/dist/abis/index.d.ts +3 -0
  12. package/dist/abis/index.js +9 -0
  13. package/dist/const.d.ts +11 -0
  14. package/dist/const.js +34 -0
  15. package/dist/gen/common.d.ts +63 -0
  16. package/dist/gen/common.js +205 -0
  17. package/dist/gen/nord.d.ts +705 -0
  18. package/dist/gen/nord.js +4784 -0
  19. package/dist/index.d.ts +5 -0
  20. package/dist/index.js +21 -0
  21. package/dist/nord/Nord.d.ts +76 -0
  22. package/dist/nord/Nord.js +376 -0
  23. package/dist/nord/NordImpl.d.ts +7 -0
  24. package/dist/nord/NordImpl.js +6 -0
  25. package/dist/nord/NordUser.d.ts +77 -0
  26. package/dist/nord/NordUser.js +249 -0
  27. package/dist/nord/actions.d.ts +101 -0
  28. package/dist/nord/actions.js +254 -0
  29. package/dist/nord/index.d.ts +2 -0
  30. package/dist/nord/index.js +9 -0
  31. package/dist/types.d.ts +343 -0
  32. package/dist/types.js +92 -0
  33. package/dist/utils.d.ts +114 -0
  34. package/dist/utils.js +257 -0
  35. package/docs/.nojekyll +1 -0
  36. package/docs/assets/highlight.css +92 -0
  37. package/docs/assets/icons.js +15 -0
  38. package/docs/assets/icons.svg +1 -0
  39. package/docs/assets/main.js +59 -0
  40. package/docs/assets/navigation.js +1 -0
  41. package/docs/assets/search.js +1 -0
  42. package/docs/assets/style.css +1415 -0
  43. package/docs/classes/Nord.html +44 -0
  44. package/docs/classes/NordUser.html +35 -0
  45. package/docs/classes/Subscriber.html +6 -0
  46. package/docs/enums/FillMode.html +5 -0
  47. package/docs/enums/KeyType.html +4 -0
  48. package/docs/enums/PeakTpsPeriodUnit.html +15 -0
  49. package/docs/enums/Side.html +3 -0
  50. package/docs/functions/assert.html +1 -0
  51. package/docs/functions/bigIntToProtoU128.html +4 -0
  52. package/docs/functions/checkPubKeyLength.html +1 -0
  53. package/docs/functions/checkedFetch.html +6 -0
  54. package/docs/functions/createWebSocketSubscription.html +12 -0
  55. package/docs/functions/decodeLengthDelimited.html +10 -0
  56. package/docs/functions/encodeLengthDelimited.html +6 -0
  57. package/docs/functions/fillModeToProtoFillMode.html +5 -0
  58. package/docs/functions/findMarket.html +1 -0
  59. package/docs/functions/findToken.html +1 -0
  60. package/docs/functions/makeWalletSignFn.html +6 -0
  61. package/docs/functions/optExpect.html +5 -0
  62. package/docs/functions/optMap.html +5 -0
  63. package/docs/functions/optUnwrap.html +2 -0
  64. package/docs/functions/panic.html +1 -0
  65. package/docs/functions/signAction.html +6 -0
  66. package/docs/functions/toScaledU128.html +8 -0
  67. package/docs/functions/toScaledU64.html +8 -0
  68. package/docs/index.html +21 -0
  69. package/docs/interfaces/Account.html +8 -0
  70. package/docs/interfaces/ActionInfo.html +8 -0
  71. package/docs/interfaces/ActionQuery.html +4 -0
  72. package/docs/interfaces/ActionResponse.html +8 -0
  73. package/docs/interfaces/ActionsExtendedInfo.html +10 -0
  74. package/docs/interfaces/ActionsQuery.html +5 -0
  75. package/docs/interfaces/ActionsResponse.html +6 -0
  76. package/docs/interfaces/AggregateMetrics.html +12 -0
  77. package/docs/interfaces/BlockQuery.html +6 -0
  78. package/docs/interfaces/BlockResponse.html +6 -0
  79. package/docs/interfaces/BlockSummary.html +8 -0
  80. package/docs/interfaces/BlockSummaryResponse.html +6 -0
  81. package/docs/interfaces/DeltaEvent.html +6 -0
  82. package/docs/interfaces/ERC20TokenInfo.html +5 -0
  83. package/docs/interfaces/Info.html +3 -0
  84. package/docs/interfaces/Market.html +6 -0
  85. package/docs/interfaces/MarketStats.html +7 -0
  86. package/docs/interfaces/MarketsStatsResponse.html +2 -0
  87. package/docs/interfaces/NordConfig.html +5 -0
  88. package/docs/interfaces/Order.html +6 -0
  89. package/docs/interfaces/OrderInfo.html +6 -0
  90. package/docs/interfaces/OrderbookOrder.html +6 -0
  91. package/docs/interfaces/OrderbookResponse.html +10 -0
  92. package/docs/interfaces/PerpMarketStats.html +5 -0
  93. package/docs/interfaces/RollmanActionExtendedInfo.html +4 -0
  94. package/docs/interfaces/RollmanActionInfo.html +4 -0
  95. package/docs/interfaces/RollmanActionResponse.html +4 -0
  96. package/docs/interfaces/RollmanActionsResponse.html +2 -0
  97. package/docs/interfaces/RollmanBlockResponse.html +3 -0
  98. package/docs/interfaces/SubscriberConfig.html +3 -0
  99. package/docs/interfaces/Token.html +5 -0
  100. package/docs/interfaces/Trade.html +5 -0
  101. package/docs/interfaces/TradeInfo.html +20 -0
  102. package/docs/interfaces/Trades.html +5 -0
  103. package/docs/interfaces/TradesQueryParams.html +10 -0
  104. package/docs/interfaces/TradesResponse.html +12 -0
  105. package/docs/modules.html +77 -0
  106. package/docs/types/BigIntValue.html +2 -0
  107. package/docs/variables/DEBUG_KEYS.html +1 -0
  108. package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -0
  109. package/docs/variables/DEV_CONTRACT_ADDRESS.html +1 -0
  110. package/docs/variables/DEV_TOKEN_INFOS.html +1 -0
  111. package/docs/variables/DEV_URL.html +1 -0
  112. package/docs/variables/ERC20_ABI.html +1 -0
  113. package/docs/variables/EVM_DEV_URL.html +1 -0
  114. package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +1 -0
  115. package/docs/variables/MAX_BUFFER_LEN.html +1 -0
  116. package/docs/variables/NORD_GETTERS_FACET_ABI.html +1 -0
  117. package/docs/variables/NORD_RAMP_FACET_ABI.html +1 -0
  118. package/docs/variables/SESSION_TTL.html +1 -0
  119. package/docs/variables/WEBSERVER_DEV_URL.html +1 -0
  120. package/docs/variables/ZERO_DECIMAL.html +1 -0
  121. package/jest.config.ts +9 -0
  122. package/nodemon.json +4 -0
  123. package/package.json +61 -0
  124. package/protoc-generate.sh +23 -0
  125. package/src/abis/ERC20_ABI.ts +310 -0
  126. package/src/abis/NORD_GETTERS_FACET_ABI.ts +192 -0
  127. package/src/abis/NORD_RAMP_FACET_ABI.ts +141 -0
  128. package/src/abis/index.ts +3 -0
  129. package/src/const.ts +39 -0
  130. package/src/gen/common.ts +280 -0
  131. package/src/gen/nord.ts +5666 -0
  132. package/src/index.ts +5 -0
  133. package/src/nord/Nord.ts +504 -0
  134. package/src/nord/NordImpl.ts +8 -0
  135. package/src/nord/NordUser.ts +469 -0
  136. package/src/nord/actions.ts +484 -0
  137. package/src/nord/index.ts +2 -0
  138. package/src/types.ts +393 -0
  139. package/src/utils.ts +300 -0
  140. package/tests/utils.spec.ts +154 -0
  141. package/tsconfig.json +24 -0
package/.eslintignore ADDED
@@ -0,0 +1 @@
1
+ src/gen/*
package/.eslintrc.js ADDED
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ es2021: true,
5
+ },
6
+ extends: [
7
+ "prettier",
8
+ "plugin:@typescript-eslint/eslint-recommended",
9
+ "plugin:@typescript-eslint/recommended",
10
+ ],
11
+ parser: "@typescript-eslint/parser",
12
+ plugins: ["@typescript-eslint"],
13
+ parserOptions: {
14
+ ecmaVersion: "latest",
15
+ sourceType: "module",
16
+ },
17
+ rules: {
18
+ "@typescript-eslint/no-explicit-any": "warn",
19
+ },
20
+ };
@@ -0,0 +1 @@
1
+ src/gen/*
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # nord-ts
2
+
3
+ This package provides an interface to interact with the Nord exchange. Functionality includes generating Action messages, signing with `Ed25119` and sending payloads. There are also various util functions and interfaces provided.
4
+
5
+ ## Installation
6
+
7
+ ### npm
8
+
9
+ ```bash
10
+ npm install nord-ts
11
+ ```
12
+
13
+ ### yarn
14
+
15
+ ```bash
16
+ yarn add nord-ts
17
+ ```
18
+
19
+ ## Features
20
+
21
+ - create a new client with a new user and a new session ( `createClient` )
22
+ - generate Action messages ( `deposit` | `withdraw` | `placeOrder` | `cancelOrderById` )
23
+ - Cryptographic support for `Ed25119` key types.
24
+ - Message signing and transmission capabilities.
25
+ - Data serialization and deserialization for protobuf.
26
+
27
+ ## Usage
28
+
29
+ ### Basic Examples
30
+
31
+ #### Client
32
+
33
+ ```typescript
34
+ import { Nord, types } from "nord-ts";
35
+
36
+ const c = await Nord.createClient({
37
+ url: 'http://localhost:3000',
38
+ privateKey: /* secp256k1 sec1 compressed secret key */,
39
+ });
40
+
41
+ const tokenId = 0;
42
+ try {
43
+ await c.deposit(tokenId, 10000000);
44
+ } catch (e) {
45
+ console.log(`couldn't do deposit, reason: ${e}`)
46
+ }
47
+
48
+ try {
49
+ await c.withdraw(tokenId, 100);
50
+ } catch (e) {
51
+ console.log(`couldn't do withdraw, reason: ${e}`)
52
+ }
53
+
54
+ const marketId = 0;
55
+ const size = 1;
56
+ const price = 1;
57
+ const isReduceOnly = false;
58
+ let orderID: number = 0;
59
+ try {
60
+ orderId = await c.placeOrder(
61
+ marketId,
62
+ Side.Ask,
63
+ FillMode.Limit,
64
+ isReduceOnly,
65
+ size,
66
+ price
67
+ );
68
+ } catch (e) {
69
+ console.log(`couldn't do placeOrder, reason: ${e}`)
70
+ }
71
+
72
+ try {
73
+ await c.cancelOrder(
74
+ marketId,
75
+ orderId
76
+ );
77
+ } catch (e) {
78
+ console.log(`couldn't do cancelOrder, reason: ${e}`)
79
+ }
80
+ ```
81
+
82
+ #### Subscriber
83
+
84
+ ```typescript
85
+ import { Subscriber } from "./nord";
86
+
87
+ const STREAM_URL =
88
+ "ws://localhost:3000/ws/trades@BTCUSDC&deltas@BTCUSDC&user@0";
89
+
90
+ const s = new Subscriber({
91
+ streamURL: STREAM_URL,
92
+ maxBufferLen: 100,
93
+ });
94
+ s.subsribe();
95
+ ```
96
+
97
+ ## Development
98
+
99
+ ### Install dependencies
100
+
101
+ ```bash
102
+ yarn
103
+ ```
104
+
105
+ ### Generate proto files
106
+
107
+ ````bash
108
+ yarn build
109
+ ```
110
+ ````
@@ -0,0 +1,39 @@
1
+ export declare const ERC20_ABI: ({
2
+ type: string;
3
+ name: string;
4
+ inputs: {
5
+ name: string;
6
+ type: string;
7
+ internalType: string;
8
+ }[];
9
+ outputs: {
10
+ name: string;
11
+ type: string;
12
+ internalType: string;
13
+ }[];
14
+ stateMutability: string;
15
+ anonymous?: undefined;
16
+ } | {
17
+ type: string;
18
+ name: string;
19
+ inputs: {
20
+ name: string;
21
+ type: string;
22
+ indexed: boolean;
23
+ internalType: string;
24
+ }[];
25
+ anonymous: boolean;
26
+ outputs?: undefined;
27
+ stateMutability?: undefined;
28
+ } | {
29
+ type: string;
30
+ name: string;
31
+ inputs: {
32
+ name: string;
33
+ type: string;
34
+ internalType: string;
35
+ }[];
36
+ outputs?: undefined;
37
+ stateMutability?: undefined;
38
+ anonymous?: undefined;
39
+ })[];
@@ -0,0 +1,313 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERC20_ABI = void 0;
4
+ exports.ERC20_ABI = [
5
+ {
6
+ type: "function",
7
+ name: "allowance",
8
+ inputs: [
9
+ {
10
+ name: "owner",
11
+ type: "address",
12
+ internalType: "address",
13
+ },
14
+ {
15
+ name: "spender",
16
+ type: "address",
17
+ internalType: "address",
18
+ },
19
+ ],
20
+ outputs: [
21
+ {
22
+ name: "",
23
+ type: "uint256",
24
+ internalType: "uint256",
25
+ },
26
+ ],
27
+ stateMutability: "view",
28
+ },
29
+ {
30
+ type: "function",
31
+ name: "approve",
32
+ inputs: [
33
+ {
34
+ name: "spender",
35
+ type: "address",
36
+ internalType: "address",
37
+ },
38
+ {
39
+ name: "value",
40
+ type: "uint256",
41
+ internalType: "uint256",
42
+ },
43
+ ],
44
+ outputs: [
45
+ {
46
+ name: "",
47
+ type: "bool",
48
+ internalType: "bool",
49
+ },
50
+ ],
51
+ stateMutability: "nonpayable",
52
+ },
53
+ {
54
+ type: "function",
55
+ name: "balanceOf",
56
+ inputs: [
57
+ {
58
+ name: "account",
59
+ type: "address",
60
+ internalType: "address",
61
+ },
62
+ ],
63
+ outputs: [
64
+ {
65
+ name: "",
66
+ type: "uint256",
67
+ internalType: "uint256",
68
+ },
69
+ ],
70
+ stateMutability: "view",
71
+ },
72
+ {
73
+ type: "function",
74
+ name: "decimals",
75
+ inputs: [],
76
+ outputs: [
77
+ {
78
+ name: "",
79
+ type: "uint8",
80
+ internalType: "uint8",
81
+ },
82
+ ],
83
+ stateMutability: "view",
84
+ },
85
+ {
86
+ type: "function",
87
+ name: "name",
88
+ inputs: [],
89
+ outputs: [
90
+ {
91
+ name: "",
92
+ type: "string",
93
+ internalType: "string",
94
+ },
95
+ ],
96
+ stateMutability: "view",
97
+ },
98
+ {
99
+ type: "function",
100
+ name: "symbol",
101
+ inputs: [],
102
+ outputs: [
103
+ {
104
+ name: "",
105
+ type: "string",
106
+ internalType: "string",
107
+ },
108
+ ],
109
+ stateMutability: "view",
110
+ },
111
+ {
112
+ type: "function",
113
+ name: "totalSupply",
114
+ inputs: [],
115
+ outputs: [
116
+ {
117
+ name: "",
118
+ type: "uint256",
119
+ internalType: "uint256",
120
+ },
121
+ ],
122
+ stateMutability: "view",
123
+ },
124
+ {
125
+ type: "function",
126
+ name: "transfer",
127
+ inputs: [
128
+ {
129
+ name: "to",
130
+ type: "address",
131
+ internalType: "address",
132
+ },
133
+ {
134
+ name: "value",
135
+ type: "uint256",
136
+ internalType: "uint256",
137
+ },
138
+ ],
139
+ outputs: [
140
+ {
141
+ name: "",
142
+ type: "bool",
143
+ internalType: "bool",
144
+ },
145
+ ],
146
+ stateMutability: "nonpayable",
147
+ },
148
+ {
149
+ type: "function",
150
+ name: "transferFrom",
151
+ inputs: [
152
+ {
153
+ name: "from",
154
+ type: "address",
155
+ internalType: "address",
156
+ },
157
+ {
158
+ name: "to",
159
+ type: "address",
160
+ internalType: "address",
161
+ },
162
+ {
163
+ name: "value",
164
+ type: "uint256",
165
+ internalType: "uint256",
166
+ },
167
+ ],
168
+ outputs: [
169
+ {
170
+ name: "",
171
+ type: "bool",
172
+ internalType: "bool",
173
+ },
174
+ ],
175
+ stateMutability: "nonpayable",
176
+ },
177
+ {
178
+ type: "event",
179
+ name: "Approval",
180
+ inputs: [
181
+ {
182
+ name: "owner",
183
+ type: "address",
184
+ indexed: true,
185
+ internalType: "address",
186
+ },
187
+ {
188
+ name: "spender",
189
+ type: "address",
190
+ indexed: true,
191
+ internalType: "address",
192
+ },
193
+ {
194
+ name: "value",
195
+ type: "uint256",
196
+ indexed: false,
197
+ internalType: "uint256",
198
+ },
199
+ ],
200
+ anonymous: false,
201
+ },
202
+ {
203
+ type: "event",
204
+ name: "Transfer",
205
+ inputs: [
206
+ {
207
+ name: "from",
208
+ type: "address",
209
+ indexed: true,
210
+ internalType: "address",
211
+ },
212
+ {
213
+ name: "to",
214
+ type: "address",
215
+ indexed: true,
216
+ internalType: "address",
217
+ },
218
+ {
219
+ name: "value",
220
+ type: "uint256",
221
+ indexed: false,
222
+ internalType: "uint256",
223
+ },
224
+ ],
225
+ anonymous: false,
226
+ },
227
+ {
228
+ type: "error",
229
+ name: "ERC20InsufficientAllowance",
230
+ inputs: [
231
+ {
232
+ name: "spender",
233
+ type: "address",
234
+ internalType: "address",
235
+ },
236
+ {
237
+ name: "allowance",
238
+ type: "uint256",
239
+ internalType: "uint256",
240
+ },
241
+ {
242
+ name: "needed",
243
+ type: "uint256",
244
+ internalType: "uint256",
245
+ },
246
+ ],
247
+ },
248
+ {
249
+ type: "error",
250
+ name: "ERC20InsufficientBalance",
251
+ inputs: [
252
+ {
253
+ name: "sender",
254
+ type: "address",
255
+ internalType: "address",
256
+ },
257
+ {
258
+ name: "balance",
259
+ type: "uint256",
260
+ internalType: "uint256",
261
+ },
262
+ {
263
+ name: "needed",
264
+ type: "uint256",
265
+ internalType: "uint256",
266
+ },
267
+ ],
268
+ },
269
+ {
270
+ type: "error",
271
+ name: "ERC20InvalidApprover",
272
+ inputs: [
273
+ {
274
+ name: "approver",
275
+ type: "address",
276
+ internalType: "address",
277
+ },
278
+ ],
279
+ },
280
+ {
281
+ type: "error",
282
+ name: "ERC20InvalidReceiver",
283
+ inputs: [
284
+ {
285
+ name: "receiver",
286
+ type: "address",
287
+ internalType: "address",
288
+ },
289
+ ],
290
+ },
291
+ {
292
+ type: "error",
293
+ name: "ERC20InvalidSender",
294
+ inputs: [
295
+ {
296
+ name: "sender",
297
+ type: "address",
298
+ internalType: "address",
299
+ },
300
+ ],
301
+ },
302
+ {
303
+ type: "error",
304
+ name: "ERC20InvalidSpender",
305
+ inputs: [
306
+ {
307
+ name: "spender",
308
+ type: "address",
309
+ internalType: "address",
310
+ },
311
+ ],
312
+ },
313
+ ];
@@ -0,0 +1,34 @@
1
+ export declare const NORD_GETTERS_FACET_ABI: ({
2
+ type: string;
3
+ name: string;
4
+ inputs: {
5
+ name: string;
6
+ type: string;
7
+ internalType: string;
8
+ }[];
9
+ outputs: {
10
+ name: string;
11
+ type: string;
12
+ internalType: string;
13
+ }[];
14
+ stateMutability: string;
15
+ } | {
16
+ type: string;
17
+ name: string;
18
+ inputs: {
19
+ name: string;
20
+ type: string;
21
+ internalType: string;
22
+ }[];
23
+ outputs: {
24
+ name: string;
25
+ type: string;
26
+ internalType: string;
27
+ components: {
28
+ name: string;
29
+ type: string;
30
+ internalType: string;
31
+ }[];
32
+ }[];
33
+ stateMutability: string;
34
+ })[];