-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
385 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
programs/cardinal-rewards-center/src/stake_entry/reset_stake_entry.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::errors::ErrorCode; | ||
use crate::StakeEntry; | ||
use crate::StakePool; | ||
use anchor_lang::prelude::*; | ||
|
||
#[derive(Accounts)] | ||
pub struct ResetStakeEntryCtx<'info> { | ||
stake_pool: Box<Account<'info, StakePool>>, | ||
#[account(mut, constraint = stake_pool.key() == stake_entry.pool @ ErrorCode::InvalidStakePool)] | ||
stake_entry: Box<Account<'info, StakeEntry>>, | ||
#[account(mut, constraint = stake_pool.authority == authority.key() @ ErrorCode::InvalidAuthority)] | ||
authority: Signer<'info>, | ||
} | ||
|
||
pub fn handler(ctx: Context<ResetStakeEntryCtx>) -> Result<()> { | ||
let stake_entry = &mut ctx.accounts.stake_entry; | ||
stake_entry.total_stake_seconds = 0; | ||
stake_entry.used_stake_seconds = 0; | ||
stake_entry.last_updated_at = Clock::get().unwrap().unix_timestamp; | ||
stake_entry.last_staked_at = Clock::get().unwrap().unix_timestamp; | ||
stake_entry.cooldown_start_seconds = None; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* This code was GENERATED using the solita package. | ||
* Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. | ||
* | ||
* See: https://github.com/metaplex-foundation/solita | ||
*/ | ||
|
||
import * as beet from '@metaplex-foundation/beet' | ||
import * as web3 from '@solana/web3.js' | ||
|
||
/** | ||
* @category Instructions | ||
* @category ResetStakeEntry | ||
* @category generated | ||
*/ | ||
export const resetStakeEntryStruct = new beet.BeetArgsStruct<{ | ||
instructionDiscriminator: number[] /* size: 8 */ | ||
}>( | ||
[['instructionDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)]], | ||
'ResetStakeEntryInstructionArgs' | ||
) | ||
/** | ||
* Accounts required by the _resetStakeEntry_ instruction | ||
* | ||
* @property [] stakePool | ||
* @property [_writable_] stakeEntry | ||
* @property [_writable_, **signer**] authority | ||
* @category Instructions | ||
* @category ResetStakeEntry | ||
* @category generated | ||
*/ | ||
export type ResetStakeEntryInstructionAccounts = { | ||
stakePool: web3.PublicKey | ||
stakeEntry: web3.PublicKey | ||
authority: web3.PublicKey | ||
} | ||
|
||
export const resetStakeEntryInstructionDiscriminator = [ | ||
189, 90, 39, 72, 82, 90, 236, 109, | ||
] | ||
|
||
/** | ||
* Creates a _ResetStakeEntry_ instruction. | ||
* | ||
* @param accounts that will be accessed while the instruction is processed | ||
* @category Instructions | ||
* @category ResetStakeEntry | ||
* @category generated | ||
*/ | ||
export function createResetStakeEntryInstruction( | ||
accounts: ResetStakeEntryInstructionAccounts, | ||
programId = new web3.PublicKey('rwcn6Ry17ChPXpJCN2hoK5kwpgFarQqzycXwVJ3om7U') | ||
) { | ||
const [data] = resetStakeEntryStruct.serialize({ | ||
instructionDiscriminator: resetStakeEntryInstructionDiscriminator, | ||
}) | ||
const keys: web3.AccountMeta[] = [ | ||
{ | ||
pubkey: accounts.stakePool, | ||
isWritable: false, | ||
isSigner: false, | ||
}, | ||
{ | ||
pubkey: accounts.stakeEntry, | ||
isWritable: true, | ||
isSigner: false, | ||
}, | ||
{ | ||
pubkey: accounts.authority, | ||
isWritable: true, | ||
isSigner: true, | ||
}, | ||
] | ||
|
||
const ix = new web3.TransactionInstruction({ | ||
programId, | ||
keys, | ||
data, | ||
}) | ||
return ix | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.