Skip to content

Commit

Permalink
chore: update to soroban 20.5 and up the mock contract storage ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
mootz12 committed Apr 1, 2024
1 parent 8254f52 commit c708725
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 29 deletions.
50 changes: 25 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ codegen-units = 1
lto = true

[workspace.dependencies.soroban-sdk]
version = "20.0.0"
version = "20.5.0"
6 changes: 4 additions & 2 deletions mock-sep-40/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion sep-40/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
repository = "https://github.com/script3/sep-40-oracle"
Expand Down
54 changes: 54 additions & 0 deletions sep-40/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand All @@ -18,3 +23,52 @@ You can optionally include the `testutils` feature in your `dev-dependencies` to
[dev_dependencies]
sep-40-oracle = { version = "<desired 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)
);
```
Binary file modified sep-40/src/testutils/mock_sep_40_oracle.wasm
Binary file not shown.

0 comments on commit c708725

Please sign in to comment.