Skip to content

Commit c96fc5f

Browse files
committed
Add dictionary deployment types: immutable, beacon
1 parent 0165fea commit c96fc5f

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

devkit/core/Dictionary.sol

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import {Validator} from "devkit/system/Validator.sol";
1212
import {ForgeHelper} from "devkit/utils/ForgeHelper.sol";
1313

1414
// External Libs
15-
import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol";
15+
import {IDictionary} from "@ucs.mc/dictionary/interfaces/IDictionary.sol";
1616
import {Dictionary as UCSDictionary} from "@ucs.mc/dictionary/Dictionary.sol";
17+
import {ImmutableDictionary, Function as Func} from "@ucs.mc/dictionary/ImmutableDictionary.sol";
18+
import {BeaconDictionary} from "@ucs.mc/dictionary/BeaconDictionary.sol";
1719
// Mock
1820
import {MockDictionary} from "devkit/test/mocks/MockDictionary.sol";
1921

@@ -60,6 +62,9 @@ library DictionaryLib {
6062

6163
/**-------------------------
6264
🚀 Deploy Dictionary
65+
- Verifiable
66+
- Immutable
67+
- Beacon
6368
---------------------------*/
6469
function deploy(address owner) internal returns(Dictionary memory dictionary) {
6570
uint pid = dictionary.startProcess("deploy", param(owner));
@@ -71,6 +76,31 @@ library DictionaryLib {
7176
return dictionary.finishProcess(pid);
7277
}
7378

79+
function deployImmutable(Function[] storage functions, address facade) internal returns(Dictionary memory dictionary) {
80+
uint pid = dictionary.startProcess("deployImmutable", param(functions, facade));
81+
Validator.SHOULD_FacadeIsContract(facade);
82+
dictionary.startBuilding();
83+
Func[] memory funcs;
84+
for (uint i; i < functions.length; ++i) {
85+
funcs[i] = Func(functions[i].selector, functions[i].implementation);
86+
}
87+
dictionary.addr = address(new ImmutableDictionary(funcs, facade));
88+
dictionary.kind = DictionaryKind.Immutable;
89+
dictionary.finishBuilding();
90+
return dictionary.finishProcess(pid);
91+
}
92+
93+
function deployBeacon(address implementation, address owner) internal returns(Dictionary memory dictionary) {
94+
uint pid = dictionary.startProcess("deployBeacon", param(implementation, owner));
95+
Validator.MUST_AddressIsContract(implementation);
96+
Validator.SHOULD_OwnerIsNotZeroAddress(owner);
97+
dictionary.startBuilding();
98+
dictionary.addr = address(new BeaconDictionary(implementation, owner));
99+
dictionary.kind = DictionaryKind.Beacon;
100+
dictionary.finishBuilding();
101+
return dictionary.finishProcess(pid);
102+
}
103+
74104
/**-----------------------
75105
📩 Load Dictionary
76106
-------------------------*/
@@ -177,6 +207,8 @@ library DictionaryLib {
177207
enum DictionaryKind {
178208
undefined,
179209
Verifiable,
210+
Immutable,
211+
Beacon,
180212
Mock
181213
}
182214
using Inspector for DictionaryKind global;

devkit/system/Tracer.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ function param(Function[] memory functions) pure returns(string memory res) {
347347
res = res.comma(functions[i].name);
348348
}
349349
}
350+
function param(Function[] memory functions, address facade) pure returns(string memory res) {
351+
return param(functions).comma(facade);
352+
}
350353

351354
function param(Bundle memory bundle) pure returns(string memory) {
352355
return bundle.name;

devkit/system/Validator.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ library Validator {
7979
function MUST_AddressIsContract(address addr) internal view {
8080
validate(MUST, addr.isContract(), HEAD.ADDRESS_NOT_CONTRACT, BODY.ADDRESS_NOT_CONTRACT);
8181
}
82+
function SHOULD_FacadeIsContract(address facade) internal view {
83+
validate(SHOULD, facade.isContract(), HEAD.FACADE_NOT_CONTRACT, BODY.FACADE_NOT_CONTRACT);
84+
}
8285
function SHOULD_OwnerIsNotZeroAddress(address owner) internal view {
8386
validate(MUST, owner.isNotZero(), HEAD.OWNER_ZERO_ADDRESS_RECOMMENDED, BODY.OWNER_ZERO_ADDRESS_RECOMMENDED);
8487
}

devkit/system/message/MessageBody.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ library MessageBody {
1111
string constant ENV_KEY_REQUIRED = "The provided environment key cannot be an empty string. Please enter a non-empty value for the key and try again.";
1212
string constant SELECTOR_RECOMMENDED = "The provided function selector is empty (0x00000000). It is recommended to use a non-empty selector.";
1313
string constant ADDRESS_NOT_CONTRACT = "The provided address is not a contract address. Please provide the address of a deployed contract and try again.";
14+
string constant FACADE_NOT_CONTRACT = "The provided facade address is not a contract address. It is recommended to use the address of a deployed facade contract and try again.";
1415
string constant OWNER_ZERO_ADDRESS_RECOMMENDED = "The provided owner address is the zero address (0x0). It is recommended to use a non-zero address for the owner to ensure proper access control and security.";
1516
// Current Context
1617
string constant CURRENT_NAME_NOT_FOUND = "Current Name Not Found";

devkit/system/message/MessageHead.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ library MessageHead {
1111
string constant ENV_KEY_REQUIRED = "EnvKey Required";
1212
string constant SELECTOR_RECOMMENDED = "Empty Selector";
1313
string constant ADDRESS_NOT_CONTRACT = "Address Not Contract";
14+
string constant FACADE_NOT_CONTRACT = "Facade Not Contract";
1415
string constant OWNER_ZERO_ADDRESS_RECOMMENDED = "Owner Zero Address";
1516
// Current Context
1617
string constant CURRENT_NAME_NOT_FOUND = "Current Name Not Found";

devkit/utils/global/MCDeployLib.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ import {NameGenerator} from "devkit/utils/mapping/NameGenerator.sol";
2626
/************************************
2727
* 🚀 Deployment
2828
* 🌞 Deploy Meta Contract
29+
* - Deploy
30+
* - DeployImmutable
31+
* - DeployRestrictedUpgradeable
32+
* - DeployContractUpgradeable
2933
* 🏠 Deploy Proxy
3034
* 📚 Deploy Dictionary
3135
* 🔂 Duplicate Dictionary

0 commit comments

Comments
 (0)