Skip to content

Commit

Permalink
Throw error when unstaking fee violates new Solana rent requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
skulltech committed May 20, 2022
1 parent 289ffaf commit 837cc0d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/gem_common/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ pub enum ErrorCode {
#[msg("max rarity points exceeded")]
TooManyRarityPointsStaked, //0x17a2

Reserved51,
#[msg("unstaking fee lamports must be either 0 or greater than 890880")]
InvalidUnstakingFee, //0x17a3

Reserved52,
Reserved53,
Reserved54,
Expand Down
5 changes: 5 additions & 0 deletions programs/gem_farm/src/instructions/init_farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ pub fn handler(
return Err(error!(ErrorCode::InvalidParameter));
}

//ensure unstaking fee does not violate solana v1.9.5 rent requirements
if farm_config.unstaking_fee_lamp > 0 && farm_config.unstaking_fee_lamp < 890880 {
return Err(error!(ErrorCode::InvalidUnstakingFee));
}

//record new farm details
let farm = &mut ctx.accounts.farm;

Expand Down
13 changes: 13 additions & 0 deletions tests/gem-farm/rate-agnostic/gem-farm.misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ describe('misc', () => {
await gf.prepAccounts(45000);
});

it('FAILS to init farm with invalid unstaking fee', async () => {
await expect(
gf.callInitFarm(
{
minStakingPeriodSec: new BN(0),
cooldownPeriodSec: new BN(0),
unstakingFeeLamp: new BN(100),
},
RewardType.Fixed
)
).to.be.rejectedWith('InvalidUnstakingFee');
});

it('inits the farm', async () => {
await gf.callInitFarm(defaultFarmConfig, RewardType.Fixed);

Expand Down

0 comments on commit 837cc0d

Please sign in to comment.