@n1xyz/nord-ts 0.0.14 → 0.0.16-29f6652

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.
Files changed (186) hide show
  1. package/.prettierignore +1 -0
  2. package/README.md +9 -6
  3. package/dist/bridge/client.d.ts +8 -7
  4. package/dist/bridge/client.js +39 -37
  5. package/dist/bridge/index.d.ts +1 -2
  6. package/dist/bridge/index.js +2 -2
  7. package/dist/bridge/types.d.ts +7 -3
  8. package/dist/bridge/types.js +3 -1
  9. package/dist/gen/common.js +1 -1
  10. package/dist/gen/nord.d.ts +74 -25
  11. package/dist/gen/nord.js +498 -78
  12. package/dist/idl/bridge.json +1493 -0
  13. package/dist/idl/index.d.ts +585 -0
  14. package/dist/idl/index.js +8 -0
  15. package/dist/nord/api/core.js +7 -5
  16. package/dist/nord/api/metrics.js +7 -4
  17. package/dist/nord/client/Nord.d.ts +19 -5
  18. package/dist/nord/client/Nord.js +50 -23
  19. package/dist/nord/client/NordUser.d.ts +1 -1
  20. package/dist/nord/client/NordUser.js +19 -16
  21. package/dist/types.d.ts +3 -3
  22. package/dist/websocket/NordWebSocketClient.js +0 -2
  23. package/docs/assets/hierarchy.js +1 -1
  24. package/docs/assets/navigation.js +1 -1
  25. package/docs/assets/search.js +1 -1
  26. package/docs/classes/Nord.html +99 -100
  27. package/docs/classes/NordError.html +6 -6
  28. package/docs/classes/NordUser.html +49 -54
  29. package/docs/classes/NordWebSocketClient.html +6 -11
  30. package/docs/classes/SolanaBridgeClient.html +32 -27
  31. package/docs/classes/Subscriber.html +3 -3
  32. package/docs/enums/FillMode.html +2 -2
  33. package/docs/enums/KeyType.html +2 -2
  34. package/docs/enums/MetricPeriod.html +2 -2
  35. package/docs/enums/PdaSeedType.html +5 -3
  36. package/docs/enums/PeakTpsPeriodUnit.html +2 -2
  37. package/docs/enums/Side.html +2 -2
  38. package/docs/enums/WebSocketMessageType.html +3 -3
  39. package/docs/functions/actionQueryRollman.html +1 -1
  40. package/docs/functions/actionsQueryRollman.html +1 -1
  41. package/docs/functions/aggregateMetrics-1.html +1 -1
  42. package/docs/functions/assert.html +1 -1
  43. package/docs/functions/bigIntToProtoU128.html +1 -1
  44. package/docs/functions/bridgeToBN.html +1 -1
  45. package/docs/functions/bufferToHex.html +1 -1
  46. package/docs/functions/cancelOrder.html +1 -1
  47. package/docs/functions/checkPubKeyLength.html +1 -1
  48. package/docs/functions/checkedFetch.html +1 -1
  49. package/docs/functions/createSession.html +1 -1
  50. package/docs/functions/decodeLengthDelimited.html +1 -1
  51. package/docs/functions/encodeLengthDelimited.html +1 -1
  52. package/docs/functions/fillModeToProtoFillMode.html +1 -1
  53. package/docs/functions/findMarket.html +1 -1
  54. package/docs/functions/findPda.html +1 -1
  55. package/docs/functions/findToken.html +1 -1
  56. package/docs/functions/fromBN.html +1 -1
  57. package/docs/functions/getAccount.html +1 -1
  58. package/docs/functions/getActionNonce.html +1 -1
  59. package/docs/functions/getCurrentTps.html +1 -1
  60. package/docs/functions/getInfo.html +1 -1
  61. package/docs/functions/{queryLastNBlocks.html → getLastActionId.html} +3 -3
  62. package/docs/functions/getMedianLatency.html +1 -1
  63. package/docs/functions/getOrderbook.html +1 -1
  64. package/docs/functions/getPeakTps.html +1 -1
  65. package/docs/functions/getTimestamp.html +1 -1
  66. package/docs/functions/getTotalTransactions.html +1 -1
  67. package/docs/functions/getTrades.html +1 -1
  68. package/docs/functions/getUserAccountIds.html +1 -1
  69. package/docs/functions/hexToBuffer.html +1 -1
  70. package/docs/functions/initWebSocketClient.html +9 -9
  71. package/docs/functions/keypairFromPrivateKey.html +1 -1
  72. package/docs/functions/makeSigningFunction.html +1 -1
  73. package/docs/functions/makeWalletSignFn.html +1 -1
  74. package/docs/functions/marketsStats.html +1 -1
  75. package/docs/functions/optExpect.html +1 -1
  76. package/docs/functions/optMap.html +1 -1
  77. package/docs/functions/optUnwrap.html +1 -1
  78. package/docs/functions/panic.html +1 -1
  79. package/docs/functions/placeOrder.html +1 -1
  80. package/docs/functions/queryAction.html +1 -1
  81. package/docs/functions/queryPrometheus.html +1 -1
  82. package/docs/functions/queryRecentActions.html +4 -3
  83. package/docs/functions/revokeSession.html +1 -1
  84. package/docs/functions/shortenPublicKey.html +1 -1
  85. package/docs/functions/signAction.html +1 -1
  86. package/docs/functions/toBN.html +1 -1
  87. package/docs/functions/toScaledU128.html +1 -1
  88. package/docs/functions/toScaledU64.html +1 -1
  89. package/docs/functions/transfer.html +1 -1
  90. package/docs/functions/withdraw.html +1 -1
  91. package/docs/hierarchy.html +1 -1
  92. package/docs/index.html +2 -2
  93. package/docs/interfaces/Account.html +2 -2
  94. package/docs/interfaces/ActionInfo.html +2 -2
  95. package/docs/interfaces/ActionNonceResponse.html +2 -2
  96. package/docs/interfaces/ActionQuery.html +2 -2
  97. package/docs/interfaces/ActionResponse.html +2 -2
  98. package/docs/interfaces/ActionsExtendedInfo.html +2 -2
  99. package/docs/interfaces/ActionsQuery.html +2 -2
  100. package/docs/interfaces/ActionsResponse.html +2 -2
  101. package/docs/interfaces/AggregateMetrics.html +2 -2
  102. package/docs/interfaces/BlockFacts.html +5 -5
  103. package/docs/interfaces/BlockQuery.html +2 -2
  104. package/docs/interfaces/BlockResponse.html +2 -2
  105. package/docs/interfaces/BlockSummary.html +2 -2
  106. package/docs/interfaces/BlockSummaryResponse.html +2 -2
  107. package/docs/interfaces/DeltaEvent.html +2 -2
  108. package/docs/interfaces/DepositSplParams.html +6 -6
  109. package/docs/interfaces/Info.html +2 -2
  110. package/docs/interfaces/Market.html +2 -2
  111. package/docs/interfaces/MarketStats.html +2 -2
  112. package/docs/interfaces/MarketsStatsResponse.html +2 -2
  113. package/docs/interfaces/NordConfig.html +19 -9
  114. package/docs/interfaces/NordWebSocketClientEvents.html +2 -2
  115. package/docs/interfaces/NordWebSocketEvents.html +3 -3
  116. package/docs/interfaces/Order.html +2 -2
  117. package/docs/interfaces/OrderInfo.html +2 -2
  118. package/docs/interfaces/OrderbookEntry.html +2 -2
  119. package/docs/interfaces/OrderbookQuery.html +2 -2
  120. package/docs/interfaces/OrderbookResponse.html +2 -2
  121. package/docs/interfaces/OrderbookSubscription.html +5 -5
  122. package/docs/interfaces/PerpMarketStats.html +2 -2
  123. package/docs/interfaces/RollmanActionExtendedInfo.html +2 -2
  124. package/docs/interfaces/RollmanActionInfo.html +2 -2
  125. package/docs/interfaces/RollmanActionResponse.html +2 -2
  126. package/docs/interfaces/RollmanActionsResponse.html +2 -2
  127. package/docs/interfaces/RollmanBlockResponse.html +2 -2
  128. package/docs/interfaces/SPLTokenInfo.html +5 -5
  129. package/docs/interfaces/SolanaBridgeConfig.html +8 -6
  130. package/docs/interfaces/StateFacts.html +5 -5
  131. package/docs/interfaces/SubscriberConfig.html +2 -2
  132. package/docs/interfaces/TimestampResponse.html +2 -2
  133. package/docs/interfaces/Token.html +2 -2
  134. package/docs/interfaces/TokenInfo.html +3 -2
  135. package/docs/interfaces/Trade.html +2 -2
  136. package/docs/interfaces/TradeSubscription.html +5 -5
  137. package/docs/interfaces/Trades.html +2 -2
  138. package/docs/interfaces/TradesQuery.html +2 -2
  139. package/docs/interfaces/TradesResponse.html +2 -2
  140. package/docs/interfaces/TransferParams.html +4 -4
  141. package/docs/interfaces/UserAccountIdsQuery.html +2 -2
  142. package/docs/interfaces/UserAccountIdsResponse.html +2 -2
  143. package/docs/interfaces/WebSocketAccountUpdate.html +6 -0
  144. package/docs/interfaces/WebSocketDeltaUpdate.html +3 -3
  145. package/docs/interfaces/WebSocketSubscription.html +3 -3
  146. package/docs/interfaces/WebSocketTradeUpdate.html +3 -3
  147. package/docs/interfaces/WithdrawalClaim.html +7 -7
  148. package/docs/interfaces/WithdrawalParams.html +4 -4
  149. package/docs/modules.html +1 -1
  150. package/docs/types/BigIntValue.html +1 -1
  151. package/docs/types/SubscriptionPattern.html +4 -0
  152. package/docs/types/SubscriptionType.html +2 -0
  153. package/docs/types/WebSocketMessage.html +1 -1
  154. package/docs/variables/DEBUG_KEYS.html +1 -1
  155. package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
  156. package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
  157. package/docs/variables/DEV_URL.html +1 -1
  158. package/docs/variables/MAX_BUFFER_LEN.html +1 -1
  159. package/docs/variables/SESSION_TTL.html +1 -1
  160. package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
  161. package/docs/variables/ZERO_DECIMAL.html +1 -1
  162. package/docs/variables/_private.html +1 -1
  163. package/idl-generate.sh +4 -0
  164. package/package.json +6 -3
  165. package/src/bridge/client.ts +55 -43
  166. package/src/bridge/index.ts +1 -2
  167. package/src/bridge/types.ts +7 -3
  168. package/src/gen/common.ts +1 -1
  169. package/src/gen/nord.ts +567 -75
  170. package/src/idl/bridge.json +1493 -0
  171. package/src/idl/index.ts +2 -0
  172. package/src/nord/api/core.ts +1 -3
  173. package/src/nord/api/metrics.ts +2 -0
  174. package/src/nord/client/Nord.ts +49 -13
  175. package/src/nord/client/NordUser.ts +52 -59
  176. package/src/types.ts +2 -2
  177. package/src/websocket/NordWebSocketClient.ts +0 -2
  178. package/tsconfig.json +1 -1
  179. package/dist/idl/bridge.d.ts +0 -2
  180. package/dist/idl/bridge.js +0 -930
  181. package/docs/functions/blockQueryRollman.html +0 -6
  182. package/docs/functions/blockSummaryQueryRollman.html +0 -6
  183. package/docs/functions/queryBlock.html +0 -6
  184. package/docs/functions/queryRecentBlocks.html +0 -6
  185. package/docs/interfaces/WebSocketUserUpdate.html +0 -6
  186. package/src/idl/bridge.ts +0 -929
