@solana/web3.js 1.32.2 → 1.35.1
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.esm.js +375 -14
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +378 -13
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +158 -1
- package/lib/index.esm.js +375 -14
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +378 -13
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +191 -1
- package/package.json +1 -1
- package/src/connection.ts +10 -8
- package/src/index.ts +1 -0
- package/src/layout.ts +15 -0
- package/src/stake-program.ts +65 -15
- package/src/vote-program.ts +386 -0
package/lib/index.d.ts
CHANGED
|
@@ -754,7 +754,7 @@ declare module '@solana/web3.js' {
|
|
|
754
754
|
export type SimulatedTransactionResponse = {
|
|
755
755
|
err: TransactionError | string | null;
|
|
756
756
|
logs: Array<string> | null;
|
|
757
|
-
accounts?: SimulatedTransactionAccountInfo[] | null;
|
|
757
|
+
accounts?: (SimulatedTransactionAccountInfo | null)[] | null;
|
|
758
758
|
unitsConsumed?: number;
|
|
759
759
|
};
|
|
760
760
|
export type ParsedInnerInstruction = {
|
|
@@ -2278,6 +2278,17 @@ declare module '@solana/web3.js' {
|
|
|
2278
2278
|
splitStakePubkey: PublicKey;
|
|
2279
2279
|
lamports: number;
|
|
2280
2280
|
};
|
|
2281
|
+
/**
|
|
2282
|
+
* Split with seed transaction params
|
|
2283
|
+
*/
|
|
2284
|
+
export type SplitStakeWithSeedParams = {
|
|
2285
|
+
stakePubkey: PublicKey;
|
|
2286
|
+
authorizedPubkey: PublicKey;
|
|
2287
|
+
splitStakePubkey: PublicKey;
|
|
2288
|
+
basePubkey: PublicKey;
|
|
2289
|
+
seed: string;
|
|
2290
|
+
lamports: number;
|
|
2291
|
+
};
|
|
2281
2292
|
/**
|
|
2282
2293
|
* Withdraw stake instruction params
|
|
2283
2294
|
*/
|
|
@@ -2439,6 +2450,11 @@ declare module '@solana/web3.js' {
|
|
|
2439
2450
|
* Generate a Transaction that splits Stake tokens into another stake account
|
|
2440
2451
|
*/
|
|
2441
2452
|
static split(params: SplitStakeParams): Transaction;
|
|
2453
|
+
/**
|
|
2454
|
+
* Generate a Transaction that splits Stake tokens into another account
|
|
2455
|
+
* derived from a base public key and seed
|
|
2456
|
+
*/
|
|
2457
|
+
static splitWithSeed(params: SplitStakeWithSeedParams): Transaction;
|
|
2442
2458
|
/**
|
|
2443
2459
|
* Generate a Transaction that merges Stake accounts.
|
|
2444
2460
|
*/
|
|
@@ -2948,6 +2964,147 @@ declare module '@solana/web3.js' {
|
|
|
2948
2964
|
): VoteAccount;
|
|
2949
2965
|
}
|
|
2950
2966
|
|
|
2967
|
+
/**
|
|
2968
|
+
* Vote account info
|
|
2969
|
+
*/
|
|
2970
|
+
export class VoteInit {
|
|
2971
|
+
nodePubkey: PublicKey;
|
|
2972
|
+
authorizedVoter: PublicKey;
|
|
2973
|
+
authorizedWithdrawer: PublicKey;
|
|
2974
|
+
commission: number; /** [0, 100] */
|
|
2975
|
+
constructor(
|
|
2976
|
+
nodePubkey: PublicKey,
|
|
2977
|
+
authorizedVoter: PublicKey,
|
|
2978
|
+
authorizedWithdrawer: PublicKey,
|
|
2979
|
+
commission: number,
|
|
2980
|
+
);
|
|
2981
|
+
}
|
|
2982
|
+
/**
|
|
2983
|
+
* Create vote account transaction params
|
|
2984
|
+
*/
|
|
2985
|
+
export type CreateVoteAccountParams = {
|
|
2986
|
+
fromPubkey: PublicKey;
|
|
2987
|
+
votePubkey: PublicKey;
|
|
2988
|
+
voteInit: VoteInit;
|
|
2989
|
+
lamports: number;
|
|
2990
|
+
};
|
|
2991
|
+
/**
|
|
2992
|
+
* InitializeAccount instruction params
|
|
2993
|
+
*/
|
|
2994
|
+
export type InitializeAccountParams = {
|
|
2995
|
+
votePubkey: PublicKey;
|
|
2996
|
+
nodePubkey: PublicKey;
|
|
2997
|
+
voteInit: VoteInit;
|
|
2998
|
+
};
|
|
2999
|
+
/**
|
|
3000
|
+
* Authorize instruction params
|
|
3001
|
+
*/
|
|
3002
|
+
export type AuthorizeVoteParams = {
|
|
3003
|
+
votePubkey: PublicKey;
|
|
3004
|
+
/** Current vote or withdraw authority, depending on `voteAuthorizationType` */
|
|
3005
|
+
authorizedPubkey: PublicKey;
|
|
3006
|
+
newAuthorizedPubkey: PublicKey;
|
|
3007
|
+
voteAuthorizationType: VoteAuthorizationType;
|
|
3008
|
+
};
|
|
3009
|
+
/**
|
|
3010
|
+
* Withdraw from vote account transaction params
|
|
3011
|
+
*/
|
|
3012
|
+
export type WithdrawFromVoteAccountParams = {
|
|
3013
|
+
votePubkey: PublicKey;
|
|
3014
|
+
authorizedWithdrawerPubkey: PublicKey;
|
|
3015
|
+
lamports: number;
|
|
3016
|
+
toPubkey: PublicKey;
|
|
3017
|
+
};
|
|
3018
|
+
/**
|
|
3019
|
+
* Vote Instruction class
|
|
3020
|
+
*/
|
|
3021
|
+
export class VoteInstruction {
|
|
3022
|
+
/**
|
|
3023
|
+
* Decode a vote instruction and retrieve the instruction type.
|
|
3024
|
+
*/
|
|
3025
|
+
static decodeInstructionType(
|
|
3026
|
+
instruction: TransactionInstruction,
|
|
3027
|
+
): VoteInstructionType;
|
|
3028
|
+
/**
|
|
3029
|
+
* Decode an initialize vote instruction and retrieve the instruction params.
|
|
3030
|
+
*/
|
|
3031
|
+
static decodeInitializeAccount(
|
|
3032
|
+
instruction: TransactionInstruction,
|
|
3033
|
+
): InitializeAccountParams;
|
|
3034
|
+
/**
|
|
3035
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
3036
|
+
*/
|
|
3037
|
+
static decodeAuthorize(
|
|
3038
|
+
instruction: TransactionInstruction,
|
|
3039
|
+
): AuthorizeVoteParams;
|
|
3040
|
+
/**
|
|
3041
|
+
* Decode a withdraw instruction and retrieve the instruction params.
|
|
3042
|
+
*/
|
|
3043
|
+
static decodeWithdraw(
|
|
3044
|
+
instruction: TransactionInstruction,
|
|
3045
|
+
): WithdrawFromVoteAccountParams;
|
|
3046
|
+
}
|
|
3047
|
+
/**
|
|
3048
|
+
* An enumeration of valid VoteInstructionType's
|
|
3049
|
+
*/
|
|
3050
|
+
export type VoteInstructionType =
|
|
3051
|
+
| 'Authorize'
|
|
3052
|
+
| 'InitializeAccount'
|
|
3053
|
+
| 'Withdraw';
|
|
3054
|
+
/**
|
|
3055
|
+
* VoteAuthorize type
|
|
3056
|
+
*/
|
|
3057
|
+
export type VoteAuthorizationType = {
|
|
3058
|
+
/** The VoteAuthorize index (from solana-vote-program) */
|
|
3059
|
+
index: number;
|
|
3060
|
+
};
|
|
3061
|
+
/**
|
|
3062
|
+
* An enumeration of valid VoteAuthorization layouts.
|
|
3063
|
+
*/
|
|
3064
|
+
export const VoteAuthorizationLayout: Readonly<{
|
|
3065
|
+
Voter: {
|
|
3066
|
+
index: number;
|
|
3067
|
+
};
|
|
3068
|
+
Withdrawer: {
|
|
3069
|
+
index: number;
|
|
3070
|
+
};
|
|
3071
|
+
}>;
|
|
3072
|
+
/**
|
|
3073
|
+
* Factory class for transactions to interact with the Vote program
|
|
3074
|
+
*/
|
|
3075
|
+
export class VoteProgram {
|
|
3076
|
+
/**
|
|
3077
|
+
* Public key that identifies the Vote program
|
|
3078
|
+
*/
|
|
3079
|
+
static programId: PublicKey;
|
|
3080
|
+
/**
|
|
3081
|
+
* Max space of a Vote account
|
|
3082
|
+
*
|
|
3083
|
+
* This is generated from the solana-vote-program VoteState struct as
|
|
3084
|
+
* `VoteState::size_of()`:
|
|
3085
|
+
* https://docs.rs/solana-vote-program/1.9.5/solana_vote_program/vote_state/struct.VoteState.html#method.size_of
|
|
3086
|
+
*/
|
|
3087
|
+
static space: number;
|
|
3088
|
+
/**
|
|
3089
|
+
* Generate an Initialize instruction.
|
|
3090
|
+
*/
|
|
3091
|
+
static initializeAccount(
|
|
3092
|
+
params: InitializeAccountParams,
|
|
3093
|
+
): TransactionInstruction;
|
|
3094
|
+
/**
|
|
3095
|
+
* Generate a transaction that creates a new Vote account.
|
|
3096
|
+
*/
|
|
3097
|
+
static createAccount(params: CreateVoteAccountParams): Transaction;
|
|
3098
|
+
/**
|
|
3099
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
|
|
3100
|
+
*/
|
|
3101
|
+
static authorize(params: AuthorizeVoteParams): Transaction;
|
|
3102
|
+
/**
|
|
3103
|
+
* Generate a transaction to withdraw from a Vote account.
|
|
3104
|
+
*/
|
|
3105
|
+
static withdraw(params: WithdrawFromVoteAccountParams): Transaction;
|
|
3106
|
+
}
|
|
3107
|
+
|
|
2951
3108
|
export const SYSVAR_CLOCK_PUBKEY: PublicKey;
|
|
2952
3109
|
export const SYSVAR_EPOCH_SCHEDULE_PUBKEY: PublicKey;
|
|
2953
3110
|
export const SYSVAR_INSTRUCTIONS_PUBKEY: PublicKey;
|
package/lib/index.esm.js
CHANGED
|
@@ -2075,6 +2075,13 @@ const authorized = (property = 'authorized') => {
|
|
|
2075
2075
|
const lockup = (property = 'lockup') => {
|
|
2076
2076
|
return BufferLayout.struct([BufferLayout.ns64('unixTimestamp'), BufferLayout.ns64('epoch'), publicKey('custodian')], property);
|
|
2077
2077
|
};
|
|
2078
|
+
/**
|
|
2079
|
+
* Layout for a VoteInit object
|
|
2080
|
+
*/
|
|
2081
|
+
|
|
2082
|
+
const voteInit = (property = 'voteInit') => {
|
|
2083
|
+
return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
|
|
2084
|
+
};
|
|
2078
2085
|
function getAlloc(type, fields) {
|
|
2079
2086
|
let alloc = 0;
|
|
2080
2087
|
type.layout.fields.forEach(item => {
|
|
@@ -4312,13 +4319,13 @@ const VersionResult = type({
|
|
|
4312
4319
|
const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(type({
|
|
4313
4320
|
err: nullable(union([type({}), string()])),
|
|
4314
4321
|
logs: nullable(array(string())),
|
|
4315
|
-
accounts: optional(nullable(array(type({
|
|
4322
|
+
accounts: optional(nullable(array(nullable(type({
|
|
4316
4323
|
executable: boolean(),
|
|
4317
4324
|
owner: string(),
|
|
4318
4325
|
lamports: number(),
|
|
4319
4326
|
data: array(string()),
|
|
4320
4327
|
rentEpoch: optional(number())
|
|
4321
|
-
})))),
|
|
4328
|
+
}))))),
|
|
4322
4329
|
unitsConsumed: optional(number())
|
|
4323
4330
|
}));
|
|
4324
4331
|
|
|
@@ -8223,30 +8230,22 @@ class StakeProgram {
|
|
|
8223
8230
|
});
|
|
8224
8231
|
}
|
|
8225
8232
|
/**
|
|
8226
|
-
*
|
|
8233
|
+
* @internal
|
|
8227
8234
|
*/
|
|
8228
8235
|
|
|
8229
8236
|
|
|
8230
|
-
static
|
|
8237
|
+
static splitInstruction(params) {
|
|
8231
8238
|
const {
|
|
8232
8239
|
stakePubkey,
|
|
8233
8240
|
authorizedPubkey,
|
|
8234
8241
|
splitStakePubkey,
|
|
8235
8242
|
lamports
|
|
8236
8243
|
} = params;
|
|
8237
|
-
const transaction = new Transaction();
|
|
8238
|
-
transaction.add(SystemProgram.createAccount({
|
|
8239
|
-
fromPubkey: authorizedPubkey,
|
|
8240
|
-
newAccountPubkey: splitStakePubkey,
|
|
8241
|
-
lamports: 0,
|
|
8242
|
-
space: this.space,
|
|
8243
|
-
programId: this.programId
|
|
8244
|
-
}));
|
|
8245
8244
|
const type = STAKE_INSTRUCTION_LAYOUTS.Split;
|
|
8246
8245
|
const data = encodeData(type, {
|
|
8247
8246
|
lamports
|
|
8248
8247
|
});
|
|
8249
|
-
return
|
|
8248
|
+
return new TransactionInstruction({
|
|
8250
8249
|
keys: [{
|
|
8251
8250
|
pubkey: stakePubkey,
|
|
8252
8251
|
isSigner: false,
|
|
@@ -8264,6 +8263,52 @@ class StakeProgram {
|
|
|
8264
8263
|
data
|
|
8265
8264
|
});
|
|
8266
8265
|
}
|
|
8266
|
+
/**
|
|
8267
|
+
* Generate a Transaction that splits Stake tokens into another stake account
|
|
8268
|
+
*/
|
|
8269
|
+
|
|
8270
|
+
|
|
8271
|
+
static split(params) {
|
|
8272
|
+
const transaction = new Transaction();
|
|
8273
|
+
transaction.add(SystemProgram.createAccount({
|
|
8274
|
+
fromPubkey: params.authorizedPubkey,
|
|
8275
|
+
newAccountPubkey: params.splitStakePubkey,
|
|
8276
|
+
lamports: 0,
|
|
8277
|
+
space: this.space,
|
|
8278
|
+
programId: this.programId
|
|
8279
|
+
}));
|
|
8280
|
+
return transaction.add(this.splitInstruction(params));
|
|
8281
|
+
}
|
|
8282
|
+
/**
|
|
8283
|
+
* Generate a Transaction that splits Stake tokens into another account
|
|
8284
|
+
* derived from a base public key and seed
|
|
8285
|
+
*/
|
|
8286
|
+
|
|
8287
|
+
|
|
8288
|
+
static splitWithSeed(params) {
|
|
8289
|
+
const {
|
|
8290
|
+
stakePubkey,
|
|
8291
|
+
authorizedPubkey,
|
|
8292
|
+
splitStakePubkey,
|
|
8293
|
+
basePubkey,
|
|
8294
|
+
seed,
|
|
8295
|
+
lamports
|
|
8296
|
+
} = params;
|
|
8297
|
+
const transaction = new Transaction();
|
|
8298
|
+
transaction.add(SystemProgram.allocate({
|
|
8299
|
+
accountPubkey: splitStakePubkey,
|
|
8300
|
+
basePubkey,
|
|
8301
|
+
seed,
|
|
8302
|
+
space: this.space,
|
|
8303
|
+
programId: this.programId
|
|
8304
|
+
}));
|
|
8305
|
+
return transaction.add(this.splitInstruction({
|
|
8306
|
+
stakePubkey,
|
|
8307
|
+
authorizedPubkey,
|
|
8308
|
+
splitStakePubkey,
|
|
8309
|
+
lamports
|
|
8310
|
+
}));
|
|
8311
|
+
}
|
|
8267
8312
|
/**
|
|
8268
8313
|
* Generate a Transaction that merges Stake accounts.
|
|
8269
8314
|
*/
|
|
@@ -8722,6 +8767,322 @@ function getPriorVoters({
|
|
|
8722
8767
|
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
8723
8768
|
}
|
|
8724
8769
|
|
|
8770
|
+
/**
|
|
8771
|
+
* Vote account info
|
|
8772
|
+
*/
|
|
8773
|
+
|
|
8774
|
+
class VoteInit {
|
|
8775
|
+
/** [0, 100] */
|
|
8776
|
+
constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
|
|
8777
|
+
this.nodePubkey = void 0;
|
|
8778
|
+
this.authorizedVoter = void 0;
|
|
8779
|
+
this.authorizedWithdrawer = void 0;
|
|
8780
|
+
this.commission = void 0;
|
|
8781
|
+
this.nodePubkey = nodePubkey;
|
|
8782
|
+
this.authorizedVoter = authorizedVoter;
|
|
8783
|
+
this.authorizedWithdrawer = authorizedWithdrawer;
|
|
8784
|
+
this.commission = commission;
|
|
8785
|
+
}
|
|
8786
|
+
|
|
8787
|
+
}
|
|
8788
|
+
/**
|
|
8789
|
+
* Create vote account transaction params
|
|
8790
|
+
*/
|
|
8791
|
+
|
|
8792
|
+
/**
|
|
8793
|
+
* Vote Instruction class
|
|
8794
|
+
*/
|
|
8795
|
+
class VoteInstruction {
|
|
8796
|
+
/**
|
|
8797
|
+
* @internal
|
|
8798
|
+
*/
|
|
8799
|
+
constructor() {}
|
|
8800
|
+
/**
|
|
8801
|
+
* Decode a vote instruction and retrieve the instruction type.
|
|
8802
|
+
*/
|
|
8803
|
+
|
|
8804
|
+
|
|
8805
|
+
static decodeInstructionType(instruction) {
|
|
8806
|
+
this.checkProgramId(instruction.programId);
|
|
8807
|
+
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
8808
|
+
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
8809
|
+
let type;
|
|
8810
|
+
|
|
8811
|
+
for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
|
|
8812
|
+
if (layout.index == typeIndex) {
|
|
8813
|
+
type = ixType;
|
|
8814
|
+
break;
|
|
8815
|
+
}
|
|
8816
|
+
}
|
|
8817
|
+
|
|
8818
|
+
if (!type) {
|
|
8819
|
+
throw new Error('Instruction type incorrect; not a VoteInstruction');
|
|
8820
|
+
}
|
|
8821
|
+
|
|
8822
|
+
return type;
|
|
8823
|
+
}
|
|
8824
|
+
/**
|
|
8825
|
+
* Decode an initialize vote instruction and retrieve the instruction params.
|
|
8826
|
+
*/
|
|
8827
|
+
|
|
8828
|
+
|
|
8829
|
+
static decodeInitializeAccount(instruction) {
|
|
8830
|
+
this.checkProgramId(instruction.programId);
|
|
8831
|
+
this.checkKeyLength(instruction.keys, 4);
|
|
8832
|
+
const {
|
|
8833
|
+
voteInit
|
|
8834
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
|
|
8835
|
+
return {
|
|
8836
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
8837
|
+
nodePubkey: instruction.keys[3].pubkey,
|
|
8838
|
+
voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
|
|
8839
|
+
};
|
|
8840
|
+
}
|
|
8841
|
+
/**
|
|
8842
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
8843
|
+
*/
|
|
8844
|
+
|
|
8845
|
+
|
|
8846
|
+
static decodeAuthorize(instruction) {
|
|
8847
|
+
this.checkProgramId(instruction.programId);
|
|
8848
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
8849
|
+
const {
|
|
8850
|
+
newAuthorized,
|
|
8851
|
+
voteAuthorizationType
|
|
8852
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.Authorize, instruction.data);
|
|
8853
|
+
return {
|
|
8854
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
8855
|
+
authorizedPubkey: instruction.keys[2].pubkey,
|
|
8856
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
8857
|
+
voteAuthorizationType: {
|
|
8858
|
+
index: voteAuthorizationType
|
|
8859
|
+
}
|
|
8860
|
+
};
|
|
8861
|
+
}
|
|
8862
|
+
/**
|
|
8863
|
+
* Decode a withdraw instruction and retrieve the instruction params.
|
|
8864
|
+
*/
|
|
8865
|
+
|
|
8866
|
+
|
|
8867
|
+
static decodeWithdraw(instruction) {
|
|
8868
|
+
this.checkProgramId(instruction.programId);
|
|
8869
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
8870
|
+
const {
|
|
8871
|
+
lamports
|
|
8872
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
|
|
8873
|
+
return {
|
|
8874
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
8875
|
+
authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
|
|
8876
|
+
lamports,
|
|
8877
|
+
toPubkey: instruction.keys[1].pubkey
|
|
8878
|
+
};
|
|
8879
|
+
}
|
|
8880
|
+
/**
|
|
8881
|
+
* @internal
|
|
8882
|
+
*/
|
|
8883
|
+
|
|
8884
|
+
|
|
8885
|
+
static checkProgramId(programId) {
|
|
8886
|
+
if (!programId.equals(VoteProgram.programId)) {
|
|
8887
|
+
throw new Error('invalid instruction; programId is not VoteProgram');
|
|
8888
|
+
}
|
|
8889
|
+
}
|
|
8890
|
+
/**
|
|
8891
|
+
* @internal
|
|
8892
|
+
*/
|
|
8893
|
+
|
|
8894
|
+
|
|
8895
|
+
static checkKeyLength(keys, expectedLength) {
|
|
8896
|
+
if (keys.length < expectedLength) {
|
|
8897
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
8898
|
+
}
|
|
8899
|
+
}
|
|
8900
|
+
|
|
8901
|
+
}
|
|
8902
|
+
/**
|
|
8903
|
+
* An enumeration of valid VoteInstructionType's
|
|
8904
|
+
*/
|
|
8905
|
+
|
|
8906
|
+
const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
8907
|
+
InitializeAccount: {
|
|
8908
|
+
index: 0,
|
|
8909
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteInit()])
|
|
8910
|
+
},
|
|
8911
|
+
Authorize: {
|
|
8912
|
+
index: 1,
|
|
8913
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), publicKey('newAuthorized'), BufferLayout.u32('voteAuthorizationType')])
|
|
8914
|
+
},
|
|
8915
|
+
Withdraw: {
|
|
8916
|
+
index: 3,
|
|
8917
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
8918
|
+
}
|
|
8919
|
+
});
|
|
8920
|
+
/**
|
|
8921
|
+
* VoteAuthorize type
|
|
8922
|
+
*/
|
|
8923
|
+
|
|
8924
|
+
/**
|
|
8925
|
+
* An enumeration of valid VoteAuthorization layouts.
|
|
8926
|
+
*/
|
|
8927
|
+
const VoteAuthorizationLayout = Object.freeze({
|
|
8928
|
+
Voter: {
|
|
8929
|
+
index: 0
|
|
8930
|
+
},
|
|
8931
|
+
Withdrawer: {
|
|
8932
|
+
index: 1
|
|
8933
|
+
}
|
|
8934
|
+
});
|
|
8935
|
+
/**
|
|
8936
|
+
* Factory class for transactions to interact with the Vote program
|
|
8937
|
+
*/
|
|
8938
|
+
|
|
8939
|
+
class VoteProgram {
|
|
8940
|
+
/**
|
|
8941
|
+
* @internal
|
|
8942
|
+
*/
|
|
8943
|
+
constructor() {}
|
|
8944
|
+
/**
|
|
8945
|
+
* Public key that identifies the Vote program
|
|
8946
|
+
*/
|
|
8947
|
+
|
|
8948
|
+
|
|
8949
|
+
/**
|
|
8950
|
+
* Generate an Initialize instruction.
|
|
8951
|
+
*/
|
|
8952
|
+
static initializeAccount(params) {
|
|
8953
|
+
const {
|
|
8954
|
+
votePubkey,
|
|
8955
|
+
nodePubkey,
|
|
8956
|
+
voteInit
|
|
8957
|
+
} = params;
|
|
8958
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
|
|
8959
|
+
const data = encodeData(type, {
|
|
8960
|
+
voteInit: {
|
|
8961
|
+
nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
|
|
8962
|
+
authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
|
|
8963
|
+
authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
|
|
8964
|
+
commission: voteInit.commission
|
|
8965
|
+
}
|
|
8966
|
+
});
|
|
8967
|
+
const instructionData = {
|
|
8968
|
+
keys: [{
|
|
8969
|
+
pubkey: votePubkey,
|
|
8970
|
+
isSigner: false,
|
|
8971
|
+
isWritable: true
|
|
8972
|
+
}, {
|
|
8973
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
8974
|
+
isSigner: false,
|
|
8975
|
+
isWritable: false
|
|
8976
|
+
}, {
|
|
8977
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
8978
|
+
isSigner: false,
|
|
8979
|
+
isWritable: false
|
|
8980
|
+
}, {
|
|
8981
|
+
pubkey: nodePubkey,
|
|
8982
|
+
isSigner: true,
|
|
8983
|
+
isWritable: false
|
|
8984
|
+
}],
|
|
8985
|
+
programId: this.programId,
|
|
8986
|
+
data
|
|
8987
|
+
};
|
|
8988
|
+
return new TransactionInstruction(instructionData);
|
|
8989
|
+
}
|
|
8990
|
+
/**
|
|
8991
|
+
* Generate a transaction that creates a new Vote account.
|
|
8992
|
+
*/
|
|
8993
|
+
|
|
8994
|
+
|
|
8995
|
+
static createAccount(params) {
|
|
8996
|
+
const transaction = new Transaction();
|
|
8997
|
+
transaction.add(SystemProgram.createAccount({
|
|
8998
|
+
fromPubkey: params.fromPubkey,
|
|
8999
|
+
newAccountPubkey: params.votePubkey,
|
|
9000
|
+
lamports: params.lamports,
|
|
9001
|
+
space: this.space,
|
|
9002
|
+
programId: this.programId
|
|
9003
|
+
}));
|
|
9004
|
+
return transaction.add(this.initializeAccount({
|
|
9005
|
+
votePubkey: params.votePubkey,
|
|
9006
|
+
nodePubkey: params.voteInit.nodePubkey,
|
|
9007
|
+
voteInit: params.voteInit
|
|
9008
|
+
}));
|
|
9009
|
+
}
|
|
9010
|
+
/**
|
|
9011
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
|
|
9012
|
+
*/
|
|
9013
|
+
|
|
9014
|
+
|
|
9015
|
+
static authorize(params) {
|
|
9016
|
+
const {
|
|
9017
|
+
votePubkey,
|
|
9018
|
+
authorizedPubkey,
|
|
9019
|
+
newAuthorizedPubkey,
|
|
9020
|
+
voteAuthorizationType
|
|
9021
|
+
} = params;
|
|
9022
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.Authorize;
|
|
9023
|
+
const data = encodeData(type, {
|
|
9024
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
9025
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
9026
|
+
});
|
|
9027
|
+
const keys = [{
|
|
9028
|
+
pubkey: votePubkey,
|
|
9029
|
+
isSigner: false,
|
|
9030
|
+
isWritable: true
|
|
9031
|
+
}, {
|
|
9032
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
9033
|
+
isSigner: false,
|
|
9034
|
+
isWritable: false
|
|
9035
|
+
}, {
|
|
9036
|
+
pubkey: authorizedPubkey,
|
|
9037
|
+
isSigner: true,
|
|
9038
|
+
isWritable: false
|
|
9039
|
+
}];
|
|
9040
|
+
return new Transaction().add({
|
|
9041
|
+
keys,
|
|
9042
|
+
programId: this.programId,
|
|
9043
|
+
data
|
|
9044
|
+
});
|
|
9045
|
+
}
|
|
9046
|
+
/**
|
|
9047
|
+
* Generate a transaction to withdraw from a Vote account.
|
|
9048
|
+
*/
|
|
9049
|
+
|
|
9050
|
+
|
|
9051
|
+
static withdraw(params) {
|
|
9052
|
+
const {
|
|
9053
|
+
votePubkey,
|
|
9054
|
+
authorizedWithdrawerPubkey,
|
|
9055
|
+
lamports,
|
|
9056
|
+
toPubkey
|
|
9057
|
+
} = params;
|
|
9058
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
9059
|
+
const data = encodeData(type, {
|
|
9060
|
+
lamports
|
|
9061
|
+
});
|
|
9062
|
+
const keys = [{
|
|
9063
|
+
pubkey: votePubkey,
|
|
9064
|
+
isSigner: false,
|
|
9065
|
+
isWritable: true
|
|
9066
|
+
}, {
|
|
9067
|
+
pubkey: toPubkey,
|
|
9068
|
+
isSigner: false,
|
|
9069
|
+
isWritable: true
|
|
9070
|
+
}, {
|
|
9071
|
+
pubkey: authorizedWithdrawerPubkey,
|
|
9072
|
+
isSigner: true,
|
|
9073
|
+
isWritable: false
|
|
9074
|
+
}];
|
|
9075
|
+
return new Transaction().add({
|
|
9076
|
+
keys,
|
|
9077
|
+
programId: this.programId,
|
|
9078
|
+
data
|
|
9079
|
+
});
|
|
9080
|
+
}
|
|
9081
|
+
|
|
9082
|
+
}
|
|
9083
|
+
VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
|
|
9084
|
+
VoteProgram.space = 3731;
|
|
9085
|
+
|
|
8725
9086
|
/**
|
|
8726
9087
|
* Send and confirm a raw transaction
|
|
8727
9088
|
*
|
|
@@ -8785,5 +9146,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
8785
9146
|
|
|
8786
9147
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
8787
9148
|
|
|
8788
|
-
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9149
|
+
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
8789
9150
|
//# sourceMappingURL=index.esm.js.map
|