Skip to content

Commit c45ac2c

Browse files
authored
Merge branch 'main' into 99-osmosis-price-oracle
2 parents 3ac2744 + 3164c23 commit c45ac2c

33 files changed

+1352
-79
lines changed

CHANGELOG.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,26 @@
22

33
## [Unreleased](https://github.com/osmosis-labs/mesh-security/tree/HEAD)
44

5-
[Full Changelog](https://github.com/osmosis-labs/mesh-security/compare/v0.8.0-alpha.1...HEAD)
5+
[Full Changelog](https://github.com/osmosis-labs/mesh-security/compare/v0.8.1-alpha.1...HEAD)
6+
7+
## [v0.8.1-alpha.1](https://github.com/osmosis-labs/mesh-security/tree/v0.8.1-alpha.1) (2023-11-06)
8+
9+
[Full Changelog](https://github.com/osmosis-labs/mesh-security/compare/v0.8.0-alpha.1...v0.8.1-alpha.1)
10+
11+
**Closed issues:**
12+
13+
- Slashing propagation accounting [\#139](https://github.com/osmosis-labs/mesh-security/issues/139)
14+
- Slashing-related messages [\#128](https://github.com/osmosis-labs/mesh-security/issues/128)
15+
- Improve cross-bond/unbond process [\#124](https://github.com/osmosis-labs/mesh-security/issues/124)
16+
- MVP slashing [\#112](https://github.com/osmosis-labs/mesh-security/issues/112)
17+
18+
**Merged pull requests:**
19+
20+
- 139/slashing proportional burn [\#159](https://github.com/osmosis-labs/mesh-security/pull/159) ([maurolacy](https://github.com/maurolacy))
21+
- Slashing propagation Consumer accounting [\#158](https://github.com/osmosis-labs/mesh-security/pull/158) ([maurolacy](https://github.com/maurolacy))
22+
- Slashing propagation acct [\#156](https://github.com/osmosis-labs/mesh-security/pull/156) ([maurolacy](https://github.com/maurolacy))
23+
- Virtual staking valset updates [\#153](https://github.com/osmosis-labs/mesh-security/pull/153) ([maurolacy](https://github.com/maurolacy))
24+
- Immediately release stake when possible [\#152](https://github.com/osmosis-labs/mesh-security/pull/152) ([uint](https://github.com/uint))
625

726
## [v0.8.0-alpha.1](https://github.com/osmosis-labs/mesh-security/tree/v0.8.0-alpha.1) (2023-10-19)
827

Cargo.lock

+19-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ resolver = "2"
44

55
[workspace.package]
66
edition = "2021"
7-
version = "0.8.0-alpha.1"
7+
version = "0.8.1-alpha.1"
88
license = "MIT"
99
repository = "https://github.com/osmosis-labs/mesh-security"
1010

1111
[workspace.dependencies]
1212
mesh-apis = { path = "./packages/apis" }
13-
mesh-bindings = { path = "./packages/bindings" }
13+
mesh-bindings = { path = "./packages/bindings" }
14+
mesh-burn = { path = "./packages/burn" }
1415
mesh-sync = { path = "./packages/sync" }
1516
mesh-virtual-staking-mock = { path = "./packages/virtual-staking-mock" }
1617

RELEASE_NOTES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 0.8.1-alpha.1
2+
3+
- Slashing propagation accounting.
4+
- Improve cross-bond/unbond process.
5+
16
# 0.8.0-alpha.1
27

38
- Add code coverage.

contracts/consumer/converter/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ serde = { workspace = true }
3434
thiserror = { workspace = true }
3535

3636
[dev-dependencies]
37+
mesh-burn = { workspace = true }
3738
mesh-simple-price-feed = { workspace = true, features = ["mt"] }
3839

3940
cw-multi-test = { workspace = true }

contracts/consumer/converter/src/contract.rs

+48
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,27 @@ impl ConverterContract<'_> {
154154
}
155155
}
156156

157+
/// This is only used for tests.
158+
/// Ideally we want conditional compilation of these whole methods and the enum variants
159+
#[msg(exec)]
160+
fn test_burn(
161+
&self,
162+
ctx: ExecCtx,
163+
validators: Vec<String>,
164+
burn: Coin,
165+
) -> Result<Response, ContractError> {
166+
#[cfg(any(test, feature = "mt"))]
167+
{
168+
// This can only ever be called in tests
169+
self.burn(ctx.deps, &validators, burn)
170+
}
171+
#[cfg(not(any(test, feature = "mt")))]
172+
{
173+
let _ = (ctx, validators, burn);
174+
Err(ContractError::Unauthorized)
175+
}
176+
}
177+
157178
#[msg(query)]
158179
fn config(&self, ctx: QueryCtx) -> Result<ConfigResponse, ContractError> {
159180
let config = self.config.load(ctx.deps.storage)?;
@@ -213,6 +234,33 @@ impl ConverterContract<'_> {
213234
Ok(Response::new().add_message(msg).add_event(event))
214235
}
215236

237+
/// This is called by ibc_packet_receive.
238+
/// It is pulled out into a method, so it can also be called by test_burn for testing
239+
pub(crate) fn burn(
240+
&self,
241+
deps: DepsMut,
242+
validators: &[String],
243+
burn: Coin,
244+
) -> Result<Response, ContractError> {
245+
let amount = self.normalize_price(deps.as_ref(), burn)?;
246+
247+
let event = Event::new("mesh-burn")
248+
.add_attribute("validators", validators.join(","))
249+
.add_attribute("amount", amount.amount.to_string());
250+
251+
let msg = virtual_staking_api::ExecMsg::Burn {
252+
validators: validators.to_vec(),
253+
amount,
254+
};
255+
let msg = WasmMsg::Execute {
256+
contract_addr: self.virtual_stake.load(deps.storage)?.into(),
257+
msg: to_binary(&msg)?,
258+
funds: vec![],
259+
};
260+
261+
Ok(Response::new().add_message(msg).add_event(event))
262+
}
263+
216264
fn normalize_price(&self, deps: Deps, amount: Coin) -> Result<Coin, ContractError> {
217265
let config = self.config.load(deps.storage)?;
218266
ensure_eq!(

contracts/consumer/converter/src/ibc.rs

+9
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ pub fn ibc_packet_receive(
214214
.add_events(response.events)
215215
.add_attributes(response.attributes)
216216
}
217+
ProviderPacket::Burn { validators, burn } => {
218+
let response = contract.burn(deps, &validators, burn)?;
219+
let ack = ack_success(&UnstakeAck {})?;
220+
IbcReceiveResponse::new()
221+
.set_ack(ack)
222+
.add_submessages(response.messages)
223+
.add_events(response.events)
224+
.add_attributes(response.attributes)
225+
}
217226
ProviderPacket::TransferRewards {
218227
rewards, recipient, ..
219228
} => {

contracts/consumer/converter/src/multitest.rs

+86
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,92 @@ fn ibc_stake_and_unstake() {
200200
);
201201
}
202202

203+
#[test]
204+
fn ibc_stake_and_burn() {
205+
let app = App::default();
206+
207+
let owner = "sunny"; // Owner of the staking contract (i. e. the vault contract)
208+
let admin = "theman";
209+
let discount = Decimal::percent(40); // 1 OSMO worth of JUNO should give 0.6 OSMO of stake
210+
let native_per_foreign = Decimal::percent(50); // 1 JUNO is worth 0.5 OSMO
211+
212+
let SetupResponse {
213+
price_feed: _,
214+
converter,
215+
virtual_staking,
216+
} = setup(
217+
&app,
218+
SetupArgs {
219+
owner,
220+
admin,
221+
discount,
222+
native_per_foreign,
223+
},
224+
);
225+
226+
// no one is staked
227+
let val1 = "Val Kilmer";
228+
let val2 = "Valley Girl";
229+
assert!(virtual_staking.all_stake().unwrap().stakes.is_empty());
230+
assert_eq!(
231+
virtual_staking
232+
.stake(val1.to_string())
233+
.unwrap()
234+
.stake
235+
.u128(),
236+
0
237+
);
238+
assert_eq!(
239+
virtual_staking
240+
.stake(val2.to_string())
241+
.unwrap()
242+
.stake
243+
.u128(),
244+
0
245+
);
246+
247+
// let's stake some
248+
converter
249+
.test_stake(val1.to_string(), coin(1000, JUNO))
250+
.call(owner)
251+
.unwrap();
252+
converter
253+
.test_stake(val2.to_string(), coin(4000, JUNO))
254+
.call(owner)
255+
.unwrap();
256+
257+
// and burn some
258+
converter
259+
.test_burn(vec![val2.to_string()], coin(2000, JUNO))
260+
.call(owner)
261+
.unwrap();
262+
263+
// and check the stakes (1000 * 0.6 * 0.5 = 300) (2000 * 0.6 * 0.5 = 600)
264+
assert_eq!(
265+
virtual_staking
266+
.stake(val1.to_string())
267+
.unwrap()
268+
.stake
269+
.u128(),
270+
300
271+
);
272+
assert_eq!(
273+
virtual_staking
274+
.stake(val2.to_string())
275+
.unwrap()
276+
.stake
277+
.u128(),
278+
600
279+
);
280+
assert_eq!(
281+
virtual_staking.all_stake().unwrap().stakes,
282+
vec![
283+
(val1.to_string(), Uint128::new(300)),
284+
(val2.to_string(), Uint128::new(600)),
285+
]
286+
);
287+
}
288+
203289
#[test]
204290
fn valset_update_works() {
205291
let app = App::default();

0 commit comments

Comments
 (0)