@atomiqlabs/chain-solana 8.0.3 → 9.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.
- package/dist/index.d.ts +11 -11
- package/dist/index.js +11 -11
- package/dist/solana/SolanaChainType.d.ts +3 -2
- package/dist/solana/SolanaInitializer.d.ts +2 -2
- package/dist/solana/SolanaInitializer.js +9 -5
- package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +4 -4
- package/dist/solana/btcrelay/SolanaBtcRelay.js +13 -14
- package/dist/solana/{base → chain}/SolanaAction.d.ts +2 -2
- package/dist/solana/chain/SolanaChainInterface.d.ts +58 -0
- package/dist/solana/chain/SolanaChainInterface.js +112 -0
- package/dist/solana/{base → chain}/SolanaModule.d.ts +3 -3
- package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -0
- package/dist/solana/{base → chain}/modules/SolanaAddresses.js +2 -3
- package/dist/solana/events/SolanaChainEvents.d.ts +0 -4
- package/dist/solana/events/SolanaChainEvents.js +0 -16
- package/dist/solana/events/SolanaChainEventsBrowser.js +0 -1
- package/dist/solana/program/SolanaProgramBase.d.ts +11 -5
- package/dist/solana/program/SolanaProgramBase.js +7 -7
- package/dist/solana/program/SolanaProgramModule.d.ts +8 -0
- package/dist/solana/program/SolanaProgramModule.js +11 -0
- package/dist/solana/program/modules/SolanaProgramEvents.d.ts +4 -3
- package/dist/solana/program/modules/SolanaProgramEvents.js +8 -8
- package/dist/solana/swaps/SolanaSwapData.js +1 -1
- package/dist/solana/swaps/SolanaSwapModule.d.ts +6 -5
- package/dist/solana/swaps/SolanaSwapModule.js +5 -6
- package/dist/solana/swaps/SolanaSwapProgram.d.ts +4 -23
- package/dist/solana/swaps/SolanaSwapProgram.js +22 -98
- package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +3 -2
- package/dist/solana/swaps/modules/SolanaDataAccount.js +9 -9
- package/dist/solana/swaps/modules/SolanaLpVault.d.ts +1 -1
- package/dist/solana/swaps/modules/SolanaLpVault.js +13 -13
- package/dist/solana/swaps/modules/SwapClaim.d.ts +3 -2
- package/dist/solana/swaps/modules/SwapClaim.js +15 -15
- package/dist/solana/swaps/modules/SwapInit.d.ts +1 -1
- package/dist/solana/swaps/modules/SwapInit.js +21 -21
- package/dist/solana/swaps/modules/SwapRefund.d.ts +1 -1
- package/dist/solana/swaps/modules/SwapRefund.js +17 -17
- package/package.json +2 -2
- package/src/index.ts +11 -11
- package/src/solana/SolanaChainType.ts +7 -2
- package/src/solana/SolanaInitializer.ts +13 -9
- package/src/solana/btcrelay/SolanaBtcRelay.ts +17 -17
- package/src/solana/{base → chain}/SolanaAction.ts +3 -3
- package/src/solana/chain/SolanaChainInterface.ts +175 -0
- package/src/solana/{base → chain}/SolanaModule.ts +3 -3
- package/src/solana/{base → chain}/modules/SolanaAddresses.ts +2 -3
- package/src/solana/events/SolanaChainEvents.ts +0 -17
- package/src/solana/events/SolanaChainEventsBrowser.ts +0 -1
- package/src/solana/program/SolanaProgramBase.ts +13 -10
- package/src/solana/program/SolanaProgramModule.ts +16 -0
- package/src/solana/program/modules/SolanaProgramEvents.ts +10 -9
- package/src/solana/swaps/SolanaSwapData.ts +1 -1
- package/src/solana/swaps/SolanaSwapModule.ts +8 -8
- package/src/solana/swaps/SolanaSwapProgram.ts +28 -133
- package/src/solana/swaps/modules/SolanaDataAccount.ts +11 -10
- package/src/solana/swaps/modules/SolanaLpVault.ts +15 -15
- package/src/solana/swaps/modules/SwapClaim.ts +17 -16
- package/src/solana/swaps/modules/SwapInit.ts +22 -22
- package/src/solana/swaps/modules/SwapRefund.ts +18 -18
- package/dist/solana/base/SolanaBase.d.ts +0 -36
- package/dist/solana/base/SolanaBase.js +0 -30
- package/dist/solana/base/modules/SolanaAddresses.d.ts +0 -9
- package/src/solana/base/SolanaBase.ts +0 -56
- /package/dist/solana/{base → chain}/SolanaAction.js +0 -0
- /package/dist/solana/{base → chain}/SolanaModule.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaBlocks.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaBlocks.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaEvents.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaEvents.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaFees.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaFees.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaSignatures.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaSignatures.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaSlots.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaSlots.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaTokens.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaTokens.js +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaTransactions.d.ts +0 -0
- /package/dist/solana/{base → chain}/modules/SolanaTransactions.js +0 -0
- /package/src/solana/{base → chain}/modules/SolanaBlocks.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaEvents.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaFees.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaSignatures.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaSlots.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaTokens.ts +0 -0
- /package/src/solana/{base → chain}/modules/SolanaTransactions.ts +0 -0
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SwapClaim = void 0;
|
|
4
4
|
const SolanaSwapModule_1 = require("../SolanaSwapModule");
|
|
5
|
-
const SolanaAction_1 = require("../../
|
|
5
|
+
const SolanaAction_1 = require("../../chain/SolanaAction");
|
|
6
6
|
const spl_token_1 = require("@solana/spl-token");
|
|
7
7
|
const base_1 = require("@atomiqlabs/base");
|
|
8
8
|
const web3_js_1 = require("@solana/web3.js");
|
|
9
9
|
const Utils_1 = require("../../../utils/Utils");
|
|
10
10
|
const SolanaSigner_1 = require("../../wallet/SolanaSigner");
|
|
11
|
-
const SolanaTokens_1 = require("../../
|
|
11
|
+
const SolanaTokens_1 = require("../../chain/modules/SolanaTokens");
|
|
12
12
|
const BN = require("bn.js");
|
|
13
13
|
class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
|
|
14
14
|
async Claim(signer, swapData, secretOrDataKey) {
|
|
@@ -16,7 +16,7 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
16
16
|
const accounts = {
|
|
17
17
|
signer,
|
|
18
18
|
initializer: swapData.isPayIn() ? swapData.offerer : swapData.claimer,
|
|
19
|
-
escrowState: this.
|
|
19
|
+
escrowState: this.program.SwapEscrowState(Buffer.from(swapData.paymentHash, "hex")),
|
|
20
20
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
21
21
|
data: isDataKey ? secretOrDataKey : null,
|
|
22
22
|
};
|
|
@@ -24,23 +24,23 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
24
24
|
Buffer.alloc(0) :
|
|
25
25
|
Buffer.from(secretOrDataKey, "hex");
|
|
26
26
|
if (swapData.isPayOut()) {
|
|
27
|
-
return new SolanaAction_1.SolanaAction(signer, this.root, await this.
|
|
27
|
+
return new SolanaAction_1.SolanaAction(signer, this.root, await this.swapProgram.methods
|
|
28
28
|
.claimerClaimPayOut(secretBuffer)
|
|
29
29
|
.accounts({
|
|
30
30
|
...accounts,
|
|
31
31
|
claimerAta: swapData.claimerAta,
|
|
32
|
-
vault: this.
|
|
33
|
-
vaultAuthority: this.
|
|
32
|
+
vault: this.program.SwapVault(swapData.token),
|
|
33
|
+
vaultAuthority: this.program.SwapVaultAuthority,
|
|
34
34
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
35
35
|
})
|
|
36
36
|
.instruction(), this.getComputeBudget(swapData));
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
return new SolanaAction_1.SolanaAction(signer, this.root, await this.
|
|
39
|
+
return new SolanaAction_1.SolanaAction(signer, this.root, await this.swapProgram.methods
|
|
40
40
|
.claimerClaim(secretBuffer)
|
|
41
41
|
.accounts({
|
|
42
42
|
...accounts,
|
|
43
|
-
claimerUserData: this.
|
|
43
|
+
claimerUserData: this.program.SwapUserVault(swapData.claimer, swapData.token)
|
|
44
44
|
})
|
|
45
45
|
.instruction(), this.getComputeBudget(swapData));
|
|
46
46
|
}
|
|
@@ -64,8 +64,8 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
64
64
|
action.computeBudget = null;
|
|
65
65
|
return action;
|
|
66
66
|
}
|
|
67
|
-
constructor(
|
|
68
|
-
super(
|
|
67
|
+
constructor(chainInterface, program, btcRelay) {
|
|
68
|
+
super(chainInterface, program);
|
|
69
69
|
this.btcRelay = btcRelay;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
@@ -135,7 +135,7 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
135
135
|
Buffer.from(tx.hex, "hex")
|
|
136
136
|
]);
|
|
137
137
|
this.logger.debug("addTxsWriteTransactionData(): writing transaction data: ", writeData.toString("hex"));
|
|
138
|
-
return this.
|
|
138
|
+
return this.program.DataAccount.addTxsWriteData(signer, reversedTxId, writeData, txs, feeRate);
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
141
|
* Checks whether we should unwrap the WSOL to SOL when claiming the swap
|
|
@@ -164,7 +164,7 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
164
164
|
async txsClaimWithSecret(signer, swapData, secret, checkExpiry, initAta, feeRate, skipAtaCheck) {
|
|
165
165
|
//We need to be sure that this transaction confirms in time, otherwise we reveal the secret to the counterparty
|
|
166
166
|
// and won't claim the funds
|
|
167
|
-
if (checkExpiry && await this.
|
|
167
|
+
if (checkExpiry && await this.program.isExpired(swapData.claimer.toString(), swapData)) {
|
|
168
168
|
throw new base_1.SwapDataVerificationError("Not enough time to reliably pay the invoice");
|
|
169
169
|
}
|
|
170
170
|
const shouldInitAta = !skipAtaCheck && swapData.isPayOut() && !await this.root.Tokens.ataExists(swapData.claimerAta);
|
|
@@ -235,7 +235,7 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
235
235
|
const accounts = [signer];
|
|
236
236
|
if (swapData.payOut) {
|
|
237
237
|
if (swapData.token != null)
|
|
238
|
-
accounts.push(this.
|
|
238
|
+
accounts.push(this.program.SwapVault(swapData.token));
|
|
239
239
|
if (swapData.payIn) {
|
|
240
240
|
if (swapData.offerer != null)
|
|
241
241
|
accounts.push(swapData.offerer);
|
|
@@ -249,7 +249,7 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
249
249
|
}
|
|
250
250
|
else {
|
|
251
251
|
if (swapData.claimer != null && swapData.token != null)
|
|
252
|
-
accounts.push(this.
|
|
252
|
+
accounts.push(this.program.SwapUserVault(swapData.claimer, swapData.token));
|
|
253
253
|
if (swapData.payIn) {
|
|
254
254
|
if (swapData.offerer != null)
|
|
255
255
|
accounts.push(swapData.offerer);
|
|
@@ -260,7 +260,7 @@ class SwapClaim extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
if (swapData.paymentHash != null)
|
|
263
|
-
accounts.push(this.
|
|
263
|
+
accounts.push(this.program.SwapEscrowState(Buffer.from(swapData.paymentHash, "hex")));
|
|
264
264
|
return this.root.Fees.getFeeRate(accounts);
|
|
265
265
|
}
|
|
266
266
|
/**
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ParsedAccountsModeBlockResponse, PublicKey } from "@solana/web3.js";
|
|
3
3
|
import { SolanaSwapData } from "../SolanaSwapData";
|
|
4
4
|
import { SolanaSwapModule } from "../SolanaSwapModule";
|
|
5
|
-
import { SolanaTx } from "../../
|
|
5
|
+
import { SolanaTx } from "../../chain/modules/SolanaTransactions";
|
|
6
6
|
import { Buffer } from "buffer";
|
|
7
7
|
import { SolanaSigner } from "../../wallet/SolanaSigner";
|
|
8
8
|
export type SolanaPreFetchVerification = {
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SwapInit = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const base_1 = require("@atomiqlabs/base");
|
|
6
|
-
const SolanaAction_1 = require("../../
|
|
6
|
+
const SolanaAction_1 = require("../../chain/SolanaAction");
|
|
7
7
|
const spl_token_1 = require("@solana/spl-token");
|
|
8
8
|
const SolanaSwapModule_1 = require("../SolanaSwapModule");
|
|
9
9
|
const Utils_1 = require("../../../utils/Utils");
|
|
10
10
|
const buffer_1 = require("buffer");
|
|
11
|
-
const SolanaTokens_1 = require("../../
|
|
11
|
+
const SolanaTokens_1 = require("../../chain/modules/SolanaTokens");
|
|
12
12
|
class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
13
13
|
constructor() {
|
|
14
14
|
super(...arguments);
|
|
@@ -28,31 +28,31 @@ class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
28
28
|
const accounts = {
|
|
29
29
|
claimer: swapData.claimer,
|
|
30
30
|
offerer: swapData.offerer,
|
|
31
|
-
escrowState: this.
|
|
31
|
+
escrowState: this.program.SwapEscrowState(paymentHash),
|
|
32
32
|
mint: swapData.token,
|
|
33
33
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
34
34
|
claimerAta: swapData.payOut ? claimerAta : null,
|
|
35
|
-
claimerUserData: !swapData.payOut ? this.
|
|
35
|
+
claimerUserData: !swapData.payOut ? this.program.SwapUserVault(swapData.claimer, swapData.token) : null
|
|
36
36
|
};
|
|
37
37
|
if (swapData.payIn) {
|
|
38
38
|
const ata = (0, spl_token_1.getAssociatedTokenAddressSync)(swapData.token, swapData.offerer);
|
|
39
|
-
return new SolanaAction_1.SolanaAction(swapData.offerer, this.root, await this.
|
|
39
|
+
return new SolanaAction_1.SolanaAction(swapData.offerer, this.root, await this.swapProgram.methods
|
|
40
40
|
.offererInitializePayIn(swapData.toSwapDataStruct(), [...buffer_1.Buffer.alloc(32, 0)], (0, Utils_1.toBN)(timeout))
|
|
41
41
|
.accounts({
|
|
42
42
|
...accounts,
|
|
43
43
|
offererAta: ata,
|
|
44
|
-
vault: this.
|
|
45
|
-
vaultAuthority: this.
|
|
44
|
+
vault: this.program.SwapVault(swapData.token),
|
|
45
|
+
vaultAuthority: this.program.SwapVaultAuthority,
|
|
46
46
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
47
47
|
})
|
|
48
48
|
.instruction(), SwapInit.CUCosts.INIT_PAY_IN);
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
return new SolanaAction_1.SolanaAction(swapData.claimer, this.root, await this.
|
|
51
|
+
return new SolanaAction_1.SolanaAction(swapData.claimer, this.root, await this.swapProgram.methods
|
|
52
52
|
.offererInitialize(swapData.toSwapDataStruct(), swapData.securityDeposit, swapData.claimerBounty, [...(swapData.txoHash != null ? buffer_1.Buffer.from(swapData.txoHash, "hex") : buffer_1.Buffer.alloc(32, 0))], (0, Utils_1.toBN)(timeout))
|
|
53
53
|
.accounts({
|
|
54
54
|
...accounts,
|
|
55
|
-
offererUserData: this.
|
|
55
|
+
offererUserData: this.program.SwapUserVault(swapData.offerer, swapData.token),
|
|
56
56
|
})
|
|
57
57
|
.instruction(), SwapInit.CUCosts.INIT);
|
|
58
58
|
}
|
|
@@ -268,13 +268,13 @@ class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
268
268
|
async isSignatureValid(swapData, timeout, prefix, signature, feeRate, preFetchedData) {
|
|
269
269
|
const sender = swapData.isPayIn() ? swapData.offerer : swapData.claimer;
|
|
270
270
|
const signer = swapData.isPayIn() ? swapData.claimer : swapData.offerer;
|
|
271
|
-
if (!swapData.isPayIn() && await this.
|
|
271
|
+
if (!swapData.isPayIn() && await this.program.isExpired(sender.toString(), swapData)) {
|
|
272
272
|
throw new base_1.SignatureVerificationError("Swap will expire too soon!");
|
|
273
273
|
}
|
|
274
274
|
if (prefix !== this.getAuthPrefix(swapData))
|
|
275
275
|
throw new base_1.SignatureVerificationError("Invalid prefix");
|
|
276
276
|
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
277
|
-
const isExpired = (BigInt(timeout) - currentTimestamp) < BigInt(this.
|
|
277
|
+
const isExpired = (BigInt(timeout) - currentTimestamp) < BigInt(this.program.authGracePeriod);
|
|
278
278
|
if (isExpired)
|
|
279
279
|
throw new base_1.SignatureVerificationError("Authorization expired!");
|
|
280
280
|
const [transactionSlot, signatureString] = signature.split(";");
|
|
@@ -313,7 +313,7 @@ class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
313
313
|
const slotsLeft = lastValidTransactionSlot - latestSlot - this.SIGNATURE_SLOT_BUFFER;
|
|
314
314
|
const now = Date.now();
|
|
315
315
|
const slotExpiryTime = now + (slotsLeft * this.root.SLOT_TIME);
|
|
316
|
-
const timeoutExpiryTime = (parseInt(timeout) - this.
|
|
316
|
+
const timeoutExpiryTime = (parseInt(timeout) - this.program.authGracePeriod) * 1000;
|
|
317
317
|
const expiry = Math.min(slotExpiryTime, timeoutExpiryTime);
|
|
318
318
|
if (expiry < now)
|
|
319
319
|
return 0;
|
|
@@ -334,7 +334,7 @@ class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
334
334
|
const slotsLeft = lastValidTransactionSlot - latestSlot + this.SIGNATURE_SLOT_BUFFER;
|
|
335
335
|
if (slotsLeft < 0)
|
|
336
336
|
return true;
|
|
337
|
-
if ((parseInt(timeout) + this.
|
|
337
|
+
if ((parseInt(timeout) + this.program.authGracePeriod) * 1000 < Date.now())
|
|
338
338
|
return true;
|
|
339
339
|
return false;
|
|
340
340
|
}
|
|
@@ -354,7 +354,7 @@ class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
354
354
|
if (!skipChecks) {
|
|
355
355
|
const [_, payStatus] = await Promise.all([
|
|
356
356
|
(0, Utils_1.tryWithRetries)(() => this.isSignatureValid(swapData, timeout, prefix, signature, feeRate), this.retryPolicy, (e) => e instanceof base_1.SignatureVerificationError),
|
|
357
|
-
(0, Utils_1.tryWithRetries)(() => this.
|
|
357
|
+
(0, Utils_1.tryWithRetries)(() => this.program.getClaimHashStatus(swapData.getClaimHash()), this.retryPolicy)
|
|
358
358
|
]);
|
|
359
359
|
if (payStatus !== base_1.SwapCommitStatus.NOT_COMMITED)
|
|
360
360
|
throw new base_1.SwapDataVerificationError("Invoice already being paid for or paid");
|
|
@@ -416,14 +416,14 @@ class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
416
416
|
if (offerer != null)
|
|
417
417
|
accounts.push(offerer);
|
|
418
418
|
if (token != null) {
|
|
419
|
-
accounts.push(this.
|
|
419
|
+
accounts.push(this.program.SwapVault(token));
|
|
420
420
|
if (offerer != null)
|
|
421
421
|
accounts.push((0, spl_token_1.getAssociatedTokenAddressSync)(token, offerer));
|
|
422
422
|
if (claimer != null)
|
|
423
|
-
accounts.push(this.
|
|
423
|
+
accounts.push(this.program.SwapUserVault(claimer, token));
|
|
424
424
|
}
|
|
425
425
|
if (paymentHash != null)
|
|
426
|
-
accounts.push(this.
|
|
426
|
+
accounts.push(this.program.SwapEscrowState(buffer_1.Buffer.from(paymentHash, "hex")));
|
|
427
427
|
const shouldCheckWSOLAta = token != null && offerer != null && token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS);
|
|
428
428
|
let [feeRate, _account] = await Promise.all([
|
|
429
429
|
this.root.Fees.getFeeRate(accounts),
|
|
@@ -451,11 +451,11 @@ class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
451
451
|
getInitFeeRate(offerer, claimer, token, paymentHash) {
|
|
452
452
|
const accounts = [];
|
|
453
453
|
if (offerer != null && token != null)
|
|
454
|
-
accounts.push(this.
|
|
454
|
+
accounts.push(this.program.SwapUserVault(offerer, token));
|
|
455
455
|
if (claimer != null)
|
|
456
456
|
accounts.push(claimer);
|
|
457
457
|
if (paymentHash != null)
|
|
458
|
-
accounts.push(this.
|
|
458
|
+
accounts.push(this.program.SwapEscrowState(buffer_1.Buffer.from(paymentHash, "hex")));
|
|
459
459
|
return this.root.Fees.getFeeRate(accounts);
|
|
460
460
|
}
|
|
461
461
|
/**
|
|
@@ -464,7 +464,7 @@ class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
464
464
|
*/
|
|
465
465
|
async getInitFee(swapData, feeRate) {
|
|
466
466
|
if (swapData == null)
|
|
467
|
-
return BigInt(this.
|
|
467
|
+
return BigInt(this.program.ESCROW_STATE_RENT_EXEMPT) + await this.getRawInitFee(swapData, feeRate);
|
|
468
468
|
feeRate = feeRate ||
|
|
469
469
|
(swapData.payIn
|
|
470
470
|
? await this.getInitPayInFeeRate(swapData.offerer, swapData.claimer, swapData.token, swapData.paymentHash)
|
|
@@ -475,7 +475,7 @@ class SwapInit extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
475
475
|
this.root.Tokens.getATAOrNull((0, spl_token_1.getAssociatedTokenAddressSync)(swapData.token, swapData.claimer)).then(acc => acc == null) :
|
|
476
476
|
Promise.resolve(null)
|
|
477
477
|
]);
|
|
478
|
-
let resultingFee = BigInt(this.
|
|
478
|
+
let resultingFee = BigInt(this.program.ESCROW_STATE_RENT_EXEMPT) + rawFee;
|
|
479
479
|
if (initAta)
|
|
480
480
|
resultingFee += BigInt(SolanaTokens_1.SolanaTokens.SPL_ATA_RENT_EXEMPT);
|
|
481
481
|
if (swapData.payIn && this.shouldWrapOnInit(swapData, feeRate) && this.extractAtaDataFromFeeRate(feeRate).initAta) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { SolanaSwapModule } from "../SolanaSwapModule";
|
|
3
3
|
import { SolanaSwapData } from "../SolanaSwapData";
|
|
4
|
-
import { SolanaTx } from "../../
|
|
4
|
+
import { SolanaTx } from "../../chain/modules/SolanaTransactions";
|
|
5
5
|
import { Buffer } from "buffer";
|
|
6
6
|
import { SolanaSigner } from "../../wallet/SolanaSigner";
|
|
7
7
|
export declare class SwapRefund extends SolanaSwapModule {
|
|
@@ -7,10 +7,10 @@ const tweetnacl_1 = require("tweetnacl");
|
|
|
7
7
|
const base_1 = require("@atomiqlabs/base");
|
|
8
8
|
const web3_js_1 = require("@solana/web3.js");
|
|
9
9
|
const spl_token_1 = require("@solana/spl-token");
|
|
10
|
-
const SolanaAction_1 = require("../../
|
|
10
|
+
const SolanaAction_1 = require("../../chain/SolanaAction");
|
|
11
11
|
const Utils_1 = require("../../../utils/Utils");
|
|
12
12
|
const buffer_1 = require("buffer");
|
|
13
|
-
const SolanaTokens_1 = require("../../
|
|
13
|
+
const SolanaTokens_1 = require("../../chain/modules/SolanaTokens");
|
|
14
14
|
const BN = require("bn.js");
|
|
15
15
|
class SwapRefund extends SolanaSwapModule_1.SolanaSwapModule {
|
|
16
16
|
/**
|
|
@@ -25,30 +25,30 @@ class SwapRefund extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
25
25
|
const accounts = {
|
|
26
26
|
offerer: swapData.offerer,
|
|
27
27
|
claimer: swapData.claimer,
|
|
28
|
-
escrowState: this.
|
|
29
|
-
claimerUserData: !swapData.payOut ? this.
|
|
28
|
+
escrowState: this.program.SwapEscrowState(buffer_1.Buffer.from(swapData.paymentHash, "hex")),
|
|
29
|
+
claimerUserData: !swapData.payOut ? this.program.SwapUserVault(swapData.claimer, swapData.token) : null,
|
|
30
30
|
ixSysvar: refundAuthTimeout != null ? web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY : null
|
|
31
31
|
};
|
|
32
32
|
const useTimeout = refundAuthTimeout != null ? refundAuthTimeout : 0n;
|
|
33
33
|
if (swapData.isPayIn()) {
|
|
34
34
|
const ata = (0, spl_token_1.getAssociatedTokenAddressSync)(swapData.token, swapData.offerer);
|
|
35
|
-
return new SolanaAction_1.SolanaAction(swapData.offerer, this.root, await this.
|
|
35
|
+
return new SolanaAction_1.SolanaAction(swapData.offerer, this.root, await this.swapProgram.methods
|
|
36
36
|
.offererRefundPayIn((0, Utils_1.toBN)(useTimeout))
|
|
37
37
|
.accounts({
|
|
38
38
|
...accounts,
|
|
39
39
|
offererAta: ata,
|
|
40
|
-
vault: this.
|
|
41
|
-
vaultAuthority: this.
|
|
40
|
+
vault: this.program.SwapVault(swapData.token),
|
|
41
|
+
vaultAuthority: this.program.SwapVaultAuthority,
|
|
42
42
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
43
43
|
})
|
|
44
44
|
.instruction(), SwapRefund.CUCosts.REFUND_PAY_OUT);
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
|
-
return new SolanaAction_1.SolanaAction(swapData.offerer, this.root, await this.
|
|
47
|
+
return new SolanaAction_1.SolanaAction(swapData.offerer, this.root, await this.swapProgram.methods
|
|
48
48
|
.offererRefund((0, Utils_1.toBN)(useTimeout))
|
|
49
49
|
.accounts({
|
|
50
50
|
...accounts,
|
|
51
|
-
offererUserData: this.
|
|
51
|
+
offererUserData: this.program.SwapUserVault(swapData.offerer, swapData.token)
|
|
52
52
|
})
|
|
53
53
|
.instruction(), SwapRefund.CUCosts.REFUND);
|
|
54
54
|
}
|
|
@@ -122,7 +122,7 @@ class SwapRefund extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
122
122
|
throw new base_1.SignatureVerificationError("Invalid prefix");
|
|
123
123
|
const expiryTimestamp = BigInt(timeout);
|
|
124
124
|
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
125
|
-
const isExpired = (expiryTimestamp - currentTimestamp) < BigInt(this.
|
|
125
|
+
const isExpired = (expiryTimestamp - currentTimestamp) < BigInt(this.program.authGracePeriod);
|
|
126
126
|
if (isExpired)
|
|
127
127
|
throw new base_1.SignatureVerificationError("Authorization expired!");
|
|
128
128
|
const signatureBuffer = buffer_1.Buffer.from(signature, "hex");
|
|
@@ -141,14 +141,14 @@ class SwapRefund extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
141
141
|
* @param feeRate fee rate to be used for the transactions
|
|
142
142
|
*/
|
|
143
143
|
async txsRefund(swapData, check, initAta, feeRate) {
|
|
144
|
-
if (check && !await (0, Utils_1.tryWithRetries)(() => this.
|
|
144
|
+
if (check && !await (0, Utils_1.tryWithRetries)(() => this.program.isRequestRefundable(swapData.offerer.toString(), swapData), this.retryPolicy)) {
|
|
145
145
|
throw new base_1.SwapDataVerificationError("Not refundable yet!");
|
|
146
146
|
}
|
|
147
147
|
const shouldInitAta = swapData.isPayIn() && !await this.root.Tokens.ataExists(swapData.offererAta);
|
|
148
148
|
if (shouldInitAta && !initAta)
|
|
149
149
|
throw new base_1.SwapDataVerificationError("ATA not initialized");
|
|
150
150
|
if (feeRate == null)
|
|
151
|
-
feeRate = await this.
|
|
151
|
+
feeRate = await this.program.getRefundFeeRate(swapData);
|
|
152
152
|
const shouldUnwrap = this.shouldUnwrap(swapData);
|
|
153
153
|
const action = new SolanaAction_1.SolanaAction(swapData.offerer, this.root);
|
|
154
154
|
if (shouldInitAta) {
|
|
@@ -176,7 +176,7 @@ class SwapRefund extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
176
176
|
* @param feeRate fee rate to be used for the transactions
|
|
177
177
|
*/
|
|
178
178
|
async txsRefundWithAuthorization(swapData, timeout, prefix, signature, check, initAta, feeRate) {
|
|
179
|
-
if (check && !await (0, Utils_1.tryWithRetries)(() => this.
|
|
179
|
+
if (check && !await (0, Utils_1.tryWithRetries)(() => this.program.isCommited(swapData), this.retryPolicy)) {
|
|
180
180
|
throw new base_1.SwapDataVerificationError("Not correctly committed");
|
|
181
181
|
}
|
|
182
182
|
await (0, Utils_1.tryWithRetries)(() => this.isSignatureValid(swapData, timeout, prefix, signature), this.retryPolicy, (e) => e instanceof base_1.SignatureVerificationError);
|
|
@@ -184,7 +184,7 @@ class SwapRefund extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
184
184
|
if (shouldInitAta && !initAta)
|
|
185
185
|
throw new base_1.SwapDataVerificationError("ATA not initialized");
|
|
186
186
|
if (feeRate == null)
|
|
187
|
-
feeRate = await this.
|
|
187
|
+
feeRate = await this.program.getRefundFeeRate(swapData);
|
|
188
188
|
console.log("[SolanaSwapProgram] txsRefundsWithAuthorization: feeRate: ", feeRate);
|
|
189
189
|
const signatureBuffer = buffer_1.Buffer.from(signature, "hex");
|
|
190
190
|
const shouldUnwrap = this.shouldUnwrap(swapData);
|
|
@@ -206,7 +206,7 @@ class SwapRefund extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
206
206
|
const accounts = [];
|
|
207
207
|
if (swapData.payIn) {
|
|
208
208
|
if (swapData.token != null)
|
|
209
|
-
accounts.push(this.
|
|
209
|
+
accounts.push(this.program.SwapVault(swapData.token));
|
|
210
210
|
if (swapData.offerer != null)
|
|
211
211
|
accounts.push(swapData.offerer);
|
|
212
212
|
if (swapData.claimer != null)
|
|
@@ -218,13 +218,13 @@ class SwapRefund extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
218
218
|
if (swapData.offerer != null) {
|
|
219
219
|
accounts.push(swapData.offerer);
|
|
220
220
|
if (swapData.token != null)
|
|
221
|
-
accounts.push(this.
|
|
221
|
+
accounts.push(this.program.SwapUserVault(swapData.offerer, swapData.token));
|
|
222
222
|
}
|
|
223
223
|
if (swapData.claimer != null)
|
|
224
224
|
accounts.push(swapData.claimer);
|
|
225
225
|
}
|
|
226
226
|
if (swapData.paymentHash != null)
|
|
227
|
-
accounts.push(this.
|
|
227
|
+
accounts.push(this.program.SwapEscrowState(buffer_1.Buffer.from(swapData.paymentHash, "hex")));
|
|
228
228
|
return this.root.Fees.getFeeRate(accounts);
|
|
229
229
|
}
|
|
230
230
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/chain-solana",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-beta.0",
|
|
4
4
|
"description": "Solana specific base implementation",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"author": "adambor",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@atomiqlabs/base": "^
|
|
25
|
+
"@atomiqlabs/base": "^9.0.0-beta.0",
|
|
26
26
|
"@noble/hashes": "^1.7.1",
|
|
27
27
|
"bn.js": "5.2.1",
|
|
28
28
|
"bs58": "4.0.1",
|
package/src/index.ts
CHANGED
|
@@ -2,18 +2,18 @@ export * from "./solana/btcrelay/headers/SolanaBtcHeader";
|
|
|
2
2
|
export * from "./solana/btcrelay/headers/SolanaBtcStoredHeader";
|
|
3
3
|
export * from "./solana/btcrelay/SolanaBtcRelay";
|
|
4
4
|
|
|
5
|
-
export * from "./solana/
|
|
6
|
-
export * from "./solana/
|
|
7
|
-
export * from "./solana/
|
|
8
|
-
export * from "./solana/
|
|
9
|
-
export * from "./solana/
|
|
10
|
-
export * from "./solana/
|
|
11
|
-
export * from "./solana/
|
|
12
|
-
export * from "./solana/
|
|
5
|
+
export * from "./solana/chain/modules/SolanaAddresses";
|
|
6
|
+
export * from "./solana/chain/modules/SolanaBlocks";
|
|
7
|
+
export * from "./solana/chain/modules/SolanaEvents";
|
|
8
|
+
export * from "./solana/chain/modules/SolanaFees";
|
|
9
|
+
export * from "./solana/chain/modules/SolanaSignatures";
|
|
10
|
+
export * from "./solana/chain/modules/SolanaSlots";
|
|
11
|
+
export * from "./solana/chain/modules/SolanaTokens";
|
|
12
|
+
export * from "./solana/chain/modules/SolanaTransactions";
|
|
13
13
|
|
|
14
|
-
export * from "./solana/
|
|
15
|
-
export * from "./solana/
|
|
16
|
-
export * from "./solana/
|
|
14
|
+
export * from "./solana/chain/SolanaAction";
|
|
15
|
+
export * from "./solana/chain/SolanaChainInterface";
|
|
16
|
+
export * from "./solana/chain/SolanaModule";
|
|
17
17
|
|
|
18
18
|
export * from "./solana/program/modules/SolanaProgramEvents";
|
|
19
19
|
export * from "./solana/program/SolanaProgramBase";
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {ChainType} from "@atomiqlabs/base";
|
|
2
|
-
import {SolanaTx} from "./
|
|
2
|
+
import {SolanaTx} from "./chain/modules/SolanaTransactions";
|
|
3
3
|
import {SolanaPreFetchData, SolanaPreFetchVerification} from "./swaps/modules/SwapInit";
|
|
4
4
|
import {SolanaSigner} from "./wallet/SolanaSigner";
|
|
5
5
|
import {SolanaSwapProgram} from "./swaps/SolanaSwapProgram";
|
|
6
6
|
import {SolanaSwapData} from "./swaps/SolanaSwapData";
|
|
7
7
|
import {SolanaChainEventsBrowser} from "./events/SolanaChainEventsBrowser";
|
|
8
8
|
import {SolanaBtcRelay} from "./btcrelay/SolanaBtcRelay";
|
|
9
|
+
import {SolanaChainInterface} from "./chain/SolanaChainInterface";
|
|
9
10
|
|
|
10
11
|
export type SolanaChainType = ChainType<
|
|
11
12
|
"SOLANA",
|
|
@@ -15,6 +16,10 @@ export type SolanaChainType = ChainType<
|
|
|
15
16
|
SolanaSigner,
|
|
16
17
|
SolanaSwapData,
|
|
17
18
|
SolanaSwapProgram,
|
|
19
|
+
SolanaChainInterface,
|
|
18
20
|
SolanaChainEventsBrowser,
|
|
19
|
-
SolanaBtcRelay<any
|
|
21
|
+
SolanaBtcRelay<any>,
|
|
22
|
+
never,
|
|
23
|
+
never,
|
|
24
|
+
never
|
|
20
25
|
>;
|
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
} from "@atomiqlabs/base";
|
|
10
10
|
import {Connection} from "@solana/web3.js";
|
|
11
11
|
import {StoredDataAccount} from "./swaps/modules/SolanaDataAccount";
|
|
12
|
-
import {SolanaRetryPolicy} from "./
|
|
13
|
-
import {SolanaFees} from "./
|
|
12
|
+
import {SolanaChainInterface, SolanaRetryPolicy} from "./chain/SolanaChainInterface";
|
|
13
|
+
import {SolanaFees} from "./chain/modules/SolanaFees";
|
|
14
14
|
import {SolanaChainType} from "./SolanaChainType";
|
|
15
15
|
import {SolanaBtcRelay} from "./btcrelay/SolanaBtcRelay";
|
|
16
16
|
import {SolanaChains} from "./SolanaChains";
|
|
@@ -66,14 +66,16 @@ export function initializeSolana(
|
|
|
66
66
|
options.rpcUrl;
|
|
67
67
|
|
|
68
68
|
const Fees = options.fees ?? new SolanaFees(connection, 200000, 4, 100);
|
|
69
|
-
|
|
69
|
+
|
|
70
|
+
const chainInterface = new SolanaChainInterface(connection, options.retryPolicy ?? {transactionResendInterval: 1000}, Fees);
|
|
71
|
+
|
|
72
|
+
const btcRelay = new SolanaBtcRelay(chainInterface, bitcoinRpc, options.btcRelayContract ?? SolanaChains[network].addresses.btcRelayContract);
|
|
73
|
+
|
|
70
74
|
const swapContract = new SolanaSwapProgram(
|
|
71
|
-
|
|
75
|
+
chainInterface,
|
|
72
76
|
btcRelay,
|
|
73
77
|
options.dataAccountStorage || storageCtor("solAccounts"),
|
|
74
|
-
options.swapContract ?? SolanaChains[network].addresses.swapContract
|
|
75
|
-
options.retryPolicy ?? {transactionResendInterval: 1000},
|
|
76
|
-
Fees
|
|
78
|
+
options.swapContract ?? SolanaChains[network].addresses.swapContract
|
|
77
79
|
);
|
|
78
80
|
const chainEvents = new SolanaChainEventsBrowser(connection, swapContract);
|
|
79
81
|
|
|
@@ -83,8 +85,10 @@ export function initializeSolana(
|
|
|
83
85
|
swapContract,
|
|
84
86
|
chainEvents,
|
|
85
87
|
swapDataConstructor: SolanaSwapData,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
chainInterface,
|
|
89
|
+
spvVaultContract: null as never,
|
|
90
|
+
spvVaultDataConstructor: null,
|
|
91
|
+
spvVaultWithdrawalDataConstructor: null
|
|
88
92
|
};
|
|
89
93
|
}
|
|
90
94
|
|
|
@@ -11,12 +11,13 @@ import * as programIdl from "./program/programIdl.json";
|
|
|
11
11
|
import {BitcoinRpc, BtcBlock, BtcRelay, StatePredictorUtils} from "@atomiqlabs/base";
|
|
12
12
|
import {MethodsBuilder} from "@coral-xyz/anchor/dist/cjs/program/namespace/methods";
|
|
13
13
|
import {SolanaProgramBase} from "../program/SolanaProgramBase";
|
|
14
|
-
import {SolanaAction} from "../
|
|
14
|
+
import {SolanaAction} from "../chain/SolanaAction";
|
|
15
15
|
import {Buffer} from "buffer";
|
|
16
|
-
import {
|
|
17
|
-
import {SolanaTx} from "../base/modules/SolanaTransactions";
|
|
16
|
+
import {SolanaTx} from "../chain/modules/SolanaTransactions";
|
|
18
17
|
import {SolanaSigner} from "../wallet/SolanaSigner";
|
|
19
18
|
import * as BN from "bn.js";
|
|
19
|
+
import {SolanaChainInterface} from "../chain/SolanaChainInterface";
|
|
20
|
+
import {getLogger} from "../../utils/Utils";
|
|
20
21
|
|
|
21
22
|
const MAX_CLOSE_IX_PER_TX = 10;
|
|
22
23
|
|
|
@@ -46,7 +47,7 @@ export class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBase<any> i
|
|
|
46
47
|
*/
|
|
47
48
|
private async Initialize(signer: PublicKey, header: B, epochStart: number, pastBlocksTimestamps: number[]): Promise<SolanaAction> {
|
|
48
49
|
const serializedBlock = serializeBlockHeader(header);
|
|
49
|
-
return new SolanaAction(signer, this,
|
|
50
|
+
return new SolanaAction(signer, this.Chain,
|
|
50
51
|
await this.program.methods
|
|
51
52
|
.initialize(
|
|
52
53
|
serializedBlock,
|
|
@@ -85,7 +86,7 @@ export class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBase<any> i
|
|
|
85
86
|
reversedMerkleProof: Buffer[],
|
|
86
87
|
committedHeader: SolanaBtcStoredHeader
|
|
87
88
|
): Promise<SolanaAction> {
|
|
88
|
-
return new SolanaAction(signer, this,
|
|
89
|
+
return new SolanaAction(signer, this.Chain,
|
|
89
90
|
await this.program.methods
|
|
90
91
|
.verifyTransaction(
|
|
91
92
|
reversedTxId,
|
|
@@ -107,7 +108,7 @@ export class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBase<any> i
|
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
public async CloseForkAccount(signer: PublicKey, forkId: number): Promise<SolanaAction> {
|
|
110
|
-
return new SolanaAction(signer, this,
|
|
111
|
+
return new SolanaAction(signer, this.Chain,
|
|
111
112
|
await this.program.methods
|
|
112
113
|
.closeForkAccount(
|
|
113
114
|
new BN(forkId)
|
|
@@ -135,12 +136,11 @@ export class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBase<any> i
|
|
|
135
136
|
readonly maxShortForkHeadersPerTx: number = 4;
|
|
136
137
|
|
|
137
138
|
constructor(
|
|
138
|
-
|
|
139
|
+
chainInterface: SolanaChainInterface,
|
|
139
140
|
bitcoinRpc: BitcoinRpc<B>,
|
|
140
|
-
programAddress?: string
|
|
141
|
-
solanaFeeEstimator: SolanaFees = new SolanaFees(connection)
|
|
141
|
+
programAddress?: string
|
|
142
142
|
) {
|
|
143
|
-
super(
|
|
143
|
+
super(chainInterface, programIdl, programAddress);
|
|
144
144
|
this.bitcoinRpc = bitcoinRpc;
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -208,8 +208,8 @@ export class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBase<any> i
|
|
|
208
208
|
.transaction();
|
|
209
209
|
tx.feePayer = signer;
|
|
210
210
|
|
|
211
|
-
this.Fees.applyFeeRateBegin(tx, null, feeRate);
|
|
212
|
-
this.Fees.applyFeeRateEnd(tx, null, feeRate);
|
|
211
|
+
this.Chain.Fees.applyFeeRateBegin(tx, null, feeRate);
|
|
212
|
+
this.Chain.Fees.applyFeeRateEnd(tx, null, feeRate);
|
|
213
213
|
|
|
214
214
|
const computedCommitedHeaders = this.computeCommitedHeaders(storedHeader, blockHeaderObj);
|
|
215
215
|
const lastStoredHeader = computedCommitedHeaders[computedCommitedHeaders.length-1];
|
|
@@ -496,7 +496,7 @@ export class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBase<any> i
|
|
|
496
496
|
let forkId: number = mainState.forkCounter.toNumber();
|
|
497
497
|
|
|
498
498
|
const txs: SolanaTx[] = [];
|
|
499
|
-
let action = new SolanaAction(signer.getPublicKey(), this);
|
|
499
|
+
let action = new SolanaAction(signer.getPublicKey(), this.Chain);
|
|
500
500
|
|
|
501
501
|
let lastCheckedId = lastSweepId;
|
|
502
502
|
for(
|
|
@@ -514,7 +514,7 @@ export class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBase<any> i
|
|
|
514
514
|
|
|
515
515
|
if(action.ixsLength()>=MAX_CLOSE_IX_PER_TX) {
|
|
516
516
|
await action.addToTxs(txs);
|
|
517
|
-
action = new SolanaAction(signer.getPublicKey(), this);
|
|
517
|
+
action = new SolanaAction(signer.getPublicKey(), this.Chain);
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
520
|
|
|
@@ -523,7 +523,7 @@ export class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBase<any> i
|
|
|
523
523
|
}
|
|
524
524
|
|
|
525
525
|
if(txs.length>0) {
|
|
526
|
-
const signatures = await this.
|
|
526
|
+
const signatures = await this.Chain.sendAndConfirm(signer, txs, true);
|
|
527
527
|
this.logger.info("sweepForkData(): forks swept, signatures: "+signatures.join());
|
|
528
528
|
}
|
|
529
529
|
|
|
@@ -567,7 +567,7 @@ export class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBase<any> i
|
|
|
567
567
|
*/
|
|
568
568
|
public getMainFeeRate(signer: string | null): Promise<string> {
|
|
569
569
|
const _signer = signer==null ? null : new PublicKey(signer);
|
|
570
|
-
return this.Fees.getFeeRate(_signer==null ? [this.BtcRelayMainState] : [
|
|
570
|
+
return this.Chain.Fees.getFeeRate(_signer==null ? [this.BtcRelayMainState] : [
|
|
571
571
|
_signer,
|
|
572
572
|
this.BtcRelayMainState
|
|
573
573
|
]);
|
|
@@ -578,7 +578,7 @@ export class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBase<any> i
|
|
|
578
578
|
*/
|
|
579
579
|
public getForkFeeRate(signer: string, forkId: number): Promise<string> {
|
|
580
580
|
const _signer = new PublicKey(signer);
|
|
581
|
-
return this.Fees.getFeeRate([
|
|
581
|
+
return this.Chain.Fees.getFeeRate([
|
|
582
582
|
_signer,
|
|
583
583
|
this.BtcRelayMainState,
|
|
584
584
|
this.BtcRelayFork(forkId, _signer)
|