From c708725da4664dd1be6facbd0096c0d0876d0862 Mon Sep 17 00:00:00 2001 From: mootz12 Date: Mon, 1 Apr 2024 13:59:25 -0400 Subject: [PATCH] chore: update to soroban 20.5 and up the mock contract storage ttl --- Cargo.lock | 50 ++++++++--------- Cargo.toml | 2 +- mock-sep-40/src/storage.rs | 6 ++- sep-40/Cargo.toml | 2 +- sep-40/README.md | 54 +++++++++++++++++++ sep-40/src/testutils/mock_sep_40_oracle.wasm | Bin 11176 -> 11197 bytes 6 files changed, 85 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c5a7d20..03da1d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -849,7 +849,7 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "sep-40-oracle" -version = "0.2.0" +version = "1.0.0" dependencies = [ "soroban-sdk", ] @@ -953,9 +953,9 @@ checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "soroban-builtin-sdk-macros" -version = "20.0.0" +version = "20.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42487d6b0268748f753feeb579c6f7908dbb002faf20b703e6a7185b12f0527" +checksum = "7cc32c6e817f3ca269764ec0d7d14da6210b74a5bf14d4e745aa3ee860558900" dependencies = [ "itertools", "proc-macro2", @@ -965,9 +965,9 @@ dependencies = [ [[package]] name = "soroban-env-common" -version = "20.0.0" +version = "20.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb493483fa3e3ebfb4c081472495d14b0abcfbe04ba142a56ff63056cc62700" +checksum = "c14e18d879c520ff82612eaae0590acaf6a7f3b977407e1abb1c9e31f94c7814" dependencies = [ "arbitrary", "crate-git-revision", @@ -983,9 +983,9 @@ dependencies = [ [[package]] name = "soroban-env-guest" -version = "20.0.0" +version = "20.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f31a738ef5faf4084c4b1824a8e3f93dfff0261a3909e86060f818e728479a3" +checksum = "5122ca2abd5ebcc1e876a96b9b44f87ce0a0e06df8f7c09772ddb58b159b7454" dependencies = [ "soroban-env-common", "static_assertions", @@ -993,9 +993,9 @@ dependencies = [ [[package]] name = "soroban-env-host" -version = "20.0.0" +version = "20.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdd1172a76c0bc2ce67ec7f28ca37dddbe9fefabe583f80434f5f60aaee3547e" +checksum = "114a0fa0d0cc39d0be16b1ee35b6e5f4ee0592ddcf459bde69391c02b03cf520" dependencies = [ "backtrace", "curve25519-dalek", @@ -1020,9 +1020,9 @@ dependencies = [ [[package]] name = "soroban-env-macros" -version = "20.0.0" +version = "20.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c0536648cea69ab3bae1801d35f92c0a31e7449cd2c7d14a18fb5e413f43279" +checksum = "b13e3f8c86f812e0669e78fcb3eae40c385c6a9dd1a4886a1de733230b4fcf27" dependencies = [ "itertools", "proc-macro2", @@ -1035,9 +1035,9 @@ dependencies = [ [[package]] name = "soroban-ledger-snapshot" -version = "20.0.0" +version = "20.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37960eec21d7dc5dbd976fa16e38c056429663a89243798486b07afbb263c9b5" +checksum = "61a54708f44890e0546180db6b4f530e2a88d83b05a9b38a131caa21d005e25a" dependencies = [ "serde", "serde_json", @@ -1049,9 +1049,9 @@ dependencies = [ [[package]] name = "soroban-sdk" -version = "20.0.0" +version = "20.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f08e1fdb18dbee88160ea6640962faf021a49f22eb1bd212c4d8b0cef32c582c" +checksum = "84fc8be9068dd4e0212d8b13ad61089ea87e69ac212c262914503a961c8dc3a3" dependencies = [ "arbitrary", "bytes-lit", @@ -1069,9 +1069,9 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" -version = "20.0.0" +version = "20.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5cae44f304f2fd32f9cfa9a31a9b58eb1c10aa07a7d5b591921cf7fa649e44" +checksum = "db20def4ead836663633f58d817d0ed8e1af052c9650a04adf730525af85b964" dependencies = [ "crate-git-revision", "darling", @@ -1089,9 +1089,9 @@ dependencies = [ [[package]] name = "soroban-spec" -version = "20.0.0" +version = "20.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7539cfa0abe36f3d33c49fe1253f6b652c91c9a9841fe83dedc1799b7f4bb55f" +checksum = "3eefeb5d373b43f6828145d00f0c5cc35e96db56a6671ae9614f84beb2711cab" dependencies = [ "base64 0.13.1", "stellar-xdr", @@ -1101,9 +1101,9 @@ dependencies = [ [[package]] name = "soroban-spec-rust" -version = "20.0.0" +version = "20.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb6189ef3ede0061db14b0cf9fa2692a2cb6c6e8d941689f0c9ca82b68c47ab2" +checksum = "3152bca4737ef734ac37fe47b225ee58765c9095970c481a18516a2b287c7a33" dependencies = [ "prettyplease", "proc-macro2", @@ -1117,9 +1117,9 @@ dependencies = [ [[package]] name = "soroban-wasmi" -version = "0.31.1-soroban.20.0.0" +version = "0.31.1-soroban.20.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1aaa682a67cbd2173f1d60cb1e7b951d490d7c4e0b7b6f5387cbb952e963c46" +checksum = "710403de32d0e0c35375518cb995d4fc056d0d48966f2e56ea471b8cb8fc9719" dependencies = [ "smallvec", "spin", @@ -1163,9 +1163,9 @@ dependencies = [ [[package]] name = "stellar-xdr" -version = "20.0.0" +version = "20.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9595b775539e475da4179fa46212b11e4575f526d57b13308989a8c1dd59238c" +checksum = "e59cdf3eb4467fb5a4b00b52e7de6dca72f67fac6f9b700f55c95a5d86f09c9d" dependencies = [ "arbitrary", "base64 0.13.1", diff --git a/Cargo.toml b/Cargo.toml index d2e0c89..5b5a52c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,4 +21,4 @@ codegen-units = 1 lto = true [workspace.dependencies.soroban-sdk] -version = "20.0.0" +version = "20.5.0" diff --git a/mock-sep-40/src/storage.rs b/mock-sep-40/src/storage.rs index 81ab330..4ebfb90 100644 --- a/mock-sep-40/src/storage.rs +++ b/mock-sep-40/src/storage.rs @@ -3,8 +3,10 @@ use soroban_sdk::{panic_with_error, unwrap::UnwrapOptimized, Address, Env, Symbo use crate::error::PriceOracleError; -pub(crate) const LEDGER_THRESHOLD: u32 = 120960; // 7 days at 5s a block -pub(crate) const LEDGER_BUMP: u32 = 138240; // 8 days at 5s a block +const ONE_DAY_LEDGERS: u32 = 17280; // assumes 5s a ledger + +const LEDGER_THRESHOLD: u32 = ONE_DAY_LEDGERS * 30; // ~ 30 days +const LEDGER_BUMP: u32 = LEDGER_THRESHOLD + ONE_DAY_LEDGERS; // ~ 31 days pub fn extend_instance(env: &Env) { env.storage() diff --git a/sep-40/Cargo.toml b/sep-40/Cargo.toml index ce21f08..4e86379 100644 --- a/sep-40/Cargo.toml +++ b/sep-40/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sep-40-oracle" -version = "0.2.0" +version = "1.0.0" description = "SEP-0040 Price Feed Oracle trait, client, and mock implementation" authors = ["Script3 "] repository = "https://github.com/script3/sep-40-oracle" diff --git a/sep-40/README.md b/sep-40/README.md index e0f0f84..05cc8db 100644 --- a/sep-40/README.md +++ b/sep-40/README.md @@ -3,6 +3,11 @@ Exposes the interface of the SEP-0040 Price Feed Oracle alongside a test price o SEP-0040 Definition: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0040.md +## Safety +This is **experimental software** and is provided on an "as is" and "as available" basis. + +We do **not give any warranties** and **will not be liable for any loss** incurred through any use of this codebase. + ## Getting Started Add the package to your `Cargo.toml`: @@ -18,3 +23,52 @@ You can optionally include the `testutils` feature in your `dev-dependencies` to [dev_dependencies] sep-40-oracle = { version = "", features = ["testutils"] } ``` + +### Client and Trait +This package exposes a client for interacting with SEP-0040 Oracles and a trait for contracts wishing to implement a SEP-0040 Oracle. + +Client usage: +```rust +use sep_40_oracle::PriceFeedClient; + +let address = // address of the oracle +let price_feed_client = PriceFeedClient::new(&env, &address); +``` + +Trait usage: +```rust +use sep_40_oracle::PriceFeedTrait; +use soroban_sdk::{contract, contractimpl}; + +#[contract] +pub struct MyPriceFeed; + +#[contractimpl] +impl PriceFeedTrait for MyPriceFeed { + // impl the trait functions +} +``` + +### Mock PriceFeed Oracle +This package exposes an example Soroban price feed oracle implementation. This is useful for testing protocols that depend on a `sep-0040` price feed oracle, including the ability to manipulate price feeds during a test. + +A WASM version of the contract can be deployed as follows: +```rust +use sep_40_oracle::testutils::{MockPriceOracleClient, MockPriceOracleWASM}; +use soroban_sdk::{testutils::Address as _, Address, Env, symbol_short, vec}; + +let env = Env::default(); + + +let admin = Address::generate(&env); +let xlm = Address::generate(&env); +let oracle_id = env.register_contract_wasm(None, MockTokenWASM); +let oracle_client = MockPriceOracleClient::new(&env, &oracle_id); +oracle_client.set_data( + &admin, + &Asset::Other(symbol_short!("TEAPOT")), + &vec![&env, Asset::Stellar(xlm)], + &7, + &(5 * 60 * 60) +); +``` \ No newline at end of file diff --git a/sep-40/src/testutils/mock_sep_40_oracle.wasm b/sep-40/src/testutils/mock_sep_40_oracle.wasm index 443f3aeec02c5a60e1c01e310ebaaea11d35c65b..421271a998be238808897d9473962c12f5ac32d4 100644 GIT binary patch delta 265 zcmZ1xzBhb>5EE0M<75%0r_2+&SvLP+5@2Mysj!)krIL~9lKkXO);yjCznGm`8h`+# zfSFC55v)>|{f%J#Iz}eudd4~?2L(n)PH$cY1x7_?1qMYHW(Ngk76+z!M@9t}T?Pgv zCdc~>ZoCXq3QUd$*^d7i3mv)qSsZ}8gA5R^6omT_%9ZryWd+JwXY(*|18LK29!3zY zm(9J_=|5w$0;>~STZZxA7DvV`MHZkUZUxrO(>YC~qC|jl)B^w(U n86}w*o0=vW8JQ%SCt4Vqq#7D0C7K$Vn;E92CK;L}B{2X1<#s^G delta 244 zcmdlRz9M{s5EIi+hsh#LPnjFq88`o75@2N7!LgZ-rIL|pBm3k|);yjG-x!=)8bAQ3 zfSFC55v)>|{f%J#OhzWAI;MIi2WAHaMg6075V z1~*;?DFxQGicAWujt1F|T>e0%td0j6vK^%$%!fdxq&F|C0+W+