@atomiqlabs/chain-solana 12.0.14 → 13.0.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.
Files changed (114) hide show
  1. package/LICENSE +201 -201
  2. package/dist/index.d.ts +12 -29
  3. package/dist/index.js +32 -45
  4. package/dist/solana/SolanaChainType.d.ts +15 -11
  5. package/dist/solana/SolanaChainType.js +2 -2
  6. package/dist/solana/SolanaChains.d.ts +9 -20
  7. package/dist/solana/SolanaChains.js +25 -25
  8. package/dist/solana/SolanaInitializer.d.ts +38 -18
  9. package/dist/solana/SolanaInitializer.js +75 -63
  10. package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +230 -228
  11. package/dist/solana/btcrelay/SolanaBtcRelay.js +463 -441
  12. package/dist/solana/btcrelay/headers/SolanaBtcHeader.d.ts +33 -29
  13. package/dist/solana/btcrelay/headers/SolanaBtcHeader.js +37 -34
  14. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.d.ts +50 -46
  15. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.js +81 -78
  16. package/dist/solana/btcrelay/program/programIdl.json +671 -671
  17. package/dist/solana/chain/SolanaAction.d.ts +26 -26
  18. package/dist/solana/chain/SolanaAction.js +86 -86
  19. package/dist/solana/chain/SolanaChainInterface.d.ts +77 -65
  20. package/dist/solana/chain/SolanaChainInterface.js +138 -125
  21. package/dist/solana/chain/SolanaModule.d.ts +14 -14
  22. package/dist/solana/chain/SolanaModule.js +13 -13
  23. package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -8
  24. package/dist/solana/chain/modules/SolanaAddresses.js +22 -22
  25. package/dist/solana/chain/modules/SolanaBlocks.d.ts +32 -28
  26. package/dist/solana/chain/modules/SolanaBlocks.js +76 -72
  27. package/dist/solana/chain/modules/SolanaEvents.d.ts +68 -68
  28. package/dist/solana/chain/modules/SolanaEvents.js +238 -238
  29. package/dist/solana/chain/modules/SolanaFees.d.ts +122 -121
  30. package/dist/solana/chain/modules/SolanaFees.js +381 -379
  31. package/dist/solana/chain/modules/SolanaSignatures.d.ts +24 -23
  32. package/dist/solana/chain/modules/SolanaSignatures.js +39 -39
  33. package/dist/solana/chain/modules/SolanaSlots.d.ts +31 -31
  34. package/dist/solana/chain/modules/SolanaSlots.js +69 -68
  35. package/dist/solana/chain/modules/SolanaTokens.d.ts +123 -136
  36. package/dist/solana/chain/modules/SolanaTokens.js +242 -248
  37. package/dist/solana/chain/modules/SolanaTransactions.d.ts +139 -124
  38. package/dist/solana/chain/modules/SolanaTransactions.js +404 -323
  39. package/dist/solana/events/SolanaChainEvents.d.ts +35 -88
  40. package/dist/solana/events/SolanaChainEvents.js +92 -256
  41. package/dist/solana/events/SolanaChainEventsBrowser.d.ts +128 -75
  42. package/dist/solana/events/SolanaChainEventsBrowser.js +337 -172
  43. package/dist/solana/program/SolanaProgramBase.d.ts +45 -40
  44. package/dist/solana/program/SolanaProgramBase.js +43 -43
  45. package/dist/solana/program/SolanaProgramModule.d.ts +8 -8
  46. package/dist/solana/program/SolanaProgramModule.js +11 -11
  47. package/dist/solana/program/modules/SolanaProgramEvents.d.ts +53 -53
  48. package/dist/solana/program/modules/SolanaProgramEvents.js +117 -114
  49. package/dist/solana/swaps/SolanaSwapData.d.ts +102 -71
  50. package/dist/solana/swaps/SolanaSwapData.js +335 -292
  51. package/dist/solana/swaps/SolanaSwapModule.d.ts +10 -10
  52. package/dist/solana/swaps/SolanaSwapModule.js +12 -11
  53. package/dist/solana/swaps/SolanaSwapProgram.d.ts +202 -224
  54. package/dist/solana/swaps/SolanaSwapProgram.js +587 -570
  55. package/dist/solana/swaps/SwapTypeEnum.d.ts +11 -11
  56. package/dist/solana/swaps/SwapTypeEnum.js +43 -42
  57. package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +95 -94
  58. package/dist/solana/swaps/modules/SolanaDataAccount.js +230 -231
  59. package/dist/solana/swaps/modules/SolanaLpVault.d.ts +69 -71
  60. package/dist/solana/swaps/modules/SolanaLpVault.js +171 -173
  61. package/dist/solana/swaps/modules/SwapClaim.d.ts +126 -129
  62. package/dist/solana/swaps/modules/SwapClaim.js +292 -291
  63. package/dist/solana/swaps/modules/SwapInit.d.ts +208 -217
  64. package/dist/solana/swaps/modules/SwapInit.js +521 -519
  65. package/dist/solana/swaps/modules/SwapRefund.d.ts +81 -82
  66. package/dist/solana/swaps/modules/SwapRefund.js +277 -262
  67. package/dist/solana/swaps/programIdl.json +945 -945
  68. package/dist/solana/swaps/programTypes.d.ts +943 -943
  69. package/dist/solana/swaps/programTypes.js +945 -945
  70. package/dist/solana/wallet/SolanaKeypairWallet.d.ts +13 -9
  71. package/dist/solana/wallet/SolanaKeypairWallet.js +37 -33
  72. package/dist/solana/wallet/SolanaSigner.d.ts +15 -11
  73. package/dist/solana/wallet/SolanaSigner.js +21 -17
  74. package/dist/utils/Utils.d.ts +58 -53
  75. package/dist/utils/Utils.js +170 -170
  76. package/package.json +44 -41
  77. package/src/index.ts +17 -36
  78. package/src/solana/SolanaChainType.ts +32 -27
  79. package/src/solana/SolanaChains.ts +23 -23
  80. package/src/solana/SolanaInitializer.ts +126 -102
  81. package/src/solana/btcrelay/SolanaBtcRelay.ts +618 -589
  82. package/src/solana/btcrelay/headers/SolanaBtcHeader.ts +60 -57
  83. package/src/solana/btcrelay/headers/SolanaBtcStoredHeader.ts +105 -102
  84. package/src/solana/btcrelay/program/programIdl.json +670 -670
  85. package/src/solana/chain/SolanaAction.ts +108 -108
  86. package/src/solana/chain/SolanaChainInterface.ts +219 -192
  87. package/src/solana/chain/SolanaModule.ts +20 -20
  88. package/src/solana/chain/modules/SolanaAddresses.ts +20 -20
  89. package/src/solana/chain/modules/SolanaBlocks.ts +83 -78
  90. package/src/solana/chain/modules/SolanaEvents.ts +271 -270
  91. package/src/solana/chain/modules/SolanaFees.ts +454 -450
  92. package/src/solana/chain/modules/SolanaSignatures.ts +39 -39
  93. package/src/solana/chain/modules/SolanaSlots.ts +83 -82
  94. package/src/solana/chain/modules/SolanaTokens.ts +300 -307
  95. package/src/solana/chain/modules/SolanaTransactions.ts +452 -365
  96. package/src/solana/events/SolanaChainEvents.ts +110 -299
  97. package/src/solana/events/SolanaChainEventsBrowser.ts +399 -209
  98. package/src/solana/program/SolanaProgramBase.ts +79 -79
  99. package/src/solana/program/SolanaProgramModule.ts +15 -15
  100. package/src/solana/program/modules/SolanaProgramEvents.ts +157 -155
  101. package/src/solana/swaps/SolanaSwapData.ts +420 -430
  102. package/src/solana/swaps/SolanaSwapModule.ts +17 -16
  103. package/src/solana/swaps/SolanaSwapProgram.ts +858 -854
  104. package/src/solana/swaps/SwapTypeEnum.ts +30 -29
  105. package/src/solana/swaps/modules/SolanaDataAccount.ts +300 -307
  106. package/src/solana/swaps/modules/SolanaLpVault.ts +208 -215
  107. package/src/solana/swaps/modules/SwapClaim.ts +385 -389
  108. package/src/solana/swaps/modules/SwapInit.ts +657 -663
  109. package/src/solana/swaps/modules/SwapRefund.ts +335 -323
  110. package/src/solana/swaps/programIdl.json +944 -944
  111. package/src/solana/swaps/programTypes.ts +1885 -1885
  112. package/src/solana/wallet/SolanaKeypairWallet.ts +40 -36
  113. package/src/solana/wallet/SolanaSigner.ts +28 -24
  114. package/src/utils/Utils.ts +194 -180
