Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eth-contracts/.gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,3 +9,4 @@ build/
coverage/
coverage.json
coverage.zip
migrations/migration-output.json
9 changes: 2 additions & 7 deletions eth-contracts/contracts/service/DelegateManager.sol
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,9 +67,6 @@ contract DelegateManager is RegistryContract {
// Requester to pending undelegate request
mapping (address => UndelegateStakeRequest) undelegateRequests;

// TODO: Evaluate whether this is necessary
bytes empty;

event IncreaseDelegatedStake(
address _delegator,
address _serviceProvider,
Expand DownExpand Up@@ -136,8 +133,7 @@ contract DelegateManager is RegistryContract {
stakingContract.delegateStakeFor(
_targetSP,
delegator,
_amount,
empty
_amount
);

// Update list of delegators to SP if necessary
Expand DownExpand Up@@ -275,8 +271,7 @@ contract DelegateManager is RegistryContract {
).undelegateStakeFor(
serviceProvider,
delegator,
unstakeAmount,
empty
unstakeAmount
);

// Update amount staked from this delegator to targeted service provider
Expand Down
10 changes: 4 additions & 6 deletions eth-contracts/contracts/service/ServiceProviderFactory.sol
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,6 @@ contract ServiceProviderFactory is RegistryContract {
bytes32 private governanceKey;
bytes32 private serviceTypeManagerKey;
address private deployerAddress;
bytes empty;

/// @dev - Stores following entities
/// 1) Directly staked amount by SP, not including delegators
Expand DownExpand Up@@ -148,7 +147,7 @@ contract ServiceProviderFactory is RegistryContract {
if (_stakeAmount > 0) {
StakingInterface(
registry.getContract(stakingProxyOwnerKey)
).stakeFor(msg.sender, _stakeAmount, empty);
).stakeFor(msg.sender, _stakeAmount);
}

require (
Expand DownExpand Up@@ -231,8 +230,7 @@ contract ServiceProviderFactory is RegistryContract {
unstakeAmount = stakingContract.totalStakedFor(msg.sender);
stakingContract.unstakeFor(
msg.sender,
unstakeAmount,
empty
unstakeAmount
);

// Update deployer total
Expand DownExpand Up@@ -313,7 +311,7 @@ contract ServiceProviderFactory is RegistryContract {
);

// Stake increased token amount for msg.sender
stakingContract.stakeFor(msg.sender, _increaseStakeAmount, empty);
stakingContract.stakeFor(msg.sender, _increaseStakeAmount);

uint newStakeAmount = stakingContract.totalStakedFor(msg.sender);

Expand DownExpand Up@@ -358,7 +356,7 @@ contract ServiceProviderFactory is RegistryContract {
"Please deregister endpoints to remove all stake");

// Decrease staked token amount for msg.sender
stakingContract.unstakeFor(msg.sender, _decreaseStakeAmount, empty);
stakingContract.unstakeFor(msg.sender, _decreaseStakeAmount);

// Query current stake
uint newStakeAmount = stakingContract.totalStakedFor(msg.sender);
Expand Down
57 changes: 13 additions & 44 deletions eth-contracts/contracts/staking/Staking.sol
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,17 +43,6 @@ contract Staking is RegistryContract, StakingInterface {
bytes32 delegateManagerKey;
bytes32 serviceProviderFactoryKey;

event StakeTransferred(
address indexed from,
uint256 amount,
address to
);

event Claimed(
address claimaint,
uint256 amountClaimed
);

event Slashed(address indexed user, uint256 amount, uint256 total);

function initialize(
Expand DownExpand Up@@ -86,11 +75,7 @@ contract Staking is RegistryContract, StakingInterface {
msg.sender == registry.getContract(claimsManagerProxyKey),
"Only callable from ClaimsManager"
);
_stakeFor(
_stakerAccount,
msg.sender,
_amount,
bytes("")); // TODO: RM bytes requirement if unused
_stakeFor(_stakerAccount, msg.sender, _amount);

// Update claim history even if no value claimed
accounts[_stakerAccount].claimHistory.add(block.number.toUint64(), _amount);
Expand DownExpand Up@@ -130,12 +115,10 @@ contract Staking is RegistryContract, StakingInterface {
* @notice Stakes `_amount` tokens, transferring them from _accountAddress, and assigns them to `_accountAddress`
* @param _accountAddress The final staker of the tokens
* @param _amount Number of tokens staked
* @param _data Used in Staked event, to add signalling information in more complex staking applications
*/
function stakeFor(
address _accountAddress,
uint256 _amount,
bytes calldata _data
uint256 _amount
) external
{
requireIsInitialized();
Expand All@@ -146,20 +129,17 @@ contract Staking is RegistryContract, StakingInterface {
_stakeFor(
_accountAddress,
_accountAddress,
_amount,
_data);
_amount);
}

/**
* @notice Unstakes `_amount` tokens, returning them to the desired account.
* @param _accountAddress Account unstaked for, and token recipient
* @param _amount Number of tokens staked
* @param _data Used in Unstaked event, to add signalling information in more complex staking applications
*/
function unstakeFor(
address _accountAddress,
uint256 _amount,
bytes calldata _data
uint256 _amount
) external
{
requireIsInitialized();
Expand All@@ -170,8 +150,7 @@ contract Staking is RegistryContract, StakingInterface {
_unstakeFor(
_accountAddress,
_accountAddress,
_amount,
_data
_amount
);
}

Expand All@@ -180,13 +159,11 @@ contract Staking is RegistryContract, StakingInterface {
* @param _accountAddress The final staker of the tokens
* @param _delegatorAddress Address from which to transfer tokens
* @param _amount Number of tokens staked
* @param _data Used in Staked event, to add signalling information in more complex staking applications
*/
function delegateStakeFor(
address _accountAddress,
address _delegatorAddress,
uint256 _amount,
bytes calldata _data
uint256 _amount
) external {
requireIsInitialized();
require(
Expand All@@ -196,22 +173,19 @@ contract Staking is RegistryContract, StakingInterface {
_stakeFor(
_accountAddress,
_delegatorAddress,
_amount,
_data);
_amount);
}

/**
* @notice Stakes `_amount` tokens, transferring them from caller, and assigns them to `_accountAddress`
* @param _accountAddress The staker of the tokens
* @param _delegatorAddress Address from which to transfer tokens
* @param _amount Number of tokens unstaked
* @param _data Used in Staked event, to add signalling information in more complex staking applications
*/
function undelegateStakeFor(
address _accountAddress,
address _delegatorAddress,
uint256 _amount,
bytes calldata _data
uint256 _amount
) external {
requireIsInitialized();
require(
Expand All@@ -221,8 +195,7 @@ contract Staking is RegistryContract, StakingInterface {
_unstakeFor(
_accountAddress,
_delegatorAddress,
_amount,
_data);
_amount);
}

/**
Expand DownExpand Up@@ -315,8 +288,7 @@ contract Staking is RegistryContract, StakingInterface {
function _stakeFor(
address _stakeAccount,
address _transferAccount,
uint256 _amount,
bytes memory _data
uint256 _amount
) internal
{
// staking 0 tokens is invalid
Expand All@@ -334,15 +306,13 @@ contract Staking is RegistryContract, StakingInterface {
emit Staked(
_stakeAccount,
_amount,
totalStakedFor(_stakeAccount),
_data);
totalStakedFor(_stakeAccount));
}

function _unstakeFor(
address _stakeAccount,
address _transferAccount,
uint256 _amount,
bytes memory _data
uint256 _amount
) internal
{
require(_amount > 0, ERROR_AMOUNT_ZERO);
Expand All@@ -359,8 +329,7 @@ contract Staking is RegistryContract, StakingInterface {
emit Unstaked(
_stakeAccount,
_amount,
totalStakedFor(_stakeAccount),
_data
totalStakedFor(_stakeAccount)
);
}

Expand Down
14 changes: 6 additions & 8 deletions eth-contracts/contracts/staking/StakingInterface.sol
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,23 +5,21 @@ pragma solidity ^0.5.0;
// Modified interface for ERC900: https://eips.ethereum.org/EIPS/eip-900
// Eliminates direct stake operations
interface StakingInterface {
event Staked(address indexed user, uint256 amount, uint256 total, bytes data);
event Unstaked(address indexed user, uint256 amount, uint256 total, bytes data);
event Staked(address indexed user, uint256 amount, uint256 total);
event Unstaked(address indexed user, uint256 amount, uint256 total);

function stakeFor(address user, uint256 amount, bytes calldata data) external;
function unstakeFor(address user, uint256 amount, bytes calldata data) external;
function stakeFor(address user, uint256 amount) external;
function unstakeFor(address user, uint256 amount) external;

function stakeRewards(uint256 amount, address stakerAccount) external;
function delegateStakeFor(
address accountAddress,
address delegatorAddress,
uint256 amount,
bytes calldata data) external;
uint256 amount) external;
function undelegateStakeFor(
address accountAddress,
address delegatorAddress,
uint256 amount,
bytes calldata data) external;
uint256 amount) external;
function slash(uint256 amount, address slashAddress) external;


Expand Down
10 changes: 4 additions & 6 deletions eth-contracts/contracts/test/MockStakingCaller.sol
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,21 +44,19 @@ contract MockStakingCaller is RegistryContract {
// Test only function
function stakeFor(
address _accountAddress,
uint256 _amount,
bytes calldata _data
uint256 _amount
) external {
requireIsInitialized();
staking.stakeFor(_accountAddress, _amount, _data);
staking.stakeFor(_accountAddress, _amount);
}

// Test only function
function unstakeFor(
address _accountAddress,
uint256 _amount,
bytes calldata _data
uint256 _amount
) external {
requireIsInitialized();
staking.unstakeFor(_accountAddress, _amount, _data);
staking.unstakeFor(_accountAddress, _amount);
}

function slash(
Expand Down
2 changes: 1 addition & 1 deletion eth-contracts/migrations/2_token_migration.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,4 +24,4 @@ module.exports = (deployer, network, accounts) => {
// Export to env for reference in future migrations
process.env.tokenAddress = tokenProxy.address
})
}
}
29 changes: 29 additions & 0 deletions eth-contracts/migrations/9_output_address_info.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
const fs = require('fs-extra')
const path = require('path')

const contractConfig = require('../contract-config.js')

// Migration to output token and registry addresses
module.exports = (deployer, network, accounts) => {
deployer.then(async () => {
const config = contractConfig[network]
const proxyAdminAddress = config.proxyAdminAddress || accounts[10]
const proxyDeployerAddress = config.proxyDeployerAddress || accounts[11]
const tokenAddress = process.env.tokenAddress
const registryAddress = process.env.registryAddress
let outputValues = {
tokenAddress,
registryAddress,
proxyAdminAddress,
proxyDeployerAddress
}
const outputFilePath = path.join(__dirname, 'migration-output.json')
fs.removeSync(outputFilePath)
console.log(`Migration output values: ${outputValues}`)
fs.writeFile(outputFilePath, JSON.stringify(outputValues), (err) => {
if (err != null) {
console.log(err)
}
})
})
}
Loading