@n1xyz/nord-ts 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions.js +39 -82
- package/dist/bundle.js +79181 -0
- package/dist/client/Nord.d.ts +13 -2
- package/dist/client/Nord.js +68 -78
- package/dist/client/NordAdmin.d.ts +2 -2
- package/dist/client/NordAdmin.js +57 -89
- package/dist/client/NordUser.js +118 -147
- package/dist/const.js +5 -8
- package/dist/error.js +7 -5
- package/dist/gen/nord_pb.js +88 -92
- package/dist/gen/openapi.d.ts +83 -6
- package/dist/gen/openapi.js +1 -2
- package/dist/index.js +10 -49
- package/dist/types.d.ts +3 -0
- package/dist/types.js +21 -60
- package/dist/utils.js +38 -86
- package/dist/websocket/NordWebSocketClient.js +12 -17
- package/dist/websocket/Subscriber.js +6 -7
- package/dist/websocket/events.js +1 -2
- package/dist/websocket/index.js +10 -15
- package/package.json +3 -4
- package/dist/api/client.d.ts +0 -14
- package/dist/api/client.js +0 -45
- package/dist/bridge/client.d.ts +0 -151
- package/dist/bridge/client.js +0 -434
- package/dist/bridge/const.d.ts +0 -23
- package/dist/bridge/const.js +0 -47
- package/dist/bridge/index.d.ts +0 -4
- package/dist/bridge/index.js +0 -23
- package/dist/bridge/types.d.ts +0 -120
- package/dist/bridge/types.js +0 -18
- package/dist/bridge/utils.d.ts +0 -64
- package/dist/bridge/utils.js +0 -131
- package/dist/gen/common.d.ts +0 -68
- package/dist/gen/common.js +0 -215
- package/dist/gen/nord.d.ts +0 -882
- package/dist/gen/nord.js +0 -6520
- package/dist/idl/bridge.d.ts +0 -569
- package/dist/idl/bridge.js +0 -8
- package/dist/idl/bridge.json +0 -1506
- package/dist/idl/index.d.ts +0 -607
- package/dist/idl/index.js +0 -8
- package/dist/nord/api/actions.d.ts +0 -126
- package/dist/nord/api/actions.js +0 -397
- package/dist/nord/api/core.d.ts +0 -16
- package/dist/nord/api/core.js +0 -81
- package/dist/nord/api/market.d.ts +0 -36
- package/dist/nord/api/market.js +0 -96
- package/dist/nord/api/metrics.d.ts +0 -67
- package/dist/nord/api/metrics.js +0 -229
- package/dist/nord/api/queries.d.ts +0 -46
- package/dist/nord/api/queries.js +0 -109
- package/dist/nord/api/triggers.d.ts +0 -7
- package/dist/nord/api/triggers.js +0 -38
- package/dist/nord/client/Nord.d.ts +0 -396
- package/dist/nord/client/Nord.js +0 -747
- package/dist/nord/client/NordAdmin.d.ts +0 -259
- package/dist/nord/client/NordAdmin.js +0 -395
- package/dist/nord/client/NordClient.d.ts +0 -33
- package/dist/nord/client/NordClient.js +0 -45
- package/dist/nord/client/NordUser.d.ts +0 -362
- package/dist/nord/client/NordUser.js +0 -781
- package/dist/nord/index.d.ts +0 -11
- package/dist/nord/index.js +0 -36
- package/dist/nord/models/Subscriber.d.ts +0 -37
- package/dist/nord/models/Subscriber.js +0 -25
- package/dist/nord/utils/NordError.d.ts +0 -35
- package/dist/nord/utils/NordError.js +0 -49
- package/src/actions.ts +0 -333
- package/src/client/Nord.ts +0 -934
- package/src/client/NordAdmin.ts +0 -484
- package/src/client/NordUser.ts +0 -1122
- package/src/const.ts +0 -34
- package/src/error.ts +0 -76
- package/src/gen/.gitkeep +0 -0
- package/src/gen/nord_pb.ts +0 -5053
- package/src/gen/openapi.ts +0 -2904
- package/src/index.ts +0 -11
- package/src/types.ts +0 -327
- package/src/utils.ts +0 -266
- package/src/websocket/NordWebSocketClient.ts +0 -316
- package/src/websocket/Subscriber.ts +0 -56
- package/src/websocket/events.ts +0 -31
- package/src/websocket/index.ts +0 -105
package/dist/bridge/client.js
DELETED
|
@@ -1,434 +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 spl_token_1 = require("@solana/spl-token");
|
|
40
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
41
|
-
const types_1 = require("./types");
|
|
42
|
-
const idl_1 = require("../idl");
|
|
43
|
-
/**
|
|
44
|
-
* Solana Bridge Client for interacting with the bridge program
|
|
45
|
-
*/
|
|
46
|
-
class SolanaBridgeClient {
|
|
47
|
-
/**
|
|
48
|
-
* Create a new Solana Bridge Client
|
|
49
|
-
*
|
|
50
|
-
* @param config Bridge configuration
|
|
51
|
-
* @param wallet Anchor wallet for signing transactions
|
|
52
|
-
*/
|
|
53
|
-
constructor(config, wallet) {
|
|
54
|
-
this.config = config;
|
|
55
|
-
this.connection = new web3_js_1.Connection(config.rpcUrl, {
|
|
56
|
-
commitment: config.commitment,
|
|
57
|
-
});
|
|
58
|
-
this.programId = new web3_js_1.PublicKey(config.programId);
|
|
59
|
-
// Create the provider
|
|
60
|
-
const provider = new anchor_1.AnchorProvider(this.connection, wallet, {
|
|
61
|
-
commitment: config.commitment,
|
|
62
|
-
skipPreflight: true, // Skip simulation
|
|
63
|
-
});
|
|
64
|
-
// Set the provider globally
|
|
65
|
-
anchor.setProvider(provider);
|
|
66
|
-
// Store the provider
|
|
67
|
-
this.provider = 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
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Derive a PDA (Program Derived Address) for the given seeds
|
|
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
|
-
*
|
|
80
|
-
* @param type PDA seed type
|
|
81
|
-
* @param seeds Additional seeds
|
|
82
|
-
* @returns [PDA, bump]
|
|
83
|
-
*/
|
|
84
|
-
async findPda(type, ...seeds) {
|
|
85
|
-
const seedBuffers = [
|
|
86
|
-
Buffer.from(type),
|
|
87
|
-
...seeds.map((seed) => {
|
|
88
|
-
if (seed instanceof web3_js_1.PublicKey) {
|
|
89
|
-
return seed.toBuffer();
|
|
90
|
-
}
|
|
91
|
-
else if (typeof seed === "string") {
|
|
92
|
-
return Buffer.from(seed);
|
|
93
|
-
}
|
|
94
|
-
else if (typeof seed === "number") {
|
|
95
|
-
// Convert number to little-endian byte array (8 bytes for u64)
|
|
96
|
-
const buffer = Buffer.alloc(8);
|
|
97
|
-
buffer.writeBigUInt64LE(BigInt(seed), 0);
|
|
98
|
-
return buffer;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
return seed.toBytes();
|
|
102
|
-
}
|
|
103
|
-
}),
|
|
104
|
-
];
|
|
105
|
-
return web3_js_1.PublicKey.findProgramAddressSync(seedBuffers, this.programId);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Find the asset config PDA for a token mint
|
|
109
|
-
*
|
|
110
|
-
* @param mint Token mint address
|
|
111
|
-
* @returns [PDA, bump]
|
|
112
|
-
*/
|
|
113
|
-
async findAssetConfigPda(mint) {
|
|
114
|
-
return this.findPda(types_1.PdaSeedType.AssetConfig, this.bridge, mint);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Find the deposit storage PDA for a deposit index
|
|
118
|
-
*
|
|
119
|
-
* @param depositIndex Deposit index
|
|
120
|
-
* @returns [PDA, bump]
|
|
121
|
-
*/
|
|
122
|
-
async findDepositStoragePda(depositIndex) {
|
|
123
|
-
return this.findPda(types_1.PdaSeedType.DepositStorage, this.bridge, depositIndex);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Find the block storage PDA for a block ID
|
|
127
|
-
*
|
|
128
|
-
* @param blockId Block ID
|
|
129
|
-
* @returns [PDA, bump]
|
|
130
|
-
*/
|
|
131
|
-
async findBlockStoragePda(blockId) {
|
|
132
|
-
return this.findPda(types_1.PdaSeedType.BlockStorage, this.bridge, blockId);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Find the withdrawal nullifier PDA
|
|
136
|
-
*
|
|
137
|
-
* @param blockId Block ID
|
|
138
|
-
* @param leafIndex Leaf index
|
|
139
|
-
* @returns [PDA, bump]
|
|
140
|
-
*/
|
|
141
|
-
async findWithdrawalNullifierPda(blockId, leafIndex) {
|
|
142
|
-
return this.findPda(types_1.PdaSeedType.WithdrawalNullifier, blockId, leafIndex);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Find the authority PDA
|
|
146
|
-
*
|
|
147
|
-
* @returns [PDA, bump]
|
|
148
|
-
*/
|
|
149
|
-
async findAuthorityPda() {
|
|
150
|
-
return this.findPda(types_1.PdaSeedType.Authority);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Helper method to sign and send a transaction
|
|
154
|
-
*
|
|
155
|
-
* @param transaction Transaction to sign and send
|
|
156
|
-
* @param signers Additional signers (beyond the provider's wallet)
|
|
157
|
-
* @returns Transaction signature
|
|
158
|
-
*/
|
|
159
|
-
async signAndSendTransaction(transaction, signers = []) {
|
|
160
|
-
// Use the provider to sign and send the transaction with skipPreflight
|
|
161
|
-
const txSignature = await this.provider.sendAndConfirm(transaction, signers, {
|
|
162
|
-
skipPreflight: true,
|
|
163
|
-
});
|
|
164
|
-
return txSignature;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Deposit SPL tokens to the bridge
|
|
168
|
-
*
|
|
169
|
-
* @param params Deposit parameters
|
|
170
|
-
* @param signer Signer keypair
|
|
171
|
-
* @returns Transaction signature
|
|
172
|
-
*/
|
|
173
|
-
async depositSpl(params) {
|
|
174
|
-
const [assetConfig] = await this.findAssetConfigPda(params.mint);
|
|
175
|
-
// Get the last deposit index from contract storage
|
|
176
|
-
const bridgeAccount = await this.program.account.bridge.fetch(this.bridge);
|
|
177
|
-
const lastDepositIndex = bridgeAccount.lastDepositIndex.toNumber();
|
|
178
|
-
// Find the deposit PDA for this deposit
|
|
179
|
-
const [deposit] = await this.findDepositStoragePda(lastDepositIndex + 1);
|
|
180
|
-
// Find the previous deposit PDA if it exists
|
|
181
|
-
let prevDeposit = undefined;
|
|
182
|
-
if (lastDepositIndex > 0) {
|
|
183
|
-
const [prevDepositPda] = await this.findDepositStoragePda(lastDepositIndex);
|
|
184
|
-
prevDeposit = prevDepositPda;
|
|
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
|
-
// Get the token program ID from the mint account
|
|
189
|
-
const mintAccount = await this.connection.getAccountInfo(params.mint);
|
|
190
|
-
if (!mintAccount) {
|
|
191
|
-
throw new Error("Mint account not found");
|
|
192
|
-
}
|
|
193
|
-
const tokenProgramId = mintAccount.owner;
|
|
194
|
-
// Validate that the mint is owned by a supported SPL token program
|
|
195
|
-
if (!tokenProgramId.equals(spl_token_1.TOKEN_PROGRAM_ID) &&
|
|
196
|
-
!tokenProgramId.equals(spl_token_1.TOKEN_2022_PROGRAM_ID)) {
|
|
197
|
-
throw new Error("Mint Account is not owned by a supported SPL token program");
|
|
198
|
-
}
|
|
199
|
-
// Get the token program ID from the fromAccount to ensure we're using the same program
|
|
200
|
-
const fromAccountInfo = await this.connection.getAccountInfo(params.fromAccount);
|
|
201
|
-
if (!fromAccountInfo) {
|
|
202
|
-
throw new Error(`From account not found for address: ${params.fromAccount.toBase58()}. ` +
|
|
203
|
-
"This may indicate an invalid, uninitialized, or missing token account.");
|
|
204
|
-
}
|
|
205
|
-
if (!fromAccountInfo.owner.equals(tokenProgramId)) {
|
|
206
|
-
throw new Error(`From account owner (${fromAccountInfo.owner.toBase58()}) does not match mint owner (${tokenProgramId.toBase58()}). ` +
|
|
207
|
-
"This usually means the fromAccount is not a valid token account for the given mint.");
|
|
208
|
-
}
|
|
209
|
-
const toAccount = await (0, spl_token_1.getAssociatedTokenAddress)(params.mint, tokenAuthority, true, tokenProgramId);
|
|
210
|
-
// Build the transaction
|
|
211
|
-
const accounts = {
|
|
212
|
-
payer: this.provider.wallet.publicKey,
|
|
213
|
-
deposit,
|
|
214
|
-
assetConfig,
|
|
215
|
-
bridge: this.bridge,
|
|
216
|
-
program: this.programId,
|
|
217
|
-
fromAccount: params.fromAccount,
|
|
218
|
-
toAccount: toAccount,
|
|
219
|
-
tokenProgram: tokenProgramId,
|
|
220
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
221
|
-
crumbAuthority,
|
|
222
|
-
tokenAuthority,
|
|
223
|
-
};
|
|
224
|
-
const allAccounts = { ...accounts, prevDeposit: prevDeposit };
|
|
225
|
-
// Create the transaction
|
|
226
|
-
const tx = await (await this.program.methods
|
|
227
|
-
.deposit(this.provider.wallet.publicKey, params.amount)
|
|
228
|
-
.accounts(allAccounts)).transaction();
|
|
229
|
-
// Check if toAccount is initialized and add preinstruction if needed
|
|
230
|
-
try {
|
|
231
|
-
await this.connection.getTokenAccountBalance(toAccount);
|
|
232
|
-
}
|
|
233
|
-
catch {
|
|
234
|
-
// Account doesn't exist, add instruction to create it
|
|
235
|
-
// Get the authority PDA which is the owner of the toAccount
|
|
236
|
-
const [authority] = await this.findAuthorityPda();
|
|
237
|
-
const createTokenAccountIx = (0, spl_token_1.createAssociatedTokenAccountInstruction)(this.provider.wallet.publicKey, // payer
|
|
238
|
-
toAccount, // associated token account address
|
|
239
|
-
authority, // owner of the token account
|
|
240
|
-
params.mint, // token mint
|
|
241
|
-
tokenProgramId);
|
|
242
|
-
// Add the instruction to the beginning of the transaction
|
|
243
|
-
tx.instructions.unshift(createTokenAccountIx);
|
|
244
|
-
}
|
|
245
|
-
// Sign and send the transaction using our helper method
|
|
246
|
-
return await this.signAndSendTransaction(tx);
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Withdraw tokens from the bridge
|
|
250
|
-
*
|
|
251
|
-
* @param params Withdrawal parameters
|
|
252
|
-
* @param signer Signer keypair
|
|
253
|
-
* @returns Transaction signature
|
|
254
|
-
*/
|
|
255
|
-
async withdraw(params, signer) {
|
|
256
|
-
const [stateUpdate] = await this.findBlockStoragePda(params.claim.blockId.toNumber());
|
|
257
|
-
const [withdrawalNullifier] = await this.findWithdrawalNullifierPda(params.claim.blockId.toNumber(), params.claim.leafIndex.toNumber());
|
|
258
|
-
const [authority] = await this.findAuthorityPda();
|
|
259
|
-
// Get the token program ID from the fromAccount
|
|
260
|
-
const fromAccountInfo = await this.connection.getAccountInfo(params.fromAccount);
|
|
261
|
-
if (!fromAccountInfo) {
|
|
262
|
-
throw new Error(`From account not found for address: ${params.fromAccount.toBase58()}. ` +
|
|
263
|
-
"This may indicate an invalid, uninitialized, or missing token account.");
|
|
264
|
-
}
|
|
265
|
-
const tokenProgramId = fromAccountInfo.owner;
|
|
266
|
-
// Validate that the account is owned by a supported SPL token program
|
|
267
|
-
if (!tokenProgramId.equals(spl_token_1.TOKEN_PROGRAM_ID) &&
|
|
268
|
-
!tokenProgramId.equals(spl_token_1.TOKEN_2022_PROGRAM_ID)) {
|
|
269
|
-
throw new Error("From Account is not owned by a supported SPL token program");
|
|
270
|
-
}
|
|
271
|
-
// Build the transaction
|
|
272
|
-
const tx = await this.program.methods
|
|
273
|
-
.withdraw(params.claim)
|
|
274
|
-
.accounts({
|
|
275
|
-
payer: signer.publicKey,
|
|
276
|
-
stateUpdate,
|
|
277
|
-
withdrawalNullifier,
|
|
278
|
-
fromAccount: params.fromAccount,
|
|
279
|
-
toAccount: params.toAccount,
|
|
280
|
-
authority,
|
|
281
|
-
tokenProgram: tokenProgramId,
|
|
282
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
283
|
-
})
|
|
284
|
-
.transaction();
|
|
285
|
-
// Sign and send the transaction using our helper method
|
|
286
|
-
return await this.signAndSendTransaction(tx, [signer]);
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Whitelist an asset (token) for use with the bridge
|
|
290
|
-
*
|
|
291
|
-
* @param mint Token mint address
|
|
292
|
-
* @param signer Operator keypair
|
|
293
|
-
* @returns Transaction signature
|
|
294
|
-
*/
|
|
295
|
-
async whitelistAsset(mint, signer) {
|
|
296
|
-
const [assetWhitelisted] = await this.findAssetConfigPda(mint);
|
|
297
|
-
// Build the transaction
|
|
298
|
-
const tx = await this.program.methods
|
|
299
|
-
.whitelistAsset(mint)
|
|
300
|
-
.accounts({
|
|
301
|
-
operator: signer.publicKey,
|
|
302
|
-
bridge: this.bridge,
|
|
303
|
-
assetWhitelisted,
|
|
304
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
305
|
-
})
|
|
306
|
-
.transaction();
|
|
307
|
-
// Sign and send the transaction using our helper method
|
|
308
|
-
return await this.signAndSendTransaction(tx, [signer]);
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Propose a new block
|
|
312
|
-
*
|
|
313
|
-
* @param facts Block facts
|
|
314
|
-
* @param signer Operator keypair
|
|
315
|
-
* @returns Transaction signature
|
|
316
|
-
*/
|
|
317
|
-
async proposeBlock(facts, signer) {
|
|
318
|
-
// Get the last block ID from contract storage
|
|
319
|
-
const bridgeAccount = await this.program.account.bridge.fetch(this.bridge);
|
|
320
|
-
const [block] = await this.findBlockStoragePda(bridgeAccount.lastBlockId.toNumber() + 1);
|
|
321
|
-
// Find the last deposit PDA
|
|
322
|
-
const [lastDeposit] = await this.findDepositStoragePda(facts.nextStateFacts.lastDepositIndex.toNumber());
|
|
323
|
-
// Find the DA fact state
|
|
324
|
-
const daFactState = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(types_1.PdaSeedType.DaFactStorage), facts.daCommitment], this.programId)[0];
|
|
325
|
-
// Build the transaction
|
|
326
|
-
const tx = await this.program.methods
|
|
327
|
-
.proposeBlock(facts)
|
|
328
|
-
.accounts({
|
|
329
|
-
operator: signer.publicKey,
|
|
330
|
-
block,
|
|
331
|
-
lastDeposit,
|
|
332
|
-
daFactState,
|
|
333
|
-
bridge: this.bridge,
|
|
334
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
335
|
-
})
|
|
336
|
-
.transaction();
|
|
337
|
-
// Sign and send the transaction using our helper method
|
|
338
|
-
return await this.signAndSendTransaction(tx, [signer]);
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Finalize a block
|
|
342
|
-
*
|
|
343
|
-
* @param blockId Block ID
|
|
344
|
-
* @param stateUpdateId State update ID
|
|
345
|
-
* @param signer Payer keypair
|
|
346
|
-
* @returns Transaction signature
|
|
347
|
-
*/
|
|
348
|
-
async finalizeBlock(blockId, stateUpdateId, signer) {
|
|
349
|
-
const [block] = await this.findBlockStoragePda(blockId);
|
|
350
|
-
// Build the transaction
|
|
351
|
-
const tx = await this.program.methods
|
|
352
|
-
.finalizeBlock(new anchor.BN(stateUpdateId))
|
|
353
|
-
.accounts({
|
|
354
|
-
payer: signer.publicKey,
|
|
355
|
-
block,
|
|
356
|
-
bridge: this.bridge,
|
|
357
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
358
|
-
})
|
|
359
|
-
.transaction();
|
|
360
|
-
// Sign and send the transaction using our helper method
|
|
361
|
-
return await this.signAndSendTransaction(tx, [signer]);
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Finalize a DA fact
|
|
365
|
-
*
|
|
366
|
-
* @param fact DA fact (32-byte array)
|
|
367
|
-
* @param signer Payer keypair
|
|
368
|
-
* @returns Transaction signature
|
|
369
|
-
*/
|
|
370
|
-
async finalizeDaFact(fact, signer) {
|
|
371
|
-
const factStateStorage = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(types_1.PdaSeedType.DaFactStorage), fact], this.programId)[0];
|
|
372
|
-
// Build the transaction
|
|
373
|
-
const tx = await this.program.methods
|
|
374
|
-
.finalizeDaFact(Array.from(fact))
|
|
375
|
-
.accounts({
|
|
376
|
-
payer: signer.publicKey,
|
|
377
|
-
factStateStorage,
|
|
378
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
379
|
-
})
|
|
380
|
-
.transaction();
|
|
381
|
-
// Sign and send the transaction using our helper method
|
|
382
|
-
return await this.signAndSendTransaction(tx, [signer]);
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Initialize the bridge contract
|
|
386
|
-
*
|
|
387
|
-
* @param operator Operator public key
|
|
388
|
-
* @param initialAppStateCommitment Initial app state commitment (32-byte array)
|
|
389
|
-
* @param signer Payer keypair
|
|
390
|
-
* @returns Transaction signature
|
|
391
|
-
*/
|
|
392
|
-
async initialize(operator, initialAppStateCommitment, signer) {
|
|
393
|
-
// Build the transaction
|
|
394
|
-
const tx = await this.program.methods
|
|
395
|
-
.initialize(operator, Array.from(initialAppStateCommitment))
|
|
396
|
-
.accounts({
|
|
397
|
-
payer: signer.publicKey,
|
|
398
|
-
program: this.programId,
|
|
399
|
-
bridge: this.bridge,
|
|
400
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
401
|
-
})
|
|
402
|
-
.transaction();
|
|
403
|
-
// Sign and send the transaction using our helper method
|
|
404
|
-
return await this.signAndSendTransaction(tx, [signer]);
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Create an associated token account if it doesn't exist
|
|
408
|
-
*
|
|
409
|
-
* @param mint Token mint
|
|
410
|
-
* @param owner Account owner
|
|
411
|
-
* @param payer Transaction payer
|
|
412
|
-
* @returns Associated token account address
|
|
413
|
-
*/
|
|
414
|
-
async createTokenAccountIfNeeded(mint, owner, payer) {
|
|
415
|
-
// Get the token program ID from the mint account
|
|
416
|
-
const mintAccount = await this.connection.getAccountInfo(mint);
|
|
417
|
-
if (!mintAccount) {
|
|
418
|
-
throw new Error("Mint account not found");
|
|
419
|
-
}
|
|
420
|
-
const tokenProgramId = mintAccount.owner;
|
|
421
|
-
const associatedTokenAddress = await (0, spl_token_1.getAssociatedTokenAddress)(mint, owner, false, tokenProgramId);
|
|
422
|
-
try {
|
|
423
|
-
await this.connection.getTokenAccountBalance(associatedTokenAddress);
|
|
424
|
-
}
|
|
425
|
-
catch {
|
|
426
|
-
// Account doesn't exist, create it
|
|
427
|
-
const transaction = new web3_js_1.Transaction().add((0, spl_token_1.createAssociatedTokenAccountInstruction)(payer.publicKey, associatedTokenAddress, owner, mint, tokenProgramId));
|
|
428
|
-
// Sign and send the transaction using our helper method
|
|
429
|
-
await this.signAndSendTransaction(transaction, [payer]);
|
|
430
|
-
}
|
|
431
|
-
return associatedTokenAddress;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
exports.SolanaBridgeClient = SolanaBridgeClient;
|
package/dist/bridge/const.d.ts
DELETED
|
@@ -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
|
-
};
|
package/dist/bridge/const.js
DELETED
|
@@ -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
|
-
};
|
package/dist/bridge/index.d.ts
DELETED
package/dist/bridge/index.js
DELETED
|
@@ -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
|
-
var idl_1 = require("../idl");
|
|
23
|
-
Object.defineProperty(exports, "BRIDGE_IDL", { enumerable: true, get: function () { return idl_1.BRIDGE_IDL; } });
|
package/dist/bridge/types.d.ts
DELETED
|
@@ -1,120 +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
|
-
/** Bridge Verifying Key */
|
|
12
|
-
bridgeVk: string;
|
|
13
|
-
/** Commitment level for transactions */
|
|
14
|
-
commitment: "processed" | "confirmed" | "finalized";
|
|
15
|
-
/** Token information for supported SPL tokens */
|
|
16
|
-
tokenInfos: SPLTokenInfo[];
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Information about an SPL token
|
|
20
|
-
*/
|
|
21
|
-
export interface SPLTokenInfo {
|
|
22
|
-
/** Token mint address */
|
|
23
|
-
mint: string;
|
|
24
|
-
/** Token decimals */
|
|
25
|
-
precision: number;
|
|
26
|
-
/** Token ID in the Layer-N system */
|
|
27
|
-
tokenId: number;
|
|
28
|
-
/** Token name */
|
|
29
|
-
name: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Parameters for depositing SPL tokens
|
|
33
|
-
*/
|
|
34
|
-
export interface DepositSplParams {
|
|
35
|
-
/** Amount to deposit (in token's smallest unit) */
|
|
36
|
-
amount: BN;
|
|
37
|
-
/** Mint address of the token to deposit */
|
|
38
|
-
mint: PublicKey;
|
|
39
|
-
/** User's token account to deposit from */
|
|
40
|
-
fromAccount: 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
|
-
Bridge = "bridge",
|
|
112
|
-
TokenAuthority = "token_authority",
|
|
113
|
-
CrumbAuthority = "crumb_authority",
|
|
114
|
-
AssetConfig = "asset_config",
|
|
115
|
-
DepositStorage = "deposit_storage",
|
|
116
|
-
BlockStorage = "block_storage",
|
|
117
|
-
WithdrawalNullifier = "withdrawal_nullifier",
|
|
118
|
-
Authority = "authority",
|
|
119
|
-
DaFactStorage = "da_fact_storage"
|
|
120
|
-
}
|
package/dist/bridge/types.js
DELETED
|
@@ -1,18 +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["Bridge"] = "bridge";
|
|
10
|
-
PdaSeedType["TokenAuthority"] = "token_authority";
|
|
11
|
-
PdaSeedType["CrumbAuthority"] = "crumb_authority";
|
|
12
|
-
PdaSeedType["AssetConfig"] = "asset_config";
|
|
13
|
-
PdaSeedType["DepositStorage"] = "deposit_storage";
|
|
14
|
-
PdaSeedType["BlockStorage"] = "block_storage";
|
|
15
|
-
PdaSeedType["WithdrawalNullifier"] = "withdrawal_nullifier";
|
|
16
|
-
PdaSeedType["Authority"] = "authority";
|
|
17
|
-
PdaSeedType["DaFactStorage"] = "da_fact_storage";
|
|
18
|
-
})(PdaSeedType || (exports.PdaSeedType = PdaSeedType = {}));
|