@solana/web3.js 1.78.0 → 2.0.0-development
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/README.md +56 -112
- package/dist/index.browser.cjs +158 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.js +137 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.development.js +1044 -0
- package/dist/index.development.js.map +1 -0
- package/dist/index.native.js +139 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.node.cjs +158 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.js +139 -0
- package/dist/index.node.js.map +1 -0
- package/dist/index.production.min.js +25 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/rpc-default-config.d.ts +3 -0
- package/dist/types/rpc-integer-overflow-error.d.ts +8 -0
- package/dist/types/rpc-request-coalescer.d.ts +5 -0
- package/dist/types/rpc-request-deduplication.d.ts +2 -0
- package/dist/types/rpc-transport.d.ts +4 -0
- package/dist/types/rpc.d.ts +5 -0
- package/package.json +86 -111
- package/lib/index.browser.cjs.js +0 -10248
- package/lib/index.browser.cjs.js.map +0 -1
- package/lib/index.browser.esm.js +0 -10145
- package/lib/index.browser.esm.js.map +0 -1
- package/lib/index.cjs.js +0 -12748
- package/lib/index.cjs.js.map +0 -1
- package/lib/index.d.ts +0 -3904
- package/lib/index.esm.js +0 -12638
- package/lib/index.esm.js.map +0 -1
- package/lib/index.iife.js +0 -26757
- package/lib/index.iife.js.map +0 -1
- package/lib/index.iife.min.js +0 -20
- package/lib/index.iife.min.js.map +0 -1
- package/lib/index.native.js +0 -10248
- package/lib/index.native.js.map +0 -1
- package/src/__forks__/browser/fetch-impl.ts +0 -4
- package/src/__forks__/browser/rpc-websocket-factory.ts +0 -1
- package/src/__forks__/react-native/fetch-impl.ts +0 -4
- package/src/__forks__/react-native/rpc-websocket-factory.ts +0 -1
- package/src/account-data.ts +0 -39
- package/src/account.ts +0 -55
- package/src/blockhash.ts +0 -4
- package/src/bpf-loader-deprecated.ts +0 -5
- package/src/bpf-loader.ts +0 -45
- package/src/connection.ts +0 -6796
- package/src/epoch-schedule.ts +0 -102
- package/src/errors.ts +0 -50
- package/src/fee-calculator.ts +0 -18
- package/src/fetch-impl.ts +0 -13
- package/src/index.ts +0 -24
- package/src/instruction.ts +0 -58
- package/src/keypair.ts +0 -93
- package/src/layout.ts +0 -188
- package/src/loader.ts +0 -267
- package/src/message/account-keys.ts +0 -79
- package/src/message/compiled-keys.ts +0 -165
- package/src/message/index.ts +0 -47
- package/src/message/legacy.ts +0 -326
- package/src/message/v0.ts +0 -496
- package/src/message/versioned.ts +0 -36
- package/src/nonce-account.ts +0 -82
- package/src/programs/address-lookup-table/index.ts +0 -435
- package/src/programs/address-lookup-table/state.ts +0 -84
- package/src/programs/compute-budget.ts +0 -281
- package/src/programs/ed25519.ts +0 -157
- package/src/programs/index.ts +0 -7
- package/src/programs/secp256k1.ts +0 -228
- package/src/programs/stake.ts +0 -935
- package/src/programs/system.ts +0 -1048
- package/src/programs/vote.ts +0 -543
- package/src/publickey.ts +0 -259
- package/src/rpc-websocket-factory.ts +0 -4
- package/src/rpc-websocket.ts +0 -79
- package/src/sysvar.ts +0 -37
- package/src/timing.ts +0 -23
- package/src/transaction/constants.ts +0 -12
- package/src/transaction/expiry-custom-errors.ts +0 -48
- package/src/transaction/index.ts +0 -5
- package/src/transaction/legacy.ts +0 -918
- package/src/transaction/message.ts +0 -140
- package/src/transaction/versioned.ts +0 -126
- package/src/utils/assert.ts +0 -8
- package/src/utils/bigint.ts +0 -43
- package/src/utils/borsh-schema.ts +0 -38
- package/src/utils/cluster.ts +0 -31
- package/src/utils/ed25519.ts +0 -43
- package/src/utils/index.ts +0 -5
- package/src/utils/makeWebsocketUrl.ts +0 -26
- package/src/utils/promise-timeout.ts +0 -14
- package/src/utils/secp256k1.ts +0 -11
- package/src/utils/send-and-confirm-raw-transaction.ts +0 -102
- package/src/utils/send-and-confirm-transaction.ts +0 -98
- package/src/utils/shortvec-encoding.ts +0 -28
- package/src/utils/sleep.ts +0 -4
- package/src/utils/to-buffer.ts +0 -11
- package/src/validator-info.ts +0 -104
- package/src/vote-account.ts +0 -236
|
@@ -1,435 +0,0 @@
|
|
|
1
|
-
import {toBufferLE} from 'bigint-buffer';
|
|
2
|
-
import * as BufferLayout from '@solana/buffer-layout';
|
|
3
|
-
|
|
4
|
-
import * as Layout from '../../layout';
|
|
5
|
-
import {PublicKey} from '../../publickey';
|
|
6
|
-
import * as bigintLayout from '../../utils/bigint';
|
|
7
|
-
import {SystemProgram} from '../system';
|
|
8
|
-
import {TransactionInstruction} from '../../transaction';
|
|
9
|
-
import {decodeData, encodeData, IInstructionInputData} from '../../instruction';
|
|
10
|
-
|
|
11
|
-
export * from './state';
|
|
12
|
-
|
|
13
|
-
export type CreateLookupTableParams = {
|
|
14
|
-
/** Account used to derive and control the new address lookup table. */
|
|
15
|
-
authority: PublicKey;
|
|
16
|
-
/** Account that will fund the new address lookup table. */
|
|
17
|
-
payer: PublicKey;
|
|
18
|
-
/** A recent slot must be used in the derivation path for each initialized table. */
|
|
19
|
-
recentSlot: bigint | number;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type FreezeLookupTableParams = {
|
|
23
|
-
/** Address lookup table account to freeze. */
|
|
24
|
-
lookupTable: PublicKey;
|
|
25
|
-
/** Account which is the current authority. */
|
|
26
|
-
authority: PublicKey;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type ExtendLookupTableParams = {
|
|
30
|
-
/** Address lookup table account to extend. */
|
|
31
|
-
lookupTable: PublicKey;
|
|
32
|
-
/** Account which is the current authority. */
|
|
33
|
-
authority: PublicKey;
|
|
34
|
-
/** Account that will fund the table reallocation.
|
|
35
|
-
* Not required if the reallocation has already been funded. */
|
|
36
|
-
payer?: PublicKey;
|
|
37
|
-
/** List of Public Keys to be added to the lookup table. */
|
|
38
|
-
addresses: Array<PublicKey>;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type DeactivateLookupTableParams = {
|
|
42
|
-
/** Address lookup table account to deactivate. */
|
|
43
|
-
lookupTable: PublicKey;
|
|
44
|
-
/** Account which is the current authority. */
|
|
45
|
-
authority: PublicKey;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type CloseLookupTableParams = {
|
|
49
|
-
/** Address lookup table account to close. */
|
|
50
|
-
lookupTable: PublicKey;
|
|
51
|
-
/** Account which is the current authority. */
|
|
52
|
-
authority: PublicKey;
|
|
53
|
-
/** Recipient of closed account lamports. */
|
|
54
|
-
recipient: PublicKey;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* An enumeration of valid LookupTableInstructionType's
|
|
59
|
-
*/
|
|
60
|
-
export type LookupTableInstructionType =
|
|
61
|
-
| 'CreateLookupTable'
|
|
62
|
-
| 'ExtendLookupTable'
|
|
63
|
-
| 'CloseLookupTable'
|
|
64
|
-
| 'FreezeLookupTable'
|
|
65
|
-
| 'DeactivateLookupTable';
|
|
66
|
-
|
|
67
|
-
type LookupTableInstructionInputData = {
|
|
68
|
-
CreateLookupTable: IInstructionInputData &
|
|
69
|
-
Readonly<{
|
|
70
|
-
recentSlot: bigint;
|
|
71
|
-
bumpSeed: number;
|
|
72
|
-
}>;
|
|
73
|
-
FreezeLookupTable: IInstructionInputData;
|
|
74
|
-
ExtendLookupTable: IInstructionInputData &
|
|
75
|
-
Readonly<{
|
|
76
|
-
numberOfAddresses: bigint;
|
|
77
|
-
addresses: Array<Uint8Array>;
|
|
78
|
-
}>;
|
|
79
|
-
DeactivateLookupTable: IInstructionInputData;
|
|
80
|
-
CloseLookupTable: IInstructionInputData;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* An enumeration of valid address lookup table InstructionType's
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
export const LOOKUP_TABLE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
88
|
-
CreateLookupTable: {
|
|
89
|
-
index: 0,
|
|
90
|
-
layout: BufferLayout.struct<
|
|
91
|
-
LookupTableInstructionInputData['CreateLookupTable']
|
|
92
|
-
>([
|
|
93
|
-
BufferLayout.u32('instruction'),
|
|
94
|
-
bigintLayout.u64('recentSlot'),
|
|
95
|
-
BufferLayout.u8('bumpSeed'),
|
|
96
|
-
]),
|
|
97
|
-
},
|
|
98
|
-
FreezeLookupTable: {
|
|
99
|
-
index: 1,
|
|
100
|
-
layout: BufferLayout.struct<
|
|
101
|
-
LookupTableInstructionInputData['FreezeLookupTable']
|
|
102
|
-
>([BufferLayout.u32('instruction')]),
|
|
103
|
-
},
|
|
104
|
-
ExtendLookupTable: {
|
|
105
|
-
index: 2,
|
|
106
|
-
layout: BufferLayout.struct<
|
|
107
|
-
LookupTableInstructionInputData['ExtendLookupTable']
|
|
108
|
-
>([
|
|
109
|
-
BufferLayout.u32('instruction'),
|
|
110
|
-
bigintLayout.u64(),
|
|
111
|
-
BufferLayout.seq(
|
|
112
|
-
Layout.publicKey(),
|
|
113
|
-
BufferLayout.offset(BufferLayout.u32(), -8),
|
|
114
|
-
'addresses',
|
|
115
|
-
),
|
|
116
|
-
]),
|
|
117
|
-
},
|
|
118
|
-
DeactivateLookupTable: {
|
|
119
|
-
index: 3,
|
|
120
|
-
layout: BufferLayout.struct<
|
|
121
|
-
LookupTableInstructionInputData['DeactivateLookupTable']
|
|
122
|
-
>([BufferLayout.u32('instruction')]),
|
|
123
|
-
},
|
|
124
|
-
CloseLookupTable: {
|
|
125
|
-
index: 4,
|
|
126
|
-
layout: BufferLayout.struct<
|
|
127
|
-
LookupTableInstructionInputData['CloseLookupTable']
|
|
128
|
-
>([BufferLayout.u32('instruction')]),
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
export class AddressLookupTableInstruction {
|
|
133
|
-
/**
|
|
134
|
-
* @internal
|
|
135
|
-
*/
|
|
136
|
-
constructor() {}
|
|
137
|
-
|
|
138
|
-
static decodeInstructionType(
|
|
139
|
-
instruction: TransactionInstruction,
|
|
140
|
-
): LookupTableInstructionType {
|
|
141
|
-
this.checkProgramId(instruction.programId);
|
|
142
|
-
|
|
143
|
-
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
144
|
-
const index = instructionTypeLayout.decode(instruction.data);
|
|
145
|
-
|
|
146
|
-
let type: LookupTableInstructionType | undefined;
|
|
147
|
-
for (const [layoutType, layout] of Object.entries(
|
|
148
|
-
LOOKUP_TABLE_INSTRUCTION_LAYOUTS,
|
|
149
|
-
)) {
|
|
150
|
-
if ((layout as any).index == index) {
|
|
151
|
-
type = layoutType as LookupTableInstructionType;
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (!type) {
|
|
156
|
-
throw new Error(
|
|
157
|
-
'Invalid Instruction. Should be a LookupTable Instruction',
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
return type;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
static decodeCreateLookupTable(
|
|
164
|
-
instruction: TransactionInstruction,
|
|
165
|
-
): CreateLookupTableParams {
|
|
166
|
-
this.checkProgramId(instruction.programId);
|
|
167
|
-
this.checkKeysLength(instruction.keys, 4);
|
|
168
|
-
|
|
169
|
-
const {recentSlot} = decodeData(
|
|
170
|
-
LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable,
|
|
171
|
-
instruction.data,
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
authority: instruction.keys[1].pubkey,
|
|
176
|
-
payer: instruction.keys[2].pubkey,
|
|
177
|
-
recentSlot: Number(recentSlot),
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
static decodeExtendLookupTable(
|
|
182
|
-
instruction: TransactionInstruction,
|
|
183
|
-
): ExtendLookupTableParams {
|
|
184
|
-
this.checkProgramId(instruction.programId);
|
|
185
|
-
if (instruction.keys.length < 2) {
|
|
186
|
-
throw new Error(
|
|
187
|
-
`invalid instruction; found ${instruction.keys.length} keys, expected at least 2`,
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const {addresses} = decodeData(
|
|
192
|
-
LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable,
|
|
193
|
-
instruction.data,
|
|
194
|
-
);
|
|
195
|
-
return {
|
|
196
|
-
lookupTable: instruction.keys[0].pubkey,
|
|
197
|
-
authority: instruction.keys[1].pubkey,
|
|
198
|
-
payer:
|
|
199
|
-
instruction.keys.length > 2 ? instruction.keys[2].pubkey : undefined,
|
|
200
|
-
addresses: addresses.map(buffer => new PublicKey(buffer)),
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
static decodeCloseLookupTable(
|
|
205
|
-
instruction: TransactionInstruction,
|
|
206
|
-
): CloseLookupTableParams {
|
|
207
|
-
this.checkProgramId(instruction.programId);
|
|
208
|
-
this.checkKeysLength(instruction.keys, 3);
|
|
209
|
-
|
|
210
|
-
return {
|
|
211
|
-
lookupTable: instruction.keys[0].pubkey,
|
|
212
|
-
authority: instruction.keys[1].pubkey,
|
|
213
|
-
recipient: instruction.keys[2].pubkey,
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
static decodeFreezeLookupTable(
|
|
218
|
-
instruction: TransactionInstruction,
|
|
219
|
-
): FreezeLookupTableParams {
|
|
220
|
-
this.checkProgramId(instruction.programId);
|
|
221
|
-
this.checkKeysLength(instruction.keys, 2);
|
|
222
|
-
|
|
223
|
-
return {
|
|
224
|
-
lookupTable: instruction.keys[0].pubkey,
|
|
225
|
-
authority: instruction.keys[1].pubkey,
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
static decodeDeactivateLookupTable(
|
|
230
|
-
instruction: TransactionInstruction,
|
|
231
|
-
): DeactivateLookupTableParams {
|
|
232
|
-
this.checkProgramId(instruction.programId);
|
|
233
|
-
this.checkKeysLength(instruction.keys, 2);
|
|
234
|
-
|
|
235
|
-
return {
|
|
236
|
-
lookupTable: instruction.keys[0].pubkey,
|
|
237
|
-
authority: instruction.keys[1].pubkey,
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* @internal
|
|
243
|
-
*/
|
|
244
|
-
static checkProgramId(programId: PublicKey) {
|
|
245
|
-
if (!programId.equals(AddressLookupTableProgram.programId)) {
|
|
246
|
-
throw new Error(
|
|
247
|
-
'invalid instruction; programId is not AddressLookupTable Program',
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* @internal
|
|
253
|
-
*/
|
|
254
|
-
static checkKeysLength(keys: Array<any>, expectedLength: number) {
|
|
255
|
-
if (keys.length < expectedLength) {
|
|
256
|
-
throw new Error(
|
|
257
|
-
`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`,
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export class AddressLookupTableProgram {
|
|
264
|
-
/**
|
|
265
|
-
* @internal
|
|
266
|
-
*/
|
|
267
|
-
constructor() {}
|
|
268
|
-
|
|
269
|
-
static programId: PublicKey = new PublicKey(
|
|
270
|
-
'AddressLookupTab1e1111111111111111111111111',
|
|
271
|
-
);
|
|
272
|
-
|
|
273
|
-
static createLookupTable(params: CreateLookupTableParams) {
|
|
274
|
-
const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync(
|
|
275
|
-
[params.authority.toBuffer(), toBufferLE(BigInt(params.recentSlot), 8)],
|
|
276
|
-
this.programId,
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
|
|
280
|
-
const data = encodeData(type, {
|
|
281
|
-
recentSlot: BigInt(params.recentSlot),
|
|
282
|
-
bumpSeed: bumpSeed,
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
const keys = [
|
|
286
|
-
{
|
|
287
|
-
pubkey: lookupTableAddress,
|
|
288
|
-
isSigner: false,
|
|
289
|
-
isWritable: true,
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
pubkey: params.authority,
|
|
293
|
-
isSigner: true,
|
|
294
|
-
isWritable: false,
|
|
295
|
-
},
|
|
296
|
-
{
|
|
297
|
-
pubkey: params.payer,
|
|
298
|
-
isSigner: true,
|
|
299
|
-
isWritable: true,
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
pubkey: SystemProgram.programId,
|
|
303
|
-
isSigner: false,
|
|
304
|
-
isWritable: false,
|
|
305
|
-
},
|
|
306
|
-
];
|
|
307
|
-
|
|
308
|
-
return [
|
|
309
|
-
new TransactionInstruction({
|
|
310
|
-
programId: this.programId,
|
|
311
|
-
keys: keys,
|
|
312
|
-
data: data,
|
|
313
|
-
}),
|
|
314
|
-
lookupTableAddress,
|
|
315
|
-
] as [TransactionInstruction, PublicKey];
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
static freezeLookupTable(params: FreezeLookupTableParams) {
|
|
319
|
-
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
|
|
320
|
-
const data = encodeData(type);
|
|
321
|
-
|
|
322
|
-
const keys = [
|
|
323
|
-
{
|
|
324
|
-
pubkey: params.lookupTable,
|
|
325
|
-
isSigner: false,
|
|
326
|
-
isWritable: true,
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
pubkey: params.authority,
|
|
330
|
-
isSigner: true,
|
|
331
|
-
isWritable: false,
|
|
332
|
-
},
|
|
333
|
-
];
|
|
334
|
-
|
|
335
|
-
return new TransactionInstruction({
|
|
336
|
-
programId: this.programId,
|
|
337
|
-
keys: keys,
|
|
338
|
-
data: data,
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
static extendLookupTable(params: ExtendLookupTableParams) {
|
|
343
|
-
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
|
|
344
|
-
const data = encodeData(type, {
|
|
345
|
-
addresses: params.addresses.map(addr => addr.toBytes()),
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
const keys = [
|
|
349
|
-
{
|
|
350
|
-
pubkey: params.lookupTable,
|
|
351
|
-
isSigner: false,
|
|
352
|
-
isWritable: true,
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
pubkey: params.authority,
|
|
356
|
-
isSigner: true,
|
|
357
|
-
isWritable: false,
|
|
358
|
-
},
|
|
359
|
-
];
|
|
360
|
-
|
|
361
|
-
if (params.payer) {
|
|
362
|
-
keys.push(
|
|
363
|
-
{
|
|
364
|
-
pubkey: params.payer,
|
|
365
|
-
isSigner: true,
|
|
366
|
-
isWritable: true,
|
|
367
|
-
},
|
|
368
|
-
{
|
|
369
|
-
pubkey: SystemProgram.programId,
|
|
370
|
-
isSigner: false,
|
|
371
|
-
isWritable: false,
|
|
372
|
-
},
|
|
373
|
-
);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
return new TransactionInstruction({
|
|
377
|
-
programId: this.programId,
|
|
378
|
-
keys: keys,
|
|
379
|
-
data: data,
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
static deactivateLookupTable(params: DeactivateLookupTableParams) {
|
|
384
|
-
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
|
|
385
|
-
const data = encodeData(type);
|
|
386
|
-
|
|
387
|
-
const keys = [
|
|
388
|
-
{
|
|
389
|
-
pubkey: params.lookupTable,
|
|
390
|
-
isSigner: false,
|
|
391
|
-
isWritable: true,
|
|
392
|
-
},
|
|
393
|
-
{
|
|
394
|
-
pubkey: params.authority,
|
|
395
|
-
isSigner: true,
|
|
396
|
-
isWritable: false,
|
|
397
|
-
},
|
|
398
|
-
];
|
|
399
|
-
|
|
400
|
-
return new TransactionInstruction({
|
|
401
|
-
programId: this.programId,
|
|
402
|
-
keys: keys,
|
|
403
|
-
data: data,
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
static closeLookupTable(params: CloseLookupTableParams) {
|
|
408
|
-
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
|
|
409
|
-
const data = encodeData(type);
|
|
410
|
-
|
|
411
|
-
const keys = [
|
|
412
|
-
{
|
|
413
|
-
pubkey: params.lookupTable,
|
|
414
|
-
isSigner: false,
|
|
415
|
-
isWritable: true,
|
|
416
|
-
},
|
|
417
|
-
{
|
|
418
|
-
pubkey: params.authority,
|
|
419
|
-
isSigner: true,
|
|
420
|
-
isWritable: false,
|
|
421
|
-
},
|
|
422
|
-
{
|
|
423
|
-
pubkey: params.recipient,
|
|
424
|
-
isSigner: false,
|
|
425
|
-
isWritable: true,
|
|
426
|
-
},
|
|
427
|
-
];
|
|
428
|
-
|
|
429
|
-
return new TransactionInstruction({
|
|
430
|
-
programId: this.programId,
|
|
431
|
-
keys: keys,
|
|
432
|
-
data: data,
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import * as BufferLayout from '@solana/buffer-layout';
|
|
2
|
-
|
|
3
|
-
import assert from '../../utils/assert';
|
|
4
|
-
import * as Layout from '../../layout';
|
|
5
|
-
import {PublicKey} from '../../publickey';
|
|
6
|
-
import {u64} from '../../utils/bigint';
|
|
7
|
-
import {decodeData} from '../../account-data';
|
|
8
|
-
|
|
9
|
-
export type AddressLookupTableState = {
|
|
10
|
-
deactivationSlot: bigint;
|
|
11
|
-
lastExtendedSlot: number;
|
|
12
|
-
lastExtendedSlotStartIndex: number;
|
|
13
|
-
authority?: PublicKey;
|
|
14
|
-
addresses: Array<PublicKey>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type AddressLookupTableAccountArgs = {
|
|
18
|
-
key: PublicKey;
|
|
19
|
-
state: AddressLookupTableState;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/// The serialized size of lookup table metadata
|
|
23
|
-
const LOOKUP_TABLE_META_SIZE = 56;
|
|
24
|
-
|
|
25
|
-
export class AddressLookupTableAccount {
|
|
26
|
-
key: PublicKey;
|
|
27
|
-
state: AddressLookupTableState;
|
|
28
|
-
|
|
29
|
-
constructor(args: AddressLookupTableAccountArgs) {
|
|
30
|
-
this.key = args.key;
|
|
31
|
-
this.state = args.state;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
isActive(): boolean {
|
|
35
|
-
const U64_MAX = BigInt('0xffffffffffffffff');
|
|
36
|
-
return this.state.deactivationSlot === U64_MAX;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static deserialize(accountData: Uint8Array): AddressLookupTableState {
|
|
40
|
-
const meta = decodeData(LookupTableMetaLayout, accountData);
|
|
41
|
-
|
|
42
|
-
const serializedAddressesLen = accountData.length - LOOKUP_TABLE_META_SIZE;
|
|
43
|
-
assert(serializedAddressesLen >= 0, 'lookup table is invalid');
|
|
44
|
-
assert(serializedAddressesLen % 32 === 0, 'lookup table is invalid');
|
|
45
|
-
|
|
46
|
-
const numSerializedAddresses = serializedAddressesLen / 32;
|
|
47
|
-
const {addresses} = BufferLayout.struct<{addresses: Array<Uint8Array>}>([
|
|
48
|
-
BufferLayout.seq(Layout.publicKey(), numSerializedAddresses, 'addresses'),
|
|
49
|
-
]).decode(accountData.slice(LOOKUP_TABLE_META_SIZE));
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
deactivationSlot: meta.deactivationSlot,
|
|
53
|
-
lastExtendedSlot: meta.lastExtendedSlot,
|
|
54
|
-
lastExtendedSlotStartIndex: meta.lastExtendedStartIndex,
|
|
55
|
-
authority:
|
|
56
|
-
meta.authority.length !== 0
|
|
57
|
-
? new PublicKey(meta.authority[0])
|
|
58
|
-
: undefined,
|
|
59
|
-
addresses: addresses.map(address => new PublicKey(address)),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const LookupTableMetaLayout = {
|
|
65
|
-
index: 1,
|
|
66
|
-
layout: BufferLayout.struct<{
|
|
67
|
-
typeIndex: number;
|
|
68
|
-
deactivationSlot: bigint;
|
|
69
|
-
lastExtendedSlot: number;
|
|
70
|
-
lastExtendedStartIndex: number;
|
|
71
|
-
authority: Array<Uint8Array>;
|
|
72
|
-
}>([
|
|
73
|
-
BufferLayout.u32('typeIndex'),
|
|
74
|
-
u64('deactivationSlot'),
|
|
75
|
-
BufferLayout.nu64('lastExtendedSlot'),
|
|
76
|
-
BufferLayout.u8('lastExtendedStartIndex'),
|
|
77
|
-
BufferLayout.u8(), // option
|
|
78
|
-
BufferLayout.seq(
|
|
79
|
-
Layout.publicKey(),
|
|
80
|
-
BufferLayout.offset(BufferLayout.u8(), -1),
|
|
81
|
-
'authority',
|
|
82
|
-
),
|
|
83
|
-
]),
|
|
84
|
-
};
|