@n1xyz/nord-ts 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. package/dist/bridge/client.d.ts +4 -4
  2. package/dist/bridge/client.js +4 -4
  3. package/dist/bridge/const.d.ts +2 -2
  4. package/dist/bridge/const.js +22 -22
  5. package/dist/bridge/index.d.ts +4 -4
  6. package/dist/bridge/types.d.ts +3 -3
  7. package/dist/bridge/utils.d.ts +4 -4
  8. package/dist/bridge/utils.js +10 -10
  9. package/dist/const.d.ts +1 -1
  10. package/dist/const.js +17 -17
  11. package/dist/gen/nord.d.ts +1 -4
  12. package/dist/idl/bridge.d.ts +1 -1
  13. package/dist/idl/bridge.js +185 -185
  14. package/dist/index.d.ts +8 -8
  15. package/dist/nord/api/actions.d.ts +3 -3
  16. package/dist/nord/api/actions.js +21 -21
  17. package/dist/nord/api/core.d.ts +3 -3
  18. package/dist/nord/api/core.js +12 -12
  19. package/dist/nord/api/market.d.ts +1 -1
  20. package/dist/nord/api/market.js +12 -12
  21. package/dist/nord/api/metrics.d.ts +1 -1
  22. package/dist/nord/api/metrics.js +6 -6
  23. package/dist/nord/api/queries.d.ts +1 -1
  24. package/dist/nord/api/queries.js +9 -9
  25. package/dist/nord/client/Nord.d.ts +4 -4
  26. package/dist/nord/client/Nord.js +18 -18
  27. package/dist/nord/client/NordUser.d.ts +7 -7
  28. package/dist/nord/client/NordUser.js +45 -49
  29. package/dist/nord/index.d.ts +9 -9
  30. package/dist/nord/models/Subscriber.d.ts +6 -6
  31. package/dist/nord/models/Subscriber.js +1 -5
  32. package/dist/nord/utils/NordError.js +2 -2
  33. package/dist/types.d.ts +1 -1
  34. package/dist/types.js +1 -1
  35. package/dist/utils.d.ts +6 -6
  36. package/dist/utils.js +8 -8
  37. package/dist/websocket/NordWebSocketClient.d.ts +2 -2
  38. package/dist/websocket/NordWebSocketClient.js +38 -38
  39. package/dist/websocket/events.d.ts +1 -1
  40. package/dist/websocket/index.d.ts +2 -2
  41. package/docs/assets/hierarchy.js +1 -0
  42. package/docs/assets/highlight.css +16 -16
  43. package/docs/assets/icons.js +17 -14
  44. package/docs/assets/icons.svg +1 -1
  45. package/docs/assets/main.js +5 -4
  46. package/docs/assets/navigation.js +1 -1
  47. package/docs/assets/search.js +1 -1
  48. package/docs/assets/style.css +1423 -1227
  49. package/docs/classes/Nord.html +190 -31
  50. package/docs/classes/NordError.html +24 -0
  51. package/docs/classes/NordUser.html +120 -35
  52. package/docs/classes/NordWebSocketClient.html +335 -0
  53. package/docs/classes/SolanaBridgeClient.html +86 -0
  54. package/docs/classes/Subscriber.html +10 -0
  55. package/docs/enums/FillMode.html +5 -5
  56. package/docs/enums/KeyType.html +4 -4
  57. package/docs/enums/MetricPeriod.html +9 -0
  58. package/docs/enums/PdaSeedType.html +9 -0
  59. package/docs/enums/PeakTpsPeriodUnit.html +7 -7
  60. package/docs/enums/Side.html +3 -3
  61. package/docs/enums/WebSocketMessageType.html +7 -0
  62. package/docs/functions/actionQueryRollman.html +6 -0
  63. package/docs/functions/actionsQueryRollman.html +6 -0
  64. package/docs/functions/aggregateMetrics-1.html +7 -0
  65. package/docs/functions/assert.html +1 -1
  66. package/docs/functions/bigIntToProtoU128.html +3 -3
  67. package/docs/functions/blockQueryRollman.html +6 -0
  68. package/docs/functions/blockSummaryQueryRollman.html +6 -0
  69. package/docs/functions/bridgeToBN.html +5 -0
  70. package/docs/functions/bufferToHex.html +4 -0
  71. package/docs/functions/cancelOrder.html +1 -0
  72. package/docs/functions/checkPubKeyLength.html +1 -1
  73. package/docs/functions/checkedFetch.html +4 -4
  74. package/docs/functions/createSession.html +1 -0
  75. package/docs/functions/decodeLengthDelimited.html +7 -6
  76. package/docs/functions/encodeLengthDelimited.html +4 -4
  77. package/docs/functions/fillModeToProtoFillMode.html +4 -4
  78. package/docs/functions/findMarket.html +1 -1
  79. package/docs/functions/findPda.html +6 -0
  80. package/docs/functions/findToken.html +1 -1
  81. package/docs/functions/fromBN.html +5 -0
  82. package/docs/functions/getAccount.html +6 -0
  83. package/docs/functions/getActionNonce.html +5 -0
  84. package/docs/functions/getCurrentTps.html +6 -0
  85. package/docs/functions/getInfo.html +5 -0
  86. package/docs/functions/getMedianLatency.html +6 -0
  87. package/docs/functions/getOrderbook.html +6 -0
  88. package/docs/functions/getPeakTps.html +6 -0
  89. package/docs/functions/getTimestamp.html +5 -0
  90. package/docs/functions/getTotalTransactions.html +5 -0
  91. package/docs/functions/getTrades.html +6 -0
  92. package/docs/functions/getUserAccountIds.html +6 -0
  93. package/docs/functions/hexToBuffer.html +4 -0
  94. package/docs/functions/initWebSocketClient.html +12 -0
  95. package/docs/functions/keypairFromPrivateKey.html +4 -0
  96. package/docs/functions/makeSigningFunction.html +4 -0
  97. package/docs/functions/makeWalletSignFn.html +5 -5
  98. package/docs/functions/marketsStats.html +5 -0
  99. package/docs/functions/optExpect.html +4 -4
  100. package/docs/functions/optMap.html +5 -5
  101. package/docs/functions/optUnwrap.html +2 -2
  102. package/docs/functions/panic.html +1 -1
  103. package/docs/functions/placeOrder.html +1 -0
  104. package/docs/functions/queryAction.html +6 -0
  105. package/docs/functions/queryBlock.html +6 -0
  106. package/docs/functions/queryLastNBlocks.html +5 -0
  107. package/docs/functions/queryPrometheus.html +6 -0
  108. package/docs/functions/queryRecentActions.html +6 -0
  109. package/docs/functions/queryRecentBlocks.html +6 -0
  110. package/docs/functions/revokeSession.html +1 -0
  111. package/docs/functions/shortenPublicKey.html +5 -0
  112. package/docs/functions/signAction.html +2 -2
  113. package/docs/functions/toBN.html +5 -0
  114. package/docs/functions/toScaledU128.html +5 -5
  115. package/docs/functions/toScaledU64.html +5 -5
  116. package/docs/functions/transfer.html +1 -0
  117. package/docs/functions/withdraw.html +1 -0
  118. package/docs/hierarchy.html +1 -0
  119. package/docs/index.html +39 -20
  120. package/docs/interfaces/Account.html +8 -8
  121. package/docs/interfaces/ActionInfo.html +8 -8
  122. package/docs/interfaces/ActionNonceResponse.html +3 -0
  123. package/docs/interfaces/ActionQuery.html +4 -4
  124. package/docs/interfaces/ActionResponse.html +8 -8
  125. package/docs/interfaces/ActionsExtendedInfo.html +10 -10
  126. package/docs/interfaces/ActionsQuery.html +5 -5
  127. package/docs/interfaces/ActionsResponse.html +6 -6
  128. package/docs/interfaces/AggregateMetrics.html +12 -12
  129. package/docs/interfaces/BlockFacts.html +10 -0
  130. package/docs/interfaces/BlockQuery.html +6 -6
  131. package/docs/interfaces/BlockResponse.html +6 -6
  132. package/docs/interfaces/BlockSummary.html +8 -8
  133. package/docs/interfaces/BlockSummaryResponse.html +6 -6
  134. package/docs/interfaces/DeltaEvent.html +6 -6
  135. package/docs/interfaces/DepositSplParams.html +10 -0
  136. package/docs/interfaces/Info.html +3 -3
  137. package/docs/interfaces/Market.html +8 -6
  138. package/docs/interfaces/MarketStats.html +7 -7
  139. package/docs/interfaces/MarketsStatsResponse.html +2 -2
  140. package/docs/interfaces/NordConfig.html +14 -5
  141. package/docs/interfaces/NordWebSocketClientEvents.html +4 -0
  142. package/docs/interfaces/NordWebSocketEvents.html +8 -0
  143. package/docs/interfaces/Order.html +6 -6
  144. package/docs/interfaces/OrderInfo.html +6 -6
  145. package/docs/interfaces/OrderbookEntry.html +4 -0
  146. package/docs/interfaces/OrderbookQuery.html +6 -0
  147. package/docs/interfaces/OrderbookResponse.html +6 -0
  148. package/docs/interfaces/OrderbookSubscription.html +159 -0
  149. package/docs/interfaces/PerpMarketStats.html +5 -5
  150. package/docs/interfaces/RollmanActionExtendedInfo.html +4 -4
  151. package/docs/interfaces/RollmanActionInfo.html +4 -4
  152. package/docs/interfaces/RollmanActionResponse.html +4 -4
  153. package/docs/interfaces/RollmanActionsResponse.html +2 -2
  154. package/docs/interfaces/RollmanBlockResponse.html +3 -3
  155. package/docs/interfaces/SPLTokenInfo.html +10 -0
  156. package/docs/interfaces/SolanaBridgeConfig.html +10 -0
  157. package/docs/interfaces/StateFacts.html +10 -0
  158. package/docs/interfaces/SubscriberConfig.html +3 -3
  159. package/docs/interfaces/TimestampResponse.html +3 -0
  160. package/docs/interfaces/Token.html +5 -5
  161. package/docs/interfaces/TokenInfo.html +5 -0
  162. package/docs/interfaces/Trade.html +5 -5
  163. package/docs/interfaces/TradeSubscription.html +159 -0
  164. package/docs/interfaces/Trades.html +5 -5
  165. package/docs/interfaces/TradesQuery.html +6 -0
  166. package/docs/interfaces/TradesResponse.html +7 -0
  167. package/docs/interfaces/TransferParams.html +8 -0
  168. package/docs/interfaces/UserAccountIdsQuery.html +3 -0
  169. package/docs/interfaces/UserAccountIdsResponse.html +3 -0
  170. package/docs/interfaces/WebSocketDeltaUpdate.html +9 -0
  171. package/docs/interfaces/WebSocketSubscription.html +4 -0
  172. package/docs/interfaces/WebSocketTradeUpdate.html +6 -0
  173. package/docs/interfaces/WebSocketUserUpdate.html +6 -0
  174. package/docs/interfaces/WithdrawalClaim.html +14 -0
  175. package/docs/interfaces/WithdrawalParams.html +8 -0
  176. package/docs/modules.html +1 -70
  177. package/docs/types/BigIntValue.html +2 -2
  178. package/docs/types/WebSocketMessage.html +1 -0
  179. package/docs/variables/DEBUG_KEYS.html +1 -1
  180. package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
  181. package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
  182. package/docs/variables/DEV_URL.html +1 -1
  183. package/docs/variables/MAX_BUFFER_LEN.html +1 -1
  184. package/docs/variables/SESSION_TTL.html +1 -1
  185. package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
  186. package/docs/variables/ZERO_DECIMAL.html +1 -1
  187. package/docs/variables/_private.html +2 -0
  188. package/eslint.config.mjs +66 -0
  189. package/package.json +12 -13
  190. package/src/bridge/client.ts +10 -10
  191. package/src/bridge/const.ts +24 -24
  192. package/src/bridge/index.ts +4 -4
  193. package/src/bridge/types.ts +10 -10
  194. package/src/bridge/utils.ts +14 -14
  195. package/src/const.ts +18 -18
  196. package/src/gen/nord.ts +1 -4
  197. package/src/idl/bridge.ts +186 -186
  198. package/src/index.ts +8 -8
  199. package/src/nord/api/actions.ts +25 -25
  200. package/src/nord/api/core.ts +16 -16
  201. package/src/nord/api/market.ts +15 -15
  202. package/src/nord/api/metrics.ts +16 -16
  203. package/src/nord/api/queries.ts +12 -12
  204. package/src/nord/client/Nord.ts +27 -27
  205. package/src/nord/client/NordUser.ts +59 -63
  206. package/src/nord/index.ts +9 -9
  207. package/src/nord/models/Subscriber.ts +11 -12
  208. package/src/nord/utils/NordError.ts +2 -2
  209. package/src/types.ts +12 -12
  210. package/src/utils.ts +20 -20
  211. package/src/websocket/NordWebSocketClient.ts +42 -42
  212. package/src/websocket/events.ts +1 -1
  213. package/src/websocket/index.ts +2 -2
  214. package/tests/utils.spec.ts +24 -24
  215. package/tsconfig.eslint.json +12 -0
  216. package/.eslintignore +0 -1
  217. package/.eslintrc.js +0 -31
  218. package/dist/abis/ERC20_ABI.d.ts +0 -39
  219. package/dist/abis/ERC20_ABI.js +0 -313
  220. package/dist/abis/NORD_GETTERS_FACET_ABI.d.ts +0 -34
  221. package/dist/abis/NORD_GETTERS_FACET_ABI.js +0 -195
  222. package/dist/abis/NORD_RAMP_FACET_ABI.d.ts +0 -35
  223. package/dist/abis/NORD_RAMP_FACET_ABI.js +0 -144
  224. package/dist/abis/index.d.ts +0 -3
  225. package/dist/abis/index.js +0 -9
  226. package/dist/bridge/NordUser.d.ts +0 -78
  227. package/dist/bridge/NordUser.js +0 -196
  228. package/dist/client.d.ts +0 -70
  229. package/dist/client.js +0 -129
  230. package/dist/constants/endpoints.d.ts +0 -65
  231. package/dist/constants/endpoints.js +0 -68
  232. package/dist/models/account.d.ts +0 -58
  233. package/dist/models/account.js +0 -6
  234. package/dist/models/index.d.ts +0 -8
  235. package/dist/models/index.js +0 -28
  236. package/dist/models/market.d.ts +0 -137
  237. package/dist/models/market.js +0 -6
  238. package/dist/models/order.d.ts +0 -211
  239. package/dist/models/order.js +0 -6
  240. package/dist/models/token.d.ts +0 -50
  241. package/dist/models/token.js +0 -6
  242. package/dist/nord/Nord.d.ts +0 -249
  243. package/dist/nord/Nord.js +0 -388
  244. package/dist/nord/NordError.d.ts +0 -23
  245. package/dist/nord/NordError.js +0 -48
  246. package/dist/nord/NordImpl.d.ts +0 -11
  247. package/dist/nord/NordImpl.js +0 -26
  248. package/dist/nord/NordUser.d.ts +0 -243
  249. package/dist/nord/NordUser.js +0 -481
  250. package/dist/nord/Subscriber.d.ts +0 -37
  251. package/dist/nord/Subscriber.js +0 -29
  252. package/dist/nord/actions.d.ts +0 -101
  253. package/dist/nord/actions.js +0 -254
  254. package/dist/nord/api/index.d.ts +0 -1
  255. package/dist/nord/api/index.js +0 -17
  256. package/dist/nord/api/orderFunctions.d.ts +0 -168
  257. package/dist/nord/api/orderFunctions.js +0 -133
  258. package/dist/nord/core.d.ts +0 -48
  259. package/dist/nord/core.js +0 -97
  260. package/dist/nord/market.d.ts +0 -36
  261. package/dist/nord/market.js +0 -90
  262. package/dist/nord/metrics.d.ts +0 -67
  263. package/dist/nord/metrics.js +0 -124
  264. package/dist/nord/queries.d.ts +0 -81
  265. package/dist/nord/queries.js +0 -181
  266. package/dist/nord/types.d.ts +0 -88
  267. package/dist/nord/types.js +0 -2
  268. package/dist/nord/websocket.d.ts +0 -49
  269. package/dist/nord/websocket.js +0 -107
  270. package/dist/operations/account.d.ts +0 -58
  271. package/dist/operations/account.js +0 -112
  272. package/dist/operations/market.d.ts +0 -65
  273. package/dist/operations/market.js +0 -131
  274. package/dist/operations/orders.d.ts +0 -57
  275. package/dist/operations/orders.js +0 -129
  276. package/dist/solana/NordUser.d.ts +0 -78
  277. package/dist/solana/NordUser.js +0 -196
  278. package/dist/solana/client.d.ts +0 -139
  279. package/dist/solana/client.js +0 -360
  280. package/dist/solana/const.d.ts +0 -23
  281. package/dist/solana/const.js +0 -47
  282. package/dist/solana/index.d.ts +0 -5
  283. package/dist/solana/index.js +0 -23
  284. package/dist/solana/types.d.ts +0 -118
  285. package/dist/solana/types.js +0 -16
  286. package/dist/solana/utils.d.ts +0 -64
  287. package/dist/solana/utils.js +0 -131
  288. package/dist/types/api.d.ts +0 -152
  289. package/dist/types/api.js +0 -6
  290. package/dist/types/config.d.ts +0 -34
  291. package/dist/types/config.js +0 -6
  292. package/dist/utils/errors.d.ts +0 -96
  293. package/dist/utils/errors.js +0 -132
  294. package/dist/utils/http.d.ts +0 -35
  295. package/dist/utils/http.js +0 -105
  296. package/dist/websocket/client.d.ts +0 -93
  297. package/dist/websocket/client.js +0 -222
  298. package/dist/websocket.d.ts +0 -55
  299. package/dist/websocket.js +0 -211
  300. package/docs/interfaces/ERC20TokenInfo.html +0 -5
  301. package/docs/variables/DEV_CONTRACT_ADDRESS.html +0 -1
  302. package/docs/variables/ERC20_ABI.html +0 -1
  303. package/docs/variables/EVM_DEV_URL.html +0 -1
  304. package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +0 -1
  305. package/docs/variables/NORD_GETTERS_FACET_ABI.html +0 -1
  306. package/docs/variables/NORD_RAMP_FACET_ABI.html +0 -1
