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

feat: incentive manager #323

Merged
merged 38 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
434684c
chore: incentive manager init
kerber0x Dec 15, 2023
8dab7d6
chore: initial commit incentive manager
kerber0x Dec 27, 2023
29b1bad
chore: update message to manage incentives
kerber0x Dec 28, 2023
25878b0
chore(incentive_manager): implement closing incentives
kerber0x Dec 29, 2023
ff85e9f
chore(incentive_manager): add epoch changed hook
kerber0x Dec 29, 2023
0a31aea
chore: add message and structs for managing positions
kerber0x Jan 2, 2024
501e2d6
chore: impl fill position
kerber0x Jan 3, 2024
14e7ad0
chore: impl expand position, refactor into fill_position fn
kerber0x Jan 4, 2024
005406c
chore: impl expand position, refactor into fill_position fn
kerber0x Jan 4, 2024
b76b896
chore: abstracting the update_ownership function into white-whale com…
kerber0x Jan 24, 2024
a8e3d86
chore: rework of the positions management
kerber0x Feb 20, 2024
095a1f9
chore: refactoring
kerber0x Feb 22, 2024
d2ddb11
feat: emergency withdrawal
kerber0x Feb 23, 2024
991eca4
chore: merge v2 branch
kerber0x Mar 12, 2024
48329e5
chore: finish removing cw20 support from incentive manager
kerber0x Mar 13, 2024
b29e311
chore: prework on claim
kerber0x Mar 26, 2024
ab8012f
feat(incentive_manager): claim implementation
kerber0x Mar 27, 2024
2be651b
chore(incentive): ensure expansion amount is a multiple of the emorig…
kerber0x Apr 2, 2024
137f326
chore: add queries
kerber0x Apr 2, 2024
8aa8a9d
chore: add remaining queries
kerber0x Apr 2, 2024
734b6f7
chore: remove unnecessary positions indexes from map
kerber0x Apr 3, 2024
050c807
refactor: incentive manager cleanup
kerber0x Apr 3, 2024
50574bd
chore: merge branch 'release/v2_contracts' into feat/incentive-manager
kerber0x Apr 3, 2024
4bc1404
test: add suite for testing incentive manager
kerber0x Apr 5, 2024
4c10c71
test: add tests for creating incentives
kerber0x Apr 5, 2024
45a7b85
test: add tests for expanding incentive
kerber0x Apr 5, 2024
e6597c4
test: add test for closing incentives
kerber0x Apr 5, 2024
6677bfd
test: update config tests
kerber0x Apr 5, 2024
c41cd3c
chore: add test to manage position while fixing minor bugs
kerber0x Apr 8, 2024
2cb67f4
test: add missing tests
kerber0x Apr 9, 2024
ff5763e
test: add complex test
kerber0x Apr 10, 2024
5f4d388
test: final tweaks and tests complementation
kerber0x Apr 10, 2024
98af037
refactor: improve state by reusing map for contract lp weights
kerber0x Apr 11, 2024
1a506aa
chore: merge branch 'release/v2_contracts' into feat/incentive-manager
kerber0x Apr 11, 2024
7d79a36
chore: add incentive manager to xtask
kerber0x Apr 11, 2024
88f82b1
chore: fix injective build
kerber0x Apr 11, 2024
fb30f1f
chore: remove the schema generation alias
kerber0x Apr 12, 2024
64ec60f
chore: cleanup things after PR suggestions
kerber0x Apr 12, 2024
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
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.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"contracts/liquidity_hub/pool-manager",
"contracts/liquidity_hub/epoch-manager",
"contracts/liquidity_hub/vault-manager",
"contracts/liquidity_hub/incentive-manager",
]

[workspace.package]
Expand Down Expand Up @@ -64,6 +65,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
1 change: 1 addition & 0 deletions contracts/liquidity_hub/epoch-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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");
kerber0x marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 4 additions & 0 deletions contracts/liquidity_hub/incentive-manager/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --lib --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --bin schema"
kerber0x marked this conversation as resolved.
Show resolved Hide resolved
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.
11 changes: 11 additions & 0 deletions contracts/liquidity_hub/incentive-manager/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cosmwasm_schema::write_api;

use white_whale_std::incentive_manager::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: ExecuteMsg,
query: QueryMsg,
}
}
kerber0x marked this conversation as resolved.
Show resolved Hide resolved
Loading