Skip to content

Commit d9968a6

Browse files
committed
Making the BPF tests pass
1 parent c6a2efd commit d9968a6

File tree

8 files changed

+59
-49
lines changed

8 files changed

+59
-49
lines changed

token-lending/cli/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,6 @@ fn main() {
781781
.required(true)
782782
.help("Reserve address"),
783783
)
784-
785784
)
786785
.subcommand(
787786
SubCommand::with_name("update-reserve")

token-lending/program/src/processor/liquidity_mining.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//! implementation of the same feature.
88
//!
99
//! There are three admin-only ixs:
10-
//! - [add_pool_reward]
11-
//! - [cancel_pool_reward]
12-
//! - [close_pool_reward]
10+
//! - [add_pool_reward] (TODO: add bpf tests)
11+
//! - [cancel_pool_reward] (TODO: add bpf tests)
12+
//! - [close_pool_reward] (TODO: add bpf tests)
1313
//!
1414
//! [suilend-lm]: https://github.com/solendprotocol/suilend/blob/dc53150416f352053ac3acbb320ee143409c4a5d/contracts/suilend/sources/liquidity_mining.move#L2
1515

token-lending/program/tests/helpers/solend_program_test.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: code budgets were increased. export them to consts and optimize code to again lower them
2+
13
use bytemuck::checked::from_bytes;
24
use oracles::switchboard_on_demand_mainnet;
35

@@ -671,7 +673,7 @@ impl SolendProgramTest {
671673
let res = self
672674
.process_transaction(
673675
&[
674-
ComputeBudgetInstruction::set_compute_unit_limit(80_000),
676+
ComputeBudgetInstruction::set_compute_unit_limit(100_011),
675677
init_reserve(
676678
solend_program::id(),
677679
liquidity_amount,
@@ -857,7 +859,7 @@ impl Info<LendingMarket> {
857859
liquidity_amount: u64,
858860
) -> Result<(), BanksClientError> {
859861
let instructions = [
860-
ComputeBudgetInstruction::set_compute_unit_limit(50_000),
862+
ComputeBudgetInstruction::set_compute_unit_limit(100_012),
861863
deposit_reserve_liquidity(
862864
solend_program::id(),
863865
liquidity_amount,
@@ -885,7 +887,7 @@ impl Info<LendingMarket> {
885887
liquidity_amount: u64,
886888
) -> Result<(), BanksClientError> {
887889
let instructions = [
888-
ComputeBudgetInstruction::set_compute_unit_limit(50_000),
890+
ComputeBudgetInstruction::set_compute_unit_limit(100_013),
889891
donate_to_reserve(
890892
solend_program::id(),
891893
liquidity_amount,
@@ -919,7 +921,7 @@ impl Info<LendingMarket> {
919921
let oracle = oracle.unwrap_or(&default_oracle);
920922

921923
let instructions = [
922-
ComputeBudgetInstruction::set_compute_unit_limit(30_000),
924+
ComputeBudgetInstruction::set_compute_unit_limit(30_014),
923925
update_reserve_config(
924926
solend_program::id(),
925927
config,
@@ -946,7 +948,7 @@ impl Info<LendingMarket> {
946948
liquidity_amount: u64,
947949
) -> Result<(), BanksClientError> {
948950
let instructions = [
949-
ComputeBudgetInstruction::set_compute_unit_limit(70_000),
951+
ComputeBudgetInstruction::set_compute_unit_limit(150_015),
950952
deposit_reserve_liquidity_and_obligation_collateral(
951953
solend_program::id(),
952954
liquidity_amount,
@@ -979,7 +981,7 @@ impl Info<LendingMarket> {
979981
collateral_amount: u64,
980982
) -> Result<(), BanksClientError> {
981983
let instructions = [
982-
ComputeBudgetInstruction::set_compute_unit_limit(58_000),
984+
ComputeBudgetInstruction::set_compute_unit_limit(150_016),
983985
refresh_reserve(
984986
solend_program::id(),
985987
reserve.pubkey,
@@ -1013,7 +1015,7 @@ impl Info<LendingMarket> {
10131015
user: &User,
10141016
) -> Result<Info<Obligation>, BanksClientError> {
10151017
let instructions = [
1016-
ComputeBudgetInstruction::set_compute_unit_limit(10_000),
1018+
ComputeBudgetInstruction::set_compute_unit_limit(10_001),
10171019
system_instruction::create_account(
10181020
&test.context.payer.pubkey(),
10191021
&obligation_keypair.pubkey(),
@@ -1047,7 +1049,7 @@ impl Info<LendingMarket> {
10471049
collateral_amount: u64,
10481050
) -> Result<(), BanksClientError> {
10491051
let instructions = [
1050-
ComputeBudgetInstruction::set_compute_unit_limit(38_000),
1052+
ComputeBudgetInstruction::set_compute_unit_limit(150_002),
10511053
deposit_obligation_collateral(
10521054
solend_program::id(),
10531055
collateral_amount,
@@ -1073,7 +1075,7 @@ impl Info<LendingMarket> {
10731075
) -> Result<(), BanksClientError> {
10741076
test.process_transaction(
10751077
&[
1076-
ComputeBudgetInstruction::set_compute_unit_limit(2_000_000),
1078+
ComputeBudgetInstruction::set_compute_unit_limit(2_000_003),
10771079
refresh_reserve(
10781080
solend_program::id(),
10791081
reserve.pubkey,
@@ -1172,7 +1174,7 @@ impl Info<LendingMarket> {
11721174
Err(e) => return Err(e),
11731175
};
11741176

1175-
let mut instructions = vec![ComputeBudgetInstruction::set_compute_unit_limit(1_000_000)];
1177+
let mut instructions = vec![ComputeBudgetInstruction::set_compute_unit_limit(1_000_004)];
11761178
instructions.push(refresh_reserve_instructions.last().unwrap().clone());
11771179

11781180
test.process_transaction(&instructions, None).await
@@ -1194,7 +1196,7 @@ impl Info<LendingMarket> {
11941196
.await;
11951197
test.process_transaction(&refresh_ixs, None).await.unwrap();
11961198

1197-
let mut instructions = vec![ComputeBudgetInstruction::set_compute_unit_limit(100_000)];
1199+
let mut instructions = vec![ComputeBudgetInstruction::set_compute_unit_limit(140_005)];
11981200
instructions.push(borrow_obligation_liquidity(
11991201
solend_program::id(),
12001202
liquidity_amount,
@@ -1228,7 +1230,7 @@ impl Info<LendingMarket> {
12281230
liquidity_amount: u64,
12291231
) -> Result<(), BanksClientError> {
12301232
let instructions = [
1231-
ComputeBudgetInstruction::set_compute_unit_limit(35_000),
1233+
ComputeBudgetInstruction::set_compute_unit_limit(80_006),
12321234
repay_obligation_liquidity(
12331235
solend_program::id(),
12341236
liquidity_amount,
@@ -1252,7 +1254,7 @@ impl Info<LendingMarket> {
12521254
reserve: &Info<Reserve>,
12531255
) -> Result<(), BanksClientError> {
12541256
let instructions = [
1255-
ComputeBudgetInstruction::set_compute_unit_limit(50_000),
1257+
ComputeBudgetInstruction::set_compute_unit_limit(100_007),
12561258
refresh_reserve(
12571259
solend_program::id(),
12581260
reserve.pubkey,
@@ -1288,7 +1290,7 @@ impl Info<LendingMarket> {
12881290

12891291
test.process_transaction(
12901292
&[
1291-
ComputeBudgetInstruction::set_compute_unit_limit(110_000),
1293+
ComputeBudgetInstruction::set_compute_unit_limit(280_008),
12921294
liquidate_obligation_and_redeem_reserve_collateral(
12931295
solend_program::id(),
12941296
liquidity_amount,
@@ -1365,7 +1367,7 @@ impl Info<LendingMarket> {
13651367

13661368
test.process_transaction(
13671369
&[
1368-
ComputeBudgetInstruction::set_compute_unit_limit(110_000),
1370+
ComputeBudgetInstruction::set_compute_unit_limit(250_009),
13691371
withdraw_obligation_collateral_and_redeem_reserve_collateral(
13701372
solend_program::id(),
13711373
collateral_amount,
@@ -1409,7 +1411,7 @@ impl Info<LendingMarket> {
14091411

14101412
test.process_transaction(
14111413
&[
1412-
ComputeBudgetInstruction::set_compute_unit_limit(100_000),
1414+
ComputeBudgetInstruction::set_compute_unit_limit(120_010),
14131415
withdraw_obligation_collateral(
14141416
solend_program::id(),
14151417
collateral_amount,

token-lending/sdk/src/state/lending_market.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,22 @@ impl Pack for LendingMarket {
179179
8
180180
];
181181

182-
match extract_discriminator_and_version(u8::from_le_bytes(*discriminator_and_version)) {
182+
let mut discriminator_and_version = u8::from_le_bytes(*discriminator_and_version);
183+
match extract_discriminator_and_version(discriminator_and_version) {
183184
Ok((AccountDiscriminator::LendingMarket, ProgramVersion::V2_1_0)) => {
184185
// migrated and all ok
185186
}
186187
Ok((AccountDiscriminator::LendingMarket, ProgramVersion::V2_0_2)) => {
187-
// Not migrated yet, will do during unpacking.
188+
// Not migrated yet.
188189
// There's no other change than discriminator & version.
190+
191+
discriminator_and_version = set_discriminator_and_version(
192+
AccountDiscriminator::LendingMarket,
193+
ProgramVersion::V2_1_0,
194+
);
195+
}
196+
Ok((AccountDiscriminator::Uninitialized, ProgramVersion::Uninitialized)) => {
197+
// uninitialized account
189198
}
190199
Ok((AccountDiscriminator::LendingMarket, _)) => {
191200
msg!("Lending market version does not match lending program version");
@@ -203,10 +212,7 @@ impl Pack for LendingMarket {
203212

204213
let owner_pubkey = Pubkey::new_from_array(*owner);
205214
Ok(Self {
206-
discriminator_and_version: set_discriminator_and_version(
207-
AccountDiscriminator::LendingMarket,
208-
ProgramVersion::V2_1_0,
209-
),
215+
discriminator_and_version,
210216
bump_seed: u8::from_le_bytes(*bump_seed),
211217
owner: owner_pubkey,
212218
quote_currency: *quote_currency,

token-lending/sdk/src/state/liquidity_mining.rs

+3
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ impl Pack for PoolRewardManager {
423423

424424
dst_id.copy_from_slice(&id.0.to_le_bytes());
425425
dst_vault.copy_from_slice(vault.as_ref());
426+
427+
// TBD: these values don't have to be written if the slot is vacant
426428
*dst_start_time_secs = start_time_secs.to_le_bytes();
427429
*dst_duration_secs = duration_secs.to_le_bytes();
428430
*dst_total_rewards = total_rewards.to_le_bytes();
@@ -459,6 +461,7 @@ impl Pack for PoolRewardManager {
459461
raw_pool_reward,
460462
PoolRewardId::LEN,
461463
PUBKEY_BYTES,
464+
// TBD: these values don't have to be referenced if the slot is vacant
462465
8, // start_time_secs
463466
4, // duration_secs
464467
8, // total_rewards

token-lending/sdk/src/state/mod.rs

-12
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ pub mod program_version {
5151
/// Will have an associated account discriminator.
5252
V2_1_0 = 2,
5353
}
54-
55-
/// Version of the program and all new accounts created until inclusive version
56-
/// @v2.0.2
57-
pub const V2_0_2: u8 = 1;
58-
59-
/// Version of the program and all new accounts created from inclusive version
60-
/// @v2.1.0 (liquidity mining)
61-
pub const V2_1_0: u8 = 2;
62-
63-
/// Accounts are created with data zeroed out, so uninitialized state instances
64-
/// will have the version set to 0.
65-
pub const UNINITIALIZED: u8 = 0;
6654
}
6755

6856
pub mod discriminator {

token-lending/sdk/src/state/obligation.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -691,14 +691,23 @@ impl Obligation {
691691
OBLIGATION_COLLATERAL_LEN + (OBLIGATION_LIQUIDITY_LEN * (MAX_OBLIGATION_RESERVES - 1))
692692
];
693693

694-
match extract_discriminator_and_version(u8::from_le_bytes(*discriminator_and_version)) {
694+
let mut discriminator_and_version = u8::from_le_bytes(*discriminator_and_version);
695+
match extract_discriminator_and_version(discriminator_and_version) {
695696
Ok((AccountDiscriminator::Obligation, ProgramVersion::V2_1_0)) => {
696697
// migrated and all ok
697698
}
698699
Ok((AccountDiscriminator::Uninitialized, ProgramVersion::V2_0_2))
699700
if input.len() == OBLIGATION_LEN_V1 =>
700701
{
701702
// not migrated yet, so must have the old size
703+
704+
discriminator_and_version = set_discriminator_and_version(
705+
AccountDiscriminator::Obligation,
706+
ProgramVersion::V2_1_0,
707+
);
708+
}
709+
Ok((AccountDiscriminator::Uninitialized, ProgramVersion::Uninitialized)) => {
710+
// uninitialized account
702711
}
703712
Ok((AccountDiscriminator::Obligation, _)) => {
704713
msg!("Obligation version does not match lending program version");
@@ -774,10 +783,7 @@ impl Obligation {
774783
};
775784

776785
Ok(Self {
777-
discriminator_and_version: set_discriminator_and_version(
778-
AccountDiscriminator::Obligation,
779-
ProgramVersion::V2_1_0,
780-
),
786+
discriminator_and_version,
781787
last_update: LastUpdate {
782788
slot: u64::from_le_bytes(*last_update_slot),
783789
stale: unpack_bool(last_update_stale)?,

token-lending/sdk/src/state/reserve.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1577,14 +1577,23 @@ impl Pack for Reserve {
15771577
49
15781578
];
15791579

1580-
match extract_discriminator_and_version(u8::from_le_bytes(*discriminator_and_version)) {
1580+
let mut discriminator_and_version = u8::from_le_bytes(*discriminator_and_version);
1581+
match extract_discriminator_and_version(discriminator_and_version) {
15811582
Ok((AccountDiscriminator::Reserve, ProgramVersion::V2_1_0)) => {
15821583
// migrated and all ok
15831584
}
15841585
Ok((AccountDiscriminator::Uninitialized, ProgramVersion::V2_0_2)) => {
1585-
// Not migrated yet, will do during unpacking.
1586+
// Not migrated yet.
15861587
// We checked earlier that the input buffer was already resized.
15871588
debug_assert_eq!(input.len(), RESERVE_LEN_V2_1_0);
1589+
1590+
discriminator_and_version = set_discriminator_and_version(
1591+
AccountDiscriminator::Reserve,
1592+
ProgramVersion::V2_1_0,
1593+
);
1594+
}
1595+
Ok((AccountDiscriminator::Uninitialized, ProgramVersion::Uninitialized)) => {
1596+
// uninitialized account
15881597
}
15891598
Ok((AccountDiscriminator::Reserve, _)) => {
15901599
msg!("Reserve version does not match lending program version");
@@ -1727,10 +1736,7 @@ impl Pack for Reserve {
17271736
PoolRewardManager::unpack_to_box(input_for_deposits_pool_reward_manager)?;
17281737

17291738
Ok(Self {
1730-
discriminator_and_version: set_discriminator_and_version(
1731-
AccountDiscriminator::Reserve,
1732-
ProgramVersion::V2_1_0,
1733-
),
1739+
discriminator_and_version,
17341740
last_update,
17351741
lending_market: Pubkey::new_from_array(*lending_market),
17361742
liquidity,

0 commit comments

Comments
 (0)