@n1xyz/nord-ts 0.0.1 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/.eslintrc.js +11 -0
  2. package/README.md +148 -65
  3. package/dist/bridge/NordUser.d.ts +78 -0
  4. package/dist/bridge/NordUser.js +196 -0
  5. package/dist/bridge/client.d.ts +150 -0
  6. package/dist/bridge/client.js +394 -0
  7. package/dist/bridge/const.d.ts +23 -0
  8. package/dist/bridge/const.js +47 -0
  9. package/dist/bridge/index.d.ts +5 -0
  10. package/dist/bridge/index.js +23 -0
  11. package/dist/bridge/types.d.ts +118 -0
  12. package/dist/bridge/types.js +16 -0
  13. package/dist/bridge/utils.d.ts +64 -0
  14. package/dist/bridge/utils.js +131 -0
  15. package/dist/client.d.ts +70 -0
  16. package/dist/client.js +129 -0
  17. package/dist/const.d.ts +2 -5
  18. package/dist/const.js +18 -22
  19. package/dist/constants/endpoints.d.ts +65 -0
  20. package/dist/constants/endpoints.js +68 -0
  21. package/dist/gen/common.d.ts +6 -1
  22. package/dist/gen/common.js +19 -9
  23. package/dist/gen/nord.d.ts +75 -17
  24. package/dist/gen/nord.js +987 -423
  25. package/dist/idl/bridge.d.ts +2 -0
  26. package/dist/idl/bridge.js +703 -0
  27. package/dist/index.d.ts +8 -5
  28. package/dist/index.js +18 -2
  29. package/dist/models/account.d.ts +58 -0
  30. package/dist/models/account.js +6 -0
  31. package/dist/models/index.d.ts +8 -0
  32. package/dist/models/index.js +28 -0
  33. package/dist/models/market.d.ts +137 -0
  34. package/dist/models/market.js +6 -0
  35. package/dist/models/order.d.ts +211 -0
  36. package/dist/models/order.js +6 -0
  37. package/dist/models/token.d.ts +50 -0
  38. package/dist/models/token.js +6 -0
  39. package/dist/nord/Nord.d.ts +222 -49
  40. package/dist/nord/Nord.js +290 -278
  41. package/dist/nord/NordError.d.ts +23 -0
  42. package/dist/nord/NordError.js +48 -0
  43. package/dist/nord/NordImpl.d.ts +6 -2
  44. package/dist/nord/NordImpl.js +21 -1
  45. package/dist/nord/NordUser.d.ts +208 -42
  46. package/dist/nord/NordUser.js +389 -157
  47. package/dist/nord/Subscriber.d.ts +37 -0
  48. package/dist/nord/Subscriber.js +29 -0
  49. package/dist/nord/api/actions.d.ts +101 -0
  50. package/dist/nord/api/actions.js +250 -0
  51. package/dist/nord/api/core.d.ts +49 -0
  52. package/dist/nord/api/core.js +121 -0
  53. package/dist/nord/api/index.d.ts +1 -0
  54. package/dist/nord/api/index.js +17 -0
  55. package/dist/nord/api/market.d.ts +36 -0
  56. package/dist/nord/api/market.js +98 -0
  57. package/dist/nord/api/metrics.d.ts +67 -0
  58. package/dist/nord/api/metrics.js +132 -0
  59. package/dist/nord/api/orderFunctions.d.ts +168 -0
  60. package/dist/nord/api/orderFunctions.js +133 -0
  61. package/dist/nord/api/queries.d.ts +81 -0
  62. package/dist/nord/api/queries.js +187 -0
  63. package/dist/nord/client/Nord.d.ts +335 -0
  64. package/dist/nord/client/Nord.js +532 -0
  65. package/dist/nord/client/NordUser.d.ts +320 -0
  66. package/dist/nord/client/NordUser.js +701 -0
  67. package/dist/nord/core.d.ts +48 -0
  68. package/dist/nord/core.js +97 -0
  69. package/dist/nord/index.d.ts +9 -2
  70. package/dist/nord/index.js +30 -6
  71. package/dist/nord/market.d.ts +36 -0
  72. package/dist/nord/market.js +90 -0
  73. package/dist/nord/metrics.d.ts +67 -0
  74. package/dist/nord/metrics.js +124 -0
  75. package/dist/nord/models/Subscriber.d.ts +37 -0
  76. package/dist/nord/models/Subscriber.js +29 -0
  77. package/dist/nord/queries.d.ts +81 -0
  78. package/dist/nord/queries.js +181 -0
  79. package/dist/nord/types.d.ts +88 -0
  80. package/dist/nord/types.js +2 -0
  81. package/dist/nord/utils/NordError.d.ts +35 -0
  82. package/dist/nord/utils/NordError.js +46 -0
  83. package/dist/nord/websocket.d.ts +49 -0
  84. package/dist/nord/websocket.js +107 -0
  85. package/dist/operations/account.d.ts +58 -0
  86. package/dist/operations/account.js +112 -0
  87. package/dist/operations/market.d.ts +65 -0
  88. package/dist/operations/market.js +131 -0
  89. package/dist/operations/orders.d.ts +57 -0
  90. package/dist/operations/orders.js +129 -0
  91. package/dist/solana/NordUser.d.ts +78 -0
  92. package/dist/solana/NordUser.js +196 -0
  93. package/dist/solana/client.d.ts +139 -0
  94. package/dist/solana/client.js +360 -0
  95. package/dist/solana/const.d.ts +23 -0
  96. package/dist/solana/const.js +47 -0
  97. package/dist/solana/index.d.ts +5 -0
  98. package/dist/solana/index.js +23 -0
  99. package/dist/solana/types.d.ts +118 -0
  100. package/dist/solana/types.js +16 -0
  101. package/dist/solana/utils.d.ts +64 -0
  102. package/dist/solana/utils.js +131 -0
  103. package/dist/types/api.d.ts +152 -0
  104. package/dist/types/api.js +6 -0
  105. package/dist/types/config.d.ts +34 -0
  106. package/dist/types/config.js +6 -0
  107. package/dist/types.d.ts +144 -87
  108. package/dist/types.js +13 -2
  109. package/dist/utils/errors.d.ts +96 -0
  110. package/dist/utils/errors.js +132 -0
  111. package/dist/utils/http.d.ts +35 -0
  112. package/dist/utils/http.js +105 -0
  113. package/dist/utils.d.ts +14 -5
  114. package/dist/utils.js +26 -7
  115. package/dist/websocket/NordWebSocketClient.d.ts +71 -0
  116. package/dist/websocket/NordWebSocketClient.js +343 -0
  117. package/dist/websocket/client.d.ts +93 -0
  118. package/dist/websocket/client.js +222 -0
  119. package/dist/websocket/events.d.ts +19 -0
  120. package/dist/websocket/events.js +2 -0
  121. package/dist/websocket/index.d.ts +2 -0
  122. package/dist/websocket/index.js +5 -0
  123. package/dist/websocket.d.ts +55 -0
  124. package/dist/websocket.js +211 -0
  125. package/docs/assets/navigation.js +1 -1
  126. package/docs/assets/search.js +1 -1
  127. package/docs/classes/Nord.html +2 -15
  128. package/docs/classes/NordUser.html +4 -4
  129. package/docs/enums/FillMode.html +2 -2
  130. package/docs/enums/KeyType.html +2 -2
  131. package/docs/enums/PeakTpsPeriodUnit.html +2 -2
  132. package/docs/enums/Side.html +2 -2
  133. package/docs/functions/assert.html +1 -1
  134. package/docs/functions/bigIntToProtoU128.html +1 -1
  135. package/docs/functions/checkPubKeyLength.html +1 -1
  136. package/docs/functions/checkedFetch.html +1 -1
  137. package/docs/functions/decodeLengthDelimited.html +1 -1
  138. package/docs/functions/encodeLengthDelimited.html +1 -1
  139. package/docs/functions/fillModeToProtoFillMode.html +1 -1
  140. package/docs/functions/findMarket.html +1 -1
  141. package/docs/functions/findToken.html +1 -1
  142. package/docs/functions/makeWalletSignFn.html +1 -1
  143. package/docs/functions/optExpect.html +1 -1
  144. package/docs/functions/optMap.html +1 -1
  145. package/docs/functions/optUnwrap.html +1 -1
  146. package/docs/functions/panic.html +1 -1
  147. package/docs/functions/signAction.html +1 -1
  148. package/docs/functions/toScaledU128.html +1 -1
  149. package/docs/functions/toScaledU64.html +1 -1
  150. package/docs/interfaces/Account.html +2 -2
  151. package/docs/interfaces/ActionInfo.html +2 -2
  152. package/docs/interfaces/ActionQuery.html +2 -2
  153. package/docs/interfaces/ActionResponse.html +2 -2
  154. package/docs/interfaces/ActionsExtendedInfo.html +2 -2
  155. package/docs/interfaces/ActionsQuery.html +2 -2
  156. package/docs/interfaces/ActionsResponse.html +2 -2
  157. package/docs/interfaces/AggregateMetrics.html +2 -2
  158. package/docs/interfaces/BlockQuery.html +2 -2
  159. package/docs/interfaces/BlockResponse.html +2 -2
  160. package/docs/interfaces/BlockSummary.html +2 -2
  161. package/docs/interfaces/BlockSummaryResponse.html +2 -2
  162. package/docs/interfaces/DeltaEvent.html +2 -2
  163. package/docs/interfaces/ERC20TokenInfo.html +2 -2
  164. package/docs/interfaces/Info.html +2 -2
  165. package/docs/interfaces/Market.html +2 -2
  166. package/docs/interfaces/MarketStats.html +2 -2
  167. package/docs/interfaces/MarketsStatsResponse.html +2 -2
  168. package/docs/interfaces/NordConfig.html +2 -2
  169. package/docs/interfaces/Order.html +2 -2
  170. package/docs/interfaces/OrderInfo.html +2 -2
  171. package/docs/interfaces/PerpMarketStats.html +2 -2
  172. package/docs/interfaces/RollmanActionExtendedInfo.html +2 -2
  173. package/docs/interfaces/RollmanActionInfo.html +2 -2
  174. package/docs/interfaces/RollmanActionResponse.html +2 -2
  175. package/docs/interfaces/RollmanActionsResponse.html +2 -2
  176. package/docs/interfaces/RollmanBlockResponse.html +2 -2
  177. package/docs/interfaces/SubscriberConfig.html +2 -2
  178. package/docs/interfaces/Token.html +2 -2
  179. package/docs/interfaces/Trade.html +2 -2
  180. package/docs/interfaces/Trades.html +2 -2
  181. package/docs/modules.html +0 -7
  182. package/docs/types/BigIntValue.html +1 -1
  183. package/docs/variables/DEBUG_KEYS.html +1 -1
  184. package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
  185. package/docs/variables/DEV_CONTRACT_ADDRESS.html +1 -1
  186. package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
  187. package/docs/variables/DEV_URL.html +1 -1
  188. package/docs/variables/ERC20_ABI.html +1 -1
  189. package/docs/variables/EVM_DEV_URL.html +1 -1
  190. package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +1 -1
  191. package/docs/variables/MAX_BUFFER_LEN.html +1 -1
  192. package/docs/variables/NORD_GETTERS_FACET_ABI.html +1 -1
  193. package/docs/variables/NORD_RAMP_FACET_ABI.html +1 -1
  194. package/docs/variables/SESSION_TTL.html +1 -1
  195. package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
  196. package/docs/variables/ZERO_DECIMAL.html +1 -1
  197. package/package.json +10 -12
  198. package/src/bridge/client.ts +487 -0
  199. package/src/bridge/const.ts +53 -0
  200. package/src/bridge/index.ts +7 -0
  201. package/src/bridge/types.ts +127 -0
  202. package/src/bridge/utils.ts +140 -0
  203. package/src/const.ts +20 -25
  204. package/src/gen/common.ts +27 -10
  205. package/src/gen/nord.ts +1044 -483
  206. package/src/idl/bridge.ts +702 -0
  207. package/src/index.ts +24 -5
  208. package/src/nord/{actions.ts → api/actions.ts} +33 -37
  209. package/src/nord/api/core.ts +130 -0
  210. package/src/nord/api/market.ts +125 -0
  211. package/src/nord/api/metrics.ts +154 -0
  212. package/src/nord/api/queries.ts +236 -0
  213. package/src/nord/client/Nord.ts +652 -0
  214. package/src/nord/client/NordUser.ts +1105 -0
  215. package/src/nord/index.ts +16 -2
  216. package/src/nord/models/Subscriber.ts +57 -0
  217. package/src/nord/utils/NordError.ts +72 -0
  218. package/src/types.ts +170 -99
  219. package/src/utils.ts +40 -19
  220. package/src/websocket/NordWebSocketClient.ts +432 -0
  221. package/src/websocket/events.ts +31 -0
  222. package/src/websocket/index.ts +2 -0
  223. package/tests/utils.spec.ts +24 -24
  224. package/docs/classes/Subscriber.html +0 -6
  225. package/docs/functions/createWebSocketSubscription.html +0 -12
  226. package/docs/interfaces/OrderbookOrder.html +0 -6
  227. package/docs/interfaces/OrderbookResponse.html +0 -10
  228. package/docs/interfaces/TradeInfo.html +0 -20
  229. package/docs/interfaces/TradesQueryParams.html +0 -10
  230. package/docs/interfaces/TradesResponse.html +0 -12
  231. package/src/abis/ERC20_ABI.ts +0 -310
  232. package/src/abis/NORD_GETTERS_FACET_ABI.ts +0 -192
  233. package/src/abis/NORD_RAMP_FACET_ABI.ts +0 -141
  234. package/src/abis/index.ts +0 -3
  235. package/src/nord/Nord.ts +0 -504
  236. package/src/nord/NordImpl.ts +0 -8
  237. package/src/nord/NordUser.ts +0 -469
