Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fabo/fix inverse redemption rate #109

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.3"
version = "0.4.4"
authors = ["Decento Labs"]
edition = "2021"
rust-version = "1.68.0"
Expand Down
2 changes: 1 addition & 1 deletion contracts/staking/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn get_redemption_rate(deps: &Deps) -> Decimal {
if total_liquid_stake_token.is_zero() {
Decimal::zero()
} else {
Decimal::from_ratio(total_native_token, total_liquid_stake_token)
Decimal::from_ratio(total_liquid_stake_token, total_native_token)
}
}

Expand Down
2 changes: 2 additions & 0 deletions contracts/staking/src/tests/circuit_breaker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod circuit_breaker_tests {
let config = CONFIG.load(&deps.storage).unwrap();

state.total_liquid_stake_token = Uint128::from(100_000u128);
state.total_native_token = Uint128::from(300_000u128);
STATE.save(&mut deps.storage, &state).unwrap();

let msg = ExecuteMsg::CircuitBreaker {};
Expand Down Expand Up @@ -53,6 +54,7 @@ mod circuit_breaker_tests {

// liquid unstake
state.total_liquid_stake_token = Uint128::from(100_000u128);
state.total_native_token = Uint128::from(300_000u128);
STATE.save(&mut deps.storage, &state).unwrap();
let info = mock_info("bob", &coins(1000, "factory/cosmos2contract/stTIA"));
let msg = ExecuteMsg::LiquidUnstake {};
Expand Down
10 changes: 7 additions & 3 deletions contracts/staking/src/tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
mod query_tests {
// use serde_json;
use crate::contract::{execute, query};
use crate::helpers::derive_intermediate_sender;
use crate::msg::{
BatchResponse, BatchesResponse, ConfigResponse, ExecuteMsg, LiquidUnstakeRequestResponse,
QueryMsg, StateResponse,
};
use crate::query::query_pending_batch;
use crate::state::{State, CONFIG, STATE};
use crate::state::{CONFIG, STATE};
use crate::tests::test_helper::{
init, CELESTIAVAL1, CELESTIAVAL2, CHANNEL_ID, NATIVE_TOKEN, OSMO1, OSMO2, OSMO3,
};
Expand Down Expand Up @@ -183,6 +182,7 @@ mod query_tests {
// 2. total_liquid_stake_token == 0
let mut state = STATE.load(&deps.storage).unwrap();
state.total_liquid_stake_token = Uint128::from(100_000_000u128);
state.total_native_token = Uint128::from(300_000_000u128);
STATE.save(&mut deps.storage, &state).unwrap();

match result {
Expand Down Expand Up @@ -229,7 +229,10 @@ mod query_tests {
assert_eq!(res.batches.len(), 2);
if let Some(first_batch) = res.batches.get(0) {
assert_eq!(first_batch.batch_total_liquid_stake, Uint128::from(500u128));
assert_eq!(first_batch.expected_native_unstaked, Uint128::from(0u128));
assert_eq!(
first_batch.expected_native_unstaked,
Uint128::from(1500u128)
);
assert_eq!(first_batch.status, "submitted".to_string());
assert_eq!(first_batch.requests.len(), 1);
assert_eq!(
Expand Down Expand Up @@ -303,6 +306,7 @@ mod query_tests {
let mut state = STATE.load(&deps.storage).unwrap();

state.total_liquid_stake_token = Uint128::from(100_000u128);
state.total_native_token = Uint128::from(300_000u128);
STATE.save(&mut deps.storage, &state).unwrap();

let info = mock_info("bob", &coins(1000, "factory/cosmos2contract/stTIA"));
Expand Down
1 change: 1 addition & 0 deletions contracts/staking/src/tests/submit_batch_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ mod submit_batch_tests {
let config = CONFIG.load(&deps.storage).unwrap();

state.total_liquid_stake_token = Uint128::from(100_000u128);
state.total_native_token = Uint128::from(300_000u128);
STATE.save(&mut deps.storage, &state).unwrap();

// batch isnt ready
Expand Down
9 changes: 7 additions & 2 deletions contracts/staking/src/tests/unstake_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ mod staking_tests {
let mut state = STATE.load(&deps.storage).unwrap();

state.total_liquid_stake_token = Uint128::from(100_000u128);
state.total_native_token = Uint128::from(300_000u128);
STATE.save(&mut deps.storage, &state).unwrap();

let info = mock_info("bob", &coins(1000, "factory/bob/stTIA"));
Expand All @@ -185,6 +186,7 @@ mod staking_tests {
let config: Config = CONFIG.load(&deps.storage).unwrap();

state.total_liquid_stake_token = Uint128::from(100_000u128);
state.total_native_token = Uint128::from(300_000u128);
STATE.save(&mut deps.storage, &state).unwrap();

let msg = ExecuteMsg::ReceiveUnstakedTokens { batch_id: 1 };
Expand Down Expand Up @@ -235,6 +237,7 @@ mod staking_tests {
let mut state = STATE.load(&deps.storage).unwrap();

state.total_liquid_stake_token = Uint128::from(100_000u128);
state.total_native_token = Uint128::from(300_000u128);
STATE.save(&mut deps.storage, &state).unwrap();

let info = mock_info(
Expand Down Expand Up @@ -274,7 +277,7 @@ mod staking_tests {
// check the state
state = STATE.load(&deps.storage).unwrap();
assert_eq!(state.total_liquid_stake_token, Uint128::from(100000u128));
assert_eq!(state.total_native_token, Uint128::from(0u128));
assert_eq!(state.total_native_token, Uint128::from(300000u128));

// check the batch
let batch = BATCHES.load(&deps.storage, 1).unwrap();
Expand All @@ -292,6 +295,7 @@ mod staking_tests {
let mut state = STATE.load(&deps.storage).unwrap();

state.total_liquid_stake_token = Uint128::from(0u128);
state.total_native_token = Uint128::from(300_000u128);
STATE.save(&mut deps.storage, &state).unwrap();

let info = mock_info(
Expand Down Expand Up @@ -331,7 +335,7 @@ mod staking_tests {
// check the state
state = STATE.load(&deps.storage).unwrap();
assert_eq!(state.total_liquid_stake_token, Uint128::from(0u128));
assert_eq!(state.total_native_token, Uint128::from(0u128));
assert_eq!(state.total_native_token, Uint128::from(300000u128));

// check the batch
let batch = BATCHES.load(&deps.storage, 1).unwrap();
Expand All @@ -349,6 +353,7 @@ mod staking_tests {
let mut state = STATE.load(&deps.storage).unwrap();

state.total_liquid_stake_token = Uint128::from(100_000u128);
state.total_native_token = Uint128::from(300_000u128);
STATE.save(&mut deps.storage, &state).unwrap();

let mut batch_1 = Batch::new(1, Uint128::from(1000u128), 1000);
Expand Down
2 changes: 2 additions & 0 deletions contracts/staking/src/tests/withdraw_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod withdraw_tests {
let mut state = STATE.load(&deps.storage).unwrap();

state.total_liquid_stake_token = Uint128::from(130_000u128);
state.total_native_token = Uint128::from(300_000u128);
STATE.save(&mut deps.storage, &state).unwrap();

let mut pending_batch: Batch =
Expand Down Expand Up @@ -147,6 +148,7 @@ mod withdraw_tests {
let mut state = STATE.load(&deps.storage).unwrap();

state.total_liquid_stake_token = Uint128::from(130_000u128);
state.total_native_token = Uint128::from(300_000u128);
STATE.save(&mut deps.storage, &state).unwrap();

let mut pending_batch: Batch =
Expand Down
Loading