@solana/web3.js 1.42.0 → 1.43.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/lib/index.browser.cjs.js +59 -3
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +59 -3
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +59 -3
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +40 -6
- package/lib/index.esm.js +59 -3
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +59 -3
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/package.json +1 -1
- package/src/compute-budget.ts +92 -3
- package/src/connection.ts +7 -5
- package/src/transaction.ts +0 -1
- package/src/util/send-and-confirm-raw-transaction.ts +6 -6
package/package.json
CHANGED
package/src/compute-budget.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
2
|
+
import {u64} from '@solana/buffer-layout-utils';
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
5
|
encodeData,
|
|
@@ -76,6 +77,34 @@ export class ComputeBudgetInstruction {
|
|
|
76
77
|
return {bytes};
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Decode set compute unit limit compute budget instruction and retrieve the instruction params.
|
|
82
|
+
*/
|
|
83
|
+
static decodeSetComputeUnitLimit(
|
|
84
|
+
instruction: TransactionInstruction,
|
|
85
|
+
): SetComputeUnitLimitParams {
|
|
86
|
+
this.checkProgramId(instruction.programId);
|
|
87
|
+
const {units} = decodeData(
|
|
88
|
+
COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit,
|
|
89
|
+
instruction.data,
|
|
90
|
+
);
|
|
91
|
+
return {units};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Decode set compute unit price compute budget instruction and retrieve the instruction params.
|
|
96
|
+
*/
|
|
97
|
+
static decodeSetComputeUnitPrice(
|
|
98
|
+
instruction: TransactionInstruction,
|
|
99
|
+
): SetComputeUnitPriceParams {
|
|
100
|
+
this.checkProgramId(instruction.programId);
|
|
101
|
+
const {microLamports} = decodeData(
|
|
102
|
+
COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice,
|
|
103
|
+
instruction.data,
|
|
104
|
+
);
|
|
105
|
+
return {microLamports};
|
|
106
|
+
}
|
|
107
|
+
|
|
79
108
|
/**
|
|
80
109
|
* @internal
|
|
81
110
|
*/
|
|
@@ -96,11 +125,18 @@ export type ComputeBudgetInstructionType =
|
|
|
96
125
|
// It would be preferable for this type to be `keyof ComputeBudgetInstructionInputData`
|
|
97
126
|
// but Typedoc does not transpile `keyof` expressions.
|
|
98
127
|
// See https://github.com/TypeStrong/typedoc/issues/1894
|
|
99
|
-
|
|
128
|
+
| 'RequestUnits'
|
|
129
|
+
| 'RequestHeapFrame'
|
|
130
|
+
| 'SetComputeUnitLimit'
|
|
131
|
+
| 'SetComputeUnitPrice';
|
|
100
132
|
|
|
101
133
|
type ComputeBudgetInstructionInputData = {
|
|
102
134
|
RequestUnits: IInstructionInputData & Readonly<RequestUnitsParams>;
|
|
103
135
|
RequestHeapFrame: IInstructionInputData & Readonly<RequestHeapFrameParams>;
|
|
136
|
+
SetComputeUnitLimit: IInstructionInputData &
|
|
137
|
+
Readonly<SetComputeUnitLimitParams>;
|
|
138
|
+
SetComputeUnitPrice: IInstructionInputData &
|
|
139
|
+
Readonly<SetComputeUnitPriceParams>;
|
|
104
140
|
};
|
|
105
141
|
|
|
106
142
|
/**
|
|
@@ -109,8 +145,7 @@ type ComputeBudgetInstructionInputData = {
|
|
|
109
145
|
export interface RequestUnitsParams {
|
|
110
146
|
/** Units to request for transaction-wide compute */
|
|
111
147
|
units: number;
|
|
112
|
-
|
|
113
|
-
/** Additional fee to pay */
|
|
148
|
+
/** Prioritization fee lamports */
|
|
114
149
|
additionalFee: number;
|
|
115
150
|
}
|
|
116
151
|
|
|
@@ -122,6 +157,22 @@ export type RequestHeapFrameParams = {
|
|
|
122
157
|
bytes: number;
|
|
123
158
|
};
|
|
124
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Set compute unit limit instruction params
|
|
162
|
+
*/
|
|
163
|
+
export interface SetComputeUnitLimitParams {
|
|
164
|
+
/** Transaction-wide compute unit limit */
|
|
165
|
+
units: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Set compute unit price instruction params
|
|
170
|
+
*/
|
|
171
|
+
export interface SetComputeUnitPriceParams {
|
|
172
|
+
/** Transaction compute unit price used for prioritization fees */
|
|
173
|
+
microLamports: number | bigint;
|
|
174
|
+
}
|
|
175
|
+
|
|
125
176
|
/**
|
|
126
177
|
* An enumeration of valid ComputeBudget InstructionType's
|
|
127
178
|
* @internal
|
|
@@ -147,6 +198,18 @@ export const COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze<{
|
|
|
147
198
|
ComputeBudgetInstructionInputData['RequestHeapFrame']
|
|
148
199
|
>([BufferLayout.u8('instruction'), BufferLayout.u32('bytes')]),
|
|
149
200
|
},
|
|
201
|
+
SetComputeUnitLimit: {
|
|
202
|
+
index: 2,
|
|
203
|
+
layout: BufferLayout.struct<
|
|
204
|
+
ComputeBudgetInstructionInputData['SetComputeUnitLimit']
|
|
205
|
+
>([BufferLayout.u8('instruction'), BufferLayout.u32('units')]),
|
|
206
|
+
},
|
|
207
|
+
SetComputeUnitPrice: {
|
|
208
|
+
index: 3,
|
|
209
|
+
layout: BufferLayout.struct<
|
|
210
|
+
ComputeBudgetInstructionInputData['SetComputeUnitPrice']
|
|
211
|
+
>([BufferLayout.u8('instruction'), u64('microLamports')]),
|
|
212
|
+
},
|
|
150
213
|
});
|
|
151
214
|
|
|
152
215
|
/**
|
|
@@ -186,4 +249,30 @@ export class ComputeBudgetProgram {
|
|
|
186
249
|
data,
|
|
187
250
|
});
|
|
188
251
|
}
|
|
252
|
+
|
|
253
|
+
static setComputeUnitLimit(
|
|
254
|
+
params: SetComputeUnitLimitParams,
|
|
255
|
+
): TransactionInstruction {
|
|
256
|
+
const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit;
|
|
257
|
+
const data = encodeData(type, params);
|
|
258
|
+
return new TransactionInstruction({
|
|
259
|
+
keys: [],
|
|
260
|
+
programId: this.programId,
|
|
261
|
+
data,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
static setComputeUnitPrice(
|
|
266
|
+
params: SetComputeUnitPriceParams,
|
|
267
|
+
): TransactionInstruction {
|
|
268
|
+
const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice;
|
|
269
|
+
const data = encodeData(type, {
|
|
270
|
+
microLamports: BigInt(params.microLamports),
|
|
271
|
+
});
|
|
272
|
+
return new TransactionInstruction({
|
|
273
|
+
keys: [],
|
|
274
|
+
programId: this.programId,
|
|
275
|
+
data,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
189
278
|
}
|
package/src/connection.ts
CHANGED
|
@@ -293,7 +293,7 @@ export type BlockhashWithExpiryBlockHeight = Readonly<{
|
|
|
293
293
|
* A strategy for confirming transactions that uses the last valid
|
|
294
294
|
* block height for a given blockhash to check for transaction expiration.
|
|
295
295
|
*/
|
|
296
|
-
export type
|
|
296
|
+
export type BlockheightBasedTransactionConfirmationStrategy = {
|
|
297
297
|
signature: TransactionSignature;
|
|
298
298
|
} & BlockhashWithExpiryBlockHeight;
|
|
299
299
|
|
|
@@ -2842,7 +2842,7 @@ export class Connection {
|
|
|
2842
2842
|
}
|
|
2843
2843
|
|
|
2844
2844
|
confirmTransaction(
|
|
2845
|
-
strategy:
|
|
2845
|
+
strategy: BlockheightBasedTransactionConfirmationStrategy,
|
|
2846
2846
|
commitment?: Commitment,
|
|
2847
2847
|
): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
2848
2848
|
|
|
@@ -2856,7 +2856,7 @@ export class Connection {
|
|
|
2856
2856
|
// eslint-disable-next-line no-dupe-class-members
|
|
2857
2857
|
async confirmTransaction(
|
|
2858
2858
|
strategy:
|
|
2859
|
-
|
|
|
2859
|
+
| BlockheightBasedTransactionConfirmationStrategy
|
|
2860
2860
|
| TransactionSignature,
|
|
2861
2861
|
commitment?: Commitment,
|
|
2862
2862
|
): Promise<RpcResponseAndContext<SignatureResult>> {
|
|
@@ -2865,7 +2865,8 @@ export class Connection {
|
|
|
2865
2865
|
if (typeof strategy == 'string') {
|
|
2866
2866
|
rawSignature = strategy;
|
|
2867
2867
|
} else {
|
|
2868
|
-
const config =
|
|
2868
|
+
const config =
|
|
2869
|
+
strategy as BlockheightBasedTransactionConfirmationStrategy;
|
|
2869
2870
|
rawSignature = config.signature;
|
|
2870
2871
|
}
|
|
2871
2872
|
|
|
@@ -2942,7 +2943,8 @@ export class Connection {
|
|
|
2942
2943
|
timeoutMs,
|
|
2943
2944
|
);
|
|
2944
2945
|
} else {
|
|
2945
|
-
let config =
|
|
2946
|
+
let config =
|
|
2947
|
+
strategy as BlockheightBasedTransactionConfirmationStrategy;
|
|
2946
2948
|
(async () => {
|
|
2947
2949
|
let currentBlockHeight = await checkBlockHeight();
|
|
2948
2950
|
if (done) return;
|
package/src/transaction.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {Buffer} from 'buffer';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
BlockheightBasedTransactionConfirmationStrategy,
|
|
5
5
|
Connection,
|
|
6
6
|
} from '../connection';
|
|
7
7
|
import type {TransactionSignature} from '../transaction';
|
|
@@ -14,14 +14,14 @@ import type {ConfirmOptions} from '../connection';
|
|
|
14
14
|
*
|
|
15
15
|
* @param {Connection} connection
|
|
16
16
|
* @param {Buffer} rawTransaction
|
|
17
|
-
* @param {
|
|
17
|
+
* @param {BlockheightBasedTransactionConfirmationStrategy} confirmationStrategy
|
|
18
18
|
* @param {ConfirmOptions} [options]
|
|
19
19
|
* @returns {Promise<TransactionSignature>}
|
|
20
20
|
*/
|
|
21
21
|
export async function sendAndConfirmRawTransaction(
|
|
22
22
|
connection: Connection,
|
|
23
23
|
rawTransaction: Buffer,
|
|
24
|
-
confirmationStrategy:
|
|
24
|
+
confirmationStrategy: BlockheightBasedTransactionConfirmationStrategy,
|
|
25
25
|
options?: ConfirmOptions,
|
|
26
26
|
): Promise<TransactionSignature>;
|
|
27
27
|
|
|
@@ -41,13 +41,13 @@ export async function sendAndConfirmRawTransaction(
|
|
|
41
41
|
connection: Connection,
|
|
42
42
|
rawTransaction: Buffer,
|
|
43
43
|
confirmationStrategyOrConfirmOptions:
|
|
44
|
-
|
|
|
44
|
+
| BlockheightBasedTransactionConfirmationStrategy
|
|
45
45
|
| ConfirmOptions
|
|
46
46
|
| undefined,
|
|
47
47
|
maybeConfirmOptions?: ConfirmOptions,
|
|
48
48
|
): Promise<TransactionSignature> {
|
|
49
49
|
let confirmationStrategy:
|
|
50
|
-
|
|
|
50
|
+
| BlockheightBasedTransactionConfirmationStrategy
|
|
51
51
|
| undefined;
|
|
52
52
|
let options: ConfirmOptions | undefined;
|
|
53
53
|
if (
|
|
@@ -58,7 +58,7 @@ export async function sendAndConfirmRawTransaction(
|
|
|
58
58
|
)
|
|
59
59
|
) {
|
|
60
60
|
confirmationStrategy =
|
|
61
|
-
confirmationStrategyOrConfirmOptions as
|
|
61
|
+
confirmationStrategyOrConfirmOptions as BlockheightBasedTransactionConfirmationStrategy;
|
|
62
62
|
options = maybeConfirmOptions;
|
|
63
63
|
} else {
|
|
64
64
|
options = confirmationStrategyOrConfirmOptions as
|