@atomiqlabs/chain-solana 13.5.13 → 13.5.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/README.md +73 -73
- package/dist/index.d.ts +81 -81
- package/dist/index.js +102 -102
- package/dist/node/index.d.ts +9 -9
- package/dist/node/index.js +13 -13
- package/dist/solana/SolanaChainType.d.ts +15 -15
- package/dist/solana/SolanaChainType.js +2 -2
- package/dist/solana/SolanaChains.d.ts +12 -12
- package/dist/solana/SolanaChains.js +45 -45
- package/dist/solana/SolanaInitializer.d.ts +94 -94
- package/dist/solana/SolanaInitializer.js +174 -174
- package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +222 -222
- package/dist/solana/btcrelay/SolanaBtcRelay.js +455 -455
- package/dist/solana/btcrelay/headers/SolanaBtcHeader.d.ts +84 -84
- package/dist/solana/btcrelay/headers/SolanaBtcHeader.js +70 -70
- package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.d.ts +92 -92
- package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.js +109 -109
- package/dist/solana/btcrelay/program/programIdl.json +671 -671
- package/dist/solana/chain/SolanaAction.d.ts +26 -26
- package/dist/solana/chain/SolanaAction.js +87 -87
- package/dist/solana/chain/SolanaChainInterface.d.ts +224 -224
- package/dist/solana/chain/SolanaChainInterface.js +275 -275
- package/dist/solana/chain/SolanaModule.d.ts +14 -14
- package/dist/solana/chain/SolanaModule.js +13 -13
- package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -8
- package/dist/solana/chain/modules/SolanaAddresses.js +22 -22
- package/dist/solana/chain/modules/SolanaBlocks.d.ts +32 -32
- package/dist/solana/chain/modules/SolanaBlocks.js +78 -78
- package/dist/solana/chain/modules/SolanaEvents.d.ts +68 -68
- package/dist/solana/chain/modules/SolanaEvents.js +238 -238
- package/dist/solana/chain/modules/SolanaFees.d.ts +189 -189
- package/dist/solana/chain/modules/SolanaFees.js +434 -434
- package/dist/solana/chain/modules/SolanaSignatures.d.ts +24 -24
- package/dist/solana/chain/modules/SolanaSignatures.js +39 -39
- package/dist/solana/chain/modules/SolanaSlots.d.ts +33 -33
- package/dist/solana/chain/modules/SolanaSlots.js +72 -72
- package/dist/solana/chain/modules/SolanaTokens.d.ts +123 -123
- package/dist/solana/chain/modules/SolanaTokens.js +242 -242
- package/dist/solana/chain/modules/SolanaTransactions.d.ts +149 -149
- package/dist/solana/chain/modules/SolanaTransactions.js +445 -445
- package/dist/solana/connection/ConnectionWithRetries.d.ts +35 -35
- package/dist/solana/connection/ConnectionWithRetries.js +86 -71
- package/dist/solana/events/SolanaChainEvents.d.ts +45 -45
- package/dist/solana/events/SolanaChainEvents.js +108 -108
- package/dist/solana/events/SolanaChainEventsBrowser.d.ts +205 -205
- package/dist/solana/events/SolanaChainEventsBrowser.js +404 -404
- package/dist/solana/program/SolanaProgramBase.d.ts +73 -73
- package/dist/solana/program/SolanaProgramBase.js +54 -54
- package/dist/solana/program/SolanaProgramModule.d.ts +8 -8
- package/dist/solana/program/SolanaProgramModule.js +11 -11
- package/dist/solana/program/modules/SolanaProgramEvents.d.ts +53 -53
- package/dist/solana/program/modules/SolanaProgramEvents.js +117 -117
- package/dist/solana/swaps/SolanaSwapData.d.ts +333 -333
- package/dist/solana/swaps/SolanaSwapData.js +535 -535
- package/dist/solana/swaps/SolanaSwapModule.d.ts +11 -11
- package/dist/solana/swaps/SolanaSwapModule.js +12 -12
- package/dist/solana/swaps/SolanaSwapProgram.d.ts +376 -376
- package/dist/solana/swaps/SolanaSwapProgram.js +769 -769
- package/dist/solana/swaps/SwapTypeEnum.d.ts +11 -11
- package/dist/solana/swaps/SwapTypeEnum.js +43 -43
- package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +95 -95
- package/dist/solana/swaps/modules/SolanaDataAccount.js +232 -232
- package/dist/solana/swaps/modules/SolanaLpVault.d.ts +69 -69
- package/dist/solana/swaps/modules/SolanaLpVault.js +171 -171
- package/dist/solana/swaps/modules/SwapClaim.d.ts +126 -126
- package/dist/solana/swaps/modules/SwapClaim.js +294 -294
- package/dist/solana/swaps/modules/SwapInit.d.ts +213 -213
- package/dist/solana/swaps/modules/SwapInit.js +658 -658
- package/dist/solana/swaps/modules/SwapRefund.d.ts +87 -87
- package/dist/solana/swaps/modules/SwapRefund.js +293 -293
- package/dist/solana/swaps/programIdl.json +945 -945
- package/dist/solana/swaps/programTypes.d.ts +943 -943
- package/dist/solana/swaps/programTypes.js +945 -945
- package/dist/solana/swaps/v1/programIdl.json +945 -945
- package/dist/solana/swaps/v1/programTypes.d.ts +943 -943
- package/dist/solana/swaps/v1/programTypes.js +945 -945
- package/dist/solana/swaps/v2/programIdl.json +952 -952
- package/dist/solana/swaps/v2/programTypes.d.ts +950 -950
- package/dist/solana/swaps/v2/programTypes.js +952 -952
- package/dist/solana/wallet/SolanaKeypairWallet.d.ts +29 -29
- package/dist/solana/wallet/SolanaKeypairWallet.js +50 -50
- package/dist/solana/wallet/SolanaSigner.d.ts +30 -30
- package/dist/solana/wallet/SolanaSigner.js +30 -30
- package/dist/utils/Utils.d.ts +58 -58
- package/dist/utils/Utils.js +170 -170
- package/node/index.d.ts +1 -1
- package/node/index.js +3 -3
- package/package.json +46 -46
- package/src/index.ts +87 -87
- package/src/node/index.ts +9 -9
- package/src/solana/SolanaChainType.ts +32 -32
- package/src/solana/SolanaChains.ts +46 -46
- package/src/solana/SolanaInitializer.ts +278 -278
- package/src/solana/btcrelay/SolanaBtcRelay.ts +615 -615
- package/src/solana/btcrelay/headers/SolanaBtcHeader.ts +116 -116
- package/src/solana/btcrelay/headers/SolanaBtcStoredHeader.ts +148 -148
- package/src/solana/btcrelay/program/programIdl.json +670 -670
- package/src/solana/chain/SolanaAction.ts +109 -109
- package/src/solana/chain/SolanaChainInterface.ts +404 -404
- package/src/solana/chain/SolanaModule.ts +20 -20
- package/src/solana/chain/modules/SolanaAddresses.ts +20 -20
- package/src/solana/chain/modules/SolanaBlocks.ts +89 -89
- package/src/solana/chain/modules/SolanaEvents.ts +271 -271
- package/src/solana/chain/modules/SolanaFees.ts +522 -522
- package/src/solana/chain/modules/SolanaSignatures.ts +39 -39
- package/src/solana/chain/modules/SolanaSlots.ts +85 -85
- package/src/solana/chain/modules/SolanaTokens.ts +300 -300
- package/src/solana/chain/modules/SolanaTransactions.ts +503 -503
- package/src/solana/connection/ConnectionWithRetries.ts +113 -96
- package/src/solana/events/SolanaChainEvents.ts +127 -127
- package/src/solana/events/SolanaChainEventsBrowser.ts +495 -495
- package/src/solana/program/SolanaProgramBase.ts +119 -119
- package/src/solana/program/SolanaProgramModule.ts +15 -15
- package/src/solana/program/modules/SolanaProgramEvents.ts +157 -157
- package/src/solana/swaps/SolanaSwapData.ts +735 -735
- package/src/solana/swaps/SolanaSwapModule.ts +19 -19
- package/src/solana/swaps/SolanaSwapProgram.ts +1074 -1074
- package/src/solana/swaps/SwapTypeEnum.ts +30 -30
- package/src/solana/swaps/modules/SolanaDataAccount.ts +302 -302
- package/src/solana/swaps/modules/SolanaLpVault.ts +208 -208
- package/src/solana/swaps/modules/SwapClaim.ts +387 -387
- package/src/solana/swaps/modules/SwapInit.ts +785 -785
- package/src/solana/swaps/modules/SwapRefund.ts +353 -353
- package/src/solana/swaps/v1/programIdl.json +944 -944
- package/src/solana/swaps/v1/programTypes.ts +1885 -1885
- package/src/solana/swaps/v2/programIdl.json +951 -951
- package/src/solana/swaps/v2/programTypes.ts +1899 -1899
- package/src/solana/wallet/SolanaKeypairWallet.ts +56 -56
- package/src/solana/wallet/SolanaSigner.ts +43 -43
- package/src/utils/Utils.ts +194 -194
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import {PublicKey, Signer, Transaction, TransactionInstruction} from "@solana/web3.js";
|
|
2
|
-
import {SolanaTx} from "./modules/SolanaTransactions";
|
|
3
|
-
import {SolanaChainInterface} from "./SolanaChainInterface";
|
|
4
|
-
import {SolanaFees} from "./modules/SolanaFees";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export class SolanaAction {
|
|
8
|
-
|
|
9
|
-
computeBudget: number | null;
|
|
10
|
-
readonly mainSigner: PublicKey;
|
|
11
|
-
private readonly root: SolanaChainInterface;
|
|
12
|
-
private readonly instructions: TransactionInstruction[];
|
|
13
|
-
private feeRate?: string;
|
|
14
|
-
private readonly signers: Signer[];
|
|
15
|
-
private firstIxBeforeComputeBudget: boolean = false;
|
|
16
|
-
|
|
17
|
-
constructor(
|
|
18
|
-
mainSigner: PublicKey,
|
|
19
|
-
root: SolanaChainInterface,
|
|
20
|
-
instructions: TransactionInstruction[] | TransactionInstruction = [],
|
|
21
|
-
computeBudget: number = 0,
|
|
22
|
-
feeRate?: string,
|
|
23
|
-
signers?: Signer[],
|
|
24
|
-
firstIxBeforeComputeBudget?: boolean
|
|
25
|
-
) {
|
|
26
|
-
this.mainSigner = mainSigner;
|
|
27
|
-
this.root = root;
|
|
28
|
-
this.instructions = Array.isArray(instructions) ? instructions : [instructions];
|
|
29
|
-
this.computeBudget = computeBudget;
|
|
30
|
-
this.feeRate = feeRate;
|
|
31
|
-
this.signers = signers || [];
|
|
32
|
-
if(firstIxBeforeComputeBudget!=null) this.firstIxBeforeComputeBudget = firstIxBeforeComputeBudget;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private estimateFee(): Promise<string> {
|
|
36
|
-
const mutableAccounts: PublicKey[] = [];
|
|
37
|
-
this.instructions.forEach(
|
|
38
|
-
ix => ix.keys.forEach(
|
|
39
|
-
key => key.isWritable && mutableAccounts.push(key.pubkey)
|
|
40
|
-
)
|
|
41
|
-
);
|
|
42
|
-
return this.root.Fees.getFeeRate(mutableAccounts);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public addIx(instruction: TransactionInstruction, computeBudget?: number, signers?: Signer[]) {
|
|
46
|
-
this.instructions.push(instruction);
|
|
47
|
-
if(this.computeBudget==null) {
|
|
48
|
-
this.computeBudget = computeBudget ?? null;
|
|
49
|
-
} else {
|
|
50
|
-
if(computeBudget!=null) this.computeBudget+=computeBudget;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public add(action: SolanaAction): this {
|
|
55
|
-
return this.addAction(action);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public addAction(action: SolanaAction, index: number = this.instructions.length, noSignerCheck?: boolean): this {
|
|
59
|
-
if(action.firstIxBeforeComputeBudget) {
|
|
60
|
-
if(this.instructions.length>0)
|
|
61
|
-
throw new Error("Tried to add firstIxBeforeComputeBudget action to existing action with instructions");
|
|
62
|
-
this.firstIxBeforeComputeBudget = true;
|
|
63
|
-
}
|
|
64
|
-
if(this.firstIxBeforeComputeBudget && this.instructions.length>0 && index===0)
|
|
65
|
-
throw new Error("Tried adding to firstIxBeforeComputeBudget action on 0th index");
|
|
66
|
-
if(!noSignerCheck && !action.mainSigner.equals(this.mainSigner)) throw new Error("Actions need to have the same signer!");
|
|
67
|
-
if(this.computeBudget==null && action.computeBudget!=null) this.computeBudget = action.computeBudget;
|
|
68
|
-
if(this.computeBudget!=null && action.computeBudget!=null) this.computeBudget += action.computeBudget;
|
|
69
|
-
this.instructions.splice(index, 0, ...action.instructions);
|
|
70
|
-
this.signers.push(...action.signers);
|
|
71
|
-
if(this.feeRate==null) this.feeRate = action.feeRate;
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public async tx(feeRate?: string, block?: {blockhash: string, blockHeight: number}): Promise<SolanaTx> {
|
|
76
|
-
const tx = new Transaction();
|
|
77
|
-
tx.feePayer = this.mainSigner;
|
|
78
|
-
|
|
79
|
-
if(feeRate==null) feeRate = this.feeRate;
|
|
80
|
-
if(feeRate==null) feeRate = await this.estimateFee();
|
|
81
|
-
|
|
82
|
-
let instructions = this.instructions;
|
|
83
|
-
if(instructions.length>0 && this.firstIxBeforeComputeBudget) {
|
|
84
|
-
tx.add(this.instructions[0]);
|
|
85
|
-
instructions = this.instructions.slice(1);
|
|
86
|
-
}
|
|
87
|
-
SolanaFees.applyFeeRateBegin(tx, this.computeBudget, feeRate);
|
|
88
|
-
instructions.forEach(ix => tx.add(ix));
|
|
89
|
-
SolanaFees.applyFeeRateEnd(tx, this.computeBudget, feeRate);
|
|
90
|
-
|
|
91
|
-
if(block!=null) {
|
|
92
|
-
tx.recentBlockhash = block.blockhash;
|
|
93
|
-
tx.lastValidBlockHeight = block.blockHeight + this.root._TX_SLOT_VALIDITY;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
tx,
|
|
98
|
-
signers: this.signers
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public async addToTxs(txs: SolanaTx[], feeRate?: string, block?: {blockhash: string, blockHeight: number}): Promise<void> {
|
|
103
|
-
txs.push(await this.tx(feeRate, block));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
public ixsLength(): number {
|
|
107
|
-
return this.instructions.length;
|
|
108
|
-
}
|
|
109
|
-
|
|
1
|
+
import {PublicKey, Signer, Transaction, TransactionInstruction} from "@solana/web3.js";
|
|
2
|
+
import {SolanaTx} from "./modules/SolanaTransactions";
|
|
3
|
+
import {SolanaChainInterface} from "./SolanaChainInterface";
|
|
4
|
+
import {SolanaFees} from "./modules/SolanaFees";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export class SolanaAction {
|
|
8
|
+
|
|
9
|
+
computeBudget: number | null;
|
|
10
|
+
readonly mainSigner: PublicKey;
|
|
11
|
+
private readonly root: SolanaChainInterface;
|
|
12
|
+
private readonly instructions: TransactionInstruction[];
|
|
13
|
+
private feeRate?: string;
|
|
14
|
+
private readonly signers: Signer[];
|
|
15
|
+
private firstIxBeforeComputeBudget: boolean = false;
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
mainSigner: PublicKey,
|
|
19
|
+
root: SolanaChainInterface,
|
|
20
|
+
instructions: TransactionInstruction[] | TransactionInstruction = [],
|
|
21
|
+
computeBudget: number = 0,
|
|
22
|
+
feeRate?: string,
|
|
23
|
+
signers?: Signer[],
|
|
24
|
+
firstIxBeforeComputeBudget?: boolean
|
|
25
|
+
) {
|
|
26
|
+
this.mainSigner = mainSigner;
|
|
27
|
+
this.root = root;
|
|
28
|
+
this.instructions = Array.isArray(instructions) ? instructions : [instructions];
|
|
29
|
+
this.computeBudget = computeBudget;
|
|
30
|
+
this.feeRate = feeRate;
|
|
31
|
+
this.signers = signers || [];
|
|
32
|
+
if(firstIxBeforeComputeBudget!=null) this.firstIxBeforeComputeBudget = firstIxBeforeComputeBudget;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private estimateFee(): Promise<string> {
|
|
36
|
+
const mutableAccounts: PublicKey[] = [];
|
|
37
|
+
this.instructions.forEach(
|
|
38
|
+
ix => ix.keys.forEach(
|
|
39
|
+
key => key.isWritable && mutableAccounts.push(key.pubkey)
|
|
40
|
+
)
|
|
41
|
+
);
|
|
42
|
+
return this.root.Fees.getFeeRate(mutableAccounts);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public addIx(instruction: TransactionInstruction, computeBudget?: number, signers?: Signer[]) {
|
|
46
|
+
this.instructions.push(instruction);
|
|
47
|
+
if(this.computeBudget==null) {
|
|
48
|
+
this.computeBudget = computeBudget ?? null;
|
|
49
|
+
} else {
|
|
50
|
+
if(computeBudget!=null) this.computeBudget+=computeBudget;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public add(action: SolanaAction): this {
|
|
55
|
+
return this.addAction(action);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public addAction(action: SolanaAction, index: number = this.instructions.length, noSignerCheck?: boolean): this {
|
|
59
|
+
if(action.firstIxBeforeComputeBudget) {
|
|
60
|
+
if(this.instructions.length>0)
|
|
61
|
+
throw new Error("Tried to add firstIxBeforeComputeBudget action to existing action with instructions");
|
|
62
|
+
this.firstIxBeforeComputeBudget = true;
|
|
63
|
+
}
|
|
64
|
+
if(this.firstIxBeforeComputeBudget && this.instructions.length>0 && index===0)
|
|
65
|
+
throw new Error("Tried adding to firstIxBeforeComputeBudget action on 0th index");
|
|
66
|
+
if(!noSignerCheck && !action.mainSigner.equals(this.mainSigner)) throw new Error("Actions need to have the same signer!");
|
|
67
|
+
if(this.computeBudget==null && action.computeBudget!=null) this.computeBudget = action.computeBudget;
|
|
68
|
+
if(this.computeBudget!=null && action.computeBudget!=null) this.computeBudget += action.computeBudget;
|
|
69
|
+
this.instructions.splice(index, 0, ...action.instructions);
|
|
70
|
+
this.signers.push(...action.signers);
|
|
71
|
+
if(this.feeRate==null) this.feeRate = action.feeRate;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public async tx(feeRate?: string, block?: {blockhash: string, blockHeight: number}): Promise<SolanaTx> {
|
|
76
|
+
const tx = new Transaction();
|
|
77
|
+
tx.feePayer = this.mainSigner;
|
|
78
|
+
|
|
79
|
+
if(feeRate==null) feeRate = this.feeRate;
|
|
80
|
+
if(feeRate==null) feeRate = await this.estimateFee();
|
|
81
|
+
|
|
82
|
+
let instructions = this.instructions;
|
|
83
|
+
if(instructions.length>0 && this.firstIxBeforeComputeBudget) {
|
|
84
|
+
tx.add(this.instructions[0]);
|
|
85
|
+
instructions = this.instructions.slice(1);
|
|
86
|
+
}
|
|
87
|
+
SolanaFees.applyFeeRateBegin(tx, this.computeBudget, feeRate);
|
|
88
|
+
instructions.forEach(ix => tx.add(ix));
|
|
89
|
+
SolanaFees.applyFeeRateEnd(tx, this.computeBudget, feeRate);
|
|
90
|
+
|
|
91
|
+
if(block!=null) {
|
|
92
|
+
tx.recentBlockhash = block.blockhash;
|
|
93
|
+
tx.lastValidBlockHeight = block.blockHeight + this.root._TX_SLOT_VALIDITY;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
tx,
|
|
98
|
+
signers: this.signers
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public async addToTxs(txs: SolanaTx[], feeRate?: string, block?: {blockhash: string, blockHeight: number}): Promise<void> {
|
|
103
|
+
txs.push(await this.tx(feeRate, block));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public ixsLength(): number {
|
|
107
|
+
return this.instructions.length;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
110
|
}
|