Skip to content

Commit e02f39c

Browse files
authored
Add slinky LST price source (#38)
* initial implementation * add new price source to display * validate denom * fmt * add test case * improve tests * tidy & generate types * tidy * v2.3.2 migration * tidy tests * update schema
1 parent 6af9a00 commit e02f39c

File tree

23 files changed

+512
-100
lines changed

23 files changed

+512
-100
lines changed

Cargo.lock

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ members = [
2525
"contracts/mock-pyth",
2626
"contracts/mock-red-bank",
2727
"contracts/mock-vault",
28+
"contracts/mock-lst-oracle",
2829

2930
# packages
3031
"packages/chains/*",
@@ -150,6 +151,7 @@ mars-mock-incentives = { path = "./contracts/mock-incentives" }
150151
mars-mock-oracle = { path = "./contracts/mock-oracle" }
151152
mars-mock-red-bank = { path = "./contracts/mock-red-bank" }
152153
mars-mock-vault = { path = "./contracts/mock-vault" }
154+
mars-mock-lst-oracle = { path = "./contracts/mock-lst-oracle" }
153155
mars-mock-rover-health = { path = "./contracts/mock-health" }
154156
mars-swapper-mock = { path = "./contracts/swapper/mock" }
155157
mars-zapper-mock = { path = "./contracts/v2-zapper/mock" }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "mars-mock-lst-oracle"
3+
description = "Mocked version of a slinky lst oracle contract"
4+
version = { workspace = true }
5+
authors = { workspace = true }
6+
license = { workspace = true }
7+
edition = { workspace = true }
8+
repository = { workspace = true }
9+
homepage = { workspace = true }
10+
documentation = { workspace = true }
11+
keywords = { workspace = true }
12+
13+
[lib]
14+
crate-type = ["cdylib", "rlib"]
15+
doctest = false
16+
17+
[features]
18+
# for quicker tests, cargo test --lib
19+
# for more explicit tests, cargo test --features=backtraces
20+
backtraces = ["cosmwasm-std/backtraces"]
21+
library = []
22+
23+
[dependencies]
24+
cosmwasm-schema = { workspace = true }
25+
cosmwasm-std = { workspace = true }
26+
schemars = { workspace = true }
27+
serde = { workspace = true }
28+
cw2 = { workspace = true }
29+
thiserror = { workspace = true }
30+
cw-storage-plus = { workspace = true }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Mock LST Oracle Contract
2+
3+
This contract, `mars-mock-lst-oracle`, is a mock implementation of a Liquid Staking Token (LST) oracle from slinky, designed specifically for use within the testing environment.
4+
5+
See the [slinky vault](https://github.com/neutron-org/slinky-vault/tree/main/contracts/lst-oracle) repository for the production version of the LST oracle.
6+
7+
## Purpose
8+
9+
In a production environment, the Mars oracle relies on external slinky LST oracle to fetch redemption rates for various liquid staked assets. To ensure robust and predictable testing without depending on external oracle deployments and their conflicting dependencies, this mock contract was created.
10+
11+
It simulates the core behavior of an LST oracle by allowing test setups to instantiate it with a specific `redemption_rate` and `lst_asset_denom`. These values can also be updated during test execution, enabling a wide range of scenarios to be tested reliably.
12+
13+
## State & Configuration
14+
15+
- **`redemption_rate`**: A `Decimal` value representing the LST's redemption rate.
16+
- **`lst_asset_denom`**: A `String` for the LST asset's denomination (e.g., `st_atom`).
17+
18+
This mock contract is a crucial component of the `packages/testing` crate, where it is uploaded and instantiated as part of the standard test setup.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use cosmwasm_std::{
2+
entry_point, to_json_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Response,
3+
StdResult,
4+
};
5+
use cw_storage_plus::Item;
6+
use schemars::JsonSchema;
7+
use serde::{Deserialize, Serialize};
8+
9+
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
10+
11+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
12+
pub struct State {
13+
pub redemption_rate: Decimal,
14+
pub lst_asset_denom: String,
15+
}
16+
17+
pub const STATE: Item<State> = Item::new("state");
18+
19+
#[entry_point]
20+
pub fn instantiate(
21+
deps: DepsMut,
22+
_env: Env,
23+
_info: MessageInfo,
24+
msg: InstantiateMsg,
25+
) -> StdResult<Response> {
26+
let state = State {
27+
redemption_rate: msg.redemption_rate,
28+
lst_asset_denom: msg.lst_asset_denom,
29+
};
30+
STATE.save(deps.storage, &state)?;
31+
Ok(Response::default())
32+
}
33+
34+
#[entry_point]
35+
pub fn execute(
36+
deps: DepsMut,
37+
_env: Env,
38+
_info: MessageInfo,
39+
msg: ExecuteMsg,
40+
) -> StdResult<Response> {
41+
match msg {
42+
ExecuteMsg::SetRedemptionRate {
43+
redemption_rate,
44+
} => {
45+
STATE.update(deps.storage, |mut state| -> StdResult<_> {
46+
state.redemption_rate = redemption_rate;
47+
Ok(state)
48+
})?;
49+
Ok(Response::default())
50+
}
51+
ExecuteMsg::SetLstAssetDenom {
52+
denom,
53+
} => {
54+
STATE.update(deps.storage, |mut state| -> StdResult<_> {
55+
state.lst_asset_denom = denom;
56+
Ok(state)
57+
})?;
58+
Ok(Response::default())
59+
}
60+
}
61+
}
62+
63+
#[entry_point]
64+
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
65+
match msg {
66+
QueryMsg::RedemptionRate {} => {
67+
let state = STATE.load(deps.storage)?;
68+
to_json_binary(&state.redemption_rate)
69+
}
70+
QueryMsg::GetLstAssetDenom {} => {
71+
let state = STATE.load(deps.storage)?;
72+
to_json_binary(&state.lst_asset_denom)
73+
}
74+
}
75+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod contract;
2+
pub mod msg;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use cosmwasm_schema::{cw_serde, QueryResponses};
2+
use cosmwasm_std::Decimal;
3+
use schemars::JsonSchema;
4+
use serde::{Deserialize, Serialize};
5+
6+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
7+
pub struct InstantiateMsg {
8+
pub redemption_rate: Decimal,
9+
pub lst_asset_denom: String,
10+
}
11+
12+
#[cw_serde]
13+
pub enum ExecuteMsg {
14+
SetRedemptionRate {
15+
redemption_rate: Decimal,
16+
},
17+
SetLstAssetDenom {
18+
denom: String,
19+
},
20+
}
21+
22+
#[cw_serde]
23+
#[derive(QueryResponses)]
24+
pub enum QueryMsg {
25+
#[returns(Decimal)]
26+
RedemptionRate {},
27+
#[returns(String)]
28+
GetLstAssetDenom {},
29+
}

contracts/oracle/wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "mars-oracle-wasm"
33
description = "A smart contract that provides prices for generic CosmWasm chains"
4-
version = "2.2.3"
4+
version = "2.3.2"
55
authors = { workspace = true }
66
edition = { workspace = true }
77
license = { workspace = true }

contracts/oracle/wasm/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ pub mod entry {
8282

8383
#[entry_point]
8484
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> ContractResult<Response> {
85-
migrations::v2_2_3::migrate(deps)
85+
migrations::v2_3_2::migrate(deps)
8686
}
8787
}

contracts/oracle/wasm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod helpers;
44
pub mod lp_pricing;
55
pub mod migrations;
66
mod price_source;
7+
mod redemption_rate;
78
pub mod slinky;
89
mod state;
910

0 commit comments

Comments
 (0)