@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
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export * from "./solana/btcrelay/headers/SolanaBtcHeader";
|
|
2
2
|
export * from "./solana/btcrelay/headers/SolanaBtcStoredHeader";
|
|
3
3
|
export * from "./solana/btcrelay/SolanaBtcRelay";
|
|
4
|
-
export * from "./solana/
|
|
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/
|
|
13
|
-
export * from "./solana/
|
|
14
|
-
export * from "./solana/
|
|
4
|
+
export * from "./solana/chain/modules/SolanaAddresses";
|
|
5
|
+
export * from "./solana/chain/modules/SolanaBlocks";
|
|
6
|
+
export * from "./solana/chain/modules/SolanaEvents";
|
|
7
|
+
export * from "./solana/chain/modules/SolanaFees";
|
|
8
|
+
export * from "./solana/chain/modules/SolanaSignatures";
|
|
9
|
+
export * from "./solana/chain/modules/SolanaSlots";
|
|
10
|
+
export * from "./solana/chain/modules/SolanaTokens";
|
|
11
|
+
export * from "./solana/chain/modules/SolanaTransactions";
|
|
12
|
+
export * from "./solana/chain/SolanaAction";
|
|
13
|
+
export * from "./solana/chain/SolanaChainInterface";
|
|
14
|
+
export * from "./solana/chain/SolanaModule";
|
|
15
15
|
export * from "./solana/program/modules/SolanaProgramEvents";
|
|
16
16
|
export * from "./solana/program/SolanaProgramBase";
|
|
17
17
|
export * from "./solana/swaps/SolanaSwapProgram";
|
package/dist/index.js
CHANGED
|
@@ -17,17 +17,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./solana/btcrelay/headers/SolanaBtcHeader"), exports);
|
|
18
18
|
__exportStar(require("./solana/btcrelay/headers/SolanaBtcStoredHeader"), exports);
|
|
19
19
|
__exportStar(require("./solana/btcrelay/SolanaBtcRelay"), exports);
|
|
20
|
-
__exportStar(require("./solana/
|
|
21
|
-
__exportStar(require("./solana/
|
|
22
|
-
__exportStar(require("./solana/
|
|
23
|
-
__exportStar(require("./solana/
|
|
24
|
-
__exportStar(require("./solana/
|
|
25
|
-
__exportStar(require("./solana/
|
|
26
|
-
__exportStar(require("./solana/
|
|
27
|
-
__exportStar(require("./solana/
|
|
28
|
-
__exportStar(require("./solana/
|
|
29
|
-
__exportStar(require("./solana/
|
|
30
|
-
__exportStar(require("./solana/
|
|
20
|
+
__exportStar(require("./solana/chain/modules/SolanaAddresses"), exports);
|
|
21
|
+
__exportStar(require("./solana/chain/modules/SolanaBlocks"), exports);
|
|
22
|
+
__exportStar(require("./solana/chain/modules/SolanaEvents"), exports);
|
|
23
|
+
__exportStar(require("./solana/chain/modules/SolanaFees"), exports);
|
|
24
|
+
__exportStar(require("./solana/chain/modules/SolanaSignatures"), exports);
|
|
25
|
+
__exportStar(require("./solana/chain/modules/SolanaSlots"), exports);
|
|
26
|
+
__exportStar(require("./solana/chain/modules/SolanaTokens"), exports);
|
|
27
|
+
__exportStar(require("./solana/chain/modules/SolanaTransactions"), exports);
|
|
28
|
+
__exportStar(require("./solana/chain/SolanaAction"), exports);
|
|
29
|
+
__exportStar(require("./solana/chain/SolanaChainInterface"), exports);
|
|
30
|
+
__exportStar(require("./solana/chain/SolanaModule"), exports);
|
|
31
31
|
__exportStar(require("./solana/program/modules/SolanaProgramEvents"), exports);
|
|
32
32
|
__exportStar(require("./solana/program/SolanaProgramBase"), exports);
|
|
33
33
|
__exportStar(require("./solana/swaps/SolanaSwapProgram"), exports);
|
|
@@ -1,9 +1,10 @@
|
|
|
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
|
-
|
|
9
|
+
import { SolanaChainInterface } from "./chain/SolanaChainInterface";
|
|
10
|
+
export type SolanaChainType = ChainType<"SOLANA", SolanaPreFetchData, SolanaPreFetchVerification, SolanaTx, SolanaSigner, SolanaSwapData, SolanaSwapProgram, SolanaChainInterface, SolanaChainEventsBrowser, SolanaBtcRelay<any>, never, never, never>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseTokenType, BitcoinNetwork, BitcoinRpc, ChainData, ChainInitializer, IStorageManager, StorageObject } from "@atomiqlabs/base";
|
|
2
2
|
import { Connection } from "@solana/web3.js";
|
|
3
3
|
import { StoredDataAccount } from "./swaps/modules/SolanaDataAccount";
|
|
4
|
-
import { SolanaRetryPolicy } from "./
|
|
5
|
-
import { SolanaFees } from "./
|
|
4
|
+
import { SolanaRetryPolicy } from "./chain/SolanaChainInterface";
|
|
5
|
+
import { SolanaFees } from "./chain/modules/SolanaFees";
|
|
6
6
|
import { SolanaChainType } from "./SolanaChainType";
|
|
7
7
|
export type SolanaAssetsType = BaseTokenType<"WBTC" | "USDC" | "USDT" | "SOL" | "BONK">;
|
|
8
8
|
export type SolanaSwapperOptions = {
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SolanaInitializer = exports.initializeSolana = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
const
|
|
5
|
+
const SolanaChainInterface_1 = require("./chain/SolanaChainInterface");
|
|
6
|
+
const SolanaFees_1 = require("./chain/modules/SolanaFees");
|
|
6
7
|
const SolanaBtcRelay_1 = require("./btcrelay/SolanaBtcRelay");
|
|
7
8
|
const SolanaChains_1 = require("./SolanaChains");
|
|
8
9
|
const SolanaSwapProgram_1 = require("./swaps/SolanaSwapProgram");
|
|
@@ -36,8 +37,9 @@ function initializeSolana(options, bitcoinRpc, network, storageCtor) {
|
|
|
36
37
|
new web3_js_1.Connection(options.rpcUrl) :
|
|
37
38
|
options.rpcUrl;
|
|
38
39
|
const Fees = options.fees ?? new SolanaFees_1.SolanaFees(connection, 200000, 4, 100);
|
|
39
|
-
const
|
|
40
|
-
const
|
|
40
|
+
const chainInterface = new SolanaChainInterface_1.SolanaChainInterface(connection, options.retryPolicy ?? { transactionResendInterval: 1000 }, Fees);
|
|
41
|
+
const btcRelay = new SolanaBtcRelay_1.SolanaBtcRelay(chainInterface, bitcoinRpc, options.btcRelayContract ?? SolanaChains_1.SolanaChains[network].addresses.btcRelayContract);
|
|
42
|
+
const swapContract = new SolanaSwapProgram_1.SolanaSwapProgram(chainInterface, btcRelay, options.dataAccountStorage || storageCtor("solAccounts"), options.swapContract ?? SolanaChains_1.SolanaChains[network].addresses.swapContract);
|
|
41
43
|
const chainEvents = new SolanaChainEventsBrowser_1.SolanaChainEventsBrowser(connection, swapContract);
|
|
42
44
|
return {
|
|
43
45
|
chainId,
|
|
@@ -45,8 +47,10 @@ function initializeSolana(options, bitcoinRpc, network, storageCtor) {
|
|
|
45
47
|
swapContract,
|
|
46
48
|
chainEvents,
|
|
47
49
|
swapDataConstructor: SolanaSwapData_1.SolanaSwapData,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
chainInterface,
|
|
51
|
+
spvVaultContract: null,
|
|
52
|
+
spvVaultDataConstructor: null,
|
|
53
|
+
spvVaultWithdrawalDataConstructor: null
|
|
50
54
|
};
|
|
51
55
|
}
|
|
52
56
|
exports.initializeSolana = initializeSolana;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { PublicKey, Signer, Transaction } from "@solana/web3.js";
|
|
3
3
|
import { SolanaBtcStoredHeader } from "./headers/SolanaBtcStoredHeader";
|
|
4
4
|
import { BitcoinRpc, BtcBlock, BtcRelay } from "@atomiqlabs/base";
|
|
5
5
|
import { SolanaProgramBase } from "../program/SolanaProgramBase";
|
|
6
|
-
import { SolanaAction } from "../
|
|
6
|
+
import { SolanaAction } from "../chain/SolanaAction";
|
|
7
7
|
import { Buffer } from "buffer";
|
|
8
|
-
import { SolanaFees } from "../base/modules/SolanaFees";
|
|
9
8
|
import { SolanaSigner } from "../wallet/SolanaSigner";
|
|
9
|
+
import { SolanaChainInterface } from "../chain/SolanaChainInterface";
|
|
10
10
|
export declare class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBase<any> implements BtcRelay<SolanaBtcStoredHeader, {
|
|
11
11
|
tx: Transaction;
|
|
12
12
|
signers: Signer[];
|
|
@@ -43,7 +43,7 @@ export declare class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBas
|
|
|
43
43
|
readonly maxHeadersPerTx: number;
|
|
44
44
|
readonly maxForkHeadersPerTx: number;
|
|
45
45
|
readonly maxShortForkHeadersPerTx: number;
|
|
46
|
-
constructor(
|
|
46
|
+
constructor(chainInterface: SolanaChainInterface, bitcoinRpc: BitcoinRpc<B>, programAddress?: string);
|
|
47
47
|
/**
|
|
48
48
|
* Gets set of block commitments representing current main chain from the mainState
|
|
49
49
|
*
|
|
@@ -7,9 +7,8 @@ const SolanaBtcHeader_1 = require("./headers/SolanaBtcHeader");
|
|
|
7
7
|
const programIdl = require("./program/programIdl.json");
|
|
8
8
|
const base_1 = require("@atomiqlabs/base");
|
|
9
9
|
const SolanaProgramBase_1 = require("../program/SolanaProgramBase");
|
|
10
|
-
const SolanaAction_1 = require("../
|
|
10
|
+
const SolanaAction_1 = require("../chain/SolanaAction");
|
|
11
11
|
const buffer_1 = require("buffer");
|
|
12
|
-
const SolanaFees_1 = require("../base/modules/SolanaFees");
|
|
13
12
|
const BN = require("bn.js");
|
|
14
13
|
const MAX_CLOSE_IX_PER_TX = 10;
|
|
15
14
|
function serializeBlockHeader(e) {
|
|
@@ -37,7 +36,7 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
37
36
|
*/
|
|
38
37
|
async Initialize(signer, header, epochStart, pastBlocksTimestamps) {
|
|
39
38
|
const serializedBlock = serializeBlockHeader(header);
|
|
40
|
-
return new SolanaAction_1.SolanaAction(signer, this, await this.program.methods
|
|
39
|
+
return new SolanaAction_1.SolanaAction(signer, this.Chain, await this.program.methods
|
|
41
40
|
.initialize(serializedBlock, header.getHeight(), header.getChainWork(), epochStart, pastBlocksTimestamps)
|
|
42
41
|
.accounts({
|
|
43
42
|
signer,
|
|
@@ -60,7 +59,7 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
60
59
|
* @param committedHeader
|
|
61
60
|
*/
|
|
62
61
|
async Verify(signer, reversedTxId, confirmations, position, reversedMerkleProof, committedHeader) {
|
|
63
|
-
return new SolanaAction_1.SolanaAction(signer, this, await this.program.methods
|
|
62
|
+
return new SolanaAction_1.SolanaAction(signer, this.Chain, await this.program.methods
|
|
64
63
|
.verifyTransaction(reversedTxId, confirmations, position, reversedMerkleProof, committedHeader)
|
|
65
64
|
.accounts({
|
|
66
65
|
signer,
|
|
@@ -69,7 +68,7 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
69
68
|
.instruction(), null, null, null, true);
|
|
70
69
|
}
|
|
71
70
|
async CloseForkAccount(signer, forkId) {
|
|
72
|
-
return new SolanaAction_1.SolanaAction(signer, this, await this.program.methods
|
|
71
|
+
return new SolanaAction_1.SolanaAction(signer, this.Chain, await this.program.methods
|
|
73
72
|
.closeForkAccount(new BN(forkId))
|
|
74
73
|
.accounts({
|
|
75
74
|
signer,
|
|
@@ -78,8 +77,8 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
78
77
|
})
|
|
79
78
|
.instruction(), 20000);
|
|
80
79
|
}
|
|
81
|
-
constructor(
|
|
82
|
-
super(
|
|
80
|
+
constructor(chainInterface, bitcoinRpc, programAddress) {
|
|
81
|
+
super(chainInterface, programIdl, programAddress);
|
|
83
82
|
this.BtcRelayMainState = this.pda("state");
|
|
84
83
|
this.BtcRelayHeader = this.pda("header", (hash) => [hash]);
|
|
85
84
|
this.BtcRelayFork = this.pda("fork", (forkId, pubkey) => [new BN(forkId).toArrayLike(buffer_1.Buffer, "le", 8), pubkey.toBuffer()]);
|
|
@@ -140,8 +139,8 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
140
139
|
}))
|
|
141
140
|
.transaction();
|
|
142
141
|
tx.feePayer = signer;
|
|
143
|
-
this.Fees.applyFeeRateBegin(tx, null, feeRate);
|
|
144
|
-
this.Fees.applyFeeRateEnd(tx, null, feeRate);
|
|
142
|
+
this.Chain.Fees.applyFeeRateBegin(tx, null, feeRate);
|
|
143
|
+
this.Chain.Fees.applyFeeRateEnd(tx, null, feeRate);
|
|
145
144
|
const computedCommitedHeaders = this.computeCommitedHeaders(storedHeader, blockHeaderObj);
|
|
146
145
|
const lastStoredHeader = computedCommitedHeaders[computedCommitedHeaders.length - 1];
|
|
147
146
|
if (forkId !== 0 && base_1.StatePredictorUtils.gtBuffer(buffer_1.Buffer.from(lastStoredHeader.chainWork), tipWork)) {
|
|
@@ -366,7 +365,7 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
366
365
|
const mainState = await this.program.account.mainState.fetch(this.BtcRelayMainState);
|
|
367
366
|
let forkId = mainState.forkCounter.toNumber();
|
|
368
367
|
const txs = [];
|
|
369
|
-
let action = new SolanaAction_1.SolanaAction(signer.getPublicKey(), this);
|
|
368
|
+
let action = new SolanaAction_1.SolanaAction(signer.getPublicKey(), this.Chain);
|
|
370
369
|
let lastCheckedId = lastSweepId;
|
|
371
370
|
for (let i = lastSweepId == null ? 0 : lastSweepId + 1; i <= forkId; i++) {
|
|
372
371
|
lastCheckedId = i;
|
|
@@ -378,14 +377,14 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
378
377
|
action.add(await this.CloseForkAccount(signer.getPublicKey(), i));
|
|
379
378
|
if (action.ixsLength() >= MAX_CLOSE_IX_PER_TX) {
|
|
380
379
|
await action.addToTxs(txs);
|
|
381
|
-
action = new SolanaAction_1.SolanaAction(signer.getPublicKey(), this);
|
|
380
|
+
action = new SolanaAction_1.SolanaAction(signer.getPublicKey(), this.Chain);
|
|
382
381
|
}
|
|
383
382
|
}
|
|
384
383
|
if (action.ixsLength() >= MAX_CLOSE_IX_PER_TX) {
|
|
385
384
|
await action.addToTxs(txs);
|
|
386
385
|
}
|
|
387
386
|
if (txs.length > 0) {
|
|
388
|
-
const signatures = await this.
|
|
387
|
+
const signatures = await this.Chain.sendAndConfirm(signer, txs, true);
|
|
389
388
|
this.logger.info("sweepForkData(): forks swept, signatures: " + signatures.join());
|
|
390
389
|
}
|
|
391
390
|
return lastCheckedId;
|
|
@@ -422,7 +421,7 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
422
421
|
*/
|
|
423
422
|
getMainFeeRate(signer) {
|
|
424
423
|
const _signer = signer == null ? null : new web3_js_1.PublicKey(signer);
|
|
425
|
-
return this.Fees.getFeeRate(_signer == null ? [this.BtcRelayMainState] : [
|
|
424
|
+
return this.Chain.Fees.getFeeRate(_signer == null ? [this.BtcRelayMainState] : [
|
|
426
425
|
_signer,
|
|
427
426
|
this.BtcRelayMainState
|
|
428
427
|
]);
|
|
@@ -432,7 +431,7 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
432
431
|
*/
|
|
433
432
|
getForkFeeRate(signer, forkId) {
|
|
434
433
|
const _signer = new web3_js_1.PublicKey(signer);
|
|
435
|
-
return this.Fees.getFeeRate([
|
|
434
|
+
return this.Chain.Fees.getFeeRate([
|
|
436
435
|
_signer,
|
|
437
436
|
this.BtcRelayMainState,
|
|
438
437
|
this.BtcRelayFork(forkId, _signer)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PublicKey, Signer, TransactionInstruction } from "@solana/web3.js";
|
|
2
2
|
import { SolanaTx } from "./modules/SolanaTransactions";
|
|
3
|
-
import {
|
|
3
|
+
import { SolanaChainInterface } from "./SolanaChainInterface";
|
|
4
4
|
export declare class SolanaAction {
|
|
5
5
|
computeBudget: number;
|
|
6
6
|
readonly mainSigner: PublicKey;
|
|
@@ -9,7 +9,7 @@ export declare class SolanaAction {
|
|
|
9
9
|
private feeRate;
|
|
10
10
|
private readonly signers;
|
|
11
11
|
private firstIxBeforeComputeBudget;
|
|
12
|
-
constructor(mainSigner: PublicKey, root:
|
|
12
|
+
constructor(mainSigner: PublicKey, root: SolanaChainInterface, instructions?: TransactionInstruction[] | TransactionInstruction, computeBudget?: number, feeRate?: string, signers?: Signer[], firstIxBeforeComputeBudget?: boolean);
|
|
13
13
|
private estimateFee;
|
|
14
14
|
addIx(instruction: TransactionInstruction, computeBudget?: number, signers?: Signer[]): void;
|
|
15
15
|
add(action: SolanaAction): this;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Connection, SendOptions } from "@solana/web3.js";
|
|
3
|
+
import { SolanaFees } from "./modules/SolanaFees";
|
|
4
|
+
import { SolanaBlocks } from "./modules/SolanaBlocks";
|
|
5
|
+
import { SolanaSlots } from "./modules/SolanaSlots";
|
|
6
|
+
import { SolanaTokens } from "./modules/SolanaTokens";
|
|
7
|
+
import { SolanaTransactions, SolanaTx } from "./modules/SolanaTransactions";
|
|
8
|
+
import { SolanaSignatures } from "./modules/SolanaSignatures";
|
|
9
|
+
import { SolanaEvents } from "./modules/SolanaEvents";
|
|
10
|
+
import { ChainInterface, TransactionConfirmationOptions } from "@atomiqlabs/base";
|
|
11
|
+
import { SolanaSigner } from "../wallet/SolanaSigner";
|
|
12
|
+
import { Buffer } from "buffer";
|
|
13
|
+
export type SolanaRetryPolicy = {
|
|
14
|
+
maxRetries?: number;
|
|
15
|
+
delay?: number;
|
|
16
|
+
exponential?: boolean;
|
|
17
|
+
transactionResendInterval?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare class SolanaChainInterface implements ChainInterface<SolanaTx, SolanaSigner, "SOLANA"> {
|
|
20
|
+
readonly chainId = "SOLANA";
|
|
21
|
+
readonly SLOT_TIME = 400;
|
|
22
|
+
readonly TX_SLOT_VALIDITY = 151;
|
|
23
|
+
readonly connection: Connection;
|
|
24
|
+
readonly retryPolicy: SolanaRetryPolicy;
|
|
25
|
+
readonly Blocks: SolanaBlocks;
|
|
26
|
+
Fees: SolanaFees;
|
|
27
|
+
readonly Slots: SolanaSlots;
|
|
28
|
+
readonly Tokens: SolanaTokens;
|
|
29
|
+
readonly Transactions: SolanaTransactions;
|
|
30
|
+
readonly Signatures: SolanaSignatures;
|
|
31
|
+
readonly Events: SolanaEvents;
|
|
32
|
+
protected readonly logger: {
|
|
33
|
+
debug: (msg: any, ...args: any[]) => void;
|
|
34
|
+
info: (msg: any, ...args: any[]) => void;
|
|
35
|
+
warn: (msg: any, ...args: any[]) => void;
|
|
36
|
+
error: (msg: any, ...args: any[]) => void;
|
|
37
|
+
};
|
|
38
|
+
constructor(connection: Connection, retryPolicy?: SolanaRetryPolicy, solanaFeeEstimator?: SolanaFees);
|
|
39
|
+
getBalance(signer: string, tokenAddress: string): Promise<bigint>;
|
|
40
|
+
isValidAddress(address: string): boolean;
|
|
41
|
+
getNativeCurrencyAddress(): string;
|
|
42
|
+
txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<SolanaTx[]>;
|
|
43
|
+
transfer(signer: SolanaSigner, token: string, amount: bigint, dstAddress: string, txOptions?: TransactionConfirmationOptions): Promise<string>;
|
|
44
|
+
sendAndConfirm(signer: SolanaSigner, txs: SolanaTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
|
|
45
|
+
serializeTx(tx: SolanaTx): Promise<string>;
|
|
46
|
+
deserializeTx(txData: string): Promise<SolanaTx>;
|
|
47
|
+
getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted">;
|
|
48
|
+
getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted">;
|
|
49
|
+
offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean;
|
|
50
|
+
onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void;
|
|
51
|
+
onBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): void;
|
|
52
|
+
offBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): boolean;
|
|
53
|
+
onSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): void;
|
|
54
|
+
offSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): boolean;
|
|
55
|
+
isValidToken(tokenIdentifier: string): boolean;
|
|
56
|
+
randomAddress(): string;
|
|
57
|
+
randomSigner(): SolanaSigner;
|
|
58
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaChainInterface = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const SolanaFees_1 = require("./modules/SolanaFees");
|
|
6
|
+
const SolanaBlocks_1 = require("./modules/SolanaBlocks");
|
|
7
|
+
const SolanaSlots_1 = require("./modules/SolanaSlots");
|
|
8
|
+
const SolanaTokens_1 = require("./modules/SolanaTokens");
|
|
9
|
+
const SolanaTransactions_1 = require("./modules/SolanaTransactions");
|
|
10
|
+
const SolanaSignatures_1 = require("./modules/SolanaSignatures");
|
|
11
|
+
const SolanaEvents_1 = require("./modules/SolanaEvents");
|
|
12
|
+
const Utils_1 = require("../../utils/Utils");
|
|
13
|
+
const SolanaAddresses_1 = require("./modules/SolanaAddresses");
|
|
14
|
+
const SolanaSigner_1 = require("../wallet/SolanaSigner");
|
|
15
|
+
const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
|
|
16
|
+
class SolanaChainInterface {
|
|
17
|
+
constructor(connection, retryPolicy, solanaFeeEstimator = new SolanaFees_1.SolanaFees(connection)) {
|
|
18
|
+
this.chainId = "SOLANA";
|
|
19
|
+
this.SLOT_TIME = 400;
|
|
20
|
+
this.TX_SLOT_VALIDITY = 151;
|
|
21
|
+
this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
|
|
22
|
+
this.connection = connection;
|
|
23
|
+
this.retryPolicy = retryPolicy;
|
|
24
|
+
this.Blocks = new SolanaBlocks_1.SolanaBlocks(this);
|
|
25
|
+
this.Fees = solanaFeeEstimator;
|
|
26
|
+
this.Slots = new SolanaSlots_1.SolanaSlots(this);
|
|
27
|
+
this.Tokens = new SolanaTokens_1.SolanaTokens(this);
|
|
28
|
+
this.Transactions = new SolanaTransactions_1.SolanaTransactions(this);
|
|
29
|
+
this.Signatures = new SolanaSignatures_1.SolanaSignatures(this);
|
|
30
|
+
this.Events = new SolanaEvents_1.SolanaEvents(this);
|
|
31
|
+
}
|
|
32
|
+
async getBalance(signer, tokenAddress) {
|
|
33
|
+
const token = new web3_js_1.PublicKey(tokenAddress);
|
|
34
|
+
const publicKey = new web3_js_1.PublicKey(signer);
|
|
35
|
+
let { balance } = await this.Tokens.getTokenBalance(publicKey, token);
|
|
36
|
+
if (token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS)) {
|
|
37
|
+
const accountRentExemptCost = 1000000n;
|
|
38
|
+
balance = balance - accountRentExemptCost;
|
|
39
|
+
if (balance < 0n)
|
|
40
|
+
balance = 0n;
|
|
41
|
+
}
|
|
42
|
+
this.logger.debug("getBalance(): token balance, token: " + token.toBase58() + " balance: " + balance.toString(10));
|
|
43
|
+
return balance;
|
|
44
|
+
}
|
|
45
|
+
isValidAddress(address) {
|
|
46
|
+
return SolanaAddresses_1.SolanaAddresses.isValidAddress(address);
|
|
47
|
+
}
|
|
48
|
+
getNativeCurrencyAddress() {
|
|
49
|
+
return this.Tokens.getNativeCurrencyAddress().toString();
|
|
50
|
+
}
|
|
51
|
+
txsTransfer(signer, token, amount, dstAddress, feeRate) {
|
|
52
|
+
return this.Tokens.txsTransfer(new web3_js_1.PublicKey(signer), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), feeRate);
|
|
53
|
+
}
|
|
54
|
+
async transfer(signer, token, amount, dstAddress, txOptions) {
|
|
55
|
+
const txs = await this.Tokens.txsTransfer(signer.getPublicKey(), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), txOptions?.feeRate);
|
|
56
|
+
const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
|
|
57
|
+
return txId;
|
|
58
|
+
}
|
|
59
|
+
////////////////////////////////////////////
|
|
60
|
+
//// Transactions
|
|
61
|
+
sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
|
|
62
|
+
return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
|
|
63
|
+
}
|
|
64
|
+
serializeTx(tx) {
|
|
65
|
+
return this.Transactions.serializeTx(tx);
|
|
66
|
+
}
|
|
67
|
+
deserializeTx(txData) {
|
|
68
|
+
return this.Transactions.deserializeTx(txData);
|
|
69
|
+
}
|
|
70
|
+
getTxIdStatus(txId) {
|
|
71
|
+
return this.Transactions.getTxIdStatus(txId);
|
|
72
|
+
}
|
|
73
|
+
getTxStatus(tx) {
|
|
74
|
+
return this.Transactions.getTxStatus(tx);
|
|
75
|
+
}
|
|
76
|
+
///////////////////////////////////
|
|
77
|
+
//// Callbacks & handlers
|
|
78
|
+
offBeforeTxReplace(callback) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
onBeforeTxReplace(callback) { }
|
|
82
|
+
onBeforeTxSigned(callback) {
|
|
83
|
+
this.Transactions.onBeforeTxSigned(callback);
|
|
84
|
+
}
|
|
85
|
+
offBeforeTxSigned(callback) {
|
|
86
|
+
return this.Transactions.offBeforeTxSigned(callback);
|
|
87
|
+
}
|
|
88
|
+
onSendTransaction(callback) {
|
|
89
|
+
this.Transactions.onSendTransaction(callback);
|
|
90
|
+
}
|
|
91
|
+
offSendTransaction(callback) {
|
|
92
|
+
return this.Transactions.offSendTransaction(callback);
|
|
93
|
+
}
|
|
94
|
+
isValidToken(tokenIdentifier) {
|
|
95
|
+
try {
|
|
96
|
+
new web3_js_1.PublicKey(tokenIdentifier);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
randomAddress() {
|
|
104
|
+
return web3_js_1.Keypair.generate().publicKey.toString();
|
|
105
|
+
}
|
|
106
|
+
randomSigner() {
|
|
107
|
+
const keypair = web3_js_1.Keypair.generate();
|
|
108
|
+
const wallet = new SolanaKeypairWallet_1.SolanaKeypairWallet(keypair);
|
|
109
|
+
return new SolanaSigner_1.SolanaSigner(wallet, keypair);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.SolanaChainInterface = SolanaChainInterface;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Connection } from "@solana/web3.js";
|
|
2
|
-
import {
|
|
2
|
+
import { SolanaChainInterface, SolanaRetryPolicy } from "./SolanaChainInterface";
|
|
3
3
|
export declare class SolanaModule {
|
|
4
4
|
protected readonly connection: Connection;
|
|
5
5
|
protected readonly retryPolicy: SolanaRetryPolicy;
|
|
6
|
-
protected readonly root:
|
|
6
|
+
protected readonly root: SolanaChainInterface;
|
|
7
7
|
protected readonly logger: {
|
|
8
8
|
debug: (msg: any, ...args: any[]) => void;
|
|
9
9
|
info: (msg: any, ...args: any[]) => void;
|
|
10
10
|
warn: (msg: any, ...args: any[]) => void;
|
|
11
11
|
error: (msg: any, ...args: any[]) => void;
|
|
12
12
|
};
|
|
13
|
-
constructor(root:
|
|
13
|
+
constructor(root: SolanaChainInterface);
|
|
14
14
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SolanaAddresses = void 0;
|
|
4
|
-
const SolanaModule_1 = require("../SolanaModule");
|
|
5
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
-
class SolanaAddresses
|
|
5
|
+
class SolanaAddresses {
|
|
7
6
|
///////////////////
|
|
8
7
|
//// Address utils
|
|
9
8
|
/**
|
|
@@ -11,7 +10,7 @@ class SolanaAddresses extends SolanaModule_1.SolanaModule {
|
|
|
11
10
|
*
|
|
12
11
|
* @param address
|
|
13
12
|
*/
|
|
14
|
-
isValidAddress(address) {
|
|
13
|
+
static isValidAddress(address) {
|
|
15
14
|
try {
|
|
16
15
|
return web3_js_1.PublicKey.isOnCurve(address);
|
|
17
16
|
}
|
|
@@ -12,13 +12,9 @@ export declare class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
|
12
12
|
private readonly logFetchInterval;
|
|
13
13
|
private readonly logFetchLimit;
|
|
14
14
|
private signaturesProcessing;
|
|
15
|
-
private processedSignatures;
|
|
16
|
-
private processedSignaturesIndex;
|
|
17
15
|
private stopped;
|
|
18
16
|
private timeout;
|
|
19
17
|
constructor(directory: string, connection: Connection, solanaSwapProgram: SolanaSwapProgram, logFetchInterval?: number, logFetchLimit?: number);
|
|
20
|
-
private addProcessedSignature;
|
|
21
|
-
private isSignatureProcessed;
|
|
22
18
|
/**
|
|
23
19
|
* Retrieves last signature & slot from filesystem
|
|
24
20
|
*
|
|
@@ -6,7 +6,6 @@ const SolanaChainEventsBrowser_1 = require("./SolanaChainEventsBrowser");
|
|
|
6
6
|
const BLOCKHEIGHT_FILENAME = "/blockheight.txt";
|
|
7
7
|
const LOG_FETCH_INTERVAL = 5 * 1000;
|
|
8
8
|
const LOG_FETCH_LIMIT = 500;
|
|
9
|
-
const PROCESSED_SIGNATURES_BACKLOG = 100;
|
|
10
9
|
/**
|
|
11
10
|
* Event handler for backend Node.js systems with access to fs, uses HTTP polling in combination with WS to not miss
|
|
12
11
|
* any events
|
|
@@ -15,21 +14,10 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
15
14
|
constructor(directory, connection, solanaSwapProgram, logFetchInterval, logFetchLimit) {
|
|
16
15
|
super(connection, solanaSwapProgram);
|
|
17
16
|
this.signaturesProcessing = {};
|
|
18
|
-
this.processedSignatures = [];
|
|
19
|
-
this.processedSignaturesIndex = 0;
|
|
20
17
|
this.directory = directory;
|
|
21
18
|
this.logFetchInterval = logFetchInterval || LOG_FETCH_INTERVAL;
|
|
22
19
|
this.logFetchLimit = logFetchLimit || LOG_FETCH_LIMIT;
|
|
23
20
|
}
|
|
24
|
-
addProcessedSignature(signature) {
|
|
25
|
-
this.processedSignatures[this.processedSignaturesIndex] = signature;
|
|
26
|
-
this.processedSignaturesIndex += 1;
|
|
27
|
-
if (this.processedSignaturesIndex >= PROCESSED_SIGNATURES_BACKLOG)
|
|
28
|
-
this.processedSignaturesIndex = 0;
|
|
29
|
-
}
|
|
30
|
-
isSignatureProcessed(signature) {
|
|
31
|
-
return this.processedSignatures.includes(signature);
|
|
32
|
-
}
|
|
33
21
|
/**
|
|
34
22
|
* Retrieves last signature & slot from filesystem
|
|
35
23
|
*
|
|
@@ -119,8 +107,6 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
119
107
|
return (data, slotNumber, signature) => {
|
|
120
108
|
if (this.signaturesProcessing[signature] != null)
|
|
121
109
|
return;
|
|
122
|
-
if (this.isSignatureProcessed(signature))
|
|
123
|
-
return;
|
|
124
110
|
console.log("[Solana Events WebSocket] Process signature: ", signature);
|
|
125
111
|
this.signaturesProcessing[signature] = this.processEvent({
|
|
126
112
|
events: [{ name, data: data }],
|
|
@@ -194,7 +180,6 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
194
180
|
delete this.signaturesProcessing[txSignature.signature];
|
|
195
181
|
if (result) {
|
|
196
182
|
lastSuccessfulSignature = txSignature;
|
|
197
|
-
this.addProcessedSignature(txSignature.signature);
|
|
198
183
|
continue;
|
|
199
184
|
}
|
|
200
185
|
}
|
|
@@ -205,7 +190,6 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
205
190
|
if (!result)
|
|
206
191
|
throw new Error("Failed to process signature: " + txSignature);
|
|
207
192
|
lastSuccessfulSignature = txSignature;
|
|
208
|
-
this.addProcessedSignature(txSignature.signature);
|
|
209
193
|
delete this.signaturesProcessing[txSignature.signature];
|
|
210
194
|
}
|
|
211
195
|
}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Idl, Program } from "@coral-xyz/anchor";
|
|
3
|
-
import {
|
|
4
|
-
import { SolanaBase, SolanaRetryPolicy } from "../base/SolanaBase";
|
|
3
|
+
import { SolanaChainInterface } from "../chain/SolanaChainInterface";
|
|
5
4
|
import { SolanaProgramEvents } from "./modules/SolanaProgramEvents";
|
|
6
|
-
import {
|
|
5
|
+
import { Keypair, PublicKey } from "@solana/web3.js";
|
|
7
6
|
import { Buffer } from "buffer";
|
|
8
7
|
/**
|
|
9
8
|
* Base class providing program specific utilities
|
|
10
9
|
*/
|
|
11
|
-
export declare class SolanaProgramBase<T extends Idl>
|
|
10
|
+
export declare class SolanaProgramBase<T extends Idl> {
|
|
11
|
+
protected readonly logger: {
|
|
12
|
+
debug: (msg: any, ...args: any[]) => void;
|
|
13
|
+
info: (msg: any, ...args: any[]) => void;
|
|
14
|
+
warn: (msg: any, ...args: any[]) => void;
|
|
15
|
+
error: (msg: any, ...args: any[]) => void;
|
|
16
|
+
};
|
|
12
17
|
program: Program<T>;
|
|
13
18
|
readonly Events: SolanaProgramEvents<T>;
|
|
14
|
-
|
|
19
|
+
readonly Chain: SolanaChainInterface;
|
|
20
|
+
constructor(chainInterface: SolanaChainInterface, programIdl: any, programAddress?: string);
|
|
15
21
|
/**
|
|
16
22
|
* Derives static PDA address from the seed
|
|
17
23
|
*
|
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SolanaProgramBase = void 0;
|
|
4
4
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
-
const SolanaFees_1 = require("../base/modules/SolanaFees");
|
|
6
|
-
const SolanaBase_1 = require("../base/SolanaBase");
|
|
7
5
|
const SolanaProgramEvents_1 = require("./modules/SolanaProgramEvents");
|
|
8
6
|
const web3_js_1 = require("@solana/web3.js");
|
|
9
7
|
const sha2_1 = require("@noble/hashes/sha2");
|
|
10
8
|
const buffer_1 = require("buffer");
|
|
11
9
|
const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
|
|
10
|
+
const Utils_1 = require("../../utils/Utils");
|
|
12
11
|
/**
|
|
13
12
|
* Base class providing program specific utilities
|
|
14
13
|
*/
|
|
15
|
-
class SolanaProgramBase
|
|
16
|
-
constructor(
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
14
|
+
class SolanaProgramBase {
|
|
15
|
+
constructor(chainInterface, programIdl, programAddress) {
|
|
16
|
+
this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
|
|
17
|
+
this.Chain = chainInterface;
|
|
18
|
+
this.program = new anchor_1.Program(programIdl, programAddress || programIdl.metadata.address, new anchor_1.AnchorProvider(chainInterface.connection, new SolanaKeypairWallet_1.SolanaKeypairWallet(web3_js_1.Keypair.generate()), {}));
|
|
19
|
+
this.Events = new SolanaProgramEvents_1.SolanaProgramEvents(chainInterface, this);
|
|
20
20
|
}
|
|
21
21
|
pda(seed, func) {
|
|
22
22
|
if (func == null) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SolanaModule } from "../chain/SolanaModule";
|
|
2
|
+
import { Idl } from "@coral-xyz/anchor";
|
|
3
|
+
import { SolanaProgramBase } from "./SolanaProgramBase";
|
|
4
|
+
import { SolanaChainInterface } from "../chain/SolanaChainInterface";
|
|
5
|
+
export declare class SolanaProgramModule<IDL extends Idl> extends SolanaModule {
|
|
6
|
+
protected readonly program: SolanaProgramBase<IDL>;
|
|
7
|
+
constructor(chainInterface: SolanaChainInterface, program: SolanaProgramBase<IDL>);
|
|
8
|
+
}
|