Skip to content

Commit

Permalink
feat: remove oracle v1, v2 contracts (#124)
Browse files Browse the repository at this point in the history
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v                               ✰  Thanks for creating a PR! ✰
v    Before smashing the submit button please review the checkboxes.
v If a checkbox is n/a - please still include it but + a little note why
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

## Overview
Removed the code related to oracle V1, V2 contracts. It won't update
them after this migration.

closes: #XXXX

## What changes have been made in this PR?

- [ ]

## Checklist

---

- [ ] Appropriate labels applied
- [ ] Targeted PR against correct branch
- [ ] Linked to Github issue with discussion and accepted design OR link
to spec that describes this work.
- [ ] Wrote unit and integration
- [ ] Updated relevant documentation
  • Loading branch information
rustcandy committed May 1, 2024
1 parent 194a92f commit b0cc7ba
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 128 deletions.
4 changes: 2 additions & 2 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 @@ -2,7 +2,7 @@
members = ["contracts/*", "packages/*"]

[workspace.package]
version = "0.4.17"
version = "0.4.18"
authors = ["Decento Labs"]
edition = "2021"
rust-version = "1.68.0"
Expand Down
76 changes: 2 additions & 74 deletions contracts/staking/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use crate::helpers::{
compute_mint_amount, compute_unbond_amount, derive_intermediate_sender, get_rates,
paginate_map, validate_address, validate_addresses,
};
use crate::oracle::{Oracle, RedemptionRateAttributes, ORACLE_REDEMPTION_RATE_KEY, PurchaseRateAttributes, ORACLE_PURCHASE_RATE_KEY};
use crate::oracle::{Oracle};
use crate::state::{
ibc::{IBCTransfer, PacketLifecycleStatus},
Config, IbcWaitingForReply, MultisigAddressConfig, ProtocolFeeConfig, State, ADMIN, BATCHES,
CONFIG, IBC_WAITING_FOR_REPLY, INFLIGHT_PACKETS, PENDING_BATCH_ID, STATE,
};
use crate::state::{new_unstake_request, remove_unstake_request, unstake_requests, UnstakeRequest};
use cosmwasm_std::{
ensure, Addr, Binary, CosmosMsg, Deps, DepsMut, Env, IbcTimeout, MessageInfo, Order, ReplyOn,
ensure, Addr, CosmosMsg, Deps, DepsMut, Env, IbcTimeout, MessageInfo, Order, ReplyOn,
Response, SubMsg, SubMsgResponse, SubMsgResult, Timestamp, Uint128,
};
use cw_utils::PaymentError;
Expand Down Expand Up @@ -95,78 +95,6 @@ fn transfer_stake_sub_msg(
fn update_oracle_msgs(deps: Deps, env: Env, config: &Config) -> Result<Vec<CosmosMsg>, ContractError> {
let (redemption_rate, purchase_rate) = get_rates(&deps);
let mut messages: Vec<CosmosMsg> = Vec::new();

// V1 uses purchase_rate (but named redemption_rate)
let update_redemption_rate_execute_msg_v1 = Oracle::PostMetric {
key: ORACLE_REDEMPTION_RATE_KEY.to_string(),
value: purchase_rate.to_string(),
metric_type: crate::oracle::MetricType::RedemptionRate,
update_time: env.block.time.seconds(),
block_height: env.block.height,
attributes: Some(Binary::from(
serde_json::to_string(&RedemptionRateAttributes {
sttoken_denom: config.liquid_stake_token_denom.clone(),
})
.unwrap()
.into_bytes(),
)),
};

let update_redemption_rate_msg_json_v1 = serde_json::to_string(&update_redemption_rate_execute_msg_v1).unwrap();
messages.push(MsgExecuteContract {
sender: env.contract.address.to_string(),
contract: config.oracle_contract_address.clone().unwrap().to_string(),
msg: update_redemption_rate_msg_json_v1.as_bytes().to_vec(),
funds: vec![]
}.into());

// V2 uses both redemption_rate and purchase_rate
let update_redemption_rate_execute_msg = Oracle::PostMetric {
key: ORACLE_REDEMPTION_RATE_KEY.to_string(),
value: redemption_rate.to_string(),
metric_type: crate::oracle::MetricType::RedemptionRate,
update_time: env.block.time.seconds(),
block_height: env.block.height,
attributes: Some(Binary::from(
serde_json::to_string(&RedemptionRateAttributes {
sttoken_denom: config.liquid_stake_token_denom.clone(),
})
.unwrap()
.into_bytes(),
)),
};

let update_redemption_rate_msg_json = serde_json::to_string(&update_redemption_rate_execute_msg).unwrap();
messages.push(MsgExecuteContract {
sender: env.contract.address.to_string(),
contract: config.oracle_contract_address_v2.clone().unwrap().to_string(),
msg: update_redemption_rate_msg_json.as_bytes().to_vec(),
funds: vec![]
}.into());

let update_purchase_rate_execute_msg = Oracle::PostMetric {
key: ORACLE_PURCHASE_RATE_KEY.to_string(),
value: purchase_rate.to_string(),
metric_type: crate::oracle::MetricType::PurchaseRate,
update_time: env.block.time.seconds(),
block_height: env.block.height,
attributes: Some(Binary::from(
serde_json::to_string(&PurchaseRateAttributes {
sttoken_denom: config.liquid_stake_token_denom.clone(),
})
.unwrap()
.into_bytes(),
)),
};

let update_purchase_rate_msg_json = serde_json::to_string(&update_purchase_rate_execute_msg).unwrap();
messages.push(MsgExecuteContract {
sender: env.contract.address.to_string(),
contract: config.oracle_contract_address_v2.clone().unwrap().to_string(),
msg: update_purchase_rate_msg_json.as_bytes().to_vec(),
funds: vec![]
}.into());

// Post rates to Milkyway Oracle contract
let post_rates_msg = Oracle::PostRates {
purchase_rate: purchase_rate.to_string(),
Expand Down
2 changes: 0 additions & 2 deletions contracts/staking/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ pub struct ConfigResponse {
pub protocol_fee_config: ProtocolFeeConfig,
pub ibc_channel_id: String,
pub stopped: bool,
pub oracle_contract_address: String,
pub oracle_contract_address_v2: String,
pub oracle_address: String,
}

Expand Down
31 changes: 1 addition & 30 deletions contracts/staking/src/oracle.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,11 @@
// Types for the Oracle contract
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Binary, Decimal};

pub const ORACLE_REDEMPTION_RATE_KEY: &str = "milkTIA_redemption_rate";
pub const ORACLE_PURCHASE_RATE_KEY: &str = "milkTIA_purchase_rate";

#[cw_serde]
pub enum Oracle {
PostMetric {
key: String,
value: String,
metric_type: MetricType,
update_time: u64,
block_height: u64,
attributes: Option<Binary>,
},
PostRates {
denom: String,
purchase_rate: String,
redemption_rate: String,
},
}

#[cw_serde]
pub enum MetricType {
RedemptionRate,
PurchaseRate,
Other(String),
}

#[cw_serde]
pub struct RedemptionRateAttributes {
pub sttoken_denom: String,
}

#[cw_serde]
pub struct PurchaseRateAttributes {
pub sttoken_denom: String,
}
}
8 changes: 0 additions & 8 deletions contracts/staking/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ pub fn query_config(deps: Deps) -> StdResult<ConfigResponse> {
protocol_fee_config: config.protocol_fee_config,
ibc_channel_id: config.ibc_channel_id,
stopped: config.stopped,
oracle_contract_address: config
.oracle_contract_address
.map(|v| v.to_string())
.unwrap_or_default(),
oracle_contract_address_v2: config
.oracle_contract_address_v2
.map(|v| v.to_string())
.unwrap_or_default(),
oracle_address: config
.oracle_address
.map(|v| v.to_string())
Expand Down
2 changes: 1 addition & 1 deletion contracts/staking/src/tests/ibc_transfer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod ibc_transfer_tests {
]
);
assert_eq!(
result.messages[5],
result.messages[2],
SubMsg {
id: ibc_sub_msg_id.clone(),
msg: <MsgTransfer as Into<CosmosMsg>>::into(MsgTransfer {
Expand Down
6 changes: 3 additions & 3 deletions contracts/staking/src/tests/reward_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ mod reward_tests {

assert!(res.is_ok());
let res = res.unwrap();
assert_eq!(res.messages.len(), 5); // transfer message and redemption/purchase rate update
assert_eq!(res.messages[4].reply_on, ReplyOn::Always);
assert_eq!(res.messages.len(), 2); // transfer message and redemption/purchase rate update
assert_eq!(res.messages[1].reply_on, ReplyOn::Always);
assert_eq!(
res.messages[4].msg,
res.messages[1].msg,
CosmosMsg::from(MsgTransfer {
source_channel: CHANNEL_ID.to_string(),
source_port: "transfer".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions contracts/staking/src/tests/stake_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ mod staking_tests {
attr("mint_amount", "1000"),
]
);
assert_eq!(result.messages.len(), 6); // transfer, mint, redemption rate update
assert_eq!(result.messages.len(), 3); // transfer, mint, redemption rate update
assert_eq!(
result.messages[5],
result.messages[2],
SubMsg {
id: ibc_sub_msg_id.clone(),
msg: <MsgTransfer as Into<CosmosMsg>>::into(MsgTransfer {
Expand Down
2 changes: 1 addition & 1 deletion contracts/staking/src/tests/unstake_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mod staking_tests {
assert_eq!(attrs[3].value, "650");

let messages = resp.messages;
assert_eq!(messages.len(), 5); // batch submit and redemption/purchase rate update
assert_eq!(messages.len(), 2); // batch submit and redemption/purchase rate update
assert_eq!(
messages[0],
SubMsg {
Expand Down
8 changes: 4 additions & 4 deletions contracts/staking/src/tests/withdraw_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod withdraw_tests {
let res = execute(deps.as_mut(), env.clone(), info, msg.clone());
assert!(res.is_ok());
let messages = res.unwrap().messages;
assert_eq!(messages.len(), 5); // withdraw and redemption/purchase rate update
assert_eq!(messages.len(), 2); // withdraw and redemption/purchase rate update

let msg = QueryMsg::UnstakeRequests {
user: Addr::unchecked("bob"),
Expand Down Expand Up @@ -112,7 +112,7 @@ mod withdraw_tests {
let res = execute(deps.as_mut(), env.clone(), info, msg.clone());
assert!(res.is_ok());
let messages = res.unwrap().messages;
assert_eq!(messages.len(), 5); // withdraw and redemption/purchase rate update
assert_eq!(messages.len(), 2); // withdraw and redemption/purchase rate update

let msg = QueryMsg::UnstakeRequests {
user: Addr::unchecked("tom"),
Expand Down Expand Up @@ -190,7 +190,7 @@ mod withdraw_tests {
let res = execute(deps.as_mut(), env.clone(), info, msg.clone());
assert!(res.is_ok());
let messages = res.unwrap().messages;
assert_eq!(messages.len(), 5); // withdraw and redemption rate update
assert_eq!(messages.len(), 2); // withdraw and redemption rate update

let msg = QueryMsg::UnstakeRequests {
user: Addr::unchecked("bob"),
Expand Down Expand Up @@ -232,7 +232,7 @@ mod withdraw_tests {
let res = execute(deps.as_mut(), env.clone(), info, msg.clone());
assert!(res.is_ok());
let messages = res.unwrap().messages;
assert_eq!(messages.len(), 5); // withdraw and redemption/purchase rate update
assert_eq!(messages.len(), 2); // withdraw and redemption/purchase rate update

let msg = QueryMsg::UnstakeRequests {
user: Addr::unchecked("tom"),
Expand Down

0 comments on commit b0cc7ba

Please sign in to comment.