Skip to content

Commit

Permalink
feat(treasury): add swap functionalities through osmosis (#126)
Browse files Browse the repository at this point in the history
## Overview

This PR updates the treasury and staking contracts, allowing the staking
contract to send protocol fees to the treasury and enabling a `trader`
account to perform swap operations, helping the treasury hedge against
asset price fluctuations.

To prevent the `trader` from converting the treasury's assets into
unwanted ones, a list of swap routes can be defined. This forces the
`trader` to use only a predefined set of pools and only in a predefined
direction. For example, if the Osmosis pool 1 has the OSMO/USDC pair, we
can enforce that the `trader` can only swap OSMO for USDC, but not the
other way around.

closes: MILKTIA-35

## What changes have been made in this PR?

- [ ] Add swap functionalities to the treasury contract
- [ ] Allow the staking contract to send the protocol fees to the
treasury
- [ ] Fix lint errors reported by `cargo clippy` 

## 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
manu0466 authored Jun 11, 2024
1 parent c3b00e4 commit 7a61644
Show file tree
Hide file tree
Showing 42 changed files with 3,534 additions and 2,386 deletions.
File renamed without changes.
79 changes: 33 additions & 46 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["contracts/*", "packages/*"]
resolver = "2"

[workspace.package]
version = "0.4.19"
Expand All @@ -13,12 +14,16 @@ documentation = "https://docs.milkyway.zone/"
keywords = ["cosmwasm", "milkyway", "cosmos"]

[workspace.dependencies]
cosmwasm-schema = "1.3.1"
cosmwasm-std = {version = "1.4.1"}
bech32 = "0.9.1"
cosmwasm-schema = "1.5.2"
cosmwasm-std = "1.5.2"
cw2 = "1.0.1"
cw-controllers = "1.1.2"
cw-storage-plus = "1.1.0"
cw-utils = "1.0.1"
osmosis-std = "0.20.1"
osmosis-std = "0.25.0"
schemars = "0.8.12"
semver = "1.0.20"
serde = { version = "1.0.155", default-features = false, features = ["derive"] }
thiserror = "1.0.39"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This repository contains MilkyWay's core contracts that is deployed and operated
| Contract | Description |
| ---------------------------------- | ------------------------------------------------------- |
| [`staking`](./contracts/staking) | Core contract for liquid staking / liquid unstaking TIA |
| [`treasury`](./contracts/treasury) | MilkyWay DAO |
| [`treasury`](./contracts/treasury) | MilkyWay treasury contract |

## Testing

Expand Down
33 changes: 16 additions & 17 deletions contracts/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,24 @@ backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = {version = "1.4.1", features = ["stargate"]}
cw-storage-plus = "1.1.0"
cw2 = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
serde_json = "1.0"
thiserror = { workspace = true }
osmosis-std = { workspace = true }
cw-controllers = "1.1.1"
cw-utils = { workspace = true }
milky_way = { path = "../../packages/milky_way" }
bech32 = "0.9.1"
bech32-no_std = "0.7.3"
sha2 = "0.10.8"
prost = {version = "0.11.2", default-features = false, features = ["prost-derive"]}
bech32.workspace = true
cw2.workspace = true
cosmwasm-schema.workspace = true
cosmwasm-std = { workspace = true, features = ["stargate"]}
cw-controllers.workspace = true
cw-storage-plus.workspace = true
cw-utils.workspace = true
enum-repr = "0.2.6"
milky_way = { path = "../../packages/milky_way" }
osmosis-std.workspace = true
prost = { version = "0.12.3", default-features = false, features = ["prost-derive"] }
prost-derive = "0.12.3"
semver = "1.0.20"
schemars.workspace = true
serde.workspace = true
serde_json = "1.0"
sha2 = "0.10.8"
thiserror.workspace = true
semver.workspace = true

[dev-dependencies]
cw-multi-test = "0.17.0"
9 changes: 2 additions & 7 deletions contracts/staking/src/ack.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_binary, Binary};
use cosmwasm_std::{to_json_binary, Binary};
use enum_repr::EnumRepr;
/// IBC ACK. See:
/// https://github.com/cosmos/cosmos-sdk/blob/f999b1ff05a4db4a338a855713864497bedd4396/proto/ibc/core/channel/v1/channel.proto#L141-L147
Expand All @@ -11,12 +11,7 @@ pub enum Ack {

pub fn make_ack_success() -> Binary {
let res = Ack::Result(b"1".into());
to_binary(&res).unwrap()
}

pub fn make_ack_fail(err: String) -> Binary {
let res = Ack::Error(err);
to_binary(&res).unwrap()
to_json_binary(&res).unwrap()
}

// reply id
Expand Down
Loading

0 comments on commit 7a61644

Please sign in to comment.