@n1xyz/nord-ts 0.0.1 → 0.0.4
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/.eslintrc.js +11 -0
- package/README.md +148 -65
- package/dist/bridge/NordUser.d.ts +78 -0
- package/dist/bridge/NordUser.js +196 -0
- package/dist/bridge/client.d.ts +150 -0
- package/dist/bridge/client.js +394 -0
- package/dist/bridge/const.d.ts +23 -0
- package/dist/bridge/const.js +47 -0
- package/dist/bridge/index.d.ts +5 -0
- package/dist/bridge/index.js +23 -0
- package/dist/bridge/types.d.ts +118 -0
- package/dist/bridge/types.js +16 -0
- package/dist/bridge/utils.d.ts +64 -0
- package/dist/bridge/utils.js +131 -0
- package/dist/client.d.ts +70 -0
- package/dist/client.js +129 -0
- package/dist/const.d.ts +2 -5
- package/dist/const.js +18 -22
- package/dist/constants/endpoints.d.ts +65 -0
- package/dist/constants/endpoints.js +68 -0
- package/dist/gen/common.d.ts +6 -1
- package/dist/gen/common.js +19 -9
- package/dist/gen/nord.d.ts +75 -17
- package/dist/gen/nord.js +987 -423
- package/dist/idl/bridge.d.ts +2 -0
- package/dist/idl/bridge.js +703 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.js +18 -2
- package/dist/models/account.d.ts +58 -0
- package/dist/models/account.js +6 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.js +28 -0
- package/dist/models/market.d.ts +137 -0
- package/dist/models/market.js +6 -0
- package/dist/models/order.d.ts +211 -0
- package/dist/models/order.js +6 -0
- package/dist/models/token.d.ts +50 -0
- package/dist/models/token.js +6 -0
- package/dist/nord/Nord.d.ts +222 -49
- package/dist/nord/Nord.js +290 -278
- package/dist/nord/NordError.d.ts +23 -0
- package/dist/nord/NordError.js +48 -0
- package/dist/nord/NordImpl.d.ts +6 -2
- package/dist/nord/NordImpl.js +21 -1
- package/dist/nord/NordUser.d.ts +208 -42
- package/dist/nord/NordUser.js +389 -157
- package/dist/nord/Subscriber.d.ts +37 -0
- package/dist/nord/Subscriber.js +29 -0
- package/dist/nord/api/actions.d.ts +101 -0
- package/dist/nord/api/actions.js +250 -0
- package/dist/nord/api/core.d.ts +49 -0
- package/dist/nord/api/core.js +121 -0
- package/dist/nord/api/index.d.ts +1 -0
- package/dist/nord/api/index.js +17 -0
- package/dist/nord/api/market.d.ts +36 -0
- package/dist/nord/api/market.js +98 -0
- package/dist/nord/api/metrics.d.ts +67 -0
- package/dist/nord/api/metrics.js +132 -0
- package/dist/nord/api/orderFunctions.d.ts +168 -0
- package/dist/nord/api/orderFunctions.js +133 -0
- package/dist/nord/api/queries.d.ts +81 -0
- package/dist/nord/api/queries.js +187 -0
- package/dist/nord/client/Nord.d.ts +335 -0
- package/dist/nord/client/Nord.js +532 -0
- package/dist/nord/client/NordUser.d.ts +320 -0
- package/dist/nord/client/NordUser.js +701 -0
- package/dist/nord/core.d.ts +48 -0
- package/dist/nord/core.js +97 -0
- package/dist/nord/index.d.ts +9 -2
- package/dist/nord/index.js +30 -6
- package/dist/nord/market.d.ts +36 -0
- package/dist/nord/market.js +90 -0
- package/dist/nord/metrics.d.ts +67 -0
- package/dist/nord/metrics.js +124 -0
- package/dist/nord/models/Subscriber.d.ts +37 -0
- package/dist/nord/models/Subscriber.js +29 -0
- package/dist/nord/queries.d.ts +81 -0
- package/dist/nord/queries.js +181 -0
- package/dist/nord/types.d.ts +88 -0
- package/dist/nord/types.js +2 -0
- package/dist/nord/utils/NordError.d.ts +35 -0
- package/dist/nord/utils/NordError.js +46 -0
- package/dist/nord/websocket.d.ts +49 -0
- package/dist/nord/websocket.js +107 -0
- package/dist/operations/account.d.ts +58 -0
- package/dist/operations/account.js +112 -0
- package/dist/operations/market.d.ts +65 -0
- package/dist/operations/market.js +131 -0
- package/dist/operations/orders.d.ts +57 -0
- package/dist/operations/orders.js +129 -0
- package/dist/solana/NordUser.d.ts +78 -0
- package/dist/solana/NordUser.js +196 -0
- package/dist/solana/client.d.ts +139 -0
- package/dist/solana/client.js +360 -0
- package/dist/solana/const.d.ts +23 -0
- package/dist/solana/const.js +47 -0
- package/dist/solana/index.d.ts +5 -0
- package/dist/solana/index.js +23 -0
- package/dist/solana/types.d.ts +118 -0
- package/dist/solana/types.js +16 -0
- package/dist/solana/utils.d.ts +64 -0
- package/dist/solana/utils.js +131 -0
- package/dist/types/api.d.ts +152 -0
- package/dist/types/api.js +6 -0
- package/dist/types/config.d.ts +34 -0
- package/dist/types/config.js +6 -0
- package/dist/types.d.ts +144 -87
- package/dist/types.js +13 -2
- package/dist/utils/errors.d.ts +96 -0
- package/dist/utils/errors.js +132 -0
- package/dist/utils/http.d.ts +35 -0
- package/dist/utils/http.js +105 -0
- package/dist/utils.d.ts +14 -5
- package/dist/utils.js +26 -7
- package/dist/websocket/NordWebSocketClient.d.ts +71 -0
- package/dist/websocket/NordWebSocketClient.js +343 -0
- package/dist/websocket/client.d.ts +93 -0
- package/dist/websocket/client.js +222 -0
- package/dist/websocket/events.d.ts +19 -0
- package/dist/websocket/events.js +2 -0
- package/dist/websocket/index.d.ts +2 -0
- package/dist/websocket/index.js +5 -0
- package/dist/websocket.d.ts +55 -0
- package/dist/websocket.js +211 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Nord.html +2 -15
- package/docs/classes/NordUser.html +4 -4
- package/docs/enums/FillMode.html +2 -2
- package/docs/enums/KeyType.html +2 -2
- package/docs/enums/PeakTpsPeriodUnit.html +2 -2
- package/docs/enums/Side.html +2 -2
- package/docs/functions/assert.html +1 -1
- package/docs/functions/bigIntToProtoU128.html +1 -1
- package/docs/functions/checkPubKeyLength.html +1 -1
- package/docs/functions/checkedFetch.html +1 -1
- package/docs/functions/decodeLengthDelimited.html +1 -1
- package/docs/functions/encodeLengthDelimited.html +1 -1
- package/docs/functions/fillModeToProtoFillMode.html +1 -1
- package/docs/functions/findMarket.html +1 -1
- package/docs/functions/findToken.html +1 -1
- package/docs/functions/makeWalletSignFn.html +1 -1
- package/docs/functions/optExpect.html +1 -1
- package/docs/functions/optMap.html +1 -1
- package/docs/functions/optUnwrap.html +1 -1
- package/docs/functions/panic.html +1 -1
- package/docs/functions/signAction.html +1 -1
- package/docs/functions/toScaledU128.html +1 -1
- package/docs/functions/toScaledU64.html +1 -1
- package/docs/interfaces/Account.html +2 -2
- package/docs/interfaces/ActionInfo.html +2 -2
- package/docs/interfaces/ActionQuery.html +2 -2
- package/docs/interfaces/ActionResponse.html +2 -2
- package/docs/interfaces/ActionsExtendedInfo.html +2 -2
- package/docs/interfaces/ActionsQuery.html +2 -2
- package/docs/interfaces/ActionsResponse.html +2 -2
- package/docs/interfaces/AggregateMetrics.html +2 -2
- package/docs/interfaces/BlockQuery.html +2 -2
- package/docs/interfaces/BlockResponse.html +2 -2
- package/docs/interfaces/BlockSummary.html +2 -2
- package/docs/interfaces/BlockSummaryResponse.html +2 -2
- package/docs/interfaces/DeltaEvent.html +2 -2
- package/docs/interfaces/ERC20TokenInfo.html +2 -2
- package/docs/interfaces/Info.html +2 -2
- package/docs/interfaces/Market.html +2 -2
- package/docs/interfaces/MarketStats.html +2 -2
- package/docs/interfaces/MarketsStatsResponse.html +2 -2
- package/docs/interfaces/NordConfig.html +2 -2
- package/docs/interfaces/Order.html +2 -2
- package/docs/interfaces/OrderInfo.html +2 -2
- package/docs/interfaces/PerpMarketStats.html +2 -2
- package/docs/interfaces/RollmanActionExtendedInfo.html +2 -2
- package/docs/interfaces/RollmanActionInfo.html +2 -2
- package/docs/interfaces/RollmanActionResponse.html +2 -2
- package/docs/interfaces/RollmanActionsResponse.html +2 -2
- package/docs/interfaces/RollmanBlockResponse.html +2 -2
- package/docs/interfaces/SubscriberConfig.html +2 -2
- package/docs/interfaces/Token.html +2 -2
- package/docs/interfaces/Trade.html +2 -2
- package/docs/interfaces/Trades.html +2 -2
- package/docs/modules.html +0 -7
- package/docs/types/BigIntValue.html +1 -1
- package/docs/variables/DEBUG_KEYS.html +1 -1
- package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
- package/docs/variables/DEV_CONTRACT_ADDRESS.html +1 -1
- package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
- package/docs/variables/DEV_URL.html +1 -1
- package/docs/variables/ERC20_ABI.html +1 -1
- package/docs/variables/EVM_DEV_URL.html +1 -1
- package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +1 -1
- package/docs/variables/MAX_BUFFER_LEN.html +1 -1
- package/docs/variables/NORD_GETTERS_FACET_ABI.html +1 -1
- package/docs/variables/NORD_RAMP_FACET_ABI.html +1 -1
- package/docs/variables/SESSION_TTL.html +1 -1
- package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
- package/docs/variables/ZERO_DECIMAL.html +1 -1
- package/package.json +10 -12
- package/src/bridge/client.ts +487 -0
- package/src/bridge/const.ts +53 -0
- package/src/bridge/index.ts +7 -0
- package/src/bridge/types.ts +127 -0
- package/src/bridge/utils.ts +140 -0
- package/src/const.ts +20 -25
- package/src/gen/common.ts +27 -10
- package/src/gen/nord.ts +1044 -483
- package/src/idl/bridge.ts +702 -0
- package/src/index.ts +24 -5
- package/src/nord/{actions.ts → api/actions.ts} +33 -37
- package/src/nord/api/core.ts +130 -0
- package/src/nord/api/market.ts +125 -0
- package/src/nord/api/metrics.ts +154 -0
- package/src/nord/api/queries.ts +236 -0
- package/src/nord/client/Nord.ts +652 -0
- package/src/nord/client/NordUser.ts +1105 -0
- package/src/nord/index.ts +16 -2
- package/src/nord/models/Subscriber.ts +57 -0
- package/src/nord/utils/NordError.ts +72 -0
- package/src/types.ts +170 -99
- package/src/utils.ts +40 -19
- package/src/websocket/NordWebSocketClient.ts +432 -0
- package/src/websocket/events.ts +31 -0
- package/src/websocket/index.ts +2 -0
- package/tests/utils.spec.ts +24 -24
- package/docs/classes/Subscriber.html +0 -6
- package/docs/functions/createWebSocketSubscription.html +0 -12
- package/docs/interfaces/OrderbookOrder.html +0 -6
- package/docs/interfaces/OrderbookResponse.html +0 -10
- package/docs/interfaces/TradeInfo.html +0 -20
- package/docs/interfaces/TradesQueryParams.html +0 -10
- package/docs/interfaces/TradesResponse.html +0 -12
- package/src/abis/ERC20_ABI.ts +0 -310
- package/src/abis/NORD_GETTERS_FACET_ABI.ts +0 -192
- package/src/abis/NORD_RAMP_FACET_ABI.ts +0 -141
- package/src/abis/index.ts +0 -3
- package/src/nord/Nord.ts +0 -504
- package/src/nord/NordImpl.ts +0 -8
- package/src/nord/NordUser.ts +0 -469
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ActionQuery,
|
|
3
|
+
ActionResponse,
|
|
4
|
+
ActionsResponse,
|
|
5
|
+
BlockQuery,
|
|
6
|
+
BlockResponse,
|
|
7
|
+
BlockSummaryResponse,
|
|
8
|
+
RollmanActionResponse,
|
|
9
|
+
RollmanActionsResponse,
|
|
10
|
+
RollmanBlockResponse,
|
|
11
|
+
} from '../../types';
|
|
12
|
+
import { checkedFetch } from '../../utils';
|
|
13
|
+
import { NordError } from '../utils/NordError';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Query a specific block
|
|
17
|
+
*
|
|
18
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
19
|
+
* @param query - Block query parameters
|
|
20
|
+
* @returns Block response
|
|
21
|
+
* @throws {NordError} If the request fails
|
|
22
|
+
*/
|
|
23
|
+
export async function queryBlock(
|
|
24
|
+
webServerUrl: string,
|
|
25
|
+
query: BlockQuery,
|
|
26
|
+
): Promise<BlockResponse> {
|
|
27
|
+
try {
|
|
28
|
+
const params = new URLSearchParams();
|
|
29
|
+
if (query.block_number !== undefined) {
|
|
30
|
+
params.append('block_height', query.block_number.toString());
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const response = await checkedFetch(
|
|
34
|
+
`${webServerUrl}/block?${params.toString()}`,
|
|
35
|
+
);
|
|
36
|
+
return await response.json();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new NordError('Failed to query block', { cause: error });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Query the last N blocks
|
|
44
|
+
*
|
|
45
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
46
|
+
* @returns Block response for the last N blocks
|
|
47
|
+
* @throws {NordError} If the request fails
|
|
48
|
+
*/
|
|
49
|
+
export async function queryLastNBlocks(
|
|
50
|
+
webServerUrl: string,
|
|
51
|
+
): Promise<BlockResponse> {
|
|
52
|
+
try {
|
|
53
|
+
const response = await checkedFetch(`${webServerUrl}/blocks`);
|
|
54
|
+
return await response.json();
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new NordError('Failed to query last N blocks', { cause: error });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Query recent blocks
|
|
62
|
+
*
|
|
63
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
64
|
+
* @param last_n - Number of recent blocks to query
|
|
65
|
+
* @returns Block summary response
|
|
66
|
+
* @throws {NordError} If the request fails
|
|
67
|
+
*/
|
|
68
|
+
export async function queryRecentBlocks(
|
|
69
|
+
webServerUrl: string,
|
|
70
|
+
last_n: number,
|
|
71
|
+
): Promise<BlockSummaryResponse> {
|
|
72
|
+
try {
|
|
73
|
+
const response = await checkedFetch(
|
|
74
|
+
`${webServerUrl}/blocks_summary?last_n=${last_n}`,
|
|
75
|
+
);
|
|
76
|
+
return await response.json();
|
|
77
|
+
} catch (error) {
|
|
78
|
+
throw new NordError(`Failed to query recent blocks (last ${last_n})`, {
|
|
79
|
+
cause: error,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Query a specific action
|
|
86
|
+
*
|
|
87
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
88
|
+
* @param query - Action query parameters
|
|
89
|
+
* @returns Action response
|
|
90
|
+
* @throws {NordError} If the request fails
|
|
91
|
+
*/
|
|
92
|
+
export async function queryAction(
|
|
93
|
+
webServerUrl: string,
|
|
94
|
+
query: ActionQuery,
|
|
95
|
+
): Promise<ActionResponse> {
|
|
96
|
+
try {
|
|
97
|
+
const params = new URLSearchParams();
|
|
98
|
+
if (query.action_id !== undefined) {
|
|
99
|
+
params.append('action_id', query.action_id.toString());
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const response = await checkedFetch(
|
|
103
|
+
`${webServerUrl}/action?${params.toString()}`,
|
|
104
|
+
);
|
|
105
|
+
return await response.json();
|
|
106
|
+
} catch (error) {
|
|
107
|
+
throw new NordError('Failed to query action', { cause: error });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Query recent actions
|
|
113
|
+
*
|
|
114
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
115
|
+
* @param last_n - Number of recent actions to query
|
|
116
|
+
* @returns Actions response
|
|
117
|
+
* @throws {NordError} If the request fails
|
|
118
|
+
*/
|
|
119
|
+
export async function queryRecentActions(
|
|
120
|
+
webServerUrl: string,
|
|
121
|
+
last_n: number,
|
|
122
|
+
): Promise<ActionsResponse> {
|
|
123
|
+
try {
|
|
124
|
+
const response = await checkedFetch(
|
|
125
|
+
`${webServerUrl}/actions?last_n=${last_n}`,
|
|
126
|
+
);
|
|
127
|
+
return await response.json();
|
|
128
|
+
} catch (error) {
|
|
129
|
+
throw new NordError(`Failed to query recent actions (last ${last_n})`, {
|
|
130
|
+
cause: error,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Query a block from Rollman
|
|
137
|
+
*
|
|
138
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
139
|
+
* @param query - Block query parameters
|
|
140
|
+
* @returns Rollman block response
|
|
141
|
+
* @throws {NordError} If the request fails
|
|
142
|
+
*/
|
|
143
|
+
export async function blockQueryRollman(
|
|
144
|
+
webServerUrl: string,
|
|
145
|
+
query: BlockQuery,
|
|
146
|
+
): Promise<RollmanBlockResponse> {
|
|
147
|
+
try {
|
|
148
|
+
const params = new URLSearchParams();
|
|
149
|
+
if (query.block_number !== undefined) {
|
|
150
|
+
params.append('block_height', query.block_number.toString());
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const response = await checkedFetch(
|
|
154
|
+
`${webServerUrl}/rollman/block?${params.toString()}`,
|
|
155
|
+
);
|
|
156
|
+
return await response.json();
|
|
157
|
+
} catch (error) {
|
|
158
|
+
throw new NordError('Failed to query Rollman block', { cause: error });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Query block summaries from Rollman
|
|
164
|
+
*
|
|
165
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
166
|
+
* @param last_n - Number of recent blocks to query
|
|
167
|
+
* @returns Block summary response
|
|
168
|
+
* @throws {NordError} If the request fails
|
|
169
|
+
*/
|
|
170
|
+
export async function blockSummaryQueryRollman(
|
|
171
|
+
webServerUrl: string,
|
|
172
|
+
last_n: number,
|
|
173
|
+
): Promise<BlockSummaryResponse> {
|
|
174
|
+
try {
|
|
175
|
+
const response = await checkedFetch(
|
|
176
|
+
`${webServerUrl}/rollman/blocks_summary?last_n=${last_n}`,
|
|
177
|
+
);
|
|
178
|
+
return await response.json();
|
|
179
|
+
} catch (error) {
|
|
180
|
+
throw new NordError(
|
|
181
|
+
`Failed to query Rollman block summaries (last ${last_n})`,
|
|
182
|
+
{ cause: error },
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Query an action from Rollman
|
|
189
|
+
*
|
|
190
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
191
|
+
* @param query - Action query parameters
|
|
192
|
+
* @returns Rollman action response
|
|
193
|
+
* @throws {NordError} If the request fails
|
|
194
|
+
*/
|
|
195
|
+
export async function actionQueryRollman(
|
|
196
|
+
webServerUrl: string,
|
|
197
|
+
query: ActionQuery,
|
|
198
|
+
): Promise<RollmanActionResponse> {
|
|
199
|
+
try {
|
|
200
|
+
const params = new URLSearchParams();
|
|
201
|
+
if (query.action_id !== undefined) {
|
|
202
|
+
params.append('action_id', query.action_id.toString());
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const response = await checkedFetch(
|
|
206
|
+
`${webServerUrl}/rollman/action?${params.toString()}`,
|
|
207
|
+
);
|
|
208
|
+
return await response.json();
|
|
209
|
+
} catch (error) {
|
|
210
|
+
throw new NordError('Failed to query Rollman action', { cause: error });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Query actions from Rollman
|
|
216
|
+
*
|
|
217
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
218
|
+
* @param last_n - Number of recent actions to query
|
|
219
|
+
* @returns Rollman actions response
|
|
220
|
+
* @throws {NordError} If the request fails
|
|
221
|
+
*/
|
|
222
|
+
export async function actionsQueryRollman(
|
|
223
|
+
webServerUrl: string,
|
|
224
|
+
last_n: number,
|
|
225
|
+
): Promise<RollmanActionsResponse> {
|
|
226
|
+
try {
|
|
227
|
+
const response = await checkedFetch(
|
|
228
|
+
`${webServerUrl}/rollman/actions?last_n=${last_n}`,
|
|
229
|
+
);
|
|
230
|
+
return await response.json();
|
|
231
|
+
} catch (error) {
|
|
232
|
+
throw new NordError(`Failed to query Rollman actions (last ${last_n})`, {
|
|
233
|
+
cause: error,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|