@atomiqlabs/chain-solana 8.0.2 → 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/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/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
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {PublicKey, Signer, Transaction, TransactionInstruction} from "@solana/web3.js";
|
|
2
2
|
import {SolanaTx} from "./modules/SolanaTransactions";
|
|
3
|
-
import {
|
|
3
|
+
import {SolanaChainInterface} from "./SolanaChainInterface";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export class SolanaAction {
|
|
7
7
|
|
|
8
8
|
computeBudget: number;
|
|
9
9
|
readonly mainSigner: PublicKey;
|
|
10
|
-
private readonly root:
|
|
10
|
+
private readonly root: SolanaChainInterface;
|
|
11
11
|
private readonly instructions: TransactionInstruction[];
|
|
12
12
|
private feeRate: string;
|
|
13
13
|
private readonly signers: Signer[];
|
|
@@ -15,7 +15,7 @@ export class SolanaAction {
|
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
17
17
|
mainSigner: PublicKey,
|
|
18
|
-
root:
|
|
18
|
+
root: SolanaChainInterface,
|
|
19
19
|
instructions: TransactionInstruction[] | TransactionInstruction = [],
|
|
20
20
|
computeBudget: number = 0,
|
|
21
21
|
feeRate?: string,
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {Connection, Keypair, PublicKey, SendOptions} from "@solana/web3.js";
|
|
2
|
+
import {SolanaFees} from "./modules/SolanaFees";
|
|
3
|
+
import {SolanaBlocks} from "./modules/SolanaBlocks";
|
|
4
|
+
import {SolanaSlots} from "./modules/SolanaSlots";
|
|
5
|
+
import {SolanaTokens} from "./modules/SolanaTokens";
|
|
6
|
+
import {SolanaTransactions, SolanaTx} from "./modules/SolanaTransactions";
|
|
7
|
+
import {SolanaSignatures} from "./modules/SolanaSignatures";
|
|
8
|
+
import {SolanaEvents} from "./modules/SolanaEvents";
|
|
9
|
+
import {getLogger} from "../../utils/Utils";
|
|
10
|
+
import {ChainInterface, TransactionConfirmationOptions} from "@atomiqlabs/base";
|
|
11
|
+
import {SolanaAddresses} from "./modules/SolanaAddresses";
|
|
12
|
+
import {SolanaSigner} from "../wallet/SolanaSigner";
|
|
13
|
+
import {Buffer} from "buffer";
|
|
14
|
+
import {SolanaKeypairWallet} from "../wallet/SolanaKeypairWallet";
|
|
15
|
+
|
|
16
|
+
export type SolanaRetryPolicy = {
|
|
17
|
+
maxRetries?: number,
|
|
18
|
+
delay?: number,
|
|
19
|
+
exponential?: boolean,
|
|
20
|
+
transactionResendInterval?: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class SolanaChainInterface implements ChainInterface<
|
|
24
|
+
SolanaTx,
|
|
25
|
+
SolanaSigner,
|
|
26
|
+
"SOLANA"
|
|
27
|
+
> {
|
|
28
|
+
readonly chainId = "SOLANA";
|
|
29
|
+
|
|
30
|
+
public readonly SLOT_TIME = 400;
|
|
31
|
+
public readonly TX_SLOT_VALIDITY = 151;
|
|
32
|
+
|
|
33
|
+
readonly connection: Connection;
|
|
34
|
+
readonly retryPolicy: SolanaRetryPolicy;
|
|
35
|
+
|
|
36
|
+
public readonly Blocks: SolanaBlocks;
|
|
37
|
+
public Fees: SolanaFees;
|
|
38
|
+
public readonly Slots: SolanaSlots;
|
|
39
|
+
public readonly Tokens: SolanaTokens;
|
|
40
|
+
public readonly Transactions: SolanaTransactions;
|
|
41
|
+
public readonly Signatures: SolanaSignatures;
|
|
42
|
+
public readonly Events: SolanaEvents;
|
|
43
|
+
|
|
44
|
+
protected readonly logger = getLogger(this.constructor.name+": ");
|
|
45
|
+
|
|
46
|
+
constructor(
|
|
47
|
+
connection: Connection,
|
|
48
|
+
retryPolicy?: SolanaRetryPolicy,
|
|
49
|
+
solanaFeeEstimator: SolanaFees = new SolanaFees(connection)
|
|
50
|
+
) {
|
|
51
|
+
this.connection = connection;
|
|
52
|
+
this.retryPolicy = retryPolicy;
|
|
53
|
+
|
|
54
|
+
this.Blocks = new SolanaBlocks(this);
|
|
55
|
+
this.Fees = solanaFeeEstimator;
|
|
56
|
+
this.Slots = new SolanaSlots(this);
|
|
57
|
+
this.Tokens = new SolanaTokens(this);
|
|
58
|
+
this.Transactions = new SolanaTransactions(this);
|
|
59
|
+
this.Signatures = new SolanaSignatures(this);
|
|
60
|
+
this.Events = new SolanaEvents(this);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async getBalance(signer: string, tokenAddress: string): Promise<bigint> {
|
|
64
|
+
const token = new PublicKey(tokenAddress);
|
|
65
|
+
const publicKey = new PublicKey(signer);
|
|
66
|
+
|
|
67
|
+
let { balance } = await this.Tokens.getTokenBalance(publicKey, token);
|
|
68
|
+
if(token.equals(SolanaTokens.WSOL_ADDRESS)) {
|
|
69
|
+
const accountRentExemptCost = 1000000n;
|
|
70
|
+
balance = balance - accountRentExemptCost;
|
|
71
|
+
if(balance < 0n) balance = 0n;
|
|
72
|
+
}
|
|
73
|
+
this.logger.debug("getBalance(): token balance, token: "+token.toBase58()+" balance: "+balance.toString(10));
|
|
74
|
+
return balance;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
isValidAddress(address: string): boolean {
|
|
78
|
+
return SolanaAddresses.isValidAddress(address);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getNativeCurrencyAddress(): string {
|
|
82
|
+
return this.Tokens.getNativeCurrencyAddress().toString();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<SolanaTx[]> {
|
|
86
|
+
return this.Tokens.txsTransfer(new PublicKey(signer), new PublicKey(token), amount, new PublicKey(dstAddress), feeRate);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async transfer(
|
|
90
|
+
signer: SolanaSigner,
|
|
91
|
+
token: string,
|
|
92
|
+
amount: bigint,
|
|
93
|
+
dstAddress: string,
|
|
94
|
+
txOptions?: TransactionConfirmationOptions
|
|
95
|
+
): Promise<string> {
|
|
96
|
+
const txs = await this.Tokens.txsTransfer(signer.getPublicKey(), new PublicKey(token), amount, new PublicKey(dstAddress), txOptions?.feeRate);
|
|
97
|
+
const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
|
|
98
|
+
return txId;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
////////////////////////////////////////////
|
|
103
|
+
//// Transactions
|
|
104
|
+
sendAndConfirm(
|
|
105
|
+
signer: SolanaSigner,
|
|
106
|
+
txs: SolanaTx[],
|
|
107
|
+
waitForConfirmation?: boolean,
|
|
108
|
+
abortSignal?: AbortSignal,
|
|
109
|
+
parallel?: boolean,
|
|
110
|
+
onBeforePublish?: (txId: string, rawTx: string) => Promise<void>
|
|
111
|
+
): Promise<string[]> {
|
|
112
|
+
return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
serializeTx(tx: SolanaTx): Promise<string> {
|
|
116
|
+
return this.Transactions.serializeTx(tx);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
deserializeTx(txData: string): Promise<SolanaTx> {
|
|
120
|
+
return this.Transactions.deserializeTx(txData);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted"> {
|
|
124
|
+
return this.Transactions.getTxIdStatus(txId);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted"> {
|
|
128
|
+
return this.Transactions.getTxStatus(tx);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
///////////////////////////////////
|
|
133
|
+
//// Callbacks & handlers
|
|
134
|
+
offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void {}
|
|
139
|
+
|
|
140
|
+
onBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): void {
|
|
141
|
+
this.Transactions.onBeforeTxSigned(callback);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
offBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): boolean {
|
|
145
|
+
return this.Transactions.offBeforeTxSigned(callback);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
onSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): void {
|
|
149
|
+
this.Transactions.onSendTransaction(callback);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
offSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): boolean {
|
|
153
|
+
return this.Transactions.offSendTransaction(callback);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
isValidToken(tokenIdentifier: string): boolean {
|
|
157
|
+
try {
|
|
158
|
+
new PublicKey(tokenIdentifier);
|
|
159
|
+
return true;
|
|
160
|
+
} catch (e) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
randomAddress(): string {
|
|
166
|
+
return Keypair.generate().publicKey.toString();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
randomSigner(): SolanaSigner {
|
|
170
|
+
const keypair = Keypair.generate();
|
|
171
|
+
const wallet = new SolanaKeypairWallet(keypair);
|
|
172
|
+
return new SolanaSigner(wallet, keypair);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {Connection} from "@solana/web3.js";
|
|
2
|
-
import {
|
|
2
|
+
import {SolanaChainInterface, SolanaRetryPolicy} from "./SolanaChainInterface";
|
|
3
3
|
import {getLogger} from "../../utils/Utils";
|
|
4
4
|
|
|
5
5
|
export class SolanaModule {
|
|
6
6
|
|
|
7
7
|
protected readonly connection: Connection;
|
|
8
8
|
protected readonly retryPolicy: SolanaRetryPolicy;
|
|
9
|
-
protected readonly root:
|
|
9
|
+
protected readonly root: SolanaChainInterface;
|
|
10
10
|
|
|
11
11
|
protected readonly logger = getLogger(this.constructor.name+": ");
|
|
12
12
|
|
|
13
13
|
constructor(
|
|
14
|
-
root:
|
|
14
|
+
root: SolanaChainInterface
|
|
15
15
|
) {
|
|
16
16
|
this.connection = root.connection;
|
|
17
17
|
this.retryPolicy = root.retryPolicy;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {SolanaModule} from "../SolanaModule";
|
|
2
1
|
import {PublicKey} from "@solana/web3.js";
|
|
3
2
|
|
|
4
3
|
|
|
5
|
-
export class SolanaAddresses
|
|
4
|
+
export class SolanaAddresses {
|
|
6
5
|
|
|
7
6
|
///////////////////
|
|
8
7
|
//// Address utils
|
|
@@ -11,7 +10,7 @@ export class SolanaAddresses extends SolanaModule {
|
|
|
11
10
|
*
|
|
12
11
|
* @param address
|
|
13
12
|
*/
|
|
14
|
-
isValidAddress(address: string): boolean {
|
|
13
|
+
static isValidAddress(address: string): boolean {
|
|
15
14
|
try {
|
|
16
15
|
return PublicKey.isOnCurve(address);
|
|
17
16
|
} catch (e) {
|
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
import {AnchorProvider, Idl, Program} from "@coral-xyz/anchor";
|
|
2
|
-
import {SolanaFees} from "../
|
|
3
|
-
import {
|
|
2
|
+
import {SolanaFees} from "../chain/modules/SolanaFees";
|
|
3
|
+
import {SolanaChainInterface, SolanaRetryPolicy} from "../chain/SolanaChainInterface";
|
|
4
4
|
import {SolanaProgramEvents} from "./modules/SolanaProgramEvents";
|
|
5
5
|
import {Connection, Keypair, PublicKey} from "@solana/web3.js";
|
|
6
6
|
import {sha256} from "@noble/hashes/sha2";
|
|
7
7
|
import {Buffer} from "buffer";
|
|
8
8
|
import {SolanaKeypairWallet} from "../wallet/SolanaKeypairWallet";
|
|
9
|
+
import {getLogger} from "../../utils/Utils";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Base class providing program specific utilities
|
|
12
13
|
*/
|
|
13
|
-
export class SolanaProgramBase<T extends Idl>
|
|
14
|
+
export class SolanaProgramBase<T extends Idl> {
|
|
15
|
+
|
|
16
|
+
protected readonly logger = getLogger(this.constructor.name+": ");
|
|
14
17
|
|
|
15
18
|
program: Program<T>;
|
|
16
19
|
|
|
17
20
|
public readonly Events: SolanaProgramEvents<T>;
|
|
21
|
+
public readonly Chain: SolanaChainInterface;
|
|
18
22
|
|
|
19
23
|
constructor(
|
|
20
|
-
|
|
24
|
+
chainInterface: SolanaChainInterface,
|
|
21
25
|
programIdl: any,
|
|
22
|
-
programAddress?: string
|
|
23
|
-
retryPolicy?: SolanaRetryPolicy,
|
|
24
|
-
solanaFeeEstimator: SolanaFees = new SolanaFees(connection)
|
|
26
|
+
programAddress?: string
|
|
25
27
|
) {
|
|
26
|
-
|
|
28
|
+
this.Chain = chainInterface;
|
|
29
|
+
|
|
27
30
|
this.program = new Program<T>(
|
|
28
31
|
programIdl as any,
|
|
29
32
|
programAddress || programIdl.metadata.address,
|
|
30
|
-
new AnchorProvider(connection, new SolanaKeypairWallet(Keypair.generate()), {})
|
|
33
|
+
new AnchorProvider(chainInterface.connection, new SolanaKeypairWallet(Keypair.generate()), {})
|
|
31
34
|
);
|
|
32
35
|
|
|
33
|
-
this.Events = new SolanaProgramEvents(this);
|
|
36
|
+
this.Events = new SolanaProgramEvents(chainInterface, this);
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
/**
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
|
|
6
|
+
|
|
7
|
+
export class SolanaProgramModule<IDL extends Idl> extends SolanaModule {
|
|
8
|
+
|
|
9
|
+
protected readonly program: SolanaProgramBase<IDL>;
|
|
10
|
+
|
|
11
|
+
constructor(chainInterface: SolanaChainInterface, program: SolanaProgramBase<IDL>) {
|
|
12
|
+
super(chainInterface);
|
|
13
|
+
this.program = program;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {SolanaEvents} from "../../
|
|
1
|
+
import {SolanaEvents} from "../../chain/modules/SolanaEvents";
|
|
2
2
|
import {BorshCoder, DecodeType, Event, EventParser, Idl, IdlTypes, Instruction} from "@coral-xyz/anchor";
|
|
3
3
|
import {IdlField, IdlInstruction} from "@coral-xyz/anchor/dist/cjs/idl";
|
|
4
4
|
import {ConfirmedSignatureInfo, ParsedMessage, PartiallyDecodedInstruction, PublicKey} from "@solana/web3.js";
|
|
5
5
|
import {SolanaProgramBase} from "../SolanaProgramBase";
|
|
6
|
+
import {SolanaChainInterface} from "../../chain/SolanaChainInterface";
|
|
6
7
|
|
|
7
8
|
type DecodedFieldOrNull<D, Defined> = D extends IdlField ? DecodeType<D["type"], Defined> : unknown;
|
|
8
9
|
type ArgsTuple<A extends IdlField[], Defined> = {
|
|
@@ -25,16 +26,16 @@ export class SolanaProgramEvents<IDL extends Idl> extends SolanaEvents {
|
|
|
25
26
|
|
|
26
27
|
private readonly programCoder: BorshCoder;
|
|
27
28
|
private readonly eventParser: EventParser;
|
|
28
|
-
readonly
|
|
29
|
+
private readonly program: SolanaProgramBase<IDL>;
|
|
29
30
|
private readonly nameMappedInstructions: {[name: string]: IdlInstruction};
|
|
30
31
|
|
|
31
|
-
constructor(
|
|
32
|
-
super(
|
|
33
|
-
this.
|
|
34
|
-
this.programCoder = new BorshCoder(
|
|
35
|
-
this.eventParser = new EventParser(
|
|
32
|
+
constructor(chain: SolanaChainInterface, program: SolanaProgramBase<IDL>) {
|
|
33
|
+
super(chain);
|
|
34
|
+
this.program = program;
|
|
35
|
+
this.programCoder = new BorshCoder(program.program.idl);
|
|
36
|
+
this.eventParser = new EventParser(program.program.programId, this.programCoder);
|
|
36
37
|
this.nameMappedInstructions = {};
|
|
37
|
-
for(let ix of
|
|
38
|
+
for(let ix of program.program.idl.instructions) {
|
|
38
39
|
this.nameMappedInstructions[ix.name] = ix;
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -94,7 +95,7 @@ export class SolanaProgramEvents<IDL extends Idl> extends SolanaEvents {
|
|
|
94
95
|
const instructions: InstructionWithAccounts<IDL>[] = [];
|
|
95
96
|
|
|
96
97
|
for(let _ix of transactionMessage.instructions) {
|
|
97
|
-
if(!_ix.programId.equals(this.
|
|
98
|
+
if(!_ix.programId.equals(this.program.program.programId)) {
|
|
98
99
|
instructions.push(null);
|
|
99
100
|
continue;
|
|
100
101
|
}
|
|
@@ -7,7 +7,7 @@ import {SwapTypeEnum} from "./SwapTypeEnum";
|
|
|
7
7
|
import {Buffer} from "buffer";
|
|
8
8
|
import {getAssociatedTokenAddressSync} from "@solana/spl-token";
|
|
9
9
|
import {toBigInt, toClaimHash, toEscrowHash} from "../../utils/Utils";
|
|
10
|
-
import {SolanaTokens} from "../
|
|
10
|
+
import {SolanaTokens} from "../chain/modules/SolanaTokens";
|
|
11
11
|
|
|
12
12
|
const EXPIRY_BLOCKHEIGHT_THRESHOLD = new BN("1000000000");
|
|
13
13
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {SolanaModule} from "../base/SolanaModule";
|
|
2
1
|
import {SolanaSwapProgram} from "./SolanaSwapProgram";
|
|
3
2
|
import {Program} from "@coral-xyz/anchor";
|
|
4
3
|
import {SwapProgram} from "./programTypes";
|
|
4
|
+
import {SolanaProgramModule} from "../program/SolanaProgramModule";
|
|
5
|
+
import {SolanaChainInterface} from "../chain/SolanaChainInterface";
|
|
5
6
|
|
|
6
|
-
export class SolanaSwapModule extends
|
|
7
|
+
export class SolanaSwapModule extends SolanaProgramModule<SwapProgram> {
|
|
7
8
|
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
9
|
+
protected readonly program: SolanaSwapProgram;
|
|
10
|
+
protected readonly swapProgram: Program<SwapProgram>;
|
|
10
11
|
|
|
11
|
-
constructor(
|
|
12
|
-
super(
|
|
13
|
-
this.
|
|
14
|
-
this.program = root.program;
|
|
12
|
+
constructor(chainInterface: SolanaChainInterface, program: SolanaSwapProgram) {
|
|
13
|
+
super(chainInterface, program);
|
|
14
|
+
this.swapProgram = program.program;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
}
|