@@ -0,0 +1,139 @@
1
+ import * as anchor from '@coral-xyz/anchor';
2
+ import { Connection, PublicKey, Keypair } from '@solana/web3.js';
3
+ import { BlockFacts, DepositSplParams, PdaSeedType, SolanaBridgeConfig, WithdrawalParams } from './types';
4
+ /**
5
+ * Solana Bridge Client for interacting with the bridge program
6
+ */
7
+ export declare class SolanaBridgeClient {
8
+ /** Anchor program instance */
9
+ program: any;
10
+ /** Solana connection */
11
+ connection: Connection;
12
+ /** Program ID */
13
+ programId: PublicKey;
14
+ /** Configuration */
15
+ config: SolanaBridgeConfig;
16
+ /**
17
+ * Create a new Solana Bridge Client
18
+ *
19
+ * @param config Bridge configuration
20
+ * @param wallet Anchor wallet for signing transactions
21
+ */
22
+ constructor(config: SolanaBridgeConfig, wallet: anchor.Wallet);
23
+ /**
24
+ * Derive a PDA (Program Derived Address) for the given seeds
25
+ *
26
+ * @param type PDA seed type
27
+ * @param seeds Additional seeds
28
+ * @returns [PDA, bump]
29
+ */
30
+ findPda(type: PdaSeedType, ...seeds: (Buffer | PublicKey | string | number)[]): Promise<[PublicKey, number]>;
31
+ /**
32
+ * Find the contract storage PDA
33
+ *
34
+ * @returns [PDA, bump]
35
+ */
36
+ findContractStoragePda(): Promise<[PublicKey, number]>;
37
+ /**
38
+ * Find the asset whitelisted PDA for a token mint
39
+ *
40
+ * @param mint Token mint address
41
+ * @returns [PDA, bump]
42
+ */
43
+ findAssetWhitelistedPda(mint: PublicKey): Promise<[PublicKey, number]>;
44
+ /**
45
+ * Find the deposit storage PDA for a deposit index
46
+ *
47
+ * @param depositIndex Deposit index
48
+ * @returns [PDA, bump]
49
+ */
50
+ findDepositStoragePda(depositIndex: number): Promise<[PublicKey, number]>;
51
+ /**
52
+ * Find the block storage PDA for a block ID
53
+ *
54
+ * @param blockId Block ID
55
+ * @returns [PDA, bump]
56
+ */
57
+ findBlockStoragePda(blockId: number): Promise<[PublicKey, number]>;
58
+ /**
59
+ * Find the withdrawal nullifier PDA
60
+ *
61
+ * @param blockId Block ID
62
+ * @param leafIndex Leaf index
63
+ * @returns [PDA, bump]
64
+ */
65
+ findWithdrawalNullifierPda(blockId: number, leafIndex: number): Promise<[PublicKey, number]>;
66
+ /**
67
+ * Find the authority PDA
68
+ *
69
+ * @returns [PDA, bump]
70
+ */
71
+ findAuthorityPda(): Promise<[PublicKey, number]>;
72
+ /**
73
+ * Deposit SPL tokens to the bridge
74
+ *
75
+ * @param params Deposit parameters
76
+ * @param signer Signer keypair
77
+ * @returns Transaction signature
78
+ */
79
+ depositSpl(params: DepositSplParams, signer: Keypair): Promise<string>;
80
+ /**
81
+ * Withdraw tokens from the bridge
82
+ *
83
+ * @param params Withdrawal parameters
84
+ * @param signer Signer keypair
85
+ * @returns Transaction signature
86
+ */
87
+ withdraw(params: WithdrawalParams, signer: Keypair): Promise<string>;
88
+ /**
89
+ * Whitelist an asset (token) for use with the bridge
90
+ *
91
+ * @param mint Token mint address
92
+ * @param signer Operator keypair
93
+ * @returns Transaction signature
94
+ */
95
+ whitelistAsset(mint: PublicKey, signer: Keypair): Promise<string>;
96
+ /**
97
+ * Propose a new block
98
+ *
99
+ * @param facts Block facts
100
+ * @param signer Operator keypair
101
+ * @returns Transaction signature
102
+ */
103
+ proposeBlock(facts: BlockFacts, signer: Keypair): Promise<string>;
104
+ /**
105
+ * Finalize a block
106
+ *
107
+ * @param blockId Block ID
108
+ * @param stateUpdateId State update ID
109
+ * @param signer Payer keypair
110
+ * @returns Transaction signature
111
+ */
112
+ finalizeBlock(blockId: number, stateUpdateId: number, signer: Keypair): Promise<string>;
113
+ /**
114
+ * Finalize a DA fact
115
+ *
116
+ * @param fact DA fact (32-byte array)
117
+ * @param signer Payer keypair
118
+ * @returns Transaction signature
119
+ */
120
+ finalizeDaFact(fact: Buffer, signer: Keypair): Promise<string>;
121
+ /**
122
+ * Initialize the bridge contract
123
+ *
124
+ * @param operator Operator public key
125
+ * @param initialAppStateCommitment Initial app state commitment (32-byte array)
126
+ * @param signer Payer keypair
127
+ * @returns Transaction signature
128
+ */
129
+ initialize(operator: PublicKey, initialAppStateCommitment: Buffer, signer: Keypair): Promise<string>;
130
+ /**
131
+ * Create an associated token account if it doesn't exist
132
+ *
133
+ * @param mint Token mint
134
+ * @param owner Account owner
135
+ * @param payer Transaction payer
136
+ * @returns Associated token account address
137
+ */
138
+ createTokenAccountIfNeeded(mint: PublicKey, owner: PublicKey, payer: Keypair): Promise<PublicKey>;
139
+ }
@@ -0,0 +1,360 @@
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;
@@ -0,0 +1,23 @@
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
+ };
@@ -0,0 +1,47 @@
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
+ };
@@ -0,0 +1,5 @@
1
+ export * from './client';
2
+ export * from './types';
3
+ export * from './utils';
4
+ import { BRIDGE_IDL } from '../idl/bridge';
5
+ export { BRIDGE_IDL };
@@ -0,0 +1,23 @@
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; } });