From 8847356db9f98f327149c87d290c8ccc27c1b33e Mon Sep 17 00:00:00 2001 From: Victor Elias Date: Mon, 25 Sep 2023 19:43:04 -0400 Subject: [PATCH] bonding: getBondingStateAt -> getVotesAndDelegateAtRoundStart --- contracts/bonding/BondingVotes.sol | 99 +++++++++---------- contracts/bonding/IBondingVotes.sol | 2 +- .../test/mocks/BondingVotesERC5805Harness.sol | 2 +- src/test/BondingVotesStateInitialization.sol | 18 ++-- test/gas-report/checkpoints.js | 28 ++++-- test/integration/BondingVotes.js | 50 ++++++---- test/unit/BondingVotes.js | 99 ++++++++++++++----- 7 files changed, 183 insertions(+), 115 deletions(-) diff --git a/contracts/bonding/BondingVotes.sol b/contracts/bonding/BondingVotes.sol index 7ddba51b..2b858d2c 100644 --- a/contracts/bonding/BondingVotes.sol +++ b/contracts/bonding/BondingVotes.sol @@ -107,7 +107,7 @@ contract BondingVotes is ManagerProxyTarget, IBondingVotes { constructor(address _controller) Manager(_controller) {} // IVotes interface implementation. - // These should not access any storage directly but proxy to the bonding state functions. + // These should not access any storage directly but proxy to the historical stake functions below. /** * @notice Returns the name of the virtual token implemented by this. @@ -149,28 +149,21 @@ contract BondingVotes is ManagerProxyTarget, IBondingVotes { /** * @notice Returns the current amount of votes that `_account` has. * - * The value returned by this function can be equivalently calculated using {BondingManager} functions as follows: - * `isRegisteredTranscoder(_account) ? transcoderTotalStake(_account) : pendingStake(_account, 0)` - * - * @dev Keep in mind that since this function should return the votes at the end of the current round, we need to - * fetch the bonding state at the next round instead. That because the bonding state reflects the active stake in - * the current round, which is the snapshotted stake from the end of the previous round. + * The voting power for a delegator is the amount they are delegating to a transcoder, while for transcoders it is + * all the stake delegated to them. If an account is not a registered transcoder + * ({BondingManager-isRegisteredTranscoder}), the voting power of itself and of all its delegators will be zero. */ function getVotes(address _account) external view returns (uint256) { - (uint256 amount, ) = getBondingStateAt(_account, clock() + 1); - return amount; + (uint256 votes, ) = getVotesAndDelegateAtRoundStart(_account, clock() + 1); + return votes; } /** - * @notice Returns the amount of votes that `_account` had at a specific moment in the past. If the `clock()` is - * configured to use block numbers, this will return the value at the end of the corresponding block. - * @dev Keep in mind that since this function should return the votes at the end of the _round (or timepoint in OZ - * terms), we need to fetch the bonding state at the next round instead. That because the bonding state reflects the - * active stake in the current round, which is the snapshotted stake from the end of the previous round. + * @notice Returns the amount of votes that `_account` had at the end of the provided past `_round`. */ function getPastVotes(address _account, uint256 _round) external view onlyPastRounds(_round) returns (uint256) { - (uint256 amount, ) = getBondingStateAt(_account, _round + 1); - return amount; + (uint256 votes, ) = getVotesAndDelegateAtRoundStart(_account, _round + 1); + return votes; } /** @@ -178,22 +171,16 @@ contract BondingVotes is ManagerProxyTarget, IBondingVotes { * @dev This value is the sum of all *active* stake, which is not necessarily the sum of all voting power. * Bonded stake that is not part of the top 100 active transcoder set is still given voting power, but is not * considered here. - * @dev Keep in mind that since this function should return the votes at the end of the current round, we need to - * fetch the total active stake at the next round instead. That because the active stake in the current round is the - * snapshotted stake from the end of the previous round. */ function totalSupply() external view returns (uint256) { return getTotalActiveStakeAt(clock() + 1); } /** - * @notice Returns the total supply of votes available at a specific round in the past. + * @notice Returns the total supply of votes available at the end of the provided past `_round`. * @dev This value is the sum of all *active* stake, which is not necessarily the sum of all voting power. * Bonded stake that is not part of the top 100 active transcoder set is still given voting power, but is not * considered here. - * @dev Keep in mind that since this function should return the votes at the end of the _round (or timepoint in OZ - * terms), we need to fetch the total active stake at the next round instead. That because the active stake in the - * current round is the snapshotted stake from the end of the previous round. */ function getPastTotalSupply(uint256 _round) external view onlyPastRounds(_round) returns (uint256) { return getTotalActiveStakeAt(_round + 1); @@ -202,25 +189,19 @@ contract BondingVotes is ManagerProxyTarget, IBondingVotes { /** * @notice Returns the delegate that _account has chosen. This means the delegated transcoder address in case of * delegators, and the account's own address for transcoders (self-delegated). - * @dev Keep in mind that since this function should return the delegate at the end of the current round, we need to - * fetch the bonding state at the next round instead. That because the bonding state reflects the active stake in - * the current round, or the snapshotted stake from the end of the previous round. */ function delegates(address _account) external view returns (address) { - (, address delegateAddress) = getBondingStateAt(_account, clock() + 1); + (, address delegateAddress) = getVotesAndDelegateAtRoundStart(_account, clock() + 1); return delegateAddress; } /** - * @notice Returns the delegate that _account had chosen in a specific round in the past. + * @notice Returns the delegate that _account had chosen at the end of the provided past `_round`. * @dev This is an addition to the IERC5805 interface to support our custom vote counting logic that allows * delegators to override their transcoders votes. See {GovernorCountingOverridable-_handleVoteOverrides}. - * @dev Keep in mind that since this function should return the delegate at the end of the _round (or timepoint in - * OZ terms), we need to fetch the bonding state at the next round instead. That because the bonding state reflects - * the active stake in the current round, which is the snapshotted stake from the end of the previous round. */ function delegatedAt(address _account, uint256 _round) external view onlyPastRounds(_round) returns (address) { - (, address delegateAddress) = getBondingStateAt(_account, _round + 1); + (, address delegateAddress) = getVotesAndDelegateAtRoundStart(_account, _round + 1); return delegateAddress; } @@ -323,7 +304,11 @@ contract BondingVotes is ManagerProxyTarget, IBondingVotes { // Historical stake access functions /** - * @dev Gets the checkpointed total active stake at a given round. + * @notice Get the total active stake at the start of a given round. + * + * Notice that this function is different from the {IERC5805Upgradeable} functions above that return the state at + * the *end* of the round. The state at the end of a round is equal to the state at the start of the next round, so + * to get the same result here, call this function with `round+1` instead. * @param _round The round for which we want to get the total active stake. */ function getTotalActiveStakeAt(uint256 _round) public view virtual returns (uint256) { @@ -353,34 +338,41 @@ contract BondingVotes is ManagerProxyTarget, IBondingVotes { } /** - * @notice Gets the bonding state of an account at a given round. - * @dev In the case of delegators it is the amount they are delegating to a transcoder, while for transcoders this - * includes all the stake that has been delegated to them (including self-delegated). - * @param _account The account whose bonding state we want to get. - * @param _round The round for which we want to get the bonding state. Normally a proposal's vote start round. - * @return amount The active stake of the account at the given round including any accrued rewards. In case of - * transcoders this also includes all the amount delegated towards them by other delegators. - * @return delegateAddress The address the account delegated to. Will be equal to _account in case of transcoders. - */ - function getBondingStateAt(address _account, uint256 _round) + * @notice Gets the voting power and delegate of an account at the start of a given round. + * + * Notice that this function is different from the {IERC5805Upgradeable} functions above that return the state at + * the *end* of the round. The state at the end of a round is equal to the state at the start of the next round, so + * to get the same result here, call this function with `round+1` instead. + * @dev The value returned by this can also be calculated with the following logic using BondingManager functions at + * the start of the corresponding round: + * - If `isRegisteredTranscoder(_account)`, the result is `(_account, transcoderTotalStake(_account))` + * - Otherwise, the `delegate` is obtained from `getDelegator(_account).delegateAddress` + * - If `isRegisteredTranscoder(delegate)`, the result is `(delegate, pendingStake(_account, 0))` + * - Otherwise, the result is `(delegate, 0)` + * @param _account The account to get the voting power and delegate from. + * @param _round The round at which to get the account state (at round start). + * @return votes The voting power of the account at the start of the given round. + * @return delegateAddress The address the account delegated to at the start of the given round. + */ + function getVotesAndDelegateAtRoundStart(address _account, uint256 _round) public view virtual - returns (uint256 amount, address delegateAddress) + returns (uint256 votes, address delegateAddress) { BondingCheckpoint storage bond = getBondingCheckpointAt(_account, _round); delegateAddress = bond.delegateAddress; if (bond.bondedAmount == 0) { - amount = 0; + votes = 0; } else if (isRegisteredTranscoder(_account, bond)) { // Address is a registered transcoder so we use its delegated amount. This includes self and delegated stake // as well as any accrued rewards, even unclaimed ones - amount = bond.delegatedAmount; + votes = bond.delegatedAmount; } else { // Address is NOT a registered transcoder so we calculate its cumulative stake for the voting power - amount = delegatorCumulativeStakeAt(bond, _round); + votes = delegatorVotesAtRoundStart(bond, _round); } } @@ -453,14 +445,17 @@ contract BondingVotes is ManagerProxyTarget, IBondingVotes { } /** - * @dev Gets the cumulative stake of a delegator at any given round. Differently from the bonding manager - * implementation, we can calculate the stake at any round through the use of the checkpointed state. It works by - * re-using the bonding manager logic while changing only the way that we find the earning pool for the end round. + * @dev Gets the voting power of a delegator at the start of the given round. This is done through cumulative + * rewards calculation on top of the bonding state. + * + * Differently from the bonding manager implementation, we can calculate the stake at any round through the use of + * the checkpointed state. It works by re-using the bonding manager logic while changing only the way that we find + * the earning pool for the end round. * @param bond The {BondingCheckpoint} of the delegator at the given round. - * @param _round The round for which we want to get the cumulative stake. + * @param _round The round at which we want the delegator votes (at round start). * @return The cumulative stake of the delegator at the given round. */ - function delegatorCumulativeStakeAt(BondingCheckpoint storage bond, uint256 _round) + function delegatorVotesAtRoundStart(BondingCheckpoint storage bond, uint256 _round) internal view returns (uint256) diff --git a/contracts/bonding/IBondingVotes.sol b/contracts/bonding/IBondingVotes.sol index 1fc4f358..dc2b09d1 100644 --- a/contracts/bonding/IBondingVotes.sol +++ b/contracts/bonding/IBondingVotes.sol @@ -46,7 +46,7 @@ interface IBondingVotes is IVotes { function getTotalActiveStakeAt(uint256 _round) external view returns (uint256); - function getBondingStateAt(address _account, uint256 _round) + function getVotesAndDelegateAtRoundStart(address _account, uint256 _round) external view returns (uint256 amount, address delegateAddress); diff --git a/contracts/test/mocks/BondingVotesERC5805Harness.sol b/contracts/test/mocks/BondingVotesERC5805Harness.sol index 82367ec8..73724ff1 100644 --- a/contracts/test/mocks/BondingVotesERC5805Harness.sol +++ b/contracts/test/mocks/BondingVotesERC5805Harness.sol @@ -16,7 +16,7 @@ contract BondingVotesERC5805Harness is BondingVotes { * @return amount lowest 4 bytes of address + _round * @return delegateAddress (_account << 4) | _round. */ - function getBondingStateAt(address _account, uint256 _round) + function getVotesAndDelegateAtRoundStart(address _account, uint256 _round) public pure override diff --git a/src/test/BondingVotesStateInitialization.sol b/src/test/BondingVotesStateInitialization.sol index c90b26b8..efbbce6c 100644 --- a/src/test/BondingVotesStateInitialization.sol +++ b/src/test/BondingVotesStateInitialization.sol @@ -108,7 +108,7 @@ contract BondingVotesStateInitialization is GovernorBaseTest { uint256 currentRound = ROUNDS_MANAGER.currentRound(); for (uint256 i = 0; i < _testAddresses.length; i++) { - (uint256 checkedAmount, address checkedDelegate) = bondingVotes.getBondingStateAt( + (uint256 checkedAmount, address checkedDelegate) = bondingVotes.getVotesAndDelegateAtRoundStart( _testAddresses[i], currentRound ); @@ -128,11 +128,11 @@ contract BondingVotesStateInitialization is GovernorBaseTest { // Still returns zero checkpoint in the current round, checkpoint is made for the next. // We don't check delegatedAmount for simplicity here, it is checked in the other tests. - (, address checkedDelegate) = bondingVotes.getBondingStateAt(addr, currentRound); + (, address checkedDelegate) = bondingVotes.getVotesAndDelegateAtRoundStart(addr, currentRound); assertEq(checkedDelegate, address(0)); // Allows querying up to the next round. - (, checkedDelegate) = bondingVotes.getBondingStateAt(addr, currentRound + 1); + (, checkedDelegate) = bondingVotes.getVotesAndDelegateAtRoundStart(addr, currentRound + 1); assertEq( checkedDelegate, addr == DELEGATOR || addr == DELEGATOR_DELEGATE ? DELEGATOR_DELEGATE : addr == TRANSCODER @@ -144,7 +144,7 @@ contract BondingVotesStateInitialization is GovernorBaseTest { CHEATS.expectRevert( abi.encodeWithSelector(IBondingVotes.FutureLookup.selector, currentRound + 2, currentRound + 1) ); - bondingVotes.getBondingStateAt(addr, currentRound + 2); + bondingVotes.getVotesAndDelegateAtRoundStart(addr, currentRound + 2); } } @@ -154,7 +154,10 @@ contract BondingVotesStateInitialization is GovernorBaseTest { BONDING_MANAGER.checkpointBondingState(TRANSCODER); - (uint256 checkedAmount, address checkedDelegate) = bondingVotes.getBondingStateAt(TRANSCODER, currentRound + 1); + (uint256 checkedAmount, address checkedDelegate) = bondingVotes.getVotesAndDelegateAtRoundStart( + TRANSCODER, + currentRound + 1 + ); assertEq(checkedAmount, delegatedAmount); assertEq(checkedDelegate, TRANSCODER); } @@ -170,7 +173,10 @@ contract BondingVotesStateInitialization is GovernorBaseTest { // the delegate also needs to be checkpointed in case of delegators BONDING_MANAGER.checkpointBondingState(DELEGATOR_DELEGATE); - (uint256 checkedAmount, address checkedDelegate) = bondingVotes.getBondingStateAt(DELEGATOR, currentRound + 1); + (uint256 checkedAmount, address checkedDelegate) = bondingVotes.getVotesAndDelegateAtRoundStart( + DELEGATOR, + currentRound + 1 + ); assertEq(checkedAmount, pendingStake); assertEq(checkedDelegate, DELEGATOR_DELEGATE); diff --git a/test/gas-report/checkpoints.js b/test/gas-report/checkpoints.js index f73ba31e..67958e9a 100644 --- a/test/gas-report/checkpoints.js +++ b/test/gas-report/checkpoints.js @@ -111,31 +111,41 @@ describe("checkpoint bonding state gas report", () => { }) }) - describe("getBondingStateAt", () => { + describe("getVotesAndDelegateAtRoundStart", () => { beforeEach(async () => { await bondingManager.checkpointBondingState(transcoder.address) await bondingManager.checkpointBondingState(delegator.address) await bondingManager.checkpointBondingState(signers[99].address) }) - const gasGetBondingStateAt = async (address, round) => { - const tx = await bondingVotes.populateTransaction.getBondingStateAt( - address, - round - ) + const gasGetVotesAndDelegateAtRoundStart = async (address, round) => { + const tx = + await bondingVotes.populateTransaction.getVotesAndDelegateAtRoundStart( + address, + round + ) await signers[0].sendTransaction(tx) } it("delegator", async () => { - await gasGetBondingStateAt(delegator.address, currentRound + 1) + await gasGetVotesAndDelegateAtRoundStart( + delegator.address, + currentRound + 1 + ) }) it("transcoder", async () => { - await gasGetBondingStateAt(transcoder.address, currentRound + 1) + await gasGetVotesAndDelegateAtRoundStart( + transcoder.address, + currentRound + 1 + ) }) it("non-participant", async () => { - await gasGetBondingStateAt(signers[99].address, currentRound + 1) + await gasGetVotesAndDelegateAtRoundStart( + signers[99].address, + currentRound + 1 + ) }) }) }) diff --git a/test/integration/BondingVotes.js b/test/integration/BondingVotes.js index 02282d32..3026ebc0 100644 --- a/test/integration/BondingVotes.js +++ b/test/integration/BondingVotes.js @@ -142,7 +142,7 @@ describe("BondingVotes", () => { await nextRound() }) - describe("getBondingStateAt", () => { + describe("getVotesAndDelegateAtRoundStart", () => { it("should return partial rewards for any rounds since bonding", async () => { const pendingRewards0 = math.precise.percOf( mintableTokens[currentRound].div(2), // 50% cut rate @@ -157,7 +157,10 @@ describe("BondingVotes", () => { const stakeAt = round => bondingVotes - .getBondingStateAt(delegator.address, round) + .getVotesAndDelegateAtRoundStart( + delegator.address, + round + ) .then(n => n[0].toString()) assert.equal(await stakeAt(2), 0) @@ -176,7 +179,10 @@ describe("BondingVotes", () => { it("should return partial rewards for all transcoder stake", async () => { const stakeAt = round => bondingVotes - .getBondingStateAt(transcoder.address, round) + .getVotesAndDelegateAtRoundStart( + transcoder.address, + round + ) .then(n => n[0].toString()) assert.equal(await stakeAt(2), 0) @@ -318,16 +324,17 @@ describe("BondingVotes", () => { assert.isFalse(await isActive(inactiveTranscoder.address)) }) - describe("getBondingStateAt", () => { + describe("getVotesAndDelegateAtRoundStart", () => { it("should provide voting power even for inactive transcoders and their delegators", async () => { const transcoder = transcoders[transcoders.length - 1].address const delegator = delegators[delegators.length - 1].address const testHasStake = async (address, round) => { - const [stake] = await bondingVotes.getBondingStateAt( - address, - round - ) + const [stake] = + await bondingVotes.getVotesAndDelegateAtRoundStart( + address, + round + ) assert.isAbove( stake, 0, @@ -354,7 +361,10 @@ describe("BondingVotes", () => { const expectedStake = pendingStakes[address] const [stakeCheckpoint] = - await bondingVotes.getBondingStateAt(address, round) + await bondingVotes.getVotesAndDelegateAtRoundStart( + address, + round + ) assert.equal( stakeCheckpoint.toString(), expectedStake, @@ -382,10 +392,11 @@ describe("BondingVotes", () => { for (const r = currentRound - 2; r <= currentRound + 2; r++) { const activeStakeSum = BigNumber.from(0) for (const transcoder of activeTranscoders) { - const [stake] = await bondingVotes.getBondingStateAt( - transcoder.address, - r - ) + const [stake] = + await bondingVotes.getVotesAndDelegateAtRoundStart( + transcoder.address, + r + ) activeStakeSum = activeStakeSum.add(stake) } @@ -458,10 +469,10 @@ describe("BondingVotes", () => { await nextRound() }) - describe("getBondingStateAt", () => { + describe("getVotesAndDelegateAtRoundStart", () => { const stakeAt = (account, round) => bondingVotes - .getBondingStateAt(account.address, round) + .getVotesAndDelegateAtRoundStart(account.address, round) .then(n => n[0].toString()) const expectStakeAt = async (account, round, expected) => { assert.equal( @@ -608,10 +619,11 @@ describe("BondingVotes", () => { }) const expectStakeAt = async (account, round, expected, delegate) => { - const stakeAndAddress = await bondingVotes.getBondingStateAt( - account.address, - round - ) + const stakeAndAddress = + await bondingVotes.getVotesAndDelegateAtRoundStart( + account.address, + round + ) assert.equal( stakeAndAddress[0].toString(), expected.toString(), diff --git a/test/unit/BondingVotes.js b/test/unit/BondingVotes.js index 5d9910b2..c62d397f 100644 --- a/test/unit/BondingVotes.js +++ b/test/unit/BondingVotes.js @@ -463,7 +463,10 @@ describe("BondingVotes", () => { assert.deepEqual( await bondingVotes - .getBondingStateAt(transcoder.address, currentRound + 1) + .getVotesAndDelegateAtRoundStart( + transcoder.address, + currentRound + 1 + ) .then(t => t.map(v => v.toString())), ["1000", transcoder.address] ) @@ -493,7 +496,10 @@ describe("BondingVotes", () => { assert.deepEqual( await bondingVotes - .getBondingStateAt(transcoder.address, currentRound + 1) + .getVotesAndDelegateAtRoundStart( + transcoder.address, + currentRound + 1 + ) .then(t => t.map(v => v.toString())), ["2000", transcoder.address] ) @@ -738,7 +744,7 @@ describe("BondingVotes", () => { }) }) - describe("getBondingStateAt", () => { + describe("getVotesAndDelegateAtRoundStart", () => { let transcoder let delegator let currentRound @@ -752,7 +758,7 @@ describe("BondingVotes", () => { }) it("should fail if round is after the next round", async () => { - const tx = bondingVotes.getBondingStateAt( + const tx = bondingVotes.getVotesAndDelegateAtRoundStart( delegator.address, currentRound + 2 ) @@ -782,7 +788,10 @@ describe("BondingVotes", () => { const expectZeroCheckpoint = async queryRound => { expect( await bondingVotes - .getBondingStateAt(delegator.address, queryRound) + .getVotesAndDelegateAtRoundStart( + delegator.address, + queryRound + ) .then(t => t.map(v => v.toString())) ).to.deep.equal(["0", constants.NULL_ADDRESS]) } @@ -838,7 +847,10 @@ describe("BondingVotes", () => { assert.deepEqual( await bondingVotes - .getBondingStateAt(transcoder.address, currentRound - 2) + .getVotesAndDelegateAtRoundStart( + transcoder.address, + currentRound - 2 + ) .then(t => t.map(v => v.toString())), ["0", constants.NULL_ADDRESS] ) @@ -849,7 +861,10 @@ describe("BondingVotes", () => { assert.deepEqual( await bondingVotes - .getBondingStateAt(transcoder.address, currentRound) + .getVotesAndDelegateAtRoundStart( + transcoder.address, + currentRound + ) .then(t => t.map(v => v.toString())), ["1000", transcoder.address] ) @@ -861,14 +876,20 @@ describe("BondingVotes", () => { assert.deepEqual( await bondingVotes - .getBondingStateAt(transcoder.address, currentRound - 7) + .getVotesAndDelegateAtRoundStart( + transcoder.address, + currentRound - 7 + ) .then(t => t.map(v => v.toString())), ["1000", transcoder.address] ) assert.deepEqual( await bondingVotes - .getBondingStateAt(transcoder.address, currentRound) + .getVotesAndDelegateAtRoundStart( + transcoder.address, + currentRound + ) .then(t => t.map(v => v.toString())), ["2000", transcoder.address] ) @@ -962,7 +983,10 @@ describe("BondingVotes", () => { assert.deepEqual( await bondingVotes - .getBondingStateAt(delegator.address, currentRound) + .getVotesAndDelegateAtRoundStart( + delegator.address, + currentRound + ) .then(t => t.map(v => v.toString())), ["0", constants.NULL_ADDRESS] ) @@ -978,7 +1002,10 @@ describe("BondingVotes", () => { assert.deepEqual( await bondingVotes - .getBondingStateAt(delegator.address, currentRound) + .getVotesAndDelegateAtRoundStart( + delegator.address, + currentRound + ) .then(t => t.map(v => v.toString())), ["1000", transcoder.address] ) @@ -1001,14 +1028,20 @@ describe("BondingVotes", () => { assert.deepEqual( await bondingVotes - .getBondingStateAt(delegator.address, currentRound - 7) + .getVotesAndDelegateAtRoundStart( + delegator.address, + currentRound - 7 + ) .then(t => t.map(v => v.toString())), ["1000", transcoder.address] ) assert.deepEqual( await bondingVotes - .getBondingStateAt(delegator.address, currentRound) + .getVotesAndDelegateAtRoundStart( + delegator.address, + currentRound + ) .then(t => t.map(v => v.toString())), ["2000", transcoder2.address] ) @@ -1040,7 +1073,10 @@ describe("BondingVotes", () => { assert.deepEqual( await bondingVotes - .getBondingStateAt(delegator.address, currentRound) + .getVotesAndDelegateAtRoundStart( + delegator.address, + currentRound + ) .then(t => t.map(v => v.toString())), ["1000", transcoder.address] ) @@ -1066,7 +1102,7 @@ describe("BondingVotes", () => { }) // no earning pool for currentRound - 2 - const tx = bondingVotes.getBondingStateAt( + const tx = bondingVotes.getVotesAndDelegateAtRoundStart( delegator.address, currentRound ) @@ -1103,7 +1139,10 @@ describe("BondingVotes", () => { assert.deepEqual( await bondingVotes - .getBondingStateAt(delegator.address, currentRound) + .getVotesAndDelegateAtRoundStart( + delegator.address, + currentRound + ) .then(t => t.map(v => v.toString())), ["3000", transcoder.address] ) @@ -1131,7 +1170,10 @@ describe("BondingVotes", () => { assert.deepEqual( await bondingVotes - .getBondingStateAt(delegator.address, currentRound) + .getVotesAndDelegateAtRoundStart( + delegator.address, + currentRound + ) .then(t => t.map(v => v.toString())), ["5000", transcoder.address] ) @@ -1212,7 +1254,10 @@ describe("BondingVotes", () => { [expectedAmount, expectedDelegate] ) => { const actual = await bondingVotes - .getBondingStateAt(delegator.address, currentRound) + .getVotesAndDelegateAtRoundStart( + delegator.address, + currentRound + ) .then(t => t.map(v => v.toString())) const expected = [ expectedAmount.toString(), @@ -1337,7 +1382,7 @@ describe("BondingVotes", () => { // Same implementation as the BondingVotesERC5805Mock const mock = { - getBondingStateAt: (_account, _round) => { + getVotesAndDelegateAtRoundStart: (_account, _round) => { const intAddr = BigNumber.from(_account) // lowest 4 bytes of address + _round @@ -1382,8 +1427,8 @@ describe("BondingVotes", () => { }) describe("getVotes", () => { - it("should proxy to getBondingStateAt with the next round", async () => { - const [expected] = mock.getBondingStateAt( + it("should proxy to getVotesAndDelegateAtRoundStart with the next round", async () => { + const [expected] = mock.getVotesAndDelegateAtRoundStart( signers[0].address, currentRound + 1 ) @@ -1402,9 +1447,9 @@ describe("BondingVotes", () => { await expect(tx).to.be.revertedWith("FutureLookup(1000, 999)") }) - it("should proxy to getBondingStateAt with next round", async () => { + it("should proxy to getVotesAndDelegateAtRoundStart with next round", async () => { const testOnce = async (account, round) => { - const [expected] = mock.getBondingStateAt( + const [expected] = mock.getVotesAndDelegateAtRoundStart( account.address, round + 1 ) @@ -1424,8 +1469,8 @@ describe("BondingVotes", () => { }) describe("delegates", () => { - it("should proxy to getBondingStateAt with the next round", async () => { - const [, expected] = mock.getBondingStateAt( + it("should proxy to getVotesAndDelegateAtRoundStart with the next round", async () => { + const [, expected] = mock.getVotesAndDelegateAtRoundStart( signers[5].address, currentRound + 1 ) @@ -1437,9 +1482,9 @@ describe("BondingVotes", () => { }) describe("delegatedAt", () => { - it("should proxy to getBondingStateAt with next round", async () => { + it("should proxy to getVotesAndDelegateAtRoundStart with next round", async () => { const testOnce = async (account, round) => { - const [, expected] = mock.getBondingStateAt( + const [, expected] = mock.getVotesAndDelegateAtRoundStart( account.address, round + 1 )