Skip to content

Commit

Permalink
Reset stake entry (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbogle committed Dec 1, 2022
1 parent 066ad21 commit eb48544
Show file tree
Hide file tree
Showing 12 changed files with 385 additions and 12 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,3 @@ If you are developing using Cardinal rewards-center contracts and libraries, fee
For issues please, file a GitHub issue.

> https://discord.gg/cardinallabs
## License

Cardinal Protocol is licensed under the GNU Affero General Public License v3.0.

In short, this means that any changes to this code must be made open source and available under the AGPL-v3.0 license, even if only used privately.
3 changes: 3 additions & 0 deletions programs/cardinal-rewards-center/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub mod cardinal_rewards_center {
pub fn update_total_stake_seconds(ctx: Context<UpdateTotalStakeSecondsCtx>) -> Result<()> {
stake_entry::update_total_stake_seconds::handler(ctx)
}
pub fn reset_stake_entry(ctx: Context<ResetStakeEntryCtx>) -> Result<()> {
stake_entry::reset_stake_entry::handler(ctx)
}
pub fn close_stake_entry(ctx: Context<CloseStakeEntryCtx>) -> Result<()> {
stake_entry::close_stake_entry::handler(ctx)
}
Expand Down
9 changes: 6 additions & 3 deletions programs/cardinal-rewards-center/src/stake_entry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ pub use state::*;
pub mod init_entry;
pub use init_entry::*;

pub mod close_stake_entry;
pub use close_stake_entry::*;

pub mod update_total_stake_seconds;
pub use update_total_stake_seconds::*;

pub mod reset_stake_entry;
pub use reset_stake_entry::*;

pub mod close_stake_entry;
pub use close_stake_entry::*;

pub mod editions;
pub use editions::stake_edition::*;
pub use editions::unstake_edition::*;
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(())
}
1 change: 1 addition & 0 deletions sdk/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export * from './initRewardDistributor'
export * from './initRewardEntry'
export * from './initRewardReceipt'
export * from './initStakeBooster'
export * from './resetStakeEntry'
export * from './setRewardReceiptAllowed'
export * from './stakeEdition'
export * from './unstakeEdition'
Expand Down
81 changes: 81 additions & 0 deletions sdk/generated/instructions/resetStakeEntry.ts
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
}
42 changes: 42 additions & 0 deletions sdk/idl/cardinal_rewards_center.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@ export type CardinalRewardsCenter = {
];
args: [];
},
{
name: "resetStakeEntry";
accounts: [
{
name: "stakePool";
isMut: false;
isSigner: false;
},
{
name: "stakeEntry";
isMut: true;
isSigner: false;
},
{
name: "authority";
isMut: true;
isSigner: true;
}
];
args: [];
},
{
name: "closeStakeEntry";
accounts: [
Expand Down Expand Up @@ -2290,6 +2311,27 @@ export const IDL: CardinalRewardsCenter = {
],
args: [],
},
{
name: "resetStakeEntry",
accounts: [
{
name: "stakePool",
isMut: false,
isSigner: false,
},
{
name: "stakeEntry",
isMut: true,
isSigner: false,
},
{
name: "authority",
isMut: true,
isSigner: true,
},
],
args: [],
},
{
name: "closeStakeEntry",
accounts: [
Expand Down
21 changes: 21 additions & 0 deletions sdk/idl/cardinal_rewards_center_idl.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@
],
"args": []
},
{
"name": "resetStakeEntry",
"accounts": [
{
"name": "stakePool",
"isMut": false,
"isSigner": false
},
{
"name": "stakeEntry",
"isMut": true,
"isSigner": false
},
{
"name": "authority",
"isMut": true,
"isSigner": true
}
],
"args": []
},
{
"name": "closeStakeEntry",
"accounts": [
Expand Down
Loading

0 comments on commit eb48544

Please sign in to comment.