Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and bugfixing - a way to view it #14

Merged
merged 24 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9496223
rename RestakeDeposit to ExtendStake
kstepanovdev Jul 1, 2024
7ccde07
add days lockup days to Flex
kstepanovdev Jul 1, 2024
de22b24
imporove uninitialize assertion
kstepanovdev Jul 1, 2024
0cd2b65
rename RewardPool:fill to RewardPool:distribute
kstepanovdev Jul 1, 2024
82da524
from now fill cannot be invoked if rewards equals to zero
kstepanovdev Jul 1, 2024
29c36e8
refactor DistributeRewards::process
kstepanovdev Jul 1, 2024
6d6dc3c
refactor withdraw_mining
kstepanovdev Jul 1, 2024
1e302bf
add fn for mining account closing
kstepanovdev Jul 2, 2024
6b88758
deposit_authority don't have to be mutable in close_mining ix
kstepanovdev Jul 2, 2024
e7e174e
use more clear variable for RewardCalculator::update_index
kstepanovdev Jul 2, 2024
de616cc
regenerate IDL and clients
kstepanovdev Jul 2, 2024
0e8f320
Initialize rewards-pool deposit authority signature (#15)
rwwwx Jul 9, 2024
e27f61c
Throw an error instead of returning Ok() when 'rewards == 0'
rwwwx Jul 9, 2024
e33690b
removed elvis operator
rwwwx Jul 9, 2024
1cfd613
Merge pull request #16 from adm-metaex/MTG-401-Throw-an-error-instead…
rwwwx Jul 9, 2024
3369062
[MTG-237] ci cd (#17)
rwwwx Jul 10, 2024
736e0dd
Fix comment in instruction.rs
kstepanovdev Jul 12, 2024
fce3aae
Forbid closing mininig if there are pending rewards
kstepanovdev Jul 12, 2024
8288e8f
Add comment regarding closing accounts
kstepanovdev Jul 12, 2024
d519d1b
Unify Contexts && verification checks (#21)
rwwwx Jul 16, 2024
994180c
mtg-425: Error handling improvements (#22)
rwwwx Jul 16, 2024
48f49d6
Threw an error if `weighted_stake_diffs.entry()` is empty (#25)
rwwwx Jul 17, 2024
6fa347c
[Mtg-296] delegated staking extend staking with delegate parameter (#18)
kstepanovdev Jul 22, 2024
b0ae0ac
Merge branch 'devnet-version' of github.com:adm-metaex/mplx-rewards i…
kstepanovdev Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions clients/js/src/generated/errors/mplxRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ nameToErrorMap.set(
InvalidPrimitiveTypesConversionError
);

/** RewardsMustBeClaimed: Rewards: unclaimed rewards must be claimed */
export class RewardsMustBeClaimedError extends ProgramError {
override readonly name: string = 'RewardsMustBeClaimed';

readonly code: number = 0xb; // 11

constructor(program: Program, cause?: Error) {
super('Rewards: unclaimed rewards must be claimed', program, cause);
}
}
codeToErrorMap.set(0xb, RewardsMustBeClaimedError);
nameToErrorMap.set('RewardsMustBeClaimed', RewardsMustBeClaimedError);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
124 changes: 124 additions & 0 deletions clients/js/src/generated/instructions/closeMining.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
* This code was AUTOGENERATED using the kinobi library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun kinobi to update it.
*
* @see https://github.com/metaplex-foundation/kinobi
*/

import {
Context,
Pda,
PublicKey,
Signer,
TransactionBuilder,
transactionBuilder,
} from '@metaplex-foundation/umi';
import {
Serializer,
mapSerializer,
struct,
u8,
} from '@metaplex-foundation/umi/serializers';
import {
ResolvedAccount,
ResolvedAccountsWithIndices,
getAccountMetasAndSigners,
} from '../shared';

// Accounts.
export type CloseMiningInstructionAccounts = {
/** The address of the user's mining account */
mining: PublicKey | Pda;
/** The end user the mining accounts belongs to */
miningOwner: Signer;
/** The address where lamports from account closing will be transferred */
targetAccount: PublicKey | Pda;
depositAuthority: Signer;
/** The address of the reward pool */
rewardPool: PublicKey | Pda;
};

// Data.
export type CloseMiningInstructionData = { discriminator: number };

export type CloseMiningInstructionDataArgs = {};

export function getCloseMiningInstructionDataSerializer(): Serializer<
CloseMiningInstructionDataArgs,
CloseMiningInstructionData
> {
return mapSerializer<
CloseMiningInstructionDataArgs,
any,
CloseMiningInstructionData
>(
struct<CloseMiningInstructionData>([['discriminator', u8()]], {
description: 'CloseMiningInstructionData',
}),
(value) => ({ ...value, discriminator: 8 })
) as Serializer<CloseMiningInstructionDataArgs, CloseMiningInstructionData>;
}

// Instruction.
export function closeMining(
context: Pick<Context, 'programs'>,
input: CloseMiningInstructionAccounts
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
'mplxRewards',
'BF5PatmRTQDgEKoXR7iHRbkibEEi83nVM38cUKWzQcTR'
);

// Accounts.
const resolvedAccounts = {
mining: {
index: 0,
isWritable: false as boolean,
value: input.mining ?? null,
},
miningOwner: {
index: 1,
isWritable: false as boolean,
value: input.miningOwner ?? null,
},
targetAccount: {
index: 2,
isWritable: true as boolean,
value: input.targetAccount ?? null,
},
depositAuthority: {
index: 3,
isWritable: false as boolean,
value: input.depositAuthority ?? null,
},
rewardPool: {
index: 4,
isWritable: true as boolean,
value: input.rewardPool ?? null,
},
} satisfies ResolvedAccountsWithIndices;

// Accounts in order.
const orderedAccounts: ResolvedAccount[] = Object.values(
resolvedAccounts
).sort((a, b) => a.index - b.index);

// Keys and Signers.
const [keys, signers] = getAccountMetasAndSigners(
orderedAccounts,
'programId',
programId
);

// Data.
const data = getCloseMiningInstructionDataSerializer().serialize({});

// Bytes Created On Chain.
const bytesCreatedOnChain = 0;

return transactionBuilder([
{ instruction: { keys, programId, data }, signers, bytesCreatedOnChain },
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from '../types';

// Accounts.
export type RestakeDepositInstructionAccounts = {
export type ExtendStakeInstructionAccounts = {
/** The address of the reward pool */
rewardPool: PublicKey | Pda;
/** The address of the mining account which belongs to the user and stores info about user's rewards */
Expand All @@ -46,7 +46,7 @@ export type RestakeDepositInstructionAccounts = {
};

// Data.
export type RestakeDepositInstructionData = {
export type ExtendStakeInstructionData = {
discriminator: number;
oldLockupPeriod: LockupPeriod;
newLockupPeriod: LockupPeriod;
Expand All @@ -56,7 +56,7 @@ export type RestakeDepositInstructionData = {
miningOwner: PublicKey;
};

export type RestakeDepositInstructionDataArgs = {
export type ExtendStakeInstructionDataArgs = {
oldLockupPeriod: LockupPeriodArgs;
newLockupPeriod: LockupPeriodArgs;
depositStartTs: number | bigint;
Expand All @@ -65,16 +65,16 @@ export type RestakeDepositInstructionDataArgs = {
miningOwner: PublicKey;
};

export function getRestakeDepositInstructionDataSerializer(): Serializer<
RestakeDepositInstructionDataArgs,
RestakeDepositInstructionData
export function getExtendStakeInstructionDataSerializer(): Serializer<
ExtendStakeInstructionDataArgs,
ExtendStakeInstructionData
> {
return mapSerializer<
RestakeDepositInstructionDataArgs,
ExtendStakeInstructionDataArgs,
any,
RestakeDepositInstructionData
ExtendStakeInstructionData
>(
struct<RestakeDepositInstructionData>(
struct<ExtendStakeInstructionData>(
[
['discriminator', u8()],
['oldLockupPeriod', getLockupPeriodSerializer()],
Expand All @@ -84,22 +84,19 @@ export function getRestakeDepositInstructionDataSerializer(): Serializer<
['additionalAmount', u64()],
['miningOwner', publicKeySerializer()],
],
{ description: 'RestakeDepositInstructionData' }
{ description: 'ExtendStakeInstructionData' }
),
(value) => ({ ...value, discriminator: 6 })
) as Serializer<
RestakeDepositInstructionDataArgs,
RestakeDepositInstructionData
>;
) as Serializer<ExtendStakeInstructionDataArgs, ExtendStakeInstructionData>;
}

// Args.
export type RestakeDepositInstructionArgs = RestakeDepositInstructionDataArgs;
export type ExtendStakeInstructionArgs = ExtendStakeInstructionDataArgs;

// Instruction.
export function restakeDeposit(
export function extendStake(
context: Pick<Context, 'programs'>,
input: RestakeDepositInstructionAccounts & RestakeDepositInstructionArgs
input: ExtendStakeInstructionAccounts & ExtendStakeInstructionArgs
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
Expand Down Expand Up @@ -132,7 +129,7 @@ export function restakeDeposit(
} satisfies ResolvedAccountsWithIndices;

// Arguments.
const resolvedArgs: RestakeDepositInstructionArgs = { ...input };
const resolvedArgs: ExtendStakeInstructionArgs = { ...input };

// Accounts in order.
const orderedAccounts: ResolvedAccount[] = Object.values(
Expand All @@ -147,8 +144,8 @@ export function restakeDeposit(
);

// Data.
const data = getRestakeDepositInstructionDataSerializer().serialize(
resolvedArgs as RestakeDepositInstructionDataArgs
const data = getExtendStakeInstructionDataSerializer().serialize(
resolvedArgs as ExtendStakeInstructionDataArgs
);

// Bytes Created On Chain.
Expand Down
3 changes: 2 additions & 1 deletion clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
*/

export * from './claim';
export * from './closeMining';
export * from './depositMining';
export * from './distributeRewards';
export * from './extendStake';
export * from './fillVault';
export * from './initializeMining';
export * from './initializePool';
export * from './restakeDeposit';
export * from './withdrawMining';
3 changes: 3 additions & 0 deletions clients/rust/src/generated/errors/mplx_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub enum MplxRewardsError {
/// 10 (0xA) - Rewards: distribution_ends_at date is lower than current date
#[error("Rewards: distribution_ends_at date is lower than current date ")]
InvalidPrimitiveTypesConversion,
/// 11 (0xB) - Rewards: unclaimed rewards must be claimed
#[error("Rewards: unclaimed rewards must be claimed")]
RewardsMustBeClaimed,
}

impl solana_program::program_error::PrintProgramError for MplxRewardsError {
Expand Down
Loading