@n1xyz/nord-ts 0.0.4 → 0.0.5
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/dist/bridge/client.d.ts +4 -4
- package/dist/bridge/client.js +4 -4
- package/dist/bridge/const.d.ts +2 -2
- package/dist/bridge/const.js +22 -22
- package/dist/bridge/index.d.ts +4 -4
- package/dist/bridge/types.d.ts +3 -3
- package/dist/bridge/utils.d.ts +4 -4
- package/dist/bridge/utils.js +10 -10
- package/dist/const.d.ts +1 -1
- package/dist/const.js +17 -17
- package/dist/gen/nord.d.ts +1 -4
- package/dist/idl/bridge.d.ts +1 -1
- package/dist/idl/bridge.js +185 -185
- package/dist/index.d.ts +8 -8
- package/dist/nord/api/actions.d.ts +3 -3
- package/dist/nord/api/actions.js +21 -21
- package/dist/nord/api/core.d.ts +3 -3
- package/dist/nord/api/core.js +12 -12
- package/dist/nord/api/market.d.ts +1 -1
- package/dist/nord/api/market.js +12 -12
- package/dist/nord/api/metrics.d.ts +1 -1
- package/dist/nord/api/metrics.js +6 -6
- package/dist/nord/api/queries.d.ts +1 -1
- package/dist/nord/api/queries.js +9 -9
- package/dist/nord/client/Nord.d.ts +4 -4
- package/dist/nord/client/Nord.js +18 -18
- package/dist/nord/client/NordUser.d.ts +7 -7
- package/dist/nord/client/NordUser.js +45 -49
- package/dist/nord/index.d.ts +9 -9
- package/dist/nord/models/Subscriber.d.ts +6 -6
- package/dist/nord/models/Subscriber.js +1 -5
- package/dist/nord/utils/NordError.js +2 -2
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.d.ts +6 -6
- package/dist/utils.js +8 -8
- package/dist/websocket/NordWebSocketClient.d.ts +2 -2
- package/dist/websocket/NordWebSocketClient.js +38 -38
- package/dist/websocket/events.d.ts +1 -1
- package/dist/websocket/index.d.ts +2 -2
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +16 -16
- package/docs/assets/icons.js +17 -14
- package/docs/assets/icons.svg +1 -1
- package/docs/assets/main.js +5 -4
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +1423 -1227
- package/docs/classes/Nord.html +190 -31
- package/docs/classes/NordError.html +24 -0
- package/docs/classes/NordUser.html +120 -35
- package/docs/classes/NordWebSocketClient.html +335 -0
- package/docs/classes/SolanaBridgeClient.html +86 -0
- package/docs/classes/Subscriber.html +10 -0
- package/docs/enums/FillMode.html +5 -5
- package/docs/enums/KeyType.html +4 -4
- package/docs/enums/MetricPeriod.html +9 -0
- package/docs/enums/PdaSeedType.html +9 -0
- package/docs/enums/PeakTpsPeriodUnit.html +7 -7
- package/docs/enums/Side.html +3 -3
- package/docs/enums/WebSocketMessageType.html +7 -0
- package/docs/functions/actionQueryRollman.html +6 -0
- package/docs/functions/actionsQueryRollman.html +6 -0
- package/docs/functions/aggregateMetrics-1.html +7 -0
- package/docs/functions/assert.html +1 -1
- package/docs/functions/bigIntToProtoU128.html +3 -3
- package/docs/functions/blockQueryRollman.html +6 -0
- package/docs/functions/blockSummaryQueryRollman.html +6 -0
- package/docs/functions/bridgeToBN.html +5 -0
- package/docs/functions/bufferToHex.html +4 -0
- package/docs/functions/cancelOrder.html +1 -0
- package/docs/functions/checkPubKeyLength.html +1 -1
- package/docs/functions/checkedFetch.html +4 -4
- package/docs/functions/createSession.html +1 -0
- package/docs/functions/decodeLengthDelimited.html +7 -6
- package/docs/functions/encodeLengthDelimited.html +4 -4
- package/docs/functions/fillModeToProtoFillMode.html +4 -4
- package/docs/functions/findMarket.html +1 -1
- package/docs/functions/findPda.html +6 -0
- package/docs/functions/findToken.html +1 -1
- package/docs/functions/fromBN.html +5 -0
- package/docs/functions/getAccount.html +6 -0
- package/docs/functions/getActionNonce.html +5 -0
- package/docs/functions/getCurrentTps.html +6 -0
- package/docs/functions/getInfo.html +5 -0
- package/docs/functions/getMedianLatency.html +6 -0
- package/docs/functions/getOrderbook.html +6 -0
- package/docs/functions/getPeakTps.html +6 -0
- package/docs/functions/getTimestamp.html +5 -0
- package/docs/functions/getTotalTransactions.html +5 -0
- package/docs/functions/getTrades.html +6 -0
- package/docs/functions/getUserAccountIds.html +6 -0
- package/docs/functions/hexToBuffer.html +4 -0
- package/docs/functions/initWebSocketClient.html +12 -0
- package/docs/functions/keypairFromPrivateKey.html +4 -0
- package/docs/functions/makeSigningFunction.html +4 -0
- package/docs/functions/makeWalletSignFn.html +5 -5
- package/docs/functions/marketsStats.html +5 -0
- package/docs/functions/optExpect.html +4 -4
- package/docs/functions/optMap.html +5 -5
- package/docs/functions/optUnwrap.html +2 -2
- package/docs/functions/panic.html +1 -1
- package/docs/functions/placeOrder.html +1 -0
- package/docs/functions/queryAction.html +6 -0
- package/docs/functions/queryBlock.html +6 -0
- package/docs/functions/queryLastNBlocks.html +5 -0
- package/docs/functions/queryPrometheus.html +6 -0
- package/docs/functions/queryRecentActions.html +6 -0
- package/docs/functions/queryRecentBlocks.html +6 -0
- package/docs/functions/revokeSession.html +1 -0
- package/docs/functions/shortenPublicKey.html +5 -0
- package/docs/functions/signAction.html +2 -2
- package/docs/functions/toBN.html +5 -0
- package/docs/functions/toScaledU128.html +5 -5
- package/docs/functions/toScaledU64.html +5 -5
- package/docs/functions/transfer.html +1 -0
- package/docs/functions/withdraw.html +1 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +39 -20
- package/docs/interfaces/Account.html +8 -8
- package/docs/interfaces/ActionInfo.html +8 -8
- package/docs/interfaces/ActionNonceResponse.html +3 -0
- package/docs/interfaces/ActionQuery.html +4 -4
- package/docs/interfaces/ActionResponse.html +8 -8
- package/docs/interfaces/ActionsExtendedInfo.html +10 -10
- package/docs/interfaces/ActionsQuery.html +5 -5
- package/docs/interfaces/ActionsResponse.html +6 -6
- package/docs/interfaces/AggregateMetrics.html +12 -12
- package/docs/interfaces/BlockFacts.html +10 -0
- package/docs/interfaces/BlockQuery.html +6 -6
- package/docs/interfaces/BlockResponse.html +6 -6
- package/docs/interfaces/BlockSummary.html +8 -8
- package/docs/interfaces/BlockSummaryResponse.html +6 -6
- package/docs/interfaces/DeltaEvent.html +6 -6
- package/docs/interfaces/DepositSplParams.html +10 -0
- package/docs/interfaces/Info.html +3 -3
- package/docs/interfaces/Market.html +8 -6
- package/docs/interfaces/MarketStats.html +7 -7
- package/docs/interfaces/MarketsStatsResponse.html +2 -2
- package/docs/interfaces/NordConfig.html +14 -5
- package/docs/interfaces/NordWebSocketClientEvents.html +4 -0
- package/docs/interfaces/NordWebSocketEvents.html +8 -0
- package/docs/interfaces/Order.html +6 -6
- package/docs/interfaces/OrderInfo.html +6 -6
- package/docs/interfaces/OrderbookEntry.html +4 -0
- package/docs/interfaces/OrderbookQuery.html +6 -0
- package/docs/interfaces/OrderbookResponse.html +6 -0
- package/docs/interfaces/OrderbookSubscription.html +159 -0
- package/docs/interfaces/PerpMarketStats.html +5 -5
- package/docs/interfaces/RollmanActionExtendedInfo.html +4 -4
- package/docs/interfaces/RollmanActionInfo.html +4 -4
- package/docs/interfaces/RollmanActionResponse.html +4 -4
- package/docs/interfaces/RollmanActionsResponse.html +2 -2
- package/docs/interfaces/RollmanBlockResponse.html +3 -3
- package/docs/interfaces/SPLTokenInfo.html +10 -0
- package/docs/interfaces/SolanaBridgeConfig.html +10 -0
- package/docs/interfaces/StateFacts.html +10 -0
- package/docs/interfaces/SubscriberConfig.html +3 -3
- package/docs/interfaces/TimestampResponse.html +3 -0
- package/docs/interfaces/Token.html +5 -5
- package/docs/interfaces/TokenInfo.html +5 -0
- package/docs/interfaces/Trade.html +5 -5
- package/docs/interfaces/TradeSubscription.html +159 -0
- package/docs/interfaces/Trades.html +5 -5
- package/docs/interfaces/TradesQuery.html +6 -0
- package/docs/interfaces/TradesResponse.html +7 -0
- package/docs/interfaces/TransferParams.html +8 -0
- package/docs/interfaces/UserAccountIdsQuery.html +3 -0
- package/docs/interfaces/UserAccountIdsResponse.html +3 -0
- package/docs/interfaces/WebSocketDeltaUpdate.html +9 -0
- package/docs/interfaces/WebSocketSubscription.html +4 -0
- package/docs/interfaces/WebSocketTradeUpdate.html +6 -0
- package/docs/interfaces/WebSocketUserUpdate.html +6 -0
- package/docs/interfaces/WithdrawalClaim.html +14 -0
- package/docs/interfaces/WithdrawalParams.html +8 -0
- package/docs/modules.html +1 -70
- package/docs/types/BigIntValue.html +2 -2
- package/docs/types/WebSocketMessage.html +1 -0
- package/docs/variables/DEBUG_KEYS.html +1 -1
- package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
- package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
- package/docs/variables/DEV_URL.html +1 -1
- package/docs/variables/MAX_BUFFER_LEN.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/docs/variables/_private.html +2 -0
- package/eslint.config.mjs +66 -0
- package/package.json +12 -13
- package/src/bridge/client.ts +10 -10
- package/src/bridge/const.ts +24 -24
- package/src/bridge/index.ts +4 -4
- package/src/bridge/types.ts +10 -10
- package/src/bridge/utils.ts +14 -14
- package/src/const.ts +18 -18
- package/src/gen/nord.ts +1 -4
- package/src/idl/bridge.ts +186 -186
- package/src/index.ts +8 -8
- package/src/nord/api/actions.ts +25 -25
- package/src/nord/api/core.ts +16 -16
- package/src/nord/api/market.ts +15 -15
- package/src/nord/api/metrics.ts +16 -16
- package/src/nord/api/queries.ts +12 -12
- package/src/nord/client/Nord.ts +27 -27
- package/src/nord/client/NordUser.ts +59 -63
- package/src/nord/index.ts +9 -9
- package/src/nord/models/Subscriber.ts +11 -12
- package/src/nord/utils/NordError.ts +2 -2
- package/src/types.ts +12 -12
- package/src/utils.ts +20 -20
- package/src/websocket/NordWebSocketClient.ts +42 -42
- package/src/websocket/events.ts +1 -1
- package/src/websocket/index.ts +2 -2
- package/tests/utils.spec.ts +24 -24
- package/tsconfig.eslint.json +12 -0
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -31
- package/dist/abis/ERC20_ABI.d.ts +0 -39
- package/dist/abis/ERC20_ABI.js +0 -313
- package/dist/abis/NORD_GETTERS_FACET_ABI.d.ts +0 -34
- package/dist/abis/NORD_GETTERS_FACET_ABI.js +0 -195
- package/dist/abis/NORD_RAMP_FACET_ABI.d.ts +0 -35
- package/dist/abis/NORD_RAMP_FACET_ABI.js +0 -144
- package/dist/abis/index.d.ts +0 -3
- package/dist/abis/index.js +0 -9
- package/dist/bridge/NordUser.d.ts +0 -78
- package/dist/bridge/NordUser.js +0 -196
- package/dist/client.d.ts +0 -70
- package/dist/client.js +0 -129
- package/dist/constants/endpoints.d.ts +0 -65
- package/dist/constants/endpoints.js +0 -68
- package/dist/models/account.d.ts +0 -58
- package/dist/models/account.js +0 -6
- package/dist/models/index.d.ts +0 -8
- package/dist/models/index.js +0 -28
- package/dist/models/market.d.ts +0 -137
- package/dist/models/market.js +0 -6
- package/dist/models/order.d.ts +0 -211
- package/dist/models/order.js +0 -6
- package/dist/models/token.d.ts +0 -50
- package/dist/models/token.js +0 -6
- package/dist/nord/Nord.d.ts +0 -249
- package/dist/nord/Nord.js +0 -388
- package/dist/nord/NordError.d.ts +0 -23
- package/dist/nord/NordError.js +0 -48
- package/dist/nord/NordImpl.d.ts +0 -11
- package/dist/nord/NordImpl.js +0 -26
- package/dist/nord/NordUser.d.ts +0 -243
- package/dist/nord/NordUser.js +0 -481
- package/dist/nord/Subscriber.d.ts +0 -37
- package/dist/nord/Subscriber.js +0 -29
- package/dist/nord/actions.d.ts +0 -101
- package/dist/nord/actions.js +0 -254
- package/dist/nord/api/index.d.ts +0 -1
- package/dist/nord/api/index.js +0 -17
- package/dist/nord/api/orderFunctions.d.ts +0 -168
- package/dist/nord/api/orderFunctions.js +0 -133
- package/dist/nord/core.d.ts +0 -48
- package/dist/nord/core.js +0 -97
- package/dist/nord/market.d.ts +0 -36
- package/dist/nord/market.js +0 -90
- package/dist/nord/metrics.d.ts +0 -67
- package/dist/nord/metrics.js +0 -124
- package/dist/nord/queries.d.ts +0 -81
- package/dist/nord/queries.js +0 -181
- package/dist/nord/types.d.ts +0 -88
- package/dist/nord/types.js +0 -2
- package/dist/nord/websocket.d.ts +0 -49
- package/dist/nord/websocket.js +0 -107
- package/dist/operations/account.d.ts +0 -58
- package/dist/operations/account.js +0 -112
- package/dist/operations/market.d.ts +0 -65
- package/dist/operations/market.js +0 -131
- package/dist/operations/orders.d.ts +0 -57
- package/dist/operations/orders.js +0 -129
- package/dist/solana/NordUser.d.ts +0 -78
- package/dist/solana/NordUser.js +0 -196
- package/dist/solana/client.d.ts +0 -139
- package/dist/solana/client.js +0 -360
- package/dist/solana/const.d.ts +0 -23
- package/dist/solana/const.js +0 -47
- package/dist/solana/index.d.ts +0 -5
- package/dist/solana/index.js +0 -23
- package/dist/solana/types.d.ts +0 -118
- package/dist/solana/types.js +0 -16
- package/dist/solana/utils.d.ts +0 -64
- package/dist/solana/utils.js +0 -131
- package/dist/types/api.d.ts +0 -152
- package/dist/types/api.js +0 -6
- package/dist/types/config.d.ts +0 -34
- package/dist/types/config.js +0 -6
- package/dist/utils/errors.d.ts +0 -96
- package/dist/utils/errors.js +0 -132
- package/dist/utils/http.d.ts +0 -35
- package/dist/utils/http.js +0 -105
- package/dist/websocket/client.d.ts +0 -93
- package/dist/websocket/client.js +0 -222
- package/dist/websocket.d.ts +0 -55
- package/dist/websocket.js +0 -211
- package/docs/interfaces/ERC20TokenInfo.html +0 -5
- package/docs/variables/DEV_CONTRACT_ADDRESS.html +0 -1
- package/docs/variables/ERC20_ABI.html +0 -1
- package/docs/variables/EVM_DEV_URL.html +0 -1
- package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +0 -1
- package/docs/variables/NORD_GETTERS_FACET_ABI.html +0 -1
- package/docs/variables/NORD_RAMP_FACET_ABI.html +0 -1
|
@@ -68,19 +68,19 @@ class NordUser {
|
|
|
68
68
|
/** SPL token information */
|
|
69
69
|
this.splTokenInfos = [];
|
|
70
70
|
if (!params.nord) {
|
|
71
|
-
throw new NordError_1.NordError(
|
|
71
|
+
throw new NordError_1.NordError("Nord instance is required");
|
|
72
72
|
}
|
|
73
73
|
if (!params.address) {
|
|
74
|
-
throw new NordError_1.NordError(
|
|
74
|
+
throw new NordError_1.NordError("Address is required");
|
|
75
75
|
}
|
|
76
76
|
if (!params.walletSignFn) {
|
|
77
|
-
throw new NordError_1.NordError(
|
|
77
|
+
throw new NordError_1.NordError("Wallet sign function is required");
|
|
78
78
|
}
|
|
79
79
|
if (!params.sessionSignFn) {
|
|
80
|
-
throw new NordError_1.NordError(
|
|
80
|
+
throw new NordError_1.NordError("Session sign function is required");
|
|
81
81
|
}
|
|
82
82
|
if (!params.sessionPubKey) {
|
|
83
|
-
throw new NordError_1.NordError(
|
|
83
|
+
throw new NordError_1.NordError("Session public key is required");
|
|
84
84
|
}
|
|
85
85
|
this.nord = params.nord;
|
|
86
86
|
this.address = params.address;
|
|
@@ -92,7 +92,7 @@ class NordUser {
|
|
|
92
92
|
this.connection =
|
|
93
93
|
params.connection ||
|
|
94
94
|
new web3_js_1.Connection(params.nord.solanaUrl, {
|
|
95
|
-
commitment:
|
|
95
|
+
commitment: "confirmed",
|
|
96
96
|
});
|
|
97
97
|
// Set sessionId if provided
|
|
98
98
|
if (params.sessionId !== undefined) {
|
|
@@ -103,7 +103,7 @@ class NordUser {
|
|
|
103
103
|
this.initBridgeClient();
|
|
104
104
|
}
|
|
105
105
|
catch (error) {
|
|
106
|
-
console.warn(
|
|
106
|
+
console.warn("Failed to initialize bridge client:", error);
|
|
107
107
|
}
|
|
108
108
|
// Convert tokens from info endpoint to SPLTokenInfo
|
|
109
109
|
if (this.nord.tokens && this.nord.tokens.length > 0) {
|
|
@@ -154,19 +154,17 @@ class NordUser {
|
|
|
154
154
|
if (!this.getSolanaPublicKey() ||
|
|
155
155
|
!this.connection ||
|
|
156
156
|
!this.nord.solanaProgramId) {
|
|
157
|
-
throw new NordError_1.NordError(
|
|
157
|
+
throw new NordError_1.NordError("Solana public key, connection, and program ID are required to initialize bridge client");
|
|
158
158
|
}
|
|
159
159
|
// Create an Anchor wallet that uses walletSignFn for signing
|
|
160
160
|
const wallet = {
|
|
161
161
|
publicKey: this.getSolanaPublicKey(),
|
|
162
162
|
signTransaction: async (tx) => {
|
|
163
|
-
await this.transactionSignFn(tx);
|
|
164
|
-
return tx;
|
|
163
|
+
return await this.transactionSignFn(tx);
|
|
165
164
|
},
|
|
166
165
|
signAllTransactions: async (txs) => {
|
|
167
166
|
return Promise.all(txs.map(async (tx) => {
|
|
168
|
-
await this.transactionSignFn(tx);
|
|
169
|
-
return tx;
|
|
167
|
+
return await this.transactionSignFn(tx);
|
|
170
168
|
}));
|
|
171
169
|
},
|
|
172
170
|
// Create a keypair-like object with just the public key
|
|
@@ -179,7 +177,7 @@ class NordUser {
|
|
|
179
177
|
this.bridgeClient = new client_1.SolanaBridgeClient({
|
|
180
178
|
rpcUrl: this.connection.rpcEndpoint,
|
|
181
179
|
programId: this.nord.solanaProgramId,
|
|
182
|
-
commitment:
|
|
180
|
+
commitment: "confirmed",
|
|
183
181
|
tokenInfos: this.splTokenInfos,
|
|
184
182
|
}, wallet);
|
|
185
183
|
}
|
|
@@ -198,7 +196,7 @@ class NordUser {
|
|
|
198
196
|
const publicKey = keypair.publicKey;
|
|
199
197
|
// Create a signing function that uses the keypair but doesn't expose it
|
|
200
198
|
const walletSignFn = async (message) => {
|
|
201
|
-
const messageBuffer = typeof message ===
|
|
199
|
+
const messageBuffer = typeof message === "string"
|
|
202
200
|
? Buffer.from(message)
|
|
203
201
|
: Buffer.from(message);
|
|
204
202
|
// Use the keypair to sign the message
|
|
@@ -218,7 +216,7 @@ class NordUser {
|
|
|
218
216
|
return transaction;
|
|
219
217
|
}
|
|
220
218
|
// For other transaction types, would need specific implementation
|
|
221
|
-
throw new NordError_1.NordError(
|
|
219
|
+
throw new NordError_1.NordError("Unsupported transaction type for signing");
|
|
222
220
|
};
|
|
223
221
|
return new NordUser({
|
|
224
222
|
nord,
|
|
@@ -232,7 +230,7 @@ class NordUser {
|
|
|
232
230
|
});
|
|
233
231
|
}
|
|
234
232
|
catch (error) {
|
|
235
|
-
throw new NordError_1.NordError(
|
|
233
|
+
throw new NordError_1.NordError("Failed to create NordUser from private key", {
|
|
236
234
|
cause: error,
|
|
237
235
|
});
|
|
238
236
|
}
|
|
@@ -246,13 +244,13 @@ class NordUser {
|
|
|
246
244
|
*/
|
|
247
245
|
async getAssociatedTokenAccount(mint) {
|
|
248
246
|
if (!this.getSolanaPublicKey()) {
|
|
249
|
-
throw new NordError_1.NordError(
|
|
247
|
+
throw new NordError_1.NordError("Solana public key is required to get associated token account");
|
|
250
248
|
}
|
|
251
249
|
try {
|
|
252
250
|
return await (0, spl_token_1.getAssociatedTokenAddress)(mint, this.getSolanaPublicKey(), false, spl_token_1.TOKEN_2022_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
253
251
|
}
|
|
254
252
|
catch (error) {
|
|
255
|
-
throw new NordError_1.NordError(
|
|
253
|
+
throw new NordError_1.NordError("Failed to get associated token account", {
|
|
256
254
|
cause: error,
|
|
257
255
|
});
|
|
258
256
|
}
|
|
@@ -267,7 +265,7 @@ class NordUser {
|
|
|
267
265
|
*/
|
|
268
266
|
async depositSpl(amount, tokenId) {
|
|
269
267
|
if (!this.bridgeClient || !this.getSolanaPublicKey() || !this.connection) {
|
|
270
|
-
throw new NordError_1.NordError(
|
|
268
|
+
throw new NordError_1.NordError("Bridge client, Solana public key, and connection are required for deposit");
|
|
271
269
|
}
|
|
272
270
|
try {
|
|
273
271
|
// Find the token info
|
|
@@ -304,7 +302,7 @@ class NordUser {
|
|
|
304
302
|
*/
|
|
305
303
|
async withdrawSpl(claim) {
|
|
306
304
|
if (!this.bridgeClient || !this.getSolanaPublicKey() || !this.connection) {
|
|
307
|
-
throw new NordError_1.NordError(
|
|
305
|
+
throw new NordError_1.NordError("Bridge client, Solana public key, and connection are required for withdrawal");
|
|
308
306
|
}
|
|
309
307
|
try {
|
|
310
308
|
// Find the token info
|
|
@@ -324,9 +322,7 @@ class NordUser {
|
|
|
324
322
|
secretKey: new Uint8Array(64), // Dummy secret key, not actually used
|
|
325
323
|
sign: async (tx) => {
|
|
326
324
|
const message = tx.serializeMessage();
|
|
327
|
-
|
|
328
|
-
// todo: fixxxxx
|
|
329
|
-
// tx.addSignature(this.getSolanaPublicKey()!, signature);
|
|
325
|
+
await this.walletSignFn(message);
|
|
330
326
|
return tx;
|
|
331
327
|
},
|
|
332
328
|
};
|
|
@@ -338,7 +334,7 @@ class NordUser {
|
|
|
338
334
|
}, transactionSigner);
|
|
339
335
|
}
|
|
340
336
|
catch (error) {
|
|
341
|
-
throw new NordError_1.NordError(
|
|
337
|
+
throw new NordError_1.NordError("Failed to withdraw SPL tokens", { cause: error });
|
|
342
338
|
}
|
|
343
339
|
}
|
|
344
340
|
/**
|
|
@@ -357,7 +353,7 @@ class NordUser {
|
|
|
357
353
|
async updateAccountId() {
|
|
358
354
|
try {
|
|
359
355
|
if (!this.publicKey) {
|
|
360
|
-
throw new NordError_1.NordError(
|
|
356
|
+
throw new NordError_1.NordError("Public key is required to update account ID");
|
|
361
357
|
}
|
|
362
358
|
const resp = await this.nord.getUserAccountIds({
|
|
363
359
|
pubkey: this.publicKey.toBase58(),
|
|
@@ -365,7 +361,7 @@ class NordUser {
|
|
|
365
361
|
this.accountIds = resp.accountIds;
|
|
366
362
|
}
|
|
367
363
|
catch (error) {
|
|
368
|
-
throw new NordError_1.NordError(
|
|
364
|
+
throw new NordError_1.NordError("Failed to update account ID", { cause: error });
|
|
369
365
|
}
|
|
370
366
|
}
|
|
371
367
|
/**
|
|
@@ -398,7 +394,7 @@ class NordUser {
|
|
|
398
394
|
this.orders[accountData.accountId] = accountData.orders.map((order) => {
|
|
399
395
|
return {
|
|
400
396
|
orderId: order.orderId,
|
|
401
|
-
isLong: order.side ===
|
|
397
|
+
isLong: order.side === "bid",
|
|
402
398
|
size: order.size,
|
|
403
399
|
price: order.price,
|
|
404
400
|
marketId: order.marketId,
|
|
@@ -448,7 +444,7 @@ class NordUser {
|
|
|
448
444
|
*/
|
|
449
445
|
checkSessionValidity() {
|
|
450
446
|
if (this.sessionId === undefined || this.sessionId === BigInt(0)) {
|
|
451
|
-
throw new NordError_1.NordError(
|
|
447
|
+
throw new NordError_1.NordError("Invalid or empty session ID. Please create or refresh your session.");
|
|
452
448
|
}
|
|
453
449
|
}
|
|
454
450
|
/**
|
|
@@ -463,7 +459,7 @@ class NordUser {
|
|
|
463
459
|
this.checkSessionValidity();
|
|
464
460
|
await (0, actions_1.withdraw)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
|
|
465
461
|
sizeDecimals: (0, utils_2.findToken)(this.nord.tokens, tokenId).decimals,
|
|
466
|
-
sessionId: (0, utils_2.optExpect)(this.sessionId,
|
|
462
|
+
sessionId: (0, utils_2.optExpect)(this.sessionId, "No session"),
|
|
467
463
|
tokenId: tokenId,
|
|
468
464
|
amount,
|
|
469
465
|
});
|
|
@@ -487,7 +483,7 @@ class NordUser {
|
|
|
487
483
|
throw new NordError_1.NordError(`Market with ID ${params.marketId} not found`);
|
|
488
484
|
}
|
|
489
485
|
return (0, actions_1.placeOrder)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
|
|
490
|
-
sessionId: (0, utils_2.optExpect)(this.sessionId,
|
|
486
|
+
sessionId: (0, utils_2.optExpect)(this.sessionId, "No session"),
|
|
491
487
|
senderId: params.accountId,
|
|
492
488
|
sizeDecimals: market.sizeDecimals,
|
|
493
489
|
priceDecimals: market.priceDecimals,
|
|
@@ -501,7 +497,7 @@ class NordUser {
|
|
|
501
497
|
});
|
|
502
498
|
}
|
|
503
499
|
catch (error) {
|
|
504
|
-
throw new NordError_1.NordError(
|
|
500
|
+
throw new NordError_1.NordError("Failed to place order", { cause: error });
|
|
505
501
|
}
|
|
506
502
|
}
|
|
507
503
|
/**
|
|
@@ -513,11 +509,11 @@ class NordUser {
|
|
|
513
509
|
* @throws {NordError} If the operation fails
|
|
514
510
|
*/
|
|
515
511
|
async cancelOrder(orderId, providedAccountId) {
|
|
516
|
-
|
|
512
|
+
const accountId = providedAccountId != null ? providedAccountId : this.accountIds?.[0];
|
|
517
513
|
try {
|
|
518
514
|
this.checkSessionValidity();
|
|
519
515
|
return (0, actions_1.cancelOrder)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
|
|
520
|
-
sessionId: (0, utils_2.optExpect)(this.sessionId,
|
|
516
|
+
sessionId: (0, utils_2.optExpect)(this.sessionId, "No session"),
|
|
521
517
|
senderId: accountId,
|
|
522
518
|
orderId,
|
|
523
519
|
});
|
|
@@ -539,16 +535,16 @@ class NordUser {
|
|
|
539
535
|
this.checkSessionValidity();
|
|
540
536
|
const token = (0, utils_2.findToken)(this.nord.tokens, params.tokenId);
|
|
541
537
|
await (0, actions_1.transfer)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
|
|
542
|
-
sessionId: (0, utils_2.optExpect)(this.sessionId,
|
|
543
|
-
fromAccountId: (0, utils_2.optExpect)(params.fromAccountId,
|
|
544
|
-
toAccountId: (0, utils_2.optExpect)(params.toAccountId,
|
|
538
|
+
sessionId: (0, utils_2.optExpect)(this.sessionId, "No session"),
|
|
539
|
+
fromAccountId: (0, utils_2.optExpect)(params.fromAccountId, "No source account"),
|
|
540
|
+
toAccountId: (0, utils_2.optExpect)(params.toAccountId, "No target account"),
|
|
545
541
|
tokenId: params.tokenId,
|
|
546
542
|
tokenDecimals: token.decimals,
|
|
547
543
|
amount: params.amount,
|
|
548
544
|
});
|
|
549
545
|
}
|
|
550
546
|
catch (error) {
|
|
551
|
-
throw new NordError_1.NordError(
|
|
547
|
+
throw new NordError_1.NordError("Failed to transfer tokens", { cause: error });
|
|
552
548
|
}
|
|
553
549
|
}
|
|
554
550
|
/**
|
|
@@ -570,13 +566,13 @@ class NordUser {
|
|
|
570
566
|
to: newUser,
|
|
571
567
|
tokenId: params.tokenId,
|
|
572
568
|
amount: params.amount,
|
|
573
|
-
fromAccountId: (0, utils_2.optExpect)(this.accountIds?.[0],
|
|
574
|
-
toAccountId: (0, utils_2.optExpect)(newUser.accountIds?.[0],
|
|
569
|
+
fromAccountId: (0, utils_2.optExpect)(this.accountIds?.[0], "No account ID"),
|
|
570
|
+
toAccountId: (0, utils_2.optExpect)(newUser.accountIds?.[0], "No account ID for new user"),
|
|
575
571
|
});
|
|
576
572
|
return newUser;
|
|
577
573
|
}
|
|
578
574
|
catch (error) {
|
|
579
|
-
throw new NordError_1.NordError(
|
|
575
|
+
throw new NordError_1.NordError("Failed to create account", { cause: error });
|
|
580
576
|
}
|
|
581
577
|
}
|
|
582
578
|
/**
|
|
@@ -600,9 +596,9 @@ class NordUser {
|
|
|
600
596
|
}
|
|
601
597
|
// Check if error is rate limiting related
|
|
602
598
|
const isRateLimitError = error instanceof Error &&
|
|
603
|
-
(error.message.includes(
|
|
604
|
-
error.message.includes(
|
|
605
|
-
error.message.includes(
|
|
599
|
+
(error.message.includes("rate limit") ||
|
|
600
|
+
error.message.includes("429") ||
|
|
601
|
+
error.message.includes("too many requests"));
|
|
606
602
|
if (!isRateLimitError) {
|
|
607
603
|
throw error;
|
|
608
604
|
}
|
|
@@ -626,16 +622,16 @@ class NordUser {
|
|
|
626
622
|
async getSolanaBalances(options = {}) {
|
|
627
623
|
const { includeZeroBalances = true, includeTokenAccounts = false, maxConcurrent = 5, maxRetries = 3, } = options;
|
|
628
624
|
if (!this.connection || !this.getSolanaPublicKey()) {
|
|
629
|
-
throw new NordError_1.NordError(
|
|
625
|
+
throw new NordError_1.NordError("Connection and Solana public key are required to get Solana balances");
|
|
630
626
|
}
|
|
631
627
|
const balances = {};
|
|
632
628
|
const tokenAccounts = {};
|
|
633
629
|
try {
|
|
634
630
|
// Get SOL balance (native token)
|
|
635
631
|
const solBalance = await this.retryWithBackoff(() => this.connection.getBalance(this.getSolanaPublicKey()), maxRetries);
|
|
636
|
-
balances[
|
|
632
|
+
balances["SOL"] = solBalance / 1e9; // Convert lamports to SOL
|
|
637
633
|
if (includeTokenAccounts) {
|
|
638
|
-
tokenAccounts[
|
|
634
|
+
tokenAccounts["SOL"] = this.getSolanaPublicKey().toString();
|
|
639
635
|
}
|
|
640
636
|
// Get SPL token balances using mintAddr from Nord tokens
|
|
641
637
|
if (this.nord.tokens && this.nord.tokens.length > 0) {
|
|
@@ -658,7 +654,7 @@ class NordUser {
|
|
|
658
654
|
balances[token.symbol] = balance;
|
|
659
655
|
}
|
|
660
656
|
}
|
|
661
|
-
catch
|
|
657
|
+
catch {
|
|
662
658
|
// Token account might not exist yet, set balance to 0
|
|
663
659
|
if (includeZeroBalances) {
|
|
664
660
|
balances[token.symbol] = 0;
|
|
@@ -679,7 +675,7 @@ class NordUser {
|
|
|
679
675
|
return includeTokenAccounts ? { balances, tokenAccounts } : { balances };
|
|
680
676
|
}
|
|
681
677
|
catch (error) {
|
|
682
|
-
throw new NordError_1.NordError(
|
|
678
|
+
throw new NordError_1.NordError("Failed to get Solana token balances", {
|
|
683
679
|
cause: error,
|
|
684
680
|
});
|
|
685
681
|
}
|
|
@@ -694,7 +690,7 @@ class NordUser {
|
|
|
694
690
|
return new web3_js_1.PublicKey(this.address);
|
|
695
691
|
}
|
|
696
692
|
catch (error) {
|
|
697
|
-
throw new NordError_1.NordError(
|
|
693
|
+
throw new NordError_1.NordError("Invalid Solana address", { cause: error });
|
|
698
694
|
}
|
|
699
695
|
}
|
|
700
696
|
}
|
package/dist/nord/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { Nord } from
|
|
2
|
-
export { NordUser } from
|
|
3
|
-
export { NordError } from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
1
|
+
export { Nord } from "./client/Nord";
|
|
2
|
+
export { NordUser } from "./client/NordUser";
|
|
3
|
+
export { NordError } from "./utils/NordError";
|
|
4
|
+
export * from "./api/core";
|
|
5
|
+
export * from "./api/metrics";
|
|
6
|
+
export * from "./api/queries";
|
|
7
|
+
export * from "./api/market";
|
|
8
|
+
export * from "./api/actions";
|
|
9
|
+
export * from "./models/Subscriber";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EventEmitter } from
|
|
2
|
-
import {
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { Account, DeltaEvent, OrderbookResponse, SubscriberConfig, Trade, Trades } from "../../types";
|
|
3
3
|
/**
|
|
4
4
|
* Subscriber class for handling WebSocket subscriptions
|
|
5
5
|
*/
|
|
@@ -21,8 +21,8 @@ export declare class Subscriber {
|
|
|
21
21
|
* Interface for orderbook subscription
|
|
22
22
|
*/
|
|
23
23
|
export interface OrderbookSubscription extends EventEmitter {
|
|
24
|
-
on(event:
|
|
25
|
-
on(event:
|
|
24
|
+
on(event: "message", listener: (data: OrderbookResponse) => void): this;
|
|
25
|
+
on(event: "error", listener: (error: Error) => void): this;
|
|
26
26
|
close(): void;
|
|
27
27
|
removeAllListeners(event?: string): this;
|
|
28
28
|
}
|
|
@@ -30,8 +30,8 @@ export interface OrderbookSubscription extends EventEmitter {
|
|
|
30
30
|
* Interface for trade subscription
|
|
31
31
|
*/
|
|
32
32
|
export interface TradeSubscription extends EventEmitter {
|
|
33
|
-
on(event:
|
|
34
|
-
on(event:
|
|
33
|
+
on(event: "message", listener: (data: Trade[]) => void): this;
|
|
34
|
+
on(event: "error", listener: (error: Error) => void): this;
|
|
35
35
|
close(): void;
|
|
36
36
|
removeAllListeners(event?: string): this;
|
|
37
37
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.Subscriber = void 0;
|
|
7
|
-
const ws_1 = __importDefault(require("ws"));
|
|
8
4
|
const utils_1 = require("../../utils");
|
|
9
5
|
/**
|
|
10
6
|
* Subscriber class for handling WebSocket subscriptions
|
|
@@ -23,7 +19,7 @@ class Subscriber {
|
|
|
23
19
|
* Subscribe to WebSocket events
|
|
24
20
|
*/
|
|
25
21
|
subscribe() {
|
|
26
|
-
|
|
22
|
+
// TODO: Implement subscription logic
|
|
27
23
|
}
|
|
28
24
|
}
|
|
29
25
|
exports.Subscriber = Subscriber;
|
|
@@ -13,7 +13,7 @@ class NordError extends Error {
|
|
|
13
13
|
*/
|
|
14
14
|
constructor(message, options = {}) {
|
|
15
15
|
super(message);
|
|
16
|
-
this.name =
|
|
16
|
+
this.name = "NordError";
|
|
17
17
|
this.cause = options.cause;
|
|
18
18
|
this.statusCode = options.statusCode;
|
|
19
19
|
this.details = options.details;
|
|
@@ -24,7 +24,7 @@ class NordError extends Error {
|
|
|
24
24
|
// Handle nested errors
|
|
25
25
|
if (this.cause instanceof Error) {
|
|
26
26
|
this.stack =
|
|
27
|
-
this.stack +
|
|
27
|
+
this.stack + "\nCaused by: " + (this.cause.stack || this.cause.message);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
/**
|
package/dist/types.d.ts
CHANGED
package/dist/types.js
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Decimal } from
|
|
2
|
-
import { KeyType, type Market, type Token } from
|
|
3
|
-
import * as proto from
|
|
4
|
-
import { ethers } from
|
|
5
|
-
import { RequestInfo, RequestInit, Response } from
|
|
6
|
-
import { BN } from
|
|
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
|
+
import { BN } from "@coral-xyz/anchor";
|
|
7
7
|
export declare const SESSION_TTL: bigint;
|
|
8
8
|
export declare const ZERO_DECIMAL: Decimal;
|
|
9
9
|
export declare const MAX_BUFFER_LEN = 10000;
|
package/dist/utils.js
CHANGED
|
@@ -38,7 +38,7 @@ function panic(message) {
|
|
|
38
38
|
}
|
|
39
39
|
function assert(predicate, message) {
|
|
40
40
|
if (!predicate)
|
|
41
|
-
panic(message ??
|
|
41
|
+
panic(message ?? "Assertion violated");
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Extracts value out of optional if it's defined, or throws error if it's not
|
|
@@ -57,7 +57,7 @@ function optExpect(value, message) {
|
|
|
57
57
|
* @returns
|
|
58
58
|
*/
|
|
59
59
|
function optUnwrap(value) {
|
|
60
|
-
return optExpect(value,
|
|
60
|
+
return optExpect(value, "Optional contains no value");
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Applies function to value if it's defined, or passes `undefined` through
|
|
@@ -99,7 +99,7 @@ function signAction(action, sk, keyType) {
|
|
|
99
99
|
sig = secp256k1_1.secp256k1.sign((0, sha256_1.sha256)(action), sk).toCompactRawBytes();
|
|
100
100
|
}
|
|
101
101
|
else {
|
|
102
|
-
throw new Error(
|
|
102
|
+
throw new Error("Invalid key type");
|
|
103
103
|
}
|
|
104
104
|
return new Uint8Array([...action, ...sig]);
|
|
105
105
|
}
|
|
@@ -236,13 +236,13 @@ function decodeLengthDelimited(bytes, coder) {
|
|
|
236
236
|
}
|
|
237
237
|
function checkPubKeyLength(keyType, len) {
|
|
238
238
|
if (keyType === types_1.KeyType.Bls12_381) {
|
|
239
|
-
throw new Error(
|
|
239
|
+
throw new Error("Cannot create a user using Bls12_381, use Ed25119 or Secp256k1 instead.");
|
|
240
240
|
}
|
|
241
241
|
if (len !== 32 && keyType === types_1.KeyType.Ed25519) {
|
|
242
|
-
throw new Error(
|
|
242
|
+
throw new Error("Ed25519 pubkeys must be 32 length.");
|
|
243
243
|
}
|
|
244
244
|
if (len !== 33 && keyType === types_1.KeyType.Secp256k1) {
|
|
245
|
-
throw new Error(
|
|
245
|
+
throw new Error("Secp256k1 pubkeys must be 33 length.");
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
function findMarket(markets, marketId) {
|
|
@@ -266,11 +266,11 @@ function findToken(tokens, tokenId) {
|
|
|
266
266
|
*/
|
|
267
267
|
function toBN(amount, decimals) {
|
|
268
268
|
const amountString = amount.toFixed(decimals);
|
|
269
|
-
const [whole, fraction] = amountString.split(
|
|
269
|
+
const [whole, fraction] = amountString.split(".");
|
|
270
270
|
// Convert to smallest units (no decimals)
|
|
271
271
|
const wholeBN = new anchor_1.BN(whole).mul(new anchor_1.BN(10).pow(new anchor_1.BN(decimals)));
|
|
272
272
|
const fractionBN = fraction
|
|
273
|
-
? new anchor_1.BN(fraction.padEnd(decimals,
|
|
273
|
+
? new anchor_1.BN(fraction.padEnd(decimals, "0").slice(0, decimals))
|
|
274
274
|
: new anchor_1.BN(0);
|
|
275
275
|
return wholeBN.add(fractionBN);
|
|
276
276
|
}
|