@atomiqlabs/chain-solana 13.2.2 → 13.2.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.
- package/dist/solana/chain/modules/SolanaBlocks.d.ts +2 -2
- package/dist/solana/chain/modules/SolanaBlocks.js +2 -2
- package/dist/solana/chain/modules/SolanaSlots.d.ts +2 -0
- package/dist/solana/chain/modules/SolanaSlots.js +4 -0
- package/dist/solana/swaps/modules/SwapInit.js +2 -2
- package/package.json +1 -1
- package/src/solana/chain/modules/SolanaBlocks.ts +4 -4
- package/src/solana/chain/modules/SolanaSlots.ts +3 -0
- package/src/solana/swaps/modules/SwapInit.ts +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SolanaModule } from "../SolanaModule";
|
|
2
|
-
import {
|
|
2
|
+
import { Finality, ParsedAccountsModeBlockResponse } from "@solana/web3.js";
|
|
3
3
|
export type BlockChecked = ParsedAccountsModeBlockResponse & {
|
|
4
4
|
blockTime: number;
|
|
5
5
|
blockHeight: number;
|
|
@@ -19,7 +19,7 @@ export declare class SolanaBlocks extends SolanaModule {
|
|
|
19
19
|
*
|
|
20
20
|
* @param commitment
|
|
21
21
|
*/
|
|
22
|
-
findLatestParsedBlock(commitment:
|
|
22
|
+
findLatestParsedBlock(commitment: Finality): Promise<{
|
|
23
23
|
block: BlockChecked;
|
|
24
24
|
slot: number;
|
|
25
25
|
}>;
|
|
@@ -40,7 +40,7 @@ class SolanaBlocks extends SolanaModule_1.SolanaModule {
|
|
|
40
40
|
*/
|
|
41
41
|
async findLatestParsedBlock(commitment) {
|
|
42
42
|
let slot = await this.root.Slots.getSlot(commitment);
|
|
43
|
-
for (let i = 0; i <
|
|
43
|
+
for (let i = 0; i < 16; i++) {
|
|
44
44
|
const block = await this.getParsedBlock(slot).catch(e => {
|
|
45
45
|
const errorStr = e.toString();
|
|
46
46
|
if (errorStr.startsWith("SolanaJSONRPCError: failed to get block:") && (errorStr.includes("Block not available for slot") ||
|
|
@@ -60,7 +60,7 @@ class SolanaBlocks extends SolanaModule_1.SolanaModule {
|
|
|
60
60
|
}
|
|
61
61
|
slot--;
|
|
62
62
|
}
|
|
63
|
-
throw new Error(
|
|
63
|
+
throw new Error(`Ran out of tries trying to find a parsedBlock, last attempted slot: ${slot + 1}`);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Gets parsed block for a given slot, uses block cache if the block was already fetched before
|
|
@@ -25,6 +25,8 @@ export declare class SolanaSlots extends SolanaModule {
|
|
|
25
25
|
* Gets the slot for a given commitment, uses slot cache & tries to estimate current slot based on the cached
|
|
26
26
|
* value, cache has relatively short expiry of just 12 slots (4.8 seconds)
|
|
27
27
|
*
|
|
28
|
+
* @remarks Doesn't try to extrapolate the slot number for `finalized` commitment level
|
|
29
|
+
*
|
|
28
30
|
* @param commitment
|
|
29
31
|
*/
|
|
30
32
|
getSlot(commitment: Commitment): Promise<number>;
|
|
@@ -54,11 +54,15 @@ class SolanaSlots extends SolanaModule_1.SolanaModule {
|
|
|
54
54
|
* Gets the slot for a given commitment, uses slot cache & tries to estimate current slot based on the cached
|
|
55
55
|
* value, cache has relatively short expiry of just 12 slots (4.8 seconds)
|
|
56
56
|
*
|
|
57
|
+
* @remarks Doesn't try to extrapolate the slot number for `finalized` commitment level
|
|
58
|
+
*
|
|
57
59
|
* @param commitment
|
|
58
60
|
*/
|
|
59
61
|
async getSlot(commitment) {
|
|
60
62
|
let cachedSlotData = this.slotCache[commitment];
|
|
61
63
|
if (cachedSlotData != null && Date.now() - cachedSlotData.timestamp < this.SLOT_CACHE_TIME) {
|
|
64
|
+
if (commitment === "finalized")
|
|
65
|
+
return await cachedSlotData.slot;
|
|
62
66
|
return (await cachedSlotData.slot) + Math.floor((Date.now() - cachedSlotData.timestamp) / this.root._SLOT_TIME);
|
|
63
67
|
}
|
|
64
68
|
cachedSlotData = this.fetchAndSaveSlot(commitment);
|
|
@@ -244,7 +244,7 @@ class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
244
244
|
txToSign.feePayer = swapData.isPayIn() ? swapData.offerer : swapData.claimer;
|
|
245
245
|
txToSign.recentBlockhash = latestBlock.blockhash;
|
|
246
246
|
txToSign.sign(signer.keypair);
|
|
247
|
-
this.logger.debug("signSwapInitialization(): Signed tx: ",
|
|
247
|
+
// this.logger.debug("signSwapInitialization(): Signed tx: ",txToSign);
|
|
248
248
|
const sig = txToSign.signatures.find(e => e.publicKey.equals(signer.getPublicKey()));
|
|
249
249
|
if (sig == null || sig.signature == null)
|
|
250
250
|
throw new Error(`Unable to extract transaction signature! Signer: ${signer.getAddress()}`);
|
|
@@ -299,7 +299,7 @@ class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
299
299
|
txToSign.feePayer = new web3_js_1.PublicKey(sender);
|
|
300
300
|
txToSign.recentBlockhash = blockhash;
|
|
301
301
|
txToSign.addSignature(signer, buffer_1.Buffer.from(signatureString, "hex"));
|
|
302
|
-
this.logger.debug("isSignatureValid(): Signed tx: ",
|
|
302
|
+
// this.logger.debug("isSignatureValid(): Signed tx: ",txToSign);
|
|
303
303
|
const valid = txToSign.verifySignatures(false);
|
|
304
304
|
if (!valid)
|
|
305
305
|
throw new base_1.SignatureVerificationError("Invalid signature!");
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {SolanaModule} from "../SolanaModule";
|
|
2
|
-
import {Commitment, ParsedAccountsModeBlockResponse} from "@solana/web3.js";
|
|
2
|
+
import {Commitment, Finality, ParsedAccountsModeBlockResponse} from "@solana/web3.js";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export type BlockChecked = ParsedAccountsModeBlockResponse & {blockTime: number, blockHeight: number};
|
|
@@ -38,13 +38,13 @@ export class SolanaBlocks extends SolanaModule {
|
|
|
38
38
|
*
|
|
39
39
|
* @param commitment
|
|
40
40
|
*/
|
|
41
|
-
public async findLatestParsedBlock(commitment:
|
|
41
|
+
public async findLatestParsedBlock(commitment: Finality): Promise<{
|
|
42
42
|
block: BlockChecked,
|
|
43
43
|
slot: number
|
|
44
44
|
}> {
|
|
45
45
|
let slot = await this.root.Slots.getSlot(commitment);
|
|
46
46
|
|
|
47
|
-
for(let i=0;i<
|
|
47
|
+
for(let i=0;i<16;i++) {
|
|
48
48
|
const block = await this.getParsedBlock(slot).catch(e => {
|
|
49
49
|
const errorStr = e.toString();
|
|
50
50
|
if(
|
|
@@ -71,7 +71,7 @@ export class SolanaBlocks extends SolanaModule {
|
|
|
71
71
|
slot--;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
throw new Error(
|
|
74
|
+
throw new Error(`Ran out of tries trying to find a parsedBlock, last attempted slot: ${slot + 1}`);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -65,12 +65,15 @@ export class SolanaSlots extends SolanaModule {
|
|
|
65
65
|
* Gets the slot for a given commitment, uses slot cache & tries to estimate current slot based on the cached
|
|
66
66
|
* value, cache has relatively short expiry of just 12 slots (4.8 seconds)
|
|
67
67
|
*
|
|
68
|
+
* @remarks Doesn't try to extrapolate the slot number for `finalized` commitment level
|
|
69
|
+
*
|
|
68
70
|
* @param commitment
|
|
69
71
|
*/
|
|
70
72
|
public async getSlot(commitment: Commitment): Promise<number> {
|
|
71
73
|
let cachedSlotData = this.slotCache[commitment];
|
|
72
74
|
|
|
73
75
|
if(cachedSlotData!=null && Date.now()-cachedSlotData.timestamp<this.SLOT_CACHE_TIME) {
|
|
76
|
+
if(commitment==="finalized") return await cachedSlotData.slot;
|
|
74
77
|
return (await cachedSlotData.slot) + Math.floor((Date.now()-cachedSlotData.timestamp)/this.root._SLOT_TIME);
|
|
75
78
|
}
|
|
76
79
|
|
|
@@ -326,7 +326,7 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
326
326
|
txToSign.feePayer = swapData.isPayIn() ? swapData.offerer : swapData.claimer;
|
|
327
327
|
txToSign.recentBlockhash = latestBlock.blockhash;
|
|
328
328
|
txToSign.sign(signer.keypair);
|
|
329
|
-
this.logger.debug("signSwapInitialization(): Signed tx: ",txToSign);
|
|
329
|
+
// this.logger.debug("signSwapInitialization(): Signed tx: ",txToSign);
|
|
330
330
|
|
|
331
331
|
const sig = txToSign.signatures.find(e => e.publicKey.equals(signer.getPublicKey()));
|
|
332
332
|
if(sig==null || sig.signature==null) throw new Error(`Unable to extract transaction signature! Signer: ${signer.getAddress()}`);
|
|
@@ -393,7 +393,7 @@ export class SwapInit extends SolanaSwapModule {
|
|
|
393
393
|
txToSign.feePayer = new PublicKey(sender);
|
|
394
394
|
txToSign.recentBlockhash = blockhash;
|
|
395
395
|
txToSign.addSignature(signer, Buffer.from(signatureString, "hex"));
|
|
396
|
-
this.logger.debug("isSignatureValid(): Signed tx: ",txToSign);
|
|
396
|
+
// this.logger.debug("isSignatureValid(): Signed tx: ",txToSign);
|
|
397
397
|
|
|
398
398
|
const valid = txToSign.verifySignatures(false);
|
|
399
399
|
|