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

Add EpochRewards smart contract to calculate epoch rewards and payments #1558

Merged
merged 172 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 166 commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
02f39db
Most things that don't touch incentives
Sep 19, 2019
0f226c8
Trying to get things to compile
Sep 19, 2019
721b9da
More work
Sep 19, 2019
17a624e
More changes
Sep 19, 2019
6ce7f7e
Compiling
Sep 20, 2019
c19b8b6
Updated validators test
Sep 21, 2019
a6921d3
LockedGold tests passing
Sep 24, 2019
871d06d
Validators tests passing
Sep 24, 2019
e0e8cf7
Fix governance tests
Sep 24, 2019
223536d
Add election test file
Sep 24, 2019
651009d
Election tests passing
Sep 26, 2019
a795125
Fix governance test
Sep 30, 2019
9b4d431
Most e2e governance tests passing
Oct 1, 2019
e866ca7
end to end tests passing
Oct 2, 2019
3a31670
Point to celo-blockchain branch
Oct 2, 2019
3f35c70
Merge master
Oct 2, 2019
c466d78
Add some natspecs
Oct 2, 2019
f02b05a
Linting
Oct 2, 2019
70d7478
Small fix
Oct 2, 2019
69f6ab2
ContractKit building
Oct 3, 2019
15d2e8c
cli builds
Oct 3, 2019
d6ef3ec
Update oclif
Oct 3, 2019
615ec4f
Checkpoint
Oct 3, 2019
1bbf1e0
Merge master
Oct 3, 2019
3ff2fe4
CLI seems to be working
Oct 3, 2019
d3b83c8
cleanup
Oct 3, 2019
2887651
Fix
Oct 3, 2019
2d61f63
Fix
Oct 3, 2019
a427d46
Begin work on validator/group payments
Oct 4, 2019
47a247c
Added test for epoch payment distribution
Oct 4, 2019
767c651
Validator set changing again
Oct 5, 2019
7f82317
Epoch payments and rewards appear to be working
Oct 6, 2019
50d6029
Update membership history upon validator registration
Oct 6, 2019
999bca2
End to end tests passing
Oct 7, 2019
03dc663
Add epoch size precompile, among other things
Oct 8, 2019
055d50f
Merge master
Oct 8, 2019
b491453
Revert "Feature #909 proxy delegatecall (#1152)"
asaj Oct 8, 2019
9cccd70
Merge branch 'revert-1152-feature/909-proxy-delegatecall' into asaj/p…
Oct 8, 2019
96f7a7a
Governance end-to-end tests working again
Oct 8, 2019
e40eaf0
Address comments
Oct 8, 2019
2fd2f9d
Merge master
Oct 9, 2019
adcad0b
Fix linting issues
Oct 9, 2019
53e4977
Make things build, tests pass
Oct 9, 2019
c2ea8e1
Merge branch 'master' into asaj/pos
Oct 9, 2019
ed62a4d
Merge asaj/pos
Oct 9, 2019
a5aa266
Fix unit tests
Oct 9, 2019
115a457
Fix migration
Oct 9, 2019
884773b
Add addFirstMember function
Oct 9, 2019
b2858d0
Rework balance requirements
Oct 10, 2019
0492b15
Fix build issues in contractkit
Oct 10, 2019
c0c1f27
Merge master
Oct 10, 2019
3c8739c
Merge asaj/pos
Oct 10, 2019
264a7f5
Fix
Oct 10, 2019
99d3fcc
Remove registry from governance test
Oct 10, 2019
7d9c5cc
Fix linting issues
Oct 10, 2019
f15e844
Add missing cli doc
Oct 10, 2019
993339c
Governance end-to-end test passing
Oct 10, 2019
44f9a43
Fix migration
Oct 10, 2019
3f5c804
Merge branch 'master' into asaj/pos
Oct 10, 2019
1ca67ac
Merge asaj/pos
Oct 10, 2019
2abdd08
Merge branch 'master' into asaj/pos
Oct 10, 2019
f59ca01
Fix CLI build
Oct 10, 2019
00f8061
Add electabilityThreshold enforcement
Oct 10, 2019
aba8552
Don't pay out epoch payments unless validator and group meet balance …
Oct 10, 2019
16f476c
Don't pay out epoch rewards unless the group meets balance requirements
Oct 10, 2019
3616cc6
Fix migrations
Oct 10, 2019
64016a7
Beef up documentation
Oct 11, 2019
6ffdd36
Merge branch 'master' into asaj/pos
Oct 11, 2019
b494b87
Merge branch 'master' into asaj/pos-2
Oct 11, 2019
67966e0
Merge asaj/pos
Oct 11, 2019
fb5e8b4
Fix linting issues
Oct 11, 2019
449e1ed
Add documentation
Oct 11, 2019
143a69c
Fix interface
Oct 11, 2019
1f18108
Expire previously upvoted proposals
Oct 11, 2019
506a77b
Address comments
Oct 11, 2019
23054fc
Merge branch 'master' into asaj/pos
Oct 11, 2019
0e207d0
Point to asaj/pos-2
Oct 11, 2019
90e8b58
Address comments
Oct 14, 2019
32557cf
Merge master
Oct 14, 2019
610cfe3
Base group locked gold requirement on number of members
Oct 16, 2019
b8e1797
Address comments
Oct 16, 2019
631894a
Merge master
Oct 16, 2019
4a4d6e2
Address comments
Oct 16, 2019
1d36857
Merge branch 'master' into asaj/pos
Oct 16, 2019
f3515ac
Fix tests, linting
Oct 16, 2019
c697213
Merge branch 'master' into asaj/pos
Oct 16, 2019
9aa6ec3
Remove bondeddeposits test
Oct 16, 2019
ed8e5a0
Merge branch 'master' into asaj/pos
Oct 16, 2019
89364ab
Fix test
Oct 16, 2019
98d8feb
Merge branch 'master' into asaj/pos
Oct 16, 2019
d85fc78
Merge asaj/pos
Oct 16, 2019
4faaf75
Merge master
Oct 16, 2019
931ceba
Address comments; remove url and authorizedBy.active, allow for varia…
Oct 18, 2019
92e254e
Fix build
Oct 18, 2019
a288e2b
Merge master
Oct 18, 2019
d9c2cc0
Fix migrations, end-to-end tests
Oct 18, 2019
0b894ac
Fix tests
Oct 18, 2019
44aa9f9
Update CLI docs
Oct 18, 2019
262c002
Fix end-to-end transfer tests
Oct 18, 2019
7346fa8
Merge branch 'master' into asaj/pos-2
Oct 18, 2019
97372e7
Fix contractkit tests
Oct 18, 2019
15ace64
Merge master
Oct 22, 2019
c6b2656
merge master
Oct 22, 2019
ef71139
Fix contractkit tests
Oct 22, 2019
c152286
Merge branch 'asaj/pos-2' into asaj/pos-3
Oct 22, 2019
b8eafd7
Fix
Oct 22, 2019
3847bef
Cleanup
Oct 22, 2019
ae1be93
Fix circle config
Oct 22, 2019
2b1da94
Contract unit tests passing
Oct 22, 2019
19488c7
Re-add isVoting tests
Oct 22, 2019
e3e3809
Small cleanup
Oct 22, 2019
fb7c235
Merge branch 'master' into asaj/pos-2
Oct 22, 2019
e39ff0a
Clean up election setters
Oct 23, 2019
1eb0e40
Merge branch 'master' into asaj/pos-2
Oct 23, 2019
5a43d3f
Add first pass at epoch rewards
Oct 23, 2019
035e7e2
Merge master
Oct 24, 2019
44d6f51
Fix contractkit test
Oct 24, 2019
aaf02cd
Remove outdated comment
Oct 24, 2019
ec88d47
More work
Oct 24, 2019
5e2ec52
Merge branch 'asaj/pos-2' into asaj/pos-3
Oct 24, 2019
7e60132
Merge master
Oct 24, 2019
a6c9bb6
Merge branch 'master' into asaj/pos-3
Oct 25, 2019
59dedea
Fix Validators contract wrapper
Oct 25, 2019
7c25aed
Merge branch 'master' into asaj/pos-3
Oct 30, 2019
172c7ec
Merge branch 'asaj/pos-3' into asaj/pos-4
Oct 30, 2019
367429d
Unit tests for EpochRewards passing
Oct 31, 2019
6fa6ee1
Merge master
Oct 31, 2019
9281b4c
Make precompile public
Oct 31, 2019
15c928e
Merge branch 'master' into asaj/pos-3
Oct 31, 2019
95c77d9
Fix migrations
Oct 31, 2019
4c609ec
Merge branch 'asaj/pos-3' into asaj/pos-4
Oct 31, 2019
e2eec9b
end-to-end tests passing, not accounting for voting yield and multiplier
Nov 1, 2019
c561862
Merge master
Nov 1, 2019
2bc75cc
Fix typo
Nov 1, 2019
72ff0ba
end-to-end tests adjusted for rewards multiplier
Nov 1, 2019
568659c
end-to-end tests working
Nov 1, 2019
6316dde
merge master
Nov 1, 2019
a871d67
Fix merge conflicts
Nov 1, 2019
fc95abc
Merge branch 'master' into asaj/pos-3
Nov 2, 2019
9163be1
Merge asaj/pos-3
Nov 2, 2019
b4638d5
Fix linting
Nov 2, 2019
9fe10d7
Add natspecs
Nov 2, 2019
990fc14
reduce gold requirement for contractkit tests
Nov 2, 2019
5d910c9
Be sure to migrate random contract in validator order end-to-end tests
Nov 2, 2019
9d28444
Merge branch 'asaj/pos-3' into asaj/pos-4
Nov 2, 2019
6bc0a1d
Merge master
Nov 2, 2019
e4a9c0b
Small cleanup
Nov 4, 2019
896b08c
Merge branch 'master' into asaj/pos-4
Nov 7, 2019
e51e20d
Update packages/protocol/contracts/governance/EpochRewards.sol
Nov 7, 2019
8d831ec
Update packages/protocol/contracts/governance/EpochRewards.sol
Nov 7, 2019
9ee4f02
Address comments
Nov 7, 2019
464ec62
Address comments
Nov 7, 2019
231eed1
Merge master
Nov 9, 2019
531e319
Address comments
Nov 9, 2019
5af2e3b
Fix tests
Nov 9, 2019
bec525b
Fix tests
Nov 9, 2019
e3f7c88
Merge branch 'master' into asaj/pos-4
Nov 9, 2019
8afe7e5
Merge branch 'master' into asaj/pos-4
Nov 9, 2019
649f7a1
Merge branch 'master' into asaj/pos-4
Nov 10, 2019
cca1e4d
Merge branch 'asaj/pos-4' of https://github.com/celo-org/celo-monorep…
Nov 10, 2019
e8bc744
Update exchange tests
Nov 10, 2019
6364667
Fix tests
Nov 10, 2019
d8265aa
Fix reserve tests
Nov 10, 2019
11d120d
Fix end-to-end tests
Nov 10, 2019
0cc9273
Merge master
Nov 10, 2019
cf50693
Fix tests
Nov 10, 2019
93571b2
Merge branch 'master' into asaj/pos-4
Nov 11, 2019
6fb7a33
Address comments
Nov 11, 2019
2e17037
Whoops
Nov 11, 2019
23776ee
Fix epoch rewards tests
Nov 11, 2019
f280f3a
Update circleci config
Nov 12, 2019
50f5e59
Explicitly wait for a new epoch
Nov 12, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Blockchain parameters tests', function(this: any) {
let parameters: BlockchainParametersWrapper

