Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
orkunkl committed Dec 6, 2024
1 parent bf92af4 commit 874d773
Show file tree
Hide file tree
Showing 14 changed files with 774 additions and 255 deletions.
960 changes: 746 additions & 214 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ too_many_arguments = "allow"
module_inception = "allow"

[workspace.dependencies]
cosmwasm-schema = "1.5.7"
cosmwasm-std = { version = "1.5.7", features = ["iterator", "staking", "stargate", "cosmwasm_1_2"] }
cw-controllers = "1.1.2"
cosmwasm-schema = "2.1.4"
cosmwasm-std = { version = "2.1.4", features = ["iterator", "staking", "stargate", "cosmwasm_1_2"] }
cw-controllers = "2.0.0"
cw-denom = "2.3.0"
cw-multi-test = { version = "0.20.1", features = ["cosmwasm_1_2"] }
cw-storage-plus = "1.2.0"
cw-utils = "1.0.3"
cw-multi-test = { version = "2.2.0", features = ["cosmwasm_1_2"] }
cw-storage-plus = "2.0.0"
cw-utils = "2.0.0"
cw-vesting = { version = "2.3.0", features = ["library"] }
cw-orch = { version = "0.24.1" }
cw2 = "1.1.2"
osmosis-std = "0.25.0"
cw-orch = { version = "0.27.0" }
cw2 = "2.0.0"
osmosis-std = "0.26.0"
osmosis_prost = { version = "0.13.1", package = "prost" }
schemars = "0.8.11"
semver = "1.0.16"
serde = { version = "1.0.152", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.38" }
thiserror = { version = "2.0.4" }

# contracts
streamswap-controller = { path = "./contracts/controller" }
Expand All @@ -55,5 +55,5 @@ streamswap-tests = { path = "./tests" }
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/workspace-optimizer:0.16.0
cosmwasm/optimizer:0.16.1
"""
File renamed without changes.
2 changes: 0 additions & 2 deletions contracts/controller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ workspace = true
crate-type = ["cdylib", "rlib"]

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

Expand Down
2 changes: 1 addition & 1 deletion contracts/controller/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub enum ContractError {
#[error("Required denom not found in funds")]
NoFundsSent {},

#[error("In_denom does not match config")]
#[error("In_denom does not match config.toml")]
InDenomIsNotAccepted {},

#[error("Out_denom can not be the same as in_denom")]
Expand Down
2 changes: 0 additions & 2 deletions contracts/stream/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ crate-type = ["cdylib", "rlib"]
workspace = true

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

Expand Down
13 changes: 6 additions & 7 deletions contracts/stream/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn instantiate(
bootstraping_start_time.to_string(),
),
];
// if pool config is set, add attributes
// if pool config.toml is set, add attributes
if let Some(pool_config) = pool_config {
match pool_config {
PoolConfig::ConcentratedLiquidity { out_amount_clp } => {
Expand Down Expand Up @@ -282,7 +282,8 @@ pub fn sync_position(
position.pending_purchase = decimals;

// floors the decimal points
uint256_purchased = purchased * Uint256::one();
uint256_purchased = purchased.to_uint_floor();

position.purchased = position.purchased.checked_add(uint256_purchased)?;
}

Expand Down Expand Up @@ -482,8 +483,7 @@ pub fn execute_finalize_stream(

// Stream's swap fee collected at fixed rate from accumulated spent_in of positions(ie stream.spent_in)
let swap_fee = Decimal256::from_ratio(stream_state.spent_in, Uint128::one())
.checked_mul(controller_params.exit_fee_percent)?
* Uint256::one();
.checked_mul(controller_params.exit_fee_percent)?.to_uint_floor();

// extract swap_fee from last amount
creator_revenue = creator_revenue.checked_sub(swap_fee)?;
Expand Down Expand Up @@ -514,7 +514,7 @@ pub fn execute_finalize_stream(
// execute post stream actions
let post_stream_actions = POST_STREAM.may_load(deps.storage)?;
if let Some(post_stream_actions) = post_stream_actions {
// if pool config and create pool is set, create a pool for the stream
// if pool config.toml and create pool is set, create a pool for the stream
creator_revenue = match (post_stream_actions.pool_config, create_pool) {
(Some(pool_config), Some(create_pool)) => {
let (msgs, attrs, creator_revenue) = pool_operations(
Expand Down Expand Up @@ -650,8 +650,7 @@ pub fn execute_exit_stream(

// Swap fee = fixed_rate*position.spent_in this calculation is only for execution reply attributes
let swap_fee = Decimal256::from_ratio(position.spent, Uint128::one())
.checked_mul(controller_params.exit_fee_percent)?
* Uint256::one();
.checked_mul(controller_params.exit_fee_percent)?.to_uint_floor();

let mut messages: Vec<CosmosMsg> = vec![];
let mut attributes: Vec<Attribute> = vec![];
Expand Down
6 changes: 3 additions & 3 deletions contracts/stream/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub enum ContractError {
#[error("Required denom not found in funds")]
NoFundsSent {},

#[error("In_denom does not match config")]
#[error("In_denom does not match config.toml")]
InDenomIsNotAccepted {},

#[error("Out_denom can not be the same as in_denom")]
Expand Down Expand Up @@ -148,12 +148,12 @@ pub enum ContractError {
#[error("Operation not allowed in ths current state {current_status}")]
OperationNotAllowed { current_status: String },

#[error("Pool config not provided")]
#[error("Pool config.toml not provided")]
PoolConfigNotProvided {},

#[error("Create pool not provided")]
CreatePoolNotProvided {},

#[error("Invalid pool config")]
#[error("Invalid pool config.toml")]
InvalidPoolConfig {},
}
2 changes: 1 addition & 1 deletion contracts/stream/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn calculate_in_amount_clp(
let ratio = Decimal256::from_ratio(pool_out_amount, out_amount);
let dec_creators_revenue = Decimal256::from_ratio(creators_revenue, Uint256::from(1u64));
let dec_clp_amount = ratio * dec_creators_revenue;
dec_clp_amount * Uint256::from(1u64)
dec_clp_amount.to_uint_floor()
}

/// This function is used to build the MsgCreatePosition for the initial pool position
Expand Down
9 changes: 3 additions & 6 deletions contracts/stream/src/vesting.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
use crate::ContractError;
use cosmwasm_std::{
attr, coin, to_json_binary, Addr, Attribute, Binary, CosmosMsg, DepsMut, HexBinary, Timestamp,
Uint128, WasmMsg,
};
use cosmwasm_std::{attr, coin, to_json_binary, Addr, Attribute, Binary, Checksum, CosmosMsg, DepsMut, Timestamp, WasmMsg};
use cw_vesting::msg::InstantiateMsg as VestingInstantiateMsg;
use cw_vesting::UncheckedDenom;
use streamswap_types::controller::VestingConfig;

pub fn vesting_operations(
deps: &DepsMut,
stream_addr: Addr,
vesting_checksum: HexBinary,
vesting_checksum: Checksum,
recipient: Addr,
salt: Option<Binary>,
start_time: Timestamp,
vesting_code_id: u64,
amount: Uint128,
amount: cosmwasm_std::Uint128,
denom: String,
vesting_config: VestingConfig,
) -> Result<(Vec<CosmosMsg>, Vec<Attribute>, Addr), ContractError> {
Expand Down
1 change: 0 additions & 1 deletion packages/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ homepage = { workspace = true }
[features]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
interface = ["dep:cw-orch"]

[lints]
Expand Down
6 changes: 3 additions & 3 deletions packages/types/src/stream/threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ pub type Threshold = Uint256;

pub const THRESHOLDS_STATE_KEY: &str = "thresholds";

pub struct ThresholdState<'a>(Item<'a, Threshold>);
pub struct ThresholdState(Item<Threshold>);

impl<'a> ThresholdState<'a> {
impl ThresholdState {
pub fn new() -> Self {
ThresholdState(Item::new(THRESHOLDS_STATE_KEY))
}
Expand Down Expand Up @@ -74,7 +74,7 @@ impl<'a> ThresholdState<'a> {
}
}

impl<'a> Default for ThresholdState<'a> {
impl Default for ThresholdState {
fn default() -> Self {
ThresholdState::new()
}
Expand Down
2 changes: 0 additions & 2 deletions packages/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ homepage = { workspace = true }

[features]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]

[lints]
workspace = true
Expand Down
2 changes: 0 additions & 2 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ license = { workspace = true }
[lib]
doctest = false
[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]

[lints]
workspace = true
Expand Down

0 comments on commit 874d773

Please sign in to comment.