@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
@@ -0,0 +1,705 @@
1
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
+ import { Message } from "./common";
3
+ export declare const protobufPackage = "nord";
4
+ export declare enum Side {
5
+ ASK = 0,
6
+ BID = 1
7
+ }
8
+ export declare function sideFromJSON(object: any): Side;
9
+ export declare function sideToJSON(object: Side): string;
10
+ export declare enum TriggerKind {
11
+ STOP_LOSS = 0,
12
+ TAKE_PROFIT = 1
13
+ }
14
+ export declare function triggerKindFromJSON(object: any): TriggerKind;
15
+ export declare function triggerKindToJSON(object: TriggerKind): string;
16
+ export declare enum FillMode {
17
+ LIMIT = 0,
18
+ POST_ONLY = 1,
19
+ IMMEDIATE_OR_CANCEL = 2,
20
+ FILL_OR_KILL = 3
21
+ }
22
+ export declare function fillModeFromJSON(object: any): FillMode;
23
+ export declare function fillModeToJSON(object: FillMode): string;
24
+ export declare enum MarketType {
25
+ SPOT = 0,
26
+ PERPETUALS = 1
27
+ }
28
+ export declare function marketTypeFromJSON(object: any): MarketType;
29
+ export declare function marketTypeToJSON(object: MarketType): string;
30
+ /**
31
+ * Error codes returned by the engine.
32
+ * Some errors has 5bit prefix about error source and 3 bit suffix specifier.
33
+ * Error source prefix indicates were too look into to fix error.
34
+ * For example if order has bad input, it would be order relevant prefix.
35
+ * But if order cannot apply results to balance, it would be balance relevant
36
+ * prefix.
37
+ */
38
+ export declare enum Error {
39
+ DUPLICATE = 0,
40
+ TIMESTAMP_STALE = 1,
41
+ DECODE_FAILURE = 2,
42
+ INVALID_SIGNATURE = 3,
43
+ MARKET_NOT_FOUND = 4,
44
+ TOKEN_NOT_FOUND = 5,
45
+ USER_NOT_FOUND = 6,
46
+ SESSION_NOT_FOUND = 7,
47
+ ORDER_NOT_FOUND = 8,
48
+ ORDER_SIZE_ZERO = 9,
49
+ ARITHMETIC_OVERFLOW = 11,
50
+ RISK_TOO_HIGH = 12,
51
+ INVALID_ORDER_OWNER = 14,
52
+ KEY_ALREADY_REGISTERED = 15,
53
+ EXPIRY_TIMESTAMP_IN_PAST = 16,
54
+ UPDATE_TIMESTAMP_IN_PAST = 17,
55
+ TOO_MANY_OPEN_ORDERS = 18,
56
+ INVALID_ACTION_NONCE = 20,
57
+ WITHDRAW_AMOUNT_TOO_SMALL = 21,
58
+ PYTH_FEED_NOT_ADDED = 93,
59
+ PYTH_FEED_MISSING = 94,
60
+ PYTH_FEED_ALREADY_ADDED = 95,
61
+ PYTH_GUARDIAN_SET_UNINITIALIZED = 96,
62
+ PYTH_GUARDIAN_SET_INVALID = 97,
63
+ /** UNINITIALIZED_PRICES - TODO(deprecate) */
64
+ UNINITIALIZED_PRICES = 98,
65
+ PYTH_FEED_PRICE_OUT_OF_RANGE = 99,
66
+ INVALID_TOKEN_PARAMETERS = 100,
67
+ INDEX_PRICE_OUT_OF_RANGE = 103,
68
+ INDEX_DECIMALS_OUT_OF_RANGE = 104,
69
+ INVALID_STATE_VERSION = 105,
70
+ POSITION_STATE_IS_WRONG_FOR_ORDER = 106,
71
+ INVALID_MARGINS = 107,
72
+ /** ACTION_CANNOT_BE_DELEGATED - means that user cannot execute proposed action on behalf of different user */
73
+ ACTION_CANNOT_BE_DELEGATED = 108,
74
+ /**
75
+ * MARKET_DECIMALS_EXCEED_LIMITS - Market's decimal parameters exceed either "quote limit" or "base limit"
76
+ * Two mentioned limits were deduced empirically and ensure
77
+ * that certain overflow errors don't happen when value rescaling is performed
78
+ * during order placement.
79
+ *
80
+ * For both perpetuals and spot markets,
81
+ * `quote_token.decimals - market.size_decimals - market.price_decimals` must
82
+ * be within range `[-19; 4]` For spot market, `base_token.decimals -
83
+ * market.size_decimals` must be within range `[-19; 23]`
84
+ */
85
+ MARKET_DECIMALS_EXCEED_LIMITS = 109,
86
+ TOO_MANY_TOKENS = 110,
87
+ BANKRUPTCY = 111,
88
+ /** TOKEN_ALREADY_REGISTERED - Token with specified blockchain address already registered */
89
+ TOKEN_ALREADY_REGISTERED = 112,
90
+ FUNDING_OVERFLOW = 123,
91
+ /**
92
+ * CAN_REDUCE_POSITION_ONLY_IF_ALL_ORDERS_ARE_CANCELED - If there is order to cancel for position, it should be canceled first
93
+ * before reducing position
94
+ */
95
+ CAN_REDUCE_POSITION_ONLY_IF_ALL_ORDERS_ARE_CANCELED = 124,
96
+ PYTH_GUARDIAN_SET_AND_PYTH_SIGNATURE_DO_NOT_MATCH = 126,
97
+ /** UNEXPECTED_TOKEN_ID - Token was found, but not expected to be used in action context */
98
+ UNEXPECTED_TOKEN_ID = 127,
99
+ SIGNATURE_VERIFICATION = 128,
100
+ /** MARKET_NOT_READY - Happens when market is not read to handle orders */
101
+ MARKET_NOT_READY = 129,
102
+ /**
103
+ * TOKEN_NOT_READY - happens in some situation when token misses some relevant information
104
+ * needed for operation
105
+ */
106
+ TOKEN_NOT_READY = 130,
107
+ OMF_LESS_THAN_OR_EQUAL_IMF = 131,
108
+ ORDER_ON_UNHEALTHY_ACCOUNT_CAN_ONLY_IMPROVE = 132,
109
+ IMMEDIATE_ORDER_GOT_NO_FILLS = 133,
110
+ /** FAILED_TO_FILL_LIMIT - In case there's no price, error if failed to fill at least one of limits */
111
+ FAILED_TO_FILL_LIMIT = 134,
112
+ POST_ONLY_MUST_NOT_FILL_ANY_OPPOSITE_ORDERS = 135,
113
+ INVALID = 136,
114
+ MAINTENANCE = 137,
115
+ MINIMUM_SIZE_DECIMALS = 138,
116
+ PARAMETERS_WILL_CREATE_NON_OPERATIONAL_MARKET = 139,
117
+ ONLY_IMMEDIATE_ORDERS_ALLOWED = 140,
118
+ TOO_MANY_USER_ACCOUNTS = 141,
119
+ /** ACCOUNT_NOT_FOUND - There's no such account with specified id, */
120
+ ACCOUNT_NOT_FOUND = 142,
121
+ /** ACCOUNT_INVALID_OWNER - Account doesn't belong to user designated by public key or session id */
122
+ ACCOUNT_INVALID_OWNER = 143,
123
+ /**
124
+ * DUST_ACCOUNT - Operation cannot be made on account because to small amount will be
125
+ * retained on account
126
+ */
127
+ DUST_ACCOUNT = 145,
128
+ /** ORDER_EXECUTION - 10011_000 - 3 bit suffix */
129
+ ORDER_EXECUTION = 152,
130
+ /** ORDER_EXECUTION_EMPTY - 10011_001; */
131
+ ORDER_EXECUTION_EMPTY = 153,
132
+ /** ORDER_EXECUTION_FILL_OR_KILL - 10011_010; */
133
+ ORDER_EXECUTION_FILL_OR_KILL = 154,
134
+ /**
135
+ * ORDER_EXECUTION_MISSING_LIMITS - Order requires some of its limits specified according to fill mode
136
+ * 10011_011;
137
+ */
138
+ ORDER_EXECUTION_MISSING_LIMITS = 155,
139
+ /** ORDER_EXECUTION_MISSING_PRICE - 10011_100; */
140
+ ORDER_EXECUTION_MISSING_PRICE = 156,
141
+ /** ORDER_EXECUTION_SIZE_LIMIT - 10011_101; */
142
+ ORDER_EXECUTION_SIZE_LIMIT = 157,
143
+ /** BALANCE - 10100_000 */
144
+ BALANCE = 160,
145
+ /** BALANCE_DEPOSIT_OVERFLOW - 10100_001 */
146
+ BALANCE_DEPOSIT_OVERFLOW = 161,
147
+ /** BALANCE_CHANGE_OVERFLOW - 10100_010 */
148
+ BALANCE_CHANGE_OVERFLOW = 162,
149
+ /** BALANCE_CHANGE_LIMIT_EXCEEDED - 10100_011 */
150
+ BALANCE_CHANGE_LIMIT_EXCEEDED = 163,
151
+ /**
152
+ * BALANCE_INSUFFICIENT - Happens when account balances has no sufficient token amount to perform
153
+ * action.
154
+ * 10100_100
155
+ */
156
+ BALANCE_INSUFFICIENT = 164,
157
+ /**
158
+ * UNAUTHENTICATED_L1_ACTION - Happens when an action is meant to come from the settlement contract,
159
+ * but is not authenticated, instead coming from the user channels.
160
+ */
161
+ UNAUTHENTICATED_L1_ACTION = 165,
162
+ /**
163
+ * ENCODED_ACTION_TOO_LARGE - Happens when an encoded action is too large. This is to mitigate dos
164
+ * attacks due to excessive padding.
165
+ */
166
+ ENCODED_ACTION_TOO_LARGE = 166,
167
+ /** TRIGGER - 10101_000 */
168
+ TRIGGER = 168,
169
+ /**
170
+ * TRIGGER_INVALID_PRICE - Happens when:
171
+ * * Trigger price is "less or equal" to its corresponding pair trigger price
172
+ * * Trigger rice is "less" than market's current index price
173
+ *
174
+ * Binary pattern: 10101_001
175
+ */
176
+ TRIGGER_INVALID_PRICE = 169,
177
+ Dropped = 999
178
+ }
179
+ export declare function errorFromJSON(object: any): Error;
180
+ export declare function errorToJSON(object: Error): string;
181
+ /** Emulation of 128-bit integers since Protobuf doesn't have native support */
182
+ export interface U128 {
183
+ /** Low 64-bit word */
184
+ lo: bigint;
185
+ /** High 64-bit word */
186
+ hi: bigint;
187
+ }
188
+ export interface Market {
189
+ marketId: number;
190
+ priceDecimals: number;
191
+ sizeDecimals: number;
192
+ baseTokenId: number;
193
+ marketType: MarketType;
194
+ imfBps: number;
195
+ cmfBps: number;
196
+ mmfBps: number;
197
+ viewSymbol: string;
198
+ }
199
+ export interface Token {
200
+ tokenId: number;
201
+ /** / See CreateToken for details. */
202
+ tokenDecimals: number;
203
+ weightBps: number;
204
+ viewSymbol: string;
205
+ }
206
+ export interface Action {
207
+ /**
208
+ * Must be within 60s of the engine's current logical time, which
209
+ * should be within a few seconds of real time.
210
+ *
211
+ * Ignored for the `PythPriceFeedUpdate` action as that action updates
212
+ * the timestamp. Should be set to 0 in that case to omit it.
213
+ */
214
+ currentTimestamp: bigint;
215
+ /**
216
+ * Optional nonce to handle if user wants several identical transactions to be
217
+ * executed with `current_timestamp`. Sending exactly same transaction twice
218
+ * is rejected. In order to change signature of transaction(execute it once
219
+ * more time), nonce should be changed(incremented).
220
+ */
221
+ nonce: number;
222
+ kind?: {
223
+ $case: "createSession";
224
+ value: Action_CreateSession;
225
+ } | {
226
+ $case: "createToken";
227
+ value: Action_CreateToken;
228
+ } | {
229
+ $case: "createMarket";
230
+ value: Action_CreateMarket;
231
+ } | {
232
+ $case: "placeOrder";
233
+ value: Action_PlaceOrder;
234
+ } | {
235
+ $case: "cancelOrderById";
236
+ value: Action_CancelOrderById;
237
+ } | {
238
+ $case: "deposit";
239
+ value: Action_Deposit;
240
+ } | {
241
+ $case: "withdraw";
242
+ value: Action_Withdraw;
243
+ } | {
244
+ $case: "pythSetWormholeGuardians";
245
+ value: Action_PythSetWormholeGuardians;
246
+ } | {
247
+ $case: "pythSetSymbolFeed";
248
+ value: Action_PythSetSymbolFeed;
249
+ } | {
250
+ $case: "pythPriceFeedUpdate";
251
+ value: Action_PythPriceFeedUpdate;
252
+ } | {
253
+ $case: "liquidate";
254
+ value: Action_Liquidate;
255
+ } | {
256
+ $case: "revokeSession";
257
+ value: Action_RevokeSession;
258
+ } | {
259
+ $case: "pause";
260
+ value: Action_Pause;
261
+ } | {
262
+ $case: "unpause";
263
+ value: Action_Unpause;
264
+ } | {
265
+ $case: "transfer";
266
+ value: Action_Transfer;
267
+ } | {
268
+ $case: "message";
269
+ value: Message;
270
+ } | {
271
+ $case: "addTrigger";
272
+ value: Action_AddTrigger;
273
+ } | {
274
+ $case: "removeTrigger";
275
+ value: Action_RemoveTrigger;
276
+ } | undefined;
277
+ }
278
+ export interface Action_CreateSession {
279
+ /**
280
+ * User's SECP256K1 registration public key, 33 bytes long;
281
+ * user must be previously registered with that key
282
+ */
283
+ userPubkey: Uint8Array;
284
+ /** MUST be 32 bytes. */
285
+ blstPubkey: Uint8Array;
286
+ expiryTimestamp: bigint;
287
+ }
288
+ export interface Action_CreateToken {
289
+ /**
290
+ * / Example:
291
+ * / Settlement 1 ETH is 10**18 value.
292
+ * / With `token_decimals` of `10`, engine balance will have 1 ETH = 10**10
293
+ * / value. Rollup sends to engine and expects from engine 10**10 as 1 ETH
294
+ * / value. So if user has on balance 10**9 of ETH, it means he has 0.1 ETH
295
+ * / on engine balance and in settlement, but in settlement it will be
296
+ * / represented as 10**17 value. As consequence, if oracle gives index_price
297
+ * / of 1 ETH as it is in Ethereum, we must divide balance by
298
+ * / `10**token_decimals` and multiply by price to get USD value (do not
299
+ * / forget allow for rounding sub USD values). As for market price, to trade
300
+ * / 0.1 ETH,
301
+ * need to 1/10 / 10**token_decimals * 10**Market.size_decimals
302
+ */
303
+ tokenDecimals: number;
304
+ weightBps: number;
305
+ viewSymbol: string;
306
+ /** / Used to bind to relevant oracle feed */
307
+ oracleSymbol: string;
308
+ /** On chain id for the wrapped asset on the rollup */
309
+ ethAddr: Uint8Array;
310
+ /** Minimum amount to withdraw per action to disincentivize spam. */
311
+ minWithdrawAmount: bigint;
312
+ }
313
+ export interface Action_CreateMarket {
314
+ sizeDecimals: number;
315
+ priceDecimals: number;
316
+ imfBps: number;
317
+ cmfBps: number;
318
+ mmfBps: number;
319
+ marketType: MarketType;
320
+ /**
321
+ * Arbitrary human-readable market symbol, not to be confused with token's
322
+ * symbol
323
+ */
324
+ viewSymbol: string;
325
+ /**
326
+ * Oracle symbol which references specific price feed. Must be
327
+ * `oracle_symbol` of registered price feed
328
+ */
329
+ oracleSymbol: string;
330
+ /**
331
+ * One of registered `token_id`'s.
332
+ *
333
+ * Base token for `MarketType::Spot`.
334
+ *
335
+ * Same as quote token id for `MarketType::Perpetual`. `oracle_symbol`
336
+ * identifies relevant price feed.
337
+ */
338
+ baseTokenId: number;
339
+ }
340
+ /**
341
+ * Note on order size.
342
+ * Any order being placed has absolute maximum size, which is 2^48-1.
343
+ * Although, this limit is applied not to initial order being placed
344
+ * but to final order being added to market's orderbook.
345
+ * This behavior exists because order can be limited by quote size,
346
+ * which converts to order size in a non-linear manner.
347
+ *
348
+ * Example: User posts order with size 2^48+100_000. Order fills counter
349
+ * orders and its size is reduced to 2^48-1_000_000 in process. This order
350
+ * will be added to orderbook successfully despite its initial size is above
351
+ * limit.
352
+ */
353
+ export interface Action_PlaceOrder {
354
+ sessionId: bigint;
355
+ marketId: number;
356
+ side: Side;
357
+ fillMode: FillMode;
358
+ /**
359
+ * A reduce-only order only reduces your current position, as opposed to
360
+ * increasing it. It means you can only use it to close a position. In
361
+ * contrast, non-reduce-only orders can reduce or increase your position.
362
+ * Reduce is handled by dynamically reducing or adjusting limit order's
363
+ * contract quantity
364
+ * / to match the contract size of the open position.
365
+ */
366
+ isReduceOnly: boolean;
367
+ /**
368
+ * Raw integral value of order limit price.
369
+ * `1` here equals to market's `10^-price_decimals`
370
+ * When used in token balances and reward computations, shifted by market's
371
+ * `price_decimals`. Optional, treated as not set if 0.
372
+ */
373
+ price: bigint;
374
+ /**
375
+ * Raw integral value of order size limit.
376
+ * For spot markers measured in base size,
377
+ * for perpetuals in contract token.
378
+ * So using base as default naming in codebase.
379
+ * `1` here equals to market's `10^-size_decimals`
380
+ * When used in token balances and reward computations, shifted by market's
381
+ * `size_decimals`. Optional, treated as not set if 0.
382
+ */
383
+ size: bigint;
384
+ /**
385
+ * Raw integral value of order quote size limit.
386
+ * `1` here equals to market's `10^-(size_decimals + price_decimals)`
387
+ * When used in token balances and reward computations, shifted by market's
388
+ * `size_decimals + price_decimals`. Optional, treated as not set if 0.
389
+ *
390
+ * NB: Requires 128-bit value because it can be seen as sum
391
+ * of order sizes multiplied by respective prices. Since size is up to 48
392
+ * bits and price is up to 64 bits, their product can easily exceed 64 bits.
393
+ */
394
+ quoteSize: U128 | undefined;
395
+ /**
396
+ * Optional account on behalf of whom the order should be placed.
397
+ * Executed only if sender has delegated authority to do so,
398
+ * like admin user or liquidator bot.
399
+ */
400
+ delegatorAccountId?: number | undefined;
401
+ /**
402
+ * Caller provided opaque order identifier up to 8 bytes.
403
+ * Not used by engine, but can be used by client to track orders.
404
+ */
405
+ clientOrderId?: bigint | undefined;
406
+ /**
407
+ * Account id which performs operation;
408
+ * if not specified, first account of session's owner user is picked
409
+ */
410
+ senderAccountId?: number | undefined;
411
+ }
412
+ export interface Action_CancelOrderById {
413
+ sessionId: bigint;
414
+ orderId: bigint;
415
+ delegatorAccountId?: number | undefined;
416
+ senderAccountId?: number | undefined;
417
+ }
418
+ export interface Action_Deposit {
419
+ /**
420
+ * used for integration of rollup with nord app
421
+ * todo(n1): remove when integrated with gate
422
+ */
423
+ actionNonce: bigint;
424
+ tokenAddr: Uint8Array;
425
+ /** Shifted by the token's decimals. */
426
+ amount: bigint;
427
+ /** User's SECP256K1 registration public key, 33 bytes long */
428
+ userPubkey: Uint8Array;
429
+ }
430
+ /** todo(n1): when gate will be here, remove or replace internals with message */
431
+ export interface Action_Withdraw {
432
+ tokenId: number;
433
+ sessionId: bigint;
434
+ /** Shifted by the token's decimals. */
435
+ amount: bigint;
436
+ }
437
+ export interface Action_PythSetWormholeGuardians {
438
+ /**
439
+ * See
440
+ * https://docs.wormhole.com/wormhole/reference/api-docs/swagger#v1-guardianset-current
441
+ */
442
+ guardianSetIndex: number;
443
+ /**
444
+ * Each address is 20 bytes, consisting of the last 20 bytes
445
+ * of the keccak256 hash of the public key of the guardian.
446
+ */
447
+ addresses: Uint8Array[];
448
+ }
449
+ /** Associate a oracle symbol to a Pyth Feed ID. */
450
+ export interface Action_PythSetSymbolFeed {
451
+ oracleSymbol: string;
452
+ /** MUST be 32 bytes. */
453
+ priceFeedId: Uint8Array;
454
+ }
455
+ export interface Action_PythPriceFeedUpdate {
456
+ /** See https://hermes.pyth.network/docs/#/rest/latest_price_updates */
457
+ rawPythnetData: Uint8Array;
458
+ }
459
+ export interface Action_Liquidate {
460
+ liquidatorSessionId: bigint;
461
+ liquidateeAccountId: number;
462
+ liquidatorAccountId?: number | undefined;
463
+ }
464
+ export interface Action_RevokeSession {
465
+ sessionId: bigint;
466
+ }
467
+ /** The engine fails with a maintenance error while paused. */
468
+ export interface Action_Pause {
469
+ }
470
+ export interface Action_Unpause {
471
+ }
472
+ export interface Action_Transfer {
473
+ sessionId: bigint;
474
+ fromAccountId: number;
475
+ tokenId: number;
476
+ amount: bigint;
477
+ /** If target account id isn't specified, new account is created */
478
+ toAccountId?: number | undefined;
479
+ }
480
+ export interface Action_AddTrigger {
481
+ sessionId: bigint;
482
+ marketId: number;
483
+ kind: TriggerKind;
484
+ side: Side;
485
+ /** Same price format as when placing order */
486
+ price: bigint;
487
+ accountId?: number | undefined;
488
+ }
489
+ export interface Action_RemoveTrigger {
490
+ sessionId: bigint;
491
+ marketId: number;
492
+ kind: TriggerKind;
493
+ side: Side;
494
+ accountId?: number | undefined;
495
+ }
496
+ export interface Receipt {
497
+ /**
498
+ * Action id which was run to produce this receipt.
499
+ * In case of error it was next action id which did not incremented because of
500
+ * error.
501
+ */
502
+ actionId: bigint;
503
+ kind?: {
504
+ $case: "err";
505
+ value: Error;
506
+ } | {
507
+ $case: "createSessionResult";
508
+ value: Receipt_CreateSessionResult;
509
+ } | {
510
+ $case: "placeOrderResult";
511
+ value: Receipt_PlaceOrderResult;
512
+ } | {
513
+ $case: "cancelOrderResult";
514
+ value: Receipt_CancelOrderResult;
515
+ } | {
516
+ $case: "depositResult";
517
+ value: Receipt_DepositResult;
518
+ } | {
519
+ $case: "insertTokenResult";
520
+ value: Receipt_InsertTokenResult;
521
+ } | {
522
+ $case: "insertMarketResult";
523
+ value: Receipt_InsertMarketResult;
524
+ } | {
525
+ $case: "withdrawResult";
526
+ value: Receipt_WithdrawResult;
527
+ } | {
528
+ $case: "oracleSymbolFeedResult";
529
+ value: Receipt_OracleSymbolFeedResult;
530
+ } | {
531
+ $case: "oracleUpdateResult";
532
+ value: Receipt_OracleUpdateResult;
533
+ } | {
534
+ $case: "updateGuardianSetResult";
535
+ value: Receipt_UpdateGuardianSetResult;
536
+ } | {
537
+ $case: "liquidated";
538
+ value: Receipt_Liquidated;
539
+ } | {
540
+ $case: "sessionRevoked";
541
+ value: Receipt_SessionRevoked;
542
+ } | {
543
+ $case: "paused";
544
+ value: Receipt_Paused;
545
+ } | {
546
+ $case: "unpaused";
547
+ value: Receipt_Unpaused;
548
+ } | {
549
+ $case: "transferred";
550
+ value: Receipt_Transferred;
551
+ } | {
552
+ $case: "triggerAdded";
553
+ value: Receipt_TriggerAdded;
554
+ } | {
555
+ $case: "triggerRemoved";
556
+ value: Receipt_TriggerRemoved;
557
+ } | undefined;
558
+ }
559
+ export interface Receipt_Posted {
560
+ side: Side;
561
+ marketId: number;
562
+ price: bigint;
563
+ size: bigint;
564
+ orderId: bigint;
565
+ accountId: number;
566
+ clientOrderId?: bigint | undefined;
567
+ }
568
+ export interface Receipt_Trade {
569
+ orderId: bigint;
570
+ /** non zero */
571
+ price: bigint;
572
+ size: bigint;
573
+ accountId: number;
574
+ }
575
+ export interface Receipt_CreateSessionResult {
576
+ sessionId: bigint;
577
+ }
578
+ export interface Receipt_PlaceOrderResult {
579
+ posted?: Receipt_Posted | undefined;
580
+ fills: Receipt_Trade[];
581
+ }
582
+ export interface Receipt_CancelOrderResult {
583
+ orderId: bigint;
584
+ /** Account from which order was cancelled */
585
+ accountId: number;
586
+ }
587
+ export interface Receipt_DepositResult {
588
+ tokenId: number;
589
+ amount: bigint;
590
+ /** Default account of newly created or existing user */
591
+ accountId: number;
592
+ userCreated: boolean;
593
+ userPubkey: Uint8Array;
594
+ }
595
+ export interface Receipt_InsertTokenResult {
596
+ chainAddr: Uint8Array;
597
+ token: Token | undefined;
598
+ }
599
+ export interface Receipt_InsertMarketResult {
600
+ market: Market | undefined;
601
+ }
602
+ export interface Receipt_WithdrawResult {
603
+ tokenId: number;
604
+ amount: bigint;
605
+ balance: bigint;
606
+ accountId: number;
607
+ userPubkey: Uint8Array;
608
+ }
609
+ /** pyth receipts are not user facing, so they can be terse and optional */
610
+ export interface Receipt_OracleSymbolFeedResult {
611
+ oracleSymbol: string;
612
+ feedId: Uint8Array;
613
+ }
614
+ export interface Receipt_OracleUpdateResult {
615
+ timestamp: bigint;
616
+ }
617
+ export interface Receipt_UpdateGuardianSetResult {
618
+ guardianSetIndex: number;
619
+ addresses: Uint8Array[];
620
+ }
621
+ export interface Receipt_Liquidated {
622
+ }
623
+ export interface Receipt_SessionRevoked {
624
+ }
625
+ export interface Receipt_Paused {
626
+ }
627
+ export interface Receipt_Unpaused {
628
+ }
629
+ export interface Receipt_Transferred {
630
+ fromAccountId: number;
631
+ toAccountId: number;
632
+ tokenId: number;
633
+ amount: bigint;
634
+ accountCreated: boolean;
635
+ }
636
+ export interface Receipt_TriggerAdded {
637
+ }
638
+ export interface Receipt_TriggerRemoved {
639
+ }
640
+ export declare const U128: MessageFns<U128>;
641
+ export declare const Market: MessageFns<Market>;
642
+ export declare const Token: MessageFns<Token>;
643
+ export declare const Action: MessageFns<Action>;
644
+ export declare const Action_CreateSession: MessageFns<Action_CreateSession>;
645
+ export declare const Action_CreateToken: MessageFns<Action_CreateToken>;
646
+ export declare const Action_CreateMarket: MessageFns<Action_CreateMarket>;
647
+ export declare const Action_PlaceOrder: MessageFns<Action_PlaceOrder>;
648
+ export declare const Action_CancelOrderById: MessageFns<Action_CancelOrderById>;
649
+ export declare const Action_Deposit: MessageFns<Action_Deposit>;
650
+ export declare const Action_Withdraw: MessageFns<Action_Withdraw>;
651
+ export declare const Action_PythSetWormholeGuardians: MessageFns<Action_PythSetWormholeGuardians>;
652
+ export declare const Action_PythSetSymbolFeed: MessageFns<Action_PythSetSymbolFeed>;
653
+ export declare const Action_PythPriceFeedUpdate: MessageFns<Action_PythPriceFeedUpdate>;
654
+ export declare const Action_Liquidate: MessageFns<Action_Liquidate>;
655
+ export declare const Action_RevokeSession: MessageFns<Action_RevokeSession>;
656
+ export declare const Action_Pause: MessageFns<Action_Pause>;
657
+ export declare const Action_Unpause: MessageFns<Action_Unpause>;
658
+ export declare const Action_Transfer: MessageFns<Action_Transfer>;
659
+ export declare const Action_AddTrigger: MessageFns<Action_AddTrigger>;
660
+ export declare const Action_RemoveTrigger: MessageFns<Action_RemoveTrigger>;
661
+ export declare const Receipt: MessageFns<Receipt>;
662
+ export declare const Receipt_Posted: MessageFns<Receipt_Posted>;
663
+ export declare const Receipt_Trade: MessageFns<Receipt_Trade>;
664
+ export declare const Receipt_CreateSessionResult: MessageFns<Receipt_CreateSessionResult>;
665
+ export declare const Receipt_PlaceOrderResult: MessageFns<Receipt_PlaceOrderResult>;
666
+ export declare const Receipt_CancelOrderResult: MessageFns<Receipt_CancelOrderResult>;
667
+ export declare const Receipt_DepositResult: MessageFns<Receipt_DepositResult>;
668
+ export declare const Receipt_InsertTokenResult: MessageFns<Receipt_InsertTokenResult>;
669
+ export declare const Receipt_InsertMarketResult: MessageFns<Receipt_InsertMarketResult>;
670
+ export declare const Receipt_WithdrawResult: MessageFns<Receipt_WithdrawResult>;
671
+ export declare const Receipt_OracleSymbolFeedResult: MessageFns<Receipt_OracleSymbolFeedResult>;
672
+ export declare const Receipt_OracleUpdateResult: MessageFns<Receipt_OracleUpdateResult>;
673
+ export declare const Receipt_UpdateGuardianSetResult: MessageFns<Receipt_UpdateGuardianSetResult>;
674
+ export declare const Receipt_Liquidated: MessageFns<Receipt_Liquidated>;
675
+ export declare const Receipt_SessionRevoked: MessageFns<Receipt_SessionRevoked>;
676
+ export declare const Receipt_Paused: MessageFns<Receipt_Paused>;
677
+ export declare const Receipt_Unpaused: MessageFns<Receipt_Unpaused>;
678
+ export declare const Receipt_Transferred: MessageFns<Receipt_Transferred>;
679
+ export declare const Receipt_TriggerAdded: MessageFns<Receipt_TriggerAdded>;
680
+ export declare const Receipt_TriggerRemoved: MessageFns<Receipt_TriggerRemoved>;
681
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
682
+ export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
683
+ $case: string;
684
+ value: unknown;
685
+ } ? {
686
+ $case: T["$case"];
687
+ value?: DeepPartial<T["value"]>;
688
+ } : T extends {} ? {
689
+ [K in keyof T]?: DeepPartial<T[K]>;
690
+ } : Partial<T>;
691
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
692
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
693
+ [K in keyof P]: Exact<P[K], I[K]>;
694
+ } & {
695
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
696
+ };
697
+ export interface MessageFns<T> {
698
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
699
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
700
+ fromJSON(object: any): T;
701
+ toJSON(message: T): unknown;
702
+ create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
703
+ fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
704
+ }
705
+ export {};