diff --git a/Cargo.lock b/Cargo.lock
index 75a3b200..37485d83 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -54,6 +54,7 @@ dependencies = [
"cast",
"fixed-point-math",
"mock-pool-factory",
+ "sep-41-token",
"soroban-sdk",
]
@@ -104,7 +105,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]]
name = "blend-interfaces"
-version = "0.0.1"
+version = "0.0.2"
dependencies = [
"soroban-sdk",
]
@@ -401,6 +402,7 @@ name = "emitter"
version = "0.0.1"
dependencies = [
"backstop",
+ "sep-41-token",
"soroban-sdk",
]
@@ -640,21 +642,6 @@ dependencies = [
"adler",
]
-[[package]]
-name = "mock-oracle"
-version = "0.0.0"
-dependencies = [
- "oracle",
- "soroban-sdk",
-]
-
-[[package]]
-name = "mock-pool"
-version = "0.0.0"
-dependencies = [
- "soroban-sdk",
-]
-
[[package]]
name = "mock-pool-factory"
version = "0.0.0"
@@ -720,13 +707,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 +736,9 @@ dependencies = [
"backstop",
"cast",
"fixed-point-math",
- "mock-oracle",
"mock-pool-factory",
- "oracle",
+ "sep-40-oracle",
+ "sep-41-token",
"soroban-sdk",
]
@@ -926,6 +906,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 +1268,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..f018e664 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,10 +6,7 @@ members = [
"blend-interfaces",
"emitter",
"pool",
- "mocks/mock-oracle",
- "mocks/mock-pool",
"mocks/mock-pool-factory",
- "oracle",
"pool-factory",
"test-suites"
]
@@ -37,3 +34,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/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/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 bddf32f0..ba936c42 100644
--- a/backstop/src/backstop/withdrawal.rs
+++ b/backstop/src/backstop/withdrawal.rs
@@ -1,9 +1,5 @@
-use crate::{
- contract::require_nonnegative,
- dependencies::TokenClient,
- emissions::{self},
- 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 d744890c..c5695aad 100644
--- a/backstop/src/emissions/claim.rs
+++ b/backstop/src/emissions/claim.rs
@@ -1,9 +1,6 @@
-use crate::{
- dependencies::{CometClient, TokenClient},
- errors::BackstopError,
- storage,
-};
+use crate::{dependencies::CometClient, errors::BackstopError, storage};
use fixed_point_math::FixedPoint;
+use sep_41_token::TokenClient;
use soroban_sdk::{panic_with_error, Address, Env, Map, Symbol, Vec};
use super::update_emissions;
diff --git a/backstop/src/emissions/manager.rs b/backstop/src/emissions/manager.rs
index 6a58d019..6fa74477 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/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;
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 5f99cf99..c8d78bb3 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
@@ -47,11 +43,9 @@ pub fn execute_drop(e: &Env) -> Map
{
// Check that the last fork was at least 45 days ago
panic_with_error!(e, EmitterError::BadDrop);
}
+
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() {
@@ -61,8 +55,11 @@ 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() {
- backstop_token_client.mint(&addr, &amt);
+ blnd_client.mint(&addr, &amt);
}
storage::set_drop_status(e, true);
drop_list
@@ -77,6 +74,7 @@ mod tests {
};
use super::*;
+ use sep_41_token::testutils::MockTokenClient;
use soroban_sdk::{
map,
testutils::{Address as _, Ledger, LedgerInfo},
@@ -102,7 +100,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);
@@ -138,7 +136,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,
@@ -185,7 +183,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,
@@ -206,10 +204,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,
@@ -222,14 +221,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),
@@ -237,8 +235,8 @@ mod tests {
];
backstop_client.initialize(
- &backstop_token,
&Address::random(&e),
+ &blnd_id,
&Address::random(&e),
&Address::random(&e),
&drop_list,
@@ -247,17 +245,15 @@ 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);
storage::set_last_fork(&e, 4000000);
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);
});
}
@@ -278,13 +274,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),
@@ -292,8 +287,8 @@ mod tests {
];
backstop_client.initialize(
- &backstop_token,
&Address::random(&e),
+ &blnd_id,
&Address::random(&e),
&Address::random(&e),
&drop_list,
@@ -302,6 +297,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);
storage::set_last_fork(&e, 4000000);
@@ -327,13 +323,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),
@@ -341,8 +336,8 @@ mod tests {
];
backstop_client.initialize(
- &backstop_token,
&Address::random(&e),
+ &blnd_id,
&Address::random(&e),
&Address::random(&e),
&drop_list,
@@ -351,6 +346,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);
storage::set_last_fork(&e, 4000000);
@@ -363,7 +359,7 @@ mod tests {
#[should_panic(expected = "Error(Contract, #40)")]
fn test_drop_bad_block() {
let e = Env::default();
- e.mock_all_auths_allowing_non_root_auth();
+ e.mock_all_auths();
e.ledger().set(LedgerInfo {
timestamp: 12345,
@@ -382,7 +378,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),
@@ -390,8 +386,8 @@ mod tests {
];
backstop_client.initialize(
- &backstop_token,
&Address::random(&e),
+ &blnd_id,
&Address::random(&e),
&Address::random(&e),
&drop_list,
@@ -400,6 +396,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_last_fork(&e, 5000000);
storage::set_drop_status(&e, false);
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/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);
-}
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 e0a9add2..00000000
Binary files a/soroban_token_contract.wasm and /dev/null differ
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 fb8b6474..ba078a2e 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, &5356700);
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 47e5df51..596199fc 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;