@@ -1,360 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.SolanaBridgeClient = void 0;
37
- const anchor = __importStar(require("@coral-xyz/anchor"));
38
- const anchor_1 = require("@coral-xyz/anchor");
39
- const web3_js_1 = require("@solana/web3.js");
40
- const spl_token_1 = require("@solana/spl-token");
41
- const types_1 = require("./types");
42
- // Import the BRIDGE_IDL
43
- const bridge_1 = require("../idl/bridge");
44
- /**
45
- * Solana Bridge Client for interacting with the bridge program
46
- */
47
- class SolanaBridgeClient {
48
- /**
49
- * Create a new Solana Bridge Client
50
- *
51
- * @param config Bridge configuration
52
- * @param wallet Anchor wallet for signing transactions
53
- */
54
- constructor(config, wallet) {
55
- this.config = config;
56
- this.connection = new web3_js_1.Connection(config.rpcUrl, {
57
- commitment: config.commitment
58
- });
59
- this.programId = new web3_js_1.PublicKey(config.programId);
60
- // Create the provider
61
- const provider = new anchor_1.AnchorProvider(this.connection, wallet, { commitment: config.commitment });
62
- // Set the provider globally
63
- anchor.setProvider(provider);
64
- // Initialize the program with the IDL using a type cast to work around type issues
65
- const ProgramClass = anchor.Program;
66
- this.program = new ProgramClass(bridge_1.BRIDGE_IDL, this.programId, provider);
67
- }
68
- /**
69
- * Derive a PDA (Program Derived Address) for the given seeds
70
- *
71
- * @param type PDA seed type
72
- * @param seeds Additional seeds
73
- * @returns [PDA, bump]
74
- */
75
- async findPda(type, ...seeds) {
76
- const seedBuffers = [
77
- Buffer.from(type),
78
- ...seeds.map(seed => {
79
- if (seed instanceof web3_js_1.PublicKey) {
80
- return seed.toBuffer();
81
- }
82
- else if (typeof seed === 'string') {
83
- return Buffer.from(seed);
84
- }
85
- else if (typeof seed === 'number') {
86
- return Buffer.from([seed]);
87
- }
88
- return seed;
89
- })
90
- ];
91
- return web3_js_1.PublicKey.findProgramAddressSync(seedBuffers, this.programId);
92
- }
93
- /**
94
- * Find the contract storage PDA
95
- *
96
- * @returns [PDA, bump]
97
- */
98
- async findContractStoragePda() {
99
- return this.findPda(types_1.PdaSeedType.ContractStorage);
100
- }
101
- /**
102
- * Find the asset whitelisted PDA for a token mint
103
- *
104
- * @param mint Token mint address
105
- * @returns [PDA, bump]
106
- */
107
- async findAssetWhitelistedPda(mint) {
108
- return this.findPda(types_1.PdaSeedType.AssetWhitelisted, mint);
109
- }
110
- /**
111
- * Find the deposit storage PDA for a deposit index
112
- *
113
- * @param depositIndex Deposit index
114
- * @returns [PDA, bump]
115
- */
116
- async findDepositStoragePda(depositIndex) {
117
- return this.findPda(types_1.PdaSeedType.DepositStorage, depositIndex);
118
- }
119
- /**
120
- * Find the block storage PDA for a block ID
121
- *
122
- * @param blockId Block ID
123
- * @returns [PDA, bump]
124
- */
125
- async findBlockStoragePda(blockId) {
126
- return this.findPda(types_1.PdaSeedType.BlockStorage, blockId);
127
- }
128
- /**
129
- * Find the withdrawal nullifier PDA
130
- *
131
- * @param blockId Block ID
132
- * @param leafIndex Leaf index
133
- * @returns [PDA, bump]
134
- */
135
- async findWithdrawalNullifierPda(blockId, leafIndex) {
136
- return this.findPda(types_1.PdaSeedType.WithdrawalNullifier, blockId, leafIndex);
137
- }
138
- /**
139
- * Find the authority PDA
140
- *
141
- * @returns [PDA, bump]
142
- */
143
- async findAuthorityPda() {
144
- return this.findPda(types_1.PdaSeedType.Authority);
145
- }
146
- /**
147
- * Deposit SPL tokens to the bridge
148
- *
149
- * @param params Deposit parameters
150
- * @param signer Signer keypair
151
- * @returns Transaction signature
152
- */
153
- async depositSpl(params, signer) {
154
- const [contractStorage] = await this.findContractStoragePda();
155
- const [assetWhitelisted] = await this.findAssetWhitelistedPda(params.mint);
156
- // Get the last deposit index from contract storage
157
- const contractStorageAccount = await this.program.account.contractStorage.fetch(contractStorage);
158
- const lastDepositIndex = contractStorageAccount.lastDepositIndex.toNumber();
159
- // Find the deposit PDA for this deposit
160
- const [deposit] = await this.findDepositStoragePda(lastDepositIndex + 1);
161
- // Find the previous deposit PDA if it exists
162
- let prevDeposit = undefined;
163
- if (lastDepositIndex > 0) {
164
- const [prevDepositPda] = await this.findDepositStoragePda(lastDepositIndex);
165
- prevDeposit = prevDepositPda;
166
- }
167
- // Build the transaction
168
- const accounts = {
169
- depositor: signer.publicKey,
170
- deposit,
171
- assetWhitelisted,
172
- contractStorage,
173
- fromAccount: params.fromAccount,
174
- toAccount: params.toAccount,
175
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
176
- systemProgram: web3_js_1.SystemProgram.programId,
177
- };
178
- // Add prevDeposit only if it exists
179
- if (prevDeposit) {
180
- accounts.prevDeposit = prevDeposit;
181
- }
182
- const tx = await this.program.methods
183
- .depositSpl(params.amount)
184
- .accounts(accounts)
185
- .transaction();
186
- // Sign and send the transaction
187
- return await (0, web3_js_1.sendAndConfirmTransaction)(this.connection, tx, [signer], { commitment: this.config.commitment });
188
- }
189
- /**
190
- * Withdraw tokens from the bridge
191
- *
192
- * @param params Withdrawal parameters
193
- * @param signer Signer keypair
194
- * @returns Transaction signature
195
- */
196
- async withdraw(params, signer) {
197
- const [stateUpdate] = await this.findBlockStoragePda(params.claim.blockId.toNumber());
198
- const [withdrawalNullifier] = await this.findWithdrawalNullifierPda(params.claim.blockId.toNumber(), params.claim.leafIndex.toNumber());
199
- const [authority] = await this.findAuthorityPda();
200
- // Build the transaction
201
- const tx = await this.program.methods
202
- .withdraw(params.claim)
203
- .accounts({
204
- payer: signer.publicKey,
205
- stateUpdate,
206
- withdrawalNullifier,
207
- fromAccount: params.fromAccount,
208
- toAccount: params.toAccount,
209
- authority,
210
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
211
- systemProgram: web3_js_1.SystemProgram.programId,
212
- })
213
- .transaction();
214
- // Sign and send the transaction
215
- return await (0, web3_js_1.sendAndConfirmTransaction)(this.connection, tx, [signer], { commitment: this.config.commitment });
216
- }
217
- /**
218
- * Whitelist an asset (token) for use with the bridge
219
- *
220
- * @param mint Token mint address
221
- * @param signer Operator keypair
222
- * @returns Transaction signature
223
- */
224
- async whitelistAsset(mint, signer) {
225
- const [contractStorage] = await this.findContractStoragePda();
226
- const [assetWhitelisted] = await this.findAssetWhitelistedPda(mint);
227
- // Build the transaction
228
- const tx = await this.program.methods
229
- .whitelistAsset(mint)
230
- .accounts({
231
- operator: signer.publicKey,
232
- contractStorage,
233
- assetWhitelisted,
234
- systemProgram: web3_js_1.SystemProgram.programId,
235
- })
236
- .transaction();
237
- // Sign and send the transaction
238
- return await (0, web3_js_1.sendAndConfirmTransaction)(this.connection, tx, [signer], { commitment: this.config.commitment });
239
- }
240
- /**
241
- * Propose a new block
242
- *
243
- * @param facts Block facts
244
- * @param signer Operator keypair
245
- * @returns Transaction signature
246
- */
247
- async proposeBlock(facts, signer) {
248
- const [contractStorage] = await this.findContractStoragePda();
249
- // Get the last block ID from contract storage
250
- const contractStorageAccount = await this.program.account.contractStorage.fetch(contractStorage);
251
- const [block] = await this.findBlockStoragePda(contractStorageAccount.lastBlockId.toNumber() + 1);
252
- // Find the last deposit PDA
253
- const [lastDeposit] = await this.findDepositStoragePda(facts.nextStateFacts.lastDepositIndex.toNumber());
254
- // Find the DA fact state
255
- const daFactState = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(types_1.PdaSeedType.DaFactStorage), facts.daCommitment], this.programId)[0];
256
- // Build the transaction
257
- const tx = await this.program.methods
258
- .proposeBlock(facts)
259
- .accounts({
260
- operator: signer.publicKey,
261
- block,
262
- lastDeposit,
263
- daFactState,
264
- contractStorage,
265
- systemProgram: web3_js_1.SystemProgram.programId,
266
- })
267
- .transaction();
268
- // Sign and send the transaction
269
- return await (0, web3_js_1.sendAndConfirmTransaction)(this.connection, tx, [signer], { commitment: this.config.commitment });
270
- }
271
- /**
272
- * Finalize a block
273
- *
274
- * @param blockId Block ID
275
- * @param stateUpdateId State update ID
276
- * @param signer Payer keypair
277
- * @returns Transaction signature
278
- */
279
- async finalizeBlock(blockId, stateUpdateId, signer) {
280
- const [contractStorage] = await this.findContractStoragePda();
281
- const [block] = await this.findBlockStoragePda(blockId);
282
- // Build the transaction
283
- const tx = await this.program.methods
284
- .finalizeBlock(new anchor.BN(stateUpdateId))
285
- .accounts({
286
- payer: signer.publicKey,
287
- block,
288
- contractStorage,
289
- systemProgram: web3_js_1.SystemProgram.programId,
290
- })
291
- .transaction();
292
- // Sign and send the transaction
293
- return await (0, web3_js_1.sendAndConfirmTransaction)(this.connection, tx, [signer], { commitment: this.config.commitment });
294
- }
295
- /**
296
- * Finalize a DA fact
297
- *
298
- * @param fact DA fact (32-byte array)
299
- * @param signer Payer keypair
300
- * @returns Transaction signature
301
- */
302
- async finalizeDaFact(fact, signer) {
303
- const factStateStorage = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(types_1.PdaSeedType.DaFactStorage), fact], this.programId)[0];
304
- // Build the transaction
305
- const tx = await this.program.methods
306
- .finalizeDaFact(Array.from(fact))
307
- .accounts({
308
- payer: signer.publicKey,
309
- factStateStorage,
310
- systemProgram: web3_js_1.SystemProgram.programId,
311
- })
312
- .transaction();
313
- // Sign and send the transaction
314
- return await (0, web3_js_1.sendAndConfirmTransaction)(this.connection, tx, [signer], { commitment: this.config.commitment });
315
- }
316
- /**
317
- * Initialize the bridge contract
318
- *
319
- * @param operator Operator public key
320
- * @param initialAppStateCommitment Initial app state commitment (32-byte array)
321
- * @param signer Payer keypair
322
- * @returns Transaction signature
323
- */
324
- async initialize(operator, initialAppStateCommitment, signer) {
325
- const [contractStorage] = await this.findContractStoragePda();
326
- // Build the transaction
327
- const tx = await this.program.methods
328
- .initialize(operator, Array.from(initialAppStateCommitment))
329
- .accounts({
330
- payer: signer.publicKey,
331
- program: this.programId,
332
- contractStorage,
333
- systemProgram: web3_js_1.SystemProgram.programId,
334
- })
335
- .transaction();
336
- // Sign and send the transaction
337
- return await (0, web3_js_1.sendAndConfirmTransaction)(this.connection, tx, [signer], { commitment: this.config.commitment });
338
- }
339
- /**
340
- * Create an associated token account if it doesn't exist
341
- *
342
- * @param mint Token mint
343
- * @param owner Account owner
344
- * @param payer Transaction payer
345
- * @returns Associated token account address
346
- */
347
- async createTokenAccountIfNeeded(mint, owner, payer) {
348
- const associatedTokenAddress = await (0, spl_token_1.getAssociatedTokenAddress)(mint, owner);
349
- try {
350
- await this.connection.getTokenAccountBalance(associatedTokenAddress);
351
- }
352
- catch (error) {
353
- // Account doesn't exist, create it
354
- const transaction = new web3_js_1.Transaction().add((0, spl_token_1.createAssociatedTokenAccountInstruction)(payer.publicKey, associatedTokenAddress, owner, mint));
355
- await (0, web3_js_1.sendAndConfirmTransaction)(this.connection, transaction, [payer], { commitment: this.config.commitment });
356
- }
357
- return associatedTokenAddress;
358
- }
359
- }
360
- exports.SolanaBridgeClient = SolanaBridgeClient;
@@ -1,23 +0,0 @@
1
- import { SPLTokenInfo } from './types';
2
- import { Commitment } from '@solana/web3.js';
3
- export declare const SOLANA_MAINNET_URL = "https://api.mainnet-beta.solana.com";
4
- export declare const SOLANA_DEVNET_URL = "https://api.devnet.solana.com";
5
- export declare const SOLANA_TESTNET_URL = "https://api.testnet.solana.com";
6
- export declare const SOLANA_LOCALNET_URL = "http://localhost:8899";
7
- export declare const DEFAULT_COMMITMENT: Commitment;
8
- export declare const DEV_URL = "http://localhost";
9
- export declare const WEBSERVER_DEV_URL: string;
10
- export declare const SOLANA_PROGRAM_ID = "CVDFLCAjXhVWiPXH9nTCTpCgVzmDVoiPzNJYuccr1dqB";
11
- export declare const DEV_TOKEN_INFOS: SPLTokenInfo[];
12
- export declare const DEFAULT_FUNDING_AMOUNTS: {
13
- [key: string]: [string, number];
14
- };
15
- export declare const PDA_SEEDS: {
16
- CONTRACT_STORAGE: string;
17
- ASSET_WHITELISTED: string;
18
- DEPOSIT_STORAGE: string;
19
- BLOCK_STORAGE: string;
20
- WITHDRAWAL_NULLIFIER: string;
21
- AUTHORITY: string;
22
- DA_FACT_STORAGE: string;
23
- };
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PDA_SEEDS = exports.DEFAULT_FUNDING_AMOUNTS = exports.DEV_TOKEN_INFOS = exports.SOLANA_PROGRAM_ID = exports.WEBSERVER_DEV_URL = exports.DEV_URL = exports.DEFAULT_COMMITMENT = exports.SOLANA_LOCALNET_URL = exports.SOLANA_TESTNET_URL = exports.SOLANA_DEVNET_URL = exports.SOLANA_MAINNET_URL = void 0;
4
- // Solana RPC endpoints
5
- exports.SOLANA_MAINNET_URL = 'https://api.mainnet-beta.solana.com';
6
- exports.SOLANA_DEVNET_URL = 'https://api.devnet.solana.com';
7
- exports.SOLANA_TESTNET_URL = 'https://api.testnet.solana.com';
8
- exports.SOLANA_LOCALNET_URL = 'http://localhost:8899';
9
- // Default commitment level
10
- exports.DEFAULT_COMMITMENT = 'confirmed';
11
- // Webserver configuration
12
- const WEBSERVER_PORT = "80";
13
- exports.DEV_URL = "http://localhost";
14
- exports.WEBSERVER_DEV_URL = exports.DEV_URL + ":" + WEBSERVER_PORT;
15
- // Program ID (will be supplied externally)
16
- exports.SOLANA_PROGRAM_ID = 'CVDFLCAjXhVWiPXH9nTCTpCgVzmDVoiPzNJYuccr1dqB';
17
- // Sample token information for development
18
- exports.DEV_TOKEN_INFOS = [
19
- {
20
- mint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC on devnet
21
- precision: 6,
22
- tokenId: 0,
23
- name: 'usdc',
24
- },
25
- {
26
- mint: 'So11111111111111111111111111111111111111112', // Wrapped SOL
27
- precision: 9,
28
- tokenId: 1,
29
- name: 'sol',
30
- },
31
- ];
32
- // Default funding amounts for development
33
- exports.DEFAULT_FUNDING_AMOUNTS = {
34
- SOL: ["0.2", 9],
35
- // USDC mint address
36
- "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v": ["10000", 6],
37
- };
38
- // PDA seed constants
39
- exports.PDA_SEEDS = {
40
- CONTRACT_STORAGE: 'contract_storage',
41
- ASSET_WHITELISTED: 'asset_whitelisted',
42
- DEPOSIT_STORAGE: 'deposit_storage',
43
- BLOCK_STORAGE: 'block_storage',
44
- WITHDRAWAL_NULLIFIER: 'withdrawal_nullifier',
45
- AUTHORITY: 'authority',
46
- DA_FACT_STORAGE: 'da_fact_storage',
47
- };
@@ -1,5 +0,0 @@
1
- export * from './client';
2
- export * from './types';
3
- export * from './utils';
4
- import { BRIDGE_IDL } from '../idl/bridge';
5
- export { BRIDGE_IDL };
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.BRIDGE_IDL = void 0;
18
- __exportStar(require("./client"), exports);
19
- __exportStar(require("./types"), exports);
20
- __exportStar(require("./utils"), exports);
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; } });
@@ -1,118 +0,0 @@
1
- import { PublicKey } from '@solana/web3.js';
2
- import { BN } from '@coral-xyz/anchor';
3
- /**
4
- * Configuration for Solana bridge
5
- */
6
- export interface SolanaBridgeConfig {
7
- /** Solana RPC URL */
8
- rpcUrl: string;
9
- /** Program ID for the bridge program */
10
- programId: string;
11
- /** Commitment level for transactions */
12
- commitment: 'processed' | 'confirmed' | 'finalized';
13
- /** Token information for supported SPL tokens */
14
- tokenInfos: SPLTokenInfo[];
15
- }
16
- /**
17
- * Information about an SPL token
18
- */
19
- export interface SPLTokenInfo {
20
- /** Token mint address */
21
- mint: string;
22
- /** Token decimals */
23
- precision: number;
24
- /** Token ID in the Layer-N system */
25
- tokenId: number;
26
- /** Token name */
27
- name: string;
28
- }
29
- /**
30
- * Parameters for depositing SPL tokens
31
- */
32
- export interface DepositSplParams {
33
- /** Amount to deposit (in token's smallest unit) */
34
- amount: BN;
35
- /** Mint address of the token to deposit */
36
- mint: PublicKey;
37
- /** User's token account to deposit from */
38
- fromAccount: PublicKey;
39
- /** Bridge's token account to deposit to */
40
- toAccount: PublicKey;
41
- }
42
- /**
43
- * Parameters for withdrawing tokens
44
- */
45
- export interface WithdrawalParams {
46
- /** Withdrawal claim data */
47
- claim: WithdrawalClaim;
48
- /** User's token account to receive tokens */
49
- toAccount: PublicKey;
50
- /** Bridge's token account to withdraw from */
51
- fromAccount: PublicKey;
52
- }
53
- /**
54
- * Withdrawal claim data
55
- */
56
- export interface WithdrawalClaim {
57
- /** Block ID containing the withdrawal */
58
- blockId: BN;
59
- /** Leaf index in the Merkle tree */
60
- leafIndex: BN;
61
- /** Amount to withdraw */
62
- amount: BN;
63
- /** Recipient address */
64
- recipient: PublicKey;
65
- /** Token mint address */
66
- mint: PublicKey;
67
- /** Merkle proof for the withdrawal */
68
- proof: Buffer[];
69
- }
70
- /**
71
- * Block facts data structure
72
- */
73
- export interface BlockFacts {
74
- /** Previous state facts */
75
- prevStateFacts: StateFacts;
76
- /** Next state facts */
77
- nextStateFacts: StateFacts;
78
- /** Data availability commitment */
79
- daCommitment: Buffer;
80
- /** Withdrawal Merkle root */
81
- withdrawalRoot: Buffer;
82
- }
83
- /**
84
- * State facts data structure
85
- */
86
- export interface StateFacts {
87
- /** Application state commitment */
88
- appStateCommitment: Buffer;
89
- /** Deposit root */
90
- depositRoot: Buffer;
91
- /** Last deposit index */
92
- lastDepositIndex: BN;
93
- /** Last action ID */
94
- lastActionId: BN;
95
- }
96
- /**
97
- * Transfer parameters
98
- */
99
- export interface TransferParams {
100
- /** User public key */
101
- user: PublicKey;
102
- /** Token mint */
103
- mint: PublicKey;
104
- /** Amount to transfer */
105
- amount: BN;
106
- }
107
- /**
108
- * PDA seed types
109
- */
110
- export declare enum PdaSeedType {
111
- ContractStorage = "contract_storage",
112
- AssetWhitelisted = "asset_whitelisted",
113
- DepositStorage = "deposit_storage",
114
- BlockStorage = "block_storage",
115
- WithdrawalNullifier = "withdrawal_nullifier",
116
- Authority = "authority",
117
- DaFactStorage = "da_fact_storage"
118
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PdaSeedType = void 0;
4
- /**
5
- * PDA seed types
6
- */
7
- var PdaSeedType;
8
- (function (PdaSeedType) {
9
- PdaSeedType["ContractStorage"] = "contract_storage";
10
- PdaSeedType["AssetWhitelisted"] = "asset_whitelisted";
11
- PdaSeedType["DepositStorage"] = "deposit_storage";
12
- PdaSeedType["BlockStorage"] = "block_storage";
13
- PdaSeedType["WithdrawalNullifier"] = "withdrawal_nullifier";
14
- PdaSeedType["Authority"] = "authority";
15
- PdaSeedType["DaFactStorage"] = "da_fact_storage";
16
- })(PdaSeedType || (exports.PdaSeedType = PdaSeedType = {}));
@@ -1,64 +0,0 @@
1
- import { Keypair, PublicKey } from '@solana/web3.js';
2
- import { BN } from '@coral-xyz/anchor';
3
- import { PdaSeedType } from './types';
4
- /**
5
- * Convert a private key string to a Solana Keypair
6
- *
7
- * @param privateKey Private key as base58 string, hex string, or Uint8Array
8
- * @returns Solana Keypair
9
- */
10
- export declare function keypairFromPrivateKey(privateKey: string | Uint8Array): Keypair;
11
- /**
12
- * Create a signing function for Solana transactions
13
- *
14
- * @param keypair Solana keypair
15
- * @returns Signing function
16
- */
17
- export declare function makeSigningFunction(keypair: Keypair): (message: Uint8Array) => Promise<Uint8Array>;
18
- /**
19
- * Convert a number to a BN with the specified number of decimals
20
- *
21
- * @param amount Amount as a number
22
- * @param decimals Number of decimals
23
- * @returns BN representation of the amount
24
- */
25
- export declare function toBN(amount: number, decimals: number): BN;
26
- /**
27
- * Format a BN as a human-readable number with the specified number of decimals
28
- *
29
- * @param amount Amount as a BN
30
- * @param decimals Number of decimals
31
- * @returns Formatted number
32
- */
33
- export declare function fromBN(amount: BN, decimals: number): number;
34
- /**
35
- * Derive a PDA (Program Derived Address) for the given seeds
36
- *
37
- * @param programId Program ID
38
- * @param type PDA seed type
39
- * @param seeds Additional seeds
40
- * @returns [PDA, bump]
41
- */
42
- export declare function findPda(programId: PublicKey, type: PdaSeedType, ...seeds: (Buffer | PublicKey | string | number)[]): [PublicKey, number];
43
- /**
44
- * Convert a buffer to a hex string
45
- *
46
- * @param buffer Buffer to convert
47
- * @returns Hex string
48
- */
49
- export declare function bufferToHex(buffer: Buffer | Uint8Array): string;
50
- /**
51
- * Convert a hex string to a buffer
52
- *
53
- * @param hex Hex string
54
- * @returns Buffer
55
- */
56
- export declare function hexToBuffer(hex: string): Buffer;
57
- /**
58
- * Shorten a public key for display
59
- *
60
- * @param publicKey Public key to shorten
61
- * @param chars Number of characters to show at the beginning and end
62
- * @returns Shortened public key
63
- */
64
- export declare function shortenPublicKey(publicKey: PublicKey | string, chars?: number): string;