package/.prettierignore CHANGED
@@ -1 +1,2 @@
1
1
  src/gen/*
2
+ src/idl/*.json
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
- solanaProgramId: 'your_solana_program_id',
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 nord.fetchNordInfo();
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
- // Create Nord instance
59
- const nord = new Nord({
58
+ // Define Nord configuration
59
+ const nordConfig = {
60
60
  webServerUrl: 'https://api.nord.exchange',
61
- solanaProgramId: 'your_solana_program_id',
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');
@@ -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: (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
+ findPda(type: PdaSeedType, ...seeds: any[]): Promise<[PublicKey, number]>;
40
41
  /**
41
42
  * Find the asset config PDA for a token mint
42
43
  *
@@ -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
- // Import the BRIDGE_IDL
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({ ...bridge_1.BRIDGE_IDL, address: config.programId }, provider);
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
- return seed;
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 contractStorageAccount = await this.program.account.contractStorage.fetch(contractStorage);
178
- const lastDepositIndex = contractStorageAccount.lastDepositIndex.toNumber();
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,39 @@ 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
- depositor: this.provider.wallet.publicKey,
191
+ payer: this.provider.wallet.publicKey,
190
192
  deposit,
191
193
  assetConfig,
192
- contractStorage,
194
+ bridge: this.bridge,
195
+ program: this.programId,
193
196
  fromAccount: params.fromAccount,
194
- toAccount: params.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 };
204
+ const txRecipient = params.recipientAddress || this.provider.wallet.publicKey;
198
205
  // Create the transaction
199
- const tx = await this.program.methods
200
- .depositSpl(params.amount)
201
- .accounts({ ...accounts, prevDeposit: prevDeposit })
202
- .transaction();
206
+ const tx = await (await this.program.methods
207
+ .deposit(txRecipient, params.amount)
208
+ .accounts(allAccounts)).transaction();
203
209
  // Check if toAccount is initialized and add preinstruction if needed
204
210
  try {
205
- await this.connection.getTokenAccountBalance(params.toAccount);
211
+ await this.connection.getTokenAccountBalance(toAccount);
206
212
  }
207
213
  catch {
208
214
  // Account doesn't exist, add instruction to create it
209
215
  // Get the authority PDA which is the owner of the toAccount
210
216
  const [authority] = await this.findAuthorityPda();
211
217
  const createTokenAccountIx = (0, spl_token_1.createAssociatedTokenAccountInstruction)(this.provider.wallet.publicKey, // payer
212
- params.toAccount, // associated token account address
218
+ toAccount, // associated token account address
213
219
  authority, // owner of the token account
214
220
  params.mint, // token mint
215
221
  spl_token_1.TOKEN_2022_PROGRAM_ID);
@@ -255,14 +261,13 @@ class SolanaBridgeClient {
255
261
  * @returns Transaction signature
256
262
  */
