From 7c925f70808a73578ad25b310d3b907a0fff484e Mon Sep 17 00:00:00 2001 From: Alex Mootz Date: Tue, 24 Oct 2023 09:10:03 -0400 Subject: [PATCH 1/6] emitter: fix: drop BLND token and use sep-41 token package --- emitter/Cargo.toml | 2 + emitter/src/dependencies/mod.rs | 5 --- emitter/src/dependencies/token.rs | 3 -- emitter/src/emitter.rs | 62 +++++++++++++++---------------- 4 files changed, 31 insertions(+), 41 deletions(-) delete mode 100644 emitter/src/dependencies/token.rs diff --git a/emitter/Cargo.toml b/emitter/Cargo.toml index f4013fe2..8f21f2b5 100644 --- a/emitter/Cargo.toml +++ b/emitter/Cargo.toml @@ -15,7 +15,9 @@ testutils = ["soroban-sdk/testutils"] [dependencies] soroban-sdk = { workspace = true } +sep-41-token = { workspace = true } [dev_dependencies] soroban-sdk = { workspace = true, features = ["testutils"] } backstop = { path = "../backstop", features = ["testutils"] } +sep-41-token = { workspace = true, features = ["testutils"] } diff --git a/emitter/src/dependencies/mod.rs b/emitter/src/dependencies/mod.rs index 6d1fe4a5..d6d77753 100644 --- a/emitter/src/dependencies/mod.rs +++ b/emitter/src/dependencies/mod.rs @@ -1,8 +1,3 @@ -mod token; -pub use token::Client as TokenClient; -#[cfg(any(test, feature = "testutils"))] -pub use token::WASM as TOKEN_WASM; - mod backstop; pub use backstop::Client as BackstopClient; #[cfg(any(test, feature = "testutils"))] diff --git a/emitter/src/dependencies/token.rs b/emitter/src/dependencies/token.rs deleted file mode 100644 index feb210b0..00000000 --- a/emitter/src/dependencies/token.rs +++ /dev/null @@ -1,3 +0,0 @@ -use soroban_sdk::contractimport; - -contractimport!(file = "../soroban_token_contract.wasm"); diff --git a/emitter/src/emitter.rs b/emitter/src/emitter.rs index ab91db0e..21b52c39 100644 --- a/emitter/src/emitter.rs +++ b/emitter/src/emitter.rs @@ -1,9 +1,5 @@ -use crate::{ - constants::SCALAR_7, - dependencies::{BackstopClient, TokenClient}, - errors::EmitterError, - storage, -}; +use crate::{constants::SCALAR_7, dependencies::BackstopClient, errors::EmitterError, storage}; +use sep_41_token::{StellarAssetClient, TokenClient}; use soroban_sdk::{panic_with_error, Address, Env, Map}; /// Perform a distribution @@ -15,7 +11,7 @@ pub fn execute_distribute(e: &Env, backstop: &Address) -> i128 { storage::set_last_distro_time(e, ×tamp); let blend_id = storage::get_blend_id(e); - let blend_client = TokenClient::new(e, &blend_id); + let blend_client = StellarAssetClient::new(e, &blend_id); blend_client.mint(backstop, &distribution_amount); distribution_amount @@ -42,11 +38,11 @@ pub fn execute_drop(e: &Env) -> Map { if storage::get_drop_status(e) { panic_with_error!(e, EmitterError::BadDrop); } + let blnd_id = storage::get_blend_id(e); + let blnd_client = StellarAssetClient::new(e, &blnd_id); + let backstop = storage::get_backstop(e); let backstop_client = BackstopClient::new(e, &backstop); - let backstop_token = backstop_client.backstop_token(); - let backstop_token_client = TokenClient::new(e, &backstop_token); - let drop_list: Map = backstop_client.drop_list(); let mut drop_amount = 0; for (_, amt) in drop_list.iter() { @@ -57,7 +53,7 @@ pub fn execute_drop(e: &Env) -> Map { panic_with_error!(e, EmitterError::BadDrop); } for (addr, amt) in drop_list.iter() { - backstop_token_client.mint(&addr, &amt); + blnd_client.mint(&addr, &amt); } storage::set_drop_status(e, true); drop_list @@ -71,6 +67,7 @@ mod tests { }; use super::*; + use sep_41_token::testutils::MockTokenClient; use soroban_sdk::{ map, testutils::{Address as _, Ledger, LedgerInfo}, @@ -96,7 +93,7 @@ mod tests { let backstop = Address::random(&e); let blnd_id = e.register_stellar_asset_contract(emitter.clone()); - let blnd_client = TokenClient::new(&e, &blnd_id); + let blnd_client = MockTokenClient::new(&e, &blnd_id); e.as_contract(&emitter, || { storage::set_last_distro_time(&e, &1000); @@ -132,7 +129,7 @@ mod tests { let new_backstop = Address::random(&e); let backstop_token = e.register_stellar_asset_contract(bombadil.clone()); - let backstop_token_client = TokenClient::new(&e, &backstop_token); + let backstop_token_client = MockTokenClient::new(&e, &backstop_token); backstop_client.initialize( &backstop_token, @@ -179,7 +176,7 @@ mod tests { let new_backstop = Address::random(&e); let backstop_token = e.register_stellar_asset_contract(bombadil.clone()); - let backstop_token_client = TokenClient::new(&e, &backstop_token); + let backstop_token_client = MockTokenClient::new(&e, &backstop_token); backstop_client.initialize( &backstop_token, @@ -200,10 +197,11 @@ mod tests { assert!(false, "Should have panicked"); }); } + #[test] fn test_drop() { let e = Env::default(); - e.mock_all_auths_allowing_non_root_auth(); + e.mock_all_auths(); e.ledger().set(LedgerInfo { timestamp: 12345, @@ -216,14 +214,13 @@ mod tests { max_entry_expiration: 2000000, }); - let bombadil = Address::random(&e); let frodo = Address::random(&e); let samwise = Address::random(&e); let emitter = create_emitter(&e); let (backstop, backstop_client) = create_backstop(&e); - let backstop_token = e.register_stellar_asset_contract(bombadil.clone()); - let backstop_token_client = TokenClient::new(&e, &backstop_token); + let blnd_id = e.register_stellar_asset_contract(emitter.clone()); + let blnd_client = MockTokenClient::new(&e, &blnd_id); let drop_list = map![ &e, (frodo.clone(), 20_000_000 * SCALAR_7), @@ -231,8 +228,8 @@ mod tests { ]; backstop_client.initialize( - &backstop_token, &Address::random(&e), + &blnd_id, &Address::random(&e), &Address::random(&e), &drop_list, @@ -241,16 +238,14 @@ mod tests { e.as_contract(&emitter, || { storage::set_last_distro_time(&e, &1000); storage::set_backstop(&e, &backstop); + storage::set_blend_id(&e, &blnd_id); storage::set_drop_status(&e, false); let list = execute_drop(&e); assert_eq!(storage::get_drop_status(&e), true); assert_eq!(list.len(), 2); - assert_eq!(backstop_token_client.balance(&frodo), 20_000_000 * SCALAR_7); - assert_eq!( - backstop_token_client.balance(&samwise), - 30_000_000 * SCALAR_7 - ); + assert_eq!(blnd_client.balance(&frodo), 20_000_000 * SCALAR_7); + assert_eq!(blnd_client.balance(&samwise), 30_000_000 * SCALAR_7); }); } @@ -271,13 +266,12 @@ mod tests { max_entry_expiration: 2000000, }); - let bombadil = Address::random(&e); let frodo = Address::random(&e); let samwise = Address::random(&e); let emitter = create_emitter(&e); let (backstop, backstop_client) = create_backstop(&e); - let backstop_token = e.register_stellar_asset_contract(bombadil.clone()); + let blnd_id = e.register_stellar_asset_contract(emitter.clone()); let drop_list = map![ &e, (frodo.clone(), 20_000_000 * SCALAR_7), @@ -285,8 +279,8 @@ mod tests { ]; backstop_client.initialize( - &backstop_token, &Address::random(&e), + &blnd_id, &Address::random(&e), &Address::random(&e), &drop_list, @@ -295,6 +289,7 @@ mod tests { e.as_contract(&emitter, || { storage::set_last_distro_time(&e, &1000); storage::set_backstop(&e, &backstop); + storage::set_blend_id(&e, &blnd_id); storage::set_drop_status(&e, true); execute_drop(&e); @@ -319,13 +314,12 @@ mod tests { max_entry_expiration: 2000000, }); - let bombadil = Address::random(&e); let frodo = Address::random(&e); let samwise = Address::random(&e); let emitter = create_emitter(&e); let (backstop, backstop_client) = create_backstop(&e); - let backstop_token = e.register_stellar_asset_contract(bombadil.clone()); + let blnd_id = e.register_stellar_asset_contract(emitter.clone()); let drop_list = map![ &e, (frodo.clone(), 20_000_000 * SCALAR_7), @@ -333,8 +327,8 @@ mod tests { ]; backstop_client.initialize( - &backstop_token, &Address::random(&e), + &blnd_id, &Address::random(&e), &Address::random(&e), &drop_list, @@ -343,6 +337,7 @@ mod tests { e.as_contract(&emitter, || { storage::set_last_distro_time(&e, &1000); storage::set_backstop(&e, &backstop); + storage::set_blend_id(&e, &blnd_id); storage::set_drop_status(&e, false); execute_drop(&e); @@ -354,7 +349,7 @@ mod tests { #[should_panic(expected = "Error(Storage, MissingValue)")] fn test_drop_no_status() { let e = Env::default(); - e.mock_all_auths_allowing_non_root_auth(); + e.mock_all_auths(); e.ledger().set(LedgerInfo { timestamp: 12345, @@ -373,7 +368,7 @@ mod tests { let emitter = create_emitter(&e); let (backstop, backstop_client) = create_backstop(&e); - let backstop_token = e.register_stellar_asset_contract(bombadil.clone()); + let blnd_id = e.register_stellar_asset_contract(bombadil.clone()); let drop_list = map![ &e, (frodo.clone(), 20_000_000 * SCALAR_7), @@ -381,8 +376,8 @@ mod tests { ]; backstop_client.initialize( - &backstop_token, &Address::random(&e), + &blnd_id, &Address::random(&e), &Address::random(&e), &drop_list, @@ -391,6 +386,7 @@ mod tests { e.as_contract(&emitter, || { storage::set_last_distro_time(&e, &1000); storage::set_backstop(&e, &backstop); + storage::set_blend_id(&e, &blnd_id); execute_drop(&e); }); From 188be3d094753fb0f3a2e3da7885cfd8e70596ba Mon Sep 17 00:00:00 2001 From: Alex Mootz Date: Tue, 24 Oct 2023 09:11:21 -0400 Subject: [PATCH 2/6] all: use sep-40 and sep-41 packages to remove unnecessary code --- Cargo.lock | 42 ++-- Cargo.toml | 11 +- backstop/Cargo.toml | 2 + backstop/src/backstop/deposit.rs | 5 +- backstop/src/backstop/fund_management.rs | 6 +- backstop/src/backstop/withdrawal.rs | 3 +- backstop/src/dependencies/mod.rs | 5 - backstop/src/dependencies/token.rs | 3 - backstop/src/emissions/claim.rs | 3 +- backstop/src/emissions/manager.rs | 2 +- backstop/src/testutils.rs | 20 +- mocks/mock-oracle/Cargo.toml | 21 -- mocks/mock-oracle/src/lib.rs | 8 - mocks/mock-oracle/src/mock_oracle.rs | 128 ---------- oracle/Cargo.toml | 20 -- oracle/src/lib.rs | 38 --- pool/Cargo.toml | 7 +- pool/src/auctions/auction.rs | 219 +++++++++++------- .../src/auctions/backstop_interest_auction.rs | 64 +++-- pool/src/auctions/bad_debt_auction.rs | 84 +++++-- pool/src/auctions/user_liquidation_auction.rs | 126 +++++++--- pool/src/dependencies/mod.rs | 5 - pool/src/dependencies/token.rs | 3 - pool/src/emissions/distributor.rs | 2 +- pool/src/pool/health_factor.rs | 19 +- pool/src/pool/pool.rs | 56 ++++- pool/src/pool/reserve.rs | 2 +- pool/src/pool/submit.rs | 33 ++- pool/src/testutils.rs | 29 +-- soroban_token_contract.wasm | Bin 8470 -> 0 bytes 30 files changed, 514 insertions(+), 452 deletions(-) delete mode 100644 backstop/src/dependencies/token.rs delete mode 100644 mocks/mock-oracle/Cargo.toml delete mode 100644 mocks/mock-oracle/src/lib.rs delete mode 100644 mocks/mock-oracle/src/mock_oracle.rs delete mode 100644 oracle/Cargo.toml delete mode 100644 oracle/src/lib.rs delete mode 100644 pool/src/dependencies/token.rs delete mode 100755 soroban_token_contract.wasm diff --git a/Cargo.lock b/Cargo.lock index 75a3b200..6bd2cef6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,6 +54,7 @@ dependencies = [ "cast", "fixed-point-math", "mock-pool-factory", + "sep-41-token", "soroban-sdk", ] @@ -401,6 +402,7 @@ name = "emitter" version = "0.0.1" dependencies = [ "backstop", + "sep-41-token", "soroban-sdk", ] @@ -640,14 +642,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mock-oracle" -version = "0.0.0" -dependencies = [ - "oracle", - "soroban-sdk", -] - [[package]] name = "mock-pool" version = "0.0.0" @@ -720,13 +714,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oracle" -version = "0.0.0" -dependencies = [ - "soroban-sdk", -] - [[package]] name = "paste" version = "1.0.14" @@ -756,9 +743,9 @@ dependencies = [ "backstop", "cast", "fixed-point-math", - "mock-oracle", "mock-pool-factory", - "oracle", + "sep-40-oracle", + "sep-41-token", "soroban-sdk", ] @@ -926,6 +913,24 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +[[package]] +name = "sep-40-oracle" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa589e8db60e397c7a7af90908eab64ca46cc5628957a554a24efb36235b34d2" +dependencies = [ + "soroban-sdk", +] + +[[package]] +name = "sep-41-token" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0edb6a114daf783364bf705d27f97a4f49ae858518eb46d46e4161cd75b9678" +dependencies = [ + "soroban-sdk", +] + [[package]] name = "serde" version = "1.0.171" @@ -1270,11 +1275,12 @@ dependencies = [ "cast", "emitter", "fixed-point-math", - "mock-oracle", "mock-pool-factory", "pool", "pool-factory", "rand 0.7.3", + "sep-40-oracle", + "sep-41-token", "soroban-sdk", ] diff --git a/Cargo.toml b/Cargo.toml index c31d4a61..ac80b475 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,10 +6,8 @@ members = [ "blend-interfaces", "emitter", "pool", - "mocks/mock-oracle", "mocks/mock-pool", "mocks/mock-pool-factory", - "oracle", "pool-factory", "test-suites" ] @@ -37,3 +35,12 @@ version = "0.0.2" [workspace.dependencies.cast] version = "0.3.0" default-features = false + +[workspace.dependencies.sep-40-oracle] +version = "0.1.1" + +[workspace.dependencies.sep-41-token] +version = "0.2.1" + +[workspace.dependencies.blend-interfaces] +path = "./blend-interfaces" \ No newline at end of file diff --git a/backstop/Cargo.toml b/backstop/Cargo.toml index 1a6e2671..32ec4852 100644 --- a/backstop/Cargo.toml +++ b/backstop/Cargo.toml @@ -19,7 +19,9 @@ testutils = [ soroban-sdk = { workspace = true } fixed-point-math = { workspace = true } cast = { workspace = true } +sep-41-token = { workspace = true } [dev_dependencies] soroban-sdk = { workspace = true, features = ["testutils"] } mock-pool-factory = { path = "../mocks/mock-pool-factory", features = ["testutils"] } +sep-41-token = { workspace = true, features = ["testutils"] } diff --git a/backstop/src/backstop/deposit.rs b/backstop/src/backstop/deposit.rs index 4646b6df..ac81c3a4 100644 --- a/backstop/src/backstop/deposit.rs +++ b/backstop/src/backstop/deposit.rs @@ -1,4 +1,5 @@ -use crate::{contract::require_nonnegative, dependencies::TokenClient, emissions, storage}; +use crate::{contract::require_nonnegative, emissions, storage}; +use sep_41_token::TokenClient; use soroban_sdk::{Address, Env}; /// Perform a deposit into the backstop module @@ -87,7 +88,7 @@ mod tests { } #[test] - #[should_panic(expected = "Error(WasmVm, InvalidAction)")] + #[should_panic] fn test_execute_deposit_too_many_tokens() { let e = Env::default(); e.mock_all_auths_allowing_non_root_auth(); diff --git a/backstop/src/backstop/fund_management.rs b/backstop/src/backstop/fund_management.rs index b8a4379c..4bafa128 100644 --- a/backstop/src/backstop/fund_management.rs +++ b/backstop/src/backstop/fund_management.rs @@ -1,10 +1,8 @@ use crate::{ - constants::SCALAR_7, - contract::require_nonnegative, - dependencies::{CometClient, TokenClient}, - storage, + constants::SCALAR_7, contract::require_nonnegative, dependencies::CometClient, storage, }; use fixed_point_math::FixedPoint; +use sep_41_token::TokenClient; use soroban_sdk::{unwrap::UnwrapOptimized, Address, Env}; use super::require_is_from_pool_factory; diff --git a/backstop/src/backstop/withdrawal.rs b/backstop/src/backstop/withdrawal.rs index ceaa90a8..a6af8151 100644 --- a/backstop/src/backstop/withdrawal.rs +++ b/backstop/src/backstop/withdrawal.rs @@ -1,4 +1,5 @@ -use crate::{contract::require_nonnegative, dependencies::TokenClient, emissions, storage}; +use crate::{contract::require_nonnegative, emissions, storage}; +use sep_41_token::TokenClient; use soroban_sdk::{unwrap::UnwrapOptimized, Address, Env}; use super::Q4W; diff --git a/backstop/src/dependencies/mod.rs b/backstop/src/dependencies/mod.rs index 3ea1daae..53892d25 100644 --- a/backstop/src/dependencies/mod.rs +++ b/backstop/src/dependencies/mod.rs @@ -1,8 +1,3 @@ -mod token; -pub use token::Client as TokenClient; -#[cfg(any(test, feature = "testutils"))] -pub use token::WASM as TOKEN_WASM; - mod pool_factory; pub use pool_factory::Client as PoolFactoryClient; diff --git a/backstop/src/dependencies/token.rs b/backstop/src/dependencies/token.rs deleted file mode 100644 index feb210b0..00000000 --- a/backstop/src/dependencies/token.rs +++ /dev/null @@ -1,3 +0,0 @@ -use soroban_sdk::contractimport; - -contractimport!(file = "../soroban_token_contract.wasm"); diff --git a/backstop/src/emissions/claim.rs b/backstop/src/emissions/claim.rs index b4f940d2..7a01ddbf 100644 --- a/backstop/src/emissions/claim.rs +++ b/backstop/src/emissions/claim.rs @@ -1,4 +1,5 @@ -use crate::{dependencies::TokenClient, errors::BackstopError, storage}; +use crate::{errors::BackstopError, storage}; +use sep_41_token::TokenClient; use soroban_sdk::{panic_with_error, Address, Env, Vec}; use super::update_emissions; diff --git a/backstop/src/emissions/manager.rs b/backstop/src/emissions/manager.rs index a78f5086..8a8bc0dc 100644 --- a/backstop/src/emissions/manager.rs +++ b/backstop/src/emissions/manager.rs @@ -1,10 +1,10 @@ use cast::{i128, u64}; use fixed_point_math::FixedPoint; +use sep_41_token::TokenClient; use soroban_sdk::{panic_with_error, unwrap::UnwrapOptimized, vec, Address, Env, Vec}; use crate::{ constants::{BACKSTOP_EPOCH, SCALAR_7}, - dependencies::TokenClient, errors::BackstopError, storage::{self, BackstopEmissionConfig, BackstopEmissionsData}, }; diff --git a/backstop/src/testutils.rs b/backstop/src/testutils.rs index 05061644..3f7041dd 100644 --- a/backstop/src/testutils.rs +++ b/backstop/src/testutils.rs @@ -2,7 +2,7 @@ use crate::{ backstop::Q4W, - dependencies::{CometClient, TokenClient, COMET_WASM, TOKEN_WASM}, + dependencies::{CometClient, COMET_WASM}, storage::{self}, BackstopContract, }; @@ -11,16 +11,18 @@ use soroban_sdk::{ testutils::Address as _, unwrap::UnwrapOptimized, vec, Address, Env, IntoVal, Vec, }; +use sep_41_token::testutils::{MockTokenClient, MockTokenWASM}; + use mock_pool_factory::{MockPoolFactory, MockPoolFactoryClient}; pub(crate) fn create_backstop(e: &Env) -> Address { e.register_contract(None, BackstopContract {}) } -pub(crate) fn create_token<'a>(e: &Env, admin: &Address) -> (Address, TokenClient<'a>) { +pub(crate) fn create_token<'a>(e: &Env, admin: &Address) -> (Address, MockTokenClient<'a>) { let contract_address = Address::random(e); - e.register_contract_wasm(&contract_address, TOKEN_WASM); - let client = TokenClient::new(e, &contract_address); + e.register_contract_wasm(&contract_address, MockTokenWASM); + let client = MockTokenClient::new(e, &contract_address); client.initialize(&admin, &7, &"unit".into_val(e), &"test".into_val(e)); (contract_address, client) } @@ -29,7 +31,7 @@ pub(crate) fn create_blnd_token<'a>( e: &Env, backstop: &Address, admin: &Address, -) -> (Address, TokenClient<'a>) { +) -> (Address, MockTokenClient<'a>) { let (contract_address, client) = create_token(e, admin); e.as_contract(backstop, || { @@ -42,7 +44,7 @@ pub(crate) fn create_usdc_token<'a>( e: &Env, backstop: &Address, admin: &Address, -) -> (Address, TokenClient<'a>) { +) -> (Address, MockTokenClient<'a>) { let (contract_address, client) = create_token(e, admin); e.as_contract(backstop, || { @@ -55,7 +57,7 @@ pub(crate) fn create_backstop_token<'a>( e: &Env, backstop: &Address, admin: &Address, -) -> (Address, TokenClient<'a>) { +) -> (Address, MockTokenClient<'a>) { let (contract_address, client) = create_token(e, admin); e.as_contract(backstop, || { @@ -95,8 +97,8 @@ pub(crate) fn create_comet_lp_pool<'a>( e.register_contract_wasm(&contract_address, COMET_WASM); let client = CometClient::new(e, &contract_address); - let blnd_client = TokenClient::new(e, blnd_token); - let usdc_client = TokenClient::new(e, usdc_token); + let blnd_client = MockTokenClient::new(e, blnd_token); + let usdc_client = MockTokenClient::new(e, usdc_token); blnd_client.mint(&admin, &1_000_0000000); usdc_client.mint(&admin, &25_0000000); let exp_ledger = e.ledger().sequence() + 100; diff --git a/mocks/mock-oracle/Cargo.toml b/mocks/mock-oracle/Cargo.toml deleted file mode 100644 index 2833bbb0..00000000 --- a/mocks/mock-oracle/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "mock-oracle" -version = "0.0.0" -authors = ["Blend Capital "] -license = "AGPL-3.0" -edition = "2021" -publish = false - -[lib] -crate-type = ["cdylib", "rlib"] -doctest = false - -[features] -testutils = ["soroban-sdk/testutils"] - -[dependencies] -soroban-sdk = { workspace = true } -oracle = { path = "../../oracle" } - -[dev_dependencies] -soroban-sdk = { workspace = true, features = ["testutils"] } diff --git a/mocks/mock-oracle/src/lib.rs b/mocks/mock-oracle/src/lib.rs deleted file mode 100644 index 40d4f810..00000000 --- a/mocks/mock-oracle/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![no_std] - -#[cfg(any(test, feature = "testutils"))] -extern crate std; - -mod mock_oracle; - -pub use mock_oracle::*; diff --git a/mocks/mock-oracle/src/mock_oracle.rs b/mocks/mock-oracle/src/mock_oracle.rs deleted file mode 100644 index e16ef2c2..00000000 --- a/mocks/mock-oracle/src/mock_oracle.rs +++ /dev/null @@ -1,128 +0,0 @@ -use soroban_sdk::{contract, contracterror, contractimpl, contracttype, Address, Env, Vec}; - -use oracle::{PriceData, PriceFeedTrait}; - -pub(crate) const LEDGER_THRESHOLD_SHARED: u32 = 172800; // ~ 10 days -pub(crate) const LEDGER_BUMP_SHARED: u32 = 241920; // ~ 14 days - -#[derive(Clone)] -#[contracttype] -pub enum MockOracleDataKey { - // The address that can manage the oracle - Admin, - // The number of decimals reported - Decimals, - // The map of asset price sources (asset contractId -> price source contractId) - Sources(Address), - // MOCK: Map of prices to return - Prices(Address), - // MOCK: If the oracle should fail - ToError, -} - -#[contracterror] -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] -#[repr(u32)] -pub enum OracleError { - StaleOracle = 1, -} - -/// ### Mock Oracle -/// -/// Contract to fetch mocked asset prices. -/// -/// ### Dev -/// For testing purposes only! -#[contract] -pub struct MockOracle; - -trait MockOraclePrice { - /// Sets the mocked price for an asset. - /// - /// Will always return with the latest ledger as the timestamp. - fn set_price(e: Env, asset: Address, price: i128); - - /// Sets the mocked price for an asset. - /// - /// Will return the given timestamp as the PriceData timestamp. - fn set_price_timestamp(e: Env, asset: Address, price: i128, timestamp: u64); -} - -#[contractimpl] -impl MockOraclePrice for MockOracle { - fn set_price(e: Env, asset: Address, price: i128) { - e.storage() - .instance() - .bump(LEDGER_THRESHOLD_SHARED, LEDGER_BUMP_SHARED); - let key = MockOracleDataKey::Prices(asset); - e.storage().temporary().set::( - &key, - &PriceData { - price, - timestamp: 0, - }, - ); - e.storage() - .temporary() - .bump(&key, LEDGER_THRESHOLD_SHARED, LEDGER_BUMP_SHARED); - } - - fn set_price_timestamp(e: Env, asset: Address, price: i128, timestamp: u64) { - let key = MockOracleDataKey::Prices(asset); - e.storage() - .temporary() - .set::(&key, &PriceData { price, timestamp }); - e.storage() - .temporary() - .bump(&key, LEDGER_THRESHOLD_SHARED, LEDGER_BUMP_SHARED); - } -} - -#[contractimpl] -impl PriceFeedTrait for MockOracle { - fn base(_e: Env) -> Address { - panic!("not impl") - } - - fn assets(_e: Env) -> Vec
{ - panic!("not impl") - } - - fn decimals(_e: Env) -> u32 { - 7_u32 - } - - fn resolution(_e: Env) -> u32 { - panic!("not impl") - } - - fn price(_e: Env, _asset: Address, _timestamp: u64) -> Option { - panic!("not impl") - } - - fn prices(_e: Env, _asset: Address, _records: u32) -> Option> { - panic!("not impl") - } - - fn lastprice(e: Env, asset: Address) -> Option { - e.storage() - .instance() - .bump(LEDGER_THRESHOLD_SHARED, LEDGER_BUMP_SHARED); - let key = MockOracleDataKey::Prices(asset); - let mut price = e - .storage() - .temporary() - .get::(&key) - .unwrap_or(PriceData { - price: 0, - timestamp: 1, - }); - if price.timestamp == 0 { - price.timestamp = e.ledger().timestamp(); - } - if price.price != 0 { - return Some(price); - } - Some(price) - } -} diff --git a/oracle/Cargo.toml b/oracle/Cargo.toml deleted file mode 100644 index d4489c39..00000000 --- a/oracle/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "oracle" -version = "0.0.0" -authors = ["Blend Capital "] -license = "AGPL-3.0" -edition = "2021" -publish = false - -[lib] -crate-type = ["cdylib", "rlib"] -doctest = false - -[features] -testutils = ["soroban-sdk/testutils"] - -[dependencies] -soroban-sdk = { workspace = true } - -[dev_dependencies] -soroban-sdk = { workspace = true, features = ["testutils"] } diff --git a/oracle/src/lib.rs b/oracle/src/lib.rs deleted file mode 100644 index af91d052..00000000 --- a/oracle/src/lib.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! Interface for SEP-40 Oracle Price Feed -//! https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0040.md - -#![no_std] - -use soroban_sdk::{contractclient, contracttype, Address, Env, Vec}; - -/// Price data for an asset at a specific timestamp -#[contracttype] -pub struct PriceData { - pub price: i128, - pub timestamp: u64, -} - -/// Oracle feed interface description -#[contractclient(name = "OracleClient")] -pub trait PriceFeedTrait { - /// Return the base asset the price is reported in - fn base(env: Env) -> Address; - - /// Return all assets quoted by the price feed - fn assets(env: Env) -> Vec
; - - /// Return the number of decimals for all assets quoted by the oracle - fn decimals(env: Env) -> u32; - - /// Return default tick period timeframe (in seconds) - fn resolution(env: Env) -> u32; - - /// Get price in base asset at specific timestamp - fn price(env: Env, asset: Address, timestamp: u64) -> Option; - - /// Get last N price records - fn prices(env: Env, asset: Address, records: u32) -> Option>; - - /// Get the most recent price for an asset - fn lastprice(env: Env, asset: Address) -> Option; -} diff --git a/pool/Cargo.toml b/pool/Cargo.toml index b968760e..b4ac5bcd 100644 --- a/pool/Cargo.toml +++ b/pool/Cargo.toml @@ -18,10 +18,13 @@ testutils = [ soroban-sdk = { workspace = true } fixed-point-math = { workspace = true } cast = { workspace = true } -oracle = { path = "../oracle" } +sep-40-oracle = { workspace = true } +sep-41-token = { workspace = true} + [dev_dependencies] soroban-sdk = { workspace = true, features = ["testutils"] } backstop = { path = "../backstop", features = ["testutils"] } +sep-40-oracle = { workspace = true, features = ["testutils"] } +sep-41-token = { workspace = true, features = ["testutils"] } mock-pool-factory = { path = "../mocks/mock-pool-factory", features = ["testutils"] } -mock-oracle = { path = "../mocks/mock-oracle", features = ["testutils"] } diff --git a/pool/src/auctions/auction.rs b/pool/src/auctions/auction.rs index b1deea22..c615b994 100644 --- a/pool/src/auctions/auction.rs +++ b/pool/src/auctions/auction.rs @@ -259,10 +259,11 @@ mod tests { }; use super::*; + use sep_40_oracle::testutils::Asset; use soroban_sdk::{ map, testutils::{Address as _, Ledger, LedgerInfo}, - vec, + vec, Symbol, }; #[test] @@ -352,12 +353,28 @@ mod tests { &reserve_config_2, &reserve_data_2, ); - - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &100_0000000); - oracle_client.set_price(&usdc, &1_0000000); - oracle_client.set_price(&blnd, &0_1000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD1")), + &vec![ + &e, + Asset::Stellar(underlying_0), + Asset::Stellar(underlying_1), + Asset::Stellar(underlying_2), + Asset::Stellar(usdc), + Asset::Stellar(blnd), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![ + &e, + 2_0000000, + 4_0000000, + 100_0000000, + 1_0000000, + 0_1000000, + ]); let positions: Positions = Positions { collateral: map![&e], @@ -454,10 +471,20 @@ mod tests { &reserve_data_2, ); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &100_0000000); - oracle_client.set_price(&usdc_id, &1_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + Asset::Stellar(underlying_2), + Asset::Stellar(usdc_id), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 100_0000000, 1_0000000]); let pool_config = PoolConfig { oracle: oracle_id, @@ -545,9 +572,19 @@ mod tests { &reserve_data_2, ); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &50_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0), + Asset::Stellar(underlying_1), + Asset::Stellar(underlying_2), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 50_0000000]); let liq_pct = 45; let positions: Positions = Positions { @@ -618,8 +655,18 @@ mod tests { ); let (oracle_id, oracle_client) = testutils::create_mock_oracle(&e); - oracle_client.set_price(&underlying_0, &10_0000000); - oracle_client.set_price(&underlying_1, &5_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0), + Asset::Stellar(underlying_1), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 10_0000000, 5_0000000]); // setup user (collateralize reserve 0 and borrow reserve 1) let collateral_amount = 17_8000000; @@ -690,8 +737,18 @@ mod tests { ); let (oracle_id, oracle_client) = testutils::create_mock_oracle(&e); - oracle_client.set_price(&underlying_0, &10_0000000); - oracle_client.set_price(&underlying_1, &5_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0), + Asset::Stellar(underlying_1), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 10_0000000, 5_0000000]); // setup user (collateralize reserve 0 and borrow reserve 1) let collateral_amount = 15_0000000; @@ -748,9 +805,9 @@ mod tests { sequence_number: 175, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let bombadil = Address::random(&e); @@ -831,9 +888,9 @@ mod tests { sequence_number: 176 + 200, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); e.budget().reset_unlimited(); let mut pool = Pool::load(&e); @@ -855,9 +912,9 @@ mod tests { sequence_number: 175, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let bombadil = Address::random(&e); @@ -938,9 +995,9 @@ mod tests { sequence_number: 176 + 200, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); e.budget().reset_unlimited(); let mut pool = Pool::load(&e); @@ -975,9 +1032,9 @@ mod tests { sequence_number: 175, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let bombadil = Address::random(&e); @@ -1059,9 +1116,9 @@ mod tests { sequence_number: 176 + 100, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let mut pool = Pool::load(&e); let mut frodo_state = User::load(&e, &frodo); @@ -1089,9 +1146,9 @@ mod tests { sequence_number: 176 + 200, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let mut pool = Pool::load(&e); let mut frodo_state = User::load(&e, &frodo); @@ -1118,9 +1175,9 @@ mod tests { sequence_number: 176 + 300, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let mut pool = Pool::load(&e); let mut frodo_state = User::load(&e, &frodo); @@ -1164,9 +1221,9 @@ mod tests { sequence_number: 175, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let bombadil = Address::random(&e); @@ -1246,9 +1303,9 @@ mod tests { sequence_number: 176 + 200, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); e.budget().reset_unlimited(); let mut pool = Pool::load(&e); @@ -1283,9 +1340,9 @@ mod tests { sequence_number: 175, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let bombadil = Address::random(&e); @@ -1367,9 +1424,9 @@ mod tests { sequence_number: 176 + 200, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); e.budget().reset_unlimited(); let mut pool = Pool::load(&e); @@ -1412,9 +1469,9 @@ mod tests { sequence_number: 1000, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let (scaled_auction, remaining_auction) = scale_auction(&e, &base_auction_data, 100); assert_eq!( @@ -1431,9 +1488,9 @@ mod tests { sequence_number: 1100, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let (scaled_auction, remaining_auction) = scale_auction(&e, &base_auction_data, 100); assert_eq!( @@ -1453,9 +1510,9 @@ mod tests { sequence_number: 1200, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let (scaled_auction, remaining_auction) = scale_auction(&e, &base_auction_data, 100); assert_eq!( @@ -1475,9 +1532,9 @@ mod tests { sequence_number: 1300, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let (scaled_auction, remaining_auction) = scale_auction(&e, &base_auction_data, 100); assert_eq!( @@ -1497,9 +1554,9 @@ mod tests { sequence_number: 1400, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let (scaled_auction, remaining_auction) = scale_auction(&e, &base_auction_data, 100); assert_eq!(scaled_auction.bid.len(), 0); @@ -1531,9 +1588,9 @@ mod tests { sequence_number: 1000, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let (scaled_auction, remaining_auction_option) = scale_auction(&e, &base_auction_data, 50); let remaining_auction = remaining_auction_option.unwrap(); @@ -1558,9 +1615,9 @@ mod tests { sequence_number: 1100, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let (scaled_auction, remaining_auction_option) = scale_auction(&e, &base_auction_data, 60); @@ -1589,9 +1646,9 @@ mod tests { sequence_number: 1300, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let (scaled_auction, remaining_auction_option) = scale_auction(&e, &base_auction_data, 60); @@ -1620,9 +1677,9 @@ mod tests { sequence_number: 1400, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 172800, + min_persistent_entry_expiration: 172800, + max_entry_expiration: u32::MAX, }); let (scaled_auction, remaining_auction_option) = scale_auction(&e, &base_auction_data, 50); let remaining_auction = remaining_auction_option.unwrap(); diff --git a/pool/src/auctions/backstop_interest_auction.rs b/pool/src/auctions/backstop_interest_auction.rs index 0edf3aad..1b050de4 100644 --- a/pool/src/auctions/backstop_interest_auction.rs +++ b/pool/src/auctions/backstop_interest_auction.rs @@ -1,12 +1,9 @@ use crate::{ - constants::SCALAR_7, - dependencies::{BackstopClient, TokenClient}, - errors::PoolError, - pool::Pool, - storage, + constants::SCALAR_7, dependencies::BackstopClient, errors::PoolError, pool::Pool, storage, }; use cast::i128; use fixed_point_math::FixedPoint; +use sep_41_token::TokenClient; use soroban_sdk::{map, panic_with_error, unwrap::UnwrapOptimized, Address, Env}; use super::{AuctionData, AuctionType}; @@ -99,9 +96,10 @@ mod tests { }; use super::*; + use sep_40_oracle::testutils::Asset; use soroban_sdk::{ testutils::{Address as _, Ledger, LedgerInfo}, - Address, + vec, Address, Symbol, }; #[test] @@ -212,10 +210,20 @@ mod tests { &reserve_data_2, ); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &100_0000000); - oracle_client.set_price(&usdc_id, &1_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + Asset::Stellar(underlying_2), + Asset::Stellar(usdc_id.clone()), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 100_0000000, 1_0000000]); let pool_config = PoolConfig { oracle: oracle_id, @@ -313,10 +321,20 @@ mod tests { &reserve_data_2, ); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &100_0000000); - oracle_client.set_price(&usdc_id, &1_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + Asset::Stellar(underlying_2), + Asset::Stellar(usdc_id.clone()), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 100_0000000, 1_0000000]); let pool_config = PoolConfig { oracle: oracle_id, @@ -414,10 +432,20 @@ mod tests { &reserve_data_2, ); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &100_0000000); - oracle_client.set_price(&usdc_id, &1_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + Asset::Stellar(underlying_2.clone()), + Asset::Stellar(usdc_id.clone()), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 100_0000000, 1_0000000]); let pool_config = PoolConfig { oracle: oracle_id, diff --git a/pool/src/auctions/bad_debt_auction.rs b/pool/src/auctions/bad_debt_auction.rs index b26c5114..05282690 100644 --- a/pool/src/auctions/bad_debt_auction.rs +++ b/pool/src/auctions/bad_debt_auction.rs @@ -120,10 +120,11 @@ mod tests { }; use super::*; + use sep_40_oracle::testutils::Asset; use soroban_sdk::{ testutils::{Address as _, Ledger, LedgerInfo}, unwrap::UnwrapOptimized, - vec, + vec, Symbol, }; #[test] @@ -279,11 +280,28 @@ mod tests { &reserve_data_2, ); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &100_0000000); - oracle_client.set_price(&usdc, &1_0000000); - oracle_client.set_price(&blnd, &0_1000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + Asset::Stellar(underlying_2), + Asset::Stellar(usdc), + Asset::Stellar(blnd), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![ + &e, + 2_0000000, + 4_0000000, + 100_0000000, + 1_0000000, + 0_1000000, + ]); let positions: Positions = Positions { collateral: map![&e], @@ -403,11 +421,28 @@ mod tests { &reserve_data_2, ); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &100_0000000); - oracle_client.set_price(&usdc, &1_0000000); - oracle_client.set_price(&blnd, &0_1000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + Asset::Stellar(underlying_2), + Asset::Stellar(usdc), + Asset::Stellar(blnd), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![ + &e, + 2_0000000, + 4_0000000, + 100_0000000, + 1_0000000, + 0_1000000, + ]); let positions: Positions = Positions { collateral: map![&e], @@ -528,11 +563,28 @@ mod tests { &reserve_data_2, ); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &100_0000000); - oracle_client.set_price(&usdc, &1_0000000); - oracle_client.set_price(&blnd, &0_1000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + Asset::Stellar(underlying_2), + Asset::Stellar(usdc), + Asset::Stellar(blnd), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![ + &e, + 2_0000000, + 4_0000000, + 100_0000000, + 1_0000000, + 0_1000000, + ]); let positions: Positions = Positions { collateral: map![&e], diff --git a/pool/src/auctions/user_liquidation_auction.rs b/pool/src/auctions/user_liquidation_auction.rs index e1abe2c0..381366b7 100644 --- a/pool/src/auctions/user_liquidation_auction.rs +++ b/pool/src/auctions/user_liquidation_auction.rs @@ -142,7 +142,11 @@ mod tests { }; use super::*; - use soroban_sdk::testutils::{Address as AddressTestTrait, Ledger, LedgerInfo}; + use sep_40_oracle::testutils::Asset; + use soroban_sdk::{ + testutils::{Address as AddressTestTrait, Ledger, LedgerInfo}, + vec, Symbol, + }; #[test] #[should_panic(expected = "Error(Contract, #103)")] @@ -257,9 +261,19 @@ mod tests { &reserve_data_2, ); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &50_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + Asset::Stellar(underlying_2.clone()), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 50_0000000]); let liq_pct = 45; let positions: Positions = Positions { @@ -361,9 +375,19 @@ mod tests { ); e.budget().reset_unlimited(); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &50_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0), + Asset::Stellar(underlying_1), + Asset::Stellar(underlying_2), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 50_0000000]); let liq_pct = 100; let pool_config = PoolConfig { @@ -458,9 +482,19 @@ mod tests { ); e.budget().reset_unlimited(); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &50_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0), + Asset::Stellar(underlying_1), + Asset::Stellar(underlying_2), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 50_0000000]); let liq_pct = 46; let pool_config = PoolConfig { @@ -556,9 +590,19 @@ mod tests { ); e.budget().reset_unlimited(); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &50_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0), + Asset::Stellar(underlying_1), + Asset::Stellar(underlying_2), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 50_0000000]); let liq_pct = 25; let pool_config = PoolConfig { @@ -595,9 +639,9 @@ mod tests { sequence_number: 175, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 17280, + min_persistent_entry_expiration: 17280, + max_entry_expiration: u32::MAX, }); let bombadil = Address::random(&e); @@ -654,9 +698,19 @@ mod tests { ); e.budget().reset_unlimited(); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &50_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + Asset::Stellar(underlying_2.clone()), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 50_0000000]); reserve_2_asset.mint(&frodo, &0_8000000); reserve_2_asset.approve(&frodo, &pool_address, &i128::MAX, &1000000); @@ -694,9 +748,9 @@ mod tests { sequence_number: 176 + 200, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 17280, + min_persistent_entry_expiration: 17280, + max_entry_expiration: u32::MAX, }); e.budget().reset_unlimited(); let mut pool = Pool::load(&e); @@ -760,9 +814,9 @@ mod tests { sequence_number: 175, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 17280, + min_persistent_entry_expiration: 17280, + max_entry_expiration: u32::MAX, }); let bombadil = Address::random(&e); @@ -819,9 +873,19 @@ mod tests { ); e.budget().reset_unlimited(); - oracle_client.set_price(&underlying_0, &2_0000000); - oracle_client.set_price(&underlying_1, &4_0000000); - oracle_client.set_price(&underlying_2, &50_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + Asset::Stellar(underlying_2.clone()), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 50_0000000]); reserve_2_asset.mint(&frodo, &0_8000000); reserve_2_asset.approve(&frodo, &pool_address, &i128::MAX, &1000000); @@ -859,9 +923,9 @@ mod tests { sequence_number: 176 + 200, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, + min_temp_entry_expiration: 17280, + min_persistent_entry_expiration: 17280, + max_entry_expiration: u32::MAX, }); e.budget().reset_unlimited(); let mut pool = Pool::load(&e); diff --git a/pool/src/dependencies/mod.rs b/pool/src/dependencies/mod.rs index 5226acdc..6c9f6d80 100644 --- a/pool/src/dependencies/mod.rs +++ b/pool/src/dependencies/mod.rs @@ -1,8 +1,3 @@ -mod token; -pub use token::Client as TokenClient; -#[cfg(any(test, feature = "testutils"))] -pub use token::WASM as TOKEN_WASM; - mod backstop; #[cfg(any(test, feature = "testutils"))] pub use backstop::{BackstopDataKey, WASM as BACKSTOP_WASM}; diff --git a/pool/src/dependencies/token.rs b/pool/src/dependencies/token.rs deleted file mode 100644 index feb210b0..00000000 --- a/pool/src/dependencies/token.rs +++ /dev/null @@ -1,3 +0,0 @@ -use soroban_sdk::contractimport; - -contractimport!(file = "../soroban_token_contract.wasm"); diff --git a/pool/src/emissions/distributor.rs b/pool/src/emissions/distributor.rs index f08098fd..83dd1628 100644 --- a/pool/src/emissions/distributor.rs +++ b/pool/src/emissions/distributor.rs @@ -1,9 +1,9 @@ use cast::i128; use fixed_point_math::FixedPoint; +use sep_41_token::TokenClient; use soroban_sdk::{panic_with_error, unwrap::UnwrapOptimized, Address, Env, Vec}; use crate::{ - dependencies::TokenClient, errors::PoolError, pool::User, storage::{self, ReserveEmissionsData, UserEmissionData}, diff --git a/pool/src/pool/health_factor.rs b/pool/src/pool/health_factor.rs index fad8b406..4b31e920 100644 --- a/pool/src/pool/health_factor.rs +++ b/pool/src/pool/health_factor.rs @@ -109,10 +109,11 @@ impl PositionData { mod tests { use super::*; use crate::{storage::PoolConfig, testutils}; + use sep_40_oracle::testutils::Asset; use soroban_sdk::{ map, testutils::{Address as _, Ledger, LedgerInfo}, - Address, + vec, Address, Symbol, }; #[test] @@ -151,9 +152,19 @@ mod tests { reserve_data.d_rate = 1_001_200_000; testutils::create_reserve(&e, &pool, &underlying_2, &reserve_config, &reserve_data); - oracle_client.set_price(&underlying_0, &1_0000000); - oracle_client.set_price(&underlying_1, &2_5000000); - oracle_client.set_price(&underlying_2, &1000_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0), + Asset::Stellar(underlying_1), + Asset::Stellar(underlying_2), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 1_0000000, 2_5000000, 1000_0000000]); e.ledger().set(LedgerInfo { timestamp: 0, diff --git a/pool/src/pool/pool.rs b/pool/src/pool/pool.rs index 809cfbff..230dbba9 100644 --- a/pool/src/pool/pool.rs +++ b/pool/src/pool/pool.rs @@ -1,6 +1,6 @@ use soroban_sdk::{map, panic_with_error, unwrap::UnwrapOptimized, vec, Address, Env, Map, Vec}; -use oracle::OracleClient; +use sep_40_oracle::{Asset, PriceFeedClient}; use crate::{ errors::PoolError, @@ -81,7 +81,7 @@ impl Pool { if let Some(decimals) = self.price_decimals { return decimals; } - let oracle_client = OracleClient::new(e, &self.config.oracle); + let oracle_client = PriceFeedClient::new(e, &self.config.oracle); let decimals = oracle_client.decimals(); self.price_decimals = Some(decimals); decimals @@ -98,8 +98,9 @@ impl Pool { if let Some(price) = self.prices.get(asset.clone()) { return price; } - let oracle_client = OracleClient::new(e, &self.config.oracle); - let price_data = oracle_client.lastprice(asset).unwrap_optimized(); + let oracle_client = PriceFeedClient::new(e, &self.config.oracle); + let oracle_asset = Asset::Stellar(asset.clone()); + let price_data = oracle_client.lastprice(&oracle_asset).unwrap_optimized(); if price_data.timestamp + 24 * 60 * 60 < e.ledger().timestamp() { panic_with_error!(e, PoolError::StalePrice); } @@ -110,7 +111,11 @@ impl Pool { #[cfg(test)] mod tests { - use soroban_sdk::testutils::{Address as _, Ledger, LedgerInfo}; + use sep_40_oracle::testutils::Asset; + use soroban_sdk::{ + testutils::{Address as _, Ledger, LedgerInfo}, + Symbol, + }; use crate::{storage::ReserveData, testutils}; @@ -357,9 +362,17 @@ mod tests { #[test] fn test_load_price_decimals() { let e = Env::default(); + e.mock_all_auths(); let pool = testutils::create_pool(&e); - let (oracle, _) = testutils::create_mock_oracle(&e); + let (oracle, oracle_client) = testutils::create_mock_oracle(&e); + oracle_client.set_data( + &Address::random(&e), + &Asset::Stellar(Address::random(&e)), + &vec![&e, Asset::Stellar(Address::random(&e))], + &7, + &300, + ); let pool_config = PoolConfig { oracle, bstop_rate: 0_200_000_000, @@ -377,13 +390,27 @@ mod tests { #[test] fn test_load_price() { let e = Env::default(); + e.mock_all_auths_allowing_non_root_auth(); + let bombadil = Address::random(&e); let pool = testutils::create_pool(&e); let asset_0 = Address::random(&e); let asset_1 = Address::random(&e); let (oracle, oracle_client) = testutils::create_mock_oracle(&e); - oracle_client.set_price(&asset_0, &123); - oracle_client.set_price(&asset_1, &456); + + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(asset_0.clone()), + Asset::Stellar(asset_1.clone()), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 123, 456]); + let pool_config = PoolConfig { oracle, bstop_rate: 0_200_000_000, @@ -400,7 +427,7 @@ mod tests { assert_eq!(price, 456); // verify the price is cached - oracle_client.set_price(&asset_0, &789); + oracle_client.set_price_stable(&vec![&e, 789, 101112]); let price = pool.load_price(&e, &asset_0); assert_eq!(price, 123); }); @@ -410,6 +437,7 @@ mod tests { #[should_panic(expected = "Error(Contract, #30)")] fn test_load_price_panics_if_stale() { let e = Env::default(); + e.mock_all_auths_allowing_non_root_auth(); e.ledger().set(LedgerInfo { timestamp: 1000 + 24 * 60 * 60 + 1, @@ -422,10 +450,18 @@ mod tests { max_entry_expiration: 2000000, }); + let bombadil = Address::random(&e); let pool = testutils::create_pool(&e); let asset = Address::random(&e); let (oracle, oracle_client) = testutils::create_mock_oracle(&e); - oracle_client.set_price_timestamp(&asset, &123, &1000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![&e, Asset::Stellar(asset.clone())], + &7, + &300, + ); + oracle_client.set_price(&vec![&e, 123], &1000); let pool_config = PoolConfig { oracle, bstop_rate: 0_200_000_000, diff --git a/pool/src/pool/reserve.rs b/pool/src/pool/reserve.rs index 0e864d9f..e67e82f7 100644 --- a/pool/src/pool/reserve.rs +++ b/pool/src/pool/reserve.rs @@ -1,10 +1,10 @@ use cast::i128; use fixed_point_math::FixedPoint; +use sep_41_token::TokenClient; use soroban_sdk::{contracttype, panic_with_error, unwrap::UnwrapOptimized, Address, Env}; use crate::{ constants::{SCALAR_7, SCALAR_9}, - dependencies::TokenClient, errors::PoolError, storage::{self, PoolConfig, ReserveData}, }; diff --git a/pool/src/pool/submit.rs b/pool/src/pool/submit.rs index 071c7558..a3c49779 100644 --- a/pool/src/pool/submit.rs +++ b/pool/src/pool/submit.rs @@ -1,4 +1,4 @@ -use crate::dependencies::TokenClient; +use sep_41_token::TokenClient; use soroban_sdk::{Address, Env, Vec}; use super::{ @@ -61,9 +61,10 @@ mod tests { }; use super::*; + use sep_40_oracle::testutils::Asset; use soroban_sdk::{ testutils::{Address as _, Ledger, LedgerInfo}, - vec, + vec, Symbol, }; #[test] @@ -100,8 +101,18 @@ mod tests { underlying_0_client.mint(&frodo, &16_0000000); - oracle_client.set_price(&underlying_0, &1_0000000); - oracle_client.set_price(&underlying_1, &5_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 1_0000000, 5_0000000]); let pool_config = PoolConfig { oracle, @@ -173,8 +184,18 @@ mod tests { underlying_0_client.mint(&frodo, &16_0000000); - oracle_client.set_price(&underlying_0, &1_0000000); - oracle_client.set_price(&underlying_1, &5_0000000); + oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &vec![ + &e, + Asset::Stellar(underlying_0.clone()), + Asset::Stellar(underlying_1.clone()), + ], + &7, + &300, + ); + oracle_client.set_price_stable(&vec![&e, 1_0000000, 5_0000000]); e.ledger().set(LedgerInfo { timestamp: 600, diff --git a/pool/src/testutils.rs b/pool/src/testutils.rs index b216d392..8d60d4f6 100644 --- a/pool/src/testutils.rs +++ b/pool/src/testutils.rs @@ -2,18 +2,18 @@ use crate::{ constants::{SCALAR_7, SCALAR_9}, - dependencies::{TokenClient, TOKEN_WASM}, pool::Reserve, storage::{self, ReserveConfig, ReserveData}, PoolContract, }; use fixed_point_math::FixedPoint; +use sep_40_oracle::testutils::{MockPriceOracleClient, MockPriceOracleWASM}; +use sep_41_token::testutils::{MockTokenClient, MockTokenWASM}; use soroban_sdk::{ map, testutils::Address as _, unwrap::UnwrapOptimized, vec, Address, Env, IntoVal, }; use backstop::{BackstopClient, BackstopContract}; -use mock_oracle::{MockOracle, MockOracleClient}; use mock_pool_factory::{MockPoolFactory, MockPoolFactoryClient}; pub(crate) fn create_pool(e: &Env) -> Address { @@ -26,10 +26,13 @@ pub(crate) fn create_pool(e: &Env) -> Address { // ***** Token ***** -pub(crate) fn create_token_contract<'a>(e: &Env, admin: &Address) -> (Address, TokenClient<'a>) { +pub(crate) fn create_token_contract<'a>( + e: &Env, + admin: &Address, +) -> (Address, MockTokenClient<'a>) { let contract_address = Address::random(e); - e.register_contract_wasm(&contract_address, TOKEN_WASM); - let client = TokenClient::new(e, &contract_address); + e.register_contract_wasm(&contract_address, MockTokenWASM); + let client = MockTokenClient::new(e, &contract_address); client.initialize(admin, &7, &"unit".into_val(e), &"test".into_val(e)); (contract_address, client) } @@ -38,7 +41,7 @@ pub(crate) fn create_blnd_token<'a>( e: &Env, pool_address: &Address, admin: &Address, -) -> (Address, TokenClient<'a>) { +) -> (Address, MockTokenClient<'a>) { let (contract_address, client) = create_token_contract(e, admin); e.as_contract(pool_address, || { @@ -51,7 +54,7 @@ pub(crate) fn create_usdc_token<'a>( e: &Env, pool_address: &Address, admin: &Address, -) -> (Address, TokenClient<'a>) { +) -> (Address, MockTokenClient<'a>) { let (contract_address, client) = create_token_contract(e, admin); e.as_contract(pool_address, || { @@ -62,11 +65,11 @@ pub(crate) fn create_usdc_token<'a>( //***** Oracle ****** -pub(crate) fn create_mock_oracle(e: &Env) -> (Address, MockOracleClient) { - let contract_address = e.register_contract(None, MockOracle {}); +pub(crate) fn create_mock_oracle(e: &Env) -> (Address, MockPriceOracleClient) { + let contract_address = e.register_contract_wasm(None, MockPriceOracleWASM); ( contract_address.clone(), - MockOracleClient::new(e, &contract_address), + MockPriceOracleClient::new(e, &contract_address), ) } @@ -133,8 +136,8 @@ pub(crate) fn create_comet_lp_pool<'a>( e.register_contract_wasm(&contract_address, comet::WASM); let client = comet::Client::new(e, &contract_address); - let blnd_client = TokenClient::new(e, blnd_token); - let usdc_client = TokenClient::new(e, usdc_token); + let blnd_client = MockTokenClient::new(e, blnd_token); + let usdc_client = MockTokenClient::new(e, usdc_token); blnd_client.mint(&admin, &1_000_0000000); usdc_client.mint(&admin, &25_0000000); let exp_ledger = e.ledger().sequence() + 100; @@ -225,7 +228,7 @@ pub(crate) fn create_reserve( storage::set_res_config(e, &token_address, &new_reserve_config); storage::set_res_data(e, &token_address, &reserve_data); }); - let underlying_client = TokenClient::new(e, token_address); + let underlying_client = MockTokenClient::new(e, token_address); // mint pool assets to set expected b_rate let total_supply = reserve_data diff --git a/soroban_token_contract.wasm b/soroban_token_contract.wasm deleted file mode 100755 index e0a9add2c378530ec03353f592a0c7e8276e027e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8470 zcmcgxdyE}b8UN0inccgcz1=A-S{9>oFPOAZ%5Gn~ts*-UY0*Y$DUv9E?9T4qrTe;f z*}ZMSwB4mIP@xKfqJRi0#YeHx1mYvQ1Ti6j1dN8iRQ@0&@&_jJhcQv{_kCy1%V$g#fO`Z#b!0%x(=i>z5W>Hjr2%*L$ShuJmS@fK z)1AeSdss8eFpM6d0cZ9Io*rg1M9-o_825Mw00^kKiHY*WCRmKVzOF+}s2&hBp}I-o z*-u*Cs5YXVs4jBU0d+mvqpBC}QOxA$RzL>T7@m`A8|F`{1Q>2qo5=-+F2E-+UpX7Q zy_VKen<}|0{Pyz7j$l>!ywx3R)||iQeXCp7C{pK9$#FC(t(0=y4%a=;_0$wPo}*}0 z%LUG?ist6#$)Ba@?9sxz_3!HZmdV;=WBMjdD@N<1&Cz6H^ouq6Xj?Kd(KwjYhiY_5 zYce%8-8fLAOIrt%34wL5NcK1PHKs9lm^PN0(@A}1q&7{P%C^}*GToS@&FisvusUPB?p zkjNiC6wUqW(%@@zb93Z>7{K5TZiXt>dxDv=LxnjynDSLdLM0i=-O`<5hLB zG<9G87t%USD?O;gamkPVc=P-mMQy>IjG>}|ouXiDy+b`ti973^QjbHSj_#9*m=NjU z>pVHQ%PeVk{pim!*lMuIqHNUhqnBjVTW(bQ(cjKJs(ftsYH^%tQIQJnHhc4UFlLwx zwf~rM)U1ZtM_?tUioec(gyDB}^e?I`P5Rb1T{f~T=dh^k)nSK3jg&^sewFWNm8 zt@u=#FvW|0J3AJ2qJ!oGXkM_Z?1gT8#i5GZu6?w2aSK$s@zrSg*g=g!h;Hb_Ehmpx zoObekv`Z)BmB%~$kgVdARos`D5C7x5n+hG!5xpktt`6?u5h|?7w4N>gvRSOu>_uon zjnKHZ!Uz>>P=`Qz?xZtE{S6 z2jAp%S3p|axtTivzpjqO&(fZ<0yFI9AoC+Rb5Urur~D4k5~|>KUKp!Aej5ef`3 zb3BsdhBHB9qcQjaQu%hZC(GgFHgbQgT>kA?!v& zXOP=kW)f`jq>N26Y(i61aWPl1{#8td;fiLk7@ZphY;;c4H5R&KvFzZ2R#*&Mg%-&? zLsyGo{!X-xeK8xlx|f*%JKgVG7-?I>6F-O4ZQeL)@2>?t|sH%bH_o%`b~SSv(59 zBC_`zupE6vM5j(iud5rXI(mwojL}9u8t_4fJxIlu-%@e$D&4|l0;qg`!3<6^E*=YR zkrt$!5$_1`tT&h<`Rx?k#&eiw|6Z-M^@r!6Y0qd{sL{Jwv3o;jH{?>LR95b;GLU;f z#~2|W78k2Ogj{=^07L5*4Rx8Jbuwg3qoS}13Je}#QqXo&zv^+WM9-5z+6TL|s`gmw zHkiVGjNuwOW4f9t{T#Fge=>AdTSBH(2!%%7uw}gJhHjc50Ddl4;$la$j&vPV041mx zH1cnr4#lshKf0DZH&iD?E1^Dd98`!iBYgSCjiDp{2e)D&>^|2AONo4!U^)*fmorcy z3&COCi+L}Q4C`kl2H)ncP~t)?Rmklc=FV7fwKa71hIs6Oiuip354;YCEoTl_ofF4m z`g~bMXC;(WY$&lDGJaOXVR(D#QAD@tOIRX zoHDdIY?mP%)&`^sJ3gd}4N}7cV7(K7tTYhHT-g{i?N0t(3xt5Yk!^%J;~^0l;{`Wx zK_H}xCz7Dx2Rz6@-i3+8vnTLI>kwqF4pnvNU32D8)w4=^QIzz7Wt4=O!S~XAY(Daj zs@!)M1bUH|V&;QLRkV9koNbE&Oi{v0Dpk`RRQ<5i1mPD7cqyi-&u^p2sK1qs;3Q4Zy z(a5nyA0}I3SZ8*v$*^3Km{p(7<&oQWeCp-L|I-E=|FLilXTg>WT&HAN=7efEgSRZO z%VldUFz5(_SZ5e?gh6yo?TOstpwPfWs%zu8X^E&g`4meu8?8bG26+_A41?^JX4MNS z=P-}5#!b_*%fxRk!B8w9=?nO23F}Uw?V3u8Ex;r*Tg*W-6nsnEG|d^|7XU*@5cA;j=7EF$S@ds-tF6IVo>xKYWH0YEUfzXQi}*asmejjBS~Ff#oAB`j3+GaW zU5P=?!#y}Dagv^wvP4c;))(BoxJY%?4hMy-<=E&C<_gQhc0o9M$^;3g{P2kl+&;vl zgEa-&hzsW`0;mKP6+$!lRXP{GG$oz!PcH~eAS8|3g@w64h~*$7vXR&d8{3MOU`R$a zoJo=YGSwi2FH#Ld9!@#o_V=aDd~xp)={bw-{E5YczPULW&ox9#pmuW85~4YjGtqE1 zCfdu1_E3`+?Ma1PojSpTDcRgMEFdSNZCF55l%8Q>iL2hen1$uNRGd)dwULm@j>@EB z3ntacN#(k~NUDVAlsMD=kr1sHOZ2^0Jxh^QY^Au^5DcM9RR1)~Eh|3xBzi8v!AS~& zlkmaOtO}`_&{4H&{RYdV>Zb9d5H)hWA_MnAp*SsdAqkv%@sZb_e*E{(1G)~_3Q>Z; z|JV}@Vk8{GMgX0k5z`3pjM6%11@5*iClNf{lwnR}$}mUDFo(-93JmRPA?-SrdQVHe z2Lf$Yg1gerGgYp+k224l(XpH7kziJ)agd{=)HPDV2W-Jyg9rkta&THo>zO4M^wfK+ z7~^C@Zc#D+`1uR%??@?EDJ4Z#nkm!3yR4Mc#Ey#S(O3FtRBLL``U0gaMe_Ev{B!_eSiJn zbTYMW{Xp2LhewHv2KrxT{OACzB@ zTZErryanSw!+RCpk-dwE&GiF#7^>}UCe2#JcLd4IOl_Liha<@-P;3te(>nvcFGw#7 zT9nzdj5pJ;3UA(nKDcVAQ5U{z^#hZ&W^$m5!T7Dg|2Ar@wBri~z3CYUNaj&X_lBO0 z8|*To()7&C@VFV?(6wRPhK(0>_YU@sB;CoTExk$7yEz#d?%uYwwsBL^RA5kd#W!Fc5WOTd<4qn`1%tP>4e5;lki;P>m z(!nFUs6w0R;h!EImiKZrE^~_{bKlC^;#C+gI@cNt=Q;U}8Ii*P{1(eqHyZ-Ca$Zgz zG69c8*KPu~GHG3;A0B)sdzmXe$WwM%itCN&EZhUiYRmguq4ACI=68z!A6<(tBAGbL zU(s$D-j-chaxd4n=|LWHhgn$vHuPAy_*{UytzJ9Wzl@LDJ@ZRa17TaU`e%ssdv5bs z(btPHpg3N%*B}eQpTx!LuG&qQXyvommKN)>h-YPn=h`d-Sv_l^ABu49^8bF#=o z-|pF#?Z>kO-ufKg%kg8^w5C}mou9=t?t7AYxMlXRv4s1cWF&6oW2T2ONmQn1_u*do Wn#Opo{uyK)zOXjqnNPgk`29cKi}ip2 From b51ec84f203586e71990b0dafadbda11ec52422b Mon Sep 17 00:00:00 2001 From: Alex Mootz Date: Tue, 24 Oct 2023 09:11:42 -0400 Subject: [PATCH 3/6] test: update test suites with new package usage --- test-suites/Cargo.toml | 3 +- test-suites/src/lib.rs | 2 +- test-suites/src/liquidity_pool.rs | 6 ++-- test-suites/src/mock_oracle.rs | 19 ----------- test-suites/src/oracle.rs | 12 +++++++ test-suites/src/test_fixture.rs | 46 +++++++++++++++++++-------- test-suites/src/token.rs | 16 ++++------ test-suites/tests/test_liquidation.rs | 27 +++++++++++----- 8 files changed, 75 insertions(+), 56 deletions(-) delete mode 100644 test-suites/src/mock_oracle.rs create mode 100644 test-suites/src/oracle.rs diff --git a/test-suites/Cargo.toml b/test-suites/Cargo.toml index 2349b3e5..dcd39dee 100644 --- a/test-suites/Cargo.toml +++ b/test-suites/Cargo.toml @@ -18,6 +18,7 @@ pool = { path = "../pool", features = ["testutils"] } backstop = { path = "../backstop", features = ["testutils"] } pool-factory = { path = "../pool-factory", features = ["testutils"] } emitter = { path = "../emitter", features = ["testutils"] } -mock-oracle = { path = "../mocks/mock-oracle", features = ["testutils"] } mock-pool-factory = { path = "../mocks/mock-pool-factory", features = ["testutils"] } cast = { workspace = true } +sep-40-oracle = { workspace = true, features = ["testutils"] } +sep-41-token = { workspace = true, features = ["testutils"] } diff --git a/test-suites/src/lib.rs b/test-suites/src/lib.rs index c12d33c6..e32c4c4d 100644 --- a/test-suites/src/lib.rs +++ b/test-suites/src/lib.rs @@ -2,7 +2,7 @@ pub mod backstop; pub mod emitter; pub mod liquidity_pool; -pub mod mock_oracle; +pub mod oracle; pub mod pool; pub mod pool_factory; mod setup; diff --git a/test-suites/src/liquidity_pool.rs b/test-suites/src/liquidity_pool.rs index 3943e24a..7bc6148f 100644 --- a/test-suites/src/liquidity_pool.rs +++ b/test-suites/src/liquidity_pool.rs @@ -6,7 +6,7 @@ mod lp_contract { pub use lp_contract::{Client as LPClient, WASM as LP_WASM}; -use crate::token::TokenClient; +use sep_41_token::testutils::MockTokenClient; /// Deploy a test Comet LP pool of 80% token_1 / 20% token_2. The admin must be the /// admin of both of the token contracts used. @@ -26,8 +26,8 @@ pub(crate) fn create_lp_pool<'a>( e.register_contract_wasm(&contract_address, LP_WASM); let client = LPClient::new(e, &contract_address); - let token_1_client = TokenClient::new(e, token_1); - let token_2_client = TokenClient::new(e, token_2); + let token_1_client = MockTokenClient::new(e, token_1); + let token_2_client = MockTokenClient::new(e, token_2); token_1_client.mint(&admin, &1_000_0000000); token_2_client.mint(&admin, &25_0000000); token_1_client.approve(&admin, &contract_address, &1_000_0000000, &535670); diff --git a/test-suites/src/mock_oracle.rs b/test-suites/src/mock_oracle.rs deleted file mode 100644 index 3ffa56fd..00000000 --- a/test-suites/src/mock_oracle.rs +++ /dev/null @@ -1,19 +0,0 @@ -use soroban_sdk::{testutils::Address as _, Address, Env}; - -mod mock_blend_oracle_wasm { - soroban_sdk::contractimport!( - file = "../target/wasm32-unknown-unknown/release/mock_oracle.wasm" - ); -} - -use mock_oracle::{MockOracle, MockOracleClient}; - -pub fn create_mock_oracle<'a>(e: &Env, wasm: bool) -> (Address, MockOracleClient<'a>) { - let contract_id = Address::random(e); - if wasm { - e.register_contract_wasm(&contract_id, mock_blend_oracle_wasm::WASM); - } else { - e.register_contract(&contract_id, MockOracle {}); - } - (contract_id.clone(), MockOracleClient::new(e, &contract_id)) -} diff --git a/test-suites/src/oracle.rs b/test-suites/src/oracle.rs new file mode 100644 index 00000000..15a760c9 --- /dev/null +++ b/test-suites/src/oracle.rs @@ -0,0 +1,12 @@ +use soroban_sdk::{testutils::Address as _, Address, Env}; + +use sep_40_oracle::testutils::{MockPriceOracleClient, MockPriceOracleWASM}; + +pub fn create_mock_oracle<'a>(e: &Env) -> (Address, MockPriceOracleClient<'a>) { + let contract_id = Address::random(e); + e.register_contract_wasm(&contract_id, MockPriceOracleWASM); + ( + contract_id.clone(), + MockPriceOracleClient::new(e, &contract_id), + ) +} diff --git a/test-suites/src/test_fixture.rs b/test-suites/src/test_fixture.rs index 0f6196dc..1910365a 100644 --- a/test-suites/src/test_fixture.rs +++ b/test-suites/src/test_fixture.rs @@ -4,20 +4,21 @@ use std::ops::Index; use crate::backstop::create_backstop; use crate::emitter::create_emitter; use crate::liquidity_pool::{create_lp_pool, LPClient}; -use crate::mock_oracle::create_mock_oracle; +use crate::oracle::create_mock_oracle; use crate::pool::POOL_WASM; use crate::pool_factory::create_pool_factory; -use crate::token::{create_stellar_token, create_token, TokenClient}; +use crate::token::{create_stellar_token, create_token}; use backstop::BackstopClient; use emitter::EmitterClient; -use mock_oracle::MockOracleClient; use pool::{ PoolClient, PoolConfig, PoolDataKey, ReserveConfig, ReserveData, ReserveEmissionsConfig, ReserveEmissionsData, }; use pool_factory::{PoolFactoryClient, PoolInitMeta}; +use sep_40_oracle::testutils::{Asset, MockPriceOracleClient}; +use sep_41_token::testutils::MockTokenClient; use soroban_sdk::testutils::{Address as _, BytesN as _, Ledger, LedgerInfo}; -use soroban_sdk::{Address, BytesN, Env, Map, Symbol}; +use soroban_sdk::{vec as svec, Address, BytesN, Env, Map, Symbol}; pub const SCALAR_7: i128 = 1_000_0000; pub const SCALAR_9: i128 = 1_000_000_000; @@ -36,8 +37,8 @@ pub struct PoolFixture<'a> { pub reserves: HashMap, } -impl<'a> Index for Vec> { - type Output = TokenClient<'a>; +impl<'a> Index for Vec> { + type Output = MockTokenClient<'a>; fn index(&self, index: TokenIndex) -> &Self::Output { &self[index as usize] @@ -51,10 +52,10 @@ pub struct TestFixture<'a> { pub emitter: EmitterClient<'a>, pub backstop: BackstopClient<'a>, pub pool_factory: PoolFactoryClient<'a>, - pub oracle: MockOracleClient<'a>, + pub oracle: MockPriceOracleClient<'a>, pub lp: LPClient<'a>, pub pools: Vec>, - pub tokens: Vec>, + pub tokens: Vec>, } impl TestFixture<'_> { @@ -91,7 +92,6 @@ impl TestFixture<'_> { let (backstop_id, backstop_client) = create_backstop(&e, wasm); let (emitter_id, emitter_client) = create_emitter(&e, wasm); let (pool_factory_id, _) = create_pool_factory(&e, wasm); - let (_, mock_oracle_client) = create_mock_oracle(&e, wasm); // initialize emitter blnd_client.mint(&bombadil, &(10_000_000 * SCALAR_7)); @@ -114,11 +114,29 @@ impl TestFixture<'_> { pool_factory_client.initialize(&pool_init_meta); // initialize oracle - mock_oracle_client.set_price(&blnd_id, &(0_0500000)); - mock_oracle_client.set_price(ð_id, &(2000_0000000)); - mock_oracle_client.set_price(&usdc_id, &(1_0000000)); - mock_oracle_client.set_price(&xlm_id, &(0_1000000)); - mock_oracle_client.set_price(&stable_id, &(1_0000000)); + let (_, mock_oracle_client) = create_mock_oracle(&e); + mock_oracle_client.set_data( + &bombadil, + &Asset::Other(Symbol::new(&e, "USD")), + &svec![ + &e, + Asset::Stellar(blnd_id.clone()), + Asset::Stellar(eth_id.clone()), + Asset::Stellar(usdc_id), + Asset::Stellar(xlm_id.clone()), + Asset::Stellar(stable_id.clone()) + ], + &7, + &300, + ); + mock_oracle_client.set_price_stable(&svec![ + &e, + 0_0500000, // blnd + 2000_0000000, // eth + 1_0000000, // usdc + 0_1000000, // xlm + 1_0000000 // stable + ]); // pass 1 day e.ledger().set(LedgerInfo { diff --git a/test-suites/src/token.rs b/test-suites/src/token.rs index 16a7f6c7..8984d809 100644 --- a/test-suites/src/token.rs +++ b/test-suites/src/token.rs @@ -1,13 +1,9 @@ +use sep_41_token::testutils::{MockTokenClient, MockTokenWASM}; use soroban_sdk::{testutils::Address as _, Address, Env, IntoVal}; -mod token_contract { - soroban_sdk::contractimport!(file = "../soroban_token_contract.wasm"); -} -pub use token_contract::{Client as TokenClient, WASM as TOKEN_WASM}; - -pub fn create_stellar_token<'a>(e: &Env, admin: &Address) -> (Address, TokenClient<'a>) { +pub fn create_stellar_token<'a>(e: &Env, admin: &Address) -> (Address, MockTokenClient<'a>) { let contract_id = e.register_stellar_asset_contract(admin.clone()); - let client = TokenClient::new(e, &contract_id); + let client = MockTokenClient::new(e, &contract_id); // set admin to bump instance client.set_admin(admin); (contract_id, client) @@ -18,10 +14,10 @@ pub fn create_token<'a>( admin: &Address, decimals: u32, symbol: &str, -) -> (Address, TokenClient<'a>) { +) -> (Address, MockTokenClient<'a>) { let contract_id = Address::random(e); - e.register_contract_wasm(&contract_id, TOKEN_WASM); - let client = TokenClient::new(e, &contract_id); + e.register_contract_wasm(&contract_id, MockTokenWASM); + let client = MockTokenClient::new(e, &contract_id); client.initialize( admin, &decimals, diff --git a/test-suites/tests/test_liquidation.rs b/test-suites/tests/test_liquidation.rs index b707a6af..dc356230 100644 --- a/test-suites/tests/test_liquidation.rs +++ b/test-suites/tests/test_liquidation.rs @@ -369,11 +369,17 @@ fn test_liquidations() { ) ] ); + //tank eth price - fixture.oracle.set_price( - &fixture.tokens[TokenIndex::WETH].address.clone(), - &(500 * SCALAR_7), - ); + fixture.oracle.set_price_stable(&vec![ + &fixture.env, + 0_0500000, // blnd + 500_0000000, // eth + 1_0000000, // usdc + 0_1000000, // xlm + 1_0000000, // stable + ]); + //fully liquidate user let blank_requests: Vec = vec![&fixture.env]; pool_fixture @@ -742,11 +748,16 @@ fn test_liquidations() { let sam_positions = pool_fixture .pool .submit(&samwise, &samwise, &samwise, &sam_requests); + // Nuke eth price more - fixture.oracle.set_price( - &fixture.tokens[TokenIndex::WETH].address.clone(), - &(10 * SCALAR_7), - ); + fixture.oracle.set_price_stable(&vec![ + &fixture.env, + 0_0500000, // blnd + 10_0000000, // eth + 1_0000000, // usdc + 0_1000000, // xlm + 1_0000000, // stable + ]); // Liquidate sam let liq_pct: u64 = 100; From bb606c05de724c7ceb0d6acc19f15f5e59e6ae2e Mon Sep 17 00:00:00 2001 From: Alex Mootz Date: Tue, 24 Oct 2023 09:12:48 -0400 Subject: [PATCH 4/6] interfaces: add no_std attribute --- Cargo.lock | 2 +- blend-interfaces/Cargo.toml | 2 +- blend-interfaces/src/lib.rs | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6bd2cef6..85502fea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,7 +105,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "blend-interfaces" -version = "0.0.1" +version = "0.0.2" dependencies = [ "soroban-sdk", ] diff --git a/blend-interfaces/Cargo.toml b/blend-interfaces/Cargo.toml index 3545a558..eb1abe76 100644 --- a/blend-interfaces/Cargo.toml +++ b/blend-interfaces/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blend-interfaces" -version = "0.0.1" +version = "0.0.2" description = "Traits, clients, and types for the Blend Protocol" homepage = "https://github.com/blend-capital/blend-contracts" repository = "https://github.com/blend-capital/blend-contracts" diff --git a/blend-interfaces/src/lib.rs b/blend-interfaces/src/lib.rs index 6c5bff74..f1dae0d2 100644 --- a/blend-interfaces/src/lib.rs +++ b/blend-interfaces/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + pub mod backstop; pub mod emitter; pub mod pool; From c0bc0c75786a7b6a73424b171bc2d2f6408e54a0 Mon Sep 17 00:00:00 2001 From: Alex Mootz Date: Tue, 24 Oct 2023 09:55:13 -0400 Subject: [PATCH 5/6] ci: fix makefile and remove dead code --- Cargo.lock | 7 ------ Cargo.toml | 1 - Makefile | 2 -- mocks/mock-pool/Cargo.toml | 20 ----------------- mocks/mock-pool/src/lib.rs | 9 -------- mocks/mock-pool/src/pool.rs | 41 ---------------------------------- mocks/mock-pool/src/storage.rs | 22 ------------------ 7 files changed, 102 deletions(-) delete mode 100644 mocks/mock-pool/Cargo.toml delete mode 100644 mocks/mock-pool/src/lib.rs delete mode 100644 mocks/mock-pool/src/pool.rs delete mode 100644 mocks/mock-pool/src/storage.rs diff --git a/Cargo.lock b/Cargo.lock index 85502fea..37485d83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -642,13 +642,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mock-pool" -version = "0.0.0" -dependencies = [ - "soroban-sdk", -] - [[package]] name = "mock-pool-factory" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index ac80b475..f018e664 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,6 @@ members = [ "blend-interfaces", "emitter", "pool", - "mocks/mock-pool", "mocks/mock-pool-factory", "pool-factory", "test-suites" diff --git a/Makefile b/Makefile index 76b0fbf3..6a166833 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,6 @@ test: build cargo test --all --tests build: - cargo rustc --manifest-path=mocks/mock-pool/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release - cargo rustc --manifest-path=mocks/mock-oracle/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release cargo rustc --manifest-path=pool-factory/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release cargo rustc --manifest-path=backstop/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release cargo rustc --manifest-path=emitter/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release diff --git a/mocks/mock-pool/Cargo.toml b/mocks/mock-pool/Cargo.toml deleted file mode 100644 index 8f5a5a3c..00000000 --- a/mocks/mock-pool/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "mock-pool" -version = "0.0.0" -authors = ["Blend Capital "] -license = "AGPL-3.0" -edition = "2021" -publish = false - -[lib] -crate-type = ["cdylib", "rlib"] -doctest = false - -[features] -testutils = ["soroban-sdk/testutils"] - -[dependencies] -soroban-sdk = { workspace = true } - -[dev_dependencies] -soroban-sdk = { workspace = true, features = ["testutils"] } \ No newline at end of file diff --git a/mocks/mock-pool/src/lib.rs b/mocks/mock-pool/src/lib.rs deleted file mode 100644 index b8931d5a..00000000 --- a/mocks/mock-pool/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![no_std] - -#[cfg(any(test, feature = "testutils"))] -extern crate std; - -mod pool; -mod storage; - -pub use pool::*; diff --git a/mocks/mock-pool/src/pool.rs b/mocks/mock-pool/src/pool.rs deleted file mode 100644 index 58470f8e..00000000 --- a/mocks/mock-pool/src/pool.rs +++ /dev/null @@ -1,41 +0,0 @@ -use crate::storage; -use soroban_sdk::{contract, contractimpl, Address, Env}; - -#[contract] -pub struct MockLendingPool; - -pub trait MockLendingPoolTrait { - /// Fetch the reserve usage configuration for a user - /// - /// ### Arguments - /// * `user` - The Address to fetch the reserve usage for - fn config(e: Env, user: Address) -> i128; - - /// Mock Only: Set the collateral usage for a user - /// - /// ### Arguments - /// * `user` - The Address to set the reserve usage configuration for - /// * `index` - The index of the reserve to update - /// * `is_collat` - True if its used as collateral, false if not (default is true) - fn set_collat(e: Env, user: Address, index: u32, is_collat: bool); -} - -#[contractimpl] -impl MockLendingPoolTrait for MockLendingPool { - fn config(e: Env, user: Address) -> i128 { - storage::read_config(&e, &user) - } - - fn set_collat(e: Env, user: Address, index: u32, is_collat: bool) { - let mut config = storage::read_config(&e, &user); - let res_collateral_bit = 1 << (index * 3 + 2); - if !is_collat { - // set bit to 1 - config |= res_collateral_bit; - } else { - // set bit to zero - config &= !res_collateral_bit; - } - storage::write_config(&e, &user, &config); - } -} diff --git a/mocks/mock-pool/src/storage.rs b/mocks/mock-pool/src/storage.rs deleted file mode 100644 index 921f2f4a..00000000 --- a/mocks/mock-pool/src/storage.rs +++ /dev/null @@ -1,22 +0,0 @@ -use soroban_sdk::{contracttype, Address, Env}; - -#[derive(Clone)] -#[contracttype] -pub enum MockPoolDataKey { - Config(Address), -} - -pub fn read_config(e: &Env, user: &Address) -> i128 { - let key = MockPoolDataKey::Config(user.clone()); - e.storage() - .persistent() - .get::(&key) - .unwrap_or(0) -} - -pub fn write_config(e: &Env, user: &Address, config: &i128) { - let key = MockPoolDataKey::Config(user.clone()); - e.storage() - .persistent() - .set::(&key, config); -} From b6a4063241aaaf6394a51579dc55c3e3c4aa8544 Mon Sep 17 00:00:00 2001 From: Alex Mootz Date: Wed, 25 Oct 2023 15:59:45 -0400 Subject: [PATCH 6/6] chore: fmt --- emitter/src/emitter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emitter/src/emitter.rs b/emitter/src/emitter.rs index 9270be55..c8d78bb3 100644 --- a/emitter/src/emitter.rs +++ b/emitter/src/emitter.rs @@ -55,7 +55,7 @@ pub fn execute_drop(e: &Env) -> Map { if drop_amount > 50_000_000 * SCALAR_7 { panic_with_error!(e, EmitterError::BadDrop); } - + let blnd_id = storage::get_blend_id(e); let blnd_client = StellarAssetClient::new(e, &blnd_id); for (addr, amt) in drop_list.iter() {