@atomiqlabs/chain-solana 7.3.8 → 8.0.0-beta.0

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 (57) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/solana/SolanaChains.d.ts +14 -0
  4. package/dist/solana/SolanaChains.js +18 -0
  5. package/dist/solana/SolanaInitializer.d.ts +18 -0
  6. package/dist/solana/SolanaInitializer.js +59 -0
  7. package/dist/solana/base/SolanaAction.js +25 -38
  8. package/dist/solana/base/modules/SolanaBlocks.js +18 -29
  9. package/dist/solana/base/modules/SolanaEvents.js +15 -26
  10. package/dist/solana/base/modules/SolanaFees.d.ts +4 -5
  11. package/dist/solana/base/modules/SolanaFees.js +168 -182
  12. package/dist/solana/base/modules/SolanaSlots.js +16 -29
  13. package/dist/solana/base/modules/SolanaTokens.d.ts +6 -7
  14. package/dist/solana/base/modules/SolanaTokens.js +63 -84
  15. package/dist/solana/base/modules/SolanaTransactions.d.ts +2 -2
  16. package/dist/solana/base/modules/SolanaTransactions.js +143 -165
  17. package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +2 -3
  18. package/dist/solana/btcrelay/SolanaBtcRelay.js +185 -221
  19. package/dist/solana/events/SolanaChainEvents.js +113 -138
  20. package/dist/solana/events/SolanaChainEventsBrowser.js +56 -65
  21. package/dist/solana/program/modules/SolanaProgramEvents.js +13 -24
  22. package/dist/solana/swaps/SolanaSwapData.d.ts +15 -11
  23. package/dist/solana/swaps/SolanaSwapData.js +29 -13
  24. package/dist/solana/swaps/SolanaSwapProgram.d.ts +40 -41
  25. package/dist/solana/swaps/SolanaSwapProgram.js +212 -221
  26. package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +2 -3
  27. package/dist/solana/swaps/modules/SolanaDataAccount.js +117 -141
  28. package/dist/solana/swaps/modules/SolanaLpVault.d.ts +4 -5
  29. package/dist/solana/swaps/modules/SolanaLpVault.js +87 -110
  30. package/dist/solana/swaps/modules/SwapClaim.d.ts +4 -4
  31. package/dist/solana/swaps/modules/SwapClaim.js +122 -134
  32. package/dist/solana/swaps/modules/SwapInit.d.ts +2 -3
  33. package/dist/solana/swaps/modules/SwapInit.js +254 -285
  34. package/dist/solana/swaps/modules/SwapRefund.d.ts +2 -3
  35. package/dist/solana/swaps/modules/SwapRefund.js +103 -113
  36. package/dist/utils/Utils.d.ts +10 -0
  37. package/dist/utils/Utils.js +62 -35
  38. package/package.json +9 -6
  39. package/src/index.ts +1 -0
  40. package/src/solana/SolanaChains.ts +16 -0
  41. package/src/solana/SolanaInitializer.ts +98 -0
  42. package/src/solana/base/SolanaBase.ts +1 -2
  43. package/src/solana/base/modules/SolanaEvents.ts +0 -1
  44. package/src/solana/base/modules/SolanaFees.ts +35 -31
  45. package/src/solana/base/modules/SolanaTokens.ts +26 -27
  46. package/src/solana/base/modules/SolanaTransactions.ts +33 -28
  47. package/src/solana/btcrelay/SolanaBtcRelay.ts +6 -10
  48. package/src/solana/events/SolanaChainEventsBrowser.ts +14 -10
  49. package/src/solana/program/modules/SolanaProgramEvents.ts +1 -1
  50. package/src/solana/swaps/SolanaSwapData.ts +38 -19
  51. package/src/solana/swaps/SolanaSwapProgram.ts +133 -105
  52. package/src/solana/swaps/modules/SolanaDataAccount.ts +4 -6
  53. package/src/solana/swaps/modules/SolanaLpVault.ts +18 -18
  54. package/src/solana/swaps/modules/SwapClaim.ts +14 -17
  55. package/src/solana/swaps/modules/SwapInit.ts +35 -38
  56. package/src/solana/swaps/modules/SwapRefund.ts +20 -23
  57. package/src/utils/Utils.ts +35 -0
@@ -6,7 +6,6 @@ import { SolanaTx } from "../../base/modules/SolanaTransactions";
6
6
  import { SolanaBtcStoredHeader } from "../../btcrelay/headers/SolanaBtcStoredHeader";
