Skip to content

Commit bbb14ff

Browse files
authored
Merge pull request #121 from milkyway-labs/rustcandy/new_oracle_address
feat: new oracle address
2 parents af214d9 + 1f3d9fc commit bbb14ff

File tree

15 files changed

+68
-61
lines changed

15 files changed

+68
-61
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
members = ["contracts/*", "packages/*"]
33

44
[workspace.package]
5-
version = "0.4.10"
5+
version = "0.4.11"
66
authors = ["Decento Labs"]
77
edition = "2021"
88
rust-version = "1.68.0"

contracts/staking/src/contract.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub fn instantiate(
9696
stopped: true, // we start stopped
9797
oracle_contract_address: None, // just for migration. This always needs to be set
9898
oracle_contract_address_v2: None,
99+
oracle_address: None,
99100
};
100101

101102
CONFIG.save(deps.storage, &config)?;
@@ -115,6 +116,7 @@ pub fn instantiate(
115116
Some(msg.treasury_address),
116117
msg.oracle_contract_address,
117118
msg.oracle_contract_address_v2,
119+
msg.oracle_address,
118120
)?;
119121

120122
// Init State
@@ -207,6 +209,7 @@ pub fn execute(
207209
treasury_address,
208210
oracle_contract_address,
209211
oracle_contract_address_v2,
212+
oracle_address,
210213
} => update_config(
211214
deps,
212215
env,
@@ -222,6 +225,7 @@ pub fn execute(
222225
treasury_address,
223226
oracle_contract_address,
224227
oracle_contract_address_v2,
228+
oracle_address,
225229
),
226230
ExecuteMsg::ReceiveRewards {} => receive_rewards(deps, env, info),
227231
ExecuteMsg::ReceiveUnstakedTokens { batch_id } => {

contracts/staking/src/execute.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,21 @@ fn update_oracle_msgs(deps: Deps, env: Env, config: &Config) -> Result<Vec<Cosmo
167167
funds: vec![]
168168
}.into());
169169

170+
// Post rates to Milkyway Oracle contract
171+
let post_rates_msg = Oracle::PostRates {
172+
purchase_rate: purchase_rate.to_string(),
173+
redemption_rate: redemption_rate.to_string(),
174+
denom: config.liquid_stake_token_denom.clone(),
175+
};
176+
177+
let post_rate_msg_json = serde_json::to_string(&post_rates_msg).unwrap();
178+
messages.push(MsgExecuteContract {
179+
sender: env.contract.address.to_string(),
180+
contract: config.oracle_address.clone().unwrap().to_string(),
181+
msg: post_rate_msg_json.as_bytes().to_vec(),
182+
funds: vec![]
183+
}.into());
184+
170185
Ok(messages)
171186
}
172187

