Skip to content

Commit

Permalink
Gov V3 fixes and nice to haves (#2242)
Browse files Browse the repository at this point in the history
* update version to 2.0.0-alpha.0

* fix default epoch start date

* refactor DebtShare tests location

* fix first epoch index initialization

* fix getting of snapshot id before the array is initialized

* update assertEvent usage

* fix merkle tree getter

* fix debtshare initialization

* fix CouncilToken proxy usage

* fix CouncilToken proxy usage

* fix tests

* fix settings initialization

* remove unnecessary check

* revert xchain-pools changes

* revert unneeded changes

* Fix governance epoch settings storage (#1722)

* fix coeverage filter

* refactor proxy deployment on tests

* fix core-utils tests

* Fix deps

* Ignore and work around subgraph AssemblyScrypt in depcheck

* Fix epoch schedule tweak & next election settings update (#1725)

* add epoch schedule tests

* fix initialization dates

* fix arrow fn usage

* add BaseElectionModule tests

* refactor tests location

* add schedule getter

* remove defaultBallotEvaluationBatchSize setting

* remove individual settings getters

* add Administration check

* add tweakEpochSchedule outside tolerance tests

* add tweakEpochSchedule happy path tests

* add period validations

* add test case for maxDateAdjustmentTolerance bypass

* add epoch duration validation

* fix lint

* fix lint

* rename settings names

* remove modifyEpochSchedule fn

* add single next election settings setter

* refactor ElectionSettingsManger

* fix snapshot usage

* fix tests

* fix settings initialization

* add set settings tests

* fix lint issues

* fix schedule calculations from settings

* add validations for not being able to nullify elections periods

* add _MIN_ELECTION_PERIOD_DURATION comments

* add maxDateAdjustmentTolerance to initialization

* fix comments

* fix ethers dependency

* fix lint

* restore testable router

* fix repetition in cannonfile.test.toml

* Xchain voting (#1728)

* add UpgradeProposalModule (#1726)

* Add missing modifiers

* disable elections flow tests

* bit of a refactor for how ballots are counted (#1734)

try to simplify the flow, make it easier to identify votes through a "snapshot record" which is an interface that can declare voting power and have snapshot taken. This can work with v3 through the use of a rewards distributor (one that doesn't actually distribute rewards)

* fix cannonfile build

* fix a couple tests

* remove unused assert

* Snapshot vote power tests (#1749)

* initial building of the tests and fixing of the cannonfile

* implement majority of tests for SnapshotRecord

* fix bugs in the recent tests

* most changes in

* fix lint issues

---------

Co-authored-by: Matías <[email protected]>

* revert crosschain storage layout. treat the first chain ID in the supported chains list as the mothership

* fix tests generation (#1770)

* Add Owner Guardianship (#1732)

* add owner guardian contracts

* fix ownershipRequestedAt usage

* refactor CrossChain into core-modules (#1756)

* refactor CrossChain into core-modules

* fix tests

* fix comment

* fix ccip tests

* fix OwnerModule compilation

* Rename lastElectionId -> currentElectionId (#1780)

* rename lastElectionId to currentElectionId

* fix testable storage generation

* Remove unnecessary ProxyStorage inheritance

* Governance Initialization Fixes (#1781)

* remove epochSeatCount param on initialization

* update initializer

* fix initial parameters

* fix initialization dates calculation

* fix calculation of days

* fix tests

* update usage of imports

* fix lint warning

* Remove guardianship & delayed upgrade functionalities (#1801)

* remove guardianship & delayed upgrade functionalities

* update storage dump

* Add satellites NFT distribution (#1787)

* refactor crosschain helper fns

* add nominate during nomination period also

* rename precint to chainId

* add nft distribution on satellites

* remove BaseElectionModule in favor of a single ElectionModule (#1826)

* remove BaseElectionModule in favor of a single ElectionModule

This can be done just by allowing to set the ballot size on ElectionModule

* fix configs lint

* fix cannonfiles

* fix synthetix test cannonfile

* add CrossChain module to gov cannonfile

* add base ElectionModuleSatellite file

* add election module satellite

* refactor cannonfiles

* add members dismissal logic

* add CCIP epoch resolution

* remove unnecessary chain number validator

* refactor council members storage

* fix usage of council members storage

* add satellite council module initialization

* fix AddressSet usage

* fix cannonfiles dependencies

* fix satellite cannonfile build

* added sepolina support

* using getter function

* Refactor ccip config to extract core settings (#1853)

* refactor ccip config to extract core settings

* update storage dumps

* fixed typo

* removed unused settings

* make cast func payable

* support crosschain voting

* update gov satellite cannonfile package name

* refactor cannonfile settings

* add cross chain address target setting on initialization

* remove depends on cannonfiles

* fix test cannonfile version

* fix ccip config

* fix msg.sender usage

* refactor satellite init

* add base for cross chain integration tests

* add ccip router

* add multiple chains connections

* add ccip router mock to gov tests

* add cross chain typechain types

* add ccip interaction

* fix nodes interaction

* fix wallet fixture

* fix dedupe

* add snapshots module to satellite

* Gov intergration test (#1873)

* test: gov v2 integration test

* push for mati

* fix cross chain calls

* fix ccipReceive mock

* fix router mock call context

* fixing func

* fixing tests

* cleaning up

---------

Co-authored-by: Peiman <[email protected]>
Co-authored-by: Matías <[email protected]>

* updated the bootstrap function

* refactor epoch storage

* fix tests

* add votingPower calculation on satellite networks

* add epoch initialization on satellites

* add epoch initialization on satellites

* Gov 2 integration (#1876)

* Remove unused supportedNetworkTargets config (#1877)

* remove unused supportedNetworkTargets config

* remove unused dependency

* fix unused deps

* refactor cannon subprocesses to be in the same process

* fix tests

* update cannon file

* Fix inifinite amount of votes (#1878)

* fix usage of ballot indexes

* remove unnecessary removal of item from set

* Old election test (#1881)

* old test

* update tests

* updating tests

* updated test

* updated eval

* refactor integration tests bootstrap

---------

Co-authored-by: Matías <[email protected]>
Co-authored-by: Peiman <[email protected]>

* fix yarn.lock

* add missing @foundry-rs/hardhat-anvil dep

* fix test period helpers

* fix cc voting tests in different steps

* Fix mothership votes casting (#1916)

* fix mothership votes casting

* fix usage of voter

* fix test cannonfile default config

* add epoch update to satellites (#1917)

* add epoch update to satellites

* fix crosschain revert parsing

* fix cast vote unit tests

* added tests

* fix payable functions

* moved validation

* Fix snapshot contract management (#1920)

* fix snapshot contract management

* fix check of disabled snapshot contract

* ccip event (#1923)

* push

* fix events parsing

* fixing test

* remove error try catch

* added type import

---------

Co-authored-by: Matías <[email protected]>

* remove possibility of gov nft transfers (#1924)

* add epoch index validation on vote casting (#1925)

* add refundLeftoverGas call on broadcast (#1926)

* Fix small issues (#1927)

* fix typo n1

* remove unused private _getCouncilToken fn

* fix consistency on dates usage

* refactor election module init

* unify test scripts

* Iosiro val candidate (#1929)

* implemented feedback

* remove console.log

* update voting period duration

* Refactor council tokenid (#1930)

* refactor council token id generation

* update storage dump

* add multi chain dev task

* add cross chain message listener

* fix cross chain signer param

* updated dev comnand

* added candidates to event

* add dummy withdrawVote fn

* removed only

* remove loop

* add trusted_multicall_forwarder to cannonfile

* fix setting location

* add presets to cannonfiles

* remove changes to protocol/synthetix

* update yarn.lock

* update storage.dump.sol

* fix package.json

* update hardhat-cannon to 2.10.8-alpha.1

* bump to 3.0.0-rc.0

* rename satellite package

* add cannonfile for snapshot record mock

* add create2 and salt to snapshot record

* bump governance to 3.0.0

* fix snapshot id incorrectly resolved when starting new election (#1986)

* Update mintable token extraction function to work with new incompatible version of the constructor (#1982)

* Update mintable token extraction function to work with new incompatible version of the constructor

* Add Sepolia

* Reduce wording for mintable token name

* fix snapshot id incorrectly resolved when starting new election

should be using snapshot id prior to the `takeSnapshot` otherwise
addresses will be able to change their voting power during hte election,
which defeats the whole point.

the tests were also incorrect

* Move ABIs generation to deployments repo (#1987)

* fixing ci

* dedupe

---------

Co-authored-by: Noisekit <[email protected]>
Co-authored-by: max <[email protected]>

* update yarn.lock

* add highlight to proxies

* remove CouncilToken interface from governance CoreProxy

* update election module satellite init

* added error

* bump gov to 3.0.1

* update comments

* fix test

* fix tests

* bump gov to 3.0.2

* update satellite cannonfile init

* fix satellite tests init

* fix satellite default values

* rename governance's proxy from CoreProxy to GovernanceProxy (#1990)

* SIP-360: Wormhole Cross Chain Integration (#2172)

* wormhole cross chain

* removed wormhole unused sdk

* typo on git ignore file

* removing unused files

* removed unnecessary file

* yarn install state ignore

* removed install state from git diff

* removed change to git ignore

* deleted old cross chain files

* removed old todo

* some solhint fixes

* trying to fix linter lol

* deleted unused file

* some code cleanup prior to review

* reset some files to main

* reset yarn.lock

* update yarn.lock

* update yarn.lock

* yarn dedupe

* fix added old contracts

* fix cannon dependencies

* fix tests to be compatible with latest cannon

* update cannon to 2.15.2

* fix events parsing

* fix chainId

* fixed chain id problems

* undo storage dump change

* undo utils hardhat config  change

* prettier *

* prettier .sol

* fix linter

* Fix deps

* fix some lint issues

* fixed gov tests

* solhint fixed errors, not warnings

* fix dev script

* Remove governance ccip (#2182)

* fix node export

* fixed cannonfiles

* fixed cannonfiles

* fixed tests

* sending cost to relayer

* remove last ccip references on governance

* remove --wipe on dev task

* refactor mothership chain id usage

* remove Election.resolved variable

* added some comments

* some more ccip cleanup

* receiveWormholeMessages

* interim changes

* fixed test relayer addresses

* fixed js lint error

* rewrite settings on root cannonfiles

* add temp testnet cannonfiles

* passing 0 for receiver value instead of msg.value when calling transmit

* update testnet cannonfiles setup

* update deployer

* update testnet deployment to base sepolia

* update testnet salt

* Moss audit fixes (#2190)

* ez fixes

* more fixes but tests breaking

* added broadcast

* added refund amount

* receiveWormholeMessages fix

* test changes

* linting

* remove unused ElectionVase file

* fixed tests

* lint

* add base for testing council members

* added refund test

* add dismisal members tests

* lint

* removed todos in gov contracts

* refactor cross chain initialization (#2194)

* fix lint

* fix lint errors

* pushing new cannonfiles

* getSupportedNetworks

* bump gov to 3.0.4

* update testnets salt

* update owners

* fix testnet cannonfiles

* fix testnet cannonfiles

* added view fns and some events

* fixed _recMessage

* fixed _recMessage

* updated cannon files

* lint

* @with-synthetix preset

* moved gas limit

* fixed salts

* reset cannon

* added gas limit to cannon files

* updated cannon files

* remove unused SetUtil import

* updated cannonfiles

* Migrate snapshot rewards distributor (#2206)

* migrate SnapshotRewardsDistributor

from https://github.com/Synthetixio/rewards-distributors

* rewards distributor fixes

---------

Co-authored-by: Moss <[email protected]>

* lint

* added view fn

* Add voting power weight configuration (#2207)

* poc for voting power algorithms

* add voting power calculation

* update implementation interface

---------

Co-authored-by: Moss <[email protected]>

* updated weight types

* added tests

* removed send msg

* getGasLimit

* natspec'd election module contracts

* added base cannonfile

* audit fixes

* added test confirming remove emitter works

* lint

* Audit fixes for SnapshotRewardsDistributor (#2220)

* update DebtShareNotFound error for AccountNorFound

* fix account balance idx reference

* deleting todos and added test

* update synthetix-snapshot-rewards version

* fix default values

* pushing version

* audit fixes

* audit fixes 2

* lint

---------

Co-authored-by: Matías <[email protected]>
Co-authored-by: Matías <[email protected]>

* fix

* added unit test and deleted cannon files

* cannonnfiles and updated snaxchain chain ids

* updated snax cannonfile

* saving work

* Bump cannon versions to latest (#2225)

* Bump cannon versions to latest

* remove unsupported toml param

* fix typo

* attempt to fix assert-revert after upgrading deps

* add contract reference in assert test

* Fix type imports

* Update typescript

* Update cannon to 2.16.3 to fix ts build

---------

Co-authored-by: Noisekit <[email protected]>

* Bfp permissions (#2140)

* Add and use permission for pay debt & split account

* Update storage dump

* Add new perms to `isPermissionValid`

* Prefix bfp permissions

* Add test for when trying to split account with different owner/signers

* Fix flakey tests

---------

Co-authored-by: 0xMithrandir <[email protected]>

* Revert if reducing order makes position liquidatable (#2210)

* Revert is order makes position liquidatable when reducing

* Reuse the logic for fill premium for mm check

* Update storage

* Fix flakey tests

* Foundry caching (#2228)

* Compile foundry only once

* Only cache forge/bin

* Bump nodejs to 20.16.0

* Avoid recursive compilation

* Weekly cannon cache to speed up build-testable

* Cannon cache for non-testable hardhat build, separate cache for testable and non-testable cannon

* Separate storage verification without cannon build (#2230)

* Separate storage verification without cannon build

* Always update cannon cache

* Add minDelegateTime in BFP createMarket (#2227)

* Add minDelegateTime in createMarket

* Add comment on minDelegateTime

Co-authored-by: David Vuong <[email protected]>

* Add a setter function for minDelegateTime

* Update utilization test

---------

Co-authored-by: David Vuong <[email protected]>

* fix: add OwnableStorage.onlyOwner and tests setMinDelegationTime (#2232)

* Fix flakey order test (#2229)

Co-authored-by: David Vuong <[email protected]>

* Add missing generate-testable (#2231)

* Add missing generate-testable

* Add missing storage dump

* ability to change token names from within synthetix core proxy

for example we want to be able to change the symbol of the synthetix usd
token

* Revert "ability to change token names from within synthetix core proxy"

This reverts commit db43572.

* ability to change token names from within synthetix core proxy (#2235)

* ability to change token names from within synthetix core proxy

for example we want to be able to change the symbol of the synthetix usd
token

* Update cannonfile.toml

* Update USDTokenModule.test.ts

* Docgen contracts (#2236)

* Remove perps docs from git

* Add missing docs to the generator and fix generation for new packages

* Deps

* Append docs

* update

* changed to clone

* test cannon files

* fix

* some fixes

* removed extraneous cannonfiles

* added view fn

* added view fns to satellite

* accidental param move

* natspec

* added nomination period to tweakepochschedule

---------

Co-authored-by: Matías <[email protected]>
Co-authored-by: meb <[email protected]>
Co-authored-by: Matías Lescano <[email protected]>
Co-authored-by: Noisekit <[email protected]>
Co-authored-by: dbeal <[email protected]>
Co-authored-by: Daniel Beal <[email protected]>
Co-authored-by: max <[email protected]>
Co-authored-by: max <[email protected]>
Co-authored-by: Peiman <[email protected]>
Co-authored-by: Peiman <[email protected]>
Co-authored-by: Noisekit <[email protected]>
Co-authored-by: MrX-SNX <[email protected]>
Co-authored-by: Leonardo Massazza <[email protected]>
Co-authored-by: Joey <[email protected]>
Co-authored-by: 0xMithrandir <[email protected]>
Co-authored-by: Noisekit <[email protected]>
Co-authored-by: David Vuong <[email protected]>
  • Loading branch information
18 people authored Sep 3, 2024
1 parent 8c84e03 commit 09b8614
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 61 deletions.
4 changes: 2 additions & 2 deletions protocol/governance/cannonfile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ defaultValue = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
defaultValue = "governance"

[setting.wormhole_core]
defaultValue = "0x98f3c9e6E3fAce36bAAd05FE09d375Ef1464288B" # mainnet ethereum https://docs.wormhole.com/wormhole/reference/constants
defaultValue = "0xc1BA3CC4bFE724A08FbbFbF64F8db196738665f4" # snaxchain https://explorer.snaxchain.io/address/0xc1BA3CC4bFE724A08FbbFbF64F8db196738665f4

[setting.wormhole_relayer]
defaultValue = "0x27428DD2d3DD32A4D7f7C497eAaa23130d894911" # mainnet ethereum https://docs.wormhole.com/wormhole/reference/constants
defaultValue = "0x27428DD2d3DD32A4D7f7C497eAaa23130d894911" # snaxchain https://explorer.snaxchain.io/address/0x27428DD2d3DD32A4D7f7C497eAaa23130d894911

[setting.initial_council_member]
defaultValue = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
Expand Down
21 changes: 3 additions & 18 deletions protocol/governance/contracts/interfaces/IElectionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,6 @@ interface IElectionModule is IElectionModuleSatellite {
// View functions
// ---------------------------------------

/// @notice Shows the current epoch schedule dates
function getEpochSchedule() external view returns (Epoch.Data memory epoch);

/// @notice Shows the settings for the current election
function getElectionSettings() external view returns (ElectionSettings.Data memory settings);

/// @notice Shows the settings for the next election
function getNextElectionSettings()
external
view
returns (ElectionSettings.Data memory settings);

/// @notice Returns the index of the current epoch. The first epoch's index is 1
function getEpochIndex() external view returns (uint256);

/// @notice Returns the current period type: Administration, Nomination, Voting, Evaluation
function getCurrentPeriod() external view returns (uint256);

/// @notice Shows if a candidate has been nominated in the current epoch
function isNominated(address candidate) external view returns (bool);

Expand Down Expand Up @@ -188,6 +170,9 @@ interface IElectionModule is IElectionModuleSatellite {
uint256 electionId
) external pure returns (Ballot.Data memory);

/// @notice Returns the number of ballots in the current election
function getNumOfBallots() external view returns (uint256);

/// @notice Returns the number of votes a candidate received. Requires the election to be partially or totally evaluated
function getCandidateVotes(address candidate) external view returns (uint256);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity ^0.8.0;

import {IWormhole} from "@synthetixio/core-modules/contracts/interfaces/IWormhole.sol";
import {IWormholeRelayer} from "@synthetixio/core-modules/contracts/interfaces/IWormholeRelayer.sol";
import {ElectionSettings} from "../storage/ElectionSettings.sol";
import {Epoch} from "../storage/Epoch.sol";

/// @title Election module council with minimal logic to be deployed on Satellite chains
interface IElectionModuleSatellite {
Expand Down Expand Up @@ -71,6 +73,28 @@ interface IElectionModuleSatellite {
/// @notice Allows to withdraw a casted vote on the current network
function withdrawVote() external payable;

// ---------------------------------------
// View functions
// ---------------------------------------

/// @notice Returns the current period type: Administration, Nomination, Voting, Evaluation
function getCurrentPeriod() external view returns (uint256);

/// @notice Shows the current epoch schedule dates
function getEpochSchedule() external view returns (Epoch.Data memory epoch);

/// @notice Shows the settings for the current election
function getElectionSettings() external view returns (ElectionSettings.Data memory settings);

/// @notice Shows the settings for the next election
function getNextElectionSettings()
external
view
returns (ElectionSettings.Data memory settings);

/// @notice Returns the index of the current epoch. The first epoch's index is 1
function getEpochIndex() external view returns (uint256);

/// @dev Burn the council tokens from the given members; receiving end of members dismissal via Wormhole
function _recvDismissMembers(address[] calldata membersToDismiss, uint256 epochIndex) external;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ interface ISnapshotVotePowerModule {
) external returns (uint256 votingPower);

function getPreparedBallot(address voter) external view returns (uint256 power);

function getVotingPowerForUser(
address snapshotContract,
address voter,
uint256 periodId
) external view returns (uint256);
}
45 changes: 7 additions & 38 deletions protocol/governance/contracts/modules/core/ElectionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ contract ElectionModule is IElectionModule, ElectionModuleSatellite, ElectionTal
uint64 newEpochEndDate
) external payable override {
OwnableStorage.onlyOwner();
Council.onlyInPeriod(Epoch.ElectionPeriod.Administration);
Council.onlyInPeriods(Epoch.ElectionPeriod.Administration, Epoch.ElectionPeriod.Nomination);
Council.Data storage council = Council.load();

Epoch.Data storage currentEpoch = council.getCurrentEpoch();
Expand Down Expand Up @@ -197,7 +197,7 @@ contract ElectionModule is IElectionModule, ElectionModuleSatellite, ElectionTal
uint64 maxDateAdjustmentTolerance
) external override {
OwnableStorage.onlyOwner();
Council.onlyInPeriod(Epoch.ElectionPeriod.Administration);
Council.onlyInPeriods(Epoch.ElectionPeriod.Administration, Epoch.ElectionPeriod.Nomination);

Council.load().getNextElectionSettings().setElectionSettings(
epochSeatCount,
Expand Down Expand Up @@ -474,42 +474,6 @@ contract ElectionModule is IElectionModule, ElectionModuleSatellite, ElectionTal
});
}

/// @inheritdoc IElectionModule
function getEpochSchedule() external view override returns (Epoch.Data memory epoch) {
return Council.load().getCurrentEpoch();
}

/// @inheritdoc IElectionModule
function getElectionSettings()
external
view
override
returns (ElectionSettings.Data memory settings)
{
return Council.load().getCurrentElectionSettings();
}

/// @inheritdoc IElectionModule
function getNextElectionSettings()
external
view
override
returns (ElectionSettings.Data memory settings)
{
return Council.load().getNextElectionSettings();
}

/// @inheritdoc IElectionModule
function getEpochIndex() external view override returns (uint256) {
return Council.load().currentElectionId;
}

/// @inheritdoc IElectionModule
function getCurrentPeriod() external view override returns (uint256) {
// solhint-disable-next-line numcast/safe-cast
return uint256(Council.load().getCurrentEpoch().getCurrentPeriod());
}

/// @inheritdoc IElectionModule
function isNominated(address candidate) external view override returns (bool) {
return Council.load().getCurrentElection().nominees.contains(candidate);
Expand Down Expand Up @@ -555,6 +519,11 @@ contract ElectionModule is IElectionModule, ElectionModuleSatellite, ElectionTal
return Ballot.load(electionId, voter, chainId).votedCandidates;
}

/// @inheritdoc IElectionModule
function getNumOfBallots() external view override returns (uint256) {
return Council.load().getCurrentElection().ballotPtrs.length();
}

/// @inheritdoc IElectionModule
function isElectionEvaluated() public view override returns (bool) {
return Council.load().getCurrentElection().evaluated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {ElectionCredentials} from "../../submodules/election/ElectionCredentials
import {Ballot} from "../../storage/Ballot.sol";
import {CouncilMembers} from "../../storage/CouncilMembers.sol";
import {Council} from "../../storage/Council.sol";
import {ElectionSettings} from "../../storage/ElectionSettings.sol";
import {Epoch} from "../../storage/Epoch.sol";

contract ElectionModuleSatellite is
Expand Down Expand Up @@ -153,6 +154,42 @@ contract ElectionModuleSatellite is
emit VoteWithdrawnSent(sender);
}

/// @inheritdoc IElectionModuleSatellite
function getCurrentPeriod() external view override returns (uint256) {
// solhint-disable-next-line numcast/safe-cast
return uint256(Council.load().getCurrentEpoch().getCurrentPeriod());
}

/// @inheritdoc IElectionModuleSatellite
function getEpochSchedule() external view override returns (Epoch.Data memory epoch) {
return Council.load().getCurrentEpoch();
}

/// @inheritdoc IElectionModuleSatellite
function getElectionSettings()
external
view
override
returns (ElectionSettings.Data memory settings)
{
return Council.load().getCurrentElectionSettings();
}

/// @inheritdoc IElectionModuleSatellite
function getNextElectionSettings()
external
view
override
returns (ElectionSettings.Data memory settings)
{
return Council.load().getNextElectionSettings();
}

/// @inheritdoc IElectionModuleSatellite
function getEpochIndex() external view override returns (uint256) {
return Council.load().currentElectionId;
}

function _recvDismissMembers(
address[] calldata membersToDismiss,
uint256 epochIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ contract SnapshotVotePowerModule is ISnapshotVotePowerModule {
return SnapshotVotePower.load(snapshotContract).epochs[electionId].snapshotId;
}

/// @dev WARNING: this function is for the frontend to get the voting power of a voter, not for the contract to use
function getVotingPowerForUser(
address snapshotContract,
address voter,
uint256 periodId
) external view override returns (uint256) {
uint256 snapshotAmount = ISnapshotRecord(snapshotContract).balanceOfOnPeriod(
voter,
periodId
);
SnapshotVotePower.Data storage snapshotVotePower = SnapshotVotePower.load(snapshotContract);
return SnapshotVotePower.calculateVotingPower(snapshotVotePower, snapshotAmount);
}

function prepareBallotWithSnapshot(
address snapshotContract,
address voter
Expand Down
6 changes: 3 additions & 3 deletions protocol/governance/contracts/storage/Council.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ library Council {
using Epoch for Epoch.Data;
using ElectionSettings for ElectionSettings.Data;

error NotCallableInCurrentPeriod();
error NotCallableInCurrentPeriod(Epoch.ElectionPeriod currentPeriod);
error InvalidEpochConfiguration(uint256 code, uint64 v1, uint64 v2);
error ChangesCurrentPeriod();

Expand Down Expand Up @@ -75,7 +75,7 @@ library Council {
function onlyInPeriod(Epoch.ElectionPeriod period) internal view {
Epoch.ElectionPeriod currentPeriod = getCurrentEpoch(load()).getCurrentPeriod();
if (currentPeriod != period) {
revert NotCallableInCurrentPeriod();
revert NotCallableInCurrentPeriod(currentPeriod);
}
}

Expand All @@ -86,7 +86,7 @@ library Council {
) internal view {
Epoch.ElectionPeriod currentPeriod = getCurrentEpoch(load()).getCurrentPeriod();
if (currentPeriod != period1 && currentPeriod != period2) {
revert NotCallableInCurrentPeriod();
revert NotCallableInCurrentPeriod(currentPeriod);
}
}

Expand Down
7 changes: 7 additions & 0 deletions utils/common-config/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ const config = {
process.env.NETWORK_ENDPOINT ||
`https://testnet.snaxchain.io/${process.env.SNAXCHAIN_API_KEY}`,
accounts: process.env.DEPLOYER_PRIVATE_KEY ? [process.env.DEPLOYER_PRIVATE_KEY] : [],
chainId: 13001,
},
['snaxchain']: {
url:
process.env.NETWORK_ENDPOINT ||
`https://mainnet.snaxchain.io/${process.env.SNAXCHAIN_API_KEY}`,
accounts: process.env.DEPLOYER_PRIVATE_KEY ? [process.env.DEPLOYER_PRIVATE_KEY] : [],
chainId: 2192,
},
},
Expand Down

0 comments on commit 09b8614

Please sign in to comment.