-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce compounder cap #220
Open
dusan-maksimovic
wants to merge
9
commits into
main
Choose a base branch
from
dusan/introduce-participant-cap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,876
−165
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f35a2f6
introduce participant's cap
dusan-maksimovic 9c5361c
Introduce snapshot map for total voting power tracking and handle its…
dusan-maksimovic 5f2bb8b
Added round<->height tracking and implemented validation for users lo…
dusan-maksimovic 9c64c29
Introduced USER_LOCKS to be able to calculate users voting power at a…
dusan-maksimovic 5531e4a
- Added test for compunders cap and fixed couple of minor bugs within…
dusan-maksimovic 4213cd4
Merge branch 'main' into dusan/introduce-participant-cap
dusan-maksimovic 34e1bca
fixing errors after merge from main
dusan-maksimovic 0550f4f
added tests for user lock snapshoting and heght<->round tracking
dusan-maksimovic 41dc0f1
added transaction to remove the constants at a specified timestamps
dusan-maksimovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod migrate; | ||
pub mod unreleased; | ||
pub mod v3_0_0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use cosmwasm_std::{DepsMut, Env}; | ||
use neutron_sdk::bindings::query::NeutronQuery; | ||
|
||
use crate::error::ContractError; | ||
|
||
pub fn migrate_v3_0_0_to_unreleased( | ||
_deps: &mut DepsMut<NeutronQuery>, | ||
_env: Env, | ||
) -> Result<(), ContractError> { | ||
// TODO: | ||
// 1) Migrate Constants from Item to Map; Make sure that the queries for past rounds keep working. | ||
// 2) TOTAL_VOTING_POWER_PER_ROUND needs to be correctly populated regardless of the point in time | ||
// we do the migration. Needs to be populated for future rounds as well. If we populate it for | ||
// the past rounds as well, we can use that in our queries instead of on-the-fly computation | ||
// e.g. query_round_total_power(), query_top_n_proposals(). | ||
// 3) LOCKS_MAP needs to be migrated to SnapshotMap. | ||
// 4) Populate USER_LOCKS for existing lockups. | ||
// 4) Populate ROUND_TO_HEIGHT_RANGE and HEIGHT_TO_ROUND for previous rounds? | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,10 +1,11 @@ | ||||||
use cosmwasm_schema::cw_serde; | ||||||
use cosmwasm_std::{Addr, Coin, Decimal, Timestamp, Uint128}; | ||||||
use cw_storage_plus::{Item, Map}; | ||||||
use cw_storage_plus::{Item, Map, SnapshotMap, Strategy}; | ||||||
|
||||||
use crate::msg::LiquidityDeployment; | ||||||
|
||||||
pub const CONSTANTS: Item<Constants> = Item::new("constants"); | ||||||
// CONSTANTS: key(activation_timestamp) -> Constants | ||||||
pub const CONSTANTS: Map<u64, Constants> = Map::new("constants"); | ||||||
|
||||||
#[cw_serde] | ||||||
pub struct LockPowerEntry { | ||||||
|
@@ -58,7 +59,15 @@ pub struct Constants { | |||||
pub round_length: u64, | ||||||
pub lock_epoch_length: u64, | ||||||
pub first_round_start: Timestamp, | ||||||
// The maximum number of tokens that can be locked by any users (currently known and the future ones) | ||||||
pub max_locked_tokens: u128, | ||||||
// The maximum number of tokens (out of the max_locked_tokens) that is reserved for locking only | ||||||
// for currently known users. This field is intended to be set to some value greater than zero at | ||||||
// the begining of the round, and such Constants would apply only for predefined period of time. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// After this period has expired, a new Constants would be activated that would set this value to | ||||||
// zero, which would allow any user to lock any amount that possibly wasn't filled, but was reserved | ||||||
// for this cap. | ||||||
pub current_users_extra_cap: u128, | ||||||
pub max_validator_shares_participating: u64, | ||||||
pub hub_connection_id: String, | ||||||
pub hub_transfer_channel_id: String, | ||||||
|
@@ -71,14 +80,30 @@ pub struct Constants { | |||||
// the total number of tokens locked in the contract | ||||||
pub const LOCKED_TOKENS: Item<u128> = Item::new("locked_tokens"); | ||||||
|
||||||
// Tracks the total number of tokens locked in extra cap, for the given round | ||||||
// EXTRA_LOCKED_TOKENS_ROUND_TOTAL: key(round_id) -> uint128 | ||||||
pub const EXTRA_LOCKED_TOKENS_ROUND_TOTAL: Map<u64, u128> = | ||||||
Map::new("extra_locked_tokens_round_total"); | ||||||
|
||||||
// Tracks the number of tokens locked in extra cap by specific user, for the given round | ||||||
// EXTRA_LOCKED_TOKENS_CURRENT_USERS: key(round_id, sender_address) -> uint128 | ||||||
pub const EXTRA_LOCKED_TOKENS_CURRENT_USERS: Map<(u64, Addr), u128> = | ||||||
Map::new("extra_locked_tokens_current_users"); | ||||||
|
||||||
pub const LOCK_ID: Item<u64> = Item::new("lock_id"); | ||||||
|
||||||
// stores the current PROP_ID, in order to ensure that each proposal has a unique ID | ||||||
// this is incremented every time a new proposal is created | ||||||
pub const PROP_ID: Item<u64> = Item::new("prop_id"); | ||||||
|
||||||
// LOCKS_MAP: key(sender_address, lock_id) -> LockEntry | ||||||
pub const LOCKS_MAP: Map<(Addr, u64), LockEntry> = Map::new("locks_map"); | ||||||
pub const LOCKS_MAP: SnapshotMap<(Addr, u64), LockEntry> = SnapshotMap::new( | ||||||
"locks_map", | ||||||
"locks_map__checkpoints", | ||||||
"locks_map__changelog", | ||||||
Strategy::EveryBlock, | ||||||
); | ||||||
|
||||||
#[cw_serde] | ||||||
pub struct LockEntry { | ||||||
pub lock_id: u64, | ||||||
|
@@ -87,6 +112,25 @@ pub struct LockEntry { | |||||
pub lock_end: Timestamp, | ||||||
} | ||||||
|
||||||
// Stores the lockup IDs that belong to a user. Snapshoted so that we can determine which lockups | ||||||
// user had at a given height and use this info to compute users voting power at that height. | ||||||
// USER_LOCKS: key(user_address) -> Vec<lock_ids> | ||||||
pub const USER_LOCKS: SnapshotMap<Addr, Vec<u64>> = SnapshotMap::new( | ||||||
"user_locks", | ||||||
"user_locks__checkpoints", | ||||||
"user_locks__changelog", | ||||||
Strategy::EveryBlock, | ||||||
); | ||||||
|
||||||
// This is the total voting power of all users combined. | ||||||
// TOTAL_VOTING_POWER_PER_ROUND: key(round_id) -> total_voting_power | ||||||
pub const TOTAL_VOTING_POWER_PER_ROUND: SnapshotMap<u64, Uint128> = SnapshotMap::new( | ||||||
"total_voting_power_per_round", | ||||||
"total_voting_power_per_round__checkpoints", | ||||||
"total_voting_power_per_round__changelog", | ||||||
Strategy::EveryBlock, | ||||||
); | ||||||
|
||||||
// PROPOSAL_MAP: key(round_id, tranche_id, prop_id) -> Proposal | ||||||
pub const PROPOSAL_MAP: Map<(u64, u64, u64), Proposal> = Map::new("prop_map"); | ||||||
#[cw_serde] | ||||||
|
@@ -228,3 +272,23 @@ impl ValidatorInfo { | |||||
// LIQUIDITY_DEPLOYMENTS_MAP: key(round_id, tranche_id, prop_id) -> deployment | ||||||
pub const LIQUIDITY_DEPLOYMENTS_MAP: Map<(u64, u64, u64), LiquidityDeployment> = | ||||||
Map::new("liquidity_deployments_map"); | ||||||
|
||||||
// Stores the mapping between the round_id and the range of known block heights for that round. | ||||||
// The lowest_known_height is the height at which the first transaction was executed, and the | ||||||
// highest_known_height is the height at which the last transaction was executed against the smart | ||||||
// contract in the given round. | ||||||
// Notice that the round could span beyond these boundaries, but we don't have a way to know that. | ||||||
// Besides, the info we store here is sufficient for our needs. | ||||||
// ROUND_TO_HEIGHT_RANGE: key(round_id) -> HeightRange | ||||||
pub const ROUND_TO_HEIGHT_RANGE: Map<u64, HeightRange> = Map::new("round_to_height_range"); | ||||||
|
||||||
// Stores the mapping between the block height and round. It gets populated | ||||||
// each time a transaction is executed against the smart contract. | ||||||
// HEIGHT_TO_ROUND: key(block_height) -> round_id | ||||||
pub const HEIGHT_TO_ROUND: Map<u64, u64> = Map::new("height_to_round"); | ||||||
|
||||||
#[cw_serde] | ||||||
pub struct HeightRange { | ||||||
pub lowest_known_height: u64, | ||||||
pub highest_known_height: u64, | ||||||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to support denom resolution for the past rounds. We need to pass in the round_id because sometimes this function gets executed in current round, but we are interested for past rounds (e.g. for compounder cap to determine users voting power in previous round).