Skip to content

Commit

Permalink
refactor(deploy): fetch facet selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
rndquu committed Oct 3, 2023
1 parent 82248eb commit 060647d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
pragma solidity 0.8.19;

import "../../../../src/dollar/libraries/Constants.sol";
import {DiamondTestHelper} from "../../../../test/helpers/DiamondTestHelper.sol";
import "forge-std/Script.sol";

contract Constants is Script {
contract Constants is DiamondTestHelper, Script {
address constant curve3PoolToken =
0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490;
address constant basePool = 0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,27 @@ import {UbiquityDollarToken} from "../../../../src/dollar/core/UbiquityDollarTok
import {StakingShare} from "../../../../src/dollar/core/StakingShare.sol";
import {UbiquityGovernanceToken} from "../../../../src/dollar/core/UbiquityGovernanceToken.sol";
import {IDiamondCut} from "../../../../src/dollar/interfaces/IDiamondCut.sol";
//import "../../src/dollar/interfaces/IDiamondLoupe.sol";

import "./00_Constants.s.sol";

contract DiamondScript is Constants {
bytes4[] selectorsOfDiamondCutFacet;
bytes4[] selectorsOfDiamondLoupeFacet;
bytes4[] selectorsOfOwnershipFacet;
bytes4[] selectorsOfManagerFacet;
// selectors of the facets
bytes4[] selectorsOfAccessControlFacet;
bytes4[] selectorsOfTWAPOracleDollar3poolFacet;
bytes4[] selectorsOfCollectableDustFacet;
bytes4[] selectorsOfChefFacet;
bytes4[] selectorsOfStakingFacet;
bytes4[] selectorsOfStakingFormulasFacet;

bytes4[] selectorsOfCollectableDustFacet;
bytes4[] selectorsOfCreditNftManagerFacet;
bytes4[] selectorsOfCreditNftRedemptionCalculatorFacet;
bytes4[] selectorsOfCreditRedemptionCalculatorFacet;

bytes4[] selectorsOfDiamondCutFacet;
bytes4[] selectorsOfDiamondLoupeFacet;
bytes4[] selectorsOfDollarMintCalculatorFacet;
bytes4[] selectorsOfDollarMintExcessFacet;
bytes4[] selectorsOfManagerFacet;
bytes4[] selectorsOfOwnershipFacet;
bytes4[] selectorsOfStakingFacet;
bytes4[] selectorsOfStakingFormulasFacet;
bytes4[] selectorsOfTWAPOracleDollar3poolFacet;

// contract types of facets to be deployed
Diamond diamond;
DiamondCutFacet dCutFacet;
Expand Down Expand Up @@ -260,266 +259,50 @@ contract DiamondScript is Constants {

function getSelectors() internal {
// set all function selectors
// Diamond Cut selectors
selectorsOfDiamondCutFacet.push(IDiamondCut.diamondCut.selector);

// Diamond Loupe
selectorsOfDiamondLoupeFacet.push(IDiamondLoupe.facets.selector);
selectorsOfDiamondLoupeFacet.push(
IDiamondLoupe.facetFunctionSelectors.selector
selectorsOfAccessControlFacet = getSelectorsFromAbi(
"/out/AccessControlFacet.sol/AccessControlFacet.json"
);
selectorsOfDiamondLoupeFacet.push(
IDiamondLoupe.facetAddresses.selector
selectorsOfChefFacet = getSelectorsFromAbi(
"/out/ChefFacet.sol/ChefFacet.json"
);
selectorsOfDiamondLoupeFacet.push(IDiamondLoupe.facetAddress.selector);
selectorsOfDiamondLoupeFacet.push(IERC165.supportsInterface.selector);

// Ownership
selectorsOfOwnershipFacet.push(IERC173.transferOwnership.selector);
selectorsOfOwnershipFacet.push(IERC173.owner.selector);

// Manager selectors
selectorsOfManagerFacet.push(
managerFacet.setCreditTokenAddress.selector
);
selectorsOfManagerFacet.push(managerFacet.setCreditNftAddress.selector);
selectorsOfManagerFacet.push(
managerFacet.setGovernanceTokenAddress.selector
);
selectorsOfManagerFacet.push(
managerFacet.setDollarTokenAddress.selector
);
selectorsOfManagerFacet.push(
managerFacet.setSushiSwapPoolAddress.selector
);
selectorsOfManagerFacet.push(
managerFacet.setDollarMintCalculatorAddress.selector
);
selectorsOfManagerFacet.push(
managerFacet.setExcessDollarsDistributor.selector
);
selectorsOfManagerFacet.push(
managerFacet.setMasterChefAddress.selector
);
selectorsOfManagerFacet.push(managerFacet.setFormulasAddress.selector);
selectorsOfManagerFacet.push(
managerFacet.setStakingShareAddress.selector
);
selectorsOfManagerFacet.push(
managerFacet.setStableSwapMetaPoolAddress.selector
);
selectorsOfManagerFacet.push(
managerFacet.setStakingContractAddress.selector
selectorsOfCollectableDustFacet = getSelectorsFromAbi(
"/out/CollectableDustFacet.sol/CollectableDustFacet.json"
);
selectorsOfManagerFacet.push(managerFacet.setTreasuryAddress.selector);
selectorsOfManagerFacet.push(
managerFacet.setIncentiveToDollar.selector
selectorsOfCreditNftManagerFacet = getSelectorsFromAbi(
"/out/CreditNftManagerFacet.sol/CreditNftManagerFacet.json"
);
selectorsOfManagerFacet.push(
managerFacet.deployStableSwapPool.selector
selectorsOfCreditNftRedemptionCalculatorFacet = getSelectorsFromAbi(
"/out/CreditNftRedemptionCalculatorFacet.sol/CreditNftRedemptionCalculatorFacet.json"
);
selectorsOfManagerFacet.push(managerFacet.twapOracleAddress.selector);
selectorsOfManagerFacet.push(managerFacet.dollarTokenAddress.selector);
selectorsOfManagerFacet.push(managerFacet.creditTokenAddress.selector);
selectorsOfManagerFacet.push(managerFacet.creditNftAddress.selector);
selectorsOfManagerFacet.push(
managerFacet.curve3PoolTokenAddress.selector
selectorsOfCreditRedemptionCalculatorFacet = getSelectorsFromAbi(
"/out/CreditRedemptionCalculatorFacet.sol/CreditRedemptionCalculatorFacet.json"
);
selectorsOfManagerFacet.push(
managerFacet.governanceTokenAddress.selector
selectorsOfDiamondCutFacet = getSelectorsFromAbi(
"/out/DiamondCutFacet.sol/DiamondCutFacet.json"
);
selectorsOfManagerFacet.push(
managerFacet.sushiSwapPoolAddress.selector
selectorsOfDiamondLoupeFacet = getSelectorsFromAbi(
"/out/DiamondLoupeFacet.sol/DiamondLoupeFacet.json"
);
selectorsOfManagerFacet.push(
managerFacet.creditCalculatorAddress.selector
selectorsOfDollarMintCalculatorFacet = getSelectorsFromAbi(
"/out/DollarMintCalculatorFacet.sol/DollarMintCalculatorFacet.json"
);
selectorsOfManagerFacet.push(
managerFacet.creditNftCalculatorAddress.selector
selectorsOfDollarMintExcessFacet = getSelectorsFromAbi(
"/out/DollarMintExcessFacet.sol/DollarMintExcessFacet.json"
);
selectorsOfManagerFacet.push(
managerFacet.dollarMintCalculatorAddress.selector
);
selectorsOfManagerFacet.push(
managerFacet.excessDollarsDistributor.selector
);
selectorsOfManagerFacet.push(managerFacet.masterChefAddress.selector);
selectorsOfManagerFacet.push(managerFacet.formulasAddress.selector);
selectorsOfManagerFacet.push(managerFacet.stakingShareAddress.selector);
selectorsOfManagerFacet.push(
managerFacet.stableSwapMetaPoolAddress.selector
);
selectorsOfManagerFacet.push(
managerFacet.stakingContractAddress.selector
);
selectorsOfManagerFacet.push(managerFacet.treasuryAddress.selector);

// Access Control
selectorsOfAccessControlFacet.push(
accessControlFacet.grantRole.selector
);
selectorsOfAccessControlFacet.push(accessControlFacet.hasRole.selector);
selectorsOfAccessControlFacet.push(
accessControlFacet.renounceRole.selector
);
selectorsOfAccessControlFacet.push(
accessControlFacet.getRoleAdmin.selector
);
selectorsOfAccessControlFacet.push(
accessControlFacet.revokeRole.selector
);
selectorsOfAccessControlFacet.push(accessControlFacet.pause.selector);
selectorsOfAccessControlFacet.push(accessControlFacet.unpause.selector);
selectorsOfAccessControlFacet.push(accessControlFacet.paused.selector);

// TWAP Oracle
selectorsOfTWAPOracleDollar3poolFacet.push(
twapOracleDollar3PoolFacet.setPool.selector
selectorsOfManagerFacet = getSelectorsFromAbi(
"/out/ManagerFacet.sol/ManagerFacet.json"
);
selectorsOfTWAPOracleDollar3poolFacet.push(
twapOracleDollar3PoolFacet.update.selector
selectorsOfOwnershipFacet = getSelectorsFromAbi(
"/out/OwnershipFacet.sol/OwnershipFacet.json"
);
selectorsOfTWAPOracleDollar3poolFacet.push(
twapOracleDollar3PoolFacet.consult.selector
selectorsOfStakingFacet = getSelectorsFromAbi(
"/out/StakingFacet.sol/StakingFacet.json"
);

// Collectable Dust
selectorsOfCollectableDustFacet.push(
collectableDustFacet.addProtocolToken.selector
);
selectorsOfCollectableDustFacet.push(
collectableDustFacet.removeProtocolToken.selector
);
selectorsOfCollectableDustFacet.push(
collectableDustFacet.sendDust.selector
);
// Chef
selectorsOfChefFacet.push(chefFacet.governanceMultiplier.selector);
selectorsOfChefFacet.push(chefFacet.setGovernancePerBlock.selector);
selectorsOfChefFacet.push(chefFacet.governancePerBlock.selector);
selectorsOfChefFacet.push(chefFacet.governanceDivider.selector);
selectorsOfChefFacet.push(
chefFacet.minPriceDiffToUpdateMultiplier.selector
);
selectorsOfChefFacet.push(
chefFacet.setGovernanceShareForTreasury.selector
);
selectorsOfChefFacet.push(
chefFacet.setMinPriceDiffToUpdateMultiplier.selector
);
selectorsOfChefFacet.push(chefFacet.getRewards.selector);
selectorsOfChefFacet.push(chefFacet.pendingGovernance.selector);
selectorsOfChefFacet.push(chefFacet.getStakingShareInfo.selector);
selectorsOfChefFacet.push(chefFacet.totalShares.selector);
selectorsOfChefFacet.push(chefFacet.pool.selector);

// Staking
selectorsOfStakingFacet.push(stakingFacet.dollarPriceReset.selector);
selectorsOfStakingFacet.push(stakingFacet.crvPriceReset.selector);
selectorsOfStakingFacet.push(
stakingFacet.setStakingDiscountMultiplier.selector
);
selectorsOfStakingFacet.push(
stakingFacet.stakingDiscountMultiplier.selector
);
selectorsOfStakingFacet.push(
stakingFacet.setBlockCountInAWeek.selector
);
selectorsOfStakingFacet.push(stakingFacet.blockCountInAWeek.selector);
selectorsOfStakingFacet.push(stakingFacet.deposit.selector);
selectorsOfStakingFacet.push(stakingFacet.addLiquidity.selector);
selectorsOfStakingFacet.push(stakingFacet.removeLiquidity.selector);
selectorsOfStakingFacet.push(stakingFacet.pendingLpRewards.selector);
selectorsOfStakingFacet.push(stakingFacet.lpRewardForShares.selector);
selectorsOfStakingFacet.push(stakingFacet.currentShareValue.selector);

// Staking Formulas
selectorsOfStakingFormulasFacet.push(
stakingFormulasFacet.sharesForLP.selector
);
selectorsOfStakingFormulasFacet.push(
stakingFormulasFacet.lpRewardsRemoveLiquidityNormalization.selector
);
selectorsOfStakingFormulasFacet.push(
stakingFormulasFacet.lpRewardsAddLiquidityNormalization.selector
);
selectorsOfStakingFormulasFacet.push(
stakingFormulasFacet.correctedAmountToWithdraw.selector
);
selectorsOfStakingFormulasFacet.push(
stakingFormulasFacet.durationMultiply.selector
);

// Credit facets
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.creditNftLengthBlocks.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.expiredCreditNftConversionRate.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.setExpiredCreditNftConversionRate.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.setCreditNftLength.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.exchangeDollarsForCreditNft.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.exchangeDollarsForCredit.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.getCreditNftReturnedForDollars.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.getCreditReturnedForDollars.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.onERC1155Received.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.onERC1155BatchReceived.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.burnExpiredCreditNftForGovernance.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.burnCreditNftForCredit.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.burnCreditTokensForDollars.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.redeemCreditNft.selector
);
selectorsOfCreditNftManagerFacet.push(
creditNftManagerFacet.mintClaimableDollars.selector
);

// Credit NFT Redemption Calculator
selectorsOfCreditNftRedemptionCalculatorFacet.push(
creditNftRedemptionCalculatorFacet.getCreditNftAmount.selector
);

// Credit Redemption Calculator
selectorsOfCreditRedemptionCalculatorFacet.push(
(creditRedemptionCalculatorFacet.setConstant.selector)
);
selectorsOfCreditRedemptionCalculatorFacet.push(
(creditRedemptionCalculatorFacet.getConstant.selector)
);
selectorsOfCreditRedemptionCalculatorFacet.push(
(creditRedemptionCalculatorFacet.getCreditAmount.selector)
);

// Dollar Mint Calculator
selectorsOfDollarMintCalculatorFacet.push(
(dollarMintCalculatorFacet.getDollarsToMint.selector)
selectorsOfStakingFormulasFacet = getSelectorsFromAbi(
"/out/StakingFormulasFacet.sol/StakingFormulasFacet.json"
);
// Dollar Mint Excess
selectorsOfDollarMintExcessFacet.push(
(dollarMintExcessFacet.distributeDollars.selector)
selectorsOfTWAPOracleDollar3poolFacet = getSelectorsFromAbi(
"/out/TWAPOracleDollar3poolFacet.sol/TWAPOracleDollar3poolFacet.json"
);
}
}
3 changes: 2 additions & 1 deletion packages/contracts/test/diamond/DiamondTestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import {DollarMintExcessFacet} from "../../src/dollar/facets/DollarMintExcessFac
import {Diamond, DiamondArgs} from "../../src/dollar/Diamond.sol";
import {DiamondInit} from "../../src/dollar/upgradeInitializers/DiamondInit.sol";
import {DiamondTestHelper} from "../helpers/DiamondTestHelper.sol";
import {UUPSTestHelper} from "../helpers/UUPSTestHelper.sol";
import {ERC1155Ubiquity} from "../../src/dollar/core/ERC1155Ubiquity.sol";
import {BondingCurveFacet} from "../../src/dollar/facets/BondingCurveFacet.sol";
import "../../src/dollar/libraries/Constants.sol";

abstract contract DiamondSetup is DiamondTestHelper {
abstract contract DiamondSetup is DiamondTestHelper, UUPSTestHelper {
// contract types of facets to be deployed
Diamond diamond;
DiamondCutFacet dCutFacet;
Expand Down
5 changes: 2 additions & 3 deletions packages/contracts/test/helpers/DiamondTestHelper.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import "forge-std/Test.sol";
import "../../src/dollar/interfaces/IDiamondCut.sol";
import "../../src/dollar/interfaces/IDiamondLoupe.sol";

import "./UUPSTestHelper.sol";

contract DiamondTestHelper is IDiamondCut, IDiamondLoupe, UUPSTestHelper, Test {
contract DiamondTestHelper is IDiamondCut, IDiamondLoupe, Test {
uint256 private seed;

modifier prankAs(address caller) {
Expand Down

0 comments on commit 060647d

Please sign in to comment.