@n1xyz/nord-ts 0.0.1 → 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/README.md +148 -65
- 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/const.d.ts +2 -5
- package/dist/const.js +2 -6
- package/dist/gen/common.d.ts +6 -1
- package/dist/gen/common.js +19 -9
- package/dist/gen/nord.d.ts +76 -21
- 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 +5 -2
- package/dist/index.js +18 -2
- package/dist/nord/{actions.d.ts → api/actions.d.ts} +6 -6
- package/dist/nord/{actions.js → api/actions.js} +6 -10
- package/dist/nord/api/core.d.ts +49 -0
- package/dist/nord/api/core.js +121 -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/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 +697 -0
- package/dist/nord/index.d.ts +9 -2
- package/dist/nord/index.js +30 -6
- package/dist/nord/models/Subscriber.d.ts +37 -0
- package/dist/nord/models/Subscriber.js +25 -0
- package/dist/nord/utils/NordError.d.ts +35 -0
- package/dist/nord/utils/NordError.js +46 -0
- package/dist/types.d.ts +143 -86
- package/dist/types.js +12 -1
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +20 -1
- package/dist/websocket/NordWebSocketClient.d.ts +71 -0
- package/dist/websocket/NordWebSocketClient.js +343 -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/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 +189 -43
- 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 -6
- 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 -10
- 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 -12
- 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 -77
- 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 +20 -23
- 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 +4 -9
- package/src/gen/common.ts +27 -10
- package/src/gen/nord.ts +1045 -487
- package/src/idl/bridge.ts +702 -0
- package/src/index.ts +21 -2
- package/src/nord/{actions.ts → api/actions.ts} +12 -16
- 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 +1101 -0
- package/src/nord/index.ts +16 -2
- package/src/nord/models/Subscriber.ts +56 -0
- package/src/nord/utils/NordError.ts +72 -0
- package/src/types.ts +163 -92
- package/src/utils.ts +22 -1
- package/src/websocket/NordWebSocketClient.ts +432 -0
- package/src/websocket/events.ts +31 -0
- package/src/websocket/index.ts +2 -0
- package/tsconfig.eslint.json +12 -0
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -20
- 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/nord/Nord.d.ts +0 -76
- package/dist/nord/Nord.js +0 -376
- package/dist/nord/NordImpl.d.ts +0 -7
- package/dist/nord/NordImpl.js +0 -6
- package/dist/nord/NordUser.d.ts +0 -77
- package/dist/nord/NordUser.js +0 -249
- package/docs/functions/createWebSocketSubscription.html +0 -12
- package/docs/interfaces/ERC20TokenInfo.html +0 -5
- package/docs/interfaces/OrderbookOrder.html +0 -6
- package/docs/interfaces/TradeInfo.html +0 -20
- package/docs/interfaces/TradesQueryParams.html +0 -10
- 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
- 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
package/README.md
CHANGED
|
@@ -1,110 +1,193 @@
|
|
|
1
1
|
# nord-ts
|
|
2
2
|
|
|
3
|
-
This package provides an interface to interact with the Nord exchange.
|
|
3
|
+
This package provides an interface to interact with the Nord exchange. The core components are `Nord` and `NordUser` classes which enable market data access, trading operations, and account management.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
### npm
|
|
8
|
-
|
|
9
7
|
```bash
|
|
8
|
+
# npm
|
|
10
9
|
npm install nord-ts
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
### yarn
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
# yarn
|
|
16
12
|
yarn add nord-ts
|
|
17
13
|
```
|
|
18
14
|
|
|
19
|
-
##
|
|
15
|
+
## Key Components
|
|
16
|
+
|
|
17
|
+
### Nord
|
|
18
|
+
|
|
19
|
+
The `Nord` class is the main entry point for interacting with the Nord exchange:
|
|
20
20
|
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
- Message signing and transmission capabilities.
|
|
25
|
-
- Data serialization and deserialization for protobuf.
|
|
21
|
+
- Provides market data access (orderbooks, trades, etc.)
|
|
22
|
+
- Manages WebSocket connections for real-time updates
|
|
23
|
+
- Offers utility methods for timestamp and nonce generation
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
### NordUser
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
The `NordUser` class represents a user account on the Nord exchange:
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
- Handles authentication and session management
|
|
30
|
+
- Provides trading functionality (place/cancel orders)
|
|
31
|
+
- Manages deposits and withdrawals
|
|
32
|
+
- Tracks user balances, positions, and orders
|
|
33
|
+
|
|
34
|
+
## Usage Examples
|
|
35
|
+
|
|
36
|
+
### Initializing Nord
|
|
32
37
|
|
|
33
38
|
```typescript
|
|
34
|
-
import { Nord
|
|
39
|
+
import { Nord } from "nord-ts";
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
// Create a Nord instance
|
|
42
|
+
const nord = new Nord({
|
|
43
|
+
webServerUrl: 'https://api.nord.exchange',
|
|
44
|
+
solanaProgramId: 'your_solana_program_id',
|
|
45
|
+
solanaUrl: 'https://api.mainnet-beta.solana.com',
|
|
39
46
|
});
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
// Initialize and fetch market data
|
|
49
|
+
await nord.fetchNordInfo();
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Creating a User from Private Key
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { Nord, NordUser } from "nord-ts";
|
|
56
|
+
import { Connection } from "@solana/web3.js";
|
|
57
|
+
|
|
58
|
+
// Create Nord instance
|
|
59
|
+
const nord = new Nord({
|
|
60
|
+
webServerUrl: 'https://api.nord.exchange',
|
|
61
|
+
solanaProgramId: 'your_solana_program_id',
|
|
62
|
+
solanaUrl: 'https://api.mainnet-beta.solana.com',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Optional Solana connection
|
|
66
|
+
const connection = new Connection('https://api.mainnet-beta.solana.com');
|
|
67
|
+
|
|
68
|
+
// Create user from private key
|
|
69
|
+
const user = NordUser.fromPrivateKey(
|
|
70
|
+
nord,
|
|
71
|
+
'your_private_key', // Can be string or Uint8Array
|
|
72
|
+
connection // Optional
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// Fetch user account information
|
|
76
|
+
await user.updateAccountId();
|
|
77
|
+
await user.fetchInfo();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Trading Operations
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { Nord, NordUser, Side, FillMode } from "nord-ts";
|
|
84
|
+
|
|
85
|
+
// Assuming nord and user are already initialized
|
|
47
86
|
|
|
87
|
+
// Place a limit order
|
|
48
88
|
try {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
89
|
+
const orderId = await user.placeOrder({
|
|
90
|
+
marketId: 0, // BTC/USDC market
|
|
91
|
+
side: Side.Bid, // Buy
|
|
92
|
+
fillMode: FillMode.Limit,
|
|
93
|
+
isReduceOnly: false,
|
|
94
|
+
size: 0.1, // 0.1 BTC
|
|
95
|
+
price: 50000, // $50,000 per BTC
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
console.log(`Order placed with ID: ${orderId}`);
|
|
99
|
+
|
|
100
|
+
// Cancel the order
|
|
101
|
+
await user.cancelOrder(orderId);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error(`Trading error: ${error}`);
|
|
52
104
|
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Deposits and Withdrawals
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { Nord, NordUser } from "nord-ts";
|
|
111
|
+
|
|
112
|
+
// Assuming nord and user are already initialized
|
|
53
113
|
|
|
54
|
-
|
|
55
|
-
const size = 1;
|
|
56
|
-
const price = 1;
|
|
57
|
-
const isReduceOnly = false;
|
|
58
|
-
let orderID: number = 0;
|
|
114
|
+
// Withdraw tokens
|
|
59
115
|
try {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
68
|
-
} catch (e) {
|
|
69
|
-
console.log(`couldn't do placeOrder, reason: ${e}`)
|
|
116
|
+
const tokenId = 0; // USDC
|
|
117
|
+
const amount = 100; // 100 USDC
|
|
118
|
+
|
|
119
|
+
await user.withdraw(tokenId, amount);
|
|
120
|
+
console.log(`Successfully withdrew ${amount} of token ID ${tokenId}`);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error(`Withdrawal error: ${error}`);
|
|
70
123
|
}
|
|
71
124
|
|
|
125
|
+
// For Solana SPL tokens
|
|
72
126
|
try {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
127
|
+
const tokenId = 1; // SOL
|
|
128
|
+
const amount = 1; // 1 SOL
|
|
129
|
+
|
|
130
|
+
const txId = await user.depositSpl(amount, tokenId);
|
|
131
|
+
console.log(`Deposit transaction ID: ${txId}`);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error(`Deposit error: ${error}`);
|
|
79
134
|
}
|
|
80
135
|
```
|
|
81
136
|
|
|
82
|
-
|
|
137
|
+
### Market Data
|
|
83
138
|
|
|
84
139
|
```typescript
|
|
85
|
-
import {
|
|
140
|
+
import { Nord } from "nord-ts";
|
|
141
|
+
|
|
142
|
+
// Assuming nord is already initialized
|
|
86
143
|
|
|
87
|
-
|
|
88
|
-
|
|
144
|
+
// Get orderbook for a market
|
|
145
|
+
const orderbook = await nord.getOrderbook({ marketId: 0 });
|
|
146
|
+
console.log('Bids:', orderbook.bids);
|
|
147
|
+
console.log('Asks:', orderbook.asks);
|
|
89
148
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
149
|
+
// Get recent trades
|
|
150
|
+
const trades = await nord.getTrades({ marketId: 0, limit: 10 });
|
|
151
|
+
console.log('Recent trades:', trades.trades);
|
|
152
|
+
|
|
153
|
+
// Subscribe to real-time orderbook updates
|
|
154
|
+
const orderbookSub = nord.subscribeOrderbook('BTC/USDC');
|
|
155
|
+
orderbookSub.on('update', (data) => {
|
|
156
|
+
console.log('Orderbook update:', data);
|
|
93
157
|
});
|
|
94
|
-
s.subsribe();
|
|
95
158
|
```
|
|
96
159
|
|
|
97
|
-
|
|
160
|
+
### Account Information
|
|
98
161
|
|
|
99
|
-
### Install dependencies
|
|
100
162
|
|
|
101
|
-
```
|
|
102
|
-
|
|
163
|
+
```typescript
|
|
164
|
+
import { Nord, NordUser } from "nord-ts";
|
|
165
|
+
|
|
166
|
+
// Assuming nord and user are already initialized
|
|
167
|
+
|
|
168
|
+
// Get account information
|
|
169
|
+
const accountInfo = await user.fetchInfo();
|
|
170
|
+
|
|
171
|
+
// Access user balances
|
|
172
|
+
console.log('Balances:', user.balances);
|
|
173
|
+
|
|
174
|
+
// Access user positions
|
|
175
|
+
console.log('Positions:', user.positions);
|
|
176
|
+
|
|
177
|
+
// Access user orders
|
|
178
|
+
console.log('Orders:', user.orders);
|
|
103
179
|
```
|
|
104
180
|
|
|
105
|
-
|
|
181
|
+
## Development
|
|
106
182
|
|
|
107
|
-
|
|
183
|
+
```bash
|
|
184
|
+
# Install dependencies
|
|
185
|
+
yarn
|
|
186
|
+
|
|
187
|
+
# Build the package
|
|
108
188
|
yarn build
|
|
109
189
|
```
|
|
110
|
-
|
|
190
|
+
|
|
191
|
+
## Documentation
|
|
192
|
+
|
|
193
|
+
For more detailed documentation, please refer to the source code and inline comments in the `Nord` and `NordUser` classes.
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor";
|
|
2
|
+
import { AnchorProvider } from "@coral-xyz/anchor";
|
|
3
|
+
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
|
4
|
+
import { BlockFacts, DepositSplParams, PdaSeedType, SolanaBridgeConfig, WithdrawalParams } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Solana Bridge Client for interacting with the bridge program
|
|
7
|
+
*/
|
|
8
|
+
export declare class SolanaBridgeClient {
|
|
9
|
+
/** Anchor program instance */
|
|
10
|
+
program: any;
|
|
11
|
+
/** Solana connection */
|
|
12
|
+
connection: Connection;
|
|
13
|
+
/** Program ID */
|
|
14
|
+
programId: PublicKey;
|
|
15
|
+
/** Configuration */
|
|
16
|
+
config: SolanaBridgeConfig;
|
|
17
|
+
/** Anchor provider */
|
|
18
|
+
provider: AnchorProvider;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new Solana Bridge Client
|
|
21
|
+
*
|
|
22
|
+
* @param config Bridge configuration
|
|
23
|
+
* @param wallet Anchor wallet for signing transactions
|
|
24
|
+
*/
|
|
25
|
+
constructor(config: SolanaBridgeConfig, wallet: anchor.Wallet);
|
|
26
|
+
/**
|
|
27
|
+
* Derive a PDA (Program Derived Address) for the given seeds
|
|
28
|
+
*
|
|
29
|
+
* @param type PDA seed type
|
|
30
|
+
* @param seeds Additional seeds
|
|
31
|
+
* @returns [PDA, bump]
|
|
32
|
+
*/
|
|
33
|
+
findPda(type: PdaSeedType, ...seeds: (Buffer | PublicKey | string | number)[]): Promise<[PublicKey, number]>;
|
|
34
|
+
/**
|
|
35
|
+
* Find the contract storage PDA
|
|
36
|
+
*
|
|
37
|
+
* @returns [PDA, bump]
|
|
38
|
+
*/
|
|
39
|
+
findContractStoragePda(): Promise<[PublicKey, number]>;
|
|
40
|
+
/**
|
|
41
|
+
* Find the asset whitelisted PDA for a token mint
|
|
42
|
+
*
|
|
43
|
+
* @param mint Token mint address
|
|
44
|
+
* @returns [PDA, bump]
|
|
45
|
+
*/
|
|
46
|
+
findAssetWhitelistedPda(mint: PublicKey): Promise<[PublicKey, number]>;
|
|
47
|
+
/**
|
|
48
|
+
* Find the deposit storage PDA for a deposit index
|
|
49
|
+
*
|
|
50
|
+
* @param depositIndex Deposit index
|
|
51
|
+
* @returns [PDA, bump]
|
|
52
|
+
*/
|
|
53
|
+
findDepositStoragePda(depositIndex: number): Promise<[PublicKey, number]>;
|
|
54
|
+
/**
|
|
55
|
+
* Find the block storage PDA for a block ID
|
|
56
|
+
*
|
|
57
|
+
* @param blockId Block ID
|
|
58
|
+
* @returns [PDA, bump]
|
|
59
|
+
*/
|
|
60
|
+
findBlockStoragePda(blockId: number): Promise<[PublicKey, number]>;
|
|
61
|
+
/**
|
|
62
|
+
* Find the withdrawal nullifier PDA
|
|
63
|
+
*
|
|
64
|
+
* @param blockId Block ID
|
|
65
|
+
* @param leafIndex Leaf index
|
|
66
|
+
* @returns [PDA, bump]
|
|
67
|
+
*/
|
|
68
|
+
findWithdrawalNullifierPda(blockId: number, leafIndex: number): Promise<[PublicKey, number]>;
|
|
69
|
+
/**
|
|
70
|
+
* Find the authority PDA
|
|
71
|
+
*
|
|
72
|
+
* @returns [PDA, bump]
|
|
73
|
+
*/
|
|
74
|
+
findAuthorityPda(): Promise<[PublicKey, number]>;
|
|
75
|
+
/**
|
|
76
|
+
* Helper method to sign and send a transaction
|
|
77
|
+
*
|
|
78
|
+
* @param transaction Transaction to sign and send
|
|
79
|
+
* @param signers Additional signers (beyond the provider's wallet)
|
|
80
|
+
* @returns Transaction signature
|
|
81
|
+
*/
|
|
82
|
+
private signAndSendTransaction;
|
|
83
|
+
/**
|
|
84
|
+
* Deposit SPL tokens to the bridge
|
|
85
|
+
*
|
|
86
|
+
* @param params Deposit parameters
|
|
87
|
+
* @param signer Signer keypair
|
|
88
|
+
* @returns Transaction signature
|
|
89
|
+
*/
|
|
90
|
+
depositSpl(params: DepositSplParams): Promise<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Withdraw tokens from the bridge
|
|
93
|
+
*
|
|
94
|
+
* @param params Withdrawal parameters
|
|
95
|
+
* @param signer Signer keypair
|
|
96
|
+
* @returns Transaction signature
|
|
97
|
+
*/
|
|
98
|
+
withdraw(params: WithdrawalParams, signer: Keypair): Promise<string>;
|
|
99
|
+
/**
|
|
100
|
+
* Whitelist an asset (token) for use with the bridge
|
|
101
|
+
*
|
|
102
|
+
* @param mint Token mint address
|
|
103
|
+
* @param signer Operator keypair
|
|
104
|
+
* @returns Transaction signature
|
|
105
|
+
*/
|
|
106
|
+
whitelistAsset(mint: PublicKey, signer: Keypair): Promise<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Propose a new block
|
|
109
|
+
*
|
|
110
|
+
* @param facts Block facts
|
|
111
|
+
* @param signer Operator keypair
|
|
112
|
+
* @returns Transaction signature
|
|
113
|
+
*/
|
|
114
|
+
proposeBlock(facts: BlockFacts, signer: Keypair): Promise<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Finalize a block
|
|
117
|
+
*
|
|
118
|
+
* @param blockId Block ID
|
|
119
|
+
* @param stateUpdateId State update ID
|
|
120
|
+
* @param signer Payer keypair
|
|
121
|
+
* @returns Transaction signature
|
|
122
|
+
*/
|
|
123
|
+
finalizeBlock(blockId: number, stateUpdateId: number, signer: Keypair): Promise<string>;
|
|
124
|
+
/**
|
|
125
|
+
* Finalize a DA fact
|
|
126
|
+
*
|
|
127
|
+
* @param fact DA fact (32-byte array)
|
|
128
|
+
* @param signer Payer keypair
|
|
129
|
+
* @returns Transaction signature
|
|
130
|
+
*/
|
|
131
|
+
finalizeDaFact(fact: Buffer, signer: Keypair): Promise<string>;
|
|
132
|
+
/**
|
|
133
|
+
* Initialize the bridge contract
|
|
134
|
+
*
|
|
135
|
+
* @param operator Operator public key
|
|
136
|
+
* @param initialAppStateCommitment Initial app state commitment (32-byte array)
|
|
137
|
+
* @param signer Payer keypair
|
|
138
|
+
* @returns Transaction signature
|
|
139
|
+
*/
|
|
140
|
+
initialize(operator: PublicKey, initialAppStateCommitment: Buffer, signer: Keypair): Promise<string>;
|
|
141
|
+
/**
|
|
142
|
+
* Create an associated token account if it doesn't exist
|
|
143
|
+
*
|
|
144
|
+
* @param mint Token mint
|
|
145
|
+
* @param owner Account owner
|
|
146
|
+
* @param payer Transaction payer
|
|
147
|
+
* @returns Associated token account address
|
|
148
|
+
*/
|
|
149
|
+
createTokenAccountIfNeeded(mint: PublicKey, owner: PublicKey, payer: Keypair): Promise<PublicKey>;
|
|
150
|
+
}
|