Skip to content

Commit

Permalink
fix: optional stake lockup field parameters (#16943)
Browse files Browse the repository at this point in the history
* fix: optional stake lockup field parameters

* chore: update web3.js/src/stake-program.ts

Co-authored-by: Justin Starry <[email protected]>

* chore: prettier

Co-authored-by: Justin Starry <[email protected]>
Co-authored-by: Justin Starry <[email protected]>
  • Loading branch information
3 people authored Apr 29, 2021
1 parent 90641ad commit a2fbb9c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions web3.js/src/publickey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
14 changes: 10 additions & 4 deletions web3.js/src/stake-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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;
};
Expand All @@ -86,7 +91,7 @@ export type CreateStakeAccountWithSeedParams = {
basePubkey: PublicKey;
seed: string;
authorized: Authorized;
lockup: Lockup;
lockup?: Lockup;
lamports: number;
};

Expand All @@ -96,7 +101,7 @@ export type CreateStakeAccountWithSeedParams = {
export type InitializeStakeParams = {
stakePubkey: PublicKey;
authorized: Authorized;
lockup: Lockup;
lockup?: Lockup;
};

/**
Expand Down Expand Up @@ -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: {
Expand Down
1 change: 0 additions & 1 deletion web3.js/test/stake-program.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ describe('StakeProgram', () => {
authorized.publicKey,
authorized.publicKey,
),
lockup: new Lockup(0, 0, new PublicKey(0)),
lamports: minimumAmount + 42,
});

Expand Down

0 comments on commit a2fbb9c

Please sign in to comment.