From 8058298735a41b5944d3790975d049779f2e2d5c Mon Sep 17 00:00:00 2001 From: Timofey <5527315+epanchee@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:17:18 +0300 Subject: [PATCH] feat(em. controller): shift epochs start by 1 week --- Cargo.lock | 12 ++-- contracts/emissions_controller/Cargo.toml | 2 +- contracts/emissions_controller/README.md | 8 +-- contracts/emissions_controller/src/ibc.rs | 2 +- .../emissions_controller/src/migration.rs | 64 +------------------ contracts/emissions_controller/src/utils.rs | 28 ++++++-- packages/astroport-governance/Cargo.toml | 2 +- .../src/emissions_controller/consts.rs | 4 +- .../astroport-emissions-controller.json | 2 +- 9 files changed, 41 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a20d89..b17969b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,7 +25,7 @@ version = "3.0.0" dependencies = [ "anyhow", "astroport 4.0.3", - "astroport-governance 4.2.0", + "astroport-governance 4.2.1", "astroport-staking", "astroport-tokenfactory-tracker", "astroport-voting-escrow", @@ -136,13 +136,13 @@ dependencies = [ [[package]] name = "astroport-emissions-controller" -version = "1.1.0" +version = "1.1.1" dependencies = [ "anyhow", "astro-assembly", "astroport 5.3.0 (git+https://github.com/astroport-fi/astroport-core)", "astroport-factory", - "astroport-governance 4.2.0", + "astroport-governance 4.2.1", "astroport-incentives", "astroport-pair", "astroport-staking", @@ -171,7 +171,7 @@ dependencies = [ "anyhow", "astroport 5.3.0 (git+https://github.com/astroport-fi/astroport-core)", "astroport-factory", - "astroport-governance 4.2.0", + "astroport-governance 4.2.1", "astroport-incentives", "astroport-pair", "astroport-voting-escrow", @@ -233,7 +233,7 @@ dependencies = [ [[package]] name = "astroport-governance" -version = "4.2.0" +version = "4.2.1" dependencies = [ "astroport 5.3.0 (git+https://github.com/astroport-fi/astroport-core)", "cosmwasm-schema", @@ -321,7 +321,7 @@ name = "astroport-voting-escrow" version = "1.1.0" dependencies = [ "astroport 5.3.0 (git+https://github.com/astroport-fi/astroport-core)", - "astroport-governance 4.2.0", + "astroport-governance 4.2.1", "cosmwasm-schema", "cosmwasm-std", "cw-multi-test 1.2.0", diff --git a/contracts/emissions_controller/Cargo.toml b/contracts/emissions_controller/Cargo.toml index 61a6fc7..a5a8f72 100644 --- a/contracts/emissions_controller/Cargo.toml +++ b/contracts/emissions_controller/Cargo.toml @@ -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" diff --git a/contracts/emissions_controller/README.md b/contracts/emissions_controller/README.md index b921090..e3fb616 100644 --- a/contracts/emissions_controller/README.md +++ b/contracts/emissions_controller/README.md @@ -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. @@ -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. @@ -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. diff --git a/contracts/emissions_controller/src/ibc.rs b/contracts/emissions_controller/src/ibc.rs index 67a99fd..aba7453 100644 --- a/contracts/emissions_controller/src/ibc.rs +++ b/contracts/emissions_controller/src/ibc.rs @@ -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 diff --git a/contracts/emissions_controller/src/migration.rs b/contracts/emissions_controller/src/migration.rs index 9a79c08..ae61a57 100644 --- a/contracts/emissions_controller/src/migration.rs +++ b/contracts/emissions_controller/src/migration.rs @@ -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, - pub astro_denom: String, - pub astro_pool_config: Option, -} - -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 { 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::>>()?; - - 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", - ¶ms.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 {}), diff --git a/contracts/emissions_controller/src/utils.rs b/contracts/emissions_controller/src/utils.rs index 199b9bc..c165ed5 100644 --- a/contracts/emissions_controller/src/utils.rs +++ b/contracts/emissions_controller/src/utils.rs @@ -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 ); } } diff --git a/packages/astroport-governance/Cargo.toml b/packages/astroport-governance/Cargo.toml index 4fe168b..282a846 100644 --- a/packages/astroport-governance/Cargo.toml +++ b/packages/astroport-governance/Cargo.toml @@ -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" diff --git a/packages/astroport-governance/src/emissions_controller/consts.rs b/packages/astroport-governance/src/emissions_controller/consts.rs index e9448e6..5892a06 100644 --- a/packages/astroport-governance/src/emissions_controller/consts.rs +++ b/packages/astroport-governance/src/emissions_controller/consts.rs @@ -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; diff --git a/schemas/astroport-emissions-controller/astroport-emissions-controller.json b/schemas/astroport-emissions-controller/astroport-emissions-controller.json index 76e65ab..2b6399a 100644 --- a/schemas/astroport-emissions-controller/astroport-emissions-controller.json +++ b/schemas/astroport-emissions-controller/astroport-emissions-controller.json @@ -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#",