Skip to content

Commit

Permalink
Agreement: Integrate external Staking app (#1151)
Browse files Browse the repository at this point in the history
* Integrate external Staking app

* Staking integration: adapt to new names

* test: fix wrapper names

Also, fix token deposit errors

* Upgrade Staking dependency

* Fixes after moving moving responsibilities to disputable app

- action end date
- cannot challenge error

* Fixes after rebase on moving responsibilities to disputable app

* Update Staking dependency

* Fixes after rebase on moving responsibilities to disputable app

Address PR #1151 comments.

* Clean _unlockAndSlashBalance

Fix dependencies (https://github.com/cgewecke/web3-issue-3544)

* fixup! Clean _unlockAndSlashBalance

Co-authored-by: Facu Spagnuolo <facuspagnuolo@users.noreply.github.com>
  • Loading branch information
ßingen and facuspagnuolo authored Jun 12, 2020
1 parent f698674 commit b378a20
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 301 deletions.
16 changes: 5 additions & 11 deletions apps/agreement/contracts/Agreement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import "@aragon/os/contracts/lib/math/SafeMath.sol";
import "@aragon/os/contracts/lib/math/SafeMath64.sol";

import "./lib/BytesHelper.sol";
import "./staking/Staking.sol";
import "./staking/StakingFactory.sol";


contract Agreement is IAgreement, AragonApp {
Expand Down Expand Up @@ -895,7 +893,7 @@ contract Agreement is IAgreement, AragonApp {
return;
}

_staking.lock(_user, _amount);
_staking.lock(_user, address(this), _amount);
}

/**
Expand All @@ -909,7 +907,7 @@ contract Agreement is IAgreement, AragonApp {
return;
}

_staking.unlock(_user, _amount);
_staking.unlock(_user, address(this), _amount);
}

/**
Expand All @@ -924,7 +922,7 @@ contract Agreement is IAgreement, AragonApp {
return;
}

_staking.slash(_user, _challenger, _amount);
_staking.slashAndUnstake(_user, _challenger, _amount);
}

/**
Expand All @@ -936,12 +934,8 @@ contract Agreement is IAgreement, AragonApp {
* @param _slashAmount Number of collateral tokens to be slashed
*/
function _unlockAndSlashBalance(Staking _staking, address _user, uint256 _unlockAmount, address _challenger, uint256 _slashAmount) internal {
if (_unlockAmount != 0 && _slashAmount != 0) {
_staking.unlockAndSlash(_user, _unlockAmount, _challenger, _slashAmount);
} else {
_unlockBalance(_staking, _user, _unlockAmount);
_slashBalance(_staking, _user, _challenger, _slashAmount);
}
_unlockBalance(_staking, _user, _unlockAmount);
_slashBalance(_staking, _user, _challenger, _slashAmount);
}

/**
Expand Down
221 changes: 0 additions & 221 deletions apps/agreement/contracts/staking/Staking.sol

This file was deleted.

38 changes: 0 additions & 38 deletions apps/agreement/contracts/staking/StakingFactory.sol

This file was deleted.

3 changes: 2 additions & 1 deletion apps/agreement/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"@aragon/apps-shared-migrations": "1.0.0",
"@aragon/cli": "^7.1.3",
"@aragon/minime": "^1.0.0",
"@aragon/contract-test-helpers": "^0.0.1",
"@aragon/contract-helpers-test": "^0.0.3",
"@aragon/staking": "^0.2.2",
"@aragon/truffle-config-v5": "^1.0.0",
"eth-gas-reporter": "^0.2.0",
"ethereumjs-testrpc-sc": "^6.5.1-sc.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/agreement/test/agreement/agreement_dispute.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { utf8ToHex, padLeft } = require('web3-utils')
const { assertBn } = require('../helpers/assert/assertBn')
const { bn, bigExp } = require('../helpers/lib/numbers')
const { assertRevert } = require('../helpers/assert/assertThrow')
const { getEventArgument } = require('@aragon/contract-test-helpers/events')
const { getEventArgument } = require('@aragon/contract-helpers-test/events')
const { decodeEventsOfType } = require('../helpers/lib/decodeEvent')
const { assertEvent, assertAmountOfEvents } = require('../helpers/assert/assertEvent')
const { AGREEMENT_ERRORS } = require('../helpers/utils/errors')
Expand Down
8 changes: 4 additions & 4 deletions apps/agreement/test/agreement/agreement_gas_cost.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ contract('Agreement', ([_, user]) => {
}

context('stake', () => {
itCostsAtMost(131e3, () => disputable.stake({ user }))
itCostsAtMost(207e3, () => disputable.stake({ user }))
})

context('unstake', () => {
beforeEach('stake', async () => {
await disputable.stake({ user })
})

itCostsAtMost(100e3, () => disputable.unstake({ user }))
itCostsAtMost(183e3, () => disputable.unstake({ user }))
})

context('newAction', () => {
itCostsAtMost(226e3, async () => (await disputable.newAction({})).receipt)
itCostsAtMost(266e3, async () => (await disputable.newAction({})).receipt)
})

context('closeAction', () => {
Expand Down Expand Up @@ -84,7 +84,7 @@ contract('Agreement', ([_, user]) => {
})

context('in favor of the challenger', () => {
itCostsAtMost(257e3, () => disputable.executeRuling({ actionId, ruling: RULINGS.IN_FAVOR_OF_CHALLENGER }))
itCostsAtMost(356e3, () => disputable.executeRuling({ actionId, ruling: RULINGS.IN_FAVOR_OF_CHALLENGER }))
})
})
})
Expand Down
8 changes: 6 additions & 2 deletions apps/agreement/test/agreement/agreement_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ contract('Agreement', ([_, challenger, holder0, holder1, holder2, holder3, holde
const returnedCollateralTotal = challengeCollateral.mul(bn(challengeSettledActions)).add(challengeCollateral.mul(bn(challengeRefusedActions)))

const expectedChallengerBalance = wonDisputesTotal.add(settledTotal).add(returnedCollateralTotal)
assertBn(await collateralToken.balanceOf(challenger), expectedChallengerBalance, 'challenger balance does not match')
const challengerBalance = await collateralToken.balanceOf(challenger)
const challengerTotalBalance = await disputable.getTotalAvailableBalance(challenger)
assertBn(challengerBalance, expectedChallengerBalance, 'challenger balance does not match')
assertBn(challengerTotalBalance, expectedChallengerBalance, 'challenger total balance does not match')
})

it('computes available stake balances properly', async () => {
Expand Down Expand Up @@ -169,7 +172,8 @@ contract('Agreement', ([_, challenger, holder0, holder1, holder2, holder3, holde

const staking = await disputable.getStaking()
const stakingBalance = await collateralToken.balanceOf(staking.address)
const expectedBalance = holder1Available.add(holder2Available).add(holder3Available).add(holder4Available).add(holder5Available)
const challengerAvailable = (await disputable.getBalance(challenger)).available
const expectedBalance = holder1Available.add(holder2Available).add(holder3Available).add(holder4Available).add(holder5Available).add(challengerAvailable)
assertBn(stakingBalance, expectedBalance, 'agreement staked balance does not match')
})

Expand Down
Loading

0 comments on commit b378a20

Please sign in to comment.