From 16d023158833f9088b1865c31bb8a1358d3b5f51 Mon Sep 17 00:00:00 2001 From: keyvan Date: Wed, 28 Aug 2024 14:57:36 -0700 Subject: [PATCH] fix: remove unlocking duration from sdk, tests, and wasm --- staking/app/StakeConnection.ts | 24 +++++------------------- staking/programs/staking/src/wasm.rs | 14 ++++---------- staking/tests/config.ts | 24 ++++++++++++------------ 3 files changed, 21 insertions(+), 41 deletions(-) diff --git a/staking/app/StakeConnection.ts b/staking/app/StakeConnection.ts index 6c0cc8dd3..ec63ed89b 100644 --- a/staking/app/StakeConnection.ts +++ b/staking/app/StakeConnection.ts @@ -418,8 +418,7 @@ export class StakeConnection { [wasm.PositionState.LOCKED, wasm.PositionState.LOCKING].includes( stakeAccount.stakeAccountPositionsWasm.getPositionState( el.index, - BigInt(currentEpoch.toString()), - this.config.unlockingDuration + BigInt(currentEpoch.toString()) ) ) ) @@ -1060,13 +1059,10 @@ export class StakeConnection { const time = new BN(Date.now() / 1000); const currentEpoch = time.div(this.config.epochDuration); - const unlockingDuration = this.config.unlockingDuration; const currentEpochBI = BigInt(currentEpoch.toString()); - const lockedBalanceSummary = positionAccountWasm.getLockedBalanceSummary( - currentEpochBI, - unlockingDuration - ); + const lockedBalanceSummary = + positionAccountWasm.getLockedBalanceSummary(currentEpochBI); const epochOfFirstStake: BN = positionAccountJs.positions.reduce( (prev: BN | undefined, curr) => { @@ -1250,15 +1246,11 @@ export class StakeAccount { ); const currentEpoch = unixTime.div(this.config.epochDuration); - const unlockingDuration = this.config.unlockingDuration; const currentEpochBI = BigInt(currentEpoch.toString()); const unvestedBN = new BN(unvestedBalance.toString()); const lockedSummaryBI = - this.stakeAccountPositionsWasm.getLockedBalanceSummary( - currentEpochBI, - unlockingDuration - ); + this.stakeAccountPositionsWasm.getLockedBalanceSummary(currentEpochBI); let lockingBN = new BN(lockedSummaryBI.locking.toString()); let lockedBN = new BN(lockedSummaryBI.locked.toString()); @@ -1372,11 +1364,9 @@ export class StakeAccount { public getVoterWeight(unixTime: BN): PythBalance { let currentEpoch = unixTime.div(this.config.epochDuration); - let unlockingDuration = this.config.unlockingDuration; const voterWeightBI = this.stakeAccountPositionsWasm.getVoterWeight( BigInt(currentEpoch.toString()), - unlockingDuration, BigInt( this.votingAccountMetadataWasm.getCurrentAmountLocked( BigInt(currentEpoch.toString()) @@ -1430,11 +1420,7 @@ export class StakeAccount { } private addUnlockingPeriod(unixTime: BN) { - return unixTime.add( - this.config.epochDuration.mul( - new BN(this.config.unlockingDuration).add(new BN(1)) - ) - ); + return unixTime.add(this.config.epochDuration.mul(new BN(2))); } public getNetExcessGovernanceAtVesting(unixTime: BN): BN { diff --git a/staking/programs/staking/src/wasm.rs b/staking/programs/staking/src/wasm.rs index 2ae41123f..a0aec7fd6 100644 --- a/staking/programs/staking/src/wasm.rs +++ b/staking/programs/staking/src/wasm.rs @@ -55,22 +55,20 @@ impl WasmPositionData { &self, index: u16, current_epoch: u64, - unlocking_duration: u8, ) -> Result { - convert_error(self.get_position_state_impl(index, current_epoch, unlocking_duration)) + convert_error(self.get_position_state_impl(index, current_epoch)) } fn get_position_state_impl( &self, index: u16, current_epoch: u64, - unlocking_duration: u8, ) -> anchor_lang::Result { let mut account = DynamicPositionArrayAccount::default_with_data(&self.wrapped); account .to_dynamic_position_array() .read_position(index as usize)? .ok_or_else(|| error!(ErrorCode::PositionNotInUse))? - .get_current_position(current_epoch, unlocking_duration) + .get_current_position(current_epoch) } #[wasm_bindgen(js_name=isPositionVoting)] pub fn is_position_voting(&self, index: u16) -> Result { @@ -93,14 +91,12 @@ impl WasmPositionData { pub fn get_locked_balance_summary( &self, current_epoch: u64, - unlocking_duration: u8, ) -> Result { - convert_error(self.get_locked_balance_summary_impl(current_epoch, unlocking_duration)) + convert_error(self.get_locked_balance_summary_impl(current_epoch)) } fn get_locked_balance_summary_impl( &self, current_epoch: u64, - unlocking_duration: u8, ) -> anchor_lang::Result { let mut account = DynamicPositionArrayAccount::default_with_data(&self.wrapped); let positions = account.to_dynamic_position_array(); @@ -112,7 +108,7 @@ impl WasmPositionData { for i in 0..positions.get_position_capacity() { if let Some(position) = positions.read_position(i)? { - match position.get_current_position(current_epoch, unlocking_duration)? { + match position.get_current_position(current_epoch)? { PositionState::LOCKING => { locking = locking .checked_add(position.amount) @@ -149,14 +145,12 @@ impl WasmPositionData { pub fn get_voter_weight( &self, current_epoch: u64, - unlocking_duration: u8, current_locked: u64, ) -> Result { let mut account = DynamicPositionArrayAccount::default_with_data(&self.wrapped); convert_error(crate::utils::voter_weight::compute_voter_weight( &account.to_dynamic_position_array(), current_epoch, - unlocking_duration, current_locked, MAX_VOTER_WEIGHT, )) diff --git a/staking/tests/config.ts b/staking/tests/config.ts index f234b95db..982c9c5b0 100644 --- a/staking/tests/config.ts +++ b/staking/tests/config.ts @@ -66,7 +66,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority: pdaAuthority, @@ -99,7 +99,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority: pdaAuthority, @@ -126,7 +126,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority: pdaAuthority, @@ -149,7 +149,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority: pdaAuthority, @@ -176,7 +176,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority: pdaAuthority, @@ -199,7 +199,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority: pdaAuthority, @@ -224,7 +224,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority: pdaAuthority, @@ -332,7 +332,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority: program.provider.publicKey, @@ -356,7 +356,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority: pdaAuthority, @@ -384,7 +384,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority, @@ -407,7 +407,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority, @@ -438,7 +438,7 @@ describe("config", async () => { governanceAuthority: program.provider.publicKey, pythTokenMint: pythMintAccount.publicKey, pythGovernanceRealm, - unlockingDuration: 2, + unlockingDuration: 0, epochDuration: new BN(3600), freeze: false, pdaAuthority: pdaAuthority,