@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,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Market-related operations
|
|
3
|
+
* @module operations/market
|
|
4
|
+
*/
|
|
5
|
+
import { NordClientConfig } from '../types/config';
|
|
6
|
+
import { Market, OrderbookData, Trade, Candle } from '../models';
|
|
7
|
+
/**
|
|
8
|
+
* Market operations implementation
|
|
9
|
+
*/
|
|
10
|
+
export declare class MarketOperations {
|
|
11
|
+
/**
|
|
12
|
+
* Client configuration
|
|
13
|
+
*/
|
|
14
|
+
private readonly config;
|
|
15
|
+
/**
|
|
16
|
+
* Create a new MarketOperations instance
|
|
17
|
+
*
|
|
18
|
+
* @param config - Client configuration
|
|
19
|
+
*/
|
|
20
|
+
constructor(config: NordClientConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Get all available markets
|
|
23
|
+
*
|
|
24
|
+
* @returns Promise resolving to an array of markets
|
|
25
|
+
* @throws {NordApiError} If the API request fails
|
|
26
|
+
*/
|
|
27
|
+
getMarkets(): Promise<Market[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Get orderbook data for a specific market
|
|
30
|
+
*
|
|
31
|
+
* @param market - Market symbol (e.g., "BTCUSDC")
|
|
32
|
+
* @returns Promise resolving to orderbook data
|
|
33
|
+
* @throws {NordValidationError} If the market parameter is invalid
|
|
34
|
+
* @throws {NordApiError} If the API request fails
|
|
35
|
+
*/
|
|
36
|
+
getOrderbook(market: string): Promise<OrderbookData>;
|
|
37
|
+
/**
|
|
38
|
+
* Get recent trades for a specific market
|
|
39
|
+
*
|
|
40
|
+
* @param market - Market symbol (e.g., "BTCUSDC")
|
|
41
|
+
* @param limit - Maximum number of trades to return (optional)
|
|
42
|
+
* @returns Promise resolving to an array of trades
|
|
43
|
+
* @throws {NordValidationError} If the market parameter is invalid
|
|
44
|
+
* @throws {NordApiError} If the API request fails
|
|
45
|
+
*/
|
|
46
|
+
getTrades(market: string, limit?: number): Promise<Trade[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Get candle data for a specific market and timeframe
|
|
49
|
+
*
|
|
50
|
+
* @param market - Market symbol (e.g., "BTCUSDC")
|
|
51
|
+
* @param timeframe - Candle timeframe (e.g., "1m", "5m", "1h", "1d")
|
|
52
|
+
* @param limit - Maximum number of candles to return (optional)
|
|
53
|
+
* @returns Promise resolving to an array of candles
|
|
54
|
+
* @throws {NordValidationError} If any parameters are invalid
|
|
55
|
+
* @throws {NordApiError} If the API request fails
|
|
56
|
+
*/
|
|
57
|
+
getCandles(market: string, timeframe: string, limit?: number): Promise<Candle[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Get current server timestamp
|
|
60
|
+
*
|
|
61
|
+
* @returns Promise resolving to the current server timestamp in milliseconds
|
|
62
|
+
* @throws {NordApiError} If the API request fails
|
|
63
|
+
*/
|
|
64
|
+
getTimestamp(): Promise<number>;
|
|
65
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Market-related operations
|
|
4
|
+
* @module operations/market
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.MarketOperations = void 0;
|
|
8
|
+
const errors_1 = require("../utils/errors");
|
|
9
|
+
const http_1 = require("../utils/http");
|
|
10
|
+
const endpoints_1 = require("../constants/endpoints");
|
|
11
|
+
/**
|
|
12
|
+
* Market operations implementation
|
|
13
|
+
*/
|
|
14
|
+
class MarketOperations {
|
|
15
|
+
/**
|
|
16
|
+
* Create a new MarketOperations instance
|
|
17
|
+
*
|
|
18
|
+
* @param config - Client configuration
|
|
19
|
+
*/
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this.config = config;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get all available markets
|
|
25
|
+
*
|
|
26
|
+
* @returns Promise resolving to an array of markets
|
|
27
|
+
* @throws {NordApiError} If the API request fails
|
|
28
|
+
*/
|
|
29
|
+
async getMarkets() {
|
|
30
|
+
try {
|
|
31
|
+
const endpoint = `${endpoints_1.ENDPOINTS.MARKETS}`;
|
|
32
|
+
const response = await (0, http_1.httpGet)(this.config.webServerUrl, endpoint);
|
|
33
|
+
return response;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
throw new errors_1.NordApiError('Failed to fetch markets', error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.MARKETS, error instanceof Error ? error : undefined);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get orderbook data for a specific market
|
|
41
|
+
*
|
|
42
|
+
* @param market - Market symbol (e.g., "BTCUSDC")
|
|
43
|
+
* @returns Promise resolving to orderbook data
|
|
44
|
+
* @throws {NordValidationError} If the market parameter is invalid
|
|
45
|
+
* @throws {NordApiError} If the API request fails
|
|
46
|
+
*/
|
|
47
|
+
async getOrderbook(market) {
|
|
48
|
+
if (!market) {
|
|
49
|
+
throw new errors_1.NordValidationError('Market symbol is required', 'market');
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const endpoint = `${endpoints_1.ENDPOINTS.ORDERBOOK}?market=${encodeURIComponent(market)}`;
|
|
53
|
+
const response = await (0, http_1.httpGet)(this.config.webServerUrl, endpoint);
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new errors_1.NordApiError(`Failed to fetch orderbook for market ${market}`, error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.ORDERBOOK, error instanceof Error ? error : undefined);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get recent trades for a specific market
|
|
62
|
+
*
|
|
63
|
+
* @param market - Market symbol (e.g., "BTCUSDC")
|
|
64
|
+
* @param limit - Maximum number of trades to return (optional)
|
|
65
|
+
* @returns Promise resolving to an array of trades
|
|
66
|
+
* @throws {NordValidationError} If the market parameter is invalid
|
|
67
|
+
* @throws {NordApiError} If the API request fails
|
|
68
|
+
*/
|
|
69
|
+
async getTrades(market, limit) {
|
|
70
|
+
if (!market) {
|
|
71
|
+
throw new errors_1.NordValidationError('Market symbol is required', 'market');
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
let endpoint = `${endpoints_1.ENDPOINTS.TRADES}?market=${encodeURIComponent(market)}`;
|
|
75
|
+
if (limit) {
|
|
76
|
+
endpoint += `&limit=${limit}`;
|
|
77
|
+
}
|
|
78
|
+
const response = await (0, http_1.httpGet)(this.config.webServerUrl, endpoint);
|
|
79
|
+
return response;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
throw new errors_1.NordApiError(`Failed to fetch trades for market ${market}`, error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.TRADES, error instanceof Error ? error : undefined);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get candle data for a specific market and timeframe
|
|
87
|
+
*
|
|
88
|
+
* @param market - Market symbol (e.g., "BTCUSDC")
|
|
89
|
+
* @param timeframe - Candle timeframe (e.g., "1m", "5m", "1h", "1d")
|
|
90
|
+
* @param limit - Maximum number of candles to return (optional)
|
|
91
|
+
* @returns Promise resolving to an array of candles
|
|
92
|
+
* @throws {NordValidationError} If any parameters are invalid
|
|
93
|
+
* @throws {NordApiError} If the API request fails
|
|
94
|
+
*/
|
|
95
|
+
async getCandles(market, timeframe, limit) {
|
|
96
|
+
if (!market) {
|
|
97
|
+
throw new errors_1.NordValidationError('Market symbol is required', 'market');
|
|
98
|
+
}
|
|
99
|
+
if (!timeframe) {
|
|
100
|
+
throw new errors_1.NordValidationError('Timeframe is required', 'timeframe');
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
let endpoint = `${endpoints_1.ENDPOINTS.CANDLES}?market=${encodeURIComponent(market)}&timeframe=${encodeURIComponent(timeframe)}`;
|
|
104
|
+
if (limit) {
|
|
105
|
+
endpoint += `&limit=${limit}`;
|
|
106
|
+
}
|
|
107
|
+
const response = await (0, http_1.httpGet)(this.config.webServerUrl, endpoint);
|
|
108
|
+
return response;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw new errors_1.NordApiError(`Failed to fetch candles for market ${market} with timeframe ${timeframe}`, error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.CANDLES, error instanceof Error ? error : undefined);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get current server timestamp
|
|
116
|
+
*
|
|
117
|
+
* @returns Promise resolving to the current server timestamp in milliseconds
|
|
118
|
+
* @throws {NordApiError} If the API request fails
|
|
119
|
+
*/
|
|
120
|
+
async getTimestamp() {
|
|
121
|
+
try {
|
|
122
|
+
const endpoint = endpoints_1.ENDPOINTS.TIMESTAMP;
|
|
123
|
+
const response = await (0, http_1.httpGet)(this.config.webServerUrl, endpoint);
|
|
124
|
+
return response.timestamp;
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
throw new errors_1.NordApiError('Failed to fetch server timestamp', error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.TIMESTAMP, error instanceof Error ? error : undefined);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.MarketOperations = MarketOperations;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Order-related operations
|
|
3
|
+
* @module operations/orders
|
|
4
|
+
*/
|
|
5
|
+
import { NordClientConfig } from '../types/config';
|
|
6
|
+
import { Order, OrderResult, PlaceOrderParams } from '../models';
|
|
7
|
+
/**
|
|
8
|
+
* Order operations implementation
|
|
9
|
+
*/
|
|
10
|
+
export declare class OrderOperations {
|
|
11
|
+
/**
|
|
12
|
+
* Client configuration
|
|
13
|
+
*/
|
|
14
|
+
private readonly config;
|
|
15
|
+
/**
|
|
16
|
+
* Create a new OrderOperations instance
|
|
17
|
+
*
|
|
18
|
+
* @param config - Client configuration
|
|
19
|
+
*/
|
|
20
|
+
constructor(config: NordClientConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Place a new order
|
|
23
|
+
*
|
|
24
|
+
* @param params - Order parameters
|
|
25
|
+
* @returns Promise resolving to order result
|
|
26
|
+
* @throws {NordValidationError} If any parameters are invalid
|
|
27
|
+
* @throws {NordApiError} If the API request fails
|
|
28
|
+
*/
|
|
29
|
+
placeOrder(params: PlaceOrderParams): Promise<OrderResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Cancel an existing order
|
|
32
|
+
*
|
|
33
|
+
* @param orderId - Order ID to cancel
|
|
34
|
+
* @returns Promise resolving to true if successful
|
|
35
|
+
* @throws {NordValidationError} If the orderId parameter is invalid
|
|
36
|
+
* @throws {NordApiError} If the API request fails
|
|
37
|
+
*/
|
|
38
|
+
cancelOrder(orderId: number): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Get information about a specific order
|
|
41
|
+
*
|
|
42
|
+
* @param orderId - Order ID
|
|
43
|
+
* @returns Promise resolving to order information
|
|
44
|
+
* @throws {NordValidationError} If the orderId parameter is invalid
|
|
45
|
+
* @throws {NordApiError} If the API request fails
|
|
46
|
+
*/
|
|
47
|
+
getOrder(orderId: number): Promise<Order>;
|
|
48
|
+
/**
|
|
49
|
+
* Get all orders for an account
|
|
50
|
+
*
|
|
51
|
+
* @param accountId - Account ID
|
|
52
|
+
* @returns Promise resolving to an array of orders
|
|
53
|
+
* @throws {NordValidationError} If the accountId parameter is invalid
|
|
54
|
+
* @throws {NordApiError} If the API request fails
|
|
55
|
+
*/
|
|
56
|
+
getOrders(accountId: number): Promise<Order[]>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Order-related operations
|
|
4
|
+
* @module operations/orders
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.OrderOperations = void 0;
|
|
8
|
+
const errors_1 = require("../utils/errors");
|
|
9
|
+
const http_1 = require("../utils/http");
|
|
10
|
+
const endpoints_1 = require("../constants/endpoints");
|
|
11
|
+
/**
|
|
12
|
+
* Order operations implementation
|
|
13
|
+
*/
|
|
14
|
+
class OrderOperations {
|
|
15
|
+
/**
|
|
16
|
+
* Create a new OrderOperations instance
|
|
17
|
+
*
|
|
18
|
+
* @param config - Client configuration
|
|
19
|
+
*/
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this.config = config;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Place a new order
|
|
25
|
+
*
|
|
26
|
+
* @param params - Order parameters
|
|
27
|
+
* @returns Promise resolving to order result
|
|
28
|
+
* @throws {NordValidationError} If any parameters are invalid
|
|
29
|
+
* @throws {NordApiError} If the API request fails
|
|
30
|
+
*/
|
|
31
|
+
async placeOrder(params) {
|
|
32
|
+
// Validate required parameters
|
|
33
|
+
if (!params.market) {
|
|
34
|
+
throw new errors_1.NordValidationError('Market symbol is required', 'market');
|
|
35
|
+
}
|
|
36
|
+
if (!params.side) {
|
|
37
|
+
throw new errors_1.NordValidationError('Order side is required', 'side');
|
|
38
|
+
}
|
|
39
|
+
if (params.size === undefined || params.size <= 0) {
|
|
40
|
+
throw new errors_1.NordValidationError('Order size must be greater than zero', 'size');
|
|
41
|
+
}
|
|
42
|
+
// Type-specific validation
|
|
43
|
+
if (params.type === 'limit' && (params.price === undefined || params.price <= 0)) {
|
|
44
|
+
throw new errors_1.NordValidationError('Limit price must be greater than zero', 'price');
|
|
45
|
+
}
|
|
46
|
+
if (params.type === 'stop' && (params.stopPrice === undefined || params.stopPrice <= 0)) {
|
|
47
|
+
throw new errors_1.NordValidationError('Stop price must be greater than zero', 'stopPrice');
|
|
48
|
+
}
|
|
49
|
+
if (params.type === 'stopLimit') {
|
|
50
|
+
if (params.stopPrice === undefined || params.stopPrice <= 0) {
|
|
51
|
+
throw new errors_1.NordValidationError('Stop price must be greater than zero', 'stopPrice');
|
|
52
|
+
}
|
|
53
|
+
if (params.limitPrice === undefined || params.limitPrice <= 0) {
|
|
54
|
+
throw new errors_1.NordValidationError('Limit price must be greater than zero', 'limitPrice');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const response = await (0, http_1.httpPost)(this.config.webServerUrl, endpoints_1.ENDPOINTS.PLACE_ORDER, params);
|
|
59
|
+
return response;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw new errors_1.NordApiError(`Failed to place order for market ${params.market}`, error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.PLACE_ORDER, error instanceof Error ? error : undefined);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Cancel an existing order
|
|
67
|
+
*
|
|
68
|
+
* @param orderId - Order ID to cancel
|
|
69
|
+
* @returns Promise resolving to true if successful
|
|
70
|
+
* @throws {NordValidationError} If the orderId parameter is invalid
|
|
71
|
+
* @throws {NordApiError} If the API request fails
|
|
72
|
+
*/
|
|
73
|
+
async cancelOrder(orderId) {
|
|
74
|
+
if (orderId === undefined || orderId === null) {
|
|
75
|
+
throw new errors_1.NordValidationError('Order ID is required', 'orderId');
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const endpoint = `${endpoints_1.ENDPOINTS.CANCEL_ORDER}/${orderId}`;
|
|
79
|
+
await (0, http_1.httpDelete)(this.config.webServerUrl, endpoint);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
throw new errors_1.NordApiError(`Failed to cancel order ${orderId}`, error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.CANCEL_ORDER, error instanceof Error ? error : undefined);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get information about a specific order
|
|
88
|
+
*
|
|
89
|
+
* @param orderId - Order ID
|
|
90
|
+
* @returns Promise resolving to order information
|
|
91
|
+
* @throws {NordValidationError} If the orderId parameter is invalid
|
|
92
|
+
* @throws {NordApiError} If the API request fails
|
|
93
|
+
*/
|
|
94
|
+
async getOrder(orderId) {
|
|
95
|
+
if (orderId === undefined || orderId === null) {
|
|
96
|
+
throw new errors_1.NordValidationError('Order ID is required', 'orderId');
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const endpoint = `${endpoints_1.ENDPOINTS.ORDER}/${orderId}`;
|
|
100
|
+
const response = await (0, http_1.httpGet)(this.config.webServerUrl, endpoint);
|
|
101
|
+
return response;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
throw new errors_1.NordApiError(`Failed to fetch order ${orderId}`, error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.ORDER, error instanceof Error ? error : undefined);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get all orders for an account
|
|
109
|
+
*
|
|
110
|
+
* @param accountId - Account ID
|
|
111
|
+
* @returns Promise resolving to an array of orders
|
|
112
|
+
* @throws {NordValidationError} If the accountId parameter is invalid
|
|
113
|
+
* @throws {NordApiError} If the API request fails
|
|
114
|
+
*/
|
|
115
|
+
async getOrders(accountId) {
|
|
116
|
+
if (accountId === undefined || accountId === null) {
|
|
117
|
+
throw new errors_1.NordValidationError('Account ID is required', 'accountId');
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const endpoint = `${endpoints_1.ENDPOINTS.ORDERS}?accountId=${accountId}`;
|
|
121
|
+
const response = await (0, http_1.httpGet)(this.config.webServerUrl, endpoint);
|
|
122
|
+
return response;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
throw new errors_1.NordApiError(`Failed to fetch orders for account ${accountId}`, error instanceof errors_1.NordApiError ? error.statusCode : 500, endpoints_1.ENDPOINTS.ORDERS, error instanceof Error ? error : undefined);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.OrderOperations = OrderOperations;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { Nord } from '../nord/Nord';
|
|
3
|
+
import { Order } from '../types';
|
|
4
|
+
import { SolanaBridgeClient } from './client';
|
|
5
|
+
import { SPLTokenInfo } from './types';
|
|
6
|
+
export declare class NordUser {
|
|
7
|
+
nord: Nord;
|
|
8
|
+
publicKey: PublicKey;
|
|
9
|
+
walletSignFn: (message: Uint8Array | string) => Promise<Uint8Array>;
|
|
10
|
+
sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
|
|
11
|
+
balances: {
|
|
12
|
+
[key: string]: {
|
|
13
|
+
accountId: number;
|
|
14
|
+
balance: number;
|
|
15
|
+
symbol: string;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
orders: {
|
|
19
|
+
[key: string]: Order[];
|
|
20
|
+
};
|
|
21
|
+
accountIds?: number[];
|
|
22
|
+
sessionId?: bigint;
|
|
23
|
+
keypair?: Keypair;
|
|
24
|
+
bridgeClient?: SolanaBridgeClient;
|
|
25
|
+
connection?: Connection;
|
|
26
|
+
splTokenInfos: SPLTokenInfo[];
|
|
27
|
+
lastTs: number;
|
|
28
|
+
lastNonce: number;
|
|
29
|
+
constructor(params: {
|
|
30
|
+
nord: Nord;
|
|
31
|
+
publicKey: PublicKey | string;
|
|
32
|
+
walletSignFn: (message: Uint8Array | string) => Promise<Uint8Array>;
|
|
33
|
+
sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
|
|
34
|
+
keypair?: Keypair;
|
|
35
|
+
connection?: Connection;
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Initialize the Solana bridge client
|
|
39
|
+
*/
|
|
40
|
+
private initBridgeClient;
|
|
41
|
+
/**
|
|
42
|
+
* Create a NordUser from a private key
|
|
43
|
+
*
|
|
44
|
+
* @param nord Nord instance
|
|
45
|
+
* @param privateKey Private key as string or Uint8Array
|
|
46
|
+
* @param connection Solana connection
|
|
47
|
+
* @returns NordUser instance
|
|
48
|
+
*/
|
|
49
|
+
static fromPrivateKey(nord: Nord, privateKey: string | Uint8Array, connection?: Connection): NordUser;
|
|
50
|
+
/**
|
|
51
|
+
* Get the associated token account for a token mint
|
|
52
|
+
*
|
|
53
|
+
* @param mint Token mint address
|
|
54
|
+
* @returns Associated token account address
|
|
55
|
+
*/
|
|
56
|
+
getAssociatedTokenAccount(mint: PublicKey): Promise<PublicKey>;
|
|
57
|
+
/**
|
|
58
|
+
* Deposit SPL tokens to the bridge
|
|
59
|
+
*
|
|
60
|
+
* @param amount Amount to deposit
|
|
61
|
+
* @param tokenId Token ID
|
|
62
|
+
* @returns Transaction signature
|
|
63
|
+
*/
|
|
64
|
+
depositSpl(amount: number, tokenId: number): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Withdraw tokens from the bridge
|
|
67
|
+
*
|
|
68
|
+
* @param claim Withdrawal claim
|
|
69
|
+
* @returns Transaction signature
|
|
70
|
+
*/
|
|
71
|
+
withdrawSpl(claim: any): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Fund the user's SPL token accounts for testing
|
|
74
|
+
*
|
|
75
|
+
* @param faucetKeypair Keypair with funds to distribute
|
|
76
|
+
*/
|
|
77
|
+
fundSplWallet(faucetKeypair: Keypair): Promise<void>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NordUser = void 0;
|
|
4
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const client_1 = require("./client");
|
|
7
|
+
const const_1 = require("./const");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
class NordUser {
|
|
10
|
+
constructor(params) {
|
|
11
|
+
this.balances = {};
|
|
12
|
+
this.orders = {};
|
|
13
|
+
// Convert TokenInfo to SPLTokenInfo
|
|
14
|
+
this.splTokenInfos = [];
|
|
15
|
+
this.lastTs = 0;
|
|
16
|
+
this.lastNonce = 0;
|
|
17
|
+
this.nord = params.nord;
|
|
18
|
+
this.publicKey = typeof params.publicKey === 'string'
|
|
19
|
+
? new web3_js_1.PublicKey(params.publicKey)
|
|
20
|
+
: params.publicKey;
|
|
21
|
+
this.walletSignFn = params.walletSignFn;
|
|
22
|
+
this.sessionSignFn = params.sessionSignFn;
|
|
23
|
+
this.keypair = params.keypair;
|
|
24
|
+
this.connection = params.connection;
|
|
25
|
+
// Convert TokenInfo to SPLTokenInfo
|
|
26
|
+
this.splTokenInfos = this.nord.tokenInfos.map(tokenInfo => ({
|
|
27
|
+
mint: tokenInfo.address, // Use address as mint
|
|
28
|
+
precision: tokenInfo.precision,
|
|
29
|
+
tokenId: tokenInfo.tokenId,
|
|
30
|
+
name: tokenInfo.name
|
|
31
|
+
}));
|
|
32
|
+
// Initialize bridge client if keypair and connection are provided
|
|
33
|
+
if (this.keypair && this.connection && this.nord.solanaProgramId) {
|
|
34
|
+
this.initBridgeClient();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Initialize the Solana bridge client
|
|
39
|
+
*/
|
|
40
|
+
initBridgeClient() {
|
|
41
|
+
if (!this.keypair || !this.connection || !this.nord.solanaProgramId) {
|
|
42
|
+
throw new Error('Keypair, connection, and program ID are required to initialize bridge client');
|
|
43
|
+
}
|
|
44
|
+
// Create an Anchor wallet from the keypair
|
|
45
|
+
const wallet = {
|
|
46
|
+
publicKey: this.keypair.publicKey,
|
|
47
|
+
signTransaction: async (tx) => {
|
|
48
|
+
tx.partialSign(this.keypair);
|
|
49
|
+
return tx;
|
|
50
|
+
},
|
|
51
|
+
signAllTransactions: async (txs) => {
|
|
52
|
+
return txs.map(tx => {
|
|
53
|
+
tx.partialSign(this.keypair);
|
|
54
|
+
return tx;
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
// Add payer property to satisfy NodeWallet interface
|
|
58
|
+
payer: this.keypair
|
|
59
|
+
};
|
|
60
|
+
// Initialize the bridge client
|
|
61
|
+
this.bridgeClient = new client_1.SolanaBridgeClient({
|
|
62
|
+
rpcUrl: this.connection.rpcEndpoint,
|
|
63
|
+
programId: this.nord.solanaProgramId,
|
|
64
|
+
commitment: 'confirmed',
|
|
65
|
+
tokenInfos: this.splTokenInfos
|
|
66
|
+
}, wallet);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create a NordUser from a private key
|
|
70
|
+
*
|
|
71
|
+
* @param nord Nord instance
|
|
72
|
+
* @param privateKey Private key as string or Uint8Array
|
|
73
|
+
* @param connection Solana connection
|
|
74
|
+
* @returns NordUser instance
|
|
75
|
+
*/
|
|
76
|
+
static fromPrivateKey(nord, privateKey, connection) {
|
|
77
|
+
const keypair = (0, utils_1.keypairFromPrivateKey)(privateKey);
|
|
78
|
+
// Create a signing function that returns Uint8Array
|
|
79
|
+
const walletSignFn = async (message) => {
|
|
80
|
+
const messageBuffer = typeof message === 'string'
|
|
81
|
+
? Buffer.from(message)
|
|
82
|
+
: Buffer.from(message);
|
|
83
|
+
// Use nacl for signing since Keypair doesn't have a sign method
|
|
84
|
+
// This is a simplified version - in a real implementation, you would use proper signing
|
|
85
|
+
return new Uint8Array(keypair.secretKey.slice(0, 64));
|
|
86
|
+
};
|
|
87
|
+
return new NordUser({
|
|
88
|
+
nord,
|
|
89
|
+
publicKey: keypair.publicKey,
|
|
90
|
+
walletSignFn,
|
|
91
|
+
sessionSignFn: walletSignFn,
|
|
92
|
+
keypair,
|
|
93
|
+
connection
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get the associated token account for a token mint
|
|
98
|
+
*
|
|
99
|
+
* @param mint Token mint address
|
|
100
|
+
* @returns Associated token account address
|
|
101
|
+
*/
|
|
102
|
+
async getAssociatedTokenAccount(mint) {
|
|
103
|
+
if (!this.connection) {
|
|
104
|
+
throw new Error('Connection is required to get associated token account');
|
|
105
|
+
}
|
|
106
|
+
const associatedTokenAddress = await (0, spl_token_1.getAssociatedTokenAddress)(mint, this.publicKey);
|
|
107
|
+
try {
|
|
108
|
+
await (0, spl_token_1.getAccount)(this.connection, associatedTokenAddress);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
// Account doesn't exist, create it if keypair is available
|
|
112
|
+
if (this.keypair && this.bridgeClient) {
|
|
113
|
+
await this.bridgeClient.createTokenAccountIfNeeded(mint, this.publicKey, this.keypair);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return associatedTokenAddress;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Deposit SPL tokens to the bridge
|
|
120
|
+
*
|
|
121
|
+
* @param amount Amount to deposit
|
|
122
|
+
* @param tokenId Token ID
|
|
123
|
+
* @returns Transaction signature
|
|
124
|
+
*/
|
|
125
|
+
async depositSpl(amount, tokenId) {
|
|
126
|
+
if (!this.bridgeClient || !this.keypair || !this.connection) {
|
|
127
|
+
throw new Error('Bridge client, keypair, and connection are required for deposit');
|
|
128
|
+
}
|
|
129
|
+
// Find the token info
|
|
130
|
+
const tokenInfo = this.splTokenInfos.find(t => t.tokenId === tokenId);
|
|
131
|
+
if (!tokenInfo) {
|
|
132
|
+
throw new Error(`Token with ID ${tokenId} not found`);
|
|
133
|
+
}
|
|
134
|
+
const mint = new web3_js_1.PublicKey(tokenInfo.mint);
|
|
135
|
+
// Get the user's token account
|
|
136
|
+
const fromAccount = await this.getAssociatedTokenAccount(mint);
|
|
137
|
+
// Get the bridge's token account
|
|
138
|
+
const [authority] = await this.bridgeClient.findAuthorityPda();
|
|
139
|
+
const toAccount = await (0, spl_token_1.getAssociatedTokenAddress)(mint, authority, true);
|
|
140
|
+
// Convert amount to BN with proper decimals
|
|
141
|
+
const amountBN = (0, utils_1.toBN)(amount, tokenInfo.precision);
|
|
142
|
+
// Deposit tokens
|
|
143
|
+
return await this.bridgeClient.depositSpl({
|
|
144
|
+
amount: amountBN,
|
|
145
|
+
mint,
|
|
146
|
+
fromAccount,
|
|
147
|
+
toAccount
|
|
148
|
+
}, this.keypair);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Withdraw tokens from the bridge
|
|
152
|
+
*
|
|
153
|
+
* @param claim Withdrawal claim
|
|
154
|
+
* @returns Transaction signature
|
|
155
|
+
*/
|
|
156
|
+
async withdrawSpl(claim) {
|
|
157
|
+
if (!this.bridgeClient || !this.keypair || !this.connection) {
|
|
158
|
+
throw new Error('Bridge client, keypair, and connection are required for withdrawal');
|
|
159
|
+
}
|
|
160
|
+
// Get the user's token account
|
|
161
|
+
const toAccount = await this.getAssociatedTokenAccount(claim.mint);
|
|
162
|
+
// Get the bridge's token account
|
|
163
|
+
const [authority] = await this.bridgeClient.findAuthorityPda();
|
|
164
|
+
const fromAccount = await (0, spl_token_1.getAssociatedTokenAddress)(claim.mint, authority, true);
|
|
165
|
+
// Withdraw tokens
|
|
166
|
+
return await this.bridgeClient.withdraw({
|
|
167
|
+
claim,
|
|
168
|
+
toAccount,
|
|
169
|
+
fromAccount
|
|
170
|
+
}, this.keypair);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Fund the user's SPL token accounts for testing
|
|
174
|
+
*
|
|
175
|
+
* @param faucetKeypair Keypair with funds to distribute
|
|
176
|
+
*/
|
|
177
|
+
async fundSplWallet(faucetKeypair) {
|
|
178
|
+
if (!this.connection) {
|
|
179
|
+
throw new Error('Connection is required to fund wallet');
|
|
180
|
+
}
|
|
181
|
+
// Fund SOL if needed
|
|
182
|
+
const solBalance = await this.connection.getBalance(this.publicKey);
|
|
183
|
+
if (solBalance < 10000000) { // 0.01 SOL
|
|
184
|
+
const solFundingAmount = const_1.DEFAULT_FUNDING_AMOUNTS["SOL"];
|
|
185
|
+
// Implement SOL transfer logic here
|
|
186
|
+
}
|
|
187
|
+
// Fund SPL tokens
|
|
188
|
+
for (const tokenInfo of this.splTokenInfos) {
|
|
189
|
+
if (const_1.DEFAULT_FUNDING_AMOUNTS[tokenInfo.mint]) {
|
|
190
|
+
const tokenAccount = await this.getAssociatedTokenAccount(new web3_js_1.PublicKey(tokenInfo.mint));
|
|
191
|
+
// Implement SPL token transfer logic here
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
exports.NordUser = NordUser;
|