@atomiqlabs/chain-solana 13.5.13 → 13.5.14
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/LICENSE +201 -201
- package/README.md +73 -73
- package/dist/index.d.ts +81 -81
- package/dist/index.js +102 -102
- package/dist/node/index.d.ts +9 -9
- package/dist/node/index.js +13 -13
- package/dist/solana/SolanaChainType.d.ts +15 -15
- package/dist/solana/SolanaChainType.js +2 -2
- package/dist/solana/SolanaChains.d.ts +12 -12
- package/dist/solana/SolanaChains.js +45 -45
- package/dist/solana/SolanaInitializer.d.ts +94 -94
- package/dist/solana/SolanaInitializer.js +174 -174
- package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +222 -222
- package/dist/solana/btcrelay/SolanaBtcRelay.js +455 -455
- package/dist/solana/btcrelay/headers/SolanaBtcHeader.d.ts +84 -84
- package/dist/solana/btcrelay/headers/SolanaBtcHeader.js +70 -70
- package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.d.ts +92 -92
- package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.js +109 -109
- package/dist/solana/btcrelay/program/programIdl.json +671 -671
- package/dist/solana/chain/SolanaAction.d.ts +26 -26
- package/dist/solana/chain/SolanaAction.js +87 -87
- package/dist/solana/chain/SolanaChainInterface.d.ts +224 -224
- package/dist/solana/chain/SolanaChainInterface.js +275 -275
- package/dist/solana/chain/SolanaModule.d.ts +14 -14
- package/dist/solana/chain/SolanaModule.js +13 -13
- package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -8
- package/dist/solana/chain/modules/SolanaAddresses.js +22 -22
- package/dist/solana/chain/modules/SolanaBlocks.d.ts +32 -32
- package/dist/solana/chain/modules/SolanaBlocks.js +78 -78
- package/dist/solana/chain/modules/SolanaEvents.d.ts +68 -68
- package/dist/solana/chain/modules/SolanaEvents.js +238 -238
- package/dist/solana/chain/modules/SolanaFees.d.ts +189 -189
- package/dist/solana/chain/modules/SolanaFees.js +434 -434
- package/dist/solana/chain/modules/SolanaSignatures.d.ts +24 -24
- package/dist/solana/chain/modules/SolanaSignatures.js +39 -39
- package/dist/solana/chain/modules/SolanaSlots.d.ts +33 -33
- package/dist/solana/chain/modules/SolanaSlots.js +72 -72
- package/dist/solana/chain/modules/SolanaTokens.d.ts +123 -123
- package/dist/solana/chain/modules/SolanaTokens.js +242 -242
- package/dist/solana/chain/modules/SolanaTransactions.d.ts +149 -149
- package/dist/solana/chain/modules/SolanaTransactions.js +445 -445
- package/dist/solana/connection/ConnectionWithRetries.d.ts +35 -35
- package/dist/solana/connection/ConnectionWithRetries.js +86 -71
- package/dist/solana/events/SolanaChainEvents.d.ts +45 -45
- package/dist/solana/events/SolanaChainEvents.js +108 -108
- package/dist/solana/events/SolanaChainEventsBrowser.d.ts +205 -205
- package/dist/solana/events/SolanaChainEventsBrowser.js +404 -404
- package/dist/solana/program/SolanaProgramBase.d.ts +73 -73
- package/dist/solana/program/SolanaProgramBase.js +54 -54
- package/dist/solana/program/SolanaProgramModule.d.ts +8 -8
- package/dist/solana/program/SolanaProgramModule.js +11 -11
- package/dist/solana/program/modules/SolanaProgramEvents.d.ts +53 -53
- package/dist/solana/program/modules/SolanaProgramEvents.js +117 -117
- package/dist/solana/swaps/SolanaSwapData.d.ts +333 -333
- package/dist/solana/swaps/SolanaSwapData.js +535 -535
- package/dist/solana/swaps/SolanaSwapModule.d.ts +11 -11
- package/dist/solana/swaps/SolanaSwapModule.js +12 -12
- package/dist/solana/swaps/SolanaSwapProgram.d.ts +376 -376
- package/dist/solana/swaps/SolanaSwapProgram.js +769 -769
- package/dist/solana/swaps/SwapTypeEnum.d.ts +11 -11
- package/dist/solana/swaps/SwapTypeEnum.js +43 -43
- package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +95 -95
- package/dist/solana/swaps/modules/SolanaDataAccount.js +232 -232
- package/dist/solana/swaps/modules/SolanaLpVault.d.ts +69 -69
- package/dist/solana/swaps/modules/SolanaLpVault.js +171 -171
- package/dist/solana/swaps/modules/SwapClaim.d.ts +126 -126
- package/dist/solana/swaps/modules/SwapClaim.js +294 -294
- package/dist/solana/swaps/modules/SwapInit.d.ts +213 -213
- package/dist/solana/swaps/modules/SwapInit.js +658 -658
- package/dist/solana/swaps/modules/SwapRefund.d.ts +87 -87
- package/dist/solana/swaps/modules/SwapRefund.js +293 -293
- package/dist/solana/swaps/programIdl.json +945 -945
- package/dist/solana/swaps/programTypes.d.ts +943 -943
- package/dist/solana/swaps/programTypes.js +945 -945
- package/dist/solana/swaps/v1/programIdl.json +945 -945
- package/dist/solana/swaps/v1/programTypes.d.ts +943 -943
- package/dist/solana/swaps/v1/programTypes.js +945 -945
- package/dist/solana/swaps/v2/programIdl.json +952 -952
- package/dist/solana/swaps/v2/programTypes.d.ts +950 -950
- package/dist/solana/swaps/v2/programTypes.js +952 -952
- package/dist/solana/wallet/SolanaKeypairWallet.d.ts +29 -29
- package/dist/solana/wallet/SolanaKeypairWallet.js +50 -50
- package/dist/solana/wallet/SolanaSigner.d.ts +30 -30
- package/dist/solana/wallet/SolanaSigner.js +30 -30
- package/dist/utils/Utils.d.ts +58 -58
- package/dist/utils/Utils.js +170 -170
- package/node/index.d.ts +1 -1
- package/node/index.js +3 -3
- package/package.json +46 -46
- package/src/index.ts +87 -87
- package/src/node/index.ts +9 -9
- package/src/solana/SolanaChainType.ts +32 -32
- package/src/solana/SolanaChains.ts +46 -46
- package/src/solana/SolanaInitializer.ts +278 -278
- package/src/solana/btcrelay/SolanaBtcRelay.ts +615 -615
- package/src/solana/btcrelay/headers/SolanaBtcHeader.ts +116 -116
- package/src/solana/btcrelay/headers/SolanaBtcStoredHeader.ts +148 -148
- package/src/solana/btcrelay/program/programIdl.json +670 -670
- package/src/solana/chain/SolanaAction.ts +109 -109
- package/src/solana/chain/SolanaChainInterface.ts +404 -404
- package/src/solana/chain/SolanaModule.ts +20 -20
- package/src/solana/chain/modules/SolanaAddresses.ts +20 -20
- package/src/solana/chain/modules/SolanaBlocks.ts +89 -89
- package/src/solana/chain/modules/SolanaEvents.ts +271 -271
- package/src/solana/chain/modules/SolanaFees.ts +522 -522
- package/src/solana/chain/modules/SolanaSignatures.ts +39 -39
- package/src/solana/chain/modules/SolanaSlots.ts +85 -85
- package/src/solana/chain/modules/SolanaTokens.ts +300 -300
- package/src/solana/chain/modules/SolanaTransactions.ts +503 -503
- package/src/solana/connection/ConnectionWithRetries.ts +113 -96
- package/src/solana/events/SolanaChainEvents.ts +127 -127
- package/src/solana/events/SolanaChainEventsBrowser.ts +495 -495
- package/src/solana/program/SolanaProgramBase.ts +119 -119
- package/src/solana/program/SolanaProgramModule.ts +15 -15
- package/src/solana/program/modules/SolanaProgramEvents.ts +157 -157
- package/src/solana/swaps/SolanaSwapData.ts +735 -735
- package/src/solana/swaps/SolanaSwapModule.ts +19 -19
- package/src/solana/swaps/SolanaSwapProgram.ts +1074 -1074
- package/src/solana/swaps/SwapTypeEnum.ts +30 -30
- package/src/solana/swaps/modules/SolanaDataAccount.ts +302 -302
- package/src/solana/swaps/modules/SolanaLpVault.ts +208 -208
- package/src/solana/swaps/modules/SwapClaim.ts +387 -387
- package/src/solana/swaps/modules/SwapInit.ts +785 -785
- package/src/solana/swaps/modules/SwapRefund.ts +353 -353
- package/src/solana/swaps/v1/programIdl.json +944 -944
- package/src/solana/swaps/v1/programTypes.ts +1885 -1885
- package/src/solana/swaps/v2/programIdl.json +951 -951
- package/src/solana/swaps/v2/programTypes.ts +1899 -1899
- package/src/solana/wallet/SolanaKeypairWallet.ts +56 -56
- package/src/solana/wallet/SolanaSigner.ts +43 -43
- package/src/utils/Utils.ts +194 -194
|
@@ -1,275 +1,275 @@
|
|
|
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 base_1 = require("@atomiqlabs/base");
|
|
14
|
-
const SolanaAddresses_1 = require("./modules/SolanaAddresses");
|
|
15
|
-
const SolanaSigner_1 = require("../wallet/SolanaSigner");
|
|
16
|
-
const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
|
|
17
|
-
const SolanaChains_1 = require("../SolanaChains");
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
const bs58 = require("bs58");
|
|
20
|
-
const CLUSTER_BY_GENESIS_HASH = {
|
|
21
|
-
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d": "mainnet-beta",
|
|
22
|
-
"EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG": "devnet",
|
|
23
|
-
"4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY": "testnet",
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Main chain interface for interacting with Solana blockchain
|
|
27
|
-
* @category Chain Interface
|
|
28
|
-
*/
|
|
29
|
-
class SolanaChainInterface {
|
|
30
|
-
constructor(connection, retryPolicy, solanaFeeEstimator = new SolanaFees_1.SolanaFees(connection)) {
|
|
31
|
-
/**
|
|
32
|
-
* @inheritDoc
|
|
33
|
-
*/
|
|
34
|
-
this.chainId = "SOLANA";
|
|
35
|
-
/**
|
|
36
|
-
* Average Solana slot time in milliseconds.
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
this._SLOT_TIME = 400;
|
|
40
|
-
/**
|
|
41
|
-
* Approximate number of recent slots for which a transaction remains valid.
|
|
42
|
-
* @internal
|
|
43
|
-
*/
|
|
44
|
-
this._TX_SLOT_VALIDITY = 151;
|
|
45
|
-
/**
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
48
|
-
this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
|
|
49
|
-
this._connection = connection;
|
|
50
|
-
this._retryPolicy = retryPolicy;
|
|
51
|
-
this.Blocks = new SolanaBlocks_1.SolanaBlocks(this);
|
|
52
|
-
this.Fees = solanaFeeEstimator;
|
|
53
|
-
this.Slots = new SolanaSlots_1.SolanaSlots(this);
|
|
54
|
-
this.Tokens = new SolanaTokens_1.SolanaTokens(this);
|
|
55
|
-
this.Transactions = new SolanaTransactions_1.SolanaTransactions(this);
|
|
56
|
-
this.Signatures = new SolanaSignatures_1.SolanaSignatures(this);
|
|
57
|
-
this.Events = new SolanaEvents_1.SolanaEvents(this);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* @inheritDoc
|
|
61
|
-
*/
|
|
62
|
-
async getBalance(signer, tokenAddress) {
|
|
63
|
-
const token = new web3_js_1.PublicKey(tokenAddress);
|
|
64
|
-
const publicKey = new web3_js_1.PublicKey(signer);
|
|
65
|
-
let { balance } = await this.Tokens.getTokenBalance(publicKey, token);
|
|
66
|
-
if (token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS)) {
|
|
67
|
-
const accountRentExemptCost = 1000000n;
|
|
68
|
-
balance = balance - accountRentExemptCost;
|
|
69
|
-
if (balance < 0n)
|
|
70
|
-
balance = 0n;
|
|
71
|
-
}
|
|
72
|
-
this.logger.debug("getBalance(): token balance, token: " + token.toBase58() + " balance: " + balance.toString(10));
|
|
73
|
-
return balance;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* @inheritDoc
|
|
77
|
-
*/
|
|
78
|
-
isValidAddress(address) {
|
|
79
|
-
return SolanaAddresses_1.SolanaAddresses.isValidAddress(address);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* @inheritDoc
|
|
83
|
-
*/
|
|
84
|
-
normalizeAddress(address) {
|
|
85
|
-
return address;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* @inheritDoc
|
|
89
|
-
*/
|
|
90
|
-
getNativeCurrencyAddress() {
|
|
91
|
-
return this.Tokens.getNativeCurrencyAddress().toString();
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* @inheritDoc
|
|
95
|
-
*/
|
|
96
|
-
shouldGetNativeTokenDrop(tokenAddress) {
|
|
97
|
-
// True for all the tokens, because the contracts don't support native SOL handling yet
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* @inheritDoc
|
|
102
|
-
*/
|
|
103
|
-
txsTransfer(signer, token, amount, dstAddress, feeRate) {
|
|
104
|
-
return this.Tokens.txsTransfer(new web3_js_1.PublicKey(signer), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), feeRate);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* @inheritDoc
|
|
108
|
-
*/
|
|
109
|
-
async transfer(signer, token, amount, dstAddress, txOptions) {
|
|
110
|
-
const txs = await this.Tokens.txsTransfer(signer.getPublicKey(), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), txOptions?.feeRate);
|
|
111
|
-
const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
|
|
112
|
-
return txId;
|
|
113
|
-
}
|
|
114
|
-
////////////////////////////////////////////
|
|
115
|
-
//// Transactions
|
|
116
|
-
/**
|
|
117
|
-
* @inheritDoc
|
|
118
|
-
*/
|
|
119
|
-
sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
|
|
120
|
-
return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* @inheritDoc
|
|
124
|
-
*/
|
|
125
|
-
sendSignedAndConfirm(txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
|
|
126
|
-
return this.Transactions.sendSignedAndConfirm(txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* @inheritDoc
|
|
130
|
-
*/
|
|
131
|
-
async prepareTxs(txs) {
|
|
132
|
-
await this.Transactions.prepareTransactions(txs);
|
|
133
|
-
return txs;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* @inheritDoc
|
|
137
|
-
*/
|
|
138
|
-
serializeTx(tx) {
|
|
139
|
-
return Promise.resolve(this.Transactions.serializeUnsignedTx(tx));
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* @inheritDoc
|
|
143
|
-
*/
|
|
144
|
-
deserializeTx(txData) {
|
|
145
|
-
return Promise.resolve(this.Transactions.deserializeUnsignedTx(txData));
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* @inheritDoc
|
|
149
|
-
*/
|
|
150
|
-
serializeSignedTx(tx) {
|
|
151
|
-
return Promise.resolve(this.Transactions.serializeSignedTx(tx));
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* @inheritDoc
|
|
155
|
-
*/
|
|
156
|
-
deserializeSignedTx(txData) {
|
|
157
|
-
return Promise.resolve(this.Transactions.deserializeSignedTransaction(txData));
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* @inheritDoc
|
|
161
|
-
*/
|
|
162
|
-
getTxId(signedTX) {
|
|
163
|
-
return Promise.resolve(bs58.encode(signedTX.signature));
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* @inheritDoc
|
|
167
|
-
*/
|
|
168
|
-
getTxIdStatus(txId) {
|
|
169
|
-
return this.Transactions.getTxIdStatus(txId);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* @inheritDoc
|
|
173
|
-
*/
|
|
174
|
-
getTxStatus(tx) {
|
|
175
|
-
return this.Transactions.getTxStatus(tx);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* @inheritDoc
|
|
179
|
-
*/
|
|
180
|
-
async getFinalizedBlock() {
|
|
181
|
-
const { block } = await this.Blocks.findLatestParsedBlock("finalized");
|
|
182
|
-
return {
|
|
183
|
-
height: block.blockHeight,
|
|
184
|
-
blockHash: block.blockhash
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
///////////////////////////////////
|
|
188
|
-
//// Callbacks & handlers
|
|
189
|
-
/**
|
|
190
|
-
* @inheritDoc
|
|
191
|
-
*/
|
|
192
|
-
offBeforeTxReplace(callback) {
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* @inheritDoc
|
|
197
|
-
*/
|
|
198
|
-
onBeforeTxReplace(callback) { }
|
|
199
|
-
/**
|
|
200
|
-
* @inheritDoc
|
|
201
|
-
*/
|
|
202
|
-
onBeforeTxSigned(callback) {
|
|
203
|
-
this.Transactions.onBeforeTxSigned(callback);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* @inheritDoc
|
|
207
|
-
*/
|
|
208
|
-
offBeforeTxSigned(callback) {
|
|
209
|
-
return this.Transactions.offBeforeTxSigned(callback);
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Registers a low-level transaction sender override hook.
|
|
213
|
-
*
|
|
214
|
-
* @param callback Callback used for raw transaction publishing
|
|
215
|
-
*/
|
|
216
|
-
onSendTransaction(callback) {
|
|
217
|
-
this.Transactions.onSendTransaction(callback);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Unregisters a previously registered transaction sender override hook.
|
|
221
|
-
*
|
|
222
|
-
* @param callback Previously registered callback
|
|
223
|
-
*/
|
|
224
|
-
offSendTransaction(callback) {
|
|
225
|
-
return this.Transactions.offSendTransaction(callback);
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* @inheritDoc
|
|
229
|
-
*/
|
|
230
|
-
isValidToken(tokenIdentifier) {
|
|
231
|
-
try {
|
|
232
|
-
new web3_js_1.PublicKey(tokenIdentifier);
|
|
233
|
-
return true;
|
|
234
|
-
}
|
|
235
|
-
catch (e) {
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* @inheritDoc
|
|
241
|
-
*/
|
|
242
|
-
randomAddress() {
|
|
243
|
-
return web3_js_1.Keypair.generate().publicKey.toString();
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* @inheritDoc
|
|
247
|
-
*/
|
|
248
|
-
randomSigner() {
|
|
249
|
-
const keypair = web3_js_1.Keypair.generate();
|
|
250
|
-
const wallet = new SolanaKeypairWallet_1.SolanaKeypairWallet(keypair);
|
|
251
|
-
return new SolanaSigner_1.SolanaSigner(wallet, keypair);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* @inheritDoc
|
|
255
|
-
*/
|
|
256
|
-
wrapSigner(signer) {
|
|
257
|
-
return Promise.resolve(new SolanaSigner_1.SolanaSigner(signer));
|
|
258
|
-
}
|
|
259
|
-
async verifyNetwork(bitcoinNetwork) {
|
|
260
|
-
const genesisHash = await this._connection.getGenesisHash();
|
|
261
|
-
const result = CLUSTER_BY_GENESIS_HASH[genesisHash];
|
|
262
|
-
if (result == null) {
|
|
263
|
-
this.logger.warn(`verifyNetwork(): Unknown cluster detected, genesis hash: ${genesisHash}`);
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
const deployment = SolanaChains_1.SolanaChains[bitcoinNetwork];
|
|
267
|
-
if (deployment == null) {
|
|
268
|
-
this.logger.warn(`verifyNetwork(): No Solana deployment is defined for ${base_1.BitcoinNetwork[bitcoinNetwork]}, the RPC check is skipped.`);
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
if (deployment.clusterName !== result)
|
|
272
|
-
throw new Error(`Expected ${deployment.clusterName} Solana cluster for ${base_1.BitcoinNetwork[bitcoinNetwork]}, but got ${result}!`);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
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 base_1 = require("@atomiqlabs/base");
|
|
14
|
+
const SolanaAddresses_1 = require("./modules/SolanaAddresses");
|
|
15
|
+
const SolanaSigner_1 = require("../wallet/SolanaSigner");
|
|
16
|
+
const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
|
|
17
|
+
const SolanaChains_1 = require("../SolanaChains");
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const bs58 = require("bs58");
|
|
20
|
+
const CLUSTER_BY_GENESIS_HASH = {
|
|
21
|
+
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d": "mainnet-beta",
|
|
22
|
+
"EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG": "devnet",
|
|
23
|
+
"4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY": "testnet",
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Main chain interface for interacting with Solana blockchain
|
|
27
|
+
* @category Chain Interface
|
|
28
|
+
*/
|
|
29
|
+
class SolanaChainInterface {
|
|
30
|
+
constructor(connection, retryPolicy, solanaFeeEstimator = new SolanaFees_1.SolanaFees(connection)) {
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
this.chainId = "SOLANA";
|
|
35
|
+
/**
|
|
36
|
+
* Average Solana slot time in milliseconds.
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
this._SLOT_TIME = 400;
|
|
40
|
+
/**
|
|
41
|
+
* Approximate number of recent slots for which a transaction remains valid.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
this._TX_SLOT_VALIDITY = 151;
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
|
|
49
|
+
this._connection = connection;
|
|
50
|
+
this._retryPolicy = retryPolicy;
|
|
51
|
+
this.Blocks = new SolanaBlocks_1.SolanaBlocks(this);
|
|
52
|
+
this.Fees = solanaFeeEstimator;
|
|
53
|
+
this.Slots = new SolanaSlots_1.SolanaSlots(this);
|
|
54
|
+
this.Tokens = new SolanaTokens_1.SolanaTokens(this);
|
|
55
|
+
this.Transactions = new SolanaTransactions_1.SolanaTransactions(this);
|
|
56
|
+
this.Signatures = new SolanaSignatures_1.SolanaSignatures(this);
|
|
57
|
+
this.Events = new SolanaEvents_1.SolanaEvents(this);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @inheritDoc
|
|
61
|
+
*/
|
|
62
|
+
async getBalance(signer, tokenAddress) {
|
|
63
|
+
const token = new web3_js_1.PublicKey(tokenAddress);
|
|
64
|
+
const publicKey = new web3_js_1.PublicKey(signer);
|
|
65
|
+
let { balance } = await this.Tokens.getTokenBalance(publicKey, token);
|
|
66
|
+
if (token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS)) {
|
|
67
|
+
const accountRentExemptCost = 1000000n;
|
|
68
|
+
balance = balance - accountRentExemptCost;
|
|
69
|
+
if (balance < 0n)
|
|
70
|
+
balance = 0n;
|
|
71
|
+
}
|
|
72
|
+
this.logger.debug("getBalance(): token balance, token: " + token.toBase58() + " balance: " + balance.toString(10));
|
|
73
|
+
return balance;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @inheritDoc
|
|
77
|
+
*/
|
|
78
|
+
isValidAddress(address) {
|
|
79
|
+
return SolanaAddresses_1.SolanaAddresses.isValidAddress(address);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @inheritDoc
|
|
83
|
+
*/
|
|
84
|
+
normalizeAddress(address) {
|
|
85
|
+
return address;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @inheritDoc
|
|
89
|
+
*/
|
|
90
|
+
getNativeCurrencyAddress() {
|
|
91
|
+
return this.Tokens.getNativeCurrencyAddress().toString();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @inheritDoc
|
|
95
|
+
*/
|
|
96
|
+
shouldGetNativeTokenDrop(tokenAddress) {
|
|
97
|
+
// True for all the tokens, because the contracts don't support native SOL handling yet
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @inheritDoc
|
|
102
|
+
*/
|
|
103
|
+
txsTransfer(signer, token, amount, dstAddress, feeRate) {
|
|
104
|
+
return this.Tokens.txsTransfer(new web3_js_1.PublicKey(signer), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), feeRate);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @inheritDoc
|
|
108
|
+
*/
|
|
109
|
+
async transfer(signer, token, amount, dstAddress, txOptions) {
|
|
110
|
+
const txs = await this.Tokens.txsTransfer(signer.getPublicKey(), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), txOptions?.feeRate);
|
|
111
|
+
const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
|
|
112
|
+
return txId;
|
|
113
|
+
}
|
|
114
|
+
////////////////////////////////////////////
|
|
115
|
+
//// Transactions
|
|
116
|
+
/**
|
|
117
|
+
* @inheritDoc
|
|
118
|
+
*/
|
|
119
|
+
sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
|
|
120
|
+
return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @inheritDoc
|
|
124
|
+
*/
|
|
125
|
+
sendSignedAndConfirm(txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
|
|
126
|
+
return this.Transactions.sendSignedAndConfirm(txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @inheritDoc
|
|
130
|
+
*/
|
|
131
|
+
async prepareTxs(txs) {
|
|
132
|
+
await this.Transactions.prepareTransactions(txs);
|
|
133
|
+
return txs;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @inheritDoc
|
|
137
|
+
*/
|
|
138
|
+
serializeTx(tx) {
|
|
139
|
+
return Promise.resolve(this.Transactions.serializeUnsignedTx(tx));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @inheritDoc
|
|
143
|
+
*/
|
|
144
|
+
deserializeTx(txData) {
|
|
145
|
+
return Promise.resolve(this.Transactions.deserializeUnsignedTx(txData));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @inheritDoc
|
|
149
|
+
*/
|
|
150
|
+
serializeSignedTx(tx) {
|
|
151
|
+
return Promise.resolve(this.Transactions.serializeSignedTx(tx));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @inheritDoc
|
|
155
|
+
*/
|
|
156
|
+
deserializeSignedTx(txData) {
|
|
157
|
+
return Promise.resolve(this.Transactions.deserializeSignedTransaction(txData));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @inheritDoc
|
|
161
|
+
*/
|
|
162
|
+
getTxId(signedTX) {
|
|
163
|
+
return Promise.resolve(bs58.encode(signedTX.signature));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @inheritDoc
|
|
167
|
+
*/
|
|
168
|
+
getTxIdStatus(txId) {
|
|
169
|
+
return this.Transactions.getTxIdStatus(txId);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* @inheritDoc
|
|
173
|
+
*/
|
|
174
|
+
getTxStatus(tx) {
|
|
175
|
+
return this.Transactions.getTxStatus(tx);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* @inheritDoc
|
|
179
|
+
*/
|
|
180
|
+
async getFinalizedBlock() {
|
|
181
|
+
const { block } = await this.Blocks.findLatestParsedBlock("finalized");
|
|
182
|
+
return {
|
|
183
|
+
height: block.blockHeight,
|
|
184
|
+
blockHash: block.blockhash
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
///////////////////////////////////
|
|
188
|
+
//// Callbacks & handlers
|
|
189
|
+
/**
|
|
190
|
+
* @inheritDoc
|
|
191
|
+
*/
|
|
192
|
+
offBeforeTxReplace(callback) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* @inheritDoc
|
|
197
|
+
*/
|
|
198
|
+
onBeforeTxReplace(callback) { }
|
|
199
|
+
/**
|
|
200
|
+
* @inheritDoc
|
|
201
|
+
*/
|
|
202
|
+
onBeforeTxSigned(callback) {
|
|
203
|
+
this.Transactions.onBeforeTxSigned(callback);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* @inheritDoc
|
|
207
|
+
*/
|
|
208
|
+
offBeforeTxSigned(callback) {
|
|
209
|
+
return this.Transactions.offBeforeTxSigned(callback);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Registers a low-level transaction sender override hook.
|
|
213
|
+
*
|
|
214
|
+
* @param callback Callback used for raw transaction publishing
|
|
215
|
+
*/
|
|
216
|
+
onSendTransaction(callback) {
|
|
217
|
+
this.Transactions.onSendTransaction(callback);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Unregisters a previously registered transaction sender override hook.
|
|
221
|
+
*
|
|
222
|
+
* @param callback Previously registered callback
|
|
223
|
+
*/
|
|
224
|
+
offSendTransaction(callback) {
|
|
225
|
+
return this.Transactions.offSendTransaction(callback);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* @inheritDoc
|
|
229
|
+
*/
|
|
230
|
+
isValidToken(tokenIdentifier) {
|
|
231
|
+
try {
|
|
232
|
+
new web3_js_1.PublicKey(tokenIdentifier);
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* @inheritDoc
|
|
241
|
+
*/
|
|
242
|
+
randomAddress() {
|
|
243
|
+
return web3_js_1.Keypair.generate().publicKey.toString();
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* @inheritDoc
|
|
247
|
+
*/
|
|
248
|
+
randomSigner() {
|
|
249
|
+
const keypair = web3_js_1.Keypair.generate();
|
|
250
|
+
const wallet = new SolanaKeypairWallet_1.SolanaKeypairWallet(keypair);
|
|
251
|
+
return new SolanaSigner_1.SolanaSigner(wallet, keypair);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* @inheritDoc
|
|
255
|
+
*/
|
|
256
|
+
wrapSigner(signer) {
|
|
257
|
+
return Promise.resolve(new SolanaSigner_1.SolanaSigner(signer));
|
|
258
|
+
}
|
|
259
|
+
async verifyNetwork(bitcoinNetwork) {
|
|
260
|
+
const genesisHash = await this._connection.getGenesisHash();
|
|
261
|
+
const result = CLUSTER_BY_GENESIS_HASH[genesisHash];
|
|
262
|
+
if (result == null) {
|
|
263
|
+
this.logger.warn(`verifyNetwork(): Unknown cluster detected, genesis hash: ${genesisHash}`);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const deployment = SolanaChains_1.SolanaChains[bitcoinNetwork];
|
|
267
|
+
if (deployment == null) {
|
|
268
|
+
this.logger.warn(`verifyNetwork(): No Solana deployment is defined for ${base_1.BitcoinNetwork[bitcoinNetwork]}, the RPC check is skipped.`);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (deployment.clusterName !== result)
|
|
272
|
+
throw new Error(`Expected ${deployment.clusterName} Solana cluster for ${base_1.BitcoinNetwork[bitcoinNetwork]}, but got ${result}!`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
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: 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
|
+
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;
|