Skip to content

Commit

Permalink
fix: πŸ› optimize the state variables in the 'roles' contract
Browse files Browse the repository at this point in the history
βœ… Closes: #330
  • Loading branch information
siriusyim committed Mar 14, 2024
1 parent c494037 commit 199b23a
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 53 deletions.
21 changes: 21 additions & 0 deletions deploy/09_deploy_escrowchallengeauditcollateral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import "@nomiclabs/hardhat-ethers";
import { deployAndSaveContract } from "../scripts/utils";

const deployFunction: DeployFunction = async function (
hre: HardhatRuntimeEnvironment
) {
const { deployments } = hre;
const roles = await deployments.get("Roles");
await deployAndSaveContract(
"EscrowChallengeAuditCollateral",
[roles.address],
hre
);
};

export default deployFunction;

deployFunction.dependencies = ["Roles"];
deployFunction.tags = ["EscrowChallengeAuditCollateral"];
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
199 changes: 162 additions & 37 deletions src/v0.8/core/access/Roles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,7 @@ contract Roles is
Ownable2StepUpgradeable,
AccessControlEnumerableUpgradeable
{
IFilplus public filplus;
IFinance public finance;
IFilecoin public filecoin;
ICarstore public carstore;
IStorages public storages;
IMerkleUtils public merkleUtils;

IDatasets public datasets;
IDatasetsProof public datasetsProof;
IDatasetsChallenge public datasetsChallenge;
IDatasetsRequirement public datasetsRequirement;

IMatchings public matchings;
IMatchingsBids public matchingsBids;
IMatchingsTarget public matchingsTarget;

IEscrow public escrowDataTradingFee;
IEscrow public escrowDatacapCollateral;
IEscrow public escrowChallengeCommission;
IEscrow public escrowDatacapChunkLandCollateral;
RolesType.DataswapContracts private dataswapContracts;

/// @notice initialize function to initialize the contract and grant the default admin role to the deployer.
function initialize() public initializer {
Expand Down Expand Up @@ -104,41 +85,57 @@ contract Roles is
address _contract
) public onlyOwner {
if (_type == RolesType.ContractType.Filplus) {
filplus = IFilplus(_contract);
dataswapContracts.filplus = IFilplus(_contract);
} else if (_type == RolesType.ContractType.Finance) {
finance = IFinance(_contract);
dataswapContracts.finance = IFinance(_contract);
} else if (_type == RolesType.ContractType.Filecoin) {
filecoin = IFilecoin(_contract);
dataswapContracts.filecoin = IFilecoin(_contract);
} else if (_type == RolesType.ContractType.Carstore) {
carstore = ICarstore(_contract);
dataswapContracts.carstore = ICarstore(_contract);
} else if (_type == RolesType.ContractType.Storages) {
storages = IStorages(_contract);
dataswapContracts.storages = IStorages(_contract);
} else if (_type == RolesType.ContractType.MerkleUtils) {
merkleUtils = IMerkleUtils(_contract);
dataswapContracts.merkleUtils = IMerkleUtils(_contract);
} else if (_type == RolesType.ContractType.Datasets) {
datasets = IDatasets(_contract);
dataswapContracts.datasets = IDatasets(_contract);
} else if (_type == RolesType.ContractType.DatasetsProof) {
datasetsProof = IDatasetsProof(_contract);
dataswapContracts.datasetsProof = IDatasetsProof(_contract);
} else if (_type == RolesType.ContractType.DatasetsChallenge) {
datasetsChallenge = IDatasetsChallenge(_contract);
dataswapContracts.datasetsChallenge = IDatasetsChallenge(_contract);
} else if (_type == RolesType.ContractType.DatasetsRequirement) {
datasetsRequirement = IDatasetsRequirement(_contract);
dataswapContracts.datasetsRequirement = IDatasetsRequirement(
_contract
);
} else if (_type == RolesType.ContractType.Matchings) {
matchings = IMatchings(_contract);
dataswapContracts.matchings = IMatchings(_contract);
} else if (_type == RolesType.ContractType.MatchingsBids) {
matchingsBids = IMatchingsBids(_contract);
dataswapContracts.matchingsBids = IMatchingsBids(_contract);
} else if (_type == RolesType.ContractType.MatchingsTarget) {
matchingsTarget = IMatchingsTarget(_contract);
dataswapContracts.matchingsTarget = IMatchingsTarget(_contract);
} else if (_type == RolesType.ContractType.EscrowDataTradingFee) {
escrowDataTradingFee = IEscrow(_contract);
dataswapContracts.escrowDataTradingFee = IEscrow(_contract);
} else if (
_type == RolesType.ContractType.EscrowDatacapChunkLandCollateral
) {
escrowDatacapChunkLandCollateral = IEscrow(_contract);
dataswapContracts.escrowDatacapChunkLandCollateral = IEscrow(
_contract
);
} else if (_type == RolesType.ContractType.EscrowDatacapCollateral) {
escrowDatacapCollateral = IEscrow(_contract);
dataswapContracts.escrowDatacapCollateral = IEscrow(_contract);
} else if (_type == RolesType.ContractType.EscrowChallengeCommission) {
escrowChallengeCommission = IEscrow(_contract);
dataswapContracts.escrowChallengeCommission = IEscrow(_contract);
} else if (
_type == RolesType.ContractType.EscrowChallengeAuditCollateral
) {
dataswapContracts.escrowChallengeAuditCollateral = IEscrow(
_contract
);
} else if (
_type == RolesType.ContractType.EscrowDisputeAuditCollateral
) {
dataswapContracts.escrowDisputeAuditCollateral = IEscrow(_contract);
} else if (_type == RolesType.ContractType.EscrowProofAuditCollateral) {
dataswapContracts.escrowProofAuditCollateral = IEscrow(_contract);
} else {
require(false, "Invalid RolesType.ContractType");

Check warning on line 140 in src/v0.8/core/access/Roles.sol

View workflow job for this annotation

GitHub Actions / solhint (0.8.21)

Use Custom Errors instead of require statements

Check warning on line 140 in src/v0.8/core/access/Roles.sol

View workflow job for this annotation

GitHub Actions / solhint (0.8.21)

Use Custom Errors instead of require statements
}
Expand Down Expand Up @@ -214,4 +211,132 @@ contract Roles is
) internal override(OwnableUpgradeable, Ownable2StepUpgradeable) {
super._transferOwnership(_newOwner);
}

/// @notice Get the Filplus contract.
/// @return Filplus contract address.
function filplus() external view returns (IFilplus) {
return dataswapContracts.filplus;
}

/// @notice Get the Finance contract.
/// @return Finance contract address.
function finance() external view returns (IFinance) {
return dataswapContracts.finance;
}

/// @notice Get the Filecoin contract.
/// @return Filecoin contract address.
function filecoin() external view returns (IFilecoin) {
return dataswapContracts.filecoin;
}

/// @notice Get the Carstore contract.
/// @return Carstore contract address.
function carstore() external view returns (ICarstore) {
return dataswapContracts.carstore;
}

/// @notice Get the Storages contract.
/// @return Storages contract address.
function storages() external view returns (IStorages) {
return dataswapContracts.storages;
}

/// @notice Get the MerkleUtils contract.
/// @return MerkleUtils contract address.
function merkleUtils() external view returns (IMerkleUtils) {
return dataswapContracts.merkleUtils;
}

/// @notice Get the Datasets contract.
/// @return Datasets contract address.
function datasets() external view returns (IDatasets) {
return dataswapContracts.datasets;
}

/// @notice Get the DatasetsProof contract.
/// @return DatasetsProof contract address.
function datasetsProof() external view returns (IDatasetsProof) {
return dataswapContracts.datasetsProof;
}

/// @notice Get the DatasetsChallenge contract.
/// @return DatasetsChallenge contract address.
function datasetsChallenge() external view returns (IDatasetsChallenge) {
return dataswapContracts.datasetsChallenge;
}

/// @notice Get the DatasetsRequirement contract.
/// @return DatasetsRequirement contract address.
function datasetsRequirement()
external
view
returns (IDatasetsRequirement)
{
return dataswapContracts.datasetsRequirement;
}

/// @notice Get the Matchings contract.
/// @return Matchings contract address.
function matchings() external view returns (IMatchings) {
return dataswapContracts.matchings;
}

/// @notice Get the MatchingsBids contract.
/// @return MatchingsBids contract address.
function matchingsBids() external view returns (IMatchingsBids) {
return dataswapContracts.matchingsBids;
}

/// @notice Get the MatchingsTarget contract.
/// @return MatchingsTarget contract address.
function matchingsTarget() external view returns (IMatchingsTarget) {
return dataswapContracts.matchingsTarget;
}

/// @notice Get the EscrowDataTradingFee contract.
/// @return EscrowDataTradingFee contract address.
function escrowDataTradingFee() external view returns (IEscrow) {
return dataswapContracts.escrowDataTradingFee;
}

/// @notice Get the EscrowDatacapChunkLandCollateral contract.
/// @return EscrowDatacapChunkLandCollateral contract address.
function escrowDatacapChunkLandCollateral()
external
view
returns (IEscrow)
{
return dataswapContracts.escrowDatacapChunkLandCollateral;
}

/// @notice Get the EscrowChallengeCommission contract.
/// @return EscrowChallengeCommission contract address.
function escrowChallengeCommission() external view returns (IEscrow) {
return dataswapContracts.escrowChallengeCommission;
}

/// @notice Get the EscrowDatacapCollateral contract.
/// @return EscrowDatacapCollateral contract address.
function escrowDatacapCollateral() external view returns (IEscrow) {
return dataswapContracts.escrowDatacapCollateral;
}

/// @notice Get the EscrowChallengeAuditCollateral contract.
/// @return EscrowChallengeAuditCollateral contract address.
function escrowChallengeAuditCollateral() external view returns (IEscrow) {
return dataswapContracts.escrowChallengeAuditCollateral;
}

/// @notice Get the EscrowDisputeAuditCollateral contract.
/// @return EscrowDisputeAuditCollateral contract address.
function escrowDisputeAuditCollateral() external view returns (IEscrow) {
return dataswapContracts.escrowDisputeAuditCollateral;
}

/// @notice Get the EscrowProofAuditCollateral contract.
/// @return EscrowProofAuditCollateral contract address.
function escrowProofAuditCollateral() external view returns (IEscrow) {
return dataswapContracts.escrowProofAuditCollateral;
}
}
6 changes: 6 additions & 0 deletions src/v0.8/core/finance/Finance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ contract Finance is
base = roles.escrowChallengeCommission();
} else if (_type == FinanceType.Type.EscrowDatacapCollateral) {
base = roles.escrowDatacapCollateral();
} else if (_type == FinanceType.Type.EscrowChallengeAuditCollateral) {
base = roles.escrowChallengeAuditCollateral();
} else if (_type == FinanceType.Type.EscrowDisputeAuditCollateral) {
base = roles.escrowDisputeAuditCollateral();
} else if (_type == FinanceType.Type.EscrowProofAuditCollateral) {
base = roles.escrowProofAuditCollateral();
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/v0.8/interfaces/core/IRoles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,16 @@ interface IRoles is IAccessControlEnumerableUpgradeable {
/// @notice Get the EscrowDatacapCollateral contract.
/// @return EscrowDatacapCollateral contract address.
function escrowDatacapCollateral() external view returns (IEscrow);

/// @notice Get the EscrowChallengeAuditCollateral contract.
/// @return EscrowChallengeAuditCollateral contract address.
function escrowChallengeAuditCollateral() external view returns (IEscrow);

/// @notice Get the EscrowDisputeAuditCollateral contract.
/// @return EscrowDisputeAuditCollateral contract address.
function escrowDisputeAuditCollateral() external view returns (IEscrow);

/// @notice Get the EscrowProofAuditCollateral contract.
/// @return EscrowProofAuditCollateral contract address.
function escrowProofAuditCollateral() external view returns (IEscrow);
}
43 changes: 42 additions & 1 deletion src/v0.8/types/RolesType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.21;
import {IRoles} from "src/v0.8/interfaces/core/IRoles.sol";
import {IEscrow} from "src/v0.8/interfaces/core/IEscrow.sol";
import {IFilplus} from "src/v0.8/interfaces/core/IFilplus.sol";
import {IFinance} from "src/v0.8/interfaces/core/IFinance.sol";
import {IFilecoin} from "src/v0.8/interfaces/core/IFilecoin.sol";
import {ICarstore} from "src/v0.8/interfaces/core/ICarstore.sol";
import {IStorages} from "src/v0.8/interfaces/module/IStorages.sol";
import {IMerkleUtils} from "src/v0.8/interfaces/utils/IMerkleUtils.sol";
import {IDatasets} from "src/v0.8/interfaces/module/IDatasets.sol";
import {IDatasetsProof} from "src/v0.8/interfaces/module/IDatasetsProof.sol";
import {IDatasetsChallenge} from "src/v0.8/interfaces/module/IDatasetsChallenge.sol";
import {IDatasetsRequirement} from "src/v0.8/interfaces/module/IDatasetsRequirement.sol";
import {IMatchings} from "src/v0.8/interfaces/module/IMatchings.sol";
import {IMatchingsBids} from "src/v0.8/interfaces/module/IMatchingsBids.sol";
import {IMatchingsTarget} from "src/v0.8/interfaces/module/IMatchingsTarget.sol";

/// @title RolesType Library
/// @notice This library defines constants for different roles within the system.
Expand Down Expand Up @@ -45,6 +60,32 @@ library RolesType {
EscrowDataTradingFee,
EscrowDatacapChunkLandCollateral,
EscrowDatacapCollateral,
EscrowChallengeCommission
EscrowChallengeCommission,
EscrowChallengeAuditCollateral,
EscrowDisputeAuditCollateral,
EscrowProofAuditCollateral
}

struct DataswapContracts {
IFilplus filplus;
IFinance finance;
IFilecoin filecoin;
ICarstore carstore;
IStorages storages;
IMerkleUtils merkleUtils;
IDatasets datasets;
IDatasetsProof datasetsProof;
IDatasetsChallenge datasetsChallenge;
IDatasetsRequirement datasetsRequirement;
IMatchings matchings;
IMatchingsBids matchingsBids;
IMatchingsTarget matchingsTarget;
IEscrow escrowDataTradingFee;
IEscrow escrowDatacapCollateral;
IEscrow escrowChallengeCommission;
IEscrow escrowDatacapChunkLandCollateral;
IEscrow escrowChallengeAuditCollateral;
IEscrow escrowDisputeAuditCollateral;
IEscrow escrowProofAuditCollateral;
}
}
Loading

0 comments on commit 199b23a

Please sign in to comment.