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

Prevent CELO Transfer to Unreleased Treasury #11222

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
5f7e5d1
first compiling draft
soloseng Aug 15, 2024
4084bac
Compiler fixes + finishNextEpochProcess
pahor167 Aug 16, 2024
f3fed48
allocateValidatorsRewards compilable
pahor167 Aug 16, 2024
0b473c2
First few tests
pahor167 Aug 16, 2024
b012f29
test fix
pahor167 Aug 16, 2024
3a4f87a
uisng registry instead
soloseng Aug 16, 2024
ad8831d
updated registry ID var names
soloseng Aug 16, 2024
5fa905d
typo
soloseng Aug 16, 2024
b3023c2
++ mock contracts in 0.8
soloseng Aug 17, 2024
9681185
++ passing test using mock
soloseng Aug 17, 2024
18ba704
Removal of using precompiles
pahor167 Aug 19, 2024
8d862d1
ScoreManager refactor
pahor167 Aug 19, 2024
70b12a5
Decouple epoch manager initializer from registry
pahor167 Aug 19, 2024
0c74a5e
isReadyToStartEpoch fix
pahor167 Aug 19, 2024
7379aff
startNextEpochProcess fixes
pahor167 Aug 19, 2024
7205bb7
rename score manager to score reader
pahor167 Aug 19, 2024
b89cc74
Rename transfer to release on CeloDistribution schedule
pahor167 Aug 19, 2024
758d097
Celo distribution schedule renamed to CeloUnreleasedTreasure
pahor167 Aug 19, 2024
d7b32fb
conditions to getFirstBlockAtEpoch and getLastBlockAtEpoch
pahor167 Aug 19, 2024
a66e578
ScoreManager update
pahor167 Aug 19, 2024
de3ae19
getFirstBlockOfEpoch in EpochManager initializer
pahor167 Aug 19, 2024
8e86672
extra checks
pahor167 Aug 19, 2024
0fae892
introduce new getValidatorsGroup
pahor167 Aug 19, 2024
0e55b36
systemAlreadyInitialized update
pahor167 Aug 19, 2024
973c21e
Removal of IEpochManagerInterface
pahor167 Aug 19, 2024
315aaee
Made CI run on feature branch
martinvol Aug 19, 2024
efebfb7
Merge branch 'release/core-contracts/12' into feat/epoch-manager
pahor167 Aug 19, 2024
4c9ee98
merge fix
pahor167 Aug 19, 2024
c6fd893
Added target for the CI
martinvol Aug 19, 2024
04af0f7
Merge branch 'feat/epoch-manager' of github.com:celo-org/celo-monorep…
martinvol Aug 19, 2024
29aadbb
Merge branch 'feat/epoch-manager' into feat/l2-epoch-system
martinvol Aug 19, 2024
41fe5e6
Fixed quote celo-monorepo.yml
martinvol Aug 19, 2024
05dcde2
Allow Validator registration in L2 without BLS key (#11181)
m-chrzan Aug 19, 2024
ce59f2e
Fix CI
martinvol Aug 19, 2024
01a3098
Fixed interfaces and imports
martinvol Aug 19, 2024
f7454fc
Build fix
pahor167 Aug 20, 2024
ff4fb8f
lint
pahor167 Aug 20, 2024
55d462a
prettify
pahor167 Aug 20, 2024
a2522a2
prettify 2
pahor167 Aug 20, 2024
dc9ece5
Attempt to fix truffle build and migrations l2 epoch (#11190)
martinvol Aug 20, 2024
85303f9
Added Blocking to LockedGold, Election (#11186)
martinvol Aug 21, 2024
7979ffb
add EpochManager to abis
pahor167 Aug 23, 2024
f7cb22c
Merge branch 'feat/l2-epoch-system' of https://github.com/celo-org/ce…
pahor167 Aug 23, 2024
9403236
force deploy abis
pahor167 Aug 23, 2024
b63e487
build fix
pahor167 Aug 23, 2024
96eb887
Move Validators.sol to 0.8 (#11192)
martinvol Aug 26, 2024
62bfb44
force release of canary abi
pahor167 Aug 26, 2024
7e5e8ea
Merge branch 'feat/l2-epoch-system' of https://github.com/celo-org/ce…
pahor167 Aug 26, 2024
40e692b
force new canary version
pahor167 Aug 26, 2024
a536b5f
npm tag revert
pahor167 Aug 26, 2024
2c49e64
Soloseng/update-l2-getepochnumber-logic (#11195)
soloseng Aug 26, 2024
4e1cf6a
++ TODO and comment
soloseng Aug 26, 2024
2eab03f
add score manager to abis
pahor167 Aug 27, 2024
49a49ed
Merge branch 'feat/l2-epoch-system' of https://github.com/celo-org/ce…
pahor167 Aug 27, 2024
4cbc6d9
Split initEpochManager Function (#11199)
soloseng Sep 11, 2024
080b430
startNextEpochProcess unit & integration test (#11191)
soloseng Sep 17, 2024
5dc389f
E2E EpochManager test + Epoch truffle migrations & Anvil L2 migration…
pahor167 Sep 17, 2024
f4b4564
Soloseng/dynamically-fetch-epochmanagerenabler-address (#11207)
soloseng Sep 17, 2024
59ea380
Implement sending of allocated validator payments (#11197)
m-chrzan Sep 18, 2024
cfe3b30
EpochManager fixes (#11208)
pahor167 Sep 18, 2024
7fe7a29
Reset pending payment to 0 after sending (#11209)
m-chrzan Sep 18, 2024
d2fd5c4
Deleted duplicated import
martinvol Sep 18, 2024
df84c5d
Make captureEpochAndValidators work in constant time (#11210)
martinvol Sep 20, 2024
c85d594
Use more general interface for token transfer (#11216)
m-chrzan Sep 20, 2024
032f543
Epoch manager enabler tests (#11213)
soloseng Sep 20, 2024
91baa1b
Make sendValidatorPayment nonReentrant (#11217)
m-chrzan Sep 23, 2024
acd1f86
Martinvol/return account instead of signer (#11215)
martinvol Sep 23, 2024
a35fdba
EpochManager e2e tests add/remove validators between ecpochs (#11214)
pahor167 Sep 23, 2024
02454f4
Send validator payment on actions that would modify reward distributi…
m-chrzan Sep 23, 2024
cac4a13
Rename `CeloUnreleasedTreasure` to `CeloUnreleasedTreasury` (#11220)
soloseng Sep 23, 2024
580bd9d
renamed file
soloseng Sep 23, 2024
3e5c033
prevent CELO transfers to `CeloUnreleasedTreasury`
soloseng Sep 23, 2024
2a26cc6
++ comment
soloseng Sep 24, 2024
63db861
Merge branch 'release/core-contracts/12' into soloseng/prevent-celo-t…
soloseng Sep 25, 2024
c516109
unused import
soloseng Oct 4, 2024
19122fe
using internal accounting for released amount
soloseng Oct 11, 2024
5aafad1
Merge branch 'release/core-contracts/12' into soloseng/prevent-celo-t…
soloseng Oct 12, 2024
b182645
updated integration test
soloseng Oct 12, 2024
ec5ed87
PR feedback
soloseng Oct 14, 2024
102b224
Merge branch 'release/core-contracts/12' into soloseng/prevent-celo-t…
soloseng Oct 14, 2024
19c5138
PR feedback
soloseng Oct 15, 2024
7778f3b
Merge branch 'release/core-contracts/12' into soloseng/prevent-celo-t…
soloseng Oct 15, 2024
3d78151
reverted due to gas consideration
soloseng Oct 15, 2024
539b513
more revert
soloseng Oct 15, 2024
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 @@ -5,15 +5,27 @@ import "@openzeppelin/contracts8/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts8/utils/math/Math.sol";

import "./UsingRegistry.sol";
import "../common/IsL2Check.sol";

import "../../contracts/common/Initializable.sol";
import "./interfaces/ICeloUnreleasedTreasuryInitializer.sol";

/**
* @title Contract for unreleased Celo tokens.
* @notice This contract is not allowed to receive transfers of CELO,
* to avoid miscalculating the epoch rewards and to prevent any malicious actor
* from routing stolen fund through the epoch reward distribution.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make the fallback payable function explicitly revert?

Copy link
Contributor Author

@soloseng soloseng Oct 14, 2024

Choose a reason for hiding this comment

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

We could add a fallback function to make it explicitly revert, but that would acheive the same result as it is currently.

contract CeloUnreleasedTreasury is UsingRegistry, ReentrancyGuard, Initializable, IsL2Check {
contract CeloUnreleasedTreasury is
ICeloUnreleasedTreasuryInitializer,
UsingRegistry,
ReentrancyGuard,
Initializable
{
bool internal hasAlreadyReleased;

// Remaining epoch rewards to distribute.
uint256 internal remainingBalanceToRelease;

event Released(address indexed to, uint256 amount);

modifier onlyEpochManager() {
Expand Down Expand Up @@ -46,11 +58,31 @@ contract CeloUnreleasedTreasury is UsingRegistry, ReentrancyGuard, Initializable
* @param amount The amount to release.
*/
function release(address to, uint256 amount) external onlyEpochManager {
require(address(this).balance >= amount, "Insufficient balance.");
if (!hasAlreadyReleased) {
remainingBalanceToRelease = address(this).balance;
hasAlreadyReleased = true;
}

require(remainingBalanceToRelease >= amount, "Insufficient balance.");
Comment on lines +62 to +66
Copy link
Contributor

@martinvol martinvol Oct 14, 2024

Choose a reason for hiding this comment

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

I'd use ERC20 balance so that it can be ported to another token if needed.

Copy link
Contributor Author

@soloseng soloseng Oct 14, 2024

Choose a reason for hiding this comment

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

Not sure I understand what you mean by porting to another token. As in distributing a different ERC20 token instead of CELO?

Copy link
Contributor

Choose a reason for hiding this comment

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

if we ever want to use this contract for another ERC20, it won't work at we use ERC20 interfaces instead of native ones.

remainingBalanceToRelease -= amount;
soloseng marked this conversation as resolved.
Show resolved Hide resolved
require(getCeloToken().transfer(to, amount), "CELO transfer failed.");

emit Released(to, amount);
}

/**
* @notice Returns the remaining balance this contract has left to release.
* @dev This uses internal accounting of the released balance,
* to avoid recounting CELO that was transferred back to this contract.
*/
function getRemainingBalanceToRelease() external view returns (uint256) {
if (!hasAlreadyReleased) {
return address(this).balance;
} else {
return remainingBalanceToRelease;
}
}

/**
* @notice Returns the storage, major, minor, and patch version of the contract.
* @return Storage version of the contract.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,28 @@ import "../UsingRegistry.sol";
* @title A mock CeloUnreleasedTreasury for testing.
*/
contract MockCeloUnreleasedTreasury is ICeloUnreleasedTreasury, UsingRegistry {
bool internal hasAlreadyReleased;
uint256 internal remainingTreasure;
function release(address to, uint256 amount) external {
require(address(this).balance >= amount, "Insufficient balance.");
if (!hasAlreadyReleased) {
remainingTreasure = address(this).balance;
hasAlreadyReleased = true;
}

require(remainingTreasure >= amount, "Insufficient balance.");
require(getCeloToken().transfer(to, amount), "CELO transfer failed.");
remainingTreasure -= amount;
}

function getRemainingBalanceToRelease() external view returns (uint256) {
remainingTreasure;
}

function setRemainingTreasure(uint256 _amount) public {
remainingTreasure = _amount;
}

function setFirstRelease(bool _hasAlreadyReleased) public {
hasAlreadyReleased = _hasAlreadyReleased;
}
}
4 changes: 1 addition & 3 deletions packages/protocol/contracts/common/GoldToken.sol
soloseng marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import "./Initializable.sol";
import "./interfaces/ICeloToken.sol";
import "./interfaces/ICeloTokenInitializer.sol";
import "./interfaces/ICeloVersionedContract.sol";
import "./interfaces/ICeloUnreleasedTreasury.sol";
import "../../contracts-0.8/common/IsL2Check.sol";

contract GoldToken is
Expand Down Expand Up @@ -270,8 +269,7 @@ contract GoldToken is
*/
function allocatedSupply() public view returns (uint256) {
if (isL2()) {
return
CELO_SUPPLY_CAP - registry.getAddressForOrDie(CELO_UNRELEASED_TREASURY_REGISTRY_ID).balance;
return CELO_SUPPLY_CAP - getCeloUnreleasedTreasury().getRemainingBalanceToRelease();
} else {
return totalSupply();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ interface ICeloUnreleasedTreasury {
* @param amount The amount to release.
*/
function release(address to, uint256 amount) external;

function getRemainingBalanceToRelease() external view returns (uint256);
}
18 changes: 17 additions & 1 deletion packages/protocol/test-sol/devchain/migration/Migration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import "@celo-contracts/governance/interfaces/IValidators.sol";
import "@celo-contracts-8/common/interfaces/IPrecompiles.sol";
import "@celo-contracts-8/common/interfaces/IScoreManager.sol";

import "@openzeppelin/contracts8/token/ERC20/IERC20.sol";

contract IntegrationTest is Test, TestConstants, Utils08 {
IRegistry registry = IRegistry(REGISTRY_ADDRESS);

Expand Down Expand Up @@ -236,6 +238,19 @@ contract EpochManagerIntegrationTest is IntegrationTest, MigrationsConstants {
epochManager.initializeSystem(100, block.number, firstElected);
}

function test_Reverts_whenTransferingCeloToUnreleasedTreasury() public {
_MockL2Migration(validatorsList);

blockTravel(vm, 43200);
timeTravel(vm, DAY);

IERC20 _celoToken = IERC20(address(celoToken));
vm.prank(randomAddress);

(bool success, ) = address(unreleasedTreasury).call{ value: 50000 ether }("");
assertFalse(success);
}

function test_SetsCurrentRewardBlock() public {
_MockL2Migration(validatorsList);

Expand All @@ -245,8 +260,9 @@ contract EpochManagerIntegrationTest is IntegrationTest, MigrationsConstants {
epochManager.startNextEpochProcess();

(, , , uint256 _currentRewardsBlock) = epochManager.getCurrentEpoch();

(uint256 status, , , , ) = epochManager.getEpochProcessingState();
assertEq(_currentRewardsBlock, block.number);
assertEq(status, 1);
}

function _MockL2Migration(address[] memory _validatorsList) internal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ contract CeloUnreleasedTreasuryTest is Test, TestConstants, IsL2Check {
deployCodeTo("Registry.sol", abi.encode(false), REGISTRY_ADDRESS);
registry = IRegistry(REGISTRY_ADDRESS);

deployCodeTo("GoldToken.sol", abi.encode(false), celoTokenAddress);
deployCodeTo("GoldToken.sol", abi.encode(true), celoTokenAddress);
celoToken = ICeloToken(celoTokenAddress);
celoToken.initialize(REGISTRY_ADDRESS);
// Using a mock contract, as foundry does not allow for library linking when using deployCodeTo
governance = new MockGovernance();

Expand Down Expand Up @@ -156,3 +157,39 @@ contract CeloUnreleasedTreasuryTest_release is CeloUnreleasedTreasuryTest {
celoUnreleasedTreasury.release(randomAddress, 4);
}
}
contract CeloUnreleasedTreasuryTest_getRemainingBalanceToRelease is CeloUnreleasedTreasuryTest {
uint256 _startingBalance;
function setUp() public override {
super.setUp();
newCeloUnreleasedTreasury();
_startingBalance = address(celoUnreleasedTreasury).balance;
}

function test_ShouldReturnContractBalanceBeforeFirstRelease() public {
uint256 _remainingBalance = celoUnreleasedTreasury.getRemainingBalanceToRelease();

assertEq(_startingBalance, _remainingBalance);
}

function test_ShouldReturnRemainingBalanceToReleaseAfterFirstRelease() public {
vm.prank(epochManagerAddress);

celoUnreleasedTreasury.release(randomAddress, 4);
uint256 _remainingBalance = celoUnreleasedTreasury.getRemainingBalanceToRelease();
assertEq(_remainingBalance, _startingBalance - 4);
}

function test_RemainingBalanceToReleaseShouldRemainUnchangedAfterCeloTransferBackToContract()
public
{
vm.prank(epochManagerAddress);

celoUnreleasedTreasury.release(randomAddress, 4);
uint256 _remainingBalanceBeforeTransfer = celoUnreleasedTreasury.getRemainingBalanceToRelease();
assertEq(_remainingBalanceBeforeTransfer, _startingBalance - 4);
// set the contract balance to mock a CELO token transfer
vm.deal(address(celoUnreleasedTreasury), L2_INITIAL_STASH_BALANCE);
uint256 _remainingBalanceAfterTransfer = celoUnreleasedTreasury.getRemainingBalanceToRelease();
assertEq(_remainingBalanceAfterTransfer, _remainingBalanceBeforeTransfer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "@celo-contracts-8/stability/test/MockStableToken.sol";
import "@celo-contracts-8/common/test/MockCeloToken.sol";
import "@celo-contracts/common/interfaces/ICeloToken.sol";
import "@celo-contracts-8/common/ScoreManager.sol";
import { CeloUnreleasedTreasury } from "@celo-contracts-8/common/CeloUnreleasedTreasury.sol";
import { ICeloUnreleasedTreasury } from "@celo-contracts/common/interfaces/ICeloUnreleasedTreasury.sol";

import { TestConstants } from "@test-sol/constants.sol";
Expand Down
52 changes: 41 additions & 11 deletions packages/protocol/test-sol/unit/common/GoldToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract GoldTokenTest is Test, TestConstants, IsL2Check {
address receiver;
address sender;
address celoTokenOwner;
address celoTokenDistributionSchedule;
address celoUnreleasedTreasuryAddress;

event Transfer(address indexed from, address indexed to, uint256 value);
event TransferComment(string comment);
Expand All @@ -26,16 +26,17 @@ contract GoldTokenTest is Test, TestConstants, IsL2Check {
}

function setUp() public {
celoTokenOwner = actor("celoTokenOwner");
celoUnreleasedTreasuryAddress = actor("celoUnreleasedTreasury");
deployCodeTo("Registry.sol", abi.encode(false), REGISTRY_ADDRESS);
deployCodeTo("CeloUnreleasedTreasury.sol", abi.encode(false), celoUnreleasedTreasuryAddress);
registry = IRegistry(REGISTRY_ADDRESS);

celoTokenOwner = actor("celoTokenOwner");
celoTokenDistributionSchedule = actor("celoTokenDistributionSchedule");
vm.prank(celoTokenOwner);
celoToken = new GoldToken(true);
vm.prank(celoTokenOwner);
celoToken.setRegistry(REGISTRY_ADDRESS);
registry.setAddressFor("CeloUnreleasedTreasury", celoTokenDistributionSchedule);
registry.setAddressFor("CeloUnreleasedTreasury", celoUnreleasedTreasuryAddress);
receiver = actor("receiver");
sender = actor("sender");
vm.deal(receiver, ONE_CELOTOKEN);
Expand Down Expand Up @@ -126,6 +127,26 @@ contract GoldTokenTest_transfer is GoldTokenTest {
vm.expectRevert();
celoToken.transfer(address(0), ONE_CELOTOKEN);
}

function test_Succeeds_whenTransferingToCeloUnreleasedTreasury() public {
vm.prank(sender);
uint256 balanceBefore = celoToken.balanceOf(celoUnreleasedTreasuryAddress);

celoToken.transfer(celoUnreleasedTreasuryAddress, ONE_CELOTOKEN);
uint256 balanceAfter = celoToken.balanceOf(celoUnreleasedTreasuryAddress);
assertGt(balanceAfter, balanceBefore);
Comment on lines +132 to +137
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 this fail?

Copy link
Contributor Author

@soloseng soloseng Oct 14, 2024

Choose a reason for hiding this comment

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

no, that's why we are now using the internal accounting. ERc20 transfers will succeeed, but we do not account for in in the release.

This is done to avoid checking the to address on every CELO token transfers.

See above comments 1 & 2 for more details

Copy link
Contributor

Choose a reason for hiding this comment

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

if ERC20 token transfer succeed, for consistency shouldn't we make native transfer for as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This follows the same pattern as all other core contracts. No fallback implemented but still receive ERC20 transfers. Since it now keeps an internal accounting of the remaining distribution, any transfers are ignored.

}

function test_FailsWhenNativeTransferingToCeloUnreleasedTreasury() public payable {
(bool success, ) = address(uint160(celoUnreleasedTreasuryAddress)).call.value(ONE_CELOTOKEN)(
""
);

assertFalse(success);

bool sent = address(uint160(celoUnreleasedTreasuryAddress)).send(ONE_CELOTOKEN);
assertFalse(sent);
}
}

contract GoldTokenTest_transferFrom is GoldTokenTest {
Expand All @@ -150,6 +171,14 @@ contract GoldTokenTest_transferFrom is GoldTokenTest {
celoToken.transferFrom(sender, address(0), ONE_CELOTOKEN);
}

function test_Succeeds_whenTransferingToCeloUnreleasedTreasury() public {
uint256 balanceBefore = celoToken.balanceOf(celoUnreleasedTreasuryAddress);
vm.prank(receiver);
celoToken.transferFrom(sender, celoUnreleasedTreasuryAddress, ONE_CELOTOKEN);
uint256 balanceAfter = celoToken.balanceOf(celoUnreleasedTreasuryAddress);
assertGt(balanceAfter, balanceBefore);
}

function test_Reverts_WhenTransferMoreThanSenderHas() public {
uint256 value = sender.balance + ONE_CELOTOKEN * 4;

Expand Down Expand Up @@ -198,7 +227,7 @@ contract GoldTokenTest_mint is GoldTokenTest {
vm.expectRevert("Only VM can call");
celoToken.mint(receiver, ONE_CELOTOKEN);

vm.prank(celoTokenDistributionSchedule);
vm.prank(celoUnreleasedTreasuryAddress);
vm.expectRevert("Only VM can call");
celoToken.mint(receiver, ONE_CELOTOKEN);
}
Expand All @@ -220,7 +249,7 @@ contract GoldTokenTest_mint is GoldTokenTest {

function test_Reverts_whenL2() public _whenL2 {
vm.expectRevert("This method is no longer supported in L2.");
vm.prank(celoTokenDistributionSchedule);
vm.prank(celoUnreleasedTreasuryAddress);
celoToken.mint(receiver, ONE_CELOTOKEN);
vm.expectRevert("This method is no longer supported in L2.");
vm.prank(address(0));
Expand Down Expand Up @@ -249,23 +278,24 @@ contract CeloTokenMockTest is Test, TestConstants {
GoldTokenMock mockCeloToken;
uint256 ONE_CELOTOKEN = 1000000000000000000;
address burnAddress = address(0x000000000000000000000000000000000000dEaD);
address celoUnreleasedTreasury;
address celoUnreleasedTreasuryAddress = actor("CeloUnreleasedTreasury");

modifier _whenL2() {
deployCodeTo("Registry.sol", abi.encode(false), PROXY_ADMIN_ADDRESS);
vm.deal(celoUnreleasedTreasury, L2_INITIAL_STASH_BALANCE);
vm.deal(celoUnreleasedTreasuryAddress, L2_INITIAL_STASH_BALANCE);
_;
}

function setUp() public {
deployCodeTo("Registry.sol", abi.encode(false), REGISTRY_ADDRESS);
deployCodeTo("CeloUnreleasedTreasury.sol", abi.encode(false), celoUnreleasedTreasuryAddress);
registry = IRegistry(REGISTRY_ADDRESS);

mockCeloToken = new GoldTokenMock();
mockCeloToken.setRegistry(REGISTRY_ADDRESS);
mockCeloToken.setTotalSupply(L1_MINTED_CELO_SUPPLY);
celoUnreleasedTreasury = actor("CeloUnreleasedTreasury");
registry.setAddressFor("CeloUnreleasedTreasury", celoUnreleasedTreasury);
vm.deal(celoUnreleasedTreasuryAddress, L2_INITIAL_STASH_BALANCE);
registry.setAddressFor("CeloUnreleasedTreasury", celoUnreleasedTreasuryAddress);
}
}

Expand Down Expand Up @@ -304,7 +334,7 @@ contract GoldTokenTest_AllocatedSupply is CeloTokenMockTest {
}

function test_ShouldReturn_WhenWithdrawn_WhenInL2() public _whenL2 {
deal(address(celoUnreleasedTreasury), ONE_CELOTOKEN);
deal(celoUnreleasedTreasuryAddress, ONE_CELOTOKEN);
assertEq(mockCeloToken.allocatedSupply(), mockCeloToken.totalSupply() - ONE_CELOTOKEN);
}
}
Expand Down
Loading