CamelCase for timelocks

This commit is contained in:
Greg Hysen
2019-08-20 16:45:18 -07:00
parent c939fe2287
commit d106051ee3
23 changed files with 220 additions and 220 deletions

View File

@@ -86,15 +86,15 @@ export class DelegatorActor extends StakerActor {
expectedDelegatorBalances.stakeDelegatedToPool[0] = initDelegatorBalances.stakeDelegatedToPool[0].plus(amount);
await this.assertBalancesAsync(expectedDelegatorBalances, [poolId]);
}
public async deactivateAndTimelockDelegatedStakeAsync(
public async deactivateAndTimeLockDelegatedStakeAsync(
poolId: string,
amount: BigNumber,
revertReason?: RevertReason,
): Promise<void> {
// query init balances
const initDelegatorBalances = await this.getBalancesAsync([poolId]);
// deactivate and timelock
const txReceiptPromise = this._stakingWrapper.deactivateAndTimelockDelegatedStakeAsync(
// deactivate and timeLock
const txReceiptPromise = this._stakingWrapper.deactivateAndTimeLockDelegatedStakeAsync(
this._owner,
poolId,
amount,
@@ -108,7 +108,7 @@ export class DelegatorActor extends StakerActor {
// check balances
const expectedDelegatorBalances = initDelegatorBalances;
expectedDelegatorBalances.activatedStakeBalance = initDelegatorBalances.activatedStakeBalance.minus(amount);
expectedDelegatorBalances.timelockedStakeBalance = expectedDelegatorBalances.timelockedStakeBalance.plus(
expectedDelegatorBalances.timeLockedStakeBalance = expectedDelegatorBalances.timeLockedStakeBalance.plus(
amount,
);
expectedDelegatorBalances.deactivatedStakeBalance = expectedDelegatorBalances.deactivatedStakeBalance.plus(

View File

@@ -61,11 +61,11 @@ export class StakerActor extends BaseActor {
expectedStakerBalances.deactivatedStakeBalance = initStakerBalances.deactivatedStakeBalance.minus(amount);
await this.assertBalancesAsync(expectedStakerBalances);
}
public async deactivateAndTimelockStakeAsync(amount: BigNumber, revertReason?: RevertReason): Promise<void> {
public async deactivateAndTimeLockStakeAsync(amount: BigNumber, revertReason?: RevertReason): Promise<void> {
// query init balances
const initStakerBalances = await this.getBalancesAsync();
// deactivate and timelock stake
const txReceiptPromise = this._stakingWrapper.deactivateAndTimelockStakeAsync(this._owner, amount);
// deactivate and timeLock stake
const txReceiptPromise = this._stakingWrapper.deactivateAndTimeLockStakeAsync(this._owner, amount);
if (revertReason !== undefined) {
await expectTransactionFailedAsync(txReceiptPromise, revertReason);
return;
@@ -75,7 +75,7 @@ export class StakerActor extends BaseActor {
// check balances
const expectedStakerBalances = initStakerBalances;
expectedStakerBalances.activatedStakeBalance = initStakerBalances.activatedStakeBalance.minus(amount);
expectedStakerBalances.timelockedStakeBalance = initStakerBalances.timelockedStakeBalance.plus(amount);
expectedStakerBalances.timeLockedStakeBalance = initStakerBalances.timeLockedStakeBalance.plus(amount);
expectedStakerBalances.deactivatedStakeBalance = initStakerBalances.deactivatedStakeBalance.plus(amount);
await this.assertBalancesAsync(expectedStakerBalances);
}
@@ -115,7 +115,7 @@ export class StakerActor extends BaseActor {
withdrawableStakeBalance: await this._stakingWrapper.getWithdrawableStakeAsync(this._owner),
activatableStakeBalance: await this._stakingWrapper.getActivatableStakeAsync(this._owner),
activatedStakeBalance: await this._stakingWrapper.getActivatedStakeAsync(this._owner),
timelockedStakeBalance: await this._stakingWrapper.getTimelockedStakeAsync(this._owner),
timeLockedStakeBalance: await this._stakingWrapper.getTimeLockedStakeAsync(this._owner),
deactivatedStakeBalance: await this._stakingWrapper.getDeactivatedStakeAsync(this._owner),
};
return stakerBalances;
@@ -136,33 +136,33 @@ export class StakerActor extends BaseActor {
expect(balances.activatedStakeBalance, 'activated stake balance').to.be.bignumber.equal(
expectedBalances.activatedStakeBalance,
);
expect(balances.timelockedStakeBalance, 'timelocked stake balance').to.be.bignumber.equal(
expectedBalances.timelockedStakeBalance,
expect(balances.timeLockedStakeBalance, 'timeLocked stake balance').to.be.bignumber.equal(
expectedBalances.timeLockedStakeBalance,
);
expect(balances.deactivatedStakeBalance, 'deactivated stake balance').to.be.bignumber.equal(
expectedBalances.deactivatedStakeBalance,
);
}
public async forceTimelockSyncAsync(): Promise<void> {
public async forceTimeLockSyncAsync(): Promise<void> {
const initBalances = await this.getBalancesAsync();
await this._stakingWrapper.forceTimelockSyncAsync(this._owner);
await this._stakingWrapper.forceTimeLockSyncAsync(this._owner);
await this.assertBalancesAsync(initBalances);
}
public async skipToNextTimelockPeriodAsync(): Promise<void> {
public async skipToNextTimeLockPeriodAsync(): Promise<void> {
// query some initial values
const initBalances = await this.getBalancesAsync();
const timelockStart = await this._stakingWrapper.getTimelockStartAsync(this._owner);
const timeLockStart = await this._stakingWrapper.getTimeLockStartAsync(this._owner);
// skip to next period
await this._stakingWrapper.skipToNextTimelockPeriodAsync();
await this._stakingWrapper.skipToNextTimeLockPeriodAsync();
// validate new balances
const expectedBalances = initBalances;
const currentTimelockPeriod = await this._stakingWrapper.getCurrentTimelockPeriodAsync();
if (currentTimelockPeriod.minus(timelockStart).isGreaterThan(1)) {
const currentTimeLockPeriod = await this._stakingWrapper.getCurrentTimeLockPeriodAsync();
if (currentTimeLockPeriod.minus(timeLockStart).isGreaterThan(1)) {
expectedBalances.activatableStakeBalance = initBalances.activatableStakeBalance.plus(
initBalances.timelockedStakeBalance,
initBalances.timeLockedStakeBalance,
);
expectedBalances.withdrawableStakeBalance = expectedBalances.activatableStakeBalance;
expectedBalances.timelockedStakeBalance = new BigNumber(0);
expectedBalances.timeLockedStakeBalance = new BigNumber(0);
}
await this.assertBalancesAsync(expectedBalances);
}

View File

@@ -51,41 +51,41 @@ describe('Epochs', () => {
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('Epochs & Timelocks', () => {
it('basic epochs & timelock periods', async () => {
describe('Epochs & TimeLocks', () => {
it('basic epochs & timeLock periods', async () => {
///// 0/3 Validate Assumptions /////
expect(await stakingWrapper.getEpochDurationInSecondsAsync()).to.be.bignumber.equal(
stakingConstants.EPOCH_DURATION_IN_SECONDS,
);
expect(await stakingWrapper.getTimelockDurationInEpochsAsync()).to.be.bignumber.equal(
expect(await stakingWrapper.getTimeLockDurationInEpochsAsync()).to.be.bignumber.equal(
stakingConstants.TIMELOCK_DURATION_IN_EPOCHS,
);
///// 1/3 Validate Initial Epoch & Timelock Period /////
///// 1/3 Validate Initial Epoch & TimeLock Period /////
{
// epoch
const currentEpoch = await stakingWrapper.getCurrentEpochAsync();
expect(currentEpoch).to.be.bignumber.equal(stakingConstants.INITIAL_EPOCH);
// timelock period
const currentTimelockPeriod = await stakingWrapper.getCurrentTimelockPeriodAsync();
expect(currentTimelockPeriod).to.be.bignumber.equal(stakingConstants.INITIAL_TIMELOCK_PERIOD);
// timeLock period
const currentTimeLockPeriod = await stakingWrapper.getCurrentTimeLockPeriodAsync();
expect(currentTimeLockPeriod).to.be.bignumber.equal(stakingConstants.INITIAL_TIMELOCK_PERIOD);
}
///// 2/3 Increment Epoch (Timelock Should Not Increment) /////
///// 2/3 Increment Epoch (TimeLock Should Not Increment) /////
await stakingWrapper.skipToNextEpochAsync();
{
// epoch
const currentEpoch = await stakingWrapper.getCurrentEpochAsync();
expect(currentEpoch).to.be.bignumber.equal(stakingConstants.INITIAL_EPOCH.plus(1));
// timelock period
const currentTimelockPeriod = await stakingWrapper.getCurrentTimelockPeriodAsync();
expect(currentTimelockPeriod).to.be.bignumber.equal(stakingConstants.INITIAL_TIMELOCK_PERIOD);
// timeLock period
const currentTimeLockPeriod = await stakingWrapper.getCurrentTimeLockPeriodAsync();
expect(currentTimeLockPeriod).to.be.bignumber.equal(stakingConstants.INITIAL_TIMELOCK_PERIOD);
}
///// 3/3 Increment Epoch (Timelock Should Increment) /////
await stakingWrapper.skipToNextTimelockPeriodAsync();
///// 3/3 Increment Epoch (TimeLock Should Increment) /////
await stakingWrapper.skipToNextTimeLockPeriodAsync();
{
// timelock period
const currentTimelockPeriod = await stakingWrapper.getCurrentTimelockPeriodAsync();
expect(currentTimelockPeriod).to.be.bignumber.equal(stakingConstants.INITIAL_TIMELOCK_PERIOD.plus(1));
// timeLock period
const currentTimeLockPeriod = await stakingWrapper.getCurrentTimeLockPeriodAsync();
expect(currentTimeLockPeriod).to.be.bignumber.equal(stakingConstants.INITIAL_TIMELOCK_PERIOD.plus(1));
}
});
});

View File

@@ -63,16 +63,16 @@ describe('Staking & Delegating', () => {
// run test - this actor will validate its own state
const staker = new StakerActor(stakers[0], stakingWrapper);
await staker.depositZrxAndMintActivatedStakeAsync(amountToStake);
await staker.deactivateAndTimelockStakeAsync(amountToDeactivate);
// note - we cannot re-activate this timelocked stake until at least one full timelock period has passed.
await staker.deactivateAndTimeLockStakeAsync(amountToDeactivate);
// note - we cannot re-activate this timeLocked stake until at least one full timeLock period has passed.
// attempting to do so should revert.
await staker.activateStakeAsync(amountToReactivate, RevertReason.InsufficientBalance);
await staker.skipToNextTimelockPeriodAsync();
await staker.skipToNextTimeLockPeriodAsync();
await staker.activateStakeAsync(amountToReactivate, RevertReason.InsufficientBalance);
await staker.skipToNextTimelockPeriodAsync();
await staker.skipToNextTimeLockPeriodAsync();
// this forces the internal state to update; it is not necessary to activate stake, but
// allows us to check that state is updated correctly after a timelock period rolls over.
await staker.forceTimelockSyncAsync();
// allows us to check that state is updated correctly after a timeLock period rolls over.
await staker.forceTimeLockSyncAsync();
// now we can activate stake
await staker.activateStakeAsync(amountToReactivate);
await staker.burnDeactivatedStakeAndWithdrawZrxAsync(amountToWithdraw);
@@ -92,16 +92,16 @@ describe('Staking & Delegating', () => {
// run test
const delegator = new DelegatorActor(stakers[0], stakingWrapper);
await delegator.depositZrxAndDelegateToStakingPoolAsync(poolId, amountToDelegate);
await delegator.deactivateAndTimelockDelegatedStakeAsync(poolId, amountToDeactivate);
// note - we cannot re-activate this timelocked stake until at least one full timelock period has passed.
await delegator.deactivateAndTimeLockDelegatedStakeAsync(poolId, amountToDeactivate);
// note - we cannot re-activate this timeLocked stake until at least one full timeLock period has passed.
// attempting to do so should revert.
await delegator.activateStakeAsync(amountToReactivate, RevertReason.InsufficientBalance);
await delegator.skipToNextTimelockPeriodAsync();
await delegator.skipToNextTimeLockPeriodAsync();
await delegator.activateStakeAsync(amountToReactivate, RevertReason.InsufficientBalance);
await delegator.skipToNextTimelockPeriodAsync();
await delegator.skipToNextTimeLockPeriodAsync();
// this forces the internal state to update; it is not necessary to activate stake, but
// allows us to check that state is updated correctly after a timelock period rolls over.
await delegator.forceTimelockSyncAsync();
// allows us to check that state is updated correctly after a timeLock period rolls over.
await delegator.forceTimeLockSyncAsync();
// now we can activate stake
await delegator.activateAndDelegateStakeAsync(poolId, amountToReactivate);
await delegator.burnDeactivatedStakeAndWithdrawZrxAsync(amountToWithdraw);

View File

@@ -72,7 +72,7 @@ export class Simulation {
const delegatorAddress = delegator.getOwner();
const amountOfStakeDelegated = p.stakeByDelegator[delegatorIdx];
const initEthBalance = await this._stakingWrapper.getEthBalanceAsync(delegatorAddress);
await delegator.deactivateAndTimelockDelegatedStakeAsync(poolId, amountOfStakeDelegated);
await delegator.deactivateAndTimeLockDelegatedStakeAsync(poolId, amountOfStakeDelegated);
const finalEthBalance = await this._stakingWrapper.getEthBalanceAsync(delegatorAddress);
const reward = finalEthBalance.minus(initEthBalance);
const rewardTrimmed = StakingWrapper.trimFloat(StakingWrapper.toFloatingPoint(reward, 18), 5);

View File

@@ -228,20 +228,20 @@ export class StakingWrapper {
const txReceipt = await this._executeTransactionAsync(calldata, owner);
return txReceipt;
}
public async deactivateAndTimelockStakeAsync(
public async deactivateAndTimeLockStakeAsync(
owner: string,
amount: BigNumber,
): Promise<TransactionReceiptWithDecodedLogs> {
const calldata = this.getStakingContract().deactivateAndTimelockStake.getABIEncodedTransactionData(amount);
const calldata = this.getStakingContract().deactivateAndTimeLockStake.getABIEncodedTransactionData(amount);
const txReceipt = await this._executeTransactionAsync(calldata, owner);
return txReceipt;
}
public async deactivateAndTimelockDelegatedStakeAsync(
public async deactivateAndTimeLockDelegatedStakeAsync(
owner: string,
poolId: string,
amount: BigNumber,
): Promise<TransactionReceiptWithDecodedLogs> {
const calldata = this.getStakingContract().deactivateAndTimelockDelegatedStake.getABIEncodedTransactionData(
const calldata = this.getStakingContract().deactivateAndTimeLockDelegatedStake.getABIEncodedTransactionData(
poolId,
amount,
);
@@ -258,8 +258,8 @@ export class StakingWrapper {
const txReceipt = await this._executeTransactionAsync(calldata, owner);
return txReceipt;
}
public async forceTimelockSyncAsync(owner: string): Promise<TransactionReceiptWithDecodedLogs> {
const calldata = this.getStakingContract().forceTimelockSync.getABIEncodedTransactionData(owner);
public async forceTimeLockSyncAsync(owner: string): Promise<TransactionReceiptWithDecodedLogs> {
const calldata = this.getStakingContract().forceTimeLockSync.getABIEncodedTransactionData(owner);
const txReceipt = await this._executeTransactionAsync(calldata, this._ownerAddress);
return txReceipt;
}
@@ -294,16 +294,16 @@ export class StakingWrapper {
const value = this.getStakingContract().getWithdrawableStake.getABIDecodedReturnData(returnData);
return value;
}
public async getTimelockedStakeAsync(owner: string): Promise<BigNumber> {
const calldata = this.getStakingContract().getTimelockedStake.getABIEncodedTransactionData(owner);
public async getTimeLockedStakeAsync(owner: string): Promise<BigNumber> {
const calldata = this.getStakingContract().getTimeLockedStake.getABIEncodedTransactionData(owner);
const returnData = await this._callAsync(calldata);
const value = this.getStakingContract().getTimelockedStake.getABIDecodedReturnData(returnData);
const value = this.getStakingContract().getTimeLockedStake.getABIDecodedReturnData(returnData);
return value;
}
public async getTimelockStartAsync(owner: string): Promise<BigNumber> {
const calldata = this.getStakingContract().getTimelockStart.getABIEncodedTransactionData(owner);
public async getTimeLockStartAsync(owner: string): Promise<BigNumber> {
const calldata = this.getStakingContract().getTimeLockStart.getABIEncodedTransactionData(owner);
const returnData = await this._callAsync(calldata);
const value = this.getStakingContract().getTimelockStart.getABIDecodedReturnData(returnData);
const value = this.getStakingContract().getTimeLockStart.getABIDecodedReturnData(returnData);
return value;
}
public async getStakeDelegatedByOwnerAsync(owner: string): Promise<BigNumber> {
@@ -440,10 +440,10 @@ export class StakingWrapper {
await this._web3Wrapper.mineBlockAsync();
return txReceipt;
}
public async skipToNextTimelockPeriodAsync(): Promise<void> {
const timelockEndEpoch = await this.getCurrentTimelockPeriodEndEpochAsync();
public async skipToNextTimeLockPeriodAsync(): Promise<void> {
const timeLockEndEpoch = await this.getCurrentTimeLockPeriodEndEpochAsync();
const currentEpoch = await this.getCurrentEpochAsync();
const nEpochsToJump = timelockEndEpoch.minus(currentEpoch);
const nEpochsToJump = timeLockEndEpoch.minus(currentEpoch);
const nEpochsToJumpAsNumber = nEpochsToJump.toNumber();
for (let i = 0; i < nEpochsToJumpAsNumber; ++i) {
await this.skipToNextEpochAsync();
@@ -455,10 +455,10 @@ export class StakingWrapper {
const value = this.getStakingContract().getEpochDurationInSeconds.getABIDecodedReturnData(returnData);
return value;
}
public async getTimelockDurationInEpochsAsync(): Promise<BigNumber> {
const calldata = this.getStakingContract().getTimelockDurationInEpochs.getABIEncodedTransactionData();
public async getTimeLockDurationInEpochsAsync(): Promise<BigNumber> {
const calldata = this.getStakingContract().getTimeLockDurationInEpochs.getABIEncodedTransactionData();
const returnData = await this._callAsync(calldata);
const value = this.getStakingContract().getTimelockDurationInEpochs.getABIDecodedReturnData(returnData);
const value = this.getStakingContract().getTimeLockDurationInEpochs.getABIDecodedReturnData(returnData);
return value;
}
public async getCurrentEpochStartTimeInSecondsAsync(): Promise<BigNumber> {
@@ -467,10 +467,10 @@ export class StakingWrapper {
const value = this.getStakingContract().getCurrentEpochStartTimeInSeconds.getABIDecodedReturnData(returnData);
return value;
}
public async getCurrentTimelockPeriodStartEpochAsync(): Promise<BigNumber> {
const calldata = this.getStakingContract().getCurrentTimelockPeriodStartEpoch.getABIEncodedTransactionData();
public async getCurrentTimeLockPeriodStartEpochAsync(): Promise<BigNumber> {
const calldata = this.getStakingContract().getCurrentTimeLockPeriodStartEpoch.getABIEncodedTransactionData();
const returnData = await this._callAsync(calldata);
const value = this.getStakingContract().getCurrentTimelockPeriodStartEpoch.getABIDecodedReturnData(returnData);
const value = this.getStakingContract().getCurrentTimeLockPeriodStartEpoch.getABIDecodedReturnData(returnData);
return value;
}
public async getCurrentEpochEarliestEndTimeInSecondsAsync(): Promise<BigNumber> {
@@ -481,10 +481,10 @@ export class StakingWrapper {
);
return value;
}
public async getCurrentTimelockPeriodEndEpochAsync(): Promise<BigNumber> {
const calldata = this.getStakingContract().getCurrentTimelockPeriodEndEpoch.getABIEncodedTransactionData();
public async getCurrentTimeLockPeriodEndEpochAsync(): Promise<BigNumber> {
const calldata = this.getStakingContract().getCurrentTimeLockPeriodEndEpoch.getABIEncodedTransactionData();
const returnData = await this._callAsync(calldata);
const value = this.getStakingContract().getCurrentTimelockPeriodEndEpoch.getABIDecodedReturnData(returnData);
const value = this.getStakingContract().getCurrentTimeLockPeriodEndEpoch.getABIDecodedReturnData(returnData);
return value;
}
public async getCurrentEpochAsync(): Promise<BigNumber> {
@@ -493,10 +493,10 @@ export class StakingWrapper {
const value = this.getStakingContract().getCurrentEpoch.getABIDecodedReturnData(returnData);
return value;
}
public async getCurrentTimelockPeriodAsync(): Promise<BigNumber> {
const calldata = this.getStakingContract().getCurrentTimelockPeriod.getABIEncodedTransactionData();
public async getCurrentTimeLockPeriodAsync(): Promise<BigNumber> {
const calldata = this.getStakingContract().getCurrentTimeLockPeriod.getABIEncodedTransactionData();
const returnData = await this._callAsync(calldata);
const value = this.getStakingContract().getCurrentTimelockPeriod.getABIDecodedReturnData(returnData);
const value = this.getStakingContract().getCurrentTimeLockPeriod.getABIDecodedReturnData(returnData);
return value;
}
///// PROTOCOL FEES /////

View File

@@ -19,7 +19,7 @@ export interface StakerBalances {
activatableStakeBalance: BigNumber;
activatedStakeBalance: BigNumber;
deactivatedStakeBalance: BigNumber;
timelockedStakeBalance: BigNumber;
timeLockedStakeBalance: BigNumber;
}
export interface DelegatorBalances extends StakerBalances {