Skip to content

Commit

Permalink
[CL Hooks]: Add hooks source and clean up source code folder (#6860)
Browse files Browse the repository at this point in the history
* implement hook messages and calls

* add comments and clean up helpers

* osmoutils go mod

* alpo/cl-hooks-wiring

* changelog

* clean up tests

* add hooks source and clean up source code folder

* tighten assertions

* remove dead code

* go mod osmoutils
  • Loading branch information
AlpinYukseloglu authored Nov 22, 2023
1 parent 9794620 commit 73d0141
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 22 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@
[workspace]
[package]
name = "counter"
version = "0.1.0"
authors = Osmosis Team
edition = "2021"

members = [
'contracts/*',
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"]

[profile.release]
codegen-units = 1
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false
lto = true
opt-level = 3
overflow-checks = true
panic = 'abort'
rpath = false

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.12.6
"""

[dependencies]
cosmwasm-schema = "1.1.2"
cosmwasm-std = "1.1.2"
cosmwasm-storage = "1.1.2"
cw-storage-plus = "0.13.2"
cw2 = "0.13.2"
schemars = "0.8.8"
serde = { version = "1.0.137", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }

[dev-dependencies]
cw-multi-test = "0.13.2"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "counter"
name = "hooks"
version = "0.1.0"
authors = Osmosis Team
authors = ["Alpin Yukseloglu <[email protected]>"]
edition = "2021"

exclude = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{coins, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, BankMsg, };
use cw2::set_contract_version;

use crate::error::ContractError;
use crate::msg::{InstantiateMsg, SudoMsg};
use crate::state::{State, STATE};

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:infinite-track-beforesend";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

/// Handling contract instantiation
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
info: MessageInfo,
_msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
let state = State {
count: 0,
};
STATE.save(deps.storage, &state)?;

// With `Response` type, it is possible to dispatch message to invoke external logic.
// See: https://github.com/CosmWasm/cosmwasm/blob/main/SEMANTICS.md#dispatching-messages
Ok(Response::new()
.add_attribute("method", "instantiate")
.add_attribute("owner", info.sender))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: (),
) -> Result<Response, ContractError> {
Ok(Response::default())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(_deps: Deps, _env: Env, _msg: ()) -> StdResult<Binary> {
Ok(Binary::default())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn sudo(_deps: DepsMut, _env: Env, msg: SudoMsg) -> Result<Response, ContractError> {
match msg {
SudoMsg::BeforeCreatePosition {
pool_id: _,
owner,
tokens_provided: _,
amount_0_min: _,
amount_1_min: _,
lower_tick: _,
upper_tick: _,
} => {
let mut response = Response::new();

// mint coins with denom "beforeCreatePosition" to owner
let coins = coins(1, "beforeCreatePosition");
let msg = BankMsg::Send {
to_address: owner.clone(),
amount: coins,
};
response = response.add_message(msg);

Ok(response.add_attribute("method", "sudo"))
},
SudoMsg::AfterCreatePosition {
pool_id: _,
owner,
tokens_provided: _,
amount_0_min: _,
amount_1_min: _,
lower_tick: _,
upper_tick: _,
} => {
let mut response = Response::new();

// mint coins with denom "afterCreatePosition" to owner
let coins = coins(1, "afterCreatePosition");
let msg = BankMsg::Send {
to_address: owner.clone(),
amount: coins,
};
response = response.add_message(msg);

Ok(response.add_attribute("method", "sudo"))
},
SudoMsg::BeforeWithdrawPosition {
pool_id: _,
owner,
position_id: _,
amount_to_withdraw: _,
} => {
let mut response = Response::new();

// mint coins with denom "beforeWithdrawPosition" to owner
let coins = coins(1, "beforeWithdrawPosition");
let msg = BankMsg::Send {
to_address: owner.clone(),
amount: coins,
};
response = response.add_message(msg);

Ok(response.add_attribute("method", "sudo"))
},
SudoMsg::AfterWithdrawPosition {
pool_id: _,
owner,
position_id: _,
amount_to_withdraw: _,
} => {
let mut response = Response::new();

// mint coins with denom "afterWithdrawPosition" to owner
let coins = coins(1, "afterWithdrawPosition");
let msg = BankMsg::Send {
to_address: owner.clone(),
amount: coins,
};
response = response.add_message(msg);

Ok(response.add_attribute("method", "sudo"))
},
SudoMsg::BeforeSwapExactAmountIn {
pool_id: _,
sender,
token_in: _,
token_out_denom: _,
token_out_min_amount: _,
spread_factor: _,
} => {
let mut response = Response::new();

// mint coins with denom "beforeSwapExactAmountIn" to sender
let coins = coins(1, "beforeSwapExactAmountIn");
let msg = BankMsg::Send {
to_address: sender.clone(),
amount: coins,
};
response = response.add_message(msg);

Ok(response.add_attribute("method", "sudo"))
},
SudoMsg::AfterSwapExactAmountIn {
pool_id: _,
sender,
token_in: _,
token_out_denom: _,
token_out_min_amount: _,
spread_factor: _,
} => {
let mut response = Response::new();

// mint coins with denom "afterSwapExactAmountIn" to sender
let coins = coins(1, "afterSwapExactAmountIn");
let msg = BankMsg::Send {
to_address: sender.clone(),
amount: coins,
};
response = response.add_message(msg);

Ok(response.add_attribute("method", "sudo"))
},
SudoMsg::BeforeSwapExactAmountOut {
pool_id: _,
sender,
token_in_denom: _,
token_in_max_amount: _,
token_out: _,
spread_factor: _,
} => {
let mut response = Response::new();

// mint coins with denom "beforeSwapExactAmountOut" to sender
let coins = coins(1, "beforeSwapExactAmountOut");
let msg = BankMsg::Send {
to_address: sender.clone(),
amount: coins,
};
response = response.add_message(msg);

Ok(response.add_attribute("method", "sudo"))
},
SudoMsg::AfterSwapExactAmountOut {
pool_id: _,
sender,
token_in_denom: _,
token_in_max_amount: _,
token_out: _,
spread_factor: _,
} => {
let mut response = Response::new();

// mint coins with denom "afterSwapExactAmountOut" to sender
let coins = coins(1, "afterSwapExactAmountOut");
let msg = BankMsg::Send {
to_address: sender.clone(),
amount: coins,
};
response = response.add_message(msg);

Ok(response.add_attribute("method", "sudo"))
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use cosmwasm_std::StdError;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),

#[error("Unauthorized")]
Unauthorized {},

#[error("Custom Error val: {val:?}")]
CustomError { val: String },
// Add any other custom errors you like here.
// Look at https://docs.rs/thiserror/1.0.21/thiserror/ for details.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod contract;
mod error;
pub mod msg;
pub mod state;

pub use crate::error::ContractError;
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::Coin;

#[cw_serde]
pub struct InstantiateMsg {}

#[cw_serde]
pub enum SudoMsg{
BeforeCreatePosition {
pool_id: u64,
owner: String,
tokens_provided: Vec<Coin>,
amount_0_min: String,
amount_1_min: String,
lower_tick: i64,
upper_tick: i64,
},
AfterCreatePosition {
pool_id: u64,
owner: String,
tokens_provided: Vec<Coin>,
amount_0_min: String,
amount_1_min: String,
lower_tick: i64,
upper_tick: i64,
},
BeforeWithdrawPosition {
pool_id: u64,
owner: String,
position_id: u64,
amount_to_withdraw: String,
},
AfterWithdrawPosition {
pool_id: u64,
owner: String,
position_id: u64,
amount_to_withdraw: String,
},
BeforeSwapExactAmountIn {
pool_id: u64,
sender: String,
token_in: Coin,
token_out_denom: String,
token_out_min_amount: String,
spread_factor: String,
},
AfterSwapExactAmountIn {
pool_id: u64,
sender: String,
token_in: Coin,
token_out_denom: String,
token_out_min_amount: String,
spread_factor: String,
},
BeforeSwapExactAmountOut {
pool_id: u64,
sender: String,
token_in_denom: String,
token_in_max_amount: String,
token_out: Coin,
spread_factor: String,
},
AfterSwapExactAmountOut {
pool_id: u64,
sender: String,
token_in_denom: String,
token_in_max_amount: String,
token_out: Coin,
spread_factor: String,
},
}

Loading

0 comments on commit 73d0141

Please sign in to comment.