@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.
- package/.eslintignore +1 -0
- package/.eslintrc.js +20 -0
- package/.prettierignore +1 -0
- package/README.md +110 -0
- package/dist/abis/ERC20_ABI.d.ts +39 -0
- package/dist/abis/ERC20_ABI.js +313 -0
- package/dist/abis/NORD_GETTERS_FACET_ABI.d.ts +34 -0
- package/dist/abis/NORD_GETTERS_FACET_ABI.js +195 -0
- package/dist/abis/NORD_RAMP_FACET_ABI.d.ts +35 -0
- package/dist/abis/NORD_RAMP_FACET_ABI.js +144 -0
- package/dist/abis/index.d.ts +3 -0
- package/dist/abis/index.js +9 -0
- package/dist/const.d.ts +11 -0
- package/dist/const.js +34 -0
- package/dist/gen/common.d.ts +63 -0
- package/dist/gen/common.js +205 -0
- package/dist/gen/nord.d.ts +705 -0
- package/dist/gen/nord.js +4784 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -0
- package/dist/nord/Nord.d.ts +76 -0
- package/dist/nord/Nord.js +376 -0
- package/dist/nord/NordImpl.d.ts +7 -0
- package/dist/nord/NordImpl.js +6 -0
- package/dist/nord/NordUser.d.ts +77 -0
- package/dist/nord/NordUser.js +249 -0
- package/dist/nord/actions.d.ts +101 -0
- package/dist/nord/actions.js +254 -0
- package/dist/nord/index.d.ts +2 -0
- package/dist/nord/index.js +9 -0
- package/dist/types.d.ts +343 -0
- package/dist/types.js +92 -0
- package/dist/utils.d.ts +114 -0
- package/dist/utils.js +257 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +92 -0
- package/docs/assets/icons.js +15 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1415 -0
- package/docs/classes/Nord.html +44 -0
- package/docs/classes/NordUser.html +35 -0
- package/docs/classes/Subscriber.html +6 -0
- package/docs/enums/FillMode.html +5 -0
- package/docs/enums/KeyType.html +4 -0
- package/docs/enums/PeakTpsPeriodUnit.html +15 -0
- package/docs/enums/Side.html +3 -0
- package/docs/functions/assert.html +1 -0
- package/docs/functions/bigIntToProtoU128.html +4 -0
- package/docs/functions/checkPubKeyLength.html +1 -0
- package/docs/functions/checkedFetch.html +6 -0
- package/docs/functions/createWebSocketSubscription.html +12 -0
- package/docs/functions/decodeLengthDelimited.html +10 -0
- package/docs/functions/encodeLengthDelimited.html +6 -0
- package/docs/functions/fillModeToProtoFillMode.html +5 -0
- package/docs/functions/findMarket.html +1 -0
- package/docs/functions/findToken.html +1 -0
- package/docs/functions/makeWalletSignFn.html +6 -0
- package/docs/functions/optExpect.html +5 -0
- package/docs/functions/optMap.html +5 -0
- package/docs/functions/optUnwrap.html +2 -0
- package/docs/functions/panic.html +1 -0
- package/docs/functions/signAction.html +6 -0
- package/docs/functions/toScaledU128.html +8 -0
- package/docs/functions/toScaledU64.html +8 -0
- package/docs/index.html +21 -0
- package/docs/interfaces/Account.html +8 -0
- package/docs/interfaces/ActionInfo.html +8 -0
- package/docs/interfaces/ActionQuery.html +4 -0
- package/docs/interfaces/ActionResponse.html +8 -0
- package/docs/interfaces/ActionsExtendedInfo.html +10 -0
- package/docs/interfaces/ActionsQuery.html +5 -0
- package/docs/interfaces/ActionsResponse.html +6 -0
- package/docs/interfaces/AggregateMetrics.html +12 -0
- package/docs/interfaces/BlockQuery.html +6 -0
- package/docs/interfaces/BlockResponse.html +6 -0
- package/docs/interfaces/BlockSummary.html +8 -0
- package/docs/interfaces/BlockSummaryResponse.html +6 -0
- package/docs/interfaces/DeltaEvent.html +6 -0
- package/docs/interfaces/ERC20TokenInfo.html +5 -0
- package/docs/interfaces/Info.html +3 -0
- package/docs/interfaces/Market.html +6 -0
- package/docs/interfaces/MarketStats.html +7 -0
- package/docs/interfaces/MarketsStatsResponse.html +2 -0
- package/docs/interfaces/NordConfig.html +5 -0
- package/docs/interfaces/Order.html +6 -0
- package/docs/interfaces/OrderInfo.html +6 -0
- package/docs/interfaces/OrderbookOrder.html +6 -0
- package/docs/interfaces/OrderbookResponse.html +10 -0
- package/docs/interfaces/PerpMarketStats.html +5 -0
- package/docs/interfaces/RollmanActionExtendedInfo.html +4 -0
- package/docs/interfaces/RollmanActionInfo.html +4 -0
- package/docs/interfaces/RollmanActionResponse.html +4 -0
- package/docs/interfaces/RollmanActionsResponse.html +2 -0
- package/docs/interfaces/RollmanBlockResponse.html +3 -0
- package/docs/interfaces/SubscriberConfig.html +3 -0
- package/docs/interfaces/Token.html +5 -0
- package/docs/interfaces/Trade.html +5 -0
- package/docs/interfaces/TradeInfo.html +20 -0
- package/docs/interfaces/Trades.html +5 -0
- package/docs/interfaces/TradesQueryParams.html +10 -0
- package/docs/interfaces/TradesResponse.html +12 -0
- package/docs/modules.html +77 -0
- package/docs/types/BigIntValue.html +2 -0
- package/docs/variables/DEBUG_KEYS.html +1 -0
- package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -0
- package/docs/variables/DEV_CONTRACT_ADDRESS.html +1 -0
- package/docs/variables/DEV_TOKEN_INFOS.html +1 -0
- package/docs/variables/DEV_URL.html +1 -0
- package/docs/variables/ERC20_ABI.html +1 -0
- package/docs/variables/EVM_DEV_URL.html +1 -0
- package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +1 -0
- package/docs/variables/MAX_BUFFER_LEN.html +1 -0
- package/docs/variables/NORD_GETTERS_FACET_ABI.html +1 -0
- package/docs/variables/NORD_RAMP_FACET_ABI.html +1 -0
- package/docs/variables/SESSION_TTL.html +1 -0
- package/docs/variables/WEBSERVER_DEV_URL.html +1 -0
- package/docs/variables/ZERO_DECIMAL.html +1 -0
- package/jest.config.ts +9 -0
- package/nodemon.json +4 -0
- package/package.json +61 -0
- package/protoc-generate.sh +23 -0
- package/src/abis/ERC20_ABI.ts +310 -0
- package/src/abis/NORD_GETTERS_FACET_ABI.ts +192 -0
- package/src/abis/NORD_RAMP_FACET_ABI.ts +141 -0
- package/src/abis/index.ts +3 -0
- package/src/const.ts +39 -0
- package/src/gen/common.ts +280 -0
- package/src/gen/nord.ts +5666 -0
- package/src/index.ts +5 -0
- package/src/nord/Nord.ts +504 -0
- package/src/nord/NordImpl.ts +8 -0
- package/src/nord/NordUser.ts +469 -0
- package/src/nord/actions.ts +484 -0
- package/src/nord/index.ts +2 -0
- package/src/types.ts +393 -0
- package/src/utils.ts +300 -0
- package/tests/utils.spec.ts +154 -0
- package/tsconfig.json +24 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import * as proto from "./gen/nord";
|
|
2
|
+
/**
|
|
3
|
+
* The peak TPS rate is queried over the specified period.
|
|
4
|
+
* The period is specified in units of: {hour, day, week, month, year}.
|
|
5
|
+
* Example inputs:
|
|
6
|
+
* 1. AggregateMetrics.txPeakTpsPeriod = 3,
|
|
7
|
+
* AggregateMetrics.txPeakTpsPeriodUnit = "d" => Peak TPS over last 3 days.
|
|
8
|
+
* 1. AggregateMetrics.txPeakTpsPeriod = 1,
|
|
9
|
+
* AggregateMetrics.txPeakTpsPeriodUnit = "w" => Peak TPS over last week.
|
|
10
|
+
*/
|
|
11
|
+
export declare enum PeakTpsPeriodUnit {
|
|
12
|
+
Hour = "h",
|
|
13
|
+
Day = "d",
|
|
14
|
+
Week = "w",
|
|
15
|
+
Month = "m",
|
|
16
|
+
Year = "y"
|
|
17
|
+
}
|
|
18
|
+
export interface NordConfig {
|
|
19
|
+
evmUrl: string;
|
|
20
|
+
webServerUrl: string;
|
|
21
|
+
contractAddress: string;
|
|
22
|
+
tokenInfos: ERC20TokenInfo[];
|
|
23
|
+
}
|
|
24
|
+
export interface ERC20TokenInfo {
|
|
25
|
+
address: string;
|
|
26
|
+
precision: number;
|
|
27
|
+
tokenId: number;
|
|
28
|
+
name: string;
|
|
29
|
+
}
|
|
30
|
+
export interface Order {
|
|
31
|
+
orderId: number;
|
|
32
|
+
isLong: boolean;
|
|
33
|
+
size: number;
|
|
34
|
+
price: number;
|
|
35
|
+
marketId: number;
|
|
36
|
+
}
|
|
37
|
+
export declare enum KeyType {
|
|
38
|
+
Ed25519 = 0,
|
|
39
|
+
Secp256k1 = 1,
|
|
40
|
+
Bls12_381 = 2
|
|
41
|
+
}
|
|
42
|
+
export declare enum Side {
|
|
43
|
+
Ask = 0,
|
|
44
|
+
Bid = 1
|
|
45
|
+
}
|
|
46
|
+
export declare enum FillMode {
|
|
47
|
+
Limit = 0,
|
|
48
|
+
PostOnly = 1,
|
|
49
|
+
ImmediateOrCancel = 2,
|
|
50
|
+
FillOrKill = 3
|
|
51
|
+
}
|
|
52
|
+
export interface SubscriberConfig {
|
|
53
|
+
streamURL: string;
|
|
54
|
+
maxBufferLen?: number;
|
|
55
|
+
}
|
|
56
|
+
export interface Market {
|
|
57
|
+
symbol: string;
|
|
58
|
+
baseTokenId: number;
|
|
59
|
+
quoteTokenId: number;
|
|
60
|
+
priceDecimals: number;
|
|
61
|
+
sizeDecimals: number;
|
|
62
|
+
}
|
|
63
|
+
export interface Token {
|
|
64
|
+
symbol: string;
|
|
65
|
+
ethAddr: string;
|
|
66
|
+
decimals: number;
|
|
67
|
+
tokenId: number;
|
|
68
|
+
}
|
|
69
|
+
export interface Info {
|
|
70
|
+
markets: Market[];
|
|
71
|
+
tokens: Token[];
|
|
72
|
+
}
|
|
73
|
+
export interface DeltaEvent {
|
|
74
|
+
last_update_id: number;
|
|
75
|
+
update_id: number;
|
|
76
|
+
market_symbol: string;
|
|
77
|
+
asks: [number, number];
|
|
78
|
+
bids: [number, number];
|
|
79
|
+
}
|
|
80
|
+
export interface Trade {
|
|
81
|
+
side: Side;
|
|
82
|
+
price: number;
|
|
83
|
+
size: number;
|
|
84
|
+
order_id: number;
|
|
85
|
+
}
|
|
86
|
+
export interface Trades {
|
|
87
|
+
last_update_id: number;
|
|
88
|
+
update_id: number;
|
|
89
|
+
market_symbol: string;
|
|
90
|
+
trades: Trade[];
|
|
91
|
+
}
|
|
92
|
+
export interface OrderInfo {
|
|
93
|
+
id: number;
|
|
94
|
+
reduce_only: boolean;
|
|
95
|
+
imit_price: number;
|
|
96
|
+
size: number;
|
|
97
|
+
account_id: number;
|
|
98
|
+
}
|
|
99
|
+
interface HashMap<T> {
|
|
100
|
+
[key: number]: T;
|
|
101
|
+
}
|
|
102
|
+
export interface Account {
|
|
103
|
+
last_update_id: number;
|
|
104
|
+
update_id: number;
|
|
105
|
+
account_id: number;
|
|
106
|
+
fills: HashMap<FillMode>;
|
|
107
|
+
places: HashMap<OrderInfo>;
|
|
108
|
+
cancels: HashMap<OrderInfo>;
|
|
109
|
+
balances: HashMap<number>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Query the transactions in the specified L2 block.
|
|
113
|
+
* @field {number} block_number specifies the block number to query.
|
|
114
|
+
* If not specified, transactions from latest block
|
|
115
|
+
* are returned.
|
|
116
|
+
*/
|
|
117
|
+
export interface BlockQuery {
|
|
118
|
+
block_number?: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Response for BlockQuery.
|
|
122
|
+
* @field {number} block_number specifies the block number being returned.
|
|
123
|
+
* @field {BlockActions} actions are the list of transactions from the block.
|
|
124
|
+
*/
|
|
125
|
+
export interface BlockResponse {
|
|
126
|
+
block_number: number;
|
|
127
|
+
actions: ActionInfo[];
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Response for BlockSummaryQuery.
|
|
131
|
+
* @field {BlockSummary} block_summary is the summary of upto the last N blocks.
|
|
132
|
+
* The server can return fewer than last_n block summary if
|
|
133
|
+
* fewer blocks are available or if it exceeds a max cap.
|
|
134
|
+
*/
|
|
135
|
+
export interface BlockSummaryResponse {
|
|
136
|
+
block_summary: BlockSummary[];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Query the action for the specified action id.
|
|
140
|
+
* @field {number} action_id specifies the action to query.
|
|
141
|
+
*/
|
|
142
|
+
export interface ActionQuery {
|
|
143
|
+
action_id: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Response for ActionQuery.
|
|
147
|
+
* @field {number} block_number the block the action is part of.
|
|
148
|
+
* If the action is not yet included in any block,
|
|
149
|
+
* null is returned.
|
|
150
|
+
* @field {Action} the transaction.
|
|
151
|
+
*/
|
|
152
|
+
export interface ActionResponse {
|
|
153
|
+
block_number?: number;
|
|
154
|
+
action: proto.Action;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Query the recent actions
|
|
158
|
+
* @field {number} last_n requests last N actions.
|
|
159
|
+
* @field {number} action_id specifies the action to query.
|
|
160
|
+
*/
|
|
161
|
+
export interface ActionsQuery {
|
|
162
|
+
last_n: number;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Response for ActionsQuery.
|
|
166
|
+
* @field {ActionsExtendedInfo} actions returns upto the last N actions.
|
|
167
|
+
* The server can return fewer than last_n actions if
|
|
168
|
+
* fewer actions are available or if it exceeds a max cap.
|
|
169
|
+
*/
|
|
170
|
+
export interface ActionsResponse {
|
|
171
|
+
actions: ActionsExtendedInfo[];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Block summary.
|
|
175
|
+
* @field {number} block_number Block number.
|
|
176
|
+
* @field {Action} from First action_id in the block.
|
|
177
|
+
* @field {Action} to Last action_id in the block.
|
|
178
|
+
*/
|
|
179
|
+
export interface BlockSummary {
|
|
180
|
+
block_number: number;
|
|
181
|
+
from_action_id: number;
|
|
182
|
+
to_action_id: number;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Info about the block transaction.
|
|
186
|
+
* @field {number} action_id is the action identifier.
|
|
187
|
+
* @field {Action} action in protobuf format.
|
|
188
|
+
* @field {number} exec_timestamp is the execution timestamp.
|
|
189
|
+
*/
|
|
190
|
+
export interface ActionInfo {
|
|
191
|
+
action_id: number;
|
|
192
|
+
action: proto.Action;
|
|
193
|
+
exec_timestamp: number;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Extended info about the block transaction.
|
|
197
|
+
* @field {number} block_number the block the action is part of.
|
|
198
|
+
* If the action is not yet included in any block,
|
|
199
|
+
* null is returned.
|
|
200
|
+
* @field {number} action_id of the action.
|
|
201
|
+
* @field {Action} action the transaction.
|
|
202
|
+
*/
|
|
203
|
+
export interface ActionsExtendedInfo {
|
|
204
|
+
block_number?: number;
|
|
205
|
+
action_id: number;
|
|
206
|
+
action: proto.Action;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Aggregate metrics
|
|
210
|
+
* @field {number} blocks_total: Total number of L2 blocks.
|
|
211
|
+
* @field {number} tx_total: Total number of transactions.
|
|
212
|
+
* @field {number} tx_tps: Transaction throughput.
|
|
213
|
+
* @field {number} tx_tps_peak: Peak transaction throughput.
|
|
214
|
+
* @field {number} request_latency_average: Average request latency.
|
|
215
|
+
*/
|
|
216
|
+
export interface AggregateMetrics {
|
|
217
|
+
blocks_total: number;
|
|
218
|
+
tx_total: number;
|
|
219
|
+
tx_tps: number;
|
|
220
|
+
tx_tps_peak: number;
|
|
221
|
+
request_latency_average: number;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Parameters for querying trades
|
|
225
|
+
* @field {number} accountId - ID of target account
|
|
226
|
+
* @field {string} [since] - Start with this timestamp (RFC3339); defaults to UNIX epoch start
|
|
227
|
+
* @field {string} [until] - End with this timestamp (RFC3339); defaults to current date-time
|
|
228
|
+
* @field {string} [pageId] - Fetch results starting with this page
|
|
229
|
+
*/
|
|
230
|
+
export interface TradesQueryParams {
|
|
231
|
+
accountId: number;
|
|
232
|
+
since?: string;
|
|
233
|
+
until?: string;
|
|
234
|
+
pageId?: string;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Trade information
|
|
238
|
+
* @field {string} id - Trade ID
|
|
239
|
+
* @field {string} timestamp - Trade timestamp (RFC3339)
|
|
240
|
+
* @field {string} symbol - Market symbol
|
|
241
|
+
* @field {string} side - Trade side (buy/sell)
|
|
242
|
+
* @field {number} price - Trade price
|
|
243
|
+
* @field {number} size - Trade size
|
|
244
|
+
* @field {number} fee - Trade fee
|
|
245
|
+
* @field {string} feeCurrency - Fee currency
|
|
246
|
+
* @field {number} orderId - Order ID
|
|
247
|
+
*/
|
|
248
|
+
export interface TradeInfo {
|
|
249
|
+
id: string;
|
|
250
|
+
timestamp: string;
|
|
251
|
+
symbol: string;
|
|
252
|
+
side: string;
|
|
253
|
+
price: number;
|
|
254
|
+
size: number;
|
|
255
|
+
fee: number;
|
|
256
|
+
feeCurrency: string;
|
|
257
|
+
orderId: number;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Response for trades query
|
|
261
|
+
* @field {number} accountId - Account ID
|
|
262
|
+
* @field {string} since - Start timestamp (RFC3339)
|
|
263
|
+
* @field {string} until - End timestamp (RFC3339)
|
|
264
|
+
* @field {string} [nextPageId] - ID for the next page of results
|
|
265
|
+
* @field {TradeInfo[]} trades - Array of trades
|
|
266
|
+
*/
|
|
267
|
+
export interface TradesResponse {
|
|
268
|
+
accountId: number;
|
|
269
|
+
since: string;
|
|
270
|
+
until: string;
|
|
271
|
+
nextPageId?: string;
|
|
272
|
+
trades: TradeInfo[];
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Order in the orderbook
|
|
276
|
+
* @field {number} price - Order price
|
|
277
|
+
* @field {number} size - Order size
|
|
278
|
+
*/
|
|
279
|
+
export interface OrderbookOrder {
|
|
280
|
+
price: number;
|
|
281
|
+
size: number;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Response for orderbook query
|
|
285
|
+
* @field {string} symbol - Market symbol
|
|
286
|
+
* @field {number} timestamp - Orderbook timestamp
|
|
287
|
+
* @field {OrderbookOrder[]} bids - Array of bid orders
|
|
288
|
+
* @field {OrderbookOrder[]} asks - Array of ask orders
|
|
289
|
+
*/
|
|
290
|
+
export interface OrderbookResponse {
|
|
291
|
+
symbol: string;
|
|
292
|
+
timestamp: number;
|
|
293
|
+
bids: OrderbookOrder[];
|
|
294
|
+
asks: OrderbookOrder[];
|
|
295
|
+
}
|
|
296
|
+
export interface RollmanBlockResponse {
|
|
297
|
+
block_number: number;
|
|
298
|
+
actions: RollmanActionInfo[];
|
|
299
|
+
}
|
|
300
|
+
export interface RollmanActionResponse {
|
|
301
|
+
block_number?: number;
|
|
302
|
+
action_pb: Uint8Array;
|
|
303
|
+
exec_timestamp: number;
|
|
304
|
+
}
|
|
305
|
+
export interface RollmanActionsResponse {
|
|
306
|
+
actions: RollmanActionExtendedInfo[];
|
|
307
|
+
}
|
|
308
|
+
export interface RollmanActionInfo {
|
|
309
|
+
action_id: number;
|
|
310
|
+
action_pb: Uint8Array;
|
|
311
|
+
exec_timestamp: number;
|
|
312
|
+
}
|
|
313
|
+
export interface RollmanActionExtendedInfo {
|
|
314
|
+
block_number?: number;
|
|
315
|
+
action_id: number;
|
|
316
|
+
action_pb: Uint8Array;
|
|
317
|
+
}
|
|
318
|
+
export interface MarketsStatsResponse {
|
|
319
|
+
markets: MarketStats[];
|
|
320
|
+
}
|
|
321
|
+
export interface MarketStats {
|
|
322
|
+
market_id: number;
|
|
323
|
+
index_price: [number, number];
|
|
324
|
+
volume_24h: number;
|
|
325
|
+
high_24h: number;
|
|
326
|
+
low_24h: number;
|
|
327
|
+
perp_stats?: PerpMarketStats;
|
|
328
|
+
}
|
|
329
|
+
export interface PerpMarketStats {
|
|
330
|
+
mark_price?: number;
|
|
331
|
+
funding_rate?: number;
|
|
332
|
+
next_funding_time?: Date;
|
|
333
|
+
open_interest?: number;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Converts a `FillMode` enum to its corresponding protobuf representation.
|
|
337
|
+
*
|
|
338
|
+
* @param x - The fill mode to convert.
|
|
339
|
+
* @returns The corresponding protobuf fill mode.
|
|
340
|
+
* @throws Will throw an error if provided with an invalid fill mode.
|
|
341
|
+
*/
|
|
342
|
+
export declare function fillModeToProtoFillMode(x: FillMode): proto.FillMode;
|
|
343
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FillMode = exports.Side = exports.KeyType = exports.PeakTpsPeriodUnit = void 0;
|
|
37
|
+
exports.fillModeToProtoFillMode = fillModeToProtoFillMode;
|
|
38
|
+
const proto = __importStar(require("./gen/nord"));
|
|
39
|
+
/**
|
|
40
|
+
* The peak TPS rate is queried over the specified period.
|
|
41
|
+
* The period is specified in units of: {hour, day, week, month, year}.
|
|
42
|
+
* Example inputs:
|
|
43
|
+
* 1. AggregateMetrics.txPeakTpsPeriod = 3,
|
|
44
|
+
* AggregateMetrics.txPeakTpsPeriodUnit = "d" => Peak TPS over last 3 days.
|
|
45
|
+
* 1. AggregateMetrics.txPeakTpsPeriod = 1,
|
|
46
|
+
* AggregateMetrics.txPeakTpsPeriodUnit = "w" => Peak TPS over last week.
|
|
47
|
+
*/
|
|
48
|
+
var PeakTpsPeriodUnit;
|
|
49
|
+
(function (PeakTpsPeriodUnit) {
|
|
50
|
+
PeakTpsPeriodUnit["Hour"] = "h";
|
|
51
|
+
PeakTpsPeriodUnit["Day"] = "d";
|
|
52
|
+
PeakTpsPeriodUnit["Week"] = "w";
|
|
53
|
+
PeakTpsPeriodUnit["Month"] = "m";
|
|
54
|
+
PeakTpsPeriodUnit["Year"] = "y";
|
|
55
|
+
})(PeakTpsPeriodUnit || (exports.PeakTpsPeriodUnit = PeakTpsPeriodUnit = {}));
|
|
56
|
+
var KeyType;
|
|
57
|
+
(function (KeyType) {
|
|
58
|
+
KeyType[KeyType["Ed25519"] = 0] = "Ed25519";
|
|
59
|
+
KeyType[KeyType["Secp256k1"] = 1] = "Secp256k1";
|
|
60
|
+
KeyType[KeyType["Bls12_381"] = 2] = "Bls12_381";
|
|
61
|
+
})(KeyType || (exports.KeyType = KeyType = {}));
|
|
62
|
+
var Side;
|
|
63
|
+
(function (Side) {
|
|
64
|
+
Side[Side["Ask"] = 0] = "Ask";
|
|
65
|
+
Side[Side["Bid"] = 1] = "Bid";
|
|
66
|
+
})(Side || (exports.Side = Side = {}));
|
|
67
|
+
var FillMode;
|
|
68
|
+
(function (FillMode) {
|
|
69
|
+
FillMode[FillMode["Limit"] = 0] = "Limit";
|
|
70
|
+
FillMode[FillMode["PostOnly"] = 1] = "PostOnly";
|
|
71
|
+
FillMode[FillMode["ImmediateOrCancel"] = 2] = "ImmediateOrCancel";
|
|
72
|
+
FillMode[FillMode["FillOrKill"] = 3] = "FillOrKill";
|
|
73
|
+
})(FillMode || (exports.FillMode = FillMode = {}));
|
|
74
|
+
/**
|
|
75
|
+
* Converts a `FillMode` enum to its corresponding protobuf representation.
|
|
76
|
+
*
|
|
77
|
+
* @param x - The fill mode to convert.
|
|
78
|
+
* @returns The corresponding protobuf fill mode.
|
|
79
|
+
* @throws Will throw an error if provided with an invalid fill mode.
|
|
80
|
+
*/
|
|
81
|
+
function fillModeToProtoFillMode(x) {
|
|
82
|
+
if (x === FillMode.Limit)
|
|
83
|
+
return proto.FillMode.LIMIT;
|
|
84
|
+
if (x === FillMode.PostOnly)
|
|
85
|
+
return proto.FillMode.POST_ONLY;
|
|
86
|
+
if (x === FillMode.ImmediateOrCancel) {
|
|
87
|
+
return proto.FillMode.IMMEDIATE_OR_CANCEL;
|
|
88
|
+
}
|
|
89
|
+
if (x === FillMode.FillOrKill)
|
|
90
|
+
return proto.FillMode.FILL_OR_KILL;
|
|
91
|
+
throw new Error("Invalid fill mode");
|
|
92
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Decimal } from "decimal.js";
|
|
2
|
+
import { KeyType, type Market, type Token } from "./types";
|
|
3
|
+
import * as proto from "./gen/nord";
|
|
4
|
+
import { ethers } from "ethers";
|
|
5
|
+
import { RequestInfo, RequestInit, Response } from "node-fetch";
|
|
6
|
+
export declare const SESSION_TTL: bigint;
|
|
7
|
+
export declare const ZERO_DECIMAL: Decimal;
|
|
8
|
+
export declare const MAX_BUFFER_LEN = 10000;
|
|
9
|
+
/** Any type convertible to bigint */
|
|
10
|
+
export type BigIntValue = bigint | number | string;
|
|
11
|
+
export declare function panic(message: string): never;
|
|
12
|
+
export declare function assert(predicate: boolean, message?: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Extracts value out of optional if it's defined, or throws error if it's not
|
|
15
|
+
* @param value Optional value to unwrap
|
|
16
|
+
* @param message Error message
|
|
17
|
+
* @returns Unwrapped value
|
|
18
|
+
*/
|
|
19
|
+
export declare function optExpect<T>(value: T | undefined, message: string): T;
|
|
20
|
+
/**
|
|
21
|
+
* Unwraps optional value with default error message
|
|
22
|
+
* @param value
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare function optUnwrap<T>(value: T | undefined): T;
|
|
26
|
+
/**
|
|
27
|
+
* Applies function to value if it's defined, or passes `undefined` through
|
|
28
|
+
* @param value Optional value to map
|
|
29
|
+
* @param mapFn Mapper function
|
|
30
|
+
* @returns Either mapped value or undefined
|
|
31
|
+
*/
|
|
32
|
+
export declare function optMap<T, U>(value: T | undefined, mapFn: (arg: T) => U): U | undefined;
|
|
33
|
+
/** Behaves same as `node-fetch/fetch` but throws if response is a failure
|
|
34
|
+
*
|
|
35
|
+
* @param url Request HTTP URL
|
|
36
|
+
* @param init Request parameters
|
|
37
|
+
* @returns Raw response if fetch succeeded
|
|
38
|
+
* @throws If response wasn't Ok
|
|
39
|
+
*/
|
|
40
|
+
export declare function checkedFetch(url: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
41
|
+
/**
|
|
42
|
+
* Signs an action using the specified secret key and key type.
|
|
43
|
+
* @param action - The action data to be signed.
|
|
44
|
+
* @param sk - Secret key used for signing the action.
|
|
45
|
+
* @param keyType - Type of the key used for signing.
|
|
46
|
+
* @returns A new Uint8Array containing the action followed by its signature.
|
|
47
|
+
*/
|
|
48
|
+
export declare function signAction(action: Uint8Array, sk: Uint8Array, keyType: KeyType): Uint8Array;
|
|
49
|
+
/**
|
|
50
|
+
* Constructs wallet signing function, usable with `NordUser` type
|
|
51
|
+
*
|
|
52
|
+
* @param walletKey Either raw signing key as bytes array or hex string prefixed with `"0x"`
|
|
53
|
+
* @returns Async function which accepts arbitrary message, generates its digets,
|
|
54
|
+
* then signs it with provided user wallet key and returns signature
|
|
55
|
+
* as hex string prefixed with `"0x"`
|
|
56
|
+
*/
|
|
57
|
+
export declare function makeWalletSignFn(walletKey: ethers.BytesLike): (message: Uint8Array | string) => Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Converts decimal value into rescaled 64-bit unsigned integer
|
|
60
|
+
* by scaling it up by specified number of decimal digits.
|
|
61
|
+
*
|
|
62
|
+
* Ensures that number won't accidentally become zero
|
|
63
|
+
* or exceed U64's value range
|
|
64
|
+
*
|
|
65
|
+
* @param x Decimal value to rescale
|
|
66
|
+
* @param decimals Number of decimal digits
|
|
67
|
+
* @returns Rescaled unsigned integer
|
|
68
|
+
*/
|
|
69
|
+
export declare const toScaledU64: (x: Decimal.Value, decimals: number) => bigint;
|
|
70
|
+
/**
|
|
71
|
+
* Converts decimal value into rescaled 128-bit unsigned integer
|
|
72
|
+
* by scaling it up by specified number of decimal digits.
|
|
73
|
+
*
|
|
74
|
+
* Ensures that number won't accidentally become zero
|
|
75
|
+
* or exceed U128's value range
|
|
76
|
+
*
|
|
77
|
+
* @param x Decimal value to rescale
|
|
78
|
+
* @param decimals Number of decimal digits
|
|
79
|
+
* @returns Rescaled unsigned integer
|
|
80
|
+
*/
|
|
81
|
+
export declare const toScaledU128: (x: Decimal.Value, decimals: number) => bigint;
|
|
82
|
+
/**
|
|
83
|
+
* Converts U128 into pair of U64 numbers, to pass it through protobuf
|
|
84
|
+
* @param value integer, must fit U128 limits
|
|
85
|
+
* @returns Pair of U64 integers which represent original number split in two
|
|
86
|
+
*/
|
|
87
|
+
export declare function bigIntToProtoU128(value: bigint): proto.U128;
|
|
88
|
+
/**
|
|
89
|
+
* Encodes any protobuf message into a length-delimited format,
|
|
90
|
+
* i.e. prefixed with its length encoded as varint
|
|
91
|
+
* @param message message object
|
|
92
|
+
* @param coder associated coder object which implements `MessageFns` interface
|
|
93
|
+
* @returns Encoded message as Uint8Array, prefixed with its length
|
|
94
|
+
*/
|
|
95
|
+
export declare function encodeLengthDelimited<T, M extends proto.MessageFns<T>>(message: T, coder: M): Uint8Array;
|
|
96
|
+
/**
|
|
97
|
+
* Decodes any protobuf message from a length-delimited format,
|
|
98
|
+
* i.e. prefixed with its length encoded as varint
|
|
99
|
+
*
|
|
100
|
+
* NB: Please note that due to limitations of Typescript type inference
|
|
101
|
+
* it requires to specify variable type explicitly:
|
|
102
|
+
*
|
|
103
|
+
* ```
|
|
104
|
+
* const foo: proto.Bar = decodeLengthDelimited(bytes, proto.Bar);
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @param bytes Byte array with encoded message
|
|
108
|
+
* @param coder associated coder object which implements `MessageFns` interface
|
|
109
|
+
* @returns Decoded Action as Uint8Array.
|
|
110
|
+
*/
|
|
111
|
+
export declare function decodeLengthDelimited<T, M extends proto.MessageFns<T>>(bytes: Uint8Array, coder: M): T;
|
|
112
|
+
export declare function checkPubKeyLength(keyType: KeyType, len: number): void;
|
|
113
|
+
export declare function findMarket(markets: Market[], marketId: number): Market;
|
|
114
|
+
export declare function findToken(tokens: Token[], tokenId: number): Token;
|