@atomiqlabs/chain-solana 10.0.0-dev.3 → 10.0.0-dev.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.
- package/dist/solana/btcrelay/SolanaBtcRelay.js +1 -1
- package/dist/solana/chain/modules/SolanaTransactions.js +13 -23
- package/dist/solana/events/SolanaChainEvents.js +1 -1
- package/dist/solana/swaps/SolanaSwapProgram.js +7 -0
- package/package.json +2 -2
- package/src/solana/btcrelay/SolanaBtcRelay.ts +2 -1
- package/src/solana/chain/modules/SolanaTransactions.ts +13 -19
- package/src/solana/events/SolanaChainEvents.ts +1 -1
- package/src/solana/swaps/SolanaSwapProgram.ts +6 -1
|
@@ -44,7 +44,7 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
44
44
|
headerTopic: this.BtcRelayHeader(serializedBlock.hash),
|
|
45
45
|
systemProgram: web3_js_1.SystemProgram.programId
|
|
46
46
|
})
|
|
47
|
-
.instruction());
|
|
47
|
+
.instruction(), 100000);
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Creates verify action to be used with the swap program, specifies the action to be firstIxBeforeComputeBudget,
|
|
@@ -209,9 +209,10 @@ class SolanaTransactions extends SolanaModule_1.SolanaModule {
|
|
|
209
209
|
};
|
|
210
210
|
this.logger.debug("sendAndConfirm(): sending transactions, count: " + _txs.length +
|
|
211
211
|
" waitForConfirmation: " + waitForConfirmation + " parallel: " + parallel);
|
|
212
|
+
const BATCH_SIZE = 50;
|
|
212
213
|
const signatures = [];
|
|
213
|
-
for (let e = 0; e < _txs.length; e +=
|
|
214
|
-
const txs = _txs.slice(e, e +
|
|
214
|
+
for (let e = 0; e < _txs.length; e += BATCH_SIZE) {
|
|
215
|
+
const txs = _txs.slice(e, e + BATCH_SIZE);
|
|
215
216
|
await this.prepareTransactions(signer, txs);
|
|
216
217
|
const signedTxs = await signer.wallet.signAllTransactions(txs.map(e => e.tx));
|
|
217
218
|
signedTxs.forEach((tx, index) => {
|
|
@@ -220,27 +221,16 @@ class SolanaTransactions extends SolanaModule_1.SolanaModule {
|
|
|
220
221
|
solTx.tx = tx;
|
|
221
222
|
});
|
|
222
223
|
this.logger.debug("sendAndConfirm(): sending transaction batch (" + e + ".." + (e + 50) + "), count: " + txs.length);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
for (let i = 0; i < txs.length; i++) {
|
|
236
|
-
const solTx = txs[i];
|
|
237
|
-
const signature = await this.sendSignedTransaction(solTx, options, onBeforePublish);
|
|
238
|
-
const confirmPromise = this.confirmTransaction(solTx, abortSignal, "confirmed");
|
|
239
|
-
//Don't await the last promise when !waitForConfirmation
|
|
240
|
-
if (i < txs.length - 1 || e + 50 < _txs.length || waitForConfirmation)
|
|
241
|
-
await confirmPromise;
|
|
242
|
-
signatures.push(signature);
|
|
243
|
-
}
|
|
224
|
+
//For solana we are forced to send txs one-by-one even with parallel, as we cannot determine their order upfront,
|
|
225
|
+
// however e.g. Jito could possibly handle sending a single package of up to 5 txns in order.
|
|
226
|
+
for (let i = 0; i < txs.length; i++) {
|
|
227
|
+
const solTx = txs[i];
|
|
228
|
+
const signature = await this.sendSignedTransaction(solTx, options, onBeforePublish);
|
|
229
|
+
const confirmPromise = this.confirmTransaction(solTx, abortSignal, "confirmed");
|
|
230
|
+
//Don't await the last promise when !waitForConfirmation
|
|
231
|
+
if (i < txs.length - 1 || e + 50 < _txs.length || waitForConfirmation)
|
|
232
|
+
await confirmPromise;
|
|
233
|
+
signatures.push(signature);
|
|
244
234
|
}
|
|
245
235
|
}
|
|
246
236
|
this.logger.info("sendAndConfirm(): sent transactions, count: " + _txs.length +
|
|
@@ -91,7 +91,7 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
91
91
|
try {
|
|
92
92
|
const transaction = await this.connection.getParsedTransaction(signature, {
|
|
93
93
|
commitment: "confirmed",
|
|
94
|
-
maxSupportedTransactionVersion:
|
|
94
|
+
maxSupportedTransactionVersion: 1
|
|
95
95
|
});
|
|
96
96
|
if (transaction == null)
|
|
97
97
|
return false;
|
|
@@ -196,11 +196,15 @@ class SolanaSwapProgram extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
196
196
|
//Check if paid or what
|
|
197
197
|
const status = await this.Events.findInEvents(escrowStateKey, async (event, info) => {
|
|
198
198
|
if (event.name === "ClaimEvent") {
|
|
199
|
+
const paymentHash = buffer_1.Buffer.from(event.data.hash).toString("hex");
|
|
200
|
+
if (paymentHash !== data.paymentHash)
|
|
201
|
+
return null;
|
|
199
202
|
if (!event.data.sequence.eq(data.sequence))
|
|
200
203
|
return null;
|
|
201
204
|
return {
|
|
202
205
|
type: base_1.SwapCommitStateType.PAID,
|
|
203
206
|
getClaimTxId: () => Promise.resolve(info.signature),
|
|
207
|
+
getClaimResult: () => Promise.resolve(buffer_1.Buffer.from(event.data.secret).toString("hex")),
|
|
204
208
|
getTxBlock: async () => {
|
|
205
209
|
return {
|
|
206
210
|
blockHeight: (await this.Chain.Blocks.getParsedBlock(info.slot)).blockHeight,
|
|
@@ -210,6 +214,9 @@ class SolanaSwapProgram extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
210
214
|
};
|
|
211
215
|
}
|
|
212
216
|
if (event.name === "RefundEvent") {
|
|
217
|
+
const paymentHash = buffer_1.Buffer.from(event.data.hash).toString("hex");
|
|
218
|
+
if (paymentHash !== data.paymentHash)
|
|
219
|
+
return null;
|
|
213
220
|
if (!event.data.sequence.eq(data.sequence))
|
|
214
221
|
return null;
|
|
215
222
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/chain-solana",
|
|
3
|
-
"version": "10.0.0-dev.
|
|
3
|
+
"version": "10.0.0-dev.5",
|
|
4
4
|
"description": "Solana specific base implementation",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"author": "adambor",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@atomiqlabs/base": "^10.0.0-dev.
|
|
25
|
+
"@atomiqlabs/base": "^10.0.0-dev.9",
|
|
26
26
|
"@noble/hashes": "^1.7.1",
|
|
27
27
|
"bn.js": "5.2.1",
|
|
28
28
|
"bs58": "4.0.1",
|
|
@@ -239,9 +239,11 @@ export class SolanaTransactions extends SolanaModule {
|
|
|
239
239
|
this.logger.debug("sendAndConfirm(): sending transactions, count: "+_txs.length+
|
|
240
240
|
" waitForConfirmation: "+waitForConfirmation+" parallel: "+parallel);
|
|
241
241
|
|
|
242
|
+
const BATCH_SIZE = 50;
|
|
243
|
+
|
|
242
244
|
const signatures: string[] = [];
|
|
243
|
-
for(let e=0;e<_txs.length;e+=
|
|
244
|
-
const txs = _txs.slice(e, e+
|
|
245
|
+
for(let e=0;e<_txs.length;e+=BATCH_SIZE) {
|
|
246
|
+
const txs = _txs.slice(e, e+BATCH_SIZE);
|
|
245
247
|
|
|
246
248
|
await this.prepareTransactions(signer, txs)
|
|
247
249
|
const signedTxs = await signer.wallet.signAllTransactions(txs.map(e => e.tx));
|
|
@@ -252,23 +254,15 @@ export class SolanaTransactions extends SolanaModule {
|
|
|
252
254
|
});
|
|
253
255
|
this.logger.debug("sendAndConfirm(): sending transaction batch ("+e+".."+(e+50)+"), count: "+txs.length);
|
|
254
256
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if(
|
|
263
|
-
|
|
264
|
-
for(let i=0;i<txs.length;i++) {
|
|
265
|
-
const solTx = txs[i];
|
|
266
|
-
const signature = await this.sendSignedTransaction(solTx, options, onBeforePublish);
|
|
267
|
-
const confirmPromise = this.confirmTransaction(solTx, abortSignal, "confirmed");
|
|
268
|
-
//Don't await the last promise when !waitForConfirmation
|
|
269
|
-
if(i<txs.length-1 || e+50<_txs.length || waitForConfirmation) await confirmPromise;
|
|
270
|
-
signatures.push(signature);
|
|
271
|
-
}
|
|
257
|
+
//For solana we are forced to send txs one-by-one even with parallel, as we cannot determine their order upfront,
|
|
258
|
+
// however e.g. Jito could possibly handle sending a single package of up to 5 txns in order.
|
|
259
|
+
for(let i=0;i<txs.length;i++) {
|
|
260
|
+
const solTx = txs[i];
|
|
261
|
+
const signature = await this.sendSignedTransaction(solTx, options, onBeforePublish);
|
|
262
|
+
const confirmPromise = this.confirmTransaction(solTx, abortSignal, "confirmed");
|
|
263
|
+
//Don't await the last promise when !waitForConfirmation
|
|
264
|
+
if(i<txs.length-1 || e+50<_txs.length || waitForConfirmation) await confirmPromise;
|
|
265
|
+
signatures.push(signature);
|
|
272
266
|
}
|
|
273
267
|
}
|
|
274
268
|
|
|
@@ -118,7 +118,7 @@ export class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
|
118
118
|
try {
|
|
119
119
|
const transaction = await this.connection.getParsedTransaction(signature, {
|
|
120
120
|
commitment: "confirmed",
|
|
121
|
-
maxSupportedTransactionVersion:
|
|
121
|
+
maxSupportedTransactionVersion: 1
|
|
122
122
|
});
|
|
123
123
|
if(transaction==null) return false;
|
|
124
124
|
|
|
@@ -33,7 +33,7 @@ import {SwapClaim} from "./modules/SwapClaim";
|
|
|
33
33
|
import {SolanaLpVault} from "./modules/SolanaLpVault";
|
|
34
34
|
import {Buffer} from "buffer";
|
|
35
35
|
import {SolanaSigner} from "../wallet/SolanaSigner";
|
|
36
|
-
import {fromClaimHash, toBN, toClaimHash} from "../../utils/Utils";
|
|
36
|
+
import {fromClaimHash, toBN, toClaimHash, toEscrowHash} from "../../utils/Utils";
|
|
37
37
|
import {SolanaTokens} from "../chain/modules/SolanaTokens";
|
|
38
38
|
import * as BN from "bn.js";
|
|
39
39
|
|
|
@@ -271,10 +271,13 @@ export class SolanaSwapProgram
|
|
|
271
271
|
//Check if paid or what
|
|
272
272
|
const status: SwapNotCommitedState | SwapExpiredState | SwapPaidState = await this.Events.findInEvents(escrowStateKey, async (event, info) => {
|
|
273
273
|
if(event.name==="ClaimEvent") {
|
|
274
|
+
const paymentHash = Buffer.from(event.data.hash).toString("hex");
|
|
275
|
+
if(paymentHash!==data.paymentHash) return null;
|
|
274
276
|
if(!event.data.sequence.eq(data.sequence)) return null;
|
|
275
277
|
return {
|
|
276
278
|
type: SwapCommitStateType.PAID,
|
|
277
279
|
getClaimTxId: () => Promise.resolve(info.signature),
|
|
280
|
+
getClaimResult: () => Promise.resolve(Buffer.from(event.data.secret).toString("hex")),
|
|
278
281
|
getTxBlock: async () => {
|
|
279
282
|
return {
|
|
280
283
|
blockHeight: (await this.Chain.Blocks.getParsedBlock(info.slot)).blockHeight,
|
|
@@ -284,6 +287,8 @@ export class SolanaSwapProgram
|
|
|
284
287
|
}
|
|
285
288
|
}
|
|
286
289
|
if(event.name==="RefundEvent") {
|
|
290
|
+
const paymentHash = Buffer.from(event.data.hash).toString("hex");
|
|
291
|
+
if(paymentHash!==data.paymentHash) return null;
|
|
287
292
|
if(!event.data.sequence.eq(data.sequence)) return null;
|
|
288
293
|
return {
|
|
289
294
|
type: isExpired ? SwapCommitStateType.EXPIRED : SwapCommitStateType.NOT_COMMITED,
|