@@ -18,8 +18,9 @@ use spl_token::{
18
18
} ;
19
19
use spl_token_lending:: {
20
20
instruction:: {
21
- borrow_obligation_liquidity, deposit_reserve_liquidity, init_lending_market,
22
- init_obligation, init_reserve, liquidate_obligation, refresh_reserve,
21
+ borrow_obligation_liquidity, deposit_reserve_liquidity,
22
+ deposit_reserve_liquidity_and_obligation_collateral, init_lending_market, init_obligation,
23
+ init_reserve, liquidate_obligation, refresh_reserve,
23
24
} ,
24
25
math:: { Decimal , Rate , TryAdd , TryMul } ,
25
26
pyth,
@@ -206,6 +207,7 @@ pub fn add_obligation(
206
207
207
208
TestObligation {
208
209
pubkey : obligation_pubkey,
210
+ keypair : obligation_keypair,
209
211
lending_market : lending_market. pubkey ,
210
212
owner : user_accounts_owner. pubkey ( ) ,
211
213
deposits : test_deposits,
@@ -588,6 +590,62 @@ impl TestLendingMarket {
588
590
assert_matches ! ( banks_client. process_transaction( transaction) . await , Ok ( ( ) ) ) ;
589
591
}
590
592
593
+ pub async fn deposit_obligation_and_collateral (
594
+ & self ,
595
+ banks_client : & mut BanksClient ,
596
+ user_accounts_owner : & Keypair ,
597
+ payer : & Keypair ,
598
+ reserve : & TestReserve ,
599
+ obligation : & TestObligation ,
600
+ obligation_keypair : & Keypair ,
601
+ liquidity_amount : u64 ,
602
+ ) {
603
+ let user_transfer_authority = Keypair :: new ( ) ;
604
+ let mut transaction = Transaction :: new_with_payer (
605
+ & [
606
+ approve (
607
+ & spl_token:: id ( ) ,
608
+ & reserve. user_liquidity_pubkey ,
609
+ & user_transfer_authority. pubkey ( ) ,
610
+ & user_accounts_owner. pubkey ( ) ,
611
+ & [ ] ,
612
+ liquidity_amount,
613
+ )
614
+ . unwrap ( ) ,
615
+ deposit_reserve_liquidity_and_obligation_collateral (
616
+ spl_token_lending:: id ( ) ,
617
+ liquidity_amount,
618
+ reserve. user_liquidity_pubkey ,
619
+ reserve. user_collateral_pubkey ,
620
+ reserve. pubkey ,
621
+ reserve. liquidity_supply_pubkey ,
622
+ reserve. collateral_mint_pubkey ,
623
+ reserve. pubkey ,
624
+ reserve. collateral_supply_pubkey ,
625
+ obligation. pubkey ,
626
+ obligation. owner ,
627
+ reserve. liquidity_pyth_oracle_pubkey ,
628
+ reserve. liquidity_switchboard_oracle_pubkey ,
629
+ user_transfer_authority. pubkey ( ) ,
630
+ ) ,
631
+ ] ,
632
+ Some ( & payer. pubkey ( ) ) ,
633
+ ) ;
634
+
635
+ let recent_blockhash = banks_client. get_recent_blockhash ( ) . await . unwrap ( ) ;
636
+ transaction. sign (
637
+ & [
638
+ payer,
639
+ user_accounts_owner,
640
+ & user_transfer_authority,
641
+ & obligation_keypair,
642
+ ] ,
643
+ recent_blockhash,
644
+ ) ;
645
+
646
+ assert_matches ! ( banks_client. process_transaction( transaction) . await , Ok ( ( ) ) ) ;
647
+ }
648
+
591
649
pub async fn liquidate (
592
650
& self ,
593
651
banks_client : & mut BanksClient ,
@@ -915,6 +973,7 @@ impl TestReserve {
915
973
#[ derive( Debug ) ]
916
974
pub struct TestObligation {
917
975
pub pubkey : Pubkey ,
976
+ pub keypair : Keypair ,
918
977
pub lending_market : Pubkey ,
919
978
pub owner : Pubkey ,
920
979
pub deposits : Vec < TestObligationCollateral > ,
@@ -932,6 +991,7 @@ impl TestObligation {
932
991
let obligation_keypair = Keypair :: new ( ) ;
933
992
let obligation = TestObligation {
934
993
pubkey : obligation_keypair. pubkey ( ) ,
994
+ keypair : obligation_keypair,
935
995
lending_market : lending_market. pubkey ,
936
996
owner : user_accounts_owner. pubkey ( ) ,
937
997
deposits : vec ! [ ] ,
@@ -943,7 +1003,7 @@ impl TestObligation {
943
1003
& [
944
1004
create_account (
945
1005
& payer. pubkey ( ) ,
946
- & obligation_keypair . pubkey ( ) ,
1006
+ & obligation . keypair . pubkey ( ) ,
947
1007
rent. minimum_balance ( Obligation :: LEN ) ,
948
1008
Obligation :: LEN as u64 ,
949
1009
& spl_token_lending:: id ( ) ,
@@ -960,7 +1020,7 @@ impl TestObligation {
960
1020
961
1021
let recent_blockhash = banks_client. get_recent_blockhash ( ) . await . unwrap ( ) ;
962
1022
transaction. sign (
963
- & vec ! [ payer, & obligation_keypair , user_accounts_owner] ,
1023
+ & vec ! [ payer, & obligation . keypair , user_accounts_owner] ,
964
1024
recent_blockhash,
965
1025
) ;
966
1026
0 commit comments