const gethConfig: GethTestConfig = {
migrateTo: 17,
migrateTo: 18,
instances: [
{ name: 'validator', validating: true, syncmode: 'full', port: 30303, rpcport: 8545 },
],
Expand Down
137 changes: 121 additions & 16 deletions packages/celotool/src/e2e-tests/governance_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { fromFixed, toFixed } from '@celo/utils/lib/fixidity'
import BigNumber from 'bignumber.js'
import { assert } from 'chai'
import Web3 from 'web3'
import { getContext, getEnode, importGenesis, initAndStartGeth, sleep } from './utils'
import {
assertAlmostEqual,
getContext,
getEnode,
importGenesis,
initAndStartGeth,
sleep,
} from './utils'

describe('governance tests', () => {
const gethConfig = {
Expand All @@ -21,9 +28,12 @@ describe('governance tests', () => {
const context: any = getContext(gethConfig)
let web3: any
let election: any
let validators: any
let stableToken: any
let sortedOracles: any
let epochRewards: any
let goldToken: any
let registry: any
let validators: any
let accounts: AccountsWrapper
let kit: ContractKit

Expand All @@ -39,9 +49,12 @@ describe('governance tests', () => {
web3 = new Web3('http://localhost:8545')
kit = newKitFromWeb3(web3)
goldToken = await kit._web3Contracts.getGoldToken()
stableToken = await kit._web3Contracts.getStableToken()
sortedOracles = await kit._web3Contracts.getSortedOracles()
validators = await kit._web3Contracts.getValidators()
registry = await kit._web3Contracts.getRegistry()
election = await kit._web3Contracts.getElection()
epochRewards = await kit._web3Contracts.getEpochRewards()
accounts = await kit.contracts.getAccounts()
}

Expand Down Expand Up @@ -278,10 +291,9 @@ describe('governance tests', () => {
})

it('should distribute epoch payments at the end of each epoch', async () => {
const stableToken = await kit._web3Contracts.getStableToken()
const commission = 0.1
const validatorEpochPayment = new BigNumber(
await validators.methods.validatorEpochPayment().call()
const targetValidatorEpochPayment = new BigNumber(
await epochRewards.methods.targetValidatorEpochPayment().call()
)
const [group] = await validators.methods.getRegisteredValidatorGroups().call()

Expand All @@ -298,7 +310,7 @@ describe('governance tests', () => {
)
assert.isNotNaN(currentBalance)
assert.isNotNaN(previousBalance)
assert.equal(expected.toFixed(), currentBalance.minus(previousBalance).toFixed())
assertAlmostEqual(currentBalance.minus(previousBalance), expected)
}

const assertBalanceUnchanged = async (validator: string, blockNumber: number) => {
Expand All @@ -310,7 +322,14 @@ describe('governance tests', () => {
(await validators.methods.getValidator(validator).call({}, blockNumber))[2]
)
assert.isNotNaN(score)
return validatorEpochPayment.times(fromFixed(score))
// We need to calculate the rewards multiplier for the previous block, before
// the rewards actually are awarded.
const rewardsMultiplier = new BigNumber(
await epochRewards.methods.getRewardsMultiplier().call({}, blockNumber - 1)
)
return targetValidatorEpochPayment
.times(fromFixed(score))
.times(fromFixed(rewardsMultiplier))
}

for (const blockNumber of blockNumbers) {
Expand Down Expand Up @@ -346,8 +365,6 @@ describe('governance tests', () => {
it('should distribute epoch rewards at the end of each epoch', async () => {
const lockedGold = await kit._web3Contracts.getLockedGold()
const governance = await kit._web3Contracts.getGovernance()
const epochReward = new BigNumber(10).pow(18)
const infraReward = new BigNumber(10).pow(18)
const [group] = await validators.methods.getRegisteredValidatorGroups().call()

const assertVotesChanged = async (blockNumber: number, expected: BigNumber) => {
Expand All @@ -357,7 +374,7 @@ describe('governance tests', () => {
const previousVotes = new BigNumber(
await election.methods.getTotalVotesForGroup(group).call({}, blockNumber - 1)
)
assert.equal(expected.toFixed(), currentVotes.minus(previousVotes).toFixed())
assertAlmostEqual(currentVotes.minus(previousVotes), expected)
}

const assertGoldTokenTotalSupplyChanged = async (
Expand All @@ -370,7 +387,7 @@ describe('governance tests', () => {
const previousSupply = new BigNumber(
await goldToken.methods.totalSupply().call({}, blockNumber - 1)
)
assert.equal(expected.toFixed(), currentSupply.minus(previousSupply).toFixed())
assertAlmostEqual(currentSupply.minus(previousSupply), expected)
}

const assertBalanceChanged = async (
Expand All @@ -384,7 +401,7 @@ describe('governance tests', () => {
const previousBalance = new BigNumber(
await goldToken.methods.balanceOf(address).call({}, blockNumber - 1)
)
assert.equal(expected.toFixed(), currentBalance.minus(previousBalance).toFixed())
assertAlmostEqual(currentBalance.minus(previousBalance), expected)
}

const assertLockedGoldBalanceChanged = async (blockNumber: number, expected: BigNumber) => {
Expand All @@ -411,12 +428,52 @@ describe('governance tests', () => {
await assertGovernanceBalanceChanged(blockNumber, new BigNumber(0))
}

const getStableTokenSupplyChange = async (blockNumber: number) => {
const currentSupply = new BigNumber(
await stableToken.methods.totalSupply().call({}, blockNumber)
)
const previousSupply = new BigNumber(
await stableToken.methods.totalSupply().call({}, blockNumber - 1)
)
return currentSupply.minus(previousSupply)
}

const getStableTokenExchangeRate = async (blockNumber: number) => {
const rate = await sortedOracles.methods
.medianRate(stableToken.options.address)
.call({}, blockNumber)
return new BigNumber(rate[0]).div(rate[1])
}

for (const blockNumber of blockNumbers) {
if (isLastBlockOfEpoch(blockNumber, epoch)) {
await assertVotesChanged(blockNumber, epochReward)
await assertGoldTokenTotalSupplyChanged(blockNumber, epochReward.plus(infraReward))
await assertLockedGoldBalanceChanged(blockNumber, epochReward)
await assertGovernanceBalanceChanged(blockNumber, infraReward)
// We use the number of active votes from the previous block to calculate the expected
// epoch reward as the number of active votes for the current block will include the
// epoch reward.
const activeVotes = new BigNumber(
await election.methods.getActiveVotes().call({}, blockNumber - 1)
)
const targetVotingYield = new BigNumber(
(await epochRewards.methods.getTargetVotingYieldParameters().call({}, blockNumber))[0]
)
// We need to calculate the rewards multiplier for the previous block, before
// the rewards actually are awarded.
const rewardsMultiplier = new BigNumber(
await epochRewards.methods.getRewardsMultiplier().call({}, blockNumber - 1)
)
const expectedEpochReward = activeVotes
.times(fromFixed(targetVotingYield))
.times(fromFixed(rewardsMultiplier))
const expectedInfraReward = new BigNumber(10).pow(18)
const stableTokenSupplyChange = await getStableTokenSupplyChange(blockNumber)
const exchangeRate = await getStableTokenExchangeRate(blockNumber)
const expectedGoldTotalSupplyChange = expectedInfraReward
.plus(expectedEpochReward)
.plus(stableTokenSupplyChange.div(exchangeRate))
await assertVotesChanged(blockNumber, expectedEpochReward)
await assertLockedGoldBalanceChanged(blockNumber, expectedEpochReward)
await assertGovernanceBalanceChanged(blockNumber, expectedInfraReward)
await assertGoldTokenTotalSupplyChanged(blockNumber, expectedGoldTotalSupplyChange)
} else {
await assertVotesUnchanged(blockNumber)
await assertGoldTokenTotalSupplyUnchanged(blockNumber)
Expand All @@ -425,6 +482,54 @@ describe('governance tests', () => {
}
}
})

it('should update the target voting yield', async () => {
const assertTargetVotingYieldChanged = async (blockNumber: number, expected: BigNumber) => {
const currentTarget = new BigNumber(
(await epochRewards.methods.getTargetVotingYieldParameters().call({}, blockNumber))[0]
)
const previousTarget = new BigNumber(
(await epochRewards.methods.getTargetVotingYieldParameters().call({}, blockNumber - 1))[0]
)
const difference = currentTarget.minus(previousTarget)

// Assert equal to 10 decimal places due to rounding errors.
assert.equal(
fromFixed(difference)
.dp(10)
.toFixed(),
fromFixed(expected)
.dp(10)
.toFixed()
)
}

const assertTargetVotingYieldUnchanged = async (blockNumber: number) => {
await assertTargetVotingYieldChanged(blockNumber, new BigNumber(0))
}

for (const blockNumber of blockNumbers) {
if (isLastBlockOfEpoch(blockNumber, epoch)) {
// We use the voting gold fraction from before the rewards are granted.
const votingGoldFraction = new BigNumber(
await epochRewards.methods.getVotingGoldFraction().call({}, blockNumber - 1)
)
const targetVotingGoldFraction = new BigNumber(
await epochRewards.methods.getTargetVotingGoldFraction().call({}, blockNumber)
)
const difference = targetVotingGoldFraction.minus(votingGoldFraction)
const adjustmentFactor = fromFixed(
new BigNumber(
(await epochRewards.methods.getTargetVotingYieldParameters().call({}, blockNumber))[2]
)
)
const delta = difference.times(adjustmentFactor)
await assertTargetVotingYieldChanged(blockNumber, delta)
} else {
await assertTargetVotingYieldUnchanged(blockNumber)
}
}
})
})

describe('after the gold token smart contract is registered', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/e2e-tests/transfer_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('Transfer tests', function(this: any) {

const syncModes = ['full', 'fast', 'light', 'ultralight']
const gethConfig: GethTestConfig = {
migrateTo: 17,
migrateTo: 18,
instances: [
{ name: 'validator', validating: true, syncmode: 'full', port: 30303, rpcport: 8545 },
],
Expand Down
17 changes: 17 additions & 0 deletions packages/celotool/src/e2e-tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BigNumber from 'bignumber.js'
import { assert } from 'chai'
import { spawn, SpawnOptions } from 'child_process'
import fs from 'fs'
Expand Down Expand Up @@ -40,6 +41,22 @@ const GENESIS_PATH = `${TEST_DIR}/genesis.json`
const NetworkId = 1101
const MonorepoRoot = resolvePath(joinPath(__dirname, '../..', '../..'))

export function assertAlmostEqual(
actual: BigNumber,
expected: BigNumber,
delta: BigNumber = new BigNumber(10).pow(12).times(5)
) {
if (expected.isZero()) {
assert.equal(actual.toFixed(), expected.toFixed())
} else {
const isCloseTo = actual.plus(delta).gte(expected) || actual.minus(delta).lte(expected)
assert(
isCloseTo,
`expected ${actual.toString()} to almost equal ${expected.toString()} +/- ${delta.toString()}`
)
}
}

export function spawnWithLog(cmd: string, args: string[], logsFilepath: string) {
try {
fs.unlinkSync(logsFilepath)
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/e2e-tests/validator_order_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const BLOCK_COUNT = EPOCH * EPOCHS_TO_WAIT

describe('governance tests', () => {
const gethConfig: GethTestConfig = {
migrateTo: 14,
migrateTo: 15,
instances: _.range(VALIDATORS).map((i) => ({
name: `validator${i}`,
validating: true,
Expand Down
1 change: 1 addition & 0 deletions packages/contractkit/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum CeloContract {
Attestations = 'Attestations',
BlockchainParameters = 'BlockchainParameters',
Election = 'Election',
EpochRewards = 'EpochRewards',
Escrow = 'Escrow',
Exchange = 'Exchange',
GasCurrencyWhitelist = 'GasCurrencyWhitelist',
Expand Down
6 changes: 6 additions & 0 deletions packages/contractkit/src/contract-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AccountsWrapper } from './wrappers/Accounts'
import { AttestationsWrapper } from './wrappers/Attestations'
import { BlockchainParametersWrapper } from './wrappers/BlockchainParameters'
import { ElectionWrapper } from './wrappers/Election'
// import { EpochRewardsWrapper } from './wrappers/EpochRewards'
m-chrzan marked this conversation as resolved.
Show resolved Hide resolved
import { EscrowWrapper } from './wrappers/Escrow'
import { ExchangeWrapper } from './wrappers/Exchange'
import { GasPriceMinimumWrapper } from './wrappers/GasPriceMinimum'
Expand All @@ -20,6 +21,7 @@ const WrapperFactories = {
[CeloContract.Attestations]: AttestationsWrapper,
[CeloContract.BlockchainParameters]: BlockchainParametersWrapper,
[CeloContract.Election]: ElectionWrapper,
// [CeloContract.EpochRewards]?: EpochRewardsWrapper,
[CeloContract.Escrow]: EscrowWrapper,
[CeloContract.Exchange]: ExchangeWrapper,
// [CeloContract.GasCurrencyWhitelist]: GasCurrencyWhitelistWrapper,
Expand All @@ -44,6 +46,7 @@ interface WrapperCacheMap {
[CeloContract.Attestations]?: AttestationsWrapper
[CeloContract.BlockchainParameters]?: BlockchainParametersWrapper
[CeloContract.Election]?: ElectionWrapper
// [CeloContract.EpochRewards]?: EpochRewardsWrapper
[CeloContract.Escrow]?: EscrowWrapper
[CeloContract.Exchange]?: ExchangeWrapper
// [CeloContract.GasCurrencyWhitelist]?: GasCurrencyWhitelistWrapper,
Expand Down Expand Up @@ -83,6 +86,9 @@ export class WrapperCache {
getElection() {
return this.getContract(CeloContract.Election)
}
// getEpochRewards() {
// return this.getContract(CeloContract.EpochRewards)
// }
getEscrow() {
return this.getContract(CeloContract.Escrow)
}
Expand Down
5 changes: 5 additions & 0 deletions packages/contractkit/src/web3-contract-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { newAccounts } from './generated/Accounts'
import { newAttestations } from './generated/Attestations'
import { newBlockchainParameters } from './generated/BlockchainParameters'
import { newElection } from './generated/Election'
import { newEpochRewards } from './generated/EpochRewards'
import { newEscrow } from './generated/Escrow'
import { newExchange } from './generated/Exchange'
import { newGasCurrencyWhitelist } from './generated/GasCurrencyWhitelist'
Expand All @@ -26,6 +27,7 @@ const ContractFactories = {
[CeloContract.Attestations]: newAttestations,
[CeloContract.BlockchainParameters]: newBlockchainParameters,
[CeloContract.Election]: newElection,
[CeloContract.EpochRewards]: newEpochRewards,
[CeloContract.Escrow]: newEscrow,
[CeloContract.Exchange]: newExchange,
[CeloContract.GasCurrencyWhitelist]: newGasCurrencyWhitelist,
Expand Down Expand Up @@ -68,6 +70,9 @@ export class Web3ContractCache {
getElection() {
return this.getContract(CeloContract.Election)
}
getEpochRewards() {
return this.getContract(CeloContract.EpochRewards)
}
getEscrow() {
return this.getContract(CeloContract.Escrow)
}
Expand Down
5 changes: 5 additions & 0 deletions packages/protocol/contracts/common/UsingRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "../governance/interfaces/IValidators.sol";

import "../identity/interfaces/IRandom.sol";

import "../stability/interfaces/ISortedOracles.sol";
import "../stability/interfaces/IStableToken.sol";

// Ideally, UsingRegistry should inherit from Initializable and implement initialize() which calls
Expand Down Expand Up @@ -81,6 +82,10 @@ contract UsingRegistry is Ownable {
return IRandom(registry.getAddressForOrDie(RANDOM_REGISTRY_ID));
}

function getSortedOracles() internal view returns (ISortedOracles) {
return ISortedOracles(registry.getAddressForOrDie(SORTED_ORACLES_REGISTRY_ID));
}

function getStableToken() internal view returns (IStableToken) {
return IStableToken(registry.getAddressForOrDie(STABLE_TOKEN_REGISTRY_ID));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ pragma solidity ^0.5.3;
*/
contract MockGoldToken {
uint8 public constant decimals = 18;
uint256 public totalSupply;

function setTotalSupply(uint256 value) external {
totalSupply = value;
}

function transfer(address, uint256) external pure returns (bool) {
return true;
Expand Down
8 changes: 8 additions & 0 deletions packages/protocol/contracts/governance/Election.sol
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,14 @@ contract Election is
return votes.active.total.add(votes.pending.total);
}

/**
* @notice Returns the active votes received across all groups.
* @return The active votes received across all groups.
*/
function getActiveVotes() public view returns (uint256) {
return votes.active.total;
}

/**
* @notice Returns the list of validator groups eligible to elect validators.
* @return The list of validator groups eligible to elect validators.
Expand Down
Loading