257
263
  async whitelistAsset(mint, signer) {
258
- const [contractStorage] = await this.findContractStoragePda();
259
264
  const [assetWhitelisted] = await this.findAssetConfigPda(mint);
260
265
  // Build the transaction
261
266
  const tx = await this.program.methods
262
267
  .whitelistAsset(mint)
263
268
  .accounts({
264
269
  operator: signer.publicKey,
265
- contractStorage,
270
+ bridge: this.bridge,
266
271
  assetWhitelisted,
267
272
  systemProgram: web3_js_1.SystemProgram.programId,
268
273
  })
@@ -278,10 +283,9 @@ class SolanaBridgeClient {
278
283
  * @returns Transaction signature
279
284
  */
280
285
  async proposeBlock(facts, signer) {
281
- const [contractStorage] = await this.findContractStoragePda();
282
286
  // Get the last block ID from contract storage
283
- const contractStorageAccount = await this.program.account.contractStorage.fetch(contractStorage);
284
- const [block] = await this.findBlockStoragePda(contractStorageAccount.lastBlockId.toNumber() + 1);
287
+ const bridgeAccount = await this.program.account.bridge.fetch(this.bridge);
288
+ const [block] = await this.findBlockStoragePda(bridgeAccount.lastBlockId.toNumber() + 1);
285
289
  // Find the last deposit PDA
286
290
  const [lastDeposit] = await this.findDepositStoragePda(facts.nextStateFacts.lastDepositIndex.toNumber());
287
291
  // Find the DA fact state
@@ -294,7 +298,7 @@ class SolanaBridgeClient {
294
298
  block,
295
299
  lastDeposit,
296
300
  daFactState,
297
- contractStorage,
301
+ bridge: this.bridge,
298
302
  systemProgram: web3_js_1.SystemProgram.programId,
299
303
  })
300
304
  .transaction();
@@ -310,7 +314,6 @@ class SolanaBridgeClient {
310
314
  * @returns Transaction signature
311
315
  */
312
316
  async finalizeBlock(blockId, stateUpdateId, signer) {
313
- const [contractStorage] = await this.findContractStoragePda();
314
317
  const [block] = await this.findBlockStoragePda(blockId);
315
318
  // Build the transaction
316
319
  const tx = await this.program.methods
@@ -318,7 +321,7 @@ class SolanaBridgeClient {
318
321
  .accounts({
319
322
  payer: signer.publicKey,
320
323
  block,
321
- contractStorage,
324
+ bridge: this.bridge,
322
325
  systemProgram: web3_js_1.SystemProgram.programId,
323
326
  })
324
327
  .transaction();
@@ -355,14 +358,13 @@ class SolanaBridgeClient {
355
358
  * @returns Transaction signature
356
359
  */
357
360
  async initialize(operator, initialAppStateCommitment, signer) {
358
- const [contractStorage] = await this.findContractStoragePda();
359
361
  // Build the transaction
360
362
  const tx = await this.program.methods
361
363
  .initialize(operator, Array.from(initialAppStateCommitment))
362
364
  .accounts({
363
365
  payer: signer.publicKey,
364
366
  program: this.programId,
365
- contractStorage,
367
+ bridge: this.bridge,
366
368
  systemProgram: web3_js_1.SystemProgram.programId,
367
369
  })
368
370
  .transaction();
@@ -1,5 +1,4 @@
1
1
  export * from "./client";
2
2
  export * from "./types";
3
3
  export * from "./utils";
4
- import { BRIDGE_IDL } from "../idl/bridge";
5
- export { BRIDGE_IDL };
4
+ export { BRIDGE_IDL } from "../idl";
@@ -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
- const bridge_1 = require("../idl/bridge");
23
- Object.defineProperty(exports, "BRIDGE_IDL", { enumerable: true, get: function () { return bridge_1.BRIDGE_IDL; } });
22
+ var idl_1 = require("../idl");
23
+ Object.defineProperty(exports, "BRIDGE_IDL", { enumerable: true, get: function () { return idl_1.BRIDGE_IDL; } });
@@ -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,8 @@ 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
+ /** Optional destination token account for the bridge deposit. If omitted, the account will be derived automatically. */
42
+ recipientAddress?: PublicKey;
41
43
  }
42
44
  /**
43
45
  * Parameters for withdrawing tokens
@@ -108,7 +110,9 @@ export interface TransferParams {
108
110
  * PDA seed types
109
111
  */
110
112
  export declare enum PdaSeedType {
111
- ContractStorage = "contract_storage",
113
+ Bridge = "bridge",
114
+ TokenAuthority = "token_authority",
115
+ CrumbAuthority = "crumb_authority",
112
116
  AssetConfig = "asset_config",
113
117
  DepositStorage = "deposit_storage",
114
118
  BlockStorage = "block_storage",
@@ -6,7 +6,9 @@ exports.PdaSeedType = void 0;
6
6
  */
7
7
  var PdaSeedType;
8
8
  (function (PdaSeedType) {
9
- PdaSeedType["ContractStorage"] = "contract_storage";
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";
@@ -2,7 +2,7 @@
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
4
  // protoc-gen-ts_proto v2.7.0
5
- // protoc v3.21.12
5
+ // protoc v5.28.3
6
6
  // source: common.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.Message_Transfer = exports.Message = exports.protobufPackage = void 0;
@@ -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
- /** UNINITIALIZED_PRICES - TODO(deprecate) */
63
- UNINITIALIZED_PRICES = 98,
62
+ PYTH_FEED_DECIMALS_OUT_OF_RANGE = 98,
64
63
  PYTH_FEED_PRICE_OUT_OF_RANGE = 99,
65
- INVALID_TOKEN_PARAMETERS = 100,
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
@@ -120,26 +119,6 @@ export declare enum Error {
120
119
  * retained on account
121
120
  */
122
121
  DUST_ACCOUNT = 145,
123
- /** ORDER_EXECUTION - 10011_000 - 3 bit suffix */
124
- ORDER_EXECUTION = 152,
125
- /** ORDER_EXECUTION_EMPTY - 10011_001; */
126
- ORDER_EXECUTION_EMPTY = 153,
127
- /** ORDER_EXECUTION_FILL_OR_KILL - 10011_010; */
128
- ORDER_EXECUTION_FILL_OR_KILL = 154,
129
- /**
130
- * ORDER_EXECUTION_MISSING_LIMITS - Order requires some of its limits specified according to fill mode
131
- * 10011_011;
132
- */
133
- ORDER_EXECUTION_MISSING_LIMITS = 155,
134
- /** ORDER_EXECUTION_MISSING_PRICE - 10011_100; */
135
- ORDER_EXECUTION_MISSING_PRICE = 156,
136
- /** ORDER_EXECUTION_SIZE_LIMIT - 10011_101; */
137
- ORDER_EXECUTION_SIZE_LIMIT = 157,
138
- /**
139
- * ORDER_REDUCE_IS_POST_ONLY - 10011_110;
140
- * Reduce orders can only be post only.
141
- */
142
- ORDER_REDUCE_IS_POST_ONLY = 158,
143
122
  /** BALANCE - 10100_000 */
144
123
  BALANCE = 160,
145
124
  /** BALANCE_DEPOSIT_OVERFLOW - 10100_001 */
@@ -174,6 +153,7 @@ export declare enum Error {
174
153
  * Binary pattern: 10101_001
175
154
  */
176
155
  TRIGGER_INVALID_PRICE = 169,
156
+ TRIGGER_NOT_FOUND = 170,
177
157
  /** TIMESTAMP - 10110_000 */
178
158
  TIMESTAMP = 176,
179
159
  /** TIMESTAMP_OUT_OF_THRESHOLD - 10110_001 */
@@ -196,11 +176,31 @@ export declare enum Error {
196
176
  MARKET_FROZEN = 193,
197
177
  /** POSITION - 11001_000 */
198
178
  POSITION = 200,
179
+ /** POSITION_NOT_FOUND - Position not found for specific entity in specific market */
180
+ POSITION_NOT_FOUND = 201,
199
181
  POSITION_STATE_ORDER = 202,
200
182
  POSITION_STATE_ORDER_PRICE = 203,
201
183
  POSITION_STATE_ORDER_SIZE = 204,
202
184
  POSITION_STATE_ORDER_SIDE = 205,
203
185
  POSITION_SIZE_LIMIT = 206,
186
+ PRICE = 209,
187
+ SIGNATURE_VERIFICATION = 217,
188
+ SIGNATURE_VERIFICATION_MALFORMED_PUBLIC_KEY = 218,
189
+ SIGNATURE_VERIFICATION_INVALID_LENGTH = 219,
190
+ /** ORDER_EXECUTION - 1111_0000 = 240 -- 4 bit suffix */
191
+ ORDER_EXECUTION = 240,
192
+ ORDER_EXECUTION_EMPTY = 241,
193
+ ORDER_EXECUTION_FILL_OR_KILL = 242,
194
+ /** ORDER_EXECUTION_MISSING_LIMITS - Order requires some of its limits specified according to fill mode */
195
+ ORDER_EXECUTION_MISSING_LIMITS = 243,
196
+ ORDER_EXECUTION_MISSING_PRICE = 244,
197
+ ORDER_EXECUTION_SIZE_LIMIT = 245,
198
+ ORDER_EXECUTION_LIMIT_PRICE = 246,
199
+ /** ORDER_REDUCE_IS_POST_ONLY - Reduce orders can only be post only. */
200
+ ORDER_REDUCE_IS_POST_ONLY = 247,
201
+ /** ORDER_EXECUTION_SELL_PRICE - Order was rejected, because it planned under proposed price */
202
+ ORDER_EXECUTION_SELL_PRICE = 248,
203
+ NOT_IMPLEMENTED = 500,
204
204
  Dropped = 999
205
205
  }
206
206
  export declare function errorFromJSON(object: any): Error;
@@ -305,6 +305,9 @@ export interface Action {
305
305
  } | {
306
306
  $case: "removeTrigger";
307
307
  value: Action_RemoveTrigger;
308
+ } | {
309
+ $case: "takePosition";
310
+ value: Action_TakePosition;
308
311
  } | undefined;
309
312
  }
310
313
  export interface Action_CreateSession {
@@ -430,6 +433,10 @@ export interface Action_PlaceOrder {
430
433
  * Optional account on behalf of whom the order should be placed.
431
434
  * Executed only if sender has delegated authority to do so,
432
435
  * like admin user or liquidator bot.
436
+ * # Delegation allowed if:
437
+ * - trigger
438
+ * - reduce bad position
439
+ * - sell at good price to reduce if cannot cover bad position
433
440
  */
434
441
  delegatorAccountId?: number | undefined;
435
442
  /**
@@ -536,6 +543,25 @@ export interface Action_RemoveTrigger {
536
543
  side: Side;
537
544
  accountId?: number | undefined;
538
545
  }
546
+ export interface Action_TakePosition {
547
+ sessionId: bigint;
548
+ marketId: number;
549
+ /** Amount to take. */
550
+ size: bigint;
551
+ /**
552
+ * Account id which performs operation;
553
+ * if not specified, first account of session's owner user is picked
554
+ */
555
+ senderAccountId?: number | undefined;
556
+ /**
557
+ * If set, then it is take action.
558
+ * If price not so good as in field, take will fail.
559
+ *
560
+ * If not set,
561
+ * will do fill-or-kill order as per liquidation trade rule.
562
+ */
563
+ price?: bigint | undefined;
564
+ }
539
565
  export interface Receipt {
540
566
  /**
541
567
  * Action id which was run to produce this receipt.
@@ -597,6 +623,9 @@ export interface Receipt {
597
623
  } | {
598
624
  $case: "triggerRemoved";
599
625
  value: Receipt_TriggerRemoved;
626
+ } | {
627
+ $case: "positionTakenOrTraded";
628
+ value: Receipt_PositionTakenOrTradedResult;
600
629
  } | undefined;
601
630
  }
602
631
  export interface Receipt_Posted {
@@ -622,6 +651,23 @@ export interface Receipt_PlaceOrderResult {
622
651
  fills: Receipt_Trade[];
623
652
  clientOrderId?: bigint | undefined;
624
653
  }
654
+ export interface Receipt_TakenResult {
655
+ pnl: bigint;
656
+ size: bigint;
657
+ takerAccountId: number;
658
+ }
659
+ export interface Receipt_PositionTakenOrTradedResult {
660
+ marketId: number;
661
+ PositionTakenOrTradedKind?: {
662
+ $case: "taken";
663
+ value: Receipt_TakenResult;
664
+ } | //
665
+ /** non empty if trade immediately */
666
+ {
667
+ $case: "traded";
668
+ value: Receipt_PlaceOrderResult;
669
+ } | undefined;
670
+ }
625
671
  export interface Receipt_CancelOrderResult {
626
672
  orderId: bigint;
627
673
  /** Account from which order was cancelled */
@@ -712,11 +758,14 @@ export declare const Action_Unpause: MessageFns<Action_Unpause>;
712
758
  export declare const Action_Transfer: MessageFns<Action_Transfer>;
713
759
  export declare const Action_AddTrigger: MessageFns<Action_AddTrigger>;
714
760
  export declare const Action_RemoveTrigger: MessageFns<Action_RemoveTrigger>;
761
+ export declare const Action_TakePosition: MessageFns<Action_TakePosition>;
715
762
  export declare const Receipt: MessageFns<Receipt>;
716
763
  export declare const Receipt_Posted: MessageFns<Receipt_Posted>;
717
764
  export declare const Receipt_Trade: MessageFns<Receipt_Trade>;
718
765
  export declare const Receipt_CreateSessionResult: MessageFns<Receipt_CreateSessionResult>;
719
766
  export declare const Receipt_PlaceOrderResult: MessageFns<Receipt_PlaceOrderResult>;
767
+ export declare const Receipt_TakenResult: MessageFns<Receipt_TakenResult>;
768
+ export declare const Receipt_PositionTakenOrTradedResult: MessageFns<Receipt_PositionTakenOrTradedResult>;
720
769
  export declare const Receipt_CancelOrderResult: MessageFns<Receipt_CancelOrderResult>;
721
770
  export declare const Receipt_DepositResult: MessageFns<Receipt_DepositResult>;
722
771
  export declare const Receipt_InsertTokenResult: MessageFns<Receipt_InsertTokenResult>;