Skip to content

Commit

Permalink
feat: incentive manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x authored Apr 12, 2024
2 parents 7440733 + 64ec60f commit 62a82ed
Show file tree
Hide file tree
Showing 68 changed files with 6,982 additions and 206 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

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

30 changes: 16 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
resolver = "2"

members = [
"packages/*",
"contracts/liquidity_hub/pool-network/*",
"contracts/liquidity_hub/fee_collector",
"contracts/liquidity_hub/fee_distributor",
"contracts/liquidity_hub/whale_lair",
"contracts/liquidity_hub/vault-network/*",
"contracts/liquidity_hub/pool-manager",
"contracts/liquidity_hub/epoch-manager",
"contracts/liquidity_hub/vault-manager",
"xtask",
"packages/*",
"contracts/liquidity_hub/pool-network/*",
"contracts/liquidity_hub/fee_collector",
"contracts/liquidity_hub/fee_distributor",
"contracts/liquidity_hub/whale_lair",
"contracts/liquidity_hub/vault-network/*",
"contracts/liquidity_hub/pool-manager",
"contracts/liquidity_hub/epoch-manager",
"contracts/liquidity_hub/vault-manager",
"contracts/liquidity_hub/incentive-manager",
"xtask",
]

[workspace.package]
Expand All @@ -26,9 +27,9 @@ authors = ["White Whale Defi"]
[workspace.dependencies]
cosmwasm-schema = { version = "1.5.3" }
cosmwasm-std = { version = "1.1.4", features = [
"iterator",
"cosmwasm_1_2",
"stargate",
"iterator",
"cosmwasm_1_2",
"stargate",
] }
cw2 = { version = "1.0.1" }
cw20 = { version = "1.0.1" }
Expand All @@ -54,7 +55,7 @@ sha2 = { version = "=0.10.8" }
sha256 = { version = "1.4.0" }
protobuf = { version = "=3.2.0", features = ["with-bytes"] }
prost = { version = "0.11.9", default-features = false, features = [
"prost-derive",
"prost-derive",
] }
test-case = { version = "3.3.1" }

