2020-11-20 09:19:59 -05:00

111 lines
2.8 KiB
Solidity

/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;
import "@0x/contracts-staking/contracts/src/Staking.sol";
contract TestStaking is
Staking
{
IEtherToken public testWeth;
struct TestPool {
uint96 operatorStake;
uint96 membersStake;
}
mapping(bytes32 => TestPool) private _testPools;
constructor(address exchangeAddress, IEtherToken _testWeth) public {
testWeth = _testWeth;
_addAuthorizedAddress(msg.sender);
init();
validExchanges[exchangeAddress] = true;
_removeAuthorizedAddressAtIndex(msg.sender, 0);
}
function advanceEpoch()
external
{
currentEpoch += 1;
}
/// @dev Create a test pool.
function createTestPool(
bytes32 poolId,
uint96 operatorStake,
uint96 membersStake
)
external
{
TestPool storage pool = _testPools[poolId];
pool.operatorStake = operatorStake;
pool.membersStake = membersStake;
}
function getAggregatedStatsForCurrentEpoch()
external
view
returns (IStructs.AggregatedStats memory)
{
return aggregatedStatsByEpoch[currentEpoch];
}
/// @dev Overridden to use test pools.
function getTotalStakeDelegatedToPool(bytes32 poolId)
public
view
returns (IStructs.StoredBalance memory balance)
{
TestPool memory pool = _testPools[poolId];
uint96 stake = pool.operatorStake + pool.membersStake;
return IStructs.StoredBalance({
currentEpoch: currentEpoch.downcastToUint64(),
currentEpochBalance: stake,
nextEpochBalance: stake
});
}
/// @dev Overridden to use test pools.
function getStakeDelegatedToPoolByOwner(address, bytes32 poolId)
public
view
returns (IStructs.StoredBalance memory balance)
{
TestPool memory pool = _testPools[poolId];
return IStructs.StoredBalance({
currentEpoch: currentEpoch.downcastToUint64(),
currentEpochBalance: pool.operatorStake,
nextEpochBalance: pool.operatorStake
});
}
function getWethContract()
public
view
returns (IEtherToken wethContract)
{
return testWeth;
}
}