From 88a9440980dc9af292317ab56d24975719c9a09d Mon Sep 17 00:00:00 2001 From: mootz12 Date: Tue, 2 Jan 2024 15:52:15 -0500 Subject: [PATCH] pool: chore: use an enum for RequestType --- pool/src/auctions/auction.rs | 8 +- pool/src/lib.rs | 2 +- pool/src/pool/actions.rs | 105 +++++++++++++++------- pool/src/pool/mod.rs | 2 +- pool/src/pool/submit.rs | 16 ++-- test-suites/fuzz/lib.rs | 8 +- test-suites/src/setup.rs | 14 +-- test-suites/tests/test_liquidation.rs | 74 +++++++-------- test-suites/tests/test_overflow_flag.rs | 10 +-- test-suites/tests/test_pool.rs | 14 +-- test-suites/tests/test_wasm_happy_path.rs | 26 +++--- 11 files changed, 158 insertions(+), 121 deletions(-) diff --git a/pool/src/auctions/auction.rs b/pool/src/auctions/auction.rs index 8c1e3e6e..2e4170ae 100644 --- a/pool/src/auctions/auction.rs +++ b/pool/src/auctions/auction.rs @@ -25,12 +25,12 @@ pub enum AuctionType { } impl AuctionType { - pub fn from_u32(value: u32) -> Self { + pub fn from_u32(e: &Env, value: u32) -> Self { match value { 0 => AuctionType::UserLiquidation, 1 => AuctionType::BadDebtAuction, 2 => AuctionType::InterestAuction, - _ => panic!("internal error"), + _ => panic_with_error!(e, PoolError::BadRequest), } } } @@ -54,7 +54,7 @@ pub struct AuctionData { /// If the auction is unable to be created pub fn create(e: &Env, auction_type: u32) -> AuctionData { let backstop = storage::get_backstop(e); - let auction_data = match AuctionType::from_u32(auction_type) { + let auction_data = match AuctionType::from_u32(e, auction_type) { AuctionType::UserLiquidation => { panic_with_error!(e, PoolError::BadRequest); } @@ -131,7 +131,7 @@ pub fn fill( ) { let auction_data = storage::get_auction(e, &auction_type, user); let (to_fill_auction, remaining_auction) = scale_auction(e, &auction_data, percent_filled); - match AuctionType::from_u32(auction_type) { + match AuctionType::from_u32(e, auction_type) { AuctionType::UserLiquidation => { fill_user_liq_auction(e, pool, &to_fill_auction, user, filler_state) } diff --git a/pool/src/lib.rs b/pool/src/lib.rs index 8501da91..03b857d3 100644 --- a/pool/src/lib.rs +++ b/pool/src/lib.rs @@ -20,7 +20,7 @@ pub use auctions::{AuctionData, AuctionType}; pub use contract::*; pub use emissions::ReserveEmissionMetadata; pub use errors::PoolError; -pub use pool::{Positions, Request}; +pub use pool::{Positions, Request, RequestType}; pub use storage::{ AuctionKey, PoolConfig, PoolDataKey, PoolEmissionConfig, ReserveConfig, ReserveData, ReserveEmissionsConfig, ReserveEmissionsData, UserEmissionData, UserReserveKey, diff --git a/pool/src/pool/actions.rs b/pool/src/pool/actions.rs index 17cc192a..23e23acf 100644 --- a/pool/src/pool/actions.rs +++ b/pool/src/pool/actions.rs @@ -6,7 +6,7 @@ use crate::{auctions, errors::PoolError, validator::require_nonnegative}; use super::pool::Pool; use super::User; -/// An request a user makes against the pool +/// A request a user makes against the pool #[derive(Clone)] #[contracttype] pub struct Request { @@ -15,6 +15,44 @@ pub struct Request { pub amount: i128, } +/// The type of request to be made against the pool +#[derive(Clone, PartialEq)] +#[repr(u32)] +pub enum RequestType { + Supply = 0, + Withdraw = 1, + SupplyCollateral = 2, + WithdrawCollateral = 3, + Borrow = 4, + Repay = 5, + FillUserLiquidationAuction = 6, + FillBadDebtAuction = 7, + FillInterestAuction = 8, + DeleteLiquidationAuction = 9, +} + +impl RequestType { + /// Convert a u32 to a RequestType + /// + /// ### Panics + /// If the value is not a valid RequestType + pub fn from_u32(e: &Env, value: u32) -> Self { + match value { + 0 => RequestType::Supply, + 1 => RequestType::Withdraw, + 2 => RequestType::SupplyCollateral, + 3 => RequestType::WithdrawCollateral, + 4 => RequestType::Borrow, + 5 => RequestType::Repay, + 6 => RequestType::FillUserLiquidationAuction, + 7 => RequestType::FillBadDebtAuction, + 8 => RequestType::FillInterestAuction, + 9 => RequestType::DeleteLiquidationAuction, + _ => panic_with_error!(e, PoolError::BadRequest), + } + } +} + /// Transfer actions to be taken by the sender and pool pub struct Actions { pub spender_transfer: Map, @@ -77,8 +115,8 @@ pub fn build_actions_from_request( // verify the request is allowed require_nonnegative(e, &request.amount); pool.require_action_allowed(e, request.request_type); - match request.request_type { - 0 => { + match RequestType::from_u32(e, request.request_type) { + RequestType::Supply => { // supply let mut reserve = pool.load_reserve(e, &request.address); let b_tokens_minted = reserve.to_b_token_down(request.amount); @@ -94,7 +132,7 @@ pub fn build_actions_from_request( (request.amount, b_tokens_minted), ); } - 1 => { + RequestType::Withdraw => { // withdraw let mut reserve = pool.load_reserve(e, &request.address); let cur_b_tokens = from_state.get_supply(reserve.index); @@ -116,7 +154,7 @@ pub fn build_actions_from_request( (tokens_out, to_burn), ); } - 2 => { + RequestType::SupplyCollateral => { // supply collateral let mut reserve = pool.load_reserve(e, &request.address); let b_tokens_minted = reserve.to_b_token_down(request.amount); @@ -132,7 +170,7 @@ pub fn build_actions_from_request( (request.amount, b_tokens_minted), ); } - 3 => { + RequestType::WithdrawCollateral => { // withdraw collateral let mut reserve = pool.load_reserve(e, &request.address); let cur_b_tokens = from_state.get_collateral(reserve.index); @@ -155,7 +193,7 @@ pub fn build_actions_from_request( (tokens_out, to_burn), ); } - 4 => { + RequestType::Borrow => { // borrow let mut reserve = pool.load_reserve(e, &request.address); let d_tokens_minted = reserve.to_d_token_up(request.amount); @@ -173,7 +211,7 @@ pub fn build_actions_from_request( (request.amount, d_tokens_minted), ); } - 5 => { + RequestType::Repay => { // repay let mut reserve = pool.load_reserve(e, &request.address); let cur_d_tokens = from_state.get_liabilities(reserve.index); @@ -206,7 +244,7 @@ pub fn build_actions_from_request( } pool.cache_reserve(reserve, true); } - 6 => { + RequestType::FillUserLiquidationAuction => { // fill user liquidation auction auctions::fill( e, @@ -227,7 +265,7 @@ pub fn build_actions_from_request( (from.clone(), request.amount), ); } - 7 => { + RequestType::FillBadDebtAuction => { // fill bad debt auction // Note: will fail if input address is not the backstop since there cannot be a bad debt auction for a different address in storage auctions::fill( @@ -249,7 +287,7 @@ pub fn build_actions_from_request( (from.clone(), request.amount), ); } - 8 => { + RequestType::FillInterestAuction => { // fill interest auction // Note: will fail if input address is not the backstop since there cannot be an interest auction for a different address in storage auctions::fill( @@ -269,7 +307,7 @@ pub fn build_actions_from_request( (from.clone(), request.amount), ); } - 9 => { + RequestType::DeleteLiquidationAuction => { // delete liquidation auction // Note: request object is ignored besides type auctions::delete_liquidation(e, &from); @@ -279,7 +317,6 @@ pub fn build_actions_from_request( (), ); } - _ => panic_with_error!(e, PoolError::BadRequest), } } @@ -347,7 +384,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 0, + request_type: RequestType::Supply as u32, address: underlying.clone(), amount: 10_1234567, }, @@ -423,7 +460,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 1, + request_type: RequestType::Withdraw as u32, address: underlying.clone(), amount: 10_1234567, }, @@ -496,7 +533,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 1, + request_type: RequestType::Withdraw as u32, address: underlying.clone(), amount: 21_0000000, }, @@ -561,7 +598,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: underlying.clone(), amount: 10_1234567, }, @@ -639,7 +676,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 3, + request_type: RequestType::WithdrawCollateral as u32, address: underlying.clone(), amount: 10_1234567, }, @@ -712,7 +749,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 3, + request_type: RequestType::WithdrawCollateral as u32, address: underlying.clone(), amount: 21_0000000, }, @@ -776,7 +813,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: underlying.clone(), amount: 10_1234567, }, @@ -847,7 +884,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: underlying.clone(), amount: 10_1234567, }, @@ -921,7 +958,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: underlying.clone(), amount: 21_0000000, }, @@ -997,32 +1034,32 @@ mod tests { let requests = vec![ &e, Request { - request_type: 0, + request_type: RequestType::Supply as u32, address: underlying.clone(), amount: 10_0000000, }, Request { - request_type: 1, + request_type: RequestType::Withdraw as u32, address: underlying.clone(), amount: 5_0000000, }, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: underlying.clone(), amount: 10_0000000, }, Request { - request_type: 3, + request_type: RequestType::WithdrawCollateral as u32, address: underlying.clone(), amount: 5_0000000, }, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: underlying.clone(), amount: 20_0000000, }, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: underlying.clone(), amount: 21_0000000, }, @@ -1162,7 +1199,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 6, + request_type: RequestType::FillUserLiquidationAuction as u32, address: samwise.clone(), amount: 50, }, @@ -1294,7 +1331,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 7, + request_type: RequestType::FillBadDebtAuction as u32, address: backstop_address.clone(), amount: 100, }, @@ -1418,7 +1455,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 8, + request_type: RequestType::FillInterestAuction as u32, address: backstop_address.clone(), amount: 100, }, @@ -1501,7 +1538,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 9, + request_type: RequestType::DeleteLiquidationAuction as u32, address: Address::generate(&e), amount: 0, }, @@ -1570,7 +1607,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 3, + request_type: RequestType::WithdrawCollateral as u32, address: underlying_1.clone(), amount: 20, }, @@ -1627,7 +1664,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: underlying.clone(), amount: 1_0000000, }, diff --git a/pool/src/pool/mod.rs b/pool/src/pool/mod.rs index 01c7b3dc..b07cbe64 100644 --- a/pool/src/pool/mod.rs +++ b/pool/src/pool/mod.rs @@ -1,5 +1,5 @@ mod actions; -pub use actions::Request; +pub use actions::{Request, RequestType}; mod bad_debt; pub use bad_debt::transfer_bad_debt_to_backstop; diff --git a/pool/src/pool/submit.rs b/pool/src/pool/submit.rs index f6dc075d..0ef7c219 100644 --- a/pool/src/pool/submit.rs +++ b/pool/src/pool/submit.rs @@ -65,7 +65,7 @@ pub fn execute_submit( mod tests { use crate::{ storage::{self, PoolConfig}, - testutils, + testutils, RequestType, }; use super::*; @@ -138,12 +138,12 @@ mod tests { let requests = vec![ &e, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: underlying_0, amount: 15_0000000, }, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: underlying_1, amount: 1_5000000, }, @@ -228,12 +228,12 @@ mod tests { let requests = vec![ &e, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: underlying_0, amount: 15_0000000, }, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: underlying_1, amount: 1_7500000, }, @@ -293,7 +293,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: underlying_0, amount: 15_0000000, }, @@ -353,7 +353,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: underlying_0, amount: 15_0000000, }, @@ -413,7 +413,7 @@ mod tests { let requests = vec![ &e, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: underlying_0, amount: 15_0000000, }, diff --git a/test-suites/fuzz/lib.rs b/test-suites/fuzz/lib.rs index 18de93d0..9cfdd2aa 100644 --- a/test-suites/fuzz/lib.rs +++ b/test-suites/fuzz/lib.rs @@ -137,7 +137,7 @@ impl Supply { &vec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: token, amount: self.amount, }, @@ -164,7 +164,7 @@ impl Withdraw { &vec![ &fixture.env, Request { - request_type: 3, + request_type: RequestType::WithdrawCollateral as u32, address: token, amount: self.amount, }, @@ -191,7 +191,7 @@ impl Borrow { &vec![ &fixture.env, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: token, amount: self.amount, }, @@ -218,7 +218,7 @@ impl Repay { &vec![ &fixture.env, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: token, amount: self.amount, }, diff --git a/test-suites/src/setup.rs b/test-suites/src/setup.rs index b26ca669..edf3b732 100644 --- a/test-suites/src/setup.rs +++ b/test-suites/src/setup.rs @@ -1,4 +1,4 @@ -use pool::{Request, ReserveEmissionMetadata}; +use pool::{Request, RequestType, ReserveEmissionMetadata}; use soroban_sdk::{testutils::Address as _, vec as svec, Address, Symbol, Vec as SVec}; use crate::{ @@ -109,12 +109,12 @@ pub fn create_fixture_with_data<'a>(wasm: bool) -> TestFixture<'a> { let requests: SVec = svec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 10_000 * 10i128.pow(6), }, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 8_000 * 10i128.pow(6), }, @@ -125,12 +125,12 @@ pub fn create_fixture_with_data<'a>(wasm: bool) -> TestFixture<'a> { let requests: SVec = svec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: fixture.tokens[TokenIndex::WETH].address.clone(), amount: 10 * 10i128.pow(9), }, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::WETH].address.clone(), amount: 5 * 10i128.pow(9), }, @@ -141,12 +141,12 @@ pub fn create_fixture_with_data<'a>(wasm: bool) -> TestFixture<'a> { let requests: SVec = svec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: 100_000 * SCALAR_7, }, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: 65_000 * SCALAR_7, }, diff --git a/test-suites/tests/test_liquidation.rs b/test-suites/tests/test_liquidation.rs index 6a7ce85b..f353bca6 100644 --- a/test-suites/tests/test_liquidation.rs +++ b/test-suites/tests/test_liquidation.rs @@ -1,6 +1,6 @@ #![cfg(test)] use cast::i128; -use pool::{PoolDataKey, Positions, Request, ReserveConfig, ReserveData}; +use pool::{PoolDataKey, Positions, Request, RequestType, ReserveConfig, ReserveData}; use soroban_fixed_point_math::FixedPoint; use soroban_sdk::{ testutils::{Address as AddressTestTrait, Events}, @@ -22,32 +22,32 @@ fn test_liquidations() { let requests: Vec = vec![ &fixture.env, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 1, }, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 1, }, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: 1, }, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: 1, }, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::WETH].address.clone(), amount: 1, }, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: fixture.tokens[TokenIndex::WETH].address.clone(), amount: 1, }, @@ -95,7 +95,7 @@ fn test_liquidations() { let frodo_requests: Vec = vec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 30_000 * 10i128.pow(6), }, @@ -108,23 +108,23 @@ fn test_liquidations() { let sam_requests: Vec = vec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: 160_000 * SCALAR_7, }, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: fixture.tokens[TokenIndex::WETH].address.clone(), amount: 17 * 10i128.pow(9), }, // Sam's max borrow is 39_200 STABLE Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 28_000 * 10i128.pow(6), }, // reduces Sam's max borrow to 14_526.31579 STABLE Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: 65_000 * SCALAR_7, }, @@ -252,27 +252,27 @@ fn test_liquidations() { let fill_requests = vec![ &fixture.env, Request { - request_type: 6, + request_type: RequestType::FillUserLiquidationAuction as u32, address: samwise.clone(), amount: 25, }, Request { - request_type: 6, + request_type: RequestType::FillUserLiquidationAuction as u32, address: samwise.clone(), amount: 100, }, Request { - request_type: 8, + request_type: RequestType::FillInterestAuction as u32, address: fixture.backstop.address.clone(), //address shouldn't matter amount: 99, }, Request { - request_type: 8, + request_type: RequestType::FillInterestAuction as u32, address: fixture.backstop.address.clone(), //address shouldn't matter amount: 100, }, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: usdc_bid_amount, }, @@ -463,19 +463,19 @@ fn test_liquidations() { let fill_requests = vec![ &fixture.env, Request { - request_type: 6, + request_type: RequestType::FillUserLiquidationAuction as u32, address: samwise.clone(), amount: 100, }, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: usdc_bid_amount .fixed_div_floor(2_0000000, SCALAR_7) .unwrap(), }, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: xlm_bid_amount.fixed_div_floor(2_0000000, SCALAR_7).unwrap(), }, @@ -595,7 +595,7 @@ fn test_liquidations() { let bad_debt_fill_request = vec![ &fixture.env, Request { - request_type: 7, + request_type: RequestType::FillBadDebtAuction as u32, address: fixture.backstop.address.clone(), amount: 20, }, @@ -704,7 +704,7 @@ fn test_liquidations() { let bad_debt_fill_request = vec![ &fixture.env, Request { - request_type: 7, + request_type: RequestType::FillBadDebtAuction as u32, address: fixture.backstop.address.clone(), amount: 100, }, @@ -784,13 +784,13 @@ fn test_liquidations() { let sam_requests: Vec = vec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: fixture.tokens[TokenIndex::WETH].address.clone(), amount: 1 * 10i128.pow(9), }, // Sam's max borrow is 39_200 STABLE Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 100 * 10i128.pow(6), }, // reduces Sam's max borrow to 14_526.31579 STABLE @@ -849,7 +849,7 @@ fn test_liquidations() { let bad_debt_fill_request = vec![ &fixture.env, Request { - request_type: 6, + request_type: RequestType::FillUserLiquidationAuction as u32, address: samwise.clone(), amount: 100, }, @@ -895,7 +895,7 @@ fn test_liquidations() { let bump_usdc = vec![ &fixture.env, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 1, }, @@ -928,7 +928,7 @@ fn test_liquidations() { let bad_debt_fill_request = vec![ &fixture.env, Request { - request_type: 7, + request_type: RequestType::FillBadDebtAuction as u32, address: fixture.backstop.address.clone(), amount: 100, }, @@ -998,12 +998,12 @@ fn test_user_restore_position_and_delete_liquidation() { let setup_request: Vec = vec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 1000 * 10i128.pow(6), }, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: 6075 * SCALAR_7, }, @@ -1030,7 +1030,7 @@ fn test_user_restore_position_and_delete_liquidation() { let delete_only_request: Vec = vec![ &fixture.env, Request { - request_type: 9, + request_type: RequestType::DeleteLiquidationAuction as u32, address: Address::generate(&fixture.env), amount: i128::MAX, }, @@ -1045,12 +1045,12 @@ fn test_user_restore_position_and_delete_liquidation() { let short_supply_delete_request: Vec = vec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 79 * 10i128.pow(6), // need $80 more collateral }, Request { - request_type: 9, + request_type: RequestType::DeleteLiquidationAuction as u32, address: Address::generate(&fixture.env), amount: i128::MAX, }, @@ -1067,12 +1067,12 @@ fn test_user_restore_position_and_delete_liquidation() { let short_repay_delete_request: Vec = vec![ &fixture.env, Request { - request_type: 9, + request_type: RequestType::DeleteLiquidationAuction as u32, address: Address::generate(&fixture.env), amount: i128::MAX, }, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: 449 * SCALAR_7, // need to repay 450 XLM }, @@ -1090,17 +1090,17 @@ fn test_user_restore_position_and_delete_liquidation() { let delete_request: Vec = vec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 41 * 10i128.pow(6), }, Request { - request_type: 9, + request_type: RequestType::DeleteLiquidationAuction as u32, address: Address::generate(&fixture.env), amount: i128::MAX, }, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: 226 * SCALAR_7, }, diff --git a/test-suites/tests/test_overflow_flag.rs b/test-suites/tests/test_overflow_flag.rs index e8be5865..5c991b4d 100644 --- a/test-suites/tests/test_overflow_flag.rs +++ b/test-suites/tests/test_overflow_flag.rs @@ -1,5 +1,5 @@ #![cfg(test)] -use pool::Request; +use pool::{Request, RequestType}; use soroban_sdk::{testutils::Address as AddressTestTrait, vec, Address, Vec}; use test_suites::{ create_fixture_with_data, @@ -47,12 +47,12 @@ fn test_auction_underflow_panics() { let sam_requests: Vec = vec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: 6_000 * SCALAR_7, }, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: 200 * 10i128.pow(6), }, @@ -84,12 +84,12 @@ fn test_auction_underflow_panics() { let fill_requests = vec![ &fixture.env, Request { - request_type: 6, + request_type: RequestType::FillUserLiquidationAuction as u32, address: samwise.clone(), amount: 1, }, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: fixture.tokens[TokenIndex::STABLE].address.clone(), amount: usdc_bid_amount, }, diff --git a/test-suites/tests/test_pool.rs b/test-suites/tests/test_pool.rs index 9bd8866e..b18397a6 100644 --- a/test-suites/tests/test_pool.rs +++ b/test-suites/tests/test_pool.rs @@ -1,6 +1,6 @@ #![cfg(test)] -use pool::{Request, ReserveEmissionMetadata}; +use pool::{Request, RequestType, ReserveEmissionMetadata}; use soroban_fixed_point_math::FixedPoint; use soroban_sdk::{ testutils::{Address as _, AuthorizedFunction, AuthorizedInvocation, Events}, @@ -45,7 +45,7 @@ fn test_pool_user() { let requests = vec![ &fixture.env, Request { - request_type: 0, + request_type: RequestType::Supply as u32, address: weth.address.clone(), amount, }, @@ -131,7 +131,7 @@ fn test_pool_user() { let requests = vec![ &fixture.env, Request { - request_type: 1, + request_type: RequestType::Withdraw as u32, address: weth.address.clone(), amount, }, @@ -201,7 +201,7 @@ fn test_pool_user() { let requests = vec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: xlm.address.clone(), amount, }, @@ -284,7 +284,7 @@ fn test_pool_user() { let requests = vec![ &fixture.env, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: weth.address.clone(), amount, }, @@ -367,12 +367,12 @@ fn test_pool_user() { let requests = vec![ &fixture.env, Request { - request_type: 3, + request_type: RequestType::WithdrawCollateral as u32, address: xlm.address.clone(), amount: amount_withdrawal, }, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: weth.address.clone(), amount: amount_repay, }, diff --git a/test-suites/tests/test_wasm_happy_path.rs b/test-suites/tests/test_wasm_happy_path.rs index 8897951e..3686f6ea 100644 --- a/test-suites/tests/test_wasm_happy_path.rs +++ b/test-suites/tests/test_wasm_happy_path.rs @@ -1,6 +1,6 @@ #![cfg(test)] -use pool::Request; +use pool::{Request, RequestType}; use soroban_fixed_point_math::FixedPoint; use soroban_sdk::{testutils::Address as _, vec, Address}; use test_suites::{ @@ -51,7 +51,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: stable.address.clone(), amount, }, @@ -83,7 +83,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 2, + request_type: RequestType::SupplyCollateral as u32, address: xlm.address.clone(), amount, }, @@ -112,7 +112,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: stable.address.clone(), amount, }, @@ -144,7 +144,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 4, + request_type: RequestType::Borrow as u32, address: xlm.address.clone(), amount, }, @@ -247,7 +247,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: stable.address.clone(), amount, }, @@ -279,7 +279,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: xlm.address.clone(), amount, }, @@ -308,7 +308,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 3, + request_type: RequestType::WithdrawCollateral as u32, address: xlm.address.clone(), amount, }, @@ -337,7 +337,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 3, + request_type: RequestType::WithdrawCollateral as u32, address: stable.address.clone(), amount, }, @@ -473,7 +473,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: stable.address.clone(), amount: amount, }, @@ -505,7 +505,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 5, + request_type: RequestType::Repay as u32, address: xlm.address.clone(), amount: amount, }, @@ -538,7 +538,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 3, + request_type: RequestType::WithdrawCollateral as u32, address: xlm.address.clone(), amount: amount, }, @@ -566,7 +566,7 @@ fn test_wasm_happy_path() { &vec![ &fixture.env, Request { - request_type: 3, + request_type: RequestType::WithdrawCollateral as u32, address: stable.address.clone(), amount: amount, },