@@ -1,125 +1,138 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaChainInterface = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- const SolanaFees_1 = require("./modules/SolanaFees");
6
- const SolanaBlocks_1 = require("./modules/SolanaBlocks");
7
- const SolanaSlots_1 = require("./modules/SolanaSlots");
8
- const SolanaTokens_1 = require("./modules/SolanaTokens");
9
- const SolanaTransactions_1 = require("./modules/SolanaTransactions");
10
- const SolanaSignatures_1 = require("./modules/SolanaSignatures");
11
- const SolanaEvents_1 = require("./modules/SolanaEvents");
12
- const Utils_1 = require("../../utils/Utils");
13
- const SolanaAddresses_1 = require("./modules/SolanaAddresses");
14
- const SolanaSigner_1 = require("../wallet/SolanaSigner");
15
- const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
16
- class SolanaChainInterface {
17
- constructor(connection, retryPolicy, solanaFeeEstimator = new SolanaFees_1.SolanaFees(connection)) {
18
- this.chainId = "SOLANA";
19
- this.SLOT_TIME = 400;
20
- this.TX_SLOT_VALIDITY = 151;
21
- this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
22
- this.connection = connection;
23
- this.retryPolicy = retryPolicy;
24
- this.Blocks = new SolanaBlocks_1.SolanaBlocks(this);
25
- this.Fees = solanaFeeEstimator;
26
- this.Slots = new SolanaSlots_1.SolanaSlots(this);
27
- this.Tokens = new SolanaTokens_1.SolanaTokens(this);
28
- this.Transactions = new SolanaTransactions_1.SolanaTransactions(this);
29
- this.Signatures = new SolanaSignatures_1.SolanaSignatures(this);
30
- this.Events = new SolanaEvents_1.SolanaEvents(this);
31
- }
32
- async getBalance(signer, tokenAddress) {
33
- const token = new web3_js_1.PublicKey(tokenAddress);
34
- const publicKey = new web3_js_1.PublicKey(signer);
35
- let { balance } = await this.Tokens.getTokenBalance(publicKey, token);
36
- if (token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS)) {
37
- const accountRentExemptCost = 1000000n;
38
- balance = balance - accountRentExemptCost;
39
- if (balance < 0n)
40
- balance = 0n;
41
- }
42
- this.logger.debug("getBalance(): token balance, token: " + token.toBase58() + " balance: " + balance.toString(10));
43
- return balance;
44
- }
45
- isValidAddress(address) {
46
- return SolanaAddresses_1.SolanaAddresses.isValidAddress(address);
47
- }
48
- normalizeAddress(address) {
49
- return address;
50
- }
51
- getNativeCurrencyAddress() {
52
- return this.Tokens.getNativeCurrencyAddress().toString();
53
- }
54
- txsTransfer(signer, token, amount, dstAddress, feeRate) {
55
- return this.Tokens.txsTransfer(new web3_js_1.PublicKey(signer), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), feeRate);
56
- }
57
- async transfer(signer, token, amount, dstAddress, txOptions) {
58
- const txs = await this.Tokens.txsTransfer(signer.getPublicKey(), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), txOptions?.feeRate);
59
- const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
60
- return txId;
61
- }
62
- ////////////////////////////////////////////
63
- //// Transactions
64
- sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
65
- return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
66
- }
67
- serializeTx(tx) {
68
- return this.Transactions.serializeTx(tx);
69
- }
70
- deserializeTx(txData) {
71
- return this.Transactions.deserializeTx(txData);
72
- }
73
- getTxIdStatus(txId) {
74
- return this.Transactions.getTxIdStatus(txId);
75
- }
76
- getTxStatus(tx) {
77
- return this.Transactions.getTxStatus(tx);
78
- }
79
- async getFinalizedBlock() {
80
- const { block } = await this.Blocks.findLatestParsedBlock("finalized");
81
- return {
82
- height: block.blockHeight,
83
- blockHash: block.blockhash
84
- };
85
- }
86
- ///////////////////////////////////
87
- //// Callbacks & handlers
88
- offBeforeTxReplace(callback) {
89
- return true;
90
- }
91
- onBeforeTxReplace(callback) { }
92
- onBeforeTxSigned(callback) {
93
- this.Transactions.onBeforeTxSigned(callback);
94
- }
95
- offBeforeTxSigned(callback) {
96
- return this.Transactions.offBeforeTxSigned(callback);
97
- }
98
- onSendTransaction(callback) {
99
- this.Transactions.onSendTransaction(callback);
100
- }
101
- offSendTransaction(callback) {
102
- return this.Transactions.offSendTransaction(callback);
103
- }
104
- isValidToken(tokenIdentifier) {
105
- try {
106
- new web3_js_1.PublicKey(tokenIdentifier);
107
- return true;
108
- }
109
- catch (e) {
110
- return false;
111
- }
112
- }
113
- randomAddress() {
114
- return web3_js_1.Keypair.generate().publicKey.toString();
115
- }
116
- randomSigner() {
117
- const keypair = web3_js_1.Keypair.generate();
118
- const wallet = new SolanaKeypairWallet_1.SolanaKeypairWallet(keypair);
119
- return new SolanaSigner_1.SolanaSigner(wallet, keypair);
120
- }
121
- wrapSigner(signer) {
122
- return Promise.resolve(new SolanaSigner_1.SolanaSigner(signer));
123
- }
124
- }
125
- exports.SolanaChainInterface = SolanaChainInterface;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaChainInterface = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const SolanaFees_1 = require("./modules/SolanaFees");
6
+ const SolanaBlocks_1 = require("./modules/SolanaBlocks");
7
+ const SolanaSlots_1 = require("./modules/SolanaSlots");
8
+ const SolanaTokens_1 = require("./modules/SolanaTokens");
9
+ const SolanaTransactions_1 = require("./modules/SolanaTransactions");
10
+ const SolanaSignatures_1 = require("./modules/SolanaSignatures");
11
+ const SolanaEvents_1 = require("./modules/SolanaEvents");
12
+ const Utils_1 = require("../../utils/Utils");
13
+ const SolanaAddresses_1 = require("./modules/SolanaAddresses");
14
+ const SolanaSigner_1 = require("../wallet/SolanaSigner");
15
+ const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
16
+ /**
17
+ * Main chain interface for interacting with Solana blockchain
18
+ * @category Chain Interface
19
+ */
20
+ class SolanaChainInterface {
21
+ constructor(connection, retryPolicy, solanaFeeEstimator = new SolanaFees_1.SolanaFees(connection)) {
22
+ this.chainId = "SOLANA";
23
+ this.SLOT_TIME = 400;
24
+ this.TX_SLOT_VALIDITY = 151;
25
+ this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
26
+ this.connection = connection;
27
+ this.retryPolicy = retryPolicy;
28
+ this.Blocks = new SolanaBlocks_1.SolanaBlocks(this);
29
+ this.Fees = solanaFeeEstimator;
30
+ this.Slots = new SolanaSlots_1.SolanaSlots(this);
31
+ this.Tokens = new SolanaTokens_1.SolanaTokens(this);
32
+ this.Transactions = new SolanaTransactions_1.SolanaTransactions(this);
33
+ this.Signatures = new SolanaSignatures_1.SolanaSignatures(this);
34
+ this.Events = new SolanaEvents_1.SolanaEvents(this);
35
+ }
36
+ async getBalance(signer, tokenAddress) {
37
+ const token = new web3_js_1.PublicKey(tokenAddress);
38
+ const publicKey = new web3_js_1.PublicKey(signer);
39
+ let { balance } = await this.Tokens.getTokenBalance(publicKey, token);
40
+ if (token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS)) {
41
+ const accountRentExemptCost = 1000000n;
42
+ balance = balance - accountRentExemptCost;
43
+ if (balance < 0n)
44
+ balance = 0n;
45
+ }
46
+ this.logger.debug("getBalance(): token balance, token: " + token.toBase58() + " balance: " + balance.toString(10));
47
+ return balance;
48
+ }
49
+ isValidAddress(address) {
50
+ return SolanaAddresses_1.SolanaAddresses.isValidAddress(address);
51
+ }
52
+ normalizeAddress(address) {
53
+ return address;
54
+ }
55
+ getNativeCurrencyAddress() {
56
+ return this.Tokens.getNativeCurrencyAddress().toString();
57
+ }
58
+ txsTransfer(signer, token, amount, dstAddress, feeRate) {
59
+ return this.Tokens.txsTransfer(new web3_js_1.PublicKey(signer), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), feeRate);
60
+ }
61
+ async transfer(signer, token, amount, dstAddress, txOptions) {
62
+ const txs = await this.Tokens.txsTransfer(signer.getPublicKey(), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), txOptions?.feeRate);
63
+ const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
64
+ return txId;
65
+ }
66
+ ////////////////////////////////////////////
67
+ //// Transactions
68
+ sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
69
+ return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
70
+ }
71
+ sendSignedAndConfirm(txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
72
+ return this.Transactions.sendSignedAndConfirm(txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
73
+ }
74
+ serializeTx(tx) {
75
+ return Promise.resolve(this.Transactions.serializeUnsignedTx(tx));
76
+ }
77
+ deserializeTx(txData) {
78
+ return Promise.resolve(this.Transactions.deserializeUnsignedTx(txData));
79
+ }
80
+ serializeSignedTx(tx) {
81
+ return Promise.resolve(this.Transactions.serializeSignedTx(tx));
82
+ }
83
+ deserializeSignedTx(txData) {
84
+ return Promise.resolve(this.Transactions.deserializeSignedTransaction(txData));
85
+ }
86
+ getTxIdStatus(txId) {
87
+ return this.Transactions.getTxIdStatus(txId);
88
+ }
89
+ getTxStatus(tx) {
90
+ return this.Transactions.getTxStatus(tx);
91
+ }
92
+ async getFinalizedBlock() {
93
+ const { block } = await this.Blocks.findLatestParsedBlock("finalized");
94
+ return {
95
+ height: block.blockHeight,
96
+ blockHash: block.blockhash
97
+ };
98
+ }
99
+ ///////////////////////////////////
100
+ //// Callbacks & handlers
101
+ offBeforeTxReplace(callback) {
102
+ return true;
103
+ }
104
+ onBeforeTxReplace(callback) { }
105
+ onBeforeTxSigned(callback) {
106
+ this.Transactions.onBeforeTxSigned(callback);
107
+ }
108
+ offBeforeTxSigned(callback) {
109
+ return this.Transactions.offBeforeTxSigned(callback);
110
+ }
111
+ onSendTransaction(callback) {
112
+ this.Transactions.onSendTransaction(callback);
113
+ }
114
+ offSendTransaction(callback) {
115
+ return this.Transactions.offSendTransaction(callback);
116
+ }
117
+ isValidToken(tokenIdentifier) {
118
+ try {
119
+ new web3_js_1.PublicKey(tokenIdentifier);
120
+ return true;
121
+ }
122
+ catch (e) {
123
+ return false;
124
+ }
125
+ }
126
+ randomAddress() {
127
+ return web3_js_1.Keypair.generate().publicKey.toString();
128
+ }
129
+ randomSigner() {
130
+ const keypair = web3_js_1.Keypair.generate();
131
+ const wallet = new SolanaKeypairWallet_1.SolanaKeypairWallet(keypair);
132
+ return new SolanaSigner_1.SolanaSigner(wallet, keypair);
133
+ }
134
+ wrapSigner(signer) {
135
+ return Promise.resolve(new SolanaSigner_1.SolanaSigner(signer));
136
+ }
137
+ }
138
+ exports.SolanaChainInterface = SolanaChainInterface;
@@ -1,14 +1,14 @@
1
- import { Connection } from "@solana/web3.js";
2
- import { SolanaChainInterface, SolanaRetryPolicy } from "./SolanaChainInterface";
3
- export declare class SolanaModule {
4
- protected readonly connection: Connection;
5
- protected readonly retryPolicy: SolanaRetryPolicy;
6
- protected readonly root: SolanaChainInterface;
7
- protected readonly logger: {
8
- debug: (msg: any, ...args: any[]) => void;
9
- info: (msg: any, ...args: any[]) => void;
10
- warn: (msg: any, ...args: any[]) => void;
11
- error: (msg: any, ...args: any[]) => void;
12
- };
13
- constructor(root: SolanaChainInterface);
14
- }
1
+ import { Connection } from "@solana/web3.js";
2
+ import { SolanaChainInterface, SolanaRetryPolicy } from "./SolanaChainInterface";
3
+ export declare class SolanaModule {
4
+ protected readonly connection: Connection;
5
+ protected readonly retryPolicy?: SolanaRetryPolicy;
6
+ protected readonly root: SolanaChainInterface;
7
+ protected readonly logger: {
8
+ debug: (msg: string, ...args: any[]) => false | void;
9
+ info: (msg: string, ...args: any[]) => false | void;
10
+ warn: (msg: string, ...args: any[]) => false | void;
11
+ error: (msg: string, ...args: any[]) => false | void;
12
+ };
13
+ constructor(root: SolanaChainInterface);
14
+ }
@@ -1,13 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaModule = void 0;
4
- const Utils_1 = require("../../utils/Utils");
5
- class SolanaModule {
6
- constructor(root) {
7
- this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
8
- this.connection = root.connection;
9
- this.retryPolicy = root.retryPolicy;
10
- this.root = root;
11
- }
12
- }
13
- exports.SolanaModule = SolanaModule;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaModule = void 0;
4
+ const Utils_1 = require("../../utils/Utils");
5
+ class SolanaModule {
6
+ constructor(root) {
7
+ this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
8
+ this.connection = root.connection;
9
+ this.retryPolicy = root.retryPolicy;
10
+ this.root = root;
11
+ }
12
+ }
13
+ exports.SolanaModule = SolanaModule;
@@ -1,8 +1,8 @@
1
- export declare class SolanaAddresses {
2
- /**
3
- * Checks whether an address is a valid Solana address (base58 encoded ed25519 public key)
4
- *
5
- * @param address
6
- */
7
- static isValidAddress(address: string): boolean;
8
- }
1
+ export declare class SolanaAddresses {
2
+ /**
3
+ * Checks whether an address is a valid Solana address (base58 encoded ed25519 public key)
4
+ *
5
+ * @param address
6
+ */
7
+ static isValidAddress(address: string): boolean;
8
+ }
@@ -1,22 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaAddresses = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- class SolanaAddresses {
6
- ///////////////////
7
- //// Address utils
8
- /**
9
- * Checks whether an address is a valid Solana address (base58 encoded ed25519 public key)
10
- *
11
- * @param address
12
- */
13
- static isValidAddress(address) {
14
- try {
15
- return web3_js_1.PublicKey.isOnCurve(address);
16
- }
17
- catch (e) {
18
- return false;
19
- }
20
- }
21
- }
22
- exports.SolanaAddresses = SolanaAddresses;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaAddresses = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ class SolanaAddresses {
6
+ ///////////////////
7
+ //// Address utils
8
+ /**
9
+ * Checks whether an address is a valid Solana address (base58 encoded ed25519 public key)
10
+ *
11
+ * @param address
12
+ */
13
+ static isValidAddress(address) {
14
+ try {
15
+ return web3_js_1.PublicKey.isOnCurve(address);
16
+ }
17
+ catch (e) {
18
+ return false;
19
+ }
20
+ }
21
+ }
22
+ exports.SolanaAddresses = SolanaAddresses;
@@ -1,28 +1,32 @@
1
- import { SolanaModule } from "../SolanaModule";
2
- import { Commitment, ParsedAccountsModeBlockResponse } from "@solana/web3.js";
3
- export declare class SolanaBlocks extends SolanaModule {
4
- private blockCache;
5
- /**
6
- * Initiates a fetch of the block at specified slot & saves the fetch promise into a block cache
7
- *
8
- * @param slot
9
- * @private
10
- */
11
- private fetchAndSaveParsedBlock;
12
- /**
13
- * Tries to find the latest existing block for a given commitment, skipping blocks that are not available, runs a
14
- * search backwards from the latest slot for the given commitment and fails after 10 tries
15
- *
16
- * @param commitment
17
- */
18
- findLatestParsedBlock(commitment: Commitment): Promise<{
19
- block: ParsedAccountsModeBlockResponse;
20
- slot: number;
21
- }>;
22
- /**
23
- * Gets parsed block for a given slot, uses block cache if the block was already fetched before
24
- *
25
- * @param slot
26
- */
27
- getParsedBlock(slot: number): Promise<ParsedAccountsModeBlockResponse>;
28
- }
1
+ import { SolanaModule } from "../SolanaModule";
2
+ import { Commitment, ParsedAccountsModeBlockResponse } from "@solana/web3.js";
3
+ export type BlockChecked = ParsedAccountsModeBlockResponse & {
4
+ blockTime: number;
5
+ blockHeight: number;
6
+ };
7
+ export declare class SolanaBlocks extends SolanaModule {
8
+ private blockCache;
9
+ /**
10
+ * Initiates a fetch of the block at specified slot & saves the fetch promise into a block cache
11
+ *
12
+ * @param slot
13
+ * @private
14
+ */
15
+ private fetchAndSaveParsedBlock;
16
+ /**
17
+ * Tries to find the latest existing block for a given commitment, skipping blocks that are not available, runs a
18
+ * search backwards from the latest slot for the given commitment and fails after 10 tries
19
+ *
20
+ * @param commitment
21
+ */
22
+ findLatestParsedBlock(commitment: Commitment): Promise<{
23
+ block: BlockChecked;
24
+ slot: number;
25
+ }>;
26
+ /**
27
+ * Gets parsed block for a given slot, uses block cache if the block was already fetched before
28
+ *
29
+ * @param slot
30
+ */
31
+ getParsedBlock(slot: number): Promise<BlockChecked>;
32
+ }
@@ -1,72 +1,76 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaBlocks = void 0;
4
- const SolanaModule_1 = require("../SolanaModule");
5
- class SolanaBlocks extends SolanaModule_1.SolanaModule {
6
- constructor() {
7
- super(...arguments);
8
- this.blockCache = new Map();
9
- }
10
- /**
11
- * Initiates a fetch of the block at specified slot & saves the fetch promise into a block cache
12
- *
13
- * @param slot
14
- * @private
15
- */
16
- fetchAndSaveParsedBlock(slot) {
17
- const blockCacheData = this.connection.getParsedBlock(slot, {
18
- transactionDetails: "none",
19
- commitment: "confirmed",
20
- rewards: false
21
- });
22
- this.blockCache.set(slot, blockCacheData);
23
- blockCacheData.catch(e => {
24
- if (this.blockCache.get(slot) == blockCacheData)
25
- this.blockCache.delete(slot);
26
- throw e;
27
- });
28
- return blockCacheData;
29
- }
30
- ///////////////////
31
- //// Blocks
32
- /**
33
- * Tries to find the latest existing block for a given commitment, skipping blocks that are not available, runs a
34
- * search backwards from the latest slot for the given commitment and fails after 10 tries
35
- *
36
- * @param commitment
37
- */
38
- async findLatestParsedBlock(commitment) {
39
- let slot = await this.root.Slots.getSlot(commitment);
40
- for (let i = 0; i < 10; i++) {
41
- const block = await this.getParsedBlock(slot).catch(e => {
42
- if (e.toString().startsWith("SolanaJSONRPCError: failed to get block: Block not available for slot")) {
43
- return null;
44
- }
45
- throw e;
46
- });
47
- if (block != null) {
48
- this.logger.debug("findLatestParsedBlock(): Found valid block, slot: " + slot +
49
- " blockhash: " + block.blockhash + " tries: " + i);
50
- return {
51
- block,
52
- slot
53
- };
54
- }
55
- slot--;
56
- }
57
- throw new Error("Ran out of tries trying to find a parsedBlock");
58
- }
59
- /**
60
- * Gets parsed block for a given slot, uses block cache if the block was already fetched before
61
- *
62
- * @param slot
63
- */
64
- getParsedBlock(slot) {
65
- let blockCacheData = this.blockCache.get(slot);
66
- if (blockCacheData == null) {
67
- blockCacheData = this.fetchAndSaveParsedBlock(slot);
68
- }
69
- return blockCacheData;
70
- }
71
- }
72
- exports.SolanaBlocks = SolanaBlocks;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaBlocks = void 0;
4
+ const SolanaModule_1 = require("../SolanaModule");
5
+ class SolanaBlocks extends SolanaModule_1.SolanaModule {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.blockCache = new Map();
9
+ }
10
+ /**
11
+ * Initiates a fetch of the block at specified slot & saves the fetch promise into a block cache
12
+ *
13
+ * @param slot
14
+ * @private
15
+ */
16
+ fetchAndSaveParsedBlock(slot) {
17
+ const blockCacheData = this.connection.getParsedBlock(slot, {
18
+ transactionDetails: "none",
19
+ commitment: "confirmed",
20
+ rewards: false
21
+ }).then(val => {
22
+ if (val.blockHeight == null || val.blockTime == null)
23
+ throw new Error(`Cannot get block for slot ${slot}: blockHeight or blockTime empty!`);
24
+ return val;
25
+ });
26
+ this.blockCache.set(slot, blockCacheData);
27
+ blockCacheData.catch(e => {
28
+ if (this.blockCache.get(slot) == blockCacheData)
29
+ this.blockCache.delete(slot);
30
+ throw e;
31
+ });
32
+ return blockCacheData;
33
+ }
34
+ ///////////////////
35
+ //// Blocks
36
+ /**
37
+ * Tries to find the latest existing block for a given commitment, skipping blocks that are not available, runs a
38
+ * search backwards from the latest slot for the given commitment and fails after 10 tries
39
+ *
40
+ * @param commitment
41
+ */
42
+ async findLatestParsedBlock(commitment) {
43
+ let slot = await this.root.Slots.getSlot(commitment);
44
+ for (let i = 0; i < 10; i++) {
45
+ const block = await this.getParsedBlock(slot).catch(e => {
46
+ if (e.toString().startsWith("SolanaJSONRPCError: failed to get block: Block not available for slot")) {
47
+ return null;
48
+ }
49
+ throw e;
50
+ });
51
+ if (block != null) {
52
+ this.logger.debug("findLatestParsedBlock(): Found valid block, slot: " + slot +
53
+ " blockhash: " + block.blockhash + " tries: " + i);
54
+ return {
55
+ block,
56
+ slot
57
+ };
58
+ }
59
+ slot--;
60
+ }
61
+ throw new Error("Ran out of tries trying to find a parsedBlock");
62
+ }
63
+ /**
64
+ * Gets parsed block for a given slot, uses block cache if the block was already fetched before
65
+ *
66
+ * @param slot
67
+ */
68
+ getParsedBlock(slot) {
69
+ let blockCacheData = this.blockCache.get(slot);
70
+ if (blockCacheData == null) {
71
+ blockCacheData = this.fetchAndSaveParsedBlock(slot);
72
+ }
73
+ return blockCacheData;
74
+ }
75
+ }
76
+ exports.SolanaBlocks = SolanaBlocks;