diff --git a/contracts/liquidity_hub/epoch-manager/.cargo/config b/contracts/liquidity_hub/epoch-manager/.cargo/config deleted file mode 100644 index af5698e5..00000000 --- a/contracts/liquidity_hub/epoch-manager/.cargo/config +++ /dev/null @@ -1,4 +0,0 @@ -[alias] -wasm = "build --release --lib --target wasm32-unknown-unknown" -unit-test = "test --lib" -schema = "run --bin schema" diff --git a/contracts/liquidity_hub/epoch-manager/.editorconfig b/contracts/liquidity_hub/epoch-manager/.editorconfig deleted file mode 100644 index 3d36f20b..00000000 --- a/contracts/liquidity_hub/epoch-manager/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.rs] -indent_size = 4 diff --git a/contracts/liquidity_hub/epoch-manager/.gitignore b/contracts/liquidity_hub/epoch-manager/.gitignore deleted file mode 100644 index 9095deaa..00000000 --- a/contracts/liquidity_hub/epoch-manager/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -# 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 diff --git a/contracts/liquidity_hub/epoch-manager/Cargo.toml b/contracts/liquidity_hub/epoch-manager/Cargo.toml deleted file mode 100644 index 0a963cbe..00000000 --- a/contracts/liquidity_hub/epoch-manager/Cargo.toml +++ /dev/null @@ -1,38 +0,0 @@ -[package] -name = "epoch-manager" -version = "0.1.0" -authors = ["Kerber0x "] -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", -] - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[lib] -crate-type = ["cdylib", "rlib"] - -[features] -osmosis_token_factory = ["white-whale-std/osmosis_token_factory"] -injective = ["white-whale-std/injective"] -osmosis = ["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 -schemars.workspace = true -serde.workspace = true -semver.workspace = true -thiserror.workspace = true -white-whale-std.workspace = true -cw-controllers.workspace = true - -[dev-dependencies] -cw-multi-test.workspace = true diff --git a/contracts/liquidity_hub/epoch-manager/README.md b/contracts/liquidity_hub/epoch-manager/README.md deleted file mode 100644 index 054ea481..00000000 --- a/contracts/liquidity_hub/epoch-manager/README.md +++ /dev/null @@ -1,99 +0,0 @@ -# CosmWasm Starter Pack - -This is a template to build smart contracts in Rust to run inside a -[Cosmos SDK](https://github.com/cosmos/cosmos-sdk) module on all chains that enable it. -To understand the framework better, please read the overview in the -[cosmwasm repo](https://github.com/CosmWasm/cosmwasm/blob/master/README.md), -and dig into the [cosmwasm docs](https://www.cosmwasm.com). -This assumes you understand the theory and just want to get coding. - -## Creating a new repo from template - -Assuming you have a recent version of Rust and Cargo installed -(via [rustup](https://rustup.rs/)), -then the following should get you a new repo to start a contract: - -Install [cargo-generate](https://github.com/ashleygwilliams/cargo-generate) and cargo-run-script. -Unless you did that before, run this line now: - -```sh -cargo install cargo-generate --features vendored-openssl -cargo install cargo-run-script -``` - -Now, use it to create your new contract. -Go to the folder in which you want to place it and run: - -**Latest** - -```sh -cargo generate --git https://github.com/CosmWasm/cw-template.git --name PROJECT_NAME -``` - -For cloning minimal code repo: - -```sh -cargo generate --git https://github.com/CosmWasm/cw-template.git --name PROJECT_NAME -d minimal=true -``` - -**Older Version** - -Pass version as branch flag: - -```sh -cargo generate --git https://github.com/CosmWasm/cw-template.git --branch --name PROJECT_NAME -``` - -Example: - -```sh -cargo generate --git https://github.com/CosmWasm/cw-template.git --branch 0.16 --name PROJECT_NAME -``` - -You will now have a new folder called `PROJECT_NAME` (I hope you changed that to something else) -containing a simple working contract and build system that you can customize. - -## Create a Repo - -After generating, you have a initialized local git repo, but no commits, and no remote. -Go to a server (eg. github) and create a new upstream repo (called `YOUR-GIT-URL` below). -Then run the following: - -```sh -# this is needed to create a valid Cargo.lock file (see below) -cargo check -git branch -M main -git add . -git commit -m 'Initial Commit' -git remote add origin YOUR-GIT-URL -git push -u origin main -``` - -## CI Support - -We have template configurations for both [GitHub Actions](.github/workflows/Basic.yml) -and [Circle CI](.circleci/config.yml) in the generated project, so you can -get up and running with CI right away. - -One note is that the CI runs all `cargo` commands -with `--locked` to ensure it uses the exact same versions as you have locally. This also means -you must have an up-to-date `Cargo.lock` file, which is not auto-generated. -The first time you set up the project (or after adding any dep), you should ensure the -`Cargo.lock` file is updated, so the CI will test properly. This can be done simply by -running `cargo check` or `cargo unit-test`. - -## Using your project - -Once you have your custom repo, you should check out [Developing](./Developing.md) to explain -more on how to run tests and develop code. Or go through the -[online tutorial](https://docs.cosmwasm.com/) to get a better feel -of how to develop. - -[Publishing](./Publishing.md) contains useful information on how to publish your contract -to the world, once you are ready to deploy it on a running blockchain. And -[Importing](./Importing.md) contains information about pulling in other contracts or crates -that have been published. - -Please replace this README file with information about your specific project. You can keep -the `Developing.md` and `Publishing.md` files as useful referenced, but please set some -proper description in the README. diff --git a/contracts/liquidity_hub/epoch-manager/src/bin/schema.rs b/contracts/liquidity_hub/epoch-manager/src/bin/schema.rs deleted file mode 100644 index 7b0b4383..00000000 --- a/contracts/liquidity_hub/epoch-manager/src/bin/schema.rs +++ /dev/null @@ -1,11 +0,0 @@ -use cosmwasm_schema::write_api; - -use white_whale_std::epoch_manager::epoch_manager::{ExecuteMsg, InstantiateMsg, QueryMsg}; - -fn main() { - write_api! { - instantiate: InstantiateMsg, - execute: ExecuteMsg, - query: QueryMsg, - } -} diff --git a/contracts/liquidity_hub/epoch-manager/src/commands.rs b/contracts/liquidity_hub/epoch-manager/src/commands.rs deleted file mode 100644 index 321f6751..00000000 --- a/contracts/liquidity_hub/epoch-manager/src/commands.rs +++ /dev/null @@ -1,98 +0,0 @@ -use cosmwasm_std::{Api, DepsMut, Env, MessageInfo, Response, SubMsg}; - -use white_whale_std::epoch_manager::epoch_manager::EpochConfig; -use white_whale_std::epoch_manager::hooks::EpochChangedHookMsg; - -use crate::state::{ADMIN, CONFIG, EPOCH, HOOKS}; -use crate::ContractError; - -/// Adds a new hook to the contract. -pub fn add_hook( - deps: DepsMut, - info: MessageInfo, - api: &dyn Api, - contract_addr: &str, -) -> Result { - Ok(HOOKS.execute_add_hook(&ADMIN, deps, info, api.addr_validate(contract_addr)?)?) -} - -pub(crate) fn remove_hook( - deps: DepsMut, - info: MessageInfo, - api: &dyn Api, - contract_addr: &str, -) -> Result { - Ok(HOOKS.execute_remove_hook(&ADMIN, deps, info, api.addr_validate(contract_addr)?)?) -} - -/// Creates a new epoch. -pub fn create_epoch(deps: DepsMut, env: Env) -> Result { - let mut current_epoch = EPOCH.load(deps.storage)?; - let config = CONFIG.load(deps.storage)?; - - if env - .block - .time - .minus_nanos(current_epoch.start_time.nanos()) - .nanos() - < config.epoch_config.duration.u64() - { - return Err(ContractError::CurrentEpochNotExpired); - } - - current_epoch.id = current_epoch - .id - .checked_add(1u64) - .ok_or(ContractError::EpochOverflow)?; - current_epoch.start_time = current_epoch - .start_time - .plus_nanos(config.epoch_config.duration.u64()); - - EPOCH.save(deps.storage, ¤t_epoch)?; - - let messages = HOOKS.prepare_hooks(deps.storage, |hook| { - EpochChangedHookMsg { - current_epoch: current_epoch.clone(), - } - .into_cosmos_msg(hook) - .map(SubMsg::new) - })?; - - Ok(Response::default() - .add_submessages(messages) - .add_attributes(vec![ - ("action", "create_epoch".to_string()), - ("current_epoch", current_epoch.to_string()), - ])) -} - -/// Updates the config of the contract. -pub fn update_config( - mut deps: DepsMut, - info: &MessageInfo, - owner: Option, - epoch_config: Option, -) -> Result { - ADMIN.assert_admin(deps.as_ref(), &info.sender)?; - - if let Some(owner) = owner.clone() { - let new_admin = deps.api.addr_validate(owner.as_str())?; - ADMIN.set(deps.branch(), Some(new_admin))?; - } - - let mut config = CONFIG.load(deps.storage)?; - - if let Some(epoch_config) = epoch_config.clone() { - config.epoch_config = epoch_config; - CONFIG.save(deps.storage, &config)?; - } - - Ok(Response::default().add_attributes(vec![ - ("action", "update_config".to_string()), - ("owner", owner.unwrap_or_else(|| info.sender.to_string())), - ( - "epoch_config", - epoch_config.unwrap_or(config.epoch_config).to_string(), - ), - ])) -} diff --git a/contracts/liquidity_hub/epoch-manager/src/contract.rs b/contracts/liquidity_hub/epoch-manager/src/contract.rs deleted file mode 100644 index f3e3679e..00000000 --- a/contracts/liquidity_hub/epoch-manager/src/contract.rs +++ /dev/null @@ -1,104 +0,0 @@ -use cosmwasm_std::{entry_point, to_json_binary, StdError}; -use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; -use cw2::{get_contract_version, set_contract_version}; -use semver::Version; - -use white_whale_std::epoch_manager::epoch_manager::{ - Config, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, -}; -use white_whale_std::migrate_guards::check_contract_name; - -use crate::error::ContractError; -use crate::state::{ADMIN, CONFIG, EPOCH}; -use crate::{commands, queries}; - -// version info for migration info -const CONTRACT_NAME: &str = "white_whale-epoch-manager"; -const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); - -#[entry_point] -pub fn instantiate( - mut deps: DepsMut, - env: Env, - info: MessageInfo, - msg: InstantiateMsg, -) -> Result { - set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - - // validate start_time for the initial epoch - if msg.start_epoch.start_time < env.block.time { - return Err(ContractError::Std(StdError::generic_err( - "start_time must be in the future", - ))); - } - - if msg.epoch_config.genesis_epoch.u64() != msg.start_epoch.start_time.nanos() { - return Err(ContractError::Std(StdError::generic_err( - "genesis_epoch must be equal to start_epoch.start_time", - ))); - } - - ADMIN.set(deps.branch(), Some(info.sender))?; - EPOCH.save(deps.storage, &msg.start_epoch)?; - CONFIG.save( - deps.storage, - &Config { - epoch_config: msg.epoch_config.clone(), - }, - )?; - Ok(Response::default().add_attributes(vec![ - ("action", "instantiate".to_string()), - ("start_epoch", msg.start_epoch.to_string()), - ("epoch_config", msg.epoch_config.to_string()), - ])) -} - -#[entry_point] -pub fn execute( - deps: DepsMut, - env: Env, - info: MessageInfo, - msg: ExecuteMsg, -) -> Result { - let api = deps.api; - match msg { - ExecuteMsg::AddHook { contract_addr } => { - commands::add_hook(deps, info, api, &contract_addr) - } - ExecuteMsg::RemoveHook { contract_addr } => { - commands::remove_hook(deps, info, api, &contract_addr) - } - ExecuteMsg::CreateEpoch {} => commands::create_epoch(deps, env), - ExecuteMsg::UpdateConfig { - owner, - epoch_config, - } => commands::update_config(deps, &info, owner, epoch_config), - } -} - -#[entry_point] -pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - match msg { - QueryMsg::Config {} => Ok(to_json_binary(&queries::query_config(deps)?)?), - QueryMsg::CurrentEpoch {} => Ok(to_json_binary(&queries::query_current_epoch(deps)?)?), - QueryMsg::Epoch { id } => Ok(to_json_binary(&queries::query_epoch(deps, id)?)?), - } -} - -#[entry_point] -pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { - check_contract_name(deps.storage, CONTRACT_NAME.to_string())?; - let version: Version = CONTRACT_VERSION.parse()?; - let storage_version: Version = get_contract_version(deps.storage)?.version.parse()?; - - if storage_version >= version { - return Err(ContractError::MigrateInvalidVersion { - current_version: storage_version, - new_version: version, - }); - } - - set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - - Ok(Response::default()) -} diff --git a/contracts/liquidity_hub/epoch-manager/src/error.rs b/contracts/liquidity_hub/epoch-manager/src/error.rs deleted file mode 100644 index 7a2bd5f1..00000000 --- a/contracts/liquidity_hub/epoch-manager/src/error.rs +++ /dev/null @@ -1,37 +0,0 @@ -use cosmwasm_std::StdError; -use cw_controllers::{AdminError, HookError}; -use semver::Version; -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum ContractError { - #[error("{0}")] - Std(#[from] StdError), - - #[error("{0}")] - AdminError(#[from] AdminError), - - #[error("{0}")] - HookError(#[from] HookError), - - #[error("The epoch id has overflowed.")] - EpochOverflow, - - #[error("Semver parsing error: {0}")] - SemVer(String), - - #[error("Attempt to migrate to version {new_version}, but contract is on a higher version {current_version}")] - MigrateInvalidVersion { - new_version: Version, - current_version: Version, - }, - - #[error("The current epoch epoch has not expired yet.")] - CurrentEpochNotExpired, -} - -impl From for ContractError { - fn from(err: semver::Error) -> Self { - Self::SemVer(err.to_string()) - } -} diff --git a/contracts/liquidity_hub/epoch-manager/src/lib.rs b/contracts/liquidity_hub/epoch-manager/src/lib.rs deleted file mode 100644 index 95db3d1b..00000000 --- a/contracts/liquidity_hub/epoch-manager/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub use crate::error::ContractError; - -pub mod commands; -pub mod contract; -mod error; -pub mod queries; -pub mod state; diff --git a/contracts/liquidity_hub/epoch-manager/src/queries.rs b/contracts/liquidity_hub/epoch-manager/src/queries.rs deleted file mode 100644 index 75775a59..00000000 --- a/contracts/liquidity_hub/epoch-manager/src/queries.rs +++ /dev/null @@ -1,42 +0,0 @@ -use cosmwasm_std::{Addr, Deps, StdResult}; - -use white_whale_std::epoch_manager::epoch_manager::{ConfigResponse, EpochResponse, EpochV2}; - -use crate::state::{ADMIN, CONFIG, EPOCH}; - -/// Queries the config. Returns a [ConfigResponse]. -pub(crate) fn query_config(deps: Deps) -> StdResult { - let admin = ADMIN.get(deps)?.unwrap_or(Addr::unchecked("")); - let config = CONFIG.load(deps.storage)?; - - Ok(ConfigResponse { - owner: admin, - epoch_config: config.epoch_config, - }) -} - -/// Queries the current epoch. Returns an [EpochResponse]. -pub(crate) fn query_current_epoch(deps: Deps) -> StdResult { - EPOCH - .load(deps.storage) - .map(|epoch| epoch.to_epoch_response()) -} - -/// Queries the current epoch. Returns an [EpochResponse]. -pub(crate) fn query_epoch(deps: Deps, id: u64) -> StdResult { - let current_epoch = EPOCH.load(deps.storage)?; - - if current_epoch.id == id { - Ok(current_epoch.to_epoch_response()) - } else { - let epoch_difference = current_epoch.id.saturating_sub(id); - - let epoch = EpochV2 { - id, - start_time: current_epoch.start_time.minus_nanos( - CONFIG.load(deps.storage)?.epoch_config.duration.u64() * epoch_difference, - ), - }; - Ok(epoch.to_epoch_response()) - } -} diff --git a/contracts/liquidity_hub/epoch-manager/src/state.rs b/contracts/liquidity_hub/epoch-manager/src/state.rs deleted file mode 100644 index 1e0c424b..00000000 --- a/contracts/liquidity_hub/epoch-manager/src/state.rs +++ /dev/null @@ -1,8 +0,0 @@ -use cw_controllers::{Admin, Hooks}; -use cw_storage_plus::Item; -use white_whale_std::epoch_manager::epoch_manager::{Config, EpochV2}; - -pub const CONFIG: Item = Item::new("config"); -pub const ADMIN: Admin = Admin::new("admin"); -pub const HOOKS: Hooks = Hooks::new("hooks"); -pub const EPOCH: Item = Item::new("epoch");