diff --git a/clients/js/src/generated/errors/mplxRewards.ts b/clients/js/src/generated/errors/mplxRewards.ts index a2b62ae8..362b66d6 100644 --- a/clients/js/src/generated/errors/mplxRewards.ts +++ b/clients/js/src/generated/errors/mplxRewards.ts @@ -41,109 +41,37 @@ export class MathOverflowError extends ProgramError { codeToErrorMap.set(0x1, MathOverflowError); nameToErrorMap.set('MathOverflow', MathOverflowError); -/** ZeroAmount: Zero amount */ -export class ZeroAmountError extends ProgramError { - override readonly name: string = 'ZeroAmount'; - - readonly code: number = 0x2; // 2 - - constructor(program: Program, cause?: Error) { - super('Zero amount', program, cause); - } -} -codeToErrorMap.set(0x2, ZeroAmountError); -nameToErrorMap.set('ZeroAmount', ZeroAmountError); - -/** RewardsInvalidVault: Rewards: Invalid vault */ -export class RewardsInvalidVaultError extends ProgramError { - override readonly name: string = 'RewardsInvalidVault'; - - readonly code: number = 0x3; // 3 - - constructor(program: Program, cause?: Error) { - super('Rewards: Invalid vault', program, cause); - } -} -codeToErrorMap.set(0x3, RewardsInvalidVaultError); -nameToErrorMap.set('RewardsInvalidVault', RewardsInvalidVaultError); - /** RewardsNoDeposits: Rewards: No deposits */ export class RewardsNoDepositsError extends ProgramError { override readonly name: string = 'RewardsNoDeposits'; - readonly code: number = 0x4; // 4 + readonly code: number = 0x2; // 2 constructor(program: Program, cause?: Error) { super('Rewards: No deposits', program, cause); } } -codeToErrorMap.set(0x4, RewardsNoDepositsError); +codeToErrorMap.set(0x2, RewardsNoDepositsError); nameToErrorMap.set('RewardsNoDeposits', RewardsNoDepositsError); -/** RebalanceLiquidityCheckFailed: Rebalancing: liquidity check failed */ -export class RebalanceLiquidityCheckFailedError extends ProgramError { - override readonly name: string = 'RebalanceLiquidityCheckFailed'; - - readonly code: number = 0x5; // 5 - - constructor(program: Program, cause?: Error) { - super('Rebalancing: liquidity check failed', program, cause); - } -} -codeToErrorMap.set(0x5, RebalanceLiquidityCheckFailedError); -nameToErrorMap.set( - 'RebalanceLiquidityCheckFailed', - RebalanceLiquidityCheckFailedError -); - -/** IndexMustExist: Rewards: index receiving failed */ -export class IndexMustExistError extends ProgramError { - override readonly name: string = 'IndexMustExist'; - - readonly code: number = 0x6; // 6 - - constructor(program: Program, cause?: Error) { - super('Rewards: index receiving failed', program, cause); - } -} -codeToErrorMap.set(0x6, IndexMustExistError); -nameToErrorMap.set('IndexMustExist', IndexMustExistError); - /** InvalidLockupPeriod: Rewards: lockup period invalid */ export class InvalidLockupPeriodError extends ProgramError { override readonly name: string = 'InvalidLockupPeriod'; - readonly code: number = 0x7; // 7 + readonly code: number = 0x3; // 3 constructor(program: Program, cause?: Error) { super('Rewards: lockup period invalid', program, cause); } } -codeToErrorMap.set(0x7, InvalidLockupPeriodError); +codeToErrorMap.set(0x3, InvalidLockupPeriodError); nameToErrorMap.set('InvalidLockupPeriod', InvalidLockupPeriodError); -/** InvalidCpiCaller: Rewards: only Staking contract is allowed to do CPI calls */ -export class InvalidCpiCallerError extends ProgramError { - override readonly name: string = 'InvalidCpiCaller'; - - readonly code: number = 0x8; // 8 - - constructor(program: Program, cause?: Error) { - super( - 'Rewards: only Staking contract is allowed to do CPI calls', - program, - cause - ); - } -} -codeToErrorMap.set(0x8, InvalidCpiCallerError); -nameToErrorMap.set('InvalidCpiCaller', InvalidCpiCallerError); - /** DistributionInThePast: Rewards: distribution_ends_at date is lower than current date */ export class DistributionInThePastError extends ProgramError { override readonly name: string = 'DistributionInThePast'; - readonly code: number = 0x9; // 9 + readonly code: number = 0x4; // 4 constructor(program: Program, cause?: Error) { super( @@ -153,14 +81,14 @@ export class DistributionInThePastError extends ProgramError { ); } } -codeToErrorMap.set(0x9, DistributionInThePastError); +codeToErrorMap.set(0x4, DistributionInThePastError); nameToErrorMap.set('DistributionInThePast', DistributionInThePastError); /** InvalidPrimitiveTypesConversion: Rewards: distribution_ends_at date is lower than current date */ export class InvalidPrimitiveTypesConversionError extends ProgramError { override readonly name: string = 'InvalidPrimitiveTypesConversion'; - readonly code: number = 0xa; // 10 + readonly code: number = 0x5; // 5 constructor(program: Program, cause?: Error) { super( @@ -170,7 +98,7 @@ export class InvalidPrimitiveTypesConversionError extends ProgramError { ); } } -codeToErrorMap.set(0xa, InvalidPrimitiveTypesConversionError); +codeToErrorMap.set(0x5, InvalidPrimitiveTypesConversionError); nameToErrorMap.set( 'InvalidPrimitiveTypesConversion', InvalidPrimitiveTypesConversionError diff --git a/clients/rust/src/generated/errors/mplx_rewards.rs b/clients/rust/src/generated/errors/mplx_rewards.rs index 050ff57b..c7db1f3d 100644 --- a/clients/rust/src/generated/errors/mplx_rewards.rs +++ b/clients/rust/src/generated/errors/mplx_rewards.rs @@ -16,31 +16,16 @@ pub enum MplxRewardsError { /// 1 (0x1) - Math operation overflow #[error("Math operation overflow")] MathOverflow, - /// 2 (0x2) - Zero amount - #[error("Zero amount")] - ZeroAmount, - /// 3 (0x3) - Rewards: Invalid vault - #[error("Rewards: Invalid vault")] - RewardsInvalidVault, - /// 4 (0x4) - Rewards: No deposits + /// 2 (0x2) - Rewards: No deposits #[error("Rewards: No deposits")] RewardsNoDeposits, - /// 5 (0x5) - Rebalancing: liquidity check failed - #[error("Rebalancing: liquidity check failed")] - RebalanceLiquidityCheckFailed, - /// 6 (0x6) - Rewards: index receiving failed - #[error("Rewards: index receiving failed")] - IndexMustExist, - /// 7 (0x7) - Rewards: lockup period invalid + /// 3 (0x3) - Rewards: lockup period invalid #[error("Rewards: lockup period invalid")] InvalidLockupPeriod, - /// 8 (0x8) - Rewards: only Staking contract is allowed to do CPI calls - #[error("Rewards: only Staking contract is allowed to do CPI calls")] - InvalidCpiCaller, - /// 9 (0x9) - Rewards: distribution_ends_at date is lower than current date + /// 4 (0x4) - Rewards: distribution_ends_at date is lower than current date #[error("Rewards: distribution_ends_at date is lower than current date ")] DistributionInThePast, - /// 10 (0xA) - Rewards: distribution_ends_at date is lower than current date + /// 5 (0x5) - Rewards: distribution_ends_at date is lower than current date #[error("Rewards: distribution_ends_at date is lower than current date ")] InvalidPrimitiveTypesConversion, } diff --git a/idls/mplx_rewards.json b/idls/mplx_rewards.json index a9057513..f9123b0f 100644 --- a/idls/mplx_rewards.json +++ b/idls/mplx_rewards.json @@ -671,46 +671,21 @@ }, { "code": 2, - "name": "ZeroAmount", - "msg": "Zero amount" - }, - { - "code": 3, - "name": "RewardsInvalidVault", - "msg": "Rewards: Invalid vault" - }, - { - "code": 4, "name": "RewardsNoDeposits", "msg": "Rewards: No deposits" }, { - "code": 5, - "name": "RebalanceLiquidityCheckFailed", - "msg": "Rebalancing: liquidity check failed" - }, - { - "code": 6, - "name": "IndexMustExist", - "msg": "Rewards: index receiving failed" - }, - { - "code": 7, + "code": 3, "name": "InvalidLockupPeriod", "msg": "Rewards: lockup period invalid" }, { - "code": 8, - "name": "InvalidCpiCaller", - "msg": "Rewards: only Staking contract is allowed to do CPI calls" - }, - { - "code": 9, + "code": 4, "name": "DistributionInThePast", "msg": "Rewards: distribution_ends_at date is lower than current date " }, { - "code": 10, + "code": 5, "name": "InvalidPrimitiveTypesConversion", "msg": "Rewards: distribution_ends_at date is lower than current date " } diff --git a/programs/rewards/src/asserts.rs b/programs/rewards/src/asserts.rs index 9b191bc3..6a15dbee 100644 --- a/programs/rewards/src/asserts.rs +++ b/programs/rewards/src/asserts.rs @@ -64,12 +64,3 @@ pub fn assert_rent_exempt(account_info: &AccountInfo) -> ProgramResult { Err(ProgramError::AccountNotRentExempt) } } - -/// Assert a non-zero amount -pub fn assert_non_zero_amount(amount: u64) -> ProgramResult { - if amount == 0 { - return Err(MplxRewardsError::ZeroAmount.into()); - } - - Ok(()) -} diff --git a/programs/rewards/src/error.rs b/programs/rewards/src/error.rs index 3b8bc2cc..67bdccb3 100644 --- a/programs/rewards/src/error.rs +++ b/programs/rewards/src/error.rs @@ -22,46 +22,21 @@ pub enum MplxRewardsError { MathOverflow, /// 2 - /// Zero amount - #[error("Zero amount")] - ZeroAmount, - - /// 3 - /// Invalid vault - #[error("Rewards: Invalid vault")] - RewardsInvalidVault, - - /// 4 /// No deposits #[error("Rewards: No deposits")] RewardsNoDeposits, - /// 5 - /// Check for liquidity amount in rebalance - #[error("Rebalancing: liquidity check failed")] - RebalanceLiquidityCheckFailed, - - /// 6 - /// Non existing reward's index - #[error("Rewards: index receiving failed")] - IndexMustExist, - - /// 7 + /// 3 /// Invalid lockup period #[error("Rewards: lockup period invalid")] InvalidLockupPeriod, - /// 8 - /// Invalid CPI caller - #[error("Rewards: only Staking contract is allowed to do CPI calls")] - InvalidCpiCaller, - - /// 9 + /// 4 /// Invalid distribution_ends_at data #[error("Rewards: distribution_ends_at date is lower than current date ")] DistributionInThePast, - /// 10 + /// 5 /// Invalid math conversion between types #[error("Rewards: distribution_ends_at date is lower than current date ")] InvalidPrimitiveTypesConversion, diff --git a/programs/rewards/src/utils.rs b/programs/rewards/src/utils.rs index a7d0dabb..5484db9d 100644 --- a/programs/rewards/src/utils.rs +++ b/programs/rewards/src/utils.rs @@ -197,30 +197,6 @@ impl AccountLoader { Err(ProgramError::MissingRequiredSignature) } - /// Checks if account is initialized and then checks it's owner - pub fn next_optional<'a, 'b, I: Iterator>>( - iter: &mut Enumerate, - owner: &Pubkey, - ) -> Result { - let (idx, acc) = iter.next().ok_or(ProgramError::NotEnoughAccountKeys)?; - if acc.owner.eq(&Pubkey::default()) { - return Ok(acc); - } - - if acc.owner.eq(owner) { - return Ok(acc); - } - - msg!( - "Account #{}:{} owner error. Got {} Expected unitialized or {}", - idx, - acc.key, - acc.owner, - owner - ); - Err(MplxRewardsError::InvalidAccountOwner.into()) - } - /// Load the account without any checks pub fn next_unchecked<'a, 'b, I: Iterator>>( iter: &mut Enumerate, @@ -278,17 +254,6 @@ impl LockupPeriod { LockupPeriod::Flex => Ok(0) } } - - /// Return number of days plain numbers to make them appliable for the self.weighted_stake_diff - pub fn days(&self) -> Result { - match self { - LockupPeriod::None => Err(MplxRewardsError::InvalidLockupPeriod), - LockupPeriod::ThreeMonths => Ok(90), - LockupPeriod::SixMonths => Ok(180), - LockupPeriod::OneYear => Ok(365), - LockupPeriod::Flex => Ok(0), - } - } } /// Get current unix time