Skip to content

Commit

Permalink
Merge pull request #168 from confio/release-0.13
Browse files Browse the repository at this point in the history
Release 0.13
  • Loading branch information
maurolacy authored Jul 26, 2022
2 parents 35997ce + d07adfd commit d796143
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 164 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@

## [Unreleased](https://github.com/confio/poe-contracts/tree/HEAD)

[Full Changelog](https://github.com/confio/poe-contracts/compare/v0.12.0...HEAD)
[Full Changelog](https://github.com/confio/poe-contracts/compare/v0.13.0...HEAD)

## [v0.13.0](https://github.com/confio/poe-contracts/tree/v0.13.0) (2022-07-26)

[Full Changelog](https://github.com/confio/poe-contracts/compare/v0.12.0...v0.13.0)

**Closed issues:**

- bug when defining the jailing start time [\#162](https://github.com/confio/poe-contracts/issues/162)
- \[tgrade-validator-voting\] Add proposal validation during creation [\#156](https://github.com/confio/poe-contracts/issues/156)

**Merged pull requests:**

- Older version migration helper [\#164](https://github.com/confio/poe-contracts/pull/164) ([maurolacy](https://github.com/maurolacy))
- Validate proposal during creation [\#163](https://github.com/confio/poe-contracts/pull/163) ([maurolacy](https://github.com/maurolacy))

## [v0.12.0](https://github.com/confio/poe-contracts/tree/v0.12.0) (2022-07-14)

Expand Down
32 changes: 16 additions & 16 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions contracts/tg4-engagement/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tg4-engagement"
version = "0.12.0"
version = "0.13.0"
authors = ["Ethan Frey <[email protected]>"]
edition = "2018"
description = "Simple TG4 implementation of group membership controlled by an admin"
Expand All @@ -25,9 +25,9 @@ cw-controllers = "0.13.4"
cw-storage-plus = "0.13.4"
cw-utils = "0.13.4"
cw2 = "0.13.4"
tg-utils = { version = "0.12.0", path = "../../packages/utils" }
tg-bindings = { version = "0.12.0", path = "../../packages/bindings" }
tg4 = { path = "../../packages/tg4", version = "0.12.0" }
tg-utils = { version = "0.13.0", path = "../../packages/utils" }
tg-bindings = { version = "0.13.0", path = "../../packages/bindings" }
tg4 = { path = "../../packages/tg4", version = "0.13.0" }
schemars = "0.8"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = "1.0.21"
Expand All @@ -37,4 +37,4 @@ anyhow = "1"
cosmwasm-schema = "1.0.0"
cw-multi-test = "0.13.4"
derivative = "2"
tg-bindings-test = { version = "0.12.0", path = "../../packages/bindings-test" }
tg-bindings-test = { version = "0.13.0", path = "../../packages/bindings-test" }
4 changes: 2 additions & 2 deletions contracts/tg4-group/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tg4-group"
version = "0.12.0"
version = "0.13.0"
authors = ["Mauro Lacy <[email protected]>"]
edition = "2018"
description = "Simple tg4 implementation of group membership controlled by admin"
Expand Down Expand Up @@ -34,7 +34,7 @@ cw-controllers = "0.13.4"
cw-storage-plus = "0.13.4"
schemars = "0.8.1"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
tg4 = { version = "0.12.0", path = "../../packages/tg4" }
tg4 = { version = "0.13.0", path = "../../packages/tg4" }
thiserror = { version = "1.0.23" }

[dev-dependencies]
Expand Down
12 changes: 6 additions & 6 deletions contracts/tg4-mixer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tg4-mixer"
version = "0.12.0"
version = "0.13.0"
authors = ["Ethan Frey <[email protected]>"]
edition = "2018"
description = "TG4 implementation that combines two different groups with a merge function"
Expand Down Expand Up @@ -33,17 +33,17 @@ rust_decimal_macros = { version = "1.16", default-features = false }
thiserror = "1.0.21"
schemars = "0.8"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
tg4 = { path = "../../packages/tg4", version = "0.12.0" }
tg-utils = { path = "../../packages/utils", version = "0.12.0" }
tg-bindings = { path = "../../packages/bindings", version = "0.12.0" }
tg4 = { path = "../../packages/tg4", version = "0.13.0" }
tg-utils = { path = "../../packages/utils", version = "0.13.0" }
tg-bindings = { path = "../../packages/bindings", version = "0.13.0" }

[dev-dependencies]
cosmwasm-schema = "1.0.0"
# bench dependencies
cosmwasm-vm = { version = "1.0.0" }
cw-multi-test = "0.13.4"
tg4-engagement = { path = "../tg4-engagement", version = "0.12.0", features = ["library"] }
tg4-stake = { path = "../tg4-stake", version = "0.12.0", features = ["library"] }
tg4-engagement = { path = "../tg4-engagement", version = "0.13.0", features = ["library"] }
tg4-stake = { path = "../tg4-stake", version = "0.13.0", features = ["library"] }

[[bench]]
name = "main"
Expand Down
10 changes: 5 additions & 5 deletions contracts/tg4-stake/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tg4-stake"
version = "0.12.0"
version = "0.13.0"
authors = ["Ethan Frey <[email protected]>"]
edition = "2018"
description = "TG4 implementation of group based on staked tokens"
Expand Down Expand Up @@ -28,11 +28,11 @@ cw-storage-plus = "0.13.4"
itertools = "0.10"
schemars = "0.8.1"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
tg4 = { path = "../../packages/tg4", version = "0.12.0" }
tg-utils = { path = "../../packages/utils", version = "0.12.0" }
tg-bindings = { path = "../../packages/bindings", version = "0.12.0" }
tg4 = { path = "../../packages/tg4", version = "0.13.0" }
tg-utils = { path = "../../packages/utils", version = "0.13.0" }
tg-bindings = { path = "../../packages/bindings", version = "0.13.0" }
thiserror = "1.0.21"

[dev-dependencies]
cosmwasm-schema = "1.0.0"
tg-bindings-test = { path = "../../packages/bindings-test", version = "0.12.0" }
tg-bindings-test = { path = "../../packages/bindings-test", version = "0.13.0" }
34 changes: 28 additions & 6 deletions contracts/tg4-stake/src/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ const DEFAULT_LIMIT: u32 = 30;
pub struct Claim {
/// Address owning the claim
pub addr: Addr,
/// Amount of tokens in claim
/// Liquid amount of tokens in claim
pub amount: Uint128,
/// Vesting amount of tokens in claim
pub vesting_amount: Option<Uint128>,
/// Release time of the claim. Originally in `cw_controllers` it is an `Expiration` type, but
/// here we need to query for claims via release time, and expiration is impossible to be
/// properly sorted, as it is impossible to properly compare expiration by height and
Expand All @@ -43,10 +45,17 @@ impl<'a> IndexList<Claim> for ClaimIndexes<'a> {
}

impl Claim {
pub fn new(addr: Addr, amount: u128, released: Expiration, creation_height: u64) -> Self {
pub fn new(
addr: Addr,
amount: u128,
vesting_amount: u128,
released: Expiration,
creation_height: u64,
) -> Self {
Claim {
addr,
amount: amount.into(),
vesting_amount: Some(vesting_amount.into()),
release_at: released,
creation_height,
}
Expand Down Expand Up @@ -80,6 +89,7 @@ impl<'a> Claims<'a> {
storage: &mut dyn Storage,
addr: Addr,
amount: Uint128,
vesting_amount: Uint128,
release_at: Expiration,
creation_height: u64,
) -> StdResult<()> {
Expand All @@ -92,11 +102,14 @@ impl<'a> Claims<'a> {
match claim {
Some(mut claim) => {
claim.amount += amount;
claim.vesting_amount =
Some(claim.vesting_amount.unwrap_or_default() + vesting_amount);
Ok(claim)
}
None => Ok(Claim {
addr: addr.clone(),
amount,
vesting_amount: Some(vesting_amount),
release_at,
creation_height,
}),
Expand All @@ -115,7 +128,7 @@ impl<'a> Claims<'a> {
addr: &Addr,
block: &BlockInfo,
limit: impl Into<Option<u64>>,
) -> StdResult<Uint128> {
) -> StdResult<(Uint128, Uint128)> {
let claims = self
.claims
.prefix(addr)
Expand All @@ -129,10 +142,14 @@ impl<'a> Claims<'a> {

let claims = self.collect_claims(claims, limit.into())?;
let amount = claims.iter().map(|claim| claim.amount).sum();
let vesting_amount = claims
.iter()
.map(|claim| claim.vesting_amount.unwrap_or_default())
.sum();

self.release_claims(storage, claims)?;

Ok(amount)
Ok((amount, vesting_amount))
}

/// This iterates over all mature claims of any addresses, and removes them. Up to `limit`
Expand Down Expand Up @@ -211,7 +228,7 @@ impl<'a> Claims<'a> {
storage: &mut dyn Storage,
address: Addr,
portion: Decimal,
) -> StdResult<Uint128> {
) -> StdResult<(Uint128, Uint128)> {
let claims: StdResult<Vec<_>> = self
.claims
.prefix(&address)
Expand All @@ -220,21 +237,26 @@ impl<'a> Claims<'a> {
let claims = claims?;

let mut total_slashed = Uint128::zero();
let mut total_vesting_slashed = Uint128::zero();

for (release_at, claim) in claims {
let key = (&address, release_at);

let slashed = claim.amount * portion;
let vesting_slashed = claim.vesting_amount.unwrap_or_default() * portion;
let mut new_claim = claim.clone();
new_claim.amount -= slashed;
new_claim.vesting_amount =
Some(claim.vesting_amount.unwrap_or_default() - vesting_slashed);

self.claims
.replace(storage, key, Some(&new_claim), Some(&claim))?;

total_slashed += slashed;
total_vesting_slashed += vesting_slashed;
}

Ok(total_slashed)
Ok((total_slashed, total_vesting_slashed))
}

pub fn query_claims<Q: CustomQuery>(
Expand Down
Loading

0 comments on commit d796143

Please sign in to comment.