fix: optional stake lockup field parameters (#16943)
* fix: optional stake lockup field parameters * chore: update web3.js/src/stake-program.ts Co-authored-by: Justin Starry <justin.m.starry@gmail.com> * chore: prettier Co-authored-by: Justin Starry <justin.m.starry@gmail.com> Co-authored-by: Justin Starry <justin@solana.com>
This commit is contained in:
parent
90641ad28b
commit
a2fbb9cfef
|
@ -39,6 +39,11 @@ export class PublicKey {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default public key value. (All zeros)
|
||||
*/
|
||||
static default: PublicKey = new PublicKey('11111111111111111111111111111111');
|
||||
|
||||
/**
|
||||
* Checks if two publicKeys are equal
|
||||
*/
|
||||
|
|
|
@ -59,6 +59,11 @@ export class Lockup {
|
|||
this.epoch = epoch;
|
||||
this.custodian = custodian;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default, inactive Lockup value
|
||||
*/
|
||||
static default: Lockup = new Lockup(0, 0, PublicKey.default);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +77,7 @@ export type CreateStakeAccountParams = {
|
|||
/** Authorities of the new stake account */
|
||||
authorized: Authorized;
|
||||
/** Lockup of the new stake account */
|
||||
lockup: Lockup;
|
||||
lockup?: Lockup;
|
||||
/** Funding amount */
|
||||
lamports: number;
|
||||
};
|
||||
|
@ -86,7 +91,7 @@ export type CreateStakeAccountWithSeedParams = {
|
|||
basePubkey: PublicKey;
|
||||
seed: string;
|
||||
authorized: Authorized;
|
||||
lockup: Lockup;
|
||||
lockup?: Lockup;
|
||||
lamports: number;
|
||||
};
|
||||
|
||||
|
@ -96,7 +101,7 @@ export type CreateStakeAccountWithSeedParams = {
|
|||
export type InitializeStakeParams = {
|
||||
stakePubkey: PublicKey;
|
||||
authorized: Authorized;
|
||||
lockup: Lockup;
|
||||
lockup?: Lockup;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -502,7 +507,8 @@ export class StakeProgram {
|
|||
* Generate an Initialize instruction to add to a Stake Create transaction
|
||||
*/
|
||||
static initialize(params: InitializeStakeParams): TransactionInstruction {
|
||||
const {stakePubkey, authorized, lockup} = params;
|
||||
const {stakePubkey, authorized, lockup: maybeLockup} = params;
|
||||
const lockup: Lockup = maybeLockup || Lockup.default;
|
||||
const type = STAKE_INSTRUCTION_LAYOUTS.Initialize;
|
||||
const data = encodeData(type, {
|
||||
authorized: {
|
||||
|
|
|
@ -367,7 +367,6 @@ describe('StakeProgram', () => {
|
|||
authorized.publicKey,
|
||||
authorized.publicKey,
|
||||
),
|
||||
lockup: new Lockup(0, 0, new PublicKey(0)),
|
||||
lamports: minimumAmount + 42,
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue