diff --git a/contracts/staking/contracts/src/MixinEpoch.sol b/contracts/staking/contracts/src/MixinEpoch.sol deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/contracts/staking/contracts/src/MixinRewards.sol b/contracts/staking/contracts/src/MixinRewards.sol deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/contracts/staking/contracts/src/MixinStake.sol b/contracts/staking/contracts/src/MixinStake.sol deleted file mode 100644 index d22613b17d..0000000000 --- a/contracts/staking/contracts/src/MixinStake.sol +++ /dev/null @@ -1,92 +0,0 @@ -/* - - Copyright 2018 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.5; - -import "./mixins/MStake.sol"; -import "./interfaces/IVault.sol"; -import "./libs/LibZrxToken.sol"; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; - - -contract MixinStake is - MStake, - SafeMath -{ - using LibZrxToken for uint256; - - // default maker id that stake is delegated to - bytes32 constant internal NIL_MAKER_ID = 0x0; - - // mapping from Staker to Maker Id to Amount Staked - mapping (address => mapping (bytes32 => uint256)) delegatedStake; - - // mapping from Staker to Maker Id to Amount Staked - mapping (address => uint256) totalStake; - - // ZRX vault - IVault zrxVault; - - constructor(address _zrxVault) public { - zrxVault = IVault(_zrxVault); - } - - function stake(uint256 amount) - external - returns (uint256) - { - // sanitize input - can only stake whole tokens - uint256 amountOfStakeToMint = amount._roundDownToNearestWholeToken(); - - // deposit equivalent amount of ZRX into vault - zrxVault.depositFrom(msg.sender, amountOfStakeToMint); - - // mint stake - totalStake[msg.sender] = _safeAdd(totalStake[msg.sender], amountOfStakeToMint); - delegatedStake[msg.sender][NIL_MAKER_ID] = _safeAdd(delegatedStake[msg.sender][NIL_MAKER_ID], amountOfStakeToMint); - - // return amount of stake minted - return amountOfStakeToMint; - } - - function unstake(uint256 amount) - external - returns (uint256) - { - // sanitize input - can only stake whole tokens - uint256 amountOfStakeToBurn = amount._roundDownToNearestWholeToken(); - - // burn stake - totalStake[msg.sender] = _safeSub(totalStake[msg.sender], amountOfStakeToBurn); - delegatedStake[msg.sender][NIL_MAKER_ID] = _safeSub(delegatedStake[msg.sender][NIL_MAKER_ID], amountOfStakeToBurn); - - // withdraw equivalent amount of ZRX from vault - zrxVault.withdrawFrom(msg.sender, amountOfStakeToBurn); - - // return amount of stake minted - return amountOfStakeToBurn; - } - - function getStakeBalance(address owner) - external - view - returns (uint256) - { - return totalStake[owner]; - } -} diff --git a/contracts/staking/contracts/src/MixinTimelock.sol b/contracts/staking/contracts/src/MixinTimelock.sol deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/contracts/staking/contracts/src/Staking.sol b/contracts/staking/contracts/src/Staking.sol index 17b9ae84d5..e6dd73beba 100644 --- a/contracts/staking/contracts/src/Staking.sol +++ b/contracts/staking/contracts/src/Staking.sol @@ -18,10 +18,12 @@ pragma solidity ^0.5.9; -import "./MixinStake.sol"; +import "./core/MixinStorage.sol"; +import "./core/MixinStake.sol"; contract Staking is + MixinStorage, MixinStake { constructor(address zrxVault) @@ -29,4 +31,87 @@ contract Staking is MixinStake(zrxVault) {} + ///// STAKING ///// + + function stake(uint256 amount) + external + returns (uint256 amountOfStakeMinted) + { + amountOfStakeMinted = _stake(amount); + return amountOfStakeMinted; + } + + function unstake(uint256 amount) + external + returns (uint256 amountOfStakeBurned) + { + amountOfStakeBurned = _unstake(amount); + return amountOfStakeBurned; + } + + function getStakeBalance(address owner) + external + view + returns (uint256 balance) + { + balance = _getStakeBalance(owner); + return balance; + } + + function delegateStake(bytes32 makerId, uint256 amount) + external + returns (uint256 amountOfStakeDelegated) + { + amountOfStakeDelegated = _delegateStake(makerId, amount); + return amountOfStakeDelegated; + } + + function undelegateStake(bytes32 makerId, uint256 amount) + external + returns (uint256 amountOfStakeUndelegated) + { + amountOfStakeUndelegated = _undelegateStake(makerId, amount); + return amountOfStakeUndelegated; + } + + function stakeAndDelegate(bytes32 makerId, uint256 amount) + external + returns (uint256 amountOfStakeMintedAndDelegated) + { + amountOfStakeMintedAndDelegated = _stakeAndDelegate(makerId, amount); + return amountOfStakeMintedAndDelegated; + } + + function undelegateAndUnstake(bytes32 makerId, uint256 amount) + external + returns (uint256 amountOfStakeUndelegatedAndUnstaked) + { + + } + + ///// STAKE BALANCES ///// + + function getStakeDelegatedByOwner(address owner, bytes32 makerId) + external + returns (uint256 balance) + { + balance = _getStakeDelegatedByOwner(owner, makerId); + return balance; + } + + function getTotalStakeDelegatedByOwner(address owner) + external + returns (uint256 balance) + { + balance = _getTotalStakeDelegatedByOwner(owner); + return balance; + } + + function getTotalStakeDelegatedToMaker(bytes32 makerId) + external + returns (uint256 balance) + { + balance = _getTotalStakeDelegatedToMaker(makerId); + return balance; + } } diff --git a/contracts/staking/contracts/src/interfaces/IERC20Vault.sol b/contracts/staking/contracts/src/interfaces/IERC20Vault.sol deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/contracts/staking/contracts/src/interfaces/IEthVault.sol b/contracts/staking/contracts/src/interfaces/IEthVault.sol deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/contracts/staking/contracts/src/interfaces/IStake.sol b/contracts/staking/contracts/src/interfaces/IStake.sol deleted file mode 100644 index 72427e241a..0000000000 --- a/contracts/staking/contracts/src/interfaces/IStake.sol +++ /dev/null @@ -1,27 +0,0 @@ -/* - - Copyright 2018 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.5; - - -contract IStake -{ - function stake(uint256 amount) external returns (uint256); - function unstake(uint256 amount) external returns (uint256); - function getStakeBalance(address owner) external view returns (uint256); -} diff --git a/contracts/staking/contracts/src/interfaces/IVault.sol b/contracts/staking/contracts/src/interfaces/IVault.sol index 87d478268d..6b3fc49fcd 100644 --- a/contracts/staking/contracts/src/interfaces/IVault.sol +++ b/contracts/staking/contracts/src/interfaces/IVault.sol @@ -22,10 +22,7 @@ pragma solidity ^0.5.5; interface IVault { function depositFrom(address owner, uint256 amount) external; - function withdrawFrom(address owner, uint256 amount) external; - function withdrawAllFrom(address owner) external returns (uint256); - function balanceOf(address owner) external view returns (uint256); } diff --git a/contracts/staking/contracts/src/mixins/MStake.sol b/contracts/staking/contracts/src/mixins/MStake.sol deleted file mode 100644 index 94272c8a1d..0000000000 --- a/contracts/staking/contracts/src/mixins/MStake.sol +++ /dev/null @@ -1,25 +0,0 @@ -/* - - 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; - -import "../interfaces/IStake.sol"; - -contract MStake is - IStake -{} diff --git a/contracts/staking/contracts/src/vaults/BuyInVault.sol b/contracts/staking/contracts/src/vaults/BuyInVault.sol deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/contracts/staking/contracts/src/vaults/RebateVault.sol b/contracts/staking/contracts/src/vaults/RebateVault.sol index e69de29bb2..a02c52ce44 100644 --- a/contracts/staking/contracts/src/vaults/RebateVault.sol +++ b/contracts/staking/contracts/src/vaults/RebateVault.sol @@ -0,0 +1,63 @@ +/* + + Copyright 2018 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.5; + +import "../interfaces/IVault.sol"; +import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "./MixinVaultCore.sol"; + + +contract ZrxVault is + IVault, + SafeMath, + MixinVaultCore +{ + + // mapping from Owner to ZRX balance + mapping (address => uint256) internal balances; + + constructor() + public + {} + + + function depositFrom(address owner, uint256 amount) + external + onlyStakingContract + {} + + function withdrawFrom(address owner, uint256 amount) + external + onlyStakingContract + {} + + function withdrawAllFrom(address owner) + external + onlyInCatostrophicFailure + returns (uint256) + {} + + function balanceOf(address owner) + external + view + returns (uint256) + { + return uint256(132 * 10**18); + } +} diff --git a/contracts/staking/contracts/test/LibMathTest.sol b/contracts/staking/contracts/test/LibMathTest.sol index 58bedc7681..9f7380f99c 100644 --- a/contracts/staking/contracts/test/LibMathTest.sol +++ b/contracts/staking/contracts/test/LibMathTest.sol @@ -96,7 +96,7 @@ contract LibMathTest { uint8 alphaDenominator ) public - pure + // pure returns (uint256) { return LibMath._cobbDouglasSimplifiedInverse( diff --git a/contracts/staking/package.json b/contracts/staking/package.json index 02df82af34..6497e62f96 100644 --- a/contracts/staking/package.json +++ b/contracts/staking/package.json @@ -10,6 +10,7 @@ "test": "test" }, "scripts": { + "build2": "tsc -b", "build": "yarn pre_build && tsc -b", "build:ci": "yarn build", "pre_build": "run-s compile contracts:gen generate_contract_wrappers", diff --git a/contracts/staking/test/utils/staking_wrapper.ts b/contracts/staking/test/utils/staking_wrapper.ts index 3d716203b5..32b066bb24 100644 --- a/contracts/staking/test/utils/staking_wrapper.ts +++ b/contracts/staking/test/utils/staking_wrapper.ts @@ -152,6 +152,15 @@ export class StakingWrapper { totalStake: BigNumber, alphaDenominator: BigNumber ) { + const txReceipt = await this.getLibMathTestContract().cobbDouglasSimplifiedInverse.awaitTransactionSuccessAsync( + totalRewards, + ownerFees, + totalFees, + ownerStake, + totalStake, + alphaDenominator + ); + const output = await this.getLibMathTestContract().cobbDouglasSimplifiedInverse.callAsync( totalRewards, ownerFees,