some refactoring for the staking proxy. Compiles, but no tests yet.
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
@@ -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
|
||||
{}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -96,7 +96,7 @@ contract LibMathTest {
|
||||
uint8 alphaDenominator
|
||||
)
|
||||
public
|
||||
pure
|
||||
// pure
|
||||
returns (uint256)
|
||||
{
|
||||
return LibMath._cobbDouglasSimplifiedInverse(
|
||||
|
@@ -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",
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user