7
7
  import { SolanaBtcRelay } from "../../btcrelay/SolanaBtcRelay";
8
8
  import { SolanaSwapProgram } from "../SolanaSwapProgram";
9
- import * as BN from "bn.js";
10
9
  import { SolanaSigner } from "../../wallet/SolanaSigner";
11
10
  export declare class SwapClaim extends SolanaSwapModule {
12
11
  private static readonly CUCosts;
@@ -107,11 +106,12 @@ export declare class SwapClaim extends SolanaSwapModule {
107
106
  * @param storageAccHolder an object holder filled in with the created data account where tx data is written
108
107
  * @param feeRate fee rate to be used for the transactions
109
108
  */
110
- txsClaimWithTxData(signer: PublicKey | SolanaSigner, swapData: SolanaSwapData, blockheight: number, tx: {
109
+ txsClaimWithTxData(signer: PublicKey | SolanaSigner, swapData: SolanaSwapData, tx: {
111
110
  blockhash: string;
112
111
  confirmations: number;
113
112
  txid: string;
114
113
  hex: string;
114
+ height: number;
115
115
  }, vout: number, commitedHeader?: SolanaBtcStoredHeader, synchronizer?: RelaySynchronizer<any, SolanaTx, any>, initAta?: boolean, storageAccHolder?: {
116
116
  storageAcc: PublicKey;
117
117
  }, feeRate?: string): Promise<SolanaTx[] | null>;
@@ -120,9 +120,9 @@ export declare class SwapClaim extends SolanaSwapModule {
120
120
  * Get the estimated solana transaction fee of the claim transaction in the worst case scenario in case where the
121
121
  * ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee)
122
122
  */
123
- getClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<BN>;
123
+ getClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
124
124
  /**
125
125
  * Get the estimated solana transaction fee of the claim transaction, without
126
126
  */
127
- getRawClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<BN>;
127
+ getRawClaimFee(signer: PublicKey, swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
128
128
  }
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.SwapClaim = void 0;
13
4
  const SolanaSwapModule_1 = require("../SolanaSwapModule");
@@ -16,35 +7,43 @@ const spl_token_1 = require("@solana/spl-token");
16
7
  const base_1 = require("@atomiqlabs/base");
17
8
  const web3_js_1 = require("@solana/web3.js");
18
9
  const Utils_1 = require("../../../utils/Utils");
19
- const BN = require("bn.js");
20
10
  const SolanaSigner_1 = require("../../wallet/SolanaSigner");
11
+ const SolanaTokens_1 = require("../../base/modules/SolanaTokens");
12
+ const BN = require("bn.js");
21
13
  class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
22
- Claim(signer, swapData, secretOrDataKey) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const isDataKey = typeof (secretOrDataKey) !== "string";
25
- const accounts = {
26
- signer,
27
- initializer: swapData.isPayIn() ? swapData.offerer : swapData.claimer,
28
- escrowState: this.root.SwapEscrowState(Buffer.from(swapData.paymentHash, "hex")),
29
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
30
- data: isDataKey ? secretOrDataKey : null,
31
- };
32
- let secretBuffer = isDataKey ?
33
- Buffer.alloc(0) :
34
- Buffer.from(secretOrDataKey, "hex");
35
- if (swapData.isPayOut()) {
36
- return new SolanaAction_1.SolanaAction(signer, this.root, yield this.program.methods
37
- .claimerClaimPayOut(secretBuffer)
38
- .accounts(Object.assign(Object.assign({}, accounts), { claimerAta: swapData.claimerAta, vault: this.root.SwapVault(swapData.token), vaultAuthority: this.root.SwapVaultAuthority, tokenProgram: spl_token_1.TOKEN_PROGRAM_ID }))
39
- .instruction(), this.getComputeBudget(swapData));
40
- }
41
- else {
42
- return new SolanaAction_1.SolanaAction(signer, this.root, yield this.program.methods
43
- .claimerClaim(secretBuffer)
44
- .accounts(Object.assign(Object.assign({}, accounts), { claimerUserData: this.root.SwapUserVault(swapData.claimer, swapData.token) }))
45
- .instruction(), this.getComputeBudget(swapData));
46
- }
47
- });
14
+ async Claim(signer, swapData, secretOrDataKey) {
15
+ const isDataKey = typeof (secretOrDataKey) !== "string";
16
+ const accounts = {
17
+ signer,
18
+ initializer: swapData.isPayIn() ? swapData.offerer : swapData.claimer,
19
+ escrowState: this.root.SwapEscrowState(Buffer.from(swapData.paymentHash, "hex")),
20
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
21
+ data: isDataKey ? secretOrDataKey : null,
22
+ };
23
+ let secretBuffer = isDataKey ?
24
+ Buffer.alloc(0) :
25
+ Buffer.from(secretOrDataKey, "hex");
26
+ if (swapData.isPayOut()) {
27
+ return new SolanaAction_1.SolanaAction(signer, this.root, await this.program.methods
28
+ .claimerClaimPayOut(secretBuffer)
29
+ .accounts({
30
+ ...accounts,
31
+ claimerAta: swapData.claimerAta,
32
+ vault: this.root.SwapVault(swapData.token),
33
+ vaultAuthority: this.root.SwapVaultAuthority,
34
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
35
+ })
36
+ .instruction(), this.getComputeBudget(swapData));
37
+ }
38
+ else {
39
+ return new SolanaAction_1.SolanaAction(signer, this.root, await this.program.methods
40
+ .claimerClaim(secretBuffer)
41
+ .accounts({
42
+ ...accounts,
43
+ claimerUserData: this.root.SwapUserVault(swapData.claimer, swapData.token)
44
+ })
45
+ .instruction(), this.getComputeBudget(swapData));
46
+ }
48
47
  }
49
48
  /**
50
49
  * Verify and claim action required for BTC on-chain swaps verified through btc relay, adds the btc relay verify
@@ -59,13 +58,11 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
59
58
  * @constructor
60
59
  * @private
61
60
  */
62
- VerifyAndClaim(signer, swapData, storeDataKey, merkleProof, commitedHeader) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- const action = yield this.btcRelay.Verify(signer, merkleProof.reversedTxId, swapData.confirmations, merkleProof.pos, merkleProof.merkle, commitedHeader);
65
- action.addAction(yield this.Claim(signer, swapData, storeDataKey));
66
- action.computeBudget = null;
67
- return action;
68
- });
61
+ async VerifyAndClaim(signer, swapData, storeDataKey, merkleProof, commitedHeader) {
62
+ const action = await this.btcRelay.Verify(signer, merkleProof.reversedTxId, swapData.confirmations, merkleProof.pos, merkleProof.merkle, commitedHeader);
63
+ action.addAction(await this.Claim(signer, swapData, storeDataKey));
64
+ action.computeBudget = null;
65
+ return action;
69
66
  }
