@n1xyz/nord-ts 0.0.14 → 0.0.15
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/.prettierignore +1 -0
- package/README.md +9 -6
- package/dist/bridge/client.d.ts +8 -7
- package/dist/bridge/client.js +38 -37
- package/dist/bridge/index.d.ts +1 -2
- package/dist/bridge/index.js +2 -2
- package/dist/bridge/types.d.ts +5 -3
- package/dist/bridge/types.js +3 -1
- package/dist/gen/nord.d.ts +66 -5
- package/dist/gen/nord.js +449 -22
- package/dist/idl/bridge.json +1493 -0
- package/dist/idl/index.d.ts +585 -0
- package/dist/idl/index.js +8 -0
- package/dist/nord/api/core.js +7 -5
- package/dist/nord/api/metrics.js +7 -4
- package/dist/nord/client/Nord.d.ts +19 -5
- package/dist/nord/client/Nord.js +50 -23
- package/dist/nord/client/NordUser.js +4 -7
- package/dist/types.d.ts +3 -3
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Nord.html +99 -100
- package/docs/classes/NordError.html +6 -6
- package/docs/classes/NordUser.html +48 -53
- package/docs/classes/NordWebSocketClient.html +6 -11
- package/docs/classes/SolanaBridgeClient.html +23 -23
- package/docs/classes/Subscriber.html +3 -3
- package/docs/enums/FillMode.html +2 -2
- package/docs/enums/KeyType.html +2 -2
- package/docs/enums/MetricPeriod.html +2 -2
- package/docs/enums/PdaSeedType.html +2 -2
- package/docs/enums/PeakTpsPeriodUnit.html +2 -2
- package/docs/enums/Side.html +2 -2
- package/docs/enums/WebSocketMessageType.html +3 -3
- package/docs/functions/actionQueryRollman.html +1 -1
- package/docs/functions/actionsQueryRollman.html +1 -1
- package/docs/functions/aggregateMetrics-1.html +1 -1
- package/docs/functions/assert.html +1 -1
- package/docs/functions/bigIntToProtoU128.html +1 -1
- package/docs/functions/bridgeToBN.html +1 -1
- package/docs/functions/bufferToHex.html +1 -1
- package/docs/functions/cancelOrder.html +1 -1
- package/docs/functions/checkPubKeyLength.html +1 -1
- package/docs/functions/checkedFetch.html +1 -1
- package/docs/functions/createSession.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/findPda.html +1 -1
- package/docs/functions/findToken.html +1 -1
- package/docs/functions/fromBN.html +1 -1
- package/docs/functions/getAccount.html +1 -1
- package/docs/functions/getActionNonce.html +1 -1
- package/docs/functions/getCurrentTps.html +1 -1
- package/docs/functions/getInfo.html +1 -1
- package/docs/functions/{queryLastNBlocks.html → getLastActionId.html} +3 -3
- package/docs/functions/getMedianLatency.html +1 -1
- package/docs/functions/getOrderbook.html +1 -1
- package/docs/functions/getPeakTps.html +1 -1
- package/docs/functions/getTimestamp.html +1 -1
- package/docs/functions/getTotalTransactions.html +1 -1
- package/docs/functions/getTrades.html +1 -1
- package/docs/functions/getUserAccountIds.html +1 -1
- package/docs/functions/hexToBuffer.html +1 -1
- package/docs/functions/initWebSocketClient.html +9 -9
- package/docs/functions/keypairFromPrivateKey.html +1 -1
- package/docs/functions/makeSigningFunction.html +1 -1
- package/docs/functions/makeWalletSignFn.html +1 -1
- package/docs/functions/marketsStats.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/placeOrder.html +1 -1
- package/docs/functions/queryAction.html +1 -1
- package/docs/functions/queryPrometheus.html +1 -1
- package/docs/functions/queryRecentActions.html +4 -3
- package/docs/functions/revokeSession.html +1 -1
- package/docs/functions/shortenPublicKey.html +1 -1
- package/docs/functions/signAction.html +1 -1
- package/docs/functions/toBN.html +1 -1
- package/docs/functions/toScaledU128.html +1 -1
- package/docs/functions/toScaledU64.html +1 -1
- package/docs/functions/transfer.html +1 -1
- package/docs/functions/withdraw.html +1 -1
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +2 -2
- package/docs/interfaces/Account.html +2 -2
- package/docs/interfaces/ActionInfo.html +2 -2
- package/docs/interfaces/ActionNonceResponse.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/BlockFacts.html +5 -5
- 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/DepositSplParams.html +5 -5
- 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 +19 -9
- package/docs/interfaces/NordWebSocketClientEvents.html +2 -2
- package/docs/interfaces/NordWebSocketEvents.html +3 -3
- package/docs/interfaces/Order.html +2 -2
- package/docs/interfaces/OrderInfo.html +2 -2
- package/docs/interfaces/OrderbookEntry.html +2 -2
- package/docs/interfaces/OrderbookQuery.html +2 -2
- package/docs/interfaces/OrderbookResponse.html +2 -2
- package/docs/interfaces/OrderbookSubscription.html +5 -5
- 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/SPLTokenInfo.html +5 -5
- package/docs/interfaces/SolanaBridgeConfig.html +5 -5
- package/docs/interfaces/StateFacts.html +5 -5
- package/docs/interfaces/SubscriberConfig.html +2 -2
- package/docs/interfaces/TimestampResponse.html +2 -2
- package/docs/interfaces/Token.html +2 -2
- package/docs/interfaces/TokenInfo.html +3 -2
- package/docs/interfaces/Trade.html +2 -2
- package/docs/interfaces/TradeSubscription.html +5 -5
- package/docs/interfaces/Trades.html +2 -2
- package/docs/interfaces/TradesQuery.html +2 -2
- package/docs/interfaces/TradesResponse.html +2 -2
- package/docs/interfaces/TransferParams.html +4 -4
- package/docs/interfaces/UserAccountIdsQuery.html +2 -2
- package/docs/interfaces/UserAccountIdsResponse.html +2 -2
- package/docs/interfaces/WebSocketAccountUpdate.html +6 -0
- package/docs/interfaces/WebSocketDeltaUpdate.html +3 -3
- package/docs/interfaces/WebSocketSubscription.html +3 -3
- package/docs/interfaces/WebSocketTradeUpdate.html +3 -3
- package/docs/interfaces/WithdrawalClaim.html +7 -7
- package/docs/interfaces/WithdrawalParams.html +4 -4
- package/docs/modules.html +1 -1
- package/docs/types/BigIntValue.html +1 -1
- package/docs/types/SubscriptionPattern.html +4 -0
- package/docs/types/SubscriptionType.html +2 -0
- package/docs/types/WebSocketMessage.html +1 -1
- 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 +1 -1
- package/idl-generate.sh +4 -0
- package/package.json +4 -3
- package/src/bridge/client.ts +54 -43
- package/src/bridge/index.ts +1 -2
- package/src/bridge/types.ts +5 -3
- package/src/gen/nord.ts +518 -19
- package/src/idl/bridge.json +1493 -0
- package/src/idl/index.ts +2 -0
- package/src/nord/api/core.ts +1 -3
- package/src/nord/api/metrics.ts +2 -0
- package/src/nord/client/Nord.ts +49 -13
- package/src/nord/client/NordUser.ts +32 -49
- package/src/types.ts +2 -2
- package/docs/functions/blockQueryRollman.html +0 -6
- package/docs/functions/blockSummaryQueryRollman.html +0 -6
- package/docs/functions/queryBlock.html +0 -6
- package/docs/functions/queryRecentBlocks.html +0 -6
- package/docs/interfaces/WebSocketUserUpdate.html +0 -6
- package/src/idl/bridge.ts +0 -929
package/.prettierignore
CHANGED
package/README.md
CHANGED
|
@@ -41,12 +41,12 @@ import { Nord } from "nord-ts";
|
|
|
41
41
|
// Create a Nord instance
|
|
42
42
|
const nord = new Nord({
|
|
43
43
|
webServerUrl: 'https://api.nord.exchange',
|
|
44
|
-
|
|
44
|
+
bridgeVk: 'your_bridge_vk', // Provide the bridge verification key
|
|
45
45
|
solanaUrl: 'https://api.mainnet-beta.solana.com',
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
// Initialize and fetch market data
|
|
49
|
-
await
|
|
49
|
+
await Nord.initNord(nord); // Initialize client (derives program ID, fetches info)
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
### Creating a User from Private Key
|
|
@@ -55,12 +55,15 @@ await nord.fetchNordInfo();
|
|
|
55
55
|
import { Nord, NordUser } from "nord-ts";
|
|
56
56
|
import { Connection } from "@solana/web3.js";
|
|
57
57
|
|
|
58
|
-
//
|
|
59
|
-
const
|
|
58
|
+
// Define Nord configuration
|
|
59
|
+
const nordConfig = {
|
|
60
60
|
webServerUrl: 'https://api.nord.exchange',
|
|
61
|
-
|
|
61
|
+
bridgeVk: 'your_bridge_vk', // Provide the bridge verification key
|
|
62
62
|
solanaUrl: 'https://api.mainnet-beta.solana.com',
|
|
63
|
-
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Initialize Nord client asynchronously
|
|
66
|
+
const nord = await Nord.initNord(nordConfig);
|
|
64
67
|
|
|
65
68
|
// Optional Solana connection
|
|
66
69
|
const connection = new Connection('https://api.mainnet-beta.solana.com');
|
package/dist/bridge/client.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare class SolanaBridgeClient {
|
|
|
16
16
|
config: SolanaBridgeConfig;
|
|
17
17
|
/** Anchor provider */
|
|
18
18
|
provider: AnchorProvider;
|
|
19
|
+
bridge: PublicKey;
|
|
19
20
|
/**
|
|
20
21
|
* Create a new Solana Bridge Client
|
|
21
22
|
*
|
|
@@ -26,17 +27,17 @@ export declare class SolanaBridgeClient {
|
|
|
26
27
|
/**
|
|
27
28
|
* Derive a PDA (Program Derived Address) for the given seeds
|
|
28
29
|
*
|
|
30
|
+
* Seeds can be of type:
|
|
31
|
+
* - Buffer: raw bytes
|
|
32
|
+
* - PublicKey: Solana public key
|
|
33
|
+
* - string: string encoded as UTF-8 bytes
|
|
34
|
+
* - number: u64 encoded as little-endian 8 bytes
|
|
35
|
+
*
|
|
29
36
|
* @param type PDA seed type
|
|
30
37
|
* @param seeds Additional seeds
|
|
31
38
|
* @returns [PDA, bump]
|
|
32
39
|
*/
|
|
33
|
-
findPda(type: PdaSeedType, ...seeds:
|
|
34
|
-
/**
|
|
35
|
-
* Find the contract storage PDA
|
|
36
|
-
*
|
|
37
|
-
* @returns [PDA, bump]
|
|
38
|
-
*/
|
|
39
|
-
findContractStoragePda(): Promise<[PublicKey, number]>;
|
|
40
|
+
findPda(type: PdaSeedType, ...seeds: any[]): Promise<[PublicKey, number]>;
|
|
40
41
|
/**
|
|
41
42
|
* Find the asset config PDA for a token mint
|
|
42
43
|
*
|
package/dist/bridge/client.js
CHANGED
|
@@ -39,8 +39,7 @@ const anchor_1 = require("@coral-xyz/anchor");
|
|
|
39
39
|
const spl_token_1 = require("@solana/spl-token");
|
|
40
40
|
const web3_js_1 = require("@solana/web3.js");
|
|
41
41
|
const types_1 = require("./types");
|
|
42
|
-
|
|
43
|
-
const bridge_1 = require("../idl/bridge");
|
|
42
|
+
const idl_1 = require("../idl");
|
|
44
43
|
/**
|
|
45
44
|
* Solana Bridge Client for interacting with the bridge program
|
|
46
45
|
*/
|
|
@@ -66,11 +65,18 @@ class SolanaBridgeClient {
|
|
|
66
65
|
anchor.setProvider(provider);
|
|
67
66
|
// Store the provider
|
|
68
67
|
this.provider = provider;
|
|
69
|
-
this.program = new anchor.Program({ ...
|
|
68
|
+
this.program = new anchor.Program({ ...idl_1.BRIDGE_IDL, address: config.programId }, provider);
|
|
69
|
+
this.bridge = new web3_js_1.PublicKey(config.bridgeVk);
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Derive a PDA (Program Derived Address) for the given seeds
|
|
73
73
|
*
|
|
74
|
+
* Seeds can be of type:
|
|
75
|
+
* - Buffer: raw bytes
|
|
76
|
+
* - PublicKey: Solana public key
|
|
77
|
+
* - string: string encoded as UTF-8 bytes
|
|
78
|
+
* - number: u64 encoded as little-endian 8 bytes
|
|
79
|
+
*
|
|
74
80
|
* @param type PDA seed type
|
|
75
81
|
* @param seeds Additional seeds
|
|
76
82
|
* @returns [PDA, bump]
|
|
@@ -91,19 +97,13 @@ class SolanaBridgeClient {
|
|
|
91
97
|
buffer.writeBigUInt64LE(BigInt(seed), 0);
|
|
92
98
|
return buffer;
|
|
93
99
|
}
|
|
94
|
-
|
|
100
|
+
else {
|
|
101
|
+
return seed.toBytes();
|
|
102
|
+
}
|
|
95
103
|
}),
|
|
96
104
|
];
|
|
97
105
|
return web3_js_1.PublicKey.findProgramAddressSync(seedBuffers, this.programId);
|
|
98
106
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Find the contract storage PDA
|
|
101
|
-
*
|
|
102
|
-
* @returns [PDA, bump]
|
|
103
|
-
*/
|
|
104
|
-
async findContractStoragePda() {
|
|
105
|
-
return this.findPda(types_1.PdaSeedType.ContractStorage);
|
|
106
|
-
}
|
|
107
107
|
/**
|
|
108
108
|
* Find the asset config PDA for a token mint
|
|
109
109
|
*
|
|
@@ -111,7 +111,7 @@ class SolanaBridgeClient {
|
|
|
111
111
|
* @returns [PDA, bump]
|
|
112
112
|
*/
|
|
113
113
|
async findAssetConfigPda(mint) {
|
|
114
|
-
return this.findPda(types_1.PdaSeedType.AssetConfig, mint);
|
|
114
|
+
return this.findPda(types_1.PdaSeedType.AssetConfig, this.bridge, mint);
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
117
|
* Find the deposit storage PDA for a deposit index
|
|
@@ -120,7 +120,7 @@ class SolanaBridgeClient {
|
|
|
120
120
|
* @returns [PDA, bump]
|
|
121
121
|
*/
|
|
122
122
|
async findDepositStoragePda(depositIndex) {
|
|
123
|
-
return this.findPda(types_1.PdaSeedType.DepositStorage, depositIndex);
|
|
123
|
+
return this.findPda(types_1.PdaSeedType.DepositStorage, this.bridge, depositIndex);
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
126
|
* Find the block storage PDA for a block ID
|
|
@@ -129,7 +129,7 @@ class SolanaBridgeClient {
|
|
|
129
129
|
* @returns [PDA, bump]
|
|
130
130
|
*/
|
|
131
131
|
async findBlockStoragePda(blockId) {
|
|
132
|
-
return this.findPda(types_1.PdaSeedType.BlockStorage, blockId);
|
|
132
|
+
return this.findPda(types_1.PdaSeedType.BlockStorage, this.bridge, blockId);
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
135
135
|
* Find the withdrawal nullifier PDA
|
|
@@ -171,11 +171,10 @@ class SolanaBridgeClient {
|
|
|
171
171
|
* @returns Transaction signature
|
|
172
172
|
*/
|
|
173
173
|
async depositSpl(params) {
|
|
174
|
-
const [contractStorage] = await this.findContractStoragePda();
|
|
175
174
|
const [assetConfig] = await this.findAssetConfigPda(params.mint);
|
|
176
175
|
// Get the last deposit index from contract storage
|
|
177
|
-
const
|
|
178
|
-
const lastDepositIndex =
|
|
176
|
+
const bridgeAccount = await this.program.account.bridge.fetch(this.bridge);
|
|
177
|
+
const lastDepositIndex = bridgeAccount.lastDepositIndex.toNumber();
|
|
179
178
|
// Find the deposit PDA for this deposit
|
|
180
179
|
const [deposit] = await this.findDepositStoragePda(lastDepositIndex + 1);
|
|
181
180
|
// Find the previous deposit PDA if it exists
|
|
@@ -184,32 +183,38 @@ class SolanaBridgeClient {
|
|
|
184
183
|
const [prevDepositPda] = await this.findDepositStoragePda(lastDepositIndex);
|
|
185
184
|
prevDeposit = prevDepositPda;
|
|
186
185
|
}
|
|
186
|
+
const tokenAuthority = (await this.findPda(types_1.PdaSeedType.TokenAuthority, this.bridge))[0];
|
|
187
|
+
const crumbAuthority = (await this.findPda(types_1.PdaSeedType.CrumbAuthority, this.bridge))[0];
|
|
188
|
+
const toAccount = await (0, spl_token_1.getAssociatedTokenAddress)(params.mint, tokenAuthority, true, spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
187
189
|
// Build the transaction
|
|
188
190
|
const accounts = {
|
|
189
|
-
|
|
191
|
+
payer: this.provider.wallet.publicKey,
|
|
190
192
|
deposit,
|
|
191
193
|
assetConfig,
|
|
192
|
-
|
|
194
|
+
bridge: this.bridge,
|
|
195
|
+
program: this.programId,
|
|
193
196
|
fromAccount: params.fromAccount,
|
|
194
|
-
toAccount:
|
|
197
|
+
toAccount: toAccount,
|
|
195
198
|
tokenProgram: spl_token_1.TOKEN_2022_PROGRAM_ID,
|
|
196
199
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
200
|
+
crumbAuthority,
|
|
201
|
+
tokenAuthority,
|
|
197
202
|
};
|
|
203
|
+
const allAccounts = { ...accounts, prevDeposit: prevDeposit };
|
|
198
204
|
// Create the transaction
|
|
199
|
-
const tx = await this.program.methods
|
|
200
|
-
.
|
|
201
|
-
.accounts(
|
|
202
|
-
.transaction();
|
|
205
|
+
const tx = await (await this.program.methods
|
|
206
|
+
.deposit(this.provider.wallet.publicKey, params.amount)
|
|
207
|
+
.accounts(allAccounts)).transaction();
|
|
203
208
|
// Check if toAccount is initialized and add preinstruction if needed
|
|
204
209
|
try {
|
|
205
|
-
await this.connection.getTokenAccountBalance(
|
|
210
|
+
await this.connection.getTokenAccountBalance(toAccount);
|
|
206
211
|
}
|
|
207
212
|
catch {
|
|
208
213
|
// Account doesn't exist, add instruction to create it
|
|
209
214
|
// Get the authority PDA which is the owner of the toAccount
|
|
210
215
|
const [authority] = await this.findAuthorityPda();
|
|
211
216
|
const createTokenAccountIx = (0, spl_token_1.createAssociatedTokenAccountInstruction)(this.provider.wallet.publicKey, // payer
|
|
212
|
-
|
|
217
|
+
toAccount, // associated token account address
|
|
213
218
|
authority, // owner of the token account
|
|
214
219
|
params.mint, // token mint
|
|
215
220
|
spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
@@ -255,14 +260,13 @@ class SolanaBridgeClient {
|
|
|
255
260
|
* @returns Transaction signature
|
|
256
261
|
*/
|
|
257
262
|
async whitelistAsset(mint, signer) {
|
|
258
|
-
const [contractStorage] = await this.findContractStoragePda();
|
|
259
263
|
const [assetWhitelisted] = await this.findAssetConfigPda(mint);
|
|
260
264
|
// Build the transaction
|
|
261
265
|
const tx = await this.program.methods
|
|
262
266
|
.whitelistAsset(mint)
|
|
263
267
|
.accounts({
|
|
264
268
|
operator: signer.publicKey,
|
|
265
|
-
|
|
269
|
+
bridge: this.bridge,
|
|
266
270
|
assetWhitelisted,
|
|
267
271
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
268
272
|
})
|
|
@@ -278,10 +282,9 @@ class SolanaBridgeClient {
|
|
|
278
282
|
* @returns Transaction signature
|
|
279
283
|
*/
|
|
280
284
|
async proposeBlock(facts, signer) {
|
|
281
|
-
const [contractStorage] = await this.findContractStoragePda();
|
|
282
285
|
// Get the last block ID from contract storage
|
|
283
|
-
const
|
|
284
|
-
const [block] = await this.findBlockStoragePda(
|
|
286
|
+
const bridgeAccount = await this.program.account.bridge.fetch(this.bridge);
|
|
287
|
+
const [block] = await this.findBlockStoragePda(bridgeAccount.lastBlockId.toNumber() + 1);
|
|
285
288
|
// Find the last deposit PDA
|
|
286
289
|
const [lastDeposit] = await this.findDepositStoragePda(facts.nextStateFacts.lastDepositIndex.toNumber());
|
|
287
290
|
// Find the DA fact state
|
|
@@ -294,7 +297,7 @@ class SolanaBridgeClient {
|
|
|
294
297
|
block,
|
|
295
298
|
lastDeposit,
|
|
296
299
|
daFactState,
|
|
297
|
-
|
|
300
|
+
bridge: this.bridge,
|
|
298
301
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
299
302
|
})
|
|
300
303
|
.transaction();
|
|
@@ -310,7 +313,6 @@ class SolanaBridgeClient {
|
|
|
310
313
|
* @returns Transaction signature
|
|
311
314
|
*/
|
|
312
315
|
async finalizeBlock(blockId, stateUpdateId, signer) {
|
|
313
|
-
const [contractStorage] = await this.findContractStoragePda();
|
|
314
316
|
const [block] = await this.findBlockStoragePda(blockId);
|
|
315
317
|
// Build the transaction
|
|
316
318
|
const tx = await this.program.methods
|
|
@@ -318,7 +320,7 @@ class SolanaBridgeClient {
|
|
|
318
320
|
.accounts({
|
|
319
321
|
payer: signer.publicKey,
|
|
320
322
|
block,
|
|
321
|
-
|
|
323
|
+
bridge: this.bridge,
|
|
322
324
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
323
325
|
})
|
|
324
326
|
.transaction();
|
|
@@ -355,14 +357,13 @@ class SolanaBridgeClient {
|
|
|
355
357
|
* @returns Transaction signature
|
|
356
358
|
*/
|
|
357
359
|
async initialize(operator, initialAppStateCommitment, signer) {
|
|
358
|
-
const [contractStorage] = await this.findContractStoragePda();
|
|
359
360
|
// Build the transaction
|
|
360
361
|
const tx = await this.program.methods
|
|
361
362
|
.initialize(operator, Array.from(initialAppStateCommitment))
|
|
362
363
|
.accounts({
|
|
363
364
|
payer: signer.publicKey,
|
|
364
365
|
program: this.programId,
|
|
365
|
-
|
|
366
|
+
bridge: this.bridge,
|
|
366
367
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
367
368
|
})
|
|
368
369
|
.transaction();
|
package/dist/bridge/index.d.ts
CHANGED
package/dist/bridge/index.js
CHANGED
|
@@ -19,5 +19,5 @@ __exportStar(require("./client"), exports);
|
|
|
19
19
|
__exportStar(require("./types"), exports);
|
|
20
20
|
__exportStar(require("./utils"), exports);
|
|
21
21
|
// Re-export the IDL for convenience
|
|
22
|
-
|
|
23
|
-
Object.defineProperty(exports, "BRIDGE_IDL", { enumerable: true, get: function () { return
|
|
22
|
+
var idl_1 = require("../idl");
|
|
23
|
+
Object.defineProperty(exports, "BRIDGE_IDL", { enumerable: true, get: function () { return idl_1.BRIDGE_IDL; } });
|
package/dist/bridge/types.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export interface SolanaBridgeConfig {
|
|
|
8
8
|
rpcUrl: string;
|
|
9
9
|
/** Program ID for the bridge program */
|
|
10
10
|
programId: string;
|
|
11
|
+
/** Bridge Verifying Key */
|
|
12
|
+
bridgeVk: string;
|
|
11
13
|
/** Commitment level for transactions */
|
|
12
14
|
commitment: "processed" | "confirmed" | "finalized";
|
|
13
15
|
/** Token information for supported SPL tokens */
|
|
@@ -36,8 +38,6 @@ export interface DepositSplParams {
|
|
|
36
38
|
mint: PublicKey;
|
|
37
39
|
/** User's token account to deposit from */
|
|
38
40
|
fromAccount: PublicKey;
|
|
39
|
-
/** Bridge's token account to deposit to */
|
|
40
|
-
toAccount: PublicKey;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Parameters for withdrawing tokens
|
|
@@ -108,7 +108,9 @@ export interface TransferParams {
|
|
|
108
108
|
* PDA seed types
|
|
109
109
|
*/
|
|
110
110
|
export declare enum PdaSeedType {
|
|
111
|
-
|
|
111
|
+
Bridge = "bridge",
|
|
112
|
+
TokenAuthority = "token_authority",
|
|
113
|
+
CrumbAuthority = "crumb_authority",
|
|
112
114
|
AssetConfig = "asset_config",
|
|
113
115
|
DepositStorage = "deposit_storage",
|
|
114
116
|
BlockStorage = "block_storage",
|
package/dist/bridge/types.js
CHANGED
|
@@ -6,7 +6,9 @@ exports.PdaSeedType = void 0;
|
|
|
6
6
|
*/
|
|
7
7
|
var PdaSeedType;
|
|
8
8
|
(function (PdaSeedType) {
|
|
9
|
-
PdaSeedType["
|
|
9
|
+
PdaSeedType["Bridge"] = "bridge";
|
|
10
|
+
PdaSeedType["TokenAuthority"] = "token_authority";
|
|
11
|
+
PdaSeedType["CrumbAuthority"] = "crumb_authority";
|
|
10
12
|
PdaSeedType["AssetConfig"] = "asset_config";
|
|
11
13
|
PdaSeedType["DepositStorage"] = "deposit_storage";
|
|
12
14
|
PdaSeedType["BlockStorage"] = "block_storage";
|
package/dist/gen/nord.d.ts
CHANGED
|
@@ -59,10 +59,11 @@ export declare enum Error {
|
|
|
59
59
|
PYTH_FEED_ALREADY_ADDED = 95,
|
|
60
60
|
PYTH_GUARDIAN_SET_UNINITIALIZED = 96,
|
|
61
61
|
PYTH_GUARDIAN_SET_INVALID = 97,
|
|
62
|
-
|
|
63
|
-
UNINITIALIZED_PRICES = 98,
|
|
62
|
+
PYTH_FEED_DECIMALS_OUT_OF_RANGE = 98,
|
|
64
63
|
PYTH_FEED_PRICE_OUT_OF_RANGE = 99,
|
|
65
|
-
|
|
64
|
+
PYTH_FEED_VARIANCE_OUT_OF_RANGE = 100,
|
|
65
|
+
PYTH_GUARDIAN_SET_AND_PYTH_SIGNATURE_DO_NOT_MATCH = 126,
|
|
66
|
+
INVALID_TOKEN_PARAMETERS = 101,
|
|
66
67
|
INDEX_PRICE_OUT_OF_RANGE = 103,
|
|
67
68
|
INDEX_DECIMALS_OUT_OF_RANGE = 104,
|
|
68
69
|
INVALID_STATE_VERSION = 105,
|
|
@@ -88,10 +89,8 @@ export declare enum Error {
|
|
|
88
89
|
* before reducing position
|
|
89
90
|
*/
|
|
90
91
|
CAN_REDUCE_POSITION_ONLY_IF_ALL_ORDERS_ARE_CANCELED = 124,
|
|
91
|
-
PYTH_GUARDIAN_SET_AND_PYTH_SIGNATURE_DO_NOT_MATCH = 126,
|
|
92
92
|
/** UNEXPECTED_TOKEN_ID - Token was found, but not expected to be used in action context */
|
|
93
93
|
UNEXPECTED_TOKEN_ID = 127,
|
|
94
|
-
SIGNATURE_VERIFICATION = 128,
|
|
95
94
|
/**
|
|
96
95
|
* TOKEN_NOT_READY - happens in some situation when token misses some relevant information
|
|
97
96
|
* needed for operation, for example index price
|
|
@@ -140,6 +139,11 @@ export declare enum Error {
|
|
|
140
139
|
* Reduce orders can only be post only.
|
|
141
140
|
*/
|
|
142
141
|
ORDER_REDUCE_IS_POST_ONLY = 158,
|
|
142
|
+
/**
|
|
143
|
+
* ORDER_EXECUTION_SELL_PRICE - 10011_111;
|
|
144
|
+
* Order was rejected, because it planned under proposed price
|
|
145
|
+
*/
|
|
146
|
+
ORDER_EXECUTION_SELL_PRICE = 159,
|
|
143
147
|
/** BALANCE - 10100_000 */
|
|
144
148
|
BALANCE = 160,
|
|
145
149
|
/** BALANCE_DEPOSIT_OVERFLOW - 10100_001 */
|
|
@@ -174,6 +178,7 @@ export declare enum Error {
|
|
|
174
178
|
* Binary pattern: 10101_001
|
|
175
179
|
*/
|
|
176
180
|
TRIGGER_INVALID_PRICE = 169,
|
|
181
|
+
TRIGGER_NOT_FOUND = 170,
|
|
177
182
|
/** TIMESTAMP - 10110_000 */
|
|
178
183
|
TIMESTAMP = 176,
|
|
179
184
|
/** TIMESTAMP_OUT_OF_THRESHOLD - 10110_001 */
|
|
@@ -196,11 +201,18 @@ export declare enum Error {
|
|
|
196
201
|
MARKET_FROZEN = 193,
|
|
197
202
|
/** POSITION - 11001_000 */
|
|
198
203
|
POSITION = 200,
|
|
204
|
+
/** POSITION_NOT_FOUND - Position not found for specific entity in specific market */
|
|
205
|
+
POSITION_NOT_FOUND = 201,
|
|
199
206
|
POSITION_STATE_ORDER = 202,
|
|
200
207
|
POSITION_STATE_ORDER_PRICE = 203,
|
|
201
208
|
POSITION_STATE_ORDER_SIZE = 204,
|
|
202
209
|
POSITION_STATE_ORDER_SIDE = 205,
|
|
203
210
|
POSITION_SIZE_LIMIT = 206,
|
|
211
|
+
PRICE = 209,
|
|
212
|
+
SIGNATURE_VERIFICATION = 217,
|
|
213
|
+
SIGNATURE_VERIFICATION_MALFORMED_PUBLIC_KEY = 218,
|
|
214
|
+
SIGNATURE_VERIFICATION_INVALID_LENGTH = 219,
|
|
215
|
+
NOT_IMPLEMENTED = 500,
|
|
204
216
|
Dropped = 999
|
|
205
217
|
}
|
|
206
218
|
export declare function errorFromJSON(object: any): Error;
|
|
@@ -305,6 +317,9 @@ export interface Action {
|
|
|
305
317
|
} | {
|
|
306
318
|
$case: "removeTrigger";
|
|
307
319
|
value: Action_RemoveTrigger;
|
|
320
|
+
} | {
|
|
321
|
+
$case: "takePosition";
|
|
322
|
+
value: Action_TakePosition;
|
|
308
323
|
} | undefined;
|
|
309
324
|
}
|
|
310
325
|
export interface Action_CreateSession {
|
|
@@ -430,6 +445,10 @@ export interface Action_PlaceOrder {
|
|
|
430
445
|
* Optional account on behalf of whom the order should be placed.
|
|
431
446
|
* Executed only if sender has delegated authority to do so,
|
|
432
447
|
* like admin user or liquidator bot.
|
|
448
|
+
* # Delegation allowed if:
|
|
449
|
+
* - trigger
|
|
450
|
+
* - reduce bad position
|
|
451
|
+
* - sell at good price to reduce if cannot cover bad position
|
|
433
452
|
*/
|
|
434
453
|
delegatorAccountId?: number | undefined;
|
|
435
454
|
/**
|
|
@@ -536,6 +555,25 @@ export interface Action_RemoveTrigger {
|
|
|
536
555
|
side: Side;
|
|
537
556
|
accountId?: number | undefined;
|
|
538
557
|
}
|
|
558
|
+
export interface Action_TakePosition {
|
|
559
|
+
sessionId: bigint;
|
|
560
|
+
marketId: number;
|
|
561
|
+
/** Amount to take. */
|
|
562
|
+
size: bigint;
|
|
563
|
+
/**
|
|
564
|
+
* Account id which performs operation;
|
|
565
|
+
* if not specified, first account of session's owner user is picked
|
|
566
|
+
*/
|
|
567
|
+
senderAccountId?: number | undefined;
|
|
568
|
+
/**
|
|
569
|
+
* If set, then it is take action.
|
|
570
|
+
* If price not so good as in field, take will fail.
|
|
571
|
+
*
|
|
572
|
+
* If not set,
|
|
573
|
+
* will do fill-or-kill order as per liquidation trade rule.
|
|
574
|
+
*/
|
|
575
|
+
price?: bigint | undefined;
|
|
576
|
+
}
|
|
539
577
|
export interface Receipt {
|
|
540
578
|
/**
|
|
541
579
|
* Action id which was run to produce this receipt.
|
|
@@ -597,6 +635,9 @@ export interface Receipt {
|
|
|
597
635
|
} | {
|
|
598
636
|
$case: "triggerRemoved";
|
|
599
637
|
value: Receipt_TriggerRemoved;
|
|
638
|
+
} | {
|
|
639
|
+
$case: "positionTakenOrTraded";
|
|
640
|
+
value: Receipt_PositionTakenOrTradedResult;
|
|
600
641
|
} | undefined;
|
|
601
642
|
}
|
|
602
643
|
export interface Receipt_Posted {
|
|
@@ -622,6 +663,23 @@ export interface Receipt_PlaceOrderResult {
|
|
|
622
663
|
fills: Receipt_Trade[];
|
|
623
664
|
clientOrderId?: bigint | undefined;
|
|
624
665
|
}
|
|
666
|
+
export interface Receipt_TakenResult {
|
|
667
|
+
pnl: bigint;
|
|
668
|
+
size: bigint;
|
|
669
|
+
takerAccountId: number;
|
|
670
|
+
}
|
|
671
|
+
export interface Receipt_PositionTakenOrTradedResult {
|
|
672
|
+
marketId: number;
|
|
673
|
+
PositionTakenOrTradedKind?: {
|
|
674
|
+
$case: "taken";
|
|
675
|
+
value: Receipt_TakenResult;
|
|
676
|
+
} | //
|
|
677
|
+
/** non empty if trade immediately */
|
|
678
|
+
{
|
|
679
|
+
$case: "traded";
|
|
680
|
+
value: Receipt_PlaceOrderResult;
|
|
681
|
+
} | undefined;
|
|
682
|
+
}
|
|
625
683
|
export interface Receipt_CancelOrderResult {
|
|
626
684
|
orderId: bigint;
|
|
627
685
|
/** Account from which order was cancelled */
|
|
@@ -712,11 +770,14 @@ export declare const Action_Unpause: MessageFns<Action_Unpause>;
|
|
|
712
770
|
export declare const Action_Transfer: MessageFns<Action_Transfer>;
|
|
713
771
|
export declare const Action_AddTrigger: MessageFns<Action_AddTrigger>;
|
|
714
772
|
export declare const Action_RemoveTrigger: MessageFns<Action_RemoveTrigger>;
|
|
773
|
+
export declare const Action_TakePosition: MessageFns<Action_TakePosition>;
|
|
715
774
|
export declare const Receipt: MessageFns<Receipt>;
|
|
716
775
|
export declare const Receipt_Posted: MessageFns<Receipt_Posted>;
|
|
717
776
|
export declare const Receipt_Trade: MessageFns<Receipt_Trade>;
|
|
718
777
|
export declare const Receipt_CreateSessionResult: MessageFns<Receipt_CreateSessionResult>;
|
|
719
778
|
export declare const Receipt_PlaceOrderResult: MessageFns<Receipt_PlaceOrderResult>;
|
|
779
|
+
export declare const Receipt_TakenResult: MessageFns<Receipt_TakenResult>;
|
|
780
|
+
export declare const Receipt_PositionTakenOrTradedResult: MessageFns<Receipt_PositionTakenOrTradedResult>;
|
|
720
781
|
export declare const Receipt_CancelOrderResult: MessageFns<Receipt_CancelOrderResult>;
|
|
721
782
|
export declare const Receipt_DepositResult: MessageFns<Receipt_DepositResult>;
|
|
722
783
|
export declare const Receipt_InsertTokenResult: MessageFns<Receipt_InsertTokenResult>;
|