Expand All @@ -66,6 +67,7 @@ fee-distributor-mock = { path = "./contracts/liquidity_hub/fee-distributor-mock"
incentive-factory = { path = "./contracts/liquidity_hub/pool-network/incentive_factory" }
terraswap-token = { path = "./contracts/liquidity_hub/pool-network/terraswap_token" }
terraswap-pair = { path = "./contracts/liquidity_hub/pool-network/terraswap_pair" }
epoch-manager = { path = "./contracts/liquidity_hub/epoch-manager" }

[workspace.metadata.dylint]
libraries = [{ git = "https://github.com/0xFable/cw-lint" }]
Expand Down
7 changes: 4 additions & 3 deletions contracts/liquidity_hub/epoch-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ authors = ["Kerber0x <[email protected]>"]
edition = "2021"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -34,3 +34,4 @@ semver.workspace = true
thiserror.workspace = true
white-whale-std.workspace = true
cw-controllers.workspace = true
cw-utils.workspace = true
4 changes: 3 additions & 1 deletion contracts/liquidity_hub/epoch-manager/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ pub(crate) fn remove_hook(
}

/// Creates a new epoch.
pub fn create_epoch(deps: DepsMut, env: Env) -> Result<Response, ContractError> {
pub fn create_epoch(deps: DepsMut, env: Env, info: MessageInfo) -> Result<Response, ContractError> {
cw_utils::nonpayable(&info)?;

let mut current_epoch = query_current_epoch(deps.as_ref())?.epoch;
let config = CONFIG.load(deps.storage)?;

Expand Down
4 changes: 2 additions & 2 deletions contracts/liquidity_hub/epoch-manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::state::{ADMIN, CONFIG, EPOCHS};
use crate::{commands, queries};

// version info for migration info
const CONTRACT_NAME: &str = "white_whale-epoch-manager";
const CONTRACT_NAME: &str = "white-whale_epoch-manager";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[entry_point]
Expand Down Expand Up @@ -69,7 +69,7 @@ pub fn execute(
ExecuteMsg::RemoveHook { contract_addr } => {
commands::remove_hook(deps, info, api, &contract_addr)
}
ExecuteMsg::CreateEpoch {} => commands::create_epoch(deps, env),
ExecuteMsg::CreateEpoch {} => commands::create_epoch(deps, env, info),
ExecuteMsg::UpdateConfig {
owner,
epoch_config,
Expand Down
4 changes: 4 additions & 0 deletions contracts/liquidity_hub/epoch-manager/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cosmwasm_std::StdError;
use cw_controllers::{AdminError, HookError};
use cw_utils::PaymentError;
use semver::Version;
use thiserror::Error;

Expand All @@ -17,6 +18,9 @@ pub enum ContractError {
#[error("The epoch id has overflowed.")]
EpochOverflow,

#[error("{0}")]
PaymentError(#[from] PaymentError),

#[error("Semver parsing error: {0}")]
SemVer(String),

Expand Down
4 changes: 2 additions & 2 deletions contracts/liquidity_hub/epoch-manager/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cw_controllers::{Admin, Hooks};
use cw_storage_plus::{Item, Map};
use white_whale_std::epoch_manager::epoch_manager::{Config, EpochV2};
use white_whale_std::epoch_manager::epoch_manager::{Config, Epoch};

pub const CONFIG: Item<Config> = Item::new("config");
pub const ADMIN: Admin = Admin::new("admin");
pub const HOOKS: Hooks = Hooks::new("hooks");
pub const EPOCHS: Map<&[u8], EpochV2> = Map::new("epochs");
pub const EPOCHS: Map<&[u8], Epoch> = Map::new("epochs");
4 changes: 2 additions & 2 deletions contracts/liquidity_hub/epoch-manager/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cosmwasm_std::{DepsMut, MessageInfo, Response, Uint64};
use epoch_manager::contract::{execute, instantiate};
use epoch_manager::ContractError;
use white_whale_std::epoch_manager::epoch_manager::{
EpochConfig, EpochV2, ExecuteMsg, InstantiateMsg,
Epoch, EpochConfig, ExecuteMsg, InstantiateMsg,
};

/// Mocks contract instantiation.
Expand All @@ -14,7 +14,7 @@ pub(crate) fn mock_instantiation(
) -> Result<Response, ContractError> {
let current_time = mock_env().block.time;
let msg = InstantiateMsg {
start_epoch: EpochV2 {
start_epoch: Epoch {
id: 123,
start_time: current_time,
},
Expand Down
6 changes: 3 additions & 3 deletions contracts/liquidity_hub/epoch-manager/tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cosmwasm_std::testing::{mock_env, mock_info};

use epoch_manager::contract::{execute, query};
use epoch_manager::ContractError;
use white_whale_std::epoch_manager::epoch_manager::{EpochResponse, EpochV2, ExecuteMsg, QueryMsg};
use white_whale_std::epoch_manager::epoch_manager::{Epoch, EpochResponse, ExecuteMsg, QueryMsg};
use white_whale_std::epoch_manager::hooks::EpochChangedHookMsg;
use white_whale_std::pool_network::mock_querier::mock_dependencies;

Expand All @@ -29,7 +29,7 @@ fn create_new_epoch_successfully() {
let query_res = query(deps.as_ref(), mock_env(), QueryMsg::CurrentEpoch {}).unwrap();
let epoch_response: EpochResponse = from_json(query_res).unwrap();

let current_epoch = EpochV2 {
let current_epoch = Epoch {
id: 124,
start_time: next_epoch_time,
};
Expand All @@ -55,7 +55,7 @@ fn create_new_epoch_successfully() {

assert_eq!(
epoch_response.epoch,
EpochV2 {
Epoch {
id: 123,
start_time: next_epoch_time.minus_nanos(86400),
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/liquidity_hub/epoch-manager/tests/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cosmwasm_std::{from_json, Addr, Uint64};
use epoch_manager::contract::{instantiate, query};
use epoch_manager::ContractError;
use white_whale_std::epoch_manager::epoch_manager::{
ConfigResponse, EpochConfig, EpochV2, InstantiateMsg, QueryMsg,
ConfigResponse, Epoch, EpochConfig, InstantiateMsg, QueryMsg,
};
use white_whale_std::pool_network::mock_querier::mock_dependencies;

Expand All @@ -17,7 +17,7 @@ fn instantiation_successful() {
let current_time = mock_env().block.time;
let info = mock_info("owner", &[]);
let msg = InstantiateMsg {
start_epoch: EpochV2 {
start_epoch: Epoch {
id: 123,
start_time: current_time,
},
Expand Down Expand Up @@ -48,7 +48,7 @@ fn instantiation_unsuccessful() {
let current_time = mock_env().block.time;
let info = mock_info("owner", &[]);
let msg = InstantiateMsg {
start_epoch: EpochV2 {
start_epoch: Epoch {
id: 123,
start_time: current_time.minus_days(1),
},
Expand All @@ -65,7 +65,7 @@ fn instantiation_unsuccessful() {
}

let msg = InstantiateMsg {
start_epoch: EpochV2 {
start_epoch: Epoch {
id: 123,
start_time: current_time.plus_days(1),
},
Expand Down
6 changes: 3 additions & 3 deletions contracts/liquidity_hub/fee-distributor-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ authors = ["Kerber0x <[email protected]>"]
edition = "2021"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
6 changes: 3 additions & 3 deletions contracts/liquidity_hub/fee_collector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ documentation.workspace = true
publish.workspace = true

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
3 changes: 3 additions & 0 deletions contracts/liquidity_hub/incentive-manager/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[alias]
wasm = "build --release --lib --target wasm32-unknown-unknown"
unit-test = "test --lib"
11 changes: 11 additions & 0 deletions contracts/liquidity_hub/incentive-manager/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.rs]
indent_size = 4
16 changes: 16 additions & 0 deletions contracts/liquidity_hub/incentive-manager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Build results
/target
/schema

# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327)
.cargo-ok

# Text file backups
**/*.rs.bk

# macOS
.DS_Store

# IDEs
*.iml
.idea
45 changes: 45 additions & 0 deletions contracts/liquidity_hub/incentive-manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "incentive-manager"
version = "0.1.0"
authors = ["Kerber0x <[email protected]>"]
edition.workspace = true
description = "The Incentive Manager is a contract that allows to manage multiple pool incentives in a single contract."
license.workspace = true
repository.workspace = true
homepage.workspace = true
documentation.workspace = true
publish.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[features]
injective = ["white-whale-std/injective"]
token_factory = ["white-whale-std/token_factory"]
osmosis_token_factory = ["white-whale-std/osmosis_token_factory"]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]

[dependencies]
cosmwasm-schema.workspace = true
cosmwasm-std.workspace = true
cw-storage-plus.workspace = true
cw2.workspace = true
cw20.workspace = true
cw20-base.workspace = true
schemars.workspace = true
semver.workspace = true
serde.workspace = true
thiserror.workspace = true
white-whale-std.workspace = true
cw-utils.workspace = true
cw-ownable.workspace = true

[dev-dependencies]
cw-multi-test.workspace = true
white-whale-testing.workspace = true
epoch-manager.workspace = true
whale-lair.workspace = true
anyhow.workspace = true
4 changes: 4 additions & 0 deletions contracts/liquidity_hub/incentive-manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Incentive Manager

The Incentive Manager is the V2 iteration of the original incentives. This is a monolithic contract that handles all
the incentives-related logic.
Loading

0 comments on commit 62a82ed

Please sign in to comment.