Skip to content

Commit

Permalink
feat(em. controller): shift epochs start by 1 week (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
epanchee authored Oct 16, 2024
1 parent d4483ef commit c4a954d
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 83 deletions.
12 changes: 6 additions & 6 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 contracts/emissions_controller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astroport-emissions-controller"
version = "1.1.0"
version = "1.1.1"
authors = ["Astroport"]
edition = "2021"
description = "Astroport vxASTRO Emissions Voting Contract"
Expand Down
8 changes: 4 additions & 4 deletions contracts/emissions_controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If the pool is located on the Hub contract also checks, this LP token correspond
Users are required to have vxASTRO to cast their votes.
They can vote for whitelisted pools at once every epoch.
Vote changes are not allowed after votes are cast.
After voting, they can't change their votes until the cooldown period ends.
After voting, they can't change their votes until the next epoch.
Executable message accepts an array of tuples with LP token and vote weight.
Vote weight is a number between 0 and 1. Total vote weight can't exceed 1.
If user doesn't vote during the next epochs, their contribution stays intact.
Expand Down Expand Up @@ -67,7 +67,7 @@ contract instantiation.
We call the process of ASTRO emission distribution `tuning`.
Tuning endpoint is permissionless and has 2-week cooldown.
During tuning contract queries snapshotted votes per pool at the exact start of the epoch
(Monday 00:00 UTC starting from Mon May 20 00:00:00 UTC 2024).
(Monday 00:00 UTC starting from Mon May 27 00:00:00 UTC 2024).
Then it filters out pools which are not part of any outpost, sorts pools by votes and
takes top X pools, where X - 'config.pools_per_outpost' * number of outposts.
At the time when this endpoint is executed, new dynamic ASTRO emissions are calculated.
Expand Down Expand Up @@ -99,8 +99,8 @@ Note that if those outposts haven't been retried during the epoch, their state w

## Maintaining Whitelist Presence

Due to security reasons we introduced special parameter `config.whitelist_threshold` which is expected to be 0.01 (1% of
all votes).
Due to security reasons we introduced special parameter `config.whitelist_threshold` which is expected to be 0.001 (0.1%
of all votes).
Every epoch during tuning the contract removes all pools that have less than `config.whitelist_threshold` of total
votes.
Those pools will need to be whitelisted again, and their voting process starts from scratch.
Expand Down
2 changes: 1 addition & 1 deletion contracts/emissions_controller/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ mod unit_tests {
let ack_err: IbcAckResult = from_json(resp.acknowledgement).unwrap();
assert_eq!(
ack_err,
IbcAckResult::Error("Next time you can change your vote is at 1725840000".to_string())
IbcAckResult::Error("Next time you can change your vote is at 1725235200".to_string())
);

// Voting from random channel is not possible
Expand Down
64 changes: 3 additions & 61 deletions contracts/emissions_controller/src/migration.rs
Original file line number Diff line number Diff line change
@@ -1,76 +1,18 @@
#![cfg(not(tarpaulin_include))]

use astroport_governance::emissions_controller::hub::{
AstroPoolConfig, OutpostInfo, OutpostParams,
};
use astroport_governance::utils::determine_ics20_escrow_address;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{entry_point, DepsMut, Empty, Env, Order, Response, StdResult};
use cosmwasm_std::{DepsMut, Empty, Env, Response};
use cw2::{get_contract_version, set_contract_version};
use cw_storage_plus::Map;

use crate::error::ContractError;
use crate::instantiate::{CONTRACT_NAME, CONTRACT_VERSION};
use crate::state::OUTPOSTS;

#[cw_serde]
struct OldOutpostParams {
pub emissions_controller: String,
pub voting_channel: String,
pub ics20_channel: String,
}

#[cw_serde]
struct OldOutpostInfo {
pub params: Option<OldOutpostParams>,
pub astro_denom: String,
pub astro_pool_config: Option<AstroPoolConfig>,
}

const OLD_OUTPOSTS: Map<&str, OldOutpostInfo> = Map::new("outposts");

#[cfg_attr(not(feature = "library"), entry_point)]
#[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
let contract_version = get_contract_version(deps.storage)?;

match contract_version.contract.as_ref() {
CONTRACT_NAME => match contract_version.version.as_ref() {
"1.0.0" | "1.0.1" => {
let old_outposts = OLD_OUTPOSTS
.range(deps.storage, None, None, Order::Ascending)
.collect::<StdResult<Vec<_>>>()?;

for (prefix, old_outpost) in old_outposts {
let params = old_outpost
.params
.map(|params| -> StdResult<_> {
Ok(OutpostParams {
emissions_controller: params.emissions_controller,
voting_channel: params.voting_channel,
escrow_address: determine_ics20_escrow_address(
deps.api,
"transfer",
&params.ics20_channel,
)?,
ics20_channel: params.ics20_channel,
})
})
.transpose()?;

OUTPOSTS.save(
deps.storage,
&prefix,
&OutpostInfo {
params,
astro_denom: old_outpost.astro_denom,
astro_pool_config: old_outpost.astro_pool_config,
jailed: false,
},
)?;
}

Ok(())
}
"1.1.0" => Ok(()),
_ => Err(ContractError::MigrationError {}),
},
_ => Err(ContractError::MigrationError {}),
Expand Down
28 changes: 22 additions & 6 deletions contracts/emissions_controller/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,31 @@ mod unit_tests {

#[test]
fn test_epoch_start() {
assert_eq!(get_epoch_start(1716163200), 1716163200);
assert_eq!(get_epoch_start(1716163200 + 1), 1716163200);
assert_eq!(get_epoch_start(1716768000), 1716768000);
assert_eq!(get_epoch_start(1716768000 + 1), 1716768000);
assert_eq!(
get_epoch_start(1716163200 + EPOCH_LENGTH),
1716163200 + EPOCH_LENGTH
get_epoch_start(1716768000 + EPOCH_LENGTH),
1716768000 + EPOCH_LENGTH
);
assert_eq!(
get_epoch_start(1716163200 + EPOCH_LENGTH + 1),
1716163200 + EPOCH_LENGTH
get_epoch_start(1716768000 + EPOCH_LENGTH + 1),
1716768000 + EPOCH_LENGTH
);

// Assert that epoch start date matches the official launch date (28 October 2024)
let official_launch_date = 1730073600;
assert_eq!(get_epoch_start(official_launch_date), official_launch_date);
assert_eq!(
get_epoch_start(official_launch_date + 1),
official_launch_date
);
assert_eq!(
get_epoch_start(official_launch_date + EPOCH_LENGTH),
official_launch_date + EPOCH_LENGTH
);
assert_eq!(
get_epoch_start(official_launch_date + EPOCH_LENGTH + 1),
official_launch_date + EPOCH_LENGTH
);
}
}
2 changes: 1 addition & 1 deletion packages/astroport-governance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astroport-governance"
version = "4.2.0"
version = "4.2.1"
authors = ["Astroport"]
edition = "2021"
description = "Astroport Governance common types, queriers and other utils"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::ops::RangeInclusive;

use cosmwasm_std::IbcOrder;

/// vxASTRO voting epoch starts on Mon May 20 00:00:00 UTC 2024
pub const EPOCHS_START: u64 = 1716163200;
/// vxASTRO voting epoch starts on Mon May 27 00:00:00 UTC 2024
pub const EPOCHS_START: u64 = 1716768000;
pub const DAY: u64 = 86400;
/// vxASTRO voting epoch lasts 14 days
pub const EPOCH_LENGTH: u64 = DAY * 14;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "astroport-emissions-controller",
"contract_version": "1.1.0",
"contract_version": "1.1.1",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down

0 comments on commit c4a954d

Please sign in to comment.