70
67
  constructor(root, btcRelay) {
71
68
  super(root);
@@ -101,26 +98,24 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
101
98
  * to the required blockheight
102
99
  * @private
103
100
  */
104
- getCommitedHeaderAndSynchronize(signer, txBlockheight, requiredConfirmations, blockhash, txs, synchronizer) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- const requiredBlockheight = txBlockheight + requiredConfirmations - 1;
107
- const result = yield (0, Utils_1.tryWithRetries)(() => this.btcRelay.retrieveLogAndBlockheight({
108
- blockhash: blockhash
109
- }, requiredBlockheight), this.retryPolicy);
110
- if (result != null)
111
- return result.header;
112
- //Need to synchronize
113
- if (synchronizer == null)
114
- return null;
115
- //TODO: We don't have to synchronize to tip, only to our required blockheight
116
- const resp = yield synchronizer.syncToLatestTxs(signer.toString());
117
- this.logger.debug("getCommitedHeaderAndSynchronize(): BTC Relay not synchronized to required blockheight, " +
118
- "synchronizing ourselves in " + resp.txs.length + " txs");
119
- this.logger.debug("getCommitedHeaderAndSynchronize(): BTC Relay computed header map: ", resp.computedHeaderMap);
120
- resp.txs.forEach(tx => txs.push(tx));
121
- //Retrieve computed header
122
- return resp.computedHeaderMap[txBlockheight];
123
- });
101
+ async getCommitedHeaderAndSynchronize(signer, txBlockheight, requiredConfirmations, blockhash, txs, synchronizer) {
102
+ const requiredBlockheight = txBlockheight + requiredConfirmations - 1;
103
+ const result = await (0, Utils_1.tryWithRetries)(() => this.btcRelay.retrieveLogAndBlockheight({
104
+ blockhash: blockhash
105
+ }, requiredBlockheight), this.retryPolicy);
106
+ if (result != null)
107
+ return result.header;
108
+ //Need to synchronize
109
+ if (synchronizer == null)
110
+ return null;
111
+ //TODO: We don't have to synchronize to tip, only to our required blockheight
112
+ const resp = await synchronizer.syncToLatestTxs(signer.toString());
113
+ this.logger.debug("getCommitedHeaderAndSynchronize(): BTC Relay not synchronized to required blockheight, " +
114
+ "synchronizing ourselves in " + resp.txs.length + " txs");
115
+ this.logger.debug("getCommitedHeaderAndSynchronize(): BTC Relay computed header map: ", resp.computedHeaderMap);
116
+ resp.txs.forEach(tx => txs.push(tx));
117
+ //Retrieve computed header
118
+ return resp.computedHeaderMap[txBlockheight];
124
119
  }
