diff --git a/.gitignore b/.gitignore index 212de44..8604f63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -.DS_Store \ No newline at end of file +.DS_Store +test_snapshots/ \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 368c923..c5a7d20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,9 +34,9 @@ dependencies = [ [[package]] name = "arbitrary" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2e1373abdaa212b704512ec2bd8b26bd0b7d5c3f70117411a5d9a451383c859" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" dependencies = [ "derive_arbitrary", ] @@ -296,9 +296,9 @@ dependencies = [ [[package]] name = "derive_arbitrary" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e0efad4403bfc52dc201159c4b842a246a14b98c64b55dfd0f2d89729dfeb8" +checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", @@ -392,11 +392,17 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "escape-bytes" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bfcf67fea2815c2fc3b90873fae90957be12ff417335dfadc7f52927feb03b2" + [[package]] name = "ethnum" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8ff382b2fa527fb7fb06eeebfc5bbb3f17e3cc6b9d70b006c41daa8824adac" +checksum = "b90ca2580b73ab6a1f724b76ca11ab632df820fd6040c336200d2c1df7b3c82c" [[package]] name = "ff" @@ -433,9 +439,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" dependencies = [ "cfg-if", "js-sys", @@ -482,6 +488,12 @@ dependencies = [ "serde", ] +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + [[package]] name = "hmac" version = "0.12.1" @@ -550,9 +562,9 @@ checksum = "8e04e2fd2b8188ea827b32ef11de88377086d690286ab35747ef7f9bf3ccb590" [[package]] name = "itertools" -version = "0.10.5" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" dependencies = [ "either", ] @@ -630,7 +642,7 @@ dependencies = [ [[package]] name = "mock-sep-40-oracle" -version = "0.1.1" +version = "0.2.0" dependencies = [ "sep-40-oracle", "soroban-sdk", @@ -837,25 +849,25 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "sep-40-oracle" -version = "0.1.1" +version = "0.2.0" dependencies = [ "soroban-sdk", ] [[package]] name = "serde" -version = "1.0.189" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" +checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.189" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" +checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" dependencies = [ "proc-macro2", "quote", @@ -864,9 +876,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" dependencies = [ "itoa", "ryu", @@ -939,11 +951,23 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +[[package]] +name = "soroban-builtin-sdk-macros" +version = "20.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42487d6b0268748f753feeb579c6f7908dbb002faf20b703e6a7185b12f0527" +dependencies = [ + "itertools", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "soroban-env-common" -version = "20.0.0-rc2" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2508a41765935d3bef43b2264667c4603725cf7ddd851321f1dc2b3bca8bb88" +checksum = "5bb493483fa3e3ebfb4c081472495d14b0abcfbe04ba142a56ff63056cc62700" dependencies = [ "arbitrary", "crate-git-revision", @@ -959,9 +983,9 @@ dependencies = [ [[package]] name = "soroban-env-guest" -version = "20.0.0-rc2" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b41f1b3ebb747487ff9920822112a5816030e053734ed63c05f1a7db476f2768" +checksum = "3f31a738ef5faf4084c4b1824a8e3f93dfff0261a3909e86060f818e728479a3" dependencies = [ "soroban-env-common", "static_assertions", @@ -969,13 +993,16 @@ dependencies = [ [[package]] name = "soroban-env-host" -version = "20.0.0-rc2" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "347fc729270de2fc8e312ba1872ef90fdc8dfcd0dacdd07a3bb7a038c41ea6d6" +checksum = "bdd1172a76c0bc2ce67ec7f28ca37dddbe9fefabe583f80434f5f60aaee3547e" dependencies = [ "backtrace", + "curve25519-dalek", "ed25519-dalek", "getrandom", + "hex-literal", + "hmac", "k256", "num-derive", "num-integer", @@ -984,8 +1011,8 @@ dependencies = [ "rand_chacha", "sha2", "sha3", + "soroban-builtin-sdk-macros", "soroban-env-common", - "soroban-native-sdk-macros", "soroban-wasmi", "static_assertions", "stellar-strkey", @@ -993,9 +1020,9 @@ dependencies = [ [[package]] name = "soroban-env-macros" -version = "20.0.0-rc2" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f16b7a75d77ae47143a07f92a35661c21e965f63bb4362d8491188a993687745" +checksum = "5c0536648cea69ab3bae1801d35f92c0a31e7449cd2c7d14a18fb5e413f43279" dependencies = [ "itertools", "proc-macro2", @@ -1008,40 +1035,31 @@ dependencies = [ [[package]] name = "soroban-ledger-snapshot" -version = "20.0.0-rc2" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d202c5870aeec1cb97bfd06a94b8fe691c513ba6da8638deb07d8660e90056ba" +checksum = "37960eec21d7dc5dbd976fa16e38c056429663a89243798486b07afbb263c9b5" dependencies = [ "serde", "serde_json", + "serde_with", "soroban-env-common", "soroban-env-host", "thiserror", ] -[[package]] -name = "soroban-native-sdk-macros" -version = "20.0.0-rc2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe8cf96e5c9308347bc6fa0735d0591475a20b43ed00f96ad2df623bbe9c1e88" -dependencies = [ - "itertools", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "soroban-sdk" -version = "20.0.0-rc2" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d771d43a66ba0df14ff28ac1b37a6568da00afa12f28273a67fe92853ab28f8" +checksum = "f08e1fdb18dbee88160ea6640962faf021a49f22eb1bd212c4d8b0cef32c582c" dependencies = [ "arbitrary", "bytes-lit", "ctor", "ed25519-dalek", "rand", + "serde", + "serde_json", "soroban-env-guest", "soroban-env-host", "soroban-ledger-snapshot", @@ -1051,9 +1069,9 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" -version = "20.0.0-rc2" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5a6dd2e08217fdd75f3f849256dda2614badda9095df233a47c7c8f9783493" +checksum = "6c5cae44f304f2fd32f9cfa9a31a9b58eb1c10aa07a7d5b591921cf7fa649e44" dependencies = [ "crate-git-revision", "darling", @@ -1071,9 +1089,9 @@ dependencies = [ [[package]] name = "soroban-spec" -version = "20.0.0-rc2" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e2a55aab81d7cd1df66f85de3d815fb08fc5fa412270dc374e031e27528c711" +checksum = "7539cfa0abe36f3d33c49fe1253f6b652c91c9a9841fe83dedc1799b7f4bb55f" dependencies = [ "base64 0.13.1", "stellar-xdr", @@ -1083,9 +1101,9 @@ dependencies = [ [[package]] name = "soroban-spec-rust" -version = "20.0.0-rc2" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bcfa549d3362e6eafa3a51ad29d571f3dbae2cb9fe33d9f94c00a9f742f71df" +checksum = "eb6189ef3ede0061db14b0cf9fa2692a2cb6c6e8d941689f0c9ca82b68c47ab2" dependencies = [ "prettyplease", "proc-macro2", @@ -1099,9 +1117,9 @@ dependencies = [ [[package]] name = "soroban-wasmi" -version = "0.31.0-soroban1" +version = "0.31.1-soroban.20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b6e3e79c1f227ec98ea1e8fbf43d0267b9ca748616c9c8c0162fa2a8ca4d5d2" +checksum = "c1aaa682a67cbd2173f1d60cb1e7b951d490d7c4e0b7b6f5387cbb952e963c46" dependencies = [ "smallvec", "spin", @@ -1134,26 +1152,29 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "stellar-strkey" -version = "0.0.7" +version = "0.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c0689070126ca7f2effc2c5726584446db52190f0cef043c02eb4040a711c11" +checksum = "12d2bf45e114117ea91d820a846fd1afbe3ba7d717988fee094ce8227a3bf8bd" dependencies = [ "base32", + "crate-git-revision", "thiserror", ] [[package]] name = "stellar-xdr" -version = "20.0.0-rc1" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e09a3734914a7427dbcd4f06b6dcd2b1cf38e934202f6abe4d73658f718b6113" +checksum = "9595b775539e475da4179fa46212b11e4575f526d57b13308989a8c1dd59238c" dependencies = [ "arbitrary", "base64 0.13.1", "crate-git-revision", + "escape-bytes", "hex", "serde", "serde_with", + "stellar-strkey", ] [[package]] @@ -1170,9 +1191,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" -version = "2.0.38" +version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 86ba422..d2e0c89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,4 +21,4 @@ codegen-units = 1 lto = true [workspace.dependencies.soroban-sdk] -version = "20.0.0-rc2" +version = "20.0.0" diff --git a/mock-sep-40/Cargo.toml b/mock-sep-40/Cargo.toml index 6d428f9..bd84d55 100644 --- a/mock-sep-40/Cargo.toml +++ b/mock-sep-40/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mock-sep-40-oracle" -version = "0.1.1" +version = "0.2.0" authors = ["Script3 "] license = "MIT" edition = "2021" diff --git a/mock-sep-40/src/mock_sep_40.rs b/mock-sep-40/src/mock_sep_40.rs index 6d8894b..e413c60 100644 --- a/mock-sep-40/src/mock_sep_40.rs +++ b/mock-sep-40/src/mock_sep_40.rs @@ -62,14 +62,14 @@ impl MockPriceFeed for MockOracle { for (i, asset) in assets.into_iter().enumerate() { storage::set_asset_index(&env, &asset, i as u32); } - storage::bump_instance(&env); + storage::extend_instance(&env); } fn set_price(env: Env, prices: Vec, timestamp: u64) { let admin = storage::get_admin(&env); admin.require_auth(); - storage::bump_instance(&env); + storage::extend_instance(&env); storage::set_last_timestamp(&env, timestamp); set_prices(&env, prices, timestamp); } @@ -78,7 +78,7 @@ impl MockPriceFeed for MockOracle { let admin = storage::get_admin(&env); admin.require_auth(); - storage::bump_instance(&env); + storage::extend_instance(&env); storage::set_last_timestamp(&env, 0); set_prices(&env, prices, 0); } diff --git a/mock-sep-40/src/storage.rs b/mock-sep-40/src/storage.rs index c0e9a38..81ab330 100644 --- a/mock-sep-40/src/storage.rs +++ b/mock-sep-40/src/storage.rs @@ -6,8 +6,10 @@ 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 -pub fn bump_instance(env: &Env) { - env.storage().instance().bump(LEDGER_THRESHOLD, LEDGER_BUMP); +pub fn extend_instance(env: &Env) { + env.storage() + .instance() + .extend_ttl(LEDGER_THRESHOLD, LEDGER_BUMP); } //********** Instance storage ***********// @@ -115,7 +117,7 @@ pub fn get_price(env: &Env, asset: u8, timestamp: u64) -> Option { if result.is_some() && timestamp == 0 { env.storage() .temporary() - .bump(&data_key, LEDGER_THRESHOLD, LEDGER_BUMP); + .extend_ttl(&data_key, LEDGER_THRESHOLD, LEDGER_BUMP); } result } @@ -125,7 +127,7 @@ pub fn set_price(env: &Env, asset: u8, price: i128, timestamp: u64) { env.storage().temporary().set(&data_key, &price); env.storage() .temporary() - .bump(&data_key, LEDGER_BUMP, LEDGER_BUMP); + .extend_ttl(&data_key, LEDGER_BUMP, LEDGER_BUMP); } pub fn get_last_timestamp(env: &Env) -> u64 { @@ -141,5 +143,5 @@ pub fn set_last_timestamp(env: &Env, timestamp: u64) { .set(&Symbol::new(env, "timestamp"), ×tamp); env.storage() .temporary() - .bump(&Symbol::new(env, "timestamp"), LEDGER_BUMP, LEDGER_BUMP); + .extend_ttl(&Symbol::new(env, "timestamp"), LEDGER_BUMP, LEDGER_BUMP); } diff --git a/mock-sep-40/src/test.rs b/mock-sep-40/src/test.rs index 5224356..9e2fd95 100644 --- a/mock-sep-40/src/test.rs +++ b/mock-sep-40/src/test.rs @@ -16,7 +16,7 @@ fn setup_price_feed_oracle<'a>( decimals: u32, resolution: u32, ) -> (Address, MockOracleClient<'a>) { - let oracle_id = Address::random(env); + let oracle_id = Address::generate(env); env.register_contract(&oracle_id, MockOracle {}); let oracle_client = MockOracleClient::new(env, &oracle_id); oracle_client.set_data(admin, base, assets, &decimals, &resolution); @@ -35,14 +35,14 @@ fn test_stable_price_feed() { sequence_number: start_block, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: u32::MAX, + min_temp_entry_ttl: 16, + min_persistent_entry_ttl: 4096, + max_entry_ttl: 6312000, }); - let bomadil = Address::random(&env); + let bomadil = Address::generate(&env); let base = Asset::Other(Symbol::new(&env, "USD")); - let asset_1 = Asset::Stellar(Address::random(&env)); + let asset_1 = Asset::Stellar(Address::generate(&env)); let asset_2 = Asset::Other(Symbol::new(&env, "EURO")); let (_, oracle_client) = setup_price_feed_oracle( @@ -73,9 +73,9 @@ fn test_stable_price_feed() { sequence_number: start_block + (6 * 24 * 60 * 60) / 5, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: u32::MAX, + min_temp_entry_ttl: 16, + min_persistent_entry_ttl: 4096, + max_entry_ttl: 6312000, }); // verify price data can still be fetched and timestamp adapts @@ -100,14 +100,14 @@ fn test_price_feed() { sequence_number: start_block, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: u32::MAX, + min_temp_entry_ttl: 16, + min_persistent_entry_ttl: 4096, + max_entry_ttl: 6312000, }); - let bomadil = Address::random(&env); + let bomadil = Address::generate(&env); let base = Asset::Other(Symbol::new(&env, "USD")); - let asset_1 = Asset::Stellar(Address::random(&env)); + let asset_1 = Asset::Stellar(Address::generate(&env)); let asset_2 = Asset::Other(Symbol::new(&env, "EURO")); let (_, oracle_client) = setup_price_feed_oracle( @@ -138,9 +138,9 @@ fn test_price_feed() { sequence_number: start_block + 325 / 5, network_id: Default::default(), base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: u32::MAX, + min_temp_entry_ttl: 16, + min_persistent_entry_ttl: 4096, + max_entry_ttl: 6312000, }); // verify price data can still be fetched and timestamp does not diff --git a/sep-40/Cargo.toml b/sep-40/Cargo.toml index ca97f98..ce21f08 100644 --- a/sep-40/Cargo.toml +++ b/sep-40/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sep-40-oracle" -version = "0.1.1" +version = "0.2.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/src/testutils/mock_sep_40_oracle.wasm b/sep-40/src/testutils/mock_sep_40_oracle.wasm index 0c8d708..443f3ae 100644 Binary files a/sep-40/src/testutils/mock_sep_40_oracle.wasm and b/sep-40/src/testutils/mock_sep_40_oracle.wasm differ