Skip to content

Commit

Permalink
cw_wormhole refractor
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-1857 committed Mar 14, 2024
1 parent 16ce990 commit 10cac6c
Show file tree
Hide file tree
Showing 21 changed files with 1,473 additions and 703 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ sg721-base = "3.1.0"
syn = { version = "1.0", features = ["derive"] }
test-context = "0.1"
# thiserror = { version = "1.0" }
wynd-utils = "0.4"
wynd-utils = {path = "./packages/wynd-utils-0.4.1/"}
bincode = "1.3.3"


Expand Down
16 changes: 9 additions & 7 deletions contracts/external/cw-vesting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,24 @@ library = []

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true, features = ["staking"] }
cosmwasm-std = { workspace = true}
cw-denom = { workspace = true }
cw-ownable = { workspace = true }
cw-paginate-storage = { workspace = true }
cw-stake-tracker = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
secret-storage-plus = { workspace = true }
secret-utils = { workspace = true }
cw-wormhole = { workspace = true }
cw2 = { workspace = true }
cw20 = { workspace = true }
secret-cw2 = { workspace = true }
secret-toolkit = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
wynd-utils = { workspace = true }
snip20-reference-impl = { workspace = true }


[dev-dependencies]
anyhow = { workspace = true }
cw-multi-test = { workspace = true }
cw20-base = { workspace = true }
secret-multi-test = { workspace = true }
snip20-reference-impl = { workspace = true }
dao-testing = { workspace = true }
26 changes: 13 additions & 13 deletions contracts/external/cw-vesting/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
from_json, to_json_binary, Binary, Coin, CosmosMsg, DelegationResponse, Deps, DepsMut,
from_binary, to_binary, Binary, Coin, CosmosMsg, DelegationResponse, Deps, DepsMut,
DistributionMsg, Env, MessageInfo, Response, StakingMsg, StakingQuery, StdResult, Timestamp,
Uint128,
};
use cw2::set_contract_version;
use cw20::Cw20ReceiveMsg;
use secret_cw2::set_contract_version;
use snip20_reference_impl::receiver::Snip20ReceiveMsg;
use cw_denom::CheckedDenom;
use cw_ownable::OwnershipError;
use cw_utils::{must_pay, nonpayable};
use secret_utils::{must_pay, nonpayable};

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg, ReceiveMsg};
Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn instantiate(
None
}
}
CheckedDenom::Cw20(_) => {
CheckedDenom::Cw20(_,_) => {
nonpayable(&info)?; // Funding happens in ExecuteMsg::Receive.
None
}
Expand Down Expand Up @@ -132,12 +132,12 @@ pub fn execute_receive_cw20(
_env: Env,
deps: DepsMut,
info: MessageInfo,
receive_msg: Cw20ReceiveMsg,
receive_msg: Snip20ReceiveMsg,
) -> Result<Response, ContractError> {
// Only accepts cw20 tokens
nonpayable(&info)?;

let msg: ReceiveMsg = from_json(&receive_msg.msg)?;
let msg: ReceiveMsg = from_binary(&receive_msg.msg.unwrap())?;

match msg {
ReceiveMsg::Fund {} => {
Expand Down Expand Up @@ -446,20 +446,20 @@ pub fn execute_register_slash(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Ownership {} => to_json_binary(&cw_ownable::get_ownership(deps.storage)?),
QueryMsg::Info {} => to_json_binary(&PAYMENT.get_vest(deps.storage)?),
QueryMsg::Distributable { t } => to_json_binary(&PAYMENT.distributable(
QueryMsg::Ownership {} => to_binary(&cw_ownable::get_ownership(deps.storage)?),
QueryMsg::Info {} => to_binary(&PAYMENT.get_vest(deps.storage)?),
QueryMsg::Distributable { t } => to_binary(&PAYMENT.distributable(
deps.storage,
&PAYMENT.get_vest(deps.storage)?,
t.unwrap_or(env.block.time),
)?),
QueryMsg::Stake(q) => PAYMENT.query_stake(deps.storage, q),
QueryMsg::Vested { t } => to_json_binary(
QueryMsg::Vested { t } => to_binary(
&PAYMENT
.get_vest(deps.storage)?
.vested(t.unwrap_or(env.block.time)),
),
QueryMsg::TotalToVest {} => to_json_binary(&PAYMENT.get_vest(deps.storage)?.total()),
QueryMsg::VestDuration {} => to_json_binary(&PAYMENT.duration(deps.storage)?),
QueryMsg::TotalToVest {} => to_binary(&PAYMENT.get_vest(deps.storage)?.total()),
QueryMsg::VestDuration {} => to_binary(&PAYMENT.duration(deps.storage)?),
}
}
2 changes: 1 addition & 1 deletion contracts/external/cw-vesting/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_std::{StdError, Uint128};
use cw_denom::DenomError;
use cw_ownable::OwnershipError;
use cw_utils::PaymentError;
use secret_utils::PaymentError;
use thiserror::Error;
use wynd_utils::CurveError;

Expand Down
4 changes: 2 additions & 2 deletions contracts/external/cw-vesting/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Timestamp, Uint128};
use cw20::Cw20ReceiveMsg;
use snip20_reference_impl::receiver::Snip20ReceiveMsg;
use cw_denom::UncheckedDenom;
use cw_ownable::cw_ownable_execute;
use cw_stake_tracker::StakeTrackerQuery;
Expand Down Expand Up @@ -68,7 +68,7 @@ pub enum ExecuteMsg {
/// as the amount to be vested (as set during instantiation).
/// Anyone may call this method so long as the contract has not
/// yet been funded.
Receive(Cw20ReceiveMsg),
Receive(Snip20ReceiveMsg),
/// Distribute vested tokens to the vest receiver. Anyone may call
/// this method.
Distribute {
Expand Down
4 changes: 2 additions & 2 deletions contracts/external/cw-vesting/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cw_storage_plus::Item;
use secret_storage_plus::Item;

use crate::vesting::Payment;

pub const PAYMENT: Payment = Payment::new("vesting", "staked", "validator", "cardinality");
pub const PAYMENT: Payment = Payment::new("vesting", b"staked", b"validator", b"cardinality");
pub const UNBONDING_DURATION_SECONDS: Item<u64> = Item::new("ubs");
6 changes: 3 additions & 3 deletions contracts/external/cw-vesting/src/suite_tests/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ impl Suite {

pub fn query_receiver_vesting_token_balance(&self) -> Uint128 {
let vest = self.query_vest();
self.query_vesting_token_balance(vest.recipient)
self.query_vesting_token_balance(vest.recipient,"")
}

pub fn query_vesting_token_balance<S: Into<String>>(&self, who: S) -> Uint128 {
pub fn query_vesting_token_balance<S: Into<String>, K: Into<String>>(&self, who: S, key: K) -> Uint128 {
let vest = self.query_vest();
vest.denom
.query_balance(&self.app.wrap(), &Addr::unchecked(who.into()))
.query_balance(&self.app.wrap(), &Addr::unchecked(who.into()),key)
.unwrap()
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/external/cw-vesting/src/vesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cosmwasm_std::{
Addr, Binary, CosmosMsg, DistributionMsg, StdResult, Storage, Timestamp, Uint128, Uint64,
};
use cw_denom::CheckedDenom;
use cw_storage_plus::Item;
use secret_storage_plus::Item;
use wynd_utils::{Curve, PiecewiseLinear, SaturatingLinear};

use cw_stake_tracker::{StakeTracker, StakeTrackerQuery};
Expand Down Expand Up @@ -83,9 +83,9 @@ pub struct VestInit {
impl<'a> Payment<'a> {
pub const fn new(
vesting_prefix: &'a str,
staked_prefix: &'a str,
validator_prefix: &'a str,
cardinality_prefix: &'a str,
staked_prefix: &'a [u8],
validator_prefix: &'a [u8],
cardinality_prefix: &'a [u8],
) -> Self {
Self {
vesting: Item::new(vesting_prefix),
Expand Down
14 changes: 7 additions & 7 deletions packages/cw-stake-tracker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{to_json_binary, Binary, StdResult, Storage, Timestamp, Uint128};
use cosmwasm_std::{to_binary, Binary, StdResult, Storage, Timestamp, Uint128};
use cw_wormhole::Wormhole;

#[cfg(test)]
Expand Down Expand Up @@ -38,9 +38,9 @@ pub enum StakeTrackerQuery {

impl<'a> StakeTracker<'a> {
pub const fn new(
staked_prefix: &'a str,
validator_prefix: &'a str,
cardinality_prefix: &'a str,
staked_prefix: &'a [u8],
validator_prefix: &'a [u8],
cardinality_prefix: &'a [u8],
) -> Self {
Self {
total_staked: Wormhole::new(staked_prefix),
Expand Down Expand Up @@ -261,12 +261,12 @@ impl<'a> StakeTracker<'a> {
/// API.
pub fn query(&self, storage: &dyn Storage, msg: StakeTrackerQuery) -> StdResult<Binary> {
match msg {
StakeTrackerQuery::Cardinality { t } => to_json_binary(&Uint128::new(
StakeTrackerQuery::Cardinality { t } => to_binary(&Uint128::new(
self.validator_cardinality(storage, t)?.into(),
)),
StakeTrackerQuery::TotalStaked { t } => to_json_binary(&self.total_staked(storage, t)?),
StakeTrackerQuery::TotalStaked { t } => to_binary(&self.total_staked(storage, t)?),
StakeTrackerQuery::ValidatorStaked { validator, t } => {
to_json_binary(&self.validator_staked(storage, t, validator)?)
to_binary(&self.validator_staked(storage, t, validator)?)
}
}
}
Expand Down
Loading

0 comments on commit 10cac6c

Please sign in to comment.