@@ -744,15 +759,16 @@ pub fn update_config_from_migrate(
744759
) -> ContractResult<Response> {
745760
let mut config: Config = CONFIG.load(deps.storage)?;
746761

747-
// update oracle contract address v2
748-
if msg.oracle_contract_address_v2.is_some() {
749-
let oracle_contract_address_v2 = msg.oracle_contract_address_v2.unwrap();
750-
let address = validate_address(&oracle_contract_address_v2, "osmo")?;
751-
config.oracle_contract_address_v2 = Some(address);
762+
// update oracle contract address v3
763+
if msg.oracle_address.is_some() {
764+
let oracle_address = msg.oracle_address.unwrap();
765+
let address = validate_address(&oracle_address, "osmo")?;
766+
config.oracle_address = Some(address);
752767
}
768+
753769
CONFIG.save(deps.storage, &config)?;
754770

755-
Ok(Response::new().add_attribute("action", "update_oracle_contract_address_v2"))
771+
Ok(Response::new().add_attribute("action", "update_oracle_address"))
756772
}
757773

758774
// Update the config; callable by the owner
@@ -771,6 +787,7 @@ pub fn update_config(
771787
treasury_address: Option<String>,
772788
oracle_contract_address: Option<String>,
773789
oracle_contract_address_v2: Option<String>,
790+
oracle_address: Option<String>,
774791
) -> ContractResult<Response> {
775792
ADMIN.assert_admin(deps.as_ref(), &info.sender)?;
776793

@@ -837,6 +854,12 @@ pub fn update_config(
837854
config.oracle_contract_address_v2 = Some(address);
838855
}
839856

857+
if oracle_address.is_some() {
858+
let oracle_address = oracle_address.unwrap();
859+
let address = validate_address(&oracle_address, "osmo")?;
860+
config.oracle_address = Some(address);
861+
}
862+
840863
CONFIG.save(deps.storage, &config)?;
841864

842865
Ok(Response::new().add_attribute("action", "update_config"))

contracts/staking/src/msg.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub struct InstantiateMsg {
3535
pub oracle_contract_address: Option<String>,
3636
// The migratable redemption / purchase rate oracle address
3737
pub oracle_contract_address_v2: Option<String>,
38+
// The redemption / purchase rate oracle address
39+
pub oracle_address: Option<String>,
3840
}
3941

4042
#[cw_serde]
@@ -71,6 +73,7 @@ pub enum ExecuteMsg {
7173
treasury_address: Option<String>,
7274
oracle_contract_address: Option<String>,
7375
oracle_contract_address_v2: Option<String>,
76+
oracle_address: Option<String>,
7477
},
7578
ReceiveRewards {},
7679
ReceiveUnstakedTokens {
@@ -108,6 +111,7 @@ pub struct ConfigResponse {
108111
pub stopped: bool,
109112
pub oracle_contract_address: String,
110113
pub oracle_contract_address_v2: String,
114+
pub oracle_address: String,
111115
}
112116

113117
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
@@ -198,7 +202,7 @@ pub enum QueryMsg {
198202

199203
#[derive(Serialize, Deserialize, JsonSchema)]
200204
pub struct MigrateMsg {
201-
pub oracle_contract_address_v2: Option<String>
205+
pub oracle_address: Option<String>
202206
}
203207

204208
#[cw_serde]

contracts/staking/src/oracle.rs

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,68 +7,33 @@ pub const ORACLE_PURCHASE_RATE_KEY: &str = "milkTIA_purchase_rate";
77

88
#[cw_serde]
99
pub enum Oracle {
10-
/// Uploads and stores a new metric
1110
PostMetric {
12-
/// Key identifying the metric (e.g. `stuatom_redemption_rate`)
1311
key: String,
14-
/// Value for the metric (e.g. `1.1`)
1512
value: String,
16-
/// Category for the metric(e.g. `redemption_rate`)
17-
/// Helps determine handling of additional context
1813
metric_type: MetricType,
19-
/// Unix timestamp with which the metric was updated on the source chain
2014
update_time: u64,
21-
/// Block height with which the metric was updated on the source chain
2215
block_height: u64,
23-
/// Additional metric-specific attributes
2416
attributes: Option<Binary>,
2517
},
18+
PostRates {
19+
denom: String,
20+
purchase_rate: String,
21+
redemption_rate: String,
22+
},
2623
}
2724

28-
/// The RedemptionRate struct represents the redemption rate of an stToken
29-
#[cw_serde]
30-
pub struct RedemptionRate {
31-
/// stToken denom as an IBC hash, as it appears on the oracle chain
32-
pub denom: String,
33-
/// The redemption rate of the stToken
34-
pub redemption_rate: Decimal,
35-
/// The unix timestamp representing when the redemption rate was last updated
36-
pub update_time: u64,
37-
}
38-
39-
/// The PurchaseRate struct represents the purchase rate of an milkTia
40-
#[cw_serde]
41-
pub struct PurchaseRate {
42-
/// stToken denom as an IBC hash, as it appears on the oracle chain
43-
pub denom: String,
44-
/// The purchase rate of the milkTia
45-
pub purchase_rate: Decimal,
46-
/// The unix timestamp representing when the purchase rate was last updated
47-
pub update_time: u64,
48-
}
49-
50-
/// This contract represents a generic key value store
51-
/// A "metric" is the term for a piece of information stored
52-
/// Each metric has a higher level category that helps inform if any other,
53-
/// metric-specific logic needs to be run
54-
/// i.e. For redemption rates, there is an expected format for the attributes
55-
/// field with additional metadata
5625
#[cw_serde]
5726
pub enum MetricType {
5827
RedemptionRate,
5928
PurchaseRate,
6029
Other(String),
6130
}
6231

63-
/// For use in price oracles, the RedemptionRate metric requires the stToken denom
64-
/// as it appears on the controller chain (e.g. `stuosmo`)
6532
#[cw_serde]
6633
pub struct RedemptionRateAttributes {
6734
pub sttoken_denom: String,
6835
}
6936

70-
/// For use in price oracles, the PurchaseRate metric requires the stToken denom
71-
/// as it appears on the controller chain (e.g. `stuosmo`)
7237
#[cw_serde]
7338
pub struct PurchaseRateAttributes {
7439
pub sttoken_denom: String,

contracts/staking/src/query.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ pub fn query_config(deps: Deps) -> StdResult<ConfigResponse> {
4949
.oracle_contract_address_v2
5050
.map(|v| v.to_string())
5151
.unwrap_or_default(),
52+
oracle_address: config
53+
.oracle_address
54+
.map(|v| v.to_string())
55+
.unwrap_or_default(),
5256
};
5357
Ok(res)
5458
}

contracts/staking/src/state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct Config {
2121
pub stopped: bool,
2222
pub oracle_contract_address: Option<Addr>,
2323
pub oracle_contract_address_v2: Option<Addr>,
24+
pub oracle_address: Option<Addr>,
2425
}
2526
// TODO: PENDING - DOCS DEFINE THESE AS MAPS?
2627
// Discuss: Do we want to add or remove any state?

contracts/staking/src/tests/ibc_transfer_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mod ibc_transfer_tests {
4848
]
4949
);
5050
assert_eq!(
51-
result.messages[4],
51+
result.messages[5],
5252
SubMsg {
5353
id: ibc_sub_msg_id.clone(),
5454
msg: <MsgTransfer as Into<CosmosMsg>>::into(MsgTransfer {

contracts/staking/src/tests/instantiate_tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ mod tests {
4747
ibc_channel_id: CHANNEL_ID.to_string(),
4848
oracle_contract_address: None,
4949
oracle_contract_address_v2: None,
50+
oracle_address: None,
5051
}
5152
}
5253

@@ -158,6 +159,7 @@ mod tests {
158159
treasury_address: Some(OSMO3.to_string()),
159160
oracle_contract_address: None,
160161
oracle_contract_address_v2: None,
162+
oracle_address: None,
161163
};
162164

163165
let res = crate::contract::execute(
@@ -189,6 +191,7 @@ mod tests {
189191
treasury_address: None,
190192
oracle_contract_address: None,
191193
oracle_contract_address_v2: None,
194+
oracle_address: None,
192195
};
193196
let res = crate::contract::execute(
194197
deps.as_mut(),
@@ -215,6 +218,7 @@ mod tests {
215218
treasury_address: None,
216219
oracle_contract_address: None,
217220
oracle_contract_address_v2: None,
221+
oracle_address: None,
218222
};
219223
let res = crate::contract::execute(
220224
deps.as_mut(),
@@ -241,6 +245,7 @@ mod tests {
241245
treasury_address: None,
242246
oracle_contract_address: None,
243247
oracle_contract_address_v2: None,
248+
oracle_address: None,
244249
};
245250
let res = crate::contract::execute(
246251
deps.as_mut(),

0 commit comments

Comments
 (0)