Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staking app #101

Closed
wants to merge 21 commits into from
Closed

Staking app #101

wants to merge 21 commits into from

Conversation

izqui
Copy link
Contributor

@izqui izqui commented Feb 23, 2018

Implements a generic Staking primitive that can be used to build things such as the Aragon Network v2 or TCRs.

Inspired by @onbjerg's aragonlabs' staking app and Harbour's Stakebank

Conforms to ERC900 staking interface.

Needs tests, documentation and review.

@izqui izqui changed the title WIP Staking app [WIP] Staking app Feb 23, 2018
function unlockedBalanceOf(address acct) public view returns (uint256) {
uint256 unlockedTokens = accounts[acct].amount;

Lock[] storage locks = accounts[acct].locks;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be memory

@coveralls
Copy link

coveralls commented Feb 23, 2018

Coverage Status

Coverage remained the same at 94.91% when pulling 6514851 on staking into 0025531 on master.

@decanus
Copy link

decanus commented Feb 23, 2018

totalStakedFor, token as well as supportsHistory need to be implemented

@CLAassistant
Copy link

CLAassistant commented Feb 23, 2018

CLA assistant check
All committers have signed the CLA.

@onbjerg
Copy link
Contributor

onbjerg commented Feb 23, 2018

Biggest hurdle will be the forwarding interface, will help you on this since I have some thoughts from my old unfinished Aragon Labs implementation

@izqui
Copy link
Contributor Author

izqui commented Feb 23, 2018

Awesome @onbjerg. I was thinking forwarding should either be stake(..) or stakeAndLock(..) and pass fwd data as input to contract scripts?

@onbjerg
Copy link
Contributor

onbjerg commented Mar 27, 2018

@izqui Biggest issue is not really the forwarding itself, it's mostly returning results from the contract we forward to.

For example, depending on the outcome of a vote, we might want to unlock stake for some users (allowing stuff like TCRs). We could modify the callscript but I feel a little dirty just bringing it up...

@izqui izqui self-assigned this Apr 16, 2018

function processStake(address acct, uint256 amount, bytes data) internal {
accounts[acct].amount += amount; // overflow check in token contract
assert(accounts[acct].amount >= amount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean with the comment one line above? Aren't you checking overflow here?
Shouldn't we use SafeMath lib like the rest of the apps?
Do we allow amount = 0?

}
}

function processStake(address acct, uint256 amount, bytes data) internal {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are using another function here? It's kind of short and only called once.

}

function unstake(uint256 amount, bytes data) authP(UNSTAKE_ROLE, arr(amount)) checkUnlocked(amount) public {
require(accounts[msg.sender].amount >= amount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SafeMath?


function unlockAll(address acct) external {
while (accounts[acct].locks.length > 0) {
if (canUnlock(acct, 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something here, but:

  • Why unlock head of array first, instead of tail? With tail there would be no need to move elements of array.
  • If the first element of the array can't be unlocked, how would the loop be exited?

function stakeFor(address user, uint256 amount, bytes data) public;
function unstake(uint256 amount, bytes data) public;

function totalStakedFor(address addr) public view returns (uint256);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing totalStaked? I saw discussion here and your response, but it seems it's part of the interface definition.


Lock[] storage locks = accounts[acct].locks;
for (uint256 i = 0; i < locks.length; i++) {
if (!canUnlock(acct, i)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. I think I understand the rationale, but I see a potential problem: If unstake function is called, it will call this function to check available staked but not locked tokens. If there are potentially unlocked, but actually locked tokens, they may be unstaked, leaving a bigger total locked balance than the staked balance.

function lock(
uint256 amount,
uint8 lockUnit,
uint64 lockEnds,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be useful a helper/wrapper to indefinitely lock tokens without forcing the user to pass MAX UINT64?

Unlocked(acct, msg.sender, lockId);
}

function moveTokens(address from, address to, uint256 amount) authP(GOD_ROLE, arr(from, to, amount)) external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we check if moved tokens are unlocked? Otherwise an account could end up having more locked tokens than staked.

@bingen
Copy link
Contributor

bingen commented Jun 7, 2018

Missing items from PR #351

@sohkai sohkai changed the title [WIP] Staking app Staking app Jun 13, 2018
@bingen bingen requested a review from sohkai June 14, 2018 18:51
@sohkai
Copy link
Contributor

sohkai commented Dec 8, 2018

Closed in favor of https://github.com/aragon/staking/

@sohkai sohkai closed this Dec 8, 2018
@facuspagnuolo facuspagnuolo deleted the staking branch April 17, 2019 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants