Skip to content

Commit 07c96e1

Browse files
feat: set constant from public to internal (#260)
Co-authored-by: Robin Le Caignec <[email protected]>
1 parent 786bee4 commit 07c96e1

File tree

6 files changed

+49
-212
lines changed

6 files changed

+49
-212
lines changed

contracts/facets/FacetBase.sol

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,28 @@ import "../interfaces/IOwnable.sol";
1414
*/
1515
abstract contract FacetBase {
1616
// Poco - Constants
17-
uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7;
18-
uint256 public constant REVEAL_DEADLINE_RATIO = 2;
19-
uint256 public constant FINAL_DEADLINE_RATIO = 10;
20-
uint256 public constant WORKERPOOL_STAKE_RATIO = 30;
21-
uint256 public constant KITTY_RATIO = 10;
22-
uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE
17+
uint256 internal constant CONTRIBUTION_DEADLINE_RATIO = 7;
18+
uint256 internal constant REVEAL_DEADLINE_RATIO = 2;
19+
uint256 internal constant FINAL_DEADLINE_RATIO = 10;
20+
uint256 internal constant WORKERPOOL_STAKE_RATIO = 30;
21+
uint256 internal constant KITTY_RATIO = 10;
22+
uint256 internal constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE
2323

2424
// Seized funds of workerpools that do not honor their deals are sent
2525
// out to this kitty address.
2626
// It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1).
27-
address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23;
27+
address internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23;
2828

2929
// Used with ERC-734 Key Manager identity contract for authorization management.
30-
uint256 public constant GROUPMEMBER_PURPOSE = 4;
30+
uint256 internal constant GROUPMEMBER_PURPOSE = 4;
3131

3232
modifier onlyOwner() {
3333
require(_msgSender() == owner(), "Ownable: caller is not the owner");
3434
_;
3535
}
3636

37-
function owner() public view returns (address) {
37+
function owner() internal view returns (address) {
38+
// TODO use LibDiamond.contractOwner() instead of an external call when migrating all contracts to v8.
3839
return IOwnable(address(this)).owner();
3940
}
4041

contracts/facets/FacetBase.v8.sol

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,20 @@ import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol";
1414
*/
1515
abstract contract FacetBase {
1616
// Poco - Constants
17-
uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7;
18-
uint256 public constant REVEAL_DEADLINE_RATIO = 2;
19-
uint256 public constant FINAL_DEADLINE_RATIO = 10;
20-
uint256 public constant WORKERPOOL_STAKE_RATIO = 30;
21-
uint256 public constant KITTY_RATIO = 10;
22-
uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE
17+
uint256 internal constant CONTRIBUTION_DEADLINE_RATIO = 7;
18+
uint256 internal constant REVEAL_DEADLINE_RATIO = 2;
19+
uint256 internal constant FINAL_DEADLINE_RATIO = 10;
20+
uint256 internal constant WORKERPOOL_STAKE_RATIO = 30;
21+
uint256 internal constant KITTY_RATIO = 10;
22+
uint256 internal constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE
2323

2424
// Seized funds of workerpools that do not honor their deals are sent
2525
// out to this kitty address.
2626
// It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1).
27-
address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23;
27+
address internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23;
2828

2929
// Used with ERC-734 Key Manager identity contract for authorization management.
30-
uint256 public constant GROUPMEMBER_PURPOSE = 4;
31-
32-
modifier onlyOwner() {
33-
require(_msgSender() == owner(), "Ownable: caller is not the owner");
34-
_;
35-
}
36-
37-
function owner() public view returns (address) {
38-
// Make an external call to delegatecall the OwnershipFacet.
39-
return IERC5313(address(this)).owner();
40-
}
30+
uint256 internal constant GROUPMEMBER_PURPOSE = 4;
4131

4232
function _msgSender() internal view returns (address) {
4333
return msg.sender;

contracts/facets/IexecAccessorsFacet.sol

Lines changed: 0 additions & 176 deletions
This file was deleted.

scripts/upgrades/accessors/deploy-and-update-accessor-facet.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ import { printFunctions } from '../upgrade-helper';
5757
const newFacetFactory = new IexecPocoAccessorsFacet__factory(iexecLibOrders);
5858
const newFacetAddress = await factoryDeployer.deployContract(newFacetFactory);
5959

60-
console.log('\n=== Step 2: Remove old facets (remove all functions of each facet) ===');
60+
console.log(
61+
'\n=== Step 2: Remove old facets (remove all functions of old accessors facets) ===',
62+
);
6163

6264
const diamondLoupe = DiamondLoupeFacet__factory.connect(diamondProxyAddress, account);
6365
const currentFacets = await diamondLoupe.facets();
@@ -67,17 +69,37 @@ import { printFunctions } from '../upgrade-helper';
6769
console.log(` ${facet.facetAddress}: ${facet.functionSelectors.length} functions`);
6870
});
6971

70-
const oldAccessorFacets = [
71-
'0xEa232be31ab0112916505Aeb7A2a94b5571DCc6b', //IexecAccessorsFacet
72-
'0xeb40697b275413241d9b31dE568C98B3EA12FFF0', //IexecPocoAccessorsFacet
73-
];
74-
7572
console.log('Diamond functions before upgrade:');
7673
await printFunctions(diamondProxyAddress);
7774

7875
const removalCuts: IDiamond.FacetCutStruct[] = [];
76+
const constantFunctionSignatures = [
77+
'CONTRIBUTION_DEADLINE_RATIO()',
78+
'FINAL_DEADLINE_RATIO()',
79+
'GROUPMEMBER_PURPOSE()',
80+
'KITTY_ADDRESS()',
81+
'KITTY_MIN()',
82+
'KITTY_RATIO()',
83+
'REVEAL_DEADLINE_RATIO()',
84+
'WORKERPOOL_STAKE_RATIO()',
85+
];
86+
const constantFunctionsToRemove = constantFunctionSignatures.map((sig) =>
87+
ethers.id(sig).slice(0, 10),
88+
);
89+
console.log(
90+
`Removing specific constant functions from diamond Proxy - will remove ${constantFunctionsToRemove.length} specific constant functions`,
91+
);
92+
removalCuts.push({
93+
facetAddress: ZeroAddress,
94+
action: FacetCutAction.Remove,
95+
functionSelectors: constantFunctionsToRemove,
96+
});
7997

80-
// Remove ALL functions from the old accessor facets using diamondLoupe.facetFunctionSelectors()
98+
const oldAccessorFacets = [
99+
'0xEa232be31ab0112916505Aeb7A2a94b5571DCc6b', //IexecAccessorsFacet
100+
'0xeb40697b275413241d9b31dE568C98B3EA12FFF0', //IexecPocoAccessorsFacet
101+
];
102+
// Remove ALL functions from the old accessor facets using diamondLoupe.facetFunctionSelectors() except of constant founctions
81103
for (const facetAddress of oldAccessorFacets) {
82104
const selectors = await diamondLoupe.facetFunctionSelectors(facetAddress);
83105
if (selectors.length > 0) {

test/byContract/IexecAccessors/IexecAccessors.test.ts renamed to test/byContract/iexecPocoAccessors/IexecPocoAccessors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let [requester, appProvider, datasetProvider, scheduler, worker1, anyone]: Signe
4848
let ordersAssets: OrdersAssets;
4949
let ordersPrices: OrdersPrices;
5050

51-
describe('IexecAccessors', async () => {
51+
describe('IexecPocoAccessors', async () => {
5252
beforeEach('Deploy', async () => {
5353
// Deploy all contracts
5454
proxyAddress = await loadHardhatFixtureDeployment();

utils/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function compactSignature(signature: string): string {
1111
}
1212

1313
export function bigintToAddress(bigint: bigint) {
14-
return ethers.getAddress(ethers.toBeHex(bigint));
14+
return ethers.getAddress(ethers.toBeHex(bigint, 20));
1515
}
1616

1717
export function minBigInt(a: bigint, b: bigint) {

0 commit comments

Comments
 (0)