This repository was archived by the owner on Mar 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +41
-2
lines changed Expand file tree Collapse file tree 4 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,11 @@ pub enum StakePoolError {
144
144
/// Instruction exceeds desired slippage limit
145
145
#[ error( "Instruction exceeds desired slippage limit" ) ]
146
146
ExceededSlippage ,
147
+
148
+ // 40.
149
+ /// Provided mint does not have 9 decimals to match SOL
150
+ #[ error( "IncorrectMintDecimals" ) ]
151
+ IncorrectMintDecimals ,
147
152
}
148
153
impl From < StakePoolError > for ProgramError {
149
154
fn from ( e : StakePoolError ) -> Self {
Original file line number Diff line number Diff line change 39
39
spl_token_2022:: {
40
40
check_spl_token_program_account,
41
41
extension:: { BaseStateWithExtensions , StateWithExtensions } ,
42
+ native_mint,
42
43
state:: Mint ,
43
44
} ,
44
45
std:: num:: NonZeroU32 ,
@@ -828,6 +829,10 @@ impl Processor {
828
829
return Err ( StakePoolError :: NonZeroPoolTokenSupply . into ( ) ) ;
829
830
}
830
831
832
+ if pool_mint. base . decimals != native_mint:: DECIMALS {
833
+ return Err ( StakePoolError :: IncorrectMintDecimals . into ( ) ) ;
834
+ }
835
+
831
836
if !pool_mint
832
837
. base
833
838
. mint_authority
@@ -4006,6 +4011,7 @@ impl PrintProgramError for StakePoolError {
4006
4011
StakePoolError :: UnsupportedMintExtension => msg ! ( "Error: mint has an unsupported extension" ) ,
4007
4012
StakePoolError :: UnsupportedFeeAccountExtension => msg ! ( "Error: fee account has an unsupported extension" ) ,
4008
4013
StakePoolError :: ExceededSlippage => msg ! ( "Error: instruction exceeds desired slippage limit" ) ,
4014
+ StakePoolError :: IncorrectMintDecimals => msg ! ( "Error: Provided mint does not have 9 decimals to match SOL" ) ,
4009
4015
}
4010
4016
}
4011
4017
}
Original file line number Diff line number Diff line change 36
36
} ,
37
37
spl_token_2022:: {
38
38
extension:: { ExtensionType , StateWithExtensionsOwned } ,
39
+ native_mint,
39
40
state:: { Account , Mint } ,
40
41
} ,
41
42
std:: { convert:: TryInto , num:: NonZeroU32 } ,
@@ -2013,7 +2014,7 @@ impl Default for StakePoolAccounts {
2013
2014
token_program_id : spl_token:: id ( ) ,
2014
2015
pool_mint,
2015
2016
pool_fee_account,
2016
- pool_decimals : 0 ,
2017
+ pool_decimals : native_mint :: DECIMALS ,
2017
2018
manager,
2018
2019
staker,
2019
2020
withdraw_authority,
Original file line number Diff line number Diff line change @@ -448,7 +448,7 @@ async fn fail_with_freeze_authority() {
448
448
& wrong_mint. pubkey ( ) ,
449
449
& stake_pool_accounts. withdraw_authority ,
450
450
Some ( & stake_pool_accounts. withdraw_authority ) ,
451
- 0 ,
451
+ stake_pool_accounts . pool_decimals ,
452
452
)
453
453
. unwrap ( ) ,
454
454
] ,
@@ -1603,3 +1603,30 @@ async fn success_with_extra_reserve_lamports() {
1603
1603
. await ;
1604
1604
assert_eq ! ( init_pool_tokens, init_lamports) ;
1605
1605
}
1606
+
1607
+ #[ tokio:: test]
1608
+ async fn fail_with_incorrect_mint_decimals ( ) {
1609
+ let ( mut banks_client, payer, recent_blockhash) = program_test ( ) . start ( ) . await ;
1610
+ let stake_pool_accounts = StakePoolAccounts {
1611
+ pool_decimals : 8 ,
1612
+ ..Default :: default ( )
1613
+ } ;
1614
+ let error = stake_pool_accounts
1615
+ . initialize_stake_pool (
1616
+ & mut banks_client,
1617
+ & payer,
1618
+ & recent_blockhash,
1619
+ MINIMUM_RESERVE_LAMPORTS ,
1620
+ )
1621
+ . await
1622
+ . unwrap_err ( )
1623
+ . unwrap ( ) ;
1624
+
1625
+ assert_eq ! (
1626
+ error,
1627
+ TransactionError :: InstructionError (
1628
+ 2 ,
1629
+ InstructionError :: Custom ( error:: StakePoolError :: IncorrectMintDecimals as u32 ) ,
1630
+ )
1631
+ ) ;
1632
+ }
You can’t perform that action at this time.
0 commit comments