Skip to content

Commit

Permalink
feat: dust-collection functional/tested
Browse files Browse the repository at this point in the history
  • Loading branch information
PFC-developer committed Oct 28, 2023
1 parent c82d488 commit d1b8240
Show file tree
Hide file tree
Showing 11 changed files with 813 additions and 1,905 deletions.
1,588 changes: 65 additions & 1,523 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["contracts/*", "packages/*"]
members = ["contracts/token", "contracts/hub", "contracts/hub-tf", "packages/*"]
resolver = '1'

[profile.release.package.pfc-steak]
opt-level = 3
Expand All @@ -9,6 +10,12 @@ codegen-units = 1
incremental = false

[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false
overflow-checks = true
5 changes: 3 additions & 2 deletions contracts/hub-tf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ backtraces = ["cosmwasm-std/backtraces"]

[dependencies]
#cosmwasm-std = { version = "1.2.1", features=["iterator","stargate","cosmwasm_1_1","staking"]}
cosmwasm-std = { version = "1.2.1", features=["iterator","stargate","staking"]}
cosmwasm-std = { version = "1.0.1", features=["iterator","stargate","staking"]}

cw2= "1.0.1"
#cw20 = "1.0.0"
Expand All @@ -29,6 +29,7 @@ pfc-steak = { path = "../../packages/steak" }
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
pfc-fee-split = "0.2.5"
pfc-dust-collector="0.1.0"
#kujira = "0.7.25"
#{ path="../../packages/pfc-dust-collector" }
osmosis-std-derive="0.13.2"
[dev-dependencies]
protobuf = { version = "3.1.0", features = ["with-bytes"] }
82 changes: 49 additions & 33 deletions contracts/hub-tf/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use cosmwasm_std::{Binary, Deps, DepsMut, entry_point, Env, MessageInfo, Reply, Response, StdError, StdResult, to_binary};
use cw2::{ContractVersion, get_contract_version, set_contract_version};
use cosmwasm_std::{
entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError,
StdResult,
};
use cw2::{get_contract_version, set_contract_version, ContractVersion};
use std::convert::TryInto;

use pfc_steak::hub::{CallbackMsg, MigrateMsg, QueryMsg};
use pfc_steak::hub_tf::{ExecuteMsg, InstantiateMsg, TokenFactoryType};

use crate::{execute, queries};
use crate::state::State;
use crate::{execute, queries};

//use crate::helpers::{ unwrap_reply};

Expand Down Expand Up @@ -41,14 +45,16 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S
.unwrap_or(info.sender),
info.funds,
exec_msg,
true,
),
ExecuteMsg::Unbond { receiver } => execute::queue_unbond(
deps,
env,
receiver
.map(|s| api.addr_validate(&s))
.transpose()?
.unwrap_or(info.sender), info.funds,
.unwrap_or(info.sender),
info.funds,
),
ExecuteMsg::WithdrawUnbonded { receiver } => execute::withdraw_unbonded(
deps,
Expand All @@ -71,9 +77,10 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S
ExecuteMsg::RemoveValidatorEx { validator } => {
execute::remove_validator_ex(deps, env, info.sender, validator)
}
ExecuteMsg::Redelegate { validator_from,validator_to } => {
execute::redelegate(deps, env, info.sender, validator_from,validator_to)
}
ExecuteMsg::Redelegate {
validator_from,
validator_to,
} => execute::redelegate(deps, env, info.sender, validator_from, validator_to),

ExecuteMsg::TransferOwnership { new_owner } => {
execute::transfer_ownership(deps, info.sender, new_owner)
Expand All @@ -83,9 +90,10 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S
ExecuteMsg::Rebalance { minimum } => execute::rebalance(deps, env, minimum),
ExecuteMsg::Reconcile {} => execute::reconcile(deps, env),
ExecuteMsg::SubmitBatch {} => execute::submit_batch(deps, env),
ExecuteMsg::TransferFeeAccount { fee_account_type, new_fee_account } => {
execute::transfer_fee_account(deps, info.sender, fee_account_type, new_fee_account)
}
ExecuteMsg::TransferFeeAccount {
fee_account_type,
new_fee_account,
} => execute::transfer_fee_account(deps, info.sender, fee_account_type, new_fee_account),
ExecuteMsg::UpdateFee { new_fee } => execute::update_fee(deps, info.sender, new_fee),
ExecuteMsg::Callback(callback_msg) => callback(deps, env, info, callback_msg),
ExecuteMsg::PauseValidator { validator } => {
Expand All @@ -94,15 +102,27 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S
ExecuteMsg::UnPauseValidator { validator } => {
execute::unpause_validator(deps, env, info.sender, validator)
}
ExecuteMsg::SetUnbondPeriod { unbond_period } => execute::set_unbond_period(deps, env, info.sender, unbond_period),
ExecuteMsg::SetUnbondPeriod { unbond_period } => {
execute::set_unbond_period(deps, env, info.sender, unbond_period)
}

ExecuteMsg::SetDustCollector { dust_collector } => { execute::set_dust_collector(deps, env, info.sender, dust_collector) }
ExecuteMsg::CollectDust { max_tokens } => { execute::collect_dust(deps, env, max_tokens) }
ExecuteMsg::ReturnDenom {} => { execute::return_denom(deps, env, info.funds) }
ExecuteMsg::SetDustCollector { dust_collector } => {
execute::set_dust_collector(deps, env, info.sender, dust_collector)
}
ExecuteMsg::CollectDust { max_tokens } => {
let max_tokens_usize_r = max_tokens.try_into();
if let Ok(max_tokens_usize) = max_tokens_usize_r {
execute::collect_dust(deps, env, max_tokens_usize)
} else {
Err(StdError::generic_err("max_tokens too large"))
}
}
ExecuteMsg::ReturnDenom {} => {
execute::bond(deps, env, info.sender, info.funds, None, false)
}
}
}


fn callback(
deps: DepsMut,
env: Env,
Expand All @@ -121,21 +141,14 @@ fn callback(
}

#[entry_point]
pub fn reply(deps: DepsMut, env: Env, reply: Reply) -> StdResult<Response> {
pub fn reply(_deps: DepsMut, _env: Env, reply: Reply) -> StdResult<Response> {
match reply.id {
REPLY_REGISTER_RECEIVED_COINS => {
execute::collect_dust(deps, env,10)
}
_ => {
Err(StdError::generic_err(format!(
"invalid reply id: {} {:?}",
reply.id,
reply.result
))
)
}
REPLY_REGISTER_RECEIVED_COINS => Ok(Response::default()),
_ => Err(StdError::generic_err(format!(
"invalid reply id: {} {:?}",
reply.id, reply.result
))),
}

}

#[entry_point]
Expand Down Expand Up @@ -186,16 +199,19 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response
#[allow(clippy::single_match)]
"0" => {}
"3.0.1" | "3.0.2" => {
let state = State::default();
let state = State::default();
let kuji = state.kuji_token_factory.load(deps.storage)?;
if kuji {
state.token_factory_type.save(deps.storage,&TokenFactoryType::Kujira)?
state
.token_factory_type
.save(deps.storage, &TokenFactoryType::Kujira)?
} else {
state.token_factory_type.save(deps.storage,&TokenFactoryType::CosmWasm)?
state
.token_factory_type
.save(deps.storage, &TokenFactoryType::CosmWasm)?
}

}
_ => {}
_ => {}
},
_ => {
return Err(StdError::generic_err(
Expand Down
Loading

0 comments on commit d1b8240

Please sign in to comment.