Remove isMakerAssignedToStakingPool to reduce sloads

This commit is contained in:
Amir Bandeali
2019-09-23 17:01:10 -07:00
parent 7f1afb57b0
commit 8a2b178e6f

View File

@@ -125,7 +125,8 @@ contract MixinStakingPool is
{ {
// Is the maker already in a pool? // Is the maker already in a pool?
address makerAddress = msg.sender; address makerAddress = msg.sender;
if (isMakerAssignedToStakingPool(makerAddress)) { IStructs.MakerPoolJoinStatus memory poolJoinStatus = poolJoinedByMakerAddress[makerAddress];
if (poolJoinStatus.confirmed) {
LibRichErrors.rrevert(LibStakingRichErrors.MakerPoolAssignmentError( LibRichErrors.rrevert(LibStakingRichErrors.MakerPoolAssignmentError(
LibStakingRichErrors.MakerPoolAssignmentErrorCodes.MakerAddressAlreadyRegistered, LibStakingRichErrors.MakerPoolAssignmentErrorCodes.MakerAddressAlreadyRegistered,
makerAddress, makerAddress,
@@ -133,10 +134,7 @@ contract MixinStakingPool is
)); ));
} }
IStructs.MakerPoolJoinStatus memory poolJoinStatus = IStructs.MakerPoolJoinStatus({ poolJoinStatus.poolId = poolId;
poolId: poolId,
confirmed: false
});
poolJoinedByMakerAddress[makerAddress] = poolJoinStatus; poolJoinedByMakerAddress[makerAddress] = poolJoinStatus;
// Maker has joined to the pool, awaiting operator confirmation // Maker has joined to the pool, awaiting operator confirmation
@@ -204,24 +202,14 @@ contract MixinStakingPool is
view view
returns (bytes32) returns (bytes32)
{ {
if (isMakerAssignedToStakingPool(makerAddress)) { IStructs.MakerPoolJoinStatus memory poolJoinStatus = poolJoinedByMakerAddress[makerAddress];
return poolJoinedByMakerAddress[makerAddress].poolId; if (poolJoinStatus.confirmed) {
return poolJoinStatus.poolId;
} else { } else {
return NIL_POOL_ID; return NIL_POOL_ID;
} }
} }
/// @dev Returns true iff the maker is assigned to a staking pool.
/// @param makerAddress Address of maker
/// @return True iff assigned.
function isMakerAssignedToStakingPool(address makerAddress)
public
view
returns (bool)
{
return poolJoinedByMakerAddress[makerAddress].confirmed;
}
/// @dev Returns a staking pool /// @dev Returns a staking pool
/// @param poolId Unique id of pool. /// @param poolId Unique id of pool.
function getStakingPool(bytes32 poolId) function getStakingPool(bytes32 poolId)
@@ -242,11 +230,12 @@ contract MixinStakingPool is
) )
internal internal
{ {
// cache pool for use throughout this function // cache pool and join status for use throughout this function
IStructs.Pool memory pool = _poolById[poolId]; IStructs.Pool memory pool = _poolById[poolId];
IStructs.MakerPoolJoinStatus memory poolJoinStatus = poolJoinedByMakerAddress[makerAddress];
// Is the maker already in a pool? // Is the maker already in a pool?
if (isMakerAssignedToStakingPool(makerAddress)) { if (poolJoinStatus.confirmed) {
LibRichErrors.rrevert(LibStakingRichErrors.MakerPoolAssignmentError( LibRichErrors.rrevert(LibStakingRichErrors.MakerPoolAssignmentError(
LibStakingRichErrors.MakerPoolAssignmentErrorCodes.MakerAddressAlreadyRegistered, LibStakingRichErrors.MakerPoolAssignmentErrorCodes.MakerAddressAlreadyRegistered,
makerAddress, makerAddress,
@@ -255,7 +244,7 @@ contract MixinStakingPool is
} }
// Is the maker trying to join this pool; or are they the operator? // Is the maker trying to join this pool; or are they the operator?
bytes32 makerPendingPoolId = poolJoinedByMakerAddress[makerAddress].poolId; bytes32 makerPendingPoolId = poolJoinStatus.poolId;
if (makerPendingPoolId != poolId && makerAddress != pool.operator) { if (makerPendingPoolId != poolId && makerAddress != pool.operator) {
LibRichErrors.rrevert(LibStakingRichErrors.MakerPoolAssignmentError( LibRichErrors.rrevert(LibStakingRichErrors.MakerPoolAssignmentError(
LibStakingRichErrors.MakerPoolAssignmentErrorCodes.MakerAddressNotPendingAdd, LibStakingRichErrors.MakerPoolAssignmentErrorCodes.MakerAddressNotPendingAdd,
@@ -276,7 +265,7 @@ contract MixinStakingPool is
} }
// Add maker to pool // Add maker to pool
IStructs.MakerPoolJoinStatus memory poolJoinStatus = IStructs.MakerPoolJoinStatus({ poolJoinStatus = IStructs.MakerPoolJoinStatus({
poolId: poolId, poolId: poolId,
confirmed: true confirmed: true
}); });