Skip to content

Commit

Permalink
refactor BurnMintERC677 to inherit from BurnMintERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
jhweintraub committed Sep 25, 2024
1 parent 2ee8c29 commit 0f22eb0
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 427 deletions.
264 changes: 132 additions & 132 deletions contracts/gas-snapshots/ccip.gas-snapshot

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions contracts/gas-snapshots/shared.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,58 @@ AuthorizedCallers_constructor:test_ZeroAddressNotAllowed_Revert() (gas: 64473)
AuthorizedCallers_constructor:test_constructor_Success() (gas: 720513)
BurnMintERC20_approve:testApproveSuccess() (gas: 55477)
BurnMintERC20_approve:testInvalidAddressReverts() (gas: 10663)
BurnMintERC20_burn:testBasicBurnSuccess() (gas: 135064)
BurnMintERC20_burn:testBasicBurnSuccess() (gas: 173886)
BurnMintERC20_burn:testBurnFromZeroAddressReverts() (gas: 47201)
BurnMintERC20_burn:testExceedsBalanceReverts() (gas: 21819)
BurnMintERC20_burn:testSenderNotBurnerReverts() (gas: 32182)
BurnMintERC20_burn:testSenderNotBurnerReverts() (gas: 16739)
BurnMintERC20_burnFrom:testBurnFromSuccess() (gas: 57957)
BurnMintERC20_burnFrom:testExceedsBalanceReverts() (gas: 35916)
BurnMintERC20_burnFrom:testInsufficientAllowanceReverts() (gas: 21914)
BurnMintERC20_burnFrom:testSenderNotBurnerReverts() (gas: 32182)
BurnMintERC20_burnFrom:testSenderNotBurnerReverts() (gas: 16739)
BurnMintERC20_burnFromAlias:testBurnFromSuccess() (gas: 57932)
BurnMintERC20_burnFromAlias:testExceedsBalanceReverts() (gas: 35880)
BurnMintERC20_burnFromAlias:testInsufficientAllowanceReverts() (gas: 21869)
BurnMintERC20_burnFromAlias:testSenderNotBurnerReverts() (gas: 32137)
BurnMintERC20_constructor:testConstructorSuccess() (gas: 1737298)
BurnMintERC20_burnFromAlias:testSenderNotBurnerReverts() (gas: 16694)
BurnMintERC20_constructor:testConstructorSuccess() (gas: 1600593)
BurnMintERC20_decreaseApproval:testDecreaseApprovalSuccess() (gas: 31123)
BurnMintERC20_grantMintAndBurnRoles:testGrantMintAndBurnRolesSuccess() (gas: 121170)
BurnMintERC20_grantRole:testGrantBurnAccessSuccess() (gas: 53407)
BurnMintERC20_grantRole:testGrantManySuccess() (gas: 957680)
BurnMintERC20_grantRole:testGrantManySuccess() (gas: 944594)
BurnMintERC20_grantRole:testGrantMintAccessSuccess() (gas: 94200)
BurnMintERC20_increaseApproval:testIncreaseApprovalSuccess() (gas: 44121)
BurnMintERC20_mint:testBasicMintSuccess() (gas: 52689)
BurnMintERC20_mint:testBasicMintSuccess() (gas: 149743)
BurnMintERC20_mint:testMaxSupplyExceededReverts() (gas: 50429)
BurnMintERC20_mint:testSenderNotMinterReverts() (gas: 30039)
BurnMintERC20_mint:testSenderNotMinterReverts() (gas: 14596)
BurnMintERC20_supportsInterface:testConstructorSuccess() (gas: 11123)
BurnMintERC20_transfer:testInvalidAddressReverts() (gas: 10661)
BurnMintERC20_transfer:testTransferSuccess() (gas: 42277)
BurnMintERC677_approve:testApproveSuccess() (gas: 55512)
BurnMintERC677_approve:testApproveSuccess() (gas: 55477)
BurnMintERC677_approve:testInvalidAddressReverts() (gas: 10663)
BurnMintERC677_burn:testBasicBurnSuccess() (gas: 173939)
BurnMintERC677_burn:testBurnFromZeroAddressReverts() (gas: 47201)
BurnMintERC677_burn:testBasicBurnSuccess() (gas: 173904)
BurnMintERC677_burn:testBurnFromZeroAddressReverts() (gas: 47223)
BurnMintERC677_burn:testExceedsBalanceReverts() (gas: 21841)
BurnMintERC677_burn:testSenderNotBurnerReverts() (gas: 13359)
BurnMintERC677_burnFrom:testBurnFromSuccess() (gas: 57923)
BurnMintERC677_burnFrom:testExceedsBalanceReverts() (gas: 35864)
BurnMintERC677_burnFrom:testInsufficientAllowanceReverts() (gas: 21849)
BurnMintERC677_burnFrom:testSenderNotBurnerReverts() (gas: 13359)
BurnMintERC677_burnFromAlias:testBurnFromSuccess() (gas: 57949)
BurnMintERC677_burn:testSenderNotBurnerReverts() (gas: 13424)
BurnMintERC677_burnFrom:testBurnFromSuccess() (gas: 57957)
BurnMintERC677_burnFrom:testExceedsBalanceReverts() (gas: 35916)
BurnMintERC677_burnFrom:testInsufficientAllowanceReverts() (gas: 21914)
BurnMintERC677_burnFrom:testSenderNotBurnerReverts() (gas: 13424)
BurnMintERC677_burnFromAlias:testBurnFromSuccess() (gas: 57932)
BurnMintERC677_burnFromAlias:testExceedsBalanceReverts() (gas: 35880)
BurnMintERC677_burnFromAlias:testInsufficientAllowanceReverts() (gas: 21869)
BurnMintERC677_burnFromAlias:testSenderNotBurnerReverts() (gas: 13379)
BurnMintERC677_constructor:testConstructorSuccess() (gas: 1672809)
BurnMintERC677_decreaseApproval:testDecreaseApprovalSuccess() (gas: 31069)
BurnMintERC677_grantMintAndBurnRoles:testGrantMintAndBurnRolesSuccess() (gas: 121324)
BurnMintERC677_grantRole:testGrantBurnAccessSuccess() (gas: 53460)
BurnMintERC677_grantRole:testGrantManySuccess() (gas: 937759)
BurnMintERC677_grantRole:testGrantMintAccessSuccess() (gas: 94340)
BurnMintERC677_increaseApproval:testIncreaseApprovalSuccess() (gas: 44076)
BurnMintERC677_mint:testBasicMintSuccess() (gas: 149699)
BurnMintERC677_mint:testMaxSupplyExceededReverts() (gas: 50385)
BurnMintERC677_constructor:testConstructorSuccess() (gas: 1763863)
BurnMintERC677_decreaseApproval:testDecreaseApprovalSuccess() (gas: 31088)
BurnMintERC677_grantMintAndBurnRoles:testGrantMintAndBurnRolesSuccess() (gas: 121214)
BurnMintERC677_grantRole:testGrantBurnAccessSuccess() (gas: 53477)
BurnMintERC677_grantRole:testGrantManySuccess() (gas: 937980)
BurnMintERC677_grantRole:testGrantMintAccessSuccess() (gas: 94200)
BurnMintERC677_increaseApproval:testIncreaseApprovalSuccess() (gas: 44121)
BurnMintERC677_mint:testBasicMintSuccess() (gas: 149677)
BurnMintERC677_mint:testMaxSupplyExceededReverts() (gas: 50297)
BurnMintERC677_mint:testSenderNotMinterReverts() (gas: 11195)
BurnMintERC677_supportsInterface:testConstructorSuccess() (gas: 12476)
BurnMintERC677_transfer:testInvalidAddressReverts() (gas: 10639)
BurnMintERC677_transfer:testTransferSuccess() (gas: 42299)
BurnMintERC677_supportsInterface:testConstructorSuccess() (gas: 12610)
BurnMintERC677_transfer:testInvalidAddressReverts() (gas: 10661)
BurnMintERC677_transfer:testTransferSuccess() (gas: 42277)
CallWithExactGas__callWithExactGas:test_CallWithExactGasReceiverErrorSuccess() (gas: 67209)
CallWithExactGas__callWithExactGas:test_CallWithExactGasSafeReturnDataExactGas() (gas: 18324)
CallWithExactGas__callWithExactGas:test_NoContractReverts() (gas: 11559)
Expand Down Expand Up @@ -101,11 +101,11 @@ EnumerableMapAddresses_set:testSetSuccess() (gas: 94685)
EnumerableMapAddresses_tryGet:testBytes32TryGetSuccess() (gas: 94622)
EnumerableMapAddresses_tryGet:testBytesTryGetSuccess() (gas: 96279)
EnumerableMapAddresses_tryGet:testTryGetSuccess() (gas: 94893)
OpStackBurnMintERC677_constructor:testConstructorSuccess() (gas: 1743649)
OpStackBurnMintERC677_interfaceCompatibility:testBurnCompatibility() (gas: 298649)
OpStackBurnMintERC677_interfaceCompatibility:testMintCompatibility() (gas: 137957)
OpStackBurnMintERC677_constructor:testConstructorSuccess() (gas: 1829158)
OpStackBurnMintERC677_interfaceCompatibility:testBurnCompatibility() (gas: 298741)
OpStackBurnMintERC677_interfaceCompatibility:testMintCompatibility() (gas: 138155)
OpStackBurnMintERC677_interfaceCompatibility:testStaticFunctionsCompatibility() (gas: 13781)
OpStackBurnMintERC677_supportsInterface:testConstructorSuccess() (gas: 12752)
OpStackBurnMintERC677_supportsInterface:testConstructorSuccess() (gas: 12814)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_EmptySubset_Reverts() (gas: 5460)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_EmptySuperset_Reverts() (gas: 4661)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_HasDuplicates_Reverts() (gas: 8265)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ pragma solidity 0.8.24;
import {BurnMintERC677} from "../../../shared/token/ERC677/BurnMintERC677.sol";
import {IGetCCIPAdmin} from "../../interfaces/IGetCCIPAdmin.sol";