125
120
  /**
126
121
  * Adds the transactions required for initialization and writing of transaction data to the data account
@@ -151,7 +146,7 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
151
146
  */
152
147
  shouldUnwrap(signer, swapData) {
153
148
  return swapData.isPayOut() &&
154
- swapData.token.equals(this.root.Tokens.WSOL_ADDRESS) &&
149
+ swapData.token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS) &&
155
150
  swapData.claimer.equals(signer);
156
151
  }
157
152
  /**
@@ -166,33 +161,31 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
166
161
  * @param feeRate fee rate to use for the transaction
167
162
  * @param skipAtaCheck whether to check if ATA exists
168
163
  */
169
- txsClaimWithSecret(signer, swapData, secret, checkExpiry, initAta, feeRate, skipAtaCheck) {
170
- return __awaiter(this, void 0, void 0, function* () {
171
- //We need to be sure that this transaction confirms in time, otherwise we reveal the secret to the counterparty
172
- // and won't claim the funds
173
- if (checkExpiry && this.root.isExpired(swapData.claimer.toString(), swapData)) {
174
- throw new base_1.SwapDataVerificationError("Not enough time to reliably pay the invoice");
175
- }
176
- const shouldInitAta = !skipAtaCheck && swapData.isPayOut() && !(yield this.root.Tokens.ataExists(swapData.claimerAta));
177
- if (shouldInitAta && !initAta)
178
- throw new base_1.SwapDataVerificationError("ATA not initialized");
179
- if (feeRate == null)
180
- feeRate = yield this.getClaimFeeRate(signer, swapData);
181
- const action = new SolanaAction_1.SolanaAction(signer, this.root);
182
- const shouldUnwrap = this.shouldUnwrap(signer, swapData);
183
- if (shouldInitAta) {
184
- const initAction = this.root.Tokens.InitAta(signer, swapData.claimer, swapData.token, swapData.claimerAta);
185
- if (initAction == null)
186
- throw new base_1.SwapDataVerificationError("Invalid claimer token account address");
187
- action.add(initAction);
188
- }
189
- action.add(yield this.Claim(signer, swapData, secret));
190
- if (shouldUnwrap)
191
- action.add(this.root.Tokens.Unwrap(signer));
192
- this.logger.debug("txsClaimWithSecret(): creating claim transaction, swap: " + swapData.getHash() +
193
- " initializingAta: " + shouldInitAta + " unwrapping: " + shouldUnwrap);
194
- return [yield action.tx(feeRate)];
195
- });
164
+ async txsClaimWithSecret(signer, swapData, secret, checkExpiry, initAta, feeRate, skipAtaCheck) {
165
+ //We need to be sure that this transaction confirms in time, otherwise we reveal the secret to the counterparty
166
+ // and won't claim the funds
167
+ if (checkExpiry && await this.root.isExpired(swapData.claimer.toString(), swapData)) {
168
+ throw new base_1.SwapDataVerificationError("Not enough time to reliably pay the invoice");
169
+ }
170
+ const shouldInitAta = !skipAtaCheck && swapData.isPayOut() && !await this.root.Tokens.ataExists(swapData.claimerAta);
171
+ if (shouldInitAta && !initAta)
172
+ throw new base_1.SwapDataVerificationError("ATA not initialized");
173
+ if (feeRate == null)
174
+ feeRate = await this.getClaimFeeRate(signer, swapData);
175
+ const action = new SolanaAction_1.SolanaAction(signer, this.root);
176
+ const shouldUnwrap = this.shouldUnwrap(signer, swapData);
177
+ if (shouldInitAta) {
178
+ const initAction = this.root.Tokens.InitAta(signer, swapData.claimer, swapData.token, swapData.claimerAta);
179
+ if (initAction == null)
180
+ throw new base_1.SwapDataVerificationError("Invalid claimer token account address");
181
+ action.add(initAction);
182
+ }
183
+ action.add(await this.Claim(signer, swapData, secret));
184
+ if (shouldUnwrap)
185
+ action.add(this.root.Tokens.Unwrap(signer));
186
+ this.logger.debug("txsClaimWithSecret(): creating claim transaction, swap: " + swapData.getClaimHash() +
187
+ " initializingAta: " + shouldInitAta + " unwrapping: " + shouldUnwrap);
188
+ return [await action.tx(feeRate)];
196
189
  }
197
190
  /**
198
191
  * Creates transaction claiming the swap using a confirmed transaction data (for BTC on-chain swaps)
@@ -208,37 +201,35 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
208
201
  * @param storageAccHolder an object holder filled in with the created data account where tx data is written
209
202
  * @param feeRate fee rate to be used for the transactions
210
203
  */
211
- txsClaimWithTxData(signer, swapData, blockheight, tx, vout, commitedHeader, synchronizer, initAta, storageAccHolder, feeRate) {
212
- return __awaiter(this, void 0, void 0, function* () {
213
- const shouldInitAta = swapData.isPayOut() && !(yield this.root.Tokens.ataExists(swapData.claimerAta));
214
- if (shouldInitAta && !initAta)
215
- throw new base_1.SwapDataVerificationError("ATA not initialized");
216
- const signerKey = signer instanceof SolanaSigner_1.SolanaSigner ? signer.getPublicKey() : signer;
217
- if (feeRate == null)
218
- feeRate = yield this.getClaimFeeRate(signerKey, swapData);
219
- const merkleProof = yield this.btcRelay.bitcoinRpc.getMerkleProof(tx.txid, tx.blockhash);
220
- this.logger.debug("txsClaimWithTxData(): merkle proof computed: ", merkleProof);
221
- const txs = [];
222
- if (commitedHeader == null)
223
- commitedHeader = yield this.getCommitedHeaderAndSynchronize(signerKey, blockheight, swapData.getConfirmations(), tx.blockhash, txs, synchronizer);
224
- const storeDataKey = yield this.addTxsWriteTransactionData(signer, tx, vout, feeRate, txs);
225
- if (storageAccHolder != null)
226
- storageAccHolder.storageAcc = storeDataKey;
227
- const shouldUnwrap = this.shouldUnwrap(signerKey, swapData);
228
- if (shouldInitAta) {
229
- const initAction = this.root.Tokens.InitAta(signerKey, swapData.claimer, swapData.token, swapData.claimerAta);
230
- if (initAction == null)
231
- throw new base_1.SwapDataVerificationError("Invalid claimer token account address");
232
- yield initAction.addToTxs(txs, feeRate);
233
- }
234
- const claimAction = yield this.VerifyAndClaim(signerKey, swapData, storeDataKey, merkleProof, commitedHeader);
235
- yield claimAction.addToTxs(txs, feeRate);
236
- if (shouldUnwrap)
237
- yield this.root.Tokens.Unwrap(signerKey).addToTxs(txs, feeRate);
238
- this.logger.debug("txsClaimWithTxData(): creating claim transaction, swap: " + swapData.getHash() +
239
- " initializingAta: " + shouldInitAta + " unwrapping: " + shouldUnwrap + " num txns: " + txs.length);
240
- return txs;
241
- });
204
+ async txsClaimWithTxData(signer, swapData, tx, vout, commitedHeader, synchronizer, initAta, storageAccHolder, feeRate) {
205
+ const shouldInitAta = swapData.isPayOut() && !await this.root.Tokens.ataExists(swapData.claimerAta);
206
+ if (shouldInitAta && !initAta)
207
+ throw new base_1.SwapDataVerificationError("ATA not initialized");
208
+ const signerKey = signer instanceof SolanaSigner_1.SolanaSigner ? signer.getPublicKey() : signer;
209
+ if (feeRate == null)
210
+ feeRate = await this.getClaimFeeRate(signerKey, swapData);
211
+ const merkleProof = await this.btcRelay.bitcoinRpc.getMerkleProof(tx.txid, tx.blockhash);
212
+ this.logger.debug("txsClaimWithTxData(): merkle proof computed: ", merkleProof);
213
+ const txs = [];
214
+ if (commitedHeader == null)
215
+ commitedHeader = await this.getCommitedHeaderAndSynchronize(signerKey, tx.height, swapData.confirmations, tx.blockhash, txs, synchronizer);
216
+ const storeDataKey = await this.addTxsWriteTransactionData(signer, tx, vout, feeRate, txs);
217
+ if (storageAccHolder != null)
218
+ storageAccHolder.storageAcc = storeDataKey;
219
+ const shouldUnwrap = this.shouldUnwrap(signerKey, swapData);
220
+ if (shouldInitAta) {
221
+ const initAction = this.root.Tokens.InitAta(signerKey, swapData.claimer, swapData.token, swapData.claimerAta);
222
+ if (initAction == null)
223
+ throw new base_1.SwapDataVerificationError("Invalid claimer token account address");
224
+ await initAction.addToTxs(txs, feeRate);
225
+ }
226
+ const claimAction = await this.VerifyAndClaim(signerKey, swapData, storeDataKey, merkleProof, commitedHeader);
227
+ await claimAction.addToTxs(txs, feeRate);
228
+ if (shouldUnwrap)
229
+ await this.root.Tokens.Unwrap(signerKey).addToTxs(txs, feeRate);
230
+ this.logger.debug("txsClaimWithTxData(): creating claim transaction, swap: " + swapData.getClaimHash() +
231
+ " initializingAta: " + shouldInitAta + " unwrapping: " + shouldUnwrap + " num txns: " + txs.length);
232
+ return txs;
242
233
  }
243
234
  getClaimFeeRate(signer, swapData) {
244
235
  const accounts = [signer];
@@ -276,22 +267,19 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
276
267
  * Get the estimated solana transaction fee of the claim transaction in the worst case scenario in case where the
277
268
  * ATA needs to be initialized again (i.e. adding the ATA rent exempt lamports to the fee)
278
269
  */
279
- getClaimFee(signer, swapData, feeRate) {
280
- return __awaiter(this, void 0, void 0, function* () {
281
- return new BN(swapData == null || swapData.payOut ? this.root.Tokens.SPL_ATA_RENT_EXEMPT : 0).add(yield this.getRawClaimFee(signer, swapData, feeRate));
282
- });
270
+ async getClaimFee(signer, swapData, feeRate) {
271
+ return BigInt(swapData == null || swapData.payOut ? SolanaTokens_1.SolanaTokens.SPL_ATA_RENT_EXEMPT : 0) +
272
+ await this.getRawClaimFee(signer, swapData, feeRate);
283
273
  }
284
274
  /**
285
275
  * Get the estimated solana transaction fee of the claim transaction, without
286
276
  */
287
- getRawClaimFee(signer, swapData, feeRate) {
288
- return __awaiter(this, void 0, void 0, function* () {
289
- if (swapData == null)
290
- return new BN(5000);
291
- feeRate = feeRate || (yield this.getClaimFeeRate(signer, swapData));
292
- //Include rent exempt in claim fee, to take into consideration worst case cost when user destroys ATA
293
- return new BN(5000).add(this.root.Fees.getPriorityFee(this.getComputeBudget(swapData), feeRate));
294
- });
277
+ async getRawClaimFee(signer, swapData, feeRate) {
278
+ if (swapData == null)
279
+ return 5000n;
280
+ feeRate = feeRate || await this.getClaimFeeRate(signer, swapData);
281
+ //Include rent exempt in claim fee, to take into consideration worst case cost when user destroys ATA
282
+ return 5000n + this.root.Fees.getPriorityFee(this.getComputeBudget(swapData), feeRate);
295
283
  }
296
284
  }
297
285
  exports.SwapClaim = SwapClaim;
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import { ParsedAccountsModeBlockResponse, PublicKey } from "@solana/web3.js";
3
- import * as BN from "bn.js";
4
3
  import { SolanaSwapData } from "../SolanaSwapData";
5
4
  import { SolanaSwapModule } from "../SolanaSwapModule";
6
5
  import { SolanaTx } from "../../base/modules/SolanaTransactions";
@@ -209,9 +208,9 @@ export declare class SwapInit extends SolanaSwapModule {
209
208
  * Get the estimated solana fee of the init transaction, this includes the required deposit for creating swap PDA
210
209
  * and also deposit for ATAs
211
210
  */
212
- getInitFee(swapData: SolanaSwapData, feeRate?: string): Promise<BN>;
211
+ getInitFee(swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
213
212
  /**
214
213
  * Get the estimated solana fee of the init transaction, without the required deposit for creating swap PDA
215
214
  */
216
- getRawInitFee(swapData: SolanaSwapData, feeRate?: string): Promise<BN>;
215
+ getRawInitFee(swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
217
216
  }