Cleanup language used in comments and variable names

This commit is contained in:
Amir Bandeali
2019-10-08 11:37:36 +09:00
parent 701b203c58
commit 681e6eab7a
9 changed files with 71 additions and 67 deletions

View File

@@ -24,7 +24,8 @@ import "./IStructs.sol";
interface IStaking {
/// @dev Moves stake between statuses: 'active', 'inactive' or 'delegated'.
/// @dev Moves stake between statuses: 'undelegated' or 'delegated'.
/// Delegated stake can also be moved between pools.
/// This change comes into effect next epoch.
/// @param from status to move stake out of.
/// @param to status to move stake into.

View File

@@ -64,7 +64,7 @@ interface IStructs {
/// @dev Statuses that stake can exist in.
/// Any stake can be (re)delegated effective at the next epoch
/// Inactive stake can be withdrawn if it is available in both the current and next epoch
/// Undelegated stake can be withdrawn if it is available in both the current and next epoch
enum StakeStatus {
UNDELEGATED,
DELEGATED

View File

@@ -54,21 +54,21 @@ contract MixinStake is
}
/// @dev Unstake. Tokens are withdrawn from the ZRX Vault and returned to
/// the staker. Stake must be in the 'inactive' status for at least
/// one full epoch to unstake.
/// the staker. Stake must be in the 'undelegated' status in both the
/// current and next epoch in order to be unstaked.
/// @param amount of ZRX to unstake.
function unstake(uint256 amount)
external
{
address staker = msg.sender;
IStructs.StoredBalance memory inactiveBalance =
IStructs.StoredBalance memory undelegatedBalance =
_loadSyncedBalance(_ownerStakeByStatus[uint8(IStructs.StakeStatus.UNDELEGATED)][staker]);
// stake must be inactive in current and next epoch to be withdrawn
// stake must be undelegated in current and next epoch to be withdrawn
uint256 currentWithdrawableStake = LibSafeMath.min256(
inactiveBalance.currentEpochBalance,
inactiveBalance.nextEpochBalance
undelegatedBalance.currentEpochBalance,
undelegatedBalance.nextEpochBalance
);
if (amount > currentWithdrawableStake) {
@@ -80,7 +80,7 @@ contract MixinStake is
);
}
// burn inactive stake
// burn undelegated stake
_decreaseCurrentAndNextBalance(
_ownerStakeByStatus[uint8(IStructs.StakeStatus.UNDELEGATED)][staker],
amount
@@ -96,7 +96,8 @@ contract MixinStake is
);
}
/// @dev Moves stake between statuses: 'active', 'inactive' or 'delegated'.
/// @dev Moves stake between statuses: 'undelegated' or 'delegated'.
/// Delegated stake can also be moved between pools.
/// This change comes into effect next epoch.
/// @param from status to move stake out of.
/// @param to status to move stake into.

View File

@@ -41,8 +41,8 @@ contract MixinStakeBalances is
_globalStakeByStatus[uint8(IStructs.StakeStatus.DELEGATED)]
);
if (stakeStatus == IStructs.StakeStatus.UNDELEGATED) {
// Inactive stake is the difference between total stake and delegated stake
// Note that any Zrx erroneously sent to the vault will be counted as inactive stake
// Undelegated stake is the difference between total stake and delegated stake
// Note that any ZRX erroneously sent to the vault will be counted as undelegated stake
uint256 totalStake = getZrxVault().balanceOfZrxVault();
balance.currentEpochBalance = totalStake.safeSub(balance.currentEpochBalance).downcastToUint96();
balance.nextEpochBalance = totalStake.safeSub(balance.nextEpochBalance).downcastToUint96();

View File

@@ -31,7 +31,7 @@ contract MixinStakeStorage is
using LibSafeMath for uint256;
using LibSafeDowncast for uint256;
/// @dev Moves stake between states: 'active', 'inactive' or 'delegated'.
/// @dev Moves stake between states: 'undelegated' or 'delegated'.
/// This change comes into effect next epoch.
/// @param fromPtr pointer to storage location of `from` stake.
/// @param toPtr pointer to storage location of `to` stake.

View File

@@ -106,8 +106,8 @@ export class StakerActor extends BaseActor {
const expectedBalances = initBalances;
expectedBalances.zrxBalance = initBalances.zrxBalance.plus(amount);
expectedBalances.stakeBalanceInVault = initBalances.stakeBalanceInVault.minus(amount);
StakerActor._decrementCurrentAndNextBalance(expectedBalances.inactiveStakeBalance, amount);
StakerActor._decrementCurrentAndNextBalance(expectedBalances.globalInactiveStakeBalance, amount);
StakerActor._decrementCurrentAndNextBalance(expectedBalances.undelegatedStakeBalance, amount);
StakerActor._decrementCurrentAndNextBalance(expectedBalances.globalUndelegatedStakeBalance, amount);
await this._assertBalancesAsync(expectedBalances);
// check zrx balance of vault
const finalZrxBalanceOfVault = await this._stakingApiWrapper.utils.getZrxTokenBalanceOfZrxVaultAsync();
@@ -182,9 +182,9 @@ export class StakerActor extends BaseActor {
private _getNextEpochBalances(balances: StakeBalances): StakeBalances {
const nextBalances = _.cloneDeep(balances);
for (const balance of [
nextBalances.inactiveStakeBalance,
nextBalances.undelegatedStakeBalance,
nextBalances.delegatedStakeBalance,
nextBalances.globalInactiveStakeBalance,
nextBalances.globalUndelegatedStakeBalance,
nextBalances.globalDelegatedStakeBalance,
...this._poolIds.map(poolId => nextBalances.delegatedStakeByPool[poolId]),
...this._poolIds.map(poolId => nextBalances.totalDelegatedStakeByPool[poolId]),
@@ -200,7 +200,7 @@ export class StakerActor extends BaseActor {
zrxBalance: await this._stakingApiWrapper.zrxTokenContract.balanceOf.callAsync(this._owner),
stakeBalance: await this._stakingApiWrapper.stakingContract.getTotalStake.callAsync(this._owner),
stakeBalanceInVault: await this._stakingApiWrapper.zrxVaultContract.balanceOf.callAsync(this._owner),
inactiveStakeBalance: await this._stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
undelegatedStakeBalance: await this._stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
this._owner,
StakeStatus.Undelegated,
),
@@ -208,7 +208,7 @@ export class StakerActor extends BaseActor {
this._owner,
StakeStatus.Delegated,
),
globalInactiveStakeBalance: await this._stakingApiWrapper.stakingContract.getGlobalStakeByStatus.callAsync(
globalUndelegatedStakeBalance: await this._stakingApiWrapper.stakingContract.getGlobalStakeByStatus.callAsync(
StakeStatus.Undelegated,
),
globalDelegatedStakeBalance: await this._stakingApiWrapper.stakingContract.getGlobalStakeByStatus.callAsync(
@@ -238,12 +238,13 @@ export class StakerActor extends BaseActor {
expectedBalances.stakeBalanceInVault,
);
expect(
balances.inactiveStakeBalance.currentEpochBalance,
'inactive stake balance (current)',
).to.be.bignumber.equal(expectedBalances.inactiveStakeBalance.currentEpochBalance);
expect(balances.inactiveStakeBalance.nextEpochBalance, 'inactive stake balance (next)').to.be.bignumber.equal(
expectedBalances.inactiveStakeBalance.nextEpochBalance,
);
balances.undelegatedStakeBalance.currentEpochBalance,
'undelegated stake balance (current)',
).to.be.bignumber.equal(expectedBalances.undelegatedStakeBalance.currentEpochBalance);
expect(
balances.undelegatedStakeBalance.nextEpochBalance,
'undelegated stake balance (next)',
).to.be.bignumber.equal(expectedBalances.undelegatedStakeBalance.nextEpochBalance);
expect(
balances.delegatedStakeBalance.currentEpochBalance,
'delegated stake balance (current)',
@@ -252,16 +253,17 @@ export class StakerActor extends BaseActor {
expectedBalances.delegatedStakeBalance.nextEpochBalance,
);
expect(
balances.globalInactiveStakeBalance.currentEpochBalance,
'global inactive stake (current)',
).to.bignumber.equal(expectedBalances.globalInactiveStakeBalance.currentEpochBalance);
balances.globalUndelegatedStakeBalance.currentEpochBalance,
'global undelegated stake (current)',
).to.bignumber.equal(expectedBalances.globalUndelegatedStakeBalance.currentEpochBalance);
expect(
balances.globalDelegatedStakeBalance.currentEpochBalance,
'global delegated stake (current)',
).to.bignumber.equal(expectedBalances.globalDelegatedStakeBalance.currentEpochBalance);
expect(balances.globalInactiveStakeBalance.nextEpochBalance, 'global inactive stake (next)').to.bignumber.equal(
expectedBalances.globalInactiveStakeBalance.nextEpochBalance,
);
expect(
balances.globalUndelegatedStakeBalance.nextEpochBalance,
'global undelegated stake (next)',
).to.bignumber.equal(expectedBalances.globalUndelegatedStakeBalance.nextEpochBalance);
expect(
balances.globalDelegatedStakeBalance.nextEpochBalance,
'global delegated stake (next)',
@@ -290,8 +292,8 @@ export class StakerActor extends BaseActor {
// check balances
// from
if (from.status === StakeStatus.Undelegated) {
StakerActor._decrementNextBalance(expectedBalances.inactiveStakeBalance, amount);
StakerActor._decrementNextBalance(expectedBalances.globalInactiveStakeBalance, amount);
StakerActor._decrementNextBalance(expectedBalances.undelegatedStakeBalance, amount);
StakerActor._decrementNextBalance(expectedBalances.globalUndelegatedStakeBalance, amount);
} else if (from.status === StakeStatus.Delegated && from.poolId !== undefined) {
StakerActor._decrementNextBalance(expectedBalances.delegatedStakeBalance, amount);
StakerActor._decrementNextBalance(expectedBalances.globalDelegatedStakeBalance, amount);
@@ -300,8 +302,8 @@ export class StakerActor extends BaseActor {
}
// to
if (to.status === StakeStatus.Undelegated) {
StakerActor._incrementNextBalance(expectedBalances.inactiveStakeBalance, amount);
StakerActor._incrementNextBalance(expectedBalances.globalInactiveStakeBalance, amount);
StakerActor._incrementNextBalance(expectedBalances.undelegatedStakeBalance, amount);
StakerActor._incrementNextBalance(expectedBalances.globalUndelegatedStakeBalance, amount);
} else if (to.status === StakeStatus.Delegated && to.poolId !== undefined) {
StakerActor._incrementNextBalance(expectedBalances.delegatedStakeBalance, amount);
StakerActor._incrementNextBalance(expectedBalances.globalDelegatedStakeBalance, amount);
@@ -319,8 +321,8 @@ export class StakerActor extends BaseActor {
// check balances
expectedBalances.zrxBalance = expectedBalances.zrxBalance.minus(amount);
expectedBalances.stakeBalanceInVault = expectedBalances.stakeBalanceInVault.plus(amount);
StakerActor._incrementCurrentAndNextBalance(expectedBalances.inactiveStakeBalance, amount);
StakerActor._incrementCurrentAndNextBalance(expectedBalances.globalInactiveStakeBalance, amount);
StakerActor._incrementCurrentAndNextBalance(expectedBalances.undelegatedStakeBalance, amount);
StakerActor._incrementCurrentAndNextBalance(expectedBalances.globalUndelegatedStakeBalance, amount);
return expectedBalances;
}
}

View File

@@ -40,11 +40,11 @@ blockchainTests.resets('Catastrophe Tests', env => {
await stakingApiWrapper.stakingContract.stake.awaitTransactionSuccessAsync(amountToStake, {
from: actors[0],
});
const inactiveStakeBalance = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
const undelegatedStakeBalance = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
actors[0],
StakeStatus.Undelegated,
);
expect(inactiveStakeBalance.currentEpochBalance).to.be.bignumber.equal(amountToStake);
expect(undelegatedStakeBalance.currentEpochBalance).to.be.bignumber.equal(amountToStake);
});
it('should not change state when in read-only mode', async () => {
// set to read-only mode
@@ -54,11 +54,11 @@ blockchainTests.resets('Catastrophe Tests', env => {
await stakingApiWrapper.stakingContract.stake.awaitTransactionSuccessAsync(amountToStake, {
from: actors[0],
});
const inactiveStakeBalance = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
const undelegatedStakeBalance = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
actors[0],
StakeStatus.Undelegated,
);
expect(inactiveStakeBalance.currentEpochBalance).to.be.bignumber.equal(ZERO);
expect(undelegatedStakeBalance.currentEpochBalance).to.be.bignumber.equal(ZERO);
});
it('should read values correctly when in read-only mode', async () => {
// stake some zrx
@@ -69,11 +69,11 @@ blockchainTests.resets('Catastrophe Tests', env => {
// set to read-only mode
await stakingApiWrapper.stakingProxyContract.setReadOnlyMode.awaitTransactionSuccessAsync(true);
// read stake balance in read-only mode
const inactiveStakeBalanceReadOnly = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
const undelegatedStakeBalanceReadOnly = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
actors[0],
StakeStatus.Undelegated,
);
expect(inactiveStakeBalanceReadOnly.currentEpochBalance).to.be.bignumber.equal(amountToStake);
expect(undelegatedStakeBalanceReadOnly.currentEpochBalance).to.be.bignumber.equal(amountToStake);
});
it('should exit read-only mode', async () => {
// set to read-only mode
@@ -84,11 +84,11 @@ blockchainTests.resets('Catastrophe Tests', env => {
await stakingApiWrapper.stakingContract.stake.awaitTransactionSuccessAsync(amountToStake, {
from: actors[0],
});
const inactiveStakeBalance = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
const undelegatedStakeBalance = await stakingApiWrapper.stakingContract.getOwnerStakeByStatus.callAsync(
actors[0],
StakeStatus.Undelegated,
);
expect(inactiveStakeBalance.currentEpochBalance).to.be.bignumber.equal(amountToStake);
expect(undelegatedStakeBalance.currentEpochBalance).to.be.bignumber.equal(amountToStake);
});
it('should emit event when setting read-only mode', async () => {
// set to read-only mode

View File

@@ -113,7 +113,7 @@ blockchainTests.resets('Stake Statuses', env => {
new StakeInfo(StakeStatus.Delegated, poolIds[0]),
amount,
);
// stake is now inactive, should not be able to move it out of active status again
// stake is now undelegated, should not be able to move it out of active status again
await staker.moveStakeAsync(
new StakeInfo(StakeStatus.Undelegated),
new StakeInfo(StakeStatus.Delegated, poolIds[1]),
@@ -146,7 +146,7 @@ blockchainTests.resets('Stake Statuses', env => {
new StakeInfo(StakeStatus.Delegated, poolIds[0]),
amount,
);
// stake is now inactive, should not be able to move it out of active status again
// stake is now undelegated, should not be able to move it out of active status again
await staker.moveStakeAsync(
new StakeInfo(StakeStatus.Undelegated),
new StakeInfo(StakeStatus.Delegated, poolIds[1]),
@@ -156,21 +156,21 @@ blockchainTests.resets('Stake Statuses', env => {
});
});
describe('Move Zero Stake', () => {
it('inactive -> inactive', async () => {
it('undelegated -> undelegated', async () => {
await staker.moveStakeAsync(
new StakeInfo(StakeStatus.Undelegated),
new StakeInfo(StakeStatus.Undelegated),
ZERO,
);
});
it('inactive -> delegated', async () => {
it('undelegated -> delegated', async () => {
await staker.moveStakeAsync(
new StakeInfo(StakeStatus.Undelegated),
new StakeInfo(StakeStatus.Delegated, poolIds[0]),
ZERO,
);
});
it('delegated -> inactive', async () => {
it('delegated -> undelegated', async () => {
await staker.moveStakeAsync(
new StakeInfo(StakeStatus.Delegated, poolIds[0]),
new StakeInfo(StakeStatus.Undelegated),
@@ -206,16 +206,16 @@ blockchainTests.resets('Stake Statuses', env => {
await staker.moveStakeAsync(from, to, amount.div(2));
await staker.goToNextEpochAsync();
};
it('inactive -> inactive', async () => {
it('undelegated -> undelegated', async () => {
await testMovePartialStake(new StakeInfo(StakeStatus.Undelegated), new StakeInfo(StakeStatus.Undelegated));
});
it('inactive -> delegated', async () => {
it('undelegated -> delegated', async () => {
await testMovePartialStake(
new StakeInfo(StakeStatus.Undelegated),
new StakeInfo(StakeStatus.Delegated, poolIds[0]),
);
});
it('delegated -> inactive', async () => {
it('delegated -> undelegated', async () => {
await testMovePartialStake(
new StakeInfo(StakeStatus.Delegated, poolIds[0]),
new StakeInfo(StakeStatus.Undelegated),
@@ -233,7 +233,7 @@ blockchainTests.resets('Stake Statuses', env => {
new StakeInfo(StakeStatus.Delegated, poolIds[1]),
);
});
it('inactive -> delegated (non-existent pool)', async () => {
it('undelegated -> delegated (non-existent pool)', async () => {
const amount = toBaseUnitAmount(10);
await staker.stakeAsync(amount);
await staker.moveStakeAsync(
@@ -264,7 +264,7 @@ blockchainTests.resets('Stake Statuses', env => {
const amount = toBaseUnitAmount(0);
await staker.unstakeAsync(amount);
});
it('should successfully unstake after becoming inactive', async () => {
it('should successfully unstake after becoming undelegated', async () => {
const amount = toBaseUnitAmount(10);
await staker.stakeAsync(amount);
await staker.moveStakeAsync(
@@ -277,10 +277,10 @@ blockchainTests.resets('Stake Statuses', env => {
new StakeInfo(StakeStatus.Undelegated),
amount,
);
await staker.goToNextEpochAsync(); // stake is now inactive
await staker.goToNextEpochAsync(); // stake is now undelegated
await staker.unstakeAsync(amount);
});
it('should fail to unstake in the same epoch as stake was set to inactive', async () => {
it('should fail to unstake in the same epoch as stake was undelegated', async () => {
const amount = toBaseUnitAmount(10);
await staker.stakeAsync(amount);
await staker.moveStakeAsync(
@@ -296,7 +296,7 @@ blockchainTests.resets('Stake Statuses', env => {
);
await staker.unstakeAsync(amount, new StakingRevertErrors.InsufficientBalanceError(amount, ZERO));
});
it('should fail to unstake in same epoch that inactive stake has been reactivated', async () => {
it('should fail to unstake in same epoch that undelegated stake has been delegated', async () => {
const amount = toBaseUnitAmount(10);
await staker.stakeAsync(amount);
await staker.moveStakeAsync(
@@ -306,7 +306,7 @@ blockchainTests.resets('Stake Statuses', env => {
);
await staker.unstakeAsync(amount, new StakingRevertErrors.InsufficientBalanceError(amount, ZERO));
});
it('should fail to unstake one epoch after inactive stake has been reactivated', async () => {
it('should fail to unstake one epoch after undelegated stake has been delegated', async () => {
const amount = toBaseUnitAmount(10);
await staker.stakeAsync(amount);
await staker.moveStakeAsync(
@@ -314,10 +314,10 @@ blockchainTests.resets('Stake Statuses', env => {
new StakeInfo(StakeStatus.Delegated, poolIds[0]),
amount,
);
await staker.goToNextEpochAsync(); // stake is now inactive
await staker.goToNextEpochAsync(); // stake is now undelegated
await staker.unstakeAsync(amount, new StakingRevertErrors.InsufficientBalanceError(amount, ZERO));
});
it('should fail to unstake >1 epoch after inactive stake has been reactivated', async () => {
it('should fail to unstake >1 epoch after undelegated stake has been delegated', async () => {
const amount = toBaseUnitAmount(10);
await staker.stakeAsync(amount);
await staker.moveStakeAsync(
@@ -325,7 +325,7 @@ blockchainTests.resets('Stake Statuses', env => {
new StakeInfo(StakeStatus.Delegated, poolIds[0]),
amount,
);
await staker.goToNextEpochAsync(); // stake is now inactive
await staker.goToNextEpochAsync(); // stake is now undelegated
await staker.goToNextEpochAsync(); // stake is now withdrawable
await staker.unstakeAsync(amount, new StakingRevertErrors.InsufficientBalanceError(amount, ZERO));
});
@@ -352,9 +352,9 @@ blockchainTests.resets('Stake Statuses', env => {
// );
// // Epoch 2: Status updates (no user intervention required)
// await staker.goToNextEpochAsync();
// // Epoch 3: Stake that has been inactive for an epoch can be withdrawn (no user intervention required)
// // Epoch 3: Stake that has been undelegated for an epoch can be withdrawn (no user intervention required)
// await staker.goToNextEpochAsync();
// // Later in Epoch 3: User reactivates half of their inactive stake; this becomes Active next epoch
// // Later in Epoch 3: User reactivates half of their undelegated stake; this becomes Active next epoch
// await staker.moveStakeAsync(
// new StakeInfo(StakeStatus.Undelegated),
// new StakeInfo(StakeStatus.Active),
@@ -374,7 +374,7 @@ blockchainTests.resets('Stake Statuses', env => {
// new StakeInfo(StakeStatus.Undelegated),
// toBaseUnitAmount(1.5),
// );
// // Later in Epoch 4: User withdraws all available inactive stake
// // Later in Epoch 4: User withdraws all available undelegated stake
// await staker.unstakeAsync(toBaseUnitAmount(0.5));
// // Epoch 5: Status updates (no user intervention required)
// await staker.goToNextEpochAsync();

View File

@@ -87,9 +87,9 @@ export interface StakeBalances {
zrxBalance: BigNumber;
stakeBalance: BigNumber;
stakeBalanceInVault: BigNumber;
inactiveStakeBalance: StoredBalance;
undelegatedStakeBalance: StoredBalance;
delegatedStakeBalance: StoredBalance;
globalInactiveStakeBalance: StoredBalance;
globalUndelegatedStakeBalance: StoredBalance;
globalDelegatedStakeBalance: StoredBalance;
delegatedStakeByPool: StakeBalanceByPool;
totalDelegatedStakeByPool: StakeBalanceByPool;