contract BurnMintERC677Helper is BurnMintERC677, IGetCCIPAdmin {
contract BurnMintERC677Helper is BurnMintERC677 {
constructor(string memory name, string memory symbol) BurnMintERC677(name, symbol, 18, 0) {}

// Gives one full token to any given address.
function drip(address to) external {
_mint(to, 1e18);
}

function getCCIPAdmin() external view override returns (address) {
return owner();
}
}
9 changes: 5 additions & 4 deletions contracts/src/v0.8/ccip/test/legacy/TokenPoolAndProxy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import {IPoolV1} from "../../interfaces/IPool.sol";
import {IPoolPriorTo1_5} from "../../interfaces/IPoolPriorTo1_5.sol";

import {BurnMintERC20} from "../../../shared/token/ERC20/BurnMintERC20.sol";
import {BurnMintERC677} from "../../../shared/token/ERC677/BurnMintERC677.sol";
import {Router} from "../../Router.sol";
import {Client} from "../../libraries/Client.sol";
Expand Down Expand Up @@ -112,9 +113,9 @@ contract TokenPoolAndProxyMigration is EVM2EVMOnRampSetup {
s_newPool.setPreviousPool(IPoolPriorTo1_5(address(0)));

// The new pool is now active, but is has not been given permissions to burn/mint yet
vm.expectRevert(abi.encodeWithSelector(BurnMintERC677.SenderNotBurner.selector, address(s_newPool)));
vm.expectRevert(abi.encodeWithSelector(BurnMintERC20.SenderNotBurner.selector, address(s_newPool)));
_ccipSend1_5();
vm.expectRevert(abi.encodeWithSelector(BurnMintERC677.SenderNotMinter.selector, address(s_newPool)));
vm.expectRevert(abi.encodeWithSelector(BurnMintERC20.SenderNotMinter.selector, address(s_newPool)));
_fakeReleaseOrMintFromOffRamp1_5();

// When we do give burn/mint, the new pool is fully active
Expand Down Expand Up @@ -176,9 +177,9 @@ contract TokenPoolAndProxyMigration is EVM2EVMOnRampSetup {
s_newPool.setPreviousPool(IPoolPriorTo1_5(address(0)));

// The new pool is now active, but is has not been given permissions to burn/mint yet
vm.expectRevert(abi.encodeWithSelector(BurnMintERC677.SenderNotBurner.selector, address(s_newPool)));
vm.expectRevert(abi.encodeWithSelector(BurnMintERC20.SenderNotBurner.selector, address(s_newPool)));
_ccipSend1_5();
vm.expectRevert(abi.encodeWithSelector(BurnMintERC677.SenderNotMinter.selector, address(s_newPool)));
vm.expectRevert(abi.encodeWithSelector(BurnMintERC20.SenderNotMinter.selector, address(s_newPool)));
_fakeReleaseOrMintFromOffRamp1_5();

// When we do give burn/mint, the new pool is fully active
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
pragma solidity ^0.8.24;

import {IOwner} from "../../interfaces/IOwner.sol";
import {ITokenAdminRegistry} from "../../interfaces/ITokenAdminRegistry.sol";

import {OwnerIsCreator} from "../../../shared/access/OwnerIsCreator.sol";

import {RateLimiter} from "../../libraries/RateLimiter.sol";
import {BurnMintTokenPool} from "../../pools/BurnMintTokenPool.sol";
import {TokenPool} from "../../pools/TokenPool.sol";

import {FactoryBurnMintERC20} from "../../tokenAdminRegistry/FactoryBurnMintERC20.sol";
import {RegistryModuleOwnerCustom} from "../../tokenAdminRegistry/RegistryModuleOwnerCustom.sol";
import {TokenAdminRegistry} from "../../tokenAdminRegistry/TokenAdminRegistry.sol";
import {TokenPoolFactory} from "../../tokenAdminRegistry/TokenPoolFactory.sol";

import {RegistryModuleOwnerCustom} from "../../tokenAdminRegistry/RegistryModuleOwnerCustom.sol";
import {TokenAdminRegistrySetup} from "./TokenAdminRegistry.t.sol";

import {RateLimiter} from "../../libraries/RateLimiter.sol";

import {OwnerIsCreator} from "../../../shared/access/OwnerIsCreator.sol";
import {BurnMintERC20} from "../../../shared/token/ERC20/BurnMintERC20.sol";

import {Create2} from "../../../vendor/openzeppelin-solidity/v5.0.2/contracts/utils/Create2.sol";

contract TokenPoolFactorySetup is TokenAdminRegistrySetup {
Expand All @@ -42,14 +40,13 @@ contract TokenPoolFactorySetup is TokenAdminRegistrySetup {
s_registryModuleOwnerCustom = new RegistryModuleOwnerCustom(address(s_tokenAdminRegistry));
s_tokenAdminRegistry.addRegistryModule(address(s_registryModuleOwnerCustom));

s_tokenPoolFactory = new TokenPoolFactory(
address(s_tokenAdminRegistry), address(s_registryModuleOwnerCustom), s_rmnProxy, address(s_sourceRouter)
);
s_tokenPoolFactory =
new TokenPoolFactory(s_tokenAdminRegistry, s_registryModuleOwnerCustom, s_rmnProxy, address(s_sourceRouter));

// Create Init Code for BurnMintERC20 TestToken with 18 decimals and supply cap of max uint256 value
s_tokenCreationParams = abi.encode("TestToken", "TT", 18, type(uint256).max, PREMINT_AMOUNT, OWNER);

s_tokenInitCode = abi.encodePacked(type(BurnMintERC20).creationCode, s_tokenCreationParams);
s_tokenInitCode = abi.encodePacked(type(FactoryBurnMintERC20).creationCode, s_tokenCreationParams);

s_poolInitCode = type(BurnMintTokenPool).creationCode;

Expand All @@ -66,9 +63,14 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {
function test_TokenPoolFactory_Constructor_Revert() public {
// Revert cause the tokenAdminRegistry is address(0)
vm.expectRevert(TokenPoolFactory.InvalidZeroAddress.selector);
new TokenPoolFactory(address(0), address(0), address(0), address(0));
new TokenPoolFactory(ITokenAdminRegistry(address(0)), RegistryModuleOwnerCustom(address(0)), address(0), address(0));

new TokenPoolFactory(address(0xdeadbeef), address(0xdeadbeef), address(0xdeadbeef), address(0xdeadbeef));
new TokenPoolFactory(
ITokenAdminRegistry(address(0xdeadbeef)),
RegistryModuleOwnerCustom(address(0xdeadbeef)),
address(0xdeadbeef),
address(0xdeadbeef)
);
}

function test_createTokenPool_WithNoExistingTokenOnRemoteChain_Success() public {
Expand Down Expand Up @@ -116,9 +118,8 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {
RegistryModuleOwnerCustom newRegistryModule = new RegistryModuleOwnerCustom(address(newTokenAdminRegistry));

// We want to deploy a new factory and Owner Module.
TokenPoolFactory newTokenPoolFactory = new TokenPoolFactory(
address(newTokenAdminRegistry), address(newRegistryModule), s_rmnProxy, address(s_destRouter)
);
TokenPoolFactory newTokenPoolFactory =
new TokenPoolFactory(newTokenAdminRegistry, newRegistryModule, s_rmnProxy, address(s_destRouter));

newTokenAdminRegistry.addRegistryModule(address(newRegistryModule));

Expand Down Expand Up @@ -207,17 +208,17 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {
vm.startPrank(OWNER);
bytes32 dynamicSalt = keccak256(abi.encodePacked(FAKE_SALT, OWNER));

BurnMintERC20 newRemoteToken = new BurnMintERC20("TestToken", "TT", 18, type(uint256).max, PREMINT_AMOUNT, OWNER);
FactoryBurnMintERC20 newRemoteToken =
new FactoryBurnMintERC20("TestToken", "TT", 18, type(uint256).max, PREMINT_AMOUNT, OWNER);

// We have to create a new factory, registry module, and token admin registry to simulate the other chain

TokenAdminRegistry newTokenAdminRegistry = new TokenAdminRegistry();
RegistryModuleOwnerCustom newRegistryModule = new RegistryModuleOwnerCustom(address(newTokenAdminRegistry));

// We want to deploy a new factory and Owner Module.
TokenPoolFactory newTokenPoolFactory = new TokenPoolFactory(
address(newTokenAdminRegistry), address(newRegistryModule), s_rmnProxy, address(s_destRouter)
);
TokenPoolFactory newTokenPoolFactory =
new TokenPoolFactory(newTokenAdminRegistry, newRegistryModule, s_rmnProxy, address(s_destRouter));

newTokenAdminRegistry.addRegistryModule(address(newRegistryModule));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {BurnMintERC20} from "../../shared/token/ERC20/BurnMintERC20.sol";

/// @notice A basic ERC20 compatible token contract with burn and minting roles.
/// @dev The total supply can be limited during deployment.
contract FactoryBurnMintERC20 is BurnMintERC20 {
constructor(
string memory name,
string memory symbol,
uint8 decimals_,
uint256 maxSupply_,
uint256 preMint_,
address newOwner_
) BurnMintERC20(name, symbol, decimals_, maxSupply_) {
i_decimals = decimals_;
i_maxSupply = maxSupply_;

s_ccipAdmin = newOwner_;

// Mint the initial supply to the new Owner, saving gas by not calling if the mint amount is zero
if (preMint_ != 0) _mint(newOwner_, preMint_);

// Grant the deployer the minter and burner roles. This contract is expected to be deployed by a factory
// contract that will transfer ownership to the correct address after deployment, so granting minting and burning
// privileges here saves gas by not requiring two transactions.
grantMintRole(newOwner_);
grantBurnRole(newOwner_);
}
}
Loading

0 comments on commit 0f22eb0

Please sign in to comment.