@solana/web3.js 1.40.1 → 1.41.2
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 +648 -388
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +646 -388
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +648 -388
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +96 -30
- package/lib/index.esm.js +646 -388
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +680 -629
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -24
- package/lib/index.iife.min.js.map +1 -1
- package/package.json +11 -8
- package/src/compute-budget.ts +189 -0
- package/src/connection.ts +657 -486
- package/src/index.ts +1 -0
- package/src/loader.ts +2 -1
- package/src/message.ts +1 -1
- package/src/transaction-constants.ts +10 -0
- package/src/transaction.ts +7 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/web3.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.2",
|
|
4
4
|
"description": "Solana Javascript API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
|
|
51
51
|
"pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
|
|
52
52
|
"re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
|
|
53
|
-
"test": "
|
|
54
|
-
"test:cover": "
|
|
53
|
+
"test": "cross-env TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\" }' ts-mocha --require esm './test/**/*.test.ts'",
|
|
54
|
+
"test:cover": "nyc --reporter=lcov npm run test",
|
|
55
55
|
"test:live": "TEST_LIVE=1 npm run test",
|
|
56
56
|
"test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
|
|
57
57
|
},
|
|
@@ -64,10 +64,12 @@
|
|
|
64
64
|
"bs58": "^4.0.1",
|
|
65
65
|
"buffer": "6.0.1",
|
|
66
66
|
"cross-fetch": "^3.1.4",
|
|
67
|
+
"fast-stable-stringify": "^1.0.0",
|
|
67
68
|
"jayson": "^3.4.4",
|
|
68
69
|
"js-sha3": "^0.8.0",
|
|
69
70
|
"rpc-websockets": "^7.4.2",
|
|
70
71
|
"secp256k1": "^4.0.2",
|
|
72
|
+
"sinon-chai": "^3.7.0",
|
|
71
73
|
"superstruct": "^0.14.2",
|
|
72
74
|
"tweetnacl": "^1.0.0"
|
|
73
75
|
},
|
|
@@ -86,7 +88,7 @@
|
|
|
86
88
|
"@rollup/plugin-json": "^4.1.0",
|
|
87
89
|
"@rollup/plugin-multi-entry": "^4.0.0",
|
|
88
90
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
89
|
-
"@rollup/plugin-replace": "^
|
|
91
|
+
"@rollup/plugin-replace": "^4.0.0",
|
|
90
92
|
"@solana/spl-token": "^0.1.2",
|
|
91
93
|
"@types/bn.js": "^5.1.0",
|
|
92
94
|
"@types/bs58": "^4.0.1",
|
|
@@ -98,6 +100,7 @@
|
|
|
98
100
|
"@types/node": "^17.0.24",
|
|
99
101
|
"@types/secp256k1": "^4.0.1",
|
|
100
102
|
"@types/sinon": "^10.0.0",
|
|
103
|
+
"@types/sinon-chai": "^3.2.8",
|
|
101
104
|
"@typescript-eslint/eslint-plugin": "^4.14.2",
|
|
102
105
|
"@typescript-eslint/parser": "^4.14.2",
|
|
103
106
|
"chai": "^4.3.0",
|
|
@@ -106,7 +109,7 @@
|
|
|
106
109
|
"cross-env": "7.0.3",
|
|
107
110
|
"eslint": "^7.19.0",
|
|
108
111
|
"eslint-config-prettier": "^8.0.0",
|
|
109
|
-
"eslint-plugin-import": "2.
|
|
112
|
+
"eslint-plugin-import": "2.26.0",
|
|
110
113
|
"eslint-plugin-mocha": "^9.0.0",
|
|
111
114
|
"eslint-plugin-prettier": "^4.0.0",
|
|
112
115
|
"esm": "^3.2.25",
|
|
@@ -117,15 +120,15 @@
|
|
|
117
120
|
"npm-run-all": "^4.1.5",
|
|
118
121
|
"nyc": "^15.1.0",
|
|
119
122
|
"prettier": "^2.3.0",
|
|
120
|
-
"puppeteer": "^12.0.0",
|
|
121
123
|
"rimraf": "3.0.2",
|
|
122
|
-
"rollup": "2.
|
|
124
|
+
"rollup": "2.70.2",
|
|
123
125
|
"rollup-plugin-dts": "^4.0.0",
|
|
124
126
|
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
125
127
|
"rollup-plugin-terser": "^7.0.2",
|
|
126
128
|
"semantic-release": "^18.0.0",
|
|
127
|
-
"sinon": "^
|
|
129
|
+
"sinon": "^13.0.2",
|
|
128
130
|
"start-server-and-test": "^1.12.0",
|
|
131
|
+
"ts-mocha": "^9.0.2",
|
|
129
132
|
"ts-node": "^10.0.0",
|
|
130
133
|
"tslib": "^2.1.0",
|
|
131
134
|
"typedoc": "^0.22.2",
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import * as BufferLayout from '@solana/buffer-layout';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
encodeData,
|
|
5
|
+
decodeData,
|
|
6
|
+
InstructionType,
|
|
7
|
+
IInstructionInputData,
|
|
8
|
+
} from './instruction';
|
|
9
|
+
import {PublicKey} from './publickey';
|
|
10
|
+
import {TransactionInstruction} from './transaction';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Compute Budget Instruction class
|
|
14
|
+
*/
|
|
15
|
+
export class ComputeBudgetInstruction {
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
constructor() {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Decode a compute budget instruction and retrieve the instruction type.
|
|
23
|
+
*/
|
|
24
|
+
static decodeInstructionType(
|
|
25
|
+
instruction: TransactionInstruction,
|
|
26
|
+
): ComputeBudgetInstructionType {
|
|
27
|
+
this.checkProgramId(instruction.programId);
|
|
28
|
+
|
|
29
|
+
const instructionTypeLayout = BufferLayout.u8('instruction');
|
|
30
|
+
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
31
|
+
|
|
32
|
+
let type: ComputeBudgetInstructionType | undefined;
|
|
33
|
+
for (const [ixType, layout] of Object.entries(
|
|
34
|
+
COMPUTE_BUDGET_INSTRUCTION_LAYOUTS,
|
|
35
|
+
)) {
|
|
36
|
+
if (layout.index == typeIndex) {
|
|
37
|
+
type = ixType as ComputeBudgetInstructionType;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!type) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
'Instruction type incorrect; not a ComputeBudgetInstruction',
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return type;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Decode request units compute budget instruction and retrieve the instruction params.
|
|
53
|
+
*/
|
|
54
|
+
static decodeRequestUnits(
|
|
55
|
+
instruction: TransactionInstruction,
|
|
56
|
+
): RequestUnitsParams {
|
|
57
|
+
this.checkProgramId(instruction.programId);
|
|
58
|
+
const {units, additionalFee} = decodeData(
|
|
59
|
+
COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits,
|
|
60
|
+
instruction.data,
|
|
61
|
+
);
|
|
62
|
+
return {units, additionalFee};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Decode request heap frame compute budget instruction and retrieve the instruction params.
|
|
67
|
+
*/
|
|
68
|
+
static decodeRequestHeapFrame(
|
|
69
|
+
instruction: TransactionInstruction,
|
|
70
|
+
): RequestHeapFrameParams {
|
|
71
|
+
this.checkProgramId(instruction.programId);
|
|
72
|
+
const {bytes} = decodeData(
|
|
73
|
+
COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame,
|
|
74
|
+
instruction.data,
|
|
75
|
+
);
|
|
76
|
+
return {bytes};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
static checkProgramId(programId: PublicKey) {
|
|
83
|
+
if (!programId.equals(ComputeBudgetProgram.programId)) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
'invalid instruction; programId is not ComputeBudgetProgram',
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* An enumeration of valid ComputeBudgetInstructionType's
|
|
93
|
+
*/
|
|
94
|
+
export type ComputeBudgetInstructionType =
|
|
95
|
+
// FIXME
|
|
96
|
+
// It would be preferable for this type to be `keyof ComputeBudgetInstructionInputData`
|
|
97
|
+
// but Typedoc does not transpile `keyof` expressions.
|
|
98
|
+
// See https://github.com/TypeStrong/typedoc/issues/1894
|
|
99
|
+
'RequestUnits' | 'RequestHeapFrame';
|
|
100
|
+
|
|
101
|
+
type ComputeBudgetInstructionInputData = {
|
|
102
|
+
RequestUnits: IInstructionInputData & Readonly<RequestUnitsParams>;
|
|
103
|
+
RequestHeapFrame: IInstructionInputData & Readonly<RequestHeapFrameParams>;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Request units instruction params
|
|
108
|
+
*/
|
|
109
|
+
export interface RequestUnitsParams {
|
|
110
|
+
/** Units to request for transaction-wide compute */
|
|
111
|
+
units: number;
|
|
112
|
+
|
|
113
|
+
/** Additional fee to pay */
|
|
114
|
+
additionalFee: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Request heap frame instruction params
|
|
119
|
+
*/
|
|
120
|
+
export type RequestHeapFrameParams = {
|
|
121
|
+
/** Requested transaction-wide program heap size in bytes. Must be multiple of 1024. Applies to each program, including CPIs. */
|
|
122
|
+
bytes: number;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* An enumeration of valid ComputeBudget InstructionType's
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
export const COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze<{
|
|
130
|
+
[Instruction in ComputeBudgetInstructionType]: InstructionType<
|
|
131
|
+
ComputeBudgetInstructionInputData[Instruction]
|
|
132
|
+
>;
|
|
133
|
+
}>({
|
|
134
|
+
RequestUnits: {
|
|
135
|
+
index: 0,
|
|
136
|
+
layout: BufferLayout.struct<
|
|
137
|
+
ComputeBudgetInstructionInputData['RequestUnits']
|
|
138
|
+
>([
|
|
139
|
+
BufferLayout.u8('instruction'),
|
|
140
|
+
BufferLayout.u32('units'),
|
|
141
|
+
BufferLayout.u32('additionalFee'),
|
|
142
|
+
]),
|
|
143
|
+
},
|
|
144
|
+
RequestHeapFrame: {
|
|
145
|
+
index: 1,
|
|
146
|
+
layout: BufferLayout.struct<
|
|
147
|
+
ComputeBudgetInstructionInputData['RequestHeapFrame']
|
|
148
|
+
>([BufferLayout.u8('instruction'), BufferLayout.u32('bytes')]),
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Factory class for transaction instructions to interact with the Compute Budget program
|
|
154
|
+
*/
|
|
155
|
+
export class ComputeBudgetProgram {
|
|
156
|
+
/**
|
|
157
|
+
* @internal
|
|
158
|
+
*/
|
|
159
|
+
constructor() {}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Public key that identifies the Compute Budget program
|
|
163
|
+
*/
|
|
164
|
+
static programId: PublicKey = new PublicKey(
|
|
165
|
+
'ComputeBudget111111111111111111111111111111',
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
static requestUnits(params: RequestUnitsParams): TransactionInstruction {
|
|
169
|
+
const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits;
|
|
170
|
+
const data = encodeData(type, params);
|
|
171
|
+
return new TransactionInstruction({
|
|
172
|
+
keys: [],
|
|
173
|
+
programId: this.programId,
|
|
174
|
+
data,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static requestHeapFrame(
|
|
179
|
+
params: RequestHeapFrameParams,
|
|
180
|
+
): TransactionInstruction {
|
|
181
|
+
const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame;
|
|
182
|
+
const data = encodeData(type, params);
|
|
183
|
+
return new TransactionInstruction({
|
|
184
|
+
keys: [],
|
|
185
|
+
programId: this.programId,
|
|
186
|
+
data,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|