Remove warmup

This commit is contained in:
armaniferrante 2021-10-24 18:14:06 -07:00
parent 5badbeb59c
commit 89ef88aef0
No known key found for this signature in database
GPG Key ID: 58BEF301E91F7828
4 changed files with 9 additions and 23 deletions

View File

@ -21,7 +21,6 @@ pub struct Registrar {
pub authority: Pubkey,
pub realm: Pubkey,
pub realm_community_mint: Pubkey,
pub warmup_secs: i64,
pub bump: u8,
// The length should be adjusted for one's use case.
pub rates: [ExchangeRateEntry; 2],
@ -189,14 +188,6 @@ impl DepositEntry {
///
/// To calculate the decay, we can simply re-use the above sum, adjusting
/// `n` for the number of days left in the lockup.
///
/// ## Voting Power Warmup
///
/// To prevent the case where one borrows tokens to suddenly vote on a
/// favorable proposal, one can introduce a "warmup" period, where the
/// lockup calculation doesn't start until a specific date, so that
/// the voting power of all new depositors remains zero for an initial
/// period of time, say, two weeks.
pub fn voting_power(&self, curr_ts: i64) -> Result<u64> {
if curr_ts < self.lockup.start_ts {
return Ok(0);
@ -293,25 +284,23 @@ impl DepositEntry {
#[derive(AnchorSerialize, AnchorDeserialize)]
pub struct Lockup {
pub kind: LockupKind,
// Start of the lockup, shifted by the warmup period.
// Start of the lockup.
pub start_ts: i64,
// End of the lockup, shifted by the warmup period.
// End of the lockup.
pub end_ts: i64,
// Empty bytes for future upgrades.
pub padding: [u8; 16],
}
impl Lockup {
/// Returns the number of days left on the lockup, ignoring the warmup
/// period.
/// Returns the number of days left on the lockup.
pub fn days_left(&self, curr_ts: i64) -> Result<u64> {
Ok(self
.days_total()?
.saturating_sub(self.day_current(curr_ts)?))
}
/// Returns the current day in the vesting schedule. The warmup period is
/// treated as day zero.
/// Returns the current day in the vesting schedule.
pub fn day_current(&self, curr_ts: i64) -> Result<u64> {
let d = u64::try_from({
let secs_elapsed = curr_ts.saturating_sub(self.start_ts);
@ -321,8 +310,7 @@ impl Lockup {
Ok(d)
}
/// Returns the total amount of days in the lockup period, ignoring the
/// warmup period.
/// Returns the total amount of days in the lockup period.
pub fn days_total(&self) -> Result<u64> {
// Number of seconds in the entire lockup.
let lockup_secs = self.end_ts.checked_sub(self.start_ts).unwrap();

View File

@ -7,7 +7,7 @@ use std::mem::size_of;
pub const VOTER_WEIGHT_RECORD: [u8; 19] = *b"voter-weight-record";
#[derive(Accounts)]
#[instruction(warmup_secs: i64, rate_decimals: u8, registrar_bump: u8)]
#[instruction(rate_decimals: u8, registrar_bump: u8)]
pub struct CreateRegistrar<'info> {
#[account(
init,

View File

@ -66,7 +66,6 @@ pub mod governance_registry {
/// per governance realm.
pub fn create_registrar(
ctx: Context<CreateRegistrar>,
warmup_secs: i64,
rate_decimals: u8,
registrar_bump: u8,
) -> Result<()> {
@ -75,7 +74,6 @@ pub mod governance_registry {
registrar.realm = ctx.accounts.realm.key();
registrar.realm_community_mint = ctx.accounts.realm_community_mint.key();
registrar.authority = ctx.accounts.authority.key();
registrar.warmup_secs = warmup_secs;
registrar.rate_decimals = rate_decimals;
Ok(())
@ -139,8 +137,8 @@ pub mod governance_registry {
let registrar = &ctx.accounts.deposit.registrar.load()?;
let voter = &mut ctx.accounts.deposit.voter.load_mut()?;
// Set the lockup start timestamp, delayed by the warmup period.
let start_ts = Clock::get()?.unix_timestamp + registrar.warmup_secs;
// Set the lockup start timestamp.
let start_ts = Clock::get()?.unix_timestamp;
// Get the exchange rate entry associated with this deposit.
let er_idx = registrar

View File

@ -167,7 +167,7 @@ describe("voting-rights", () => {
});
it("Initializes a registrar", async () => {
await program.rpc.createRegistrar(new BN(0), 6, registrarBump, {
await program.rpc.createRegistrar(6, registrarBump, {
accounts: {
registrar,
realm,