From 8c413c819d8ec541c3835aad7ef5e3c1c47fd7c4 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 13:32:21 +0900 Subject: [PATCH 001/111] CI: Add install with template --- .github/workflows/ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d587b7c..03e63ed6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,23 @@ jobs: run: | forge test + install-with-template-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + - name: Run forge install + run: | + mkdir /tmp/install-with-template-test + cd /tmp/install-with-template-test + forge init mc-example-project -t metacontract/template + forge test + # slither: # runs-on: ubuntu-latest # steps: From b4b7815ef4d54ae0e6759d8094328958fbad1a2a Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 13:54:05 +0900 Subject: [PATCH 002/111] Update deploy script --- .../DeployDefaultDictionaryUpgradeable.s.sol | 18 ------------------ script/DeployLib.sol | 8 ++++---- script/DeployNewProxyScript.s.sol | 15 --------------- script/DeployStdDictionary.s.sol | 18 ++++++++++++++++++ ...{Deploy.s.sol => DeployStdFunctions.s.sol} | 4 ++-- script/deploy.sh | 19 ------------------- script/verify.sh | 12 ------------ test/std/bundles/Std.t.sol | 2 +- 8 files changed, 25 insertions(+), 71 deletions(-) delete mode 100644 script/DeployDefaultDictionaryUpgradeable.s.sol delete mode 100644 script/DeployNewProxyScript.s.sol create mode 100644 script/DeployStdDictionary.s.sol rename script/{Deploy.s.sol => DeployStdFunctions.s.sol} (81%) delete mode 100644 script/deploy.sh delete mode 100644 script/verify.sh diff --git a/script/DeployDefaultDictionaryUpgradeable.s.sol b/script/DeployDefaultDictionaryUpgradeable.s.sol deleted file mode 100644 index 0bca6ebf..00000000 --- a/script/DeployDefaultDictionaryUpgradeable.s.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import {MCScript} from "devkit/MCScript.sol"; -// import {UCSContractList} from "utils/common/UCSTypes.sol"; -// import "@devkit/MCDevKit.sol"; - -// import {UCSDeployUtils} from "../utils/UCSDeployUtils.sol"; - -contract DeployDefaultDictionaryUpgradeableEtherscanScript is MCScript { - // using UCSDeployUtils for UCSDeployUtils.UCS; - function setUp() public startBroadcastWithDeployerPrivKey {} - - function run() public { - // address dictionary = mc.deployDeafultDictionaryUpgradeableEtherscan(); - // address dictionary = mc.deploy(UCSContractList.DeafultDictionaryUpgradeableEtherscan); - } -} diff --git a/script/DeployLib.sol b/script/DeployLib.sol index 253aea82..b850dd3c 100755 --- a/script/DeployLib.sol +++ b/script/DeployLib.sol @@ -4,17 +4,17 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; import {StdFunctions} from "devkit/ucs/functions/StdFunctions.sol"; - -using DeployLib for MCDevKit; library DeployLib { + using DeployLib for MCDevKit; string internal constant BUNDLE_NAME = "Std"; - function deployStdIfNotExists(MCDevKit storage mc) internal { + function deployStdFunctions(MCDevKit storage mc) internal returns(MCDevKit storage) { mc.functions.std.deployIfNotExists(); + return mc; } function deployStdDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { - mc.deployStdIfNotExists(); + mc.deployStdFunctions(); mc.deployDictionary(mc.functions.std.all); return mc; } diff --git a/script/DeployNewProxyScript.s.sol b/script/DeployNewProxyScript.s.sol deleted file mode 100644 index d1606a30..00000000 --- a/script/DeployNewProxyScript.s.sol +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import {MCScript} from "devkit/MCScript.sol"; -// import {IClone} from "@mc-std/interfaces/functions/IClone.sol"; - -contract DeployNewProxyScript is MCScript { - function run() public startBroadcastWithDeployerPrivKey { - // address proxy = newProxy(); - // address dictionary = getDictionary(proxy); - // opNames.push(OpName.Clone); - // setOps(dictionary, mc.opNames); - // ICloneOp(proxy).clone(""); - } -} diff --git a/script/DeployStdDictionary.s.sol b/script/DeployStdDictionary.s.sol new file mode 100644 index 00000000..f5a64241 --- /dev/null +++ b/script/DeployStdDictionary.s.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {MCScriptWithoutSetup} from "devkit/MCScript.sol"; +import {DeployLib} from "./DeployLib.sol"; +import {MCDevKit} from "devkit/MCDevKit.sol"; + +contract DeployStdDictionary is MCScriptWithoutSetup { + using DeployLib for MCDevKit; + + function setUp() public { + mc.functions.std.assignAndLoad(); + } + + function run() public startBroadcastWith("DEPLOYER_PRIV_KEY") { + mc.deployStdDictionary(); + } +} diff --git a/script/Deploy.s.sol b/script/DeployStdFunctions.s.sol similarity index 81% rename from script/Deploy.s.sol rename to script/DeployStdFunctions.s.sol index 15a7f5a6..7c5a5f73 100644 --- a/script/Deploy.s.sol +++ b/script/DeployStdFunctions.s.sol @@ -5,7 +5,7 @@ import {MCScriptWithoutSetup} from "devkit/MCScript.sol"; import {DeployLib} from "./DeployLib.sol"; import {MCDevKit} from "devkit/MCDevKit.sol"; -contract DeployScript is MCScriptWithoutSetup { +contract DeployStdFunctions is MCScriptWithoutSetup { using DeployLib for MCDevKit; function setUp() public { @@ -13,6 +13,6 @@ contract DeployScript is MCScriptWithoutSetup { } function run() public startBroadcastWith("DEPLOYER_PRIV_KEY") { - mc.deployStdIfNotExists(); + mc.deployStdFunctions(); } } diff --git a/script/deploy.sh b/script/deploy.sh deleted file mode 100644 index 8e381f43..00000000 --- a/script/deploy.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env sh -source .env - -script="forge script UCSDeployScript -vvvvv" -rpc="--rpc-url $RPC_URL" -verify="--verify --verifier-url $VERIFIER --etherscan-api-key $ETHERSCAN_API_KEY" - -dryrun="$script $rpc" -run="$dryrun $verify --broadcast" - -# eval "$run --sig 'deployProxyEtherscan()'" -# eval "$dryrun --sig 'deployProxyEtherscan()'" -# eval "$dryrun --sig 'deployDictionaryUpgradeableEtherscan()'" -# eval "$run --sig 'upgradeDefaultFacadeToV2(address)' $DICTIONARY_UPGRADEABLE_ETHERSCAN" -# eval "$run --sig 'getOrCreateDefaultOpsFacadeV2()'" -# eval "$run --sig 'setDefaultOps(address)' $DICTIONARY_UPGRADEABLE_ETHERSCAN" -eval "$run --sig 'setEtherscanOps(address)' $DICTIONARY_UPGRADEABLE_ETHERSCAN" - -# eval "$dryrun --sig 'getDeps()'" diff --git a/script/verify.sh b/script/verify.sh deleted file mode 100644 index 0cd58471..00000000 --- a/script/verify.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env sh -source .env -# forge verify-contract $INIT_SET_ADMIN_OP InitSetAdminOp --verifier-url $VERIFIER --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia -# forge verify-contract $SET_IMPLEMENTATION_OP SetImplementationOp --verifier-url $VERIFIER --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia -# forge verify-contract $DEFAULT_OPS_FACADE DefaultOpsFacade --verifier-url $VERIFIER --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia -# forge verify-contract $DICTIONARY_UPGRADEABLE_IMPL DictionaryUpgradeable --verifier-url $VERIFIER --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia -# forge verify-contract $DICTIONARY_UPGRADEABLE_ETHERSCAN_IMPL DictionaryUpgradeableEtherscan --verifier-url $VERIFIER --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia -# forge verify-contract $DICTIONARY_UPGRADEABLE_ETHERSCAN DictionaryUpgradeableEtherscanProxy --verifier-url $VERIFIER --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia --constructor-args $DICTIONARY_UPGRADEABLE_ETHERSCAN_ARGS -# forge verify-contract $UCS_DEPLOYER UCSDeployer --verifier-url $VERIFIER --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia --constructor-args $UCS_DEPLOYER_ARGS - -# forge verify-contract $DICTIONARY_ETHERSCAN DictionaryEtherscan --verifier-url $VERIFIER --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia --constructor-args $DICTIONARY_ETHERSCAN_ARGS -forge verify-contract $PROXY_ETHERSCAN ERC7546ProxyEtherscan --verifier-url $VERIFIER --etherscan-api-key $ETHERSCAN_API_KEY --chain sepolia --constructor-args $PROXY_ETHERSCAN_ARGS diff --git a/test/std/bundles/Std.t.sol b/test/std/bundles/Std.t.sol index 37d13d19..e2a67a56 100644 --- a/test/std/bundles/Std.t.sol +++ b/test/std/bundles/Std.t.sol @@ -13,6 +13,6 @@ contract StdTest is MCDevKitTest { } function test_Success_DeployStdFunctions() public startPrankWith("TEST_DEPLOYER") { - mc.deployStdIfNotExists(); + mc.deployStdFunctions(); } } From 68eb759209f55bce064db66d62de13a9c8db5cce Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 14:04:17 +0900 Subject: [PATCH 003/111] Update MCSetupTest --- test/devkit/global/{Setup.t.sol => MCSetup.t.sol} | 3 +++ 1 file changed, 3 insertions(+) rename test/devkit/global/{Setup.t.sol => MCSetup.t.sol} (88%) diff --git a/test/devkit/global/Setup.t.sol b/test/devkit/global/MCSetup.t.sol similarity index 88% rename from test/devkit/global/Setup.t.sol rename to test/devkit/global/MCSetup.t.sol index 205facf4..6f29a93f 100644 --- a/test/devkit/global/Setup.t.sol +++ b/test/devkit/global/MCSetup.t.sol @@ -9,6 +9,9 @@ import {TestHelper} from "test/utils/TestHelper.sol"; contract DevKitTest_MCSetup is MCDevKitTest { + /**---------------------------- + 🧩 Setup Standard Funcs + ------------------------------*/ function test_Success_setupStdFuncs() public { mc.setupStdFunctions(); From 24f38ef55a205860fb20c2db4ee55051bdc492e7 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 15:53:56 +0900 Subject: [PATCH 004/111] Add toBytes to StringUtils --- devkit/utils/StringUtils.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/devkit/utils/StringUtils.sol b/devkit/utils/StringUtils.sol index a7dd7095..3ec92c1c 100644 --- a/devkit/utils/StringUtils.sol +++ b/devkit/utils/StringUtils.sol @@ -46,6 +46,14 @@ library StringUtils { } + /**----------------------- + 🔀 Type Convertor + -------------------------*/ + function toBytes(string memory str) internal returns (bytes memory) { + return bytes(str); + } + + /**---------------- ➕ Append ------------------*/ From 0c5503427bd5e59073895fe84d863bc4c0b8c5d7 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 15:54:23 +0900 Subject: [PATCH 005/111] Add message method to ERR lib --- devkit/error/Error.sol | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/devkit/error/Error.sol b/devkit/error/Error.sol index fbefb9ed..1b12482c 100644 --- a/devkit/error/Error.sol +++ b/devkit/error/Error.sol @@ -11,7 +11,7 @@ import {Logger} from "devkit/debug/Logger.sol"; function throwError(string memory errorBody) { Logger.logError(errorBody); - revert(StringUtils.append(ERR.HEADER, errorBody).bold()); + revert(ERR.message(errorBody)); } library ERR { @@ -19,4 +19,8 @@ library ERR { string constant FIND_NAME_OVER_RANGE = "Default names are automatically set up to 5. Please manually assign names beyond that."; // string constant STR_EMPTY = "Empty String"; // string constant STR_EXISTS = "String Already Exist"; + + function message(string memory errorBody) internal returns(string memory) { + return StringUtils.append(HEADER, errorBody).bold(); + } } From 71db9d57fbb588f6f7235d98c5ab4dcf80670660 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 15:54:49 +0900 Subject: [PATCH 006/111] Fix Function to use memory params --- devkit/ucs/functions/Function.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devkit/ucs/functions/Function.sol b/devkit/ucs/functions/Function.sol index 24f963bd..4b98da62 100644 --- a/devkit/ucs/functions/Function.sol +++ b/devkit/ucs/functions/Function.sol @@ -165,7 +165,7 @@ library FunctionLib { return functionInfo; } - function isEqual(Function storage a, Function storage b) internal pure returns(bool) { + function isEqual(Function memory a, Function memory b) internal pure returns(bool) { return keccak256(abi.encode(a)) == keccak256(abi.encode(b)); } From 7285289f1f3127bec30bb97dbe94e124da0fe611 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 15:55:06 +0900 Subject: [PATCH 007/111] Add DummyFunction contract for test --- test/utils/DummyFunction.sol | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 test/utils/DummyFunction.sol diff --git a/test/utils/DummyFunction.sol b/test/utils/DummyFunction.sol new file mode 100644 index 00000000..c574930f --- /dev/null +++ b/test/utils/DummyFunction.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +contract DummyFunction { + function dummy() external {} +} From c3cd35cd1d14ab099382ae1773118908ab1884e7 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 15:55:59 +0900 Subject: [PATCH 008/111] Add {use} tests to MCBundleTest --- .../global/{Bundle.t.sol => MCBundle.t.sol} | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) rename test/devkit/global/{Bundle.t.sol => MCBundle.t.sol} (53%) diff --git a/test/devkit/global/Bundle.t.sol b/test/devkit/global/MCBundle.t.sol similarity index 53% rename from test/devkit/global/Bundle.t.sol rename to test/devkit/global/MCBundle.t.sol index a158e4a0..f37fa7ca 100644 --- a/test/devkit/global/Bundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -6,6 +6,11 @@ import {MCDevKitTest} from "devkit/MCTest.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; import {Config} from "devkit/config/Config.sol"; +import {ERR} from "devkit/error/Error.sol"; + +import {Bundle} from "devkit/ucs/functions/Bundle.sol"; +import {Function} from "devkit/ucs/functions/Function.sol"; +import {DummyFunction} from "test/utils/DummyFunction.sol"; contract DevKitTest_MCBundle is MCDevKitTest { /**--------------------------- @@ -50,6 +55,37 @@ contract DevKitTest_MCBundle is MCDevKitTest { /**--------------------- 🔗 Use Function -----------------------*/ + function test_Success_use() public { + string memory bundleName = mc.functions.genUniqueBundleName(); + string memory functionName = "DummyFunction"; + bytes4 selector = DummyFunction.dummy.selector; + address impl = address(new DummyFunction()); + + mc.use(functionName, selector, impl); + + Bundle memory bundle = mc.functions.bundles[bundleName.safeCalcHash()]; + assertEq(bundle.name, bundleName); + assertEq(bundle.facade, address(0)); + Function memory func = mc.functions.customs[functionName.safeCalcHash()]; + assertEq(func.name, functionName); + assertEq(func.selector, selector); + assertEq(func.implementation, impl); + assertTrue(bundle.functionInfos[0].isEqual(func)); + assertEq(mc.functions.currentFunctionName, functionName); + } + + function test_Success_use_withSameName() public { + string memory bundleName = mc.functions.genUniqueBundleName(); + string memory functionName = "DummyFunction"; + bytes4 selector = DummyFunction.dummy.selector; + address impl = address(new DummyFunction()); + + mc.use(functionName, selector, impl); + + vm.expectRevert(ERR.message("Name Already Exist").toBytes()); + mc.use(functionName, selector, impl); + } + /**------------------ đŸĒŸ Use Facade --------------------*/ From f6fe6a98b2b2a98cefb89a41af4fc49641a1e552 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 16:23:32 +0900 Subject: [PATCH 009/111] Update {use} MCBundleTest --- test/devkit/global/MCBundle.t.sol | 39 +++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index f37fa7ca..a7620d2d 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -55,14 +55,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { /**--------------------- 🔗 Use Function -----------------------*/ - function test_Success_use() public { - string memory bundleName = mc.functions.genUniqueBundleName(); - string memory functionName = "DummyFunction"; - bytes4 selector = DummyFunction.dummy.selector; - address impl = address(new DummyFunction()); - - mc.use(functionName, selector, impl); - + function assertFunctionAdded(string memory bundleName, uint256 functionsIndex, string memory functionName, bytes4 selector, address impl) internal { Bundle memory bundle = mc.functions.bundles[bundleName.safeCalcHash()]; assertEq(bundle.name, bundleName); assertEq(bundle.facade, address(0)); @@ -70,11 +63,22 @@ contract DevKitTest_MCBundle is MCDevKitTest { assertEq(func.name, functionName); assertEq(func.selector, selector); assertEq(func.implementation, impl); - assertTrue(bundle.functionInfos[0].isEqual(func)); + assertTrue(bundle.functionInfos[functionsIndex].isEqual(func)); assertEq(mc.functions.currentFunctionName, functionName); } - function test_Success_use_withSameName() public { + function test_Success_use() public { + string memory bundleName = mc.functions.genUniqueBundleName(); + string memory functionName = "DummyFunction"; + bytes4 selector = DummyFunction.dummy.selector; + address impl = address(new DummyFunction()); + + mc.use(functionName, selector, impl); + + assertFunctionAdded(bundleName, 0, functionName, selector, impl); + } + + function test_Revert_use_withSameName() public { string memory bundleName = mc.functions.genUniqueBundleName(); string memory functionName = "DummyFunction"; bytes4 selector = DummyFunction.dummy.selector; @@ -86,6 +90,21 @@ contract DevKitTest_MCBundle is MCDevKitTest { mc.use(functionName, selector, impl); } + function test_Success_use_withDifferentName() public { + string memory bundleName = mc.functions.genUniqueBundleName(); + + string memory functionName = "DummyFunction"; + string memory functionName2 = "DummyFunction2"; + bytes4 selector = DummyFunction.dummy.selector; + address impl = address(new DummyFunction()); + + mc.use(functionName, selector, impl); + mc.use(functionName2, selector, impl); + + assertFunctionAdded(bundleName, 1, functionName2, selector, impl); + } + + /**------------------ đŸĒŸ Use Facade --------------------*/ From a2e9d346d5a7215c2a09b8e5c1e3a588b013e0ed Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 17:04:40 +0900 Subject: [PATCH 010/111] Add useFacade tests --- test/devkit/global/MCBundle.t.sol | 12 ++++++++++++ test/utils/DummyFacade.sol | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 test/utils/DummyFacade.sol diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index a7620d2d..a86ac88e 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -11,6 +11,7 @@ import {ERR} from "devkit/error/Error.sol"; import {Bundle} from "devkit/ucs/functions/Bundle.sol"; import {Function} from "devkit/ucs/functions/Function.sol"; import {DummyFunction} from "test/utils/DummyFunction.sol"; +import {DummyFacade} from "test/utils/DummyFacade.sol"; contract DevKitTest_MCBundle is MCDevKitTest { /**--------------------------- @@ -108,4 +109,15 @@ contract DevKitTest_MCBundle is MCDevKitTest { /**------------------ đŸĒŸ Use Facade --------------------*/ + function test_Success_useFacade() public { + address facade = address(new DummyFacade()); + mc.init(); + mc.useFacade(facade); + } + + function test_Revert_useFacade_withoutInit() public { + address facade = address(new DummyFacade()); + vm.expectRevert(ERR.message(ERR.NOT_INIT).toBytes()); + mc.useFacade(facade); + } } diff --git a/test/utils/DummyFacade.sol b/test/utils/DummyFacade.sol new file mode 100644 index 00000000..b4d84282 --- /dev/null +++ b/test/utils/DummyFacade.sol @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +contract DummyFacade {} From 0abf14b4ce9bb31ba86c76f06eff16bde266e473 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 17:05:09 +0900 Subject: [PATCH 011/111] Update useFacade() --- devkit/error/Error.sol | 1 + devkit/global/MCBundleLib.sol | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/devkit/error/Error.sol b/devkit/error/Error.sol index 1b12482c..6df222ea 100644 --- a/devkit/error/Error.sol +++ b/devkit/error/Error.sol @@ -19,6 +19,7 @@ library ERR { string constant FIND_NAME_OVER_RANGE = "Default names are automatically set up to 5. Please manually assign names beyond that."; // string constant STR_EMPTY = "Empty String"; // string constant STR_EXISTS = "String Already Exist"; + string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; function message(string memory errorBody) internal returns(string memory) { return StringUtils.append(HEADER, errorBody).bold(); diff --git a/devkit/global/MCBundleLib.sol b/devkit/global/MCBundleLib.sol index 1265e83d..954a8ee8 100644 --- a/devkit/global/MCBundleLib.sol +++ b/devkit/global/MCBundleLib.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Validation import {check} from "devkit/error/Validation.sol"; +import {ERR} from "devkit/error/Error.sol"; // Utils import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {Params} from "devkit/debug/Params.sol"; @@ -94,14 +95,11 @@ library MCBundleLib { /**------------------ đŸĒŸ Use Facade --------------------*/ - function useFacade(MCDevKit storage mc, string memory name, address facade) internal returns(MCDevKit storage) { + function useFacade(MCDevKit storage mc, address facade) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("set"); - mc.functions.set(name, facade); + check(mc.functions.existsCurrentBundle(), ERR.NOT_INIT); + mc.functions.set(mc.functions.findCurrentBundleName(), facade); return mc.recordExecFinish(pid); } - function useFacade(MCDevKit storage mc, address facade) internal returns(MCDevKit storage) { - return mc.useFacade(mc.functions.findCurrentBundleName(), facade); - } - } From 7941383c02f3bbeb10537baa392544ac1668d881 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 17:15:43 +0900 Subject: [PATCH 012/111] Chore update var name bundle & function --- devkit/ucs/functions/Bundle.sol | 98 +++++++++++++++---------------- devkit/ucs/functions/Function.sol | 84 +++++++++++++------------- 2 files changed, 91 insertions(+), 91 deletions(-) diff --git a/devkit/ucs/functions/Bundle.sol b/devkit/ucs/functions/Bundle.sol index c3177a61..24465cfd 100644 --- a/devkit/ucs/functions/Bundle.sol +++ b/devkit/ucs/functions/Bundle.sol @@ -37,103 +37,103 @@ library BundleUtils { function recordExecStart(string memory funcName) internal returns(uint) { return recordExecStart(funcName, ""); } - function recordExecFinish(Bundle storage bundleInfo, uint pid) internal returns(Bundle storage) { + function recordExecFinish(Bundle storage bundle, uint pid) internal returns(Bundle storage) { Debug.recordExecFinish(pid); - return bundleInfo; + return bundle; } /**--------------------------- đŸ“Ĩ Assign Bundle -----------------------------*/ - function safeAssign(Bundle storage bundleInfo, string memory name) internal returns(Bundle storage) { + function safeAssign(Bundle storage bundle, string memory name) internal returns(Bundle storage) { uint pid = recordExecStart("safeAssign"); - bundleInfo.name = name.assertNotEmpty(); - return bundleInfo.recordExecFinish(pid); + bundle.name = name.assertNotEmpty(); + return bundle.recordExecFinish(pid); } - function safeAssign(Bundle storage bundleInfo, address facade) internal returns(Bundle storage) { + function safeAssign(Bundle storage bundle, address facade) internal returns(Bundle storage) { uint pid = recordExecStart("safeAssign"); - bundleInfo.facade = facade.assertIsContract(); - return bundleInfo.recordExecFinish(pid); + bundle.facade = facade.assertIsContract(); + return bundle.recordExecFinish(pid); } - function safeAdd(Bundle storage bundleInfo, Function storage functionInfo) internal returns(Bundle storage) { + function safeAdd(Bundle storage bundle, Function storage functionInfo) internal returns(Bundle storage) { uint pid = recordExecStart("safeAdd"); - check(bundleInfo.hasNot(functionInfo), "Already added"); - bundleInfo.functionInfos.push( + check(bundle.hasNot(functionInfo), "Already added"); + bundle.functionInfos.push( functionInfo.assertImplIsContract() ); - return bundleInfo.recordExecFinish(pid); + return bundle.recordExecFinish(pid); } - function safeAdd(Bundle storage bundleInfo, Function[] storage functionInfos) internal returns(Bundle storage) { + function safeAdd(Bundle storage bundle, Function[] storage functionInfos) internal returns(Bundle storage) { uint pid = recordExecStart("safeAdd"); for (uint i; i < functionInfos.length; ++i) { - bundleInfo.safeAdd(functionInfos[i]); + bundle.safeAdd(functionInfos[i]); } - return bundleInfo.recordExecFinish(pid); + return bundle.recordExecFinish(pid); } /**------------------------------- 🧐 Inspectors & Assertions ---------------------------------*/ - function has(Bundle storage bundleInfo, Function storage functionInfo) internal view returns(bool flag) { - for (uint i; i < bundleInfo.functionInfos.length; ++i) { - if (functionInfo.isEqual(bundleInfo.functionInfos[i])) return true; + function has(Bundle storage bundle, Function storage functionInfo) internal view returns(bool flag) { + for (uint i; i < bundle.functionInfos.length; ++i) { + if (functionInfo.isEqual(bundle.functionInfos[i])) return true; } } - function hasNot(Bundle storage bundleInfo, Function storage functionInfo) internal returns(bool) { - return bundleInfo.has(functionInfo).isFalse(); + function hasNot(Bundle storage bundle, Function storage functionInfo) internal returns(bool) { + return bundle.has(functionInfo).isFalse(); } - function isComplete(Bundle storage bundleInfo) internal returns(bool) { - return bundleInfo.name.isNotEmpty() && - bundleInfo.functionInfos.length != 0 && - bundleInfo.facade.isContract(); + function isComplete(Bundle storage bundle) internal returns(bool) { + return bundle.name.isNotEmpty() && + bundle.functionInfos.length != 0 && + bundle.facade.isContract(); } - function assertComplete(Bundle storage bundleInfo) internal returns(Bundle storage) { - check(bundleInfo.isComplete(), "Bundle Info Not Complete", bundleInfo.parse()); - return bundleInfo; + function assertComplete(Bundle storage bundle) internal returns(Bundle storage) { + check(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); + return bundle; } - function hasName(Bundle storage bundleInfo) internal returns(bool) { - return bundleInfo.name.isNotEmpty(); + function hasName(Bundle storage bundle) internal returns(bool) { + return bundle.name.isNotEmpty(); } - function hasNotName(Bundle storage bundleInfo) internal returns(bool) { - return bundleInfo.name.isEmpty(); + function hasNotName(Bundle storage bundle) internal returns(bool) { + return bundle.name.isEmpty(); } - function exists(Bundle storage bundleInfo) internal returns(bool) { - return bundleInfo.name.isNotEmpty() || - bundleInfo.functionInfos.length != 0 || - bundleInfo.facade.isNotContract(); + function exists(Bundle storage bundle) internal returns(bool) { + return bundle.name.isNotEmpty() || + bundle.functionInfos.length != 0 || + bundle.facade.isNotContract(); } - function notExists(Bundle storage bundleInfo) internal returns(bool) { - return bundleInfo.exists().isNot(); + function notExists(Bundle storage bundle) internal returns(bool) { + return bundle.exists().isNot(); } - function assertExists(Bundle storage bundleInfo) internal returns(Bundle storage) { - check(bundleInfo.exists(), "Bundle Info Not Exists"); - return bundleInfo; + function assertExists(Bundle storage bundle) internal returns(Bundle storage) { + check(bundle.exists(), "Bundle Info Not Exists"); + return bundle; } - function assertNotExists(Bundle storage bundleInfo) internal returns(Bundle storage) { - check(bundleInfo.notExists(), "Bundle Info Already Exists"); - return bundleInfo; + function assertNotExists(Bundle storage bundle) internal returns(Bundle storage) { + check(bundle.notExists(), "Bundle Info Already Exists"); + return bundle; } /**--------------- 🐞 Debug -----------------*/ - function parseAndLog(Bundle storage bundleInfo) internal returns(Bundle storage) { + function parseAndLog(Bundle storage bundle) internal returns(Bundle storage) { Logger.logDebug( - bundleInfo.parse() + bundle.parse() ); - return bundleInfo; + return bundle; } - function parse(Bundle storage bundleInfo) internal returns(string memory message) { - message = message.append("Facade: ").append(bundleInfo.facade); + function parse(Bundle storage bundle) internal returns(string memory message) { + message = message.append("Facade: ").append(bundle.facade); - Function[] memory _funcs = bundleInfo.functionInfos; + Function[] memory _funcs = bundle.functionInfos; for (uint i; i < _funcs.length; ++i) { message = message.br().append(_funcs[i].parse()); } diff --git a/devkit/ucs/functions/Function.sol b/devkit/ucs/functions/Function.sol index 4b98da62..27507313 100644 --- a/devkit/ucs/functions/Function.sol +++ b/devkit/ucs/functions/Function.sol @@ -47,56 +47,56 @@ library FunctionLib { đŸ“Ĩ Assign Function --------------------------*/ /**----- Name --------*/ - function assign(Function storage functionInfo, string memory name) internal returns(Function storage) { - functionInfo.name = name; - return functionInfo; + function assign(Function storage func, string memory name) internal returns(Function storage) { + func.name = name; + return func; } - function safeAssign(Function storage functionInfo, string memory name) internal returns(Function storage) { + function safeAssign(Function storage func, string memory name) internal returns(Function storage) { uint pid = recordExecStart("safeAssign"); - return functionInfo .assertEmptyName() + return func .assertEmptyName() .assign(name.assertNotEmpty()) .recordExecFinish(pid); } /**----- Selector --------*/ - function safeAssign(Function storage functionInfo, bytes4 selector) internal returns(Function storage) { + function safeAssign(Function storage func, bytes4 selector) internal returns(Function storage) { uint pid = recordExecStart("safeAssign"); - return functionInfo .assertEmptySelector() + return func .assertEmptySelector() .assign(selector.assertNotEmpty()) .recordExecFinish(pid); } - function assign(Function storage functionInfo, bytes4 selector) internal returns(Function storage) { - functionInfo.selector = selector; - return functionInfo; + function assign(Function storage func, bytes4 selector) internal returns(Function storage) { + func.selector = selector; + return func; } /**----- Implementation --------*/ - function safeAssign(Function storage functionInfo, address implementation) internal returns(Function storage) { + function safeAssign(Function storage func, address implementation) internal returns(Function storage) { uint pid = recordExecStart("safeAssign"); - return functionInfo .assertEmptyImpl() + return func .assertEmptyImpl() .assign(implementation.assertIsContract()) .recordExecFinish(pid); } - function assign(Function storage functionInfo, address implementation) internal returns(Function storage) { - functionInfo.implementation = implementation; - return functionInfo; + function assign(Function storage func, address implementation) internal returns(Function storage) { + func.implementation = implementation; + return func; } - function loadAndAssignFromEnv(Function storage functionInfo, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { + function loadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { uint pid = recordExecStart("loadAndAssignFromEnv"); - return functionInfo .assign(name) + return func .assign(name) .assign(selector) .assign(envKey.loadAddress()) .recordExecFinish(pid); } - function loadAndAssignFromEnv(Function storage functionInfo) internal returns(Function storage) { - string memory name = functionInfo.name.assertNotEmpty(); - bytes4 selector = functionInfo.selector.assertNotEmpty(); - return functionInfo.loadAndAssignFromEnv(name, name, selector); + function loadAndAssignFromEnv(Function storage func) internal returns(Function storage) { + string memory name = func.name.assertNotEmpty(); + bytes4 selector = func.selector.assertNotEmpty(); + return func.loadAndAssignFromEnv(name, name, selector); } - function safeLoadAndAssignFromEnv(Function storage functionInfo, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { + function safeLoadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { uint pid = recordExecStart("safeLoadAndAssignFromEnv"); - return functionInfo.loadAndAssignFromEnv( + return func.loadAndAssignFromEnv( envKey.assertNotEmpty(), name.assertNotEmpty(), selector.assertNotEmpty() @@ -107,35 +107,35 @@ library FunctionLib { /**------------------------------- 🧐 Inspectors & Assertions ---------------------------------*/ - function exists(Function memory functionInfo) internal returns(bool) { - return functionInfo.implementation.isContract(); + function exists(Function memory func) internal returns(bool) { + return func.implementation.isContract(); } - function assignLabel(Function storage functionInfo) internal returns(Function storage) { - if (functionInfo.exists()) { - ForgeHelper.assignLabel(functionInfo.implementation, functionInfo.name); + function assignLabel(Function storage func) internal returns(Function storage) { + if (func.exists()) { + ForgeHelper.assignLabel(func.implementation, func.name); } - return functionInfo; + return func; } - function assertExists(Function storage functionInfo) internal returns(Function storage) { - if (!functionInfo.exists()) { - throwError("FunctionInfo does not exists"); + function assertExists(Function storage func) internal returns(Function storage) { + if (!func.exists()) { + throwError("func does not exists"); } - return functionInfo; + return func; } - function assertEmptyName(Function storage functionInfo) internal returns(Function storage) { - check(functionInfo.name.isEmpty(), "Name Already Exist"); - return functionInfo; + function assertEmptyName(Function storage func) internal returns(Function storage) { + check(func.name.isEmpty(), "Name Already Exist"); + return func; } - function assertEmptySelector(Function storage functionInfo) internal returns(Function storage) { - check(functionInfo.selector.isEmpty(), "Selector Already Exist"); - return functionInfo; + function assertEmptySelector(Function storage func) internal returns(Function storage) { + check(func.selector.isEmpty(), "Selector Already Exist"); + return func; } - function assertEmptyImpl(Function storage functionInfo) internal returns(Function storage) { - check(functionInfo.implementation.isNotContract(), "Implementation Already Exist"); - return functionInfo; + function assertEmptyImpl(Function storage func) internal returns(Function storage) { + check(func.implementation.isNotContract(), "Implementation Already Exist"); + return func; } function assertNotEmpty(Function storage functionInfo) internal returns(Function storage) { From 9a63891aae79b6f3ae544583f8aa68ba9a383278 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Sun, 7 Apr 2024 17:18:00 +0900 Subject: [PATCH 013/111] Rename ucs to core --- devkit/MCDevKit.sol | 6 +++--- devkit/{ucs => core}/dictionary/Dictionary.sol | 0 devkit/{ucs => core}/dictionary/DictionaryRegistry.sol | 0 devkit/{ucs => core}/functions/Bundle.sol | 0 devkit/{ucs => core}/functions/Function.sol | 0 devkit/{ucs => core}/functions/FunctionRegistry.sol | 0 devkit/{ucs => core}/functions/StdFunctions.sol | 0 devkit/{ucs => core}/proxy/Proxy.sol | 2 +- devkit/{ucs => core}/proxy/ProxyRegistry.sol | 0 devkit/global/MCBundleLib.sol | 2 +- devkit/global/MCDeployLib.sol | 8 ++++---- devkit/global/MCFinderLib.sol | 8 ++++---- devkit/global/MCTestLib.sol | 8 ++++---- devkit/test/MockDictionary.sol | 2 +- devkit/test/SimpleMockProxy.sol | 2 +- script/DeployLib.sol | 2 +- test/devkit/MCDevKit.t.sol | 2 +- test/devkit/global/MCBundle.t.sol | 4 ++-- test/devkit/global/MCSetup.t.sol | 2 +- test/utils/TestHelper.sol | 2 +- 20 files changed, 25 insertions(+), 25 deletions(-) rename devkit/{ucs => core}/dictionary/Dictionary.sol (100%) rename devkit/{ucs => core}/dictionary/DictionaryRegistry.sol (100%) rename devkit/{ucs => core}/functions/Bundle.sol (100%) rename devkit/{ucs => core}/functions/Function.sol (100%) rename devkit/{ucs => core}/functions/FunctionRegistry.sol (100%) rename devkit/{ucs => core}/functions/StdFunctions.sol (100%) rename devkit/{ucs => core}/proxy/Proxy.sol (98%) rename devkit/{ucs => core}/proxy/ProxyRegistry.sol (100%) diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index 47277887..74041928 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -2,9 +2,9 @@ pragma solidity ^0.8.24; // Registries -import {FunctionRegistry} from "devkit/ucs/functions/FunctionRegistry.sol"; -import {DictionaryRegistry} from "devkit/ucs/dictionary/DictionaryRegistry.sol"; -import {ProxyRegistry} from "devkit/ucs/proxy/ProxyRegistry.sol"; +import {FunctionRegistry} from "devkit/core/functions/FunctionRegistry.sol"; +import {DictionaryRegistry} from "devkit/core/dictionary/DictionaryRegistry.sol"; +import {ProxyRegistry} from "devkit/core/proxy/ProxyRegistry.sol"; // Global Methods import {MCSetupLib} from "devkit/global/MCSetupLib.sol"; diff --git a/devkit/ucs/dictionary/Dictionary.sol b/devkit/core/dictionary/Dictionary.sol similarity index 100% rename from devkit/ucs/dictionary/Dictionary.sol rename to devkit/core/dictionary/Dictionary.sol diff --git a/devkit/ucs/dictionary/DictionaryRegistry.sol b/devkit/core/dictionary/DictionaryRegistry.sol similarity index 100% rename from devkit/ucs/dictionary/DictionaryRegistry.sol rename to devkit/core/dictionary/DictionaryRegistry.sol diff --git a/devkit/ucs/functions/Bundle.sol b/devkit/core/functions/Bundle.sol similarity index 100% rename from devkit/ucs/functions/Bundle.sol rename to devkit/core/functions/Bundle.sol diff --git a/devkit/ucs/functions/Function.sol b/devkit/core/functions/Function.sol similarity index 100% rename from devkit/ucs/functions/Function.sol rename to devkit/core/functions/Function.sol diff --git a/devkit/ucs/functions/FunctionRegistry.sol b/devkit/core/functions/FunctionRegistry.sol similarity index 100% rename from devkit/ucs/functions/FunctionRegistry.sol rename to devkit/core/functions/FunctionRegistry.sol diff --git a/devkit/ucs/functions/StdFunctions.sol b/devkit/core/functions/StdFunctions.sol similarity index 100% rename from devkit/ucs/functions/StdFunctions.sol rename to devkit/core/functions/StdFunctions.sol diff --git a/devkit/ucs/proxy/Proxy.sol b/devkit/core/proxy/Proxy.sol similarity index 98% rename from devkit/ucs/proxy/Proxy.sol rename to devkit/core/proxy/Proxy.sol index f5376383..ebb4ea72 100644 --- a/devkit/ucs/proxy/Proxy.sol +++ b/devkit/core/proxy/Proxy.sol @@ -13,7 +13,7 @@ import {StringUtils} from "../../utils/StringUtils.sol"; using StringUtils for string; import {ForgeHelper} from "../../utils/ForgeHelper.sol"; // Core -// import {MCStdFuncs} from "../../ucs/functions/MCStdFuncs.sol"; +// import {MCStdFuncs} from "../../core/functions/MCStdFuncs.sol"; import {Dictionary} from "../dictionary/Dictionary.sol"; import {Function} from "../functions/Function.sol"; // Test diff --git a/devkit/ucs/proxy/ProxyRegistry.sol b/devkit/core/proxy/ProxyRegistry.sol similarity index 100% rename from devkit/ucs/proxy/ProxyRegistry.sol rename to devkit/core/proxy/ProxyRegistry.sol diff --git a/devkit/global/MCBundleLib.sol b/devkit/global/MCBundleLib.sol index 954a8ee8..52602223 100644 --- a/devkit/global/MCBundleLib.sol +++ b/devkit/global/MCBundleLib.sol @@ -9,7 +9,7 @@ import {ERR} from "devkit/error/Error.sol"; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {Params} from "devkit/debug/Params.sol"; // Core -import {Function} from "devkit/ucs/functions/Function.sol"; +import {Function} from "devkit/core/functions/Function.sol"; /*********************************************** diff --git a/devkit/global/MCDeployLib.sol b/devkit/global/MCDeployLib.sol index 5be42673..127c264d 100644 --- a/devkit/global/MCDeployLib.sol +++ b/devkit/global/MCDeployLib.sol @@ -9,13 +9,13 @@ import {check} from "devkit/error/Validation.sol"; import {Params} from "devkit/debug/Params.sol"; // Core // dictionary -import {Dictionary, DictionaryLib} from "devkit/ucs/dictionary/Dictionary.sol"; +import {Dictionary, DictionaryLib} from "devkit/core/dictionary/Dictionary.sol"; // functions -import {Bundle} from "devkit/ucs/functions/Bundle.sol"; -import {StdFunctionsArgs} from "devkit/ucs/functions/StdFunctions.sol"; +import {Bundle} from "devkit/core/functions/Bundle.sol"; +import {StdFunctionsArgs} from "devkit/core/functions/StdFunctions.sol"; using StdFunctionsArgs for address; // proxy -import {Proxy, ProxyLib} from "devkit/ucs/proxy/Proxy.sol"; +import {Proxy, ProxyLib} from "devkit/core/proxy/Proxy.sol"; diff --git a/devkit/global/MCFinderLib.sol b/devkit/global/MCFinderLib.sol index 8f2aa3c6..5869acf5 100644 --- a/devkit/global/MCFinderLib.sol +++ b/devkit/global/MCFinderLib.sol @@ -4,12 +4,12 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Core // functions -import {Bundle} from "devkit/ucs/functions/Bundle.sol"; -import {Function} from "devkit/ucs/functions/Function.sol"; +import {Bundle} from "devkit/core/functions/Bundle.sol"; +import {Function} from "devkit/core/functions/Function.sol"; // proxy -import {Proxy} from "devkit/ucs/proxy/Proxy.sol"; +import {Proxy} from "devkit/core/proxy/Proxy.sol"; // dictionary -import {Dictionary} from "devkit/ucs/dictionary/Dictionary.sol"; +import {Dictionary} from "devkit/core/dictionary/Dictionary.sol"; /********************************** diff --git a/devkit/global/MCTestLib.sol b/devkit/global/MCTestLib.sol index 1ef7ba80..682a395e 100644 --- a/devkit/global/MCTestLib.sol +++ b/devkit/global/MCTestLib.sol @@ -7,12 +7,12 @@ import {Config} from "devkit/config/Config.sol"; import {Params} from "devkit/debug/Params.sol"; // Core // functions -import {Bundle} from "devkit/ucs/functions/Bundle.sol"; -import {Function} from "devkit/ucs/functions/Function.sol"; +import {Bundle} from "devkit/core/functions/Bundle.sol"; +import {Function} from "devkit/core/functions/Function.sol"; // proxy -import {Proxy, ProxyLib} from "devkit/ucs/proxy/Proxy.sol"; +import {Proxy, ProxyLib} from "devkit/core/proxy/Proxy.sol"; // dictionary -import {Dictionary, DictionaryLib} from "devkit/ucs/dictionary/Dictionary.sol"; +import {Dictionary, DictionaryLib} from "devkit/core/dictionary/Dictionary.sol"; /****************************************** diff --git a/devkit/test/MockDictionary.sol b/devkit/test/MockDictionary.sol index 716218c2..be569704 100644 --- a/devkit/test/MockDictionary.sol +++ b/devkit/test/MockDictionary.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Core -import {Function} from "../ucs/functions/Function.sol"; +import {Function} from "../core/functions/Function.sol"; // External Lib import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; diff --git a/devkit/test/SimpleMockProxy.sol b/devkit/test/SimpleMockProxy.sol index a9934af8..791f2112 100644 --- a/devkit/test/SimpleMockProxy.sol +++ b/devkit/test/SimpleMockProxy.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Core -import {Function} from "../ucs/functions/Function.sol"; +import {Function} from "../core/functions/Function.sol"; // External Lib import {Proxy as OZProxy} from "@oz.mc/proxy/Proxy.sol"; diff --git a/script/DeployLib.sol b/script/DeployLib.sol index b850dd3c..7c930392 100755 --- a/script/DeployLib.sol +++ b/script/DeployLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {StdFunctions} from "devkit/ucs/functions/StdFunctions.sol"; +import {StdFunctions} from "devkit/core/functions/StdFunctions.sol"; library DeployLib { using DeployLib for MCDevKit; diff --git a/test/devkit/MCDevKit.t.sol b/test/devkit/MCDevKit.t.sol index e3036afd..b872459d 100644 --- a/test/devkit/MCDevKit.t.sol +++ b/test/devkit/MCDevKit.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; import {Test, console2} from "forge-std/Test.sol"; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Function} from "devkit/ucs/functions/Function.sol"; +import {Function} from "devkit/core/functions/Function.sol"; import {TestHelper} from "../utils/TestHelper.sol"; using TestHelper for Function; diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index a86ac88e..b5466226 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -8,8 +8,8 @@ import {StringUtils} from "devkit/utils/StringUtils.sol"; import {Config} from "devkit/config/Config.sol"; import {ERR} from "devkit/error/Error.sol"; -import {Bundle} from "devkit/ucs/functions/Bundle.sol"; -import {Function} from "devkit/ucs/functions/Function.sol"; +import {Bundle} from "devkit/core/functions/Bundle.sol"; +import {Function} from "devkit/core/functions/Function.sol"; import {DummyFunction} from "test/utils/DummyFunction.sol"; import {DummyFacade} from "test/utils/DummyFacade.sol"; diff --git a/test/devkit/global/MCSetup.t.sol b/test/devkit/global/MCSetup.t.sol index 6f29a93f..1aa85927 100644 --- a/test/devkit/global/MCSetup.t.sol +++ b/test/devkit/global/MCSetup.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; import {MCDevKitTest} from "devkit/MCTest.sol"; -import {Function} from "devkit/ucs/functions/Function.sol"; +import {Function} from "devkit/core/functions/Function.sol"; import {TestHelper} from "test/utils/TestHelper.sol"; using TestHelper for Function; diff --git a/test/utils/TestHelper.sol b/test/utils/TestHelper.sol index 5b45a1e9..04ac0110 100644 --- a/test/utils/TestHelper.sol +++ b/test/utils/TestHelper.sol @@ -6,7 +6,7 @@ import {AddressUtils} from "devkit/utils/AddressUtils.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; -import {Function} from "devkit/ucs/functions/Function.sol"; +import {Function} from "devkit/core/functions/Function.sol"; // import {Bundle} from "./Bundle.sol"; import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; From d4b97dfd2b51b69099557846deea89af7bf63dcf Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 07:49:52 +0900 Subject: [PATCH 014/111] Update Function: externalize debug methods --- devkit/core/functions/Function.sol | 38 ++++++++-------------- devkit/core/functions/FunctionRegistry.sol | 4 +-- devkit/debug/ProcessLib.sol | 20 ++++++++++++ 3 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 devkit/debug/ProcessLib.sol diff --git a/devkit/core/functions/Function.sol b/devkit/core/functions/Function.sol index 27507313..8738d441 100644 --- a/devkit/core/functions/Function.sol +++ b/devkit/core/functions/Function.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; // Validation import {check} from "devkit/error/Validation.sol"; import {throwError} from "devkit/error/Error.sol"; +import {ProcessLib} from "devkit/debug/ProcessLib.sol"; // Utils import {ForgeHelper} from "../../utils/ForgeHelper.sol"; import {StringUtils} from "../../utils/StringUtils.sol"; @@ -22,12 +23,13 @@ import {Bundle} from "./Bundle.sol"; /**====================== 🧩 Function Info ========================*/ -using FunctionLib for Function global; struct Function { /// @dev Function may be different depending on the op version. string name; bytes4 selector; address implementation; } +using FunctionLib for Function global; +using ProcessLib for Function global; /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ << Primary >> @@ -52,18 +54,18 @@ library FunctionLib { return func; } function safeAssign(Function storage func, string memory name) internal returns(Function storage) { - uint pid = recordExecStart("safeAssign"); + uint pid = func.startProcess("safeAssign"); return func .assertEmptyName() - .assign(name.assertNotEmpty()) - .recordExecFinish(pid); + .assign(name.assertNotEmpty()) + .finishProcess(pid); } /**----- Selector --------*/ function safeAssign(Function storage func, bytes4 selector) internal returns(Function storage) { - uint pid = recordExecStart("safeAssign"); + uint pid = func.startProcess("safeAssign"); return func .assertEmptySelector() .assign(selector.assertNotEmpty()) - .recordExecFinish(pid); + .finishProcess(pid); } function assign(Function storage func, bytes4 selector) internal returns(Function storage) { func.selector = selector; @@ -72,10 +74,10 @@ library FunctionLib { /**----- Implementation --------*/ function safeAssign(Function storage func, address implementation) internal returns(Function storage) { - uint pid = recordExecStart("safeAssign"); + uint pid = func.startProcess("safeAssign"); return func .assertEmptyImpl() .assign(implementation.assertIsContract()) - .recordExecFinish(pid); + .finishProcess(pid); } function assign(Function storage func, address implementation) internal returns(Function storage) { func.implementation = implementation; @@ -83,11 +85,11 @@ library FunctionLib { } function loadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { - uint pid = recordExecStart("loadAndAssignFromEnv"); + uint pid = func.startProcess("loadAndAssignFromEnv"); return func .assign(name) .assign(selector) .assign(envKey.loadAddress()) - .recordExecFinish(pid); + .finishProcess(pid); } function loadAndAssignFromEnv(Function storage func) internal returns(Function storage) { string memory name = func.name.assertNotEmpty(); @@ -95,12 +97,12 @@ library FunctionLib { return func.loadAndAssignFromEnv(name, name, selector); } function safeLoadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { - uint pid = recordExecStart("safeLoadAndAssignFromEnv"); + uint pid = func.startProcess("safeLoadAndAssignFromEnv"); return func.loadAndAssignFromEnv( envKey.assertNotEmpty(), name.assertNotEmpty(), selector.assertNotEmpty() - ).recordExecFinish(pid); + ).finishProcess(pid); } @@ -185,16 +187,4 @@ library FunctionLib { .append("Name: ").append(functionInfo.name); } - - function recordExecStart(string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(string memory funcName) internal returns(uint) { - return recordExecStart(funcName, ""); - } - function recordExecFinish(Function storage funcInfo, uint pid) internal returns(Function storage) { - Debug.recordExecFinish(pid); - return funcInfo; - } - } diff --git a/devkit/core/functions/FunctionRegistry.sol b/devkit/core/functions/FunctionRegistry.sol index 262baff9..81aa149c 100644 --- a/devkit/core/functions/FunctionRegistry.sol +++ b/devkit/core/functions/FunctionRegistry.sol @@ -157,11 +157,11 @@ library FunctionRegistryLib { /**----- 🧩 Function -------*/ function findFunction(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { uint pid = functions.recordExecStart("findFunction"); - return functions.customs[name.safeCalcHash()].assertExists().recordExecFinish(pid); + return functions.customs[name.safeCalcHash()].assertExists().finishProcess(pid); } function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { uint pid = functions.recordExecStart("findCurrentFunction"); - return functions.findFunction(functions.findCurrentFunctionName()).recordExecFinish(pid); + return functions.findFunction(functions.findCurrentFunctionName()).finishProcess(pid); } function findCurrentFunctionName(FunctionRegistry storage functions) internal returns(string memory) { uint pid = functions.recordExecStart("findCurrentFunctionName"); diff --git a/devkit/debug/ProcessLib.sol b/devkit/debug/ProcessLib.sol new file mode 100644 index 00000000..503a2ba0 --- /dev/null +++ b/devkit/debug/ProcessLib.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {Debug} from "./Debug.sol"; +// Types +import {Function} from "devkit/core/functions/Function.sol"; + +library ProcessLib { + function startProcess(Function storage, string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("FunctionLib", name, params); + } + function startProcess(Function storage func, string memory name) internal returns(uint) { + return func.startProcess(name, ""); + } + function finishProcess(Function storage func, uint pid) internal returns(Function storage) { + Debug.recordExecFinish(pid); + return func; + } + +} From 8b9e6dd4080e91310a2e4883f298295d5f3789ff Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 09:13:42 +0900 Subject: [PATCH 015/111] Update Function: externalize Libs, FunctionLib, Check, LogLib --- devkit/core/functions/Function.sol | 183 +------------------------- devkit/core/functions/FunctionLib.sol | 161 ++++++++++++++++++++++ devkit/debug/LogLib.sol | 30 +++++ devkit/error/Error.sol | 6 +- devkit/error/Validation.sol | 26 +++- test/devkit/global/MCBundle.t.sol | 2 +- 6 files changed, 228 insertions(+), 180 deletions(-) create mode 100644 devkit/core/functions/FunctionLib.sol create mode 100644 devkit/debug/LogLib.sol diff --git a/devkit/core/functions/Function.sol b/devkit/core/functions/Function.sol index 8738d441..d3e639a6 100644 --- a/devkit/core/functions/Function.sol +++ b/devkit/core/functions/Function.sol @@ -1,28 +1,14 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Validation -import {check} from "devkit/error/Validation.sol"; -import {throwError} from "devkit/error/Error.sol"; +import {FunctionLib} from "./FunctionLib.sol"; import {ProcessLib} from "devkit/debug/ProcessLib.sol"; -// Utils -import {ForgeHelper} from "../../utils/ForgeHelper.sol"; -import {StringUtils} from "../../utils/StringUtils.sol"; - using StringUtils for string; -import {Bytes4Utils} from "../../utils/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; -import {AddressUtils} from "../../utils/AddressUtils.sol"; - using AddressUtils for address; -// Debug -import {Debug} from "../../debug/Debug.sol"; -import {Logger} from "../../debug/Logger.sol"; -// Core -import {Bundle} from "./Bundle.sol"; +import {LogLib} from "devkit/debug/LogLib.sol"; -/**====================== - 🧩 Function Info -========================*/ +/**================== + 🧩 Function +====================*/ struct Function { /// @dev Function may be different depending on the op version. string name; bytes4 selector; @@ -30,161 +16,4 @@ struct Function { /// @dev Function may be different depending on the op version } using FunctionLib for Function global; using ProcessLib for Function global; - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> - đŸ“Ĩ Assign Function - đŸ”ŧ Update Current Context Proxy - 🔍 Find Proxy - 🏷 Generate Unique Name - << Helper >> - 🧐 Inspectors & Assertions - 🐞 Debug -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library FunctionLib { - string constant LIB_NAME = "Function"; - - - /**------------------------ - đŸ“Ĩ Assign Function - --------------------------*/ - /**----- Name --------*/ - function assign(Function storage func, string memory name) internal returns(Function storage) { - func.name = name; - return func; - } - function safeAssign(Function storage func, string memory name) internal returns(Function storage) { - uint pid = func.startProcess("safeAssign"); - return func .assertEmptyName() - .assign(name.assertNotEmpty()) - .finishProcess(pid); - } - - /**----- Selector --------*/ - function safeAssign(Function storage func, bytes4 selector) internal returns(Function storage) { - uint pid = func.startProcess("safeAssign"); - return func .assertEmptySelector() - .assign(selector.assertNotEmpty()) - .finishProcess(pid); - } - function assign(Function storage func, bytes4 selector) internal returns(Function storage) { - func.selector = selector; - return func; - } - - /**----- Implementation --------*/ - function safeAssign(Function storage func, address implementation) internal returns(Function storage) { - uint pid = func.startProcess("safeAssign"); - return func .assertEmptyImpl() - .assign(implementation.assertIsContract()) - .finishProcess(pid); - } - function assign(Function storage func, address implementation) internal returns(Function storage) { - func.implementation = implementation; - return func; - } - - function loadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { - uint pid = func.startProcess("loadAndAssignFromEnv"); - return func .assign(name) - .assign(selector) - .assign(envKey.loadAddress()) - .finishProcess(pid); - } - function loadAndAssignFromEnv(Function storage func) internal returns(Function storage) { - string memory name = func.name.assertNotEmpty(); - bytes4 selector = func.selector.assertNotEmpty(); - return func.loadAndAssignFromEnv(name, name, selector); - } - function safeLoadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { - uint pid = func.startProcess("safeLoadAndAssignFromEnv"); - return func.loadAndAssignFromEnv( - envKey.assertNotEmpty(), - name.assertNotEmpty(), - selector.assertNotEmpty() - ).finishProcess(pid); - } - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function exists(Function memory func) internal returns(bool) { - return func.implementation.isContract(); - } - - function assignLabel(Function storage func) internal returns(Function storage) { - if (func.exists()) { - ForgeHelper.assignLabel(func.implementation, func.name); - } - return func; - } - - function assertExists(Function storage func) internal returns(Function storage) { - if (!func.exists()) { - throwError("func does not exists"); - } - return func; - } - - function assertEmptyName(Function storage func) internal returns(Function storage) { - check(func.name.isEmpty(), "Name Already Exist"); - return func; - } - function assertEmptySelector(Function storage func) internal returns(Function storage) { - check(func.selector.isEmpty(), "Selector Already Exist"); - return func; - } - function assertEmptyImpl(Function storage func) internal returns(Function storage) { - check(func.implementation.isNotContract(), "Implementation Already Exist"); - return func; - } - - function assertNotEmpty(Function storage functionInfo) internal returns(Function storage) { - if (!functionInfo.exists()) { - throwError("Empty Deployed Contract in FunctionInfo"); - } - return functionInfo; - } - - function assertNotIncludedIn(Function storage functionInfo, Bundle storage bundleInfo) internal returns(Function storage) { - check(bundleInfo.hasNot(functionInfo), "Already exists in the Bundel"); - return functionInfo; - } - - function assertImplIsContract(Function storage functionInfo) internal returns(Function storage) { - check(functionInfo.implementation.isContract(), "Implementation Not Contract"); - return functionInfo; - } - - function isComplete(Function storage functionInfo) internal returns(bool) { - return functionInfo.name.isNotEmpty() && - functionInfo.selector.isNotEmpty() && - functionInfo.implementation.isContract(); - } - function assertComplete(Function storage functionInfo) internal returns(Function storage) { - check(functionInfo.isComplete(), "Function Info Not Complete"); - return functionInfo; - } - - function isEqual(Function memory a, Function memory b) internal pure returns(bool) { - return keccak256(abi.encode(a)) == keccak256(abi.encode(b)); - } - - - /**--------------- - 🐞 Debug - -----------------*/ - function parseAndLog(Function storage functionInfo) internal returns(Function storage) { - Logger.log( - functionInfo.parse() - ); - return functionInfo; - } - function parse(Function memory functionInfo) internal returns(string memory message) { - return message .append("Impl: ").append(functionInfo.implementation).comma() - .append("Selector: ").append(functionInfo.selector).comma() - .append("Name: ").append(functionInfo.name); - } - -} +using LogLib for Function global; diff --git a/devkit/core/functions/FunctionLib.sol b/devkit/core/functions/FunctionLib.sol new file mode 100644 index 00000000..c65214dd --- /dev/null +++ b/devkit/core/functions/FunctionLib.sol @@ -0,0 +1,161 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Validation +import {check, Check} from "devkit/error/Validation.sol"; +// import {throwError} from "devkit/error/Error.sol"; +// import {ProcessLib} from "devkit/debug/ProcessLib.sol"; +// Utils +import {ForgeHelper} from "../../utils/ForgeHelper.sol"; +import {StringUtils} from "../../utils/StringUtils.sol"; + using StringUtils for string; +import {Bytes4Utils} from "../../utils/Bytes4Utils.sol"; + using Bytes4Utils for bytes4; +import {AddressUtils} from "../../utils/AddressUtils.sol"; + using AddressUtils for address; +// // Debug +// import {Debug} from "../../debug/Debug.sol"; +// import {Logger} from "../../debug/Logger.sol"; +// Core +import {Function} from "./Function.sol"; +import {Bundle} from "./Bundle.sol"; + + +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + << Primary >> + đŸ“Ĩ Assign Function + đŸ”ŧ Update Current Context Proxy + 🔍 Find Proxy + 🏷 Generate Unique Name + << Helper >> + 🧐 Inspectors & Assertions + 🐞 Debug +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library FunctionLib { + /**------------------------ + đŸ“Ĩ Assign Function + --------------------------*/ + /**----- Name --------*/ + function assign(Function storage func, string memory name) internal returns(Function storage) { + func.name = name; + return func; + } + function safeAssign(Function storage func, string memory name) internal returns(Function storage) { + uint pid = func.startProcess("safeAssign"); + Check.isNotEmpty(name); + return func .assertEmptyName() + .assign(name) + .finishProcess(pid); + } + + /**----- Selector --------*/ + function safeAssign(Function storage func, bytes4 selector) internal returns(Function storage) { + uint pid = func.startProcess("safeAssign"); + Check.isNotEmpty(selector); + return func .assertEmptySelector() + .assign(selector) + .finishProcess(pid); + } + function assign(Function storage func, bytes4 selector) internal returns(Function storage) { + func.selector = selector; + return func; + } + + /**----- Implementation --------*/ + function safeAssign(Function storage func, address implementation) internal returns(Function storage) { + uint pid = func.startProcess("safeAssign"); + Check.isContract(implementation); + return func .assertEmptyImpl() + .assign(implementation) + .finishProcess(pid); + } + function assign(Function storage func, address implementation) internal returns(Function storage) { + func.implementation = implementation; + return func; + } + + function loadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { + uint pid = func.startProcess("loadAndAssignFromEnv"); + return func .assign(name) + .assign(selector) + .assign(envKey.loadAddress()) + .finishProcess(pid); + } + function loadAndAssignFromEnv(Function storage func) internal returns(Function storage) { + Check.isNotEmpty(func.name); + Check.isNotEmpty(func.selector); + return func.loadAndAssignFromEnv(func.name, func.name, func.selector); + } + function safeLoadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { + uint pid = func.startProcess("safeLoadAndAssignFromEnv"); + Check.isNotEmpty(envKey); + Check.isNotEmpty(name); + Check.isNotEmpty(selector); + return func.loadAndAssignFromEnv(envKey, name, selector).finishProcess(pid); + } + + + /**------------------------------- + 🧐 Inspectors & Assertions + ---------------------------------*/ + function exists(Function memory func) internal returns(bool) { + return func.implementation.isContract(); + } + + function assignLabel(Function storage func) internal returns(Function storage) { + if (func.exists()) { + ForgeHelper.assignLabel(func.implementation, func.name); + } + return func; + } + + function assertExists(Function storage func) internal returns(Function storage) { + check(func.exists(), "func does not exists"); + return func; + } + + function assertEmptyName(Function storage func) internal returns(Function storage) { + Check.isUnassigned(func.name); + return func; + } + function assertEmptySelector(Function storage func) internal returns(Function storage) { + Check.isUnassigned(func.selector); + return func; + } + function assertEmptyImpl(Function storage func) internal returns(Function storage) { + check(func.implementation.isNotContract(), "Implementation Already Exist"); + return func; + } + + function assertNotEmpty(Function storage func) internal returns(Function storage) { + check(func.exists(), "Empty Deployed Contract"); + return func; + } + + function assertNotIncludedIn(Function storage func, Bundle storage bundleInfo) internal returns(Function storage) { + check(bundleInfo.hasNot(func), "Already exists in the Bundel"); + return func; + } + + function assertImplIsContract(Function storage func) internal returns(Function storage) { + check(func.implementation.isContract(), "Implementation Not Contract"); + return func; + } + + function isComplete(Function storage func) internal returns(bool) { + return func.name.isNotEmpty() && + func.selector.isNotEmpty() && + func.implementation.isContract(); + } + function assertComplete(Function storage func) internal returns(Function storage) { + check(func.isComplete(), "Function Info Not Complete"); + return func; + } + + function isEqual(Function memory a, Function memory b) internal pure returns(bool) { + return keccak256(abi.encode(a)) == keccak256(abi.encode(b)); + } + + + +} diff --git a/devkit/debug/LogLib.sol b/devkit/debug/LogLib.sol new file mode 100644 index 00000000..36be8e9a --- /dev/null +++ b/devkit/debug/LogLib.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {Logger} from "./Logger.sol"; +import {Function} from "devkit/core/functions/Function.sol"; + +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; + +//================ +// 📊 LogLib +library LogLib { + /**================== + 🧩 Function + ====================*/ + function parseAndLog(Function storage func) internal returns(Function storage) { + Logger.log( + func.parse() + ); + return func; + } + function parse(Function memory func) internal returns(string memory message) { + return message .append("Impl: ").append(func.implementation).comma() + .append("Selector: ").append(func.selector).comma() + .append("Name: ").append(func.name); + } + +} + + diff --git a/devkit/error/Error.sol b/devkit/error/Error.sol index 6df222ea..bbadf84e 100644 --- a/devkit/error/Error.sol +++ b/devkit/error/Error.sol @@ -17,7 +17,11 @@ function throwError(string memory errorBody) { library ERR { string constant HEADER = "\u2716 DevKit Error: "; string constant FIND_NAME_OVER_RANGE = "Default names are automatically set up to 5. Please manually assign names beyond that."; - // string constant STR_EMPTY = "Empty String"; + string constant EMPTY_STR = "Empty String"; + string constant EMPTY_B4 = "Empty Bytes4"; + string constant NOT_CONTRACT = "Not Contract Address"; + string constant STR_ALREADY_ASSIGNED = "String Already Assigned"; + string constant B4_ALREADY_ASSIGNED = "Bytes4 Already Assigned"; // string constant STR_EXISTS = "String Already Exist"; string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; diff --git a/devkit/error/Validation.sol b/devkit/error/Validation.sol index eab8ee6a..a401185a 100644 --- a/devkit/error/Validation.sol +++ b/devkit/error/Validation.sol @@ -1,12 +1,16 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {throwError} from "./Error.sol"; +import {throwError, ERR} from "./Error.sol"; // Utils import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; +import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; + using Bytes4Utils for bytes4; +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; + using AddressUtils for address; /// @dev like `require` function check(bool condition, string memory errorBody) { @@ -15,3 +19,23 @@ function check(bool condition, string memory errorBody) { function check(bool condition, string memory errorBody, string memory errorDetail) { check(condition, errorBody.append(errorDetail)); } + +library Check { + function isUnassigned(string storage str) internal { + check(str.isEmpty(), ERR.STR_ALREADY_ASSIGNED); + } + function isNotEmpty(string memory str) internal { + check(str.isNotEmpty(), ERR.EMPTY_STR); + } + + function isUnassigned(bytes4 b4) internal { + check(b4.isEmpty(), ERR.B4_ALREADY_ASSIGNED); + } + function isNotEmpty(bytes4 b4) internal { + check(b4.isNotEmpty(), ERR.EMPTY_B4); + } + + function isContract(address addr) internal { + check(addr.isContract(), ERR.NOT_CONTRACT); + } +} diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index b5466226..5e8bbc4a 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -87,7 +87,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { mc.use(functionName, selector, impl); - vm.expectRevert(ERR.message("Name Already Exist").toBytes()); + vm.expectRevert(ERR.message(ERR.STR_ALREADY_ASSIGNED).toBytes()); mc.use(functionName, selector, impl); } From ae27e5b80e222c6fdeebb893c2edf2d3a03d61e3 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 09:30:44 +0900 Subject: [PATCH 016/111] update file location: method files --- devkit/MCDevKit.sol | 16 ++++++++-------- devkit/core/functions/Function.sol | 6 +++--- devkit/{global => method}/MCBundleLib.sol | 0 devkit/{global => method}/MCContextLib.sol | 0 devkit/{global => method}/MCDebugLib.sol | 0 devkit/{global => method}/MCDeployLib.sol | 0 devkit/{global => method}/MCFinderLib.sol | 0 devkit/{global => method}/MCSetupLib.sol | 0 devkit/{global => method}/MCTestLib.sol | 0 .../functions => method/core}/FunctionLib.sol | 4 ++-- devkit/{ => method}/debug/LogLib.sol | 2 +- devkit/{ => method}/debug/ProcessLib.sol | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) rename devkit/{global => method}/MCBundleLib.sol (100%) rename devkit/{global => method}/MCContextLib.sol (100%) rename devkit/{global => method}/MCDebugLib.sol (100%) rename devkit/{global => method}/MCDeployLib.sol (100%) rename devkit/{global => method}/MCFinderLib.sol (100%) rename devkit/{global => method}/MCSetupLib.sol (100%) rename devkit/{global => method}/MCTestLib.sol (100%) rename devkit/{core/functions => method/core}/FunctionLib.sol (98%) rename devkit/{ => method}/debug/LogLib.sol (94%) rename devkit/{ => method}/debug/ProcessLib.sol (93%) diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index 74041928..e23f68c6 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -1,19 +1,19 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Registries +// Core Registries import {FunctionRegistry} from "devkit/core/functions/FunctionRegistry.sol"; import {DictionaryRegistry} from "devkit/core/dictionary/DictionaryRegistry.sol"; import {ProxyRegistry} from "devkit/core/proxy/ProxyRegistry.sol"; // Global Methods -import {MCSetupLib} from "devkit/global/MCSetupLib.sol"; -import {MCBundleLib} from "devkit/global/MCBundleLib.sol"; -import {MCDeployLib} from "devkit/global/MCDeployLib.sol"; -import {MCFinderLib} from "devkit/global/MCFinderLib.sol"; -import {MCContextLib} from "devkit/global/MCContextLib.sol"; -import {MCTestLib} from "devkit/global/MCTestLib.sol"; -import {MCDebugLib} from "devkit/global/MCDebugLib.sol"; +import {MCSetupLib} from "devkit/method/MCSetupLib.sol"; +import {MCBundleLib} from "devkit/method/MCBundleLib.sol"; +import {MCDeployLib} from "devkit/method/MCDeployLib.sol"; +import {MCFinderLib} from "devkit/method/MCFinderLib.sol"; +import {MCContextLib} from "devkit/method/MCContextLib.sol"; +import {MCTestLib} from "devkit/method/MCTestLib.sol"; +import {MCDebugLib} from "devkit/method/MCDebugLib.sol"; /******************************** diff --git a/devkit/core/functions/Function.sol b/devkit/core/functions/Function.sol index d3e639a6..bdf723f9 100644 --- a/devkit/core/functions/Function.sol +++ b/devkit/core/functions/Function.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {FunctionLib} from "./FunctionLib.sol"; -import {ProcessLib} from "devkit/debug/ProcessLib.sol"; -import {LogLib} from "devkit/debug/LogLib.sol"; +import {FunctionLib} from "devkit/method/core/FunctionLib.sol"; +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {LogLib} from "devkit/method/debug/LogLib.sol"; /**================== diff --git a/devkit/global/MCBundleLib.sol b/devkit/method/MCBundleLib.sol similarity index 100% rename from devkit/global/MCBundleLib.sol rename to devkit/method/MCBundleLib.sol diff --git a/devkit/global/MCContextLib.sol b/devkit/method/MCContextLib.sol similarity index 100% rename from devkit/global/MCContextLib.sol rename to devkit/method/MCContextLib.sol diff --git a/devkit/global/MCDebugLib.sol b/devkit/method/MCDebugLib.sol similarity index 100% rename from devkit/global/MCDebugLib.sol rename to devkit/method/MCDebugLib.sol diff --git a/devkit/global/MCDeployLib.sol b/devkit/method/MCDeployLib.sol similarity index 100% rename from devkit/global/MCDeployLib.sol rename to devkit/method/MCDeployLib.sol diff --git a/devkit/global/MCFinderLib.sol b/devkit/method/MCFinderLib.sol similarity index 100% rename from devkit/global/MCFinderLib.sol rename to devkit/method/MCFinderLib.sol diff --git a/devkit/global/MCSetupLib.sol b/devkit/method/MCSetupLib.sol similarity index 100% rename from devkit/global/MCSetupLib.sol rename to devkit/method/MCSetupLib.sol diff --git a/devkit/global/MCTestLib.sol b/devkit/method/MCTestLib.sol similarity index 100% rename from devkit/global/MCTestLib.sol rename to devkit/method/MCTestLib.sol diff --git a/devkit/core/functions/FunctionLib.sol b/devkit/method/core/FunctionLib.sol similarity index 98% rename from devkit/core/functions/FunctionLib.sol rename to devkit/method/core/FunctionLib.sol index c65214dd..9982bf07 100644 --- a/devkit/core/functions/FunctionLib.sol +++ b/devkit/method/core/FunctionLib.sol @@ -17,8 +17,8 @@ import {AddressUtils} from "../../utils/AddressUtils.sol"; // import {Debug} from "../../debug/Debug.sol"; // import {Logger} from "../../debug/Logger.sol"; // Core -import {Function} from "./Function.sol"; -import {Bundle} from "./Bundle.sol"; +import {Function} from "devkit/core/functions/Function.sol"; +import {Bundle} from "devkit/core/functions/Bundle.sol"; /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/devkit/debug/LogLib.sol b/devkit/method/debug/LogLib.sol similarity index 94% rename from devkit/debug/LogLib.sol rename to devkit/method/debug/LogLib.sol index 36be8e9a..45b49afe 100644 --- a/devkit/debug/LogLib.sol +++ b/devkit/method/debug/LogLib.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Logger} from "./Logger.sol"; +import {Logger} from "devkit/debug/Logger.sol"; import {Function} from "devkit/core/functions/Function.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; diff --git a/devkit/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol similarity index 93% rename from devkit/debug/ProcessLib.sol rename to devkit/method/debug/ProcessLib.sol index 503a2ba0..5368dcd0 100644 --- a/devkit/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Debug} from "./Debug.sol"; +import {Debug} from "devkit/debug/Debug.sol"; // Types import {Function} from "devkit/core/functions/Function.sol"; From c85e313a86d9c05160b48b4abc10cfec8a787385 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 10:43:52 +0900 Subject: [PATCH 017/111] fix typo --- devkit/method/MCTestLib.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devkit/method/MCTestLib.sol b/devkit/method/MCTestLib.sol index 682a395e..aa146738 100644 --- a/devkit/method/MCTestLib.sol +++ b/devkit/method/MCTestLib.sol @@ -95,7 +95,7 @@ library MCTestLib { uint pid = mc.recordExecStart("setStorageReader", Params.append(selector, implementation)); dictionary.set( Function({ - name: "StorageGetter", + name: "StorageReader", selector: selector, implementation: implementation }) From eb0d14a11fa1adde62a1a30f677d37c6e3a1ca89 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 13:13:01 +0900 Subject: [PATCH 018/111] Move core/Function --- devkit/MCDevKit.sol | 2 +- devkit/core/{functions => }/Function.sol | 3 + devkit/core/FunctionRegistry.sol | 244 ++++++++++++++++++ devkit/core/dictionary/Dictionary.sol | 2 +- devkit/core/functions/Bundle.sol | 2 +- ...unctionRegistry.sol => BundleRegistry.sol} | 0 devkit/core/functions/StdFunctions.sol | 2 +- devkit/core/functions/StdRegistry.sol | 244 ++++++++++++++++++ devkit/core/proxy/Proxy.sol | 2 +- devkit/error/Error.sol | 2 + devkit/error/Validation.sol | 9 + devkit/method/MCBundleLib.sol | 2 +- devkit/method/MCFinderLib.sol | 2 +- devkit/method/MCTestLib.sol | 17 +- devkit/method/core/FunctionLib.sol | 66 ++++- devkit/method/debug/LogLib.sol | 2 +- devkit/method/debug/ProcessLib.sol | 2 +- devkit/test/MockDictionary.sol | 2 +- devkit/test/SimpleMockProxy.sol | 2 +- devkit/utils/ForgeHelper.sol | 4 + devkit/utils/type/TypeSafetyUtils.sol | 15 ++ test/devkit/MCDevKit.t.sol | 2 +- test/devkit/global/MCBundle.t.sol | 2 +- test/devkit/global/MCSetup.t.sol | 2 +- test/utils/TestHelper.sol | 2 +- 25 files changed, 603 insertions(+), 31 deletions(-) rename devkit/core/{functions => }/Function.sol (78%) create mode 100644 devkit/core/FunctionRegistry.sol rename devkit/core/functions/{FunctionRegistry.sol => BundleRegistry.sol} (100%) create mode 100644 devkit/core/functions/StdRegistry.sol create mode 100644 devkit/utils/type/TypeSafetyUtils.sol diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index e23f68c6..2fdf03ad 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Core Registries -import {FunctionRegistry} from "devkit/core/functions/FunctionRegistry.sol"; +import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; import {DictionaryRegistry} from "devkit/core/dictionary/DictionaryRegistry.sol"; import {ProxyRegistry} from "devkit/core/proxy/ProxyRegistry.sol"; diff --git a/devkit/core/functions/Function.sol b/devkit/core/Function.sol similarity index 78% rename from devkit/core/functions/Function.sol rename to devkit/core/Function.sol index bdf723f9..ee0f1f49 100644 --- a/devkit/core/functions/Function.sol +++ b/devkit/core/Function.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; import {FunctionLib} from "devkit/method/core/FunctionLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; import {LogLib} from "devkit/method/debug/LogLib.sol"; +import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; /**================== @@ -13,7 +14,9 @@ struct Function { /// @dev Function may be different depending on the op version string name; bytes4 selector; address implementation; + BuildStatus buildStatus; } using FunctionLib for Function global; using ProcessLib for Function global; using LogLib for Function global; +using TypeSafetyUtils for Function global; diff --git a/devkit/core/FunctionRegistry.sol b/devkit/core/FunctionRegistry.sol new file mode 100644 index 00000000..dd492efc --- /dev/null +++ b/devkit/core/FunctionRegistry.sol @@ -0,0 +1,244 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Error & Debug +import {check} from "devkit/error/Validation.sol"; +import {ERR, throwError} from "devkit/error/Error.sol"; +import {Debug} from "devkit/debug/Debug.sol"; +// Config +import {ScanRange, Config} from "devkit/config/Config.sol"; +// Utils +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +// Core +import {Function} from "./Function.sol"; +import {Bundle} from "devkit/core/functions/Bundle.sol"; +import {StdFunctions} from "devkit/core/functions/StdFunctions.sol"; + + +/**------------------------------- + 🧩 UCS Functions Registry +---------------------------------*/ +using FunctionRegistryLib for FunctionRegistry global; +struct FunctionRegistry { + StdFunctions std; + mapping(bytes32 nameHash => Function) customs; + mapping(bytes32 nameHash => Bundle) bundles; + string currentFunctionName; + string currentBundleName; +} + +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + << Primary >> + 🌱 Init Bundle + ✨ Add Custom Function + 🔏 Load and Assign Custom Function from Env + đŸ§ē Add Custom Function to Bundle + đŸĒŸ Set Facade + đŸ”ŧ Update Current Context Function & Bundle + 🔍 Find Function & Bundle + 🏷 Generate Unique Name + << Helper >> + 🔍 Find Custom Function +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library FunctionRegistryLib { + string constant LIB_NAME = "FunctionRegistry"; + + + /**--------------------- + 🌱 Init Bundle + -----------------------*/ + function init(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("init"); + functions.bundles[name.safeCalcHash()].safeAssign(name); + functions.safeUpdateCurrentBundle(name); + return functions.recordExecFinish(pid); + } + function safeInit(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("safeInit"); + check(name.isNotEmpty(), "Empty Name"); + return functions.assertBundleNotExists(name) + .init(name) + .recordExecFinish(pid); + } + + + /**--------------------------- + ✨ Add Custom Function + -----------------------------*/ + function safeAddFunction(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("safeAddFunction"); + check(name.isNotEmpty(), "Empty Name"); + functions.customs[name.safeCalcHash()] + .safeAssign(name) + .safeAssign(selector) + .safeAssign(implementation); + functions.safeUpdateCurrentFunction(name); + return functions.recordExecFinish(pid); + } + + + /**--------------------------------------------- + 🔏 Load and Add Custom Function from Env + -----------------------------------------------*/ + function safeLoadAndAdd(FunctionRegistry storage functions, string memory envKey, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("safeLoadAndAdd"); + functions.customs[name.safeCalcHash()] + .loadAndAssignFromEnv(envKey, name, selector); + functions.safeUpdateCurrentFunction(name); + return functions.recordExecFinish(pid); + } + + + /**------------------------------------- + đŸ§ē Add Custom Function to Bundle + ---------------------------------------*/ + function addToBundle(FunctionRegistry storage functions, Function storage functionInfo) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("addToBundle", "function"); + functions.findCurrentBundle().safeAdd(functionInfo); + return functions.recordExecFinish(pid); + } + function addToBundle(FunctionRegistry storage functions, Function[] storage functionInfos) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("addToBundle", "functions"); // TODO params + functions.findCurrentBundle().safeAdd(functionInfos); + return functions.recordExecFinish(pid); + } + + + /**------------------ + đŸĒŸ Set Facade + --------------------*/ + function set(FunctionRegistry storage functions, string memory name, address facade) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("set"); + functions.bundles[name.safeCalcHash()] + .assertExists() + .safeAssign(facade); + return functions.recordExecFinish(pid); + } + function set(FunctionRegistry storage functions, address facade) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("set"); + return functions.set(functions.findCurrentBundleName(), facade).recordExecFinish(pid); + } + + + /**------------------------------------------------ + đŸ”ŧ Update Current Context Function & Bundle + --------------------------------------------------*/ + /**----- 🧩 Function -------*/ + function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("safeUpdateCurrentFunction"); + functions.currentFunctionName = name.assertNotEmpty(); + return functions.recordExecFinish(pid); + } + /**----- đŸ§ē Bundle -------*/ + function safeUpdateCurrentBundle(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("safeUpdateCurrentBundle"); + functions.currentBundleName = name.assertNotEmpty(); + return functions.recordExecFinish(pid); + } + + + /**----------------------------------------------- + â™ģī¸ Reset Current Context Function & Bundle + -------------------------------------------------*/ + function reset(FunctionRegistry storage functions) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("reset"); + delete functions.currentFunctionName; + delete functions.currentBundleName; + return functions.recordExecFinish(pid); + } + + + /**------------------------------- + 🔍 Find Function & Bundle + ---------------------------------*/ + /**----- 🧩 Function -------*/ + function findFunction(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { + uint pid = functions.recordExecStart("findFunction"); + return functions.customs[name.safeCalcHash()].assertExists().finishProcess(pid); + } + function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { + uint pid = functions.recordExecStart("findCurrentFunction"); + return functions.findFunction(functions.findCurrentFunctionName()).finishProcess(pid); + } + function findCurrentFunctionName(FunctionRegistry storage functions) internal returns(string memory) { + uint pid = functions.recordExecStart("findCurrentFunctionName"); + return functions.currentFunctionName.assertNotEmpty().recordExecFinish(pid); + } + + /**----- đŸ§ē Bundle -------*/ + function findBundle(FunctionRegistry storage functions, string memory name) internal returns(Bundle storage) { + uint pid = functions.recordExecStart("findBundle"); + return functions.bundles[name.safeCalcHash()].recordExecFinish(pid); + } + function findCurrentBundle(FunctionRegistry storage functions) internal returns(Bundle storage) { + uint pid = functions.recordExecStart("findCurrentBundle"); + return functions.findBundle(functions.findCurrentBundleName()).recordExecFinish(pid); + } + function findCurrentBundleName(FunctionRegistry storage functions) internal returns(string memory) { + uint pid = functions.recordExecStart("findCurrentBundleName"); + return functions.currentBundleName.assertNotEmpty().recordExecFinish(pid); + } + + + /**----------------------------- + 🏷 Generate Unique Name + -------------------------------*/ + function genUniqueBundleName(FunctionRegistry storage functions) internal returns(string memory name) { + uint pid = functions.recordExecStart("genUniqueBundleName"); + ScanRange storage range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = Config().DEFAULT_BUNDLE_NAME.toSequential(i); + if (functions.existsBundle(name).isFalse()) return name.recordExecFinish(pid); + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + + + + /**------------------------------- + 🧐 Inspectors & Assertions + ---------------------------------*/ + function existsBundle(FunctionRegistry storage functions, string memory name) internal returns(bool) { + return functions.bundles[name.safeCalcHash()].hasName(); + } + function notExistsBundle(FunctionRegistry storage functions, string memory name) internal returns(bool) { + return functions.existsBundle(name).isNot(); + } + function assertBundleNotExists(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + check(functions.notExistsBundle(name), "Bundle Already Exists"); + return functions; + } + + function existsCurrentBundle(FunctionRegistry storage functions) internal returns(bool) { + return functions.currentBundleName.isNotEmpty(); + } + function notExistsCurrentBundle(FunctionRegistry storage functions) internal returns(bool) { + return functions.existsCurrentBundle().isNot(); + } + + + /**---------------- + 🐞 Debug + ------------------*/ + /** + Record Start + */ + function recordExecStart(FunctionRegistry storage, string memory funcName, string memory params) internal returns(uint) { + return Debug.recordExecStart(LIB_NAME, funcName, params); + } + function recordExecStart(FunctionRegistry storage functions, string memory funcName) internal returns(uint) { + return functions.recordExecStart(funcName, ""); + } + + /** + Record Finish + */ + function recordExecFinish(FunctionRegistry storage functions, uint pid) internal returns(FunctionRegistry storage) { + Debug.recordExecFinish(pid); + return functions; + } + +} diff --git a/devkit/core/dictionary/Dictionary.sol b/devkit/core/dictionary/Dictionary.sol index 3db5a4b1..75b93b0c 100644 --- a/devkit/core/dictionary/Dictionary.sol +++ b/devkit/core/dictionary/Dictionary.sol @@ -17,7 +17,7 @@ import {ForgeHelper} from "../../utils/ForgeHelper.sol"; // Debug import {Debug} from "../../debug/Debug.sol"; // Core -import {Function} from "../functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; import {Bundle} from "../functions/Bundle.sol"; // Test import {MockDictionary} from "../../test/MockDictionary.sol"; diff --git a/devkit/core/functions/Bundle.sol b/devkit/core/functions/Bundle.sol index 24465cfd..bdf23fa1 100644 --- a/devkit/core/functions/Bundle.sol +++ b/devkit/core/functions/Bundle.sol @@ -17,7 +17,7 @@ import {Bytes4Utils} from "../../utils/Bytes4Utils.sol"; import {Debug} from "../../debug/Debug.sol"; import {Logger} from "../../debug/Logger.sol"; // Core -import {Function} from "./Function.sol"; +import {Function} from "devkit/core/Function.sol"; /**==================== đŸ§ē Bundle Info diff --git a/devkit/core/functions/FunctionRegistry.sol b/devkit/core/functions/BundleRegistry.sol similarity index 100% rename from devkit/core/functions/FunctionRegistry.sol rename to devkit/core/functions/BundleRegistry.sol diff --git a/devkit/core/functions/StdFunctions.sol b/devkit/core/functions/StdFunctions.sol index 6580ecff..ba95f1ac 100644 --- a/devkit/core/functions/StdFunctions.sol +++ b/devkit/core/functions/StdFunctions.sol @@ -11,7 +11,7 @@ import {StringUtils} from "../../utils/StringUtils.sol"; import {Debug} from "../../debug/Debug.sol"; import {Logger} from "../../debug/Logger.sol"; // Core -import {Function} from "./Function.sol"; +import {Function} from "devkit/core/Function.sol"; import {Bundle} from "./Bundle.sol"; // MC Std import {Clone} from "mc-std/functions/Clone.sol"; diff --git a/devkit/core/functions/StdRegistry.sol b/devkit/core/functions/StdRegistry.sol new file mode 100644 index 00000000..81aa149c --- /dev/null +++ b/devkit/core/functions/StdRegistry.sol @@ -0,0 +1,244 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Error & Debug +import {check} from "devkit/error/Validation.sol"; +import {ERR, throwError} from "devkit/error/Error.sol"; +import {Debug} from "devkit/debug/Debug.sol"; +// Config +import {ScanRange, Config} from "devkit/config/Config.sol"; +// Utils +import {StringUtils} from "../../utils/StringUtils.sol"; + using StringUtils for string; +import {BoolUtils} from "../../utils/BoolUtils.sol"; + using BoolUtils for bool; +// Core +import {Function} from "./Function.sol"; +import {Bundle} from "./Bundle.sol"; +import {StdFunctions} from "./StdFunctions.sol"; + + +/**------------------------------- + 🧩 UCS Functions Registry +---------------------------------*/ +using FunctionRegistryLib for FunctionRegistry global; +struct FunctionRegistry { + StdFunctions std; + mapping(bytes32 nameHash => Function) customs; + mapping(bytes32 nameHash => Bundle) bundles; + string currentFunctionName; + string currentBundleName; +} + +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + << Primary >> + 🌱 Init Bundle + ✨ Add Custom Function + 🔏 Load and Assign Custom Function from Env + đŸ§ē Add Custom Function to Bundle + đŸĒŸ Set Facade + đŸ”ŧ Update Current Context Function & Bundle + 🔍 Find Function & Bundle + 🏷 Generate Unique Name + << Helper >> + 🔍 Find Custom Function +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library FunctionRegistryLib { + string constant LIB_NAME = "FunctionRegistry"; + + + /**--------------------- + 🌱 Init Bundle + -----------------------*/ + function init(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("init"); + functions.bundles[name.safeCalcHash()].safeAssign(name); + functions.safeUpdateCurrentBundle(name); + return functions.recordExecFinish(pid); + } + function safeInit(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("safeInit"); + check(name.isNotEmpty(), "Empty Name"); + return functions.assertBundleNotExists(name) + .init(name) + .recordExecFinish(pid); + } + + + /**--------------------------- + ✨ Add Custom Function + -----------------------------*/ + function safeAddFunction(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("safeAddFunction"); + check(name.isNotEmpty(), "Empty Name"); + functions.customs[name.safeCalcHash()] + .safeAssign(name) + .safeAssign(selector) + .safeAssign(implementation); + functions.safeUpdateCurrentFunction(name); + return functions.recordExecFinish(pid); + } + + + /**--------------------------------------------- + 🔏 Load and Add Custom Function from Env + -----------------------------------------------*/ + function safeLoadAndAdd(FunctionRegistry storage functions, string memory envKey, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("safeLoadAndAdd"); + functions.customs[name.safeCalcHash()] + .loadAndAssignFromEnv(envKey, name, selector); + functions.safeUpdateCurrentFunction(name); + return functions.recordExecFinish(pid); + } + + + /**------------------------------------- + đŸ§ē Add Custom Function to Bundle + ---------------------------------------*/ + function addToBundle(FunctionRegistry storage functions, Function storage functionInfo) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("addToBundle", "function"); + functions.findCurrentBundle().safeAdd(functionInfo); + return functions.recordExecFinish(pid); + } + function addToBundle(FunctionRegistry storage functions, Function[] storage functionInfos) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("addToBundle", "functions"); // TODO params + functions.findCurrentBundle().safeAdd(functionInfos); + return functions.recordExecFinish(pid); + } + + + /**------------------ + đŸĒŸ Set Facade + --------------------*/ + function set(FunctionRegistry storage functions, string memory name, address facade) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("set"); + functions.bundles[name.safeCalcHash()] + .assertExists() + .safeAssign(facade); + return functions.recordExecFinish(pid); + } + function set(FunctionRegistry storage functions, address facade) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("set"); + return functions.set(functions.findCurrentBundleName(), facade).recordExecFinish(pid); + } + + + /**------------------------------------------------ + đŸ”ŧ Update Current Context Function & Bundle + --------------------------------------------------*/ + /**----- 🧩 Function -------*/ + function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("safeUpdateCurrentFunction"); + functions.currentFunctionName = name.assertNotEmpty(); + return functions.recordExecFinish(pid); + } + /**----- đŸ§ē Bundle -------*/ + function safeUpdateCurrentBundle(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("safeUpdateCurrentBundle"); + functions.currentBundleName = name.assertNotEmpty(); + return functions.recordExecFinish(pid); + } + + + /**----------------------------------------------- + â™ģī¸ Reset Current Context Function & Bundle + -------------------------------------------------*/ + function reset(FunctionRegistry storage functions) internal returns(FunctionRegistry storage) { + uint pid = functions.recordExecStart("reset"); + delete functions.currentFunctionName; + delete functions.currentBundleName; + return functions.recordExecFinish(pid); + } + + + /**------------------------------- + 🔍 Find Function & Bundle + ---------------------------------*/ + /**----- 🧩 Function -------*/ + function findFunction(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { + uint pid = functions.recordExecStart("findFunction"); + return functions.customs[name.safeCalcHash()].assertExists().finishProcess(pid); + } + function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { + uint pid = functions.recordExecStart("findCurrentFunction"); + return functions.findFunction(functions.findCurrentFunctionName()).finishProcess(pid); + } + function findCurrentFunctionName(FunctionRegistry storage functions) internal returns(string memory) { + uint pid = functions.recordExecStart("findCurrentFunctionName"); + return functions.currentFunctionName.assertNotEmpty().recordExecFinish(pid); + } + + /**----- đŸ§ē Bundle -------*/ + function findBundle(FunctionRegistry storage functions, string memory name) internal returns(Bundle storage) { + uint pid = functions.recordExecStart("findBundle"); + return functions.bundles[name.safeCalcHash()].recordExecFinish(pid); + } + function findCurrentBundle(FunctionRegistry storage functions) internal returns(Bundle storage) { + uint pid = functions.recordExecStart("findCurrentBundle"); + return functions.findBundle(functions.findCurrentBundleName()).recordExecFinish(pid); + } + function findCurrentBundleName(FunctionRegistry storage functions) internal returns(string memory) { + uint pid = functions.recordExecStart("findCurrentBundleName"); + return functions.currentBundleName.assertNotEmpty().recordExecFinish(pid); + } + + + /**----------------------------- + 🏷 Generate Unique Name + -------------------------------*/ + function genUniqueBundleName(FunctionRegistry storage functions) internal returns(string memory name) { + uint pid = functions.recordExecStart("genUniqueBundleName"); + ScanRange storage range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = Config().DEFAULT_BUNDLE_NAME.toSequential(i); + if (functions.existsBundle(name).isFalse()) return name.recordExecFinish(pid); + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + + + + /**------------------------------- + 🧐 Inspectors & Assertions + ---------------------------------*/ + function existsBundle(FunctionRegistry storage functions, string memory name) internal returns(bool) { + return functions.bundles[name.safeCalcHash()].hasName(); + } + function notExistsBundle(FunctionRegistry storage functions, string memory name) internal returns(bool) { + return functions.existsBundle(name).isNot(); + } + function assertBundleNotExists(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + check(functions.notExistsBundle(name), "Bundle Already Exists"); + return functions; + } + + function existsCurrentBundle(FunctionRegistry storage functions) internal returns(bool) { + return functions.currentBundleName.isNotEmpty(); + } + function notExistsCurrentBundle(FunctionRegistry storage functions) internal returns(bool) { + return functions.existsCurrentBundle().isNot(); + } + + + /**---------------- + 🐞 Debug + ------------------*/ + /** + Record Start + */ + function recordExecStart(FunctionRegistry storage, string memory funcName, string memory params) internal returns(uint) { + return Debug.recordExecStart(LIB_NAME, funcName, params); + } + function recordExecStart(FunctionRegistry storage functions, string memory funcName) internal returns(uint) { + return functions.recordExecStart(funcName, ""); + } + + /** + Record Finish + */ + function recordExecFinish(FunctionRegistry storage functions, uint pid) internal returns(FunctionRegistry storage) { + Debug.recordExecFinish(pid); + return functions; + } + +} diff --git a/devkit/core/proxy/Proxy.sol b/devkit/core/proxy/Proxy.sol index ebb4ea72..6e004521 100644 --- a/devkit/core/proxy/Proxy.sol +++ b/devkit/core/proxy/Proxy.sol @@ -15,7 +15,7 @@ import {ForgeHelper} from "../../utils/ForgeHelper.sol"; // Core // import {MCStdFuncs} from "../../core/functions/MCStdFuncs.sol"; import {Dictionary} from "../dictionary/Dictionary.sol"; -import {Function} from "../functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; // Test import {SimpleMockProxy} from "../../test/SimpleMockProxy.sol"; // External Lib diff --git a/devkit/error/Error.sol b/devkit/error/Error.sol index bbadf84e..b1e3d076 100644 --- a/devkit/error/Error.sol +++ b/devkit/error/Error.sol @@ -22,6 +22,8 @@ library ERR { string constant NOT_CONTRACT = "Not Contract Address"; string constant STR_ALREADY_ASSIGNED = "String Already Assigned"; string constant B4_ALREADY_ASSIGNED = "Bytes4 Already Assigned"; + string constant RQ_SELECTOR = "Selector is required."; + string constant RQ_CONTRACT = "Contract is required."; // string constant STR_EXISTS = "String Already Exist"; string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; diff --git a/devkit/error/Validation.sol b/devkit/error/Validation.sol index a401185a..765f70ec 100644 --- a/devkit/error/Validation.sol +++ b/devkit/error/Validation.sol @@ -39,3 +39,12 @@ library Check { check(addr.isContract(), ERR.NOT_CONTRACT); } } + +library Require { + function assigned(bytes4 str) internal { + check(str.isNotEmpty(), ERR.RQ_SELECTOR); + } + function contractAssigned(address addr) internal { + check(addr.isContract(), ERR.RQ_CONTRACT); + } +} diff --git a/devkit/method/MCBundleLib.sol b/devkit/method/MCBundleLib.sol index 52602223..b850e132 100644 --- a/devkit/method/MCBundleLib.sol +++ b/devkit/method/MCBundleLib.sol @@ -9,7 +9,7 @@ import {ERR} from "devkit/error/Error.sol"; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {Params} from "devkit/debug/Params.sol"; // Core -import {Function} from "devkit/core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; /*********************************************** diff --git a/devkit/method/MCFinderLib.sol b/devkit/method/MCFinderLib.sol index 5869acf5..ab6d59e7 100644 --- a/devkit/method/MCFinderLib.sol +++ b/devkit/method/MCFinderLib.sol @@ -5,7 +5,7 @@ import {MCDevKit} from "devkit/MCDevKit.sol"; // Core // functions import {Bundle} from "devkit/core/functions/Bundle.sol"; -import {Function} from "devkit/core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; // proxy import {Proxy} from "devkit/core/proxy/Proxy.sol"; // dictionary diff --git a/devkit/method/MCTestLib.sol b/devkit/method/MCTestLib.sol index aa146738..a3078930 100644 --- a/devkit/method/MCTestLib.sol +++ b/devkit/method/MCTestLib.sol @@ -8,7 +8,7 @@ import {Params} from "devkit/debug/Params.sol"; // Core // functions import {Bundle} from "devkit/core/functions/Bundle.sol"; -import {Function} from "devkit/core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; // proxy import {Proxy, ProxyLib} from "devkit/core/proxy/Proxy.sol"; // dictionary @@ -93,13 +93,14 @@ library MCTestLib { ----------------------------*/ function setStorageReader(MCDevKit storage mc, Dictionary memory dictionary, bytes4 selector, address implementation) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("setStorageReader", Params.append(selector, implementation)); - dictionary.set( - Function({ - name: "StorageReader", - selector: selector, - implementation: implementation - }) - ); + // dictionary.set( + // Function.create("aaa") + // // Function({ + // // name: "StorageReader", + // // selector: selector, + // // implementation: implementation + // // }) + // ); return mc.recordExecFinish(pid); } function setStorageReader(MCDevKit storage mc, string memory bundleName, bytes4 selector, address implementation) internal returns(MCDevKit storage) { diff --git a/devkit/method/core/FunctionLib.sol b/devkit/method/core/FunctionLib.sol index 9982bf07..1b42221f 100644 --- a/devkit/method/core/FunctionLib.sol +++ b/devkit/method/core/FunctionLib.sol @@ -2,24 +2,21 @@ pragma solidity ^0.8.24; // Validation -import {check, Check} from "devkit/error/Validation.sol"; -// import {throwError} from "devkit/error/Error.sol"; -// import {ProcessLib} from "devkit/debug/ProcessLib.sol"; +import {check, Check, Require} from "devkit/error/Validation.sol"; // Utils -import {ForgeHelper} from "../../utils/ForgeHelper.sol"; +import {ForgeHelper, loadAddressFrom} from "../../utils/ForgeHelper.sol"; import {StringUtils} from "../../utils/StringUtils.sol"; using StringUtils for string; import {Bytes4Utils} from "../../utils/Bytes4Utils.sol"; using Bytes4Utils for bytes4; import {AddressUtils} from "../../utils/AddressUtils.sol"; using AddressUtils for address; -// // Debug -// import {Debug} from "../../debug/Debug.sol"; -// import {Logger} from "../../debug/Logger.sol"; // Core -import {Function} from "devkit/core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/functions/Bundle.sol"; +import {BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ << Primary >> @@ -35,9 +32,51 @@ library FunctionLib { /**------------------------ đŸ“Ĩ Assign Function --------------------------*/ + function assign(Function storage func, string memory name, bytes4 selector, address implementation) internal returns(Function storage) { + uint pid = func.startProcess("safeAssign"); + Check.isUnassigned(func.name); + Check.isNotEmpty(name); + Check.isNotEmpty(selector); + Check.isContract(implementation); + func.name = name; + func.selector = selector; + func.implementation = implementation; + return func.finishProcess(pid); + } + + function asBuilding(Function storage func) internal returns(Function storage) { + func.buildStatus = BuildStatus.Building; + return func; + } + function build(Function storage func) internal returns(Function storage) { + Require.assigned(func.selector); + Require.contractAssigned(func.implementation); + func.buildStatus = BuildStatus.Built; + return func; + } + + function assign(Function storage func, bytes4 selector, address implementation) internal returns(Function storage) { + func.assignSelector(selector); + func.assignImplementation(implementation); + return func; + } + + function assignSelector(Function storage func, bytes4 selector) internal returns(Function storage) { + func.selector = selector; + func.asBuilding(); + return func; + } + function assignImplementation(Function storage func, address implementation) internal returns(Function storage) { + func.implementation = implementation; + func.asBuilding(); + return func; + } + + /**----- Name --------*/ function assign(Function storage func, string memory name) internal returns(Function storage) { func.name = name; + return func; } function safeAssign(Function storage func, string memory name) internal returns(Function storage) { @@ -73,6 +112,17 @@ library FunctionLib { func.implementation = implementation; return func; } + function fetch(Function storage func, string memory envKey) internal returns(Function storage) { + uint pid = func.startProcess("fetch"); + Check.isUnassigned(func.name); + Check.isNotEmpty(envKey); + return func; + } + function fetchAndAssign(Function storage func, string memory envKey, bytes4 selector) internal returns(Function storage) { + uint pid = func.startProcess("fetchAndAssign"); + func.assign(envKey, selector, loadAddressFrom(envKey)); + return func.finishProcess(pid); + } function loadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { uint pid = func.startProcess("loadAndAssignFromEnv"); diff --git a/devkit/method/debug/LogLib.sol b/devkit/method/debug/LogLib.sol index 45b49afe..ed992488 100644 --- a/devkit/method/debug/LogLib.sol +++ b/devkit/method/debug/LogLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {Logger} from "devkit/debug/Logger.sol"; -import {Function} from "devkit/core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol index 5368dcd0..0d52cd81 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; import {Debug} from "devkit/debug/Debug.sol"; // Types -import {Function} from "devkit/core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; library ProcessLib { function startProcess(Function storage, string memory name, string memory params) internal returns(uint) { diff --git a/devkit/test/MockDictionary.sol b/devkit/test/MockDictionary.sol index be569704..3620d2ee 100644 --- a/devkit/test/MockDictionary.sol +++ b/devkit/test/MockDictionary.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Core -import {Function} from "../core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; // External Lib import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; diff --git a/devkit/test/SimpleMockProxy.sol b/devkit/test/SimpleMockProxy.sol index 791f2112..13bbcf4a 100644 --- a/devkit/test/SimpleMockProxy.sol +++ b/devkit/test/SimpleMockProxy.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Core -import {Function} from "../core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; // External Lib import {Proxy as OZProxy} from "@oz.mc/proxy/Proxy.sol"; diff --git a/devkit/utils/ForgeHelper.sol b/devkit/utils/ForgeHelper.sol index cfe72030..cf4a104d 100644 --- a/devkit/utils/ForgeHelper.sol +++ b/devkit/utils/ForgeHelper.sol @@ -15,6 +15,10 @@ import {StdStyle} from "forge-std/StdStyle.sol"; /// @dev address(uint160(uint256(keccak256("hevm cheat code")))); Vm constant vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); +function loadAddressFrom(string memory envKey) returns(address) { + return ForgeHelper.loadAddressFromEnv(envKey); +} + /************************************** 🛠 Helper Methods for Forge Std **************************************/ diff --git a/devkit/utils/type/TypeSafetyUtils.sol b/devkit/utils/type/TypeSafetyUtils.sol new file mode 100644 index 00000000..444bce54 --- /dev/null +++ b/devkit/utils/type/TypeSafetyUtils.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// import {StringUtils} from "devkit/utils/StringUtils.sol"; +// using StringUtils for string; +// import {AddressUtils} from "devkit/utils/AddressUtils.sol"; +// using AddressUtils for address; +// import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; +// using Bytes4Utils for bytes4; + +enum BuildStatus { Building, Built } + +library TypeSafetyUtils { + +} diff --git a/test/devkit/MCDevKit.t.sol b/test/devkit/MCDevKit.t.sol index b872459d..d0b38722 100644 --- a/test/devkit/MCDevKit.t.sol +++ b/test/devkit/MCDevKit.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; import {Test, console2} from "forge-std/Test.sol"; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Function} from "devkit/core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; import {TestHelper} from "../utils/TestHelper.sol"; using TestHelper for Function; diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 5e8bbc4a..57d4992c 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -9,7 +9,7 @@ import {Config} from "devkit/config/Config.sol"; import {ERR} from "devkit/error/Error.sol"; import {Bundle} from "devkit/core/functions/Bundle.sol"; -import {Function} from "devkit/core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; import {DummyFunction} from "test/utils/DummyFunction.sol"; import {DummyFacade} from "test/utils/DummyFacade.sol"; diff --git a/test/devkit/global/MCSetup.t.sol b/test/devkit/global/MCSetup.t.sol index 1aa85927..5ccc6bef 100644 --- a/test/devkit/global/MCSetup.t.sol +++ b/test/devkit/global/MCSetup.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; import {MCDevKitTest} from "devkit/MCTest.sol"; -import {Function} from "devkit/core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; import {TestHelper} from "test/utils/TestHelper.sol"; using TestHelper for Function; diff --git a/test/utils/TestHelper.sol b/test/utils/TestHelper.sol index 04ac0110..90f99b97 100644 --- a/test/utils/TestHelper.sol +++ b/test/utils/TestHelper.sol @@ -6,7 +6,7 @@ import {AddressUtils} from "devkit/utils/AddressUtils.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; -import {Function} from "devkit/core/functions/Function.sol"; +import {Function} from "devkit/core/Function.sol"; // import {Bundle} from "./Bundle.sol"; import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; From e2af6ce322458f0e193bf85b2024cfe0b8e60669 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 13:25:34 +0900 Subject: [PATCH 019/111] Move core/functions --- devkit/MCDevKit.sol | 4 + devkit/core/{functions => }/Bundle.sol | 0 .../core/{functions => }/BundleRegistry.sol | 0 devkit/core/FunctionRegistry.sol | 115 +-------- devkit/core/{functions => }/StdFunctions.sol | 0 devkit/core/functions/StdRegistry.sol | 244 ------------------ devkit/method/MCDeployLib.sol | 4 +- devkit/method/MCFinderLib.sol | 2 +- devkit/method/MCTestLib.sol | 2 +- devkit/method/core/FunctionLib.sol | 2 +- script/DeployLib.sol | 2 +- test/devkit/global/MCBundle.t.sol | 2 +- 12 files changed, 14 insertions(+), 363 deletions(-) rename devkit/core/{functions => }/Bundle.sol (100%) rename devkit/core/{functions => }/BundleRegistry.sol (100%) rename devkit/core/{functions => }/StdFunctions.sol (100%) delete mode 100644 devkit/core/functions/StdRegistry.sol diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index 2fdf03ad..63e303b9 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -3,6 +3,8 @@ pragma solidity ^0.8.24; // Core Registries import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; +import {StdFunctions} from "devkit/core/StdFunctions.sol"; +import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; import {DictionaryRegistry} from "devkit/core/dictionary/DictionaryRegistry.sol"; import {ProxyRegistry} from "devkit/core/proxy/ProxyRegistry.sol"; @@ -20,7 +22,9 @@ import {MCDebugLib} from "devkit/method/MCDebugLib.sol"; 🌟 Meta Contract DevKit *********************************/ struct MCDevKit { + StdFunctions std; FunctionRegistry functions; + BundleRegistry bundle; DictionaryRegistry dictionary; ProxyRegistry proxy; } diff --git a/devkit/core/functions/Bundle.sol b/devkit/core/Bundle.sol similarity index 100% rename from devkit/core/functions/Bundle.sol rename to devkit/core/Bundle.sol diff --git a/devkit/core/functions/BundleRegistry.sol b/devkit/core/BundleRegistry.sol similarity index 100% rename from devkit/core/functions/BundleRegistry.sol rename to devkit/core/BundleRegistry.sol diff --git a/devkit/core/FunctionRegistry.sol b/devkit/core/FunctionRegistry.sol index dd492efc..c45ffe2d 100644 --- a/devkit/core/FunctionRegistry.sol +++ b/devkit/core/FunctionRegistry.sol @@ -14,8 +14,8 @@ import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; // Core import {Function} from "./Function.sol"; -import {Bundle} from "devkit/core/functions/Bundle.sol"; -import {StdFunctions} from "devkit/core/functions/StdFunctions.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {StdFunctions} from "devkit/core/StdFunctions.sol"; /**------------------------------- @@ -23,11 +23,9 @@ import {StdFunctions} from "devkit/core/functions/StdFunctions.sol"; ---------------------------------*/ using FunctionRegistryLib for FunctionRegistry global; struct FunctionRegistry { - StdFunctions std; mapping(bytes32 nameHash => Function) customs; mapping(bytes32 nameHash => Bundle) bundles; string currentFunctionName; - string currentBundleName; } /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -47,24 +45,6 @@ library FunctionRegistryLib { string constant LIB_NAME = "FunctionRegistry"; - /**--------------------- - 🌱 Init Bundle - -----------------------*/ - function init(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("init"); - functions.bundles[name.safeCalcHash()].safeAssign(name); - functions.safeUpdateCurrentBundle(name); - return functions.recordExecFinish(pid); - } - function safeInit(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("safeInit"); - check(name.isNotEmpty(), "Empty Name"); - return functions.assertBundleNotExists(name) - .init(name) - .recordExecFinish(pid); - } - - /**--------------------------- ✨ Add Custom Function -----------------------------*/ @@ -92,52 +72,14 @@ library FunctionRegistryLib { } - /**------------------------------------- - đŸ§ē Add Custom Function to Bundle - ---------------------------------------*/ - function addToBundle(FunctionRegistry storage functions, Function storage functionInfo) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("addToBundle", "function"); - functions.findCurrentBundle().safeAdd(functionInfo); - return functions.recordExecFinish(pid); - } - function addToBundle(FunctionRegistry storage functions, Function[] storage functionInfos) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("addToBundle", "functions"); // TODO params - functions.findCurrentBundle().safeAdd(functionInfos); - return functions.recordExecFinish(pid); - } - - - /**------------------ - đŸĒŸ Set Facade - --------------------*/ - function set(FunctionRegistry storage functions, string memory name, address facade) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("set"); - functions.bundles[name.safeCalcHash()] - .assertExists() - .safeAssign(facade); - return functions.recordExecFinish(pid); - } - function set(FunctionRegistry storage functions, address facade) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("set"); - return functions.set(functions.findCurrentBundleName(), facade).recordExecFinish(pid); - } - - /**------------------------------------------------ - đŸ”ŧ Update Current Context Function & Bundle + đŸ”ŧ Update Current Context --------------------------------------------------*/ - /**----- 🧩 Function -------*/ function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { uint pid = functions.recordExecStart("safeUpdateCurrentFunction"); functions.currentFunctionName = name.assertNotEmpty(); return functions.recordExecFinish(pid); } - /**----- đŸ§ē Bundle -------*/ - function safeUpdateCurrentBundle(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("safeUpdateCurrentBundle"); - functions.currentBundleName = name.assertNotEmpty(); - return functions.recordExecFinish(pid); - } /**----------------------------------------------- @@ -146,7 +88,6 @@ library FunctionRegistryLib { function reset(FunctionRegistry storage functions) internal returns(FunctionRegistry storage) { uint pid = functions.recordExecStart("reset"); delete functions.currentFunctionName; - delete functions.currentBundleName; return functions.recordExecFinish(pid); } @@ -168,56 +109,6 @@ library FunctionRegistryLib { return functions.currentFunctionName.assertNotEmpty().recordExecFinish(pid); } - /**----- đŸ§ē Bundle -------*/ - function findBundle(FunctionRegistry storage functions, string memory name) internal returns(Bundle storage) { - uint pid = functions.recordExecStart("findBundle"); - return functions.bundles[name.safeCalcHash()].recordExecFinish(pid); - } - function findCurrentBundle(FunctionRegistry storage functions) internal returns(Bundle storage) { - uint pid = functions.recordExecStart("findCurrentBundle"); - return functions.findBundle(functions.findCurrentBundleName()).recordExecFinish(pid); - } - function findCurrentBundleName(FunctionRegistry storage functions) internal returns(string memory) { - uint pid = functions.recordExecStart("findCurrentBundleName"); - return functions.currentBundleName.assertNotEmpty().recordExecFinish(pid); - } - - - /**----------------------------- - 🏷 Generate Unique Name - -------------------------------*/ - function genUniqueBundleName(FunctionRegistry storage functions) internal returns(string memory name) { - uint pid = functions.recordExecStart("genUniqueBundleName"); - ScanRange storage range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = Config().DEFAULT_BUNDLE_NAME.toSequential(i); - if (functions.existsBundle(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } - - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function existsBundle(FunctionRegistry storage functions, string memory name) internal returns(bool) { - return functions.bundles[name.safeCalcHash()].hasName(); - } - function notExistsBundle(FunctionRegistry storage functions, string memory name) internal returns(bool) { - return functions.existsBundle(name).isNot(); - } - function assertBundleNotExists(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - check(functions.notExistsBundle(name), "Bundle Already Exists"); - return functions; - } - - function existsCurrentBundle(FunctionRegistry storage functions) internal returns(bool) { - return functions.currentBundleName.isNotEmpty(); - } - function notExistsCurrentBundle(FunctionRegistry storage functions) internal returns(bool) { - return functions.existsCurrentBundle().isNot(); - } /**---------------- diff --git a/devkit/core/functions/StdFunctions.sol b/devkit/core/StdFunctions.sol similarity index 100% rename from devkit/core/functions/StdFunctions.sol rename to devkit/core/StdFunctions.sol diff --git a/devkit/core/functions/StdRegistry.sol b/devkit/core/functions/StdRegistry.sol deleted file mode 100644 index 81aa149c..00000000 --- a/devkit/core/functions/StdRegistry.sol +++ /dev/null @@ -1,244 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Error & Debug -import {check} from "devkit/error/Validation.sol"; -import {ERR, throwError} from "devkit/error/Error.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Config -import {ScanRange, Config} from "devkit/config/Config.sol"; -// Utils -import {StringUtils} from "../../utils/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "../../utils/BoolUtils.sol"; - using BoolUtils for bool; -// Core -import {Function} from "./Function.sol"; -import {Bundle} from "./Bundle.sol"; -import {StdFunctions} from "./StdFunctions.sol"; - - -/**------------------------------- - 🧩 UCS Functions Registry ----------------------------------*/ -using FunctionRegistryLib for FunctionRegistry global; -struct FunctionRegistry { - StdFunctions std; - mapping(bytes32 nameHash => Function) customs; - mapping(bytes32 nameHash => Bundle) bundles; - string currentFunctionName; - string currentBundleName; -} - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> - 🌱 Init Bundle - ✨ Add Custom Function - 🔏 Load and Assign Custom Function from Env - đŸ§ē Add Custom Function to Bundle - đŸĒŸ Set Facade - đŸ”ŧ Update Current Context Function & Bundle - 🔍 Find Function & Bundle - 🏷 Generate Unique Name - << Helper >> - 🔍 Find Custom Function -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library FunctionRegistryLib { - string constant LIB_NAME = "FunctionRegistry"; - - - /**--------------------- - 🌱 Init Bundle - -----------------------*/ - function init(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("init"); - functions.bundles[name.safeCalcHash()].safeAssign(name); - functions.safeUpdateCurrentBundle(name); - return functions.recordExecFinish(pid); - } - function safeInit(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("safeInit"); - check(name.isNotEmpty(), "Empty Name"); - return functions.assertBundleNotExists(name) - .init(name) - .recordExecFinish(pid); - } - - - /**--------------------------- - ✨ Add Custom Function - -----------------------------*/ - function safeAddFunction(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("safeAddFunction"); - check(name.isNotEmpty(), "Empty Name"); - functions.customs[name.safeCalcHash()] - .safeAssign(name) - .safeAssign(selector) - .safeAssign(implementation); - functions.safeUpdateCurrentFunction(name); - return functions.recordExecFinish(pid); - } - - - /**--------------------------------------------- - 🔏 Load and Add Custom Function from Env - -----------------------------------------------*/ - function safeLoadAndAdd(FunctionRegistry storage functions, string memory envKey, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("safeLoadAndAdd"); - functions.customs[name.safeCalcHash()] - .loadAndAssignFromEnv(envKey, name, selector); - functions.safeUpdateCurrentFunction(name); - return functions.recordExecFinish(pid); - } - - - /**------------------------------------- - đŸ§ē Add Custom Function to Bundle - ---------------------------------------*/ - function addToBundle(FunctionRegistry storage functions, Function storage functionInfo) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("addToBundle", "function"); - functions.findCurrentBundle().safeAdd(functionInfo); - return functions.recordExecFinish(pid); - } - function addToBundle(FunctionRegistry storage functions, Function[] storage functionInfos) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("addToBundle", "functions"); // TODO params - functions.findCurrentBundle().safeAdd(functionInfos); - return functions.recordExecFinish(pid); - } - - - /**------------------ - đŸĒŸ Set Facade - --------------------*/ - function set(FunctionRegistry storage functions, string memory name, address facade) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("set"); - functions.bundles[name.safeCalcHash()] - .assertExists() - .safeAssign(facade); - return functions.recordExecFinish(pid); - } - function set(FunctionRegistry storage functions, address facade) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("set"); - return functions.set(functions.findCurrentBundleName(), facade).recordExecFinish(pid); - } - - - /**------------------------------------------------ - đŸ”ŧ Update Current Context Function & Bundle - --------------------------------------------------*/ - /**----- 🧩 Function -------*/ - function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("safeUpdateCurrentFunction"); - functions.currentFunctionName = name.assertNotEmpty(); - return functions.recordExecFinish(pid); - } - /**----- đŸ§ē Bundle -------*/ - function safeUpdateCurrentBundle(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("safeUpdateCurrentBundle"); - functions.currentBundleName = name.assertNotEmpty(); - return functions.recordExecFinish(pid); - } - - - /**----------------------------------------------- - â™ģī¸ Reset Current Context Function & Bundle - -------------------------------------------------*/ - function reset(FunctionRegistry storage functions) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("reset"); - delete functions.currentFunctionName; - delete functions.currentBundleName; - return functions.recordExecFinish(pid); - } - - - /**------------------------------- - 🔍 Find Function & Bundle - ---------------------------------*/ - /**----- 🧩 Function -------*/ - function findFunction(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { - uint pid = functions.recordExecStart("findFunction"); - return functions.customs[name.safeCalcHash()].assertExists().finishProcess(pid); - } - function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { - uint pid = functions.recordExecStart("findCurrentFunction"); - return functions.findFunction(functions.findCurrentFunctionName()).finishProcess(pid); - } - function findCurrentFunctionName(FunctionRegistry storage functions) internal returns(string memory) { - uint pid = functions.recordExecStart("findCurrentFunctionName"); - return functions.currentFunctionName.assertNotEmpty().recordExecFinish(pid); - } - - /**----- đŸ§ē Bundle -------*/ - function findBundle(FunctionRegistry storage functions, string memory name) internal returns(Bundle storage) { - uint pid = functions.recordExecStart("findBundle"); - return functions.bundles[name.safeCalcHash()].recordExecFinish(pid); - } - function findCurrentBundle(FunctionRegistry storage functions) internal returns(Bundle storage) { - uint pid = functions.recordExecStart("findCurrentBundle"); - return functions.findBundle(functions.findCurrentBundleName()).recordExecFinish(pid); - } - function findCurrentBundleName(FunctionRegistry storage functions) internal returns(string memory) { - uint pid = functions.recordExecStart("findCurrentBundleName"); - return functions.currentBundleName.assertNotEmpty().recordExecFinish(pid); - } - - - /**----------------------------- - 🏷 Generate Unique Name - -------------------------------*/ - function genUniqueBundleName(FunctionRegistry storage functions) internal returns(string memory name) { - uint pid = functions.recordExecStart("genUniqueBundleName"); - ScanRange storage range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = Config().DEFAULT_BUNDLE_NAME.toSequential(i); - if (functions.existsBundle(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } - - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function existsBundle(FunctionRegistry storage functions, string memory name) internal returns(bool) { - return functions.bundles[name.safeCalcHash()].hasName(); - } - function notExistsBundle(FunctionRegistry storage functions, string memory name) internal returns(bool) { - return functions.existsBundle(name).isNot(); - } - function assertBundleNotExists(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - check(functions.notExistsBundle(name), "Bundle Already Exists"); - return functions; - } - - function existsCurrentBundle(FunctionRegistry storage functions) internal returns(bool) { - return functions.currentBundleName.isNotEmpty(); - } - function notExistsCurrentBundle(FunctionRegistry storage functions) internal returns(bool) { - return functions.existsCurrentBundle().isNot(); - } - - - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Start - */ - function recordExecStart(FunctionRegistry storage, string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(FunctionRegistry storage functions, string memory funcName) internal returns(uint) { - return functions.recordExecStart(funcName, ""); - } - - /** - Record Finish - */ - function recordExecFinish(FunctionRegistry storage functions, uint pid) internal returns(FunctionRegistry storage) { - Debug.recordExecFinish(pid); - return functions; - } - -} diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index 127c264d..cd146c10 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -11,8 +11,8 @@ import {Params} from "devkit/debug/Params.sol"; // dictionary import {Dictionary, DictionaryLib} from "devkit/core/dictionary/Dictionary.sol"; // functions -import {Bundle} from "devkit/core/functions/Bundle.sol"; -import {StdFunctionsArgs} from "devkit/core/functions/StdFunctions.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {StdFunctionsArgs} from "devkit/core/StdFunctions.sol"; using StdFunctionsArgs for address; // proxy import {Proxy, ProxyLib} from "devkit/core/proxy/Proxy.sol"; diff --git a/devkit/method/MCFinderLib.sol b/devkit/method/MCFinderLib.sol index ab6d59e7..cbfb4f95 100644 --- a/devkit/method/MCFinderLib.sol +++ b/devkit/method/MCFinderLib.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Core // functions -import {Bundle} from "devkit/core/functions/Bundle.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; // proxy import {Proxy} from "devkit/core/proxy/Proxy.sol"; diff --git a/devkit/method/MCTestLib.sol b/devkit/method/MCTestLib.sol index a3078930..c0a05794 100644 --- a/devkit/method/MCTestLib.sol +++ b/devkit/method/MCTestLib.sol @@ -7,7 +7,7 @@ import {Config} from "devkit/config/Config.sol"; import {Params} from "devkit/debug/Params.sol"; // Core // functions -import {Bundle} from "devkit/core/functions/Bundle.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; // proxy import {Proxy, ProxyLib} from "devkit/core/proxy/Proxy.sol"; diff --git a/devkit/method/core/FunctionLib.sol b/devkit/method/core/FunctionLib.sol index 1b42221f..90fd9048 100644 --- a/devkit/method/core/FunctionLib.sol +++ b/devkit/method/core/FunctionLib.sol @@ -13,7 +13,7 @@ import {AddressUtils} from "../../utils/AddressUtils.sol"; using AddressUtils for address; // Core import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/functions/Bundle.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; import {BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; diff --git a/script/DeployLib.sol b/script/DeployLib.sol index 7c930392..391a49c8 100755 --- a/script/DeployLib.sol +++ b/script/DeployLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {StdFunctions} from "devkit/core/functions/StdFunctions.sol"; +import {StdFunctions} from "devkit/core/StdFunctions.sol"; library DeployLib { using DeployLib for MCDevKit; diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 57d4992c..54c94679 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -8,7 +8,7 @@ import {StringUtils} from "devkit/utils/StringUtils.sol"; import {Config} from "devkit/config/Config.sol"; import {ERR} from "devkit/error/Error.sol"; -import {Bundle} from "devkit/core/functions/Bundle.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; import {DummyFunction} from "test/utils/DummyFunction.sol"; import {DummyFacade} from "test/utils/DummyFacade.sol"; From e8665b3b57ad8c347e5229f58d33fe47a3a41417 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 13:41:02 +0900 Subject: [PATCH 020/111] Adjust Path --- devkit/core/Bundle.sol | 14 +++--- devkit/core/BundleRegistry.sol | 64 +++++++++++++-------------- devkit/core/StdFunctions.sol | 10 ++--- devkit/core/dictionary/Dictionary.sol | 2 +- devkit/method/MCBundleLib.sol | 18 ++++---- devkit/method/MCDeployLib.sol | 12 ++--- devkit/method/MCFinderLib.sol | 4 +- devkit/method/MCSetupLib.sol | 2 +- devkit/method/MCTestLib.sol | 10 ++--- script/DeployLib.sol | 4 +- script/DeployStdDictionary.s.sol | 2 +- script/DeployStdFunctions.s.sol | 2 +- test/devkit/MCDevKit.t.sol | 20 ++++----- test/devkit/global/MCBundle.t.sol | 28 ++++++------ test/devkit/global/MCSetup.t.sol | 14 +++--- 15 files changed, 103 insertions(+), 103 deletions(-) diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index bdf23fa1..0d81a068 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -4,18 +4,18 @@ pragma solidity ^0.8.24; // Validation import {check} from "devkit/error/Validation.sol"; // Utils -import {console2} from "../../utils/ForgeHelper.sol"; -import {StringUtils} from "../../utils/StringUtils.sol"; +import {console2} from "devkit/utils/ForgeHelper.sol"; +import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; -import {AddressUtils} from "../../utils/AddressUtils.sol"; +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; -import {BoolUtils} from "../../utils/BoolUtils.sol"; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; -import {Bytes4Utils} from "../../utils/Bytes4Utils.sol"; +import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; using Bytes4Utils for bytes4; // Debug -import {Debug} from "../../debug/Debug.sol"; -import {Logger} from "../../debug/Logger.sol"; +import {Debug} from "devkit/debug/Debug.sol"; +import {Logger} from "devkit/debug/Logger.sol"; // Core import {Function} from "devkit/core/Function.sol"; diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/BundleRegistry.sol index 81aa149c..aaf8b931 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/BundleRegistry.sol @@ -8,9 +8,9 @@ import {Debug} from "devkit/debug/Debug.sol"; // Config import {ScanRange, Config} from "devkit/config/Config.sol"; // Utils -import {StringUtils} from "../../utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; -import {BoolUtils} from "../../utils/BoolUtils.sol"; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; // Core import {Function} from "./Function.sol"; @@ -21,8 +21,8 @@ import {StdFunctions} from "./StdFunctions.sol"; /**------------------------------- 🧩 UCS Functions Registry ---------------------------------*/ -using FunctionRegistryLib for FunctionRegistry global; -struct FunctionRegistry { +using BundleRegistryLib for BundleRegistry global; +struct BundleRegistry { StdFunctions std; mapping(bytes32 nameHash => Function) customs; mapping(bytes32 nameHash => Bundle) bundles; @@ -43,20 +43,20 @@ struct FunctionRegistry { << Helper >> 🔍 Find Custom Function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library FunctionRegistryLib { - string constant LIB_NAME = "FunctionRegistry"; +library BundleRegistryLib { + string constant LIB_NAME = "BundleRegistry"; /**--------------------- 🌱 Init Bundle -----------------------*/ - function init(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + function init(BundleRegistry storage functions, string memory name) internal returns(BundleRegistry storage) { uint pid = functions.recordExecStart("init"); functions.bundles[name.safeCalcHash()].safeAssign(name); functions.safeUpdateCurrentBundle(name); return functions.recordExecFinish(pid); } - function safeInit(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + function safeInit(BundleRegistry storage functions, string memory name) internal returns(BundleRegistry storage) { uint pid = functions.recordExecStart("safeInit"); check(name.isNotEmpty(), "Empty Name"); return functions.assertBundleNotExists(name) @@ -68,7 +68,7 @@ library FunctionRegistryLib { /**--------------------------- ✨ Add Custom Function -----------------------------*/ - function safeAddFunction(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + function safeAddFunction(BundleRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(BundleRegistry storage) { uint pid = functions.recordExecStart("safeAddFunction"); check(name.isNotEmpty(), "Empty Name"); functions.customs[name.safeCalcHash()] @@ -83,7 +83,7 @@ library FunctionRegistryLib { /**--------------------------------------------- 🔏 Load and Add Custom Function from Env -----------------------------------------------*/ - function safeLoadAndAdd(FunctionRegistry storage functions, string memory envKey, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + function safeLoadAndAdd(BundleRegistry storage functions, string memory envKey, string memory name, bytes4 selector, address implementation) internal returns(BundleRegistry storage) { uint pid = functions.recordExecStart("safeLoadAndAdd"); functions.customs[name.safeCalcHash()] .loadAndAssignFromEnv(envKey, name, selector); @@ -95,12 +95,12 @@ library FunctionRegistryLib { /**------------------------------------- đŸ§ē Add Custom Function to Bundle ---------------------------------------*/ - function addToBundle(FunctionRegistry storage functions, Function storage functionInfo) internal returns(FunctionRegistry storage) { + function addToBundle(BundleRegistry storage functions, Function storage functionInfo) internal returns(BundleRegistry storage) { uint pid = functions.recordExecStart("addToBundle", "function"); functions.findCurrentBundle().safeAdd(functionInfo); return functions.recordExecFinish(pid); } - function addToBundle(FunctionRegistry storage functions, Function[] storage functionInfos) internal returns(FunctionRegistry storage) { + function addToBundle(BundleRegistry storage functions, Function[] storage functionInfos) internal returns(BundleRegistry storage) { uint pid = functions.recordExecStart("addToBundle", "functions"); // TODO params functions.findCurrentBundle().safeAdd(functionInfos); return functions.recordExecFinish(pid); @@ -110,14 +110,14 @@ library FunctionRegistryLib { /**------------------ đŸĒŸ Set Facade --------------------*/ - function set(FunctionRegistry storage functions, string memory name, address facade) internal returns(FunctionRegistry storage) { + function set(BundleRegistry storage functions, string memory name, address facade) internal returns(BundleRegistry storage) { uint pid = functions.recordExecStart("set"); functions.bundles[name.safeCalcHash()] .assertExists() .safeAssign(facade); return functions.recordExecFinish(pid); } - function set(FunctionRegistry storage functions, address facade) internal returns(FunctionRegistry storage) { + function set(BundleRegistry storage functions, address facade) internal returns(BundleRegistry storage) { uint pid = functions.recordExecStart("set"); return functions.set(functions.findCurrentBundleName(), facade).recordExecFinish(pid); } @@ -127,13 +127,13 @@ library FunctionRegistryLib { đŸ”ŧ Update Current Context Function & Bundle --------------------------------------------------*/ /**----- 🧩 Function -------*/ - function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + function safeUpdateCurrentFunction(BundleRegistry storage functions, string memory name) internal returns(BundleRegistry storage) { uint pid = functions.recordExecStart("safeUpdateCurrentFunction"); functions.currentFunctionName = name.assertNotEmpty(); return functions.recordExecFinish(pid); } /**----- đŸ§ē Bundle -------*/ - function safeUpdateCurrentBundle(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + function safeUpdateCurrentBundle(BundleRegistry storage functions, string memory name) internal returns(BundleRegistry storage) { uint pid = functions.recordExecStart("safeUpdateCurrentBundle"); functions.currentBundleName = name.assertNotEmpty(); return functions.recordExecFinish(pid); @@ -143,7 +143,7 @@ library FunctionRegistryLib { /**----------------------------------------------- â™ģī¸ Reset Current Context Function & Bundle -------------------------------------------------*/ - function reset(FunctionRegistry storage functions) internal returns(FunctionRegistry storage) { + function reset(BundleRegistry storage functions) internal returns(BundleRegistry storage) { uint pid = functions.recordExecStart("reset"); delete functions.currentFunctionName; delete functions.currentBundleName; @@ -155,29 +155,29 @@ library FunctionRegistryLib { 🔍 Find Function & Bundle ---------------------------------*/ /**----- 🧩 Function -------*/ - function findFunction(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { + function findFunction(BundleRegistry storage functions, string memory name) internal returns(Function storage) { uint pid = functions.recordExecStart("findFunction"); return functions.customs[name.safeCalcHash()].assertExists().finishProcess(pid); } - function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { + function findCurrentFunction(BundleRegistry storage functions) internal returns(Function storage) { uint pid = functions.recordExecStart("findCurrentFunction"); return functions.findFunction(functions.findCurrentFunctionName()).finishProcess(pid); } - function findCurrentFunctionName(FunctionRegistry storage functions) internal returns(string memory) { + function findCurrentFunctionName(BundleRegistry storage functions) internal returns(string memory) { uint pid = functions.recordExecStart("findCurrentFunctionName"); return functions.currentFunctionName.assertNotEmpty().recordExecFinish(pid); } /**----- đŸ§ē Bundle -------*/ - function findBundle(FunctionRegistry storage functions, string memory name) internal returns(Bundle storage) { + function findBundle(BundleRegistry storage functions, string memory name) internal returns(Bundle storage) { uint pid = functions.recordExecStart("findBundle"); return functions.bundles[name.safeCalcHash()].recordExecFinish(pid); } - function findCurrentBundle(FunctionRegistry storage functions) internal returns(Bundle storage) { + function findCurrentBundle(BundleRegistry storage functions) internal returns(Bundle storage) { uint pid = functions.recordExecStart("findCurrentBundle"); return functions.findBundle(functions.findCurrentBundleName()).recordExecFinish(pid); } - function findCurrentBundleName(FunctionRegistry storage functions) internal returns(string memory) { + function findCurrentBundleName(BundleRegistry storage functions) internal returns(string memory) { uint pid = functions.recordExecStart("findCurrentBundleName"); return functions.currentBundleName.assertNotEmpty().recordExecFinish(pid); } @@ -186,7 +186,7 @@ library FunctionRegistryLib { /**----------------------------- 🏷 Generate Unique Name -------------------------------*/ - function genUniqueBundleName(FunctionRegistry storage functions) internal returns(string memory name) { + function genUniqueBundleName(BundleRegistry storage functions) internal returns(string memory name) { uint pid = functions.recordExecStart("genUniqueBundleName"); ScanRange storage range = Config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { @@ -201,21 +201,21 @@ library FunctionRegistryLib { /**------------------------------- 🧐 Inspectors & Assertions ---------------------------------*/ - function existsBundle(FunctionRegistry storage functions, string memory name) internal returns(bool) { + function existsBundle(BundleRegistry storage functions, string memory name) internal returns(bool) { return functions.bundles[name.safeCalcHash()].hasName(); } - function notExistsBundle(FunctionRegistry storage functions, string memory name) internal returns(bool) { + function notExistsBundle(BundleRegistry storage functions, string memory name) internal returns(bool) { return functions.existsBundle(name).isNot(); } - function assertBundleNotExists(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + function assertBundleNotExists(BundleRegistry storage functions, string memory name) internal returns(BundleRegistry storage) { check(functions.notExistsBundle(name), "Bundle Already Exists"); return functions; } - function existsCurrentBundle(FunctionRegistry storage functions) internal returns(bool) { + function existsCurrentBundle(BundleRegistry storage functions) internal returns(bool) { return functions.currentBundleName.isNotEmpty(); } - function notExistsCurrentBundle(FunctionRegistry storage functions) internal returns(bool) { + function notExistsCurrentBundle(BundleRegistry storage functions) internal returns(bool) { return functions.existsCurrentBundle().isNot(); } @@ -226,17 +226,17 @@ library FunctionRegistryLib { /** Record Start */ - function recordExecStart(FunctionRegistry storage, string memory funcName, string memory params) internal returns(uint) { + function recordExecStart(BundleRegistry storage, string memory funcName, string memory params) internal returns(uint) { return Debug.recordExecStart(LIB_NAME, funcName, params); } - function recordExecStart(FunctionRegistry storage functions, string memory funcName) internal returns(uint) { + function recordExecStart(BundleRegistry storage functions, string memory funcName) internal returns(uint) { return functions.recordExecStart(funcName, ""); } /** Record Finish */ - function recordExecFinish(FunctionRegistry storage functions, uint pid) internal returns(FunctionRegistry storage) { + function recordExecFinish(BundleRegistry storage functions, uint pid) internal returns(BundleRegistry storage) { Debug.recordExecFinish(pid); return functions; } diff --git a/devkit/core/StdFunctions.sol b/devkit/core/StdFunctions.sol index ba95f1ac..eb2d0000 100644 --- a/devkit/core/StdFunctions.sol +++ b/devkit/core/StdFunctions.sol @@ -2,14 +2,14 @@ pragma solidity ^0.8.24; // Utils -import {console2} from "../../utils/ForgeHelper.sol"; -import {AddressUtils} from "../../utils/AddressUtils.sol"; +import {console2} from "devkit/utils/ForgeHelper.sol"; +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; -import {StringUtils} from "../../utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; // Debug -import {Debug} from "../../debug/Debug.sol"; -import {Logger} from "../../debug/Logger.sol"; +import {Debug} from "devkit/debug/Debug.sol"; +import {Logger} from "devkit/debug/Logger.sol"; // Core import {Function} from "devkit/core/Function.sol"; import {Bundle} from "./Bundle.sol"; diff --git a/devkit/core/dictionary/Dictionary.sol b/devkit/core/dictionary/Dictionary.sol index 75b93b0c..dfa0f3f1 100644 --- a/devkit/core/dictionary/Dictionary.sol +++ b/devkit/core/dictionary/Dictionary.sol @@ -18,7 +18,7 @@ import {ForgeHelper} from "../../utils/ForgeHelper.sol"; import {Debug} from "../../debug/Debug.sol"; // Core import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "../functions/Bundle.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; // Test import {MockDictionary} from "../../test/MockDictionary.sol"; // External Libs diff --git a/devkit/method/MCBundleLib.sol b/devkit/method/MCBundleLib.sol index b850e132..03ec7ad1 100644 --- a/devkit/method/MCBundleLib.sol +++ b/devkit/method/MCBundleLib.sol @@ -29,18 +29,18 @@ library MCBundleLib { -----------------------------*/ function init(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("init", Params.append(name)); - mc.functions.safeInit(name); + mc.bundle.safeInit(name); return mc.recordExecFinish(pid); } function init(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.init(mc.functions.genUniqueBundleName()); + return mc.init(mc.bundle.genUniqueBundleName()); } // function ensureInit(MCDevKit storage mc) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("ensureInit"); - if (mc.functions.notExistsCurrentBundle()) { + if (mc.bundle.notExistsCurrentBundle()) { mc.init(); } return mc.recordExecFinish(pid); @@ -67,7 +67,7 @@ library MCBundleLib { // return mc; // } TODO function use(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - check(mc.functions.findFunction(name).isComplete(), "Invalid Function Name"); + check(mc.bundle.findFunction(name).isComplete(), "Invalid Function Name"); return mc.use(mc.findFunction(name)); } /**--------------------------- @@ -75,7 +75,7 @@ library MCBundleLib { -----------------------------*/ function addFunction(MCDevKit storage mc, string memory name, bytes4 selector, address implementation) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("addFunction"); - mc.functions.safeAddFunction(name, selector, implementation); + mc.bundle.safeAddFunction(name, selector, implementation); return mc.recordExecFinish(pid); } /**------------------------------------- @@ -83,11 +83,11 @@ library MCBundleLib { ---------------------------------------*/ function addToBundle(MCDevKit storage mc, Function storage functionInfo) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("addToBundle"); - mc.functions.addToBundle(functionInfo); + mc.bundle.addToBundle(functionInfo); return mc.recordExecFinish(pid); } function addCurrentToBundle(MCDevKit storage mc) internal returns(MCDevKit storage) { - mc.functions.addToBundle(mc.findCurrentFunction()); + mc.bundle.addToBundle(mc.findCurrentFunction()); return mc; } @@ -97,8 +97,8 @@ library MCBundleLib { --------------------*/ function useFacade(MCDevKit storage mc, address facade) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("set"); - check(mc.functions.existsCurrentBundle(), ERR.NOT_INIT); - mc.functions.set(mc.functions.findCurrentBundleName(), facade); + check(mc.bundle.existsCurrentBundle(), ERR.NOT_INIT); + mc.bundle.set(mc.bundle.findCurrentBundleName(), facade); return mc.recordExecFinish(pid); } diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index cd146c10..a137d70f 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -43,7 +43,7 @@ library MCDeployLib { } function deploy(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.deploy(mc.findCurrentBundleName(), mc.functions.findCurrentBundle(), Config().defaultOwner(), Config().defaultInitData()); + return mc.deploy(mc.findCurrentBundleName(), mc.bundle.findCurrentBundle(), Config().defaultOwner(), Config().defaultInitData()); } // function deploy(MCDevKit storage mc, string memory name, Bundle storage bundleInfo, address facade, address owner) internal returns(MCDevKit storage) { // return mc.deploy(name, bundleInfo, facade, owner, Config().defaultInitData()); @@ -61,7 +61,7 @@ library MCDeployLib { // return mc.deploy(name, mc.functions.findBundle(name), Config().defaultInitData()); // } function deploy(MCDevKit storage mc, bytes memory initData) internal returns(MCDevKit storage) { - return mc.deploy(mc.findCurrentBundleName(), mc.functions.findCurrentBundle(), Config().defaultOwner(), initData); + return mc.deploy(mc.findCurrentBundleName(), mc.bundle.findCurrentBundle(), Config().defaultOwner(), initData); } @@ -109,22 +109,22 @@ library MCDeployLib { } function deployDictionary(MCDevKit storage mc) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.genUniqueName(), mc.functions.findCurrentBundle(), Config().defaultOwner()); + return mc.deployDictionary(mc.dictionary.genUniqueName(), mc.bundle.findCurrentBundle(), Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, string memory name) internal returns(Dictionary memory) { - return mc.deployDictionary(name, mc.functions.findCurrentBundle(), Config().defaultOwner()); + return mc.deployDictionary(name, mc.bundle.findCurrentBundle(), Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, Bundle storage bundleInfo) internal returns(Dictionary memory) { return mc.deployDictionary(mc.dictionary.genUniqueName(), bundleInfo, Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, address owner) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.genUniqueName(), mc.functions.findCurrentBundle(), owner); + return mc.deployDictionary(mc.dictionary.genUniqueName(), mc.bundle.findCurrentBundle(), owner); } function deployDictionary(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(Dictionary memory) { return mc.deployDictionary(name, bundleInfo, Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, string memory name, address owner) internal returns(Dictionary memory) { - return mc.deployDictionary(name, mc.functions.findCurrentBundle(), owner); + return mc.deployDictionary(name, mc.bundle.findCurrentBundle(), owner); } function deployDictionary(MCDevKit storage mc, Bundle storage bundleInfo, address owner) internal returns(Dictionary memory) { return mc.deployDictionary(mc.dictionary.genUniqueName(), bundleInfo, owner); diff --git a/devkit/method/MCFinderLib.sol b/devkit/method/MCFinderLib.sol index cbfb4f95..9222af6d 100644 --- a/devkit/method/MCFinderLib.sol +++ b/devkit/method/MCFinderLib.sol @@ -31,11 +31,11 @@ library MCFinderLib { // return mc.functions.findCurrentBundle(); // } function findBundle(MCDevKit storage mc, string memory name) internal returns(Bundle storage) { - return mc.functions.findBundle(name); + return mc.bundle.findBundle(name); } function findCurrentBundleName(MCDevKit storage mc) internal returns(string memory) { uint pid = mc.recordExecStart("findCurrentBundleName", ""); - return mc.functions.findCurrentBundleName(); + return mc.bundle.findCurrentBundleName(); } /**---------------------- diff --git a/devkit/method/MCSetupLib.sol b/devkit/method/MCSetupLib.sol index e66c99ff..c75672fa 100644 --- a/devkit/method/MCSetupLib.sol +++ b/devkit/method/MCSetupLib.sol @@ -16,7 +16,7 @@ library MCSetupLib { ------------------------------*/ function setupStdFunctions(MCDevKit storage mc) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("setupStdFunctions"); - mc.functions.std.assignAndLoad() + mc.std.assignAndLoad() .deployIfNotExists() .configureStdBundle(); return mc.recordExecFinish(pid); diff --git a/devkit/method/MCTestLib.sol b/devkit/method/MCTestLib.sol index c0a05794..41fca2d1 100644 --- a/devkit/method/MCTestLib.sol +++ b/devkit/method/MCTestLib.sol @@ -48,13 +48,13 @@ library MCTestLib { return mc.createSimpleMockProxy(name, bundleInfo.functionInfos); } function createSimpleMockProxy(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - return mc.createSimpleMockProxy(name, mc.functions.std.all); + return mc.createSimpleMockProxy(name, mc.std.all); } function createSimpleMockProxy(MCDevKit storage mc, Function[] memory functionInfos) internal returns(MCDevKit storage) { return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), functionInfos); } function createSimpleMockProxy(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), mc.functions.std.all); + return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), mc.std.all); } @@ -78,13 +78,13 @@ library MCTestLib { return mc.createMockDictionary(name, owner, bundleInfo.functionInfos); } function createMockDictionary(MCDevKit storage mc, string memory name, address owner) internal returns(MCDevKit storage) { - return mc.createMockDictionary(name, owner, mc.functions.std.all); + return mc.createMockDictionary(name, owner, mc.std.all); } function createMockDictionary(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - return mc.createMockDictionary(name, Config().defaultOwner(), mc.functions.std.all); + return mc.createMockDictionary(name, Config().defaultOwner(), mc.std.all); } function createMockDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), Config().defaultOwner(), mc.functions.std.all); + return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), Config().defaultOwner(), mc.std.all); } diff --git a/script/DeployLib.sol b/script/DeployLib.sol index 391a49c8..29bb9671 100755 --- a/script/DeployLib.sol +++ b/script/DeployLib.sol @@ -9,13 +9,13 @@ library DeployLib { string internal constant BUNDLE_NAME = "Std"; function deployStdFunctions(MCDevKit storage mc) internal returns(MCDevKit storage) { - mc.functions.std.deployIfNotExists(); + mc.std.deployIfNotExists(); return mc; } function deployStdDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { mc.deployStdFunctions(); - mc.deployDictionary(mc.functions.std.all); + mc.deployDictionary(mc.std.all); return mc; } } diff --git a/script/DeployStdDictionary.s.sol b/script/DeployStdDictionary.s.sol index f5a64241..c6205ff7 100644 --- a/script/DeployStdDictionary.s.sol +++ b/script/DeployStdDictionary.s.sol @@ -9,7 +9,7 @@ contract DeployStdDictionary is MCScriptWithoutSetup { using DeployLib for MCDevKit; function setUp() public { - mc.functions.std.assignAndLoad(); + mc.std.assignAndLoad(); } function run() public startBroadcastWith("DEPLOYER_PRIV_KEY") { diff --git a/script/DeployStdFunctions.s.sol b/script/DeployStdFunctions.s.sol index 7c5a5f73..dd1d7331 100644 --- a/script/DeployStdFunctions.s.sol +++ b/script/DeployStdFunctions.s.sol @@ -9,7 +9,7 @@ contract DeployStdFunctions is MCScriptWithoutSetup { using DeployLib for MCDevKit; function setUp() public { - mc.functions.std.assignAndLoad(); + mc.std.assignAndLoad(); } function run() public startBroadcastWith("DEPLOYER_PRIV_KEY") { diff --git a/test/devkit/MCDevKit.t.sol b/test/devkit/MCDevKit.t.sol index d0b38722..3a2582f6 100644 --- a/test/devkit/MCDevKit.t.sol +++ b/test/devkit/MCDevKit.t.sol @@ -19,21 +19,21 @@ contract MCDevKitTest is Test { function test_Success_setupStdFunctions() public { mc.setupStdFunctions(); - assertTrue(mc.functions.std.initSetAdmin.isInitSetAdmin()); - assertTrue(mc.functions.std.getDeps.isGetDeps()); - assertTrue(mc.functions.std.clone.isClone()); - - assertTrue(mc.functions.std.all.functionInfos.length == 3); - assertTrue(mc.functions.std.all.functionInfos[0].isInitSetAdmin()); - assertTrue(mc.functions.std.all.functionInfos[1].isGetDeps()); - assertTrue(mc.functions.std.all.functionInfos[2].isClone()); + assertTrue(mc.std.initSetAdmin.isInitSetAdmin()); + assertTrue(mc.std.getDeps.isGetDeps()); + assertTrue(mc.std.clone.isClone()); + + assertTrue(mc.std.all.functionInfos.length == 3); + assertTrue(mc.std.all.functionInfos[0].isInitSetAdmin()); + assertTrue(mc.std.all.functionInfos[1].isGetDeps()); + assertTrue(mc.std.all.functionInfos[2].isClone()); } function test_Success_init_withName() public { string memory name = "TestBundleName"; mc.init(name); - assertTrue(mc.functions.bundles[name.safeCalcHash()].name.isEqual(name)); - assertTrue(mc.functions.currentBundleName.isEqual(name)); + assertTrue(mc.bundle.bundles[name.safeCalcHash()].name.isEqual(name)); + assertTrue(mc.bundle.currentBundleName.isEqual(name)); } } diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 54c94679..17f9d4dc 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -21,35 +21,35 @@ contract DevKitTest_MCBundle is MCDevKitTest { string memory name = "TestBundleName"; mc.init(name); - assertTrue(mc.functions.bundles[name.safeCalcHash()].name.isEqual(name)); - assertTrue(mc.functions.currentBundleName.isEqual(name)); + assertTrue(mc.bundle.bundles[name.safeCalcHash()].name.isEqual(name)); + assertTrue(mc.bundle.currentBundleName.isEqual(name)); } // verify genUniqueBundleName // function test_Success_init_withoutName() public {} function test_Success_ensureInit_beforeInit() public { - string memory name = mc.functions.genUniqueBundleName(); + string memory name = mc.bundle.genUniqueBundleName(); mc.ensureInit(); - assertTrue(mc.functions.bundles[name.safeCalcHash()].name.isEqual(name)); - assertTrue(mc.functions.currentBundleName.isEqual(name)); + assertTrue(mc.bundle.bundles[name.safeCalcHash()].name.isEqual(name)); + assertTrue(mc.bundle.currentBundleName.isEqual(name)); } function test_Success_ensureInit_afterInit() public { - string memory name = mc.functions.genUniqueBundleName(); + string memory name = mc.bundle.genUniqueBundleName(); mc.init(); - assertTrue(mc.functions.bundles[name.safeCalcHash()].name.isEqual(name)); - assertTrue(mc.functions.currentBundleName.isEqual(name)); + assertTrue(mc.bundle.bundles[name.safeCalcHash()].name.isEqual(name)); + assertTrue(mc.bundle.currentBundleName.isEqual(name)); - string memory name2 = mc.functions.genUniqueBundleName(); + string memory name2 = mc.bundle.genUniqueBundleName(); mc.ensureInit(); - assertTrue(mc.functions.bundles[name2.safeCalcHash()].name.isEmpty()); - assertTrue(mc.functions.currentBundleName.isEqual(name)); + assertTrue(mc.bundle.bundles[name2.safeCalcHash()].name.isEmpty()); + assertTrue(mc.bundle.currentBundleName.isEqual(name)); } @@ -69,7 +69,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { } function test_Success_use() public { - string memory bundleName = mc.functions.genUniqueBundleName(); + string memory bundleName = mc.bundle.genUniqueBundleName(); string memory functionName = "DummyFunction"; bytes4 selector = DummyFunction.dummy.selector; address impl = address(new DummyFunction()); @@ -80,7 +80,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { } function test_Revert_use_withSameName() public { - string memory bundleName = mc.functions.genUniqueBundleName(); + string memory bundleName = mc.bundle.genUniqueBundleName(); string memory functionName = "DummyFunction"; bytes4 selector = DummyFunction.dummy.selector; address impl = address(new DummyFunction()); @@ -92,7 +92,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { } function test_Success_use_withDifferentName() public { - string memory bundleName = mc.functions.genUniqueBundleName(); + string memory bundleName = mc.bundle.genUniqueBundleName(); string memory functionName = "DummyFunction"; string memory functionName2 = "DummyFunction2"; diff --git a/test/devkit/global/MCSetup.t.sol b/test/devkit/global/MCSetup.t.sol index 5ccc6bef..2ba6f153 100644 --- a/test/devkit/global/MCSetup.t.sol +++ b/test/devkit/global/MCSetup.t.sol @@ -15,14 +15,14 @@ contract DevKitTest_MCSetup is MCDevKitTest { function test_Success_setupStdFuncs() public { mc.setupStdFunctions(); - assertTrue(mc.functions.std.initSetAdmin.isInitSetAdmin()); - assertTrue(mc.functions.std.getDeps.isGetDeps()); - assertTrue(mc.functions.std.clone.isClone()); + assertTrue(mc.std.initSetAdmin.isInitSetAdmin()); + assertTrue(mc.std.getDeps.isGetDeps()); + assertTrue(mc.std.clone.isClone()); - assertTrue(mc.functions.std.all.functionInfos.length == 3); - assertTrue(mc.functions.std.all.functionInfos[0].isInitSetAdmin()); - assertTrue(mc.functions.std.all.functionInfos[1].isGetDeps()); - assertTrue(mc.functions.std.all.functionInfos[2].isClone()); + assertTrue(mc.std.all.functionInfos.length == 3); + assertTrue(mc.std.all.functionInfos[0].isInitSetAdmin()); + assertTrue(mc.std.all.functionInfos[1].isGetDeps()); + assertTrue(mc.std.all.functionInfos[2].isClone()); } } From 74492e71e398bfb6b925473b5ffbc346226e07d7 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 13:49:13 +0900 Subject: [PATCH 021/111] Remove function's methods from bundle registry --- devkit/core/BundleRegistry.sol | 170 ++++++++++++--------------------- devkit/method/MCBundleLib.sol | 4 +- 2 files changed, 62 insertions(+), 112 deletions(-) diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/BundleRegistry.sol index aaf8b931..72585bf6 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/BundleRegistry.sol @@ -50,148 +50,98 @@ library BundleRegistryLib { /**--------------------- 🌱 Init Bundle -----------------------*/ - function init(BundleRegistry storage functions, string memory name) internal returns(BundleRegistry storage) { - uint pid = functions.recordExecStart("init"); - functions.bundles[name.safeCalcHash()].safeAssign(name); - functions.safeUpdateCurrentBundle(name); - return functions.recordExecFinish(pid); - } - function safeInit(BundleRegistry storage functions, string memory name) internal returns(BundleRegistry storage) { - uint pid = functions.recordExecStart("safeInit"); + function init(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("init"); + bundle.bundles[name.safeCalcHash()].safeAssign(name); + bundle.safeUpdateCurrentBundle(name); + return bundle.recordExecFinish(pid); + } + function safeInit(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("safeInit"); check(name.isNotEmpty(), "Empty Name"); - return functions.assertBundleNotExists(name) + return bundle.assertBundleNotExists(name) .init(name) .recordExecFinish(pid); } - /**--------------------------- - ✨ Add Custom Function - -----------------------------*/ - function safeAddFunction(BundleRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(BundleRegistry storage) { - uint pid = functions.recordExecStart("safeAddFunction"); - check(name.isNotEmpty(), "Empty Name"); - functions.customs[name.safeCalcHash()] - .safeAssign(name) - .safeAssign(selector) - .safeAssign(implementation); - functions.safeUpdateCurrentFunction(name); - return functions.recordExecFinish(pid); - } - - - /**--------------------------------------------- - 🔏 Load and Add Custom Function from Env - -----------------------------------------------*/ - function safeLoadAndAdd(BundleRegistry storage functions, string memory envKey, string memory name, bytes4 selector, address implementation) internal returns(BundleRegistry storage) { - uint pid = functions.recordExecStart("safeLoadAndAdd"); - functions.customs[name.safeCalcHash()] - .loadAndAssignFromEnv(envKey, name, selector); - functions.safeUpdateCurrentFunction(name); - return functions.recordExecFinish(pid); - } - - /**------------------------------------- đŸ§ē Add Custom Function to Bundle ---------------------------------------*/ - function addToBundle(BundleRegistry storage functions, Function storage functionInfo) internal returns(BundleRegistry storage) { - uint pid = functions.recordExecStart("addToBundle", "function"); - functions.findCurrentBundle().safeAdd(functionInfo); - return functions.recordExecFinish(pid); + function addToBundle(BundleRegistry storage bundle, Function storage functionInfo) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("addToBundle", "function"); + bundle.findCurrentBundle().safeAdd(functionInfo); + return bundle.recordExecFinish(pid); } - function addToBundle(BundleRegistry storage functions, Function[] storage functionInfos) internal returns(BundleRegistry storage) { - uint pid = functions.recordExecStart("addToBundle", "functions"); // TODO params - functions.findCurrentBundle().safeAdd(functionInfos); - return functions.recordExecFinish(pid); + function addToBundle(BundleRegistry storage bundle, Function[] storage functionInfos) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("addToBundle", "bundle"); // TODO params + bundle.findCurrentBundle().safeAdd(functionInfos); + return bundle.recordExecFinish(pid); } /**------------------ đŸĒŸ Set Facade --------------------*/ - function set(BundleRegistry storage functions, string memory name, address facade) internal returns(BundleRegistry storage) { - uint pid = functions.recordExecStart("set"); - functions.bundles[name.safeCalcHash()] + function set(BundleRegistry storage bundle, string memory name, address facade) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("set"); + bundle.bundles[name.safeCalcHash()] .assertExists() .safeAssign(facade); - return functions.recordExecFinish(pid); + return bundle.recordExecFinish(pid); } - function set(BundleRegistry storage functions, address facade) internal returns(BundleRegistry storage) { - uint pid = functions.recordExecStart("set"); - return functions.set(functions.findCurrentBundleName(), facade).recordExecFinish(pid); + function set(BundleRegistry storage bundle, address facade) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("set"); + return bundle.set(bundle.findCurrentBundleName(), facade).recordExecFinish(pid); } /**------------------------------------------------ - đŸ”ŧ Update Current Context Function & Bundle + đŸ”ŧ Update Current Context --------------------------------------------------*/ - /**----- 🧩 Function -------*/ - function safeUpdateCurrentFunction(BundleRegistry storage functions, string memory name) internal returns(BundleRegistry storage) { - uint pid = functions.recordExecStart("safeUpdateCurrentFunction"); - functions.currentFunctionName = name.assertNotEmpty(); - return functions.recordExecFinish(pid); - } - /**----- đŸ§ē Bundle -------*/ - function safeUpdateCurrentBundle(BundleRegistry storage functions, string memory name) internal returns(BundleRegistry storage) { - uint pid = functions.recordExecStart("safeUpdateCurrentBundle"); - functions.currentBundleName = name.assertNotEmpty(); - return functions.recordExecFinish(pid); + function safeUpdateCurrentBundle(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("safeUpdateCurrentBundle"); + bundle.currentBundleName = name.assertNotEmpty(); + return bundle.recordExecFinish(pid); } /**----------------------------------------------- â™ģī¸ Reset Current Context Function & Bundle -------------------------------------------------*/ - function reset(BundleRegistry storage functions) internal returns(BundleRegistry storage) { - uint pid = functions.recordExecStart("reset"); - delete functions.currentFunctionName; - delete functions.currentBundleName; - return functions.recordExecFinish(pid); + function reset(BundleRegistry storage bundle) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("reset"); + delete bundle.currentBundleName; + return bundle.recordExecFinish(pid); } /**------------------------------- 🔍 Find Function & Bundle ---------------------------------*/ - /**----- 🧩 Function -------*/ - function findFunction(BundleRegistry storage functions, string memory name) internal returns(Function storage) { - uint pid = functions.recordExecStart("findFunction"); - return functions.customs[name.safeCalcHash()].assertExists().finishProcess(pid); - } - function findCurrentFunction(BundleRegistry storage functions) internal returns(Function storage) { - uint pid = functions.recordExecStart("findCurrentFunction"); - return functions.findFunction(functions.findCurrentFunctionName()).finishProcess(pid); - } - function findCurrentFunctionName(BundleRegistry storage functions) internal returns(string memory) { - uint pid = functions.recordExecStart("findCurrentFunctionName"); - return functions.currentFunctionName.assertNotEmpty().recordExecFinish(pid); - } - - /**----- đŸ§ē Bundle -------*/ - function findBundle(BundleRegistry storage functions, string memory name) internal returns(Bundle storage) { - uint pid = functions.recordExecStart("findBundle"); - return functions.bundles[name.safeCalcHash()].recordExecFinish(pid); + function findBundle(BundleRegistry storage bundle, string memory name) internal returns(Bundle storage) { + uint pid = bundle.recordExecStart("findBundle"); + return bundle.bundles[name.safeCalcHash()].recordExecFinish(pid); } - function findCurrentBundle(BundleRegistry storage functions) internal returns(Bundle storage) { - uint pid = functions.recordExecStart("findCurrentBundle"); - return functions.findBundle(functions.findCurrentBundleName()).recordExecFinish(pid); + function findCurrentBundle(BundleRegistry storage bundle) internal returns(Bundle storage) { + uint pid = bundle.recordExecStart("findCurrentBundle"); + return bundle.findBundle(bundle.findCurrentBundleName()).recordExecFinish(pid); } - function findCurrentBundleName(BundleRegistry storage functions) internal returns(string memory) { - uint pid = functions.recordExecStart("findCurrentBundleName"); - return functions.currentBundleName.assertNotEmpty().recordExecFinish(pid); + function findCurrentBundleName(BundleRegistry storage bundle) internal returns(string memory) { + uint pid = bundle.recordExecStart("findCurrentBundleName"); + return bundle.currentBundleName.assertNotEmpty().recordExecFinish(pid); } /**----------------------------- 🏷 Generate Unique Name -------------------------------*/ - function genUniqueBundleName(BundleRegistry storage functions) internal returns(string memory name) { - uint pid = functions.recordExecStart("genUniqueBundleName"); + function genUniqueBundleName(BundleRegistry storage bundle) internal returns(string memory name) { + uint pid = bundle.recordExecStart("genUniqueBundleName"); ScanRange storage range = Config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = Config().DEFAULT_BUNDLE_NAME.toSequential(i); - if (functions.existsBundle(name).isFalse()) return name.recordExecFinish(pid); + if (bundle.existsBundle(name).isFalse()) return name.recordExecFinish(pid); } throwError(ERR.FIND_NAME_OVER_RANGE); } @@ -201,22 +151,22 @@ library BundleRegistryLib { /**------------------------------- 🧐 Inspectors & Assertions ---------------------------------*/ - function existsBundle(BundleRegistry storage functions, string memory name) internal returns(bool) { - return functions.bundles[name.safeCalcHash()].hasName(); + function existsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { + return bundle.bundles[name.safeCalcHash()].hasName(); } - function notExistsBundle(BundleRegistry storage functions, string memory name) internal returns(bool) { - return functions.existsBundle(name).isNot(); + function notExistsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { + return bundle.existsBundle(name).isNot(); } - function assertBundleNotExists(BundleRegistry storage functions, string memory name) internal returns(BundleRegistry storage) { - check(functions.notExistsBundle(name), "Bundle Already Exists"); - return functions; + function assertBundleNotExists(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + check(bundle.notExistsBundle(name), "Bundle Already Exists"); + return bundle; } - function existsCurrentBundle(BundleRegistry storage functions) internal returns(bool) { - return functions.currentBundleName.isNotEmpty(); + function existsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { + return bundle.currentBundleName.isNotEmpty(); } - function notExistsCurrentBundle(BundleRegistry storage functions) internal returns(bool) { - return functions.existsCurrentBundle().isNot(); + function notExistsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { + return bundle.existsCurrentBundle().isNot(); } @@ -229,16 +179,16 @@ library BundleRegistryLib { function recordExecStart(BundleRegistry storage, string memory funcName, string memory params) internal returns(uint) { return Debug.recordExecStart(LIB_NAME, funcName, params); } - function recordExecStart(BundleRegistry storage functions, string memory funcName) internal returns(uint) { - return functions.recordExecStart(funcName, ""); + function recordExecStart(BundleRegistry storage bundle, string memory funcName) internal returns(uint) { + return bundle.recordExecStart(funcName, ""); } /** Record Finish */ - function recordExecFinish(BundleRegistry storage functions, uint pid) internal returns(BundleRegistry storage) { + function recordExecFinish(BundleRegistry storage bundle, uint pid) internal returns(BundleRegistry storage) { Debug.recordExecFinish(pid); - return functions; + return bundle; } } diff --git a/devkit/method/MCBundleLib.sol b/devkit/method/MCBundleLib.sol index 03ec7ad1..d9992db3 100644 --- a/devkit/method/MCBundleLib.sol +++ b/devkit/method/MCBundleLib.sol @@ -67,7 +67,7 @@ library MCBundleLib { // return mc; // } TODO function use(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - check(mc.bundle.findFunction(name).isComplete(), "Invalid Function Name"); + check(mc.functions.findFunction(name).isComplete(), "Invalid Function Name"); return mc.use(mc.findFunction(name)); } /**--------------------------- @@ -75,7 +75,7 @@ library MCBundleLib { -----------------------------*/ function addFunction(MCDevKit storage mc, string memory name, bytes4 selector, address implementation) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("addFunction"); - mc.bundle.safeAddFunction(name, selector, implementation); + mc.functions.safeAddFunction(name, selector, implementation); return mc.recordExecFinish(pid); } /**------------------------------------- From 133ea6bb28561e15a50ed55b922acc3768242498 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 13:54:56 +0900 Subject: [PATCH 022/111] Adjust name change --- devkit/core/FunctionRegistry.sol | 29 ++++++++++++----------------- test/devkit/global/MCBundle.t.sol | 4 ++-- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/devkit/core/FunctionRegistry.sol b/devkit/core/FunctionRegistry.sol index c45ffe2d..8c9655e3 100644 --- a/devkit/core/FunctionRegistry.sol +++ b/devkit/core/FunctionRegistry.sol @@ -18,26 +18,21 @@ import {Bundle} from "devkit/core/Bundle.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; -/**------------------------------- - 🧩 UCS Functions Registry ----------------------------------*/ +/**--------------------------- + 🧩 Functions Registry +-----------------------------*/ using FunctionRegistryLib for FunctionRegistry global; struct FunctionRegistry { mapping(bytes32 nameHash => Function) customs; - mapping(bytes32 nameHash => Bundle) bundles; - string currentFunctionName; + string currentName; } /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ << Primary >> - 🌱 Init Bundle ✨ Add Custom Function 🔏 Load and Assign Custom Function from Env - đŸ§ē Add Custom Function to Bundle - đŸĒŸ Set Facade - đŸ”ŧ Update Current Context Function & Bundle - 🔍 Find Function & Bundle - 🏷 Generate Unique Name + đŸ”ŧ Update Current Context Function + 🔍 Find Function << Helper >> 🔍 Find Custom Function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ @@ -77,7 +72,7 @@ library FunctionRegistryLib { --------------------------------------------------*/ function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { uint pid = functions.recordExecStart("safeUpdateCurrentFunction"); - functions.currentFunctionName = name.assertNotEmpty(); + functions.currentName = name.assertNotEmpty(); return functions.recordExecFinish(pid); } @@ -87,7 +82,7 @@ library FunctionRegistryLib { -------------------------------------------------*/ function reset(FunctionRegistry storage functions) internal returns(FunctionRegistry storage) { uint pid = functions.recordExecStart("reset"); - delete functions.currentFunctionName; + delete functions.currentName; return functions.recordExecFinish(pid); } @@ -102,11 +97,11 @@ library FunctionRegistryLib { } function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { uint pid = functions.recordExecStart("findCurrentFunction"); - return functions.findFunction(functions.findCurrentFunctionName()).finishProcess(pid); + return functions.findFunction(functions.findCurrentName()).finishProcess(pid); } - function findCurrentFunctionName(FunctionRegistry storage functions) internal returns(string memory) { - uint pid = functions.recordExecStart("findCurrentFunctionName"); - return functions.currentFunctionName.assertNotEmpty().recordExecFinish(pid); + function findCurrentName(FunctionRegistry storage functions) internal returns(string memory) { + uint pid = functions.recordExecStart("findCurrentName"); + return functions.currentName.assertNotEmpty().recordExecFinish(pid); } diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 17f9d4dc..3cf553b7 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -57,7 +57,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { 🔗 Use Function -----------------------*/ function assertFunctionAdded(string memory bundleName, uint256 functionsIndex, string memory functionName, bytes4 selector, address impl) internal { - Bundle memory bundle = mc.functions.bundles[bundleName.safeCalcHash()]; + Bundle memory bundle = mc.bundle.bundles[bundleName.safeCalcHash()]; assertEq(bundle.name, bundleName); assertEq(bundle.facade, address(0)); Function memory func = mc.functions.customs[functionName.safeCalcHash()]; @@ -65,7 +65,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { assertEq(func.selector, selector); assertEq(func.implementation, impl); assertTrue(bundle.functionInfos[functionsIndex].isEqual(func)); - assertEq(mc.functions.currentFunctionName, functionName); + assertEq(mc.functions.currentName, functionName); } function test_Success_use() public { From 3179c7c4c60b5b83edcbb706b24c3238ec9477b8 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 13:57:42 +0900 Subject: [PATCH 023/111] Move dictionary to core/ --- devkit/MCDevKit.sol | 2 +- devkit/core/{dictionary => }/Dictionary.sol | 14 +++++++------- .../core/{dictionary => }/DictionaryRegistry.sol | 6 +++--- devkit/core/proxy/Proxy.sol | 2 +- devkit/core/proxy/ProxyRegistry.sol | 2 +- devkit/method/MCDeployLib.sol | 2 +- devkit/method/MCFinderLib.sol | 2 +- devkit/method/MCTestLib.sol | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) rename devkit/core/{dictionary => }/Dictionary.sol (95%) rename devkit/core/{dictionary => }/DictionaryRegistry.sol (97%) diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index 63e303b9..a8548f12 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; -import {DictionaryRegistry} from "devkit/core/dictionary/DictionaryRegistry.sol"; +import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; import {ProxyRegistry} from "devkit/core/proxy/ProxyRegistry.sol"; // Global Methods diff --git a/devkit/core/dictionary/Dictionary.sol b/devkit/core/Dictionary.sol similarity index 95% rename from devkit/core/dictionary/Dictionary.sol rename to devkit/core/Dictionary.sol index dfa0f3f1..44c2d8dd 100644 --- a/devkit/core/dictionary/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -5,22 +5,22 @@ pragma solidity ^0.8.24; import {check} from "devkit/error/Validation.sol"; import {Params} from "devkit/debug/Params.sol"; // Utils -import {AddressUtils} from "../../utils/AddressUtils.sol"; +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; -import {BoolUtils} from "../../utils/BoolUtils.sol"; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; -import {Bytes4Utils} from "../../utils/Bytes4Utils.sol"; +import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; using Bytes4Utils for bytes4; -import {StringUtils} from "../../utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; -import {ForgeHelper} from "../../utils/ForgeHelper.sol"; +import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; // Debug -import {Debug} from "../../debug/Debug.sol"; +import {Debug} from "devkit/debug/Debug.sol"; // Core import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; // Test -import {MockDictionary} from "../../test/MockDictionary.sol"; +import {MockDictionary} from "devkit/test/MockDictionary.sol"; // External Libs import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; diff --git a/devkit/core/dictionary/DictionaryRegistry.sol b/devkit/core/DictionaryRegistry.sol similarity index 97% rename from devkit/core/dictionary/DictionaryRegistry.sol rename to devkit/core/DictionaryRegistry.sol index f08e10a9..15c13a24 100644 --- a/devkit/core/dictionary/DictionaryRegistry.sol +++ b/devkit/core/DictionaryRegistry.sol @@ -8,11 +8,11 @@ import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; // Utils -import {AddressUtils} from "../../utils/AddressUtils.sol"; +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; -import {StringUtils} from "../../utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; -import {BoolUtils} from "../../utils/BoolUtils.sol"; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; // Core import {Dictionary} from "./Dictionary.sol"; diff --git a/devkit/core/proxy/Proxy.sol b/devkit/core/proxy/Proxy.sol index 6e004521..fbeeb34b 100644 --- a/devkit/core/proxy/Proxy.sol +++ b/devkit/core/proxy/Proxy.sol @@ -14,7 +14,7 @@ import {StringUtils} from "../../utils/StringUtils.sol"; import {ForgeHelper} from "../../utils/ForgeHelper.sol"; // Core // import {MCStdFuncs} from "../../core/functions/MCStdFuncs.sol"; -import {Dictionary} from "../dictionary/Dictionary.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; import {Function} from "devkit/core/Function.sol"; // Test import {SimpleMockProxy} from "../../test/SimpleMockProxy.sol"; diff --git a/devkit/core/proxy/ProxyRegistry.sol b/devkit/core/proxy/ProxyRegistry.sol index ed5f6ef8..b1ac6ca4 100644 --- a/devkit/core/proxy/ProxyRegistry.sol +++ b/devkit/core/proxy/ProxyRegistry.sol @@ -14,7 +14,7 @@ import {BoolUtils} from "../../utils/BoolUtils.sol"; using BoolUtils for bool; // Core import {Proxy} from "./Proxy.sol"; -import {Dictionary} from "../dictionary/Dictionary.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; /**--------------------------- diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index a137d70f..68fdb3b0 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -9,7 +9,7 @@ import {check} from "devkit/error/Validation.sol"; import {Params} from "devkit/debug/Params.sol"; // Core // dictionary -import {Dictionary, DictionaryLib} from "devkit/core/dictionary/Dictionary.sol"; +import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; // functions import {Bundle} from "devkit/core/Bundle.sol"; import {StdFunctionsArgs} from "devkit/core/StdFunctions.sol"; diff --git a/devkit/method/MCFinderLib.sol b/devkit/method/MCFinderLib.sol index 9222af6d..964ae078 100644 --- a/devkit/method/MCFinderLib.sol +++ b/devkit/method/MCFinderLib.sol @@ -9,7 +9,7 @@ import {Function} from "devkit/core/Function.sol"; // proxy import {Proxy} from "devkit/core/proxy/Proxy.sol"; // dictionary -import {Dictionary} from "devkit/core/dictionary/Dictionary.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; /********************************** diff --git a/devkit/method/MCTestLib.sol b/devkit/method/MCTestLib.sol index 41fca2d1..0e7071f3 100644 --- a/devkit/method/MCTestLib.sol +++ b/devkit/method/MCTestLib.sol @@ -12,7 +12,7 @@ import {Function} from "devkit/core/Function.sol"; // proxy import {Proxy, ProxyLib} from "devkit/core/proxy/Proxy.sol"; // dictionary -import {Dictionary, DictionaryLib} from "devkit/core/dictionary/Dictionary.sol"; +import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; /****************************************** From bbc120ef5fd34b25afec61fd6b90ccf54cbeecf4 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 13:59:26 +0900 Subject: [PATCH 024/111] Move proxy to core/ --- devkit/MCDevKit.sol | 2 +- devkit/core/{proxy => }/Proxy.sol | 12 ++++++------ devkit/core/{proxy => }/ProxyRegistry.sol | 4 ++-- devkit/method/MCDeployLib.sol | 2 +- devkit/method/MCFinderLib.sol | 2 +- devkit/method/MCTestLib.sol | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) rename devkit/core/{proxy => }/Proxy.sol (94%) rename devkit/core/{proxy => }/ProxyRegistry.sol (98%) diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index a8548f12..0f6ae491 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -6,7 +6,7 @@ import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; -import {ProxyRegistry} from "devkit/core/proxy/ProxyRegistry.sol"; +import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; // Global Methods import {MCSetupLib} from "devkit/method/MCSetupLib.sol"; diff --git a/devkit/core/proxy/Proxy.sol b/devkit/core/Proxy.sol similarity index 94% rename from devkit/core/proxy/Proxy.sol rename to devkit/core/Proxy.sol index fbeeb34b..14f31a0e 100644 --- a/devkit/core/proxy/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -5,19 +5,19 @@ pragma solidity ^0.8.24; import {check} from "devkit/error/Validation.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Utils -import {AddressUtils} from "../../utils/AddressUtils.sol"; +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; -import {BoolUtils} from "../../utils/BoolUtils.sol"; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; -import {StringUtils} from "../../utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; -import {ForgeHelper} from "../../utils/ForgeHelper.sol"; +import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; // Core -// import {MCStdFuncs} from "../../core/functions/MCStdFuncs.sol"; +// import {MCStdFuncs} from "devkit/core/functions/MCStdFuncs.sol"; import {Dictionary} from "devkit/core/Dictionary.sol"; import {Function} from "devkit/core/Function.sol"; // Test -import {SimpleMockProxy} from "../../test/SimpleMockProxy.sol"; +import {SimpleMockProxy} from "devkit/test/SimpleMockProxy.sol"; // External Lib import {ERC7546Utils} from "@ucs.mc/proxy/ERC7546Utils.sol"; import {ERC7546Proxy} from "@ucs.mc/proxy/ERC7546Proxy.sol"; diff --git a/devkit/core/proxy/ProxyRegistry.sol b/devkit/core/ProxyRegistry.sol similarity index 98% rename from devkit/core/proxy/ProxyRegistry.sol rename to devkit/core/ProxyRegistry.sol index b1ac6ca4..581526ed 100644 --- a/devkit/core/proxy/ProxyRegistry.sol +++ b/devkit/core/ProxyRegistry.sol @@ -8,9 +8,9 @@ import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; // Utils -import {StringUtils} from "../../utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; -import {BoolUtils} from "../../utils/BoolUtils.sol"; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; // Core import {Proxy} from "./Proxy.sol"; diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index 68fdb3b0..54e936e2 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -15,7 +15,7 @@ import {Bundle} from "devkit/core/Bundle.sol"; import {StdFunctionsArgs} from "devkit/core/StdFunctions.sol"; using StdFunctionsArgs for address; // proxy -import {Proxy, ProxyLib} from "devkit/core/proxy/Proxy.sol"; +import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; diff --git a/devkit/method/MCFinderLib.sol b/devkit/method/MCFinderLib.sol index 964ae078..467c864b 100644 --- a/devkit/method/MCFinderLib.sol +++ b/devkit/method/MCFinderLib.sol @@ -7,7 +7,7 @@ import {MCDevKit} from "devkit/MCDevKit.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; // proxy -import {Proxy} from "devkit/core/proxy/Proxy.sol"; +import {Proxy} from "devkit/core/Proxy.sol"; // dictionary import {Dictionary} from "devkit/core/Dictionary.sol"; diff --git a/devkit/method/MCTestLib.sol b/devkit/method/MCTestLib.sol index 0e7071f3..a40afa6d 100644 --- a/devkit/method/MCTestLib.sol +++ b/devkit/method/MCTestLib.sol @@ -10,7 +10,7 @@ import {Params} from "devkit/debug/Params.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; // proxy -import {Proxy, ProxyLib} from "devkit/core/proxy/Proxy.sol"; +import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; // dictionary import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; From 5ce0c76d0ab14c926865ea1e92d2e4577c304896 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 14:17:13 +0900 Subject: [PATCH 025/111] Separate process method from StdFunctionsLib --- devkit/MCDevKit.sol | 2 +- devkit/core/StdFunctions.sol | 146 +------------------------ devkit/method/MCDeployLib.sol | 2 +- devkit/method/core/StdFunctionsLib.sol | 140 ++++++++++++++++++++++++ devkit/method/debug/ProcessLib.sol | 16 +++ 5 files changed, 163 insertions(+), 143 deletions(-) create mode 100644 devkit/method/core/StdFunctionsLib.sol diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index 0f6ae491..172db8c9 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.24; // Core Registries -import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; +import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; diff --git a/devkit/core/StdFunctions.sol b/devkit/core/StdFunctions.sol index eb2d0000..f1c9ff6b 100644 --- a/devkit/core/StdFunctions.sol +++ b/devkit/core/StdFunctions.sol @@ -1,157 +1,21 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Utils -import {console2} from "devkit/utils/ForgeHelper.sol"; -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -// Debug -import {Debug} from "devkit/debug/Debug.sol"; -import {Logger} from "devkit/debug/Logger.sol"; // Core import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "./Bundle.sol"; -// MC Std -import {Clone} from "mc-std/functions/Clone.sol"; -import {GetDeps} from "mc-std/functions/GetDeps.sol"; -import {FeatureToggle} from "mc-std/functions/protected/FeatureToggle.sol"; -import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; -import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.sol"; -import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {StdFunctionsLib} from "devkit/method/core/StdFunctionsLib.sol"; +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; /***************************************** 🏛 Meta Contract Standard Functions ******************************************/ -using StdFunctionsLib for StdFunctions global; struct StdFunctions { Function initSetAdmin; Function getDeps; Function clone; Bundle all; } - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🔏 Assign and Load Standard Functions - đŸŖ Deploy Standard Functions If Not Exists - đŸ§ē Configure Standard Bundles -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library StdFunctionsLib { - string constant LIB_NAME = "StdFunctionsLib"; - function recordExecStart(string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(string memory funcName) internal returns(uint) { - return recordExecStart(funcName, ""); - } - function recordExecFinish(StdFunctions storage std, uint pid) internal returns(StdFunctions storage) { - Debug.recordExecFinish(pid); - return std; - } - - /**------------------------------------------ - 🔏 Assign and Load Standard Functions - --------------------------------------------*/ - function assignAndLoad(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = recordExecStart("assignAndLoad"); - return std .assignAndLoad_InitSetAdmin() - .assignAndLoad_GetDeps() - .assignAndLoad_Clone() - .recordExecFinish(pid); - } - - /**===== Each Std Function =====*/ - function assignAndLoad_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = recordExecStart("assignAndLoad_InitSetAdmin"); - std.initSetAdmin.safeAssign("InitSetAdmin") - .safeAssign(InitSetAdmin.initSetAdmin.selector) - .loadAndAssignFromEnv() - .parseAndLog(); - return std.recordExecFinish(pid); - } - - function assignAndLoad_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = recordExecStart("assignAndLoad_GetDeps"); - std.getDeps .safeAssign("GetDeps") - .safeAssign(GetDeps.getDeps.selector) - .loadAndAssignFromEnv() - .parseAndLog(); - return std.recordExecFinish(pid); - } - - function assignAndLoad_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = recordExecStart("assignAndLoad_Clone"); - std.clone .safeAssign("Clone") - .safeAssign(Clone.clone.selector) - .loadAndAssignFromEnv() - .parseAndLog(); - return std.recordExecFinish(pid); - } - - - /**----------------------------------------------- - đŸŖ Deploy Standard Functions If Not Exists - TODO versioning - -------------------------------------------------*/ - function deployIfNotExists(StdFunctions storage std) internal returns(StdFunctions storage) { - return std .deployIfNotExists_InitSetAdmin() - .deployIfNotExists_GetDeps() - .deployIfNotExists_Clone(); - } - /**===== Each Std Function =====*/ - function deployIfNotExists_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { - if (std.initSetAdmin.implementation.isNotContract()) { - std.initSetAdmin.safeAssign(address(new InitSetAdmin())); - } - return std; - } - - function deployIfNotExists_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { - if (!std.getDeps.implementation.isContract()) { - std.getDeps.safeAssign(address(new GetDeps())); - } - return std; - } - - function deployIfNotExists_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { - if (!std.clone.implementation.isContract()) { - std.clone.safeAssign(address(new Clone())); - } - return std; - } - - - /**---------------------------------- - đŸ§ē Configure Standard Bundles - ------------------------------------*/ - function configureStdBundle(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = recordExecStart("configureStdBundle"); - return std .configureStdBundle_AllFunctions() - .recordExecFinish(pid); - } - - /**===== Each Std Bundle =====*/ - function configureStdBundle_AllFunctions(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = recordExecStart("configureStdBundle_AllFunctions"); - std.all .safeAssign("ALL_FUNCTIONS") - .safeAdd(std.initSetAdmin) - .safeAdd(std.getDeps) - .safeAdd(std.clone) - .safeAssign(address(new StdFacade())); - return std.recordExecFinish(pid); - } - -} - - -/**************************************************** - 🧩 Std Ops Primitive Utils for Arguments -*****************************************************/ -library StdFunctionsArgs { - function initSetAdminBytes(address admin) internal view returns(bytes memory) { - return abi.encodeCall(InitSetAdmin.initSetAdmin, admin); - } - -} +using StdFunctionsLib for StdFunctions global; +using ProcessLib for StdFunctions global; diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index 54e936e2..aacfa501 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -12,7 +12,7 @@ import {Params} from "devkit/debug/Params.sol"; import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; // functions import {Bundle} from "devkit/core/Bundle.sol"; -import {StdFunctionsArgs} from "devkit/core/StdFunctions.sol"; +import {StdFunctionsArgs} from "devkit/method/core/StdFunctionsLib.sol"; using StdFunctionsArgs for address; // proxy import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; diff --git a/devkit/method/core/StdFunctionsLib.sol b/devkit/method/core/StdFunctionsLib.sol new file mode 100644 index 00000000..d68ed884 --- /dev/null +++ b/devkit/method/core/StdFunctionsLib.sol @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Utils +import {console2} from "devkit/utils/ForgeHelper.sol"; +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; + using AddressUtils for address; +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +// Debug +import {Debug} from "devkit/debug/Debug.sol"; +import {Logger} from "devkit/debug/Logger.sol"; +// Core +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +// MC Std +import {Clone} from "mc-std/functions/Clone.sol"; +import {GetDeps} from "mc-std/functions/GetDeps.sol"; +import {FeatureToggle} from "mc-std/functions/protected/FeatureToggle.sol"; +import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; +import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.sol"; +import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; + +import {StdFunctions} from "devkit/core/StdFunctions.sol"; + +/***************************************** + 🏛 Meta Contract Standard Functions +******************************************/ + +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 🔏 Assign and Load Standard Functions + đŸŖ Deploy Standard Functions If Not Exists + đŸ§ē Configure Standard Bundles +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library StdFunctionsLib { + + /**------------------------------------------ + 🔏 Assign and Load Standard Functions + --------------------------------------------*/ + function assignAndLoad(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("assignAndLoad"); + return std .assignAndLoad_InitSetAdmin() + .assignAndLoad_GetDeps() + .assignAndLoad_Clone() + .finishProcess(pid); + } + + /**===== Each Std Function =====*/ + function assignAndLoad_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("assignAndLoad_InitSetAdmin"); + std.initSetAdmin.safeAssign("InitSetAdmin") + .safeAssign(InitSetAdmin.initSetAdmin.selector) + .loadAndAssignFromEnv() + .parseAndLog(); + return std.finishProcess(pid); + } + + function assignAndLoad_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("assignAndLoad_GetDeps"); + std.getDeps .safeAssign("GetDeps") + .safeAssign(GetDeps.getDeps.selector) + .loadAndAssignFromEnv() + .parseAndLog(); + return std.finishProcess(pid); + } + + function assignAndLoad_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("assignAndLoad_Clone"); + std.clone .safeAssign("Clone") + .safeAssign(Clone.clone.selector) + .loadAndAssignFromEnv() + .parseAndLog(); + return std.finishProcess(pid); + } + + + /**----------------------------------------------- + đŸŖ Deploy Standard Functions If Not Exists + TODO versioning + -------------------------------------------------*/ + function deployIfNotExists(StdFunctions storage std) internal returns(StdFunctions storage) { + return std .deployIfNotExists_InitSetAdmin() + .deployIfNotExists_GetDeps() + .deployIfNotExists_Clone(); + } + /**===== Each Std Function =====*/ + function deployIfNotExists_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { + if (std.initSetAdmin.implementation.isNotContract()) { + std.initSetAdmin.safeAssign(address(new InitSetAdmin())); + } + return std; + } + + function deployIfNotExists_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { + if (!std.getDeps.implementation.isContract()) { + std.getDeps.safeAssign(address(new GetDeps())); + } + return std; + } + + function deployIfNotExists_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { + if (!std.clone.implementation.isContract()) { + std.clone.safeAssign(address(new Clone())); + } + return std; + } + + + /**---------------------------------- + đŸ§ē Configure Standard Bundles + ------------------------------------*/ + function configureStdBundle(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("configureStdBundle"); + return std .configureStdBundle_AllFunctions() + .finishProcess(pid); + } + + /**===== Each Std Bundle =====*/ + function configureStdBundle_AllFunctions(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("configureStdBundle_AllFunctions"); + std.all .safeAssign("ALL_FUNCTIONS") + .safeAdd(std.initSetAdmin) + .safeAdd(std.getDeps) + .safeAdd(std.clone) + .safeAssign(address(new StdFacade())); + return std.finishProcess(pid); + } + +} + + +/**************************************************** + 🧩 Std Ops Primitive Utils for Arguments +*****************************************************/ +library StdFunctionsArgs { + function initSetAdminBytes(address admin) internal view returns(bytes memory) { + return abi.encodeCall(InitSetAdmin.initSetAdmin, admin); + } + +} diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol index 0d52cd81..ca933ad4 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; import {Debug} from "devkit/debug/Debug.sol"; // Types import {Function} from "devkit/core/Function.sol"; +import {StdFunctions} from "devkit/core/StdFunctions.sol"; library ProcessLib { function startProcess(Function storage, string memory name, string memory params) internal returns(uint) { @@ -17,4 +18,19 @@ library ProcessLib { return func; } + + /**-------------------------- + 🏛 Standard Functions + ----------------------------*/ + function startProcess(StdFunctions storage, string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("StdFunctionsLib", name, params); + } + function startProcess(StdFunctions storage std, string memory name) internal returns(uint) { + return std.startProcess(name, ""); + } + function finishProcess(StdFunctions storage std, uint pid) internal returns(StdFunctions storage) { + Debug.recordExecFinish(pid); + return std; + } + } From 76ec827b2d6821decfa2fb0fd04032153534b45e Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 14:26:39 +0900 Subject: [PATCH 026/111] chore update std functions --- devkit/core/StdFunctions.sol | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/devkit/core/StdFunctions.sol b/devkit/core/StdFunctions.sol index f1c9ff6b..b27b3433 100644 --- a/devkit/core/StdFunctions.sol +++ b/devkit/core/StdFunctions.sol @@ -1,16 +1,17 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Core +// Core Types import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; - +// Methods import {StdFunctionsLib} from "devkit/method/core/StdFunctionsLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/***************************************** - 🏛 Meta Contract Standard Functions -******************************************/ + +/**************************** + 🏛 Standard Functions +*****************************/ struct StdFunctions { Function initSetAdmin; Function getDeps; From 5ea46806029cf609ee9fa64ff85b75c54222f4d1 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 14:36:12 +0900 Subject: [PATCH 027/111] Separate ProxyRegistryLib file --- devkit/core/ProxyRegistry.sol | 162 +----------------------- devkit/method/core/ProxyRegistryLib.sol | 158 +++++++++++++++++++++++ 2 files changed, 165 insertions(+), 155 deletions(-) create mode 100644 devkit/method/core/ProxyRegistryLib.sol diff --git a/devkit/core/ProxyRegistry.sol b/devkit/core/ProxyRegistry.sol index 581526ed..343ec192 100644 --- a/devkit/core/ProxyRegistry.sol +++ b/devkit/core/ProxyRegistry.sol @@ -1,166 +1,18 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Error & Debug -import {ERR, throwError} from "devkit/error/Error.sol"; -import {check} from "devkit/error/Validation.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Config -import {Config, ScanRange} from "devkit/config/Config.sol"; -// Utils -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -// Core -import {Proxy} from "./Proxy.sol"; -import {Dictionary} from "devkit/core/Dictionary.sol"; +// Core Types +import {Proxy} from "devkit/core/Proxy.sol"; +// Methods +import {ProxyRegistryLib} from "devkit/method/core/ProxyRegistryLib.sol"; -/**--------------------------- - 🏠 UCS Proxy Registry ------------------------------*/ +/************************ + 🏠 Proxy Registry +*************************/ using ProxyRegistryLib for ProxyRegistry global; struct ProxyRegistry { mapping(bytes32 nameHash => Proxy) deployed; mapping(bytes32 nameHash => Proxy) mocks; Proxy currentProxy; } - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> - đŸ“Ĩ Add Proxy - đŸ”ŧ Update Current Context Proxy - â™ģī¸ Reset Current Context Proxy - 🔍 Find Proxy - 🏷 Generate Unique Name - << Helper >> - 🧐 Inspectors & Assertions - 🐞 Debug -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library ProxyRegistryLib { - string constant LIB_NAME = "ProxyRegistryLib"; - - - /**------------------- - đŸ“Ĩ Add Proxy - ---------------------*/ - function add(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.recordExecStart("add"); - bytes32 nameHash = name.calcHash(); - if (proxy.isNotMock()) { - proxies.deployed[nameHash] = proxy; - } - if (proxy.isMock()) { - proxies.mocks[nameHash] = proxy; - } - return proxies.recordExecFinish(pid); - } - - function safeAdd(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.recordExecStart("safeAdd"); - return proxies .add(name.assertNotEmpty(), proxy.assertNotEmpty()) - .recordExecFinish(pid); - } - - - /**------------------------------------ - đŸ”ŧ Update Current Context Proxy - --------------------------------------*/ - function safeUpdate(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.recordExecStart("safeUpdate"); - return proxies.update(proxy.assertNotEmpty()).recordExecFinish(pid); - } - function update(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.recordExecStart("update"); - proxies.currentProxy = proxy; - return proxies.recordExecFinish(pid); - } - - - /**---------------------------------- - â™ģī¸ Reset Current Context Proxy - ------------------------------------*/ - function reset(ProxyRegistry storage proxies) internal returns(ProxyRegistry storage) { - uint pid = proxies.recordExecStart("reset"); - delete proxies.currentProxy; - return proxies.recordExecFinish(pid); - } - - - /**------------------- - 🔍 Find Proxy - ---------------------*/ - function find(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { - uint pid = proxies.recordExecStart("find"); - return proxies.deployed[name.safeCalcHash()] - .assertExists().recordExecFinishInStorage(pid); - } - function findCurrentProxy(ProxyRegistry storage proxies) internal returns(Proxy storage) { - uint pid = proxies.recordExecStart("findCurrentProxy"); - return proxies.currentProxy.assertExists().recordExecFinishInStorage(pid); - } - function findSimpleMockProxy(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { - uint pid = proxies.recordExecStart("findSimpleMockProxy"); - return proxies.mocks[name.safeCalcHash()].assertExists().recordExecFinishInStorage(pid); - } - - - /**----------------------------- - 🏷 Generate Unique Name - -------------------------------*/ - function genUniqueName(ProxyRegistry storage proxies) internal returns(string memory name) { - uint pid = proxies.recordExecStart("genUniqueName"); - ScanRange memory range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = Config().DEFAULT_PROXY_NAME.toSequential(i); - if (proxies.existsInDeployed(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } - - function genUniqueMockName(ProxyRegistry storage proxies) internal returns(string memory name) { - uint pid = proxies.recordExecStart("genUniqueMockName"); - ScanRange memory range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = Config().DEFAULT_PROXY_MOCK_NAME.toSequential(i); - if (proxies.existsInMocks(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } - - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function existsInDeployed(ProxyRegistry storage proxies, string memory name) internal returns(bool) { - return proxies.deployed[name.safeCalcHash()].exists(); - } - function existsInMocks(ProxyRegistry storage proxies, string memory name) internal returns(bool) { - return proxies.mocks[name.safeCalcHash()].exists(); - } - - - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Start - */ - function recordExecStart(ProxyRegistry storage, string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(ProxyRegistry storage proxies, string memory funcName) internal returns(uint) { - return proxies.recordExecStart(funcName, ""); - } - - /** - Record Finish - */ - function recordExecFinish(ProxyRegistry storage proxies, uint pid) internal returns(ProxyRegistry storage) { - Debug.recordExecFinish(pid); - return proxies; - } - -} diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol new file mode 100644 index 00000000..af7996a1 --- /dev/null +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Error & Debug +import {ERR, throwError} from "devkit/error/Error.sol"; +import {check} from "devkit/error/Validation.sol"; +import {Debug} from "devkit/debug/Debug.sol"; +// Config +import {Config, ScanRange} from "devkit/config/Config.sol"; +// Utils +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +// Core +import {Proxy} from "devkit/core/Proxy.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; + +import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; + +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 🏠 UCS Proxy Registry + << Primary >> + đŸ“Ĩ Add Proxy + đŸ”ŧ Update Current Context Proxy + â™ģī¸ Reset Current Context Proxy + 🔍 Find Proxy + 🏷 Generate Unique Name + << Helper >> + 🧐 Inspectors & Assertions + 🐞 Debug +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library ProxyRegistryLib { + string constant LIB_NAME = "ProxyRegistryLib"; + + + /**------------------- + đŸ“Ĩ Add Proxy + ---------------------*/ + function add(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { + uint pid = proxies.recordExecStart("add"); + bytes32 nameHash = name.calcHash(); + if (proxy.isNotMock()) { + proxies.deployed[nameHash] = proxy; + } + if (proxy.isMock()) { + proxies.mocks[nameHash] = proxy; + } + return proxies.recordExecFinish(pid); + } + + function safeAdd(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { + uint pid = proxies.recordExecStart("safeAdd"); + return proxies .add(name.assertNotEmpty(), proxy.assertNotEmpty()) + .recordExecFinish(pid); + } + + + /**------------------------------------ + đŸ”ŧ Update Current Context Proxy + --------------------------------------*/ + function safeUpdate(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { + uint pid = proxies.recordExecStart("safeUpdate"); + return proxies.update(proxy.assertNotEmpty()).recordExecFinish(pid); + } + function update(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { + uint pid = proxies.recordExecStart("update"); + proxies.currentProxy = proxy; + return proxies.recordExecFinish(pid); + } + + + /**---------------------------------- + â™ģī¸ Reset Current Context Proxy + ------------------------------------*/ + function reset(ProxyRegistry storage proxies) internal returns(ProxyRegistry storage) { + uint pid = proxies.recordExecStart("reset"); + delete proxies.currentProxy; + return proxies.recordExecFinish(pid); + } + + + /**------------------- + 🔍 Find Proxy + ---------------------*/ + function find(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { + uint pid = proxies.recordExecStart("find"); + return proxies.deployed[name.safeCalcHash()] + .assertExists().recordExecFinishInStorage(pid); + } + function findCurrentProxy(ProxyRegistry storage proxies) internal returns(Proxy storage) { + uint pid = proxies.recordExecStart("findCurrentProxy"); + return proxies.currentProxy.assertExists().recordExecFinishInStorage(pid); + } + function findSimpleMockProxy(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { + uint pid = proxies.recordExecStart("findSimpleMockProxy"); + return proxies.mocks[name.safeCalcHash()].assertExists().recordExecFinishInStorage(pid); + } + + + /**----------------------------- + 🏷 Generate Unique Name + -------------------------------*/ + function genUniqueName(ProxyRegistry storage proxies) internal returns(string memory name) { + uint pid = proxies.recordExecStart("genUniqueName"); + ScanRange memory range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = Config().DEFAULT_PROXY_NAME.toSequential(i); + if (proxies.existsInDeployed(name).isFalse()) return name.recordExecFinish(pid); + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + + function genUniqueMockName(ProxyRegistry storage proxies) internal returns(string memory name) { + uint pid = proxies.recordExecStart("genUniqueMockName"); + ScanRange memory range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = Config().DEFAULT_PROXY_MOCK_NAME.toSequential(i); + if (proxies.existsInMocks(name).isFalse()) return name.recordExecFinish(pid); + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + + + + /**------------------------------- + 🧐 Inspectors & Assertions + ---------------------------------*/ + function existsInDeployed(ProxyRegistry storage proxies, string memory name) internal returns(bool) { + return proxies.deployed[name.safeCalcHash()].exists(); + } + function existsInMocks(ProxyRegistry storage proxies, string memory name) internal returns(bool) { + return proxies.mocks[name.safeCalcHash()].exists(); + } + + + /**---------------- + 🐞 Debug + ------------------*/ + /** + Record Start + */ + function recordExecStart(ProxyRegistry storage, string memory funcName, string memory params) internal returns(uint) { + return Debug.recordExecStart(LIB_NAME, funcName, params); + } + function recordExecStart(ProxyRegistry storage proxies, string memory funcName) internal returns(uint) { + return proxies.recordExecStart(funcName, ""); + } + + /** + Record Finish + */ + function recordExecFinish(ProxyRegistry storage proxies, uint pid) internal returns(ProxyRegistry storage) { + Debug.recordExecFinish(pid); + return proxies; + } + +} From 90450a2a6010a4ad09bf24f3dffa03e7486c8d4f Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 15:27:37 +0900 Subject: [PATCH 028/111] Separate process methods from ProxyRegistryLib --- devkit/core/ProxyRegistry.sol | 4 +- devkit/method/core/ProxyRegistryLib.sol | 53 +++++++------------------ devkit/method/debug/ProcessLib.sol | 21 ++++++++++ 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/devkit/core/ProxyRegistry.sol b/devkit/core/ProxyRegistry.sol index 343ec192..26da6c60 100644 --- a/devkit/core/ProxyRegistry.sol +++ b/devkit/core/ProxyRegistry.sol @@ -5,14 +5,16 @@ pragma solidity ^0.8.24; import {Proxy} from "devkit/core/Proxy.sol"; // Methods import {ProxyRegistryLib} from "devkit/method/core/ProxyRegistryLib.sol"; +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; /************************ 🏠 Proxy Registry *************************/ -using ProxyRegistryLib for ProxyRegistry global; struct ProxyRegistry { mapping(bytes32 nameHash => Proxy) deployed; mapping(bytes32 nameHash => Proxy) mocks; Proxy currentProxy; } +using ProxyRegistryLib for ProxyRegistry global; +using ProcessLib for ProxyRegistry global; diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol index af7996a1..c3423dda 100644 --- a/devkit/method/core/ProxyRegistryLib.sol +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -31,14 +31,13 @@ import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; 🐞 Debug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library ProxyRegistryLib { - string constant LIB_NAME = "ProxyRegistryLib"; /**------------------- đŸ“Ĩ Add Proxy ---------------------*/ function add(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.recordExecStart("add"); + uint pid = proxies.startProcess("add"); bytes32 nameHash = name.calcHash(); if (proxy.isNotMock()) { proxies.deployed[nameHash] = proxy; @@ -46,13 +45,13 @@ library ProxyRegistryLib { if (proxy.isMock()) { proxies.mocks[nameHash] = proxy; } - return proxies.recordExecFinish(pid); + return proxies.finishProcess(pid); } function safeAdd(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.recordExecStart("safeAdd"); + uint pid = proxies.startProcess("safeAdd"); return proxies .add(name.assertNotEmpty(), proxy.assertNotEmpty()) - .recordExecFinish(pid); + .finishProcess(pid); } @@ -60,13 +59,13 @@ library ProxyRegistryLib { đŸ”ŧ Update Current Context Proxy --------------------------------------*/ function safeUpdate(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.recordExecStart("safeUpdate"); - return proxies.update(proxy.assertNotEmpty()).recordExecFinish(pid); + uint pid = proxies.startProcess("safeUpdate"); + return proxies.update(proxy.assertNotEmpty()).finishProcess(pid); } function update(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.recordExecStart("update"); + uint pid = proxies.startProcess("update"); proxies.currentProxy = proxy; - return proxies.recordExecFinish(pid); + return proxies.finishProcess(pid); } @@ -74,9 +73,9 @@ library ProxyRegistryLib { â™ģī¸ Reset Current Context Proxy ------------------------------------*/ function reset(ProxyRegistry storage proxies) internal returns(ProxyRegistry storage) { - uint pid = proxies.recordExecStart("reset"); + uint pid = proxies.startProcess("reset"); delete proxies.currentProxy; - return proxies.recordExecFinish(pid); + return proxies.finishProcess(pid); } @@ -84,16 +83,16 @@ library ProxyRegistryLib { 🔍 Find Proxy ---------------------*/ function find(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { - uint pid = proxies.recordExecStart("find"); + uint pid = proxies.startProcess("find"); return proxies.deployed[name.safeCalcHash()] .assertExists().recordExecFinishInStorage(pid); } function findCurrentProxy(ProxyRegistry storage proxies) internal returns(Proxy storage) { - uint pid = proxies.recordExecStart("findCurrentProxy"); + uint pid = proxies.startProcess("findCurrentProxy"); return proxies.currentProxy.assertExists().recordExecFinishInStorage(pid); } function findSimpleMockProxy(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { - uint pid = proxies.recordExecStart("findSimpleMockProxy"); + uint pid = proxies.startProcess("findSimpleMockProxy"); return proxies.mocks[name.safeCalcHash()].assertExists().recordExecFinishInStorage(pid); } @@ -102,7 +101,7 @@ library ProxyRegistryLib { 🏷 Generate Unique Name -------------------------------*/ function genUniqueName(ProxyRegistry storage proxies) internal returns(string memory name) { - uint pid = proxies.recordExecStart("genUniqueName"); + uint pid = proxies.startProcess("genUniqueName"); ScanRange memory range = Config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = Config().DEFAULT_PROXY_NAME.toSequential(i); @@ -112,7 +111,7 @@ library ProxyRegistryLib { } function genUniqueMockName(ProxyRegistry storage proxies) internal returns(string memory name) { - uint pid = proxies.recordExecStart("genUniqueMockName"); + uint pid = proxies.startProcess("genUniqueMockName"); ScanRange memory range = Config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = Config().DEFAULT_PROXY_MOCK_NAME.toSequential(i); @@ -133,26 +132,4 @@ library ProxyRegistryLib { return proxies.mocks[name.safeCalcHash()].exists(); } - - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Start - */ - function recordExecStart(ProxyRegistry storage, string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(ProxyRegistry storage proxies, string memory funcName) internal returns(uint) { - return proxies.recordExecStart(funcName, ""); - } - - /** - Record Finish - */ - function recordExecFinish(ProxyRegistry storage proxies, uint pid) internal returns(ProxyRegistry storage) { - Debug.recordExecFinish(pid); - return proxies; - } - } diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol index ca933ad4..257d7682 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -5,14 +5,19 @@ import {Debug} from "devkit/debug/Debug.sol"; // Types import {Function} from "devkit/core/Function.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; +import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; library ProcessLib { + /**------------------ + 🧩 Function + --------------------*/ function startProcess(Function storage, string memory name, string memory params) internal returns(uint) { return Debug.recordExecStart("FunctionLib", name, params); } function startProcess(Function storage func, string memory name) internal returns(uint) { return func.startProcess(name, ""); } + function finishProcess(Function storage func, uint pid) internal returns(Function storage) { Debug.recordExecFinish(pid); return func; @@ -28,9 +33,25 @@ library ProcessLib { function startProcess(StdFunctions storage std, string memory name) internal returns(uint) { return std.startProcess(name, ""); } + function finishProcess(StdFunctions storage std, uint pid) internal returns(StdFunctions storage) { Debug.recordExecFinish(pid); return std; } + + /**---------------------- + 🏠 Proxy Registry + ------------------------*/ + function startProcess(ProxyRegistry storage, string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("ProxyRegistryLib", name, params); + } + function startProcess(ProxyRegistry storage proxies, string memory name) internal returns(uint) { + return proxies.startProcess(name, ""); + } + + function finishProcess(ProxyRegistry storage proxies, uint pid) internal returns(ProxyRegistry storage) { + Debug.recordExecFinish(pid); + return proxies; + } } From 3518f19a65c5285dc23a68bc5fa82f5b1ec13a3c Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 15:33:22 +0900 Subject: [PATCH 029/111] Separate BundleLib from Bundle file --- devkit/core/Bundle.sol | 143 +++---------------------------- devkit/method/core/BundleLib.sol | 135 +++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+), 133 deletions(-) create mode 100644 devkit/method/core/BundleLib.sol diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 0d81a068..349949a6 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -1,143 +1,20 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Validation -import {check} from "devkit/error/Validation.sol"; -// Utils -import {console2} from "devkit/utils/ForgeHelper.sol"; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; -// Debug -import {Debug} from "devkit/debug/Debug.sol"; -import {Logger} from "devkit/debug/Logger.sol"; -// Core +// Core Type import {Function} from "devkit/core/Function.sol"; +// Methods +import {BundleLib} from "devkit/method/core/BundleLib.sol"; +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/**==================== - đŸ§ē Bundle Info -======================*/ -using BundleUtils for Bundle global; + +/****************** + đŸ§ē Bundle +*******************/ struct Bundle { string name; Function[] functionInfos; address facade; } - -library BundleUtils { - string constant LIB_NAME = "Bundle"; - function recordExecStart(string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(string memory funcName) internal returns(uint) { - return recordExecStart(funcName, ""); - } - function recordExecFinish(Bundle storage bundle, uint pid) internal returns(Bundle storage) { - Debug.recordExecFinish(pid); - return bundle; - } - - /**--------------------------- - đŸ“Ĩ Assign Bundle - -----------------------------*/ - function safeAssign(Bundle storage bundle, string memory name) internal returns(Bundle storage) { - uint pid = recordExecStart("safeAssign"); - bundle.name = name.assertNotEmpty(); - return bundle.recordExecFinish(pid); - } - - function safeAssign(Bundle storage bundle, address facade) internal returns(Bundle storage) { - uint pid = recordExecStart("safeAssign"); - bundle.facade = facade.assertIsContract(); - return bundle.recordExecFinish(pid); - } - - function safeAdd(Bundle storage bundle, Function storage functionInfo) internal returns(Bundle storage) { - uint pid = recordExecStart("safeAdd"); - check(bundle.hasNot(functionInfo), "Already added"); - bundle.functionInfos.push( - functionInfo.assertImplIsContract() - ); - return bundle.recordExecFinish(pid); - } - function safeAdd(Bundle storage bundle, Function[] storage functionInfos) internal returns(Bundle storage) { - uint pid = recordExecStart("safeAdd"); - for (uint i; i < functionInfos.length; ++i) { - bundle.safeAdd(functionInfos[i]); - } - return bundle.recordExecFinish(pid); - } - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function has(Bundle storage bundle, Function storage functionInfo) internal view returns(bool flag) { - for (uint i; i < bundle.functionInfos.length; ++i) { - if (functionInfo.isEqual(bundle.functionInfos[i])) return true; - } - } - function hasNot(Bundle storage bundle, Function storage functionInfo) internal returns(bool) { - return bundle.has(functionInfo).isFalse(); - } - - function isComplete(Bundle storage bundle) internal returns(bool) { - return bundle.name.isNotEmpty() && - bundle.functionInfos.length != 0 && - bundle.facade.isContract(); - } - function assertComplete(Bundle storage bundle) internal returns(Bundle storage) { - check(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); - return bundle; - } - - function hasName(Bundle storage bundle) internal returns(bool) { - return bundle.name.isNotEmpty(); - } - function hasNotName(Bundle storage bundle) internal returns(bool) { - return bundle.name.isEmpty(); - } - - function exists(Bundle storage bundle) internal returns(bool) { - return bundle.name.isNotEmpty() || - bundle.functionInfos.length != 0 || - bundle.facade.isNotContract(); - } - function notExists(Bundle storage bundle) internal returns(bool) { - return bundle.exists().isNot(); - } - function assertExists(Bundle storage bundle) internal returns(Bundle storage) { - check(bundle.exists(), "Bundle Info Not Exists"); - return bundle; - } - function assertNotExists(Bundle storage bundle) internal returns(Bundle storage) { - check(bundle.notExists(), "Bundle Info Already Exists"); - return bundle; - } - - - /**--------------- - 🐞 Debug - -----------------*/ - function parseAndLog(Bundle storage bundle) internal returns(Bundle storage) { - Logger.logDebug( - bundle.parse() - ); - return bundle; - } - function parse(Bundle storage bundle) internal returns(string memory message) { - message = message.append("Facade: ").append(bundle.facade); - - Function[] memory _funcs = bundle.functionInfos; - for (uint i; i < _funcs.length; ++i) { - message = message.br().append(_funcs[i].parse()); - } - console2.log(message); - } - -} +using BundleLib for Bundle global; +using ProcessLib for Bundle global; diff --git a/devkit/method/core/BundleLib.sol b/devkit/method/core/BundleLib.sol new file mode 100644 index 00000000..7f66bf0a --- /dev/null +++ b/devkit/method/core/BundleLib.sol @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Validation +import {check} from "devkit/error/Validation.sol"; +// Utils +import {console2} from "devkit/utils/ForgeHelper.sol"; +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; + using AddressUtils for address; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; + using Bytes4Utils for bytes4; +// Debug +import {Debug} from "devkit/debug/Debug.sol"; +import {Logger} from "devkit/debug/Logger.sol"; +// Core +import {Function} from "devkit/core/Function.sol"; + +import {Bundle} from "devkit/core/Bundle.sol"; + +library BundleLib { + string constant LIB_NAME = "Bundle"; + function recordExecStart(string memory funcName, string memory params) internal returns(uint) { + return Debug.recordExecStart(LIB_NAME, funcName, params); + } + function recordExecStart(string memory funcName) internal returns(uint) { + return recordExecStart(funcName, ""); + } + function recordExecFinish(Bundle storage bundle, uint pid) internal returns(Bundle storage) { + Debug.recordExecFinish(pid); + return bundle; + } + + /**--------------------------- + đŸ“Ĩ Assign Bundle + -----------------------------*/ + function safeAssign(Bundle storage bundle, string memory name) internal returns(Bundle storage) { + uint pid = recordExecStart("safeAssign"); + bundle.name = name.assertNotEmpty(); + return bundle.recordExecFinish(pid); + } + + function safeAssign(Bundle storage bundle, address facade) internal returns(Bundle storage) { + uint pid = recordExecStart("safeAssign"); + bundle.facade = facade.assertIsContract(); + return bundle.recordExecFinish(pid); + } + + function safeAdd(Bundle storage bundle, Function storage functionInfo) internal returns(Bundle storage) { + uint pid = recordExecStart("safeAdd"); + check(bundle.hasNot(functionInfo), "Already added"); + bundle.functionInfos.push( + functionInfo.assertImplIsContract() + ); + return bundle.recordExecFinish(pid); + } + function safeAdd(Bundle storage bundle, Function[] storage functionInfos) internal returns(Bundle storage) { + uint pid = recordExecStart("safeAdd"); + for (uint i; i < functionInfos.length; ++i) { + bundle.safeAdd(functionInfos[i]); + } + return bundle.recordExecFinish(pid); + } + + + /**------------------------------- + 🧐 Inspectors & Assertions + ---------------------------------*/ + function has(Bundle storage bundle, Function storage functionInfo) internal view returns(bool flag) { + for (uint i; i < bundle.functionInfos.length; ++i) { + if (functionInfo.isEqual(bundle.functionInfos[i])) return true; + } + } + function hasNot(Bundle storage bundle, Function storage functionInfo) internal returns(bool) { + return bundle.has(functionInfo).isFalse(); + } + + function isComplete(Bundle storage bundle) internal returns(bool) { + return bundle.name.isNotEmpty() && + bundle.functionInfos.length != 0 && + bundle.facade.isContract(); + } + function assertComplete(Bundle storage bundle) internal returns(Bundle storage) { + check(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); + return bundle; + } + + function hasName(Bundle storage bundle) internal returns(bool) { + return bundle.name.isNotEmpty(); + } + function hasNotName(Bundle storage bundle) internal returns(bool) { + return bundle.name.isEmpty(); + } + + function exists(Bundle storage bundle) internal returns(bool) { + return bundle.name.isNotEmpty() || + bundle.functionInfos.length != 0 || + bundle.facade.isNotContract(); + } + function notExists(Bundle storage bundle) internal returns(bool) { + return bundle.exists().isNot(); + } + function assertExists(Bundle storage bundle) internal returns(Bundle storage) { + check(bundle.exists(), "Bundle Info Not Exists"); + return bundle; + } + function assertNotExists(Bundle storage bundle) internal returns(Bundle storage) { + check(bundle.notExists(), "Bundle Info Already Exists"); + return bundle; + } + + + /**--------------- + 🐞 Debug + -----------------*/ + function parseAndLog(Bundle storage bundle) internal returns(Bundle storage) { + Logger.logDebug( + bundle.parse() + ); + return bundle; + } + function parse(Bundle storage bundle) internal returns(string memory message) { + message = message.append("Facade: ").append(bundle.facade); + + Function[] memory _funcs = bundle.functionInfos; + for (uint i; i < _funcs.length; ++i) { + message = message.br().append(_funcs[i].parse()); + } + console2.log(message); + } + +} From 69e41b6311664a81d02fe94b6b8e9af20bf2dc34 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 15:38:38 +0900 Subject: [PATCH 030/111] Separate process methods from BundleLib --- devkit/core/BundleRegistry.sol | 4 ++-- devkit/method/core/BundleLib.sol | 27 ++++++++------------------- devkit/method/debug/ProcessLib.sol | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/BundleRegistry.sol index 72585bf6..e8a38969 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/BundleRegistry.sol @@ -121,11 +121,11 @@ library BundleRegistryLib { ---------------------------------*/ function findBundle(BundleRegistry storage bundle, string memory name) internal returns(Bundle storage) { uint pid = bundle.recordExecStart("findBundle"); - return bundle.bundles[name.safeCalcHash()].recordExecFinish(pid); + return bundle.bundles[name.safeCalcHash()].finishProcess(pid); } function findCurrentBundle(BundleRegistry storage bundle) internal returns(Bundle storage) { uint pid = bundle.recordExecStart("findCurrentBundle"); - return bundle.findBundle(bundle.findCurrentBundleName()).recordExecFinish(pid); + return bundle.findBundle(bundle.findCurrentBundleName()).finishProcess(pid); } function findCurrentBundleName(BundleRegistry storage bundle) internal returns(string memory) { uint pid = bundle.recordExecStart("findCurrentBundleName"); diff --git a/devkit/method/core/BundleLib.sol b/devkit/method/core/BundleLib.sol index 7f66bf0a..e1257f2b 100644 --- a/devkit/method/core/BundleLib.sol +++ b/devkit/method/core/BundleLib.sol @@ -22,47 +22,36 @@ import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; library BundleLib { - string constant LIB_NAME = "Bundle"; - function recordExecStart(string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(string memory funcName) internal returns(uint) { - return recordExecStart(funcName, ""); - } - function recordExecFinish(Bundle storage bundle, uint pid) internal returns(Bundle storage) { - Debug.recordExecFinish(pid); - return bundle; - } /**--------------------------- đŸ“Ĩ Assign Bundle -----------------------------*/ function safeAssign(Bundle storage bundle, string memory name) internal returns(Bundle storage) { - uint pid = recordExecStart("safeAssign"); + uint pid = bundle.startProcess("safeAssign"); bundle.name = name.assertNotEmpty(); - return bundle.recordExecFinish(pid); + return bundle.finishProcess(pid); } function safeAssign(Bundle storage bundle, address facade) internal returns(Bundle storage) { - uint pid = recordExecStart("safeAssign"); + uint pid = bundle.startProcess("safeAssign"); bundle.facade = facade.assertIsContract(); - return bundle.recordExecFinish(pid); + return bundle.finishProcess(pid); } function safeAdd(Bundle storage bundle, Function storage functionInfo) internal returns(Bundle storage) { - uint pid = recordExecStart("safeAdd"); + uint pid = bundle.startProcess("safeAdd"); check(bundle.hasNot(functionInfo), "Already added"); bundle.functionInfos.push( functionInfo.assertImplIsContract() ); - return bundle.recordExecFinish(pid); + return bundle.finishProcess(pid); } function safeAdd(Bundle storage bundle, Function[] storage functionInfos) internal returns(Bundle storage) { - uint pid = recordExecStart("safeAdd"); + uint pid = bundle.startProcess("safeAdd"); for (uint i; i < functionInfos.length; ++i) { bundle.safeAdd(functionInfos[i]); } - return bundle.recordExecFinish(pid); + return bundle.finishProcess(pid); } diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol index 257d7682..ea91ba65 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; import {Debug} from "devkit/debug/Debug.sol"; // Types import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; @@ -24,6 +25,22 @@ library ProcessLib { } + /**---------------- + đŸ§ē Bundle + ------------------*/ + function startProcess(Bundle storage, string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("Bundle", name, params); + } + function startProcess(Bundle storage bundle, string memory name) internal returns(uint) { + return bundle.startProcess(name, ""); + } + + function finishProcess(Bundle storage bundle, uint pid) internal returns(Bundle storage) { + Debug.recordExecFinish(pid); + return bundle; + } + + /**-------------------------- 🏛 Standard Functions ----------------------------*/ From b88261d10fae4bc399e71c2688c17faa0751f5f8 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 15:45:02 +0900 Subject: [PATCH 031/111] Separate DictionaryRegistryLib from DictionaryRegistry file --- devkit/core/DictionaryRegistry.sol | 172 +------------------ devkit/method/core/DictionaryRegistryLib.sol | 168 ++++++++++++++++++ 2 files changed, 177 insertions(+), 163 deletions(-) create mode 100644 devkit/method/core/DictionaryRegistryLib.sol diff --git a/devkit/core/DictionaryRegistry.sol b/devkit/core/DictionaryRegistry.sol index 15c13a24..87477065 100644 --- a/devkit/core/DictionaryRegistry.sol +++ b/devkit/core/DictionaryRegistry.sol @@ -1,174 +1,20 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Error & Debug -import {ERR, throwError} from "devkit/error/Error.sol"; -import {check} from "devkit/error/Validation.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Config -import {Config, ScanRange} from "devkit/config/Config.sol"; -// Utils -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -// Core +// Core Types import {Dictionary} from "./Dictionary.sol"; +// Methods +import {DictionaryRegistryLib} from "devkit/method/core/DictionaryRegistryLib.sol"; +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/**------------------------------- - 📚 UCS Dictionary Registry ----------------------------------*/ -using DictionaryRegistryLib for DictionaryRegistry global; +/****************************** + 📚 Dictionary Registry +*******************************/ struct DictionaryRegistry { mapping(bytes32 nameHash => Dictionary) deployed; mapping(bytes32 nameHash => Dictionary) mocks; Dictionary currentDictionary; } - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> - đŸ“Ĩ Add Dictionary - đŸ”ŧ Update Current Context Dictionary - â™ģī¸ Reset Current Context Dictionary - 🔍 Find Dictionary - 🏷 Generate Unique Name - << Helper >> - 🧐 Inspectors & Assertions - 🐞 Debug -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library DictionaryRegistryLib { - string constant LIB_NAME = "DictionaryRegistryLib"; - - - /**------------------------ - đŸ“Ĩ Add Dictionary - --------------------------*/ - function add(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.recordExecStart("add"); - bytes32 nameHash = name.calcHash(); - if (dictionary.isNotMock()) { - dictionaries.deployed[nameHash] = dictionary; - } - if (dictionary.isMock()) { - dictionaries.mocks[nameHash] = dictionary; - } - return dictionaries.recordExecFinish(pid); - } - - function safeAdd(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.recordExecStart("safeAdd"); - return dictionaries .add(name.assertNotEmpty(), dictionary.assertNotEmpty()) - .recordExecFinish(pid); - } - - - /**----------------------------------------- - đŸ”ŧ Update Current Context Dictionary - -------------------------------------------*/ - function safeUpdate(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.recordExecStart("safeUpdate"); - return dictionaries .update(dictionary.assertNotEmpty()).recordExecFinish(pid); - } - function update(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.recordExecStart("update"); - dictionaries.currentDictionary = dictionary; - return dictionaries.recordExecFinish(pid); - } - - - /**---------------------------------------- - â™ģī¸ Reset Current Context Dictionary - ------------------------------------------*/ - function reset(DictionaryRegistry storage dictionaries) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.recordExecStart("reset"); - delete dictionaries.currentDictionary; - return dictionaries.recordExecFinish(pid); - } - - - /**------------------------ - 🔍 Find Dictionary - --------------------------*/ - function find(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { - uint pid = dictionaries.recordExecStart("find"); - return dictionaries.deployed[name.safeCalcHash()] - .assertExists() - .recordExecFinishInStorage(pid); - } - function findCurrentDictionary(DictionaryRegistry storage dictionaries) internal returns(Dictionary storage) { - uint pid = dictionaries.recordExecStart("findCurrentDictionary"); - return dictionaries.currentDictionary.assertExists().recordExecFinishInStorage(pid); - } - function findMockDictionary(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { - uint pid = dictionaries.recordExecStart("findMockDictionary"); - return dictionaries.mocks[name.safeCalcHash()].assertExists().recordExecFinishInStorage(pid); - } - - - /**----------------------------- - 🏷 Generate Unique Name - -------------------------------*/ - function genUniqueName(DictionaryRegistry storage dictionaries, string memory baseName) internal returns(string memory name) { - uint pid = dictionaries.recordExecStart("genUniqueName"); - ScanRange memory range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = baseName.toSequential(i); - if (dictionaries.existsInDeployed(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } - function genUniqueName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { - return dictionaries.genUniqueName(Config().DEFAULT_DICTIONARY_NAME); - } - function genUniqueDuplicatedName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { - return dictionaries.genUniqueName(Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); - } - - function genUniqueMockName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { - uint pid = dictionaries.recordExecStart("genUniqueName"); - ScanRange memory range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = Config().DEFAULT_DICTIONARY_MOCK_NAME.toSequential(i); - if (dictionaries.existsInMocks(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } - - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function existsInDeployed(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { - return dictionaries.deployed[name.safeCalcHash()].exists(); - } - function existsInMocks(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { - return dictionaries.mocks[name.safeCalcHash()].exists(); - } - - - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Start - */ - function recordExecStart(DictionaryRegistry storage, string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(DictionaryRegistry storage dictionaries, string memory funcName) internal returns(uint) { - return dictionaries.recordExecStart(funcName, ""); - } - - /** - Record Finish - */ - function recordExecFinish(DictionaryRegistry storage dictionaries, uint pid) internal returns(DictionaryRegistry storage) { - Debug.recordExecFinish(pid); - return dictionaries; - } - -} +using DictionaryRegistryLib for DictionaryRegistry global; +using ProcessLib for DictionaryRegistry global; diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol new file mode 100644 index 00000000..3e72b6f1 --- /dev/null +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Error & Debug +import {ERR, throwError} from "devkit/error/Error.sol"; +import {check} from "devkit/error/Validation.sol"; +import {Debug} from "devkit/debug/Debug.sol"; +// Config +import {Config, ScanRange} from "devkit/config/Config.sol"; +// Utils +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; + using AddressUtils for address; +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +// Core +import {Dictionary} from "devkit/core/Dictionary.sol"; + +import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; + +/****************************** + 📚 Dictionary Registry +*******************************/ +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + << Primary >> + đŸ“Ĩ Add Dictionary + đŸ”ŧ Update Current Context Dictionary + â™ģī¸ Reset Current Context Dictionary + 🔍 Find Dictionary + 🏷 Generate Unique Name + << Helper >> + 🧐 Inspectors & Assertions + 🐞 Debug +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library DictionaryRegistryLib { + string constant LIB_NAME = "DictionaryRegistryLib"; + + + /**------------------------ + đŸ“Ĩ Add Dictionary + --------------------------*/ + function add(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { + uint pid = dictionaries.recordExecStart("add"); + bytes32 nameHash = name.calcHash(); + if (dictionary.isNotMock()) { + dictionaries.deployed[nameHash] = dictionary; + } + if (dictionary.isMock()) { + dictionaries.mocks[nameHash] = dictionary; + } + return dictionaries.recordExecFinish(pid); + } + + function safeAdd(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { + uint pid = dictionaries.recordExecStart("safeAdd"); + return dictionaries .add(name.assertNotEmpty(), dictionary.assertNotEmpty()) + .recordExecFinish(pid); + } + + + /**----------------------------------------- + đŸ”ŧ Update Current Context Dictionary + -------------------------------------------*/ + function safeUpdate(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { + uint pid = dictionaries.recordExecStart("safeUpdate"); + return dictionaries .update(dictionary.assertNotEmpty()).recordExecFinish(pid); + } + function update(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { + uint pid = dictionaries.recordExecStart("update"); + dictionaries.currentDictionary = dictionary; + return dictionaries.recordExecFinish(pid); + } + + + /**---------------------------------------- + â™ģī¸ Reset Current Context Dictionary + ------------------------------------------*/ + function reset(DictionaryRegistry storage dictionaries) internal returns(DictionaryRegistry storage) { + uint pid = dictionaries.recordExecStart("reset"); + delete dictionaries.currentDictionary; + return dictionaries.recordExecFinish(pid); + } + + + /**------------------------ + 🔍 Find Dictionary + --------------------------*/ + function find(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { + uint pid = dictionaries.recordExecStart("find"); + return dictionaries.deployed[name.safeCalcHash()] + .assertExists() + .recordExecFinishInStorage(pid); + } + function findCurrentDictionary(DictionaryRegistry storage dictionaries) internal returns(Dictionary storage) { + uint pid = dictionaries.recordExecStart("findCurrentDictionary"); + return dictionaries.currentDictionary.assertExists().recordExecFinishInStorage(pid); + } + function findMockDictionary(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { + uint pid = dictionaries.recordExecStart("findMockDictionary"); + return dictionaries.mocks[name.safeCalcHash()].assertExists().recordExecFinishInStorage(pid); + } + + + /**----------------------------- + 🏷 Generate Unique Name + -------------------------------*/ + function genUniqueName(DictionaryRegistry storage dictionaries, string memory baseName) internal returns(string memory name) { + uint pid = dictionaries.recordExecStart("genUniqueName"); + ScanRange memory range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = baseName.toSequential(i); + if (dictionaries.existsInDeployed(name).isFalse()) return name.recordExecFinish(pid); + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + function genUniqueName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { + return dictionaries.genUniqueName(Config().DEFAULT_DICTIONARY_NAME); + } + function genUniqueDuplicatedName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { + return dictionaries.genUniqueName(Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); + } + + function genUniqueMockName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { + uint pid = dictionaries.recordExecStart("genUniqueName"); + ScanRange memory range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = Config().DEFAULT_DICTIONARY_MOCK_NAME.toSequential(i); + if (dictionaries.existsInMocks(name).isFalse()) return name.recordExecFinish(pid); + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + + + + /**------------------------------- + 🧐 Inspectors & Assertions + ---------------------------------*/ + function existsInDeployed(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { + return dictionaries.deployed[name.safeCalcHash()].exists(); + } + function existsInMocks(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { + return dictionaries.mocks[name.safeCalcHash()].exists(); + } + + + /**---------------- + 🐞 Debug + ------------------*/ + /** + Record Start + */ + function recordExecStart(DictionaryRegistry storage, string memory funcName, string memory params) internal returns(uint) { + return Debug.recordExecStart(LIB_NAME, funcName, params); + } + function recordExecStart(DictionaryRegistry storage dictionaries, string memory funcName) internal returns(uint) { + return dictionaries.recordExecStart(funcName, ""); + } + + /** + Record Finish + */ + function recordExecFinish(DictionaryRegistry storage dictionaries, uint pid) internal returns(DictionaryRegistry storage) { + Debug.recordExecFinish(pid); + return dictionaries; + } + +} From 4bd35c8a8650d533f0917f0b215912da2760f985 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 16:04:20 +0900 Subject: [PATCH 032/111] Separate process methods from DictionaryRegistryLib --- devkit/method/core/DictionaryRegistryLib.sol | 53 ++++++-------------- devkit/method/debug/ProcessLib.sol | 18 +++++++ 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol index 3e72b6f1..459a3dea 100644 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -34,14 +34,13 @@ import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; 🐞 Debug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library DictionaryRegistryLib { - string constant LIB_NAME = "DictionaryRegistryLib"; /**------------------------ đŸ“Ĩ Add Dictionary --------------------------*/ function add(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.recordExecStart("add"); + uint pid = dictionaries.startProcess("add"); bytes32 nameHash = name.calcHash(); if (dictionary.isNotMock()) { dictionaries.deployed[nameHash] = dictionary; @@ -49,13 +48,13 @@ library DictionaryRegistryLib { if (dictionary.isMock()) { dictionaries.mocks[nameHash] = dictionary; } - return dictionaries.recordExecFinish(pid); + return dictionaries.finishProcess(pid); } function safeAdd(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.recordExecStart("safeAdd"); + uint pid = dictionaries.startProcess("safeAdd"); return dictionaries .add(name.assertNotEmpty(), dictionary.assertNotEmpty()) - .recordExecFinish(pid); + .finishProcess(pid); } @@ -63,13 +62,13 @@ library DictionaryRegistryLib { đŸ”ŧ Update Current Context Dictionary -------------------------------------------*/ function safeUpdate(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.recordExecStart("safeUpdate"); - return dictionaries .update(dictionary.assertNotEmpty()).recordExecFinish(pid); + uint pid = dictionaries.startProcess("safeUpdate"); + return dictionaries .update(dictionary.assertNotEmpty()).finishProcess(pid); } function update(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.recordExecStart("update"); + uint pid = dictionaries.startProcess("update"); dictionaries.currentDictionary = dictionary; - return dictionaries.recordExecFinish(pid); + return dictionaries.finishProcess(pid); } @@ -77,9 +76,9 @@ library DictionaryRegistryLib { â™ģī¸ Reset Current Context Dictionary ------------------------------------------*/ function reset(DictionaryRegistry storage dictionaries) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.recordExecStart("reset"); + uint pid = dictionaries.startProcess("reset"); delete dictionaries.currentDictionary; - return dictionaries.recordExecFinish(pid); + return dictionaries.finishProcess(pid); } @@ -87,17 +86,17 @@ library DictionaryRegistryLib { 🔍 Find Dictionary --------------------------*/ function find(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { - uint pid = dictionaries.recordExecStart("find"); + uint pid = dictionaries.startProcess("find"); return dictionaries.deployed[name.safeCalcHash()] .assertExists() .recordExecFinishInStorage(pid); } function findCurrentDictionary(DictionaryRegistry storage dictionaries) internal returns(Dictionary storage) { - uint pid = dictionaries.recordExecStart("findCurrentDictionary"); + uint pid = dictionaries.startProcess("findCurrentDictionary"); return dictionaries.currentDictionary.assertExists().recordExecFinishInStorage(pid); } function findMockDictionary(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { - uint pid = dictionaries.recordExecStart("findMockDictionary"); + uint pid = dictionaries.startProcess("findMockDictionary"); return dictionaries.mocks[name.safeCalcHash()].assertExists().recordExecFinishInStorage(pid); } @@ -106,7 +105,7 @@ library DictionaryRegistryLib { 🏷 Generate Unique Name -------------------------------*/ function genUniqueName(DictionaryRegistry storage dictionaries, string memory baseName) internal returns(string memory name) { - uint pid = dictionaries.recordExecStart("genUniqueName"); + uint pid = dictionaries.startProcess("genUniqueName"); ScanRange memory range = Config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = baseName.toSequential(i); @@ -122,7 +121,7 @@ library DictionaryRegistryLib { } function genUniqueMockName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { - uint pid = dictionaries.recordExecStart("genUniqueName"); + uint pid = dictionaries.startProcess("genUniqueName"); ScanRange memory range = Config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = Config().DEFAULT_DICTIONARY_MOCK_NAME.toSequential(i); @@ -143,26 +142,4 @@ library DictionaryRegistryLib { return dictionaries.mocks[name.safeCalcHash()].exists(); } - - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Start - */ - function recordExecStart(DictionaryRegistry storage, string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(DictionaryRegistry storage dictionaries, string memory funcName) internal returns(uint) { - return dictionaries.recordExecStart(funcName, ""); - } - - /** - Record Finish - */ - function recordExecFinish(DictionaryRegistry storage dictionaries, uint pid) internal returns(DictionaryRegistry storage) { - Debug.recordExecFinish(pid); - return dictionaries; - } - } diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol index ea91ba65..d4a6cb7c 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -7,6 +7,7 @@ import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; +import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; library ProcessLib { /**------------------ @@ -71,4 +72,21 @@ library ProcessLib { Debug.recordExecFinish(pid); return proxies; } + + + /**---------------------------- + 📚 Dictionary Registry + ------------------------------*/ + function startProcess(DictionaryRegistry storage, string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("DictionaryRegistryLib", name, params); + } + function startProcess(DictionaryRegistry storage dictionaries, string memory name) internal returns(uint) { + return dictionaries.startProcess(name, ""); + } + + function finishProcess(DictionaryRegistry storage dictionaries, uint pid) internal returns(DictionaryRegistry storage) { + Debug.recordExecFinish(pid); + return dictionaries; + } + } From 2d8714779376bd2955ffe1af7f045db57f08d8a0 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 16:15:35 +0900 Subject: [PATCH 033/111] Separate BundleRegistryLib from BundleRegistry file --- devkit/core/BundleRegistry.sol | 195 ++--------------------- devkit/core/DictionaryRegistry.sol | 2 +- devkit/method/core/BundleRegistryLib.sol | 187 ++++++++++++++++++++++ devkit/method/debug/ProcessLib.sol | 2 +- 4 files changed, 199 insertions(+), 187 deletions(-) create mode 100644 devkit/method/core/BundleRegistryLib.sol diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/BundleRegistry.sol index e8a38969..0f5a527f 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/BundleRegistry.sol @@ -1,194 +1,19 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Error & Debug -import {check} from "devkit/error/Validation.sol"; -import {ERR, throwError} from "devkit/error/Error.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Config -import {ScanRange, Config} from "devkit/config/Config.sol"; -// Utils -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -// Core -import {Function} from "./Function.sol"; -import {Bundle} from "./Bundle.sol"; -import {StdFunctions} from "./StdFunctions.sol"; +// Core Type +import {Bundle} from "devkit/core/Bundle.sol"; +//Methods +import {BundleRegistryLib} from "devkit/method/core/BundleRegistryLib.sol"; +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/**------------------------------- - 🧩 UCS Functions Registry ----------------------------------*/ -using BundleRegistryLib for BundleRegistry global; +/************************** + đŸ—‚ī¸ Bundle Registry +***************************/ struct BundleRegistry { - StdFunctions std; - mapping(bytes32 nameHash => Function) customs; mapping(bytes32 nameHash => Bundle) bundles; - string currentFunctionName; string currentBundleName; } - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> - 🌱 Init Bundle - ✨ Add Custom Function - 🔏 Load and Assign Custom Function from Env - đŸ§ē Add Custom Function to Bundle - đŸĒŸ Set Facade - đŸ”ŧ Update Current Context Function & Bundle - 🔍 Find Function & Bundle - 🏷 Generate Unique Name - << Helper >> - 🔍 Find Custom Function -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library BundleRegistryLib { - string constant LIB_NAME = "BundleRegistry"; - - - /**--------------------- - 🌱 Init Bundle - -----------------------*/ - function init(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("init"); - bundle.bundles[name.safeCalcHash()].safeAssign(name); - bundle.safeUpdateCurrentBundle(name); - return bundle.recordExecFinish(pid); - } - function safeInit(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("safeInit"); - check(name.isNotEmpty(), "Empty Name"); - return bundle.assertBundleNotExists(name) - .init(name) - .recordExecFinish(pid); - } - - - /**------------------------------------- - đŸ§ē Add Custom Function to Bundle - ---------------------------------------*/ - function addToBundle(BundleRegistry storage bundle, Function storage functionInfo) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("addToBundle", "function"); - bundle.findCurrentBundle().safeAdd(functionInfo); - return bundle.recordExecFinish(pid); - } - function addToBundle(BundleRegistry storage bundle, Function[] storage functionInfos) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("addToBundle", "bundle"); // TODO params - bundle.findCurrentBundle().safeAdd(functionInfos); - return bundle.recordExecFinish(pid); - } - - - /**------------------ - đŸĒŸ Set Facade - --------------------*/ - function set(BundleRegistry storage bundle, string memory name, address facade) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("set"); - bundle.bundles[name.safeCalcHash()] - .assertExists() - .safeAssign(facade); - return bundle.recordExecFinish(pid); - } - function set(BundleRegistry storage bundle, address facade) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("set"); - return bundle.set(bundle.findCurrentBundleName(), facade).recordExecFinish(pid); - } - - - /**------------------------------------------------ - đŸ”ŧ Update Current Context - --------------------------------------------------*/ - function safeUpdateCurrentBundle(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("safeUpdateCurrentBundle"); - bundle.currentBundleName = name.assertNotEmpty(); - return bundle.recordExecFinish(pid); - } - - - /**----------------------------------------------- - â™ģī¸ Reset Current Context Function & Bundle - -------------------------------------------------*/ - function reset(BundleRegistry storage bundle) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("reset"); - delete bundle.currentBundleName; - return bundle.recordExecFinish(pid); - } - - - /**------------------------------- - 🔍 Find Function & Bundle - ---------------------------------*/ - function findBundle(BundleRegistry storage bundle, string memory name) internal returns(Bundle storage) { - uint pid = bundle.recordExecStart("findBundle"); - return bundle.bundles[name.safeCalcHash()].finishProcess(pid); - } - function findCurrentBundle(BundleRegistry storage bundle) internal returns(Bundle storage) { - uint pid = bundle.recordExecStart("findCurrentBundle"); - return bundle.findBundle(bundle.findCurrentBundleName()).finishProcess(pid); - } - function findCurrentBundleName(BundleRegistry storage bundle) internal returns(string memory) { - uint pid = bundle.recordExecStart("findCurrentBundleName"); - return bundle.currentBundleName.assertNotEmpty().recordExecFinish(pid); - } - - - /**----------------------------- - 🏷 Generate Unique Name - -------------------------------*/ - function genUniqueBundleName(BundleRegistry storage bundle) internal returns(string memory name) { - uint pid = bundle.recordExecStart("genUniqueBundleName"); - ScanRange storage range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = Config().DEFAULT_BUNDLE_NAME.toSequential(i); - if (bundle.existsBundle(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } - - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function existsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { - return bundle.bundles[name.safeCalcHash()].hasName(); - } - function notExistsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { - return bundle.existsBundle(name).isNot(); - } - function assertBundleNotExists(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - check(bundle.notExistsBundle(name), "Bundle Already Exists"); - return bundle; - } - - function existsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { - return bundle.currentBundleName.isNotEmpty(); - } - function notExistsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { - return bundle.existsCurrentBundle().isNot(); - } - - - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Start - */ - function recordExecStart(BundleRegistry storage, string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(BundleRegistry storage bundle, string memory funcName) internal returns(uint) { - return bundle.recordExecStart(funcName, ""); - } - - /** - Record Finish - */ - function recordExecFinish(BundleRegistry storage bundle, uint pid) internal returns(BundleRegistry storage) { - Debug.recordExecFinish(pid); - return bundle; - } - -} +using BundleRegistryLib for BundleRegistry global; +using ProcessLib for BundleRegistry global; diff --git a/devkit/core/DictionaryRegistry.sol b/devkit/core/DictionaryRegistry.sol index 87477065..08502074 100644 --- a/devkit/core/DictionaryRegistry.sol +++ b/devkit/core/DictionaryRegistry.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Core Types +// Core Type import {Dictionary} from "./Dictionary.sol"; // Methods import {DictionaryRegistryLib} from "devkit/method/core/DictionaryRegistryLib.sol"; diff --git a/devkit/method/core/BundleRegistryLib.sol b/devkit/method/core/BundleRegistryLib.sol new file mode 100644 index 00000000..46b8a527 --- /dev/null +++ b/devkit/method/core/BundleRegistryLib.sol @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Error & Debug +import {check} from "devkit/error/Validation.sol"; +import {ERR, throwError} from "devkit/error/Error.sol"; +import {Debug} from "devkit/debug/Debug.sol"; +// Config +import {ScanRange, Config} from "devkit/config/Config.sol"; +// Utils +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +// Core +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {StdFunctions} from "devkit/core/StdFunctions.sol"; + +import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; + +/**------------------------------- + 🧩 UCS Functions Registry +---------------------------------*/ + +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + << Primary >> + 🌱 Init Bundle + ✨ Add Custom Function + 🔏 Load and Assign Custom Function from Env + đŸ§ē Add Custom Function to Bundle + đŸĒŸ Set Facade + đŸ”ŧ Update Current Context Function & Bundle + 🔍 Find Function & Bundle + 🏷 Generate Unique Name + << Helper >> + 🔍 Find Custom Function +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library BundleRegistryLib { + string constant LIB_NAME = "BundleRegistry"; + + + /**--------------------- + 🌱 Init Bundle + -----------------------*/ + function init(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("init"); + bundle.bundles[name.safeCalcHash()].safeAssign(name); + bundle.safeUpdateCurrentBundle(name); + return bundle.recordExecFinish(pid); + } + function safeInit(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("safeInit"); + check(name.isNotEmpty(), "Empty Name"); + return bundle.assertBundleNotExists(name) + .init(name) + .recordExecFinish(pid); + } + + + /**------------------------------------- + đŸ§ē Add Custom Function to Bundle + ---------------------------------------*/ + function addToBundle(BundleRegistry storage bundle, Function storage functionInfo) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("addToBundle", "function"); + bundle.findCurrentBundle().safeAdd(functionInfo); + return bundle.recordExecFinish(pid); + } + function addToBundle(BundleRegistry storage bundle, Function[] storage functionInfos) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("addToBundle", "bundle"); // TODO params + bundle.findCurrentBundle().safeAdd(functionInfos); + return bundle.recordExecFinish(pid); + } + + + /**------------------ + đŸĒŸ Set Facade + --------------------*/ + function set(BundleRegistry storage bundle, string memory name, address facade) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("set"); + bundle.bundles[name.safeCalcHash()] + .assertExists() + .safeAssign(facade); + return bundle.recordExecFinish(pid); + } + function set(BundleRegistry storage bundle, address facade) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("set"); + return bundle.set(bundle.findCurrentBundleName(), facade).recordExecFinish(pid); + } + + + /**------------------------------------------------ + đŸ”ŧ Update Current Context + --------------------------------------------------*/ + function safeUpdateCurrentBundle(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("safeUpdateCurrentBundle"); + bundle.currentBundleName = name.assertNotEmpty(); + return bundle.recordExecFinish(pid); + } + + + /**----------------------------------------------- + â™ģī¸ Reset Current Context Function & Bundle + -------------------------------------------------*/ + function reset(BundleRegistry storage bundle) internal returns(BundleRegistry storage) { + uint pid = bundle.recordExecStart("reset"); + delete bundle.currentBundleName; + return bundle.recordExecFinish(pid); + } + + + /**------------------------------- + 🔍 Find Function & Bundle + ---------------------------------*/ + function findBundle(BundleRegistry storage bundle, string memory name) internal returns(Bundle storage) { + uint pid = bundle.recordExecStart("findBundle"); + return bundle.bundles[name.safeCalcHash()].finishProcess(pid); + } + function findCurrentBundle(BundleRegistry storage bundle) internal returns(Bundle storage) { + uint pid = bundle.recordExecStart("findCurrentBundle"); + return bundle.findBundle(bundle.findCurrentBundleName()).finishProcess(pid); + } + function findCurrentBundleName(BundleRegistry storage bundle) internal returns(string memory) { + uint pid = bundle.recordExecStart("findCurrentBundleName"); + return bundle.currentBundleName.assertNotEmpty().recordExecFinish(pid); + } + + + /**----------------------------- + 🏷 Generate Unique Name + -------------------------------*/ + function genUniqueBundleName(BundleRegistry storage bundle) internal returns(string memory name) { + uint pid = bundle.recordExecStart("genUniqueBundleName"); + ScanRange storage range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = Config().DEFAULT_BUNDLE_NAME.toSequential(i); + if (bundle.existsBundle(name).isFalse()) return name.recordExecFinish(pid); + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + + + + /**------------------------------- + 🧐 Inspectors & Assertions + ---------------------------------*/ + function existsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { + return bundle.bundles[name.safeCalcHash()].hasName(); + } + function notExistsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { + return bundle.existsBundle(name).isNot(); + } + function assertBundleNotExists(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + check(bundle.notExistsBundle(name), "Bundle Already Exists"); + return bundle; + } + + function existsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { + return bundle.currentBundleName.isNotEmpty(); + } + function notExistsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { + return bundle.existsCurrentBundle().isNot(); + } + + + /**---------------- + 🐞 Debug + ------------------*/ + /** + Record Start + */ + function recordExecStart(BundleRegistry storage, string memory funcName, string memory params) internal returns(uint) { + return Debug.recordExecStart(LIB_NAME, funcName, params); + } + function recordExecStart(BundleRegistry storage bundle, string memory funcName) internal returns(uint) { + return bundle.recordExecStart(funcName, ""); + } + + /** + Record Finish + */ + function recordExecFinish(BundleRegistry storage bundle, uint pid) internal returns(BundleRegistry storage) { + Debug.recordExecFinish(pid); + return bundle; + } + +} diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol index d4a6cb7c..92f2d8b9 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {Debug} from "devkit/debug/Debug.sol"; -// Types +// Core Types import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; From b2576fdfe561a1a251a848c52af04e02bd1682f7 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 16:25:53 +0900 Subject: [PATCH 034/111] Separate process methods from BundleRegistryLib --- devkit/method/core/BundleRegistryLib.sol | 66 ++++++++---------------- devkit/method/debug/ProcessLib.sol | 22 +++++++- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/devkit/method/core/BundleRegistryLib.sol b/devkit/method/core/BundleRegistryLib.sol index 46b8a527..5b31ef96 100644 --- a/devkit/method/core/BundleRegistryLib.sol +++ b/devkit/method/core/BundleRegistryLib.sol @@ -20,7 +20,7 @@ import {StdFunctions} from "devkit/core/StdFunctions.sol"; import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; /**------------------------------- - 🧩 UCS Functions Registry + 🧩 Functions Registry ---------------------------------*/ /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -37,24 +37,23 @@ import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; 🔍 Find Custom Function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library BundleRegistryLib { - string constant LIB_NAME = "BundleRegistry"; /**--------------------- 🌱 Init Bundle -----------------------*/ function init(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("init"); + uint pid = bundle.startProcess("init"); bundle.bundles[name.safeCalcHash()].safeAssign(name); bundle.safeUpdateCurrentBundle(name); - return bundle.recordExecFinish(pid); + return bundle.finishProcess(pid); } function safeInit(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("safeInit"); + uint pid = bundle.startProcess("safeInit"); check(name.isNotEmpty(), "Empty Name"); return bundle.assertBundleNotExists(name) .init(name) - .recordExecFinish(pid); + .finishProcess(pid); } @@ -62,14 +61,14 @@ library BundleRegistryLib { đŸ§ē Add Custom Function to Bundle ---------------------------------------*/ function addToBundle(BundleRegistry storage bundle, Function storage functionInfo) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("addToBundle", "function"); + uint pid = bundle.startProcess("addToBundle", "function"); bundle.findCurrentBundle().safeAdd(functionInfo); - return bundle.recordExecFinish(pid); + return bundle.finishProcess(pid); } function addToBundle(BundleRegistry storage bundle, Function[] storage functionInfos) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("addToBundle", "bundle"); // TODO params + uint pid = bundle.startProcess("addToBundle", "bundle"); // TODO params bundle.findCurrentBundle().safeAdd(functionInfos); - return bundle.recordExecFinish(pid); + return bundle.finishProcess(pid); } @@ -77,15 +76,15 @@ library BundleRegistryLib { đŸĒŸ Set Facade --------------------*/ function set(BundleRegistry storage bundle, string memory name, address facade) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("set"); + uint pid = bundle.startProcess("set"); bundle.bundles[name.safeCalcHash()] .assertExists() .safeAssign(facade); - return bundle.recordExecFinish(pid); + return bundle.finishProcess(pid); } function set(BundleRegistry storage bundle, address facade) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("set"); - return bundle.set(bundle.findCurrentBundleName(), facade).recordExecFinish(pid); + uint pid = bundle.startProcess("set"); + return bundle.set(bundle.findCurrentBundleName(), facade).finishProcess(pid); } @@ -93,9 +92,9 @@ library BundleRegistryLib { đŸ”ŧ Update Current Context --------------------------------------------------*/ function safeUpdateCurrentBundle(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("safeUpdateCurrentBundle"); + uint pid = bundle.startProcess("safeUpdateCurrentBundle"); bundle.currentBundleName = name.assertNotEmpty(); - return bundle.recordExecFinish(pid); + return bundle.finishProcess(pid); } @@ -103,9 +102,9 @@ library BundleRegistryLib { â™ģī¸ Reset Current Context Function & Bundle -------------------------------------------------*/ function reset(BundleRegistry storage bundle) internal returns(BundleRegistry storage) { - uint pid = bundle.recordExecStart("reset"); + uint pid = bundle.startProcess("reset"); delete bundle.currentBundleName; - return bundle.recordExecFinish(pid); + return bundle.finishProcess(pid); } @@ -113,15 +112,15 @@ library BundleRegistryLib { 🔍 Find Function & Bundle ---------------------------------*/ function findBundle(BundleRegistry storage bundle, string memory name) internal returns(Bundle storage) { - uint pid = bundle.recordExecStart("findBundle"); + uint pid = bundle.startProcess("findBundle"); return bundle.bundles[name.safeCalcHash()].finishProcess(pid); } function findCurrentBundle(BundleRegistry storage bundle) internal returns(Bundle storage) { - uint pid = bundle.recordExecStart("findCurrentBundle"); + uint pid = bundle.startProcess("findCurrentBundle"); return bundle.findBundle(bundle.findCurrentBundleName()).finishProcess(pid); } function findCurrentBundleName(BundleRegistry storage bundle) internal returns(string memory) { - uint pid = bundle.recordExecStart("findCurrentBundleName"); + uint pid = bundle.startProcess("findCurrentBundleName"); return bundle.currentBundleName.assertNotEmpty().recordExecFinish(pid); } @@ -130,7 +129,7 @@ library BundleRegistryLib { 🏷 Generate Unique Name -------------------------------*/ function genUniqueBundleName(BundleRegistry storage bundle) internal returns(string memory name) { - uint pid = bundle.recordExecStart("genUniqueBundleName"); + uint pid = bundle.startProcess("genUniqueBundleName"); ScanRange storage range = Config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = Config().DEFAULT_BUNDLE_NAME.toSequential(i); @@ -161,27 +160,4 @@ library BundleRegistryLib { function notExistsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { return bundle.existsCurrentBundle().isNot(); } - - - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Start - */ - function recordExecStart(BundleRegistry storage, string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(BundleRegistry storage bundle, string memory funcName) internal returns(uint) { - return bundle.recordExecStart(funcName, ""); - } - - /** - Record Finish - */ - function recordExecFinish(BundleRegistry storage bundle, uint pid) internal returns(BundleRegistry storage) { - Debug.recordExecFinish(pid); - return bundle; - } - } diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol index 92f2d8b9..d55a1e9a 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -5,6 +5,7 @@ import {Debug} from "devkit/debug/Debug.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; +import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; @@ -25,9 +26,13 @@ library ProcessLib { return func; } + /**-------------------------- + 🧩 Functions Registry + ----------------------------*/ + /**---------------- - đŸ§ē Bundle + đŸ—‚ī¸ Bundle ------------------*/ function startProcess(Bundle storage, string memory name, string memory params) internal returns(uint) { return Debug.recordExecStart("Bundle", name, params); @@ -41,6 +46,21 @@ library ProcessLib { return bundle; } + /**-------------------------- + 🧩 Bundle Registry + ----------------------------*/ + function startProcess(BundleRegistry storage, string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("BundleRegistry", name, params); + } + function startProcess(BundleRegistry storage bundle, string memory name) internal returns(uint) { + return bundle.startProcess(name, ""); + } + + function finishProcess(BundleRegistry storage bundle, uint pid) internal returns(BundleRegistry storage) { + Debug.recordExecFinish(pid); + return bundle; + } + /**-------------------------- 🏛 Standard Functions From 661a143bc660b32b696d1a06cdbaea876629348f Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 17:11:18 +0900 Subject: [PATCH 035/111] Separate process methods from ProxyLib --- devkit/core/Proxy.sol | 180 ++---------------------- devkit/method/MCDeployLib.sol | 4 +- devkit/method/MCTestLib.sol | 3 +- devkit/method/core/ProxyKindLib.sol | 20 +++ devkit/method/core/ProxyLib.sol | 135 ++++++++++++++++++ devkit/method/core/ProxyRegistryLib.sol | 6 +- devkit/method/debug/ProcessLib.sol | 25 ++++ 7 files changed, 198 insertions(+), 175 deletions(-) create mode 100644 devkit/method/core/ProxyKindLib.sol create mode 100644 devkit/method/core/ProxyLib.sol diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index 14f31a0e..93323c75 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -1,184 +1,26 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Errors & Debug -import {check} from "devkit/error/Validation.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Utils -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -// Core -// import {MCStdFuncs} from "devkit/core/functions/MCStdFuncs.sol"; -import {Dictionary} from "devkit/core/Dictionary.sol"; -import {Function} from "devkit/core/Function.sol"; -// Test -import {SimpleMockProxy} from "devkit/test/SimpleMockProxy.sol"; -// External Lib -import {ERC7546Utils} from "@ucs.mc/proxy/ERC7546Utils.sol"; -import {ERC7546Proxy} from "@ucs.mc/proxy/ERC7546Proxy.sol"; -import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; +// Methods +import {ProxyLib} from "devkit/method/core/ProxyLib.sol"; +import {ProxyKindLib} from "devkit/method/core/ProxyKindLib.sol"; +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/**------------------- - 🏠 UCS Proxy ----------------------*/ -using ProxyLib for Proxy global; +/**************** + 🏠 Proxy +*****************/ struct Proxy { address addr; ProxyKind kind; } - using ProxyKindLib for ProxyKind global; +using ProxyLib for Proxy global; +using ProcessLib for Proxy global; + enum ProxyKind { undefined, Normal, Verifiable, Mock } - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> - 🚀 Deploy Proxy - 🤖 Create Mock Proxy - << Helper >> - đŸ§Ē Test Utils - 🐞 Debug - 🧐 Inspectors & Assertions -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library ProxyLib { - string constant LIB_NAME = "ProxyLib"; - - - /**--------------------- - 🚀 Deploy Proxy - -----------------------*/ - function deploy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory proxy) { - uint pid = recordExecStart("deploy"); - // Note Temporarily disable (see details in https://github.com/metacontract/mc/issues/16) - // proxy = dictionary.isVerifiable() ? - // deployProxyVerifiable(dictionary, initData) : - // deployProxy(dictionary, initData); - proxy = deployProxyVerifiable(dictionary, initData); - return proxy.recordExecFinish(pid); - } - /**--------------------------- - Deploy Proxy Primitives - -----------------------------*/ - function deployProxyVerifiable(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory) { - return Proxy({ - addr: address(new ERC7546ProxyEtherscan(dictionary.addr, initData)), - kind: ProxyKind.Verifiable - }); - } - - function deployProxy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory) { - return Proxy({ - addr: address(new ERC7546Proxy(dictionary.addr, initData)), - kind: ProxyKind.Normal - }); - } - - function safeDeploy(Dictionary storage dictionary, bytes memory initData) internal returns(Proxy memory) { - uint pid = recordExecStart("safeDeploy"); - return deploy(dictionary.assertExists(), initData).recordExecFinish(pid); - } - - - /**------------------------- - 🤖 Create Mock Proxy - ---------------------------*/ - function createSimpleMockProxy(Function[] memory functionInfos) internal returns(Proxy memory) { - uint pid = recordExecStart("createSimpleMockProxy"); - return Proxy({ - addr: address(new SimpleMockProxy(functionInfos)), - kind: ProxyKind.Mock - }).recordExecFinish(pid); - } - - - - /**------------------- - đŸ§Ē Test Utils - ---------------------*/ - // function loadDictionary(Proxy storage proxy) internal returns(Dictionary storage) { - // return ForgeHelper.loadAddress(proxy.addr, ERC7546Utils.DICTIONARY_SLOT).asDictionary(); - // } - - // function changeDictionary(Proxy storage proxy) internal {} - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function exists(Proxy storage proxy) internal returns(bool) { - return proxy.addr.isContract(); - } - function assertExists(Proxy storage proxy) internal returns(Proxy storage) { - check(proxy.exists(), "Proxy Not Exist"); - return proxy; - } - - function isNotEmpty(Proxy memory proxy) internal returns(bool) { - return proxy.addr.isContract(); - } - function assertNotEmpty(Proxy memory proxy) internal returns(Proxy memory) { - check(proxy.isNotEmpty(), "Empty Proxy"); - return proxy; - } - - function isMock(Proxy memory proxy) internal pure returns(bool) { - return proxy.kind == ProxyKind.Mock; - } - function isNotMock(Proxy memory proxy) internal returns(bool) { - return proxy.isMock().isNot(); - } - - function assignLabel(Proxy storage proxy, string memory name) internal returns(Proxy storage) { - ForgeHelper.assignLabel(proxy.addr, name); - return proxy; - } - - - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Start - */ - function recordExecStart(string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(string memory funcName) internal returns(uint) { - return recordExecStart(funcName, ""); - } - - /** - Record Finish - */ - function recordExecFinish(uint pid) internal { - Debug.recordExecFinish(pid); - } - function recordExecFinish(Proxy memory proxy, uint pid) internal returns(Proxy memory) { - recordExecFinish(pid); - return proxy; - } - function recordExecFinishInStorage(Proxy storage proxy, uint pid) internal returns(Proxy storage) { - recordExecFinish(pid); - return proxy; - } - -} - -library ProxyKindLib { - function isNotUndefined(ProxyKind kind) internal pure returns(bool) { - return kind != ProxyKind.undefined; - } - function assertNotUndefined(ProxyKind kind) internal returns(ProxyKind) { - check(kind.isNotUndefined(), "Undefined Proxy Kind"); - return kind; - } -} + using ProxyKindLib for ProxyKind global; diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index aacfa501..d53d0446 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -15,8 +15,8 @@ import {Bundle} from "devkit/core/Bundle.sol"; import {StdFunctionsArgs} from "devkit/method/core/StdFunctionsLib.sol"; using StdFunctionsArgs for address; // proxy -import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; - +import {Proxy} from "devkit/core/Proxy.sol"; +import {ProxyLib} from "devkit/method/core/ProxyLib.sol"; /*********************************************** diff --git a/devkit/method/MCTestLib.sol b/devkit/method/MCTestLib.sol index a40afa6d..63808344 100644 --- a/devkit/method/MCTestLib.sol +++ b/devkit/method/MCTestLib.sol @@ -10,7 +10,8 @@ import {Params} from "devkit/debug/Params.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; // proxy -import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; +import {Proxy} from "devkit/core/Proxy.sol"; +import {ProxyLib} from "devkit/method/core/ProxyLib.sol"; // dictionary import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; diff --git a/devkit/method/core/ProxyKindLib.sol b/devkit/method/core/ProxyKindLib.sol new file mode 100644 index 00000000..bf80b9fb --- /dev/null +++ b/devkit/method/core/ProxyKindLib.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Errors & Debug +import {check} from "devkit/error/Validation.sol"; +// Core Type +import {ProxyKind} from "devkit/core/Proxy.sol"; + +/**--------------- + 🏠 Proxy +-----------------*/ +library ProxyKindLib { + function isNotUndefined(ProxyKind kind) internal pure returns(bool) { + return kind != ProxyKind.undefined; + } + function assertNotUndefined(ProxyKind kind) internal returns(ProxyKind) { + check(kind.isNotUndefined(), "Undefined Proxy Kind"); + return kind; + } +} diff --git a/devkit/method/core/ProxyLib.sol b/devkit/method/core/ProxyLib.sol new file mode 100644 index 00000000..dbb4e9a0 --- /dev/null +++ b/devkit/method/core/ProxyLib.sol @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Errors & Debug +import {check} from "devkit/error/Validation.sol"; +import {Debug} from "devkit/debug/Debug.sol"; +// Utils +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; + using AddressUtils for address; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; +// Core +// import {MCStdFuncs} from "devkit/core/functions/MCStdFuncs.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; +import {Function} from "devkit/core/Function.sol"; +// Test +import {SimpleMockProxy} from "devkit/test/SimpleMockProxy.sol"; +// External Lib +import {ERC7546Utils} from "@ucs.mc/proxy/ERC7546Utils.sol"; +import {ERC7546Proxy} from "@ucs.mc/proxy/ERC7546Proxy.sol"; +import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; + + +import {Proxy, ProxyKind} from "devkit/core/Proxy.sol"; +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; + +/**--------------- + 🏠 Proxy +-----------------*/ + +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + << Primary >> + 🚀 Deploy Proxy + 🤖 Create Mock Proxy + << Helper >> + đŸ§Ē Test Utils + 🐞 Debug + 🧐 Inspectors & Assertions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library ProxyLib { + + + /**--------------------- + 🚀 Deploy Proxy + -----------------------*/ + function deploy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory proxy) { + uint pid = ProcessLib.startProxyLibProcess("deploy"); + // Note Temporarily disable (see details in https://github.com/metacontract/mc/issues/16) + // proxy = dictionary.isVerifiable() ? + // deployProxyVerifiable(dictionary, initData) : + // deployProxy(dictionary, initData); + proxy = deployProxyVerifiable(dictionary, initData); + return proxy.finishProcess(pid); + } + /**--------------------------- + Deploy Proxy Primitives + -----------------------------*/ + function deployProxyVerifiable(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory) { + return Proxy({ + addr: address(new ERC7546ProxyEtherscan(dictionary.addr, initData)), + kind: ProxyKind.Verifiable + }); + } + + function deployProxy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory) { + return Proxy({ + addr: address(new ERC7546Proxy(dictionary.addr, initData)), + kind: ProxyKind.Normal + }); + } + + function safeDeploy(Dictionary storage dictionary, bytes memory initData) internal returns(Proxy memory) { + uint pid = ProcessLib.startProxyLibProcess("safeDeploy"); + return deploy(dictionary.assertExists(), initData).finishProcess(pid); + } + + + /**------------------------- + 🤖 Create Mock Proxy + ---------------------------*/ + function createSimpleMockProxy(Function[] memory functionInfos) internal returns(Proxy memory) { + uint pid = ProcessLib.startProxyLibProcess("createSimpleMockProxy"); + return Proxy({ + addr: address(new SimpleMockProxy(functionInfos)), + kind: ProxyKind.Mock + }).finishProcess(pid); + } + + + + /**------------------- + đŸ§Ē Test Utils + ---------------------*/ + // function loadDictionary(Proxy storage proxy) internal returns(Dictionary storage) { + // return ForgeHelper.loadAddress(proxy.addr, ERC7546Utils.DICTIONARY_SLOT).asDictionary(); + // } + + // function changeDictionary(Proxy storage proxy) internal {} + + + /**------------------------------- + 🧐 Inspectors & Assertions + ---------------------------------*/ + function exists(Proxy storage proxy) internal returns(bool) { + return proxy.addr.isContract(); + } + function assertExists(Proxy storage proxy) internal returns(Proxy storage) { + check(proxy.exists(), "Proxy Not Exist"); + return proxy; + } + + function isNotEmpty(Proxy memory proxy) internal returns(bool) { + return proxy.addr.isContract(); + } + function assertNotEmpty(Proxy memory proxy) internal returns(Proxy memory) { + check(proxy.isNotEmpty(), "Empty Proxy"); + return proxy; + } + + function isMock(Proxy memory proxy) internal pure returns(bool) { + return proxy.kind == ProxyKind.Mock; + } + function isNotMock(Proxy memory proxy) internal returns(bool) { + return proxy.isMock().isNot(); + } + + function assignLabel(Proxy storage proxy, string memory name) internal returns(Proxy storage) { + ForgeHelper.assignLabel(proxy.addr, name); + return proxy; + } + +} diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol index c3423dda..4fe453ef 100644 --- a/devkit/method/core/ProxyRegistryLib.sol +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -85,15 +85,15 @@ library ProxyRegistryLib { function find(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { uint pid = proxies.startProcess("find"); return proxies.deployed[name.safeCalcHash()] - .assertExists().recordExecFinishInStorage(pid); + .assertExists().finishProcessInStorage(pid); } function findCurrentProxy(ProxyRegistry storage proxies) internal returns(Proxy storage) { uint pid = proxies.startProcess("findCurrentProxy"); - return proxies.currentProxy.assertExists().recordExecFinishInStorage(pid); + return proxies.currentProxy.assertExists().finishProcessInStorage(pid); } function findSimpleMockProxy(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { uint pid = proxies.startProcess("findSimpleMockProxy"); - return proxies.mocks[name.safeCalcHash()].assertExists().recordExecFinishInStorage(pid); + return proxies.mocks[name.safeCalcHash()].assertExists().finishProcessInStorage(pid); } diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol index d55a1e9a..6c78e450 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -7,10 +7,16 @@ import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; +import {Proxy} from "devkit/core/Proxy.sol"; import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; library ProcessLib { + function finishProcess(uint pid) internal { + Debug.recordExecFinish(pid); + } + + /**------------------ 🧩 Function --------------------*/ @@ -78,6 +84,25 @@ library ProcessLib { } + /**--------------- + 🏠 Proxy + -----------------*/ + function startProxyLibProcess(string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("ProxyLib", name, params); + } + function startProxyLibProcess(string memory name) internal returns(uint) { + return startProxyLibProcess(name, ""); + } + + function finishProcess(Proxy memory proxy, uint pid) internal returns(Proxy memory) { + finishProcess(pid); + return proxy; + } + function finishProcessInStorage(Proxy storage proxy, uint pid) internal returns(Proxy storage) { + finishProcess(pid); + return proxy; + } + /**---------------------- 🏠 Proxy Registry ------------------------*/ From 03220c9a5505c63cca579294c7b4f5845787255e Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 17:17:46 +0900 Subject: [PATCH 036/111] Separate DictionaryLib file --- devkit/core/Dictionary.sol | 215 +------------------ devkit/method/core/DictionaryKindLib.sol | 18 ++ devkit/method/core/DictionaryLib.sol | 249 +++++++++++++++++++++++ 3 files changed, 269 insertions(+), 213 deletions(-) create mode 100644 devkit/method/core/DictionaryKindLib.sol create mode 100644 devkit/method/core/DictionaryLib.sol diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 44c2d8dd..8a762bd6 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -27,6 +27,8 @@ import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; import {IBeacon} from "@oz.mc/proxy/beacon/IBeacon.sol"; import {ERC1967Utils} from "@oz.mc/proxy/ERC1967/ERC1967Utils.sol"; +import {DictionaryLib} from "devkit/method/core/DictionaryLib.sol"; +import {DictionaryKindLib} from "devkit/method/core/DictionaryKindLib.sol"; /**------------------------ 📚 UCS Dictionary @@ -42,216 +44,3 @@ struct Dictionary { Verifiable, Mock } - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> - 🚀 Deploy Dictionary - 🔂 Duplicate Dictionary - 🧩 Set Function - đŸĒŸ Upgrade Facade - 🤖 Create Mock Dictionary - << Helper >> - 🧐 Inspectors & Assertions - 🐞 Debug -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library DictionaryLib { - string constant LIB_NAME = "DictionaryLib"; - - - /**------------------------- - 🚀 Deploy Dictionary - ---------------------------*/ - function deploy(address owner) internal returns(Dictionary memory) { - uint pid = recordExecStart("deploy"); - /// @dev Until Etherscan supports UCS, we are deploying contracts with additional features for Etherscan compatibility by default. - return deployDictionaryVerifiable(owner).recordExecFinish(pid); - } - /**--------------------------- - Deploy Proxy Primitives - -----------------------------*/ - function deployDictionaryVerifiable(address owner) internal returns(Dictionary memory) { - return Dictionary({ - addr: address(new DictionaryEtherscan(owner)), - kind: DictionaryKind.Verifiable - }); - } - - function safeDeploy(address owner) internal returns(Dictionary memory) { - uint pid = recordExecStart("safeDeploy"); - return deploy(owner.assertNotZero()).recordExecFinish(pid); - } - - - /**---------------------------- - 🔂 Duplicate Dictionary - ------------------------------*/ - function duplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { - uint pid = recordExecStart("duplicate"); - return deploy(ForgeHelper.msgSender()) - .duplicateFunctionsFrom(targetDictionary).recordExecFinish(pid); - } - function duplicateFunctionsFrom(Dictionary memory toDictionary, Dictionary memory fromDictionary) internal returns(Dictionary memory) { - uint pid = recordExecStart("duplicateFunctionsFrom"); - address toAddr = toDictionary.addr; - address fromAddr = fromDictionary.addr; - - bytes4[] memory _selectors = IDictionary(fromAddr).supportsInterfaces(); - for (uint i; i < _selectors.length; ++i) { - bytes4 _selector = _selectors[i]; - if (_selector.isEmpty()) continue; - IDictionary(toAddr).setImplementation({ - functionSelector: _selector, - implementation: IDictionary(fromAddr).getImplementation(_selector) - }); - } - - return toDictionary.recordExecFinish(pid); - } - function safeDuplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { - uint pid = recordExecStart("safeDuplicate"); - return targetDictionary.assertNotEmpty().duplicate().recordExecFinish(pid); - } - - - /**----------------------------- - 🧩 Set Function & Bundle - -------------------------------*/ - function set(Dictionary memory dictionary, Function memory functionInfo) internal returns(Dictionary memory) { - uint pid = recordExecStart("set", Params.append(functionInfo.name)); - IDictionary(dictionary.addr).setImplementation({ - functionSelector: functionInfo.selector, - implementation: functionInfo.implementation - }); - return dictionary.recordExecFinish(pid); - } - function set(Dictionary memory dictionary, Bundle storage bundleInfo) internal returns(Dictionary memory) { - uint pid = recordExecStart("set", Params.append(bundleInfo.name)); - - Function[] memory functionInfos = bundleInfo.functionInfos; - - for (uint i; i < functionInfos.length; ++i) { - dictionary.set(functionInfos[i]); - } - - // TODO Generate Facade - // if (dictionary.isVerifiable()) { - // dictionary.upgradeFacade(bundleInfo.facade); - // } - - return dictionary.recordExecFinish(pid); - } - - - /**---------------------- - đŸĒŸ Upgrade Facade - ------------------------*/ - function upgradeFacade(Dictionary memory dictionary, address newFacade) internal returns(Dictionary memory) { - uint pid = recordExecStart("upgradeFacade"); - DictionaryEtherscan(dictionary.assertVerifiable().addr).upgradeFacade(newFacade); - return dictionary.recordExecFinish(pid); - } - - - /**------------------------------ - 🤖 Create Mock Dictionary - --------------------------------*/ - function createMockDictionary(address owner, Function[] memory functionInfos) internal returns(Dictionary memory) { - uint pid = recordExecStart("createMockDictionary"); - return Dictionary({ - addr: address(new MockDictionary(owner, functionInfos)), - kind: DictionaryKind.Mock - }).recordExecFinish(pid); - } - - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function exists(Dictionary storage dictionary) internal returns(bool) { - return dictionary.addr.isContract(); - } - function assertExists(Dictionary storage dictionary) internal returns(Dictionary storage) { - check(dictionary.exists(), "Dictionary Not Exists"); - return dictionary; - } - - function isNotEmpty(Dictionary memory dictionary) internal returns(bool) { - return dictionary.addr.isContract(); - } - function assertNotEmpty(Dictionary memory dictionary) internal returns(Dictionary memory) { - check(dictionary.isNotEmpty(), "Empty Dictionary"); - return dictionary; - } - - function isSupported(Dictionary memory dictionary, bytes4 selector) internal view returns(bool) { - return IDictionary(dictionary.addr).supportsInterface(selector); - } - function assertSupports(Dictionary storage dictionary, bytes4 selector) internal returns(Dictionary storage) { - check(dictionary.isSupported(selector), "Unsupported Selector"); - return dictionary; - } - - function isVerifiable(Dictionary memory dictionary) internal returns(bool) { - (bool success,) = dictionary.addr.call(abi.encodeWithSelector(IBeacon.implementation.selector)); - return success; - } - function assertVerifiable(Dictionary memory dictionary) internal returns(Dictionary memory) { - check(dictionary.isVerifiable(), "Dictionary Not Verifiable"); - return dictionary; - } - - function isMock(Dictionary memory dictionary) internal pure returns(bool) { - return dictionary.kind == DictionaryKind.Mock; - } - function isNotMock(Dictionary memory dictionary) internal returns(bool) { - return dictionary.isMock().isNot(); - } - // function isUUPS(Dictionary dictionary) internal returns(bool) { - // return UUPSUpgradeable(dictionary.toAddress()).proxiableUUID() == ERC1967Utils.IMPLEMENTATION_SLOT; - // } - - - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Start - */ - function recordExecStart(string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(string memory funcName) internal returns(uint) { - return recordExecStart(funcName, ""); - } - function recordExecFinish(uint pid) internal { - Debug.recordExecFinish(pid); - } - - /** - Record Finish - */ - function recordExecFinish(Dictionary memory dictionary, uint pid) internal returns(Dictionary memory) { - recordExecFinish(pid); - return dictionary; - } - function recordExecFinishInStorage(Dictionary storage dictionary, uint pid) internal returns(Dictionary storage) { - recordExecFinish(pid); - return dictionary; - } - - // function assignLabel(Dictionary storage dictionary, string memory name) internal returns(Dictionary storage) { - // ForgeHelper.assignLabel(dictionary.addr, name); - // return dictionary; - // } -} - -library DictionaryKindLib { - function isNotUndefined(DictionaryKind kind) internal pure returns(bool) { - return kind != DictionaryKind.undefined; - } - function assertNotUndefined(DictionaryKind kind) internal returns(DictionaryKind) { - check(kind.isNotUndefined(), "Undefined Dictionary Kind"); - return kind; - } -} diff --git a/devkit/method/core/DictionaryKindLib.sol b/devkit/method/core/DictionaryKindLib.sol new file mode 100644 index 00000000..673a9ab4 --- /dev/null +++ b/devkit/method/core/DictionaryKindLib.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {check} from "devkit/error/Validation.sol"; +import {DictionaryKind} from "devkit/core/Dictionary.sol"; + +/**------------------------ + 📚 Dictionary Kind +--------------------------*/ +library DictionaryKindLib { + function isNotUndefined(DictionaryKind kind) internal pure returns(bool) { + return kind != DictionaryKind.undefined; + } + function assertNotUndefined(DictionaryKind kind) internal returns(DictionaryKind) { + check(kind.isNotUndefined(), "Undefined Dictionary Kind"); + return kind; + } +} diff --git a/devkit/method/core/DictionaryLib.sol b/devkit/method/core/DictionaryLib.sol new file mode 100644 index 00000000..a5bc8728 --- /dev/null +++ b/devkit/method/core/DictionaryLib.sol @@ -0,0 +1,249 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Validation +import {check} from "devkit/error/Validation.sol"; +import {Params} from "devkit/debug/Params.sol"; +// Utils +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; + using AddressUtils for address; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; + using Bytes4Utils for bytes4; +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; +// Debug +import {Debug} from "devkit/debug/Debug.sol"; +// Core +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +// Test +import {MockDictionary} from "devkit/test/MockDictionary.sol"; +// External Libs +import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; +import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; +import {IBeacon} from "@oz.mc/proxy/beacon/IBeacon.sol"; +import {ERC1967Utils} from "@oz.mc/proxy/ERC1967/ERC1967Utils.sol"; + + +import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; +// import {} from "devkit/core/"; + +/**------------------------ + 📚 UCS Dictionary +--------------------------*/ + +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + << Primary >> + 🚀 Deploy Dictionary + 🔂 Duplicate Dictionary + 🧩 Set Function + đŸĒŸ Upgrade Facade + 🤖 Create Mock Dictionary + << Helper >> + 🧐 Inspectors & Assertions + 🐞 Debug +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library DictionaryLib { + string constant LIB_NAME = "DictionaryLib"; + + + /**------------------------- + 🚀 Deploy Dictionary + ---------------------------*/ + function deploy(address owner) internal returns(Dictionary memory) { + uint pid = recordExecStart("deploy"); + /// @dev Until Etherscan supports UCS, we are deploying contracts with additional features for Etherscan compatibility by default. + return deployDictionaryVerifiable(owner).recordExecFinish(pid); + } + /**--------------------------- + Deploy Proxy Primitives + -----------------------------*/ + function deployDictionaryVerifiable(address owner) internal returns(Dictionary memory) { + return Dictionary({ + addr: address(new DictionaryEtherscan(owner)), + kind: DictionaryKind.Verifiable + }); + } + + function safeDeploy(address owner) internal returns(Dictionary memory) { + uint pid = recordExecStart("safeDeploy"); + return deploy(owner.assertNotZero()).recordExecFinish(pid); + } + + + /**---------------------------- + 🔂 Duplicate Dictionary + ------------------------------*/ + function duplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { + uint pid = recordExecStart("duplicate"); + return deploy(ForgeHelper.msgSender()) + .duplicateFunctionsFrom(targetDictionary).recordExecFinish(pid); + } + function duplicateFunctionsFrom(Dictionary memory toDictionary, Dictionary memory fromDictionary) internal returns(Dictionary memory) { + uint pid = recordExecStart("duplicateFunctionsFrom"); + address toAddr = toDictionary.addr; + address fromAddr = fromDictionary.addr; + + bytes4[] memory _selectors = IDictionary(fromAddr).supportsInterfaces(); + for (uint i; i < _selectors.length; ++i) { + bytes4 _selector = _selectors[i]; + if (_selector.isEmpty()) continue; + IDictionary(toAddr).setImplementation({ + functionSelector: _selector, + implementation: IDictionary(fromAddr).getImplementation(_selector) + }); + } + + return toDictionary.recordExecFinish(pid); + } + function safeDuplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { + uint pid = recordExecStart("safeDuplicate"); + return targetDictionary.assertNotEmpty().duplicate().recordExecFinish(pid); + } + + + /**----------------------------- + 🧩 Set Function & Bundle + -------------------------------*/ + function set(Dictionary memory dictionary, Function memory functionInfo) internal returns(Dictionary memory) { + uint pid = recordExecStart("set", Params.append(functionInfo.name)); + IDictionary(dictionary.addr).setImplementation({ + functionSelector: functionInfo.selector, + implementation: functionInfo.implementation + }); + return dictionary.recordExecFinish(pid); + } + function set(Dictionary memory dictionary, Bundle storage bundleInfo) internal returns(Dictionary memory) { + uint pid = recordExecStart("set", Params.append(bundleInfo.name)); + + Function[] memory functionInfos = bundleInfo.functionInfos; + + for (uint i; i < functionInfos.length; ++i) { + dictionary.set(functionInfos[i]); + } + + // TODO Generate Facade + // if (dictionary.isVerifiable()) { + // dictionary.upgradeFacade(bundleInfo.facade); + // } + + return dictionary.recordExecFinish(pid); + } + + + /**---------------------- + đŸĒŸ Upgrade Facade + ------------------------*/ + function upgradeFacade(Dictionary memory dictionary, address newFacade) internal returns(Dictionary memory) { + uint pid = recordExecStart("upgradeFacade"); + DictionaryEtherscan(dictionary.assertVerifiable().addr).upgradeFacade(newFacade); + return dictionary.recordExecFinish(pid); + } + + + /**------------------------------ + 🤖 Create Mock Dictionary + --------------------------------*/ + function createMockDictionary(address owner, Function[] memory functionInfos) internal returns(Dictionary memory) { + uint pid = recordExecStart("createMockDictionary"); + return Dictionary({ + addr: address(new MockDictionary(owner, functionInfos)), + kind: DictionaryKind.Mock + }).recordExecFinish(pid); + } + + + + /**------------------------------- + 🧐 Inspectors & Assertions + ---------------------------------*/ + function exists(Dictionary storage dictionary) internal returns(bool) { + return dictionary.addr.isContract(); + } + function assertExists(Dictionary storage dictionary) internal returns(Dictionary storage) { + check(dictionary.exists(), "Dictionary Not Exists"); + return dictionary; + } + + function isNotEmpty(Dictionary memory dictionary) internal returns(bool) { + return dictionary.addr.isContract(); + } + function assertNotEmpty(Dictionary memory dictionary) internal returns(Dictionary memory) { + check(dictionary.isNotEmpty(), "Empty Dictionary"); + return dictionary; + } + + function isSupported(Dictionary memory dictionary, bytes4 selector) internal view returns(bool) { + return IDictionary(dictionary.addr).supportsInterface(selector); + } + function assertSupports(Dictionary storage dictionary, bytes4 selector) internal returns(Dictionary storage) { + check(dictionary.isSupported(selector), "Unsupported Selector"); + return dictionary; + } + + function isVerifiable(Dictionary memory dictionary) internal returns(bool) { + (bool success,) = dictionary.addr.call(abi.encodeWithSelector(IBeacon.implementation.selector)); + return success; + } + function assertVerifiable(Dictionary memory dictionary) internal returns(Dictionary memory) { + check(dictionary.isVerifiable(), "Dictionary Not Verifiable"); + return dictionary; + } + + function isMock(Dictionary memory dictionary) internal pure returns(bool) { + return dictionary.kind == DictionaryKind.Mock; + } + function isNotMock(Dictionary memory dictionary) internal returns(bool) { + return dictionary.isMock().isNot(); + } + // function isUUPS(Dictionary dictionary) internal returns(bool) { + // return UUPSUpgradeable(dictionary.toAddress()).proxiableUUID() == ERC1967Utils.IMPLEMENTATION_SLOT; + // } + + + /**---------------- + 🐞 Debug + ------------------*/ + /** + Record Start + */ + function recordExecStart(string memory funcName, string memory params) internal returns(uint) { + return Debug.recordExecStart(LIB_NAME, funcName, params); + } + function recordExecStart(string memory funcName) internal returns(uint) { + return recordExecStart(funcName, ""); + } + function recordExecFinish(uint pid) internal { + Debug.recordExecFinish(pid); + } + + /** + Record Finish + */ + function recordExecFinish(Dictionary memory dictionary, uint pid) internal returns(Dictionary memory) { + recordExecFinish(pid); + return dictionary; + } + function recordExecFinishInStorage(Dictionary storage dictionary, uint pid) internal returns(Dictionary storage) { + recordExecFinish(pid); + return dictionary; + } + + // function assignLabel(Dictionary storage dictionary, string memory name) internal returns(Dictionary storage) { + // ForgeHelper.assignLabel(dictionary.addr, name); + // return dictionary; + // } +} + +library DictionaryKindLib { + function isNotUndefined(DictionaryKind kind) internal pure returns(bool) { + return kind != DictionaryKind.undefined; + } + function assertNotUndefined(DictionaryKind kind) internal returns(DictionaryKind) { + check(kind.isNotUndefined(), "Undefined Dictionary Kind"); + return kind; + } +} From 86e990fb4b86729b015b5af119e414d7e812c573 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 17:29:05 +0900 Subject: [PATCH 037/111] Separate process methods from DictionaryLib --- devkit/core/Dictionary.sol | 7 +- devkit/method/MCDeployLib.sol | 2 +- devkit/method/core/DictionaryLib.sol | 79 +++++--------------- devkit/method/core/DictionaryRegistryLib.sol | 6 +- devkit/method/debug/ProcessLib.sol | 20 +++++ 5 files changed, 48 insertions(+), 66 deletions(-) diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 8a762bd6..76b0190f 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -29,18 +29,21 @@ import {ERC1967Utils} from "@oz.mc/proxy/ERC1967/ERC1967Utils.sol"; import {DictionaryLib} from "devkit/method/core/DictionaryLib.sol"; import {DictionaryKindLib} from "devkit/method/core/DictionaryKindLib.sol"; +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; /**------------------------ 📚 UCS Dictionary --------------------------*/ -using DictionaryLib for Dictionary global; struct Dictionary { address addr; DictionaryKind kind; } - using DictionaryKindLib for DictionaryKind global; +using DictionaryLib for Dictionary global; +using ProcessLib for Dictionary global; + enum DictionaryKind { undefined, Verifiable, Mock } + using DictionaryKindLib for DictionaryKind global; diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index d53d0446..e85c351a 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -105,7 +105,7 @@ library MCDeployLib { .upgradeFacade(bundleInfo.facade); mc.dictionary .safeAdd(name, dictionary) .safeUpdate(dictionary); - return dictionary.recordExecFinish(pid); + return dictionary.finishProcess(pid); } function deployDictionary(MCDevKit storage mc) internal returns(Dictionary memory) { diff --git a/devkit/method/core/DictionaryLib.sol b/devkit/method/core/DictionaryLib.sol index a5bc8728..d5543043 100644 --- a/devkit/method/core/DictionaryLib.sol +++ b/devkit/method/core/DictionaryLib.sol @@ -29,7 +29,7 @@ import {ERC1967Utils} from "@oz.mc/proxy/ERC1967/ERC1967Utils.sol"; import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; -// import {} from "devkit/core/"; +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; /**------------------------ 📚 UCS Dictionary @@ -47,16 +47,13 @@ import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; 🐞 Debug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library DictionaryLib { - string constant LIB_NAME = "DictionaryLib"; - - /**------------------------- 🚀 Deploy Dictionary ---------------------------*/ function deploy(address owner) internal returns(Dictionary memory) { - uint pid = recordExecStart("deploy"); + uint pid = ProcessLib.startDictionaryLibProcess("deploy"); /// @dev Until Etherscan supports UCS, we are deploying contracts with additional features for Etherscan compatibility by default. - return deployDictionaryVerifiable(owner).recordExecFinish(pid); + return deployDictionaryVerifiable(owner).finishProcess(pid); } /**--------------------------- Deploy Proxy Primitives @@ -69,8 +66,8 @@ library DictionaryLib { } function safeDeploy(address owner) internal returns(Dictionary memory) { - uint pid = recordExecStart("safeDeploy"); - return deploy(owner.assertNotZero()).recordExecFinish(pid); + uint pid = ProcessLib.startDictionaryLibProcess("safeDeploy"); + return deploy(owner.assertNotZero()).finishProcess(pid); } @@ -78,12 +75,12 @@ library DictionaryLib { 🔂 Duplicate Dictionary ------------------------------*/ function duplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { - uint pid = recordExecStart("duplicate"); + uint pid = ProcessLib.startDictionaryLibProcess("duplicate"); return deploy(ForgeHelper.msgSender()) - .duplicateFunctionsFrom(targetDictionary).recordExecFinish(pid); + .duplicateFunctionsFrom(targetDictionary).finishProcess(pid); } function duplicateFunctionsFrom(Dictionary memory toDictionary, Dictionary memory fromDictionary) internal returns(Dictionary memory) { - uint pid = recordExecStart("duplicateFunctionsFrom"); + uint pid = ProcessLib.startDictionaryLibProcess("duplicateFunctionsFrom"); address toAddr = toDictionary.addr; address fromAddr = fromDictionary.addr; @@ -97,11 +94,11 @@ library DictionaryLib { }); } - return toDictionary.recordExecFinish(pid); + return toDictionary.finishProcess(pid); } function safeDuplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { - uint pid = recordExecStart("safeDuplicate"); - return targetDictionary.assertNotEmpty().duplicate().recordExecFinish(pid); + uint pid = ProcessLib.startDictionaryLibProcess("safeDuplicate"); + return targetDictionary.assertNotEmpty().duplicate().finishProcess(pid); } @@ -109,15 +106,15 @@ library DictionaryLib { 🧩 Set Function & Bundle -------------------------------*/ function set(Dictionary memory dictionary, Function memory functionInfo) internal returns(Dictionary memory) { - uint pid = recordExecStart("set", Params.append(functionInfo.name)); + uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(functionInfo.name)); IDictionary(dictionary.addr).setImplementation({ functionSelector: functionInfo.selector, implementation: functionInfo.implementation }); - return dictionary.recordExecFinish(pid); + return dictionary.finishProcess(pid); } function set(Dictionary memory dictionary, Bundle storage bundleInfo) internal returns(Dictionary memory) { - uint pid = recordExecStart("set", Params.append(bundleInfo.name)); + uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(bundleInfo.name)); Function[] memory functionInfos = bundleInfo.functionInfos; @@ -130,7 +127,7 @@ library DictionaryLib { // dictionary.upgradeFacade(bundleInfo.facade); // } - return dictionary.recordExecFinish(pid); + return dictionary.finishProcess(pid); } @@ -138,9 +135,9 @@ library DictionaryLib { đŸĒŸ Upgrade Facade ------------------------*/ function upgradeFacade(Dictionary memory dictionary, address newFacade) internal returns(Dictionary memory) { - uint pid = recordExecStart("upgradeFacade"); + uint pid = ProcessLib.startDictionaryLibProcess("upgradeFacade"); DictionaryEtherscan(dictionary.assertVerifiable().addr).upgradeFacade(newFacade); - return dictionary.recordExecFinish(pid); + return dictionary.finishProcess(pid); } @@ -148,11 +145,11 @@ library DictionaryLib { 🤖 Create Mock Dictionary --------------------------------*/ function createMockDictionary(address owner, Function[] memory functionInfos) internal returns(Dictionary memory) { - uint pid = recordExecStart("createMockDictionary"); + uint pid = ProcessLib.startDictionaryLibProcess("createMockDictionary"); return Dictionary({ addr: address(new MockDictionary(owner, functionInfos)), kind: DictionaryKind.Mock - }).recordExecFinish(pid); + }).finishProcess(pid); } @@ -204,46 +201,8 @@ library DictionaryLib { // } - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Start - */ - function recordExecStart(string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(string memory funcName) internal returns(uint) { - return recordExecStart(funcName, ""); - } - function recordExecFinish(uint pid) internal { - Debug.recordExecFinish(pid); - } - - /** - Record Finish - */ - function recordExecFinish(Dictionary memory dictionary, uint pid) internal returns(Dictionary memory) { - recordExecFinish(pid); - return dictionary; - } - function recordExecFinishInStorage(Dictionary storage dictionary, uint pid) internal returns(Dictionary storage) { - recordExecFinish(pid); - return dictionary; - } - // function assignLabel(Dictionary storage dictionary, string memory name) internal returns(Dictionary storage) { // ForgeHelper.assignLabel(dictionary.addr, name); // return dictionary; // } } - -library DictionaryKindLib { - function isNotUndefined(DictionaryKind kind) internal pure returns(bool) { - return kind != DictionaryKind.undefined; - } - function assertNotUndefined(DictionaryKind kind) internal returns(DictionaryKind) { - check(kind.isNotUndefined(), "Undefined Dictionary Kind"); - return kind; - } -} diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol index 459a3dea..a37e1841 100644 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -89,15 +89,15 @@ library DictionaryRegistryLib { uint pid = dictionaries.startProcess("find"); return dictionaries.deployed[name.safeCalcHash()] .assertExists() - .recordExecFinishInStorage(pid); + .finishProcessInStorage(pid); } function findCurrentDictionary(DictionaryRegistry storage dictionaries) internal returns(Dictionary storage) { uint pid = dictionaries.startProcess("findCurrentDictionary"); - return dictionaries.currentDictionary.assertExists().recordExecFinishInStorage(pid); + return dictionaries.currentDictionary.assertExists().finishProcessInStorage(pid); } function findMockDictionary(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { uint pid = dictionaries.startProcess("findMockDictionary"); - return dictionaries.mocks[name.safeCalcHash()].assertExists().recordExecFinishInStorage(pid); + return dictionaries.mocks[name.safeCalcHash()].assertExists().finishProcessInStorage(pid); } diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol index 6c78e450..cf2e30e4 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -9,6 +9,7 @@ import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; import {Proxy} from "devkit/core/Proxy.sol"; import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; library ProcessLib { @@ -119,6 +120,25 @@ library ProcessLib { } + /**------------------- + 📚 Dictionary + ---------------------*/ + function startDictionaryLibProcess(string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("DictionaryLib", name, params); + } + function startDictionaryLibProcess(string memory name) internal returns(uint) { + return startDictionaryLibProcess(name, ""); + } + + function finishProcess(Dictionary memory dictionary, uint pid) internal returns(Dictionary memory) { + finishProcess(pid); + return dictionary; + } + function finishProcessInStorage(Dictionary storage dictionary, uint pid) internal returns(Dictionary storage) { + finishProcess(pid); + return dictionary; + } + /**---------------------------- 📚 Dictionary Registry ------------------------------*/ From 59fa6b3b4b180d84ee7c10872ee53fb3256524d7 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 18:45:07 +0900 Subject: [PATCH 038/111] Separate FunctionRegistryLib --- devkit/core/FunctionRegistry.sol | 125 ++------------------- devkit/method/MCBundleLib.sol | 2 +- devkit/method/MCFinderLib.sol | 2 +- devkit/method/core/FunctionRegistryLib.sol | 98 ++++++++++++++++ devkit/method/debug/ProcessLib.sol | 12 ++ 5 files changed, 119 insertions(+), 120 deletions(-) create mode 100644 devkit/method/core/FunctionRegistryLib.sol diff --git a/devkit/core/FunctionRegistry.sol b/devkit/core/FunctionRegistry.sol index 8c9655e3..76964754 100644 --- a/devkit/core/FunctionRegistry.sol +++ b/devkit/core/FunctionRegistry.sol @@ -1,130 +1,19 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Error & Debug -import {check} from "devkit/error/Validation.sol"; -import {ERR, throwError} from "devkit/error/Error.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Config -import {ScanRange, Config} from "devkit/config/Config.sol"; -// Utils -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -// Core -import {Function} from "./Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -import {StdFunctions} from "devkit/core/StdFunctions.sol"; +// Core Type +import {Function} from "devkit/core/Function.sol"; +// Methods +import {FunctionRegistryLib} from "devkit/method/core/FunctionRegistryLib.sol"; +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; /**--------------------------- 🧩 Functions Registry -----------------------------*/ -using FunctionRegistryLib for FunctionRegistry global; struct FunctionRegistry { mapping(bytes32 nameHash => Function) customs; string currentName; } - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> - ✨ Add Custom Function - 🔏 Load and Assign Custom Function from Env - đŸ”ŧ Update Current Context Function - 🔍 Find Function - << Helper >> - 🔍 Find Custom Function -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library FunctionRegistryLib { - string constant LIB_NAME = "FunctionRegistry"; - - - /**--------------------------- - ✨ Add Custom Function - -----------------------------*/ - function safeAddFunction(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("safeAddFunction"); - check(name.isNotEmpty(), "Empty Name"); - functions.customs[name.safeCalcHash()] - .safeAssign(name) - .safeAssign(selector) - .safeAssign(implementation); - functions.safeUpdateCurrentFunction(name); - return functions.recordExecFinish(pid); - } - - - /**--------------------------------------------- - 🔏 Load and Add Custom Function from Env - -----------------------------------------------*/ - function safeLoadAndAdd(FunctionRegistry storage functions, string memory envKey, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("safeLoadAndAdd"); - functions.customs[name.safeCalcHash()] - .loadAndAssignFromEnv(envKey, name, selector); - functions.safeUpdateCurrentFunction(name); - return functions.recordExecFinish(pid); - } - - - /**------------------------------------------------ - đŸ”ŧ Update Current Context - --------------------------------------------------*/ - function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("safeUpdateCurrentFunction"); - functions.currentName = name.assertNotEmpty(); - return functions.recordExecFinish(pid); - } - - - /**----------------------------------------------- - â™ģī¸ Reset Current Context Function & Bundle - -------------------------------------------------*/ - function reset(FunctionRegistry storage functions) internal returns(FunctionRegistry storage) { - uint pid = functions.recordExecStart("reset"); - delete functions.currentName; - return functions.recordExecFinish(pid); - } - - - /**------------------------------- - 🔍 Find Function & Bundle - ---------------------------------*/ - /**----- 🧩 Function -------*/ - function findFunction(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { - uint pid = functions.recordExecStart("findFunction"); - return functions.customs[name.safeCalcHash()].assertExists().finishProcess(pid); - } - function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { - uint pid = functions.recordExecStart("findCurrentFunction"); - return functions.findFunction(functions.findCurrentName()).finishProcess(pid); - } - function findCurrentName(FunctionRegistry storage functions) internal returns(string memory) { - uint pid = functions.recordExecStart("findCurrentName"); - return functions.currentName.assertNotEmpty().recordExecFinish(pid); - } - - - - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Start - */ - function recordExecStart(FunctionRegistry storage, string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); - } - function recordExecStart(FunctionRegistry storage functions, string memory funcName) internal returns(uint) { - return functions.recordExecStart(funcName, ""); - } - - /** - Record Finish - */ - function recordExecFinish(FunctionRegistry storage functions, uint pid) internal returns(FunctionRegistry storage) { - Debug.recordExecFinish(pid); - return functions; - } - -} +using FunctionRegistryLib for FunctionRegistry global; +using ProcessLib for FunctionRegistry global; diff --git a/devkit/method/MCBundleLib.sol b/devkit/method/MCBundleLib.sol index d9992db3..e845c86a 100644 --- a/devkit/method/MCBundleLib.sol +++ b/devkit/method/MCBundleLib.sol @@ -67,7 +67,7 @@ library MCBundleLib { // return mc; // } TODO function use(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - check(mc.functions.findFunction(name).isComplete(), "Invalid Function Name"); + check(mc.functions.find(name).isComplete(), "Invalid Function Name"); return mc.use(mc.findFunction(name)); } /**--------------------------- diff --git a/devkit/method/MCFinderLib.sol b/devkit/method/MCFinderLib.sol index 467c864b..ece775e1 100644 --- a/devkit/method/MCFinderLib.sol +++ b/devkit/method/MCFinderLib.sol @@ -43,7 +43,7 @@ library MCFinderLib { ------------------------*/ function findFunction(MCDevKit storage mc, string memory name) internal returns(Function storage) { uint pid = mc.recordExecStart("findFunction"); - return mc.functions.findFunction(name); + return mc.functions.find(name); } function findCurrentFunction(MCDevKit storage mc) internal returns(Function storage) { uint pid = mc.recordExecStart("findCurrentFunction", ""); diff --git a/devkit/method/core/FunctionRegistryLib.sol b/devkit/method/core/FunctionRegistryLib.sol new file mode 100644 index 00000000..bddaaa3d --- /dev/null +++ b/devkit/method/core/FunctionRegistryLib.sol @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Error & Debug +import {check} from "devkit/error/Validation.sol"; +import {ERR, throwError} from "devkit/error/Error.sol"; +import {Debug} from "devkit/debug/Debug.sol"; +// Config +import {ScanRange, Config} from "devkit/config/Config.sol"; +// Utils +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +// Core +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {StdFunctions} from "devkit/core/StdFunctions.sol"; + +import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; + +/**--------------------------- + 🧩 Functions Registry +-----------------------------*/ +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + << Primary >> + ✨ Add Custom Function + 🔏 Load and Assign Custom Function from Env + đŸ”ŧ Update Current Context Function + 🔍 Find Function + << Helper >> + 🔍 Find Custom Function +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library FunctionRegistryLib { + /**--------------------------- + ✨ Add Custom Function + -----------------------------*/ + function safeAddFunction(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + uint pid = functions.startProcess("safeAddFunction"); + check(name.isNotEmpty(), "Empty Name"); + functions.customs[name.safeCalcHash()] + .safeAssign(name) + .safeAssign(selector) + .safeAssign(implementation); + functions.safeUpdateCurrentFunction(name); + return functions.finishProcess(pid); + } + + + /**--------------------------------------------- + 🔏 Load and Add Custom Function from Env + -----------------------------------------------*/ + function safeLoadAndAdd(FunctionRegistry storage functions, string memory envKey, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + uint pid = functions.startProcess("safeLoadAndAdd"); + functions.customs[name.safeCalcHash()] + .loadAndAssignFromEnv(envKey, name, selector); + functions.safeUpdateCurrentFunction(name); + return functions.finishProcess(pid); + } + + + /**------------------------------------------------ + đŸ”ŧ Update Current Context + --------------------------------------------------*/ + function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + uint pid = functions.startProcess("safeUpdateCurrentFunction"); + functions.currentName = name.assertNotEmpty(); + return functions.finishProcess(pid); + } + + + /**----------------------------------------------- + â™ģī¸ Reset Current Context Function & Bundle + -------------------------------------------------*/ + function reset(FunctionRegistry storage functions) internal returns(FunctionRegistry storage) { + uint pid = functions.startProcess("reset"); + delete functions.currentName; + return functions.finishProcess(pid); + } + + + /**------------------------------- + 🔍 Find Function + ---------------------------------*/ + function find(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { + uint pid = functions.startProcess("findFunction"); + return functions.customs[name.safeCalcHash()].assertExists().finishProcess(pid); + } + function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { + uint pid = functions.startProcess("findCurrentFunction"); + return functions.find(functions.findCurrentName()).finishProcess(pid); + } + function findCurrentName(FunctionRegistry storage functions) internal returns(string memory) { + uint pid = functions.startProcess("findCurrentName"); + return functions.currentName.assertNotEmpty().recordExecFinish(pid); + } + +} diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol index cf2e30e4..439fcedf 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; import {Debug} from "devkit/debug/Debug.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; +import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; @@ -36,6 +37,17 @@ library ProcessLib { /**-------------------------- 🧩 Functions Registry ----------------------------*/ + function startProcess(FunctionRegistry storage, string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("FunctionRegistry", name, params); + } + function startProcess(FunctionRegistry storage functions, string memory name) internal returns(uint) { + return functions.startProcess(name, ""); + } + + function finishProcess(FunctionRegistry storage functions, uint pid) internal returns(FunctionRegistry storage) { + Debug.recordExecFinish(pid); + return functions; + } /**---------------- From df4c91de8461a49394b1912951c7be5f9fdec2a4 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 18:54:08 +0900 Subject: [PATCH 039/111] chore update cores --- devkit/core/Bundle.sol | 4 ++-- devkit/core/BundleRegistry.sol | 4 ++-- devkit/core/Dictionary.sol | 34 +++++------------------------- devkit/core/DictionaryRegistry.sol | 4 ++-- devkit/core/Function.sol | 1 + devkit/core/FunctionRegistry.sol | 4 ++-- devkit/core/Proxy.sol | 4 ++-- devkit/core/ProxyRegistry.sol | 6 +++--- devkit/core/StdFunctions.sol | 4 ++-- 9 files changed, 21 insertions(+), 44 deletions(-) diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 349949a6..18d71a03 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -8,9 +8,9 @@ import {BundleLib} from "devkit/method/core/BundleLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/****************** +/**================ đŸ§ē Bundle -*******************/ +==================*/ struct Bundle { string name; Function[] functionInfos; diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/BundleRegistry.sol index 0f5a527f..84da3377 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/BundleRegistry.sol @@ -8,9 +8,9 @@ import {BundleRegistryLib} from "devkit/method/core/BundleRegistryLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/************************** +/**======================== đŸ—‚ī¸ Bundle Registry -***************************/ +==========================*/ struct BundleRegistry { mapping(bytes32 nameHash => Bundle) bundles; string currentBundleName; diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 76b0190f..afbea303 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -1,39 +1,15 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Validation -import {check} from "devkit/error/Validation.sol"; -import {Params} from "devkit/debug/Params.sol"; -// Utils -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -// Debug -import {Debug} from "devkit/debug/Debug.sol"; -// Core -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -// Test -import {MockDictionary} from "devkit/test/MockDictionary.sol"; -// External Libs -import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; -import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; -import {IBeacon} from "@oz.mc/proxy/beacon/IBeacon.sol"; -import {ERC1967Utils} from "@oz.mc/proxy/ERC1967/ERC1967Utils.sol"; - +// Methods import {DictionaryLib} from "devkit/method/core/DictionaryLib.sol"; import {DictionaryKindLib} from "devkit/method/core/DictionaryKindLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/**------------------------ - 📚 UCS Dictionary ---------------------------*/ + +/**==================== + 📚 Dictionary +======================*/ struct Dictionary { address addr; DictionaryKind kind; diff --git a/devkit/core/DictionaryRegistry.sol b/devkit/core/DictionaryRegistry.sol index 08502074..00b8f85c 100644 --- a/devkit/core/DictionaryRegistry.sol +++ b/devkit/core/DictionaryRegistry.sol @@ -8,9 +8,9 @@ import {DictionaryRegistryLib} from "devkit/method/core/DictionaryRegistryLib.so import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/****************************** +/**============================ 📚 Dictionary Registry -*******************************/ +==============================*/ struct DictionaryRegistry { mapping(bytes32 nameHash => Dictionary) deployed; mapping(bytes32 nameHash => Dictionary) mocks; diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index ee0f1f49..d43b9a49 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; +// Methods import {FunctionLib} from "devkit/method/core/FunctionLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; import {LogLib} from "devkit/method/debug/LogLib.sol"; diff --git a/devkit/core/FunctionRegistry.sol b/devkit/core/FunctionRegistry.sol index 76964754..5fa0f8b5 100644 --- a/devkit/core/FunctionRegistry.sol +++ b/devkit/core/FunctionRegistry.sol @@ -8,9 +8,9 @@ import {FunctionRegistryLib} from "devkit/method/core/FunctionRegistryLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/**--------------------------- +/**=========================== 🧩 Functions Registry ------------------------------*/ +=============================*/ struct FunctionRegistry { mapping(bytes32 nameHash => Function) customs; string currentName; diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index 93323c75..eccea95a 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -7,9 +7,9 @@ import {ProxyKindLib} from "devkit/method/core/ProxyKindLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/**************** +/**=============== 🏠 Proxy -*****************/ +=================*/ struct Proxy { address addr; ProxyKind kind; diff --git a/devkit/core/ProxyRegistry.sol b/devkit/core/ProxyRegistry.sol index 26da6c60..658d7c31 100644 --- a/devkit/core/ProxyRegistry.sol +++ b/devkit/core/ProxyRegistry.sol @@ -1,16 +1,16 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Core Types +// Core Type import {Proxy} from "devkit/core/Proxy.sol"; // Methods import {ProxyRegistryLib} from "devkit/method/core/ProxyRegistryLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/************************ +/**======================= 🏠 Proxy Registry -*************************/ +=========================*/ struct ProxyRegistry { mapping(bytes32 nameHash => Proxy) deployed; mapping(bytes32 nameHash => Proxy) mocks; diff --git a/devkit/core/StdFunctions.sol b/devkit/core/StdFunctions.sol index b27b3433..8b348aaa 100644 --- a/devkit/core/StdFunctions.sol +++ b/devkit/core/StdFunctions.sol @@ -9,9 +9,9 @@ import {StdFunctionsLib} from "devkit/method/core/StdFunctionsLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/**************************** +/**========================== 🏛 Standard Functions -*****************************/ +============================*/ struct StdFunctions { Function initSetAdmin; Function getDeps; From c2ea4ff45e6f0c394a1430a713833d58b804f5d3 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 19:09:43 +0900 Subject: [PATCH 040/111] Externalize Parser & Dumper --- devkit/core/Bundle.sol | 2 ++ devkit/core/Function.sol | 2 ++ devkit/method/core/BundleLib.sol | 21 -------------- devkit/method/core/DictionaryLib.sol | 2 +- devkit/method/core/StdFunctionsLib.sol | 6 ++-- devkit/method/debug/LogLib.sol | 22 ++++++++------- devkit/method/debug/ParseLib.sol | 38 ++++++++++++++++++++++++++ 7 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 devkit/method/debug/ParseLib.sol diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 18d71a03..56f2187f 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -6,6 +6,7 @@ import {Function} from "devkit/core/Function.sol"; // Methods import {BundleLib} from "devkit/method/core/BundleLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {ParseLib} from "devkit/method/debug/ParseLib.sol"; /**================ @@ -18,3 +19,4 @@ struct Bundle { } using BundleLib for Bundle global; using ProcessLib for Bundle global; +using ParseLib for Bundle global; diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index d43b9a49..3004f2fd 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; // Methods import {FunctionLib} from "devkit/method/core/FunctionLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {ParseLib} from "devkit/method/debug/ParseLib.sol"; import {LogLib} from "devkit/method/debug/LogLib.sol"; import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; @@ -19,5 +20,6 @@ struct Function { /// @dev Function may be different depending on the op version } using FunctionLib for Function global; using ProcessLib for Function global; +using ParseLib for Function global; using LogLib for Function global; using TypeSafetyUtils for Function global; diff --git a/devkit/method/core/BundleLib.sol b/devkit/method/core/BundleLib.sol index e1257f2b..5cc00247 100644 --- a/devkit/method/core/BundleLib.sol +++ b/devkit/method/core/BundleLib.sol @@ -100,25 +100,4 @@ library BundleLib { check(bundle.notExists(), "Bundle Info Already Exists"); return bundle; } - - - /**--------------- - 🐞 Debug - -----------------*/ - function parseAndLog(Bundle storage bundle) internal returns(Bundle storage) { - Logger.logDebug( - bundle.parse() - ); - return bundle; - } - function parse(Bundle storage bundle) internal returns(string memory message) { - message = message.append("Facade: ").append(bundle.facade); - - Function[] memory _funcs = bundle.functionInfos; - for (uint i; i < _funcs.length; ++i) { - message = message.br().append(_funcs[i].parse()); - } - console2.log(message); - } - } diff --git a/devkit/method/core/DictionaryLib.sol b/devkit/method/core/DictionaryLib.sol index d5543043..6c728fc3 100644 --- a/devkit/method/core/DictionaryLib.sol +++ b/devkit/method/core/DictionaryLib.sol @@ -32,7 +32,7 @@ import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; /**------------------------ - 📚 UCS Dictionary + 📚 Dictionary --------------------------*/ /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/devkit/method/core/StdFunctionsLib.sol b/devkit/method/core/StdFunctionsLib.sol index d68ed884..382d6337 100644 --- a/devkit/method/core/StdFunctionsLib.sol +++ b/devkit/method/core/StdFunctionsLib.sol @@ -51,7 +51,7 @@ library StdFunctionsLib { std.initSetAdmin.safeAssign("InitSetAdmin") .safeAssign(InitSetAdmin.initSetAdmin.selector) .loadAndAssignFromEnv() - .parseAndLog(); + .dump(); return std.finishProcess(pid); } @@ -60,7 +60,7 @@ library StdFunctionsLib { std.getDeps .safeAssign("GetDeps") .safeAssign(GetDeps.getDeps.selector) .loadAndAssignFromEnv() - .parseAndLog(); + .dump(); return std.finishProcess(pid); } @@ -69,7 +69,7 @@ library StdFunctionsLib { std.clone .safeAssign("Clone") .safeAssign(Clone.clone.selector) .loadAndAssignFromEnv() - .parseAndLog(); + .dump(); return std.finishProcess(pid); } diff --git a/devkit/method/debug/LogLib.sol b/devkit/method/debug/LogLib.sol index ed992488..74f40be0 100644 --- a/devkit/method/debug/LogLib.sol +++ b/devkit/method/debug/LogLib.sol @@ -2,10 +2,10 @@ pragma solidity ^0.8.24; import {Logger} from "devkit/debug/Logger.sol"; +// Core Types import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; //================ // 📊 LogLib @@ -13,16 +13,18 @@ library LogLib { /**================== 🧩 Function ====================*/ - function parseAndLog(Function storage func) internal returns(Function storage) { - Logger.log( - func.parse() - ); + function dump(Function storage func) internal returns(Function storage) { + Logger.log(func.parse()); return func; } - function parse(Function memory func) internal returns(string memory message) { - return message .append("Impl: ").append(func.implementation).comma() - .append("Selector: ").append(func.selector).comma() - .append("Name: ").append(func.name); + + + /**=============== + đŸ—‚ī¸ Bundle + =================*/ + function dump(Bundle storage bundle) internal returns(Bundle storage) { + Logger.logDebug(bundle.parse()); + return bundle; } } diff --git a/devkit/method/debug/ParseLib.sol b/devkit/method/debug/ParseLib.sol new file mode 100644 index 00000000..0d5d52eb --- /dev/null +++ b/devkit/method/debug/ParseLib.sol @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Core Types +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +// Utils +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; + +//================ +// đŸ—’ī¸ Parse Lib +library ParseLib { + /**================== + 🧩 Function + ====================*/ + function parse(Function memory func) internal returns(string memory message) { + return message .append("Impl: ").append(func.implementation).comma() + .append("Selector: ").append(func.selector).comma() + .append("Name: ").append(func.name); + } + + + /**=============== + đŸ—‚ī¸ Bundle + =================*/ + function parse(Bundle storage bundle) internal returns(string memory message) { + message = message.append("Facade: ").append(bundle.facade); + + Function[] memory _funcs = bundle.functionInfos; + for (uint i; i < _funcs.length; ++i) { + message = message.br().append(_funcs[i].parse()); + } + } + +} + + From dd71a43a455ffdd70b1d8563adfd0cd05006a6bb Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 8 Apr 2024 19:12:44 +0900 Subject: [PATCH 041/111] Rename Parser & Dumper --- devkit/core/Bundle.sol | 4 ++-- devkit/core/Function.sol | 8 ++++---- devkit/method/debug/{LogLib.sol => Dumper.sol} | 4 ++-- devkit/method/debug/{ParseLib.sol => Parser.sol} | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) rename devkit/method/debug/{LogLib.sol => Dumper.sol} (95%) rename devkit/method/debug/{ParseLib.sol => Parser.sol} (96%) diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 56f2187f..73f2ef15 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -6,7 +6,7 @@ import {Function} from "devkit/core/Function.sol"; // Methods import {BundleLib} from "devkit/method/core/BundleLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -import {ParseLib} from "devkit/method/debug/ParseLib.sol"; +import {Parser} from "devkit/method/debug/Parser.sol"; /**================ @@ -19,4 +19,4 @@ struct Bundle { } using BundleLib for Bundle global; using ProcessLib for Bundle global; -using ParseLib for Bundle global; +using Parser for Bundle global; diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index 3004f2fd..2f525253 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -4,8 +4,8 @@ pragma solidity ^0.8.24; // Methods import {FunctionLib} from "devkit/method/core/FunctionLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -import {ParseLib} from "devkit/method/debug/ParseLib.sol"; -import {LogLib} from "devkit/method/debug/LogLib.sol"; +import {Parser} from "devkit/method/debug/Parser.sol"; +import {Dumper} from "devkit/method/debug/Dumper.sol"; import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; @@ -20,6 +20,6 @@ struct Function { /// @dev Function may be different depending on the op version } using FunctionLib for Function global; using ProcessLib for Function global; -using ParseLib for Function global; -using LogLib for Function global; +using Parser for Function global; +using Dumper for Function global; using TypeSafetyUtils for Function global; diff --git a/devkit/method/debug/LogLib.sol b/devkit/method/debug/Dumper.sol similarity index 95% rename from devkit/method/debug/LogLib.sol rename to devkit/method/debug/Dumper.sol index 74f40be0..de19af8f 100644 --- a/devkit/method/debug/LogLib.sol +++ b/devkit/method/debug/Dumper.sol @@ -8,8 +8,8 @@ import {Bundle} from "devkit/core/Bundle.sol"; //================ -// 📊 LogLib -library LogLib { +// 🚰 Dumper +library Dumper { /**================== 🧩 Function ====================*/ diff --git a/devkit/method/debug/ParseLib.sol b/devkit/method/debug/Parser.sol similarity index 96% rename from devkit/method/debug/ParseLib.sol rename to devkit/method/debug/Parser.sol index 0d5d52eb..128d3e8b 100644 --- a/devkit/method/debug/ParseLib.sol +++ b/devkit/method/debug/Parser.sol @@ -9,8 +9,8 @@ import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; //================ -// đŸ—’ī¸ Parse Lib -library ParseLib { +// đŸ—’ī¸ Parser +library Parser { /**================== 🧩 Function ====================*/ From a7b386006fe069d350b22b05da549e817766218c Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 10:40:56 +0900 Subject: [PATCH 042/111] Externalize Inspector --- devkit/core/Bundle.sol | 5 +- devkit/core/BundleRegistry.sol | 5 +- devkit/core/Dictionary.sol | 7 + devkit/core/DictionaryRegistry.sol | 5 +- devkit/core/Function.sol | 3 + devkit/core/FunctionRegistry.sol | 3 +- devkit/core/Proxy.sol | 7 + devkit/core/ProxyRegistry.sol | 5 +- devkit/core/StdFunctions.sol | 1 + devkit/method/core/BundleLib.sol | 47 ---- devkit/method/core/BundleRegistryLib.sol | 24 +- devkit/method/core/DictionaryLib.sol | 47 ---- devkit/method/core/DictionaryRegistryLib.sol | 13 - devkit/method/core/FunctionLib.sol | 64 ----- devkit/method/core/ProxyLib.sol | 32 --- devkit/method/core/ProxyRegistryLib.sol | 14 +- devkit/method/inspector/Inspector.sol | 260 +++++++++++++++++++ 17 files changed, 298 insertions(+), 244 deletions(-) create mode 100644 devkit/method/inspector/Inspector.sol diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 73f2ef15..08df5a36 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -7,10 +7,11 @@ import {Function} from "devkit/core/Function.sol"; import {BundleLib} from "devkit/method/core/BundleLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; import {Parser} from "devkit/method/debug/Parser.sol"; +import {Inspector} from "devkit/method/inspector/Inspector.sol"; /**================ - đŸ§ē Bundle + đŸ—‚ī¸ Bundle ==================*/ struct Bundle { string name; @@ -18,5 +19,7 @@ struct Bundle { address facade; } using BundleLib for Bundle global; +// Support Methods using ProcessLib for Bundle global; using Parser for Bundle global; +using Inspector for Bundle global; diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/BundleRegistry.sol index 84da3377..9409353d 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/BundleRegistry.sol @@ -6,14 +6,17 @@ import {Bundle} from "devkit/core/Bundle.sol"; //Methods import {BundleRegistryLib} from "devkit/method/core/BundleRegistryLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {Inspector} from "devkit/method/inspector/Inspector.sol"; /**======================== - đŸ—‚ī¸ Bundle Registry + 📙 Bundle Registry ==========================*/ struct BundleRegistry { mapping(bytes32 nameHash => Bundle) bundles; string currentBundleName; } using BundleRegistryLib for BundleRegistry global; +// Support Methods using ProcessLib for BundleRegistry global; +using Inspector for BundleRegistry global; diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index afbea303..a101d5e0 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.24; import {DictionaryLib} from "devkit/method/core/DictionaryLib.sol"; import {DictionaryKindLib} from "devkit/method/core/DictionaryKindLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {Inspector} from "devkit/method/inspector/Inspector.sol"; /**==================== @@ -15,8 +16,14 @@ struct Dictionary { DictionaryKind kind; } using DictionaryLib for Dictionary global; +// Support Methods using ProcessLib for Dictionary global; +using Inspector for Dictionary global; + + /**-------------------- + Dictionary Kind + ----------------------*/ enum DictionaryKind { undefined, Verifiable, diff --git a/devkit/core/DictionaryRegistry.sol b/devkit/core/DictionaryRegistry.sol index 00b8f85c..c7715aee 100644 --- a/devkit/core/DictionaryRegistry.sol +++ b/devkit/core/DictionaryRegistry.sol @@ -6,10 +6,11 @@ import {Dictionary} from "./Dictionary.sol"; // Methods import {DictionaryRegistryLib} from "devkit/method/core/DictionaryRegistryLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {Inspector} from "devkit/method/inspector/Inspector.sol"; /**============================ - 📚 Dictionary Registry + 📘 Dictionary Registry ==============================*/ struct DictionaryRegistry { mapping(bytes32 nameHash => Dictionary) deployed; @@ -17,4 +18,6 @@ struct DictionaryRegistry { Dictionary currentDictionary; } using DictionaryRegistryLib for DictionaryRegistry global; +// Support Methods using ProcessLib for DictionaryRegistry global; +using Inspector for DictionaryRegistry global; diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index 2f525253..f8535fba 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -6,6 +6,7 @@ import {FunctionLib} from "devkit/method/core/FunctionLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; import {Parser} from "devkit/method/debug/Parser.sol"; import {Dumper} from "devkit/method/debug/Dumper.sol"; +import {Inspector} from "devkit/method/inspector/Inspector.sol"; import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; @@ -19,7 +20,9 @@ struct Function { /// @dev Function may be different depending on the op version BuildStatus buildStatus; } using FunctionLib for Function global; +// Support Methods using ProcessLib for Function global; using Parser for Function global; using Dumper for Function global; +using Inspector for Function global; using TypeSafetyUtils for Function global; diff --git a/devkit/core/FunctionRegistry.sol b/devkit/core/FunctionRegistry.sol index 5fa0f8b5..9408900b 100644 --- a/devkit/core/FunctionRegistry.sol +++ b/devkit/core/FunctionRegistry.sol @@ -9,11 +9,12 @@ import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; /**=========================== - 🧩 Functions Registry + 📗 Functions Registry =============================*/ struct FunctionRegistry { mapping(bytes32 nameHash => Function) customs; string currentName; } using FunctionRegistryLib for FunctionRegistry global; +// Support Methods using ProcessLib for FunctionRegistry global; diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index eccea95a..dddd49c8 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.24; import {ProxyLib} from "devkit/method/core/ProxyLib.sol"; import {ProxyKindLib} from "devkit/method/core/ProxyKindLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {Inspector} from "devkit/method/inspector/Inspector.sol"; /**=============== @@ -15,8 +16,14 @@ struct Proxy { ProxyKind kind; } using ProxyLib for Proxy global; +// Support Methods using ProcessLib for Proxy global; +using Inspector for Proxy global; + + /**--------------- + Proxy Kind + -----------------*/ enum ProxyKind { undefined, Normal, diff --git a/devkit/core/ProxyRegistry.sol b/devkit/core/ProxyRegistry.sol index 658d7c31..7675a770 100644 --- a/devkit/core/ProxyRegistry.sol +++ b/devkit/core/ProxyRegistry.sol @@ -6,10 +6,11 @@ import {Proxy} from "devkit/core/Proxy.sol"; // Methods import {ProxyRegistryLib} from "devkit/method/core/ProxyRegistryLib.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {Inspector} from "devkit/method/inspector/Inspector.sol"; /**======================= - 🏠 Proxy Registry + 📕 Proxy Registry =========================*/ struct ProxyRegistry { mapping(bytes32 nameHash => Proxy) deployed; @@ -17,4 +18,6 @@ struct ProxyRegistry { Proxy currentProxy; } using ProxyRegistryLib for ProxyRegistry global; +// Support Methods using ProcessLib for ProxyRegistry global; +using Inspector for ProxyRegistry global; diff --git a/devkit/core/StdFunctions.sol b/devkit/core/StdFunctions.sol index 8b348aaa..9e2bde72 100644 --- a/devkit/core/StdFunctions.sol +++ b/devkit/core/StdFunctions.sol @@ -19,4 +19,5 @@ struct StdFunctions { Bundle all; } using StdFunctionsLib for StdFunctions global; +// Support Methods using ProcessLib for StdFunctions global; diff --git a/devkit/method/core/BundleLib.sol b/devkit/method/core/BundleLib.sol index 5cc00247..3b80c6d8 100644 --- a/devkit/method/core/BundleLib.sol +++ b/devkit/method/core/BundleLib.sol @@ -53,51 +53,4 @@ library BundleLib { } return bundle.finishProcess(pid); } - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function has(Bundle storage bundle, Function storage functionInfo) internal view returns(bool flag) { - for (uint i; i < bundle.functionInfos.length; ++i) { - if (functionInfo.isEqual(bundle.functionInfos[i])) return true; - } - } - function hasNot(Bundle storage bundle, Function storage functionInfo) internal returns(bool) { - return bundle.has(functionInfo).isFalse(); - } - - function isComplete(Bundle storage bundle) internal returns(bool) { - return bundle.name.isNotEmpty() && - bundle.functionInfos.length != 0 && - bundle.facade.isContract(); - } - function assertComplete(Bundle storage bundle) internal returns(Bundle storage) { - check(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); - return bundle; - } - - function hasName(Bundle storage bundle) internal returns(bool) { - return bundle.name.isNotEmpty(); - } - function hasNotName(Bundle storage bundle) internal returns(bool) { - return bundle.name.isEmpty(); - } - - function exists(Bundle storage bundle) internal returns(bool) { - return bundle.name.isNotEmpty() || - bundle.functionInfos.length != 0 || - bundle.facade.isNotContract(); - } - function notExists(Bundle storage bundle) internal returns(bool) { - return bundle.exists().isNot(); - } - function assertExists(Bundle storage bundle) internal returns(Bundle storage) { - check(bundle.exists(), "Bundle Info Not Exists"); - return bundle; - } - function assertNotExists(Bundle storage bundle) internal returns(Bundle storage) { - check(bundle.notExists(), "Bundle Info Already Exists"); - return bundle; - } } diff --git a/devkit/method/core/BundleRegistryLib.sol b/devkit/method/core/BundleRegistryLib.sol index 5b31ef96..a0644443 100644 --- a/devkit/method/core/BundleRegistryLib.sol +++ b/devkit/method/core/BundleRegistryLib.sol @@ -20,7 +20,7 @@ import {StdFunctions} from "devkit/core/StdFunctions.sol"; import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; /**------------------------------- - 🧩 Functions Registry + 🧩 Bundle Registry ---------------------------------*/ /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -138,26 +138,4 @@ library BundleRegistryLib { throwError(ERR.FIND_NAME_OVER_RANGE); } - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function existsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { - return bundle.bundles[name.safeCalcHash()].hasName(); - } - function notExistsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { - return bundle.existsBundle(name).isNot(); - } - function assertBundleNotExists(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - check(bundle.notExistsBundle(name), "Bundle Already Exists"); - return bundle; - } - - function existsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { - return bundle.currentBundleName.isNotEmpty(); - } - function notExistsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { - return bundle.existsCurrentBundle().isNot(); - } } diff --git a/devkit/method/core/DictionaryLib.sol b/devkit/method/core/DictionaryLib.sol index 6c728fc3..c89ed751 100644 --- a/devkit/method/core/DictionaryLib.sol +++ b/devkit/method/core/DictionaryLib.sol @@ -154,53 +154,6 @@ library DictionaryLib { - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function exists(Dictionary storage dictionary) internal returns(bool) { - return dictionary.addr.isContract(); - } - function assertExists(Dictionary storage dictionary) internal returns(Dictionary storage) { - check(dictionary.exists(), "Dictionary Not Exists"); - return dictionary; - } - - function isNotEmpty(Dictionary memory dictionary) internal returns(bool) { - return dictionary.addr.isContract(); - } - function assertNotEmpty(Dictionary memory dictionary) internal returns(Dictionary memory) { - check(dictionary.isNotEmpty(), "Empty Dictionary"); - return dictionary; - } - - function isSupported(Dictionary memory dictionary, bytes4 selector) internal view returns(bool) { - return IDictionary(dictionary.addr).supportsInterface(selector); - } - function assertSupports(Dictionary storage dictionary, bytes4 selector) internal returns(Dictionary storage) { - check(dictionary.isSupported(selector), "Unsupported Selector"); - return dictionary; - } - - function isVerifiable(Dictionary memory dictionary) internal returns(bool) { - (bool success,) = dictionary.addr.call(abi.encodeWithSelector(IBeacon.implementation.selector)); - return success; - } - function assertVerifiable(Dictionary memory dictionary) internal returns(Dictionary memory) { - check(dictionary.isVerifiable(), "Dictionary Not Verifiable"); - return dictionary; - } - - function isMock(Dictionary memory dictionary) internal pure returns(bool) { - return dictionary.kind == DictionaryKind.Mock; - } - function isNotMock(Dictionary memory dictionary) internal returns(bool) { - return dictionary.isMock().isNot(); - } - // function isUUPS(Dictionary dictionary) internal returns(bool) { - // return UUPSUpgradeable(dictionary.toAddress()).proxiableUUID() == ERC1967Utils.IMPLEMENTATION_SLOT; - // } - - // function assignLabel(Dictionary storage dictionary, string memory name) internal returns(Dictionary storage) { // ForgeHelper.assignLabel(dictionary.addr, name); // return dictionary; diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol index a37e1841..eb79c57f 100644 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -129,17 +129,4 @@ library DictionaryRegistryLib { } throwError(ERR.FIND_NAME_OVER_RANGE); } - - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function existsInDeployed(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { - return dictionaries.deployed[name.safeCalcHash()].exists(); - } - function existsInMocks(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { - return dictionaries.mocks[name.safeCalcHash()].exists(); - } - } diff --git a/devkit/method/core/FunctionLib.sol b/devkit/method/core/FunctionLib.sol index 90fd9048..6082bf66 100644 --- a/devkit/method/core/FunctionLib.sol +++ b/devkit/method/core/FunctionLib.sol @@ -144,68 +144,4 @@ library FunctionLib { return func.loadAndAssignFromEnv(envKey, name, selector).finishProcess(pid); } - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function exists(Function memory func) internal returns(bool) { - return func.implementation.isContract(); - } - - function assignLabel(Function storage func) internal returns(Function storage) { - if (func.exists()) { - ForgeHelper.assignLabel(func.implementation, func.name); - } - return func; - } - - function assertExists(Function storage func) internal returns(Function storage) { - check(func.exists(), "func does not exists"); - return func; - } - - function assertEmptyName(Function storage func) internal returns(Function storage) { - Check.isUnassigned(func.name); - return func; - } - function assertEmptySelector(Function storage func) internal returns(Function storage) { - Check.isUnassigned(func.selector); - return func; - } - function assertEmptyImpl(Function storage func) internal returns(Function storage) { - check(func.implementation.isNotContract(), "Implementation Already Exist"); - return func; - } - - function assertNotEmpty(Function storage func) internal returns(Function storage) { - check(func.exists(), "Empty Deployed Contract"); - return func; - } - - function assertNotIncludedIn(Function storage func, Bundle storage bundleInfo) internal returns(Function storage) { - check(bundleInfo.hasNot(func), "Already exists in the Bundel"); - return func; - } - - function assertImplIsContract(Function storage func) internal returns(Function storage) { - check(func.implementation.isContract(), "Implementation Not Contract"); - return func; - } - - function isComplete(Function storage func) internal returns(bool) { - return func.name.isNotEmpty() && - func.selector.isNotEmpty() && - func.implementation.isContract(); - } - function assertComplete(Function storage func) internal returns(Function storage) { - check(func.isComplete(), "Function Info Not Complete"); - return func; - } - - function isEqual(Function memory a, Function memory b) internal pure returns(bool) { - return keccak256(abi.encode(a)) == keccak256(abi.encode(b)); - } - - - } diff --git a/devkit/method/core/ProxyLib.sol b/devkit/method/core/ProxyLib.sol index dbb4e9a0..682d4796 100644 --- a/devkit/method/core/ProxyLib.sol +++ b/devkit/method/core/ProxyLib.sol @@ -100,36 +100,4 @@ library ProxyLib { // function changeDictionary(Proxy storage proxy) internal {} - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function exists(Proxy storage proxy) internal returns(bool) { - return proxy.addr.isContract(); - } - function assertExists(Proxy storage proxy) internal returns(Proxy storage) { - check(proxy.exists(), "Proxy Not Exist"); - return proxy; - } - - function isNotEmpty(Proxy memory proxy) internal returns(bool) { - return proxy.addr.isContract(); - } - function assertNotEmpty(Proxy memory proxy) internal returns(Proxy memory) { - check(proxy.isNotEmpty(), "Empty Proxy"); - return proxy; - } - - function isMock(Proxy memory proxy) internal pure returns(bool) { - return proxy.kind == ProxyKind.Mock; - } - function isNotMock(Proxy memory proxy) internal returns(bool) { - return proxy.isMock().isNot(); - } - - function assignLabel(Proxy storage proxy, string memory name) internal returns(Proxy storage) { - ForgeHelper.assignLabel(proxy.addr, name); - return proxy; - } - } diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol index 4fe453ef..b22c6edd 100644 --- a/devkit/method/core/ProxyRegistryLib.sol +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -19,7 +19,7 @@ import {Dictionary} from "devkit/core/Dictionary.sol"; import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🏠 UCS Proxy Registry + 🏠 Proxy Registry << Primary >> đŸ“Ĩ Add Proxy đŸ”ŧ Update Current Context Proxy @@ -120,16 +120,4 @@ library ProxyRegistryLib { throwError(ERR.FIND_NAME_OVER_RANGE); } - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function existsInDeployed(ProxyRegistry storage proxies, string memory name) internal returns(bool) { - return proxies.deployed[name.safeCalcHash()].exists(); - } - function existsInMocks(ProxyRegistry storage proxies, string memory name) internal returns(bool) { - return proxies.mocks[name.safeCalcHash()].exists(); - } - } diff --git a/devkit/method/inspector/Inspector.sol b/devkit/method/inspector/Inspector.sol new file mode 100644 index 00000000..90909b18 --- /dev/null +++ b/devkit/method/inspector/Inspector.sol @@ -0,0 +1,260 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {check, Check} from "devkit/error/Validation.sol"; +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; + using AddressUtils for address; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; + using Bytes4Utils for bytes4; +import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; +// External Library +import {IBeacon} from "@oz.mc/proxy/beacon/IBeacon.sol"; +import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; +// Core Types +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; +import {Proxy, ProxyKind} from "devkit/core/Proxy.sol"; +import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; +import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; +import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; + + +/**------------------------------- + 🧐 Inspectors & Assertions +---------------------------------*/ +library Inspector { + /**================== + 🧩 Function + ====================*/ + function exists(Function memory func) internal returns(bool) { + return func.implementation.isContract(); + } + + function assignLabel(Function storage func) internal returns(Function storage) { + if (func.exists()) { + ForgeHelper.assignLabel(func.implementation, func.name); + } + return func; + } + + function assertExists(Function storage func) internal returns(Function storage) { + check(func.exists(), "func does not exists"); + return func; + } + + function assertEmptyName(Function storage func) internal returns(Function storage) { + Check.isUnassigned(func.name); + return func; + } + function assertEmptySelector(Function storage func) internal returns(Function storage) { + Check.isUnassigned(func.selector); + return func; + } + function assertEmptyImpl(Function storage func) internal returns(Function storage) { + check(func.implementation.isNotContract(), "Implementation Already Exist"); + return func; + } + + function assertNotEmpty(Function storage func) internal returns(Function storage) { + check(func.exists(), "Empty Deployed Contract"); + return func; + } + + function assertNotIncludedIn(Function storage func, Bundle storage bundleInfo) internal returns(Function storage) { + check(bundleInfo.hasNot(func), "Already exists in the Bundel"); + return func; + } + + function assertImplIsContract(Function storage func) internal returns(Function storage) { + check(func.implementation.isContract(), "Implementation Not Contract"); + return func; + } + + function isComplete(Function storage func) internal returns(bool) { + return func.name.isNotEmpty() && + func.selector.isNotEmpty() && + func.implementation.isContract(); + } + function assertComplete(Function storage func) internal returns(Function storage) { + check(func.isComplete(), "Function Info Not Complete"); + return func; + } + + function isEqual(Function memory a, Function memory b) internal pure returns(bool) { + return keccak256(abi.encode(a)) == keccak256(abi.encode(b)); + } + + + /**=============== + đŸ—‚ī¸ Bundle + =================*/ + function has(Bundle storage bundle, Function storage functionInfo) internal view returns(bool flag) { + for (uint i; i < bundle.functionInfos.length; ++i) { + if (functionInfo.isEqual(bundle.functionInfos[i])) return true; + } + } + function hasNot(Bundle storage bundle, Function storage functionInfo) internal returns(bool) { + return bundle.has(functionInfo).isFalse(); + } + + function isComplete(Bundle storage bundle) internal returns(bool) { + return bundle.name.isNotEmpty() && + bundle.functionInfos.length != 0 && + bundle.facade.isContract(); + } + function assertComplete(Bundle storage bundle) internal returns(Bundle storage) { + check(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); + return bundle; + } + + function hasName(Bundle storage bundle) internal returns(bool) { + return bundle.name.isNotEmpty(); + } + function hasNotName(Bundle storage bundle) internal returns(bool) { + return bundle.name.isEmpty(); + } + + function exists(Bundle storage bundle) internal returns(bool) { + return bundle.name.isNotEmpty() || + bundle.functionInfos.length != 0 || + bundle.facade.isNotContract(); + } + function notExists(Bundle storage bundle) internal returns(bool) { + return bundle.exists().isNot(); + } + function assertExists(Bundle storage bundle) internal returns(Bundle storage) { + check(bundle.exists(), "Bundle Info Not Exists"); + return bundle; + } + function assertNotExists(Bundle storage bundle) internal returns(Bundle storage) { + check(bundle.notExists(), "Bundle Info Already Exists"); + return bundle; + } + + + /**======================= + đŸ—‚ī¸ Bundle Registry + =========================*/ + function existsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { + return bundle.bundles[name.safeCalcHash()].hasName(); + } + function notExistsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { + return bundle.existsBundle(name).isNot(); + } + function assertBundleNotExists(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + check(bundle.notExistsBundle(name), "Bundle Already Exists"); + return bundle; + } + + function existsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { + return bundle.currentBundleName.isNotEmpty(); + } + function notExistsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { + return bundle.existsCurrentBundle().isNot(); + } + + + /**============== + 🏠 Proxy + ================*/ + function exists(Proxy storage proxy) internal returns(bool) { + return proxy.addr.isContract(); + } + function assertExists(Proxy storage proxy) internal returns(Proxy storage) { + check(proxy.exists(), "Proxy Not Exist"); + return proxy; + } + + function isNotEmpty(Proxy memory proxy) internal returns(bool) { + return proxy.addr.isContract(); + } + function assertNotEmpty(Proxy memory proxy) internal returns(Proxy memory) { + check(proxy.isNotEmpty(), "Empty Proxy"); + return proxy; + } + + function isMock(Proxy memory proxy) internal pure returns(bool) { + return proxy.kind == ProxyKind.Mock; + } + function isNotMock(Proxy memory proxy) internal returns(bool) { + return proxy.isMock().isNot(); + } + + function assignLabel(Proxy storage proxy, string memory name) internal returns(Proxy storage) { + ForgeHelper.assignLabel(proxy.addr, name); + return proxy; + } + + /**======================= + 🏠 Proxy Registry + =========================*/ + function existsInDeployed(ProxyRegistry storage proxies, string memory name) internal returns(bool) { + return proxies.deployed[name.safeCalcHash()].exists(); + } + function existsInMocks(ProxyRegistry storage proxies, string memory name) internal returns(bool) { + return proxies.mocks[name.safeCalcHash()].exists(); + } + + + /**==================== + 📚 Dictionary + ======================*/ + function exists(Dictionary storage dictionary) internal returns(bool) { + return dictionary.addr.isContract(); + } + function assertExists(Dictionary storage dictionary) internal returns(Dictionary storage) { + check(dictionary.exists(), "Dictionary Not Exists"); + return dictionary; + } + + function isNotEmpty(Dictionary memory dictionary) internal returns(bool) { + return dictionary.addr.isContract(); + } + function assertNotEmpty(Dictionary memory dictionary) internal returns(Dictionary memory) { + check(dictionary.isNotEmpty(), "Empty Dictionary"); + return dictionary; + } + + function isSupported(Dictionary memory dictionary, bytes4 selector) internal view returns(bool) { + return IDictionary(dictionary.addr).supportsInterface(selector); + } + function assertSupports(Dictionary storage dictionary, bytes4 selector) internal returns(Dictionary storage) { + check(dictionary.isSupported(selector), "Unsupported Selector"); + return dictionary; + } + + function isVerifiable(Dictionary memory dictionary) internal returns(bool) { + (bool success,) = dictionary.addr.call(abi.encodeWithSelector(IBeacon.implementation.selector)); + return success; + } + function assertVerifiable(Dictionary memory dictionary) internal returns(Dictionary memory) { + check(dictionary.isVerifiable(), "Dictionary Not Verifiable"); + return dictionary; + } + + function isMock(Dictionary memory dictionary) internal pure returns(bool) { + return dictionary.kind == DictionaryKind.Mock; + } + function isNotMock(Dictionary memory dictionary) internal returns(bool) { + return dictionary.isMock().isNot(); + } + // function isUUPS(Dictionary dictionary) internal returns(bool) { + // return UUPSUpgradeable(dictionary.toAddress()).proxiableUUID() == ERC1967Utils.IMPLEMENTATION_SLOT; + // } + + + /**============================ + 📚 Dictionary Registry + ==============================*/ + function existsInDeployed(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { + return dictionaries.deployed[name.safeCalcHash()].exists(); + } + function existsInMocks(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { + return dictionaries.mocks[name.safeCalcHash()].exists(); + } +} From 8248d9559fa199d642a3f5d97b673554eeb2178f Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 11:26:59 +0900 Subject: [PATCH 043/111] chore update pretty --- devkit/core/Bundle.sol | 3 ++- devkit/core/BundleRegistry.sol | 3 ++- devkit/core/Dictionary.sol | 6 +++--- devkit/core/DictionaryRegistry.sol | 3 ++- devkit/core/Function.sol | 3 ++- devkit/core/FunctionRegistry.sol | 3 ++- devkit/core/Proxy.sol | 6 +++--- devkit/core/ProxyRegistry.sol | 3 ++- devkit/core/StdFunctions.sol | 3 ++- devkit/method/core/BundleLib.sol | 6 +++++- devkit/method/core/BundleRegistryLib.sol | 8 +------- devkit/method/core/DictionaryKindLib.sol | 18 ----------------- devkit/method/core/DictionaryLib.sol | 12 +++-------- devkit/method/core/DictionaryRegistryLib.sol | 11 ++-------- devkit/method/core/FunctionLib.sol | 8 +------- devkit/method/core/FunctionRegistryLib.sol | 11 ++++------ devkit/method/core/ProxyKindLib.sol | 20 ------------------- devkit/method/core/ProxyLib.sol | 11 ++-------- devkit/method/core/ProxyRegistryLib.sol | 7 +------ devkit/method/core/StdFunctionsLib.sol | 10 ++++------ devkit/method/inspector/Inspector.sol | 21 ++++++++++++++++++++ 21 files changed, 64 insertions(+), 112 deletions(-) delete mode 100644 devkit/method/core/DictionaryKindLib.sol delete mode 100644 devkit/method/core/ProxyKindLib.sol diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 08df5a36..ac4a9d4b 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -3,8 +3,9 @@ pragma solidity ^0.8.24; // Core Type import {Function} from "devkit/core/Function.sol"; -// Methods +// Core Method import {BundleLib} from "devkit/method/core/BundleLib.sol"; +// Support Methods import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; import {Parser} from "devkit/method/debug/Parser.sol"; import {Inspector} from "devkit/method/inspector/Inspector.sol"; diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/BundleRegistry.sol index 9409353d..5623c5dd 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/BundleRegistry.sol @@ -3,8 +3,9 @@ pragma solidity ^0.8.24; // Core Type import {Bundle} from "devkit/core/Bundle.sol"; -//Methods +// Core Method import {BundleRegistryLib} from "devkit/method/core/BundleRegistryLib.sol"; +// Support Methods import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; import {Inspector} from "devkit/method/inspector/Inspector.sol"; diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index a101d5e0..c2a9306a 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Methods +// Core Method import {DictionaryLib} from "devkit/method/core/DictionaryLib.sol"; -import {DictionaryKindLib} from "devkit/method/core/DictionaryKindLib.sol"; +// Support Methods import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; import {Inspector} from "devkit/method/inspector/Inspector.sol"; @@ -29,4 +29,4 @@ using Inspector for Dictionary global; Verifiable, Mock } - using DictionaryKindLib for DictionaryKind global; + using Inspector for DictionaryKind global; diff --git a/devkit/core/DictionaryRegistry.sol b/devkit/core/DictionaryRegistry.sol index c7715aee..aff949fa 100644 --- a/devkit/core/DictionaryRegistry.sol +++ b/devkit/core/DictionaryRegistry.sol @@ -3,8 +3,9 @@ pragma solidity ^0.8.24; // Core Type import {Dictionary} from "./Dictionary.sol"; -// Methods +// Core Method import {DictionaryRegistryLib} from "devkit/method/core/DictionaryRegistryLib.sol"; +// Support Methods import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; import {Inspector} from "devkit/method/inspector/Inspector.sol"; diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index f8535fba..2954fc84 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -1,8 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Methods +// Core Method import {FunctionLib} from "devkit/method/core/FunctionLib.sol"; +// Support Methods import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; import {Parser} from "devkit/method/debug/Parser.sol"; import {Dumper} from "devkit/method/debug/Dumper.sol"; diff --git a/devkit/core/FunctionRegistry.sol b/devkit/core/FunctionRegistry.sol index 9408900b..561999f4 100644 --- a/devkit/core/FunctionRegistry.sol +++ b/devkit/core/FunctionRegistry.sol @@ -3,8 +3,9 @@ pragma solidity ^0.8.24; // Core Type import {Function} from "devkit/core/Function.sol"; -// Methods +// Core Method import {FunctionRegistryLib} from "devkit/method/core/FunctionRegistryLib.sol"; +// Support Method import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index dddd49c8..084c741d 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Methods +// Core Method import {ProxyLib} from "devkit/method/core/ProxyLib.sol"; -import {ProxyKindLib} from "devkit/method/core/ProxyKindLib.sol"; +// Support Methods import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; import {Inspector} from "devkit/method/inspector/Inspector.sol"; @@ -30,4 +30,4 @@ using Inspector for Proxy global; Verifiable, Mock } - using ProxyKindLib for ProxyKind global; + using Inspector for ProxyKind global; diff --git a/devkit/core/ProxyRegistry.sol b/devkit/core/ProxyRegistry.sol index 7675a770..b0ac4a5a 100644 --- a/devkit/core/ProxyRegistry.sol +++ b/devkit/core/ProxyRegistry.sol @@ -3,8 +3,9 @@ pragma solidity ^0.8.24; // Core Type import {Proxy} from "devkit/core/Proxy.sol"; -// Methods +// Core Method import {ProxyRegistryLib} from "devkit/method/core/ProxyRegistryLib.sol"; +// Support Methods import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; import {Inspector} from "devkit/method/inspector/Inspector.sol"; diff --git a/devkit/core/StdFunctions.sol b/devkit/core/StdFunctions.sol index 9e2bde72..a71a0694 100644 --- a/devkit/core/StdFunctions.sol +++ b/devkit/core/StdFunctions.sol @@ -4,8 +4,9 @@ pragma solidity ^0.8.24; // Core Types import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; -// Methods +// Core Methods import {StdFunctionsLib} from "devkit/method/core/StdFunctionsLib.sol"; +// Support Method import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; diff --git a/devkit/method/core/BundleLib.sol b/devkit/method/core/BundleLib.sol index 3b80c6d8..d9f4c021 100644 --- a/devkit/method/core/BundleLib.sol +++ b/devkit/method/core/BundleLib.sol @@ -21,8 +21,12 @@ import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; -library BundleLib { +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~ + đŸ—‚ī¸ Bundle + đŸ“Ĩ Assign Bundle +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library BundleLib { /**--------------------------- đŸ“Ĩ Assign Bundle -----------------------------*/ diff --git a/devkit/method/core/BundleRegistryLib.sol b/devkit/method/core/BundleRegistryLib.sol index a0644443..d75d8213 100644 --- a/devkit/method/core/BundleRegistryLib.sol +++ b/devkit/method/core/BundleRegistryLib.sol @@ -19,12 +19,9 @@ import {StdFunctions} from "devkit/core/StdFunctions.sol"; import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; -/**------------------------------- - 🧩 Bundle Registry ----------------------------------*/ /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> + 📙 Bundle Registry 🌱 Init Bundle ✨ Add Custom Function 🔏 Load and Assign Custom Function from Env @@ -33,12 +30,9 @@ import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; đŸ”ŧ Update Current Context Function & Bundle 🔍 Find Function & Bundle 🏷 Generate Unique Name - << Helper >> 🔍 Find Custom Function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library BundleRegistryLib { - - /**--------------------- 🌱 Init Bundle -----------------------*/ diff --git a/devkit/method/core/DictionaryKindLib.sol b/devkit/method/core/DictionaryKindLib.sol deleted file mode 100644 index 673a9ab4..00000000 --- a/devkit/method/core/DictionaryKindLib.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import {check} from "devkit/error/Validation.sol"; -import {DictionaryKind} from "devkit/core/Dictionary.sol"; - -/**------------------------ - 📚 Dictionary Kind ---------------------------*/ -library DictionaryKindLib { - function isNotUndefined(DictionaryKind kind) internal pure returns(bool) { - return kind != DictionaryKind.undefined; - } - function assertNotUndefined(DictionaryKind kind) internal returns(DictionaryKind) { - check(kind.isNotUndefined(), "Undefined Dictionary Kind"); - return kind; - } -} diff --git a/devkit/method/core/DictionaryLib.sol b/devkit/method/core/DictionaryLib.sol index c89ed751..da310460 100644 --- a/devkit/method/core/DictionaryLib.sol +++ b/devkit/method/core/DictionaryLib.sol @@ -31,20 +31,14 @@ import {ERC1967Utils} from "@oz.mc/proxy/ERC1967/ERC1967Utils.sol"; import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/**------------------------ - 📚 Dictionary ---------------------------*/ /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> + 📚 Dictionary 🚀 Deploy Dictionary 🔂 Duplicate Dictionary - 🧩 Set Function + 🧩 Set Function or Bundle đŸĒŸ Upgrade Facade 🤖 Create Mock Dictionary - << Helper >> - 🧐 Inspectors & Assertions - 🐞 Debug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library DictionaryLib { /**------------------------- @@ -103,7 +97,7 @@ library DictionaryLib { /**----------------------------- - 🧩 Set Function & Bundle + 🧩 Set Function or Bundle -------------------------------*/ function set(Dictionary memory dictionary, Function memory functionInfo) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(functionInfo.name)); diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol index eb79c57f..1377e20a 100644 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -19,23 +19,16 @@ import {Dictionary} from "devkit/core/Dictionary.sol"; import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; -/****************************** - 📚 Dictionary Registry -*******************************/ + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> + 📘 Dictionary Registry đŸ“Ĩ Add Dictionary đŸ”ŧ Update Current Context Dictionary â™ģī¸ Reset Current Context Dictionary 🔍 Find Dictionary 🏷 Generate Unique Name - << Helper >> - 🧐 Inspectors & Assertions - 🐞 Debug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library DictionaryRegistryLib { - - /**------------------------ đŸ“Ĩ Add Dictionary --------------------------*/ diff --git a/devkit/method/core/FunctionLib.sol b/devkit/method/core/FunctionLib.sol index 6082bf66..48119f46 100644 --- a/devkit/method/core/FunctionLib.sol +++ b/devkit/method/core/FunctionLib.sol @@ -19,14 +19,8 @@ import {BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> + 🧩 Function đŸ“Ĩ Assign Function - đŸ”ŧ Update Current Context Proxy - 🔍 Find Proxy - 🏷 Generate Unique Name - << Helper >> - 🧐 Inspectors & Assertions - 🐞 Debug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library FunctionLib { /**------------------------ diff --git a/devkit/method/core/FunctionRegistryLib.sol b/devkit/method/core/FunctionRegistryLib.sol index bddaaa3d..364d2c86 100644 --- a/devkit/method/core/FunctionRegistryLib.sol +++ b/devkit/method/core/FunctionRegistryLib.sol @@ -19,17 +19,14 @@ import {StdFunctions} from "devkit/core/StdFunctions.sol"; import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; -/**--------------------------- - 🧩 Functions Registry ------------------------------*/ + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> + 📗 Functions Registry ✨ Add Custom Function 🔏 Load and Assign Custom Function from Env đŸ”ŧ Update Current Context Function + â™ģī¸ Reset Current Context Function & Bundle 🔍 Find Function - << Helper >> - 🔍 Find Custom Function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library FunctionRegistryLib { /**--------------------------- @@ -60,7 +57,7 @@ library FunctionRegistryLib { /**------------------------------------------------ - đŸ”ŧ Update Current Context + đŸ”ŧ Update Current Context Function --------------------------------------------------*/ function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { uint pid = functions.startProcess("safeUpdateCurrentFunction"); diff --git a/devkit/method/core/ProxyKindLib.sol b/devkit/method/core/ProxyKindLib.sol deleted file mode 100644 index bf80b9fb..00000000 --- a/devkit/method/core/ProxyKindLib.sol +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Errors & Debug -import {check} from "devkit/error/Validation.sol"; -// Core Type -import {ProxyKind} from "devkit/core/Proxy.sol"; - -/**--------------- - 🏠 Proxy ------------------*/ -library ProxyKindLib { - function isNotUndefined(ProxyKind kind) internal pure returns(bool) { - return kind != ProxyKind.undefined; - } - function assertNotUndefined(ProxyKind kind) internal returns(ProxyKind) { - check(kind.isNotUndefined(), "Undefined Proxy Kind"); - return kind; - } -} diff --git a/devkit/method/core/ProxyLib.sol b/devkit/method/core/ProxyLib.sol index 682d4796..c0b7265c 100644 --- a/devkit/method/core/ProxyLib.sol +++ b/devkit/method/core/ProxyLib.sol @@ -27,22 +27,15 @@ import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; import {Proxy, ProxyKind} from "devkit/core/Proxy.sol"; import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -/**--------------- - 🏠 Proxy ------------------*/ /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - << Primary >> + 🏠 Proxy 🚀 Deploy Proxy - 🤖 Create Mock Proxy << Helper >> đŸ§Ē Test Utils - 🐞 Debug - 🧐 Inspectors & Assertions + 🤖 Create Mock Proxy ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library ProxyLib { - - /**--------------------- 🚀 Deploy Proxy -----------------------*/ diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol index b22c6edd..829d09f9 100644 --- a/devkit/method/core/ProxyRegistryLib.sol +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -18,21 +18,16 @@ import {Dictionary} from "devkit/core/Dictionary.sol"; import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 🏠 Proxy Registry - << Primary >> đŸ“Ĩ Add Proxy đŸ”ŧ Update Current Context Proxy â™ģī¸ Reset Current Context Proxy 🔍 Find Proxy 🏷 Generate Unique Name - << Helper >> - 🧐 Inspectors & Assertions - 🐞 Debug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library ProxyRegistryLib { - - /**------------------- đŸ“Ĩ Add Proxy ---------------------*/ diff --git a/devkit/method/core/StdFunctionsLib.sol b/devkit/method/core/StdFunctionsLib.sol index 382d6337..37a98db1 100644 --- a/devkit/method/core/StdFunctionsLib.sol +++ b/devkit/method/core/StdFunctionsLib.sol @@ -23,14 +23,12 @@ import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; -/***************************************** - 🏛 Meta Contract Standard Functions -******************************************/ /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🔏 Assign and Load Standard Functions - đŸŖ Deploy Standard Functions If Not Exists - đŸ§ē Configure Standard Bundles + 🏛 Standard Functions + 🔏 Assign and Load Standard Functions + đŸŖ Deploy Standard Functions If Not Exists + đŸ§ē Configure Standard Bundles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library StdFunctionsLib { diff --git a/devkit/method/inspector/Inspector.sol b/devkit/method/inspector/Inspector.sol index 90909b18..a0ba4bf8 100644 --- a/devkit/method/inspector/Inspector.sol +++ b/devkit/method/inspector/Inspector.sol @@ -190,6 +190,17 @@ library Inspector { return proxy; } + /**~~~~~~~~~~~~~~~~~~~ + 🏠 Proxy Kind + ~~~~~~~~~~~~~~~~~~~~~*/ + function isNotUndefined(ProxyKind kind) internal pure returns(bool) { + return kind != ProxyKind.undefined; + } + function assertNotUndefined(ProxyKind kind) internal returns(ProxyKind) { + check(kind.isNotUndefined(), "Undefined Proxy Kind"); + return kind; + } + /**======================= 🏠 Proxy Registry =========================*/ @@ -247,6 +258,16 @@ library Inspector { // return UUPSUpgradeable(dictionary.toAddress()).proxiableUUID() == ERC1967Utils.IMPLEMENTATION_SLOT; // } + /**------------------------ + 📚 Dictionary Kind + --------------------------*/ + function isNotUndefined(DictionaryKind kind) internal pure returns(bool) { + return kind != DictionaryKind.undefined; + } + function assertNotUndefined(DictionaryKind kind) internal returns(DictionaryKind) { + check(kind.isNotUndefined(), "Undefined Dictionary Kind"); + return kind; + } /**============================ 📚 Dictionary Registry From 7a741c19c695ba8982f14575cf1e149217e5dea5 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 11:51:51 +0900 Subject: [PATCH 044/111] Separate MockRegistry from Proxy, Dictionary registry --- devkit/MCDevKit.sol | 2 + devkit/core/DictionaryRegistry.sol | 1 - devkit/core/MockRegistry.sol | 24 +++++ devkit/core/ProxyRegistry.sol | 1 - devkit/method/MCFinderLib.sol | 2 +- devkit/method/MCTestLib.sol | 18 ++-- devkit/method/core/DictionaryRegistryLib.sol | 20 +--- devkit/method/core/MockRegistryLib.sol | 108 +++++++++++++++++++ devkit/method/core/ProxyRegistryLib.sol | 20 +--- devkit/method/debug/ProcessLib.sol | 17 +++ devkit/method/inspector/Inspector.sol | 12 +-- 11 files changed, 169 insertions(+), 56 deletions(-) create mode 100644 devkit/core/MockRegistry.sol create mode 100644 devkit/method/core/MockRegistryLib.sol diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index 172db8c9..31f39ffd 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -7,6 +7,7 @@ import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; +import {MockRegistry} from "devkit/core/MockRegistry.sol"; // Global Methods import {MCSetupLib} from "devkit/method/MCSetupLib.sol"; @@ -27,6 +28,7 @@ struct MCDevKit { BundleRegistry bundle; DictionaryRegistry dictionary; ProxyRegistry proxy; + MockRegistry mock; } using MCSetupLib for MCDevKit global; using MCBundleLib for MCDevKit global; diff --git a/devkit/core/DictionaryRegistry.sol b/devkit/core/DictionaryRegistry.sol index aff949fa..1dee6083 100644 --- a/devkit/core/DictionaryRegistry.sol +++ b/devkit/core/DictionaryRegistry.sol @@ -15,7 +15,6 @@ import {Inspector} from "devkit/method/inspector/Inspector.sol"; ==============================*/ struct DictionaryRegistry { mapping(bytes32 nameHash => Dictionary) deployed; - mapping(bytes32 nameHash => Dictionary) mocks; Dictionary currentDictionary; } using DictionaryRegistryLib for DictionaryRegistry global; diff --git a/devkit/core/MockRegistry.sol b/devkit/core/MockRegistry.sol new file mode 100644 index 00000000..317a4b0f --- /dev/null +++ b/devkit/core/MockRegistry.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Core Types +import {Proxy} from "devkit/core/Proxy.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; +// Core Method +import {MockRegistryLib} from "devkit/method/core/MockRegistryLib.sol"; +// Support Methods +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {Inspector} from "devkit/method/inspector/Inspector.sol"; + + +/**====================== + 🏭 Mock Registry +========================*/ +struct MockRegistry { + mapping(bytes32 nameHash => Proxy) proxy; + mapping(bytes32 nameHash => Dictionary) dictionary; +} +using MockRegistryLib for MockRegistry global; +// Support Methods +using ProcessLib for MockRegistry global; +using Inspector for MockRegistry global; diff --git a/devkit/core/ProxyRegistry.sol b/devkit/core/ProxyRegistry.sol index b0ac4a5a..938de211 100644 --- a/devkit/core/ProxyRegistry.sol +++ b/devkit/core/ProxyRegistry.sol @@ -15,7 +15,6 @@ import {Inspector} from "devkit/method/inspector/Inspector.sol"; =========================*/ struct ProxyRegistry { mapping(bytes32 nameHash => Proxy) deployed; - mapping(bytes32 nameHash => Proxy) mocks; Proxy currentProxy; } using ProxyRegistryLib for ProxyRegistry global; diff --git a/devkit/method/MCFinderLib.sol b/devkit/method/MCFinderLib.sol index ece775e1..50c924ed 100644 --- a/devkit/method/MCFinderLib.sol +++ b/devkit/method/MCFinderLib.sol @@ -76,7 +76,7 @@ library MCFinderLib { return mc.dictionary.find(name); } function findMockDictionary(MCDevKit storage mc, string memory name) internal returns(Dictionary storage) { - return mc.dictionary.findMockDictionary(name); + return mc.mock.findMockDictionary(name); } function toDictionaryAddress(MCDevKit storage mc) internal returns(address) { diff --git a/devkit/method/MCTestLib.sol b/devkit/method/MCTestLib.sol index 63808344..2396824e 100644 --- a/devkit/method/MCTestLib.sol +++ b/devkit/method/MCTestLib.sol @@ -51,12 +51,12 @@ library MCTestLib { function createSimpleMockProxy(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { return mc.createSimpleMockProxy(name, mc.std.all); } - function createSimpleMockProxy(MCDevKit storage mc, Function[] memory functionInfos) internal returns(MCDevKit storage) { - return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), functionInfos); - } - function createSimpleMockProxy(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), mc.std.all); - } + // function createSimpleMockProxy(MCDevKit storage mc, Function[] memory functionInfos) internal returns(MCDevKit storage) { + // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), functionInfos); + // } + // function createSimpleMockProxy(MCDevKit storage mc) internal returns(MCDevKit storage) { + // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), mc.std.all); + // } /**------------------------- @@ -84,9 +84,9 @@ library MCTestLib { function createMockDictionary(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { return mc.createMockDictionary(name, Config().defaultOwner(), mc.std.all); } - function createMockDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), Config().defaultOwner(), mc.std.all); - } + // function createMockDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { + // return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), Config().defaultOwner(), mc.std.all); + // } /**-------------------------- diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol index 1377e20a..1bd7c086 100644 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -35,12 +35,7 @@ library DictionaryRegistryLib { function add(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { uint pid = dictionaries.startProcess("add"); bytes32 nameHash = name.calcHash(); - if (dictionary.isNotMock()) { - dictionaries.deployed[nameHash] = dictionary; - } - if (dictionary.isMock()) { - dictionaries.mocks[nameHash] = dictionary; - } + dictionaries.deployed[nameHash] = dictionary; return dictionaries.finishProcess(pid); } @@ -88,10 +83,6 @@ library DictionaryRegistryLib { uint pid = dictionaries.startProcess("findCurrentDictionary"); return dictionaries.currentDictionary.assertExists().finishProcessInStorage(pid); } - function findMockDictionary(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { - uint pid = dictionaries.startProcess("findMockDictionary"); - return dictionaries.mocks[name.safeCalcHash()].assertExists().finishProcessInStorage(pid); - } /**----------------------------- @@ -113,13 +104,4 @@ library DictionaryRegistryLib { return dictionaries.genUniqueName(Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); } - function genUniqueMockName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { - uint pid = dictionaries.startProcess("genUniqueName"); - ScanRange memory range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = Config().DEFAULT_DICTIONARY_MOCK_NAME.toSequential(i); - if (dictionaries.existsInMocks(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } } diff --git a/devkit/method/core/MockRegistryLib.sol b/devkit/method/core/MockRegistryLib.sol new file mode 100644 index 00000000..1f84cc0d --- /dev/null +++ b/devkit/method/core/MockRegistryLib.sol @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Error & Debug +import {ERR, throwError} from "devkit/error/Error.sol"; +import {check} from "devkit/error/Validation.sol"; +import {Debug} from "devkit/debug/Debug.sol"; +// Config +import {Config, ScanRange} from "devkit/config/Config.sol"; +// Utils +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; + using AddressUtils for address; +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +// Core +import {Proxy} from "devkit/core/Proxy.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; + +import {MockRegistry} from "devkit/core/MockRegistry.sol"; + + +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 📘 Dictionary Registry + đŸ“Ĩ Add Dictionary + đŸ”ŧ Update Current Context Dictionary + â™ģī¸ Reset Current Context Dictionary + 🔍 Find Dictionary + 🏷 Generate Unique Name +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library MockRegistryLib { + /**------------------------ + đŸ“Ĩ Add Dictionary + --------------------------*/ + function add(MockRegistry storage mock, string memory name, Dictionary memory dictionary) internal returns(MockRegistry storage) { + uint pid = mock.startProcess("add"); + bytes32 nameHash = name.calcHash(); + mock.dictionary[nameHash] = dictionary; + return mock.finishProcess(pid); + } + + function safeAdd(MockRegistry storage mock, string memory name, Dictionary memory dictionary) internal returns(MockRegistry storage) { + uint pid = mock.startProcess("safeAdd"); + return mock .add(name.assertNotEmpty(), dictionary.assertNotEmpty()) + .finishProcess(pid); + } + + + /**------------------------ + 🔍 Find Dictionary + --------------------------*/ + function find(MockRegistry storage mock, string memory name) internal returns(Dictionary storage) { + uint pid = mock.startProcess("find"); + return mock.dictionary[name.safeCalcHash()] + .assertExists() + .finishProcessInStorage(pid); + } + function findMockDictionary(MockRegistry storage mock, string memory name) internal returns(Dictionary storage) { + uint pid = mock.startProcess("findMockDictionary"); + return mock.dictionary[name.safeCalcHash()].assertExists().finishProcessInStorage(pid); + } + function findSimpleMockProxy(MockRegistry storage mock, string memory name) internal returns(Proxy storage) { + uint pid = mock.startProcess("findSimpleMockProxy"); + return mock.proxy[name.safeCalcHash()].assertExists().finishProcessInStorage(pid); + } + + + /**----------------------------- + 🏷 Generate Unique Name + -------------------------------*/ + // function genUniqueName(MockRegistry storage mock, string memory baseName) internal returns(string memory name) { + // uint pid = mock.startProcess("genUniqueName"); + // ScanRange memory range = Config().SCAN_RANGE; + // for (uint i = range.START; i <= range.END; ++i) { + // name = baseName.toSequential(i); + // if (mock.existsInDeployed(name).isFalse()) return name.recordExecFinish(pid); + // } + // throwError(ERR.FIND_NAME_OVER_RANGE); + // } + // function genUniqueName(MockRegistry storage mock) internal returns(string memory name) { + // return mock.genUniqueName(Config().DEFAULT_DICTIONARY_NAME); + // } + // function genUniqueDuplicatedName(MockRegistry storage mock) internal returns(string memory name) { + // return mock.genUniqueName(Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); + // } + + // function genUniqueMockName(MockRegistry storage mock) internal returns(string memory name) { + // uint pid = mock.startProcess("genUniqueName"); + // ScanRange memory range = Config().SCAN_RANGE; + // for (uint i = range.START; i <= range.END; ++i) { + // name = Config().DEFAULT_DICTIONARY_MOCK_NAME.toSequential(i); + // if (mock.existsInMocks(name).isFalse()) return name.recordExecFinish(pid); + // } + // throwError(ERR.FIND_NAME_OVER_RANGE); + // } + + // function genUniqueMockName(MockRegistry storage mock) internal returns(string memory name) { + // uint pid = mock.startProcess("genUniqueMockName"); + // ScanRange memory range = Config().SCAN_RANGE; + // for (uint i = range.START; i <= range.END; ++i) { + // name = Config().DEFAULT_PROXY_MOCK_NAME.toSequential(i); + // if (mock.existsInMocks(name).isFalse()) return name.recordExecFinish(pid); + // } + // throwError(ERR.FIND_NAME_OVER_RANGE); + // } + +} diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol index 829d09f9..7a2a5692 100644 --- a/devkit/method/core/ProxyRegistryLib.sol +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -34,12 +34,7 @@ library ProxyRegistryLib { function add(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { uint pid = proxies.startProcess("add"); bytes32 nameHash = name.calcHash(); - if (proxy.isNotMock()) { - proxies.deployed[nameHash] = proxy; - } - if (proxy.isMock()) { - proxies.mocks[nameHash] = proxy; - } + proxies.deployed[nameHash] = proxy; return proxies.finishProcess(pid); } @@ -86,10 +81,6 @@ library ProxyRegistryLib { uint pid = proxies.startProcess("findCurrentProxy"); return proxies.currentProxy.assertExists().finishProcessInStorage(pid); } - function findSimpleMockProxy(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { - uint pid = proxies.startProcess("findSimpleMockProxy"); - return proxies.mocks[name.safeCalcHash()].assertExists().finishProcessInStorage(pid); - } /**----------------------------- @@ -105,14 +96,5 @@ library ProxyRegistryLib { throwError(ERR.FIND_NAME_OVER_RANGE); } - function genUniqueMockName(ProxyRegistry storage proxies) internal returns(string memory name) { - uint pid = proxies.startProcess("genUniqueMockName"); - ScanRange memory range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = Config().DEFAULT_PROXY_MOCK_NAME.toSequential(i); - if (proxies.existsInMocks(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } } diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/method/debug/ProcessLib.sol index 439fcedf..33b59b02 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/method/debug/ProcessLib.sol @@ -12,6 +12,8 @@ import {Proxy} from "devkit/core/Proxy.sol"; import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; import {Dictionary} from "devkit/core/Dictionary.sol"; import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; +import {MockRegistry} from "devkit/core/MockRegistry.sol"; + library ProcessLib { function finishProcess(uint pid) internal { @@ -166,4 +168,19 @@ library ProcessLib { return dictionaries; } + + /**--------------------- + 🏭 Mock Registry + -----------------------*/ + function startProcess(MockRegistry storage, string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("MockRegistryLib", name, params); + } + function startProcess(MockRegistry storage mock, string memory name) internal returns(uint) { + return mock.startProcess(name, ""); + } + + function finishProcess(MockRegistry storage mock, uint pid) internal returns(MockRegistry storage) { + Debug.recordExecFinish(pid); + return mock; + } } diff --git a/devkit/method/inspector/Inspector.sol b/devkit/method/inspector/Inspector.sol index a0ba4bf8..590d54b2 100644 --- a/devkit/method/inspector/Inspector.sol +++ b/devkit/method/inspector/Inspector.sol @@ -207,9 +207,9 @@ library Inspector { function existsInDeployed(ProxyRegistry storage proxies, string memory name) internal returns(bool) { return proxies.deployed[name.safeCalcHash()].exists(); } - function existsInMocks(ProxyRegistry storage proxies, string memory name) internal returns(bool) { - return proxies.mocks[name.safeCalcHash()].exists(); - } + // function existsInMocks(ProxyRegistry storage proxies, string memory name) internal returns(bool) { + // return proxies.mocks[name.safeCalcHash()].exists(); + // } /**==================== @@ -275,7 +275,7 @@ library Inspector { function existsInDeployed(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { return dictionaries.deployed[name.safeCalcHash()].exists(); } - function existsInMocks(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { - return dictionaries.mocks[name.safeCalcHash()].exists(); - } + // function existsInMocks(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { + // return dictionaries.mocks[name.safeCalcHash()].exists(); + // } } From b30eac6b6a15157823b51ac4ba360a5f009f2c3c Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 15:21:32 +0900 Subject: [PATCH 045/111] Externalize naming from MockRegistry --- devkit/core/MockRegistry.sol | 4 +- devkit/method/core/MockRegistryLib.sol | 113 ++++++++++--------------- devkit/method/inspector/Inspector.sol | 8 ++ devkit/method/naming/Naming.sol | 61 +++++++++++++ 4 files changed, 115 insertions(+), 71 deletions(-) create mode 100644 devkit/method/naming/Naming.sol diff --git a/devkit/core/MockRegistry.sol b/devkit/core/MockRegistry.sol index 317a4b0f..9977c9f5 100644 --- a/devkit/core/MockRegistry.sol +++ b/devkit/core/MockRegistry.sol @@ -15,8 +15,8 @@ import {Inspector} from "devkit/method/inspector/Inspector.sol"; 🏭 Mock Registry ========================*/ struct MockRegistry { - mapping(bytes32 nameHash => Proxy) proxy; - mapping(bytes32 nameHash => Dictionary) dictionary; + mapping(string name => Proxy) proxy; + mapping(string name => Dictionary) dictionary; } using MockRegistryLib for MockRegistry global; // Support Methods diff --git a/devkit/method/core/MockRegistryLib.sol b/devkit/method/core/MockRegistryLib.sol index 1f84cc0d..ec81b1b5 100644 --- a/devkit/method/core/MockRegistryLib.sol +++ b/devkit/method/core/MockRegistryLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; -import {check} from "devkit/error/Validation.sol"; +import {check, Check} from "devkit/error/Validation.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; @@ -19,90 +19,65 @@ import {Proxy} from "devkit/core/Proxy.sol"; import {Dictionary} from "devkit/core/Dictionary.sol"; import {MockRegistry} from "devkit/core/MockRegistry.sol"; +import {Naming} from "devkit/method/naming/Naming.sol"; + using Naming for mapping(string => Dictionary); + using Naming for mapping(string => Proxy); /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 📘 Dictionary Registry - đŸ“Ĩ Add Dictionary - đŸ”ŧ Update Current Context Dictionary - â™ģī¸ Reset Current Context Dictionary - 🔍 Find Dictionary - 🏷 Generate Unique Name + 🏭 Mock Registry + đŸ“Ĩ Add + Mock Dictionary + Mock Proxy + 🔍 Find + Mock Dictionary + Mock Proxy ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library MockRegistryLib { - /**------------------------ - đŸ“Ĩ Add Dictionary - --------------------------*/ + + /**------------- + đŸ“Ĩ Add + ---------------*/ + /*----- Mock Dictionary -----*/ function add(MockRegistry storage mock, string memory name, Dictionary memory dictionary) internal returns(MockRegistry storage) { uint pid = mock.startProcess("add"); - bytes32 nameHash = name.calcHash(); - mock.dictionary[nameHash] = dictionary; + Check.isNotEmpty(name); + check(dictionary.isNotEmpty(), "Empty Dictionary"); + mock.dictionary[name] = dictionary; return mock.finishProcess(pid); } + function add(MockRegistry storage mock, Dictionary memory dictionary) internal returns(MockRegistry storage) { + return add(mock, mock.dictionary.genUniqueMockName(), dictionary); + } - function safeAdd(MockRegistry storage mock, string memory name, Dictionary memory dictionary) internal returns(MockRegistry storage) { - uint pid = mock.startProcess("safeAdd"); - return mock .add(name.assertNotEmpty(), dictionary.assertNotEmpty()) - .finishProcess(pid); + /*----- Mock Proxy -----*/ + function add(MockRegistry storage mock, string memory name, Proxy memory proxy) internal returns(MockRegistry storage) { + uint pid = mock.startProcess("add"); + Check.isNotEmpty(name); + check(proxy.isNotEmpty(), "Empty Proxy"); + mock.proxy[name] = proxy; + return mock.finishProcess(pid); + } + function add(MockRegistry storage mock, Proxy memory proxy) internal returns(MockRegistry storage) { + return add(mock, mock.proxy.genUniqueMockName(), proxy); } - /**------------------------ - 🔍 Find Dictionary - --------------------------*/ - function find(MockRegistry storage mock, string memory name) internal returns(Dictionary storage) { - uint pid = mock.startProcess("find"); - return mock.dictionary[name.safeCalcHash()] - .assertExists() - .finishProcessInStorage(pid); - } + /**------------- + 🔍 Find + ---------------*/ + /*----- Mock Dictionary -----*/ function findMockDictionary(MockRegistry storage mock, string memory name) internal returns(Dictionary storage) { uint pid = mock.startProcess("findMockDictionary"); - return mock.dictionary[name.safeCalcHash()].assertExists().finishProcessInStorage(pid); + Check.isNotEmpty(name); + return mock.dictionary[name].assertExists().finishProcessInStorage(pid); } - function findSimpleMockProxy(MockRegistry storage mock, string memory name) internal returns(Proxy storage) { - uint pid = mock.startProcess("findSimpleMockProxy"); - return mock.proxy[name.safeCalcHash()].assertExists().finishProcessInStorage(pid); - } - - - /**----------------------------- - 🏷 Generate Unique Name - -------------------------------*/ - // function genUniqueName(MockRegistry storage mock, string memory baseName) internal returns(string memory name) { - // uint pid = mock.startProcess("genUniqueName"); - // ScanRange memory range = Config().SCAN_RANGE; - // for (uint i = range.START; i <= range.END; ++i) { - // name = baseName.toSequential(i); - // if (mock.existsInDeployed(name).isFalse()) return name.recordExecFinish(pid); - // } - // throwError(ERR.FIND_NAME_OVER_RANGE); - // } - // function genUniqueName(MockRegistry storage mock) internal returns(string memory name) { - // return mock.genUniqueName(Config().DEFAULT_DICTIONARY_NAME); - // } - // function genUniqueDuplicatedName(MockRegistry storage mock) internal returns(string memory name) { - // return mock.genUniqueName(Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); - // } - // function genUniqueMockName(MockRegistry storage mock) internal returns(string memory name) { - // uint pid = mock.startProcess("genUniqueName"); - // ScanRange memory range = Config().SCAN_RANGE; - // for (uint i = range.START; i <= range.END; ++i) { - // name = Config().DEFAULT_DICTIONARY_MOCK_NAME.toSequential(i); - // if (mock.existsInMocks(name).isFalse()) return name.recordExecFinish(pid); - // } - // throwError(ERR.FIND_NAME_OVER_RANGE); - // } - - // function genUniqueMockName(MockRegistry storage mock) internal returns(string memory name) { - // uint pid = mock.startProcess("genUniqueMockName"); - // ScanRange memory range = Config().SCAN_RANGE; - // for (uint i = range.START; i <= range.END; ++i) { - // name = Config().DEFAULT_PROXY_MOCK_NAME.toSequential(i); - // if (mock.existsInMocks(name).isFalse()) return name.recordExecFinish(pid); - // } - // throwError(ERR.FIND_NAME_OVER_RANGE); - // } + /*----- Mock Proxy -----*/ + function findMockProxy(MockRegistry storage mock, string memory name) internal returns(Proxy storage) { + uint pid = mock.startProcess("findMockProxy"); + Check.isNotEmpty(name); + return mock.proxy[name].assertExists().finishProcessInStorage(pid); + } } diff --git a/devkit/method/inspector/Inspector.sol b/devkit/method/inspector/Inspector.sol index 590d54b2..99c22786 100644 --- a/devkit/method/inspector/Inspector.sol +++ b/devkit/method/inspector/Inspector.sol @@ -170,6 +170,10 @@ library Inspector { return proxy; } + function notExists(Proxy storage proxy) internal returns(bool) { + return proxy.exists().isFalse(); + } + function isNotEmpty(Proxy memory proxy) internal returns(bool) { return proxy.addr.isContract(); } @@ -223,6 +227,10 @@ library Inspector { return dictionary; } + function notExists(Dictionary storage dictionary) internal returns(bool) { + return dictionary.exists().isFalse(); + } + function isNotEmpty(Dictionary memory dictionary) internal returns(bool) { return dictionary.addr.isContract(); } diff --git a/devkit/method/naming/Naming.sol b/devkit/method/naming/Naming.sol new file mode 100644 index 00000000..cbc95cbf --- /dev/null +++ b/devkit/method/naming/Naming.sol @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {throwError, ERR} from "devkit/error/Error.sol"; +import {Config, ScanRange} from "devkit/config/Config.sol"; +// Core Types +import {Dictionary} from "devkit/core/Dictionary.sol"; +import {Proxy} from "devkit/core/Proxy.sol"; +// Utils +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; + +//================ +// đŸ—’ī¸ Parser +library Naming { + + /**--------------------------- + 📚 Dictionary Mapping + -----------------------------*/ + function genUniqueName(mapping(string => Dictionary) storage dictionary, string memory baseName) internal returns(string memory name) { + ScanRange memory range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = baseName.toSequential(i); + if (dictionary[name].notExists()) return name; + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + /*----- Dictionary -----*/ + function genUniqueName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { + return genUniqueName(dictionary, Config().DEFAULT_DICTIONARY_NAME); + } + /*----- Mock Dictionary -----*/ + function genUniqueMockName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { + return genUniqueName(dictionary, Config().DEFAULT_DICTIONARY_MOCK_NAME); + } + + + /**----------------------- + 🏠 Proxy Mapping + -------------------------*/ + /*----- Mock Proxy -----*/ + function genUniqueName(mapping(string => Proxy) storage proxy, string memory baseName) internal returns(string memory name) { + ScanRange memory range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = baseName.toSequential(i); + if (proxy[name].notExists()) return name; + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + /*----- Proxy -----*/ + function genUniqueName(mapping(string => Proxy) storage proxy) internal returns(string memory name) { + return genUniqueName(proxy, Config().DEFAULT_PROXY_NAME); + } + /*----- Mock Proxy -----*/ + function genUniqueMockName(mapping(string => Proxy) storage proxy) internal returns(string memory name) { + return genUniqueName(proxy, Config().DEFAULT_PROXY_MOCK_NAME); + } + +} + + From f2d2cb5da98a3349faea6086093b98f51dd4326b Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 16:11:05 +0900 Subject: [PATCH 046/111] Externalize MappingAnalyzer (formerly Naming) --- devkit/config/Config.sol | 2 + devkit/core/BundleRegistry.sol | 2 +- devkit/core/DictionaryRegistry.sol | 2 +- devkit/core/FunctionRegistry.sol | 2 +- devkit/core/ProxyRegistry.sol | 2 +- devkit/method/MCBundleLib.sol | 5 +- devkit/method/MCDeployLib.sol | 20 ++-- devkit/method/core/BundleRegistryLib.sol | 18 ++- devkit/method/core/DictionaryRegistryLib.sol | 26 +---- devkit/method/core/FunctionRegistryLib.sol | 6 +- devkit/method/core/MockRegistryLib.sol | 10 +- devkit/method/core/ProxyRegistryLib.sol | 21 +--- devkit/method/inspector/Inspector.sol | 14 ++- devkit/method/inspector/MappingAnalyzer.sol | 116 +++++++++++++++++++ devkit/method/naming/Naming.sol | 61 ---------- test/devkit/MCDevKit.t.sol | 2 +- test/devkit/global/MCBundle.t.sol | 24 ++-- 17 files changed, 179 insertions(+), 154 deletions(-) create mode 100644 devkit/method/inspector/MappingAnalyzer.sol delete mode 100644 devkit/method/naming/Naming.sol diff --git a/devkit/config/Config.sol b/devkit/config/Config.sol index 25c17dcb..c7d0245e 100644 --- a/devkit/config/Config.sol +++ b/devkit/config/Config.sol @@ -22,6 +22,7 @@ struct Configuration { string DEFAULT_PROXY_NAME; string DEFAULT_PROXY_MOCK_NAME; string DEFAULT_BUNDLE_NAME; + string DEFAULT_FUNCTION_NAME; ScanRange SCAN_RANGE; } @@ -47,6 +48,7 @@ library ConfigLib { config.DEFAULT_PROXY_NAME = "Proxy"; config.DEFAULT_PROXY_MOCK_NAME = "MockProxy"; config.DEFAULT_BUNDLE_NAME = "Bundle"; + config.DEFAULT_FUNCTION_NAME = "Function"; config.SCAN_RANGE.START = 1; config.SCAN_RANGE.END = 5; diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/BundleRegistry.sol index 5623c5dd..f8bd7e2f 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/BundleRegistry.sol @@ -14,7 +14,7 @@ import {Inspector} from "devkit/method/inspector/Inspector.sol"; 📙 Bundle Registry ==========================*/ struct BundleRegistry { - mapping(bytes32 nameHash => Bundle) bundles; + mapping(string name => Bundle) bundles; string currentBundleName; } using BundleRegistryLib for BundleRegistry global; diff --git a/devkit/core/DictionaryRegistry.sol b/devkit/core/DictionaryRegistry.sol index 1dee6083..f34e9893 100644 --- a/devkit/core/DictionaryRegistry.sol +++ b/devkit/core/DictionaryRegistry.sol @@ -14,7 +14,7 @@ import {Inspector} from "devkit/method/inspector/Inspector.sol"; 📘 Dictionary Registry ==============================*/ struct DictionaryRegistry { - mapping(bytes32 nameHash => Dictionary) deployed; + mapping(string name => Dictionary) deployed; Dictionary currentDictionary; } using DictionaryRegistryLib for DictionaryRegistry global; diff --git a/devkit/core/FunctionRegistry.sol b/devkit/core/FunctionRegistry.sol index 561999f4..168b1b04 100644 --- a/devkit/core/FunctionRegistry.sol +++ b/devkit/core/FunctionRegistry.sol @@ -13,7 +13,7 @@ import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; 📗 Functions Registry =============================*/ struct FunctionRegistry { - mapping(bytes32 nameHash => Function) customs; + mapping(string name => Function) customs; string currentName; } using FunctionRegistryLib for FunctionRegistry global; diff --git a/devkit/core/ProxyRegistry.sol b/devkit/core/ProxyRegistry.sol index 938de211..6e549f4b 100644 --- a/devkit/core/ProxyRegistry.sol +++ b/devkit/core/ProxyRegistry.sol @@ -14,7 +14,7 @@ import {Inspector} from "devkit/method/inspector/Inspector.sol"; 📕 Proxy Registry =========================*/ struct ProxyRegistry { - mapping(bytes32 nameHash => Proxy) deployed; + mapping(string name => Proxy) deployed; Proxy currentProxy; } using ProxyRegistryLib for ProxyRegistry global; diff --git a/devkit/method/MCBundleLib.sol b/devkit/method/MCBundleLib.sol index e845c86a..b6e4c210 100644 --- a/devkit/method/MCBundleLib.sol +++ b/devkit/method/MCBundleLib.sol @@ -10,7 +10,10 @@ import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {Params} from "devkit/debug/Params.sol"; // Core import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; + using MappingAnalyzer for mapping(string => Bundle); /*********************************************** đŸ—‚ī¸ Bundle Configuration @@ -34,7 +37,7 @@ library MCBundleLib { } function init(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.init(mc.bundle.genUniqueBundleName()); + return mc.init(mc.bundle.genUniqueName()); } // diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index e85c351a..66bb8f8b 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -18,6 +18,10 @@ import {StdFunctionsArgs} from "devkit/method/core/StdFunctionsLib.sol"; import {Proxy} from "devkit/core/Proxy.sol"; import {ProxyLib} from "devkit/method/core/ProxyLib.sol"; +import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; + using MappingAnalyzer for mapping(string => Dictionary); + using MappingAnalyzer for mapping(string => Proxy); + /*********************************************** 🚀 Deployment @@ -88,10 +92,10 @@ library MCDeployLib { return mc.deployProxy(name, mc.findCurrentDictionary(), initData); } function deployProxy(MCDevKit storage mc, bytes memory initData) internal returns(MCDevKit storage) { - return mc.deployProxy(mc.proxy.genUniqueName(), mc.findCurrentDictionary(), initData); + return mc.deployProxy(mc.proxy.deployed.genUniqueName(), mc.findCurrentDictionary(), initData); } function deployProxy(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.deployProxy(mc.proxy.genUniqueName(), mc.findCurrentDictionary(), Config().defaultOwner().initSetAdminBytes()); + return mc.deployProxy(mc.proxy.deployed.genUniqueName(), mc.findCurrentDictionary(), Config().defaultOwner().initSetAdminBytes()); } @@ -109,16 +113,16 @@ library MCDeployLib { } function deployDictionary(MCDevKit storage mc) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.genUniqueName(), mc.bundle.findCurrentBundle(), Config().defaultOwner()); + return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), mc.bundle.findCurrentBundle(), Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, string memory name) internal returns(Dictionary memory) { return mc.deployDictionary(name, mc.bundle.findCurrentBundle(), Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, Bundle storage bundleInfo) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.genUniqueName(), bundleInfo, Config().defaultOwner()); + return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), bundleInfo, Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, address owner) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.genUniqueName(), mc.bundle.findCurrentBundle(), owner); + return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), mc.bundle.findCurrentBundle(), owner); } function deployDictionary(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(Dictionary memory) { return mc.deployDictionary(name, bundleInfo, Config().defaultOwner()); @@ -127,7 +131,7 @@ library MCDeployLib { return mc.deployDictionary(name, mc.bundle.findCurrentBundle(), owner); } function deployDictionary(MCDevKit storage mc, Bundle storage bundleInfo, address owner) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.genUniqueName(), bundleInfo, owner); + return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), bundleInfo, owner); } @@ -145,10 +149,10 @@ library MCDeployLib { return mc.duplicateDictionary(name, mc.findCurrentDictionary()); } function duplicateDictionary(MCDevKit storage mc, Dictionary storage targetDictionary) internal returns(MCDevKit storage) { - return mc.duplicateDictionary(mc.dictionary.genUniqueDuplicatedName(), targetDictionary); + return mc.duplicateDictionary(mc.dictionary.deployed.genUniqueDuplicatedName(), targetDictionary); } function duplicateDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.duplicateDictionary(mc.dictionary.genUniqueDuplicatedName(), mc.findCurrentDictionary()); + return mc.duplicateDictionary(mc.dictionary.deployed.genUniqueDuplicatedName(), mc.findCurrentDictionary()); } } diff --git a/devkit/method/core/BundleRegistryLib.sol b/devkit/method/core/BundleRegistryLib.sol index d75d8213..c4ab72f1 100644 --- a/devkit/method/core/BundleRegistryLib.sol +++ b/devkit/method/core/BundleRegistryLib.sol @@ -18,6 +18,8 @@ import {Bundle} from "devkit/core/Bundle.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; +import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; + using MappingAnalyzer for mapping(string => Bundle); /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -38,7 +40,7 @@ library BundleRegistryLib { -----------------------*/ function init(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { uint pid = bundle.startProcess("init"); - bundle.bundles[name.safeCalcHash()].safeAssign(name); + bundle.bundles[name].safeAssign(name); bundle.safeUpdateCurrentBundle(name); return bundle.finishProcess(pid); } @@ -71,7 +73,7 @@ library BundleRegistryLib { --------------------*/ function set(BundleRegistry storage bundle, string memory name, address facade) internal returns(BundleRegistry storage) { uint pid = bundle.startProcess("set"); - bundle.bundles[name.safeCalcHash()] + bundle.bundles[name] .assertExists() .safeAssign(facade); return bundle.finishProcess(pid); @@ -107,7 +109,7 @@ library BundleRegistryLib { ---------------------------------*/ function findBundle(BundleRegistry storage bundle, string memory name) internal returns(Bundle storage) { uint pid = bundle.startProcess("findBundle"); - return bundle.bundles[name.safeCalcHash()].finishProcess(pid); + return bundle.bundles[name].finishProcess(pid); } function findCurrentBundle(BundleRegistry storage bundle) internal returns(Bundle storage) { uint pid = bundle.startProcess("findCurrentBundle"); @@ -122,14 +124,8 @@ library BundleRegistryLib { /**----------------------------- 🏷 Generate Unique Name -------------------------------*/ - function genUniqueBundleName(BundleRegistry storage bundle) internal returns(string memory name) { - uint pid = bundle.startProcess("genUniqueBundleName"); - ScanRange storage range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = Config().DEFAULT_BUNDLE_NAME.toSequential(i); - if (bundle.existsBundle(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); + function genUniqueName(BundleRegistry storage bundle) internal returns(string memory name) { + return bundle.bundles.genUniqueName(); } } diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol index 1bd7c086..4c3573c3 100644 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -26,7 +26,6 @@ import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; đŸ”ŧ Update Current Context Dictionary â™ģī¸ Reset Current Context Dictionary 🔍 Find Dictionary - 🏷 Generate Unique Name ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library DictionaryRegistryLib { /**------------------------ @@ -34,8 +33,7 @@ library DictionaryRegistryLib { --------------------------*/ function add(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { uint pid = dictionaries.startProcess("add"); - bytes32 nameHash = name.calcHash(); - dictionaries.deployed[nameHash] = dictionary; + dictionaries.deployed[name] = dictionary; return dictionaries.finishProcess(pid); } @@ -75,7 +73,7 @@ library DictionaryRegistryLib { --------------------------*/ function find(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { uint pid = dictionaries.startProcess("find"); - return dictionaries.deployed[name.safeCalcHash()] + return dictionaries.deployed[name] .assertExists() .finishProcessInStorage(pid); } @@ -84,24 +82,4 @@ library DictionaryRegistryLib { return dictionaries.currentDictionary.assertExists().finishProcessInStorage(pid); } - - /**----------------------------- - 🏷 Generate Unique Name - -------------------------------*/ - function genUniqueName(DictionaryRegistry storage dictionaries, string memory baseName) internal returns(string memory name) { - uint pid = dictionaries.startProcess("genUniqueName"); - ScanRange memory range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = baseName.toSequential(i); - if (dictionaries.existsInDeployed(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } - function genUniqueName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { - return dictionaries.genUniqueName(Config().DEFAULT_DICTIONARY_NAME); - } - function genUniqueDuplicatedName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { - return dictionaries.genUniqueName(Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); - } - } diff --git a/devkit/method/core/FunctionRegistryLib.sol b/devkit/method/core/FunctionRegistryLib.sol index 364d2c86..f6808cf6 100644 --- a/devkit/method/core/FunctionRegistryLib.sol +++ b/devkit/method/core/FunctionRegistryLib.sol @@ -35,7 +35,7 @@ library FunctionRegistryLib { function safeAddFunction(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { uint pid = functions.startProcess("safeAddFunction"); check(name.isNotEmpty(), "Empty Name"); - functions.customs[name.safeCalcHash()] + functions.customs[name] .safeAssign(name) .safeAssign(selector) .safeAssign(implementation); @@ -49,7 +49,7 @@ library FunctionRegistryLib { -----------------------------------------------*/ function safeLoadAndAdd(FunctionRegistry storage functions, string memory envKey, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { uint pid = functions.startProcess("safeLoadAndAdd"); - functions.customs[name.safeCalcHash()] + functions.customs[name] .loadAndAssignFromEnv(envKey, name, selector); functions.safeUpdateCurrentFunction(name); return functions.finishProcess(pid); @@ -81,7 +81,7 @@ library FunctionRegistryLib { ---------------------------------*/ function find(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { uint pid = functions.startProcess("findFunction"); - return functions.customs[name.safeCalcHash()].assertExists().finishProcess(pid); + return functions.customs[name].assertExists().finishProcess(pid); } function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { uint pid = functions.startProcess("findCurrentFunction"); diff --git a/devkit/method/core/MockRegistryLib.sol b/devkit/method/core/MockRegistryLib.sol index ec81b1b5..b462de2f 100644 --- a/devkit/method/core/MockRegistryLib.sol +++ b/devkit/method/core/MockRegistryLib.sol @@ -19,9 +19,9 @@ import {Proxy} from "devkit/core/Proxy.sol"; import {Dictionary} from "devkit/core/Dictionary.sol"; import {MockRegistry} from "devkit/core/MockRegistry.sol"; -import {Naming} from "devkit/method/naming/Naming.sol"; - using Naming for mapping(string => Dictionary); - using Naming for mapping(string => Proxy); +import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; + using MappingAnalyzer for mapping(string => Dictionary); + using MappingAnalyzer for mapping(string => Proxy); /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -63,9 +63,9 @@ library MockRegistryLib { } - /**------------- + /**-------------- 🔍 Find - ---------------*/ + ----------------*/ /*----- Mock Dictionary -----*/ function findMockDictionary(MockRegistry storage mock, string memory name) internal returns(Dictionary storage) { uint pid = mock.startProcess("findMockDictionary"); diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol index 7a2a5692..94ee913e 100644 --- a/devkit/method/core/ProxyRegistryLib.sol +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -25,7 +25,6 @@ import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; đŸ”ŧ Update Current Context Proxy â™ģī¸ Reset Current Context Proxy 🔍 Find Proxy - 🏷 Generate Unique Name ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library ProxyRegistryLib { /**------------------- @@ -33,8 +32,7 @@ library ProxyRegistryLib { ---------------------*/ function add(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { uint pid = proxies.startProcess("add"); - bytes32 nameHash = name.calcHash(); - proxies.deployed[nameHash] = proxy; + proxies.deployed[name] = proxy; return proxies.finishProcess(pid); } @@ -74,7 +72,7 @@ library ProxyRegistryLib { ---------------------*/ function find(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { uint pid = proxies.startProcess("find"); - return proxies.deployed[name.safeCalcHash()] + return proxies.deployed[name] .assertExists().finishProcessInStorage(pid); } function findCurrentProxy(ProxyRegistry storage proxies) internal returns(Proxy storage) { @@ -82,19 +80,4 @@ library ProxyRegistryLib { return proxies.currentProxy.assertExists().finishProcessInStorage(pid); } - - /**----------------------------- - 🏷 Generate Unique Name - -------------------------------*/ - function genUniqueName(ProxyRegistry storage proxies) internal returns(string memory name) { - uint pid = proxies.startProcess("genUniqueName"); - ScanRange memory range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = Config().DEFAULT_PROXY_NAME.toSequential(i); - if (proxies.existsInDeployed(name).isFalse()) return name.recordExecFinish(pid); - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } - - } diff --git a/devkit/method/inspector/Inspector.sol b/devkit/method/inspector/Inspector.sol index 99c22786..83eb4f42 100644 --- a/devkit/method/inspector/Inspector.sol +++ b/devkit/method/inspector/Inspector.sol @@ -42,6 +42,10 @@ library Inspector { return func; } + function notExists(Function storage func) internal returns(bool) { + return func.exists().isFalse(); + } + function assertExists(Function storage func) internal returns(Function storage) { check(func.exists(), "func does not exists"); return func; @@ -141,7 +145,7 @@ library Inspector { đŸ—‚ī¸ Bundle Registry =========================*/ function existsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { - return bundle.bundles[name.safeCalcHash()].hasName(); + return bundle.bundles[name].hasName(); } function notExistsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { return bundle.existsBundle(name).isNot(); @@ -209,10 +213,10 @@ library Inspector { 🏠 Proxy Registry =========================*/ function existsInDeployed(ProxyRegistry storage proxies, string memory name) internal returns(bool) { - return proxies.deployed[name.safeCalcHash()].exists(); + return proxies.deployed[name].exists(); } // function existsInMocks(ProxyRegistry storage proxies, string memory name) internal returns(bool) { - // return proxies.mocks[name.safeCalcHash()].exists(); + // return proxies.mocks[name].exists(); // } @@ -281,9 +285,9 @@ library Inspector { 📚 Dictionary Registry ==============================*/ function existsInDeployed(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { - return dictionaries.deployed[name.safeCalcHash()].exists(); + return dictionaries.deployed[name].exists(); } // function existsInMocks(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { - // return dictionaries.mocks[name.safeCalcHash()].exists(); + // return dictionaries.mocks[name].exists(); // } } diff --git a/devkit/method/inspector/MappingAnalyzer.sol b/devkit/method/inspector/MappingAnalyzer.sol new file mode 100644 index 00000000..242a5cbb --- /dev/null +++ b/devkit/method/inspector/MappingAnalyzer.sol @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {throwError, ERR} from "devkit/error/Error.sol"; +import {Config, ScanRange} from "devkit/config/Config.sol"; +// Core Types +import {Bundle} from "devkit/core/Bundle.sol"; +import {Function} from "devkit/core/Function.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; +import {Proxy} from "devkit/core/Proxy.sol"; +// Utils +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; + +/*********************************** + đŸ—ēī¸ Mapping Analyzer + 🆕 Generate Unique Name +************************************/ +library MappingAnalyzer { + + /**------------------------ + đŸ—‚ī¸ Bundle Mapping + --------------------------*/ + function genUniqueName(mapping(string => Bundle) storage bundle, string memory baseName) internal returns(string memory name) { + ScanRange memory range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = baseName.toSequential(i); + if (bundle[name].hasNotName()) return name; // TODO + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + function genUniqueName(mapping(string => Bundle) storage bundle) internal returns(string memory name) { + return genUniqueName(bundle, Config().DEFAULT_BUNDLE_NAME); + } + + + /**------------------------- + 🧩 Function Mapping + ---------------------------*/ + function genUniqueName(mapping(string => Function) storage func, string memory baseName) internal returns(string memory name) { + ScanRange memory range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = baseName.toSequential(i); + if (func[name].notExists()) return name; + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + function genUniqueName(mapping(string => Function) storage func) internal returns(string memory name) { + return genUniqueName(func, Config().DEFAULT_FUNCTION_NAME); + } + + + /**--------------------------- + 📚 Dictionary Mapping + -----------------------------*/ + function genUniqueName(mapping(string => Dictionary) storage dictionary, string memory baseName) internal returns(string memory name) { + ScanRange memory range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = baseName.toSequential(i); + if (dictionary[name].notExists()) return name; + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + /*----- Dictionary -----*/ + function genUniqueName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { + return genUniqueName(dictionary, Config().DEFAULT_DICTIONARY_NAME); + } + /*----- Dictionary -----*/ + function genUniqueDuplicatedName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { + return genUniqueName(dictionary, Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); + } + /*----- Mock Dictionary -----*/ + function genUniqueMockName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { + return genUniqueName(dictionary, Config().DEFAULT_DICTIONARY_MOCK_NAME); + } + // function genUniqueName(DictionaryRegistry storage dictionaries, string memory baseName) internal returns(string memory name) { + // uint pid = dictionaries.startProcess("genUniqueName"); + // ScanRange memory range = Config().SCAN_RANGE; + // for (uint i = range.START; i <= range.END; ++i) { + // name = baseName.toSequential(i); + // if (dictionaries.existsInDeployed(name).isFalse()) return name.recordExecFinish(pid); + // } + // throwError(ERR.FIND_NAME_OVER_RANGE); + // } + // function genUniqueName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { + // return dictionaries.genUniqueName(Config().DEFAULT_DICTIONARY_NAME); + // } + // function genUniqueDuplicatedName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { + // return dictionaries.genUniqueName(Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); + // } + + + /**----------------------- + 🏠 Proxy Mapping + -------------------------*/ + /*----- Mock Proxy -----*/ + function genUniqueName(mapping(string => Proxy) storage proxy, string memory baseName) internal returns(string memory name) { + ScanRange memory range = Config().SCAN_RANGE; + for (uint i = range.START; i <= range.END; ++i) { + name = baseName.toSequential(i); + if (proxy[name].notExists()) return name; + } + throwError(ERR.FIND_NAME_OVER_RANGE); + } + /*----- Proxy -----*/ + function genUniqueName(mapping(string => Proxy) storage proxy) internal returns(string memory name) { + return genUniqueName(proxy, Config().DEFAULT_PROXY_NAME); + } + /*----- Mock Proxy -----*/ + function genUniqueMockName(mapping(string => Proxy) storage proxy) internal returns(string memory name) { + return genUniqueName(proxy, Config().DEFAULT_PROXY_MOCK_NAME); + } + +} + + diff --git a/devkit/method/naming/Naming.sol b/devkit/method/naming/Naming.sol deleted file mode 100644 index cbc95cbf..00000000 --- a/devkit/method/naming/Naming.sol +++ /dev/null @@ -1,61 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import {throwError, ERR} from "devkit/error/Error.sol"; -import {Config, ScanRange} from "devkit/config/Config.sol"; -// Core Types -import {Dictionary} from "devkit/core/Dictionary.sol"; -import {Proxy} from "devkit/core/Proxy.sol"; -// Utils -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; - -//================ -// đŸ—’ī¸ Parser -library Naming { - - /**--------------------------- - 📚 Dictionary Mapping - -----------------------------*/ - function genUniqueName(mapping(string => Dictionary) storage dictionary, string memory baseName) internal returns(string memory name) { - ScanRange memory range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = baseName.toSequential(i); - if (dictionary[name].notExists()) return name; - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } - /*----- Dictionary -----*/ - function genUniqueName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { - return genUniqueName(dictionary, Config().DEFAULT_DICTIONARY_NAME); - } - /*----- Mock Dictionary -----*/ - function genUniqueMockName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { - return genUniqueName(dictionary, Config().DEFAULT_DICTIONARY_MOCK_NAME); - } - - - /**----------------------- - 🏠 Proxy Mapping - -------------------------*/ - /*----- Mock Proxy -----*/ - function genUniqueName(mapping(string => Proxy) storage proxy, string memory baseName) internal returns(string memory name) { - ScanRange memory range = Config().SCAN_RANGE; - for (uint i = range.START; i <= range.END; ++i) { - name = baseName.toSequential(i); - if (proxy[name].notExists()) return name; - } - throwError(ERR.FIND_NAME_OVER_RANGE); - } - /*----- Proxy -----*/ - function genUniqueName(mapping(string => Proxy) storage proxy) internal returns(string memory name) { - return genUniqueName(proxy, Config().DEFAULT_PROXY_NAME); - } - /*----- Mock Proxy -----*/ - function genUniqueMockName(mapping(string => Proxy) storage proxy) internal returns(string memory name) { - return genUniqueName(proxy, Config().DEFAULT_PROXY_MOCK_NAME); - } - -} - - diff --git a/test/devkit/MCDevKit.t.sol b/test/devkit/MCDevKit.t.sol index 3a2582f6..cdd99f7e 100644 --- a/test/devkit/MCDevKit.t.sol +++ b/test/devkit/MCDevKit.t.sol @@ -33,7 +33,7 @@ contract MCDevKitTest is Test { string memory name = "TestBundleName"; mc.init(name); - assertTrue(mc.bundle.bundles[name.safeCalcHash()].name.isEqual(name)); + assertTrue(mc.bundle.bundles[name].name.isEqual(name)); assertTrue(mc.bundle.currentBundleName.isEqual(name)); } } diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 3cf553b7..9361ed71 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -21,7 +21,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { string memory name = "TestBundleName"; mc.init(name); - assertTrue(mc.bundle.bundles[name.safeCalcHash()].name.isEqual(name)); + assertTrue(mc.bundle.bundles[name].name.isEqual(name)); assertTrue(mc.bundle.currentBundleName.isEqual(name)); } @@ -29,26 +29,26 @@ contract DevKitTest_MCBundle is MCDevKitTest { // function test_Success_init_withoutName() public {} function test_Success_ensureInit_beforeInit() public { - string memory name = mc.bundle.genUniqueBundleName(); + string memory name = mc.bundle.genUniqueName(); mc.ensureInit(); - assertTrue(mc.bundle.bundles[name.safeCalcHash()].name.isEqual(name)); + assertTrue(mc.bundle.bundles[name].name.isEqual(name)); assertTrue(mc.bundle.currentBundleName.isEqual(name)); } function test_Success_ensureInit_afterInit() public { - string memory name = mc.bundle.genUniqueBundleName(); + string memory name = mc.bundle.genUniqueName(); mc.init(); - assertTrue(mc.bundle.bundles[name.safeCalcHash()].name.isEqual(name)); + assertTrue(mc.bundle.bundles[name].name.isEqual(name)); assertTrue(mc.bundle.currentBundleName.isEqual(name)); - string memory name2 = mc.bundle.genUniqueBundleName(); + string memory name2 = mc.bundle.genUniqueName(); mc.ensureInit(); - assertTrue(mc.bundle.bundles[name2.safeCalcHash()].name.isEmpty()); + assertTrue(mc.bundle.bundles[name2].name.isEmpty()); assertTrue(mc.bundle.currentBundleName.isEqual(name)); } @@ -57,10 +57,10 @@ contract DevKitTest_MCBundle is MCDevKitTest { 🔗 Use Function -----------------------*/ function assertFunctionAdded(string memory bundleName, uint256 functionsIndex, string memory functionName, bytes4 selector, address impl) internal { - Bundle memory bundle = mc.bundle.bundles[bundleName.safeCalcHash()]; + Bundle memory bundle = mc.bundle.bundles[bundleName]; assertEq(bundle.name, bundleName); assertEq(bundle.facade, address(0)); - Function memory func = mc.functions.customs[functionName.safeCalcHash()]; + Function memory func = mc.functions.customs[functionName]; assertEq(func.name, functionName); assertEq(func.selector, selector); assertEq(func.implementation, impl); @@ -69,7 +69,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { } function test_Success_use() public { - string memory bundleName = mc.bundle.genUniqueBundleName(); + string memory bundleName = mc.bundle.genUniqueName(); string memory functionName = "DummyFunction"; bytes4 selector = DummyFunction.dummy.selector; address impl = address(new DummyFunction()); @@ -80,7 +80,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { } function test_Revert_use_withSameName() public { - string memory bundleName = mc.bundle.genUniqueBundleName(); + string memory bundleName = mc.bundle.genUniqueName(); string memory functionName = "DummyFunction"; bytes4 selector = DummyFunction.dummy.selector; address impl = address(new DummyFunction()); @@ -92,7 +92,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { } function test_Success_use_withDifferentName() public { - string memory bundleName = mc.bundle.genUniqueBundleName(); + string memory bundleName = mc.bundle.genUniqueName(); string memory functionName = "DummyFunction"; string memory functionName2 = "DummyFunction2"; From a66dd10dd564edc254d16e66437bfa5670fca04f Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 16:29:15 +0900 Subject: [PATCH 047/111] Create Require --- devkit/MCTest.sol | 2 +- devkit/error/Require.sol | 24 ++++++++++++++++++++++++ devkit/error/Validation.sol | 9 --------- devkit/method/core/FunctionLib.sol | 3 ++- 4 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 devkit/error/Require.sol diff --git a/devkit/MCTest.sol b/devkit/MCTest.sol index 6a815a48..f39f4ae7 100644 --- a/devkit/MCTest.sol +++ b/devkit/MCTest.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {Config} from "devkit/config/Config.sol"; -import {DecodeErrorString} from "./error/DecodeErrorString.sol"; +import {DecodeErrorString} from "devkit/error/DecodeErrorString.sol"; // đŸ’Ŧ ABOUT // Meta Contract's default Test based on Forge Std Test diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol new file mode 100644 index 00000000..7ea04ce3 --- /dev/null +++ b/devkit/error/Require.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {throwError, ERR} from "./Error.sol"; +// Utils +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; +import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; + using Bytes4Utils for bytes4; +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; + using AddressUtils for address; + +import {check} from "devkit/error/Validation.sol"; + +library Require { + function assigned(bytes4 str) internal { + check(str.isNotEmpty(), ERR.RQ_SELECTOR); + } + function contractAssigned(address addr) internal { + check(addr.isContract(), ERR.RQ_CONTRACT); + } +} diff --git a/devkit/error/Validation.sol b/devkit/error/Validation.sol index 765f70ec..a401185a 100644 --- a/devkit/error/Validation.sol +++ b/devkit/error/Validation.sol @@ -39,12 +39,3 @@ library Check { check(addr.isContract(), ERR.NOT_CONTRACT); } } - -library Require { - function assigned(bytes4 str) internal { - check(str.isNotEmpty(), ERR.RQ_SELECTOR); - } - function contractAssigned(address addr) internal { - check(addr.isContract(), ERR.RQ_CONTRACT); - } -} diff --git a/devkit/method/core/FunctionLib.sol b/devkit/method/core/FunctionLib.sol index 48119f46..22e4dfb9 100644 --- a/devkit/method/core/FunctionLib.sol +++ b/devkit/method/core/FunctionLib.sol @@ -2,7 +2,8 @@ pragma solidity ^0.8.24; // Validation -import {check, Check, Require} from "devkit/error/Validation.sol"; +import {check, Check} from "devkit/error/Validation.sol"; +import {Require} from "devkit/error/Require.sol"; // Utils import {ForgeHelper, loadAddressFrom} from "../../utils/ForgeHelper.sol"; import {StringUtils} from "../../utils/StringUtils.sol"; From 27b75e63e3d588eff7399799b7e8e96b77197087 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 16:55:13 +0900 Subject: [PATCH 048/111] Update BundleLib --- devkit/config/Config.sol | 2 +- devkit/core/Bundle.sol | 2 +- devkit/error/Error.sol | 2 + devkit/error/{ => validation}/Require.sol | 15 +++++-- devkit/error/{ => validation}/Validation.sol | 2 +- devkit/method/MCBundleLib.sol | 2 +- devkit/method/MCDeployLib.sol | 2 +- devkit/method/MCTestLib.sol | 24 +++++------ devkit/method/core/BundleLib.sol | 42 +++++++++++--------- devkit/method/core/BundleRegistryLib.sol | 12 +++--- devkit/method/core/DictionaryLib.sol | 12 +++--- devkit/method/core/DictionaryRegistryLib.sol | 2 +- devkit/method/core/FunctionLib.sol | 4 +- devkit/method/core/FunctionRegistryLib.sol | 2 +- devkit/method/core/MockRegistryLib.sol | 2 +- devkit/method/core/ProxyLib.sol | 6 +-- devkit/method/core/ProxyRegistryLib.sol | 2 +- devkit/method/core/StdFunctionsLib.sol | 10 ++--- devkit/method/debug/Parser.sol | 2 +- devkit/method/inspector/Inspector.sol | 10 ++--- devkit/test/MockDictionary.sol | 6 +-- devkit/test/SimpleMockProxy.sol | 8 ++-- devkit/utils/AddressUtils.sol | 2 +- devkit/utils/Bytes4Utils.sol | 2 +- devkit/utils/StringUtils.sol | 2 +- test/devkit/MCDevKit.t.sol | 8 ++-- test/devkit/global/MCBundle.t.sol | 2 +- test/devkit/global/MCSetup.t.sol | 8 ++-- 28 files changed, 104 insertions(+), 91 deletions(-) rename devkit/error/{ => validation}/Require.sol (56%) rename devkit/error/{ => validation}/Validation.sol (95%) diff --git a/devkit/config/Config.sol b/devkit/config/Config.sol index c7d0245e..7e549963 100644 --- a/devkit/config/Config.sol +++ b/devkit/config/Config.sol @@ -80,7 +80,7 @@ library ConfigLib { // } // function defaultFunctionInfos(MCDevKit storage mc) internal returns(Function[] storage) { - // return mc.functions.std.allFunctions.functionInfos; + // return mc.functions.std.allFunctions.functions; // } // function defaultBundleName(MCDevKit storage mc) internal returns(string memory) { // return mc.functions.genUniqueBundleName(); diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index ac4a9d4b..8cb32628 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -16,7 +16,7 @@ import {Inspector} from "devkit/method/inspector/Inspector.sol"; ==================*/ struct Bundle { string name; - Function[] functionInfos; + Function[] functions; address facade; } using BundleLib for Bundle global; diff --git a/devkit/error/Error.sol b/devkit/error/Error.sol index b1e3d076..9e4c44fa 100644 --- a/devkit/error/Error.sol +++ b/devkit/error/Error.sol @@ -22,8 +22,10 @@ library ERR { string constant NOT_CONTRACT = "Not Contract Address"; string constant STR_ALREADY_ASSIGNED = "String Already Assigned"; string constant B4_ALREADY_ASSIGNED = "Bytes4 Already Assigned"; + // Require string constant RQ_SELECTOR = "Selector is required."; string constant RQ_CONTRACT = "Contract is required."; + string constant RQ_NOT_EMPTY_STRING = "String is empty."; // string constant STR_EXISTS = "String Already Exist"; string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; diff --git a/devkit/error/Require.sol b/devkit/error/validation/Require.sol similarity index 56% rename from devkit/error/Require.sol rename to devkit/error/validation/Require.sol index 7ea04ce3..60bbabc0 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/validation/Require.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {throwError, ERR} from "./Error.sol"; +import {throwError, ERR} from "devkit/error/Error.sol"; // Utils import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; @@ -12,11 +12,18 @@ import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; library Require { - function assigned(bytes4 str) internal { - check(str.isNotEmpty(), ERR.RQ_SELECTOR); + function notEmptyString(string memory str) internal { + check(str.isNotEmpty(), ERR.RQ_NOT_EMPTY_STRING); + } + function isContract(address addr) internal { + check(addr.isContract(), ERR.RQ_CONTRACT); + } + + function assigned(bytes4 b4) internal { + check(b4.isNotEmpty(), ERR.RQ_SELECTOR); } function contractAssigned(address addr) internal { check(addr.isContract(), ERR.RQ_CONTRACT); diff --git a/devkit/error/Validation.sol b/devkit/error/validation/Validation.sol similarity index 95% rename from devkit/error/Validation.sol rename to devkit/error/validation/Validation.sol index a401185a..6341bb0d 100644 --- a/devkit/error/Validation.sol +++ b/devkit/error/validation/Validation.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {throwError, ERR} from "./Error.sol"; +import {throwError, ERR} from "devkit/error/Error.sol"; // Utils import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; diff --git a/devkit/method/MCBundleLib.sol b/devkit/method/MCBundleLib.sol index b6e4c210..0be529e1 100644 --- a/devkit/method/MCBundleLib.sol +++ b/devkit/method/MCBundleLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Validation -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; import {ERR} from "devkit/error/Error.sol"; // Utils import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index 66bb8f8b..4ccbf46b 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; import {Config} from "devkit/config/Config.sol"; // Validation -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; // Utils import {Params} from "devkit/debug/Params.sol"; // Core diff --git a/devkit/method/MCTestLib.sol b/devkit/method/MCTestLib.sol index 2396824e..9024ac43 100644 --- a/devkit/method/MCTestLib.sol +++ b/devkit/method/MCTestLib.sol @@ -32,27 +32,27 @@ library MCTestLib { /** @notice Creates a SimpleMockProxy as a MockProxy @param name The name of the MockProxy, used as a key in the `mc.test.mockProxies` mapping and as a label name in the Forge test runner. If not provided, sequential default names from `MockProxy0` to `MockProxy4` will be used. - @param functionInfos The function contract infos to be registered with the SimpleMockProxy. A bundle can also be specified. Note that the SimpleMockProxy cannot have its functions changed later. If no functions are provided, defaultBundle will be used. + @param functions The function contract infos to be registered with the SimpleMockProxy. A bundle can also be specified. Note that the SimpleMockProxy cannot have its functions changed later. If no functions are provided, defaultBundle will be used. */ - function createSimpleMockProxy(MCDevKit storage mc, string memory name, Function[] memory functionInfos) internal returns(MCDevKit storage) { + function createSimpleMockProxy(MCDevKit storage mc, string memory name, Function[] memory functions) internal returns(MCDevKit storage) { string memory params = Params.append(name); - // for (uint i; i < functionInfos.length; ++i) { - // params = params.comma().append(functionInfos[i].name); + // for (uint i; i < functions.length; ++i) { + // params = params.comma().append(functions[i].name); // } uint pid = mc.recordExecStart("createSimpleMockProxy", params); - Proxy memory simpleMockProxy = ProxyLib.createSimpleMockProxy(functionInfos); + Proxy memory simpleMockProxy = ProxyLib.createSimpleMockProxy(functions); mc.proxy.safeAdd(name, simpleMockProxy) .safeUpdate(simpleMockProxy); return mc.recordExecFinish(pid); } function createSimpleMockProxy(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(MCDevKit storage) { - return mc.createSimpleMockProxy(name, bundleInfo.functionInfos); + return mc.createSimpleMockProxy(name, bundleInfo.functions); } function createSimpleMockProxy(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { return mc.createSimpleMockProxy(name, mc.std.all); } - // function createSimpleMockProxy(MCDevKit storage mc, Function[] memory functionInfos) internal returns(MCDevKit storage) { - // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), functionInfos); + // function createSimpleMockProxy(MCDevKit storage mc, Function[] memory functions) internal returns(MCDevKit storage) { + // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), functions); // } // function createSimpleMockProxy(MCDevKit storage mc) internal returns(MCDevKit storage) { // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), mc.std.all); @@ -66,17 +66,17 @@ library MCTestLib { @notice Creates a DictionaryEtherscan as a MockDictionary. @param name The name of the `MockDictionary`, used as a key in the `mc.test.mockDictionaries` mapping and as a label name in the Forge test runner. If not provided, sequential default names from `MockDictionary0` to `MockDictionary4` will be used. @param owner The address to be set as the owner of the DictionaryEtherscan contract. If not provided, the DefaultOwner from the UCS environment settings is used. - @param functionInfos The Functions to be registered with the `MockDictionary`. A bundle can also be specified. If no Ops are provided, defaultBundle will be used. + @param functions The Functions to be registered with the `MockDictionary`. A bundle can also be specified. If no Ops are provided, defaultBundle will be used. */ - function createMockDictionary(MCDevKit storage mc, string memory name, address owner, Function[] memory functionInfos) internal returns(MCDevKit storage) { + function createMockDictionary(MCDevKit storage mc, string memory name, address owner, Function[] memory functions) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("createMockDictionary", Params.append(name, owner)); - Dictionary memory mockDictionary = DictionaryLib.createMockDictionary(owner, functionInfos); + Dictionary memory mockDictionary = DictionaryLib.createMockDictionary(owner, functions); mc.dictionary .safeAdd(name, mockDictionary) .safeUpdate(mockDictionary); return mc.recordExecFinish(pid); } function createMockDictionary(MCDevKit storage mc, string memory name, address owner, Bundle storage bundleInfo) internal returns(MCDevKit storage) { - return mc.createMockDictionary(name, owner, bundleInfo.functionInfos); + return mc.createMockDictionary(name, owner, bundleInfo.functions); } function createMockDictionary(MCDevKit storage mc, string memory name, address owner) internal returns(MCDevKit storage) { return mc.createMockDictionary(name, owner, mc.std.all); diff --git a/devkit/method/core/BundleLib.sol b/devkit/method/core/BundleLib.sol index d9f4c021..252ac5c8 100644 --- a/devkit/method/core/BundleLib.sol +++ b/devkit/method/core/BundleLib.sol @@ -2,7 +2,8 @@ pragma solidity ^0.8.24; // Validation -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; +import {Require} from "devkit/error/validation/Require.sol"; // Utils import {console2} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; @@ -30,31 +31,34 @@ library BundleLib { /**--------------------------- đŸ“Ĩ Assign Bundle -----------------------------*/ - function safeAssign(Bundle storage bundle, string memory name) internal returns(Bundle storage) { - uint pid = bundle.startProcess("safeAssign"); - bundle.name = name.assertNotEmpty(); + function assignName(Bundle storage bundle, string memory name) internal returns(Bundle storage) { + uint pid = bundle.startProcess("assignName"); + Require.notEmptyString(name); + bundle.name = name; return bundle.finishProcess(pid); } - function safeAssign(Bundle storage bundle, address facade) internal returns(Bundle storage) { - uint pid = bundle.startProcess("safeAssign"); - bundle.facade = facade.assertIsContract(); - return bundle.finishProcess(pid); - } - - function safeAdd(Bundle storage bundle, Function storage functionInfo) internal returns(Bundle storage) { - uint pid = bundle.startProcess("safeAdd"); - check(bundle.hasNot(functionInfo), "Already added"); - bundle.functionInfos.push( - functionInfo.assertImplIsContract() + function pushFunction(Bundle storage bundle, Function storage func) internal returns(Bundle storage) { + uint pid = bundle.startProcess("pushFunction"); + check(bundle.hasNot(func), "Already added"); + bundle.functions.push( + func.assertImplIsContract() ); return bundle.finishProcess(pid); } - function safeAdd(Bundle storage bundle, Function[] storage functionInfos) internal returns(Bundle storage) { - uint pid = bundle.startProcess("safeAdd"); - for (uint i; i < functionInfos.length; ++i) { - bundle.safeAdd(functionInfos[i]); + function pushFunctions(Bundle storage bundle, Function[] storage functions) internal returns(Bundle storage) { + uint pid = bundle.startProcess("pushFunctions"); + for (uint i; i < functions.length; ++i) { + bundle.pushFunction(functions[i]); } return bundle.finishProcess(pid); } + + function assignFacade(Bundle storage bundle, address facade) internal returns(Bundle storage) { + uint pid = bundle.startProcess("assignFacade"); + Require.isContract(facade); + bundle.facade = facade; + return bundle.finishProcess(pid); + } + } diff --git a/devkit/method/core/BundleRegistryLib.sol b/devkit/method/core/BundleRegistryLib.sol index c4ab72f1..4c4aca75 100644 --- a/devkit/method/core/BundleRegistryLib.sol +++ b/devkit/method/core/BundleRegistryLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Error & Debug -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; import {ERR, throwError} from "devkit/error/Error.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config @@ -40,7 +40,7 @@ library BundleRegistryLib { -----------------------*/ function init(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { uint pid = bundle.startProcess("init"); - bundle.bundles[name].safeAssign(name); + bundle.bundles[name].assignName(name); bundle.safeUpdateCurrentBundle(name); return bundle.finishProcess(pid); } @@ -58,12 +58,12 @@ library BundleRegistryLib { ---------------------------------------*/ function addToBundle(BundleRegistry storage bundle, Function storage functionInfo) internal returns(BundleRegistry storage) { uint pid = bundle.startProcess("addToBundle", "function"); - bundle.findCurrentBundle().safeAdd(functionInfo); + bundle.findCurrentBundle().pushFunction(functionInfo); return bundle.finishProcess(pid); } - function addToBundle(BundleRegistry storage bundle, Function[] storage functionInfos) internal returns(BundleRegistry storage) { + function addToBundle(BundleRegistry storage bundle, Function[] storage functions) internal returns(BundleRegistry storage) { uint pid = bundle.startProcess("addToBundle", "bundle"); // TODO params - bundle.findCurrentBundle().safeAdd(functionInfos); + bundle.findCurrentBundle().pushFunctions(functions); return bundle.finishProcess(pid); } @@ -75,7 +75,7 @@ library BundleRegistryLib { uint pid = bundle.startProcess("set"); bundle.bundles[name] .assertExists() - .safeAssign(facade); + .assignFacade(facade); return bundle.finishProcess(pid); } function set(BundleRegistry storage bundle, address facade) internal returns(BundleRegistry storage) { diff --git a/devkit/method/core/DictionaryLib.sol b/devkit/method/core/DictionaryLib.sol index da310460..e0883eff 100644 --- a/devkit/method/core/DictionaryLib.sol +++ b/devkit/method/core/DictionaryLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; import {Params} from "devkit/debug/Params.sol"; // Utils import {AddressUtils} from "devkit/utils/AddressUtils.sol"; @@ -110,10 +110,10 @@ library DictionaryLib { function set(Dictionary memory dictionary, Bundle storage bundleInfo) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(bundleInfo.name)); - Function[] memory functionInfos = bundleInfo.functionInfos; + Function[] memory functions = bundleInfo.functions; - for (uint i; i < functionInfos.length; ++i) { - dictionary.set(functionInfos[i]); + for (uint i; i < functions.length; ++i) { + dictionary.set(functions[i]); } // TODO Generate Facade @@ -138,10 +138,10 @@ library DictionaryLib { /**------------------------------ 🤖 Create Mock Dictionary --------------------------------*/ - function createMockDictionary(address owner, Function[] memory functionInfos) internal returns(Dictionary memory) { + function createMockDictionary(address owner, Function[] memory functions) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("createMockDictionary"); return Dictionary({ - addr: address(new MockDictionary(owner, functionInfos)), + addr: address(new MockDictionary(owner, functions)), kind: DictionaryKind.Mock }).finishProcess(pid); } diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol index 4c3573c3..b4e93340 100644 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; diff --git a/devkit/method/core/FunctionLib.sol b/devkit/method/core/FunctionLib.sol index 22e4dfb9..f5050957 100644 --- a/devkit/method/core/FunctionLib.sol +++ b/devkit/method/core/FunctionLib.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.24; // Validation -import {check, Check} from "devkit/error/Validation.sol"; -import {Require} from "devkit/error/Require.sol"; +import {check, Check} from "devkit/error/validation/Validation.sol"; +import {Require} from "devkit/error/validation/Require.sol"; // Utils import {ForgeHelper, loadAddressFrom} from "../../utils/ForgeHelper.sol"; import {StringUtils} from "../../utils/StringUtils.sol"; diff --git a/devkit/method/core/FunctionRegistryLib.sol b/devkit/method/core/FunctionRegistryLib.sol index f6808cf6..950c10b9 100644 --- a/devkit/method/core/FunctionRegistryLib.sol +++ b/devkit/method/core/FunctionRegistryLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Error & Debug -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; import {ERR, throwError} from "devkit/error/Error.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config diff --git a/devkit/method/core/MockRegistryLib.sol b/devkit/method/core/MockRegistryLib.sol index b462de2f..03ae4873 100644 --- a/devkit/method/core/MockRegistryLib.sol +++ b/devkit/method/core/MockRegistryLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; -import {check, Check} from "devkit/error/Validation.sol"; +import {check, Check} from "devkit/error/validation/Validation.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; diff --git a/devkit/method/core/ProxyLib.sol b/devkit/method/core/ProxyLib.sol index c0b7265c..6247cb3f 100644 --- a/devkit/method/core/ProxyLib.sol +++ b/devkit/method/core/ProxyLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Errors & Debug -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Utils import {AddressUtils} from "devkit/utils/AddressUtils.sol"; @@ -74,10 +74,10 @@ library ProxyLib { /**------------------------- 🤖 Create Mock Proxy ---------------------------*/ - function createSimpleMockProxy(Function[] memory functionInfos) internal returns(Proxy memory) { + function createSimpleMockProxy(Function[] memory functions) internal returns(Proxy memory) { uint pid = ProcessLib.startProxyLibProcess("createSimpleMockProxy"); return Proxy({ - addr: address(new SimpleMockProxy(functionInfos)), + addr: address(new SimpleMockProxy(functions)), kind: ProxyKind.Mock }).finishProcess(pid); } diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol index 94ee913e..49f2e5c1 100644 --- a/devkit/method/core/ProxyRegistryLib.sol +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; diff --git a/devkit/method/core/StdFunctionsLib.sol b/devkit/method/core/StdFunctionsLib.sol index 37a98db1..37153172 100644 --- a/devkit/method/core/StdFunctionsLib.sol +++ b/devkit/method/core/StdFunctionsLib.sol @@ -116,11 +116,11 @@ library StdFunctionsLib { /**===== Each Std Bundle =====*/ function configureStdBundle_AllFunctions(StdFunctions storage std) internal returns(StdFunctions storage) { uint pid = std.startProcess("configureStdBundle_AllFunctions"); - std.all .safeAssign("ALL_FUNCTIONS") - .safeAdd(std.initSetAdmin) - .safeAdd(std.getDeps) - .safeAdd(std.clone) - .safeAssign(address(new StdFacade())); + std.all .assignName("ALL_FUNCTIONS") + .pushFunction(std.initSetAdmin) + .pushFunction(std.getDeps) + .pushFunction(std.clone) + .assignFacade(address(new StdFacade())); return std.finishProcess(pid); } diff --git a/devkit/method/debug/Parser.sol b/devkit/method/debug/Parser.sol index 128d3e8b..38d94458 100644 --- a/devkit/method/debug/Parser.sol +++ b/devkit/method/debug/Parser.sol @@ -27,7 +27,7 @@ library Parser { function parse(Bundle storage bundle) internal returns(string memory message) { message = message.append("Facade: ").append(bundle.facade); - Function[] memory _funcs = bundle.functionInfos; + Function[] memory _funcs = bundle.functions; for (uint i; i < _funcs.length; ++i) { message = message.br().append(_funcs[i].parse()); } diff --git a/devkit/method/inspector/Inspector.sol b/devkit/method/inspector/Inspector.sol index 83eb4f42..01521f3d 100644 --- a/devkit/method/inspector/Inspector.sol +++ b/devkit/method/inspector/Inspector.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {check, Check} from "devkit/error/Validation.sol"; +import {check, Check} from "devkit/error/validation/Validation.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; import {AddressUtils} from "devkit/utils/AddressUtils.sol"; @@ -98,8 +98,8 @@ library Inspector { đŸ—‚ī¸ Bundle =================*/ function has(Bundle storage bundle, Function storage functionInfo) internal view returns(bool flag) { - for (uint i; i < bundle.functionInfos.length; ++i) { - if (functionInfo.isEqual(bundle.functionInfos[i])) return true; + for (uint i; i < bundle.functions.length; ++i) { + if (functionInfo.isEqual(bundle.functions[i])) return true; } } function hasNot(Bundle storage bundle, Function storage functionInfo) internal returns(bool) { @@ -108,7 +108,7 @@ library Inspector { function isComplete(Bundle storage bundle) internal returns(bool) { return bundle.name.isNotEmpty() && - bundle.functionInfos.length != 0 && + bundle.functions.length != 0 && bundle.facade.isContract(); } function assertComplete(Bundle storage bundle) internal returns(Bundle storage) { @@ -125,7 +125,7 @@ library Inspector { function exists(Bundle storage bundle) internal returns(bool) { return bundle.name.isNotEmpty() || - bundle.functionInfos.length != 0 || + bundle.functions.length != 0 || bundle.facade.isNotContract(); } function notExists(Bundle storage bundle) internal returns(bool) { diff --git a/devkit/test/MockDictionary.sol b/devkit/test/MockDictionary.sol index 3620d2ee..19f5f29b 100644 --- a/devkit/test/MockDictionary.sol +++ b/devkit/test/MockDictionary.sol @@ -10,9 +10,9 @@ import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; @title Mock Dictionary Contract */ contract MockDictionary is DictionaryEtherscan { - constructor (address owner, Function[] memory functionInfos) DictionaryEtherscan(owner) { - for (uint i; i < functionInfos.length; ++i) { - setImplementation(functionInfos[i].selector, functionInfos[i].implementation); + constructor (address owner, Function[] memory functions) DictionaryEtherscan(owner) { + for (uint i; i < functions.length; ++i) { + setImplementation(functions[i].selector, functions[i].implementation); } } } diff --git a/devkit/test/SimpleMockProxy.sol b/devkit/test/SimpleMockProxy.sol index 13bbcf4a..c12228ba 100644 --- a/devkit/test/SimpleMockProxy.sol +++ b/devkit/test/SimpleMockProxy.sol @@ -10,11 +10,11 @@ import {Proxy as OZProxy} from "@oz.mc/proxy/Proxy.sol"; @title Mock Proxy Contract */ contract SimpleMockProxy is OZProxy { - constructor (Function[] memory functionInfos) { - for (uint i; i < functionInfos.length; ++i) { + constructor (Function[] memory functions) { + for (uint i; i < functions.length; ++i) { SimpleMockProxyLib.set({ - selector: functionInfos[i].selector, - implementation: functionInfos[i].implementation + selector: functions[i].selector, + implementation: functions[i].implementation }); } } diff --git a/devkit/utils/AddressUtils.sol b/devkit/utils/AddressUtils.sol index 597c885c..ac855821 100644 --- a/devkit/utils/AddressUtils.sol +++ b/devkit/utils/AddressUtils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; // Utils import {vm} from "./ForgeHelper.sol"; import {BoolUtils} from "./BoolUtils.sol"; diff --git a/devkit/utils/Bytes4Utils.sol b/devkit/utils/Bytes4Utils.sol index c29ba7d5..357b45d8 100644 --- a/devkit/utils/Bytes4Utils.sol +++ b/devkit/utils/Bytes4Utils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; // Utils import {vm} from "./ForgeHelper.sol"; import {StringUtils} from "./StringUtils.sol"; diff --git a/devkit/utils/StringUtils.sol b/devkit/utils/StringUtils.sol index 3ec92c1c..c79be56d 100644 --- a/devkit/utils/StringUtils.sol +++ b/devkit/utils/StringUtils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {check} from "devkit/error/Validation.sol"; +import {check} from "devkit/error/validation/Validation.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Utils import {StdStyle, ForgeHelper, vm} from "./ForgeHelper.sol"; diff --git a/test/devkit/MCDevKit.t.sol b/test/devkit/MCDevKit.t.sol index cdd99f7e..8ec9e15e 100644 --- a/test/devkit/MCDevKit.t.sol +++ b/test/devkit/MCDevKit.t.sol @@ -23,10 +23,10 @@ contract MCDevKitTest is Test { assertTrue(mc.std.getDeps.isGetDeps()); assertTrue(mc.std.clone.isClone()); - assertTrue(mc.std.all.functionInfos.length == 3); - assertTrue(mc.std.all.functionInfos[0].isInitSetAdmin()); - assertTrue(mc.std.all.functionInfos[1].isGetDeps()); - assertTrue(mc.std.all.functionInfos[2].isClone()); + assertTrue(mc.std.all.functions.length == 3); + assertTrue(mc.std.all.functions[0].isInitSetAdmin()); + assertTrue(mc.std.all.functions[1].isGetDeps()); + assertTrue(mc.std.all.functions[2].isClone()); } function test_Success_init_withName() public { diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 9361ed71..9b7b2911 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -64,7 +64,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { assertEq(func.name, functionName); assertEq(func.selector, selector); assertEq(func.implementation, impl); - assertTrue(bundle.functionInfos[functionsIndex].isEqual(func)); + assertTrue(bundle.functions[functionsIndex].isEqual(func)); assertEq(mc.functions.currentName, functionName); } diff --git a/test/devkit/global/MCSetup.t.sol b/test/devkit/global/MCSetup.t.sol index 2ba6f153..4c2d8512 100644 --- a/test/devkit/global/MCSetup.t.sol +++ b/test/devkit/global/MCSetup.t.sol @@ -19,10 +19,10 @@ contract DevKitTest_MCSetup is MCDevKitTest { assertTrue(mc.std.getDeps.isGetDeps()); assertTrue(mc.std.clone.isClone()); - assertTrue(mc.std.all.functionInfos.length == 3); - assertTrue(mc.std.all.functionInfos[0].isInitSetAdmin()); - assertTrue(mc.std.all.functionInfos[1].isGetDeps()); - assertTrue(mc.std.all.functionInfos[2].isClone()); + assertTrue(mc.std.all.functions.length == 3); + assertTrue(mc.std.all.functions[0].isInitSetAdmin()); + assertTrue(mc.std.all.functions[1].isGetDeps()); + assertTrue(mc.std.all.functions[2].isClone()); } } From 6b61368b3266875958f3386c256d8547606f8fe2 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 17:24:26 +0900 Subject: [PATCH 049/111] Rename Check & Require to Valid --- devkit/core/Bundle.sol | 63 +++++++++++++++---- .../{validation/Validation.sol => Valid.sol} | 29 ++++++--- devkit/error/validation/Require.sol | 31 --------- devkit/method/MCBundleLib.sol | 6 +- devkit/method/MCDeployLib.sol | 2 +- devkit/method/core/BundleLib.sol | 43 +------------ devkit/method/core/BundleRegistryLib.sol | 4 +- devkit/method/core/DictionaryLib.sol | 2 +- devkit/method/core/DictionaryRegistryLib.sol | 2 +- devkit/method/core/FunctionLib.sol | 35 +++++------ devkit/method/core/FunctionRegistryLib.sol | 4 +- devkit/method/core/MockRegistryLib.sol | 14 ++--- devkit/method/core/ProxyLib.sol | 2 +- devkit/method/core/ProxyRegistryLib.sol | 2 +- devkit/method/inspector/Inspector.sol | 42 ++++++------- devkit/utils/AddressUtils.sol | 8 +-- devkit/utils/Bytes4Utils.sol | 6 +- devkit/utils/StringUtils.sol | 8 +-- 18 files changed, 142 insertions(+), 161 deletions(-) rename devkit/error/{validation/Validation.sol => Valid.sol} (52%) delete mode 100644 devkit/error/validation/Require.sol diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 8cb32628..460ad8a0 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -1,26 +1,67 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; - -// Core Type -import {Function} from "devkit/core/Function.sol"; -// Core Method -import {BundleLib} from "devkit/method/core/BundleLib.sol"; -// Support Methods +/**-------------------------- + Apply Support Methods +----------------------------*/ import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; + using ProcessLib for Bundle global; import {Parser} from "devkit/method/debug/Parser.sol"; + using Parser for Bundle global; import {Inspector} from "devkit/method/inspector/Inspector.sol"; + using Inspector for Bundle global; + +// Core Type +import {Function} from "devkit/core/Function.sol"; +// Validation +import {valid, Valid} from "devkit/error/Valid.sol"; /**================ đŸ—‚ī¸ Bundle ==================*/ +using BundleLib for Bundle global; struct Bundle { string name; Function[] functions; address facade; } -using BundleLib for Bundle global; -// Support Methods -using ProcessLib for Bundle global; -using Parser for Bundle global; -using Inspector for Bundle global; + +/**~~~~~~~~~~~~~~~~~~~~~~~~~~~ + đŸ—‚ī¸ Core Methods + đŸ“Ĩ Assign Bundle +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +library BundleLib { + /**--------------------------- + đŸ“Ĩ Assign Bundle + -----------------------------*/ + function assignName(Bundle storage bundle, string memory name) internal returns(Bundle storage) { + uint pid = bundle.startProcess("assignName"); + Valid.notEmptyString(name); + bundle.name = name; + return bundle.finishProcess(pid); + } + + function pushFunction(Bundle storage bundle, Function storage func) internal returns(Bundle storage) { + uint pid = bundle.startProcess("pushFunction"); + valid(bundle.hasNot(func), "Already added"); + bundle.functions.push( + func.assertImplIsContract() + ); + return bundle.finishProcess(pid); + } + function pushFunctions(Bundle storage bundle, Function[] storage functions) internal returns(Bundle storage) { + uint pid = bundle.startProcess("pushFunctions"); + for (uint i; i < functions.length; ++i) { + bundle.pushFunction(functions[i]); + } + return bundle.finishProcess(pid); + } + + function assignFacade(Bundle storage bundle, address facade) internal returns(Bundle storage) { + uint pid = bundle.startProcess("assignFacade"); + Valid.isContract(facade); + bundle.facade = facade; + return bundle.finishProcess(pid); + } + +} diff --git a/devkit/error/validation/Validation.sol b/devkit/error/Valid.sol similarity index 52% rename from devkit/error/validation/Validation.sol rename to devkit/error/Valid.sol index 6341bb0d..174ea86e 100644 --- a/devkit/error/validation/Validation.sol +++ b/devkit/error/Valid.sol @@ -13,29 +13,40 @@ import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; /// @dev like `require` -function check(bool condition, string memory errorBody) { +function valid(bool condition, string memory errorBody) { if (condition.isFalse()) throwError(errorBody); } -function check(bool condition, string memory errorBody, string memory errorDetail) { - check(condition, errorBody.append(errorDetail)); +function valid(bool condition, string memory errorBody, string memory errorDetail) { + valid(condition, errorBody.append(errorDetail)); } -library Check { +library Valid { function isUnassigned(string storage str) internal { - check(str.isEmpty(), ERR.STR_ALREADY_ASSIGNED); + valid(str.isEmpty(), ERR.STR_ALREADY_ASSIGNED); } function isNotEmpty(string memory str) internal { - check(str.isNotEmpty(), ERR.EMPTY_STR); + valid(str.isNotEmpty(), ERR.EMPTY_STR); } function isUnassigned(bytes4 b4) internal { - check(b4.isEmpty(), ERR.B4_ALREADY_ASSIGNED); + valid(b4.isEmpty(), ERR.B4_ALREADY_ASSIGNED); } function isNotEmpty(bytes4 b4) internal { - check(b4.isNotEmpty(), ERR.EMPTY_B4); + valid(b4.isNotEmpty(), ERR.EMPTY_B4); } function isContract(address addr) internal { - check(addr.isContract(), ERR.NOT_CONTRACT); + valid(addr.isContract(), ERR.NOT_CONTRACT); + } + + function notEmptyString(string memory str) internal { + valid(str.isNotEmpty(), ERR.RQ_NOT_EMPTY_STRING); + } + + function assigned(bytes4 b4) internal { + valid(b4.isNotEmpty(), ERR.RQ_SELECTOR); + } + function contractAssigned(address addr) internal { + valid(addr.isContract(), ERR.RQ_CONTRACT); } } diff --git a/devkit/error/validation/Require.sol b/devkit/error/validation/Require.sol deleted file mode 100644 index 60bbabc0..00000000 --- a/devkit/error/validation/Require.sol +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import {throwError, ERR} from "devkit/error/Error.sol"; -// Utils -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; - -import {check} from "devkit/error/validation/Validation.sol"; - -library Require { - function notEmptyString(string memory str) internal { - check(str.isNotEmpty(), ERR.RQ_NOT_EMPTY_STRING); - } - function isContract(address addr) internal { - check(addr.isContract(), ERR.RQ_CONTRACT); - } - - function assigned(bytes4 b4) internal { - check(b4.isNotEmpty(), ERR.RQ_SELECTOR); - } - function contractAssigned(address addr) internal { - check(addr.isContract(), ERR.RQ_CONTRACT); - } -} diff --git a/devkit/method/MCBundleLib.sol b/devkit/method/MCBundleLib.sol index 0be529e1..1a131f06 100644 --- a/devkit/method/MCBundleLib.sol +++ b/devkit/method/MCBundleLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Validation -import {check} from "devkit/error/validation/Validation.sol"; +import {valid} from "devkit/error/Valid.sol"; import {ERR} from "devkit/error/Error.sol"; // Utils import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; @@ -70,7 +70,7 @@ library MCBundleLib { // return mc; // } TODO function use(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - check(mc.functions.find(name).isComplete(), "Invalid Function Name"); + valid(mc.functions.find(name).isComplete(), "Invalid Function Name"); return mc.use(mc.findFunction(name)); } /**--------------------------- @@ -100,7 +100,7 @@ library MCBundleLib { --------------------*/ function useFacade(MCDevKit storage mc, address facade) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("set"); - check(mc.bundle.existsCurrentBundle(), ERR.NOT_INIT); + valid(mc.bundle.existsCurrentBundle(), ERR.NOT_INIT); mc.bundle.set(mc.bundle.findCurrentBundleName(), facade); return mc.recordExecFinish(pid); } diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index 4ccbf46b..6b7c72d7 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; import {Config} from "devkit/config/Config.sol"; // Validation -import {check} from "devkit/error/validation/Validation.sol"; +import {valid} from "devkit/error/Valid.sol"; // Utils import {Params} from "devkit/debug/Params.sol"; // Core diff --git a/devkit/method/core/BundleLib.sol b/devkit/method/core/BundleLib.sol index 252ac5c8..d2b9fc5a 100644 --- a/devkit/method/core/BundleLib.sol +++ b/devkit/method/core/BundleLib.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.24; // Validation -import {check} from "devkit/error/validation/Validation.sol"; -import {Require} from "devkit/error/validation/Require.sol"; +import {valid} from "devkit/error/Valid.sol"; +import {Valid} from "devkit/error/Valid.sol"; // Utils import {console2} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; @@ -23,42 +23,3 @@ import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~ - đŸ—‚ī¸ Bundle - đŸ“Ĩ Assign Bundle -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library BundleLib { - /**--------------------------- - đŸ“Ĩ Assign Bundle - -----------------------------*/ - function assignName(Bundle storage bundle, string memory name) internal returns(Bundle storage) { - uint pid = bundle.startProcess("assignName"); - Require.notEmptyString(name); - bundle.name = name; - return bundle.finishProcess(pid); - } - - function pushFunction(Bundle storage bundle, Function storage func) internal returns(Bundle storage) { - uint pid = bundle.startProcess("pushFunction"); - check(bundle.hasNot(func), "Already added"); - bundle.functions.push( - func.assertImplIsContract() - ); - return bundle.finishProcess(pid); - } - function pushFunctions(Bundle storage bundle, Function[] storage functions) internal returns(Bundle storage) { - uint pid = bundle.startProcess("pushFunctions"); - for (uint i; i < functions.length; ++i) { - bundle.pushFunction(functions[i]); - } - return bundle.finishProcess(pid); - } - - function assignFacade(Bundle storage bundle, address facade) internal returns(Bundle storage) { - uint pid = bundle.startProcess("assignFacade"); - Require.isContract(facade); - bundle.facade = facade; - return bundle.finishProcess(pid); - } - -} diff --git a/devkit/method/core/BundleRegistryLib.sol b/devkit/method/core/BundleRegistryLib.sol index 4c4aca75..95b510bc 100644 --- a/devkit/method/core/BundleRegistryLib.sol +++ b/devkit/method/core/BundleRegistryLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Error & Debug -import {check} from "devkit/error/validation/Validation.sol"; +import {valid} from "devkit/error/Valid.sol"; import {ERR, throwError} from "devkit/error/Error.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config @@ -46,7 +46,7 @@ library BundleRegistryLib { } function safeInit(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { uint pid = bundle.startProcess("safeInit"); - check(name.isNotEmpty(), "Empty Name"); + valid(name.isNotEmpty(), "Empty Name"); return bundle.assertBundleNotExists(name) .init(name) .finishProcess(pid); diff --git a/devkit/method/core/DictionaryLib.sol b/devkit/method/core/DictionaryLib.sol index e0883eff..403ad988 100644 --- a/devkit/method/core/DictionaryLib.sol +++ b/devkit/method/core/DictionaryLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {check} from "devkit/error/validation/Validation.sol"; +import {valid} from "devkit/error/Valid.sol"; import {Params} from "devkit/debug/Params.sol"; // Utils import {AddressUtils} from "devkit/utils/AddressUtils.sol"; diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol index b4e93340..8da709a5 100644 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; -import {check} from "devkit/error/validation/Validation.sol"; +import {valid} from "devkit/error/Valid.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; diff --git a/devkit/method/core/FunctionLib.sol b/devkit/method/core/FunctionLib.sol index f5050957..7ad291d6 100644 --- a/devkit/method/core/FunctionLib.sol +++ b/devkit/method/core/FunctionLib.sol @@ -2,8 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {check, Check} from "devkit/error/validation/Validation.sol"; -import {Require} from "devkit/error/validation/Require.sol"; +import {valid, Valid} from "devkit/error/Valid.sol"; // Utils import {ForgeHelper, loadAddressFrom} from "../../utils/ForgeHelper.sol"; import {StringUtils} from "../../utils/StringUtils.sol"; @@ -29,10 +28,10 @@ library FunctionLib { --------------------------*/ function assign(Function storage func, string memory name, bytes4 selector, address implementation) internal returns(Function storage) { uint pid = func.startProcess("safeAssign"); - Check.isUnassigned(func.name); - Check.isNotEmpty(name); - Check.isNotEmpty(selector); - Check.isContract(implementation); + Valid.isUnassigned(func.name); + Valid.isNotEmpty(name); + Valid.isNotEmpty(selector); + Valid.isContract(implementation); func.name = name; func.selector = selector; func.implementation = implementation; @@ -44,8 +43,8 @@ library FunctionLib { return func; } function build(Function storage func) internal returns(Function storage) { - Require.assigned(func.selector); - Require.contractAssigned(func.implementation); + Valid.assigned(func.selector); + Valid.contractAssigned(func.implementation); func.buildStatus = BuildStatus.Built; return func; } @@ -76,7 +75,7 @@ library FunctionLib { } function safeAssign(Function storage func, string memory name) internal returns(Function storage) { uint pid = func.startProcess("safeAssign"); - Check.isNotEmpty(name); + Valid.isNotEmpty(name); return func .assertEmptyName() .assign(name) .finishProcess(pid); @@ -85,7 +84,7 @@ library FunctionLib { /**----- Selector --------*/ function safeAssign(Function storage func, bytes4 selector) internal returns(Function storage) { uint pid = func.startProcess("safeAssign"); - Check.isNotEmpty(selector); + Valid.isNotEmpty(selector); return func .assertEmptySelector() .assign(selector) .finishProcess(pid); @@ -98,7 +97,7 @@ library FunctionLib { /**----- Implementation --------*/ function safeAssign(Function storage func, address implementation) internal returns(Function storage) { uint pid = func.startProcess("safeAssign"); - Check.isContract(implementation); + Valid.isContract(implementation); return func .assertEmptyImpl() .assign(implementation) .finishProcess(pid); @@ -109,8 +108,8 @@ library FunctionLib { } function fetch(Function storage func, string memory envKey) internal returns(Function storage) { uint pid = func.startProcess("fetch"); - Check.isUnassigned(func.name); - Check.isNotEmpty(envKey); + Valid.isUnassigned(func.name); + Valid.isNotEmpty(envKey); return func; } function fetchAndAssign(Function storage func, string memory envKey, bytes4 selector) internal returns(Function storage) { @@ -127,15 +126,15 @@ library FunctionLib { .finishProcess(pid); } function loadAndAssignFromEnv(Function storage func) internal returns(Function storage) { - Check.isNotEmpty(func.name); - Check.isNotEmpty(func.selector); + Valid.isNotEmpty(func.name); + Valid.isNotEmpty(func.selector); return func.loadAndAssignFromEnv(func.name, func.name, func.selector); } function safeLoadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { uint pid = func.startProcess("safeLoadAndAssignFromEnv"); - Check.isNotEmpty(envKey); - Check.isNotEmpty(name); - Check.isNotEmpty(selector); + Valid.isNotEmpty(envKey); + Valid.isNotEmpty(name); + Valid.isNotEmpty(selector); return func.loadAndAssignFromEnv(envKey, name, selector).finishProcess(pid); } diff --git a/devkit/method/core/FunctionRegistryLib.sol b/devkit/method/core/FunctionRegistryLib.sol index 950c10b9..658af8f6 100644 --- a/devkit/method/core/FunctionRegistryLib.sol +++ b/devkit/method/core/FunctionRegistryLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Error & Debug -import {check} from "devkit/error/validation/Validation.sol"; +import {valid} from "devkit/error/Valid.sol"; import {ERR, throwError} from "devkit/error/Error.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config @@ -34,7 +34,7 @@ library FunctionRegistryLib { -----------------------------*/ function safeAddFunction(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { uint pid = functions.startProcess("safeAddFunction"); - check(name.isNotEmpty(), "Empty Name"); + valid(name.isNotEmpty(), "Empty Name"); functions.customs[name] .safeAssign(name) .safeAssign(selector) diff --git a/devkit/method/core/MockRegistryLib.sol b/devkit/method/core/MockRegistryLib.sol index 03ae4873..8106322b 100644 --- a/devkit/method/core/MockRegistryLib.sol +++ b/devkit/method/core/MockRegistryLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; -import {check, Check} from "devkit/error/validation/Validation.sol"; +import {valid, Valid} from "devkit/error/Valid.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; @@ -41,8 +41,8 @@ library MockRegistryLib { /*----- Mock Dictionary -----*/ function add(MockRegistry storage mock, string memory name, Dictionary memory dictionary) internal returns(MockRegistry storage) { uint pid = mock.startProcess("add"); - Check.isNotEmpty(name); - check(dictionary.isNotEmpty(), "Empty Dictionary"); + Valid.isNotEmpty(name); + valid(dictionary.isNotEmpty(), "Empty Dictionary"); mock.dictionary[name] = dictionary; return mock.finishProcess(pid); } @@ -53,8 +53,8 @@ library MockRegistryLib { /*----- Mock Proxy -----*/ function add(MockRegistry storage mock, string memory name, Proxy memory proxy) internal returns(MockRegistry storage) { uint pid = mock.startProcess("add"); - Check.isNotEmpty(name); - check(proxy.isNotEmpty(), "Empty Proxy"); + Valid.isNotEmpty(name); + valid(proxy.isNotEmpty(), "Empty Proxy"); mock.proxy[name] = proxy; return mock.finishProcess(pid); } @@ -69,14 +69,14 @@ library MockRegistryLib { /*----- Mock Dictionary -----*/ function findMockDictionary(MockRegistry storage mock, string memory name) internal returns(Dictionary storage) { uint pid = mock.startProcess("findMockDictionary"); - Check.isNotEmpty(name); + Valid.isNotEmpty(name); return mock.dictionary[name].assertExists().finishProcessInStorage(pid); } /*----- Mock Proxy -----*/ function findMockProxy(MockRegistry storage mock, string memory name) internal returns(Proxy storage) { uint pid = mock.startProcess("findMockProxy"); - Check.isNotEmpty(name); + Valid.isNotEmpty(name); return mock.proxy[name].assertExists().finishProcessInStorage(pid); } diff --git a/devkit/method/core/ProxyLib.sol b/devkit/method/core/ProxyLib.sol index 6247cb3f..370d3b65 100644 --- a/devkit/method/core/ProxyLib.sol +++ b/devkit/method/core/ProxyLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Errors & Debug -import {check} from "devkit/error/validation/Validation.sol"; +import {valid} from "devkit/error/Valid.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Utils import {AddressUtils} from "devkit/utils/AddressUtils.sol"; diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol index 49f2e5c1..0e0a0267 100644 --- a/devkit/method/core/ProxyRegistryLib.sol +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; -import {check} from "devkit/error/validation/Validation.sol"; +import {valid} from "devkit/error/Valid.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; diff --git a/devkit/method/inspector/Inspector.sol b/devkit/method/inspector/Inspector.sol index 01521f3d..8e896c1b 100644 --- a/devkit/method/inspector/Inspector.sol +++ b/devkit/method/inspector/Inspector.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {check, Check} from "devkit/error/validation/Validation.sol"; +import {valid, Valid} from "devkit/error/Valid.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; import {AddressUtils} from "devkit/utils/AddressUtils.sol"; @@ -47,35 +47,35 @@ library Inspector { } function assertExists(Function storage func) internal returns(Function storage) { - check(func.exists(), "func does not exists"); + valid(func.exists(), "func does not exists"); return func; } function assertEmptyName(Function storage func) internal returns(Function storage) { - Check.isUnassigned(func.name); + Valid.isUnassigned(func.name); return func; } function assertEmptySelector(Function storage func) internal returns(Function storage) { - Check.isUnassigned(func.selector); + Valid.isUnassigned(func.selector); return func; } function assertEmptyImpl(Function storage func) internal returns(Function storage) { - check(func.implementation.isNotContract(), "Implementation Already Exist"); + valid(func.implementation.isNotContract(), "Implementation Already Exist"); return func; } function assertNotEmpty(Function storage func) internal returns(Function storage) { - check(func.exists(), "Empty Deployed Contract"); + valid(func.exists(), "Empty Deployed Contract"); return func; } function assertNotIncludedIn(Function storage func, Bundle storage bundleInfo) internal returns(Function storage) { - check(bundleInfo.hasNot(func), "Already exists in the Bundel"); + valid(bundleInfo.hasNot(func), "Already exists in the Bundel"); return func; } function assertImplIsContract(Function storage func) internal returns(Function storage) { - check(func.implementation.isContract(), "Implementation Not Contract"); + valid(func.implementation.isContract(), "Implementation Not Contract"); return func; } @@ -85,7 +85,7 @@ library Inspector { func.implementation.isContract(); } function assertComplete(Function storage func) internal returns(Function storage) { - check(func.isComplete(), "Function Info Not Complete"); + valid(func.isComplete(), "Function Info Not Complete"); return func; } @@ -112,7 +112,7 @@ library Inspector { bundle.facade.isContract(); } function assertComplete(Bundle storage bundle) internal returns(Bundle storage) { - check(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); + valid(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); return bundle; } @@ -132,11 +132,11 @@ library Inspector { return bundle.exists().isNot(); } function assertExists(Bundle storage bundle) internal returns(Bundle storage) { - check(bundle.exists(), "Bundle Info Not Exists"); + valid(bundle.exists(), "Bundle Info Not Exists"); return bundle; } function assertNotExists(Bundle storage bundle) internal returns(Bundle storage) { - check(bundle.notExists(), "Bundle Info Already Exists"); + valid(bundle.notExists(), "Bundle Info Already Exists"); return bundle; } @@ -151,7 +151,7 @@ library Inspector { return bundle.existsBundle(name).isNot(); } function assertBundleNotExists(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - check(bundle.notExistsBundle(name), "Bundle Already Exists"); + valid(bundle.notExistsBundle(name), "Bundle Already Exists"); return bundle; } @@ -170,7 +170,7 @@ library Inspector { return proxy.addr.isContract(); } function assertExists(Proxy storage proxy) internal returns(Proxy storage) { - check(proxy.exists(), "Proxy Not Exist"); + valid(proxy.exists(), "Proxy Not Exist"); return proxy; } @@ -182,7 +182,7 @@ library Inspector { return proxy.addr.isContract(); } function assertNotEmpty(Proxy memory proxy) internal returns(Proxy memory) { - check(proxy.isNotEmpty(), "Empty Proxy"); + valid(proxy.isNotEmpty(), "Empty Proxy"); return proxy; } @@ -205,7 +205,7 @@ library Inspector { return kind != ProxyKind.undefined; } function assertNotUndefined(ProxyKind kind) internal returns(ProxyKind) { - check(kind.isNotUndefined(), "Undefined Proxy Kind"); + valid(kind.isNotUndefined(), "Undefined Proxy Kind"); return kind; } @@ -227,7 +227,7 @@ library Inspector { return dictionary.addr.isContract(); } function assertExists(Dictionary storage dictionary) internal returns(Dictionary storage) { - check(dictionary.exists(), "Dictionary Not Exists"); + valid(dictionary.exists(), "Dictionary Not Exists"); return dictionary; } @@ -239,7 +239,7 @@ library Inspector { return dictionary.addr.isContract(); } function assertNotEmpty(Dictionary memory dictionary) internal returns(Dictionary memory) { - check(dictionary.isNotEmpty(), "Empty Dictionary"); + valid(dictionary.isNotEmpty(), "Empty Dictionary"); return dictionary; } @@ -247,7 +247,7 @@ library Inspector { return IDictionary(dictionary.addr).supportsInterface(selector); } function assertSupports(Dictionary storage dictionary, bytes4 selector) internal returns(Dictionary storage) { - check(dictionary.isSupported(selector), "Unsupported Selector"); + valid(dictionary.isSupported(selector), "Unsupported Selector"); return dictionary; } @@ -256,7 +256,7 @@ library Inspector { return success; } function assertVerifiable(Dictionary memory dictionary) internal returns(Dictionary memory) { - check(dictionary.isVerifiable(), "Dictionary Not Verifiable"); + valid(dictionary.isVerifiable(), "Dictionary Not Verifiable"); return dictionary; } @@ -277,7 +277,7 @@ library Inspector { return kind != DictionaryKind.undefined; } function assertNotUndefined(DictionaryKind kind) internal returns(DictionaryKind) { - check(kind.isNotUndefined(), "Undefined Dictionary Kind"); + valid(kind.isNotUndefined(), "Undefined Dictionary Kind"); return kind; } diff --git a/devkit/utils/AddressUtils.sol b/devkit/utils/AddressUtils.sol index ac855821..7b6f4bbb 100644 --- a/devkit/utils/AddressUtils.sol +++ b/devkit/utils/AddressUtils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {check} from "devkit/error/validation/Validation.sol"; +import {valid} from "devkit/error/Valid.sol"; // Utils import {vm} from "./ForgeHelper.sol"; import {BoolUtils} from "./BoolUtils.sol"; @@ -31,7 +31,7 @@ library AddressUtils { return addr == address(0); } function assertZero(address addr) internal returns(address) { - check(addr.isZero(), "Address Not Zero"); + valid(addr.isZero(), "Address Not Zero"); return addr; } @@ -40,7 +40,7 @@ library AddressUtils { return addr.isZero().isNot(); } function assertNotZero(address addr) internal returns(address) { - check(addr.isNotZero(), "Zero Address"); + valid(addr.isNotZero(), "Zero Address"); return addr; } @@ -59,7 +59,7 @@ library AddressUtils { return addr.hasCode(); } function assertIsContract(address addr) internal returns(address) { - check(addr.isContract(), "Address Not Contract"); + valid(addr.isContract(), "Address Not Contract"); return addr; } diff --git a/devkit/utils/Bytes4Utils.sol b/devkit/utils/Bytes4Utils.sol index 357b45d8..808279af 100644 --- a/devkit/utils/Bytes4Utils.sol +++ b/devkit/utils/Bytes4Utils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {check} from "devkit/error/validation/Validation.sol"; +import {valid} from "devkit/error/Valid.sol"; // Utils import {vm} from "./ForgeHelper.sol"; import {StringUtils} from "./StringUtils.sol"; @@ -36,7 +36,7 @@ library Bytes4Utils { return selector == bytes4(0); } function assertEmpty(bytes4 selector) internal returns(bytes4) { - check(selector.isEmpty(), "Selector Not Empty"); + valid(selector.isEmpty(), "Selector Not Empty"); return selector; } @@ -44,7 +44,7 @@ library Bytes4Utils { return selector.isEmpty().isFalse(); } function assertNotEmpty(bytes4 selector) internal returns(bytes4) { - check(selector.isNotEmpty(), "Empty Selector"); + valid(selector.isNotEmpty(), "Empty Selector"); return selector; } diff --git a/devkit/utils/StringUtils.sol b/devkit/utils/StringUtils.sol index c79be56d..5c6cc501 100644 --- a/devkit/utils/StringUtils.sol +++ b/devkit/utils/StringUtils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {check} from "devkit/error/validation/Validation.sol"; +import {valid} from "devkit/error/Valid.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Utils import {StdStyle, ForgeHelper, vm} from "./ForgeHelper.sol"; @@ -24,7 +24,7 @@ library StringUtils { return keccak256(abi.encode(name)); } function safeCalcHash(string memory name) internal returns(bytes32) { - check(name.isNotEmpty(), "Calc Hash"); + valid(name.isNotEmpty(), "Calc Hash"); return name.calcHash(); } @@ -105,7 +105,7 @@ library StringUtils { return bytes(str).length == 0; } function assertEmpty(string memory str) internal returns(string memory) { - check(str.isEmpty(), "String Not Empty"); + valid(str.isEmpty(), "String Not Empty"); return str; } @@ -114,7 +114,7 @@ library StringUtils { return str.isEmpty().isNot(); } function assertNotEmpty(string memory str) internal returns(string memory) { - check(str.isNotEmpty(), "Empty String"); + valid(str.isNotEmpty(), "Empty String"); return str; } From ca123b336ea5c688d201d2c81945728e8bd1f55d Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 17:48:13 +0900 Subject: [PATCH 050/111] Update chore bundle file --- devkit/core/Bundle.sol | 22 ++++++++++++++++------ devkit/method/core/BundleLib.sol | 25 ------------------------- 2 files changed, 16 insertions(+), 31 deletions(-) delete mode 100644 devkit/method/core/BundleLib.sol diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 460ad8a0..ab8e24ff 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -9,6 +9,7 @@ import {Parser} from "devkit/method/debug/Parser.sol"; using Parser for Bundle global; import {Inspector} from "devkit/method/inspector/Inspector.sol"; using Inspector for Bundle global; +import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; // Core Type import {Function} from "devkit/core/Function.sol"; @@ -24,15 +25,18 @@ struct Bundle { string name; Function[] functions; address facade; + BuildStatus buildStatus; } - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~ - đŸ—‚ī¸ Core Methods - đŸ“Ĩ Assign Bundle -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library BundleLib { + /**~~~~~~~~~~~~~~~~~~~~~~ + đŸ“Ĩ Assign Name + 🧩 Push Function + 🧩 Push Functions + đŸĒŸ Assign Facade + ~~~~~~~~~~~~~~~~~~~~~~~~*/ + /**--------------------------- - đŸ“Ĩ Assign Bundle + đŸ“Ĩ Assign Name -----------------------------*/ function assignName(Bundle storage bundle, string memory name) internal returns(Bundle storage) { uint pid = bundle.startProcess("assignName"); @@ -41,6 +45,9 @@ library BundleLib { return bundle.finishProcess(pid); } + /**--------------------------- + đŸ“Ĩ Push Function + -----------------------------*/ function pushFunction(Bundle storage bundle, Function storage func) internal returns(Bundle storage) { uint pid = bundle.startProcess("pushFunction"); valid(bundle.hasNot(func), "Already added"); @@ -57,6 +64,9 @@ library BundleLib { return bundle.finishProcess(pid); } + /**--------------------------- + đŸ“Ĩ Assign Facade + -----------------------------*/ function assignFacade(Bundle storage bundle, address facade) internal returns(Bundle storage) { uint pid = bundle.startProcess("assignFacade"); Valid.isContract(facade); diff --git a/devkit/method/core/BundleLib.sol b/devkit/method/core/BundleLib.sol deleted file mode 100644 index d2b9fc5a..00000000 --- a/devkit/method/core/BundleLib.sol +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Validation -import {valid} from "devkit/error/Valid.sol"; -import {Valid} from "devkit/error/Valid.sol"; -// Utils -import {console2} from "devkit/utils/ForgeHelper.sol"; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; -// Debug -import {Debug} from "devkit/debug/Debug.sol"; -import {Logger} from "devkit/debug/Logger.sol"; -// Core -import {Function} from "devkit/core/Function.sol"; - -import {Bundle} from "devkit/core/Bundle.sol"; - - From 37780f9ba70665a847f6bae0dbdc261d321b5c2e Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 18:17:17 +0900 Subject: [PATCH 051/111] Merge FunctionLib --- devkit/core/Bundle.sol | 27 +++--- devkit/core/Function.sol | 147 ++++++++++++++++++++++++++--- devkit/method/core/FunctionLib.sol | 141 --------------------------- 3 files changed, 149 insertions(+), 166 deletions(-) delete mode 100644 devkit/method/core/FunctionLib.sol diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index ab8e24ff..b81c4119 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -28,16 +28,15 @@ struct Bundle { BuildStatus buildStatus; } library BundleLib { - /**~~~~~~~~~~~~~~~~~~~~~~ - đŸ“Ĩ Assign Name - 🧩 Push Function - 🧩 Push Functions + /**~~~~~~~~~~~~~~~~~~~~~~~ + 📛 Assign Name + 🧩 Push Function(s) đŸĒŸ Assign Facade - ~~~~~~~~~~~~~~~~~~~~~~~~*/ + ~~~~~~~~~~~~~~~~~~~~~~~~~*/ - /**--------------------------- - đŸ“Ĩ Assign Name - -----------------------------*/ + /**-------------------- + 📛 Assign Name + ----------------------*/ function assignName(Bundle storage bundle, string memory name) internal returns(Bundle storage) { uint pid = bundle.startProcess("assignName"); Valid.notEmptyString(name); @@ -45,9 +44,9 @@ library BundleLib { return bundle.finishProcess(pid); } - /**--------------------------- - đŸ“Ĩ Push Function - -----------------------------*/ + /**------------------------- + 🧩 Push Function(s) + ---------------------------*/ function pushFunction(Bundle storage bundle, Function storage func) internal returns(Bundle storage) { uint pid = bundle.startProcess("pushFunction"); valid(bundle.hasNot(func), "Already added"); @@ -64,9 +63,9 @@ library BundleLib { return bundle.finishProcess(pid); } - /**--------------------------- - đŸ“Ĩ Assign Facade - -----------------------------*/ + /**---------------------- + đŸĒŸ Assign Facade + ------------------------*/ function assignFacade(Bundle storage bundle, address facade) internal returns(Bundle storage) { uint pid = bundle.startProcess("assignFacade"); Valid.isContract(facade); diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index 2954fc84..181d9f0e 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -1,29 +1,154 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; - -// Core Method -import {FunctionLib} from "devkit/method/core/FunctionLib.sol"; -// Support Methods +/**-------------------------- + Apply Support Methods +----------------------------*/ import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; + using ProcessLib for Function global; import {Parser} from "devkit/method/debug/Parser.sol"; + using Parser for Function global; import {Dumper} from "devkit/method/debug/Dumper.sol"; + using Dumper for Function global; import {Inspector} from "devkit/method/inspector/Inspector.sol"; + using Inspector for Function global; import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; + using TypeSafetyUtils for Function global; + +// Validation +import {Valid} from "devkit/error/Valid.sol"; +import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; /**================== 🧩 Function ====================*/ +using FunctionLib for Function global; struct Function { /// @dev Function may be different depending on the op version. string name; bytes4 selector; address implementation; BuildStatus buildStatus; } -using FunctionLib for Function global; -// Support Methods -using ProcessLib for Function global; -using Parser for Function global; -using Dumper for Function global; -using Inspector for Function global; -using TypeSafetyUtils for Function global; +library FunctionLib { + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 📛 Assign Name + 🧩 Assign Selector + đŸĒŸ Assign Implementation + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + + /**-------------------- + 📛 Assign Name + ----------------------*/ + function assign(Function storage func, string memory name, bytes4 selector, address implementation) internal returns(Function storage) { + uint pid = func.startProcess("safeAssign"); + Valid.isUnassigned(func.name); + Valid.isNotEmpty(name); + Valid.isNotEmpty(selector); + Valid.isContract(implementation); + func.name = name; + func.selector = selector; + func.implementation = implementation; + return func.finishProcess(pid); + } + + function asBuilding(Function storage func) internal returns(Function storage) { + func.buildStatus = BuildStatus.Building; + return func; + } + function build(Function storage func) internal returns(Function storage) { + Valid.assigned(func.selector); + Valid.contractAssigned(func.implementation); + func.buildStatus = BuildStatus.Built; + return func; + } + + function assign(Function storage func, bytes4 selector, address implementation) internal returns(Function storage) { + func.assignSelector(selector); + func.assignImplementation(implementation); + return func; + } + + function assignSelector(Function storage func, bytes4 selector) internal returns(Function storage) { + func.selector = selector; + func.asBuilding(); + return func; + } + function assignImplementation(Function storage func, address implementation) internal returns(Function storage) { + func.implementation = implementation; + func.asBuilding(); + return func; + } + + + /**----- Name --------*/ + function assign(Function storage func, string memory name) internal returns(Function storage) { + func.name = name; + + return func; + } + function safeAssign(Function storage func, string memory name) internal returns(Function storage) { + uint pid = func.startProcess("safeAssign"); + Valid.isNotEmpty(name); + return func .assertEmptyName() + .assign(name) + .finishProcess(pid); + } + + /**----- Selector --------*/ + function safeAssign(Function storage func, bytes4 selector) internal returns(Function storage) { + uint pid = func.startProcess("safeAssign"); + Valid.isNotEmpty(selector); + return func .assertEmptySelector() + .assign(selector) + .finishProcess(pid); + } + function assign(Function storage func, bytes4 selector) internal returns(Function storage) { + func.selector = selector; + return func; + } + + /**----- Implementation --------*/ + function safeAssign(Function storage func, address implementation) internal returns(Function storage) { + uint pid = func.startProcess("safeAssign"); + Valid.isContract(implementation); + return func .assertEmptyImpl() + .assign(implementation) + .finishProcess(pid); + } + function assign(Function storage func, address implementation) internal returns(Function storage) { + func.implementation = implementation; + return func; + } + function fetch(Function storage func, string memory envKey) internal returns(Function storage) { + uint pid = func.startProcess("fetch"); + Valid.isUnassigned(func.name); + Valid.isNotEmpty(envKey); + return func; + } + function fetchAndAssign(Function storage func, string memory envKey, bytes4 selector) internal returns(Function storage) { + uint pid = func.startProcess("fetchAndAssign"); + func.assign(envKey, selector, loadAddressFrom(envKey)); + return func.finishProcess(pid); + } + + function loadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { + uint pid = func.startProcess("loadAndAssignFromEnv"); + return func .assign(name) + .assign(selector) + .assign(loadAddressFrom(envKey)) + .finishProcess(pid); + } + function loadAndAssignFromEnv(Function storage func) internal returns(Function storage) { + Valid.isNotEmpty(func.name); + Valid.isNotEmpty(func.selector); + return func.loadAndAssignFromEnv(func.name, func.name, func.selector); + } + function safeLoadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { + uint pid = func.startProcess("safeLoadAndAssignFromEnv"); + Valid.isNotEmpty(envKey); + Valid.isNotEmpty(name); + Valid.isNotEmpty(selector); + return func.loadAndAssignFromEnv(envKey, name, selector).finishProcess(pid); + } + +} diff --git a/devkit/method/core/FunctionLib.sol b/devkit/method/core/FunctionLib.sol deleted file mode 100644 index 7ad291d6..00000000 --- a/devkit/method/core/FunctionLib.sol +++ /dev/null @@ -1,141 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Validation -import {valid, Valid} from "devkit/error/Valid.sol"; -// Utils -import {ForgeHelper, loadAddressFrom} from "../../utils/ForgeHelper.sol"; -import {StringUtils} from "../../utils/StringUtils.sol"; - using StringUtils for string; -import {Bytes4Utils} from "../../utils/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; -import {AddressUtils} from "../../utils/AddressUtils.sol"; - using AddressUtils for address; -// Core -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; - -import {BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; - - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🧩 Function - đŸ“Ĩ Assign Function -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library FunctionLib { - /**------------------------ - đŸ“Ĩ Assign Function - --------------------------*/ - function assign(Function storage func, string memory name, bytes4 selector, address implementation) internal returns(Function storage) { - uint pid = func.startProcess("safeAssign"); - Valid.isUnassigned(func.name); - Valid.isNotEmpty(name); - Valid.isNotEmpty(selector); - Valid.isContract(implementation); - func.name = name; - func.selector = selector; - func.implementation = implementation; - return func.finishProcess(pid); - } - - function asBuilding(Function storage func) internal returns(Function storage) { - func.buildStatus = BuildStatus.Building; - return func; - } - function build(Function storage func) internal returns(Function storage) { - Valid.assigned(func.selector); - Valid.contractAssigned(func.implementation); - func.buildStatus = BuildStatus.Built; - return func; - } - - function assign(Function storage func, bytes4 selector, address implementation) internal returns(Function storage) { - func.assignSelector(selector); - func.assignImplementation(implementation); - return func; - } - - function assignSelector(Function storage func, bytes4 selector) internal returns(Function storage) { - func.selector = selector; - func.asBuilding(); - return func; - } - function assignImplementation(Function storage func, address implementation) internal returns(Function storage) { - func.implementation = implementation; - func.asBuilding(); - return func; - } - - - /**----- Name --------*/ - function assign(Function storage func, string memory name) internal returns(Function storage) { - func.name = name; - - return func; - } - function safeAssign(Function storage func, string memory name) internal returns(Function storage) { - uint pid = func.startProcess("safeAssign"); - Valid.isNotEmpty(name); - return func .assertEmptyName() - .assign(name) - .finishProcess(pid); - } - - /**----- Selector --------*/ - function safeAssign(Function storage func, bytes4 selector) internal returns(Function storage) { - uint pid = func.startProcess("safeAssign"); - Valid.isNotEmpty(selector); - return func .assertEmptySelector() - .assign(selector) - .finishProcess(pid); - } - function assign(Function storage func, bytes4 selector) internal returns(Function storage) { - func.selector = selector; - return func; - } - - /**----- Implementation --------*/ - function safeAssign(Function storage func, address implementation) internal returns(Function storage) { - uint pid = func.startProcess("safeAssign"); - Valid.isContract(implementation); - return func .assertEmptyImpl() - .assign(implementation) - .finishProcess(pid); - } - function assign(Function storage func, address implementation) internal returns(Function storage) { - func.implementation = implementation; - return func; - } - function fetch(Function storage func, string memory envKey) internal returns(Function storage) { - uint pid = func.startProcess("fetch"); - Valid.isUnassigned(func.name); - Valid.isNotEmpty(envKey); - return func; - } - function fetchAndAssign(Function storage func, string memory envKey, bytes4 selector) internal returns(Function storage) { - uint pid = func.startProcess("fetchAndAssign"); - func.assign(envKey, selector, loadAddressFrom(envKey)); - return func.finishProcess(pid); - } - - function loadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { - uint pid = func.startProcess("loadAndAssignFromEnv"); - return func .assign(name) - .assign(selector) - .assign(envKey.loadAddress()) - .finishProcess(pid); - } - function loadAndAssignFromEnv(Function storage func) internal returns(Function storage) { - Valid.isNotEmpty(func.name); - Valid.isNotEmpty(func.selector); - return func.loadAndAssignFromEnv(func.name, func.name, func.selector); - } - function safeLoadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { - uint pid = func.startProcess("safeLoadAndAssignFromEnv"); - Valid.isNotEmpty(envKey); - Valid.isNotEmpty(name); - Valid.isNotEmpty(selector); - return func.loadAndAssignFromEnv(envKey, name, selector).finishProcess(pid); - } - -} From 8a2c0f4d083600e5f490ecff14434285d779c78f Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 19:12:55 +0900 Subject: [PATCH 052/111] Update FunctionLib to improve type safety --- devkit/core/Function.sol | 162 +++++++++------------ devkit/error/Error.sol | 2 + devkit/error/Valid.sol | 5 + devkit/method/MCBundleLib.sol | 2 +- devkit/method/core/FunctionRegistryLib.sol | 39 ++--- devkit/method/core/StdFunctionsLib.sol | 32 ++-- devkit/utils/type/TypeSafetyUtils.sol | 2 +- test/devkit/global/MCBundle.t.sol | 2 +- 8 files changed, 111 insertions(+), 135 deletions(-) diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index 181d9f0e..f07305a7 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -16,6 +16,7 @@ import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.so // Validation import {Valid} from "devkit/error/Valid.sol"; +// Loader import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; @@ -31,124 +32,103 @@ struct Function { /// @dev Function may be different depending on the op version } library FunctionLib { /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 🌈 Assign 📛 Assign Name - 🧩 Assign Selector - đŸĒŸ Assign Implementation + đŸŽ¯ Assign Selector + 🔌 Assign Implementation + đŸ‘ˇâ€â™‚ī¸ Build ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - /**-------------------- - 📛 Assign Name - ----------------------*/ + /**--------------- + 🌈 Assign + -----------------*/ function assign(Function storage func, string memory name, bytes4 selector, address implementation) internal returns(Function storage) { - uint pid = func.startProcess("safeAssign"); - Valid.isUnassigned(func.name); - Valid.isNotEmpty(name); - Valid.isNotEmpty(selector); - Valid.isContract(implementation); - func.name = name; - func.selector = selector; - func.implementation = implementation; - return func.finishProcess(pid); - } - - function asBuilding(Function storage func) internal returns(Function storage) { - func.buildStatus = BuildStatus.Building; - return func; - } - function build(Function storage func) internal returns(Function storage) { - Valid.assigned(func.selector); - Valid.contractAssigned(func.implementation); - func.buildStatus = BuildStatus.Built; + func.assignName(name); + func.assignSelector(selector); + func.assignImplementation(implementation); return func; } - function assign(Function storage func, bytes4 selector, address implementation) internal returns(Function storage) { - func.assignSelector(selector); - func.assignImplementation(implementation); + /**-------------------- + 📛 Assign Name + ----------------------*/ + function assignName(Function storage func, string memory name) internal returns(Function storage) { + Valid.notLocked(func.buildStatus); + func.name = name; + func.asBuilding(); return func; } + /**------------------------ + đŸŽ¯ Assign Selector + --------------------------*/ function assignSelector(Function storage func, bytes4 selector) internal returns(Function storage) { + Valid.notLocked(func.buildStatus); func.selector = selector; func.asBuilding(); return func; } + + /**------------------------------ + 🔌 Assign Implementation + --------------------------------*/ function assignImplementation(Function storage func, address implementation) internal returns(Function storage) { + Valid.notLocked(func.buildStatus); func.implementation = implementation; func.asBuilding(); return func; } - - /**----- Name --------*/ - function assign(Function storage func, string memory name) internal returns(Function storage) { - func.name = name; - - return func; - } - function safeAssign(Function storage func, string memory name) internal returns(Function storage) { - uint pid = func.startProcess("safeAssign"); - Valid.isNotEmpty(name); - return func .assertEmptyName() - .assign(name) - .finishProcess(pid); - } - - /**----- Selector --------*/ - function safeAssign(Function storage func, bytes4 selector) internal returns(Function storage) { - uint pid = func.startProcess("safeAssign"); - Valid.isNotEmpty(selector); - return func .assertEmptySelector() - .assign(selector) - .finishProcess(pid); - } - function assign(Function storage func, bytes4 selector) internal returns(Function storage) { - func.selector = selector; + /**-------------- + đŸ‘ˇâ€â™‚ī¸ Build + ----------------*/ + function asBuilding(Function storage func) internal returns(Function storage) { + func.buildStatus = BuildStatus.Building; return func; } - - /**----- Implementation --------*/ - function safeAssign(Function storage func, address implementation) internal returns(Function storage) { - uint pid = func.startProcess("safeAssign"); - Valid.isContract(implementation); - return func .assertEmptyImpl() - .assign(implementation) - .finishProcess(pid); - } - function assign(Function storage func, address implementation) internal returns(Function storage) { - func.implementation = implementation; + function build(Function storage func) internal returns(Function storage) { + // TODO + Valid.assigned(func.selector); + Valid.contractAssigned(func.implementation); + func.buildStatus = BuildStatus.Built; return func; } - function fetch(Function storage func, string memory envKey) internal returns(Function storage) { - uint pid = func.startProcess("fetch"); - Valid.isUnassigned(func.name); - Valid.isNotEmpty(envKey); + function lock(Function storage func) internal returns(Function storage) { + func.buildStatus = BuildStatus.Locked; return func; } - function fetchAndAssign(Function storage func, string memory envKey, bytes4 selector) internal returns(Function storage) { - uint pid = func.startProcess("fetchAndAssign"); - func.assign(envKey, selector, loadAddressFrom(envKey)); - return func.finishProcess(pid); - } - function loadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { - uint pid = func.startProcess("loadAndAssignFromEnv"); - return func .assign(name) - .assign(selector) - .assign(loadAddressFrom(envKey)) - .finishProcess(pid); - } - function loadAndAssignFromEnv(Function storage func) internal returns(Function storage) { - Valid.isNotEmpty(func.name); - Valid.isNotEmpty(func.selector); - return func.loadAndAssignFromEnv(func.name, func.name, func.selector); - } - function safeLoadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { - uint pid = func.startProcess("safeLoadAndAssignFromEnv"); - Valid.isNotEmpty(envKey); - Valid.isNotEmpty(name); - Valid.isNotEmpty(selector); - return func.loadAndAssignFromEnv(envKey, name, selector).finishProcess(pid); - } + + // function fetch(Function storage func, string memory envKey) internal returns(Function storage) { + // uint pid = func.startProcess("fetch"); + // Valid.isUnassigned(func.name); + // Valid.isNotEmpty(envKey); + // return func; + // } + // function fetchAndAssign(Function storage func, string memory envKey, bytes4 selector) internal returns(Function storage) { + // uint pid = func.startProcess("fetchAndAssign"); + // func.assign(envKey, selector, loadAddressFrom(envKey)); + // return func.finishProcess(pid); + // } + + // function loadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { + // uint pid = func.startProcess("loadAndAssignFromEnv"); + // return func .assign(name) + // .assign(selector) + // .assign(loadAddressFrom(envKey)) + // .finishProcess(pid); + // } + // function loadAndAssignFromEnv(Function storage func) internal returns(Function storage) { + // Valid.isNotEmpty(func.name); + // Valid.isNotEmpty(func.selector); + // return func.loadAndAssignFromEnv(func.name, func.name, func.selector); + // } + // function safeLoadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { + // uint pid = func.startProcess("safeLoadAndAssignFromEnv"); + // Valid.isNotEmpty(envKey); + // Valid.isNotEmpty(name); + // Valid.isNotEmpty(selector); + // return func.loadAndAssignFromEnv(envKey, name, selector).finishProcess(pid); + // } } diff --git a/devkit/error/Error.sol b/devkit/error/Error.sol index 9e4c44fa..9f943044 100644 --- a/devkit/error/Error.sol +++ b/devkit/error/Error.sol @@ -26,6 +26,8 @@ library ERR { string constant RQ_SELECTOR = "Selector is required."; string constant RQ_CONTRACT = "Contract is required."; string constant RQ_NOT_EMPTY_STRING = "String is empty."; + string constant LOCKED_OBJECT = "Locaked Object"; + // string constant STR_EXISTS = "String Already Exist"; string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; diff --git a/devkit/error/Valid.sol b/devkit/error/Valid.sol index 174ea86e..2267813c 100644 --- a/devkit/error/Valid.sol +++ b/devkit/error/Valid.sol @@ -11,6 +11,7 @@ import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; using Bytes4Utils for bytes4; import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; +import {BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; /// @dev like `require` function valid(bool condition, string memory errorBody) { @@ -49,4 +50,8 @@ library Valid { function contractAssigned(address addr) internal { valid(addr.isContract(), ERR.RQ_CONTRACT); } + + function notLocked(BuildStatus status) internal { + valid(status != BuildStatus.Locked, ERR.LOCKED_OBJECT); + } } diff --git a/devkit/method/MCBundleLib.sol b/devkit/method/MCBundleLib.sol index 1a131f06..5e47a8aa 100644 --- a/devkit/method/MCBundleLib.sol +++ b/devkit/method/MCBundleLib.sol @@ -78,7 +78,7 @@ library MCBundleLib { -----------------------------*/ function addFunction(MCDevKit storage mc, string memory name, bytes4 selector, address implementation) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("addFunction"); - mc.functions.safeAddFunction(name, selector, implementation); + mc.functions.insert(name, selector, implementation); return mc.recordExecFinish(pid); } /**------------------------------------- diff --git a/devkit/method/core/FunctionRegistryLib.sol b/devkit/method/core/FunctionRegistryLib.sol index 658af8f6..26e5e145 100644 --- a/devkit/method/core/FunctionRegistryLib.sol +++ b/devkit/method/core/FunctionRegistryLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Error & Debug -import {valid} from "devkit/error/Valid.sol"; +import {Valid, valid} from "devkit/error/Valid.sol"; import {ERR, throwError} from "devkit/error/Error.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config @@ -22,40 +22,23 @@ import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 📗 Functions Registry - ✨ Add Custom Function - 🔏 Load and Assign Custom Function from Env + đŸ—ŗī¸ Insert Custom Function đŸ”ŧ Update Current Context Function â™ģī¸ Reset Current Context Function & Bundle 🔍 Find Function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ library FunctionRegistryLib { - /**--------------------------- - ✨ Add Custom Function - -----------------------------*/ - function safeAddFunction(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { - uint pid = functions.startProcess("safeAddFunction"); - valid(name.isNotEmpty(), "Empty Name"); - functions.customs[name] - .safeAssign(name) - .safeAssign(selector) - .safeAssign(implementation); - functions.safeUpdateCurrentFunction(name); + /**------------------------------ + đŸ—ŗī¸ Insert Custom Function + --------------------------------*/ + function insert(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + uint pid = functions.startProcess("insert"); + Valid.isNotEmpty(name); + functions.customs[name].assign(name, selector, implementation).lock(); + functions.safeUpdateCurrentFunction(name); // TODO return functions.finishProcess(pid); } - - /**--------------------------------------------- - 🔏 Load and Add Custom Function from Env - -----------------------------------------------*/ - function safeLoadAndAdd(FunctionRegistry storage functions, string memory envKey, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { - uint pid = functions.startProcess("safeLoadAndAdd"); - functions.customs[name] - .loadAndAssignFromEnv(envKey, name, selector); - functions.safeUpdateCurrentFunction(name); - return functions.finishProcess(pid); - } - - /**------------------------------------------------ đŸ”ŧ Update Current Context Function --------------------------------------------------*/ @@ -65,7 +48,6 @@ library FunctionRegistryLib { return functions.finishProcess(pid); } - /**----------------------------------------------- â™ģī¸ Reset Current Context Function & Bundle -------------------------------------------------*/ @@ -75,7 +57,6 @@ library FunctionRegistryLib { return functions.finishProcess(pid); } - /**------------------------------- 🔍 Find Function ---------------------------------*/ diff --git a/devkit/method/core/StdFunctionsLib.sol b/devkit/method/core/StdFunctionsLib.sol index 37153172..0fa23104 100644 --- a/devkit/method/core/StdFunctionsLib.sol +++ b/devkit/method/core/StdFunctionsLib.sol @@ -22,6 +22,8 @@ import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.so import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; import {StdFunctions} from "devkit/core/StdFunctions.sol"; +// Loader +import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -46,27 +48,33 @@ library StdFunctionsLib { /**===== Each Std Function =====*/ function assignAndLoad_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { uint pid = std.startProcess("assignAndLoad_InitSetAdmin"); - std.initSetAdmin.safeAssign("InitSetAdmin") - .safeAssign(InitSetAdmin.initSetAdmin.selector) - .loadAndAssignFromEnv() + string memory name = "InitSetAdmin"; + bytes4 selector = InitSetAdmin.initSetAdmin.selector; + address implementation = loadAddressFrom(name); // TODO + std.initSetAdmin.assign(name, selector, implementation) + // .lock() .dump(); return std.finishProcess(pid); } function assignAndLoad_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { uint pid = std.startProcess("assignAndLoad_GetDeps"); - std.getDeps .safeAssign("GetDeps") - .safeAssign(GetDeps.getDeps.selector) - .loadAndAssignFromEnv() + string memory name = "GetDeps"; + bytes4 selector = GetDeps.getDeps.selector; + address implementation = loadAddressFrom(name); + std.getDeps .assign(name, selector, implementation) + // .lock() .dump(); return std.finishProcess(pid); } function assignAndLoad_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { uint pid = std.startProcess("assignAndLoad_Clone"); - std.clone .safeAssign("Clone") - .safeAssign(Clone.clone.selector) - .loadAndAssignFromEnv() + string memory name = "Clone"; + bytes4 selector = Clone.clone.selector; + address implementation = loadAddressFrom(name); + std.clone .assign(name, selector, implementation) + // .lock() .dump(); return std.finishProcess(pid); } @@ -84,21 +92,21 @@ library StdFunctionsLib { /**===== Each Std Function =====*/ function deployIfNotExists_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { if (std.initSetAdmin.implementation.isNotContract()) { - std.initSetAdmin.safeAssign(address(new InitSetAdmin())); + std.initSetAdmin.assignImplementation(address(new InitSetAdmin())); } return std; } function deployIfNotExists_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { if (!std.getDeps.implementation.isContract()) { - std.getDeps.safeAssign(address(new GetDeps())); + std.getDeps.assignImplementation(address(new GetDeps())); } return std; } function deployIfNotExists_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { if (!std.clone.implementation.isContract()) { - std.clone.safeAssign(address(new Clone())); + std.clone.assignImplementation(address(new Clone())); } return std; } diff --git a/devkit/utils/type/TypeSafetyUtils.sol b/devkit/utils/type/TypeSafetyUtils.sol index 444bce54..b18511e5 100644 --- a/devkit/utils/type/TypeSafetyUtils.sol +++ b/devkit/utils/type/TypeSafetyUtils.sol @@ -8,7 +8,7 @@ pragma solidity ^0.8.24; // import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; // using Bytes4Utils for bytes4; -enum BuildStatus { Building, Built } +enum BuildStatus { Building, Built, Locked } library TypeSafetyUtils { diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 9b7b2911..5b0ba4ec 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -87,7 +87,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { mc.use(functionName, selector, impl); - vm.expectRevert(ERR.message(ERR.STR_ALREADY_ASSIGNED).toBytes()); + vm.expectRevert(ERR.message(ERR.LOCKED_OBJECT).toBytes()); mc.use(functionName, selector, impl); } From 354757a3ad6faf554f44c258f7d485978efb7586 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 21:49:26 +0900 Subject: [PATCH 053/111] Update ProxyLib --- devkit/core/Proxy.sol | 71 ++++++++++++++++++------ devkit/error/Error.sol | 2 + devkit/error/Valid.sol | 5 ++ devkit/method/MCDeployLib.sol | 3 +- devkit/method/MCTestLib.sol | 3 +- devkit/method/core/ProxyLib.sol | 96 --------------------------------- devkit/method/test/TestLib.sol | 30 +++++++++++ 7 files changed, 93 insertions(+), 117 deletions(-) delete mode 100644 devkit/method/core/ProxyLib.sol create mode 100644 devkit/method/test/TestLib.sol diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index 084c741d..5f2c4838 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -1,33 +1,70 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; - -// Core Method -import {ProxyLib} from "devkit/method/core/ProxyLib.sol"; -// Support Methods +/**-------------------------- + Apply Support Methods +----------------------------*/ import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; + using ProcessLib for Proxy global; import {Inspector} from "devkit/method/inspector/Inspector.sol"; + using Inspector for Proxy global; + using Inspector for ProxyKind global; + +// Validation +import {Valid} from "devkit/error/Valid.sol"; +// Core Type +import {Dictionary} from "devkit/core/Dictionary.sol"; +import {Function} from "devkit/core/Function.sol"; +// Test +import {SimpleMockProxy} from "devkit/test/SimpleMockProxy.sol"; +// External Lib +import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; /**=============== 🏠 Proxy =================*/ +using ProxyLib for Proxy global; struct Proxy { address addr; ProxyKind kind; } -using ProxyLib for Proxy global; -// Support Methods -using ProcessLib for Proxy global; -using Inspector for Proxy global; +library ProxyLib { + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 🚀 Deploy Proxy + 🤖 Create Mock Proxy + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + /**--------------------- + 🚀 Deploy Proxy + -----------------------*/ + function deploy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory proxy) { + uint pid = ProcessLib.startProxyLibProcess("deploy"); + Valid.isNotEmpty(dictionary); + return Proxy({ + addr: address(new ERC7546ProxyEtherscan(dictionary.addr, initData)), + kind: ProxyKind.Verifiable + }).finishProcess(pid); + } - /**--------------- - Proxy Kind - -----------------*/ - enum ProxyKind { - undefined, - Normal, - Verifiable, - Mock + /**-------------------------- + 🤖 Create Mock Proxy + ----------------------------*/ + function createSimpleMockProxy(Function[] memory functions) internal returns(Proxy memory) { + uint pid = ProcessLib.startProxyLibProcess("createSimpleMockProxy"); + return Proxy({ + addr: address(new SimpleMockProxy(functions)), + kind: ProxyKind.Mock + }).finishProcess(pid); } - using Inspector for ProxyKind global; +} + + +/**--------------- + Proxy Kind +-----------------*/ +enum ProxyKind { + undefined, + Normal, + Verifiable, + Mock +} diff --git a/devkit/error/Error.sol b/devkit/error/Error.sol index 9f943044..29e00649 100644 --- a/devkit/error/Error.sol +++ b/devkit/error/Error.sol @@ -26,6 +26,8 @@ library ERR { string constant RQ_SELECTOR = "Selector is required."; string constant RQ_CONTRACT = "Contract is required."; string constant RQ_NOT_EMPTY_STRING = "String is empty."; + string constant DICTIONARY_NOT_EXISTS = "Dictionary Not Exists"; + string constant EMPTY_DICTIONARY = "Empty Dictionary"; string constant LOCKED_OBJECT = "Locaked Object"; // string constant STR_EXISTS = "String Already Exist"; diff --git a/devkit/error/Valid.sol b/devkit/error/Valid.sol index 2267813c..7fa1e03e 100644 --- a/devkit/error/Valid.sol +++ b/devkit/error/Valid.sol @@ -12,6 +12,7 @@ import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; import {BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; /// @dev like `require` function valid(bool condition, string memory errorBody) { @@ -54,4 +55,8 @@ library Valid { function notLocked(BuildStatus status) internal { valid(status != BuildStatus.Locked, ERR.LOCKED_OBJECT); } + + function isNotEmpty(Dictionary memory dictionary) internal { + valid(dictionary.isNotEmpty(), ERR.EMPTY_DICTIONARY); + } } diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index 6b7c72d7..e33d54ac 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -15,8 +15,7 @@ import {Bundle} from "devkit/core/Bundle.sol"; import {StdFunctionsArgs} from "devkit/method/core/StdFunctionsLib.sol"; using StdFunctionsArgs for address; // proxy -import {Proxy} from "devkit/core/Proxy.sol"; -import {ProxyLib} from "devkit/method/core/ProxyLib.sol"; +import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Dictionary); diff --git a/devkit/method/MCTestLib.sol b/devkit/method/MCTestLib.sol index 9024ac43..51d2f109 100644 --- a/devkit/method/MCTestLib.sol +++ b/devkit/method/MCTestLib.sol @@ -10,8 +10,7 @@ import {Params} from "devkit/debug/Params.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; // proxy -import {Proxy} from "devkit/core/Proxy.sol"; -import {ProxyLib} from "devkit/method/core/ProxyLib.sol"; +import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; // dictionary import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; diff --git a/devkit/method/core/ProxyLib.sol b/devkit/method/core/ProxyLib.sol deleted file mode 100644 index 370d3b65..00000000 --- a/devkit/method/core/ProxyLib.sol +++ /dev/null @@ -1,96 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Errors & Debug -import {valid} from "devkit/error/Valid.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Utils -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -// Core -// import {MCStdFuncs} from "devkit/core/functions/MCStdFuncs.sol"; -import {Dictionary} from "devkit/core/Dictionary.sol"; -import {Function} from "devkit/core/Function.sol"; -// Test -import {SimpleMockProxy} from "devkit/test/SimpleMockProxy.sol"; -// External Lib -import {ERC7546Utils} from "@ucs.mc/proxy/ERC7546Utils.sol"; -import {ERC7546Proxy} from "@ucs.mc/proxy/ERC7546Proxy.sol"; -import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; - - -import {Proxy, ProxyKind} from "devkit/core/Proxy.sol"; -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; - - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🏠 Proxy - 🚀 Deploy Proxy - << Helper >> - đŸ§Ē Test Utils - 🤖 Create Mock Proxy -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library ProxyLib { - /**--------------------- - 🚀 Deploy Proxy - -----------------------*/ - function deploy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory proxy) { - uint pid = ProcessLib.startProxyLibProcess("deploy"); - // Note Temporarily disable (see details in https://github.com/metacontract/mc/issues/16) - // proxy = dictionary.isVerifiable() ? - // deployProxyVerifiable(dictionary, initData) : - // deployProxy(dictionary, initData); - proxy = deployProxyVerifiable(dictionary, initData); - return proxy.finishProcess(pid); - } - /**--------------------------- - Deploy Proxy Primitives - -----------------------------*/ - function deployProxyVerifiable(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory) { - return Proxy({ - addr: address(new ERC7546ProxyEtherscan(dictionary.addr, initData)), - kind: ProxyKind.Verifiable - }); - } - - function deployProxy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory) { - return Proxy({ - addr: address(new ERC7546Proxy(dictionary.addr, initData)), - kind: ProxyKind.Normal - }); - } - - function safeDeploy(Dictionary storage dictionary, bytes memory initData) internal returns(Proxy memory) { - uint pid = ProcessLib.startProxyLibProcess("safeDeploy"); - return deploy(dictionary.assertExists(), initData).finishProcess(pid); - } - - - /**------------------------- - 🤖 Create Mock Proxy - ---------------------------*/ - function createSimpleMockProxy(Function[] memory functions) internal returns(Proxy memory) { - uint pid = ProcessLib.startProxyLibProcess("createSimpleMockProxy"); - return Proxy({ - addr: address(new SimpleMockProxy(functions)), - kind: ProxyKind.Mock - }).finishProcess(pid); - } - - - - /**------------------- - đŸ§Ē Test Utils - ---------------------*/ - // function loadDictionary(Proxy storage proxy) internal returns(Dictionary storage) { - // return ForgeHelper.loadAddress(proxy.addr, ERC7546Utils.DICTIONARY_SLOT).asDictionary(); - // } - - // function changeDictionary(Proxy storage proxy) internal {} - -} diff --git a/devkit/method/test/TestLib.sol b/devkit/method/test/TestLib.sol new file mode 100644 index 00000000..95436043 --- /dev/null +++ b/devkit/method/test/TestLib.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; +/**-------------------------- + Apply Support Methods +----------------------------*/ + +// Core Type +import {Proxy} from "devkit/core/Proxy.sol"; + + +/**=============== + 🏠 Proxy +=================*/ +library TestLib { + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 🚀 Deploy Proxy + đŸ§Ē Test Utils + 🤖 Create Mock Proxy + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + + /**------------------- + đŸ§Ē Test Utils + ---------------------*/ + function loadDictionary(Proxy storage proxy) internal returns(Dictionary storage) { + return ForgeHelper.loadAddress(proxy.addr, ERC7546Utils.DICTIONARY_SLOT).asDictionary(); + } + + function changeDictionary(Proxy storage proxy) internal {} + +} From b490cbbbc892d8efc572fa879ea48378b3d76331 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Tue, 9 Apr 2024 22:11:19 +0900 Subject: [PATCH 054/111] Update DictionaryLib --- devkit/core/Dictionary.sol | 158 ++++++++++++++++++++++++--- devkit/error/Error.sol | 2 + devkit/error/Valid.sol | 4 + devkit/method/core/DictionaryLib.sol | 155 -------------------------- 4 files changed, 146 insertions(+), 173 deletions(-) delete mode 100644 devkit/method/core/DictionaryLib.sol diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index c2a9306a..6cf5dffe 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -1,32 +1,154 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; - -// Core Method -import {DictionaryLib} from "devkit/method/core/DictionaryLib.sol"; -// Support Methods +/**-------------------------- + Apply Support Methods +----------------------------*/ import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; + using ProcessLib for Dictionary global; import {Inspector} from "devkit/method/inspector/Inspector.sol"; + using Inspector for Dictionary global; +import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; +import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; + using Bytes4Utils for bytes4; + +// Validation +import {Valid} from "devkit/error/Valid.sol"; +import {Params} from "devkit/debug/Params.sol"; +// Core Type +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +// Test +import {MockDictionary} from "devkit/test/MockDictionary.sol"; +// External Libs +import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; +import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; /**==================== 📚 Dictionary ======================*/ +using DictionaryLib for Dictionary global; struct Dictionary { address addr; DictionaryKind kind; } -using DictionaryLib for Dictionary global; -// Support Methods -using ProcessLib for Dictionary global; -using Inspector for Dictionary global; - - - /**-------------------- - Dictionary Kind - ----------------------*/ - enum DictionaryKind { - undefined, - Verifiable, - Mock +library DictionaryLib { + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 🚀 Deploy Dictionary + 🔂 Duplicate Dictionary + 🧩 Set Function or Bundle + đŸĒŸ Upgrade Facade + 🤖 Create Mock Dictionary + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + /**------------------------- + 🚀 Deploy Dictionary + ---------------------------*/ + function deploy(address owner) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("deploy"); + Valid.isNotZero(owner); + /// @dev Until Etherscan supports UCS, we are deploying contracts with additional features for Etherscan compatibility by default. + return Dictionary({ + addr: address(new DictionaryEtherscan(owner)), + kind: DictionaryKind.Verifiable + }).finishProcess(pid); + } + + /**---------------------------- + 🔂 Duplicate Dictionary + ------------------------------*/ + function duplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("duplicate"); + return deploy(ForgeHelper.msgSender()) + .duplicateFunctionsFrom(targetDictionary).finishProcess(pid); + } + function duplicateFunctionsFrom(Dictionary memory toDictionary, Dictionary memory fromDictionary) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("duplicateFunctionsFrom"); + address toAddr = toDictionary.addr; + address fromAddr = fromDictionary.addr; + + bytes4[] memory _selectors = IDictionary(fromAddr).supportsInterfaces(); + for (uint i; i < _selectors.length; ++i) { + bytes4 _selector = _selectors[i]; + if (_selector.isEmpty()) continue; + IDictionary(toAddr).setImplementation({ + functionSelector: _selector, + implementation: IDictionary(fromAddr).getImplementation(_selector) + }); + } + + return toDictionary.finishProcess(pid); + } + function safeDuplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("safeDuplicate"); + return targetDictionary.assertNotEmpty().duplicate().finishProcess(pid); + } + + + /**----------------------------- + 🧩 Set Function or Bundle + -------------------------------*/ + function set(Dictionary memory dictionary, Function memory functionInfo) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(functionInfo.name)); + IDictionary(dictionary.addr).setImplementation({ + functionSelector: functionInfo.selector, + implementation: functionInfo.implementation + }); + return dictionary.finishProcess(pid); + } + function set(Dictionary memory dictionary, Bundle storage bundleInfo) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(bundleInfo.name)); + + Function[] memory functions = bundleInfo.functions; + + for (uint i; i < functions.length; ++i) { + dictionary.set(functions[i]); + } + + // TODO Generate Facade + // if (dictionary.isVerifiable()) { + // dictionary.upgradeFacade(bundleInfo.facade); + // } + + return dictionary.finishProcess(pid); + } + + + /**---------------------- + đŸĒŸ Upgrade Facade + ------------------------*/ + function upgradeFacade(Dictionary memory dictionary, address newFacade) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("upgradeFacade"); + DictionaryEtherscan(dictionary.assertVerifiable().addr).upgradeFacade(newFacade); + return dictionary.finishProcess(pid); + } + + + /**------------------------------ + 🤖 Create Mock Dictionary + --------------------------------*/ + function createMockDictionary(address owner, Function[] memory functions) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("createMockDictionary"); + return Dictionary({ + addr: address(new MockDictionary(owner, functions)), + kind: DictionaryKind.Mock + }).finishProcess(pid); } - using Inspector for DictionaryKind global; + + + + // function assignLabel(Dictionary storage dictionary, string memory name) internal returns(Dictionary storage) { + // ForgeHelper.assignLabel(dictionary.addr, name); + // return dictionary; + // } +} + + +/**-------------------- + Dictionary Kind +----------------------*/ +enum DictionaryKind { + undefined, + Verifiable, + Mock +} +using Inspector for DictionaryKind global; diff --git a/devkit/error/Error.sol b/devkit/error/Error.sol index 29e00649..c03d06f8 100644 --- a/devkit/error/Error.sol +++ b/devkit/error/Error.sol @@ -22,6 +22,8 @@ library ERR { string constant NOT_CONTRACT = "Not Contract Address"; string constant STR_ALREADY_ASSIGNED = "String Already Assigned"; string constant B4_ALREADY_ASSIGNED = "Bytes4 Already Assigned"; + string constant ZERO_ADDRESS = "Zero Address"; + // Require string constant RQ_SELECTOR = "Selector is required."; string constant RQ_CONTRACT = "Contract is required."; diff --git a/devkit/error/Valid.sol b/devkit/error/Valid.sol index 7fa1e03e..35dad74a 100644 --- a/devkit/error/Valid.sol +++ b/devkit/error/Valid.sol @@ -59,4 +59,8 @@ library Valid { function isNotEmpty(Dictionary memory dictionary) internal { valid(dictionary.isNotEmpty(), ERR.EMPTY_DICTIONARY); } + + function isNotZero(address addr) internal { + valid(addr.isNotZero(), ERR.ZERO_ADDRESS); + } } diff --git a/devkit/method/core/DictionaryLib.sol b/devkit/method/core/DictionaryLib.sol deleted file mode 100644 index 403ad988..00000000 --- a/devkit/method/core/DictionaryLib.sol +++ /dev/null @@ -1,155 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Validation -import {valid} from "devkit/error/Valid.sol"; -import {Params} from "devkit/debug/Params.sol"; -// Utils -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -// Debug -import {Debug} from "devkit/debug/Debug.sol"; -// Core -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -// Test -import {MockDictionary} from "devkit/test/MockDictionary.sol"; -// External Libs -import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; -import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; -import {IBeacon} from "@oz.mc/proxy/beacon/IBeacon.sol"; -import {ERC1967Utils} from "@oz.mc/proxy/ERC1967/ERC1967Utils.sol"; - - -import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; - - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 📚 Dictionary - 🚀 Deploy Dictionary - 🔂 Duplicate Dictionary - 🧩 Set Function or Bundle - đŸĒŸ Upgrade Facade - 🤖 Create Mock Dictionary -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library DictionaryLib { - /**------------------------- - 🚀 Deploy Dictionary - ---------------------------*/ - function deploy(address owner) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("deploy"); - /// @dev Until Etherscan supports UCS, we are deploying contracts with additional features for Etherscan compatibility by default. - return deployDictionaryVerifiable(owner).finishProcess(pid); - } - /**--------------------------- - Deploy Proxy Primitives - -----------------------------*/ - function deployDictionaryVerifiable(address owner) internal returns(Dictionary memory) { - return Dictionary({ - addr: address(new DictionaryEtherscan(owner)), - kind: DictionaryKind.Verifiable - }); - } - - function safeDeploy(address owner) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("safeDeploy"); - return deploy(owner.assertNotZero()).finishProcess(pid); - } - - - /**---------------------------- - 🔂 Duplicate Dictionary - ------------------------------*/ - function duplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("duplicate"); - return deploy(ForgeHelper.msgSender()) - .duplicateFunctionsFrom(targetDictionary).finishProcess(pid); - } - function duplicateFunctionsFrom(Dictionary memory toDictionary, Dictionary memory fromDictionary) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("duplicateFunctionsFrom"); - address toAddr = toDictionary.addr; - address fromAddr = fromDictionary.addr; - - bytes4[] memory _selectors = IDictionary(fromAddr).supportsInterfaces(); - for (uint i; i < _selectors.length; ++i) { - bytes4 _selector = _selectors[i]; - if (_selector.isEmpty()) continue; - IDictionary(toAddr).setImplementation({ - functionSelector: _selector, - implementation: IDictionary(fromAddr).getImplementation(_selector) - }); - } - - return toDictionary.finishProcess(pid); - } - function safeDuplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("safeDuplicate"); - return targetDictionary.assertNotEmpty().duplicate().finishProcess(pid); - } - - - /**----------------------------- - 🧩 Set Function or Bundle - -------------------------------*/ - function set(Dictionary memory dictionary, Function memory functionInfo) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(functionInfo.name)); - IDictionary(dictionary.addr).setImplementation({ - functionSelector: functionInfo.selector, - implementation: functionInfo.implementation - }); - return dictionary.finishProcess(pid); - } - function set(Dictionary memory dictionary, Bundle storage bundleInfo) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(bundleInfo.name)); - - Function[] memory functions = bundleInfo.functions; - - for (uint i; i < functions.length; ++i) { - dictionary.set(functions[i]); - } - - // TODO Generate Facade - // if (dictionary.isVerifiable()) { - // dictionary.upgradeFacade(bundleInfo.facade); - // } - - return dictionary.finishProcess(pid); - } - - - /**---------------------- - đŸĒŸ Upgrade Facade - ------------------------*/ - function upgradeFacade(Dictionary memory dictionary, address newFacade) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("upgradeFacade"); - DictionaryEtherscan(dictionary.assertVerifiable().addr).upgradeFacade(newFacade); - return dictionary.finishProcess(pid); - } - - - /**------------------------------ - 🤖 Create Mock Dictionary - --------------------------------*/ - function createMockDictionary(address owner, Function[] memory functions) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("createMockDictionary"); - return Dictionary({ - addr: address(new MockDictionary(owner, functions)), - kind: DictionaryKind.Mock - }).finishProcess(pid); - } - - - - // function assignLabel(Dictionary storage dictionary, string memory name) internal returns(Dictionary storage) { - // ForgeHelper.assignLabel(dictionary.addr, name); - // return dictionary; - // } -} From ee678d769c21d345da806cda1894a6d956ea087e Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 08:06:16 +0900 Subject: [PATCH 055/111] Update BundleRegistry Lib --- devkit/core/BundleRegistry.sol | 132 +++++++++++++++++++++-- devkit/method/core/BundleRegistryLib.sol | 131 ---------------------- 2 files changed, 123 insertions(+), 140 deletions(-) delete mode 100644 devkit/method/core/BundleRegistryLib.sol diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/BundleRegistry.sol index f8bd7e2f..0f9bac13 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/BundleRegistry.sol @@ -1,23 +1,137 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; +/**-------------------------- + Apply Support Methods +----------------------------*/ +import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; + using ProcessLib for BundleRegistry global; +import {Inspector} from "devkit/method/inspector/Inspector.sol"; + using Inspector for BundleRegistry global; +import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; + using MappingAnalyzer for mapping(string => Bundle); +// Validation +import {Valid, valid} from "devkit/error/Valid.sol"; // Core Type import {Bundle} from "devkit/core/Bundle.sol"; -// Core Method -import {BundleRegistryLib} from "devkit/method/core/BundleRegistryLib.sol"; -// Support Methods -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -import {Inspector} from "devkit/method/inspector/Inspector.sol"; +import {Function} from "devkit/core/Function.sol"; /**======================== 📙 Bundle Registry ==========================*/ +using BundleRegistryLib for BundleRegistry global; struct BundleRegistry { mapping(string name => Bundle) bundles; string currentBundleName; } -using BundleRegistryLib for BundleRegistry global; -// Support Methods -using ProcessLib for BundleRegistry global; -using Inspector for BundleRegistry global; +library BundleRegistryLib { + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 🌱 Init Bundle + ✨ Add Custom Function + 🔏 Load and Assign Custom Function from Env + đŸ§ē Add Custom Function to Bundle + đŸĒŸ Set Facade + đŸ”ŧ Update Current Context Function & Bundle + 🔍 Find Function & Bundle + 🏷 Generate Unique Name + 🔍 Find Custom Function + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + + /**--------------------- + 🌱 Init Bundle + -----------------------*/ + function init(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + uint pid = bundle.startProcess("init"); + bundle.bundles[name].assignName(name); + bundle.safeUpdateCurrentBundle(name); + return bundle.finishProcess(pid); + } + function safeInit(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + uint pid = bundle.startProcess("safeInit"); + Valid.isNotEmpty(name); + return bundle.assertBundleNotExists(name) + .init(name) + .finishProcess(pid); + } + + + /**------------------------------------- + đŸ§ē Add Custom Function to Bundle + ---------------------------------------*/ + function addToBundle(BundleRegistry storage bundle, Function storage functionInfo) internal returns(BundleRegistry storage) { + uint pid = bundle.startProcess("addToBundle", "function"); + bundle.findCurrentBundle().pushFunction(functionInfo); + return bundle.finishProcess(pid); + } + function addToBundle(BundleRegistry storage bundle, Function[] storage functions) internal returns(BundleRegistry storage) { + uint pid = bundle.startProcess("addToBundle", "bundle"); // TODO params + bundle.findCurrentBundle().pushFunctions(functions); + return bundle.finishProcess(pid); + } + + + /**------------------ + đŸĒŸ Set Facade + --------------------*/ + function set(BundleRegistry storage bundle, string memory name, address facade) internal returns(BundleRegistry storage) { + uint pid = bundle.startProcess("set"); + bundle.bundles[name] + .assertExists() + .assignFacade(facade); + return bundle.finishProcess(pid); + } + function set(BundleRegistry storage bundle, address facade) internal returns(BundleRegistry storage) { + uint pid = bundle.startProcess("set"); + return bundle.set(bundle.findCurrentBundleName(), facade).finishProcess(pid); + } + + + /**------------------------------------------------ + đŸ”ŧ Update Current Context + --------------------------------------------------*/ + function safeUpdateCurrentBundle(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + uint pid = bundle.startProcess("safeUpdateCurrentBundle"); + Valid.isNotEmpty(name); + bundle.currentBundleName = name; + return bundle.finishProcess(pid); + } + + + /**----------------------------------------------- + â™ģī¸ Reset Current Context Function & Bundle + -------------------------------------------------*/ + function reset(BundleRegistry storage bundle) internal returns(BundleRegistry storage) { + uint pid = bundle.startProcess("reset"); + delete bundle.currentBundleName; + return bundle.finishProcess(pid); + } + + + /**------------------------------- + 🔍 Find Function & Bundle + ---------------------------------*/ + function findBundle(BundleRegistry storage bundle, string memory name) internal returns(Bundle storage) { + uint pid = bundle.startProcess("findBundle"); + return bundle.bundles[name].finishProcess(pid); + } + function findCurrentBundle(BundleRegistry storage bundle) internal returns(Bundle storage) { + uint pid = bundle.startProcess("findCurrentBundle"); + return bundle.findBundle(bundle.findCurrentBundleName()).finishProcess(pid); + } + function findCurrentBundleName(BundleRegistry storage bundle) internal returns(string memory) { + uint pid = bundle.startProcess("findCurrentBundleName"); + Valid.isNotEmpty(bundle.currentBundleName); + return bundle.currentBundleName; + // return bundle.currentBundleName.recordExecFinish(pid); + } + + + /**----------------------------- + 🏷 Generate Unique Name + -------------------------------*/ + function genUniqueName(BundleRegistry storage bundle) internal returns(string memory name) { + return bundle.bundles.genUniqueName(); + } + +} diff --git a/devkit/method/core/BundleRegistryLib.sol b/devkit/method/core/BundleRegistryLib.sol deleted file mode 100644 index 95b510bc..00000000 --- a/devkit/method/core/BundleRegistryLib.sol +++ /dev/null @@ -1,131 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Error & Debug -import {valid} from "devkit/error/Valid.sol"; -import {ERR, throwError} from "devkit/error/Error.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Config -import {ScanRange, Config} from "devkit/config/Config.sol"; -// Utils -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -// Core -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -import {StdFunctions} from "devkit/core/StdFunctions.sol"; - -import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; -import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; - using MappingAnalyzer for mapping(string => Bundle); - - -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 📙 Bundle Registry - 🌱 Init Bundle - ✨ Add Custom Function - 🔏 Load and Assign Custom Function from Env - đŸ§ē Add Custom Function to Bundle - đŸĒŸ Set Facade - đŸ”ŧ Update Current Context Function & Bundle - 🔍 Find Function & Bundle - 🏷 Generate Unique Name - 🔍 Find Custom Function -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library BundleRegistryLib { - /**--------------------- - 🌱 Init Bundle - -----------------------*/ - function init(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("init"); - bundle.bundles[name].assignName(name); - bundle.safeUpdateCurrentBundle(name); - return bundle.finishProcess(pid); - } - function safeInit(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("safeInit"); - valid(name.isNotEmpty(), "Empty Name"); - return bundle.assertBundleNotExists(name) - .init(name) - .finishProcess(pid); - } - - - /**------------------------------------- - đŸ§ē Add Custom Function to Bundle - ---------------------------------------*/ - function addToBundle(BundleRegistry storage bundle, Function storage functionInfo) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("addToBundle", "function"); - bundle.findCurrentBundle().pushFunction(functionInfo); - return bundle.finishProcess(pid); - } - function addToBundle(BundleRegistry storage bundle, Function[] storage functions) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("addToBundle", "bundle"); // TODO params - bundle.findCurrentBundle().pushFunctions(functions); - return bundle.finishProcess(pid); - } - - - /**------------------ - đŸĒŸ Set Facade - --------------------*/ - function set(BundleRegistry storage bundle, string memory name, address facade) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("set"); - bundle.bundles[name] - .assertExists() - .assignFacade(facade); - return bundle.finishProcess(pid); - } - function set(BundleRegistry storage bundle, address facade) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("set"); - return bundle.set(bundle.findCurrentBundleName(), facade).finishProcess(pid); - } - - - /**------------------------------------------------ - đŸ”ŧ Update Current Context - --------------------------------------------------*/ - function safeUpdateCurrentBundle(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("safeUpdateCurrentBundle"); - bundle.currentBundleName = name.assertNotEmpty(); - return bundle.finishProcess(pid); - } - - - /**----------------------------------------------- - â™ģī¸ Reset Current Context Function & Bundle - -------------------------------------------------*/ - function reset(BundleRegistry storage bundle) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("reset"); - delete bundle.currentBundleName; - return bundle.finishProcess(pid); - } - - - /**------------------------------- - 🔍 Find Function & Bundle - ---------------------------------*/ - function findBundle(BundleRegistry storage bundle, string memory name) internal returns(Bundle storage) { - uint pid = bundle.startProcess("findBundle"); - return bundle.bundles[name].finishProcess(pid); - } - function findCurrentBundle(BundleRegistry storage bundle) internal returns(Bundle storage) { - uint pid = bundle.startProcess("findCurrentBundle"); - return bundle.findBundle(bundle.findCurrentBundleName()).finishProcess(pid); - } - function findCurrentBundleName(BundleRegistry storage bundle) internal returns(string memory) { - uint pid = bundle.startProcess("findCurrentBundleName"); - return bundle.currentBundleName.assertNotEmpty().recordExecFinish(pid); - } - - - /**----------------------------- - 🏷 Generate Unique Name - -------------------------------*/ - function genUniqueName(BundleRegistry storage bundle) internal returns(string memory name) { - return bundle.bundles.genUniqueName(); - } - -} From 4e6e52619125194db5cae97d5866c67048323147 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 08:25:46 +0900 Subject: [PATCH 056/111] Separate valid and Require --- devkit/core/Bundle.sol | 9 ++-- devkit/core/BundleRegistry.sol | 9 ++-- devkit/core/Dictionary.sol | 5 +-- devkit/core/Function.sol | 26 ++++++------ devkit/core/Proxy.sol | 5 +-- devkit/error/{Valid.sol => Require.sol} | 32 ++++++--------- devkit/error/Validate.sol | 17 ++++++++ devkit/method/MCBundleLib.sol | 6 +-- devkit/method/MCDeployLib.sol | 2 +- devkit/method/core/DictionaryRegistryLib.sol | 2 +- devkit/method/core/FunctionRegistryLib.sol | 5 ++- devkit/method/core/MockRegistryLib.sol | 15 +++---- devkit/method/core/ProxyRegistryLib.sol | 2 +- devkit/method/inspector/Inspector.sol | 43 ++++++++++---------- devkit/utils/AddressUtils.sol | 8 ++-- devkit/utils/Bytes4Utils.sol | 6 +-- devkit/utils/StringUtils.sol | 8 ++-- 17 files changed, 107 insertions(+), 93 deletions(-) rename devkit/error/{Valid.sol => Require.sol} (58%) create mode 100644 devkit/error/Validate.sol diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index b81c4119..6778c7e8 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -14,7 +14,8 @@ import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.so // Core Type import {Function} from "devkit/core/Function.sol"; // Validation -import {valid, Valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; +import {Require} from "devkit/error/Require.sol"; /**================ @@ -39,7 +40,7 @@ library BundleLib { ----------------------*/ function assignName(Bundle storage bundle, string memory name) internal returns(Bundle storage) { uint pid = bundle.startProcess("assignName"); - Valid.notEmptyString(name); + Require.notEmptyString(name); bundle.name = name; return bundle.finishProcess(pid); } @@ -49,7 +50,7 @@ library BundleLib { ---------------------------*/ function pushFunction(Bundle storage bundle, Function storage func) internal returns(Bundle storage) { uint pid = bundle.startProcess("pushFunction"); - valid(bundle.hasNot(func), "Already added"); + validate(bundle.hasNot(func), "Already added"); bundle.functions.push( func.assertImplIsContract() ); @@ -68,7 +69,7 @@ library BundleLib { ------------------------*/ function assignFacade(Bundle storage bundle, address facade) internal returns(Bundle storage) { uint pid = bundle.startProcess("assignFacade"); - Valid.isContract(facade); + Require.isContract(facade); bundle.facade = facade; return bundle.finishProcess(pid); } diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/BundleRegistry.sol index 0f9bac13..effd02af 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/BundleRegistry.sol @@ -11,7 +11,8 @@ import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Bundle); // Validation -import {Valid, valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; +import {Require} from "devkit/error/Require.sol"; // Core Type import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; @@ -49,7 +50,7 @@ library BundleRegistryLib { } function safeInit(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { uint pid = bundle.startProcess("safeInit"); - Valid.isNotEmpty(name); + Require.isNotEmpty(name); return bundle.assertBundleNotExists(name) .init(name) .finishProcess(pid); @@ -92,7 +93,7 @@ library BundleRegistryLib { --------------------------------------------------*/ function safeUpdateCurrentBundle(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { uint pid = bundle.startProcess("safeUpdateCurrentBundle"); - Valid.isNotEmpty(name); + Require.isNotEmpty(name); bundle.currentBundleName = name; return bundle.finishProcess(pid); } @@ -121,7 +122,7 @@ library BundleRegistryLib { } function findCurrentBundleName(BundleRegistry storage bundle) internal returns(string memory) { uint pid = bundle.startProcess("findCurrentBundleName"); - Valid.isNotEmpty(bundle.currentBundleName); + Require.isNotEmpty(bundle.currentBundleName); return bundle.currentBundleName; // return bundle.currentBundleName.recordExecFinish(pid); } diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 6cf5dffe..0bcc653b 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -12,8 +12,7 @@ import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; using Bytes4Utils for bytes4; // Validation -import {Valid} from "devkit/error/Valid.sol"; -import {Params} from "devkit/debug/Params.sol"; +import {Require} from "devkit/error/Require.sol";import {Params} from "devkit/debug/Params.sol"; // Core Type import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; @@ -45,7 +44,7 @@ library DictionaryLib { ---------------------------*/ function deploy(address owner) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("deploy"); - Valid.isNotZero(owner); + Require.isNotZero(owner); /// @dev Until Etherscan supports UCS, we are deploying contracts with additional features for Etherscan compatibility by default. return Dictionary({ addr: address(new DictionaryEtherscan(owner)), diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index f07305a7..9c51b862 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -15,7 +15,7 @@ import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.so using TypeSafetyUtils for Function global; // Validation -import {Valid} from "devkit/error/Valid.sol"; +import {Require} from "devkit/error/Require.sol"; // Loader import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; @@ -53,7 +53,7 @@ library FunctionLib { 📛 Assign Name ----------------------*/ function assignName(Function storage func, string memory name) internal returns(Function storage) { - Valid.notLocked(func.buildStatus); + Require.notLocked(func.buildStatus); func.name = name; func.asBuilding(); return func; @@ -63,7 +63,7 @@ library FunctionLib { đŸŽ¯ Assign Selector --------------------------*/ function assignSelector(Function storage func, bytes4 selector) internal returns(Function storage) { - Valid.notLocked(func.buildStatus); + Require.notLocked(func.buildStatus); func.selector = selector; func.asBuilding(); return func; @@ -73,7 +73,7 @@ library FunctionLib { 🔌 Assign Implementation --------------------------------*/ function assignImplementation(Function storage func, address implementation) internal returns(Function storage) { - Valid.notLocked(func.buildStatus); + Require.notLocked(func.buildStatus); func.implementation = implementation; func.asBuilding(); return func; @@ -88,8 +88,8 @@ library FunctionLib { } function build(Function storage func) internal returns(Function storage) { // TODO - Valid.assigned(func.selector); - Valid.contractAssigned(func.implementation); + Require.assigned(func.selector); + Require.contractAssigned(func.implementation); func.buildStatus = BuildStatus.Built; return func; } @@ -101,8 +101,8 @@ library FunctionLib { // function fetch(Function storage func, string memory envKey) internal returns(Function storage) { // uint pid = func.startProcess("fetch"); - // Valid.isUnassigned(func.name); - // Valid.isNotEmpty(envKey); + // Require.isUnassigned(func.name); + // Require.isNotEmpty(envKey); // return func; // } // function fetchAndAssign(Function storage func, string memory envKey, bytes4 selector) internal returns(Function storage) { @@ -119,15 +119,15 @@ library FunctionLib { // .finishProcess(pid); // } // function loadAndAssignFromEnv(Function storage func) internal returns(Function storage) { - // Valid.isNotEmpty(func.name); - // Valid.isNotEmpty(func.selector); + // Require.isNotEmpty(func.name); + // Require.isNotEmpty(func.selector); // return func.loadAndAssignFromEnv(func.name, func.name, func.selector); // } // function safeLoadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { // uint pid = func.startProcess("safeLoadAndAssignFromEnv"); - // Valid.isNotEmpty(envKey); - // Valid.isNotEmpty(name); - // Valid.isNotEmpty(selector); + // Require.isNotEmpty(envKey); + // Require.isNotEmpty(name); + // Require.isNotEmpty(selector); // return func.loadAndAssignFromEnv(envKey, name, selector).finishProcess(pid); // } diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index 5f2c4838..7cafc385 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -10,8 +10,7 @@ import {Inspector} from "devkit/method/inspector/Inspector.sol"; using Inspector for ProxyKind global; // Validation -import {Valid} from "devkit/error/Valid.sol"; -// Core Type +import {Require} from "devkit/error/Require.sol";// Core Type import {Dictionary} from "devkit/core/Dictionary.sol"; import {Function} from "devkit/core/Function.sol"; // Test @@ -39,7 +38,7 @@ library ProxyLib { -----------------------*/ function deploy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory proxy) { uint pid = ProcessLib.startProxyLibProcess("deploy"); - Valid.isNotEmpty(dictionary); + Require.isNotEmpty(dictionary); return Proxy({ addr: address(new ERC7546ProxyEtherscan(dictionary.addr, initData)), kind: ProxyKind.Verifiable diff --git a/devkit/error/Valid.sol b/devkit/error/Require.sol similarity index 58% rename from devkit/error/Valid.sol rename to devkit/error/Require.sol index 35dad74a..1c2c9e92 100644 --- a/devkit/error/Valid.sol +++ b/devkit/error/Require.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.24; import {throwError, ERR} from "devkit/error/Error.sol"; +import {validate} from "devkit/error/Validate.sol"; // Utils import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; @@ -14,53 +15,46 @@ import {AddressUtils} from "devkit/utils/AddressUtils.sol"; import {BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; import {Dictionary} from "devkit/core/Dictionary.sol"; -/// @dev like `require` -function valid(bool condition, string memory errorBody) { - if (condition.isFalse()) throwError(errorBody); -} -function valid(bool condition, string memory errorBody, string memory errorDetail) { - valid(condition, errorBody.append(errorDetail)); -} -library Valid { +library Require { function isUnassigned(string storage str) internal { - valid(str.isEmpty(), ERR.STR_ALREADY_ASSIGNED); + validate(str.isEmpty(), ERR.STR_ALREADY_ASSIGNED); } function isNotEmpty(string memory str) internal { - valid(str.isNotEmpty(), ERR.EMPTY_STR); + validate(str.isNotEmpty(), ERR.EMPTY_STR); } function isUnassigned(bytes4 b4) internal { - valid(b4.isEmpty(), ERR.B4_ALREADY_ASSIGNED); + validate(b4.isEmpty(), ERR.B4_ALREADY_ASSIGNED); } function isNotEmpty(bytes4 b4) internal { - valid(b4.isNotEmpty(), ERR.EMPTY_B4); + validate(b4.isNotEmpty(), ERR.EMPTY_B4); } function isContract(address addr) internal { - valid(addr.isContract(), ERR.NOT_CONTRACT); + validate(addr.isContract(), ERR.NOT_CONTRACT); } function notEmptyString(string memory str) internal { - valid(str.isNotEmpty(), ERR.RQ_NOT_EMPTY_STRING); + validate(str.isNotEmpty(), ERR.RQ_NOT_EMPTY_STRING); } function assigned(bytes4 b4) internal { - valid(b4.isNotEmpty(), ERR.RQ_SELECTOR); + validate(b4.isNotEmpty(), ERR.RQ_SELECTOR); } function contractAssigned(address addr) internal { - valid(addr.isContract(), ERR.RQ_CONTRACT); + validate(addr.isContract(), ERR.RQ_CONTRACT); } function notLocked(BuildStatus status) internal { - valid(status != BuildStatus.Locked, ERR.LOCKED_OBJECT); + validate(status != BuildStatus.Locked, ERR.LOCKED_OBJECT); } function isNotEmpty(Dictionary memory dictionary) internal { - valid(dictionary.isNotEmpty(), ERR.EMPTY_DICTIONARY); + validate(dictionary.isNotEmpty(), ERR.EMPTY_DICTIONARY); } function isNotZero(address addr) internal { - valid(addr.isNotZero(), ERR.ZERO_ADDRESS); + validate(addr.isNotZero(), ERR.ZERO_ADDRESS); } } diff --git a/devkit/error/Validate.sol b/devkit/error/Validate.sol new file mode 100644 index 00000000..529388b0 --- /dev/null +++ b/devkit/error/Validate.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {throwError, ERR} from "devkit/error/Error.sol"; +// Utils +import {BoolUtils} from "devkit/utils/BoolUtils.sol"; + using BoolUtils for bool; +import {StringUtils} from "devkit/utils/StringUtils.sol"; + using StringUtils for string; + +/// @dev like `require` +function validate(bool condition, string memory errorBody) { + if (condition.isFalse()) throwError(errorBody); +} +function validate(bool condition, string memory errorBody, string memory errorDetail) { + validate(condition, errorBody.append(errorDetail)); +} diff --git a/devkit/method/MCBundleLib.sol b/devkit/method/MCBundleLib.sol index 5e47a8aa..6a10901e 100644 --- a/devkit/method/MCBundleLib.sol +++ b/devkit/method/MCBundleLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Validation -import {valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; import {ERR} from "devkit/error/Error.sol"; // Utils import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; @@ -70,7 +70,7 @@ library MCBundleLib { // return mc; // } TODO function use(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - valid(mc.functions.find(name).isComplete(), "Invalid Function Name"); + validate(mc.functions.find(name).isComplete(), "Invalid Function Name"); return mc.use(mc.findFunction(name)); } /**--------------------------- @@ -100,7 +100,7 @@ library MCBundleLib { --------------------*/ function useFacade(MCDevKit storage mc, address facade) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("set"); - valid(mc.bundle.existsCurrentBundle(), ERR.NOT_INIT); + validate(mc.bundle.existsCurrentBundle(), ERR.NOT_INIT); mc.bundle.set(mc.bundle.findCurrentBundleName(), facade); return mc.recordExecFinish(pid); } diff --git a/devkit/method/MCDeployLib.sol b/devkit/method/MCDeployLib.sol index e33d54ac..5235caef 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/method/MCDeployLib.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; import {Config} from "devkit/config/Config.sol"; // Validation -import {valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; // Utils import {Params} from "devkit/debug/Params.sol"; // Core diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol index 8da709a5..2de7c401 100644 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; -import {valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; diff --git a/devkit/method/core/FunctionRegistryLib.sol b/devkit/method/core/FunctionRegistryLib.sol index 26e5e145..a890fbc1 100644 --- a/devkit/method/core/FunctionRegistryLib.sol +++ b/devkit/method/core/FunctionRegistryLib.sol @@ -2,7 +2,8 @@ pragma solidity ^0.8.24; // Error & Debug -import {Valid, valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; +import {Require} from "devkit/error/Require.sol"; import {ERR, throwError} from "devkit/error/Error.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config @@ -33,7 +34,7 @@ library FunctionRegistryLib { --------------------------------*/ function insert(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { uint pid = functions.startProcess("insert"); - Valid.isNotEmpty(name); + Require.isNotEmpty(name); functions.customs[name].assign(name, selector, implementation).lock(); functions.safeUpdateCurrentFunction(name); // TODO return functions.finishProcess(pid); diff --git a/devkit/method/core/MockRegistryLib.sol b/devkit/method/core/MockRegistryLib.sol index 8106322b..cf39d441 100644 --- a/devkit/method/core/MockRegistryLib.sol +++ b/devkit/method/core/MockRegistryLib.sol @@ -3,7 +3,8 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; -import {valid, Valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; +import {Require} from "devkit/error/Require.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; @@ -41,8 +42,8 @@ library MockRegistryLib { /*----- Mock Dictionary -----*/ function add(MockRegistry storage mock, string memory name, Dictionary memory dictionary) internal returns(MockRegistry storage) { uint pid = mock.startProcess("add"); - Valid.isNotEmpty(name); - valid(dictionary.isNotEmpty(), "Empty Dictionary"); + Require.isNotEmpty(name); + validate(dictionary.isNotEmpty(), "Empty Dictionary"); mock.dictionary[name] = dictionary; return mock.finishProcess(pid); } @@ -53,8 +54,8 @@ library MockRegistryLib { /*----- Mock Proxy -----*/ function add(MockRegistry storage mock, string memory name, Proxy memory proxy) internal returns(MockRegistry storage) { uint pid = mock.startProcess("add"); - Valid.isNotEmpty(name); - valid(proxy.isNotEmpty(), "Empty Proxy"); + Require.isNotEmpty(name); + validate(proxy.isNotEmpty(), "Empty Proxy"); mock.proxy[name] = proxy; return mock.finishProcess(pid); } @@ -69,14 +70,14 @@ library MockRegistryLib { /*----- Mock Dictionary -----*/ function findMockDictionary(MockRegistry storage mock, string memory name) internal returns(Dictionary storage) { uint pid = mock.startProcess("findMockDictionary"); - Valid.isNotEmpty(name); + Require.isNotEmpty(name); return mock.dictionary[name].assertExists().finishProcessInStorage(pid); } /*----- Mock Proxy -----*/ function findMockProxy(MockRegistry storage mock, string memory name) internal returns(Proxy storage) { uint pid = mock.startProcess("findMockProxy"); - Valid.isNotEmpty(name); + Require.isNotEmpty(name); return mock.proxy[name].assertExists().finishProcessInStorage(pid); } diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol index 0e0a0267..3ca68578 100644 --- a/devkit/method/core/ProxyRegistryLib.sol +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; -import {valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; diff --git a/devkit/method/inspector/Inspector.sol b/devkit/method/inspector/Inspector.sol index 8e896c1b..5e60d774 100644 --- a/devkit/method/inspector/Inspector.sol +++ b/devkit/method/inspector/Inspector.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {valid, Valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; +import {Require} from "devkit/error/Require.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; import {AddressUtils} from "devkit/utils/AddressUtils.sol"; @@ -47,35 +48,35 @@ library Inspector { } function assertExists(Function storage func) internal returns(Function storage) { - valid(func.exists(), "func does not exists"); + validate(func.exists(), "func does not exists"); return func; } function assertEmptyName(Function storage func) internal returns(Function storage) { - Valid.isUnassigned(func.name); + Require.isUnassigned(func.name); return func; } function assertEmptySelector(Function storage func) internal returns(Function storage) { - Valid.isUnassigned(func.selector); + Require.isUnassigned(func.selector); return func; } function assertEmptyImpl(Function storage func) internal returns(Function storage) { - valid(func.implementation.isNotContract(), "Implementation Already Exist"); + validate(func.implementation.isNotContract(), "Implementation Already Exist"); return func; } function assertNotEmpty(Function storage func) internal returns(Function storage) { - valid(func.exists(), "Empty Deployed Contract"); + validate(func.exists(), "Empty Deployed Contract"); return func; } function assertNotIncludedIn(Function storage func, Bundle storage bundleInfo) internal returns(Function storage) { - valid(bundleInfo.hasNot(func), "Already exists in the Bundel"); + validate(bundleInfo.hasNot(func), "Already exists in the Bundel"); return func; } function assertImplIsContract(Function storage func) internal returns(Function storage) { - valid(func.implementation.isContract(), "Implementation Not Contract"); + validate(func.implementation.isContract(), "Implementation Not Contract"); return func; } @@ -85,7 +86,7 @@ library Inspector { func.implementation.isContract(); } function assertComplete(Function storage func) internal returns(Function storage) { - valid(func.isComplete(), "Function Info Not Complete"); + validate(func.isComplete(), "Function Info Not Complete"); return func; } @@ -112,7 +113,7 @@ library Inspector { bundle.facade.isContract(); } function assertComplete(Bundle storage bundle) internal returns(Bundle storage) { - valid(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); + validate(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); return bundle; } @@ -132,11 +133,11 @@ library Inspector { return bundle.exists().isNot(); } function assertExists(Bundle storage bundle) internal returns(Bundle storage) { - valid(bundle.exists(), "Bundle Info Not Exists"); + validate(bundle.exists(), "Bundle Info Not Exists"); return bundle; } function assertNotExists(Bundle storage bundle) internal returns(Bundle storage) { - valid(bundle.notExists(), "Bundle Info Already Exists"); + validate(bundle.notExists(), "Bundle Info Already Exists"); return bundle; } @@ -151,7 +152,7 @@ library Inspector { return bundle.existsBundle(name).isNot(); } function assertBundleNotExists(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - valid(bundle.notExistsBundle(name), "Bundle Already Exists"); + validate(bundle.notExistsBundle(name), "Bundle Already Exists"); return bundle; } @@ -170,7 +171,7 @@ library Inspector { return proxy.addr.isContract(); } function assertExists(Proxy storage proxy) internal returns(Proxy storage) { - valid(proxy.exists(), "Proxy Not Exist"); + validate(proxy.exists(), "Proxy Not Exist"); return proxy; } @@ -182,7 +183,7 @@ library Inspector { return proxy.addr.isContract(); } function assertNotEmpty(Proxy memory proxy) internal returns(Proxy memory) { - valid(proxy.isNotEmpty(), "Empty Proxy"); + validate(proxy.isNotEmpty(), "Empty Proxy"); return proxy; } @@ -205,7 +206,7 @@ library Inspector { return kind != ProxyKind.undefined; } function assertNotUndefined(ProxyKind kind) internal returns(ProxyKind) { - valid(kind.isNotUndefined(), "Undefined Proxy Kind"); + validate(kind.isNotUndefined(), "Undefined Proxy Kind"); return kind; } @@ -227,7 +228,7 @@ library Inspector { return dictionary.addr.isContract(); } function assertExists(Dictionary storage dictionary) internal returns(Dictionary storage) { - valid(dictionary.exists(), "Dictionary Not Exists"); + validate(dictionary.exists(), "Dictionary Not Exists"); return dictionary; } @@ -239,7 +240,7 @@ library Inspector { return dictionary.addr.isContract(); } function assertNotEmpty(Dictionary memory dictionary) internal returns(Dictionary memory) { - valid(dictionary.isNotEmpty(), "Empty Dictionary"); + validate(dictionary.isNotEmpty(), "Empty Dictionary"); return dictionary; } @@ -247,7 +248,7 @@ library Inspector { return IDictionary(dictionary.addr).supportsInterface(selector); } function assertSupports(Dictionary storage dictionary, bytes4 selector) internal returns(Dictionary storage) { - valid(dictionary.isSupported(selector), "Unsupported Selector"); + validate(dictionary.isSupported(selector), "Unsupported Selector"); return dictionary; } @@ -256,7 +257,7 @@ library Inspector { return success; } function assertVerifiable(Dictionary memory dictionary) internal returns(Dictionary memory) { - valid(dictionary.isVerifiable(), "Dictionary Not Verifiable"); + validate(dictionary.isVerifiable(), "Dictionary Not Verifiable"); return dictionary; } @@ -277,7 +278,7 @@ library Inspector { return kind != DictionaryKind.undefined; } function assertNotUndefined(DictionaryKind kind) internal returns(DictionaryKind) { - valid(kind.isNotUndefined(), "Undefined Dictionary Kind"); + validate(kind.isNotUndefined(), "Undefined Dictionary Kind"); return kind; } diff --git a/devkit/utils/AddressUtils.sol b/devkit/utils/AddressUtils.sol index 7b6f4bbb..ba85a85a 100644 --- a/devkit/utils/AddressUtils.sol +++ b/devkit/utils/AddressUtils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; // Utils import {vm} from "./ForgeHelper.sol"; import {BoolUtils} from "./BoolUtils.sol"; @@ -31,7 +31,7 @@ library AddressUtils { return addr == address(0); } function assertZero(address addr) internal returns(address) { - valid(addr.isZero(), "Address Not Zero"); + validate(addr.isZero(), "Address Not Zero"); return addr; } @@ -40,7 +40,7 @@ library AddressUtils { return addr.isZero().isNot(); } function assertNotZero(address addr) internal returns(address) { - valid(addr.isNotZero(), "Zero Address"); + validate(addr.isNotZero(), "Zero Address"); return addr; } @@ -59,7 +59,7 @@ library AddressUtils { return addr.hasCode(); } function assertIsContract(address addr) internal returns(address) { - valid(addr.isContract(), "Address Not Contract"); + validate(addr.isContract(), "Address Not Contract"); return addr; } diff --git a/devkit/utils/Bytes4Utils.sol b/devkit/utils/Bytes4Utils.sol index 808279af..18606182 100644 --- a/devkit/utils/Bytes4Utils.sol +++ b/devkit/utils/Bytes4Utils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; // Utils import {vm} from "./ForgeHelper.sol"; import {StringUtils} from "./StringUtils.sol"; @@ -36,7 +36,7 @@ library Bytes4Utils { return selector == bytes4(0); } function assertEmpty(bytes4 selector) internal returns(bytes4) { - valid(selector.isEmpty(), "Selector Not Empty"); + validate(selector.isEmpty(), "Selector Not Empty"); return selector; } @@ -44,7 +44,7 @@ library Bytes4Utils { return selector.isEmpty().isFalse(); } function assertNotEmpty(bytes4 selector) internal returns(bytes4) { - valid(selector.isNotEmpty(), "Empty Selector"); + validate(selector.isNotEmpty(), "Empty Selector"); return selector; } diff --git a/devkit/utils/StringUtils.sol b/devkit/utils/StringUtils.sol index 5c6cc501..b993ea66 100644 --- a/devkit/utils/StringUtils.sol +++ b/devkit/utils/StringUtils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {valid} from "devkit/error/Valid.sol"; +import {validate} from "devkit/error/Validate.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Utils import {StdStyle, ForgeHelper, vm} from "./ForgeHelper.sol"; @@ -24,7 +24,7 @@ library StringUtils { return keccak256(abi.encode(name)); } function safeCalcHash(string memory name) internal returns(bytes32) { - valid(name.isNotEmpty(), "Calc Hash"); + validate(name.isNotEmpty(), "Calc Hash"); return name.calcHash(); } @@ -105,7 +105,7 @@ library StringUtils { return bytes(str).length == 0; } function assertEmpty(string memory str) internal returns(string memory) { - valid(str.isEmpty(), "String Not Empty"); + validate(str.isEmpty(), "String Not Empty"); return str; } @@ -114,7 +114,7 @@ library StringUtils { return str.isEmpty().isNot(); } function assertNotEmpty(string memory str) internal returns(string memory) { - valid(str.isNotEmpty(), "Empty String"); + validate(str.isNotEmpty(), "Empty String"); return str; } From 99a5714db652741ae1c4140ba989c440401d59f7 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 09:21:42 +0900 Subject: [PATCH 057/111] Update Require --- devkit/core/Bundle.sol | 5 +- devkit/core/BundleRegistry.sol | 15 ++- devkit/core/Dictionary.sol | 6 +- devkit/error/Require.sol | 112 ++++++++++++++++++- devkit/method/core/DictionaryRegistryLib.sol | 16 ++- devkit/method/core/FunctionRegistryLib.sol | 5 +- devkit/method/core/MockRegistryLib.sol | 14 ++- devkit/method/core/ProxyRegistryLib.sol | 15 ++- devkit/method/inspector/Inspector.sol | 94 +--------------- 9 files changed, 159 insertions(+), 123 deletions(-) diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 6778c7e8..34433cf6 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -51,9 +51,8 @@ library BundleLib { function pushFunction(Bundle storage bundle, Function storage func) internal returns(Bundle storage) { uint pid = bundle.startProcess("pushFunction"); validate(bundle.hasNot(func), "Already added"); - bundle.functions.push( - func.assertImplIsContract() - ); + Require.implIsContract(func); + bundle.functions.push(func); return bundle.finishProcess(pid); } function pushFunctions(Bundle storage bundle, Function[] storage functions) internal returns(Bundle storage) { diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/BundleRegistry.sol index effd02af..88a81770 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/BundleRegistry.sol @@ -50,9 +50,9 @@ library BundleRegistryLib { } function safeInit(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { uint pid = bundle.startProcess("safeInit"); - Require.isNotEmpty(name); - return bundle.assertBundleNotExists(name) - .init(name) + Require.notEmpty(name); + Require.bundleNotExists(bundle, name); + return bundle .init(name) .finishProcess(pid); } @@ -77,9 +77,8 @@ library BundleRegistryLib { --------------------*/ function set(BundleRegistry storage bundle, string memory name, address facade) internal returns(BundleRegistry storage) { uint pid = bundle.startProcess("set"); - bundle.bundles[name] - .assertExists() - .assignFacade(facade); + Require.exists(bundle.bundles[name]); + bundle.bundles[name].assignFacade(facade); return bundle.finishProcess(pid); } function set(BundleRegistry storage bundle, address facade) internal returns(BundleRegistry storage) { @@ -93,7 +92,7 @@ library BundleRegistryLib { --------------------------------------------------*/ function safeUpdateCurrentBundle(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { uint pid = bundle.startProcess("safeUpdateCurrentBundle"); - Require.isNotEmpty(name); + Require.notEmpty(name); bundle.currentBundleName = name; return bundle.finishProcess(pid); } @@ -122,7 +121,7 @@ library BundleRegistryLib { } function findCurrentBundleName(BundleRegistry storage bundle) internal returns(string memory) { uint pid = bundle.startProcess("findCurrentBundleName"); - Require.isNotEmpty(bundle.currentBundleName); + Require.notEmpty(bundle.currentBundleName); return bundle.currentBundleName; // return bundle.currentBundleName.recordExecFinish(pid); } diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 0bcc653b..9087dd83 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -79,7 +79,8 @@ library DictionaryLib { } function safeDuplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("safeDuplicate"); - return targetDictionary.assertNotEmpty().duplicate().finishProcess(pid); + Require.notEmpty(targetDictionary); + return targetDictionary.duplicate().finishProcess(pid); } @@ -117,7 +118,8 @@ library DictionaryLib { ------------------------*/ function upgradeFacade(Dictionary memory dictionary, address newFacade) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("upgradeFacade"); - DictionaryEtherscan(dictionary.assertVerifiable().addr).upgradeFacade(newFacade); + Require.verifiable(dictionary); + DictionaryEtherscan(dictionary.addr).upgradeFacade(newFacade); return dictionary.finishProcess(pid); } diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index 1c2c9e92..083fea5e 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -13,14 +13,122 @@ import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; import {BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; -import {Dictionary} from "devkit/core/Dictionary.sol"; +// Core Types +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; +import {Proxy, ProxyKind} from "devkit/core/Proxy.sol"; +import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; +import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; +import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; library Require { + /**================== + 🧩 Function + ====================*/ + function exists(Function storage func) internal { + validate(func.exists(), "func does not exists"); + // validate(func.isBuilt(), "func does not exists"); // TODO + } + + function EmptyName(Function storage func) internal { + Require.isUnassigned(func.name); + } + function EmptySelector(Function storage func) internal { + Require.isUnassigned(func.selector); + } + function EmptyImpl(Function storage func) internal { + validate(func.implementation.isNotContract(), "Implementation Already Exist"); + } + + function NotEmpty(Function storage func) internal { + validate(func.exists(), "Empty Deployed Contract"); + } + + function NotIncludedIn(Function storage func, Bundle storage bundleInfo) internal { + validate(bundleInfo.hasNot(func), "Already exists in the Bundel"); + } + + function implIsContract(Function storage func) internal { + validate(func.implementation.isContract(), "Implementation Not Contract"); + } + function Complete(Function storage func) internal { + validate(func.isComplete(), "Function Info Not Complete"); + } + + + /**=============== + đŸ—‚ī¸ Bundle + =================*/ + function Complete(Bundle storage bundle) internal returns(Bundle storage) { + validate(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); + return bundle; + } + function exists(Bundle storage bundle) internal returns(Bundle storage) { + validate(bundle.exists(), "Bundle Info Not Exists"); + return bundle; + } + function notExists(Bundle storage bundle) internal returns(Bundle storage) { + validate(bundle.notExists(), "Bundle Info Already Exists"); + return bundle; + } + + /**======================= + 📙 Bundle Registry + =========================*/ + function bundleNotExists(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + validate(bundle.notExistsBundle(name), "Bundle Already Exists"); + return bundle; + } + + /**============== + 🏠 Proxy + ================*/ + function exists(Proxy storage proxy) internal returns(Proxy storage) { + validate(proxy.exists(), "Proxy Not Exist"); + return proxy; + } + function notEmpty(Proxy memory proxy) internal returns(Proxy memory) { + validate(proxy.isNotEmpty(), "Empty Proxy"); + return proxy; + } + /*---- Proxy Kind -----*/ + function NotUndefined(ProxyKind kind) internal returns(ProxyKind) { + validate(kind.isNotUndefined(), "Undefined Proxy Kind"); + return kind; + } + + /**==================== + 📚 Dictionary + ======================*/ + function exists(Dictionary storage dictionary) internal returns(Dictionary storage) { + validate(dictionary.exists(), "Dictionary Not Exists"); + return dictionary; + } + function notEmpty(Dictionary memory dictionary) internal returns(Dictionary memory) { + validate(dictionary.isNotEmpty(), "Empty Dictionary"); + return dictionary; + } + function Supports(Dictionary storage dictionary, bytes4 selector) internal returns(Dictionary storage) { + validate(dictionary.isSupported(selector), "Unsupported Selector"); + return dictionary; + } + function verifiable(Dictionary memory dictionary) internal returns(Dictionary memory) { + validate(dictionary.isVerifiable(), "Dictionary Not Verifiable"); + return dictionary; + } + /*---- Dictionary Kind -----*/ + function NotUndefined(DictionaryKind kind) internal returns(DictionaryKind) { + validate(kind.isNotUndefined(), "Undefined Dictionary Kind"); + return kind; + } + + function isUnassigned(string storage str) internal { validate(str.isEmpty(), ERR.STR_ALREADY_ASSIGNED); } - function isNotEmpty(string memory str) internal { + function notEmpty(string memory str) internal { validate(str.isNotEmpty(), ERR.EMPTY_STR); } diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol index 2de7c401..43980a75 100644 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; import {validate} from "devkit/error/Validate.sol"; +import {Require} from "devkit/error/Require.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; @@ -39,7 +40,9 @@ library DictionaryRegistryLib { function safeAdd(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { uint pid = dictionaries.startProcess("safeAdd"); - return dictionaries .add(name.assertNotEmpty(), dictionary.assertNotEmpty()) + Require.notEmpty(name); + Require.notEmpty(dictionary); + return dictionaries .add(name, dictionary) .finishProcess(pid); } @@ -49,7 +52,8 @@ library DictionaryRegistryLib { -------------------------------------------*/ function safeUpdate(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { uint pid = dictionaries.startProcess("safeUpdate"); - return dictionaries .update(dictionary.assertNotEmpty()).finishProcess(pid); + Require.notEmpty(dictionary); + return dictionaries .update(dictionary).finishProcess(pid); } function update(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { uint pid = dictionaries.startProcess("update"); @@ -73,13 +77,13 @@ library DictionaryRegistryLib { --------------------------*/ function find(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { uint pid = dictionaries.startProcess("find"); - return dictionaries.deployed[name] - .assertExists() - .finishProcessInStorage(pid); + Require.exists(dictionaries.deployed[name]); + return dictionaries.deployed[name].finishProcessInStorage(pid); } function findCurrentDictionary(DictionaryRegistry storage dictionaries) internal returns(Dictionary storage) { uint pid = dictionaries.startProcess("findCurrentDictionary"); - return dictionaries.currentDictionary.assertExists().finishProcessInStorage(pid); + Require.exists(dictionaries.currentDictionary); + return dictionaries.currentDictionary.finishProcessInStorage(pid); } } diff --git a/devkit/method/core/FunctionRegistryLib.sol b/devkit/method/core/FunctionRegistryLib.sol index a890fbc1..113356f0 100644 --- a/devkit/method/core/FunctionRegistryLib.sol +++ b/devkit/method/core/FunctionRegistryLib.sol @@ -34,7 +34,7 @@ library FunctionRegistryLib { --------------------------------*/ function insert(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { uint pid = functions.startProcess("insert"); - Require.isNotEmpty(name); + Require.notEmpty(name); functions.customs[name].assign(name, selector, implementation).lock(); functions.safeUpdateCurrentFunction(name); // TODO return functions.finishProcess(pid); @@ -63,7 +63,8 @@ library FunctionRegistryLib { ---------------------------------*/ function find(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { uint pid = functions.startProcess("findFunction"); - return functions.customs[name].assertExists().finishProcess(pid); + Require.exists(functions.customs[name]); + return functions.customs[name].finishProcess(pid); } function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { uint pid = functions.startProcess("findCurrentFunction"); diff --git a/devkit/method/core/MockRegistryLib.sol b/devkit/method/core/MockRegistryLib.sol index cf39d441..adedd8e1 100644 --- a/devkit/method/core/MockRegistryLib.sol +++ b/devkit/method/core/MockRegistryLib.sol @@ -42,7 +42,7 @@ library MockRegistryLib { /*----- Mock Dictionary -----*/ function add(MockRegistry storage mock, string memory name, Dictionary memory dictionary) internal returns(MockRegistry storage) { uint pid = mock.startProcess("add"); - Require.isNotEmpty(name); + Require.notEmpty(name); validate(dictionary.isNotEmpty(), "Empty Dictionary"); mock.dictionary[name] = dictionary; return mock.finishProcess(pid); @@ -54,7 +54,7 @@ library MockRegistryLib { /*----- Mock Proxy -----*/ function add(MockRegistry storage mock, string memory name, Proxy memory proxy) internal returns(MockRegistry storage) { uint pid = mock.startProcess("add"); - Require.isNotEmpty(name); + Require.notEmpty(name); validate(proxy.isNotEmpty(), "Empty Proxy"); mock.proxy[name] = proxy; return mock.finishProcess(pid); @@ -70,15 +70,17 @@ library MockRegistryLib { /*----- Mock Dictionary -----*/ function findMockDictionary(MockRegistry storage mock, string memory name) internal returns(Dictionary storage) { uint pid = mock.startProcess("findMockDictionary"); - Require.isNotEmpty(name); - return mock.dictionary[name].assertExists().finishProcessInStorage(pid); + Require.notEmpty(name); + Require.exists(mock.dictionary[name]); + return mock.dictionary[name].finishProcessInStorage(pid); } /*----- Mock Proxy -----*/ function findMockProxy(MockRegistry storage mock, string memory name) internal returns(Proxy storage) { uint pid = mock.startProcess("findMockProxy"); - Require.isNotEmpty(name); - return mock.proxy[name].assertExists().finishProcessInStorage(pid); + Require.notEmpty(name); + Require.exists(mock.proxy[name]); + return mock.proxy[name].finishProcessInStorage(pid); } } diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol index 3ca68578..1055b9cd 100644 --- a/devkit/method/core/ProxyRegistryLib.sol +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; // Error & Debug import {ERR, throwError} from "devkit/error/Error.sol"; import {validate} from "devkit/error/Validate.sol"; +import {Require} from "devkit/error/Require.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Config import {Config, ScanRange} from "devkit/config/Config.sol"; @@ -38,7 +39,9 @@ library ProxyRegistryLib { function safeAdd(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { uint pid = proxies.startProcess("safeAdd"); - return proxies .add(name.assertNotEmpty(), proxy.assertNotEmpty()) + Require.notEmpty(name); + Require.notEmpty(proxy); + return proxies .add(name, proxy) .finishProcess(pid); } @@ -48,7 +51,8 @@ library ProxyRegistryLib { --------------------------------------*/ function safeUpdate(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { uint pid = proxies.startProcess("safeUpdate"); - return proxies.update(proxy.assertNotEmpty()).finishProcess(pid); + Require.notEmpty(proxy); + return proxies.update(proxy).finishProcess(pid); } function update(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { uint pid = proxies.startProcess("update"); @@ -72,12 +76,13 @@ library ProxyRegistryLib { ---------------------*/ function find(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { uint pid = proxies.startProcess("find"); - return proxies.deployed[name] - .assertExists().finishProcessInStorage(pid); + Require.exists(proxies.deployed[name]); + return proxies.deployed[name].finishProcessInStorage(pid); } function findCurrentProxy(ProxyRegistry storage proxies) internal returns(Proxy storage) { uint pid = proxies.startProcess("findCurrentProxy"); - return proxies.currentProxy.assertExists().finishProcessInStorage(pid); + Require.exists(proxies.currentProxy); + return proxies.currentProxy.finishProcessInStorage(pid); } } diff --git a/devkit/method/inspector/Inspector.sol b/devkit/method/inspector/Inspector.sol index 5e60d774..8849e3a3 100644 --- a/devkit/method/inspector/Inspector.sol +++ b/devkit/method/inspector/Inspector.sol @@ -25,9 +25,9 @@ import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; -/**------------------------------- - 🧐 Inspectors & Assertions ----------------------------------*/ +/**-------------------- + 🧐 Inspectors +----------------------*/ library Inspector { /**================== 🧩 Function @@ -47,47 +47,11 @@ library Inspector { return func.exists().isFalse(); } - function assertExists(Function storage func) internal returns(Function storage) { - validate(func.exists(), "func does not exists"); - return func; - } - - function assertEmptyName(Function storage func) internal returns(Function storage) { - Require.isUnassigned(func.name); - return func; - } - function assertEmptySelector(Function storage func) internal returns(Function storage) { - Require.isUnassigned(func.selector); - return func; - } - function assertEmptyImpl(Function storage func) internal returns(Function storage) { - validate(func.implementation.isNotContract(), "Implementation Already Exist"); - return func; - } - - function assertNotEmpty(Function storage func) internal returns(Function storage) { - validate(func.exists(), "Empty Deployed Contract"); - return func; - } - - function assertNotIncludedIn(Function storage func, Bundle storage bundleInfo) internal returns(Function storage) { - validate(bundleInfo.hasNot(func), "Already exists in the Bundel"); - return func; - } - - function assertImplIsContract(Function storage func) internal returns(Function storage) { - validate(func.implementation.isContract(), "Implementation Not Contract"); - return func; - } - function isComplete(Function storage func) internal returns(bool) { return func.name.isNotEmpty() && func.selector.isNotEmpty() && func.implementation.isContract(); - } - function assertComplete(Function storage func) internal returns(Function storage) { - validate(func.isComplete(), "Function Info Not Complete"); - return func; + // return func.buildStatus == BuildStatus.Built; } function isEqual(Function memory a, Function memory b) internal pure returns(bool) { @@ -112,10 +76,6 @@ library Inspector { bundle.functions.length != 0 && bundle.facade.isContract(); } - function assertComplete(Bundle storage bundle) internal returns(Bundle storage) { - validate(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); - return bundle; - } function hasName(Bundle storage bundle) internal returns(bool) { return bundle.name.isNotEmpty(); @@ -132,18 +92,10 @@ library Inspector { function notExists(Bundle storage bundle) internal returns(bool) { return bundle.exists().isNot(); } - function assertExists(Bundle storage bundle) internal returns(Bundle storage) { - validate(bundle.exists(), "Bundle Info Not Exists"); - return bundle; - } - function assertNotExists(Bundle storage bundle) internal returns(Bundle storage) { - validate(bundle.notExists(), "Bundle Info Already Exists"); - return bundle; - } /**======================= - đŸ—‚ī¸ Bundle Registry + 📙 Bundle Registry =========================*/ function existsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { return bundle.bundles[name].hasName(); @@ -151,10 +103,6 @@ library Inspector { function notExistsBundle(BundleRegistry storage bundle, string memory name) internal returns(bool) { return bundle.existsBundle(name).isNot(); } - function assertBundleNotExists(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - validate(bundle.notExistsBundle(name), "Bundle Already Exists"); - return bundle; - } function existsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { return bundle.currentBundleName.isNotEmpty(); @@ -170,10 +118,6 @@ library Inspector { function exists(Proxy storage proxy) internal returns(bool) { return proxy.addr.isContract(); } - function assertExists(Proxy storage proxy) internal returns(Proxy storage) { - validate(proxy.exists(), "Proxy Not Exist"); - return proxy; - } function notExists(Proxy storage proxy) internal returns(bool) { return proxy.exists().isFalse(); @@ -182,10 +126,6 @@ library Inspector { function isNotEmpty(Proxy memory proxy) internal returns(bool) { return proxy.addr.isContract(); } - function assertNotEmpty(Proxy memory proxy) internal returns(Proxy memory) { - validate(proxy.isNotEmpty(), "Empty Proxy"); - return proxy; - } function isMock(Proxy memory proxy) internal pure returns(bool) { return proxy.kind == ProxyKind.Mock; @@ -205,10 +145,6 @@ library Inspector { function isNotUndefined(ProxyKind kind) internal pure returns(bool) { return kind != ProxyKind.undefined; } - function assertNotUndefined(ProxyKind kind) internal returns(ProxyKind) { - validate(kind.isNotUndefined(), "Undefined Proxy Kind"); - return kind; - } /**======================= 🏠 Proxy Registry @@ -227,10 +163,6 @@ library Inspector { function exists(Dictionary storage dictionary) internal returns(bool) { return dictionary.addr.isContract(); } - function assertExists(Dictionary storage dictionary) internal returns(Dictionary storage) { - validate(dictionary.exists(), "Dictionary Not Exists"); - return dictionary; - } function notExists(Dictionary storage dictionary) internal returns(bool) { return dictionary.exists().isFalse(); @@ -239,27 +171,15 @@ library Inspector { function isNotEmpty(Dictionary memory dictionary) internal returns(bool) { return dictionary.addr.isContract(); } - function assertNotEmpty(Dictionary memory dictionary) internal returns(Dictionary memory) { - validate(dictionary.isNotEmpty(), "Empty Dictionary"); - return dictionary; - } function isSupported(Dictionary memory dictionary, bytes4 selector) internal view returns(bool) { return IDictionary(dictionary.addr).supportsInterface(selector); } - function assertSupports(Dictionary storage dictionary, bytes4 selector) internal returns(Dictionary storage) { - validate(dictionary.isSupported(selector), "Unsupported Selector"); - return dictionary; - } function isVerifiable(Dictionary memory dictionary) internal returns(bool) { (bool success,) = dictionary.addr.call(abi.encodeWithSelector(IBeacon.implementation.selector)); return success; } - function assertVerifiable(Dictionary memory dictionary) internal returns(Dictionary memory) { - validate(dictionary.isVerifiable(), "Dictionary Not Verifiable"); - return dictionary; - } function isMock(Dictionary memory dictionary) internal pure returns(bool) { return dictionary.kind == DictionaryKind.Mock; @@ -277,10 +197,6 @@ library Inspector { function isNotUndefined(DictionaryKind kind) internal pure returns(bool) { return kind != DictionaryKind.undefined; } - function assertNotUndefined(DictionaryKind kind) internal returns(DictionaryKind) { - validate(kind.isNotUndefined(), "Undefined Dictionary Kind"); - return kind; - } /**============================ 📚 Dictionary Registry From 2a7ef87e7bb5453dddc7d6ea2c5afa2bc5c7e40f Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 10:08:10 +0900 Subject: [PATCH 058/111] Arrange directory structure --- devkit/MCDevKit.sol | 26 +-- devkit/core/DictionaryRegistry.sol | 23 --- devkit/core/FunctionRegistry.sol | 21 --- devkit/core/MockRegistry.sol | 24 --- devkit/core/ProxyRegistry.sol | 23 --- devkit/core/StdFunctions.sol | 24 --- devkit/{ => core}/method/debug/Dumper.sol | 4 +- devkit/{ => core}/method/debug/Parser.sol | 4 +- devkit/{ => core}/method/debug/ProcessLib.sol | 20 +-- .../method/global}/MCBundleLib.sol | 6 +- .../method/global}/MCContextLib.sol | 0 .../method/global}/MCDebugLib.sol | 0 .../method/global}/MCDeployLib.sol | 10 +- .../method/global}/MCFinderLib.sol | 8 +- .../method/global}/MCSetupLib.sol | 0 .../method/global}/MCTestLib.sol | 8 +- .../{ => core}/method/inspector/Inspector.sol | 14 +- .../method/inspector/MappingAnalyzer.sol | 8 +- devkit/{ => core}/method/test/TestLib.sol | 2 +- devkit/core/{ => registry}/BundleRegistry.sol | 10 +- devkit/core/registry/DictionaryRegistry.sol | 89 +++++++++++ devkit/core/registry/FunctionRegistry.sol | 77 +++++++++ devkit/core/registry/MockRegistry.sol | 83 ++++++++++ devkit/core/registry/ProxyRegistry.sol | 86 ++++++++++ devkit/core/registry/StdFunctions.sol | 150 ++++++++++++++++++ devkit/core/{ => types}/Bundle.sol | 8 +- devkit/core/{ => types}/Dictionary.sol | 13 +- devkit/core/{ => types}/Function.sol | 8 +- devkit/core/{ => types}/Proxy.sol | 10 +- devkit/error/Require.sol | 14 +- devkit/method/core/DictionaryRegistryLib.sol | 70 +------- devkit/method/core/FunctionRegistryLib.sol | 63 +------- devkit/method/core/MockRegistryLib.sol | 67 +------- devkit/method/core/ProxyRegistryLib.sol | 72 +-------- devkit/method/core/StdFunctionsLib.sol | 124 +-------------- .../{test => utils/mocks}/MockDictionary.sol | 2 +- .../{test => utils/mocks}/SimpleMockProxy.sol | 2 +- script/DeployLib.sol | 2 +- test/devkit/MCDevKit.t.sol | 2 +- test/devkit/global/MCBundle.t.sol | 4 +- test/devkit/global/MCSetup.t.sol | 2 +- test/utils/TestHelper.sol | 2 +- 42 files changed, 596 insertions(+), 589 deletions(-) delete mode 100644 devkit/core/DictionaryRegistry.sol delete mode 100644 devkit/core/FunctionRegistry.sol delete mode 100644 devkit/core/MockRegistry.sol delete mode 100644 devkit/core/ProxyRegistry.sol delete mode 100644 devkit/core/StdFunctions.sol rename devkit/{ => core}/method/debug/Dumper.sol (84%) rename devkit/{ => core}/method/debug/Parser.sol (90%) rename devkit/{ => core}/method/debug/ProcessLib.sol (90%) rename devkit/{method => core/method/global}/MCBundleLib.sol (95%) rename devkit/{method => core/method/global}/MCContextLib.sol (100%) rename devkit/{method => core/method/global}/MCDebugLib.sol (100%) rename devkit/{method => core/method/global}/MCDeployLib.sol (96%) rename devkit/{method => core/method/global}/MCFinderLib.sol (92%) rename devkit/{method => core/method/global}/MCSetupLib.sol (100%) rename devkit/{method => core/method/global}/MCTestLib.sol (95%) rename devkit/{ => core}/method/inspector/Inspector.sol (93%) rename devkit/{ => core}/method/inspector/MappingAnalyzer.sol (95%) rename devkit/{ => core}/method/test/TestLib.sol (93%) rename devkit/core/{ => registry}/BundleRegistry.sol (94%) create mode 100644 devkit/core/registry/DictionaryRegistry.sol create mode 100644 devkit/core/registry/FunctionRegistry.sol create mode 100644 devkit/core/registry/MockRegistry.sol create mode 100644 devkit/core/registry/ProxyRegistry.sol create mode 100644 devkit/core/registry/StdFunctions.sol rename devkit/core/{ => types}/Bundle.sol (90%) rename devkit/core/{ => types}/Dictionary.sol (93%) rename devkit/core/{ => types}/Function.sol (94%) rename devkit/core/{ => types}/Proxy.sol (84%) rename devkit/{test => utils/mocks}/MockDictionary.sol (89%) rename devkit/{test => utils/mocks}/SimpleMockProxy.sol (96%) diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index 31f39ffd..35c8fe49 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -2,21 +2,21 @@ pragma solidity ^0.8.24; // Core Registries -import {StdFunctions} from "devkit/core/StdFunctions.sol"; -import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; -import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; -import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; -import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; -import {MockRegistry} from "devkit/core/MockRegistry.sol"; +import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; +import {FunctionRegistry} from "devkit/core/registry/FunctionRegistry.sol"; +import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; +import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; +import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; +import {MockRegistry} from "devkit/core/registry/MockRegistry.sol"; // Global Methods -import {MCSetupLib} from "devkit/method/MCSetupLib.sol"; -import {MCBundleLib} from "devkit/method/MCBundleLib.sol"; -import {MCDeployLib} from "devkit/method/MCDeployLib.sol"; -import {MCFinderLib} from "devkit/method/MCFinderLib.sol"; -import {MCContextLib} from "devkit/method/MCContextLib.sol"; -import {MCTestLib} from "devkit/method/MCTestLib.sol"; -import {MCDebugLib} from "devkit/method/MCDebugLib.sol"; +import {MCSetupLib} from "devkit/core/method/global/MCSetupLib.sol"; +import {MCBundleLib} from "devkit/core/method/global/MCBundleLib.sol"; +import {MCDeployLib} from "devkit/core/method/global/MCDeployLib.sol"; +import {MCFinderLib} from "devkit/core/method/global/MCFinderLib.sol"; +import {MCContextLib} from "devkit/core/method/global/MCContextLib.sol"; +import {MCTestLib} from "devkit/core/method/global/MCTestLib.sol"; +import {MCDebugLib} from "devkit/core/method/global/MCDebugLib.sol"; /******************************** diff --git a/devkit/core/DictionaryRegistry.sol b/devkit/core/DictionaryRegistry.sol deleted file mode 100644 index f34e9893..00000000 --- a/devkit/core/DictionaryRegistry.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Core Type -import {Dictionary} from "./Dictionary.sol"; -// Core Method -import {DictionaryRegistryLib} from "devkit/method/core/DictionaryRegistryLib.sol"; -// Support Methods -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -import {Inspector} from "devkit/method/inspector/Inspector.sol"; - - -/**============================ - 📘 Dictionary Registry -==============================*/ -struct DictionaryRegistry { - mapping(string name => Dictionary) deployed; - Dictionary currentDictionary; -} -using DictionaryRegistryLib for DictionaryRegistry global; -// Support Methods -using ProcessLib for DictionaryRegistry global; -using Inspector for DictionaryRegistry global; diff --git a/devkit/core/FunctionRegistry.sol b/devkit/core/FunctionRegistry.sol deleted file mode 100644 index 168b1b04..00000000 --- a/devkit/core/FunctionRegistry.sol +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Core Type -import {Function} from "devkit/core/Function.sol"; -// Core Method -import {FunctionRegistryLib} from "devkit/method/core/FunctionRegistryLib.sol"; -// Support Method -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; - - -/**=========================== - 📗 Functions Registry -=============================*/ -struct FunctionRegistry { - mapping(string name => Function) customs; - string currentName; -} -using FunctionRegistryLib for FunctionRegistry global; -// Support Methods -using ProcessLib for FunctionRegistry global; diff --git a/devkit/core/MockRegistry.sol b/devkit/core/MockRegistry.sol deleted file mode 100644 index 9977c9f5..00000000 --- a/devkit/core/MockRegistry.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Core Types -import {Proxy} from "devkit/core/Proxy.sol"; -import {Dictionary} from "devkit/core/Dictionary.sol"; -// Core Method -import {MockRegistryLib} from "devkit/method/core/MockRegistryLib.sol"; -// Support Methods -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -import {Inspector} from "devkit/method/inspector/Inspector.sol"; - - -/**====================== - 🏭 Mock Registry -========================*/ -struct MockRegistry { - mapping(string name => Proxy) proxy; - mapping(string name => Dictionary) dictionary; -} -using MockRegistryLib for MockRegistry global; -// Support Methods -using ProcessLib for MockRegistry global; -using Inspector for MockRegistry global; diff --git a/devkit/core/ProxyRegistry.sol b/devkit/core/ProxyRegistry.sol deleted file mode 100644 index 6e549f4b..00000000 --- a/devkit/core/ProxyRegistry.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Core Type -import {Proxy} from "devkit/core/Proxy.sol"; -// Core Method -import {ProxyRegistryLib} from "devkit/method/core/ProxyRegistryLib.sol"; -// Support Methods -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; -import {Inspector} from "devkit/method/inspector/Inspector.sol"; - - -/**======================= - 📕 Proxy Registry -=========================*/ -struct ProxyRegistry { - mapping(string name => Proxy) deployed; - Proxy currentProxy; -} -using ProxyRegistryLib for ProxyRegistry global; -// Support Methods -using ProcessLib for ProxyRegistry global; -using Inspector for ProxyRegistry global; diff --git a/devkit/core/StdFunctions.sol b/devkit/core/StdFunctions.sol deleted file mode 100644 index a71a0694..00000000 --- a/devkit/core/StdFunctions.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Core Types -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -// Core Methods -import {StdFunctionsLib} from "devkit/method/core/StdFunctionsLib.sol"; -// Support Method -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; - - -/**========================== - 🏛 Standard Functions -============================*/ -struct StdFunctions { - Function initSetAdmin; - Function getDeps; - Function clone; - Bundle all; -} -using StdFunctionsLib for StdFunctions global; -// Support Methods -using ProcessLib for StdFunctions global; diff --git a/devkit/method/debug/Dumper.sol b/devkit/core/method/debug/Dumper.sol similarity index 84% rename from devkit/method/debug/Dumper.sol rename to devkit/core/method/debug/Dumper.sol index de19af8f..19eca68f 100644 --- a/devkit/method/debug/Dumper.sol +++ b/devkit/core/method/debug/Dumper.sol @@ -3,8 +3,8 @@ pragma solidity ^0.8.24; import {Logger} from "devkit/debug/Logger.sol"; // Core Types -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; //================ diff --git a/devkit/method/debug/Parser.sol b/devkit/core/method/debug/Parser.sol similarity index 90% rename from devkit/method/debug/Parser.sol rename to devkit/core/method/debug/Parser.sol index 38d94458..708c000a 100644 --- a/devkit/method/debug/Parser.sol +++ b/devkit/core/method/debug/Parser.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.24; // Core Types -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; // Utils import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; diff --git a/devkit/method/debug/ProcessLib.sol b/devkit/core/method/debug/ProcessLib.sol similarity index 90% rename from devkit/method/debug/ProcessLib.sol rename to devkit/core/method/debug/ProcessLib.sol index 33b59b02..a0d0fec2 100644 --- a/devkit/method/debug/ProcessLib.sol +++ b/devkit/core/method/debug/ProcessLib.sol @@ -3,16 +3,16 @@ pragma solidity ^0.8.24; import {Debug} from "devkit/debug/Debug.sol"; // Core Types -import {Function} from "devkit/core/Function.sol"; -import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; -import {StdFunctions} from "devkit/core/StdFunctions.sol"; -import {Proxy} from "devkit/core/Proxy.sol"; -import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; -import {Dictionary} from "devkit/core/Dictionary.sol"; -import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; -import {MockRegistry} from "devkit/core/MockRegistry.sol"; +import {Function} from "devkit/core/types/Function.sol"; +import {FunctionRegistry} from "devkit/core/registry/FunctionRegistry.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; +import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; +import {Proxy} from "devkit/core/types/Proxy.sol"; +import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; +import {Dictionary} from "devkit/core/types/Dictionary.sol"; +import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; +import {MockRegistry} from "devkit/core/registry/MockRegistry.sol"; library ProcessLib { diff --git a/devkit/method/MCBundleLib.sol b/devkit/core/method/global/MCBundleLib.sol similarity index 95% rename from devkit/method/MCBundleLib.sol rename to devkit/core/method/global/MCBundleLib.sol index 6a10901e..b59538f5 100644 --- a/devkit/method/MCBundleLib.sol +++ b/devkit/core/method/global/MCBundleLib.sol @@ -9,10 +9,10 @@ import {ERR} from "devkit/error/Error.sol"; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {Params} from "devkit/debug/Params.sol"; // Core -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; -import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; +import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Bundle); /*********************************************** diff --git a/devkit/method/MCContextLib.sol b/devkit/core/method/global/MCContextLib.sol similarity index 100% rename from devkit/method/MCContextLib.sol rename to devkit/core/method/global/MCContextLib.sol diff --git a/devkit/method/MCDebugLib.sol b/devkit/core/method/global/MCDebugLib.sol similarity index 100% rename from devkit/method/MCDebugLib.sol rename to devkit/core/method/global/MCDebugLib.sol diff --git a/devkit/method/MCDeployLib.sol b/devkit/core/method/global/MCDeployLib.sol similarity index 96% rename from devkit/method/MCDeployLib.sol rename to devkit/core/method/global/MCDeployLib.sol index 5235caef..39f9f74e 100644 --- a/devkit/method/MCDeployLib.sol +++ b/devkit/core/method/global/MCDeployLib.sol @@ -9,15 +9,15 @@ import {validate} from "devkit/error/Validate.sol"; import {Params} from "devkit/debug/Params.sol"; // Core // dictionary -import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; +import {Dictionary, DictionaryLib} from "devkit/core/types/Dictionary.sol"; // functions -import {Bundle} from "devkit/core/Bundle.sol"; -import {StdFunctionsArgs} from "devkit/method/core/StdFunctionsLib.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +import {StdFunctionsArgs} from "devkit/core/registry/StdFunctions.sol"; using StdFunctionsArgs for address; // proxy -import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; +import {Proxy, ProxyLib} from "devkit/core/types/Proxy.sol"; -import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; +import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Dictionary); using MappingAnalyzer for mapping(string => Proxy); diff --git a/devkit/method/MCFinderLib.sol b/devkit/core/method/global/MCFinderLib.sol similarity index 92% rename from devkit/method/MCFinderLib.sol rename to devkit/core/method/global/MCFinderLib.sol index 50c924ed..9b90e9e6 100644 --- a/devkit/method/MCFinderLib.sol +++ b/devkit/core/method/global/MCFinderLib.sol @@ -4,12 +4,12 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Core // functions -import {Bundle} from "devkit/core/Bundle.sol"; -import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +import {Function} from "devkit/core/types/Function.sol"; // proxy -import {Proxy} from "devkit/core/Proxy.sol"; +import {Proxy} from "devkit/core/types/Proxy.sol"; // dictionary -import {Dictionary} from "devkit/core/Dictionary.sol"; +import {Dictionary} from "devkit/core/types/Dictionary.sol"; /********************************** diff --git a/devkit/method/MCSetupLib.sol b/devkit/core/method/global/MCSetupLib.sol similarity index 100% rename from devkit/method/MCSetupLib.sol rename to devkit/core/method/global/MCSetupLib.sol diff --git a/devkit/method/MCTestLib.sol b/devkit/core/method/global/MCTestLib.sol similarity index 95% rename from devkit/method/MCTestLib.sol rename to devkit/core/method/global/MCTestLib.sol index 51d2f109..2074e38c 100644 --- a/devkit/method/MCTestLib.sol +++ b/devkit/core/method/global/MCTestLib.sol @@ -7,12 +7,12 @@ import {Config} from "devkit/config/Config.sol"; import {Params} from "devkit/debug/Params.sol"; // Core // functions -import {Bundle} from "devkit/core/Bundle.sol"; -import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +import {Function} from "devkit/core/types/Function.sol"; // proxy -import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; +import {Proxy, ProxyLib} from "devkit/core/types/Proxy.sol"; // dictionary -import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; +import {Dictionary, DictionaryLib} from "devkit/core/types/Dictionary.sol"; /****************************************** diff --git a/devkit/method/inspector/Inspector.sol b/devkit/core/method/inspector/Inspector.sol similarity index 93% rename from devkit/method/inspector/Inspector.sol rename to devkit/core/method/inspector/Inspector.sol index 8849e3a3..89596453 100644 --- a/devkit/method/inspector/Inspector.sol +++ b/devkit/core/method/inspector/Inspector.sol @@ -16,13 +16,13 @@ import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {IBeacon} from "@oz.mc/proxy/beacon/IBeacon.sol"; import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; // Core Types -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; -import {Proxy, ProxyKind} from "devkit/core/Proxy.sol"; -import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; -import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; -import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; +import {Proxy, ProxyKind} from "devkit/core/types/Proxy.sol"; +import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; +import {Dictionary, DictionaryKind} from "devkit/core/types/Dictionary.sol"; +import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; /**-------------------- diff --git a/devkit/method/inspector/MappingAnalyzer.sol b/devkit/core/method/inspector/MappingAnalyzer.sol similarity index 95% rename from devkit/method/inspector/MappingAnalyzer.sol rename to devkit/core/method/inspector/MappingAnalyzer.sol index 242a5cbb..42c4e862 100644 --- a/devkit/method/inspector/MappingAnalyzer.sol +++ b/devkit/core/method/inspector/MappingAnalyzer.sol @@ -4,10 +4,10 @@ pragma solidity ^0.8.24; import {throwError, ERR} from "devkit/error/Error.sol"; import {Config, ScanRange} from "devkit/config/Config.sol"; // Core Types -import {Bundle} from "devkit/core/Bundle.sol"; -import {Function} from "devkit/core/Function.sol"; -import {Dictionary} from "devkit/core/Dictionary.sol"; -import {Proxy} from "devkit/core/Proxy.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +import {Function} from "devkit/core/types/Function.sol"; +import {Dictionary} from "devkit/core/types/Dictionary.sol"; +import {Proxy} from "devkit/core/types/Proxy.sol"; // Utils import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; diff --git a/devkit/method/test/TestLib.sol b/devkit/core/method/test/TestLib.sol similarity index 93% rename from devkit/method/test/TestLib.sol rename to devkit/core/method/test/TestLib.sol index 95436043..f4e927e0 100644 --- a/devkit/method/test/TestLib.sol +++ b/devkit/core/method/test/TestLib.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; ----------------------------*/ // Core Type -import {Proxy} from "devkit/core/Proxy.sol"; +import {Proxy} from "devkit/core/types/Proxy.sol"; /**=============== diff --git a/devkit/core/BundleRegistry.sol b/devkit/core/registry/BundleRegistry.sol similarity index 94% rename from devkit/core/BundleRegistry.sol rename to devkit/core/registry/BundleRegistry.sol index 88a81770..e849132d 100644 --- a/devkit/core/BundleRegistry.sol +++ b/devkit/core/registry/BundleRegistry.sol @@ -3,19 +3,19 @@ pragma solidity ^0.8.24; /**-------------------------- Apply Support Methods ----------------------------*/ -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for BundleRegistry global; -import {Inspector} from "devkit/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for BundleRegistry global; -import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; +import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Bundle); // Validation import {validate} from "devkit/error/Validate.sol"; import {Require} from "devkit/error/Require.sol"; // Core Type -import {Bundle} from "devkit/core/Bundle.sol"; -import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +import {Function} from "devkit/core/types/Function.sol"; /**======================== diff --git a/devkit/core/registry/DictionaryRegistry.sol b/devkit/core/registry/DictionaryRegistry.sol new file mode 100644 index 00000000..5d799372 --- /dev/null +++ b/devkit/core/registry/DictionaryRegistry.sol @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; +/**-------------------------- + Apply Support Methods +----------------------------*/ +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; + using ProcessLib for DictionaryRegistry global; +import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; + using Inspector for DictionaryRegistry global; + +// Core Type +import {Dictionary} from "devkit/core/types/Dictionary.sol"; +import {Require} from "devkit/error/Require.sol"; + + +/**============================ + 📘 Dictionary Registry +==============================*/ +using DictionaryRegistryLib for DictionaryRegistry global; +struct DictionaryRegistry { + mapping(string name => Dictionary) deployed; + Dictionary currentDictionary; +} +library DictionaryRegistryLib { + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + đŸ“Ĩ Add Dictionary + đŸ”ŧ Update Current Context Dictionary + â™ģī¸ Reset Current Context Dictionary + 🔍 Find Dictionary + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + + /**------------------------ + đŸ“Ĩ Add Dictionary + --------------------------*/ + function add(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { + uint pid = dictionaries.startProcess("add"); + dictionaries.deployed[name] = dictionary; + return dictionaries.finishProcess(pid); + } + + function safeAdd(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { + uint pid = dictionaries.startProcess("safeAdd"); + Require.notEmpty(name); + Require.notEmpty(dictionary); + return dictionaries .add(name, dictionary) + .finishProcess(pid); + } + + + /**----------------------------------------- + đŸ”ŧ Update Current Context Dictionary + -------------------------------------------*/ + function safeUpdate(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { + uint pid = dictionaries.startProcess("safeUpdate"); + Require.notEmpty(dictionary); + return dictionaries .update(dictionary).finishProcess(pid); + } + function update(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { + uint pid = dictionaries.startProcess("update"); + dictionaries.currentDictionary = dictionary; + return dictionaries.finishProcess(pid); + } + + + /**---------------------------------------- + â™ģī¸ Reset Current Context Dictionary + ------------------------------------------*/ + function reset(DictionaryRegistry storage dictionaries) internal returns(DictionaryRegistry storage) { + uint pid = dictionaries.startProcess("reset"); + delete dictionaries.currentDictionary; + return dictionaries.finishProcess(pid); + } + + + /**------------------------ + 🔍 Find Dictionary + --------------------------*/ + function find(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { + uint pid = dictionaries.startProcess("find"); + Require.exists(dictionaries.deployed[name]); + return dictionaries.deployed[name].finishProcessInStorage(pid); + } + function findCurrentDictionary(DictionaryRegistry storage dictionaries) internal returns(Dictionary storage) { + uint pid = dictionaries.startProcess("findCurrentDictionary"); + Require.exists(dictionaries.currentDictionary); + return dictionaries.currentDictionary.finishProcessInStorage(pid); + } + +} diff --git a/devkit/core/registry/FunctionRegistry.sol b/devkit/core/registry/FunctionRegistry.sol new file mode 100644 index 00000000..61074708 --- /dev/null +++ b/devkit/core/registry/FunctionRegistry.sol @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Core Type +import {Function} from "devkit/core/types/Function.sol"; +// Support Method +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +using ProcessLib for FunctionRegistry global; +import {Require} from "devkit/error/Require.sol"; + + +/**=========================== + 📗 Functions Registry +=============================*/ +using FunctionRegistryLib for FunctionRegistry global; +struct FunctionRegistry { + mapping(string name => Function) customs; + string currentName; +} +library FunctionRegistryLib { + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + đŸ—ŗī¸ Insert Custom Function + đŸ”ŧ Update Current Context Function + â™ģī¸ Reset Current Context Function & Bundle + 🔍 Find Function + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + + /**------------------------------ + đŸ—ŗī¸ Insert Custom Function + --------------------------------*/ + function insert(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + uint pid = functions.startProcess("insert"); + Require.notEmpty(name); + functions.customs[name].assign(name, selector, implementation).lock(); + functions.safeUpdateCurrentFunction(name); // TODO + return functions.finishProcess(pid); + } + + /**------------------------------------------------ + đŸ”ŧ Update Current Context Function + --------------------------------------------------*/ + function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { + uint pid = functions.startProcess("safeUpdateCurrentFunction"); + Require.notEmpty(name); + functions.currentName = name; + return functions.finishProcess(pid); + } + + /**----------------------------------------------- + â™ģī¸ Reset Current Context Function & Bundle + -------------------------------------------------*/ + function reset(FunctionRegistry storage functions) internal returns(FunctionRegistry storage) { + uint pid = functions.startProcess("reset"); + delete functions.currentName; + return functions.finishProcess(pid); + } + + /**------------------------------- + 🔍 Find Function + ---------------------------------*/ + function find(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { + uint pid = functions.startProcess("findFunction"); + Require.exists(functions.customs[name]); + return functions.customs[name].finishProcess(pid); + } + function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { + uint pid = functions.startProcess("findCurrentFunction"); + return functions.find(functions.findCurrentName()).finishProcess(pid); + } + function findCurrentName(FunctionRegistry storage functions) internal returns(string memory) { + uint pid = functions.startProcess("findCurrentName"); + Require.notEmpty(functions.currentName); + return functions.currentName; + // return functions.currentName.recordExecFinish(pid); + } + +} diff --git a/devkit/core/registry/MockRegistry.sol b/devkit/core/registry/MockRegistry.sol new file mode 100644 index 00000000..06c3efdf --- /dev/null +++ b/devkit/core/registry/MockRegistry.sol @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Core Types +import {Proxy} from "devkit/core/types/Proxy.sol"; +import {Dictionary} from "devkit/core/types/Dictionary.sol"; +// Support Methods +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; + using ProcessLib for MockRegistry global; +import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; + using Inspector for MockRegistry global; +import {Require} from "devkit/error/Require.sol"; +import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; + using MappingAnalyzer for mapping(string => Dictionary); + using MappingAnalyzer for mapping(string => Proxy); + + +/**====================== + 🏭 Mock Registry +========================*/ +using MockRegistryLib for MockRegistry global; +struct MockRegistry { + mapping(string name => Proxy) proxy; + mapping(string name => Dictionary) dictionary; +} +library MockRegistryLib { + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + đŸ“Ĩ Add + Mock Dictionary + Mock Proxy + 🔍 Find + Mock Dictionary + Mock Proxy + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + + /**------------- + đŸ“Ĩ Add + ---------------*/ + /*----- Mock Dictionary -----*/ + function add(MockRegistry storage mock, string memory name, Dictionary memory dictionary) internal returns(MockRegistry storage) { + uint pid = mock.startProcess("add"); + Require.notEmpty(name); + Require.notEmpty(dictionary); + mock.dictionary[name] = dictionary; + return mock.finishProcess(pid); + } + function add(MockRegistry storage mock, Dictionary memory dictionary) internal returns(MockRegistry storage) { + return add(mock, mock.dictionary.genUniqueMockName(), dictionary); + } + + /*----- Mock Proxy -----*/ + function add(MockRegistry storage mock, string memory name, Proxy memory proxy) internal returns(MockRegistry storage) { + uint pid = mock.startProcess("add"); + Require.notEmpty(name); + Require.notEmpty(proxy); + mock.proxy[name] = proxy; + return mock.finishProcess(pid); + } + function add(MockRegistry storage mock, Proxy memory proxy) internal returns(MockRegistry storage) { + return add(mock, mock.proxy.genUniqueMockName(), proxy); + } + + + /**-------------- + 🔍 Find + ----------------*/ + /*----- Mock Dictionary -----*/ + function findMockDictionary(MockRegistry storage mock, string memory name) internal returns(Dictionary storage) { + uint pid = mock.startProcess("findMockDictionary"); + Require.notEmpty(name); + Require.exists(mock.dictionary[name]); + return mock.dictionary[name].finishProcessInStorage(pid); + } + + /*----- Mock Proxy -----*/ + function findMockProxy(MockRegistry storage mock, string memory name) internal returns(Proxy storage) { + uint pid = mock.startProcess("findMockProxy"); + Require.notEmpty(name); + Require.exists(mock.proxy[name]); + return mock.proxy[name].finishProcessInStorage(pid); + } + +} diff --git a/devkit/core/registry/ProxyRegistry.sol b/devkit/core/registry/ProxyRegistry.sol new file mode 100644 index 00000000..cae75cec --- /dev/null +++ b/devkit/core/registry/ProxyRegistry.sol @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Core Type +import {Proxy} from "devkit/core/types/Proxy.sol"; +// Support Methods +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; + using ProcessLib for ProxyRegistry global; +import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; + using Inspector for ProxyRegistry global; +import {Require} from "devkit/error/Require.sol"; + + +/**======================= + 📕 Proxy Registry +=========================*/ +using ProxyRegistryLib for ProxyRegistry global; +struct ProxyRegistry { + mapping(string name => Proxy) deployed; + Proxy currentProxy; +} +library ProxyRegistryLib { + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + đŸ“Ĩ Add Proxy + đŸ”ŧ Update Current Context Proxy + â™ģī¸ Reset Current Context Proxy + 🔍 Find Proxy + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + /**------------------- + đŸ“Ĩ Add Proxy + ---------------------*/ + function add(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { + uint pid = proxies.startProcess("add"); + proxies.deployed[name] = proxy; + return proxies.finishProcess(pid); + } + + function safeAdd(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { + uint pid = proxies.startProcess("safeAdd"); + Require.notEmpty(name); + Require.notEmpty(proxy); + return proxies .add(name, proxy) + .finishProcess(pid); + } + + + /**------------------------------------ + đŸ”ŧ Update Current Context Proxy + --------------------------------------*/ + function safeUpdate(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { + uint pid = proxies.startProcess("safeUpdate"); + Require.notEmpty(proxy); + return proxies.update(proxy).finishProcess(pid); + } + function update(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { + uint pid = proxies.startProcess("update"); + proxies.currentProxy = proxy; + return proxies.finishProcess(pid); + } + + + /**---------------------------------- + â™ģī¸ Reset Current Context Proxy + ------------------------------------*/ + function reset(ProxyRegistry storage proxies) internal returns(ProxyRegistry storage) { + uint pid = proxies.startProcess("reset"); + delete proxies.currentProxy; + return proxies.finishProcess(pid); + } + + + /**------------------- + 🔍 Find Proxy + ---------------------*/ + function find(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { + uint pid = proxies.startProcess("find"); + Require.exists(proxies.deployed[name]); + return proxies.deployed[name].finishProcessInStorage(pid); + } + function findCurrentProxy(ProxyRegistry storage proxies) internal returns(Proxy storage) { + uint pid = proxies.startProcess("findCurrentProxy"); + Require.exists(proxies.currentProxy); + return proxies.currentProxy.finishProcessInStorage(pid); + } + +} diff --git a/devkit/core/registry/StdFunctions.sol b/devkit/core/registry/StdFunctions.sol new file mode 100644 index 00000000..1117b50f --- /dev/null +++ b/devkit/core/registry/StdFunctions.sol @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Core Types +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +// Support Method +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; + using ProcessLib for StdFunctions global; +// MC Std +import {Clone} from "mc-std/functions/Clone.sol"; +import {GetDeps} from "mc-std/functions/GetDeps.sol"; +import {FeatureToggle} from "mc-std/functions/protected/FeatureToggle.sol"; +import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; +import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.sol"; +import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; +// Loader +import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; +// Utils +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; + using AddressUtils for address; + + +/**========================== + 🏛 Standard Functions +============================*/ +using StdFunctionsLib for StdFunctions global; +struct StdFunctions { + Function initSetAdmin; + Function getDeps; + Function clone; + Bundle all; +} +library StdFunctionsLib { + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 🔏 Assign and Load Standard Functions + đŸŖ Deploy Standard Functions If Not Exists + đŸ§ē Configure Standard Bundles + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + + /**------------------------------------------ + 🔏 Assign and Load Standard Functions + --------------------------------------------*/ + function assignAndLoad(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("assignAndLoad"); + return std .assignAndLoad_InitSetAdmin() + .assignAndLoad_GetDeps() + .assignAndLoad_Clone() + .finishProcess(pid); + } + + /**===== Each Std Function =====*/ + function assignAndLoad_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("assignAndLoad_InitSetAdmin"); + string memory name = "InitSetAdmin"; + bytes4 selector = InitSetAdmin.initSetAdmin.selector; + address implementation = loadAddressFrom(name); // TODO + std.initSetAdmin.assign(name, selector, implementation) + // .lock() + .dump(); + return std.finishProcess(pid); + } + + function assignAndLoad_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("assignAndLoad_GetDeps"); + string memory name = "GetDeps"; + bytes4 selector = GetDeps.getDeps.selector; + address implementation = loadAddressFrom(name); + std.getDeps .assign(name, selector, implementation) + // .lock() + .dump(); + return std.finishProcess(pid); + } + + function assignAndLoad_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("assignAndLoad_Clone"); + string memory name = "Clone"; + bytes4 selector = Clone.clone.selector; + address implementation = loadAddressFrom(name); + std.clone .assign(name, selector, implementation) + // .lock() + .dump(); + return std.finishProcess(pid); + } + + + /**----------------------------------------------- + đŸŖ Deploy Standard Functions If Not Exists + TODO versioning + -------------------------------------------------*/ + function deployIfNotExists(StdFunctions storage std) internal returns(StdFunctions storage) { + return std .deployIfNotExists_InitSetAdmin() + .deployIfNotExists_GetDeps() + .deployIfNotExists_Clone(); + } + /**===== Each Std Function =====*/ + function deployIfNotExists_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { + if (std.initSetAdmin.implementation.isNotContract()) { + std.initSetAdmin.assignImplementation(address(new InitSetAdmin())); + } + return std; + } + + function deployIfNotExists_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { + if (!std.getDeps.implementation.isContract()) { + std.getDeps.assignImplementation(address(new GetDeps())); + } + return std; + } + + function deployIfNotExists_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { + if (!std.clone.implementation.isContract()) { + std.clone.assignImplementation(address(new Clone())); + } + return std; + } + + + /**---------------------------------- + đŸ§ē Configure Standard Bundles + ------------------------------------*/ + function configureStdBundle(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("configureStdBundle"); + return std .configureStdBundle_AllFunctions() + .finishProcess(pid); + } + + /**===== Each Std Bundle =====*/ + function configureStdBundle_AllFunctions(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("configureStdBundle_AllFunctions"); + std.all .assignName("ALL_FUNCTIONS") + .pushFunction(std.initSetAdmin) + .pushFunction(std.getDeps) + .pushFunction(std.clone) + .assignFacade(address(new StdFacade())); + return std.finishProcess(pid); + } + +} + + +/**************************************************** + 🧩 Std Ops Primitive Utils for Arguments +*****************************************************/ +library StdFunctionsArgs { + function initSetAdminBytes(address admin) internal view returns(bytes memory) { + return abi.encodeCall(InitSetAdmin.initSetAdmin, admin); + } + +} diff --git a/devkit/core/Bundle.sol b/devkit/core/types/Bundle.sol similarity index 90% rename from devkit/core/Bundle.sol rename to devkit/core/types/Bundle.sol index 34433cf6..173982e6 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/types/Bundle.sol @@ -3,16 +3,16 @@ pragma solidity ^0.8.24; /**-------------------------- Apply Support Methods ----------------------------*/ -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for Bundle global; -import {Parser} from "devkit/method/debug/Parser.sol"; +import {Parser} from "devkit/core/method/debug/Parser.sol"; using Parser for Bundle global; -import {Inspector} from "devkit/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for Bundle global; import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; // Core Type -import {Function} from "devkit/core/Function.sol"; +import {Function} from "devkit/core/types/Function.sol"; // Validation import {validate} from "devkit/error/Validate.sol"; import {Require} from "devkit/error/Require.sol"; diff --git a/devkit/core/Dictionary.sol b/devkit/core/types/Dictionary.sol similarity index 93% rename from devkit/core/Dictionary.sol rename to devkit/core/types/Dictionary.sol index 9087dd83..a0f45a4d 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/types/Dictionary.sol @@ -3,21 +3,22 @@ pragma solidity ^0.8.24; /**-------------------------- Apply Support Methods ----------------------------*/ -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for Dictionary global; -import {Inspector} from "devkit/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for Dictionary global; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; using Bytes4Utils for bytes4; // Validation -import {Require} from "devkit/error/Require.sol";import {Params} from "devkit/debug/Params.sol"; +import {Require} from "devkit/error/Require.sol"; +import {Params} from "devkit/debug/Params.sol"; // Core Type -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; // Test -import {MockDictionary} from "devkit/test/MockDictionary.sol"; +import {MockDictionary} from "devkit/utils/mocks/MockDictionary.sol"; // External Libs import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; diff --git a/devkit/core/Function.sol b/devkit/core/types/Function.sol similarity index 94% rename from devkit/core/Function.sol rename to devkit/core/types/Function.sol index 9c51b862..6866786a 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/types/Function.sol @@ -3,13 +3,13 @@ pragma solidity ^0.8.24; /**-------------------------- Apply Support Methods ----------------------------*/ -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for Function global; -import {Parser} from "devkit/method/debug/Parser.sol"; +import {Parser} from "devkit/core/method/debug/Parser.sol"; using Parser for Function global; -import {Dumper} from "devkit/method/debug/Dumper.sol"; +import {Dumper} from "devkit/core/method/debug/Dumper.sol"; using Dumper for Function global; -import {Inspector} from "devkit/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for Function global; import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; using TypeSafetyUtils for Function global; diff --git a/devkit/core/Proxy.sol b/devkit/core/types/Proxy.sol similarity index 84% rename from devkit/core/Proxy.sol rename to devkit/core/types/Proxy.sol index 7cafc385..6afb0147 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/types/Proxy.sol @@ -3,18 +3,18 @@ pragma solidity ^0.8.24; /**-------------------------- Apply Support Methods ----------------------------*/ -import {ProcessLib} from "devkit/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for Proxy global; -import {Inspector} from "devkit/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for Proxy global; using Inspector for ProxyKind global; // Validation import {Require} from "devkit/error/Require.sol";// Core Type -import {Dictionary} from "devkit/core/Dictionary.sol"; -import {Function} from "devkit/core/Function.sol"; +import {Dictionary} from "devkit/core/types/Dictionary.sol"; +import {Function} from "devkit/core/types/Function.sol"; // Test -import {SimpleMockProxy} from "devkit/test/SimpleMockProxy.sol"; +import {SimpleMockProxy} from "devkit/utils/mocks/SimpleMockProxy.sol"; // External Lib import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index 083fea5e..8fd62303 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -14,13 +14,13 @@ import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; import {BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; // Core Types -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -import {BundleRegistry} from "devkit/core/BundleRegistry.sol"; -import {Proxy, ProxyKind} from "devkit/core/Proxy.sol"; -import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; -import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; -import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; +import {Proxy, ProxyKind} from "devkit/core/types/Proxy.sol"; +import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; +import {Dictionary, DictionaryKind} from "devkit/core/types/Dictionary.sol"; +import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; library Require { diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol index 43980a75..4edc32e0 100644 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ b/devkit/method/core/DictionaryRegistryLib.sol @@ -16,74 +16,8 @@ import {StringUtils} from "devkit/utils/StringUtils.sol"; import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; // Core -import {Dictionary} from "devkit/core/Dictionary.sol"; +import {Dictionary} from "devkit/core/types/Dictionary.sol"; -import {DictionaryRegistry} from "devkit/core/DictionaryRegistry.sol"; +import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 📘 Dictionary Registry - đŸ“Ĩ Add Dictionary - đŸ”ŧ Update Current Context Dictionary - â™ģī¸ Reset Current Context Dictionary - 🔍 Find Dictionary -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library DictionaryRegistryLib { - /**------------------------ - đŸ“Ĩ Add Dictionary - --------------------------*/ - function add(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.startProcess("add"); - dictionaries.deployed[name] = dictionary; - return dictionaries.finishProcess(pid); - } - - function safeAdd(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.startProcess("safeAdd"); - Require.notEmpty(name); - Require.notEmpty(dictionary); - return dictionaries .add(name, dictionary) - .finishProcess(pid); - } - - - /**----------------------------------------- - đŸ”ŧ Update Current Context Dictionary - -------------------------------------------*/ - function safeUpdate(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.startProcess("safeUpdate"); - Require.notEmpty(dictionary); - return dictionaries .update(dictionary).finishProcess(pid); - } - function update(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.startProcess("update"); - dictionaries.currentDictionary = dictionary; - return dictionaries.finishProcess(pid); - } - - - /**---------------------------------------- - â™ģī¸ Reset Current Context Dictionary - ------------------------------------------*/ - function reset(DictionaryRegistry storage dictionaries) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.startProcess("reset"); - delete dictionaries.currentDictionary; - return dictionaries.finishProcess(pid); - } - - - /**------------------------ - 🔍 Find Dictionary - --------------------------*/ - function find(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { - uint pid = dictionaries.startProcess("find"); - Require.exists(dictionaries.deployed[name]); - return dictionaries.deployed[name].finishProcessInStorage(pid); - } - function findCurrentDictionary(DictionaryRegistry storage dictionaries) internal returns(Dictionary storage) { - uint pid = dictionaries.startProcess("findCurrentDictionary"); - Require.exists(dictionaries.currentDictionary); - return dictionaries.currentDictionary.finishProcessInStorage(pid); - } - -} diff --git a/devkit/method/core/FunctionRegistryLib.sol b/devkit/method/core/FunctionRegistryLib.sol index 113356f0..a05926dc 100644 --- a/devkit/method/core/FunctionRegistryLib.sol +++ b/devkit/method/core/FunctionRegistryLib.sol @@ -14,65 +14,10 @@ import {StringUtils} from "devkit/utils/StringUtils.sol"; import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; // Core -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -import {StdFunctions} from "devkit/core/StdFunctions.sol"; +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; -import {FunctionRegistry} from "devkit/core/FunctionRegistry.sol"; +import {FunctionRegistry} from "devkit/core/registry/FunctionRegistry.sol"; -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 📗 Functions Registry - đŸ—ŗī¸ Insert Custom Function - đŸ”ŧ Update Current Context Function - â™ģī¸ Reset Current Context Function & Bundle - 🔍 Find Function -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library FunctionRegistryLib { - /**------------------------------ - đŸ—ŗī¸ Insert Custom Function - --------------------------------*/ - function insert(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { - uint pid = functions.startProcess("insert"); - Require.notEmpty(name); - functions.customs[name].assign(name, selector, implementation).lock(); - functions.safeUpdateCurrentFunction(name); // TODO - return functions.finishProcess(pid); - } - - /**------------------------------------------------ - đŸ”ŧ Update Current Context Function - --------------------------------------------------*/ - function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - uint pid = functions.startProcess("safeUpdateCurrentFunction"); - functions.currentName = name.assertNotEmpty(); - return functions.finishProcess(pid); - } - - /**----------------------------------------------- - â™ģī¸ Reset Current Context Function & Bundle - -------------------------------------------------*/ - function reset(FunctionRegistry storage functions) internal returns(FunctionRegistry storage) { - uint pid = functions.startProcess("reset"); - delete functions.currentName; - return functions.finishProcess(pid); - } - - /**------------------------------- - 🔍 Find Function - ---------------------------------*/ - function find(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { - uint pid = functions.startProcess("findFunction"); - Require.exists(functions.customs[name]); - return functions.customs[name].finishProcess(pid); - } - function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { - uint pid = functions.startProcess("findCurrentFunction"); - return functions.find(functions.findCurrentName()).finishProcess(pid); - } - function findCurrentName(FunctionRegistry storage functions) internal returns(string memory) { - uint pid = functions.startProcess("findCurrentName"); - return functions.currentName.assertNotEmpty().recordExecFinish(pid); - } - -} diff --git a/devkit/method/core/MockRegistryLib.sol b/devkit/method/core/MockRegistryLib.sol index adedd8e1..e590ee6f 100644 --- a/devkit/method/core/MockRegistryLib.sol +++ b/devkit/method/core/MockRegistryLib.sol @@ -16,71 +16,12 @@ import {StringUtils} from "devkit/utils/StringUtils.sol"; import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; // Core -import {Proxy} from "devkit/core/Proxy.sol"; -import {Dictionary} from "devkit/core/Dictionary.sol"; +import {Proxy} from "devkit/core/types/Proxy.sol"; +import {Dictionary} from "devkit/core/types/Dictionary.sol"; -import {MockRegistry} from "devkit/core/MockRegistry.sol"; -import {MappingAnalyzer} from "devkit/method/inspector/MappingAnalyzer.sol"; +import {MockRegistry} from "devkit/core/registry/MockRegistry.sol"; +import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Dictionary); using MappingAnalyzer for mapping(string => Proxy); -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🏭 Mock Registry - đŸ“Ĩ Add - Mock Dictionary - Mock Proxy - 🔍 Find - Mock Dictionary - Mock Proxy -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library MockRegistryLib { - - /**------------- - đŸ“Ĩ Add - ---------------*/ - /*----- Mock Dictionary -----*/ - function add(MockRegistry storage mock, string memory name, Dictionary memory dictionary) internal returns(MockRegistry storage) { - uint pid = mock.startProcess("add"); - Require.notEmpty(name); - validate(dictionary.isNotEmpty(), "Empty Dictionary"); - mock.dictionary[name] = dictionary; - return mock.finishProcess(pid); - } - function add(MockRegistry storage mock, Dictionary memory dictionary) internal returns(MockRegistry storage) { - return add(mock, mock.dictionary.genUniqueMockName(), dictionary); - } - - /*----- Mock Proxy -----*/ - function add(MockRegistry storage mock, string memory name, Proxy memory proxy) internal returns(MockRegistry storage) { - uint pid = mock.startProcess("add"); - Require.notEmpty(name); - validate(proxy.isNotEmpty(), "Empty Proxy"); - mock.proxy[name] = proxy; - return mock.finishProcess(pid); - } - function add(MockRegistry storage mock, Proxy memory proxy) internal returns(MockRegistry storage) { - return add(mock, mock.proxy.genUniqueMockName(), proxy); - } - - - /**-------------- - 🔍 Find - ----------------*/ - /*----- Mock Dictionary -----*/ - function findMockDictionary(MockRegistry storage mock, string memory name) internal returns(Dictionary storage) { - uint pid = mock.startProcess("findMockDictionary"); - Require.notEmpty(name); - Require.exists(mock.dictionary[name]); - return mock.dictionary[name].finishProcessInStorage(pid); - } - - /*----- Mock Proxy -----*/ - function findMockProxy(MockRegistry storage mock, string memory name) internal returns(Proxy storage) { - uint pid = mock.startProcess("findMockProxy"); - Require.notEmpty(name); - Require.exists(mock.proxy[name]); - return mock.proxy[name].finishProcessInStorage(pid); - } - -} diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol index 1055b9cd..e7b5ee70 100644 --- a/devkit/method/core/ProxyRegistryLib.sol +++ b/devkit/method/core/ProxyRegistryLib.sol @@ -14,75 +14,9 @@ import {StringUtils} from "devkit/utils/StringUtils.sol"; import {BoolUtils} from "devkit/utils/BoolUtils.sol"; using BoolUtils for bool; // Core -import {Proxy} from "devkit/core/Proxy.sol"; -import {Dictionary} from "devkit/core/Dictionary.sol"; +import {Proxy} from "devkit/core/types/Proxy.sol"; +import {Dictionary} from "devkit/core/types/Dictionary.sol"; -import {ProxyRegistry} from "devkit/core/ProxyRegistry.sol"; +import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🏠 Proxy Registry - đŸ“Ĩ Add Proxy - đŸ”ŧ Update Current Context Proxy - â™ģī¸ Reset Current Context Proxy - 🔍 Find Proxy -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library ProxyRegistryLib { - /**------------------- - đŸ“Ĩ Add Proxy - ---------------------*/ - function add(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.startProcess("add"); - proxies.deployed[name] = proxy; - return proxies.finishProcess(pid); - } - - function safeAdd(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.startProcess("safeAdd"); - Require.notEmpty(name); - Require.notEmpty(proxy); - return proxies .add(name, proxy) - .finishProcess(pid); - } - - - /**------------------------------------ - đŸ”ŧ Update Current Context Proxy - --------------------------------------*/ - function safeUpdate(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.startProcess("safeUpdate"); - Require.notEmpty(proxy); - return proxies.update(proxy).finishProcess(pid); - } - function update(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.startProcess("update"); - proxies.currentProxy = proxy; - return proxies.finishProcess(pid); - } - - - /**---------------------------------- - â™ģī¸ Reset Current Context Proxy - ------------------------------------*/ - function reset(ProxyRegistry storage proxies) internal returns(ProxyRegistry storage) { - uint pid = proxies.startProcess("reset"); - delete proxies.currentProxy; - return proxies.finishProcess(pid); - } - - - /**------------------- - 🔍 Find Proxy - ---------------------*/ - function find(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { - uint pid = proxies.startProcess("find"); - Require.exists(proxies.deployed[name]); - return proxies.deployed[name].finishProcessInStorage(pid); - } - function findCurrentProxy(ProxyRegistry storage proxies) internal returns(Proxy storage) { - uint pid = proxies.startProcess("findCurrentProxy"); - Require.exists(proxies.currentProxy); - return proxies.currentProxy.finishProcessInStorage(pid); - } - -} diff --git a/devkit/method/core/StdFunctionsLib.sol b/devkit/method/core/StdFunctionsLib.sol index 0fa23104..778a255f 100644 --- a/devkit/method/core/StdFunctionsLib.sol +++ b/devkit/method/core/StdFunctionsLib.sol @@ -11,8 +11,8 @@ import {StringUtils} from "devkit/utils/StringUtils.sol"; import {Debug} from "devkit/debug/Debug.sol"; import {Logger} from "devkit/debug/Logger.sol"; // Core -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; // MC Std import {Clone} from "mc-std/functions/Clone.sol"; import {GetDeps} from "mc-std/functions/GetDeps.sol"; @@ -21,126 +21,8 @@ import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.sol"; import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; -import {StdFunctions} from "devkit/core/StdFunctions.sol"; +import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; // Loader import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; -/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🏛 Standard Functions - 🔏 Assign and Load Standard Functions - đŸŖ Deploy Standard Functions If Not Exists - đŸ§ē Configure Standard Bundles -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -library StdFunctionsLib { - - /**------------------------------------------ - 🔏 Assign and Load Standard Functions - --------------------------------------------*/ - function assignAndLoad(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("assignAndLoad"); - return std .assignAndLoad_InitSetAdmin() - .assignAndLoad_GetDeps() - .assignAndLoad_Clone() - .finishProcess(pid); - } - - /**===== Each Std Function =====*/ - function assignAndLoad_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("assignAndLoad_InitSetAdmin"); - string memory name = "InitSetAdmin"; - bytes4 selector = InitSetAdmin.initSetAdmin.selector; - address implementation = loadAddressFrom(name); // TODO - std.initSetAdmin.assign(name, selector, implementation) - // .lock() - .dump(); - return std.finishProcess(pid); - } - - function assignAndLoad_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("assignAndLoad_GetDeps"); - string memory name = "GetDeps"; - bytes4 selector = GetDeps.getDeps.selector; - address implementation = loadAddressFrom(name); - std.getDeps .assign(name, selector, implementation) - // .lock() - .dump(); - return std.finishProcess(pid); - } - - function assignAndLoad_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("assignAndLoad_Clone"); - string memory name = "Clone"; - bytes4 selector = Clone.clone.selector; - address implementation = loadAddressFrom(name); - std.clone .assign(name, selector, implementation) - // .lock() - .dump(); - return std.finishProcess(pid); - } - - - /**----------------------------------------------- - đŸŖ Deploy Standard Functions If Not Exists - TODO versioning - -------------------------------------------------*/ - function deployIfNotExists(StdFunctions storage std) internal returns(StdFunctions storage) { - return std .deployIfNotExists_InitSetAdmin() - .deployIfNotExists_GetDeps() - .deployIfNotExists_Clone(); - } - /**===== Each Std Function =====*/ - function deployIfNotExists_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { - if (std.initSetAdmin.implementation.isNotContract()) { - std.initSetAdmin.assignImplementation(address(new InitSetAdmin())); - } - return std; - } - - function deployIfNotExists_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { - if (!std.getDeps.implementation.isContract()) { - std.getDeps.assignImplementation(address(new GetDeps())); - } - return std; - } - - function deployIfNotExists_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { - if (!std.clone.implementation.isContract()) { - std.clone.assignImplementation(address(new Clone())); - } - return std; - } - - - /**---------------------------------- - đŸ§ē Configure Standard Bundles - ------------------------------------*/ - function configureStdBundle(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("configureStdBundle"); - return std .configureStdBundle_AllFunctions() - .finishProcess(pid); - } - - /**===== Each Std Bundle =====*/ - function configureStdBundle_AllFunctions(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("configureStdBundle_AllFunctions"); - std.all .assignName("ALL_FUNCTIONS") - .pushFunction(std.initSetAdmin) - .pushFunction(std.getDeps) - .pushFunction(std.clone) - .assignFacade(address(new StdFacade())); - return std.finishProcess(pid); - } - -} - - -/**************************************************** - 🧩 Std Ops Primitive Utils for Arguments -*****************************************************/ -library StdFunctionsArgs { - function initSetAdminBytes(address admin) internal view returns(bytes memory) { - return abi.encodeCall(InitSetAdmin.initSetAdmin, admin); - } - -} diff --git a/devkit/test/MockDictionary.sol b/devkit/utils/mocks/MockDictionary.sol similarity index 89% rename from devkit/test/MockDictionary.sol rename to devkit/utils/mocks/MockDictionary.sol index 19f5f29b..74bc3391 100644 --- a/devkit/test/MockDictionary.sol +++ b/devkit/utils/mocks/MockDictionary.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Core -import {Function} from "devkit/core/Function.sol"; +import {Function} from "devkit/core/types/Function.sol"; // External Lib import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; diff --git a/devkit/test/SimpleMockProxy.sol b/devkit/utils/mocks/SimpleMockProxy.sol similarity index 96% rename from devkit/test/SimpleMockProxy.sol rename to devkit/utils/mocks/SimpleMockProxy.sol index c12228ba..98bb3d8c 100644 --- a/devkit/test/SimpleMockProxy.sol +++ b/devkit/utils/mocks/SimpleMockProxy.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Core -import {Function} from "devkit/core/Function.sol"; +import {Function} from "devkit/core/types/Function.sol"; // External Lib import {Proxy as OZProxy} from "@oz.mc/proxy/Proxy.sol"; diff --git a/script/DeployLib.sol b/script/DeployLib.sol index 29bb9671..bcc1e81b 100755 --- a/script/DeployLib.sol +++ b/script/DeployLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {StdFunctions} from "devkit/core/StdFunctions.sol"; +import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; library DeployLib { using DeployLib for MCDevKit; diff --git a/test/devkit/MCDevKit.t.sol b/test/devkit/MCDevKit.t.sol index 8ec9e15e..2c7d4901 100644 --- a/test/devkit/MCDevKit.t.sol +++ b/test/devkit/MCDevKit.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; import {Test, console2} from "forge-std/Test.sol"; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Function} from "devkit/core/Function.sol"; +import {Function} from "devkit/core/types/Function.sol"; import {TestHelper} from "../utils/TestHelper.sol"; using TestHelper for Function; diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 5b0ba4ec..6c7aafc6 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -8,8 +8,8 @@ import {StringUtils} from "devkit/utils/StringUtils.sol"; import {Config} from "devkit/config/Config.sol"; import {ERR} from "devkit/error/Error.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +import {Function} from "devkit/core/types/Function.sol"; import {DummyFunction} from "test/utils/DummyFunction.sol"; import {DummyFacade} from "test/utils/DummyFacade.sol"; diff --git a/test/devkit/global/MCSetup.t.sol b/test/devkit/global/MCSetup.t.sol index 4c2d8512..766f1c21 100644 --- a/test/devkit/global/MCSetup.t.sol +++ b/test/devkit/global/MCSetup.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; import {MCDevKitTest} from "devkit/MCTest.sol"; -import {Function} from "devkit/core/Function.sol"; +import {Function} from "devkit/core/types/Function.sol"; import {TestHelper} from "test/utils/TestHelper.sol"; using TestHelper for Function; diff --git a/test/utils/TestHelper.sol b/test/utils/TestHelper.sol index 90f99b97..cda473bf 100644 --- a/test/utils/TestHelper.sol +++ b/test/utils/TestHelper.sol @@ -6,7 +6,7 @@ import {AddressUtils} from "devkit/utils/AddressUtils.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; -import {Function} from "devkit/core/Function.sol"; +import {Function} from "devkit/core/types/Function.sol"; // import {Bundle} from "./Bundle.sol"; import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; From e167d9143e3bcb930a490c06a3850efd290023d1 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 10:09:36 +0900 Subject: [PATCH 059/111] Remove unused files --- devkit/method/core/DictionaryRegistryLib.sol | 23 ---------------- devkit/method/core/FunctionRegistryLib.sol | 23 ---------------- devkit/method/core/MockRegistryLib.sol | 27 ------------------- devkit/method/core/ProxyRegistryLib.sol | 22 --------------- devkit/method/core/StdFunctionsLib.sol | 28 -------------------- 5 files changed, 123 deletions(-) delete mode 100644 devkit/method/core/DictionaryRegistryLib.sol delete mode 100644 devkit/method/core/FunctionRegistryLib.sol delete mode 100644 devkit/method/core/MockRegistryLib.sol delete mode 100644 devkit/method/core/ProxyRegistryLib.sol delete mode 100644 devkit/method/core/StdFunctionsLib.sol diff --git a/devkit/method/core/DictionaryRegistryLib.sol b/devkit/method/core/DictionaryRegistryLib.sol deleted file mode 100644 index 4edc32e0..00000000 --- a/devkit/method/core/DictionaryRegistryLib.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Error & Debug -import {ERR, throwError} from "devkit/error/Error.sol"; -import {validate} from "devkit/error/Validate.sol"; -import {Require} from "devkit/error/Require.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Config -import {Config, ScanRange} from "devkit/config/Config.sol"; -// Utils -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -// Core -import {Dictionary} from "devkit/core/types/Dictionary.sol"; - -import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; - - diff --git a/devkit/method/core/FunctionRegistryLib.sol b/devkit/method/core/FunctionRegistryLib.sol deleted file mode 100644 index a05926dc..00000000 --- a/devkit/method/core/FunctionRegistryLib.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Error & Debug -import {validate} from "devkit/error/Validate.sol"; -import {Require} from "devkit/error/Require.sol"; -import {ERR, throwError} from "devkit/error/Error.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Config -import {ScanRange, Config} from "devkit/config/Config.sol"; -// Utils -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -// Core -import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; - -import {FunctionRegistry} from "devkit/core/registry/FunctionRegistry.sol"; - - diff --git a/devkit/method/core/MockRegistryLib.sol b/devkit/method/core/MockRegistryLib.sol deleted file mode 100644 index e590ee6f..00000000 --- a/devkit/method/core/MockRegistryLib.sol +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Error & Debug -import {ERR, throwError} from "devkit/error/Error.sol"; -import {validate} from "devkit/error/Validate.sol"; -import {Require} from "devkit/error/Require.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Config -import {Config, ScanRange} from "devkit/config/Config.sol"; -// Utils -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -// Core -import {Proxy} from "devkit/core/types/Proxy.sol"; -import {Dictionary} from "devkit/core/types/Dictionary.sol"; - -import {MockRegistry} from "devkit/core/registry/MockRegistry.sol"; -import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; - using MappingAnalyzer for mapping(string => Dictionary); - using MappingAnalyzer for mapping(string => Proxy); - - diff --git a/devkit/method/core/ProxyRegistryLib.sol b/devkit/method/core/ProxyRegistryLib.sol deleted file mode 100644 index e7b5ee70..00000000 --- a/devkit/method/core/ProxyRegistryLib.sol +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Error & Debug -import {ERR, throwError} from "devkit/error/Error.sol"; -import {validate} from "devkit/error/Validate.sol"; -import {Require} from "devkit/error/Require.sol"; -import {Debug} from "devkit/debug/Debug.sol"; -// Config -import {Config, ScanRange} from "devkit/config/Config.sol"; -// Utils -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; - using BoolUtils for bool; -// Core -import {Proxy} from "devkit/core/types/Proxy.sol"; -import {Dictionary} from "devkit/core/types/Dictionary.sol"; - -import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; - - diff --git a/devkit/method/core/StdFunctionsLib.sol b/devkit/method/core/StdFunctionsLib.sol deleted file mode 100644 index 778a255f..00000000 --- a/devkit/method/core/StdFunctionsLib.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Utils -import {console2} from "devkit/utils/ForgeHelper.sol"; -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; - using AddressUtils for address; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; -// Debug -import {Debug} from "devkit/debug/Debug.sol"; -import {Logger} from "devkit/debug/Logger.sol"; -// Core -import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; -// MC Std -import {Clone} from "mc-std/functions/Clone.sol"; -import {GetDeps} from "mc-std/functions/GetDeps.sol"; -import {FeatureToggle} from "mc-std/functions/protected/FeatureToggle.sol"; -import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; -import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.sol"; -import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; - -import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; -// Loader -import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; - - From 71b93d8700eaabce4debf1bb148929d24d6a4ed4 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 10:27:14 +0900 Subject: [PATCH 060/111] chore update --- devkit/core/types/Bundle.sol | 12 ++++++------ devkit/core/types/Dictionary.sol | 20 +++++++++++--------- devkit/core/types/Function.sol | 7 +++---- devkit/core/types/Proxy.sol | 16 +++++++++------- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/devkit/core/types/Bundle.sol b/devkit/core/types/Bundle.sol index 173982e6..d2cb5a74 100644 --- a/devkit/core/types/Bundle.sol +++ b/devkit/core/types/Bundle.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -/**-------------------------- - Apply Support Methods -----------------------------*/ +/**--------------------- + Support Methods +-----------------------*/ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for Bundle global; import {Parser} from "devkit/core/method/debug/Parser.sol"; @@ -10,13 +10,13 @@ import {Parser} from "devkit/core/method/debug/Parser.sol"; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for Bundle global; import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; - -// Core Type -import {Function} from "devkit/core/types/Function.sol"; // Validation import {validate} from "devkit/error/Validate.sol"; import {Require} from "devkit/error/Require.sol"; +// Core Type +import {Function} from "devkit/core/types/Function.sol"; + /**================ đŸ—‚ī¸ Bundle diff --git a/devkit/core/types/Dictionary.sol b/devkit/core/types/Dictionary.sol index a0f45a4d..6781b1cc 100644 --- a/devkit/core/types/Dictionary.sol +++ b/devkit/core/types/Dictionary.sol @@ -1,28 +1,30 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -/**-------------------------- - Apply Support Methods -----------------------------*/ +/**--------------------- + Support Methods +-----------------------*/ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for Dictionary global; +import {Params} from "devkit/debug/Params.sol"; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for Dictionary global; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; +// Type Util import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; using Bytes4Utils for bytes4; - // Validation import {Require} from "devkit/error/Require.sol"; -import {Params} from "devkit/debug/Params.sol"; -// Core Type -import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; -// Test + +// Mock import {MockDictionary} from "devkit/utils/mocks/MockDictionary.sol"; // External Libs import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; +// Core Types +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; + /**==================== 📚 Dictionary diff --git a/devkit/core/types/Function.sol b/devkit/core/types/Function.sol index 6866786a..5a111c46 100644 --- a/devkit/core/types/Function.sol +++ b/devkit/core/types/Function.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -/**-------------------------- - Apply Support Methods -----------------------------*/ +/**--------------------- + Support Methods +-----------------------*/ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for Function global; import {Parser} from "devkit/core/method/debug/Parser.sol"; @@ -13,7 +13,6 @@ import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for Function global; import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; using TypeSafetyUtils for Function global; - // Validation import {Require} from "devkit/error/Require.sol"; // Loader diff --git a/devkit/core/types/Proxy.sol b/devkit/core/types/Proxy.sol index 6afb0147..102d86ab 100644 --- a/devkit/core/types/Proxy.sol +++ b/devkit/core/types/Proxy.sol @@ -1,23 +1,25 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -/**-------------------------- - Apply Support Methods -----------------------------*/ +/**--------------------- + Support Methods +-----------------------*/ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for Proxy global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for Proxy global; using Inspector for ProxyKind global; - // Validation import {Require} from "devkit/error/Require.sol";// Core Type -import {Dictionary} from "devkit/core/types/Dictionary.sol"; -import {Function} from "devkit/core/types/Function.sol"; -// Test + +// Mock import {SimpleMockProxy} from "devkit/utils/mocks/SimpleMockProxy.sol"; // External Lib import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; +// Core Types +import {Dictionary} from "devkit/core/types/Dictionary.sol"; +import {Function} from "devkit/core/types/Function.sol"; + /**=============== 🏠 Proxy From 15105c9bac8f5073350e19735904a94ef223acd8 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 11:39:23 +0900 Subject: [PATCH 061/111] Update BundleRegistry --- devkit/core/method/global/MCBundleLib.sol | 9 +- devkit/core/method/global/MCDeployLib.sol | 12 +- devkit/core/method/global/MCFinderLib.sol | 10 +- devkit/core/method/inspector/Inspector.sol | 2 +- devkit/core/registry/BundleRegistry.sol | 137 +++++++++------------ devkit/error/Require.sol | 5 +- devkit/utils/type/TypeSafetyUtils.sol | 2 +- test/devkit/MCDevKit.t.sol | 2 +- test/devkit/global/MCBundle.t.sol | 8 +- 9 files changed, 83 insertions(+), 104 deletions(-) diff --git a/devkit/core/method/global/MCBundleLib.sol b/devkit/core/method/global/MCBundleLib.sol index b59538f5..02d47990 100644 --- a/devkit/core/method/global/MCBundleLib.sol +++ b/devkit/core/method/global/MCBundleLib.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Validation +import {Require} from "devkit/error/Require.sol"; import {validate} from "devkit/error/Validate.sol"; import {ERR} from "devkit/error/Error.sol"; // Utils @@ -32,7 +33,7 @@ library MCBundleLib { -----------------------------*/ function init(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("init", Params.append(name)); - mc.bundle.safeInit(name); + mc.bundle.init(name); return mc.recordExecFinish(pid); } @@ -86,11 +87,11 @@ library MCBundleLib { ---------------------------------------*/ function addToBundle(MCDevKit storage mc, Function storage functionInfo) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("addToBundle"); - mc.bundle.addToBundle(functionInfo); + mc.bundle.findCurrent().pushFunction(functionInfo); return mc.recordExecFinish(pid); } function addCurrentToBundle(MCDevKit storage mc) internal returns(MCDevKit storage) { - mc.bundle.addToBundle(mc.findCurrentFunction()); + mc.bundle.findCurrent().pushFunction(mc.findCurrentFunction()); return mc; } @@ -101,7 +102,7 @@ library MCBundleLib { function useFacade(MCDevKit storage mc, address facade) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("set"); validate(mc.bundle.existsCurrentBundle(), ERR.NOT_INIT); - mc.bundle.set(mc.bundle.findCurrentBundleName(), facade); + mc.bundle.findCurrent().assignFacade(facade); return mc.recordExecFinish(pid); } diff --git a/devkit/core/method/global/MCDeployLib.sol b/devkit/core/method/global/MCDeployLib.sol index 39f9f74e..d2080800 100644 --- a/devkit/core/method/global/MCDeployLib.sol +++ b/devkit/core/method/global/MCDeployLib.sol @@ -46,7 +46,7 @@ library MCDeployLib { } function deploy(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.deploy(mc.findCurrentBundleName(), mc.bundle.findCurrentBundle(), Config().defaultOwner(), Config().defaultInitData()); + return mc.deploy(mc.bundle.findCurrent().name, mc.bundle.findCurrent(), Config().defaultOwner(), Config().defaultInitData()); } // function deploy(MCDevKit storage mc, string memory name, Bundle storage bundleInfo, address facade, address owner) internal returns(MCDevKit storage) { // return mc.deploy(name, bundleInfo, facade, owner, Config().defaultInitData()); @@ -64,7 +64,7 @@ library MCDeployLib { // return mc.deploy(name, mc.functions.findBundle(name), Config().defaultInitData()); // } function deploy(MCDevKit storage mc, bytes memory initData) internal returns(MCDevKit storage) { - return mc.deploy(mc.findCurrentBundleName(), mc.bundle.findCurrentBundle(), Config().defaultOwner(), initData); + return mc.deploy(mc.bundle.findCurrent().name, mc.bundle.findCurrent(), Config().defaultOwner(), initData); } @@ -112,22 +112,22 @@ library MCDeployLib { } function deployDictionary(MCDevKit storage mc) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), mc.bundle.findCurrentBundle(), Config().defaultOwner()); + return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), mc.bundle.findCurrent(), Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, string memory name) internal returns(Dictionary memory) { - return mc.deployDictionary(name, mc.bundle.findCurrentBundle(), Config().defaultOwner()); + return mc.deployDictionary(name, mc.bundle.findCurrent(), Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, Bundle storage bundleInfo) internal returns(Dictionary memory) { return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), bundleInfo, Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, address owner) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), mc.bundle.findCurrentBundle(), owner); + return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), mc.bundle.findCurrent(), owner); } function deployDictionary(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(Dictionary memory) { return mc.deployDictionary(name, bundleInfo, Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, string memory name, address owner) internal returns(Dictionary memory) { - return mc.deployDictionary(name, mc.bundle.findCurrentBundle(), owner); + return mc.deployDictionary(name, mc.bundle.findCurrent(), owner); } function deployDictionary(MCDevKit storage mc, Bundle storage bundleInfo, address owner) internal returns(Dictionary memory) { return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), bundleInfo, owner); diff --git a/devkit/core/method/global/MCFinderLib.sol b/devkit/core/method/global/MCFinderLib.sol index 9b90e9e6..6989eb3c 100644 --- a/devkit/core/method/global/MCFinderLib.sol +++ b/devkit/core/method/global/MCFinderLib.sol @@ -31,12 +31,12 @@ library MCFinderLib { // return mc.functions.findCurrentBundle(); // } function findBundle(MCDevKit storage mc, string memory name) internal returns(Bundle storage) { - return mc.bundle.findBundle(name); - } - function findCurrentBundleName(MCDevKit storage mc) internal returns(string memory) { - uint pid = mc.recordExecStart("findCurrentBundleName", ""); - return mc.bundle.findCurrentBundleName(); + return mc.bundle.find(name); } + // function findCurrentBundleName(MCDevKit storage mc) internal returns(string memory) { + // uint pid = mc.recordExecStart("findCurrentBundleName", ""); + // return mc.bundle.findCurrentBundleName(); + // } /**---------------------- 🧩 Find Function diff --git a/devkit/core/method/inspector/Inspector.sol b/devkit/core/method/inspector/Inspector.sol index 89596453..1aa015d0 100644 --- a/devkit/core/method/inspector/Inspector.sol +++ b/devkit/core/method/inspector/Inspector.sol @@ -105,7 +105,7 @@ library Inspector { } function existsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { - return bundle.currentBundleName.isNotEmpty(); + return bundle.current.name.isNotEmpty(); } function notExistsCurrentBundle(BundleRegistry storage bundle) internal returns(bool) { return bundle.existsCurrentBundle().isNot(); diff --git a/devkit/core/registry/BundleRegistry.sol b/devkit/core/registry/BundleRegistry.sol index e849132d..5d418fda 100644 --- a/devkit/core/registry/BundleRegistry.sol +++ b/devkit/core/registry/BundleRegistry.sol @@ -18,113 +18,88 @@ import {Bundle} from "devkit/core/types/Bundle.sol"; import {Function} from "devkit/core/types/Function.sol"; +struct Current { + string name; +} +using CurrentLib for Current global; +library CurrentLib { + function update(Current storage current, string memory name) internal { + Require.notEmpty(name); + current.name = name; + } + function reset(Current storage current) internal { + // uint pid = bundle.startProcess("reset"); + delete current.name; + // return bundle.finishProcess(pid); + } +} + /**======================== 📙 Bundle Registry ==========================*/ using BundleRegistryLib for BundleRegistry global; struct BundleRegistry { mapping(string name => Bundle) bundles; - string currentBundleName; + Current current; } library BundleRegistryLib { /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 🌱 Init Bundle - ✨ Add Custom Function - 🔏 Load and Assign Custom Function from Env - đŸ§ē Add Custom Function to Bundle - đŸĒŸ Set Facade đŸ”ŧ Update Current Context Function & Bundle - 🔍 Find Function & Bundle + 🔍 Find Bundle 🏷 Generate Unique Name - 🔍 Find Custom Function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /**--------------------- 🌱 Init Bundle -----------------------*/ - function init(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("init"); - bundle.bundles[name].assignName(name); - bundle.safeUpdateCurrentBundle(name); - return bundle.finishProcess(pid); - } - function safeInit(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("safeInit"); + function init(BundleRegistry storage registry, string memory name) internal returns(BundleRegistry storage) { + uint pid = registry.startProcess("init"); Require.notEmpty(name); - Require.bundleNotExists(bundle, name); - return bundle .init(name) - .finishProcess(pid); - } + Bundle storage bundle = registry.bundles[name]; + Require.isUnassigned(bundle); + bundle.assignName(name); - /**------------------------------------- - đŸ§ē Add Custom Function to Bundle - ---------------------------------------*/ - function addToBundle(BundleRegistry storage bundle, Function storage functionInfo) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("addToBundle", "function"); - bundle.findCurrentBundle().pushFunction(functionInfo); - return bundle.finishProcess(pid); - } - function addToBundle(BundleRegistry storage bundle, Function[] storage functions) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("addToBundle", "bundle"); // TODO params - bundle.findCurrentBundle().pushFunctions(functions); - return bundle.finishProcess(pid); + registry.current.update(name); + return registry.finishProcess(pid); } - /**------------------ - đŸĒŸ Set Facade - --------------------*/ - function set(BundleRegistry storage bundle, string memory name, address facade) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("set"); - Require.exists(bundle.bundles[name]); - bundle.bundles[name].assignFacade(facade); - return bundle.finishProcess(pid); - } - function set(BundleRegistry storage bundle, address facade) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("set"); - return bundle.set(bundle.findCurrentBundleName(), facade).finishProcess(pid); - } - - - /**------------------------------------------------ - đŸ”ŧ Update Current Context - --------------------------------------------------*/ - function safeUpdateCurrentBundle(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("safeUpdateCurrentBundle"); - Require.notEmpty(name); - bundle.currentBundleName = name; - return bundle.finishProcess(pid); - } - - - /**----------------------------------------------- - â™ģī¸ Reset Current Context Function & Bundle - -------------------------------------------------*/ - function reset(BundleRegistry storage bundle) internal returns(BundleRegistry storage) { - uint pid = bundle.startProcess("reset"); - delete bundle.currentBundleName; - return bundle.finishProcess(pid); - } - - - /**------------------------------- - 🔍 Find Function & Bundle - ---------------------------------*/ - function findBundle(BundleRegistry storage bundle, string memory name) internal returns(Bundle storage) { - uint pid = bundle.startProcess("findBundle"); + // /**------------------------------------------------ + // đŸ”ŧ Update Current Context + // --------------------------------------------------*/ + // function updateCurrent(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { + // uint pid = bundle.startProcess("safeUpdateCurrentBundle"); + // Require.notEmpty(name); + // bundle.currentName = name; + // return bundle.finishProcess(pid); + // } + + + // /**----------------------------------------------- + // â™ģī¸ Reset Current Context Function & Bundle + // -------------------------------------------------*/ + // function reset(BundleRegistry storage bundle) internal returns(BundleRegistry storage) { + // uint pid = bundle.startProcess("reset"); + // delete bundle.currentName; + // return bundle.finishProcess(pid); + // } + + + /**-------------------- + 🔍 Find Bundle + ----------------------*/ + function find(BundleRegistry storage bundle, string memory name) internal returns(Bundle storage) { + uint pid = bundle.startProcess("find"); return bundle.bundles[name].finishProcess(pid); } - function findCurrentBundle(BundleRegistry storage bundle) internal returns(Bundle storage) { - uint pid = bundle.startProcess("findCurrentBundle"); - return bundle.findBundle(bundle.findCurrentBundleName()).finishProcess(pid); + function findCurrent(BundleRegistry storage bundle) internal returns(Bundle storage) { + uint pid = bundle.startProcess("findCurrent"); + string memory name = bundle.current.name; + Require.notEmpty(name); + return bundle.find(name).finishProcess(pid); } - function findCurrentBundleName(BundleRegistry storage bundle) internal returns(string memory) { - uint pid = bundle.startProcess("findCurrentBundleName"); - Require.notEmpty(bundle.currentBundleName); - return bundle.currentBundleName; - // return bundle.currentBundleName.recordExecFinish(pid); - } /**----------------------------- diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index 8fd62303..0cc05c68 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -70,9 +70,12 @@ library Require { return bundle; } function notExists(Bundle storage bundle) internal returns(Bundle storage) { - validate(bundle.notExists(), "Bundle Info Already Exists"); + validate(bundle.notExists(), "Bundle Already Exists"); return bundle; } + function isUnassigned(Bundle storage bundle) internal { + validate(bundle.hasNotName(), "Bundle Already Assigned."); + } /**======================= 📙 Bundle Registry diff --git a/devkit/utils/type/TypeSafetyUtils.sol b/devkit/utils/type/TypeSafetyUtils.sol index b18511e5..5c6dcbab 100644 --- a/devkit/utils/type/TypeSafetyUtils.sol +++ b/devkit/utils/type/TypeSafetyUtils.sol @@ -8,7 +8,7 @@ pragma solidity ^0.8.24; // import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; // using Bytes4Utils for bytes4; -enum BuildStatus { Building, Built, Locked } +enum BuildStatus { Uninitialized, Building, Built, Locked } library TypeSafetyUtils { diff --git a/test/devkit/MCDevKit.t.sol b/test/devkit/MCDevKit.t.sol index 2c7d4901..5ed0a7d4 100644 --- a/test/devkit/MCDevKit.t.sol +++ b/test/devkit/MCDevKit.t.sol @@ -34,6 +34,6 @@ contract MCDevKitTest is Test { mc.init(name); assertTrue(mc.bundle.bundles[name].name.isEqual(name)); - assertTrue(mc.bundle.currentBundleName.isEqual(name)); + assertTrue(mc.bundle.current.name.isEqual(name)); } } diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 6c7aafc6..debabbe2 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -22,7 +22,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { mc.init(name); assertTrue(mc.bundle.bundles[name].name.isEqual(name)); - assertTrue(mc.bundle.currentBundleName.isEqual(name)); + assertTrue(mc.bundle.current.name.isEqual(name)); } // verify genUniqueBundleName @@ -34,7 +34,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { mc.ensureInit(); assertTrue(mc.bundle.bundles[name].name.isEqual(name)); - assertTrue(mc.bundle.currentBundleName.isEqual(name)); + assertTrue(mc.bundle.current.name.isEqual(name)); } function test_Success_ensureInit_afterInit() public { @@ -43,13 +43,13 @@ contract DevKitTest_MCBundle is MCDevKitTest { mc.init(); assertTrue(mc.bundle.bundles[name].name.isEqual(name)); - assertTrue(mc.bundle.currentBundleName.isEqual(name)); + assertTrue(mc.bundle.current.name.isEqual(name)); string memory name2 = mc.bundle.genUniqueName(); mc.ensureInit(); assertTrue(mc.bundle.bundles[name2].name.isEmpty()); - assertTrue(mc.bundle.currentBundleName.isEqual(name)); + assertTrue(mc.bundle.current.name.isEqual(name)); } From 15de0a46539e21177c68578d7fa2e60361cfe422 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 11:58:04 +0900 Subject: [PATCH 062/111] Externalize Current --- devkit/core/method/context/Current.sol | 41 ++++++++++++++++++++++++ devkit/core/method/debug/ProcessLib.sol | 13 ++++++++ devkit/core/registry/BundleRegistry.sol | 42 ++----------------------- 3 files changed, 56 insertions(+), 40 deletions(-) create mode 100644 devkit/core/method/context/Current.sol diff --git a/devkit/core/method/context/Current.sol b/devkit/core/method/context/Current.sol new file mode 100644 index 00000000..6662a943 --- /dev/null +++ b/devkit/core/method/context/Current.sol @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; +/**--------------------- + Support Methods +-----------------------*/ +import {Params} from "devkit/debug/Params.sol"; +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; + using ProcessLib for Current global; + +// Validation +import {Require} from "devkit/error/Require.sol"; + + +/**======================== + 📸 Current Context +==========================*/ +using CurrentLib for Current global; +struct Current { + string name; +} +library CurrentLib { + /**------------------------------- + 🔄 Update Current Context + ---------------------------------*/ + function update(Current storage current, string memory name) internal { + uint pid = current.startProcess("update", Params.append(name)); + Require.notEmpty(name); + current.name = name; + ProcessLib.finishProcess(pid); + } + + /**------------------------------ + 🧹 Reset Current Context + --------------------------------*/ + function reset(Current storage current) internal { + uint pid = current.startProcess("reset"); + delete current.name; + ProcessLib.finishProcess(pid); + } + +} diff --git a/devkit/core/method/debug/ProcessLib.sol b/devkit/core/method/debug/ProcessLib.sol index a0d0fec2..4f1c543b 100644 --- a/devkit/core/method/debug/ProcessLib.sol +++ b/devkit/core/method/debug/ProcessLib.sol @@ -13,6 +13,7 @@ import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; import {Dictionary} from "devkit/core/types/Dictionary.sol"; import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; import {MockRegistry} from "devkit/core/registry/MockRegistry.sol"; +import {Current} from "devkit/core/method/context/Current.sol"; library ProcessLib { @@ -183,4 +184,16 @@ library ProcessLib { Debug.recordExecFinish(pid); return mock; } + + + /**------------------------ + 📸 Current Context + --------------------------*/ + function startProcess(Current storage, string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("CurrentLib", name, params); + } + function startProcess(Current storage current, string memory name) internal returns(uint) { + return current.startProcess(name, ""); + } + } diff --git a/devkit/core/registry/BundleRegistry.sol b/devkit/core/registry/BundleRegistry.sol index 5d418fda..472c05aa 100644 --- a/devkit/core/registry/BundleRegistry.sol +++ b/devkit/core/registry/BundleRegistry.sol @@ -13,27 +13,13 @@ import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol" // Validation import {validate} from "devkit/error/Validate.sol"; import {Require} from "devkit/error/Require.sol"; +// Context +import {Current} from "devkit/core/method/context/Current.sol"; // Core Type import {Bundle} from "devkit/core/types/Bundle.sol"; import {Function} from "devkit/core/types/Function.sol"; -struct Current { - string name; -} -using CurrentLib for Current global; -library CurrentLib { - function update(Current storage current, string memory name) internal { - Require.notEmpty(name); - current.name = name; - } - function reset(Current storage current) internal { - // uint pid = bundle.startProcess("reset"); - delete current.name; - // return bundle.finishProcess(pid); - } -} - /**======================== 📙 Bundle Registry ==========================*/ @@ -45,7 +31,6 @@ struct BundleRegistry { library BundleRegistryLib { /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 🌱 Init Bundle - đŸ”ŧ Update Current Context Function & Bundle 🔍 Find Bundle 🏷 Generate Unique Name ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ @@ -65,28 +50,6 @@ library BundleRegistryLib { return registry.finishProcess(pid); } - - // /**------------------------------------------------ - // đŸ”ŧ Update Current Context - // --------------------------------------------------*/ - // function updateCurrent(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - // uint pid = bundle.startProcess("safeUpdateCurrentBundle"); - // Require.notEmpty(name); - // bundle.currentName = name; - // return bundle.finishProcess(pid); - // } - - - // /**----------------------------------------------- - // â™ģī¸ Reset Current Context Function & Bundle - // -------------------------------------------------*/ - // function reset(BundleRegistry storage bundle) internal returns(BundleRegistry storage) { - // uint pid = bundle.startProcess("reset"); - // delete bundle.currentName; - // return bundle.finishProcess(pid); - // } - - /**-------------------- 🔍 Find Bundle ----------------------*/ @@ -101,7 +64,6 @@ library BundleRegistryLib { return bundle.find(name).finishProcess(pid); } - /**----------------------------- 🏷 Generate Unique Name -------------------------------*/ From f204848e94e5853d6e210ec981672144ffc53e3e Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 12:13:50 +0900 Subject: [PATCH 063/111] Update FunctionRegistry to use Current --- devkit/core/method/global/MCBundleLib.sol | 2 +- devkit/core/method/global/MCContextLib.sol | 6 +- devkit/core/method/global/MCFinderLib.sol | 8 +-- devkit/core/registry/BundleRegistry.sol | 20 +++--- devkit/core/registry/DictionaryRegistry.sol | 5 +- devkit/core/registry/FunctionRegistry.sol | 68 ++++++++------------- test/devkit/global/MCBundle.t.sol | 4 +- 7 files changed, 49 insertions(+), 64 deletions(-) diff --git a/devkit/core/method/global/MCBundleLib.sol b/devkit/core/method/global/MCBundleLib.sol index 02d47990..9d5a6a42 100644 --- a/devkit/core/method/global/MCBundleLib.sol +++ b/devkit/core/method/global/MCBundleLib.sol @@ -91,7 +91,7 @@ library MCBundleLib { return mc.recordExecFinish(pid); } function addCurrentToBundle(MCDevKit storage mc) internal returns(MCDevKit storage) { - mc.bundle.findCurrent().pushFunction(mc.findCurrentFunction()); + mc.bundle.findCurrent().pushFunction(mc.functions.findCurrent()); return mc; } diff --git a/devkit/core/method/global/MCContextLib.sol b/devkit/core/method/global/MCContextLib.sol index 9ae97b67..bcf8d02e 100644 --- a/devkit/core/method/global/MCContextLib.sol +++ b/devkit/core/method/global/MCContextLib.sol @@ -16,9 +16,9 @@ library MCContextLib { -------------------------------*/ function reset(MCDevKit storage mc) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("reset"); - mc.dictionary.reset(); - mc.functions.reset(); - mc.proxy.reset(); + mc.dictionary.current.reset(); + mc.functions.current.reset(); + // mc.proxy.current.reset(); return mc.recordExecFinish(pid); } diff --git a/devkit/core/method/global/MCFinderLib.sol b/devkit/core/method/global/MCFinderLib.sol index 6989eb3c..fdeb7de6 100644 --- a/devkit/core/method/global/MCFinderLib.sol +++ b/devkit/core/method/global/MCFinderLib.sol @@ -45,10 +45,10 @@ library MCFinderLib { uint pid = mc.recordExecStart("findFunction"); return mc.functions.find(name); } - function findCurrentFunction(MCDevKit storage mc) internal returns(Function storage) { - uint pid = mc.recordExecStart("findCurrentFunction", ""); - return mc.functions.findCurrentFunction(); - } + // function findCurrentFunction(MCDevKit storage mc) internal returns(Function storage) { + // uint pid = mc.recordExecStart("findCurrentFunction", ""); + // return mc.functions.findCurrentFunction(); + // } /**------------------- 🏠 Find Proxy diff --git a/devkit/core/registry/BundleRegistry.sol b/devkit/core/registry/BundleRegistry.sol index 472c05aa..4714da81 100644 --- a/devkit/core/registry/BundleRegistry.sol +++ b/devkit/core/registry/BundleRegistry.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -/**-------------------------- - Apply Support Methods -----------------------------*/ +/**--------------------- + Support Methods +-----------------------*/ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for BundleRegistry global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; @@ -53,15 +53,15 @@ library BundleRegistryLib { /**-------------------- 🔍 Find Bundle ----------------------*/ - function find(BundleRegistry storage bundle, string memory name) internal returns(Bundle storage) { - uint pid = bundle.startProcess("find"); - return bundle.bundles[name].finishProcess(pid); + function find(BundleRegistry storage registry, string memory name) internal returns(Bundle storage) { + uint pid = registry.startProcess("find"); + return registry.bundles[name].finishProcess(pid); } - function findCurrent(BundleRegistry storage bundle) internal returns(Bundle storage) { - uint pid = bundle.startProcess("findCurrent"); - string memory name = bundle.current.name; + function findCurrent(BundleRegistry storage registry) internal returns(Bundle storage) { + uint pid = registry.startProcess("findCurrent"); + string memory name = registry.current.name; Require.notEmpty(name); - return bundle.find(name).finishProcess(pid); + return registry.find(name).finishProcess(pid); } /**----------------------------- diff --git a/devkit/core/registry/DictionaryRegistry.sol b/devkit/core/registry/DictionaryRegistry.sol index 5d799372..539bb1b7 100644 --- a/devkit/core/registry/DictionaryRegistry.sol +++ b/devkit/core/registry/DictionaryRegistry.sol @@ -8,6 +8,8 @@ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for DictionaryRegistry global; +// Context +import {Current} from "devkit/core/method/context/Current.sol"; // Core Type import {Dictionary} from "devkit/core/types/Dictionary.sol"; import {Require} from "devkit/error/Require.sol"; @@ -19,13 +21,12 @@ import {Require} from "devkit/error/Require.sol"; using DictionaryRegistryLib for DictionaryRegistry global; struct DictionaryRegistry { mapping(string name => Dictionary) deployed; + Current current; Dictionary currentDictionary; } library DictionaryRegistryLib { /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ đŸ“Ĩ Add Dictionary - đŸ”ŧ Update Current Context Dictionary - â™ģī¸ Reset Current Context Dictionary 🔍 Find Dictionary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ diff --git a/devkit/core/registry/FunctionRegistry.sol b/devkit/core/registry/FunctionRegistry.sol index 61074708..c02b4e36 100644 --- a/devkit/core/registry/FunctionRegistry.sol +++ b/devkit/core/registry/FunctionRegistry.sol @@ -1,21 +1,25 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; - -// Core Type -import {Function} from "devkit/core/types/Function.sol"; -// Support Method +/**--------------------- + Support Methods +-----------------------*/ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for FunctionRegistry global; import {Require} from "devkit/error/Require.sol"; +// Context +import {Current} from "devkit/core/method/context/Current.sol"; +// Core Type +import {Function} from "devkit/core/types/Function.sol"; + /**=========================== 📗 Functions Registry =============================*/ using FunctionRegistryLib for FunctionRegistry global; struct FunctionRegistry { - mapping(string name => Function) customs; - string currentName; + mapping(string name => Function) functions; + Current current; } library FunctionRegistryLib { /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -28,50 +32,30 @@ library FunctionRegistryLib { /**------------------------------ đŸ—ŗī¸ Insert Custom Function --------------------------------*/ - function insert(FunctionRegistry storage functions, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { - uint pid = functions.startProcess("insert"); - Require.notEmpty(name); - functions.customs[name].assign(name, selector, implementation).lock(); - functions.safeUpdateCurrentFunction(name); // TODO - return functions.finishProcess(pid); - } - - /**------------------------------------------------ - đŸ”ŧ Update Current Context Function - --------------------------------------------------*/ - function safeUpdateCurrentFunction(FunctionRegistry storage functions, string memory name) internal returns(FunctionRegistry storage) { - uint pid = functions.startProcess("safeUpdateCurrentFunction"); + function insert(FunctionRegistry storage registry, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + uint pid = registry.startProcess("insert"); Require.notEmpty(name); - functions.currentName = name; - return functions.finishProcess(pid); + registry.functions[name].assign(name, selector, implementation).lock(); + registry.current.update(name); + return registry.finishProcess(pid); } - /**----------------------------------------------- - â™ģī¸ Reset Current Context Function & Bundle - -------------------------------------------------*/ - function reset(FunctionRegistry storage functions) internal returns(FunctionRegistry storage) { - uint pid = functions.startProcess("reset"); - delete functions.currentName; - return functions.finishProcess(pid); - } /**------------------------------- 🔍 Find Function ---------------------------------*/ - function find(FunctionRegistry storage functions, string memory name) internal returns(Function storage) { - uint pid = functions.startProcess("findFunction"); - Require.exists(functions.customs[name]); - return functions.customs[name].finishProcess(pid); + function find(FunctionRegistry storage registry, string memory name) internal returns(Function storage) { + uint pid = registry.startProcess("find"); + Require.notEmpty(name); + Function storage func = registry.functions[name]; + Require.exists(func); + return func.finishProcess(pid); } - function findCurrentFunction(FunctionRegistry storage functions) internal returns(Function storage) { - uint pid = functions.startProcess("findCurrentFunction"); - return functions.find(functions.findCurrentName()).finishProcess(pid); + function findCurrent(FunctionRegistry storage registry) internal returns(Function storage) { + uint pid = registry.startProcess("findCurrent"); + string memory name = registry.current.name; + Require.notEmpty(name); + return registry.find(name).finishProcess(pid); } - function findCurrentName(FunctionRegistry storage functions) internal returns(string memory) { - uint pid = functions.startProcess("findCurrentName"); - Require.notEmpty(functions.currentName); - return functions.currentName; - // return functions.currentName.recordExecFinish(pid); - } } diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index debabbe2..6f75549a 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -60,12 +60,12 @@ contract DevKitTest_MCBundle is MCDevKitTest { Bundle memory bundle = mc.bundle.bundles[bundleName]; assertEq(bundle.name, bundleName); assertEq(bundle.facade, address(0)); - Function memory func = mc.functions.customs[functionName]; + Function memory func = mc.functions.functions[functionName]; assertEq(func.name, functionName); assertEq(func.selector, selector); assertEq(func.implementation, impl); assertTrue(bundle.functions[functionsIndex].isEqual(func)); - assertEq(mc.functions.currentName, functionName); + assertEq(mc.functions.current.name, functionName); } function test_Success_use() public { From 986c4a7414bc497116b95af89e0822fa9a98f60b Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 12:27:34 +0900 Subject: [PATCH 064/111] Update DictionaryRegistry to use Current --- devkit/core/method/global/MCDeployLib.sol | 18 +++--- devkit/core/method/global/MCFinderLib.sol | 2 +- devkit/core/method/global/MCTestLib.sol | 3 +- devkit/core/method/inspector/Inspector.sol | 4 +- devkit/core/registry/DictionaryRegistry.sol | 70 ++++++--------------- devkit/core/registry/FunctionRegistry.sol | 16 ++--- 6 files changed, 36 insertions(+), 77 deletions(-) diff --git a/devkit/core/method/global/MCDeployLib.sol b/devkit/core/method/global/MCDeployLib.sol index d2080800..b65aa725 100644 --- a/devkit/core/method/global/MCDeployLib.sol +++ b/devkit/core/method/global/MCDeployLib.sol @@ -106,22 +106,21 @@ library MCDeployLib { Dictionary memory dictionary = DictionaryLib .deploy(owner) .set(bundleInfo) .upgradeFacade(bundleInfo.facade); - mc.dictionary .safeAdd(name, dictionary) - .safeUpdate(dictionary); + mc.dictionary.insert(name, dictionary); return dictionary.finishProcess(pid); } function deployDictionary(MCDevKit storage mc) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), mc.bundle.findCurrent(), Config().defaultOwner()); + return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), mc.bundle.findCurrent(), Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, string memory name) internal returns(Dictionary memory) { return mc.deployDictionary(name, mc.bundle.findCurrent(), Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, Bundle storage bundleInfo) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), bundleInfo, Config().defaultOwner()); + return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), bundleInfo, Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, address owner) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), mc.bundle.findCurrent(), owner); + return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), mc.bundle.findCurrent(), owner); } function deployDictionary(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(Dictionary memory) { return mc.deployDictionary(name, bundleInfo, Config().defaultOwner()); @@ -130,7 +129,7 @@ library MCDeployLib { return mc.deployDictionary(name, mc.bundle.findCurrent(), owner); } function deployDictionary(MCDevKit storage mc, Bundle storage bundleInfo, address owner) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.deployed.genUniqueName(), bundleInfo, owner); + return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), bundleInfo, owner); } @@ -140,18 +139,17 @@ library MCDeployLib { function duplicateDictionary(MCDevKit storage mc, string memory name, Dictionary storage targetDictionary) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("duplicateDictionary", Params.append(name, targetDictionary.addr)); Dictionary memory newDictionary = targetDictionary.duplicate(); - mc.dictionary .safeAdd(name, newDictionary) - .safeUpdate(newDictionary); + mc.dictionary.insert(name, newDictionary); return mc.recordExecFinish(pid); } function duplicateDictionary(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { return mc.duplicateDictionary(name, mc.findCurrentDictionary()); } function duplicateDictionary(MCDevKit storage mc, Dictionary storage targetDictionary) internal returns(MCDevKit storage) { - return mc.duplicateDictionary(mc.dictionary.deployed.genUniqueDuplicatedName(), targetDictionary); + return mc.duplicateDictionary(mc.dictionary.dictionaries.genUniqueDuplicatedName(), targetDictionary); } function duplicateDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.duplicateDictionary(mc.dictionary.deployed.genUniqueDuplicatedName(), mc.findCurrentDictionary()); + return mc.duplicateDictionary(mc.dictionary.dictionaries.genUniqueDuplicatedName(), mc.findCurrentDictionary()); } } diff --git a/devkit/core/method/global/MCFinderLib.sol b/devkit/core/method/global/MCFinderLib.sol index fdeb7de6..e6758279 100644 --- a/devkit/core/method/global/MCFinderLib.sol +++ b/devkit/core/method/global/MCFinderLib.sol @@ -70,7 +70,7 @@ library MCFinderLib { 📚 Find Dictionary --------------------------*/ function findCurrentDictionary(MCDevKit storage mc) internal returns(Dictionary storage) { - return mc.dictionary.findCurrentDictionary(); + return mc.dictionary.findCurrent(); } function findDictionary(MCDevKit storage mc, string memory name) internal returns(Dictionary storage) { return mc.dictionary.find(name); diff --git a/devkit/core/method/global/MCTestLib.sol b/devkit/core/method/global/MCTestLib.sol index 2074e38c..46cf4cf3 100644 --- a/devkit/core/method/global/MCTestLib.sol +++ b/devkit/core/method/global/MCTestLib.sol @@ -70,8 +70,7 @@ library MCTestLib { function createMockDictionary(MCDevKit storage mc, string memory name, address owner, Function[] memory functions) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("createMockDictionary", Params.append(name, owner)); Dictionary memory mockDictionary = DictionaryLib.createMockDictionary(owner, functions); - mc.dictionary .safeAdd(name, mockDictionary) - .safeUpdate(mockDictionary); + mc.dictionary.insert(name, mockDictionary); return mc.recordExecFinish(pid); } function createMockDictionary(MCDevKit storage mc, string memory name, address owner, Bundle storage bundleInfo) internal returns(MCDevKit storage) { diff --git a/devkit/core/method/inspector/Inspector.sol b/devkit/core/method/inspector/Inspector.sol index 1aa015d0..1c76ca5d 100644 --- a/devkit/core/method/inspector/Inspector.sol +++ b/devkit/core/method/inspector/Inspector.sol @@ -201,8 +201,8 @@ library Inspector { /**============================ 📚 Dictionary Registry ==============================*/ - function existsInDeployed(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { - return dictionaries.deployed[name].exists(); + function existsInDeployed(DictionaryRegistry storage registry, string memory name) internal returns(bool) { + return registry.dictionaries[name].exists(); } // function existsInMocks(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { // return dictionaries.mocks[name].exists(); diff --git a/devkit/core/registry/DictionaryRegistry.sol b/devkit/core/registry/DictionaryRegistry.sol index 539bb1b7..87327509 100644 --- a/devkit/core/registry/DictionaryRegistry.sol +++ b/devkit/core/registry/DictionaryRegistry.sol @@ -20,71 +20,39 @@ import {Require} from "devkit/error/Require.sol"; ==============================*/ using DictionaryRegistryLib for DictionaryRegistry global; struct DictionaryRegistry { - mapping(string name => Dictionary) deployed; + mapping(string name => Dictionary) dictionaries; Current current; Dictionary currentDictionary; } library DictionaryRegistryLib { - /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - đŸ“Ĩ Add Dictionary - 🔍 Find Dictionary - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - - /**------------------------ - đŸ“Ĩ Add Dictionary - --------------------------*/ - function add(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.startProcess("add"); - dictionaries.deployed[name] = dictionary; - return dictionaries.finishProcess(pid); - } - function safeAdd(DictionaryRegistry storage dictionaries, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.startProcess("safeAdd"); + /**--------------------------- + đŸ—ŗī¸ Insert Dictionary + -----------------------------*/ + function insert(DictionaryRegistry storage registry, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { + uint pid = registry.startProcess("insert"); Require.notEmpty(name); Require.notEmpty(dictionary); - return dictionaries .add(name, dictionary) - .finishProcess(pid); - } - - - /**----------------------------------------- - đŸ”ŧ Update Current Context Dictionary - -------------------------------------------*/ - function safeUpdate(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.startProcess("safeUpdate"); - Require.notEmpty(dictionary); - return dictionaries .update(dictionary).finishProcess(pid); - } - function update(DictionaryRegistry storage dictionaries, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.startProcess("update"); - dictionaries.currentDictionary = dictionary; - return dictionaries.finishProcess(pid); - } - - - /**---------------------------------------- - â™ģī¸ Reset Current Context Dictionary - ------------------------------------------*/ - function reset(DictionaryRegistry storage dictionaries) internal returns(DictionaryRegistry storage) { - uint pid = dictionaries.startProcess("reset"); - delete dictionaries.currentDictionary; - return dictionaries.finishProcess(pid); + registry.dictionaries[name] = dictionary; + return registry.finishProcess(pid); } /**------------------------ 🔍 Find Dictionary --------------------------*/ - function find(DictionaryRegistry storage dictionaries, string memory name) internal returns(Dictionary storage) { - uint pid = dictionaries.startProcess("find"); - Require.exists(dictionaries.deployed[name]); - return dictionaries.deployed[name].finishProcessInStorage(pid); + function find(DictionaryRegistry storage registry, string memory name) internal returns(Dictionary storage) { + uint pid = registry.startProcess("find"); + Require.notEmpty(name); + Dictionary storage dictionary = registry.dictionaries[name]; + Require.exists(dictionary); + return dictionary.finishProcessInStorage(pid); } - function findCurrentDictionary(DictionaryRegistry storage dictionaries) internal returns(Dictionary storage) { - uint pid = dictionaries.startProcess("findCurrentDictionary"); - Require.exists(dictionaries.currentDictionary); - return dictionaries.currentDictionary.finishProcessInStorage(pid); + function findCurrent(DictionaryRegistry storage registry) internal returns(Dictionary storage) { + uint pid = registry.startProcess("findCurrent"); + string memory name = registry.current.name; + Require.notEmpty(name); + return registry.find(name).finishProcessInStorage(pid); } } diff --git a/devkit/core/registry/FunctionRegistry.sol b/devkit/core/registry/FunctionRegistry.sol index c02b4e36..12b56cc5 100644 --- a/devkit/core/registry/FunctionRegistry.sol +++ b/devkit/core/registry/FunctionRegistry.sol @@ -22,16 +22,10 @@ struct FunctionRegistry { Current current; } library FunctionRegistryLib { - /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - đŸ—ŗī¸ Insert Custom Function - đŸ”ŧ Update Current Context Function - â™ģī¸ Reset Current Context Function & Bundle - 🔍 Find Function - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - /**------------------------------ - đŸ—ŗī¸ Insert Custom Function - --------------------------------*/ + /**------------------------- + đŸ—ŗī¸ Insert Function + ---------------------------*/ function insert(FunctionRegistry storage registry, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { uint pid = registry.startProcess("insert"); Require.notEmpty(name); @@ -41,9 +35,9 @@ library FunctionRegistryLib { } - /**------------------------------- + /**---------------------- 🔍 Find Function - ---------------------------------*/ + ------------------------*/ function find(FunctionRegistry storage registry, string memory name) internal returns(Function storage) { uint pid = registry.startProcess("find"); Require.notEmpty(name); From 86d0db966c99336c1f400d967f19a74595837bb7 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 12:36:11 +0900 Subject: [PATCH 065/111] Update Proxy Registry --- devkit/core/method/global/MCDeployLib.sol | 7 +- devkit/core/method/global/MCFinderLib.sol | 2 +- devkit/core/method/global/MCTestLib.sol | 5 +- devkit/core/method/inspector/Inspector.sol | 8 +- devkit/core/registry/DictionaryRegistry.sol | 7 +- devkit/core/registry/ProxyRegistry.sol | 85 +++++++------------- test/std/functions/CloneOpUCSTest.spec.t.sol | 8 +- 7 files changed, 45 insertions(+), 77 deletions(-) diff --git a/devkit/core/method/global/MCDeployLib.sol b/devkit/core/method/global/MCDeployLib.sol index b65aa725..9cf6aca3 100644 --- a/devkit/core/method/global/MCDeployLib.sol +++ b/devkit/core/method/global/MCDeployLib.sol @@ -74,8 +74,7 @@ library MCDeployLib { function deployProxy(MCDevKit storage mc, string memory name, Dictionary memory dictionary, bytes memory initData) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("deployProxy", Params.append(dictionary.addr, initData)); Proxy memory proxy = ProxyLib.deploy(dictionary, initData); - mc.proxy.safeAdd(name, proxy) - .safeUpdate(proxy); + mc.proxy.insert(name, proxy); return mc.recordExecFinish(pid); } function deployProxy(MCDevKit storage mc, string memory name, Dictionary storage dictionary, address owner) internal returns(MCDevKit storage) { @@ -91,10 +90,10 @@ library MCDeployLib { return mc.deployProxy(name, mc.findCurrentDictionary(), initData); } function deployProxy(MCDevKit storage mc, bytes memory initData) internal returns(MCDevKit storage) { - return mc.deployProxy(mc.proxy.deployed.genUniqueName(), mc.findCurrentDictionary(), initData); + return mc.deployProxy(mc.proxy.proxies.genUniqueName(), mc.findCurrentDictionary(), initData); } function deployProxy(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.deployProxy(mc.proxy.deployed.genUniqueName(), mc.findCurrentDictionary(), Config().defaultOwner().initSetAdminBytes()); + return mc.deployProxy(mc.proxy.proxies.genUniqueName(), mc.findCurrentDictionary(), Config().defaultOwner().initSetAdminBytes()); } diff --git a/devkit/core/method/global/MCFinderLib.sol b/devkit/core/method/global/MCFinderLib.sol index e6758279..b97a40c6 100644 --- a/devkit/core/method/global/MCFinderLib.sol +++ b/devkit/core/method/global/MCFinderLib.sol @@ -57,7 +57,7 @@ library MCFinderLib { return mc.proxy.find(name); } function findCurrentProxy(MCDevKit storage mc) internal returns(Proxy storage) { - return mc.proxy.findCurrentProxy(); + return mc.proxy.findCurrent(); } // function findMockProxy(MCDevKit storage mc, string memory name) internal returns(MockProxy) { // return mc.test.findMockProxy(name); diff --git a/devkit/core/method/global/MCTestLib.sol b/devkit/core/method/global/MCTestLib.sol index 46cf4cf3..02b01989 100644 --- a/devkit/core/method/global/MCTestLib.sol +++ b/devkit/core/method/global/MCTestLib.sol @@ -37,11 +37,10 @@ library MCTestLib { string memory params = Params.append(name); // for (uint i; i < functions.length; ++i) { // params = params.comma().append(functions[i].name); - // } + // } TODO uint pid = mc.recordExecStart("createSimpleMockProxy", params); Proxy memory simpleMockProxy = ProxyLib.createSimpleMockProxy(functions); - mc.proxy.safeAdd(name, simpleMockProxy) - .safeUpdate(simpleMockProxy); + mc.proxy.insert(name, simpleMockProxy); return mc.recordExecFinish(pid); } function createSimpleMockProxy(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(MCDevKit storage) { diff --git a/devkit/core/method/inspector/Inspector.sol b/devkit/core/method/inspector/Inspector.sol index 1c76ca5d..55d23d8d 100644 --- a/devkit/core/method/inspector/Inspector.sol +++ b/devkit/core/method/inspector/Inspector.sol @@ -149,11 +149,11 @@ library Inspector { /**======================= 🏠 Proxy Registry =========================*/ - function existsInDeployed(ProxyRegistry storage proxies, string memory name) internal returns(bool) { - return proxies.deployed[name].exists(); + function existsInDeployed(ProxyRegistry storage registry, string memory name) internal returns(bool) { + return registry.proxies[name].exists(); } - // function existsInMocks(ProxyRegistry storage proxies, string memory name) internal returns(bool) { - // return proxies.mocks[name].exists(); + // function existsInMocks(ProxyRegistry storage registry, string memory name) internal returns(bool) { + // return registry.mocks[name].exists(); // } diff --git a/devkit/core/registry/DictionaryRegistry.sol b/devkit/core/registry/DictionaryRegistry.sol index 87327509..f80529be 100644 --- a/devkit/core/registry/DictionaryRegistry.sol +++ b/devkit/core/registry/DictionaryRegistry.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -/**-------------------------- - Apply Support Methods -----------------------------*/ +/**--------------------- + Support Methods +-----------------------*/ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for DictionaryRegistry global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; @@ -22,7 +22,6 @@ using DictionaryRegistryLib for DictionaryRegistry global; struct DictionaryRegistry { mapping(string name => Dictionary) dictionaries; Current current; - Dictionary currentDictionary; } library DictionaryRegistryLib { diff --git a/devkit/core/registry/ProxyRegistry.sol b/devkit/core/registry/ProxyRegistry.sol index cae75cec..20ebd4f7 100644 --- a/devkit/core/registry/ProxyRegistry.sol +++ b/devkit/core/registry/ProxyRegistry.sol @@ -1,86 +1,57 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; - -// Core Type -import {Proxy} from "devkit/core/types/Proxy.sol"; -// Support Methods +/**--------------------- + Support Methods +-----------------------*/ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for ProxyRegistry global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for ProxyRegistry global; import {Require} from "devkit/error/Require.sol"; +// Context +import {Current} from "devkit/core/method/context/Current.sol"; +// Core Type +import {Proxy} from "devkit/core/types/Proxy.sol"; + /**======================= 📕 Proxy Registry =========================*/ using ProxyRegistryLib for ProxyRegistry global; struct ProxyRegistry { - mapping(string name => Proxy) deployed; - Proxy currentProxy; + mapping(string name => Proxy) proxies; + Current current; } library ProxyRegistryLib { - /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - đŸ“Ĩ Add Proxy - đŸ”ŧ Update Current Context Proxy - â™ģī¸ Reset Current Context Proxy - 🔍 Find Proxy - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - /**------------------- - đŸ“Ĩ Add Proxy - ---------------------*/ - function add(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.startProcess("add"); - proxies.deployed[name] = proxy; - return proxies.finishProcess(pid); - } - function safeAdd(ProxyRegistry storage proxies, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.startProcess("safeAdd"); + /**--------------------- + đŸ—ŗī¸ Insert Proxy + -----------------------*/ + function insert(ProxyRegistry storage registry, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { + uint pid = registry.startProcess("insert"); Require.notEmpty(name); Require.notEmpty(proxy); - return proxies .add(name, proxy) - .finishProcess(pid); - } - - - /**------------------------------------ - đŸ”ŧ Update Current Context Proxy - --------------------------------------*/ - function safeUpdate(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.startProcess("safeUpdate"); - Require.notEmpty(proxy); - return proxies.update(proxy).finishProcess(pid); - } - function update(ProxyRegistry storage proxies, Proxy memory proxy) internal returns(ProxyRegistry storage) { - uint pid = proxies.startProcess("update"); - proxies.currentProxy = proxy; - return proxies.finishProcess(pid); - } - - - /**---------------------------------- - â™ģī¸ Reset Current Context Proxy - ------------------------------------*/ - function reset(ProxyRegistry storage proxies) internal returns(ProxyRegistry storage) { - uint pid = proxies.startProcess("reset"); - delete proxies.currentProxy; - return proxies.finishProcess(pid); + registry.proxies[name] = proxy; + return registry.finishProcess(pid); } /**------------------- 🔍 Find Proxy ---------------------*/ - function find(ProxyRegistry storage proxies, string memory name) internal returns(Proxy storage) { - uint pid = proxies.startProcess("find"); - Require.exists(proxies.deployed[name]); - return proxies.deployed[name].finishProcessInStorage(pid); + function find(ProxyRegistry storage registry, string memory name) internal returns(Proxy storage) { + uint pid = registry.startProcess("find"); + Require.notEmpty(name); + Proxy storage proxy = registry.proxies[name]; + Require.exists(proxy); + return proxy.finishProcessInStorage(pid); } - function findCurrentProxy(ProxyRegistry storage proxies) internal returns(Proxy storage) { - uint pid = proxies.startProcess("findCurrentProxy"); - Require.exists(proxies.currentProxy); - return proxies.currentProxy.finishProcessInStorage(pid); + function findCurrent(ProxyRegistry storage registry) internal returns(Proxy storage) { + uint pid = registry.startProcess("findCurrent"); + string memory name = registry.current.name; + Require.notEmpty(name); + return registry.find(name).finishProcessInStorage(pid); } } diff --git a/test/std/functions/CloneOpUCSTest.spec.t.sol b/test/std/functions/CloneOpUCSTest.spec.t.sol index 7f5eed99..016658ad 100644 --- a/test/std/functions/CloneOpUCSTest.spec.t.sol +++ b/test/std/functions/CloneOpUCSTest.spec.t.sol @@ -9,10 +9,10 @@ contract CloneOpSpecMCTest is MCTest { address proxy; function setUp() public { - proxy = mc.createSimpleMockProxy("MyProxy") - // .set(mc.functions.stdOps.clone.toOp()) - // .set(mc.functions.stdOps.initSetAdmin.toOp()) - .toProxyAddress(); + // proxy = mc.createSimpleMockProxy("MyProxy") + // // .set(mc.functions.stdOps.clone.toOp()) + // // .set(mc.functions.stdOps.initSetAdmin.toOp()) + // .toProxyAddress(); // mc.getCurrentDictionary(); // mc.getCurrentProxy(); // CloneOp(proxy).clone(""); From c955d51ab8d28e3d5e8994bfc534e92d2f7cac99 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 12:59:22 +0900 Subject: [PATCH 066/111] Add deploy() to proxy registry --- devkit/core/method/global/MCBundleLib.sol | 5 +---- devkit/core/method/global/MCDeployLib.sol | 2 +- devkit/core/registry/ProxyRegistry.sol | 14 +++++++++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/devkit/core/method/global/MCBundleLib.sol b/devkit/core/method/global/MCBundleLib.sol index 9d5a6a42..1983ba15 100644 --- a/devkit/core/method/global/MCBundleLib.sol +++ b/devkit/core/method/global/MCBundleLib.sol @@ -25,8 +25,6 @@ import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol" đŸĒŸ Use Facade ************************************************/ library MCBundleLib { - string constant LIB_NAME = "MCBundleLib"; - /**--------------------------- 🌱 Init Custom Bundle @@ -36,9 +34,8 @@ library MCBundleLib { mc.bundle.init(name); return mc.recordExecFinish(pid); } - function init(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.init(mc.bundle.genUniqueName()); + return init(mc, mc.bundle.genUniqueName()); } // diff --git a/devkit/core/method/global/MCDeployLib.sol b/devkit/core/method/global/MCDeployLib.sol index 9cf6aca3..49d1cf2a 100644 --- a/devkit/core/method/global/MCDeployLib.sol +++ b/devkit/core/method/global/MCDeployLib.sol @@ -40,7 +40,7 @@ library MCDeployLib { uint pid = mc.recordExecStart("deploy"); // uint pid = mc.recordExecStart("deploy", PARAMS.append(name).comma().append(bundleInfo.name).comma().append(facade).comma().append(owner).comma().append(string(initData))); Dictionary memory dictionary = mc.deployDictionary(name, bundleInfo, owner); - mc.deployProxy(name, dictionary, initData); + mc.proxy.deploy(name, dictionary, initData); return mc.recordExecFinish(pid); // TODO gen and set facade } diff --git a/devkit/core/registry/ProxyRegistry.sol b/devkit/core/registry/ProxyRegistry.sol index 20ebd4f7..001a8514 100644 --- a/devkit/core/registry/ProxyRegistry.sol +++ b/devkit/core/registry/ProxyRegistry.sol @@ -12,7 +12,8 @@ import {Require} from "devkit/error/Require.sol"; // Context import {Current} from "devkit/core/method/context/Current.sol"; // Core Type -import {Proxy} from "devkit/core/types/Proxy.sol"; +import {Proxy, ProxyLib} from "devkit/core/types/Proxy.sol"; +import {Dictionary} from "devkit/core/types/Dictionary.sol"; /**======================= @@ -25,6 +26,17 @@ struct ProxyRegistry { } library ProxyRegistryLib { + /**--------------------- + 🚀 Deploy Proxy + -----------------------*/ + function deploy(ProxyRegistry storage registry, string memory name, Dictionary memory dictionary, bytes memory initData) internal returns(Proxy storage) { + uint pid = registry.startProcess("deploy"); + Require.isNotEmpty(dictionary); + registry.insert(name, ProxyLib.deploy(dictionary, initData)); + return registry.findCurrent().finishProcessInStorage(pid); + } + + /**--------------------- đŸ—ŗī¸ Insert Proxy -----------------------*/ From 3d5a6b1793915bbcf04c3975085cee39bb76a3ae Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 13:26:58 +0900 Subject: [PATCH 067/111] Add deploy() to DictionaryRegistry --- devkit/core/method/global/MCDeployLib.sol | 2 +- devkit/core/registry/DictionaryRegistry.sol | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/devkit/core/method/global/MCDeployLib.sol b/devkit/core/method/global/MCDeployLib.sol index 49d1cf2a..789e4381 100644 --- a/devkit/core/method/global/MCDeployLib.sol +++ b/devkit/core/method/global/MCDeployLib.sol @@ -39,7 +39,7 @@ library MCDeployLib { function deploy(MCDevKit storage mc, string memory name, Bundle storage bundleInfo, address owner, bytes memory initData) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("deploy"); // uint pid = mc.recordExecStart("deploy", PARAMS.append(name).comma().append(bundleInfo.name).comma().append(facade).comma().append(owner).comma().append(string(initData))); - Dictionary memory dictionary = mc.deployDictionary(name, bundleInfo, owner); + Dictionary memory dictionary = mc.dictionary.deploy(name, bundleInfo, owner); mc.proxy.deploy(name, dictionary, initData); return mc.recordExecFinish(pid); // TODO gen and set facade diff --git a/devkit/core/registry/DictionaryRegistry.sol b/devkit/core/registry/DictionaryRegistry.sol index f80529be..713f1ea0 100644 --- a/devkit/core/registry/DictionaryRegistry.sol +++ b/devkit/core/registry/DictionaryRegistry.sol @@ -11,7 +11,8 @@ import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; // Context import {Current} from "devkit/core/method/context/Current.sol"; // Core Type -import {Dictionary} from "devkit/core/types/Dictionary.sol"; +import {Dictionary, DictionaryLib} from "devkit/core/types/Dictionary.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; import {Require} from "devkit/error/Require.sol"; @@ -25,15 +26,28 @@ struct DictionaryRegistry { } library DictionaryRegistryLib { + /**--------------------- + 🚀 Deploy Proxy + -----------------------*/ + function deploy(DictionaryRegistry storage registry, string memory name, Bundle storage bundle, address owner) internal returns(Dictionary storage) { + uint pid = registry.startProcess("deploy"); + // Require.isNotEmpty(dictionary); TODO + registry.insert(name, DictionaryLib.deploy(owner)); + registry.findCurrent().set(bundle).upgradeFacade(bundle.facade); + return registry.findCurrent().finishProcessInStorage(pid); + } + + /**--------------------------- đŸ—ŗī¸ Insert Dictionary -----------------------------*/ - function insert(DictionaryRegistry storage registry, string memory name, Dictionary memory dictionary) internal returns(DictionaryRegistry storage) { + function insert(DictionaryRegistry storage registry, string memory name, Dictionary memory dictionary) internal returns(Dictionary storage) { uint pid = registry.startProcess("insert"); Require.notEmpty(name); Require.notEmpty(dictionary); registry.dictionaries[name] = dictionary; - return registry.finishProcess(pid); + registry.current.update(name); + return registry.findCurrent().finishProcessInStorage(pid); } From dbf2ecfd0092bc18084d42fd25aaeacc8a3b38e9 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 13:33:40 +0900 Subject: [PATCH 068/111] chore update --- devkit/core/method/debug/Dumper.sol | 6 ++++-- devkit/core/method/debug/Parser.sol | 7 +++++-- devkit/core/method/debug/ProcessLib.sol | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/devkit/core/method/debug/Dumper.sol b/devkit/core/method/debug/Dumper.sol index 19eca68f..6694973d 100644 --- a/devkit/core/method/debug/Dumper.sol +++ b/devkit/core/method/debug/Dumper.sol @@ -7,9 +7,11 @@ import {Function} from "devkit/core/types/Function.sol"; import {Bundle} from "devkit/core/types/Bundle.sol"; -//================ -// 🚰 Dumper +/**================= + 🚰 Dumper +===================*/ library Dumper { + /**================== 🧩 Function ====================*/ diff --git a/devkit/core/method/debug/Parser.sol b/devkit/core/method/debug/Parser.sol index 708c000a..08a2f48a 100644 --- a/devkit/core/method/debug/Parser.sol +++ b/devkit/core/method/debug/Parser.sol @@ -8,9 +8,12 @@ import {Bundle} from "devkit/core/types/Bundle.sol"; import {StringUtils} from "devkit/utils/StringUtils.sol"; using StringUtils for string; -//================ -// đŸ—’ī¸ Parser + +/**================= + đŸ—’ī¸ Parser +===================*/ library Parser { + /**================== 🧩 Function ====================*/ diff --git a/devkit/core/method/debug/ProcessLib.sol b/devkit/core/method/debug/ProcessLib.sol index 4f1c543b..ce8c3a7e 100644 --- a/devkit/core/method/debug/ProcessLib.sol +++ b/devkit/core/method/debug/ProcessLib.sol @@ -16,6 +16,9 @@ import {MockRegistry} from "devkit/core/registry/MockRegistry.sol"; import {Current} from "devkit/core/method/context/Current.sol"; +/**================= + â›“ī¸ Process +===================*/ library ProcessLib { function finishProcess(uint pid) internal { Debug.recordExecFinish(pid); From c2d4c9a50cd406eae028f496b4ab4708576e2dec Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 17:20:48 +0900 Subject: [PATCH 069/111] Update StdFunctions --- devkit/MCDevKit.sol | 4 +- devkit/config/Config.sol | 2 +- devkit/core/method/debug/ProcessLib.sol | 36 +++++- devkit/core/method/global/MCDeployLib.sol | 2 +- devkit/core/method/global/MCSetupLib.sol | 4 +- devkit/core/method/global/MCTestLib.sol | 10 +- devkit/core/method/inspector/Inspector.sol | 12 +- devkit/core/registry/FunctionRegistry.sol | 2 +- devkit/core/registry/StdBundle.sol | 19 +++ devkit/core/registry/StdFunctions.sol | 142 +++++++++------------ devkit/core/registry/StdRegistry.sol | 82 ++++++++++++ devkit/core/types/Bundle.sol | 27 ++-- devkit/core/types/Function.sol | 95 ++++---------- devkit/core/types/TypeGuard.sol | 102 +++++++++++++++ devkit/error/Require.sol | 30 ++++- devkit/utils/UintUtils.sol | 35 +++++ devkit/utils/type/TypeSafetyUtils.sol | 15 --- script/DeployLib.sol | 5 +- script/DeployStdDictionary.s.sol | 2 +- script/DeployStdFunctions.s.sol | 2 +- test/devkit/MCDevKit.t.sol | 78 +++++------ test/devkit/global/MCBundle.t.sol | 2 +- test/devkit/global/MCSetup.t.sol | 14 +- 23 files changed, 463 insertions(+), 259 deletions(-) create mode 100644 devkit/core/registry/StdBundle.sol create mode 100644 devkit/core/registry/StdRegistry.sol create mode 100644 devkit/core/types/TypeGuard.sol create mode 100644 devkit/utils/UintUtils.sol delete mode 100644 devkit/utils/type/TypeSafetyUtils.sol diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index 35c8fe49..73730137 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Core Registries -import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; +import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; import {FunctionRegistry} from "devkit/core/registry/FunctionRegistry.sol"; import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; @@ -23,7 +23,7 @@ import {MCDebugLib} from "devkit/core/method/global/MCDebugLib.sol"; 🌟 Meta Contract DevKit *********************************/ struct MCDevKit { - StdFunctions std; + StdRegistry std; FunctionRegistry functions; BundleRegistry bundle; DictionaryRegistry dictionary; diff --git a/devkit/config/Config.sol b/devkit/config/Config.sol index 7e549963..81861293 100644 --- a/devkit/config/Config.sol +++ b/devkit/config/Config.sol @@ -37,7 +37,7 @@ function Config() pure returns(Configuration storage ref) { \================*/ library ConfigLib { function load(Configuration storage config) internal { - config.DEBUG_MODE = false; + config.DEBUG_MODE = true; config.DEFAULT_LOG_LEVEL = LogLevel.Warn; config.SETUP_STD_FUNCS = true; diff --git a/devkit/core/method/debug/ProcessLib.sol b/devkit/core/method/debug/ProcessLib.sol index ce8c3a7e..af2b83dd 100644 --- a/devkit/core/method/debug/ProcessLib.sol +++ b/devkit/core/method/debug/ProcessLib.sol @@ -7,7 +7,9 @@ import {Function} from "devkit/core/types/Function.sol"; import {FunctionRegistry} from "devkit/core/registry/FunctionRegistry.sol"; import {Bundle} from "devkit/core/types/Bundle.sol"; import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; +import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; +import {StdBundle} from "devkit/core/registry/StdBundle.sol"; import {Proxy} from "devkit/core/types/Proxy.sol"; import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; import {Dictionary} from "devkit/core/types/Dictionary.sol"; @@ -87,8 +89,24 @@ library ProcessLib { } + /**------------------------- + 🏛 Standard Registry + ---------------------------*/ + function startProcess(StdRegistry storage, string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("StdRegistryLib", name, params); + } + function startProcess(StdRegistry storage std, string memory name) internal returns(uint) { + return std.startProcess(name, ""); + } + + function finishProcess(StdRegistry storage std, uint pid) internal returns(StdRegistry storage) { + Debug.recordExecFinish(pid); + return std; + } + + /**-------------------------- - 🏛 Standard Functions + 🏰 Standard Functions ----------------------------*/ function startProcess(StdFunctions storage, string memory name, string memory params) internal returns(uint) { return Debug.recordExecStart("StdFunctionsLib", name, params); @@ -103,6 +121,22 @@ library ProcessLib { } + /**------------------------ + đŸ—ŧ Standard Bundle + --------------------------*/ + function startProcess(StdBundle storage, string memory name, string memory params) internal returns(uint) { + return Debug.recordExecStart("StdRegistryLib", name, params); + } + function startProcess(StdBundle storage std, string memory name) internal returns(uint) { + return std.startProcess(name, ""); + } + + function finishProcess(StdBundle storage std, uint pid) internal returns(StdBundle storage) { + Debug.recordExecFinish(pid); + return std; + } + + /**--------------- 🏠 Proxy -----------------*/ diff --git a/devkit/core/method/global/MCDeployLib.sol b/devkit/core/method/global/MCDeployLib.sol index 789e4381..e40e2e3c 100644 --- a/devkit/core/method/global/MCDeployLib.sol +++ b/devkit/core/method/global/MCDeployLib.sol @@ -12,7 +12,7 @@ import {Params} from "devkit/debug/Params.sol"; import {Dictionary, DictionaryLib} from "devkit/core/types/Dictionary.sol"; // functions import {Bundle} from "devkit/core/types/Bundle.sol"; -import {StdFunctionsArgs} from "devkit/core/registry/StdFunctions.sol"; +import {StdFunctionsArgs} from "devkit/core/registry/StdRegistry.sol"; using StdFunctionsArgs for address; // proxy import {Proxy, ProxyLib} from "devkit/core/types/Proxy.sol"; diff --git a/devkit/core/method/global/MCSetupLib.sol b/devkit/core/method/global/MCSetupLib.sol index c75672fa..04689835 100644 --- a/devkit/core/method/global/MCSetupLib.sol +++ b/devkit/core/method/global/MCSetupLib.sol @@ -16,9 +16,7 @@ library MCSetupLib { ------------------------------*/ function setupStdFunctions(MCDevKit storage mc) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("setupStdFunctions"); - mc.std.assignAndLoad() - .deployIfNotExists() - .configureStdBundle(); + mc.std.complete(); return mc.recordExecFinish(pid); } diff --git a/devkit/core/method/global/MCTestLib.sol b/devkit/core/method/global/MCTestLib.sol index 02b01989..a8181c51 100644 --- a/devkit/core/method/global/MCTestLib.sol +++ b/devkit/core/method/global/MCTestLib.sol @@ -47,13 +47,13 @@ library MCTestLib { return mc.createSimpleMockProxy(name, bundleInfo.functions); } function createSimpleMockProxy(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - return mc.createSimpleMockProxy(name, mc.std.all); + return mc.createSimpleMockProxy(name, mc.std.bundle.all); } // function createSimpleMockProxy(MCDevKit storage mc, Function[] memory functions) internal returns(MCDevKit storage) { // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), functions); // } // function createSimpleMockProxy(MCDevKit storage mc) internal returns(MCDevKit storage) { - // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), mc.std.all); + // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), mc.std.bundle.all); // } @@ -76,13 +76,13 @@ library MCTestLib { return mc.createMockDictionary(name, owner, bundleInfo.functions); } function createMockDictionary(MCDevKit storage mc, string memory name, address owner) internal returns(MCDevKit storage) { - return mc.createMockDictionary(name, owner, mc.std.all); + return mc.createMockDictionary(name, owner, mc.std.bundle.all); } function createMockDictionary(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - return mc.createMockDictionary(name, Config().defaultOwner(), mc.std.all); + return mc.createMockDictionary(name, Config().defaultOwner(), mc.std.bundle.all); } // function createMockDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { - // return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), Config().defaultOwner(), mc.std.all); + // return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), Config().defaultOwner(), mc.std.bundle.all); // } diff --git a/devkit/core/method/inspector/Inspector.sol b/devkit/core/method/inspector/Inspector.sol index 55d23d8d..3c58c309 100644 --- a/devkit/core/method/inspector/Inspector.sol +++ b/devkit/core/method/inspector/Inspector.sol @@ -47,12 +47,12 @@ library Inspector { return func.exists().isFalse(); } - function isComplete(Function storage func) internal returns(bool) { - return func.name.isNotEmpty() && - func.selector.isNotEmpty() && - func.implementation.isContract(); - // return func.buildStatus == BuildStatus.Built; - } + // function isComplete(Function storage func) internal returns(bool) { + // return func.name.isNotEmpty() && + // func.selector.isNotEmpty() && + // func.implementation.isContract(); + // // return func.buildStatus == BuildStatus.Built; + // } function isEqual(Function memory a, Function memory b) internal pure returns(bool) { return keccak256(abi.encode(a)) == keccak256(abi.encode(b)); diff --git a/devkit/core/registry/FunctionRegistry.sol b/devkit/core/registry/FunctionRegistry.sol index 12b56cc5..a00ed95c 100644 --- a/devkit/core/registry/FunctionRegistry.sol +++ b/devkit/core/registry/FunctionRegistry.sol @@ -29,7 +29,7 @@ library FunctionRegistryLib { function insert(FunctionRegistry storage registry, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { uint pid = registry.startProcess("insert"); Require.notEmpty(name); - registry.functions[name].assign(name, selector, implementation).lock(); + registry.functions[name].assign(name, selector, implementation).build(); registry.current.update(name); return registry.finishProcess(pid); } diff --git a/devkit/core/registry/StdBundle.sol b/devkit/core/registry/StdBundle.sol new file mode 100644 index 00000000..195b9dd6 --- /dev/null +++ b/devkit/core/registry/StdBundle.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Core Types +import {Bundle} from "devkit/core/types/Bundle.sol"; +// Support Method +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; + using ProcessLib for StdBundle global; +import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; + using TypeGuard for StdBundle global; + + +/**========================== + đŸ—ŧ Standard Bundle +============================*/ +struct StdBundle { + Bundle all; + TypeStatus status; +} diff --git a/devkit/core/registry/StdFunctions.sol b/devkit/core/registry/StdFunctions.sol index 1117b50f..de3bd471 100644 --- a/devkit/core/registry/StdFunctions.sol +++ b/devkit/core/registry/StdFunctions.sol @@ -1,12 +1,16 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; +/**--------------------- + Support Methods +-----------------------*/ +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; + using ProcessLib for StdFunctions global; +import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; + using TypeGuard for StdFunctions global; +import {Require} from "devkit/error/Require.sol"; // Core Types import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; -// Support Method -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; - using ProcessLib for StdFunctions global; // MC Std import {Clone} from "mc-std/functions/Clone.sol"; import {GetDeps} from "mc-std/functions/GetDeps.sol"; @@ -14,84 +18,92 @@ import {FeatureToggle} from "mc-std/functions/protected/FeatureToggle.sol"; import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.sol"; import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; -// Loader -import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; // Utils import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; /**========================== - 🏛 Standard Functions + 🏰 Standard Functions ============================*/ using StdFunctionsLib for StdFunctions global; struct StdFunctions { Function initSetAdmin; Function getDeps; Function clone; - Bundle all; + TypeStatus status; } library StdFunctionsLib { /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🔏 Assign and Load Standard Functions - đŸŖ Deploy Standard Functions If Not Exists - đŸ§ē Configure Standard Bundles + đŸŸĸ Complete Standard Functions + 📨 Fetch Standard Functions from Env + 🚀 Deploy Standard Functions If Not Exists ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - /**------------------------------------------ - 🔏 Assign and Load Standard Functions - --------------------------------------------*/ - function assignAndLoad(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("assignAndLoad"); - return std .assignAndLoad_InitSetAdmin() - .assignAndLoad_GetDeps() - .assignAndLoad_Clone() - .finishProcess(pid); + /**------------------------------------ + đŸŸĸ Complete Standard Functions + --------------------------------------*/ + function complete(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { + uint pid = stdFunctions.startProcess("complete"); + stdFunctions.fetch(); + stdFunctions.deployIfNotExists(); + stdFunctions.initSetAdmin.build(); + stdFunctions.getDeps.build(); + stdFunctions.clone.build(); + stdFunctions.build(); + return stdFunctions.finishProcess(pid); + } + + /**----------------------------------------- + 📨 Fetch Standard Functions from Env + -------------------------------------------*/ + function fetch(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { + uint pid = stdFunctions.startProcess("fetch"); + return stdFunctions .fetch_InitSetAdmin() + .fetch_GetDeps() + .fetch_Clone() + .finishProcess(pid); } /**===== Each Std Function =====*/ - function assignAndLoad_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("assignAndLoad_InitSetAdmin"); - string memory name = "InitSetAdmin"; - bytes4 selector = InitSetAdmin.initSetAdmin.selector; - address implementation = loadAddressFrom(name); // TODO - std.initSetAdmin.assign(name, selector, implementation) - // .lock() - .dump(); - return std.finishProcess(pid); + function fetch_InitSetAdmin(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { + uint pid = stdFunctions.startProcess("fetch_InitSetAdmin"); + Require.notLocked(stdFunctions.initSetAdmin.status); + stdFunctions.initSetAdmin .fetch("InitSetAdmin") + .assignSelector(InitSetAdmin.initSetAdmin.selector) + .dump(); + return stdFunctions.finishProcess(pid); } - function assignAndLoad_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("assignAndLoad_GetDeps"); - string memory name = "GetDeps"; - bytes4 selector = GetDeps.getDeps.selector; - address implementation = loadAddressFrom(name); - std.getDeps .assign(name, selector, implementation) - // .lock() - .dump(); - return std.finishProcess(pid); + function fetch_GetDeps(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { + uint pid = stdFunctions.startProcess("fetch_GetDeps"); + Require.notLocked(stdFunctions.getDeps.status); + stdFunctions.getDeps.fetch("GetDeps") + .assignSelector(GetDeps.getDeps.selector) + .dump(); + return stdFunctions.finishProcess(pid); } - function assignAndLoad_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("assignAndLoad_Clone"); - string memory name = "Clone"; - bytes4 selector = Clone.clone.selector; - address implementation = loadAddressFrom(name); - std.clone .assign(name, selector, implementation) - // .lock() - .dump(); - return std.finishProcess(pid); + function fetch_Clone(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { + uint pid = stdFunctions.startProcess("fetch_Clone"); + Require.notLocked(stdFunctions.clone.status); + stdFunctions.clone .fetch("Clone") + .assignSelector(Clone.clone.selector) + .dump(); + return stdFunctions.finishProcess(pid); } /**----------------------------------------------- - đŸŖ Deploy Standard Functions If Not Exists + 🚀 Deploy Standard Functions If Not Exists TODO versioning -------------------------------------------------*/ function deployIfNotExists(StdFunctions storage std) internal returns(StdFunctions storage) { + uint pid = std.startProcess("deployIfNotExists"); return std .deployIfNotExists_InitSetAdmin() .deployIfNotExists_GetDeps() - .deployIfNotExists_Clone(); + .deployIfNotExists_Clone() + .finishProcess(pid); } /**===== Each Std Function =====*/ function deployIfNotExists_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { @@ -115,36 +127,4 @@ library StdFunctionsLib { return std; } - - /**---------------------------------- - đŸ§ē Configure Standard Bundles - ------------------------------------*/ - function configureStdBundle(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("configureStdBundle"); - return std .configureStdBundle_AllFunctions() - .finishProcess(pid); - } - - /**===== Each Std Bundle =====*/ - function configureStdBundle_AllFunctions(StdFunctions storage std) internal returns(StdFunctions storage) { - uint pid = std.startProcess("configureStdBundle_AllFunctions"); - std.all .assignName("ALL_FUNCTIONS") - .pushFunction(std.initSetAdmin) - .pushFunction(std.getDeps) - .pushFunction(std.clone) - .assignFacade(address(new StdFacade())); - return std.finishProcess(pid); - } - -} - - -/**************************************************** - 🧩 Std Ops Primitive Utils for Arguments -*****************************************************/ -library StdFunctionsArgs { - function initSetAdminBytes(address admin) internal view returns(bytes memory) { - return abi.encodeCall(InitSetAdmin.initSetAdmin, admin); - } - } diff --git a/devkit/core/registry/StdRegistry.sol b/devkit/core/registry/StdRegistry.sol new file mode 100644 index 00000000..5954e57c --- /dev/null +++ b/devkit/core/registry/StdRegistry.sol @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Core Types +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +// Support Method +import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; + using ProcessLib for StdRegistry global; +import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; + using TypeGuard for StdRegistry global; +// MC Std +import {Clone} from "mc-std/functions/Clone.sol"; +import {GetDeps} from "mc-std/functions/GetDeps.sol"; +import {FeatureToggle} from "mc-std/functions/protected/FeatureToggle.sol"; +import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; +import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.sol"; +import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; +// Loader +import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; +// Utils +import {AddressUtils} from "devkit/utils/AddressUtils.sol"; + using AddressUtils for address; + +import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; +import {StdBundle} from "devkit/core/registry/StdBundle.sol"; + + +/**========================== + 🏛 Standard Registry +============================*/ +using StdRegistryLib for StdRegistry global; +struct StdRegistry { + StdFunctions functions; + StdBundle bundle; +} +library StdRegistryLib { + /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 🔏 Assign and Load Standard Functions + đŸŖ Deploy Standard Functions If Not Exists + đŸ§ē Configure Standard Bundles + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + function complete(StdRegistry storage registry) internal returns(StdRegistry storage) { + uint pid = registry.startProcess("complete"); + registry.functions.complete(); + registry.configureStdBundle(); + return registry.finishProcess(pid); + } + + /**---------------------------------- + đŸ§ē Configure Standard Bundles + ------------------------------------*/ + function configureStdBundle(StdRegistry storage registry) internal returns(StdRegistry storage) { + uint pid = registry.startProcess("configureStdBundle"); + return registry .configureStdBundle_AllFunctions() + .finishProcess(pid); + } + + /**===== Each Std Bundle =====*/ + function configureStdBundle_AllFunctions(StdRegistry storage registry) internal returns(StdRegistry storage) { + uint pid = registry.startProcess("configureStdBundle_AllFunctions"); + registry.bundle.all .assignName("ALL_FUNCTIONS") + .pushFunction(registry.functions.initSetAdmin) + .pushFunction(registry.functions.getDeps) + .pushFunction(registry.functions.clone) + .assignFacade(address(new StdFacade())) + .build(); + return registry.finishProcess(pid); + } + +} + + +/**************************************************** + 🧩 Std Ops Primitive Utils for Arguments +*****************************************************/ +library StdFunctionsArgs { + function initSetAdminBytes(address admin) internal view returns(bytes memory) { + return abi.encodeCall(InitSetAdmin.initSetAdmin, admin); + } + +} diff --git a/devkit/core/types/Bundle.sol b/devkit/core/types/Bundle.sol index d2cb5a74..c9f9d246 100644 --- a/devkit/core/types/Bundle.sol +++ b/devkit/core/types/Bundle.sol @@ -9,7 +9,8 @@ import {Parser} from "devkit/core/method/debug/Parser.sol"; using Parser for Bundle global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for Bundle global; -import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; +import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; + using TypeGuard for Bundle global; // Validation import {validate} from "devkit/error/Validate.sol"; import {Require} from "devkit/error/Require.sol"; @@ -26,23 +27,18 @@ struct Bundle { string name; Function[] functions; address facade; - BuildStatus buildStatus; + TypeStatus status; } library BundleLib { - /**~~~~~~~~~~~~~~~~~~~~~~~ - 📛 Assign Name - 🧩 Push Function(s) - đŸĒŸ Assign Facade - ~~~~~~~~~~~~~~~~~~~~~~~~~*/ - /**-------------------- 📛 Assign Name ----------------------*/ function assignName(Bundle storage bundle, string memory name) internal returns(Bundle storage) { uint pid = bundle.startProcess("assignName"); - Require.notEmptyString(name); + Require.notLocked(bundle.status); + Require.notEmpty(name); bundle.name = name; - return bundle.finishProcess(pid); + return bundle.building().finishProcess(pid); } /**------------------------- @@ -50,17 +46,18 @@ library BundleLib { ---------------------------*/ function pushFunction(Bundle storage bundle, Function storage func) internal returns(Bundle storage) { uint pid = bundle.startProcess("pushFunction"); - validate(bundle.hasNot(func), "Already added"); - Require.implIsContract(func); + Require.notLocked(bundle.status); + Require.isComplete(func); + Require.hasNot(bundle, func); bundle.functions.push(func); - return bundle.finishProcess(pid); + return bundle.building().finishProcess(pid); } function pushFunctions(Bundle storage bundle, Function[] storage functions) internal returns(Bundle storage) { uint pid = bundle.startProcess("pushFunctions"); for (uint i; i < functions.length; ++i) { bundle.pushFunction(functions[i]); } - return bundle.finishProcess(pid); + return bundle.building().finishProcess(pid); } /**---------------------- @@ -70,7 +67,7 @@ library BundleLib { uint pid = bundle.startProcess("assignFacade"); Require.isContract(facade); bundle.facade = facade; - return bundle.finishProcess(pid); + return bundle.building().finishProcess(pid); } } diff --git a/devkit/core/types/Function.sol b/devkit/core/types/Function.sol index 5a111c46..fd2c97fd 100644 --- a/devkit/core/types/Function.sol +++ b/devkit/core/types/Function.sol @@ -11,8 +11,8 @@ import {Dumper} from "devkit/core/method/debug/Dumper.sol"; using Dumper for Function global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for Function global; -import {TypeSafetyUtils, BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; - using TypeSafetyUtils for Function global; +import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; + using TypeGuard for Function global; // Validation import {Require} from "devkit/error/Require.sol"; // Loader @@ -27,107 +27,60 @@ struct Function { /// @dev Function may be different depending on the op version string name; bytes4 selector; address implementation; - BuildStatus buildStatus; + TypeStatus status; } library FunctionLib { - /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🌈 Assign - 📛 Assign Name - đŸŽ¯ Assign Selector - 🔌 Assign Implementation - đŸ‘ˇâ€â™‚ī¸ Build - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - /**--------------- 🌈 Assign -----------------*/ function assign(Function storage func, string memory name, bytes4 selector, address implementation) internal returns(Function storage) { + uint pid = func.startProcess("assign"); func.assignName(name); func.assignSelector(selector); func.assignImplementation(implementation); - return func; + return func.finishProcess(pid); } /**-------------------- 📛 Assign Name ----------------------*/ function assignName(Function storage func, string memory name) internal returns(Function storage) { - Require.notLocked(func.buildStatus); + uint pid = func.startProcess("assignName"); + Require.notLocked(func.status); func.name = name; - func.asBuilding(); - return func; + return func.building().finishProcess(pid); } /**------------------------ đŸŽ¯ Assign Selector --------------------------*/ function assignSelector(Function storage func, bytes4 selector) internal returns(Function storage) { - Require.notLocked(func.buildStatus); + uint pid = func.startProcess("assignSelector"); + Require.notLocked(func.status); func.selector = selector; - func.asBuilding(); - return func; + return func.building().finishProcess(pid); } /**------------------------------ - 🔌 Assign Implementation + 🎨 Assign Implementation --------------------------------*/ function assignImplementation(Function storage func, address implementation) internal returns(Function storage) { - Require.notLocked(func.buildStatus); + uint pid = func.startProcess("assignImplementation"); + Require.notLocked(func.status); func.implementation = implementation; - func.asBuilding(); - return func; + return func.building().finishProcess(pid); } - /**-------------- - đŸ‘ˇâ€â™‚ī¸ Build - ----------------*/ - function asBuilding(Function storage func) internal returns(Function storage) { - func.buildStatus = BuildStatus.Building; + /**----------------------- + 📨 Fetch Function + -------------------------*/ + function fetch(Function storage func, string memory envKey) internal returns(Function storage) { + uint pid = func.startProcess("fetch"); + Require.isUnassigned(func.name); + Require.notEmpty(envKey); + func.assignName(envKey); + func.assignImplementation(loadAddressFrom(envKey)); return func; } - function build(Function storage func) internal returns(Function storage) { - // TODO - Require.assigned(func.selector); - Require.contractAssigned(func.implementation); - func.buildStatus = BuildStatus.Built; - return func; - } - function lock(Function storage func) internal returns(Function storage) { - func.buildStatus = BuildStatus.Locked; - return func; - } - - - // function fetch(Function storage func, string memory envKey) internal returns(Function storage) { - // uint pid = func.startProcess("fetch"); - // Require.isUnassigned(func.name); - // Require.isNotEmpty(envKey); - // return func; - // } - // function fetchAndAssign(Function storage func, string memory envKey, bytes4 selector) internal returns(Function storage) { - // uint pid = func.startProcess("fetchAndAssign"); - // func.assign(envKey, selector, loadAddressFrom(envKey)); - // return func.finishProcess(pid); - // } - - // function loadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { - // uint pid = func.startProcess("loadAndAssignFromEnv"); - // return func .assign(name) - // .assign(selector) - // .assign(loadAddressFrom(envKey)) - // .finishProcess(pid); - // } - // function loadAndAssignFromEnv(Function storage func) internal returns(Function storage) { - // Require.isNotEmpty(func.name); - // Require.isNotEmpty(func.selector); - // return func.loadAndAssignFromEnv(func.name, func.name, func.selector); - // } - // function safeLoadAndAssignFromEnv(Function storage func, string memory envKey, string memory name, bytes4 selector) internal returns(Function storage) { - // uint pid = func.startProcess("safeLoadAndAssignFromEnv"); - // Require.isNotEmpty(envKey); - // Require.isNotEmpty(name); - // Require.isNotEmpty(selector); - // return func.loadAndAssignFromEnv(envKey, name, selector).finishProcess(pid); - // } } diff --git a/devkit/core/types/TypeGuard.sol b/devkit/core/types/TypeGuard.sol new file mode 100644 index 00000000..2b86f9bc --- /dev/null +++ b/devkit/core/types/TypeGuard.sol @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// import {StringUtils} from "devkit/utils/StringUtils.sol"; +// using StringUtils for string; +// import {AddressUtils} from "devkit/utils/AddressUtils.sol"; +// using AddressUtils for address; +// import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; +// using Bytes4Utils for bytes4; +import {Require} from "devkit/error/Require.sol"; +// Core Types +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; +import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; +import {StdBundle} from "devkit/core/registry/StdBundle.sol"; + +using TypeGuard for TypeStatus global; +enum TypeStatus { Uninitialized, Building, Built, Locked } + +library TypeGuard { + function building(TypeStatus status) internal { + status = TypeStatus.Building; + } + function isBuilt(TypeStatus status) internal returns(bool) { + return status == TypeStatus.Built; + } + + function isLocked(TypeStatus status) internal returns(bool) { + return status == TypeStatus.Locked; + } + + function isComplete(TypeStatus status) internal returns(bool) { + return status.isBuilt() || status.isLocked(); + } + + + /**================== + 🧩 Function + ====================*/ + function building(Function storage func) internal returns(Function storage) { + func.status.building(); + return func; + } + function build(Function storage func) internal returns(Function storage) { + Require.assigned(func.name); + Require.assigned(func.selector); + Require.contractAssigned(func.implementation); + func.status = TypeStatus.Built; + return func; + } + function lock(Function storage func) internal returns(Function storage) { + Require.isBuilt(func.status); + func.status = TypeStatus.Locked; + return func; + } + function isComplete(Function storage func) internal returns(bool) { + return func.status.isComplete(); + } + + + /**================ + đŸ—‚ī¸ Bundle + ==================*/ + function building(Bundle storage bundle) internal returns(Bundle storage) { + bundle.status.building(); + return bundle; + } + function build(Bundle storage bundle) internal returns(Bundle storage) { + Require.assigned(bundle.name); + Require.notZero(bundle.functions.length); + Require.contractAssigned(bundle.facade); + bundle.status = TypeStatus.Built; + return bundle; + } + function lock(Bundle storage bundle) internal returns(Bundle storage) { + Require.isBuilt(bundle.status); + bundle.status = TypeStatus.Locked; + return bundle; + } + + + /**========================== + 🏰 Standard Functions + ============================*/ + function building(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { + stdFunctions.status.building(); + return stdFunctions; + } + function build(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { + Require.isComplete(stdFunctions.initSetAdmin); + Require.isComplete(stdFunctions.getDeps); + Require.isComplete(stdFunctions.clone); + stdFunctions.status = TypeStatus.Built; + return stdFunctions; + } + function lock(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { + Require.isBuilt(stdFunctions.status); + stdFunctions.status = TypeStatus.Locked; + return stdFunctions; + } + +} diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index 0cc05c68..6474324a 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -12,7 +12,9 @@ import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; using Bytes4Utils for bytes4; import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; -import {BuildStatus} from "devkit/utils/type/TypeSafetyUtils.sol"; +import {UintUtils} from "devkit/utils/UintUtils.sol"; + using UintUtils for uint256; +import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; // Core Types import {Function} from "devkit/core/types/Function.sol"; import {Bundle} from "devkit/core/types/Bundle.sol"; @@ -24,6 +26,21 @@ import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; library Require { + /** + Type Guard + */ + function isBuilt(TypeStatus status) internal { + validate(status.isBuilt(), "Not Built Yet"); + } + + function notZero(uint256 num) internal { + validate(num.isNotZero(), "Zero Number"); + } + + function assigned(string memory str) internal { + validate(str.isNotEmpty(), "Not Assigned"); + } + /**================== 🧩 Function ====================*/ @@ -53,8 +70,8 @@ library Require { function implIsContract(Function storage func) internal { validate(func.implementation.isContract(), "Implementation Not Contract"); } - function Complete(Function storage func) internal { - validate(func.isComplete(), "Function Info Not Complete"); + function isComplete(Function storage func) internal { + validate(func.isComplete(), "Function Not Complete"); } @@ -76,6 +93,9 @@ library Require { function isUnassigned(Bundle storage bundle) internal { validate(bundle.hasNotName(), "Bundle Already Assigned."); } + function hasNot(Bundle storage bundle, Function storage func) internal { + validate(bundle.hasNot(func), "Bundle has same Function"); + } /**======================= 📙 Bundle Registry @@ -157,8 +177,8 @@ library Require { validate(addr.isContract(), ERR.RQ_CONTRACT); } - function notLocked(BuildStatus status) internal { - validate(status != BuildStatus.Locked, ERR.LOCKED_OBJECT); + function notLocked(TypeStatus status) internal { + validate(status != TypeStatus.Locked, ERR.LOCKED_OBJECT); } function isNotEmpty(Dictionary memory dictionary) internal { diff --git a/devkit/utils/UintUtils.sol b/devkit/utils/UintUtils.sol new file mode 100644 index 00000000..cb30cac6 --- /dev/null +++ b/devkit/utils/UintUtils.sol @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Validation +import {validate} from "devkit/error/Validate.sol"; +// Utils +import {vm} from "./ForgeHelper.sol"; +import {StringUtils} from "./StringUtils.sol"; + using StringUtils for string; +import {BoolUtils} from "./BoolUtils.sol"; + using BoolUtils for bool; + + +/**=====================\ +| 💾 Bytes4 Utils | +\======================*/ +using UintUtils for bytes4; +library UintUtils { + /**--------------------------- + đŸ”ĸ Utils for Primitives + -----------------------------*/ + + + /**----------------------- + 🔀 Type Convertor + -------------------------*/ + + + /**------------------------------- + 🧐 Inspectors & Assertions + ---------------------------------*/ + function isNotZero(uint256 num) internal pure returns(bool) { + return num != 0; + } +} diff --git a/devkit/utils/type/TypeSafetyUtils.sol b/devkit/utils/type/TypeSafetyUtils.sol deleted file mode 100644 index 5c6dcbab..00000000 --- a/devkit/utils/type/TypeSafetyUtils.sol +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// import {StringUtils} from "devkit/utils/StringUtils.sol"; -// using StringUtils for string; -// import {AddressUtils} from "devkit/utils/AddressUtils.sol"; -// using AddressUtils for address; -// import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; -// using Bytes4Utils for bytes4; - -enum BuildStatus { Uninitialized, Building, Built, Locked } - -library TypeSafetyUtils { - -} diff --git a/script/DeployLib.sol b/script/DeployLib.sol index bcc1e81b..ed365679 100755 --- a/script/DeployLib.sol +++ b/script/DeployLib.sol @@ -2,20 +2,19 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; library DeployLib { using DeployLib for MCDevKit; string internal constant BUNDLE_NAME = "Std"; function deployStdFunctions(MCDevKit storage mc) internal returns(MCDevKit storage) { - mc.std.deployIfNotExists(); + mc.std.functions.deployIfNotExists(); return mc; } function deployStdDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { mc.deployStdFunctions(); - mc.deployDictionary(mc.std.all); + mc.deployDictionary(mc.std.bundle.all); return mc; } } diff --git a/script/DeployStdDictionary.s.sol b/script/DeployStdDictionary.s.sol index c6205ff7..fceec90e 100644 --- a/script/DeployStdDictionary.s.sol +++ b/script/DeployStdDictionary.s.sol @@ -9,7 +9,7 @@ contract DeployStdDictionary is MCScriptWithoutSetup { using DeployLib for MCDevKit; function setUp() public { - mc.std.assignAndLoad(); + mc.std.functions.fetch(); } function run() public startBroadcastWith("DEPLOYER_PRIV_KEY") { diff --git a/script/DeployStdFunctions.s.sol b/script/DeployStdFunctions.s.sol index dd1d7331..83efdae1 100644 --- a/script/DeployStdFunctions.s.sol +++ b/script/DeployStdFunctions.s.sol @@ -9,7 +9,7 @@ contract DeployStdFunctions is MCScriptWithoutSetup { using DeployLib for MCDevKit; function setUp() public { - mc.std.assignAndLoad(); + mc.std.functions.fetch(); } function run() public startBroadcastWith("DEPLOYER_PRIV_KEY") { diff --git a/test/devkit/MCDevKit.t.sol b/test/devkit/MCDevKit.t.sol index 5ed0a7d4..031510f3 100644 --- a/test/devkit/MCDevKit.t.sol +++ b/test/devkit/MCDevKit.t.sol @@ -1,39 +1,39 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import {Test, console2} from "forge-std/Test.sol"; -import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Function} from "devkit/core/types/Function.sol"; - -import {TestHelper} from "../utils/TestHelper.sol"; - using TestHelper for Function; -import {StringUtils} from "devkit/utils/StringUtils.sol"; - using StringUtils for string; - -contract MCDevKitTest is Test { - MCDevKit internal mc; - function setUp() public { - mc.stopLog(); - } - - function test_Success_setupStdFunctions() public { - mc.setupStdFunctions(); - - assertTrue(mc.std.initSetAdmin.isInitSetAdmin()); - assertTrue(mc.std.getDeps.isGetDeps()); - assertTrue(mc.std.clone.isClone()); - - assertTrue(mc.std.all.functions.length == 3); - assertTrue(mc.std.all.functions[0].isInitSetAdmin()); - assertTrue(mc.std.all.functions[1].isGetDeps()); - assertTrue(mc.std.all.functions[2].isClone()); - } - - function test_Success_init_withName() public { - string memory name = "TestBundleName"; - mc.init(name); - - assertTrue(mc.bundle.bundles[name].name.isEqual(name)); - assertTrue(mc.bundle.current.name.isEqual(name)); - } -} +// // SPDX-License-Identifier: MIT +// pragma solidity ^0.8.24; + +// import {Test, console2} from "forge-std/Test.sol"; +// import {MCDevKit} from "devkit/MCDevKit.sol"; +// import {Function} from "devkit/core/types/Function.sol"; + +// import {TestHelper} from "../utils/TestHelper.sol"; +// using TestHelper for Function; +// import {StringUtils} from "devkit/utils/StringUtils.sol"; +// using StringUtils for string; + +// contract MCDevKitTest is Test { +// MCDevKit internal mc; +// function setUp() public { +// mc.stopLog(); +// } + +// function test_Success_setupStdFunctions() public { +// mc.setupStdFunctions(); + +// assertTrue(mc.std.initSetAdmin.isInitSetAdmin()); +// assertTrue(mc.std.getDeps.isGetDeps()); +// assertTrue(mc.std.clone.isClone()); + +// assertTrue(mc.std.all.functions.length == 3); +// assertTrue(mc.std.all.functions[0].isInitSetAdmin()); +// assertTrue(mc.std.all.functions[1].isGetDeps()); +// assertTrue(mc.std.all.functions[2].isClone()); +// } + +// function test_Success_init_withName() public { +// string memory name = "TestBundleName"; +// mc.init(name); + +// assertTrue(mc.bundle.bundles[name].name.isEqual(name)); +// assertTrue(mc.bundle.current.name.isEqual(name)); +// } +// } diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 6f75549a..426335c3 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -87,7 +87,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { mc.use(functionName, selector, impl); - vm.expectRevert(ERR.message(ERR.LOCKED_OBJECT).toBytes()); + vm.expectRevert(ERR.message("Bundle has same Function").toBytes()); // TODO mc.use(functionName, selector, impl); } diff --git a/test/devkit/global/MCSetup.t.sol b/test/devkit/global/MCSetup.t.sol index 766f1c21..fd888358 100644 --- a/test/devkit/global/MCSetup.t.sol +++ b/test/devkit/global/MCSetup.t.sol @@ -15,14 +15,14 @@ contract DevKitTest_MCSetup is MCDevKitTest { function test_Success_setupStdFuncs() public { mc.setupStdFunctions(); - assertTrue(mc.std.initSetAdmin.isInitSetAdmin()); - assertTrue(mc.std.getDeps.isGetDeps()); - assertTrue(mc.std.clone.isClone()); + assertTrue(mc.std.functions.initSetAdmin.isInitSetAdmin()); + assertTrue(mc.std.functions.getDeps.isGetDeps()); + assertTrue(mc.std.functions.clone.isClone()); - assertTrue(mc.std.all.functions.length == 3); - assertTrue(mc.std.all.functions[0].isInitSetAdmin()); - assertTrue(mc.std.all.functions[1].isGetDeps()); - assertTrue(mc.std.all.functions[2].isClone()); + assertTrue(mc.std.bundle.all.functions.length == 3); + assertTrue(mc.std.bundle.all.functions[0].isInitSetAdmin()); + assertTrue(mc.std.bundle.all.functions[1].isGetDeps()); + assertTrue(mc.std.bundle.all.functions[2].isClone()); } } From 8991616792b2e8ebdab5f6c9eb8a19bf52491f9e Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 17:45:56 +0900 Subject: [PATCH 070/111] Update StdRegistry: merge stdBundle --- devkit/core/method/global/MCTestLib.sol | 10 ++--- devkit/core/method/inspector/Inspector.sol | 10 ++--- devkit/core/registry/StdBundle.sol | 1 - devkit/core/registry/StdFunctions.sol | 3 +- devkit/core/registry/StdRegistry.sol | 17 +++++---- devkit/core/types/TypeGuard.sol | 43 ++++++++++++++++++++++ devkit/error/Require.sol | 19 +++++++++- script/DeployLib.sol | 2 +- test/devkit/global/MCSetup.t.sol | 8 ++-- 9 files changed, 87 insertions(+), 26 deletions(-) diff --git a/devkit/core/method/global/MCTestLib.sol b/devkit/core/method/global/MCTestLib.sol index a8181c51..02b01989 100644 --- a/devkit/core/method/global/MCTestLib.sol +++ b/devkit/core/method/global/MCTestLib.sol @@ -47,13 +47,13 @@ library MCTestLib { return mc.createSimpleMockProxy(name, bundleInfo.functions); } function createSimpleMockProxy(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - return mc.createSimpleMockProxy(name, mc.std.bundle.all); + return mc.createSimpleMockProxy(name, mc.std.all); } // function createSimpleMockProxy(MCDevKit storage mc, Function[] memory functions) internal returns(MCDevKit storage) { // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), functions); // } // function createSimpleMockProxy(MCDevKit storage mc) internal returns(MCDevKit storage) { - // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), mc.std.bundle.all); + // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), mc.std.all); // } @@ -76,13 +76,13 @@ library MCTestLib { return mc.createMockDictionary(name, owner, bundleInfo.functions); } function createMockDictionary(MCDevKit storage mc, string memory name, address owner) internal returns(MCDevKit storage) { - return mc.createMockDictionary(name, owner, mc.std.bundle.all); + return mc.createMockDictionary(name, owner, mc.std.all); } function createMockDictionary(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - return mc.createMockDictionary(name, Config().defaultOwner(), mc.std.bundle.all); + return mc.createMockDictionary(name, Config().defaultOwner(), mc.std.all); } // function createMockDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { - // return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), Config().defaultOwner(), mc.std.bundle.all); + // return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), Config().defaultOwner(), mc.std.all); // } diff --git a/devkit/core/method/inspector/Inspector.sol b/devkit/core/method/inspector/Inspector.sol index 3c58c309..f9b9225e 100644 --- a/devkit/core/method/inspector/Inspector.sol +++ b/devkit/core/method/inspector/Inspector.sol @@ -71,11 +71,11 @@ library Inspector { return bundle.has(functionInfo).isFalse(); } - function isComplete(Bundle storage bundle) internal returns(bool) { - return bundle.name.isNotEmpty() && - bundle.functions.length != 0 && - bundle.facade.isContract(); - } + // function isComplete(Bundle storage bundle) internal returns(bool) { + // return bundle.name.isNotEmpty() && + // bundle.functions.length != 0 && + // bundle.facade.isContract(); + // } function hasName(Bundle storage bundle) internal returns(bool) { return bundle.name.isNotEmpty(); diff --git a/devkit/core/registry/StdBundle.sol b/devkit/core/registry/StdBundle.sol index 195b9dd6..ed729d90 100644 --- a/devkit/core/registry/StdBundle.sol +++ b/devkit/core/registry/StdBundle.sol @@ -14,6 +14,5 @@ import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; đŸ—ŧ Standard Bundle ============================*/ struct StdBundle { - Bundle all; TypeStatus status; } diff --git a/devkit/core/registry/StdFunctions.sol b/devkit/core/registry/StdFunctions.sol index de3bd471..862fac24 100644 --- a/devkit/core/registry/StdFunctions.sol +++ b/devkit/core/registry/StdFunctions.sol @@ -50,8 +50,7 @@ library StdFunctionsLib { stdFunctions.initSetAdmin.build(); stdFunctions.getDeps.build(); stdFunctions.clone.build(); - stdFunctions.build(); - return stdFunctions.finishProcess(pid); + return stdFunctions.build().finishProcess(pid); } /**----------------------------------------- diff --git a/devkit/core/registry/StdRegistry.sol b/devkit/core/registry/StdRegistry.sol index 5954e57c..d7673946 100644 --- a/devkit/core/registry/StdRegistry.sol +++ b/devkit/core/registry/StdRegistry.sol @@ -21,9 +21,10 @@ import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; // Utils import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; +// Validation +import {Require} from "devkit/error/Require.sol"; import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; -import {StdBundle} from "devkit/core/registry/StdBundle.sol"; /**========================== @@ -32,11 +33,12 @@ import {StdBundle} from "devkit/core/registry/StdBundle.sol"; using StdRegistryLib for StdRegistry global; struct StdRegistry { StdFunctions functions; - StdBundle bundle; + Bundle all; + TypeStatus status; } library StdRegistryLib { /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🔏 Assign and Load Standard Functions + đŸŸĸ Complete Standard Registry đŸŖ Deploy Standard Functions If Not Exists đŸ§ē Configure Standard Bundles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ @@ -44,7 +46,7 @@ library StdRegistryLib { uint pid = registry.startProcess("complete"); registry.functions.complete(); registry.configureStdBundle(); - return registry.finishProcess(pid); + return registry.build().lock().finishProcess(pid); } /**---------------------------------- @@ -52,14 +54,15 @@ library StdRegistryLib { ------------------------------------*/ function configureStdBundle(StdRegistry storage registry) internal returns(StdRegistry storage) { uint pid = registry.startProcess("configureStdBundle"); - return registry .configureStdBundle_AllFunctions() - .finishProcess(pid); + Require.notLocked(registry.all.status); + return registry .configureStdBundle_AllFunctions() + .finishProcess(pid); } /**===== Each Std Bundle =====*/ function configureStdBundle_AllFunctions(StdRegistry storage registry) internal returns(StdRegistry storage) { uint pid = registry.startProcess("configureStdBundle_AllFunctions"); - registry.bundle.all .assignName("ALL_FUNCTIONS") + registry.all .assignName("ALL_FUNCTIONS") .pushFunction(registry.functions.initSetAdmin) .pushFunction(registry.functions.getDeps) .pushFunction(registry.functions.clone) diff --git a/devkit/core/types/TypeGuard.sol b/devkit/core/types/TypeGuard.sol index 2b86f9bc..d3bc9e56 100644 --- a/devkit/core/types/TypeGuard.sol +++ b/devkit/core/types/TypeGuard.sol @@ -11,6 +11,7 @@ import {Require} from "devkit/error/Require.sol"; // Core Types import {Function} from "devkit/core/types/Function.sol"; import {Bundle} from "devkit/core/types/Bundle.sol"; +import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; import {StdBundle} from "devkit/core/registry/StdBundle.sol"; @@ -77,6 +78,29 @@ library TypeGuard { bundle.status = TypeStatus.Locked; return bundle; } + function isComplete(Bundle storage bundle) internal returns(bool) { + return bundle.status.isComplete(); + } + + + /**========================== + 🏛 Standard Registry + ============================*/ + function building(StdRegistry storage registry) internal returns(StdRegistry storage) { + registry.status.building(); + return registry; + } + function build(StdRegistry storage registry) internal returns(StdRegistry storage) { + Require.isComplete(registry.functions); + Require.isComplete(registry.all); + registry.status = TypeStatus.Built; + return registry; + } + function lock(StdRegistry storage registry) internal returns(StdRegistry storage) { + Require.isBuilt(registry.status); + registry.status = TypeStatus.Locked; + return registry; + } /**========================== @@ -99,4 +123,23 @@ library TypeGuard { return stdFunctions; } + + // /**========================== + // đŸ—ŧ Standard Bundle + // ============================*/ + // function building(StdBundle storage stdBundle) internal returns(StdBundle storage) { + // stdBundle.status.building(); + // return stdBundle; + // } + // function build(StdBundle storage stdBundle) internal returns(StdBundle storage) { + // Require.isComplete(stdBundle.all); + // stdBundle.status = TypeStatus.Built; + // return stdBundle; + // } + // function lock(StdBundle storage stdBundle) internal returns(StdBundle storage) { + // Require.isBuilt(stdBundle.status); + // stdBundle.status = TypeStatus.Locked; + // return stdBundle; + // } + } diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index 6474324a..5e5d3cc8 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -23,6 +23,9 @@ import {Proxy, ProxyKind} from "devkit/core/types/Proxy.sol"; import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; import {Dictionary, DictionaryKind} from "devkit/core/types/Dictionary.sol"; import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; +import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; +import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; +import {StdBundle} from "devkit/core/registry/StdBundle.sol"; library Require { @@ -78,7 +81,7 @@ library Require { /**=============== đŸ—‚ī¸ Bundle =================*/ - function Complete(Bundle storage bundle) internal returns(Bundle storage) { + function isComplete(Bundle storage bundle) internal returns(Bundle storage) { validate(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); return bundle; } @@ -188,4 +191,18 @@ library Require { function isNotZero(address addr) internal { validate(addr.isNotZero(), ERR.ZERO_ADDRESS); } + + + /**========================== + 🏛 Standard Registry + ============================*/ + function isComplete(StdRegistry storage registry) internal { + validate(registry.status.isComplete(), "Registry Not Complete"); + } + function isComplete(StdFunctions storage stdFunctions) internal { + validate(stdFunctions.status.isComplete(), "Registry Not Complete"); + } + function isComplete(StdBundle storage stdBundle) internal { + validate(stdBundle.status.isComplete(), "Registry Not Complete"); + } } diff --git a/script/DeployLib.sol b/script/DeployLib.sol index ed365679..6f8e340a 100755 --- a/script/DeployLib.sol +++ b/script/DeployLib.sol @@ -14,7 +14,7 @@ library DeployLib { function deployStdDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { mc.deployStdFunctions(); - mc.deployDictionary(mc.std.bundle.all); + mc.deployDictionary(mc.std.all); return mc; } } diff --git a/test/devkit/global/MCSetup.t.sol b/test/devkit/global/MCSetup.t.sol index fd888358..6729dddc 100644 --- a/test/devkit/global/MCSetup.t.sol +++ b/test/devkit/global/MCSetup.t.sol @@ -19,10 +19,10 @@ contract DevKitTest_MCSetup is MCDevKitTest { assertTrue(mc.std.functions.getDeps.isGetDeps()); assertTrue(mc.std.functions.clone.isClone()); - assertTrue(mc.std.bundle.all.functions.length == 3); - assertTrue(mc.std.bundle.all.functions[0].isInitSetAdmin()); - assertTrue(mc.std.bundle.all.functions[1].isGetDeps()); - assertTrue(mc.std.bundle.all.functions[2].isClone()); + assertTrue(mc.std.all.functions.length == 3); + assertTrue(mc.std.all.functions[0].isInitSetAdmin()); + assertTrue(mc.std.all.functions[1].isGetDeps()); + assertTrue(mc.std.all.functions[2].isClone()); } } From 1b2a48b0043816d22ac1515e2f0b99562670515f Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 18:17:58 +0900 Subject: [PATCH 071/111] Improve TypeGuard for StdFunction --- devkit/core/method/debug/ProcessLib.sol | 17 --------------- devkit/core/registry/StdBundle.sol | 18 ---------------- devkit/core/registry/StdFunctions.sol | 14 ++++++------- devkit/core/registry/StdRegistry.sol | 28 ++++++++++++------------- devkit/core/types/Function.sol | 4 ++-- devkit/core/types/TypeGuard.sol | 21 ------------------- devkit/error/Require.sol | 4 ---- 7 files changed, 22 insertions(+), 84 deletions(-) delete mode 100644 devkit/core/registry/StdBundle.sol diff --git a/devkit/core/method/debug/ProcessLib.sol b/devkit/core/method/debug/ProcessLib.sol index af2b83dd..4964db53 100644 --- a/devkit/core/method/debug/ProcessLib.sol +++ b/devkit/core/method/debug/ProcessLib.sol @@ -9,7 +9,6 @@ import {Bundle} from "devkit/core/types/Bundle.sol"; import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; -import {StdBundle} from "devkit/core/registry/StdBundle.sol"; import {Proxy} from "devkit/core/types/Proxy.sol"; import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; import {Dictionary} from "devkit/core/types/Dictionary.sol"; @@ -121,22 +120,6 @@ library ProcessLib { } - /**------------------------ - đŸ—ŧ Standard Bundle - --------------------------*/ - function startProcess(StdBundle storage, string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("StdRegistryLib", name, params); - } - function startProcess(StdBundle storage std, string memory name) internal returns(uint) { - return std.startProcess(name, ""); - } - - function finishProcess(StdBundle storage std, uint pid) internal returns(StdBundle storage) { - Debug.recordExecFinish(pid); - return std; - } - - /**--------------- 🏠 Proxy -----------------*/ diff --git a/devkit/core/registry/StdBundle.sol b/devkit/core/registry/StdBundle.sol deleted file mode 100644 index ed729d90..00000000 --- a/devkit/core/registry/StdBundle.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Core Types -import {Bundle} from "devkit/core/types/Bundle.sol"; -// Support Method -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; - using ProcessLib for StdBundle global; -import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; - using TypeGuard for StdBundle global; - - -/**========================== - đŸ—ŧ Standard Bundle -============================*/ -struct StdBundle { - TypeStatus status; -} diff --git a/devkit/core/registry/StdFunctions.sol b/devkit/core/registry/StdFunctions.sol index 862fac24..37a9107e 100644 --- a/devkit/core/registry/StdFunctions.sol +++ b/devkit/core/registry/StdFunctions.sol @@ -47,10 +47,10 @@ library StdFunctionsLib { uint pid = stdFunctions.startProcess("complete"); stdFunctions.fetch(); stdFunctions.deployIfNotExists(); - stdFunctions.initSetAdmin.build(); - stdFunctions.getDeps.build(); - stdFunctions.clone.build(); - return stdFunctions.build().finishProcess(pid); + stdFunctions.initSetAdmin.build().lock(); + stdFunctions.getDeps.build().lock(); + stdFunctions.clone.build().lock(); + return stdFunctions.build().lock().finishProcess(pid); } /**----------------------------------------- @@ -106,21 +106,21 @@ library StdFunctionsLib { } /**===== Each Std Function =====*/ function deployIfNotExists_InitSetAdmin(StdFunctions storage std) internal returns(StdFunctions storage) { - if (std.initSetAdmin.implementation.isNotContract()) { + if (std.initSetAdmin.notExists()) { std.initSetAdmin.assignImplementation(address(new InitSetAdmin())); } return std; } function deployIfNotExists_GetDeps(StdFunctions storage std) internal returns(StdFunctions storage) { - if (!std.getDeps.implementation.isContract()) { + if (std.getDeps.notExists()) { std.getDeps.assignImplementation(address(new GetDeps())); } return std; } function deployIfNotExists_Clone(StdFunctions storage std) internal returns(StdFunctions storage) { - if (!std.clone.implementation.isContract()) { + if (std.clone.notExists()) { std.clone.assignImplementation(address(new Clone())); } return std; diff --git a/devkit/core/registry/StdRegistry.sol b/devkit/core/registry/StdRegistry.sol index d7673946..90f8126b 100644 --- a/devkit/core/registry/StdRegistry.sol +++ b/devkit/core/registry/StdRegistry.sol @@ -39,35 +39,33 @@ struct StdRegistry { library StdRegistryLib { /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ đŸŸĸ Complete Standard Registry - đŸŖ Deploy Standard Functions If Not Exists - đŸ§ē Configure Standard Bundles + 🔧 Configure Standard Bundles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ function complete(StdRegistry storage registry) internal returns(StdRegistry storage) { uint pid = registry.startProcess("complete"); + Require.notLocked(registry.status); registry.functions.complete(); registry.configureStdBundle(); return registry.build().lock().finishProcess(pid); } /**---------------------------------- - đŸ§ē Configure Standard Bundles + 🔧 Configure Standard Bundles ------------------------------------*/ function configureStdBundle(StdRegistry storage registry) internal returns(StdRegistry storage) { uint pid = registry.startProcess("configureStdBundle"); - Require.notLocked(registry.all.status); - return registry .configureStdBundle_AllFunctions() - .finishProcess(pid); + return registry.configureStdBundle_All().finishProcess(pid); } - /**===== Each Std Bundle =====*/ - function configureStdBundle_AllFunctions(StdRegistry storage registry) internal returns(StdRegistry storage) { - uint pid = registry.startProcess("configureStdBundle_AllFunctions"); - registry.all .assignName("ALL_FUNCTIONS") - .pushFunction(registry.functions.initSetAdmin) - .pushFunction(registry.functions.getDeps) - .pushFunction(registry.functions.clone) - .assignFacade(address(new StdFacade())) - .build(); + function configureStdBundle_All(StdRegistry storage registry) internal returns(StdRegistry storage) { + uint pid = registry.startProcess("configureStdBundle_All"); + Require.notLocked(registry.all.status); + registry.all.assignName("ALL_STD_FUNCTIONS") + .pushFunction(registry.functions.initSetAdmin) + .pushFunction(registry.functions.getDeps) + .pushFunction(registry.functions.clone) + .assignFacade(address(new StdFacade())) + .build(); return registry.finishProcess(pid); } diff --git a/devkit/core/types/Function.sol b/devkit/core/types/Function.sol index fd2c97fd..3b8fe370 100644 --- a/devkit/core/types/Function.sol +++ b/devkit/core/types/Function.sol @@ -76,11 +76,11 @@ library FunctionLib { -------------------------*/ function fetch(Function storage func, string memory envKey) internal returns(Function storage) { uint pid = func.startProcess("fetch"); - Require.isUnassigned(func.name); + Require.notLocked(func.status); Require.notEmpty(envKey); func.assignName(envKey); func.assignImplementation(loadAddressFrom(envKey)); - return func; + return func.building().finishProcess(pid); } } diff --git a/devkit/core/types/TypeGuard.sol b/devkit/core/types/TypeGuard.sol index d3bc9e56..3ce6d94b 100644 --- a/devkit/core/types/TypeGuard.sol +++ b/devkit/core/types/TypeGuard.sol @@ -13,7 +13,6 @@ import {Function} from "devkit/core/types/Function.sol"; import {Bundle} from "devkit/core/types/Bundle.sol"; import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; -import {StdBundle} from "devkit/core/registry/StdBundle.sol"; using TypeGuard for TypeStatus global; enum TypeStatus { Uninitialized, Building, Built, Locked } @@ -122,24 +121,4 @@ library TypeGuard { stdFunctions.status = TypeStatus.Locked; return stdFunctions; } - - - // /**========================== - // đŸ—ŧ Standard Bundle - // ============================*/ - // function building(StdBundle storage stdBundle) internal returns(StdBundle storage) { - // stdBundle.status.building(); - // return stdBundle; - // } - // function build(StdBundle storage stdBundle) internal returns(StdBundle storage) { - // Require.isComplete(stdBundle.all); - // stdBundle.status = TypeStatus.Built; - // return stdBundle; - // } - // function lock(StdBundle storage stdBundle) internal returns(StdBundle storage) { - // Require.isBuilt(stdBundle.status); - // stdBundle.status = TypeStatus.Locked; - // return stdBundle; - // } - } diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index 5e5d3cc8..401da524 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -25,7 +25,6 @@ import {Dictionary, DictionaryKind} from "devkit/core/types/Dictionary.sol"; import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; -import {StdBundle} from "devkit/core/registry/StdBundle.sol"; library Require { @@ -202,7 +201,4 @@ library Require { function isComplete(StdFunctions storage stdFunctions) internal { validate(stdFunctions.status.isComplete(), "Registry Not Complete"); } - function isComplete(StdBundle storage stdBundle) internal { - validate(stdBundle.status.isComplete(), "Registry Not Complete"); - } } From ee611196faf544af47db0892bdab9ea67f9947ce Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 19:25:06 +0900 Subject: [PATCH 072/111] Improve Dictionary type safety --- devkit/core/registry/ProxyRegistry.sol | 1 + devkit/core/types/Dictionary.sol | 78 ++++++++++++++------------ devkit/core/types/Proxy.sol | 9 ++- devkit/core/types/TypeGuard.sol | 42 ++++++++++++++ devkit/error/Require.sol | 8 ++- 5 files changed, 97 insertions(+), 41 deletions(-) diff --git a/devkit/core/registry/ProxyRegistry.sol b/devkit/core/registry/ProxyRegistry.sol index 001a8514..5de2d565 100644 --- a/devkit/core/registry/ProxyRegistry.sol +++ b/devkit/core/registry/ProxyRegistry.sol @@ -31,6 +31,7 @@ library ProxyRegistryLib { -----------------------*/ function deploy(ProxyRegistry storage registry, string memory name, Dictionary memory dictionary, bytes memory initData) internal returns(Proxy storage) { uint pid = registry.startProcess("deploy"); + Require.notEmpty(name); Require.isNotEmpty(dictionary); registry.insert(name, ProxyLib.deploy(dictionary, initData)); return registry.findCurrent().finishProcessInStorage(pid); diff --git a/devkit/core/types/Dictionary.sol b/devkit/core/types/Dictionary.sol index 6781b1cc..8a9d650f 100644 --- a/devkit/core/types/Dictionary.sol +++ b/devkit/core/types/Dictionary.sol @@ -14,6 +14,8 @@ import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; using Bytes4Utils for bytes4; // Validation import {Require} from "devkit/error/Require.sol"; +import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; + using TypeGuard for Dictionary global; // Mock import {MockDictionary} from "devkit/utils/mocks/MockDictionary.sol"; @@ -33,6 +35,7 @@ using DictionaryLib for Dictionary global; struct Dictionary { address addr; DictionaryKind kind; + TypeStatus status; } library DictionaryLib { /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -51,65 +54,66 @@ library DictionaryLib { /// @dev Until Etherscan supports UCS, we are deploying contracts with additional features for Etherscan compatibility by default. return Dictionary({ addr: address(new DictionaryEtherscan(owner)), - kind: DictionaryKind.Verifiable + kind: DictionaryKind.Verifiable, + status: TypeStatus.Building }).finishProcess(pid); } /**---------------------------- 🔂 Duplicate Dictionary ------------------------------*/ - function duplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { + function duplicate(Dictionary memory toDictionary, Dictionary memory fromDictionary) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("duplicate"); - return deploy(ForgeHelper.msgSender()) - .duplicateFunctionsFrom(targetDictionary).finishProcess(pid); - } - function duplicateFunctionsFrom(Dictionary memory toDictionary, Dictionary memory fromDictionary) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("duplicateFunctionsFrom"); - address toAddr = toDictionary.addr; - address fromAddr = fromDictionary.addr; - - bytes4[] memory _selectors = IDictionary(fromAddr).supportsInterfaces(); - for (uint i; i < _selectors.length; ++i) { - bytes4 _selector = _selectors[i]; - if (_selector.isEmpty()) continue; - IDictionary(toAddr).setImplementation({ - functionSelector: _selector, - implementation: IDictionary(fromAddr).getImplementation(_selector) - }); - } - - return toDictionary.finishProcess(pid); + Require.notEmpty(toDictionary); + Require.notEmpty(fromDictionary); + + address toAddr = toDictionary.addr; + address fromAddr = fromDictionary.addr; + + bytes4[] memory _selectors = IDictionary(fromAddr).supportsInterfaces(); + for (uint i; i < _selectors.length; ++i) { + bytes4 _selector = _selectors[i]; + if (_selector.isEmpty()) continue; + toDictionary.set(_selector, IDictionary(fromAddr).getImplementation(_selector)); } - function safeDuplicate(Dictionary memory targetDictionary) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("safeDuplicate"); - Require.notEmpty(targetDictionary); - return targetDictionary.duplicate().finishProcess(pid); + + return toDictionary.finishProcess(pid); + } + function duplicate(Dictionary memory fromDictionary) internal returns(Dictionary memory) { + return duplicate(deploy(ForgeHelper.msgSender()), fromDictionary); } /**----------------------------- 🧩 Set Function or Bundle -------------------------------*/ - function set(Dictionary memory dictionary, Function memory functionInfo) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(functionInfo.name)); + function set(Dictionary memory dictionary, bytes4 selector, address implementation) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(selector, implementation)); + Require.isContract(dictionary.addr); + Require.notEmpty(selector); + Require.isContract(implementation); IDictionary(dictionary.addr).setImplementation({ - functionSelector: functionInfo.selector, - implementation: functionInfo.implementation + functionSelector: selector, + implementation: implementation }); return dictionary.finishProcess(pid); } - function set(Dictionary memory dictionary, Bundle storage bundleInfo) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(bundleInfo.name)); + function set(Dictionary memory dictionary, Function memory func) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(func.name)); + return set(dictionary, func.selector, func.implementation).finishProcess(pid); + } + function set(Dictionary memory dictionary, Bundle storage bundle) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(bundle.name)); - Function[] memory functions = bundleInfo.functions; + Function[] memory functions = bundle.functions; for (uint i; i < functions.length; ++i) { - dictionary.set(functions[i]); + set(dictionary, functions[i]); } // TODO Generate Facade // if (dictionary.isVerifiable()) { - // dictionary.upgradeFacade(bundleInfo.facade); + // dictionary.upgradeFacade(bundle.facade); // } return dictionary.finishProcess(pid); @@ -121,7 +125,8 @@ library DictionaryLib { ------------------------*/ function upgradeFacade(Dictionary memory dictionary, address newFacade) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("upgradeFacade"); - Require.verifiable(dictionary); + Require.isContract(newFacade); + // Require.verifiable(dictionary); TODO without CALL DictionaryEtherscan(dictionary.addr).upgradeFacade(newFacade); return dictionary.finishProcess(pid); } @@ -134,7 +139,8 @@ library DictionaryLib { uint pid = ProcessLib.startDictionaryLibProcess("createMockDictionary"); return Dictionary({ addr: address(new MockDictionary(owner, functions)), - kind: DictionaryKind.Mock + kind: DictionaryKind.Mock, + status: TypeStatus.Building }).finishProcess(pid); } diff --git a/devkit/core/types/Proxy.sol b/devkit/core/types/Proxy.sol index 102d86ab..ab59f89e 100644 --- a/devkit/core/types/Proxy.sol +++ b/devkit/core/types/Proxy.sol @@ -10,6 +10,8 @@ import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for ProxyKind global; // Validation import {Require} from "devkit/error/Require.sol";// Core Type +import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; + using TypeGuard for Proxy global; // Mock import {SimpleMockProxy} from "devkit/utils/mocks/SimpleMockProxy.sol"; @@ -28,6 +30,7 @@ using ProxyLib for Proxy global; struct Proxy { address addr; ProxyKind kind; + TypeStatus status; } library ProxyLib { /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -43,7 +46,8 @@ library ProxyLib { Require.isNotEmpty(dictionary); return Proxy({ addr: address(new ERC7546ProxyEtherscan(dictionary.addr, initData)), - kind: ProxyKind.Verifiable + kind: ProxyKind.Verifiable, + status: TypeStatus.Building }).finishProcess(pid); } @@ -54,7 +58,8 @@ library ProxyLib { uint pid = ProcessLib.startProxyLibProcess("createSimpleMockProxy"); return Proxy({ addr: address(new SimpleMockProxy(functions)), - kind: ProxyKind.Mock + kind: ProxyKind.Mock, + status: TypeStatus.Building }).finishProcess(pid); } } diff --git a/devkit/core/types/TypeGuard.sol b/devkit/core/types/TypeGuard.sol index 3ce6d94b..86157181 100644 --- a/devkit/core/types/TypeGuard.sol +++ b/devkit/core/types/TypeGuard.sol @@ -11,6 +11,8 @@ import {Require} from "devkit/error/Require.sol"; // Core Types import {Function} from "devkit/core/types/Function.sol"; import {Bundle} from "devkit/core/types/Bundle.sol"; +import {Dictionary} from "devkit/core/types/Dictionary.sol"; +import {Proxy} from "devkit/core/types/Proxy.sol"; import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; @@ -121,4 +123,44 @@ library TypeGuard { stdFunctions.status = TypeStatus.Locked; return stdFunctions; } + + + /**==================== + 📚 Dictionary + ======================*/ + function building(Dictionary storage dictionary) internal returns(Dictionary storage) { + dictionary.status.building(); + return dictionary; + } + function build(Dictionary storage dictionary) internal returns(Dictionary storage) { + Require.isContract(dictionary.addr); + Require.notUndefined(dictionary.kind); + dictionary.status = TypeStatus.Built; + return dictionary; + } + function lock(Dictionary storage dictionary) internal returns(Dictionary storage) { + Require.isBuilt(dictionary.status); + dictionary.status = TypeStatus.Locked; + return dictionary; + } + + + /**=============== + 🏠 Proxy + =================*/ + function building(Proxy storage proxy) internal returns(Proxy storage) { + proxy.status.building(); + return proxy; + } + function build(Proxy storage proxy) internal returns(Proxy storage) { + Require.isContract(proxy.addr); + Require.notUndefined(proxy.kind); + proxy.status = TypeStatus.Built; + return proxy; + } + function lock(Proxy storage proxy) internal returns(Proxy storage) { + Require.isBuilt(proxy.status); + proxy.status = TypeStatus.Locked; + return proxy; + } } diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index 401da524..a9422adf 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -144,9 +144,11 @@ library Require { return dictionary; } /*---- Dictionary Kind -----*/ - function NotUndefined(DictionaryKind kind) internal returns(DictionaryKind) { + function notUndefined(DictionaryKind kind) internal { + validate(kind.isNotUndefined(), "Undefined Dictionary Kind"); + } + function notUndefined(ProxyKind kind) internal { validate(kind.isNotUndefined(), "Undefined Dictionary Kind"); - return kind; } @@ -160,7 +162,7 @@ library Require { function isUnassigned(bytes4 b4) internal { validate(b4.isEmpty(), ERR.B4_ALREADY_ASSIGNED); } - function isNotEmpty(bytes4 b4) internal { + function notEmpty(bytes4 b4) internal { validate(b4.isNotEmpty(), ERR.EMPTY_B4); } From ae3bf350ef5bde70f985f69288e4576432a1b9db Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 21:46:20 +0900 Subject: [PATCH 073/111] Improve DictionaryRegistry type safety --- devkit/core/registry/DictionaryRegistry.sol | 19 ++++++++++++------- devkit/core/types/Dictionary.sol | 2 +- devkit/core/types/TypeGuard.sol | 3 +++ devkit/error/Require.sol | 9 ++++++++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/devkit/core/registry/DictionaryRegistry.sol b/devkit/core/registry/DictionaryRegistry.sol index 713f1ea0..ab9e30b4 100644 --- a/devkit/core/registry/DictionaryRegistry.sol +++ b/devkit/core/registry/DictionaryRegistry.sol @@ -26,14 +26,17 @@ struct DictionaryRegistry { } library DictionaryRegistryLib { - /**--------------------- - 🚀 Deploy Proxy - -----------------------*/ + /**-------------------------- + 🚀 Deploy Dictionary + ----------------------------*/ function deploy(DictionaryRegistry storage registry, string memory name, Bundle storage bundle, address owner) internal returns(Dictionary storage) { uint pid = registry.startProcess("deploy"); - // Require.isNotEmpty(dictionary); TODO - registry.insert(name, DictionaryLib.deploy(owner)); - registry.findCurrent().set(bundle).upgradeFacade(bundle.facade); + Require.notEmpty(name); + Require.exists(bundle); + Require.notZero(owner); + Dictionary memory dictionary = DictionaryLib.deploy(owner); + dictionary.set(bundle).upgradeFacade(bundle.facade); + registry.insert(name, dictionary); return registry.findCurrent().finishProcessInStorage(pid); } @@ -45,9 +48,10 @@ library DictionaryRegistryLib { uint pid = registry.startProcess("insert"); Require.notEmpty(name); Require.notEmpty(dictionary); + Require.notExists(registry, name); registry.dictionaries[name] = dictionary; registry.current.update(name); - return registry.findCurrent().finishProcessInStorage(pid); + return registry.findCurrent().build().lock().finishProcessInStorage(pid); } @@ -57,6 +61,7 @@ library DictionaryRegistryLib { function find(DictionaryRegistry storage registry, string memory name) internal returns(Dictionary storage) { uint pid = registry.startProcess("find"); Require.notEmpty(name); + Require.isComplete(registry, name); Dictionary storage dictionary = registry.dictionaries[name]; Require.exists(dictionary); return dictionary.finishProcessInStorage(pid); diff --git a/devkit/core/types/Dictionary.sol b/devkit/core/types/Dictionary.sol index 8a9d650f..cf01098f 100644 --- a/devkit/core/types/Dictionary.sol +++ b/devkit/core/types/Dictionary.sol @@ -50,7 +50,7 @@ library DictionaryLib { ---------------------------*/ function deploy(address owner) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("deploy"); - Require.isNotZero(owner); + Require.notZero(owner); /// @dev Until Etherscan supports UCS, we are deploying contracts with additional features for Etherscan compatibility by default. return Dictionary({ addr: address(new DictionaryEtherscan(owner)), diff --git a/devkit/core/types/TypeGuard.sol b/devkit/core/types/TypeGuard.sol index 86157181..c04aca76 100644 --- a/devkit/core/types/TypeGuard.sol +++ b/devkit/core/types/TypeGuard.sol @@ -143,6 +143,9 @@ library TypeGuard { dictionary.status = TypeStatus.Locked; return dictionary; } + function isComplete(Dictionary storage dictionary) internal returns(bool) { + return dictionary.status.isComplete(); + } /**=============== diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index a9422adf..4cb016db 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -151,6 +151,13 @@ library Require { validate(kind.isNotUndefined(), "Undefined Dictionary Kind"); } + function notExists(DictionaryRegistry storage registry, string memory name) internal { + validate(registry.dictionaries[name].notExists(), "Dictionary Already Exists"); + } + function isComplete(DictionaryRegistry storage registry, string memory name) internal { + validate(registry.dictionaries[name].isComplete(), "Dictionary Not Complete"); + } + function isUnassigned(string storage str) internal { validate(str.isEmpty(), ERR.STR_ALREADY_ASSIGNED); @@ -189,7 +196,7 @@ library Require { validate(dictionary.isNotEmpty(), ERR.EMPTY_DICTIONARY); } - function isNotZero(address addr) internal { + function notZero(address addr) internal { validate(addr.isNotZero(), ERR.ZERO_ADDRESS); } From 9bd928474334866122ddadff34c717220a5f4018 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Wed, 10 Apr 2024 22:04:26 +0900 Subject: [PATCH 074/111] Update ProxyRegistry type safety --- devkit/core/registry/ProxyRegistry.sol | 7 +++++-- devkit/core/types/Proxy.sol | 2 +- devkit/core/types/TypeGuard.sol | 3 +++ devkit/error/Require.sol | 8 ++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/devkit/core/registry/ProxyRegistry.sol b/devkit/core/registry/ProxyRegistry.sol index 5de2d565..58da5c75 100644 --- a/devkit/core/registry/ProxyRegistry.sol +++ b/devkit/core/registry/ProxyRegistry.sol @@ -41,12 +41,14 @@ library ProxyRegistryLib { /**--------------------- đŸ—ŗī¸ Insert Proxy -----------------------*/ - function insert(ProxyRegistry storage registry, string memory name, Proxy memory proxy) internal returns(ProxyRegistry storage) { + function insert(ProxyRegistry storage registry, string memory name, Proxy memory proxy) internal returns(Proxy storage) { uint pid = registry.startProcess("insert"); Require.notEmpty(name); Require.notEmpty(proxy); + Require.notExists(registry, name); registry.proxies[name] = proxy; - return registry.finishProcess(pid); + registry.current.update(name); + return registry.findCurrent().build().lock().finishProcessInStorage(pid); } @@ -56,6 +58,7 @@ library ProxyRegistryLib { function find(ProxyRegistry storage registry, string memory name) internal returns(Proxy storage) { uint pid = registry.startProcess("find"); Require.notEmpty(name); + Require.isComplete(registry, name); Proxy storage proxy = registry.proxies[name]; Require.exists(proxy); return proxy.finishProcessInStorage(pid); diff --git a/devkit/core/types/Proxy.sol b/devkit/core/types/Proxy.sol index ab59f89e..f163ea93 100644 --- a/devkit/core/types/Proxy.sol +++ b/devkit/core/types/Proxy.sol @@ -43,7 +43,7 @@ library ProxyLib { -----------------------*/ function deploy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory proxy) { uint pid = ProcessLib.startProxyLibProcess("deploy"); - Require.isNotEmpty(dictionary); + Require.notEmpty(dictionary); return Proxy({ addr: address(new ERC7546ProxyEtherscan(dictionary.addr, initData)), kind: ProxyKind.Verifiable, diff --git a/devkit/core/types/TypeGuard.sol b/devkit/core/types/TypeGuard.sol index c04aca76..11c98d14 100644 --- a/devkit/core/types/TypeGuard.sol +++ b/devkit/core/types/TypeGuard.sol @@ -166,4 +166,7 @@ library TypeGuard { proxy.status = TypeStatus.Locked; return proxy; } + function isComplete(Proxy storage proxy) internal returns(bool) { + return proxy.status.isComplete(); + } } diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index 4cb016db..4f7b3322 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -124,6 +124,14 @@ library Require { return kind; } + function notExists(ProxyRegistry storage registry, string memory name) internal { + validate(registry.proxies[name].notExists(), "Proxy Already Exists"); + } + function isComplete(ProxyRegistry storage registry, string memory name) internal { + validate(registry.proxies[name].isComplete(), "Proxy Not Complete"); + } + + /**==================== 📚 Dictionary ======================*/ From 8608dc2544cf8301ddbf5e69fe43482da2f5ec91 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 10:59:07 +0900 Subject: [PATCH 075/111] Update registry to use type check --- devkit/core/registry/DictionaryRegistry.sol | 6 ++++-- devkit/core/registry/ProxyRegistry.sol | 12 ++++++++++-- test/std/bundles/Std.t.sol | 4 ++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/devkit/core/registry/DictionaryRegistry.sol b/devkit/core/registry/DictionaryRegistry.sol index ab9e30b4..eb414727 100644 --- a/devkit/core/registry/DictionaryRegistry.sol +++ b/devkit/core/registry/DictionaryRegistry.sol @@ -37,7 +37,8 @@ library DictionaryRegistryLib { Dictionary memory dictionary = DictionaryLib.deploy(owner); dictionary.set(bundle).upgradeFacade(bundle.facade); registry.insert(name, dictionary); - return registry.findCurrent().finishProcessInStorage(pid); + return registry.dictionaries[name].finishProcessInStorage(pid); + // return registry.findCurrent().finishProcessInStorage(pid); } @@ -51,7 +52,8 @@ library DictionaryRegistryLib { Require.notExists(registry, name); registry.dictionaries[name] = dictionary; registry.current.update(name); - return registry.findCurrent().build().lock().finishProcessInStorage(pid); + return registry.dictionaries[name].build().lock().finishProcessInStorage(pid); + // return registry.findCurrent().build().lock().finishProcessInStorage(pid); } diff --git a/devkit/core/registry/ProxyRegistry.sol b/devkit/core/registry/ProxyRegistry.sol index 58da5c75..9649f24a 100644 --- a/devkit/core/registry/ProxyRegistry.sol +++ b/devkit/core/registry/ProxyRegistry.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ +import {console2} from "forge-std/console2.sol"; import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for ProxyRegistry global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; @@ -46,9 +47,16 @@ library ProxyRegistryLib { Require.notEmpty(name); Require.notEmpty(proxy); Require.notExists(registry, name); - registry.proxies[name] = proxy; + Proxy storage proxy_ = registry.proxies[name] = proxy; + // proxy_ = proxy; + // registry.proxies[name] = proxy; registry.current.update(name); - return registry.findCurrent().build().lock().finishProcessInStorage(pid); + proxy_.build().lock(); +console2.log(proxy_.addr); +console2.log(uint8(proxy_.kind)); +console2.log(uint8(proxy_.status)); + return proxy_.finishProcessInStorage(pid); + // return proxy_.build().lock().finishProcessInStorage(pid); } diff --git a/test/std/bundles/Std.t.sol b/test/std/bundles/Std.t.sol index e2a67a56..a4a2dbe9 100644 --- a/test/std/bundles/Std.t.sol +++ b/test/std/bundles/Std.t.sol @@ -10,9 +10,13 @@ import {Clone} from "mc-std/functions/Clone.sol"; contract StdTest is MCDevKitTest { using DeployLib for MCDevKit; function setUp() public { +mc.startDebug(); } function test_Success_DeployStdFunctions() public startPrankWith("TEST_DEPLOYER") { mc.deployStdFunctions(); + mc.std.complete(); + // mc.init("STD").use(mc.std.functions.initSetAdmin).deploy(); + mc.deploy("STD", mc.std.all, deployer, ""); } } From 19a54ababf712d392f407f556440cff352357be0 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 11:05:05 +0900 Subject: [PATCH 076/111] Move & Rename mocks --- devkit/core/types/Dictionary.sol | 4 ++-- devkit/core/types/Proxy.sol | 4 ++-- .../MockDictionary.sol => mocks/DictionaryMock.sol} | 4 +++- .../ProxySimpleMock.sol} | 12 ++++++------ 4 files changed, 13 insertions(+), 11 deletions(-) rename devkit/{utils/mocks/MockDictionary.sol => mocks/DictionaryMock.sol} (84%) rename devkit/{utils/mocks/SimpleMockProxy.sol => mocks/ProxySimpleMock.sol} (83%) diff --git a/devkit/core/types/Dictionary.sol b/devkit/core/types/Dictionary.sol index cf01098f..3b4c8d98 100644 --- a/devkit/core/types/Dictionary.sol +++ b/devkit/core/types/Dictionary.sol @@ -18,7 +18,7 @@ import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; using TypeGuard for Dictionary global; // Mock -import {MockDictionary} from "devkit/utils/mocks/MockDictionary.sol"; +import {DictionaryMock} from "devkit/mocks/DictionaryMock.sol"; // External Libs import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; @@ -138,7 +138,7 @@ library DictionaryLib { function createMockDictionary(address owner, Function[] memory functions) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("createMockDictionary"); return Dictionary({ - addr: address(new MockDictionary(owner, functions)), + addr: address(new DictionaryMock(owner, functions)), kind: DictionaryKind.Mock, status: TypeStatus.Building }).finishProcess(pid); diff --git a/devkit/core/types/Proxy.sol b/devkit/core/types/Proxy.sol index f163ea93..d9b32695 100644 --- a/devkit/core/types/Proxy.sol +++ b/devkit/core/types/Proxy.sol @@ -14,7 +14,7 @@ import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; using TypeGuard for Proxy global; // Mock -import {SimpleMockProxy} from "devkit/utils/mocks/SimpleMockProxy.sol"; +import {ProxySimpleMock} from "devkit/mocks/ProxySimpleMock.sol"; // External Lib import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; @@ -57,7 +57,7 @@ library ProxyLib { function createSimpleMockProxy(Function[] memory functions) internal returns(Proxy memory) { uint pid = ProcessLib.startProxyLibProcess("createSimpleMockProxy"); return Proxy({ - addr: address(new SimpleMockProxy(functions)), + addr: address(new ProxySimpleMock(functions)), kind: ProxyKind.Mock, status: TypeStatus.Building }).finishProcess(pid); diff --git a/devkit/utils/mocks/MockDictionary.sol b/devkit/mocks/DictionaryMock.sol similarity index 84% rename from devkit/utils/mocks/MockDictionary.sol rename to devkit/mocks/DictionaryMock.sol index 74bc3391..b4900f55 100644 --- a/devkit/utils/mocks/MockDictionary.sol +++ b/devkit/mocks/DictionaryMock.sol @@ -9,10 +9,12 @@ import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; /** @title Mock Dictionary Contract */ -contract MockDictionary is DictionaryEtherscan { +contract DictionaryMock is DictionaryEtherscan { constructor (address owner, Function[] memory functions) DictionaryEtherscan(owner) { for (uint i; i < functions.length; ++i) { setImplementation(functions[i].selector, functions[i].implementation); } } } + +// TODO DictionaryWithPermissionsMock.sol diff --git a/devkit/utils/mocks/SimpleMockProxy.sol b/devkit/mocks/ProxySimpleMock.sol similarity index 83% rename from devkit/utils/mocks/SimpleMockProxy.sol rename to devkit/mocks/ProxySimpleMock.sol index 98bb3d8c..c2dd8fb8 100644 --- a/devkit/utils/mocks/SimpleMockProxy.sol +++ b/devkit/mocks/ProxySimpleMock.sol @@ -9,10 +9,10 @@ import {Proxy as OZProxy} from "@oz.mc/proxy/Proxy.sol"; /** @title Mock Proxy Contract */ -contract SimpleMockProxy is OZProxy { +contract ProxySimpleMock is OZProxy { constructor (Function[] memory functions) { for (uint i; i < functions.length; ++i) { - SimpleMockProxyLib.set({ + ProxySimpleMockLib.set({ selector: functions[i].selector, implementation: functions[i].implementation }); @@ -20,17 +20,17 @@ contract SimpleMockProxy is OZProxy { } function _implementation() internal view override returns(address) { - return SimpleMockProxyLib.getImplementation(msg.sig); + return ProxySimpleMockLib.getImplementation(msg.sig); } } -library SimpleMockProxyLib { +library ProxySimpleMockLib { bytes32 internal constant STORAGE_LOCATION = 0x64a9f0903a8f864d59bc40808555c0090d6ada027fd81884feeb2af9acdbc200; /// @custom:storage-location erc7021:mc.mock.proxy - struct SimpleMockProxyStorage { + struct ProxySimpleMockStorage { mapping(bytes4 selector => address) implementations; } - function Storage() internal pure returns(SimpleMockProxyStorage storage ref) { assembly { ref.slot := STORAGE_LOCATION } } + function Storage() internal pure returns(ProxySimpleMockStorage storage ref) { assembly { ref.slot := STORAGE_LOCATION } } function set(bytes4 selector, address implementation) internal { Storage().implementations[selector] = implementation; From 248391c3083302555bd6027ea5bd83ab529f92fd Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 12:17:57 +0900 Subject: [PATCH 077/111] Update ProxyRegistry & DictionaryRegistry --- devkit/core/method/global/MCDeployLib.sol | 6 +-- devkit/core/method/global/MCTestLib.sol | 4 +- devkit/core/registry/DictionaryRegistry.sol | 43 ++++++++++----------- devkit/core/registry/ProxyRegistry.sol | 43 +++++++++------------ devkit/error/Require.sol | 24 +++++++++--- 5 files changed, 64 insertions(+), 56 deletions(-) diff --git a/devkit/core/method/global/MCDeployLib.sol b/devkit/core/method/global/MCDeployLib.sol index e40e2e3c..15da7a99 100644 --- a/devkit/core/method/global/MCDeployLib.sol +++ b/devkit/core/method/global/MCDeployLib.sol @@ -74,7 +74,7 @@ library MCDeployLib { function deployProxy(MCDevKit storage mc, string memory name, Dictionary memory dictionary, bytes memory initData) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("deployProxy", Params.append(dictionary.addr, initData)); Proxy memory proxy = ProxyLib.deploy(dictionary, initData); - mc.proxy.insert(name, proxy); + mc.proxy.register(name, proxy); return mc.recordExecFinish(pid); } function deployProxy(MCDevKit storage mc, string memory name, Dictionary storage dictionary, address owner) internal returns(MCDevKit storage) { @@ -105,7 +105,7 @@ library MCDeployLib { Dictionary memory dictionary = DictionaryLib .deploy(owner) .set(bundleInfo) .upgradeFacade(bundleInfo.facade); - mc.dictionary.insert(name, dictionary); + mc.dictionary.register(name, dictionary); return dictionary.finishProcess(pid); } @@ -138,7 +138,7 @@ library MCDeployLib { function duplicateDictionary(MCDevKit storage mc, string memory name, Dictionary storage targetDictionary) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("duplicateDictionary", Params.append(name, targetDictionary.addr)); Dictionary memory newDictionary = targetDictionary.duplicate(); - mc.dictionary.insert(name, newDictionary); + mc.dictionary.register(name, newDictionary); return mc.recordExecFinish(pid); } function duplicateDictionary(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { diff --git a/devkit/core/method/global/MCTestLib.sol b/devkit/core/method/global/MCTestLib.sol index 02b01989..788cb10e 100644 --- a/devkit/core/method/global/MCTestLib.sol +++ b/devkit/core/method/global/MCTestLib.sol @@ -40,7 +40,7 @@ library MCTestLib { // } TODO uint pid = mc.recordExecStart("createSimpleMockProxy", params); Proxy memory simpleMockProxy = ProxyLib.createSimpleMockProxy(functions); - mc.proxy.insert(name, simpleMockProxy); + mc.proxy.register(name, simpleMockProxy); return mc.recordExecFinish(pid); } function createSimpleMockProxy(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(MCDevKit storage) { @@ -69,7 +69,7 @@ library MCTestLib { function createMockDictionary(MCDevKit storage mc, string memory name, address owner, Function[] memory functions) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("createMockDictionary", Params.append(name, owner)); Dictionary memory mockDictionary = DictionaryLib.createMockDictionary(owner, functions); - mc.dictionary.insert(name, mockDictionary); + mc.dictionary.register(name, mockDictionary); return mc.recordExecFinish(pid); } function createMockDictionary(MCDevKit storage mc, string memory name, address owner, Bundle storage bundleInfo) internal returns(MCDevKit storage) { diff --git a/devkit/core/registry/DictionaryRegistry.sol b/devkit/core/registry/DictionaryRegistry.sol index eb414727..80911a0e 100644 --- a/devkit/core/registry/DictionaryRegistry.sol +++ b/devkit/core/registry/DictionaryRegistry.sol @@ -7,13 +7,14 @@ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for DictionaryRegistry global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for DictionaryRegistry global; +// Validation +import {Require} from "devkit/error/Require.sol"; -// Context -import {Current} from "devkit/core/method/context/Current.sol"; // Core Type import {Dictionary, DictionaryLib} from "devkit/core/types/Dictionary.sol"; import {Bundle} from "devkit/core/types/Bundle.sol"; -import {Require} from "devkit/error/Require.sol"; +// Context +import {Current} from "devkit/core/method/context/Current.sol"; /**============================ @@ -26,46 +27,44 @@ struct DictionaryRegistry { } library DictionaryRegistryLib { - /**-------------------------- - 🚀 Deploy Dictionary - ----------------------------*/ + /**------------------------------------- + 🚀 Deploy & Register Dictionary + ---------------------------------------*/ function deploy(DictionaryRegistry storage registry, string memory name, Bundle storage bundle, address owner) internal returns(Dictionary storage) { uint pid = registry.startProcess("deploy"); Require.notEmpty(name); Require.exists(bundle); Require.notZero(owner); - Dictionary memory dictionary = DictionaryLib.deploy(owner); - dictionary.set(bundle).upgradeFacade(bundle.facade); - registry.insert(name, dictionary); - return registry.dictionaries[name].finishProcessInStorage(pid); - // return registry.findCurrent().finishProcessInStorage(pid); + Dictionary memory dictionary = DictionaryLib.deploy(owner) + .set(bundle) + .upgradeFacade(bundle.facade); + registry.register(name, dictionary); + return registry.findCurrent().finishProcessInStorage(pid); } - /**--------------------------- - đŸ—ŗī¸ Insert Dictionary + đŸ—ŗī¸ Register Dictionary -----------------------------*/ - function insert(DictionaryRegistry storage registry, string memory name, Dictionary memory dictionary) internal returns(Dictionary storage) { - uint pid = registry.startProcess("insert"); + function register(DictionaryRegistry storage registry, string memory name, Dictionary memory dictionary) internal returns(Dictionary storage) { + uint pid = registry.startProcess("register"); Require.notEmpty(name); Require.notEmpty(dictionary); - Require.notExists(registry, name); - registry.dictionaries[name] = dictionary; + Require.notRegistered(registry, name); + Dictionary storage dictionaryStorage = registry.dictionaries[name] = dictionary; + dictionaryStorage.build().lock(); registry.current.update(name); - return registry.dictionaries[name].build().lock().finishProcessInStorage(pid); - // return registry.findCurrent().build().lock().finishProcessInStorage(pid); + return dictionaryStorage.finishProcessInStorage(pid); } - /**------------------------ 🔍 Find Dictionary --------------------------*/ function find(DictionaryRegistry storage registry, string memory name) internal returns(Dictionary storage) { uint pid = registry.startProcess("find"); Require.notEmpty(name); - Require.isComplete(registry, name); + Require.validRegistration(registry, name); Dictionary storage dictionary = registry.dictionaries[name]; - Require.exists(dictionary); + Require.valid(dictionary); return dictionary.finishProcessInStorage(pid); } function findCurrent(DictionaryRegistry storage registry) internal returns(Dictionary storage) { diff --git a/devkit/core/registry/ProxyRegistry.sol b/devkit/core/registry/ProxyRegistry.sol index 9649f24a..b0289e9d 100644 --- a/devkit/core/registry/ProxyRegistry.sol +++ b/devkit/core/registry/ProxyRegistry.sol @@ -3,18 +3,18 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {console2} from "forge-std/console2.sol"; import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for ProxyRegistry global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for ProxyRegistry global; +// Validation import {Require} from "devkit/error/Require.sol"; -// Context -import {Current} from "devkit/core/method/context/Current.sol"; // Core Type import {Proxy, ProxyLib} from "devkit/core/types/Proxy.sol"; import {Dictionary} from "devkit/core/types/Dictionary.sol"; +// Context +import {Current} from "devkit/core/method/context/Current.sol"; /**======================= @@ -27,36 +27,31 @@ struct ProxyRegistry { } library ProxyRegistryLib { - /**--------------------- - 🚀 Deploy Proxy - -----------------------*/ + /**------------------------------- + 🚀 Deploy & Register Proxy + ---------------------------------*/ function deploy(ProxyRegistry storage registry, string memory name, Dictionary memory dictionary, bytes memory initData) internal returns(Proxy storage) { uint pid = registry.startProcess("deploy"); Require.notEmpty(name); Require.isNotEmpty(dictionary); - registry.insert(name, ProxyLib.deploy(dictionary, initData)); + Proxy memory proxy = ProxyLib.deploy(dictionary, initData); + registry.register(name, proxy); return registry.findCurrent().finishProcessInStorage(pid); } - /**--------------------- - đŸ—ŗī¸ Insert Proxy - -----------------------*/ - function insert(ProxyRegistry storage registry, string memory name, Proxy memory proxy) internal returns(Proxy storage) { - uint pid = registry.startProcess("insert"); + /**----------------------- + đŸ—ŗī¸ Register Proxy + -------------------------*/ + function register(ProxyRegistry storage registry, string memory name, Proxy memory proxy) internal returns(Proxy storage) { + uint pid = registry.startProcess("register"); Require.notEmpty(name); Require.notEmpty(proxy); - Require.notExists(registry, name); - Proxy storage proxy_ = registry.proxies[name] = proxy; - // proxy_ = proxy; - // registry.proxies[name] = proxy; + Require.notRegistered(registry, name); + Proxy storage proxyStorage = registry.proxies[name] = proxy; + proxyStorage.build().lock(); registry.current.update(name); - proxy_.build().lock(); -console2.log(proxy_.addr); -console2.log(uint8(proxy_.kind)); -console2.log(uint8(proxy_.status)); - return proxy_.finishProcessInStorage(pid); - // return proxy_.build().lock().finishProcessInStorage(pid); + return proxyStorage.finishProcessInStorage(pid); } @@ -66,9 +61,9 @@ console2.log(uint8(proxy_.status)); function find(ProxyRegistry storage registry, string memory name) internal returns(Proxy storage) { uint pid = registry.startProcess("find"); Require.notEmpty(name); - Require.isComplete(registry, name); + Require.validRegistration(registry, name); Proxy storage proxy = registry.proxies[name]; - Require.exists(proxy); + Require.valid(proxy); return proxy.finishProcessInStorage(pid); } function findCurrent(ProxyRegistry storage registry) internal returns(Proxy storage) { diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index 4f7b3322..3553b45a 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -114,6 +114,13 @@ library Require { validate(proxy.exists(), "Proxy Not Exist"); return proxy; } + function isComplete(Proxy storage proxy) internal { + validate(proxy.isComplete(), "Proxy Not Complete"); + } + function valid(Proxy storage proxy) internal { + exists(proxy); + isComplete(proxy); + } function notEmpty(Proxy memory proxy) internal returns(Proxy memory) { validate(proxy.isNotEmpty(), "Empty Proxy"); return proxy; @@ -124,10 +131,10 @@ library Require { return kind; } - function notExists(ProxyRegistry storage registry, string memory name) internal { + function notRegistered(ProxyRegistry storage registry, string memory name) internal { validate(registry.proxies[name].notExists(), "Proxy Already Exists"); } - function isComplete(ProxyRegistry storage registry, string memory name) internal { + function validRegistration(ProxyRegistry storage registry, string memory name) internal { validate(registry.proxies[name].isComplete(), "Proxy Not Complete"); } @@ -139,6 +146,13 @@ library Require { validate(dictionary.exists(), "Dictionary Not Exists"); return dictionary; } + function isComplete(Dictionary storage dictionary) internal { + validate(dictionary.isComplete(), "Dictionary Not Complete"); + } + function valid(Dictionary storage dictionary) internal { + exists(dictionary); + isComplete(dictionary); + } function notEmpty(Dictionary memory dictionary) internal returns(Dictionary memory) { validate(dictionary.isNotEmpty(), "Empty Dictionary"); return dictionary; @@ -159,11 +173,11 @@ library Require { validate(kind.isNotUndefined(), "Undefined Dictionary Kind"); } - function notExists(DictionaryRegistry storage registry, string memory name) internal { + function notRegistered(DictionaryRegistry storage registry, string memory name) internal { validate(registry.dictionaries[name].notExists(), "Dictionary Already Exists"); } - function isComplete(DictionaryRegistry storage registry, string memory name) internal { - validate(registry.dictionaries[name].isComplete(), "Dictionary Not Complete"); + function validRegistration(DictionaryRegistry storage registry, string memory name) internal { + validate(registry.dictionaries[name].isComplete(), "Dictionary Not Registered"); } From c1c8394356183d1d7b4475f304f56db77c4127c9 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 12:30:33 +0900 Subject: [PATCH 078/111] chore update proxy & registry --- devkit/core/registry/ProxyRegistry.sol | 2 -- devkit/core/types/Proxy.sol | 17 +++++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/devkit/core/registry/ProxyRegistry.sol b/devkit/core/registry/ProxyRegistry.sol index b0289e9d..caebfedd 100644 --- a/devkit/core/registry/ProxyRegistry.sol +++ b/devkit/core/registry/ProxyRegistry.sol @@ -39,7 +39,6 @@ library ProxyRegistryLib { return registry.findCurrent().finishProcessInStorage(pid); } - /**----------------------- đŸ—ŗī¸ Register Proxy -------------------------*/ @@ -54,7 +53,6 @@ library ProxyRegistryLib { return proxyStorage.finishProcessInStorage(pid); } - /**------------------- 🔍 Find Proxy ---------------------*/ diff --git a/devkit/core/types/Proxy.sol b/devkit/core/types/Proxy.sol index d9b32695..58dcf7f5 100644 --- a/devkit/core/types/Proxy.sol +++ b/devkit/core/types/Proxy.sol @@ -13,10 +13,10 @@ import {Require} from "devkit/error/Require.sol";// Core Type import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; using TypeGuard for Proxy global; -// Mock -import {ProxySimpleMock} from "devkit/mocks/ProxySimpleMock.sol"; -// External Lib +// External Lib Contract import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; +// Mock Contract +import {ProxySimpleMock} from "devkit/mocks/ProxySimpleMock.sol"; // Core Types import {Dictionary} from "devkit/core/types/Dictionary.sol"; @@ -33,15 +33,11 @@ struct Proxy { TypeStatus status; } library ProxyLib { - /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🚀 Deploy Proxy - 🤖 Create Mock Proxy - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /**--------------------- 🚀 Deploy Proxy -----------------------*/ - function deploy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory proxy) { + function deploy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory) { uint pid = ProcessLib.startProxyLibProcess("deploy"); Require.notEmpty(dictionary); return Proxy({ @@ -54,14 +50,15 @@ library ProxyLib { /**-------------------------- 🤖 Create Mock Proxy ----------------------------*/ - function createSimpleMockProxy(Function[] memory functions) internal returns(Proxy memory) { - uint pid = ProcessLib.startProxyLibProcess("createSimpleMockProxy"); + function createProxySimpleMock(Function[] memory functions) internal returns(Proxy memory) { + uint pid = ProcessLib.startProxyLibProcess("createProxySimpleMock"); return Proxy({ addr: address(new ProxySimpleMock(functions)), kind: ProxyKind.Mock, status: TypeStatus.Building }).finishProcess(pid); } + } From dedea04da9d1d506dd67d4466cf86a7afe794e4a Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 13:25:46 +0900 Subject: [PATCH 079/111] Remove MockRegistry --- devkit/MCDevKit.sol | 2 - devkit/core/method/debug/ProcessLib.sol | 17 ----- devkit/core/method/global/MCFinderLib.sol | 6 +- devkit/core/method/global/MCTestLib.sol | 5 +- devkit/core/registry/MockRegistry.sol | 83 ----------------------- 5 files changed, 6 insertions(+), 107 deletions(-) delete mode 100644 devkit/core/registry/MockRegistry.sol diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index 73730137..86c254a5 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -7,7 +7,6 @@ import {FunctionRegistry} from "devkit/core/registry/FunctionRegistry.sol"; import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; -import {MockRegistry} from "devkit/core/registry/MockRegistry.sol"; // Global Methods import {MCSetupLib} from "devkit/core/method/global/MCSetupLib.sol"; @@ -28,7 +27,6 @@ struct MCDevKit { BundleRegistry bundle; DictionaryRegistry dictionary; ProxyRegistry proxy; - MockRegistry mock; } using MCSetupLib for MCDevKit global; using MCBundleLib for MCDevKit global; diff --git a/devkit/core/method/debug/ProcessLib.sol b/devkit/core/method/debug/ProcessLib.sol index 4964db53..2d4103bc 100644 --- a/devkit/core/method/debug/ProcessLib.sol +++ b/devkit/core/method/debug/ProcessLib.sol @@ -13,7 +13,6 @@ import {Proxy} from "devkit/core/types/Proxy.sol"; import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; import {Dictionary} from "devkit/core/types/Dictionary.sol"; import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; -import {MockRegistry} from "devkit/core/registry/MockRegistry.sol"; import {Current} from "devkit/core/method/context/Current.sol"; @@ -190,22 +189,6 @@ library ProcessLib { } - /**--------------------- - 🏭 Mock Registry - -----------------------*/ - function startProcess(MockRegistry storage, string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("MockRegistryLib", name, params); - } - function startProcess(MockRegistry storage mock, string memory name) internal returns(uint) { - return mock.startProcess(name, ""); - } - - function finishProcess(MockRegistry storage mock, uint pid) internal returns(MockRegistry storage) { - Debug.recordExecFinish(pid); - return mock; - } - - /**------------------------ 📸 Current Context --------------------------*/ diff --git a/devkit/core/method/global/MCFinderLib.sol b/devkit/core/method/global/MCFinderLib.sol index b97a40c6..8736003d 100644 --- a/devkit/core/method/global/MCFinderLib.sol +++ b/devkit/core/method/global/MCFinderLib.sol @@ -75,9 +75,9 @@ library MCFinderLib { function findDictionary(MCDevKit storage mc, string memory name) internal returns(Dictionary storage) { return mc.dictionary.find(name); } - function findMockDictionary(MCDevKit storage mc, string memory name) internal returns(Dictionary storage) { - return mc.mock.findMockDictionary(name); - } + // function findMockDictionary(MCDevKit storage mc, string memory name) internal returns(Dictionary storage) { + // return mc.mock.findMockDictionary(name); + // } function toDictionaryAddress(MCDevKit storage mc) internal returns(address) { return mc.findCurrentDictionary().addr; diff --git a/devkit/core/method/global/MCTestLib.sol b/devkit/core/method/global/MCTestLib.sol index 788cb10e..0c3315fa 100644 --- a/devkit/core/method/global/MCTestLib.sol +++ b/devkit/core/method/global/MCTestLib.sol @@ -22,8 +22,9 @@ import {Dictionary, DictionaryLib} from "devkit/core/types/Dictionary.sol"; 🤲 Set Storage Reader *******************************************/ library MCTestLib { - string constant LIB_NAME = "MCTestLib"; + function createMock(MCDevKit storage mc, Bundle storage bundle) internal {} + function createMock(MCDevKit storage mc, Function storage func) internal {} /**--------------------- 🏠 Mocking Proxy @@ -39,7 +40,7 @@ library MCTestLib { // params = params.comma().append(functions[i].name); // } TODO uint pid = mc.recordExecStart("createSimpleMockProxy", params); - Proxy memory simpleMockProxy = ProxyLib.createSimpleMockProxy(functions); + Proxy memory simpleMockProxy = ProxyLib.createProxySimpleMock(functions); mc.proxy.register(name, simpleMockProxy); return mc.recordExecFinish(pid); } diff --git a/devkit/core/registry/MockRegistry.sol b/devkit/core/registry/MockRegistry.sol deleted file mode 100644 index 06c3efdf..00000000 --- a/devkit/core/registry/MockRegistry.sol +++ /dev/null @@ -1,83 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Core Types -import {Proxy} from "devkit/core/types/Proxy.sol"; -import {Dictionary} from "devkit/core/types/Dictionary.sol"; -// Support Methods -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; - using ProcessLib for MockRegistry global; -import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; - using Inspector for MockRegistry global; -import {Require} from "devkit/error/Require.sol"; -import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; - using MappingAnalyzer for mapping(string => Dictionary); - using MappingAnalyzer for mapping(string => Proxy); - - -/**====================== - 🏭 Mock Registry -========================*/ -using MockRegistryLib for MockRegistry global; -struct MockRegistry { - mapping(string name => Proxy) proxy; - mapping(string name => Dictionary) dictionary; -} -library MockRegistryLib { - /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - đŸ“Ĩ Add - Mock Dictionary - Mock Proxy - 🔍 Find - Mock Dictionary - Mock Proxy - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - - /**------------- - đŸ“Ĩ Add - ---------------*/ - /*----- Mock Dictionary -----*/ - function add(MockRegistry storage mock, string memory name, Dictionary memory dictionary) internal returns(MockRegistry storage) { - uint pid = mock.startProcess("add"); - Require.notEmpty(name); - Require.notEmpty(dictionary); - mock.dictionary[name] = dictionary; - return mock.finishProcess(pid); - } - function add(MockRegistry storage mock, Dictionary memory dictionary) internal returns(MockRegistry storage) { - return add(mock, mock.dictionary.genUniqueMockName(), dictionary); - } - - /*----- Mock Proxy -----*/ - function add(MockRegistry storage mock, string memory name, Proxy memory proxy) internal returns(MockRegistry storage) { - uint pid = mock.startProcess("add"); - Require.notEmpty(name); - Require.notEmpty(proxy); - mock.proxy[name] = proxy; - return mock.finishProcess(pid); - } - function add(MockRegistry storage mock, Proxy memory proxy) internal returns(MockRegistry storage) { - return add(mock, mock.proxy.genUniqueMockName(), proxy); - } - - - /**-------------- - 🔍 Find - ----------------*/ - /*----- Mock Dictionary -----*/ - function findMockDictionary(MockRegistry storage mock, string memory name) internal returns(Dictionary storage) { - uint pid = mock.startProcess("findMockDictionary"); - Require.notEmpty(name); - Require.exists(mock.dictionary[name]); - return mock.dictionary[name].finishProcessInStorage(pid); - } - - /*----- Mock Proxy -----*/ - function findMockProxy(MockRegistry storage mock, string memory name) internal returns(Proxy storage) { - uint pid = mock.startProcess("findMockProxy"); - Require.notEmpty(name); - Require.exists(mock.proxy[name]); - return mock.proxy[name].finishProcessInStorage(pid); - } - -} From b7d75fcdc3e598111c0b90be27b0ad299805e076 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 14:13:06 +0900 Subject: [PATCH 080/111] Update create mock proxy&dictionary --- devkit/core/method/global/MCTestLib.sol | 54 ++++++++++++--------- devkit/core/registry/BundleRegistry.sol | 4 +- devkit/core/registry/DictionaryRegistry.sol | 12 +++++ devkit/core/registry/ProxyRegistry.sol | 14 +++++- devkit/core/types/Dictionary.sol | 6 +-- devkit/core/types/Proxy.sol | 6 +-- 6 files changed, 63 insertions(+), 33 deletions(-) diff --git a/devkit/core/method/global/MCTestLib.sol b/devkit/core/method/global/MCTestLib.sol index 0c3315fa..36ad4323 100644 --- a/devkit/core/method/global/MCTestLib.sol +++ b/devkit/core/method/global/MCTestLib.sol @@ -1,5 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; +// Validation +import {Require} from "devkit/error/Require.sol"; import {MCDevKit} from "devkit/MCDevKit.sol"; import {Config} from "devkit/config/Config.sol"; @@ -17,15 +19,19 @@ import {Dictionary, DictionaryLib} from "devkit/core/types/Dictionary.sol"; /****************************************** đŸ§Ē Test + 🌞 Mocking Meta Contract 🏠 Mocking Proxy 📚 Mocking Dictionary 🤲 Set Storage Reader *******************************************/ library MCTestLib { - + /**----------------------------- + 🌞 Mocking Meta Contract + -------------------------------*/ function createMock(MCDevKit storage mc, Bundle storage bundle) internal {} function createMock(MCDevKit storage mc, Function storage func) internal {} + /**--------------------- 🏠 Mocking Proxy -----------------------*/ @@ -34,28 +40,26 @@ library MCTestLib { @param name The name of the MockProxy, used as a key in the `mc.test.mockProxies` mapping and as a label name in the Forge test runner. If not provided, sequential default names from `MockProxy0` to `MockProxy4` will be used. @param functions The function contract infos to be registered with the SimpleMockProxy. A bundle can also be specified. Note that the SimpleMockProxy cannot have its functions changed later. If no functions are provided, defaultBundle will be used. */ - function createSimpleMockProxy(MCDevKit storage mc, string memory name, Function[] memory functions) internal returns(MCDevKit storage) { - string memory params = Params.append(name); - // for (uint i; i < functions.length; ++i) { - // params = params.comma().append(functions[i].name); - // } TODO - uint pid = mc.recordExecStart("createSimpleMockProxy", params); - Proxy memory simpleMockProxy = ProxyLib.createProxySimpleMock(functions); - mc.proxy.register(name, simpleMockProxy); + function createProxySimpleMock(MCDevKit storage mc, string memory name, Function[] memory functions) internal returns(MCDevKit storage) { + uint pid = mc.recordExecStart("createProxySimpleMock", Params.append(name)); // TODO append functions + Require.notEmpty(name); + // TODO Check Functions? + Proxy memory proxyMock = ProxyLib.createSimpleMock(functions); + mc.proxy.register(name, proxyMock); return mc.recordExecFinish(pid); } - function createSimpleMockProxy(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(MCDevKit storage) { - return mc.createSimpleMockProxy(name, bundleInfo.functions); + function createProxySimpleMock(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(MCDevKit storage) { + return createProxySimpleMock(mc, name, bundleInfo.functions); + } + function createProxySimpleMock(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { + return createProxySimpleMock(mc, name, mc.std.all); } - function createSimpleMockProxy(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - return mc.createSimpleMockProxy(name, mc.std.all); + function createProxySimpleMock(MCDevKit storage mc, Function[] memory functions) internal returns(MCDevKit storage) { + return createProxySimpleMock(mc, mc.proxy.genUniqueMockName(), functions); + } + function createProxySimpleMock(MCDevKit storage mc) internal returns(MCDevKit storage) { + return createProxySimpleMock(mc, mc.proxy.genUniqueMockName(), mc.std.all); } - // function createSimpleMockProxy(MCDevKit storage mc, Function[] memory functions) internal returns(MCDevKit storage) { - // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), functions); - // } - // function createSimpleMockProxy(MCDevKit storage mc) internal returns(MCDevKit storage) { - // return mc.createSimpleMockProxy(mc.proxy.genUniqueMockName(), mc.std.all); - // } /**------------------------- @@ -69,8 +73,10 @@ library MCTestLib { */ function createMockDictionary(MCDevKit storage mc, string memory name, address owner, Function[] memory functions) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("createMockDictionary", Params.append(name, owner)); - Dictionary memory mockDictionary = DictionaryLib.createMockDictionary(owner, functions); - mc.dictionary.register(name, mockDictionary); + Require.notEmpty(name); + // TODO Check Functions? + Dictionary memory dictionaryMock = DictionaryLib.createMock(owner, functions); + mc.dictionary.register(name, dictionaryMock); return mc.recordExecFinish(pid); } function createMockDictionary(MCDevKit storage mc, string memory name, address owner, Bundle storage bundleInfo) internal returns(MCDevKit storage) { @@ -82,9 +88,9 @@ library MCTestLib { function createMockDictionary(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { return mc.createMockDictionary(name, Config().defaultOwner(), mc.std.all); } - // function createMockDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { - // return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), Config().defaultOwner(), mc.std.all); - // } + function createMockDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { + return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), Config().defaultOwner(), mc.std.all); + } /**-------------------------- diff --git a/devkit/core/registry/BundleRegistry.sol b/devkit/core/registry/BundleRegistry.sol index 4714da81..2d719158 100644 --- a/devkit/core/registry/BundleRegistry.sol +++ b/devkit/core/registry/BundleRegistry.sol @@ -67,8 +67,8 @@ library BundleRegistryLib { /**----------------------------- 🏷 Generate Unique Name -------------------------------*/ - function genUniqueName(BundleRegistry storage bundle) internal returns(string memory name) { - return bundle.bundles.genUniqueName(); + function genUniqueName(BundleRegistry storage registry) internal returns(string memory name) { + return registry.bundles.genUniqueName(); } } diff --git a/devkit/core/registry/DictionaryRegistry.sol b/devkit/core/registry/DictionaryRegistry.sol index 80911a0e..05dc6431 100644 --- a/devkit/core/registry/DictionaryRegistry.sol +++ b/devkit/core/registry/DictionaryRegistry.sol @@ -7,6 +7,8 @@ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for DictionaryRegistry global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for DictionaryRegistry global; +import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; + using MappingAnalyzer for mapping(string => Dictionary); // Validation import {Require} from "devkit/error/Require.sol"; @@ -74,4 +76,14 @@ library DictionaryRegistryLib { return registry.find(name).finishProcessInStorage(pid); } + /**----------------------------- + 🏷 Generate Unique Name + -------------------------------*/ + function genUniqueName(DictionaryRegistry storage registry) internal returns(string memory name) { + return registry.dictionaries.genUniqueName(); + } + function genUniqueMockName(DictionaryRegistry storage registry) internal returns(string memory name) { + return registry.dictionaries.genUniqueMockName(); + } + } diff --git a/devkit/core/registry/ProxyRegistry.sol b/devkit/core/registry/ProxyRegistry.sol index caebfedd..ec414c25 100644 --- a/devkit/core/registry/ProxyRegistry.sol +++ b/devkit/core/registry/ProxyRegistry.sol @@ -7,6 +7,8 @@ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for ProxyRegistry global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for ProxyRegistry global; +import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; + using MappingAnalyzer for mapping(string => Proxy); // Validation import {Require} from "devkit/error/Require.sol"; @@ -33,7 +35,7 @@ library ProxyRegistryLib { function deploy(ProxyRegistry storage registry, string memory name, Dictionary memory dictionary, bytes memory initData) internal returns(Proxy storage) { uint pid = registry.startProcess("deploy"); Require.notEmpty(name); - Require.isNotEmpty(dictionary); + Require.notEmpty(dictionary); Proxy memory proxy = ProxyLib.deploy(dictionary, initData); registry.register(name, proxy); return registry.findCurrent().finishProcessInStorage(pid); @@ -71,4 +73,14 @@ library ProxyRegistryLib { return registry.find(name).finishProcessInStorage(pid); } + /**----------------------------- + 🏷 Generate Unique Name + -------------------------------*/ + function genUniqueName(ProxyRegistry storage registry) internal returns(string memory name) { + return registry.proxies.genUniqueName(); + } + function genUniqueMockName(ProxyRegistry storage registry) internal returns(string memory name) { + return registry.proxies.genUniqueMockName(); + } + } diff --git a/devkit/core/types/Dictionary.sol b/devkit/core/types/Dictionary.sol index 3b4c8d98..73308037 100644 --- a/devkit/core/types/Dictionary.sol +++ b/devkit/core/types/Dictionary.sol @@ -133,10 +133,10 @@ library DictionaryLib { /**------------------------------ - 🤖 Create Mock Dictionary + 🤖 Create Dictionary Mock --------------------------------*/ - function createMockDictionary(address owner, Function[] memory functions) internal returns(Dictionary memory) { - uint pid = ProcessLib.startDictionaryLibProcess("createMockDictionary"); + function createMock(address owner, Function[] memory functions) internal returns(Dictionary memory) { + uint pid = ProcessLib.startDictionaryLibProcess("createMock"); return Dictionary({ addr: address(new DictionaryMock(owner, functions)), kind: DictionaryKind.Mock, diff --git a/devkit/core/types/Proxy.sol b/devkit/core/types/Proxy.sol index 58dcf7f5..59e65a22 100644 --- a/devkit/core/types/Proxy.sol +++ b/devkit/core/types/Proxy.sol @@ -48,10 +48,10 @@ library ProxyLib { } /**-------------------------- - 🤖 Create Mock Proxy + 🤖 Create Proxy Mock ----------------------------*/ - function createProxySimpleMock(Function[] memory functions) internal returns(Proxy memory) { - uint pid = ProcessLib.startProxyLibProcess("createProxySimpleMock"); + function createSimpleMock(Function[] memory functions) internal returns(Proxy memory) { + uint pid = ProcessLib.startProxyLibProcess("createSimpleMock"); return Proxy({ addr: address(new ProxySimpleMock(functions)), kind: ProxyKind.Mock, From 0d12bd6ddebd97ec2ee5efdbe1385fce8ce111d9 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 14:26:13 +0900 Subject: [PATCH 081/111] Update createMock methods --- devkit/core/method/global/MCTestLib.sol | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/devkit/core/method/global/MCTestLib.sol b/devkit/core/method/global/MCTestLib.sol index 36ad4323..d89002ba 100644 --- a/devkit/core/method/global/MCTestLib.sol +++ b/devkit/core/method/global/MCTestLib.sol @@ -28,8 +28,18 @@ library MCTestLib { /**----------------------------- 🌞 Mocking Meta Contract -------------------------------*/ - function createMock(MCDevKit storage mc, Bundle storage bundle) internal {} - function createMock(MCDevKit storage mc, Function storage func) internal {} + function createMock(MCDevKit storage mc, Bundle storage bundle) internal returns(MCDevKit storage) { + uint pid = mc.recordExecStart("createMock", Params.append(bundle.name)); + createProxySimpleMock(mc, bundle); + return mc.recordExecFinish(pid); + } + function createMock(MCDevKit storage mc, Function storage func) internal returns(MCDevKit storage) { + uint pid = mc.recordExecStart("createMock", Params.append(func.name)); + Function[] memory funcs = new Function[](1); + funcs[0] = func; + createProxySimpleMock(mc, funcs); + return mc.recordExecFinish(pid); + } /**--------------------- @@ -48,8 +58,8 @@ library MCTestLib { mc.proxy.register(name, proxyMock); return mc.recordExecFinish(pid); } - function createProxySimpleMock(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(MCDevKit storage) { - return createProxySimpleMock(mc, name, bundleInfo.functions); + function createProxySimpleMock(MCDevKit storage mc, string memory name, Bundle storage bundle) internal returns(MCDevKit storage) { + return createProxySimpleMock(mc, name, bundle.functions); } function createProxySimpleMock(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { return createProxySimpleMock(mc, name, mc.std.all); @@ -57,6 +67,9 @@ library MCTestLib { function createProxySimpleMock(MCDevKit storage mc, Function[] memory functions) internal returns(MCDevKit storage) { return createProxySimpleMock(mc, mc.proxy.genUniqueMockName(), functions); } + function createProxySimpleMock(MCDevKit storage mc, Bundle memory bundle) internal returns(MCDevKit storage) { + return createProxySimpleMock(mc, mc.proxy.genUniqueMockName(), bundle.functions); + } function createProxySimpleMock(MCDevKit storage mc) internal returns(MCDevKit storage) { return createProxySimpleMock(mc, mc.proxy.genUniqueMockName(), mc.std.all); } From fd44c431cbbc35ba4f9aaf35a56021f2a3631b51 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 14:41:56 +0900 Subject: [PATCH 082/111] Update FunctionRegistry to use register() --- devkit/core/method/global/MCBundleLib.sol | 2 +- devkit/core/registry/BundleRegistry.sol | 7 +++---- devkit/core/registry/FunctionRegistry.sol | 15 ++++++++------- devkit/core/types/Function.sol | 5 +++-- devkit/error/Require.sol | 12 ++++++++++-- test/devkit/global/MCBundle.t.sol | 2 +- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/devkit/core/method/global/MCBundleLib.sol b/devkit/core/method/global/MCBundleLib.sol index 1983ba15..128fe55e 100644 --- a/devkit/core/method/global/MCBundleLib.sol +++ b/devkit/core/method/global/MCBundleLib.sol @@ -76,7 +76,7 @@ library MCBundleLib { -----------------------------*/ function addFunction(MCDevKit storage mc, string memory name, bytes4 selector, address implementation) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("addFunction"); - mc.functions.insert(name, selector, implementation); + mc.functions.register(name, selector, implementation); return mc.recordExecFinish(pid); } /**------------------------------------- diff --git a/devkit/core/registry/BundleRegistry.sol b/devkit/core/registry/BundleRegistry.sol index 2d719158..8429823f 100644 --- a/devkit/core/registry/BundleRegistry.sol +++ b/devkit/core/registry/BundleRegistry.sol @@ -9,15 +9,14 @@ import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for BundleRegistry global; import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Bundle); - // Validation -import {validate} from "devkit/error/Validate.sol"; import {Require} from "devkit/error/Require.sol"; -// Context -import {Current} from "devkit/core/method/context/Current.sol"; + // Core Type import {Bundle} from "devkit/core/types/Bundle.sol"; import {Function} from "devkit/core/types/Function.sol"; +// Context +import {Current} from "devkit/core/method/context/Current.sol"; /**======================== diff --git a/devkit/core/registry/FunctionRegistry.sol b/devkit/core/registry/FunctionRegistry.sol index a00ed95c..2809f282 100644 --- a/devkit/core/registry/FunctionRegistry.sol +++ b/devkit/core/registry/FunctionRegistry.sol @@ -23,13 +23,13 @@ struct FunctionRegistry { } library FunctionRegistryLib { - /**------------------------- - đŸ—ŗī¸ Insert Function - ---------------------------*/ - function insert(FunctionRegistry storage registry, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { - uint pid = registry.startProcess("insert"); + /**-------------------------- + đŸ—ŗī¸ Register Function + ----------------------------*/ + function register(FunctionRegistry storage registry, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { + uint pid = registry.startProcess("register"); Require.notEmpty(name); - registry.functions[name].assign(name, selector, implementation).build(); + registry.functions[name].assign(name, selector, implementation).build().lock(); registry.current.update(name); return registry.finishProcess(pid); } @@ -41,8 +41,9 @@ library FunctionRegistryLib { function find(FunctionRegistry storage registry, string memory name) internal returns(Function storage) { uint pid = registry.startProcess("find"); Require.notEmpty(name); + Require.validRegistration(registry, name); Function storage func = registry.functions[name]; - Require.exists(func); + Require.valid(func); return func.finishProcess(pid); } function findCurrent(FunctionRegistry storage registry) internal returns(Function storage) { diff --git a/devkit/core/types/Function.sol b/devkit/core/types/Function.sol index 3b8fe370..2702c4eb 100644 --- a/devkit/core/types/Function.sol +++ b/devkit/core/types/Function.sol @@ -11,10 +11,10 @@ import {Dumper} from "devkit/core/method/debug/Dumper.sol"; using Dumper for Function global; import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; using Inspector for Function global; -import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; - using TypeGuard for Function global; // Validation import {Require} from "devkit/error/Require.sol"; +import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; + using TypeGuard for Function global; // Loader import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; @@ -30,6 +30,7 @@ struct Function { /// @dev Function may be different depending on the op version TypeStatus status; } library FunctionLib { + /**--------------- 🌈 Assign -----------------*/ diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index 3553b45a..37154e39 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -17,6 +17,7 @@ import {UintUtils} from "devkit/utils/UintUtils.sol"; import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; // Core Types import {Function} from "devkit/core/types/Function.sol"; +import {FunctionRegistry} from "devkit/core/registry/FunctionRegistry.sol"; import {Bundle} from "devkit/core/types/Bundle.sol"; import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; import {Proxy, ProxyKind} from "devkit/core/types/Proxy.sol"; @@ -50,6 +51,13 @@ library Require { validate(func.exists(), "func does not exists"); // validate(func.isBuilt(), "func does not exists"); // TODO } + function isComplete(Function storage func) internal { + validate(func.isComplete(), "Function Not Complete"); + } + function valid(Function storage func) internal { + exists(func); + isComplete(func); + } function EmptyName(Function storage func) internal { Require.isUnassigned(func.name); @@ -72,8 +80,8 @@ library Require { function implIsContract(Function storage func) internal { validate(func.implementation.isContract(), "Implementation Not Contract"); } - function isComplete(Function storage func) internal { - validate(func.isComplete(), "Function Not Complete"); + function validRegistration(FunctionRegistry storage registry, string memory name) internal { + validate(registry.functions[name].isComplete(), "Function Not Complete"); } diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 426335c3..bddcd2ad 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -87,7 +87,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { mc.use(functionName, selector, impl); - vm.expectRevert(ERR.message("Bundle has same Function").toBytes()); // TODO + vm.expectRevert(ERR.message("Locaked Object").toBytes()); // TODO mc.use(functionName, selector, impl); } From b3e27ac0da5c6b8721170e7cb09e997ca7854505 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 14:50:12 +0900 Subject: [PATCH 083/111] Update BundleRegistry to improve type safety --- devkit/core/registry/BundleRegistry.sol | 13 +++++-------- devkit/core/registry/FunctionRegistry.sol | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/devkit/core/registry/BundleRegistry.sol b/devkit/core/registry/BundleRegistry.sol index 8429823f..970da337 100644 --- a/devkit/core/registry/BundleRegistry.sol +++ b/devkit/core/registry/BundleRegistry.sol @@ -28,11 +28,6 @@ struct BundleRegistry { Current current; } library BundleRegistryLib { - /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 🌱 Init Bundle - 🔍 Find Bundle - 🏷 Generate Unique Name - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /**--------------------- 🌱 Init Bundle @@ -41,10 +36,8 @@ library BundleRegistryLib { uint pid = registry.startProcess("init"); Require.notEmpty(name); Bundle storage bundle = registry.bundles[name]; - Require.isUnassigned(bundle); bundle.assignName(name); - registry.current.update(name); return registry.finishProcess(pid); } @@ -54,7 +47,11 @@ library BundleRegistryLib { ----------------------*/ function find(BundleRegistry storage registry, string memory name) internal returns(Bundle storage) { uint pid = registry.startProcess("find"); - return registry.bundles[name].finishProcess(pid); + Require.notEmpty(name); + // Warning.isComplete(registry, name); TODO + Bundle storage bundle = registry.bundles[name]; + Require.valid(bundle); + return bundle.finishProcess(pid); } function findCurrent(BundleRegistry storage registry) internal returns(Bundle storage) { uint pid = registry.startProcess("findCurrent"); diff --git a/devkit/core/registry/FunctionRegistry.sol b/devkit/core/registry/FunctionRegistry.sol index 2809f282..512a0835 100644 --- a/devkit/core/registry/FunctionRegistry.sol +++ b/devkit/core/registry/FunctionRegistry.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.24; -----------------------*/ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for FunctionRegistry global; +// Validation import {Require} from "devkit/error/Require.sol"; // Context From 3863b0f6b13133db9ffb96a14328ddc65c97ef40 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 14:54:59 +0900 Subject: [PATCH 084/111] chore update --- devkit/core/registry/FunctionRegistry.sol | 1 - devkit/core/registry/StdRegistry.sol | 33 +++++++++++------------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/devkit/core/registry/FunctionRegistry.sol b/devkit/core/registry/FunctionRegistry.sol index 512a0835..a74a2863 100644 --- a/devkit/core/registry/FunctionRegistry.sol +++ b/devkit/core/registry/FunctionRegistry.sol @@ -35,7 +35,6 @@ library FunctionRegistryLib { return registry.finishProcess(pid); } - /**---------------------- 🔍 Find Function ------------------------*/ diff --git a/devkit/core/registry/StdRegistry.sol b/devkit/core/registry/StdRegistry.sol index 90f8126b..36bd3331 100644 --- a/devkit/core/registry/StdRegistry.sol +++ b/devkit/core/registry/StdRegistry.sol @@ -1,30 +1,29 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; - -// Core Types -import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; -// Support Method +/**--------------------- + Support Methods +-----------------------*/ import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; using ProcessLib for StdRegistry global; import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; using TypeGuard for StdRegistry global; -// MC Std -import {Clone} from "mc-std/functions/Clone.sol"; -import {GetDeps} from "mc-std/functions/GetDeps.sol"; -import {FeatureToggle} from "mc-std/functions/protected/FeatureToggle.sol"; -import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; -import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.sol"; -import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; -// Loader -import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; // Utils import {AddressUtils} from "devkit/utils/AddressUtils.sol"; using AddressUtils for address; // Validation import {Require} from "devkit/error/Require.sol"; +// Core Types +import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/types/Bundle.sol"; import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; +// MC Std +import {Clone} from "mc-std/functions/Clone.sol"; +import {GetDeps} from "mc-std/functions/GetDeps.sol"; +import {FeatureToggle} from "mc-std/functions/protected/FeatureToggle.sol"; +import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; +import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.sol"; +import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; /**========================== @@ -37,10 +36,10 @@ struct StdRegistry { TypeStatus status; } library StdRegistryLib { - /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + /**---------------------------------- đŸŸĸ Complete Standard Registry - 🔧 Configure Standard Bundles - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + ------------------------------------*/ function complete(StdRegistry storage registry) internal returns(StdRegistry storage) { uint pid = registry.startProcess("complete"); Require.notLocked(registry.status); From f661cdd2947bf8e0b69bac44e337c3b57debb41f Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 15:20:54 +0900 Subject: [PATCH 085/111] Update directory structure --- devkit/MCDevKit.sol | 24 +++++------ devkit/core/{types => }/Bundle.sol | 11 ++--- devkit/core/{types => }/Dictionary.sol | 24 ++++------- devkit/core/{types => }/Function.sol | 10 ++--- devkit/core/{types => }/Proxy.sol | 10 ++--- devkit/debug/Debug.sol | 4 +- devkit/debug/Logger.sol | 2 +- devkit/debug/Params.sol | 6 +-- devkit/error/Error.sol | 2 +- devkit/error/Require.sol | 42 ++++++++++--------- devkit/error/Validate.sol | 4 +- devkit/mocks/DictionaryMock.sol | 2 +- devkit/mocks/ProxySimpleMock.sol | 2 +- devkit/{core => }/registry/BundleRegistry.sol | 14 +++---- .../registry/DictionaryRegistry.sol | 12 +++--- .../{core => }/registry/FunctionRegistry.sol | 6 +-- devkit/{core => }/registry/ProxyRegistry.sol | 12 +++--- devkit/{core => }/registry/StdFunctions.sol | 8 ++-- devkit/{core => }/registry/StdRegistry.sol | 12 +++--- devkit/{core => }/types/TypeGuard.sol | 18 ++++---- .../method => utils}/context/Current.sol | 2 +- .../{core/method => utils}/debug/Dumper.sol | 4 +- .../{core/method => utils}/debug/Parser.sol | 6 +-- .../method => utils}/debug/ProcessLib.sol | 22 +++++----- .../method => utils}/global/MCBundleLib.sol | 6 +-- .../method => utils}/global/MCContextLib.sol | 0 .../method => utils}/global/MCDebugLib.sol | 0 .../method => utils}/global/MCDeployLib.sol | 10 ++--- .../method => utils}/global/MCFinderLib.sol | 8 ++-- .../method => utils}/global/MCSetupLib.sol | 0 .../method => utils}/global/MCTestLib.sol | 8 ++-- .../method => utils}/inspector/Inspector.sol | 22 +++++----- .../inspector/MappingAnalyzer.sol | 10 ++--- devkit/utils/{ => primitive}/AddressUtils.sol | 2 +- devkit/utils/{ => primitive}/BoolUtils.sol | 0 devkit/utils/{ => primitive}/Bytes4Utils.sol | 2 +- devkit/utils/{ => primitive}/StringUtils.sol | 2 +- devkit/utils/{ => primitive}/UintUtils.sol | 6 +-- .../{core/method => utils}/test/TestLib.sol | 2 +- test/devkit/MCDevKit.t.sol | 4 +- test/devkit/global/MCBundle.t.sol | 6 +-- test/devkit/global/MCSetup.t.sol | 2 +- test/utils/TestHelper.sol | 6 +-- 43 files changed, 175 insertions(+), 180 deletions(-) rename devkit/core/{types => }/Bundle.sol (87%) rename devkit/core/{types => }/Dictionary.sol (90%) rename devkit/core/{types => }/Function.sol (89%) rename devkit/core/{types => }/Proxy.sol (84%) rename devkit/{core => }/registry/BundleRegistry.sol (83%) rename devkit/{core => }/registry/DictionaryRegistry.sol (89%) rename devkit/{core => }/registry/FunctionRegistry.sol (90%) rename devkit/{core => }/registry/ProxyRegistry.sol (87%) rename devkit/{core => }/registry/StdFunctions.sol (95%) rename devkit/{core => }/registry/StdRegistry.sol (88%) rename devkit/{core => }/types/TypeGuard.sol (91%) rename devkit/{core/method => utils}/context/Current.sol (94%) rename devkit/{core/method => utils}/debug/Dumper.sol (85%) rename devkit/{core/method => utils}/debug/Parser.sol (85%) rename devkit/{core/method => utils}/debug/ProcessLib.sol (90%) rename devkit/{core/method => utils}/global/MCBundleLib.sol (95%) rename devkit/{core/method => utils}/global/MCContextLib.sol (100%) rename devkit/{core/method => utils}/global/MCDebugLib.sol (100%) rename devkit/{core/method => utils}/global/MCDeployLib.sol (96%) rename devkit/{core/method => utils}/global/MCFinderLib.sol (93%) rename devkit/{core/method => utils}/global/MCSetupLib.sol (100%) rename devkit/{core/method => utils}/global/MCTestLib.sol (96%) rename devkit/{core/method => utils}/inspector/Inspector.sol (91%) rename devkit/{core/method => utils}/inspector/MappingAnalyzer.sol (94%) rename devkit/utils/{ => primitive}/AddressUtils.sol (98%) rename devkit/utils/{ => primitive}/BoolUtils.sol (100%) rename devkit/utils/{ => primitive}/Bytes4Utils.sol (97%) rename devkit/utils/{ => primitive}/StringUtils.sol (98%) rename devkit/utils/{ => primitive}/UintUtils.sol (80%) rename devkit/{core/method => utils}/test/TestLib.sol (93%) diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index 86c254a5..6d4964f9 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -2,20 +2,20 @@ pragma solidity ^0.8.24; // Core Registries -import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; -import {FunctionRegistry} from "devkit/core/registry/FunctionRegistry.sol"; -import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; -import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; -import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; +import {StdRegistry} from "devkit/registry/StdRegistry.sol"; +import {FunctionRegistry} from "devkit/registry/FunctionRegistry.sol"; +import {BundleRegistry} from "devkit/registry/BundleRegistry.sol"; +import {DictionaryRegistry} from "devkit/registry/DictionaryRegistry.sol"; +import {ProxyRegistry} from "devkit/registry/ProxyRegistry.sol"; // Global Methods -import {MCSetupLib} from "devkit/core/method/global/MCSetupLib.sol"; -import {MCBundleLib} from "devkit/core/method/global/MCBundleLib.sol"; -import {MCDeployLib} from "devkit/core/method/global/MCDeployLib.sol"; -import {MCFinderLib} from "devkit/core/method/global/MCFinderLib.sol"; -import {MCContextLib} from "devkit/core/method/global/MCContextLib.sol"; -import {MCTestLib} from "devkit/core/method/global/MCTestLib.sol"; -import {MCDebugLib} from "devkit/core/method/global/MCDebugLib.sol"; +import {MCSetupLib} from "devkit/utils/global/MCSetupLib.sol"; +import {MCBundleLib} from "devkit/utils/global/MCBundleLib.sol"; +import {MCDeployLib} from "devkit/utils/global/MCDeployLib.sol"; +import {MCFinderLib} from "devkit/utils/global/MCFinderLib.sol"; +import {MCContextLib} from "devkit/utils/global/MCContextLib.sol"; +import {MCTestLib} from "devkit/utils/global/MCTestLib.sol"; +import {MCDebugLib} from "devkit/utils/global/MCDebugLib.sol"; /******************************** diff --git a/devkit/core/types/Bundle.sol b/devkit/core/Bundle.sol similarity index 87% rename from devkit/core/types/Bundle.sol rename to devkit/core/Bundle.sol index c9f9d246..a83e7cca 100644 --- a/devkit/core/types/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -3,20 +3,20 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for Bundle global; -import {Parser} from "devkit/core/method/debug/Parser.sol"; +import {Parser} from "devkit/utils/debug/Parser.sol"; using Parser for Bundle global; -import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/utils/inspector/Inspector.sol"; using Inspector for Bundle global; -import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; +import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Bundle global; // Validation import {validate} from "devkit/error/Validate.sol"; import {Require} from "devkit/error/Require.sol"; // Core Type -import {Function} from "devkit/core/types/Function.sol"; +import {Function} from "devkit/core/Function.sol"; /**================ @@ -30,6 +30,7 @@ struct Bundle { TypeStatus status; } library BundleLib { + /**-------------------- 📛 Assign Name ----------------------*/ diff --git a/devkit/core/types/Dictionary.sol b/devkit/core/Dictionary.sol similarity index 90% rename from devkit/core/types/Dictionary.sol rename to devkit/core/Dictionary.sol index 73308037..55971c1e 100644 --- a/devkit/core/types/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -3,18 +3,18 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for Dictionary global; import {Params} from "devkit/debug/Params.sol"; -import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/utils/inspector/Inspector.sol"; using Inspector for Dictionary global; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; // Type Util -import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; +import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; using Bytes4Utils for bytes4; // Validation import {Require} from "devkit/error/Require.sol"; -import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; +import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Dictionary global; // Mock @@ -24,8 +24,8 @@ import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; // Core Types -import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; /**==================== @@ -43,8 +43,9 @@ library DictionaryLib { 🔂 Duplicate Dictionary 🧩 Set Function or Bundle đŸĒŸ Upgrade Facade - 🤖 Create Mock Dictionary + 🤖 Create Dictionary Mock ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + /**------------------------- 🚀 Deploy Dictionary ---------------------------*/ @@ -83,7 +84,6 @@ library DictionaryLib { return duplicate(deploy(ForgeHelper.msgSender()), fromDictionary); } - /**----------------------------- 🧩 Set Function or Bundle -------------------------------*/ @@ -119,7 +119,6 @@ library DictionaryLib { return dictionary.finishProcess(pid); } - /**---------------------- đŸĒŸ Upgrade Facade ------------------------*/ @@ -131,7 +130,6 @@ library DictionaryLib { return dictionary.finishProcess(pid); } - /**------------------------------ 🤖 Create Dictionary Mock --------------------------------*/ @@ -144,12 +142,6 @@ library DictionaryLib { }).finishProcess(pid); } - - - // function assignLabel(Dictionary storage dictionary, string memory name) internal returns(Dictionary storage) { - // ForgeHelper.assignLabel(dictionary.addr, name); - // return dictionary; - // } } diff --git a/devkit/core/types/Function.sol b/devkit/core/Function.sol similarity index 89% rename from devkit/core/types/Function.sol rename to devkit/core/Function.sol index 2702c4eb..f3ec7c9d 100644 --- a/devkit/core/types/Function.sol +++ b/devkit/core/Function.sol @@ -3,17 +3,17 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for Function global; -import {Parser} from "devkit/core/method/debug/Parser.sol"; +import {Parser} from "devkit/utils/debug/Parser.sol"; using Parser for Function global; -import {Dumper} from "devkit/core/method/debug/Dumper.sol"; +import {Dumper} from "devkit/utils/debug/Dumper.sol"; using Dumper for Function global; -import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/utils/inspector/Inspector.sol"; using Inspector for Function global; // Validation import {Require} from "devkit/error/Require.sol"; -import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; +import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Function global; // Loader import {loadAddressFrom} from "devkit/utils/ForgeHelper.sol"; diff --git a/devkit/core/types/Proxy.sol b/devkit/core/Proxy.sol similarity index 84% rename from devkit/core/types/Proxy.sol rename to devkit/core/Proxy.sol index 59e65a22..0da83071 100644 --- a/devkit/core/types/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -3,14 +3,14 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for Proxy global; -import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/utils/inspector/Inspector.sol"; using Inspector for Proxy global; using Inspector for ProxyKind global; // Validation import {Require} from "devkit/error/Require.sol";// Core Type -import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; +import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Proxy global; // External Lib Contract @@ -19,8 +19,8 @@ import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; import {ProxySimpleMock} from "devkit/mocks/ProxySimpleMock.sol"; // Core Types -import {Dictionary} from "devkit/core/types/Dictionary.sol"; -import {Function} from "devkit/core/types/Function.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; +import {Function} from "devkit/core/Function.sol"; /**=============== diff --git a/devkit/debug/Debug.sol b/devkit/debug/Debug.sol index ca440b73..a08e9a9e 100644 --- a/devkit/debug/Debug.sol +++ b/devkit/debug/Debug.sol @@ -4,9 +4,9 @@ pragma solidity ^0.8.24; // Utils import {console2, StdStyle} from "../utils/ForgeHelper.sol"; using StdStyle for string; -import {StringUtils} from "../utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; +import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; using BoolUtils for bool; import {Logger} from "./Logger.sol"; diff --git a/devkit/debug/Logger.sol b/devkit/debug/Logger.sol index 493bb197..1882edc9 100644 --- a/devkit/debug/Logger.sol +++ b/devkit/debug/Logger.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; import {ERR} from "devkit/error/Error.sol"; // Utils import {console2, StdStyle, vm} from "../utils/ForgeHelper.sol"; -import {StringUtils} from "../utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; // Debug import {Debug, Process} from "./Debug.sol"; diff --git a/devkit/debug/Params.sol b/devkit/debug/Params.sol index 511f04bc..90db71a9 100644 --- a/devkit/debug/Params.sol +++ b/devkit/debug/Params.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {StringUtils} from "devkit/utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; +import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; using AddressUtils for address; -import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; +import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; using Bytes4Utils for bytes4; diff --git a/devkit/error/Error.sol b/devkit/error/Error.sol index c03d06f8..4fe68a66 100644 --- a/devkit/error/Error.sol +++ b/devkit/error/Error.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; // Utils import {StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; -import {StringUtils} from "devkit/utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; // Debug import {Logger} from "devkit/debug/Logger.sol"; diff --git a/devkit/error/Require.sol b/devkit/error/Require.sol index 37154e39..8c2aca97 100644 --- a/devkit/error/Require.sol +++ b/devkit/error/Require.sol @@ -4,28 +4,28 @@ pragma solidity ^0.8.24; import {throwError, ERR} from "devkit/error/Error.sol"; import {validate} from "devkit/error/Validate.sol"; // Utils -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; +import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; using BoolUtils for bool; -import {StringUtils} from "devkit/utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; -import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; +import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; using Bytes4Utils for bytes4; -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; +import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; using AddressUtils for address; -import {UintUtils} from "devkit/utils/UintUtils.sol"; +import {UintUtils} from "devkit/utils/primitive/UintUtils.sol"; using UintUtils for uint256; -import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; +import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; // Core Types -import {Function} from "devkit/core/types/Function.sol"; -import {FunctionRegistry} from "devkit/core/registry/FunctionRegistry.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; -import {Proxy, ProxyKind} from "devkit/core/types/Proxy.sol"; -import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; -import {Dictionary, DictionaryKind} from "devkit/core/types/Dictionary.sol"; -import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; -import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; -import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; +import {Function} from "devkit/core/Function.sol"; +import {FunctionRegistry} from "devkit/registry/FunctionRegistry.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {BundleRegistry} from "devkit/registry/BundleRegistry.sol"; +import {Proxy, ProxyKind} from "devkit/core/Proxy.sol"; +import {ProxyRegistry} from "devkit/registry/ProxyRegistry.sol"; +import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; +import {DictionaryRegistry} from "devkit/registry/DictionaryRegistry.sol"; +import {StdRegistry} from "devkit/registry/StdRegistry.sol"; +import {StdFunctions} from "devkit/registry/StdFunctions.sol"; library Require { @@ -88,13 +88,15 @@ library Require { /**=============== đŸ—‚ī¸ Bundle =================*/ - function isComplete(Bundle storage bundle) internal returns(Bundle storage) { + function isComplete(Bundle storage bundle) internal { validate(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); - return bundle; } - function exists(Bundle storage bundle) internal returns(Bundle storage) { + function valid(Bundle storage bundle) internal { + exists(bundle); + isComplete(bundle); + } + function exists(Bundle storage bundle) internal { validate(bundle.exists(), "Bundle Info Not Exists"); - return bundle; } function notExists(Bundle storage bundle) internal returns(Bundle storage) { validate(bundle.notExists(), "Bundle Already Exists"); diff --git a/devkit/error/Validate.sol b/devkit/error/Validate.sol index 529388b0..301a68ce 100644 --- a/devkit/error/Validate.sol +++ b/devkit/error/Validate.sol @@ -3,9 +3,9 @@ pragma solidity ^0.8.24; import {throwError, ERR} from "devkit/error/Error.sol"; // Utils -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; +import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; using BoolUtils for bool; -import {StringUtils} from "devkit/utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; /// @dev like `require` diff --git a/devkit/mocks/DictionaryMock.sol b/devkit/mocks/DictionaryMock.sol index b4900f55..b4a1101c 100644 --- a/devkit/mocks/DictionaryMock.sol +++ b/devkit/mocks/DictionaryMock.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Core -import {Function} from "devkit/core/types/Function.sol"; +import {Function} from "devkit/core/Function.sol"; // External Lib import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; diff --git a/devkit/mocks/ProxySimpleMock.sol b/devkit/mocks/ProxySimpleMock.sol index c2dd8fb8..9df11729 100644 --- a/devkit/mocks/ProxySimpleMock.sol +++ b/devkit/mocks/ProxySimpleMock.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Core -import {Function} from "devkit/core/types/Function.sol"; +import {Function} from "devkit/core/Function.sol"; // External Lib import {Proxy as OZProxy} from "@oz.mc/proxy/Proxy.sol"; diff --git a/devkit/core/registry/BundleRegistry.sol b/devkit/registry/BundleRegistry.sol similarity index 83% rename from devkit/core/registry/BundleRegistry.sol rename to devkit/registry/BundleRegistry.sol index 970da337..651d62f6 100644 --- a/devkit/core/registry/BundleRegistry.sol +++ b/devkit/registry/BundleRegistry.sol @@ -3,20 +3,20 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for BundleRegistry global; -import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/utils/inspector/Inspector.sol"; using Inspector for BundleRegistry global; -import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; +import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Bundle); // Validation import {Require} from "devkit/error/Require.sol"; // Core Type -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {Function} from "devkit/core/Function.sol"; // Context -import {Current} from "devkit/core/method/context/Current.sol"; +import {Current} from "devkit/utils/context/Current.sol"; /**======================== @@ -50,7 +50,7 @@ library BundleRegistryLib { Require.notEmpty(name); // Warning.isComplete(registry, name); TODO Bundle storage bundle = registry.bundles[name]; - Require.valid(bundle); + // Require.valid(bundle); TODO return bundle.finishProcess(pid); } function findCurrent(BundleRegistry storage registry) internal returns(Bundle storage) { diff --git a/devkit/core/registry/DictionaryRegistry.sol b/devkit/registry/DictionaryRegistry.sol similarity index 89% rename from devkit/core/registry/DictionaryRegistry.sol rename to devkit/registry/DictionaryRegistry.sol index 05dc6431..a6e0860f 100644 --- a/devkit/core/registry/DictionaryRegistry.sol +++ b/devkit/registry/DictionaryRegistry.sol @@ -3,20 +3,20 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for DictionaryRegistry global; -import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/utils/inspector/Inspector.sol"; using Inspector for DictionaryRegistry global; -import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; +import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Dictionary); // Validation import {Require} from "devkit/error/Require.sol"; // Core Type -import {Dictionary, DictionaryLib} from "devkit/core/types/Dictionary.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; +import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; // Context -import {Current} from "devkit/core/method/context/Current.sol"; +import {Current} from "devkit/utils/context/Current.sol"; /**============================ diff --git a/devkit/core/registry/FunctionRegistry.sol b/devkit/registry/FunctionRegistry.sol similarity index 90% rename from devkit/core/registry/FunctionRegistry.sol rename to devkit/registry/FunctionRegistry.sol index a74a2863..0fc6fcfb 100644 --- a/devkit/core/registry/FunctionRegistry.sol +++ b/devkit/registry/FunctionRegistry.sol @@ -3,15 +3,15 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for FunctionRegistry global; // Validation import {Require} from "devkit/error/Require.sol"; // Context -import {Current} from "devkit/core/method/context/Current.sol"; +import {Current} from "devkit/utils/context/Current.sol"; // Core Type -import {Function} from "devkit/core/types/Function.sol"; +import {Function} from "devkit/core/Function.sol"; /**=========================== diff --git a/devkit/core/registry/ProxyRegistry.sol b/devkit/registry/ProxyRegistry.sol similarity index 87% rename from devkit/core/registry/ProxyRegistry.sol rename to devkit/registry/ProxyRegistry.sol index ec414c25..23e43fc0 100644 --- a/devkit/core/registry/ProxyRegistry.sol +++ b/devkit/registry/ProxyRegistry.sol @@ -3,20 +3,20 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for ProxyRegistry global; -import {Inspector} from "devkit/core/method/inspector/Inspector.sol"; +import {Inspector} from "devkit/utils/inspector/Inspector.sol"; using Inspector for ProxyRegistry global; -import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; +import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Proxy); // Validation import {Require} from "devkit/error/Require.sol"; // Core Type -import {Proxy, ProxyLib} from "devkit/core/types/Proxy.sol"; -import {Dictionary} from "devkit/core/types/Dictionary.sol"; +import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; // Context -import {Current} from "devkit/core/method/context/Current.sol"; +import {Current} from "devkit/utils/context/Current.sol"; /**======================= diff --git a/devkit/core/registry/StdFunctions.sol b/devkit/registry/StdFunctions.sol similarity index 95% rename from devkit/core/registry/StdFunctions.sol rename to devkit/registry/StdFunctions.sol index 37a9107e..b5aadded 100644 --- a/devkit/core/registry/StdFunctions.sol +++ b/devkit/registry/StdFunctions.sol @@ -3,14 +3,14 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for StdFunctions global; -import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; +import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for StdFunctions global; import {Require} from "devkit/error/Require.sol"; // Core Types -import {Function} from "devkit/core/types/Function.sol"; +import {Function} from "devkit/core/Function.sol"; // MC Std import {Clone} from "mc-std/functions/Clone.sol"; import {GetDeps} from "mc-std/functions/GetDeps.sol"; @@ -19,7 +19,7 @@ import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.sol"; import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; // Utils -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; +import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; using AddressUtils for address; diff --git a/devkit/core/registry/StdRegistry.sol b/devkit/registry/StdRegistry.sol similarity index 88% rename from devkit/core/registry/StdRegistry.sol rename to devkit/registry/StdRegistry.sol index 36bd3331..53807d3b 100644 --- a/devkit/core/registry/StdRegistry.sol +++ b/devkit/registry/StdRegistry.sol @@ -3,20 +3,20 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for StdRegistry global; -import {TypeGuard, TypeStatus} from "devkit/core/types/TypeGuard.sol"; +import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for StdRegistry global; // Utils -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; +import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; using AddressUtils for address; // Validation import {Require} from "devkit/error/Require.sol"; // Core Types -import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {StdFunctions} from "devkit/registry/StdFunctions.sol"; // MC Std import {Clone} from "mc-std/functions/Clone.sol"; import {GetDeps} from "mc-std/functions/GetDeps.sol"; diff --git a/devkit/core/types/TypeGuard.sol b/devkit/types/TypeGuard.sol similarity index 91% rename from devkit/core/types/TypeGuard.sol rename to devkit/types/TypeGuard.sol index 11c98d14..1eb1ff1a 100644 --- a/devkit/core/types/TypeGuard.sol +++ b/devkit/types/TypeGuard.sol @@ -1,20 +1,20 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// import {StringUtils} from "devkit/utils/StringUtils.sol"; +// import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; // using StringUtils for string; -// import {AddressUtils} from "devkit/utils/AddressUtils.sol"; +// import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; // using AddressUtils for address; -// import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; +// import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; // using Bytes4Utils for bytes4; import {Require} from "devkit/error/Require.sol"; // Core Types -import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {Dictionary} from "devkit/core/types/Dictionary.sol"; -import {Proxy} from "devkit/core/types/Proxy.sol"; -import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; -import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; +import {Proxy} from "devkit/core/Proxy.sol"; +import {StdRegistry} from "devkit/registry/StdRegistry.sol"; +import {StdFunctions} from "devkit/registry/StdFunctions.sol"; using TypeGuard for TypeStatus global; enum TypeStatus { Uninitialized, Building, Built, Locked } diff --git a/devkit/core/method/context/Current.sol b/devkit/utils/context/Current.sol similarity index 94% rename from devkit/core/method/context/Current.sol rename to devkit/utils/context/Current.sol index 6662a943..ab15795c 100644 --- a/devkit/core/method/context/Current.sol +++ b/devkit/utils/context/Current.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; Support Methods -----------------------*/ import {Params} from "devkit/debug/Params.sol"; -import {ProcessLib} from "devkit/core/method/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for Current global; // Validation diff --git a/devkit/core/method/debug/Dumper.sol b/devkit/utils/debug/Dumper.sol similarity index 85% rename from devkit/core/method/debug/Dumper.sol rename to devkit/utils/debug/Dumper.sol index 6694973d..120e0cff 100644 --- a/devkit/core/method/debug/Dumper.sol +++ b/devkit/utils/debug/Dumper.sol @@ -3,8 +3,8 @@ pragma solidity ^0.8.24; import {Logger} from "devkit/debug/Logger.sol"; // Core Types -import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; /**================= diff --git a/devkit/core/method/debug/Parser.sol b/devkit/utils/debug/Parser.sol similarity index 85% rename from devkit/core/method/debug/Parser.sol rename to devkit/utils/debug/Parser.sol index 08a2f48a..dfdb9513 100644 --- a/devkit/core/method/debug/Parser.sol +++ b/devkit/utils/debug/Parser.sol @@ -2,10 +2,10 @@ pragma solidity ^0.8.24; // Core Types -import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; // Utils -import {StringUtils} from "devkit/utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; diff --git a/devkit/core/method/debug/ProcessLib.sol b/devkit/utils/debug/ProcessLib.sol similarity index 90% rename from devkit/core/method/debug/ProcessLib.sol rename to devkit/utils/debug/ProcessLib.sol index 2d4103bc..9737d6b9 100644 --- a/devkit/core/method/debug/ProcessLib.sol +++ b/devkit/utils/debug/ProcessLib.sol @@ -3,17 +3,17 @@ pragma solidity ^0.8.24; import {Debug} from "devkit/debug/Debug.sol"; // Core Types -import {Function} from "devkit/core/types/Function.sol"; -import {FunctionRegistry} from "devkit/core/registry/FunctionRegistry.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; -import {StdRegistry} from "devkit/core/registry/StdRegistry.sol"; -import {StdFunctions} from "devkit/core/registry/StdFunctions.sol"; -import {Proxy} from "devkit/core/types/Proxy.sol"; -import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; -import {Dictionary} from "devkit/core/types/Dictionary.sol"; -import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; -import {Current} from "devkit/core/method/context/Current.sol"; +import {Function} from "devkit/core/Function.sol"; +import {FunctionRegistry} from "devkit/registry/FunctionRegistry.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {BundleRegistry} from "devkit/registry/BundleRegistry.sol"; +import {StdRegistry} from "devkit/registry/StdRegistry.sol"; +import {StdFunctions} from "devkit/registry/StdFunctions.sol"; +import {Proxy} from "devkit/core/Proxy.sol"; +import {ProxyRegistry} from "devkit/registry/ProxyRegistry.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; +import {DictionaryRegistry} from "devkit/registry/DictionaryRegistry.sol"; +import {Current} from "devkit/utils/context/Current.sol"; /**================= diff --git a/devkit/core/method/global/MCBundleLib.sol b/devkit/utils/global/MCBundleLib.sol similarity index 95% rename from devkit/core/method/global/MCBundleLib.sol rename to devkit/utils/global/MCBundleLib.sol index 128fe55e..38d1aed8 100644 --- a/devkit/core/method/global/MCBundleLib.sol +++ b/devkit/utils/global/MCBundleLib.sol @@ -10,10 +10,10 @@ import {ERR} from "devkit/error/Error.sol"; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {Params} from "devkit/debug/Params.sol"; // Core -import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; -import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; +import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Bundle); /*********************************************** diff --git a/devkit/core/method/global/MCContextLib.sol b/devkit/utils/global/MCContextLib.sol similarity index 100% rename from devkit/core/method/global/MCContextLib.sol rename to devkit/utils/global/MCContextLib.sol diff --git a/devkit/core/method/global/MCDebugLib.sol b/devkit/utils/global/MCDebugLib.sol similarity index 100% rename from devkit/core/method/global/MCDebugLib.sol rename to devkit/utils/global/MCDebugLib.sol diff --git a/devkit/core/method/global/MCDeployLib.sol b/devkit/utils/global/MCDeployLib.sol similarity index 96% rename from devkit/core/method/global/MCDeployLib.sol rename to devkit/utils/global/MCDeployLib.sol index 15da7a99..7dc4e022 100644 --- a/devkit/core/method/global/MCDeployLib.sol +++ b/devkit/utils/global/MCDeployLib.sol @@ -9,15 +9,15 @@ import {validate} from "devkit/error/Validate.sol"; import {Params} from "devkit/debug/Params.sol"; // Core // dictionary -import {Dictionary, DictionaryLib} from "devkit/core/types/Dictionary.sol"; +import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; // functions -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {StdFunctionsArgs} from "devkit/core/registry/StdRegistry.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {StdFunctionsArgs} from "devkit/registry/StdRegistry.sol"; using StdFunctionsArgs for address; // proxy -import {Proxy, ProxyLib} from "devkit/core/types/Proxy.sol"; +import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; -import {MappingAnalyzer} from "devkit/core/method/inspector/MappingAnalyzer.sol"; +import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Dictionary); using MappingAnalyzer for mapping(string => Proxy); diff --git a/devkit/core/method/global/MCFinderLib.sol b/devkit/utils/global/MCFinderLib.sol similarity index 93% rename from devkit/core/method/global/MCFinderLib.sol rename to devkit/utils/global/MCFinderLib.sol index 8736003d..69a9a085 100644 --- a/devkit/core/method/global/MCFinderLib.sol +++ b/devkit/utils/global/MCFinderLib.sol @@ -4,12 +4,12 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Core // functions -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {Function} from "devkit/core/Function.sol"; // proxy -import {Proxy} from "devkit/core/types/Proxy.sol"; +import {Proxy} from "devkit/core/Proxy.sol"; // dictionary -import {Dictionary} from "devkit/core/types/Dictionary.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; /********************************** diff --git a/devkit/core/method/global/MCSetupLib.sol b/devkit/utils/global/MCSetupLib.sol similarity index 100% rename from devkit/core/method/global/MCSetupLib.sol rename to devkit/utils/global/MCSetupLib.sol diff --git a/devkit/core/method/global/MCTestLib.sol b/devkit/utils/global/MCTestLib.sol similarity index 96% rename from devkit/core/method/global/MCTestLib.sol rename to devkit/utils/global/MCTestLib.sol index d89002ba..6709615c 100644 --- a/devkit/core/method/global/MCTestLib.sol +++ b/devkit/utils/global/MCTestLib.sol @@ -9,12 +9,12 @@ import {Config} from "devkit/config/Config.sol"; import {Params} from "devkit/debug/Params.sol"; // Core // functions -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {Function} from "devkit/core/Function.sol"; // proxy -import {Proxy, ProxyLib} from "devkit/core/types/Proxy.sol"; +import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; // dictionary -import {Dictionary, DictionaryLib} from "devkit/core/types/Dictionary.sol"; +import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; /****************************************** diff --git a/devkit/core/method/inspector/Inspector.sol b/devkit/utils/inspector/Inspector.sol similarity index 91% rename from devkit/core/method/inspector/Inspector.sol rename to devkit/utils/inspector/Inspector.sol index f9b9225e..d5ac7ba7 100644 --- a/devkit/core/method/inspector/Inspector.sol +++ b/devkit/utils/inspector/Inspector.sol @@ -3,26 +3,26 @@ pragma solidity ^0.8.24; import {validate} from "devkit/error/Validate.sol"; import {Require} from "devkit/error/Require.sol"; -import {StringUtils} from "devkit/utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; +import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; using AddressUtils for address; -import {BoolUtils} from "devkit/utils/BoolUtils.sol"; +import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; using BoolUtils for bool; -import {Bytes4Utils} from "devkit/utils/Bytes4Utils.sol"; +import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; using Bytes4Utils for bytes4; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; // External Library import {IBeacon} from "@oz.mc/proxy/beacon/IBeacon.sol"; import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; // Core Types -import {Function} from "devkit/core/types/Function.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {BundleRegistry} from "devkit/core/registry/BundleRegistry.sol"; -import {Proxy, ProxyKind} from "devkit/core/types/Proxy.sol"; -import {ProxyRegistry} from "devkit/core/registry/ProxyRegistry.sol"; -import {Dictionary, DictionaryKind} from "devkit/core/types/Dictionary.sol"; -import {DictionaryRegistry} from "devkit/core/registry/DictionaryRegistry.sol"; +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {BundleRegistry} from "devkit/registry/BundleRegistry.sol"; +import {Proxy, ProxyKind} from "devkit/core/Proxy.sol"; +import {ProxyRegistry} from "devkit/registry/ProxyRegistry.sol"; +import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; +import {DictionaryRegistry} from "devkit/registry/DictionaryRegistry.sol"; /**-------------------- diff --git a/devkit/core/method/inspector/MappingAnalyzer.sol b/devkit/utils/inspector/MappingAnalyzer.sol similarity index 94% rename from devkit/core/method/inspector/MappingAnalyzer.sol rename to devkit/utils/inspector/MappingAnalyzer.sol index 42c4e862..22f956cb 100644 --- a/devkit/core/method/inspector/MappingAnalyzer.sol +++ b/devkit/utils/inspector/MappingAnalyzer.sol @@ -4,12 +4,12 @@ pragma solidity ^0.8.24; import {throwError, ERR} from "devkit/error/Error.sol"; import {Config, ScanRange} from "devkit/config/Config.sol"; // Core Types -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {Function} from "devkit/core/types/Function.sol"; -import {Dictionary} from "devkit/core/types/Dictionary.sol"; -import {Proxy} from "devkit/core/types/Proxy.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {Function} from "devkit/core/Function.sol"; +import {Dictionary} from "devkit/core/Dictionary.sol"; +import {Proxy} from "devkit/core/Proxy.sol"; // Utils -import {StringUtils} from "devkit/utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; /*********************************** diff --git a/devkit/utils/AddressUtils.sol b/devkit/utils/primitive/AddressUtils.sol similarity index 98% rename from devkit/utils/AddressUtils.sol rename to devkit/utils/primitive/AddressUtils.sol index ba85a85a..6790b4e1 100644 --- a/devkit/utils/AddressUtils.sol +++ b/devkit/utils/primitive/AddressUtils.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; // Validation import {validate} from "devkit/error/Validate.sol"; // Utils -import {vm} from "./ForgeHelper.sol"; +import {vm} from "devkit/utils/ForgeHelper.sol"; import {BoolUtils} from "./BoolUtils.sol"; using BoolUtils for bool; // External Lib diff --git a/devkit/utils/BoolUtils.sol b/devkit/utils/primitive/BoolUtils.sol similarity index 100% rename from devkit/utils/BoolUtils.sol rename to devkit/utils/primitive/BoolUtils.sol diff --git a/devkit/utils/Bytes4Utils.sol b/devkit/utils/primitive/Bytes4Utils.sol similarity index 97% rename from devkit/utils/Bytes4Utils.sol rename to devkit/utils/primitive/Bytes4Utils.sol index 18606182..b057d993 100644 --- a/devkit/utils/Bytes4Utils.sol +++ b/devkit/utils/primitive/Bytes4Utils.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; // Validation import {validate} from "devkit/error/Validate.sol"; // Utils -import {vm} from "./ForgeHelper.sol"; +import {vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "./StringUtils.sol"; using StringUtils for string; import {BoolUtils} from "./BoolUtils.sol"; diff --git a/devkit/utils/StringUtils.sol b/devkit/utils/primitive/StringUtils.sol similarity index 98% rename from devkit/utils/StringUtils.sol rename to devkit/utils/primitive/StringUtils.sol index b993ea66..4ef447a5 100644 --- a/devkit/utils/StringUtils.sol +++ b/devkit/utils/primitive/StringUtils.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; import {validate} from "devkit/error/Validate.sol"; import {Debug} from "devkit/debug/Debug.sol"; // Utils -import {StdStyle, ForgeHelper, vm} from "./ForgeHelper.sol"; +import {StdStyle, ForgeHelper, vm} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; import {Bytes4Utils} from "./Bytes4Utils.sol"; using Bytes4Utils for bytes4; diff --git a/devkit/utils/UintUtils.sol b/devkit/utils/primitive/UintUtils.sol similarity index 80% rename from devkit/utils/UintUtils.sol rename to devkit/utils/primitive/UintUtils.sol index cb30cac6..4991a9d5 100644 --- a/devkit/utils/UintUtils.sol +++ b/devkit/utils/primitive/UintUtils.sol @@ -4,10 +4,10 @@ pragma solidity ^0.8.24; // Validation import {validate} from "devkit/error/Validate.sol"; // Utils -import {vm} from "./ForgeHelper.sol"; -import {StringUtils} from "./StringUtils.sol"; +import {vm} from "devkit/utils/ForgeHelper.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; -import {BoolUtils} from "./BoolUtils.sol"; +import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; using BoolUtils for bool; diff --git a/devkit/core/method/test/TestLib.sol b/devkit/utils/test/TestLib.sol similarity index 93% rename from devkit/core/method/test/TestLib.sol rename to devkit/utils/test/TestLib.sol index f4e927e0..95436043 100644 --- a/devkit/core/method/test/TestLib.sol +++ b/devkit/utils/test/TestLib.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; ----------------------------*/ // Core Type -import {Proxy} from "devkit/core/types/Proxy.sol"; +import {Proxy} from "devkit/core/Proxy.sol"; /**=============== diff --git a/test/devkit/MCDevKit.t.sol b/test/devkit/MCDevKit.t.sol index 031510f3..3db3f6e2 100644 --- a/test/devkit/MCDevKit.t.sol +++ b/test/devkit/MCDevKit.t.sol @@ -3,11 +3,11 @@ // import {Test, console2} from "forge-std/Test.sol"; // import {MCDevKit} from "devkit/MCDevKit.sol"; -// import {Function} from "devkit/core/types/Function.sol"; +// import {Function} from "devkit/core/Function.sol"; // import {TestHelper} from "../utils/TestHelper.sol"; // using TestHelper for Function; -// import {StringUtils} from "devkit/utils/StringUtils.sol"; +// import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; // using StringUtils for string; // contract MCDevKitTest is Test { diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index bddcd2ad..89b43579 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -3,13 +3,13 @@ pragma solidity ^0.8.24; import {MCDevKitTest} from "devkit/MCTest.sol"; -import {StringUtils} from "devkit/utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; import {Config} from "devkit/config/Config.sol"; import {ERR} from "devkit/error/Error.sol"; -import {Bundle} from "devkit/core/types/Bundle.sol"; -import {Function} from "devkit/core/types/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {Function} from "devkit/core/Function.sol"; import {DummyFunction} from "test/utils/DummyFunction.sol"; import {DummyFacade} from "test/utils/DummyFacade.sol"; diff --git a/test/devkit/global/MCSetup.t.sol b/test/devkit/global/MCSetup.t.sol index 6729dddc..8f34c950 100644 --- a/test/devkit/global/MCSetup.t.sol +++ b/test/devkit/global/MCSetup.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; import {MCDevKitTest} from "devkit/MCTest.sol"; -import {Function} from "devkit/core/types/Function.sol"; +import {Function} from "devkit/core/Function.sol"; import {TestHelper} from "test/utils/TestHelper.sol"; using TestHelper for Function; diff --git a/test/utils/TestHelper.sol b/test/utils/TestHelper.sol index cda473bf..6c999ef8 100644 --- a/test/utils/TestHelper.sol +++ b/test/utils/TestHelper.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {AddressUtils} from "devkit/utils/AddressUtils.sol"; +import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; using AddressUtils for address; -import {StringUtils} from "devkit/utils/StringUtils.sol"; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; -import {Function} from "devkit/core/types/Function.sol"; +import {Function} from "devkit/core/Function.sol"; // import {Bundle} from "./Bundle.sol"; import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; From a5d529b2f81ba43b20a223ff4246afdc028448f9 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 15:34:16 +0900 Subject: [PATCH 086/111] Move Current to registry/ --- devkit/MCDevKit.sol | 2 +- devkit/registry/BundleRegistry.sol | 2 +- devkit/registry/DictionaryRegistry.sol | 2 +- devkit/registry/FunctionRegistry.sol | 2 +- devkit/registry/ProxyRegistry.sol | 2 +- devkit/{utils => registry}/context/Current.sol | 2 +- devkit/utils/debug/ProcessLib.sol | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename devkit/{utils => registry}/context/Current.sol (100%) diff --git a/devkit/MCDevKit.sol b/devkit/MCDevKit.sol index 6d4964f9..becd1402 100644 --- a/devkit/MCDevKit.sol +++ b/devkit/MCDevKit.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// Core Registries +// Registries import {StdRegistry} from "devkit/registry/StdRegistry.sol"; import {FunctionRegistry} from "devkit/registry/FunctionRegistry.sol"; import {BundleRegistry} from "devkit/registry/BundleRegistry.sol"; diff --git a/devkit/registry/BundleRegistry.sol b/devkit/registry/BundleRegistry.sol index 651d62f6..8a0d8684 100644 --- a/devkit/registry/BundleRegistry.sol +++ b/devkit/registry/BundleRegistry.sol @@ -16,7 +16,7 @@ import {Require} from "devkit/error/Require.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; // Context -import {Current} from "devkit/utils/context/Current.sol"; +import {Current} from "devkit/registry/context/Current.sol"; /**======================== diff --git a/devkit/registry/DictionaryRegistry.sol b/devkit/registry/DictionaryRegistry.sol index a6e0860f..f369ba60 100644 --- a/devkit/registry/DictionaryRegistry.sol +++ b/devkit/registry/DictionaryRegistry.sol @@ -16,7 +16,7 @@ import {Require} from "devkit/error/Require.sol"; import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; import {Bundle} from "devkit/core/Bundle.sol"; // Context -import {Current} from "devkit/utils/context/Current.sol"; +import {Current} from "devkit/registry/context/Current.sol"; /**============================ diff --git a/devkit/registry/FunctionRegistry.sol b/devkit/registry/FunctionRegistry.sol index 0fc6fcfb..e4019e6b 100644 --- a/devkit/registry/FunctionRegistry.sol +++ b/devkit/registry/FunctionRegistry.sol @@ -9,7 +9,7 @@ using ProcessLib for FunctionRegistry global; import {Require} from "devkit/error/Require.sol"; // Context -import {Current} from "devkit/utils/context/Current.sol"; +import {Current} from "devkit/registry/context/Current.sol"; // Core Type import {Function} from "devkit/core/Function.sol"; diff --git a/devkit/registry/ProxyRegistry.sol b/devkit/registry/ProxyRegistry.sol index 23e43fc0..e4da8417 100644 --- a/devkit/registry/ProxyRegistry.sol +++ b/devkit/registry/ProxyRegistry.sol @@ -16,7 +16,7 @@ import {Require} from "devkit/error/Require.sol"; import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; import {Dictionary} from "devkit/core/Dictionary.sol"; // Context -import {Current} from "devkit/utils/context/Current.sol"; +import {Current} from "devkit/registry/context/Current.sol"; /**======================= diff --git a/devkit/utils/context/Current.sol b/devkit/registry/context/Current.sol similarity index 100% rename from devkit/utils/context/Current.sol rename to devkit/registry/context/Current.sol index ab15795c..a669259e 100644 --- a/devkit/utils/context/Current.sol +++ b/devkit/registry/context/Current.sol @@ -6,7 +6,6 @@ pragma solidity ^0.8.24; import {Params} from "devkit/debug/Params.sol"; import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for Current global; - // Validation import {Require} from "devkit/error/Require.sol"; @@ -19,6 +18,7 @@ struct Current { string name; } library CurrentLib { + /**------------------------------- 🔄 Update Current Context ---------------------------------*/ diff --git a/devkit/utils/debug/ProcessLib.sol b/devkit/utils/debug/ProcessLib.sol index 9737d6b9..34de2854 100644 --- a/devkit/utils/debug/ProcessLib.sol +++ b/devkit/utils/debug/ProcessLib.sol @@ -13,7 +13,7 @@ import {Proxy} from "devkit/core/Proxy.sol"; import {ProxyRegistry} from "devkit/registry/ProxyRegistry.sol"; import {Dictionary} from "devkit/core/Dictionary.sol"; import {DictionaryRegistry} from "devkit/registry/DictionaryRegistry.sol"; -import {Current} from "devkit/utils/context/Current.sol"; +import {Current} from "devkit/registry/context/Current.sol"; /**================= From 179dce756ee1fdcf32bedc5fcd230c5cf00f3eaf Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 17:27:47 +0900 Subject: [PATCH 087/111] Restructure --- devkit/MCTest.sol | 2 +- devkit/config/Config.sol | 2 +- devkit/core/Bundle.sol | 16 +++---- devkit/core/Dictionary.sol | 20 ++++----- devkit/core/Function.sol | 12 ++--- devkit/core/Proxy.sol | 4 +- devkit/error/Validate.sol | 17 ------- devkit/{ => log}/debug/Debug.sol | 14 +++--- devkit/{ => log}/debug/Logger.sol | 4 +- devkit/{ => log}/debug/Params.sol | 0 devkit/{ => log}/error/DecodeErrorString.sol | 0 devkit/log/error/ThrowError.sol | 10 +++++ .../Error.sol => log/message/Errors.sol} | 9 +--- devkit/log/message/Warnings.sol | 34 ++++++++++++++ devkit/registry/BundleRegistry.sol | 12 ++--- devkit/registry/DictionaryRegistry.sol | 22 +++++----- devkit/registry/FunctionRegistry.sol | 12 ++--- devkit/registry/ProxyRegistry.sol | 20 ++++----- devkit/registry/StdFunctions.sol | 8 ++-- devkit/registry/StdRegistry.sol | 6 +-- devkit/registry/context/Current.sol | 6 +-- devkit/types/TypeGuard.sol | 44 +++++++++---------- devkit/utils/debug/Dumper.sol | 2 +- devkit/utils/debug/ProcessLib.sol | 2 +- devkit/utils/global/MCBundleLib.sol | 8 ++-- devkit/utils/global/MCDebugLib.sol | 4 +- devkit/utils/global/MCDeployLib.sol | 4 +- devkit/utils/global/MCTestLib.sol | 8 ++-- devkit/utils/inspector/Inspector.sol | 4 +- devkit/utils/inspector/MappingAnalyzer.sol | 3 +- devkit/utils/primitive/AddressUtils.sol | 2 +- devkit/utils/primitive/Bytes4Utils.sol | 2 +- devkit/utils/primitive/StringUtils.sol | 4 +- devkit/utils/primitive/UintUtils.sol | 2 +- .../Require.sol => validate/Validate.sol} | 17 ++++--- test/devkit/global/MCBundle.t.sol | 2 +- 36 files changed, 183 insertions(+), 155 deletions(-) delete mode 100644 devkit/error/Validate.sol rename devkit/{ => log}/debug/Debug.sol (87%) rename devkit/{ => log}/debug/Logger.sol (96%) rename devkit/{ => log}/debug/Params.sol (100%) rename devkit/{ => log}/error/DecodeErrorString.sol (100%) create mode 100644 devkit/log/error/ThrowError.sol rename devkit/{error/Error.sol => log/message/Errors.sol} (87%) create mode 100644 devkit/log/message/Warnings.sol rename devkit/{error/Require.sol => validate/Validate.sol} (94%) diff --git a/devkit/MCTest.sol b/devkit/MCTest.sol index f39f4ae7..4ca424aa 100644 --- a/devkit/MCTest.sol +++ b/devkit/MCTest.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {Config} from "devkit/config/Config.sol"; -import {DecodeErrorString} from "devkit/error/DecodeErrorString.sol"; +import {DecodeErrorString} from "devkit/log/error/DecodeErrorString.sol"; // đŸ’Ŧ ABOUT // Meta Contract's default Test based on Forge Std Test diff --git a/devkit/config/Config.sol b/devkit/config/Config.sol index 81861293..358bdb3e 100644 --- a/devkit/config/Config.sol +++ b/devkit/config/Config.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -import {LogLevel} from "devkit/debug/Debug.sol"; +import {LogLevel} from "devkit/log/debug/Debug.sol"; /**---------------------- diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index a83e7cca..e61c196a 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -12,8 +12,8 @@ import {Inspector} from "devkit/utils/inspector/Inspector.sol"; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Bundle global; // Validation -import {validate} from "devkit/error/Validate.sol"; -import {Require} from "devkit/error/Require.sol"; +import {validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/validate/Validate.sol"; // Core Type import {Function} from "devkit/core/Function.sol"; @@ -36,8 +36,8 @@ library BundleLib { ----------------------*/ function assignName(Bundle storage bundle, string memory name) internal returns(Bundle storage) { uint pid = bundle.startProcess("assignName"); - Require.notLocked(bundle.status); - Require.notEmpty(name); + Validate.notLocked(bundle.status); + Validate.notEmpty(name); bundle.name = name; return bundle.building().finishProcess(pid); } @@ -47,9 +47,9 @@ library BundleLib { ---------------------------*/ function pushFunction(Bundle storage bundle, Function storage func) internal returns(Bundle storage) { uint pid = bundle.startProcess("pushFunction"); - Require.notLocked(bundle.status); - Require.isComplete(func); - Require.hasNot(bundle, func); + Validate.notLocked(bundle.status); + Validate.isComplete(func); + Validate.hasNot(bundle, func); bundle.functions.push(func); return bundle.building().finishProcess(pid); } @@ -66,7 +66,7 @@ library BundleLib { ------------------------*/ function assignFacade(Bundle storage bundle, address facade) internal returns(Bundle storage) { uint pid = bundle.startProcess("assignFacade"); - Require.isContract(facade); + Validate.isContract(facade); bundle.facade = facade; return bundle.building().finishProcess(pid); } diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 55971c1e..7f24b6f4 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; -----------------------*/ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for Dictionary global; -import {Params} from "devkit/debug/Params.sol"; +import {Params} from "devkit/log/debug/Params.sol"; import {Inspector} from "devkit/utils/inspector/Inspector.sol"; using Inspector for Dictionary global; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; @@ -13,7 +13,7 @@ import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; using Bytes4Utils for bytes4; // Validation -import {Require} from "devkit/error/Require.sol"; +import {Validate} from "devkit/validate/Validate.sol"; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Dictionary global; @@ -51,7 +51,7 @@ library DictionaryLib { ---------------------------*/ function deploy(address owner) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("deploy"); - Require.notZero(owner); + Validate.notZero(owner); /// @dev Until Etherscan supports UCS, we are deploying contracts with additional features for Etherscan compatibility by default. return Dictionary({ addr: address(new DictionaryEtherscan(owner)), @@ -65,8 +65,8 @@ library DictionaryLib { ------------------------------*/ function duplicate(Dictionary memory toDictionary, Dictionary memory fromDictionary) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("duplicate"); - Require.notEmpty(toDictionary); - Require.notEmpty(fromDictionary); + Validate.notEmpty(toDictionary); + Validate.notEmpty(fromDictionary); address toAddr = toDictionary.addr; address fromAddr = fromDictionary.addr; @@ -89,9 +89,9 @@ library DictionaryLib { -------------------------------*/ function set(Dictionary memory dictionary, bytes4 selector, address implementation) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(selector, implementation)); - Require.isContract(dictionary.addr); - Require.notEmpty(selector); - Require.isContract(implementation); + Validate.isContract(dictionary.addr); + Validate.notEmpty(selector); + Validate.isContract(implementation); IDictionary(dictionary.addr).setImplementation({ functionSelector: selector, implementation: implementation @@ -124,8 +124,8 @@ library DictionaryLib { ------------------------*/ function upgradeFacade(Dictionary memory dictionary, address newFacade) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("upgradeFacade"); - Require.isContract(newFacade); - // Require.verifiable(dictionary); TODO without CALL + Validate.isContract(newFacade); + // Validate.verifiable(dictionary); TODO without CALL DictionaryEtherscan(dictionary.addr).upgradeFacade(newFacade); return dictionary.finishProcess(pid); } diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index f3ec7c9d..a3fd278c 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -12,7 +12,7 @@ import {Dumper} from "devkit/utils/debug/Dumper.sol"; import {Inspector} from "devkit/utils/inspector/Inspector.sol"; using Inspector for Function global; // Validation -import {Require} from "devkit/error/Require.sol"; +import {Validate} from "devkit/validate/Validate.sol"; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Function global; // Loader @@ -47,7 +47,7 @@ library FunctionLib { ----------------------*/ function assignName(Function storage func, string memory name) internal returns(Function storage) { uint pid = func.startProcess("assignName"); - Require.notLocked(func.status); + Validate.notLocked(func.status); func.name = name; return func.building().finishProcess(pid); } @@ -57,7 +57,7 @@ library FunctionLib { --------------------------*/ function assignSelector(Function storage func, bytes4 selector) internal returns(Function storage) { uint pid = func.startProcess("assignSelector"); - Require.notLocked(func.status); + Validate.notLocked(func.status); func.selector = selector; return func.building().finishProcess(pid); } @@ -67,7 +67,7 @@ library FunctionLib { --------------------------------*/ function assignImplementation(Function storage func, address implementation) internal returns(Function storage) { uint pid = func.startProcess("assignImplementation"); - Require.notLocked(func.status); + Validate.notLocked(func.status); func.implementation = implementation; return func.building().finishProcess(pid); } @@ -77,8 +77,8 @@ library FunctionLib { -------------------------*/ function fetch(Function storage func, string memory envKey) internal returns(Function storage) { uint pid = func.startProcess("fetch"); - Require.notLocked(func.status); - Require.notEmpty(envKey); + Validate.notLocked(func.status); + Validate.notEmpty(envKey); func.assignName(envKey); func.assignImplementation(loadAddressFrom(envKey)); return func.building().finishProcess(pid); diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index 0da83071..e74f5fc2 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -9,7 +9,7 @@ import {Inspector} from "devkit/utils/inspector/Inspector.sol"; using Inspector for Proxy global; using Inspector for ProxyKind global; // Validation -import {Require} from "devkit/error/Require.sol";// Core Type +import {Validate} from "devkit/validate/Validate.sol";// Core Type import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Proxy global; @@ -39,7 +39,7 @@ library ProxyLib { -----------------------*/ function deploy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory) { uint pid = ProcessLib.startProxyLibProcess("deploy"); - Require.notEmpty(dictionary); + Validate.notEmpty(dictionary); return Proxy({ addr: address(new ERC7546ProxyEtherscan(dictionary.addr, initData)), kind: ProxyKind.Verifiable, diff --git a/devkit/error/Validate.sol b/devkit/error/Validate.sol deleted file mode 100644 index 301a68ce..00000000 --- a/devkit/error/Validate.sol +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import {throwError, ERR} from "devkit/error/Error.sol"; -// Utils -import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; - using BoolUtils for bool; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; - using StringUtils for string; - -/// @dev like `require` -function validate(bool condition, string memory errorBody) { - if (condition.isFalse()) throwError(errorBody); -} -function validate(bool condition, string memory errorBody, string memory errorDetail) { - validate(condition, errorBody.append(errorDetail)); -} diff --git a/devkit/debug/Debug.sol b/devkit/log/debug/Debug.sol similarity index 87% rename from devkit/debug/Debug.sol rename to devkit/log/debug/Debug.sol index a08e9a9e..d06af9bb 100644 --- a/devkit/debug/Debug.sol +++ b/devkit/log/debug/Debug.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Utils -import {console2, StdStyle} from "../utils/ForgeHelper.sol"; +import {console2, StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; @@ -19,12 +19,12 @@ struct DebugState { uint nextPid; } enum LogLevel { - Disable, - Debug, - Info, - Warn, - Error, - Critical + Disable, // Display no message + Debug, // Display all messages including debug details + Info, // Display info, warning, and error messages + Warn, // Display warning and error messages + Error, // Display error messages only + Critical // Display critical error messages only } struct Process { string libName; diff --git a/devkit/debug/Logger.sol b/devkit/log/debug/Logger.sol similarity index 96% rename from devkit/debug/Logger.sol rename to devkit/log/debug/Logger.sol index 1882edc9..a3b422b9 100644 --- a/devkit/debug/Logger.sol +++ b/devkit/log/debug/Logger.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {ERR} from "devkit/error/Error.sol"; +import {ERR} from "devkit/log/message/Errors.sol"; // Utils -import {console2, StdStyle, vm} from "../utils/ForgeHelper.sol"; +import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; // Debug import {Debug, Process} from "./Debug.sol"; diff --git a/devkit/debug/Params.sol b/devkit/log/debug/Params.sol similarity index 100% rename from devkit/debug/Params.sol rename to devkit/log/debug/Params.sol diff --git a/devkit/error/DecodeErrorString.sol b/devkit/log/error/DecodeErrorString.sol similarity index 100% rename from devkit/error/DecodeErrorString.sol rename to devkit/log/error/DecodeErrorString.sol diff --git a/devkit/log/error/ThrowError.sol b/devkit/log/error/ThrowError.sol new file mode 100644 index 00000000..4a3f3575 --- /dev/null +++ b/devkit/log/error/ThrowError.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {Logger} from "devkit/log/debug/Logger.sol"; +import {ERR} from "devkit/log/message/Errors.sol"; + +function throwError(string memory errorBody) { + Logger.logError(errorBody); + revert(ERR.message(errorBody)); +} diff --git a/devkit/error/Error.sol b/devkit/log/message/Errors.sol similarity index 87% rename from devkit/error/Error.sol rename to devkit/log/message/Errors.sol index 4fe68a66..a275dd38 100644 --- a/devkit/error/Error.sol +++ b/devkit/log/message/Errors.sol @@ -5,15 +5,8 @@ pragma solidity ^0.8.24; import {StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; - using StringUtils for string; -// Debug -import {Logger} from "devkit/debug/Logger.sol"; - -function throwError(string memory errorBody) { - Logger.logError(errorBody); - revert(ERR.message(errorBody)); -} +/// @title Error Message library ERR { string constant HEADER = "\u2716 DevKit Error: "; string constant FIND_NAME_OVER_RANGE = "Default names are automatically set up to 5. Please manually assign names beyond that."; diff --git a/devkit/log/message/Warnings.sol b/devkit/log/message/Warnings.sol new file mode 100644 index 00000000..a275dd38 --- /dev/null +++ b/devkit/log/message/Warnings.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Utils +import {StdStyle} from "devkit/utils/ForgeHelper.sol"; + using StdStyle for string; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; + +/// @title Error Message +library ERR { + string constant HEADER = "\u2716 DevKit Error: "; + string constant FIND_NAME_OVER_RANGE = "Default names are automatically set up to 5. Please manually assign names beyond that."; + string constant EMPTY_STR = "Empty String"; + string constant EMPTY_B4 = "Empty Bytes4"; + string constant NOT_CONTRACT = "Not Contract Address"; + string constant STR_ALREADY_ASSIGNED = "String Already Assigned"; + string constant B4_ALREADY_ASSIGNED = "Bytes4 Already Assigned"; + string constant ZERO_ADDRESS = "Zero Address"; + + // Require + string constant RQ_SELECTOR = "Selector is required."; + string constant RQ_CONTRACT = "Contract is required."; + string constant RQ_NOT_EMPTY_STRING = "String is empty."; + string constant DICTIONARY_NOT_EXISTS = "Dictionary Not Exists"; + string constant EMPTY_DICTIONARY = "Empty Dictionary"; + string constant LOCKED_OBJECT = "Locaked Object"; + + // string constant STR_EXISTS = "String Already Exist"; + string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; + + function message(string memory errorBody) internal returns(string memory) { + return StringUtils.append(HEADER, errorBody).bold(); + } +} diff --git a/devkit/registry/BundleRegistry.sol b/devkit/registry/BundleRegistry.sol index 8a0d8684..623be755 100644 --- a/devkit/registry/BundleRegistry.sol +++ b/devkit/registry/BundleRegistry.sol @@ -10,7 +10,7 @@ import {Inspector} from "devkit/utils/inspector/Inspector.sol"; import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Bundle); // Validation -import {Require} from "devkit/error/Require.sol"; +import {Validate} from "devkit/validate/Validate.sol"; // Core Type import {Bundle} from "devkit/core/Bundle.sol"; @@ -34,9 +34,9 @@ library BundleRegistryLib { -----------------------*/ function init(BundleRegistry storage registry, string memory name) internal returns(BundleRegistry storage) { uint pid = registry.startProcess("init"); - Require.notEmpty(name); + Validate.notEmpty(name); Bundle storage bundle = registry.bundles[name]; - Require.isUnassigned(bundle); + Validate.isUnassigned(bundle); bundle.assignName(name); registry.current.update(name); return registry.finishProcess(pid); @@ -47,16 +47,16 @@ library BundleRegistryLib { ----------------------*/ function find(BundleRegistry storage registry, string memory name) internal returns(Bundle storage) { uint pid = registry.startProcess("find"); - Require.notEmpty(name); + Validate.notEmpty(name); // Warning.isComplete(registry, name); TODO Bundle storage bundle = registry.bundles[name]; - // Require.valid(bundle); TODO + // Validate.valid(bundle); TODO return bundle.finishProcess(pid); } function findCurrent(BundleRegistry storage registry) internal returns(Bundle storage) { uint pid = registry.startProcess("findCurrent"); string memory name = registry.current.name; - Require.notEmpty(name); + Validate.notEmpty(name); return registry.find(name).finishProcess(pid); } diff --git a/devkit/registry/DictionaryRegistry.sol b/devkit/registry/DictionaryRegistry.sol index f369ba60..d3388dc6 100644 --- a/devkit/registry/DictionaryRegistry.sol +++ b/devkit/registry/DictionaryRegistry.sol @@ -10,7 +10,7 @@ import {Inspector} from "devkit/utils/inspector/Inspector.sol"; import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Dictionary); // Validation -import {Require} from "devkit/error/Require.sol"; +import {Validate} from "devkit/validate/Validate.sol"; // Core Type import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; @@ -34,9 +34,9 @@ library DictionaryRegistryLib { ---------------------------------------*/ function deploy(DictionaryRegistry storage registry, string memory name, Bundle storage bundle, address owner) internal returns(Dictionary storage) { uint pid = registry.startProcess("deploy"); - Require.notEmpty(name); - Require.exists(bundle); - Require.notZero(owner); + Validate.notEmpty(name); + Validate.exists(bundle); + Validate.notZero(owner); Dictionary memory dictionary = DictionaryLib.deploy(owner) .set(bundle) .upgradeFacade(bundle.facade); @@ -49,9 +49,9 @@ library DictionaryRegistryLib { -----------------------------*/ function register(DictionaryRegistry storage registry, string memory name, Dictionary memory dictionary) internal returns(Dictionary storage) { uint pid = registry.startProcess("register"); - Require.notEmpty(name); - Require.notEmpty(dictionary); - Require.notRegistered(registry, name); + Validate.notEmpty(name); + Validate.notEmpty(dictionary); + Validate.notRegistered(registry, name); Dictionary storage dictionaryStorage = registry.dictionaries[name] = dictionary; dictionaryStorage.build().lock(); registry.current.update(name); @@ -63,16 +63,16 @@ library DictionaryRegistryLib { --------------------------*/ function find(DictionaryRegistry storage registry, string memory name) internal returns(Dictionary storage) { uint pid = registry.startProcess("find"); - Require.notEmpty(name); - Require.validRegistration(registry, name); + Validate.notEmpty(name); + Validate.validRegistration(registry, name); Dictionary storage dictionary = registry.dictionaries[name]; - Require.valid(dictionary); + Validate.valid(dictionary); return dictionary.finishProcessInStorage(pid); } function findCurrent(DictionaryRegistry storage registry) internal returns(Dictionary storage) { uint pid = registry.startProcess("findCurrent"); string memory name = registry.current.name; - Require.notEmpty(name); + Validate.notEmpty(name); return registry.find(name).finishProcessInStorage(pid); } diff --git a/devkit/registry/FunctionRegistry.sol b/devkit/registry/FunctionRegistry.sol index e4019e6b..cad530d9 100644 --- a/devkit/registry/FunctionRegistry.sol +++ b/devkit/registry/FunctionRegistry.sol @@ -6,7 +6,7 @@ pragma solidity ^0.8.24; import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for FunctionRegistry global; // Validation -import {Require} from "devkit/error/Require.sol"; +import {Validate} from "devkit/validate/Validate.sol"; // Context import {Current} from "devkit/registry/context/Current.sol"; @@ -29,7 +29,7 @@ library FunctionRegistryLib { ----------------------------*/ function register(FunctionRegistry storage registry, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { uint pid = registry.startProcess("register"); - Require.notEmpty(name); + Validate.notEmpty(name); registry.functions[name].assign(name, selector, implementation).build().lock(); registry.current.update(name); return registry.finishProcess(pid); @@ -40,16 +40,16 @@ library FunctionRegistryLib { ------------------------*/ function find(FunctionRegistry storage registry, string memory name) internal returns(Function storage) { uint pid = registry.startProcess("find"); - Require.notEmpty(name); - Require.validRegistration(registry, name); + Validate.notEmpty(name); + Validate.validRegistration(registry, name); Function storage func = registry.functions[name]; - Require.valid(func); + Validate.valid(func); return func.finishProcess(pid); } function findCurrent(FunctionRegistry storage registry) internal returns(Function storage) { uint pid = registry.startProcess("findCurrent"); string memory name = registry.current.name; - Require.notEmpty(name); + Validate.notEmpty(name); return registry.find(name).finishProcess(pid); } diff --git a/devkit/registry/ProxyRegistry.sol b/devkit/registry/ProxyRegistry.sol index e4da8417..41fdc023 100644 --- a/devkit/registry/ProxyRegistry.sol +++ b/devkit/registry/ProxyRegistry.sol @@ -10,7 +10,7 @@ import {Inspector} from "devkit/utils/inspector/Inspector.sol"; import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Proxy); // Validation -import {Require} from "devkit/error/Require.sol"; +import {Validate} from "devkit/validate/Validate.sol"; // Core Type import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; @@ -34,8 +34,8 @@ library ProxyRegistryLib { ---------------------------------*/ function deploy(ProxyRegistry storage registry, string memory name, Dictionary memory dictionary, bytes memory initData) internal returns(Proxy storage) { uint pid = registry.startProcess("deploy"); - Require.notEmpty(name); - Require.notEmpty(dictionary); + Validate.notEmpty(name); + Validate.notEmpty(dictionary); Proxy memory proxy = ProxyLib.deploy(dictionary, initData); registry.register(name, proxy); return registry.findCurrent().finishProcessInStorage(pid); @@ -46,9 +46,9 @@ library ProxyRegistryLib { -------------------------*/ function register(ProxyRegistry storage registry, string memory name, Proxy memory proxy) internal returns(Proxy storage) { uint pid = registry.startProcess("register"); - Require.notEmpty(name); - Require.notEmpty(proxy); - Require.notRegistered(registry, name); + Validate.notEmpty(name); + Validate.notEmpty(proxy); + Validate.notRegistered(registry, name); Proxy storage proxyStorage = registry.proxies[name] = proxy; proxyStorage.build().lock(); registry.current.update(name); @@ -60,16 +60,16 @@ library ProxyRegistryLib { ---------------------*/ function find(ProxyRegistry storage registry, string memory name) internal returns(Proxy storage) { uint pid = registry.startProcess("find"); - Require.notEmpty(name); - Require.validRegistration(registry, name); + Validate.notEmpty(name); + Validate.validRegistration(registry, name); Proxy storage proxy = registry.proxies[name]; - Require.valid(proxy); + Validate.valid(proxy); return proxy.finishProcessInStorage(pid); } function findCurrent(ProxyRegistry storage registry) internal returns(Proxy storage) { uint pid = registry.startProcess("findCurrent"); string memory name = registry.current.name; - Require.notEmpty(name); + Validate.notEmpty(name); return registry.find(name).finishProcessInStorage(pid); } diff --git a/devkit/registry/StdFunctions.sol b/devkit/registry/StdFunctions.sol index b5aadded..4f42e823 100644 --- a/devkit/registry/StdFunctions.sol +++ b/devkit/registry/StdFunctions.sol @@ -7,7 +7,7 @@ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for StdFunctions global; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for StdFunctions global; -import {Require} from "devkit/error/Require.sol"; +import {Validate} from "devkit/validate/Validate.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; @@ -67,7 +67,7 @@ library StdFunctionsLib { /**===== Each Std Function =====*/ function fetch_InitSetAdmin(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { uint pid = stdFunctions.startProcess("fetch_InitSetAdmin"); - Require.notLocked(stdFunctions.initSetAdmin.status); + Validate.notLocked(stdFunctions.initSetAdmin.status); stdFunctions.initSetAdmin .fetch("InitSetAdmin") .assignSelector(InitSetAdmin.initSetAdmin.selector) .dump(); @@ -76,7 +76,7 @@ library StdFunctionsLib { function fetch_GetDeps(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { uint pid = stdFunctions.startProcess("fetch_GetDeps"); - Require.notLocked(stdFunctions.getDeps.status); + Validate.notLocked(stdFunctions.getDeps.status); stdFunctions.getDeps.fetch("GetDeps") .assignSelector(GetDeps.getDeps.selector) .dump(); @@ -85,7 +85,7 @@ library StdFunctionsLib { function fetch_Clone(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { uint pid = stdFunctions.startProcess("fetch_Clone"); - Require.notLocked(stdFunctions.clone.status); + Validate.notLocked(stdFunctions.clone.status); stdFunctions.clone .fetch("Clone") .assignSelector(Clone.clone.selector) .dump(); diff --git a/devkit/registry/StdRegistry.sol b/devkit/registry/StdRegistry.sol index 53807d3b..634e07e7 100644 --- a/devkit/registry/StdRegistry.sol +++ b/devkit/registry/StdRegistry.sol @@ -11,7 +11,7 @@ import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; using AddressUtils for address; // Validation -import {Require} from "devkit/error/Require.sol"; +import {Validate} from "devkit/validate/Validate.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; @@ -42,7 +42,7 @@ library StdRegistryLib { ------------------------------------*/ function complete(StdRegistry storage registry) internal returns(StdRegistry storage) { uint pid = registry.startProcess("complete"); - Require.notLocked(registry.status); + Validate.notLocked(registry.status); registry.functions.complete(); registry.configureStdBundle(); return registry.build().lock().finishProcess(pid); @@ -58,7 +58,7 @@ library StdRegistryLib { /**===== Each Std Bundle =====*/ function configureStdBundle_All(StdRegistry storage registry) internal returns(StdRegistry storage) { uint pid = registry.startProcess("configureStdBundle_All"); - Require.notLocked(registry.all.status); + Validate.notLocked(registry.all.status); registry.all.assignName("ALL_STD_FUNCTIONS") .pushFunction(registry.functions.initSetAdmin) .pushFunction(registry.functions.getDeps) diff --git a/devkit/registry/context/Current.sol b/devkit/registry/context/Current.sol index a669259e..5f41d228 100644 --- a/devkit/registry/context/Current.sol +++ b/devkit/registry/context/Current.sol @@ -3,11 +3,11 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {Params} from "devkit/debug/Params.sol"; +import {Params} from "devkit/log/debug/Params.sol"; import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for Current global; // Validation -import {Require} from "devkit/error/Require.sol"; +import {Validate} from "devkit/validate/Validate.sol"; /**======================== @@ -24,7 +24,7 @@ library CurrentLib { ---------------------------------*/ function update(Current storage current, string memory name) internal { uint pid = current.startProcess("update", Params.append(name)); - Require.notEmpty(name); + Validate.notEmpty(name); current.name = name; ProcessLib.finishProcess(pid); } diff --git a/devkit/types/TypeGuard.sol b/devkit/types/TypeGuard.sol index 1eb1ff1a..f9349975 100644 --- a/devkit/types/TypeGuard.sol +++ b/devkit/types/TypeGuard.sol @@ -7,7 +7,7 @@ pragma solidity ^0.8.24; // using AddressUtils for address; // import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; // using Bytes4Utils for bytes4; -import {Require} from "devkit/error/Require.sol"; +import {Validate} from "devkit/validate/Validate.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; @@ -44,14 +44,14 @@ library TypeGuard { return func; } function build(Function storage func) internal returns(Function storage) { - Require.assigned(func.name); - Require.assigned(func.selector); - Require.contractAssigned(func.implementation); + Validate.assigned(func.name); + Validate.assigned(func.selector); + Validate.contractAssigned(func.implementation); func.status = TypeStatus.Built; return func; } function lock(Function storage func) internal returns(Function storage) { - Require.isBuilt(func.status); + Validate.isBuilt(func.status); func.status = TypeStatus.Locked; return func; } @@ -68,14 +68,14 @@ library TypeGuard { return bundle; } function build(Bundle storage bundle) internal returns(Bundle storage) { - Require.assigned(bundle.name); - Require.notZero(bundle.functions.length); - Require.contractAssigned(bundle.facade); + Validate.assigned(bundle.name); + Validate.notZero(bundle.functions.length); + Validate.contractAssigned(bundle.facade); bundle.status = TypeStatus.Built; return bundle; } function lock(Bundle storage bundle) internal returns(Bundle storage) { - Require.isBuilt(bundle.status); + Validate.isBuilt(bundle.status); bundle.status = TypeStatus.Locked; return bundle; } @@ -92,13 +92,13 @@ library TypeGuard { return registry; } function build(StdRegistry storage registry) internal returns(StdRegistry storage) { - Require.isComplete(registry.functions); - Require.isComplete(registry.all); + Validate.isComplete(registry.functions); + Validate.isComplete(registry.all); registry.status = TypeStatus.Built; return registry; } function lock(StdRegistry storage registry) internal returns(StdRegistry storage) { - Require.isBuilt(registry.status); + Validate.isBuilt(registry.status); registry.status = TypeStatus.Locked; return registry; } @@ -112,14 +112,14 @@ library TypeGuard { return stdFunctions; } function build(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { - Require.isComplete(stdFunctions.initSetAdmin); - Require.isComplete(stdFunctions.getDeps); - Require.isComplete(stdFunctions.clone); + Validate.isComplete(stdFunctions.initSetAdmin); + Validate.isComplete(stdFunctions.getDeps); + Validate.isComplete(stdFunctions.clone); stdFunctions.status = TypeStatus.Built; return stdFunctions; } function lock(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { - Require.isBuilt(stdFunctions.status); + Validate.isBuilt(stdFunctions.status); stdFunctions.status = TypeStatus.Locked; return stdFunctions; } @@ -133,13 +133,13 @@ library TypeGuard { return dictionary; } function build(Dictionary storage dictionary) internal returns(Dictionary storage) { - Require.isContract(dictionary.addr); - Require.notUndefined(dictionary.kind); + Validate.isContract(dictionary.addr); + Validate.notUndefined(dictionary.kind); dictionary.status = TypeStatus.Built; return dictionary; } function lock(Dictionary storage dictionary) internal returns(Dictionary storage) { - Require.isBuilt(dictionary.status); + Validate.isBuilt(dictionary.status); dictionary.status = TypeStatus.Locked; return dictionary; } @@ -156,13 +156,13 @@ library TypeGuard { return proxy; } function build(Proxy storage proxy) internal returns(Proxy storage) { - Require.isContract(proxy.addr); - Require.notUndefined(proxy.kind); + Validate.isContract(proxy.addr); + Validate.notUndefined(proxy.kind); proxy.status = TypeStatus.Built; return proxy; } function lock(Proxy storage proxy) internal returns(Proxy storage) { - Require.isBuilt(proxy.status); + Validate.isBuilt(proxy.status); proxy.status = TypeStatus.Locked; return proxy; } diff --git a/devkit/utils/debug/Dumper.sol b/devkit/utils/debug/Dumper.sol index 120e0cff..87617a2a 100644 --- a/devkit/utils/debug/Dumper.sol +++ b/devkit/utils/debug/Dumper.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Logger} from "devkit/debug/Logger.sol"; +import {Logger} from "devkit/log/debug/Logger.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; diff --git a/devkit/utils/debug/ProcessLib.sol b/devkit/utils/debug/ProcessLib.sol index 34de2854..9f90aeec 100644 --- a/devkit/utils/debug/ProcessLib.sol +++ b/devkit/utils/debug/ProcessLib.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Debug} from "devkit/debug/Debug.sol"; +import {Debug} from "devkit/log/debug/Debug.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {FunctionRegistry} from "devkit/registry/FunctionRegistry.sol"; diff --git a/devkit/utils/global/MCBundleLib.sol b/devkit/utils/global/MCBundleLib.sol index 38d1aed8..0df93c18 100644 --- a/devkit/utils/global/MCBundleLib.sol +++ b/devkit/utils/global/MCBundleLib.sol @@ -3,12 +3,12 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Validation -import {Require} from "devkit/error/Require.sol"; -import {validate} from "devkit/error/Validate.sol"; -import {ERR} from "devkit/error/Error.sol"; +import {Validate} from "devkit/validate/Validate.sol"; +import {validate} from "devkit/validate/Validate.sol"; +import {ERR} from "devkit/log/message/Errors.sol"; // Utils import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -import {Params} from "devkit/debug/Params.sol"; +import {Params} from "devkit/log/debug/Params.sol"; // Core import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; diff --git a/devkit/utils/global/MCDebugLib.sol b/devkit/utils/global/MCDebugLib.sol index fb19f81c..82271a02 100644 --- a/devkit/utils/global/MCDebugLib.sol +++ b/devkit/utils/global/MCDebugLib.sol @@ -3,8 +3,8 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Debug -import {Debug} from "devkit/debug/Debug.sol"; -import {Logger} from "devkit/debug/Logger.sol"; +import {Debug} from "devkit/log/debug/Debug.sol"; +import {Logger} from "devkit/log/debug/Logger.sol"; /*********************************************** diff --git a/devkit/utils/global/MCDeployLib.sol b/devkit/utils/global/MCDeployLib.sol index 7dc4e022..d872de80 100644 --- a/devkit/utils/global/MCDeployLib.sol +++ b/devkit/utils/global/MCDeployLib.sol @@ -4,9 +4,9 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; import {Config} from "devkit/config/Config.sol"; // Validation -import {validate} from "devkit/error/Validate.sol"; +import {validate} from "devkit/validate/Validate.sol"; // Utils -import {Params} from "devkit/debug/Params.sol"; +import {Params} from "devkit/log/debug/Params.sol"; // Core // dictionary import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; diff --git a/devkit/utils/global/MCTestLib.sol b/devkit/utils/global/MCTestLib.sol index 6709615c..00a94813 100644 --- a/devkit/utils/global/MCTestLib.sol +++ b/devkit/utils/global/MCTestLib.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; // Validation -import {Require} from "devkit/error/Require.sol"; +import {Validate} from "devkit/validate/Validate.sol"; import {MCDevKit} from "devkit/MCDevKit.sol"; import {Config} from "devkit/config/Config.sol"; // Utils -import {Params} from "devkit/debug/Params.sol"; +import {Params} from "devkit/log/debug/Params.sol"; // Core // functions import {Bundle} from "devkit/core/Bundle.sol"; @@ -52,7 +52,7 @@ library MCTestLib { */ function createProxySimpleMock(MCDevKit storage mc, string memory name, Function[] memory functions) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("createProxySimpleMock", Params.append(name)); // TODO append functions - Require.notEmpty(name); + Validate.notEmpty(name); // TODO Check Functions? Proxy memory proxyMock = ProxyLib.createSimpleMock(functions); mc.proxy.register(name, proxyMock); @@ -86,7 +86,7 @@ library MCTestLib { */ function createMockDictionary(MCDevKit storage mc, string memory name, address owner, Function[] memory functions) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("createMockDictionary", Params.append(name, owner)); - Require.notEmpty(name); + Validate.notEmpty(name); // TODO Check Functions? Dictionary memory dictionaryMock = DictionaryLib.createMock(owner, functions); mc.dictionary.register(name, dictionaryMock); diff --git a/devkit/utils/inspector/Inspector.sol b/devkit/utils/inspector/Inspector.sol index d5ac7ba7..651b41ae 100644 --- a/devkit/utils/inspector/Inspector.sol +++ b/devkit/utils/inspector/Inspector.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {validate} from "devkit/error/Validate.sol"; -import {Require} from "devkit/error/Require.sol"; +import {validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/validate/Validate.sol"; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; diff --git a/devkit/utils/inspector/MappingAnalyzer.sol b/devkit/utils/inspector/MappingAnalyzer.sol index 22f956cb..4ae582e5 100644 --- a/devkit/utils/inspector/MappingAnalyzer.sol +++ b/devkit/utils/inspector/MappingAnalyzer.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {throwError, ERR} from "devkit/error/Error.sol"; +import {throwError} from "devkit/log/error/ThrowError.sol"; +import {ERR} from "devkit/log/message/Errors.sol"; import {Config, ScanRange} from "devkit/config/Config.sol"; // Core Types import {Bundle} from "devkit/core/Bundle.sol"; diff --git a/devkit/utils/primitive/AddressUtils.sol b/devkit/utils/primitive/AddressUtils.sol index 6790b4e1..488e7c99 100644 --- a/devkit/utils/primitive/AddressUtils.sol +++ b/devkit/utils/primitive/AddressUtils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {validate} from "devkit/error/Validate.sol"; +import {validate} from "devkit/validate/Validate.sol"; // Utils import {vm} from "devkit/utils/ForgeHelper.sol"; import {BoolUtils} from "./BoolUtils.sol"; diff --git a/devkit/utils/primitive/Bytes4Utils.sol b/devkit/utils/primitive/Bytes4Utils.sol index b057d993..b6d79eba 100644 --- a/devkit/utils/primitive/Bytes4Utils.sol +++ b/devkit/utils/primitive/Bytes4Utils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {validate} from "devkit/error/Validate.sol"; +import {validate} from "devkit/validate/Validate.sol"; // Utils import {vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "./StringUtils.sol"; diff --git a/devkit/utils/primitive/StringUtils.sol b/devkit/utils/primitive/StringUtils.sol index 4ef447a5..653b22b8 100644 --- a/devkit/utils/primitive/StringUtils.sol +++ b/devkit/utils/primitive/StringUtils.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.24; // Validation -import {validate} from "devkit/error/Validate.sol"; -import {Debug} from "devkit/debug/Debug.sol"; +import {validate} from "devkit/validate/Validate.sol"; +import {Debug} from "devkit/log/debug/Debug.sol"; // Utils import {StdStyle, ForgeHelper, vm} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; diff --git a/devkit/utils/primitive/UintUtils.sol b/devkit/utils/primitive/UintUtils.sol index 4991a9d5..285f686b 100644 --- a/devkit/utils/primitive/UintUtils.sol +++ b/devkit/utils/primitive/UintUtils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {validate} from "devkit/error/Validate.sol"; +import {validate} from "devkit/validate/Validate.sol"; // Utils import {vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; diff --git a/devkit/error/Require.sol b/devkit/validate/Validate.sol similarity index 94% rename from devkit/error/Require.sol rename to devkit/validate/Validate.sol index 8c2aca97..ef6e00e8 100644 --- a/devkit/error/Require.sol +++ b/devkit/validate/Validate.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {throwError, ERR} from "devkit/error/Error.sol"; -import {validate} from "devkit/error/Validate.sol"; +import {throwError} from "devkit/log/error/ThrowError.sol"; +import {ERR} from "devkit/log/message/Errors.sol"; // Utils import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; using BoolUtils for bool; @@ -27,8 +27,15 @@ import {DictionaryRegistry} from "devkit/registry/DictionaryRegistry.sol"; import {StdRegistry} from "devkit/registry/StdRegistry.sol"; import {StdFunctions} from "devkit/registry/StdFunctions.sol"; +/// @dev like `require` +function validate(bool condition, string memory errorBody) { + if (condition.isFalse()) throwError(errorBody); +} +function validate(bool condition, string memory errorBody, string memory errorDetail) { + validate(condition, errorBody.append(errorDetail)); +} -library Require { +library Validate { /** Type Guard */ @@ -60,10 +67,10 @@ library Require { } function EmptyName(Function storage func) internal { - Require.isUnassigned(func.name); + Validate.isUnassigned(func.name); } function EmptySelector(Function storage func) internal { - Require.isUnassigned(func.selector); + Validate.isUnassigned(func.selector); } function EmptyImpl(Function storage func) internal { validate(func.implementation.isNotContract(), "Implementation Already Exist"); diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 89b43579..5fe23aab 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -6,7 +6,7 @@ import {MCDevKitTest} from "devkit/MCTest.sol"; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; import {Config} from "devkit/config/Config.sol"; -import {ERR} from "devkit/error/Error.sol"; +import {ERR} from "devkit/log/message/Errors.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; From c190c76fb469374ba835ae4a0b2d78265d6961ba Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Thu, 11 Apr 2024 19:28:45 +0900 Subject: [PATCH 088/111] Improve validation & debugger --- devkit/log/debug/Logger.sol | 2 +- devkit/log/error/ThrowError.sol | 2 +- devkit/log/message/{Errors.sol => ERR.sol} | 0 devkit/log/message/{Warnings.sol => WARN.sol} | 0 devkit/registry/BundleRegistry.sol | 8 ++--- devkit/utils/global/MCBundleLib.sol | 2 +- devkit/utils/inspector/MappingAnalyzer.sol | 2 +- devkit/validate/Validate.sol | 33 +++++++++++++++++-- test/devkit/global/MCBundle.t.sol | 2 +- 9 files changed, 39 insertions(+), 12 deletions(-) rename devkit/log/message/{Errors.sol => ERR.sol} (100%) rename devkit/log/message/{Warnings.sol => WARN.sol} (100%) diff --git a/devkit/log/debug/Logger.sol b/devkit/log/debug/Logger.sol index a3b422b9..5de1cf36 100644 --- a/devkit/log/debug/Logger.sol +++ b/devkit/log/debug/Logger.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {ERR} from "devkit/log/message/Errors.sol"; +import {ERR} from "devkit/log/message/ERR.sol"; // Utils import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; diff --git a/devkit/log/error/ThrowError.sol b/devkit/log/error/ThrowError.sol index 4a3f3575..4b4a6d58 100644 --- a/devkit/log/error/ThrowError.sol +++ b/devkit/log/error/ThrowError.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {Logger} from "devkit/log/debug/Logger.sol"; -import {ERR} from "devkit/log/message/Errors.sol"; +import {ERR} from "devkit/log/message/ERR.sol"; function throwError(string memory errorBody) { Logger.logError(errorBody); diff --git a/devkit/log/message/Errors.sol b/devkit/log/message/ERR.sol similarity index 100% rename from devkit/log/message/Errors.sol rename to devkit/log/message/ERR.sol diff --git a/devkit/log/message/Warnings.sol b/devkit/log/message/WARN.sol similarity index 100% rename from devkit/log/message/Warnings.sol rename to devkit/log/message/WARN.sol diff --git a/devkit/registry/BundleRegistry.sol b/devkit/registry/BundleRegistry.sol index 623be755..d8ffba9a 100644 --- a/devkit/registry/BundleRegistry.sol +++ b/devkit/registry/BundleRegistry.sol @@ -47,16 +47,16 @@ library BundleRegistryLib { ----------------------*/ function find(BundleRegistry storage registry, string memory name) internal returns(Bundle storage) { uint pid = registry.startProcess("find"); - Validate.notEmpty(name); - // Warning.isComplete(registry, name); TODO + Validate.MUST_notEmpty(name); + Validate.SHOULD_beCompleted(registry, name); Bundle storage bundle = registry.bundles[name]; - // Validate.valid(bundle); TODO + Validate.SHOULD_valid(bundle); return bundle.finishProcess(pid); } function findCurrent(BundleRegistry storage registry) internal returns(Bundle storage) { uint pid = registry.startProcess("findCurrent"); string memory name = registry.current.name; - Validate.notEmpty(name); + Validate.MUST_notEmpty(name); return registry.find(name).finishProcess(pid); } diff --git a/devkit/utils/global/MCBundleLib.sol b/devkit/utils/global/MCBundleLib.sol index 0df93c18..f44e0eeb 100644 --- a/devkit/utils/global/MCBundleLib.sol +++ b/devkit/utils/global/MCBundleLib.sol @@ -5,7 +5,7 @@ import {MCDevKit} from "devkit/MCDevKit.sol"; // Validation import {Validate} from "devkit/validate/Validate.sol"; import {validate} from "devkit/validate/Validate.sol"; -import {ERR} from "devkit/log/message/Errors.sol"; +import {ERR} from "devkit/log/message/ERR.sol"; // Utils import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {Params} from "devkit/log/debug/Params.sol"; diff --git a/devkit/utils/inspector/MappingAnalyzer.sol b/devkit/utils/inspector/MappingAnalyzer.sol index 4ae582e5..bc300c76 100644 --- a/devkit/utils/inspector/MappingAnalyzer.sol +++ b/devkit/utils/inspector/MappingAnalyzer.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {throwError} from "devkit/log/error/ThrowError.sol"; -import {ERR} from "devkit/log/message/Errors.sol"; +import {ERR} from "devkit/log/message/ERR.sol"; import {Config, ScanRange} from "devkit/config/Config.sol"; // Core Types import {Bundle} from "devkit/core/Bundle.sol"; diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index ef6e00e8..0d758866 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -2,7 +2,9 @@ pragma solidity ^0.8.24; import {throwError} from "devkit/log/error/ThrowError.sol"; -import {ERR} from "devkit/log/message/Errors.sol"; +import {ERR} from "devkit/log/message/ERR.sol"; +import {Debug, LogLevel} from "devkit/log/debug/Debug.sol"; +import {Logger} from "devkit/log/debug/Logger.sol"; // Utils import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; using BoolUtils for bool; @@ -27,15 +29,27 @@ import {DictionaryRegistry} from "devkit/registry/DictionaryRegistry.sol"; import {StdRegistry} from "devkit/registry/StdRegistry.sol"; import {StdFunctions} from "devkit/registry/StdFunctions.sol"; + /// @dev like `require` -function validate(bool condition, string memory errorBody) { - if (condition.isFalse()) throwError(errorBody); +function validate(ValidationType validationType, bool condition, string memory messageBody, string memory messageDetail) { + if (condition) return; + Logger.log(messageBody.append(messageDetail)); + if (validationType == MUST) revert(ERR.message(messageBody)); // TODO +} +function validate(bool condition, string memory logMessage) { + validate(MUST, condition, logMessage, ""); } function validate(bool condition, string memory errorBody, string memory errorDetail) { validate(condition, errorBody.append(errorDetail)); } +ValidationType constant MUST = ValidationType.MUST; +ValidationType constant SHOULD = ValidationType.SHOULD; + +enum ValidationType { MUST, SHOULD } + library Validate { + /** Type Guard */ @@ -102,6 +116,13 @@ library Validate { exists(bundle); isComplete(bundle); } + function SHOULD_valid(Bundle storage bundle) internal { + validate(SHOULD, bundle.exists(), "Bundle Not Exists", ""); + // exists(bundle); + validate(SHOULD, bundle.isComplete(), "Bundle Not Complete", ""); + // isComplete(bundle); + } + function exists(Bundle storage bundle) internal { validate(bundle.exists(), "Bundle Info Not Exists"); } @@ -123,6 +144,9 @@ library Validate { validate(bundle.notExistsBundle(name), "Bundle Already Exists"); return bundle; } + function SHOULD_beCompleted(BundleRegistry storage registry, string memory name) internal { + validate(SHOULD, registry.bundles[name].isComplete(), "Incompleted Bundle", ""); + } /**============== 🏠 Proxy @@ -204,6 +228,9 @@ library Validate { function notEmpty(string memory str) internal { validate(str.isNotEmpty(), ERR.EMPTY_STR); } + function MUST_notEmpty(string memory str) internal { + validate(MUST, str.isNotEmpty(), "Current Bundle Not Found", ""); + } function isUnassigned(bytes4 b4) internal { validate(b4.isEmpty(), ERR.B4_ALREADY_ASSIGNED); diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 5fe23aab..c73dd339 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -6,7 +6,7 @@ import {MCDevKitTest} from "devkit/MCTest.sol"; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; import {Config} from "devkit/config/Config.sol"; -import {ERR} from "devkit/log/message/Errors.sol"; +import {ERR} from "devkit/log/message/ERR.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; From b59d111e22abb55e5f34e6eefe75c87181f27c02 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 11:51:58 +0900 Subject: [PATCH 089/111] Use Validate methods instead of validate() --- devkit/core/Bundle.sol | 1 - devkit/utils/global/MCBundleLib.sol | 5 ++-- devkit/utils/global/MCDeployLib.sol | 2 +- devkit/utils/inspector/Inspector.sol | 1 - devkit/utils/primitive/AddressUtils.sol | 8 ++--- devkit/utils/primitive/Bytes4Utils.sol | 6 ++-- devkit/utils/primitive/StringUtils.sol | 8 ++--- devkit/utils/primitive/UintUtils.sol | 3 -- devkit/validate/Validate.sol | 39 +++++++++++++------------ 9 files changed, 35 insertions(+), 38 deletions(-) diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index e61c196a..70bebd22 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -12,7 +12,6 @@ import {Inspector} from "devkit/utils/inspector/Inspector.sol"; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Bundle global; // Validation -import {validate} from "devkit/validate/Validate.sol"; import {Validate} from "devkit/validate/Validate.sol"; // Core Type diff --git a/devkit/utils/global/MCBundleLib.sol b/devkit/utils/global/MCBundleLib.sol index f44e0eeb..44d0b60f 100644 --- a/devkit/utils/global/MCBundleLib.sol +++ b/devkit/utils/global/MCBundleLib.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Validation import {Validate} from "devkit/validate/Validate.sol"; -import {validate} from "devkit/validate/Validate.sol"; import {ERR} from "devkit/log/message/ERR.sol"; // Utils import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; @@ -68,7 +67,7 @@ library MCBundleLib { // return mc; // } TODO function use(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - validate(mc.functions.find(name).isComplete(), "Invalid Function Name"); + Validate.validRegistration(mc.functions, name); return mc.use(mc.findFunction(name)); } /**--------------------------- @@ -98,7 +97,7 @@ library MCBundleLib { --------------------*/ function useFacade(MCDevKit storage mc, address facade) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("set"); - validate(mc.bundle.existsCurrentBundle(), ERR.NOT_INIT); + Validate.MUST_beInitialized(mc.bundle); mc.bundle.findCurrent().assignFacade(facade); return mc.recordExecFinish(pid); } diff --git a/devkit/utils/global/MCDeployLib.sol b/devkit/utils/global/MCDeployLib.sol index d872de80..609db270 100644 --- a/devkit/utils/global/MCDeployLib.sol +++ b/devkit/utils/global/MCDeployLib.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; import {Config} from "devkit/config/Config.sol"; // Validation -import {validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/validate/Validate.sol"; // Utils import {Params} from "devkit/log/debug/Params.sol"; // Core diff --git a/devkit/utils/inspector/Inspector.sol b/devkit/utils/inspector/Inspector.sol index 651b41ae..af56ebf1 100644 --- a/devkit/utils/inspector/Inspector.sol +++ b/devkit/utils/inspector/Inspector.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {validate} from "devkit/validate/Validate.sol"; import {Validate} from "devkit/validate/Validate.sol"; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; diff --git a/devkit/utils/primitive/AddressUtils.sol b/devkit/utils/primitive/AddressUtils.sol index 488e7c99..de0e7f66 100644 --- a/devkit/utils/primitive/AddressUtils.sol +++ b/devkit/utils/primitive/AddressUtils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/validate/Validate.sol"; // Utils import {vm} from "devkit/utils/ForgeHelper.sol"; import {BoolUtils} from "./BoolUtils.sol"; @@ -31,7 +31,7 @@ library AddressUtils { return addr == address(0); } function assertZero(address addr) internal returns(address) { - validate(addr.isZero(), "Address Not Zero"); + Validate.notZero(addr); return addr; } @@ -40,7 +40,7 @@ library AddressUtils { return addr.isZero().isNot(); } function assertNotZero(address addr) internal returns(address) { - validate(addr.isNotZero(), "Zero Address"); + Validate.notZero(addr); return addr; } @@ -59,7 +59,7 @@ library AddressUtils { return addr.hasCode(); } function assertIsContract(address addr) internal returns(address) { - validate(addr.isContract(), "Address Not Contract"); + Validate.isContract(addr); return addr; } diff --git a/devkit/utils/primitive/Bytes4Utils.sol b/devkit/utils/primitive/Bytes4Utils.sol index b6d79eba..cf61b566 100644 --- a/devkit/utils/primitive/Bytes4Utils.sol +++ b/devkit/utils/primitive/Bytes4Utils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/validate/Validate.sol"; // Utils import {vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "./StringUtils.sol"; @@ -36,7 +36,7 @@ library Bytes4Utils { return selector == bytes4(0); } function assertEmpty(bytes4 selector) internal returns(bytes4) { - validate(selector.isEmpty(), "Selector Not Empty"); + Validate.notEmpty(selector); return selector; } @@ -44,7 +44,7 @@ library Bytes4Utils { return selector.isEmpty().isFalse(); } function assertNotEmpty(bytes4 selector) internal returns(bytes4) { - validate(selector.isNotEmpty(), "Empty Selector"); + Validate.notEmpty(selector); return selector; } diff --git a/devkit/utils/primitive/StringUtils.sol b/devkit/utils/primitive/StringUtils.sol index 653b22b8..9a4c6c19 100644 --- a/devkit/utils/primitive/StringUtils.sol +++ b/devkit/utils/primitive/StringUtils.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; // Validation -import {validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/validate/Validate.sol"; import {Debug} from "devkit/log/debug/Debug.sol"; // Utils import {StdStyle, ForgeHelper, vm} from "devkit/utils/ForgeHelper.sol"; @@ -24,7 +24,7 @@ library StringUtils { return keccak256(abi.encode(name)); } function safeCalcHash(string memory name) internal returns(bytes32) { - validate(name.isNotEmpty(), "Calc Hash"); + Validate.notEmpty(name); return name.calcHash(); } @@ -105,7 +105,7 @@ library StringUtils { return bytes(str).length == 0; } function assertEmpty(string memory str) internal returns(string memory) { - validate(str.isEmpty(), "String Not Empty"); + Validate.notEmpty(str); return str; } @@ -114,7 +114,7 @@ library StringUtils { return str.isEmpty().isNot(); } function assertNotEmpty(string memory str) internal returns(string memory) { - validate(str.isNotEmpty(), "Empty String"); + Validate.notEmpty(str); return str; } diff --git a/devkit/utils/primitive/UintUtils.sol b/devkit/utils/primitive/UintUtils.sol index 285f686b..381143cb 100644 --- a/devkit/utils/primitive/UintUtils.sol +++ b/devkit/utils/primitive/UintUtils.sol @@ -1,8 +1,5 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; - -// Validation -import {validate} from "devkit/validate/Validate.sol"; // Utils import {vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index 0d758866..2ab9a535 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -30,25 +30,22 @@ import {StdRegistry} from "devkit/registry/StdRegistry.sol"; import {StdFunctions} from "devkit/registry/StdFunctions.sol"; -/// @dev like `require` -function validate(ValidationType validationType, bool condition, string memory messageBody, string memory messageDetail) { - if (condition) return; - Logger.log(messageBody.append(messageDetail)); - if (validationType == MUST) revert(ERR.message(messageBody)); // TODO -} -function validate(bool condition, string memory logMessage) { - validate(MUST, condition, logMessage, ""); -} -function validate(bool condition, string memory errorBody, string memory errorDetail) { - validate(condition, errorBody.append(errorDetail)); -} - -ValidationType constant MUST = ValidationType.MUST; -ValidationType constant SHOULD = ValidationType.SHOULD; - -enum ValidationType { MUST, SHOULD } - library Validate { + enum Type { MUST, SHOULD } + Type constant MUST = Type.MUST; + Type constant SHOULD = Type.SHOULD; + + function validate(Type T, bool condition, string memory messageBody, string memory messageDetail) internal { + if (condition) return; + Logger.log(messageBody.append(messageDetail)); + if (T == MUST) revert(ERR.message(messageBody)); // TODO + } + function validate(bool condition, string memory logMessage) internal { + validate(MUST, condition, logMessage, ""); + } + function validate(bool condition, string memory errorBody, string memory errorDetail) internal { + validate(condition, errorBody.append(errorDetail)); + } /** Type Guard @@ -147,6 +144,12 @@ library Validate { function SHOULD_beCompleted(BundleRegistry storage registry, string memory name) internal { validate(SHOULD, registry.bundles[name].isComplete(), "Incompleted Bundle", ""); } + function MUST_existCurrent(BundleRegistry storage registry) internal { + validate(MUST, registry.current.name.isNotEmpty(), "Current Not Exist", ""); + } + function MUST_beInitialized(BundleRegistry storage registry) internal { + validate(MUST, registry.current.name.isNotEmpty(), ERR.NOT_INIT, ""); + } /**============== 🏠 Proxy From f82357d9f98bdb40001f8d20c3e92bf44ad5564f Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 12:34:06 +0900 Subject: [PATCH 090/111] update validate method --- devkit/types/TypeGuard.sol | 16 +++-- devkit/validate/Validate.sol | 119 ++++++++++++++++++----------------- 2 files changed, 72 insertions(+), 63 deletions(-) diff --git a/devkit/types/TypeGuard.sol b/devkit/types/TypeGuard.sol index f9349975..dec3f85f 100644 --- a/devkit/types/TypeGuard.sol +++ b/devkit/types/TypeGuard.sol @@ -19,6 +19,10 @@ import {StdFunctions} from "devkit/registry/StdFunctions.sol"; using TypeGuard for TypeStatus global; enum TypeStatus { Uninitialized, Building, Built, Locked } + +/**=================== + 🔒 Type Guard +=====================*/ library TypeGuard { function building(TypeStatus status) internal { status = TypeStatus.Building; @@ -51,7 +55,7 @@ library TypeGuard { return func; } function lock(Function storage func) internal returns(Function storage) { - Validate.isBuilt(func.status); + Validate.MUST_beBuilt(func.status); func.status = TypeStatus.Locked; return func; } @@ -75,7 +79,7 @@ library TypeGuard { return bundle; } function lock(Bundle storage bundle) internal returns(Bundle storage) { - Validate.isBuilt(bundle.status); + Validate.MUST_beBuilt(bundle.status); bundle.status = TypeStatus.Locked; return bundle; } @@ -98,7 +102,7 @@ library TypeGuard { return registry; } function lock(StdRegistry storage registry) internal returns(StdRegistry storage) { - Validate.isBuilt(registry.status); + Validate.MUST_beBuilt(registry.status); registry.status = TypeStatus.Locked; return registry; } @@ -119,7 +123,7 @@ library TypeGuard { return stdFunctions; } function lock(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { - Validate.isBuilt(stdFunctions.status); + Validate.MUST_beBuilt(stdFunctions.status); stdFunctions.status = TypeStatus.Locked; return stdFunctions; } @@ -139,7 +143,7 @@ library TypeGuard { return dictionary; } function lock(Dictionary storage dictionary) internal returns(Dictionary storage) { - Validate.isBuilt(dictionary.status); + Validate.MUST_beBuilt(dictionary.status); dictionary.status = TypeStatus.Locked; return dictionary; } @@ -162,7 +166,7 @@ library TypeGuard { return proxy; } function lock(Proxy storage proxy) internal returns(Proxy storage) { - Validate.isBuilt(proxy.status); + Validate.MUST_beBuilt(proxy.status); proxy.status = TypeStatus.Locked; return proxy; } diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index 2ab9a535..8c861948 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -30,6 +30,9 @@ import {StdRegistry} from "devkit/registry/StdRegistry.sol"; import {StdFunctions} from "devkit/registry/StdFunctions.sol"; +/**================= + ✅ Validate +===================*/ library Validate { enum Type { MUST, SHOULD } Type constant MUST = Type.MUST; @@ -40,37 +43,39 @@ library Validate { Logger.log(messageBody.append(messageDetail)); if (T == MUST) revert(ERR.message(messageBody)); // TODO } - function validate(bool condition, string memory logMessage) internal { - validate(MUST, condition, logMessage, ""); - } - function validate(bool condition, string memory errorBody, string memory errorDetail) internal { - validate(condition, errorBody.append(errorDetail)); - } - /** - Type Guard - */ - function isBuilt(TypeStatus status) internal { - validate(status.isBuilt(), "Not Built Yet"); + + /**=================== + 🔒 Type Guard + =====================*/ + function MUST_beBuilt(TypeStatus status) internal { + validate(MUST, status.isBuilt(), "Not Built Yet", ""); } + // function MUST_beCompleted(TypeStatus status) internal { + // validate(MUST, status.isComplete(), "", ""); + // } + + /**================== + 🧱 Primitives + ====================*/ function notZero(uint256 num) internal { - validate(num.isNotZero(), "Zero Number"); + validate(MUST, num.isNotZero(), "Zero Number", ""); } function assigned(string memory str) internal { - validate(str.isNotEmpty(), "Not Assigned"); + validate(MUST, str.isNotEmpty(), "Not Assigned", ""); } /**================== 🧩 Function ====================*/ function exists(Function storage func) internal { - validate(func.exists(), "func does not exists"); - // validate(func.isBuilt(), "func does not exists"); // TODO + validate(MUST, func.exists(), "func does not exists", ""); + // validate(MUST, func.isBuilt(), "func does not exists", ""); // TODO } function isComplete(Function storage func) internal { - validate(func.isComplete(), "Function Not Complete"); + validate(MUST, func.isComplete(), "Function Not Complete", ""); } function valid(Function storage func) internal { exists(func); @@ -78,28 +83,28 @@ library Validate { } function EmptyName(Function storage func) internal { - Validate.isUnassigned(func.name); + isUnassigned(func.name); } function EmptySelector(Function storage func) internal { - Validate.isUnassigned(func.selector); + isUnassigned(func.selector); } function EmptyImpl(Function storage func) internal { - validate(func.implementation.isNotContract(), "Implementation Already Exist"); + validate(MUST, func.implementation.isNotContract(), "Implementation Already Exist", ""); } function NotEmpty(Function storage func) internal { - validate(func.exists(), "Empty Deployed Contract"); + validate(MUST, func.exists(), "Empty Deployed Contract", ""); } function NotIncludedIn(Function storage func, Bundle storage bundleInfo) internal { - validate(bundleInfo.hasNot(func), "Already exists in the Bundel"); + validate(MUST, bundleInfo.hasNot(func), "Already exists in the Bundel", ""); } function implIsContract(Function storage func) internal { - validate(func.implementation.isContract(), "Implementation Not Contract"); + validate(MUST, func.implementation.isContract(), "Implementation Not Contract", ""); } function validRegistration(FunctionRegistry storage registry, string memory name) internal { - validate(registry.functions[name].isComplete(), "Function Not Complete"); + validate(MUST, registry.functions[name].isComplete(), "Function Not Complete", ""); } @@ -107,7 +112,7 @@ library Validate { đŸ—‚ī¸ Bundle =================*/ function isComplete(Bundle storage bundle) internal { - validate(bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); + validate(MUST, bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); } function valid(Bundle storage bundle) internal { exists(bundle); @@ -121,24 +126,24 @@ library Validate { } function exists(Bundle storage bundle) internal { - validate(bundle.exists(), "Bundle Info Not Exists"); + validate(MUST, bundle.exists(), "Bundle Info Not Exists", ""); } function notExists(Bundle storage bundle) internal returns(Bundle storage) { - validate(bundle.notExists(), "Bundle Already Exists"); + validate(MUST, bundle.notExists(), "Bundle Already Exists", ""); return bundle; } function isUnassigned(Bundle storage bundle) internal { - validate(bundle.hasNotName(), "Bundle Already Assigned."); + validate(MUST, bundle.hasNotName(), "Bundle Already Assigned.", ""); } function hasNot(Bundle storage bundle, Function storage func) internal { - validate(bundle.hasNot(func), "Bundle has same Function"); + validate(MUST, bundle.hasNot(func), "Bundle has same Function", ""); } /**======================= 📙 Bundle Registry =========================*/ function bundleNotExists(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - validate(bundle.notExistsBundle(name), "Bundle Already Exists"); + validate(MUST, bundle.notExistsBundle(name), "Bundle Already Exists", ""); return bundle; } function SHOULD_beCompleted(BundleRegistry storage registry, string memory name) internal { @@ -155,31 +160,31 @@ library Validate { 🏠 Proxy ================*/ function exists(Proxy storage proxy) internal returns(Proxy storage) { - validate(proxy.exists(), "Proxy Not Exist"); + validate(MUST, proxy.exists(), "Proxy Not Exist", ""); return proxy; } function isComplete(Proxy storage proxy) internal { - validate(proxy.isComplete(), "Proxy Not Complete"); + validate(MUST, proxy.isComplete(), "Proxy Not Complete", ""); } function valid(Proxy storage proxy) internal { exists(proxy); isComplete(proxy); } function notEmpty(Proxy memory proxy) internal returns(Proxy memory) { - validate(proxy.isNotEmpty(), "Empty Proxy"); + validate(MUST, proxy.isNotEmpty(), "Empty Proxy", ""); return proxy; } /*---- Proxy Kind -----*/ function NotUndefined(ProxyKind kind) internal returns(ProxyKind) { - validate(kind.isNotUndefined(), "Undefined Proxy Kind"); + validate(MUST, kind.isNotUndefined(), "Undefined Proxy Kind", ""); return kind; } function notRegistered(ProxyRegistry storage registry, string memory name) internal { - validate(registry.proxies[name].notExists(), "Proxy Already Exists"); + validate(MUST, registry.proxies[name].notExists(), "Proxy Already Exists", ""); } function validRegistration(ProxyRegistry storage registry, string memory name) internal { - validate(registry.proxies[name].isComplete(), "Proxy Not Complete"); + validate(MUST, registry.proxies[name].isComplete(), "Proxy Not Complete", ""); } @@ -187,86 +192,86 @@ library Validate { 📚 Dictionary ======================*/ function exists(Dictionary storage dictionary) internal returns(Dictionary storage) { - validate(dictionary.exists(), "Dictionary Not Exists"); + validate(MUST, dictionary.exists(), "Dictionary Not Exists", ""); return dictionary; } function isComplete(Dictionary storage dictionary) internal { - validate(dictionary.isComplete(), "Dictionary Not Complete"); + validate(MUST, dictionary.isComplete(), "Dictionary Not Complete", ""); } function valid(Dictionary storage dictionary) internal { exists(dictionary); isComplete(dictionary); } function notEmpty(Dictionary memory dictionary) internal returns(Dictionary memory) { - validate(dictionary.isNotEmpty(), "Empty Dictionary"); + validate(MUST, dictionary.isNotEmpty(), "Empty Dictionary", ""); return dictionary; } function Supports(Dictionary storage dictionary, bytes4 selector) internal returns(Dictionary storage) { - validate(dictionary.isSupported(selector), "Unsupported Selector"); + validate(MUST, dictionary.isSupported(selector), "Unsupported Selector", ""); return dictionary; } function verifiable(Dictionary memory dictionary) internal returns(Dictionary memory) { - validate(dictionary.isVerifiable(), "Dictionary Not Verifiable"); + validate(MUST, dictionary.isVerifiable(), "Dictionary Not Verifiable", ""); return dictionary; } /*---- Dictionary Kind -----*/ function notUndefined(DictionaryKind kind) internal { - validate(kind.isNotUndefined(), "Undefined Dictionary Kind"); + validate(MUST, kind.isNotUndefined(), "Undefined Dictionary Kind", ""); } function notUndefined(ProxyKind kind) internal { - validate(kind.isNotUndefined(), "Undefined Dictionary Kind"); + validate(MUST, kind.isNotUndefined(), "Undefined Dictionary Kind", ""); } function notRegistered(DictionaryRegistry storage registry, string memory name) internal { - validate(registry.dictionaries[name].notExists(), "Dictionary Already Exists"); + validate(MUST, registry.dictionaries[name].notExists(), "Dictionary Already Exists", ""); } function validRegistration(DictionaryRegistry storage registry, string memory name) internal { - validate(registry.dictionaries[name].isComplete(), "Dictionary Not Registered"); + validate(MUST, registry.dictionaries[name].isComplete(), "Dictionary Not Registered", ""); } function isUnassigned(string storage str) internal { - validate(str.isEmpty(), ERR.STR_ALREADY_ASSIGNED); + validate(MUST, str.isEmpty(), ERR.STR_ALREADY_ASSIGNED, ""); } function notEmpty(string memory str) internal { - validate(str.isNotEmpty(), ERR.EMPTY_STR); + validate(MUST, str.isNotEmpty(), ERR.EMPTY_STR, ""); } function MUST_notEmpty(string memory str) internal { validate(MUST, str.isNotEmpty(), "Current Bundle Not Found", ""); } function isUnassigned(bytes4 b4) internal { - validate(b4.isEmpty(), ERR.B4_ALREADY_ASSIGNED); + validate(MUST, b4.isEmpty(), ERR.B4_ALREADY_ASSIGNED, ""); } function notEmpty(bytes4 b4) internal { - validate(b4.isNotEmpty(), ERR.EMPTY_B4); + validate(MUST, b4.isNotEmpty(), ERR.EMPTY_B4, ""); } function isContract(address addr) internal { - validate(addr.isContract(), ERR.NOT_CONTRACT); + validate(MUST, addr.isContract(), ERR.NOT_CONTRACT, ""); } function notEmptyString(string memory str) internal { - validate(str.isNotEmpty(), ERR.RQ_NOT_EMPTY_STRING); + validate(MUST, str.isNotEmpty(), ERR.RQ_NOT_EMPTY_STRING, ""); } function assigned(bytes4 b4) internal { - validate(b4.isNotEmpty(), ERR.RQ_SELECTOR); + validate(MUST, b4.isNotEmpty(), ERR.RQ_SELECTOR, ""); } function contractAssigned(address addr) internal { - validate(addr.isContract(), ERR.RQ_CONTRACT); + validate(MUST, addr.isContract(), ERR.RQ_CONTRACT, ""); } function notLocked(TypeStatus status) internal { - validate(status != TypeStatus.Locked, ERR.LOCKED_OBJECT); + validate(MUST, status != TypeStatus.Locked, ERR.LOCKED_OBJECT, ""); } function isNotEmpty(Dictionary memory dictionary) internal { - validate(dictionary.isNotEmpty(), ERR.EMPTY_DICTIONARY); + validate(MUST, dictionary.isNotEmpty(), ERR.EMPTY_DICTIONARY, ""); } function notZero(address addr) internal { - validate(addr.isNotZero(), ERR.ZERO_ADDRESS); + validate(MUST, addr.isNotZero(), ERR.ZERO_ADDRESS, ""); } @@ -274,9 +279,9 @@ library Validate { 🏛 Standard Registry ============================*/ function isComplete(StdRegistry storage registry) internal { - validate(registry.status.isComplete(), "Registry Not Complete"); + validate(MUST, registry.status.isComplete(), "Registry Not Complete", ""); } function isComplete(StdFunctions storage stdFunctions) internal { - validate(stdFunctions.status.isComplete(), "Registry Not Complete"); + validate(MUST, stdFunctions.status.isComplete(), "Registry Not Complete", ""); } } From bba7191a086fadfdc03075313ff54206fbcb6922 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 16:16:28 +0900 Subject: [PATCH 091/111] Improve Validation --- devkit/core/Bundle.sol | 12 +- devkit/core/Dictionary.sol | 15 +- devkit/core/Function.sol | 10 +- devkit/core/Proxy.sol | 2 +- devkit/log/debug/Logger.sol | 2 + devkit/registry/BundleRegistry.sol | 11 +- devkit/registry/DictionaryRegistry.sol | 20 +- devkit/registry/FunctionRegistry.sol | 10 +- devkit/registry/ProxyRegistry.sol | 19 +- devkit/registry/StdFunctions.sol | 6 +- devkit/registry/StdRegistry.sol | 4 +- devkit/registry/context/Current.sol | 2 +- devkit/types/TypeGuard.sol | 57 +++-- devkit/utils/global/MCBundleLib.sol | 4 +- devkit/utils/global/MCTestLib.sol | 4 +- devkit/utils/inspector/Inspector.sol | 65 ++++++ devkit/utils/primitive/AddressUtils.sol | 46 ----- devkit/utils/primitive/Bytes4Utils.sol | 26 --- devkit/utils/primitive/StringUtils.sol | 33 +-- devkit/validate/Validate.sol | 263 +++++++++--------------- devkit/validate/ValidationHandler.sol | 31 +++ test/devkit/global/MCBundle.t.sol | 5 +- test/utils/TestHelper.sol | 3 + 23 files changed, 294 insertions(+), 356 deletions(-) create mode 100644 devkit/validate/ValidationHandler.sol diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 70bebd22..969aaafe 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -35,8 +35,8 @@ library BundleLib { ----------------------*/ function assignName(Bundle storage bundle, string memory name) internal returns(Bundle storage) { uint pid = bundle.startProcess("assignName"); - Validate.notLocked(bundle.status); - Validate.notEmpty(name); + Validate.MUST_BundleNotLocked(bundle); + Validate.MUST_NotEmptyName(name); bundle.name = name; return bundle.building().finishProcess(pid); } @@ -46,9 +46,9 @@ library BundleLib { ---------------------------*/ function pushFunction(Bundle storage bundle, Function storage func) internal returns(Bundle storage) { uint pid = bundle.startProcess("pushFunction"); - Validate.notLocked(bundle.status); - Validate.isComplete(func); - Validate.hasNot(bundle, func); + Validate.MUST_BundleNotLocked(bundle); + Validate.MUST_completed(func); + Validate.MUST_notHave(bundle, func); bundle.functions.push(func); return bundle.building().finishProcess(pid); } @@ -65,7 +65,7 @@ library BundleLib { ------------------------*/ function assignFacade(Bundle storage bundle, address facade) internal returns(Bundle storage) { uint pid = bundle.startProcess("assignFacade"); - Validate.isContract(facade); + Validate.MUST_AddressIsContract(facade); bundle.facade = facade; return bundle.building().finishProcess(pid); } diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 7f24b6f4..5cf5c3e1 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -8,6 +8,7 @@ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; import {Params} from "devkit/log/debug/Params.sol"; import {Inspector} from "devkit/utils/inspector/Inspector.sol"; using Inspector for Dictionary global; + using Inspector for bytes4; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; // Type Util import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; @@ -51,7 +52,7 @@ library DictionaryLib { ---------------------------*/ function deploy(address owner) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("deploy"); - Validate.notZero(owner); + Validate.MUST_AddressIsNotZero(owner); /// @dev Until Etherscan supports UCS, we are deploying contracts with additional features for Etherscan compatibility by default. return Dictionary({ addr: address(new DictionaryEtherscan(owner)), @@ -65,8 +66,8 @@ library DictionaryLib { ------------------------------*/ function duplicate(Dictionary memory toDictionary, Dictionary memory fromDictionary) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("duplicate"); - Validate.notEmpty(toDictionary); - Validate.notEmpty(fromDictionary); + Validate.MUST_haveContract(toDictionary); + Validate.MUST_haveContract(fromDictionary); address toAddr = toDictionary.addr; address fromAddr = fromDictionary.addr; @@ -89,9 +90,9 @@ library DictionaryLib { -------------------------------*/ function set(Dictionary memory dictionary, bytes4 selector, address implementation) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("set", Params.append(selector, implementation)); - Validate.isContract(dictionary.addr); - Validate.notEmpty(selector); - Validate.isContract(implementation); + Validate.MUST_haveContract(dictionary); + Validate.MUST_Bytes4NotEmpty(selector); + Validate.MUST_AddressIsContract(implementation); IDictionary(dictionary.addr).setImplementation({ functionSelector: selector, implementation: implementation @@ -124,7 +125,7 @@ library DictionaryLib { ------------------------*/ function upgradeFacade(Dictionary memory dictionary, address newFacade) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("upgradeFacade"); - Validate.isContract(newFacade); + Validate.MUST_AddressIsContract(newFacade); // Validate.verifiable(dictionary); TODO without CALL DictionaryEtherscan(dictionary.addr).upgradeFacade(newFacade); return dictionary.finishProcess(pid); diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index a3fd278c..ea894f7a 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -47,7 +47,7 @@ library FunctionLib { ----------------------*/ function assignName(Function storage func, string memory name) internal returns(Function storage) { uint pid = func.startProcess("assignName"); - Validate.notLocked(func.status); + Validate.MUST_FunctionNotLocked(func); func.name = name; return func.building().finishProcess(pid); } @@ -57,7 +57,7 @@ library FunctionLib { --------------------------*/ function assignSelector(Function storage func, bytes4 selector) internal returns(Function storage) { uint pid = func.startProcess("assignSelector"); - Validate.notLocked(func.status); + Validate.MUST_FunctionNotLocked(func); func.selector = selector; return func.building().finishProcess(pid); } @@ -67,7 +67,7 @@ library FunctionLib { --------------------------------*/ function assignImplementation(Function storage func, address implementation) internal returns(Function storage) { uint pid = func.startProcess("assignImplementation"); - Validate.notLocked(func.status); + Validate.MUST_FunctionNotLocked(func); func.implementation = implementation; return func.building().finishProcess(pid); } @@ -77,8 +77,8 @@ library FunctionLib { -------------------------*/ function fetch(Function storage func, string memory envKey) internal returns(Function storage) { uint pid = func.startProcess("fetch"); - Validate.notLocked(func.status); - Validate.notEmpty(envKey); + Validate.MUST_FunctionNotLocked(func); + Validate.MUST_NotEmptyEnvKey(envKey); func.assignName(envKey); func.assignImplementation(loadAddressFrom(envKey)); return func.building().finishProcess(pid); diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index e74f5fc2..1091a651 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -39,7 +39,7 @@ library ProxyLib { -----------------------*/ function deploy(Dictionary memory dictionary, bytes memory initData) internal returns(Proxy memory) { uint pid = ProcessLib.startProxyLibProcess("deploy"); - Validate.notEmpty(dictionary); + Validate.MUST_haveContract(dictionary); return Proxy({ addr: address(new ERC7546ProxyEtherscan(dictionary.addr, initData)), kind: ProxyKind.Verifiable, diff --git a/devkit/log/debug/Logger.sol b/devkit/log/debug/Logger.sol index 5de1cf36..482f1654 100644 --- a/devkit/log/debug/Logger.sol +++ b/devkit/log/debug/Logger.sol @@ -7,6 +7,8 @@ import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; // Debug import {Debug, Process} from "./Debug.sol"; +import {Inspector} from "devkit/utils/inspector/Inspector.sol"; + using Inspector for string; //================ // 📊 Logger diff --git a/devkit/registry/BundleRegistry.sol b/devkit/registry/BundleRegistry.sol index d8ffba9a..2d0c2490 100644 --- a/devkit/registry/BundleRegistry.sol +++ b/devkit/registry/BundleRegistry.sol @@ -34,9 +34,9 @@ library BundleRegistryLib { -----------------------*/ function init(BundleRegistry storage registry, string memory name) internal returns(BundleRegistry storage) { uint pid = registry.startProcess("init"); - Validate.notEmpty(name); + Validate.MUST_NotEmptyName(name); Bundle storage bundle = registry.bundles[name]; - Validate.isUnassigned(bundle); + Validate.MUST_notInitialized(bundle); bundle.assignName(name); registry.current.update(name); return registry.finishProcess(pid); @@ -47,16 +47,15 @@ library BundleRegistryLib { ----------------------*/ function find(BundleRegistry storage registry, string memory name) internal returns(Bundle storage) { uint pid = registry.startProcess("find"); - Validate.MUST_notEmpty(name); - Validate.SHOULD_beCompleted(registry, name); + Validate.MUST_NotEmptyName(name); Bundle storage bundle = registry.bundles[name]; - Validate.SHOULD_valid(bundle); + Validate.SHOULD_completed(bundle); return bundle.finishProcess(pid); } function findCurrent(BundleRegistry storage registry) internal returns(Bundle storage) { uint pid = registry.startProcess("findCurrent"); string memory name = registry.current.name; - Validate.MUST_notEmpty(name); + Validate.MUST_NotEmptyName(name); return registry.find(name).finishProcess(pid); } diff --git a/devkit/registry/DictionaryRegistry.sol b/devkit/registry/DictionaryRegistry.sol index d3388dc6..1af9afae 100644 --- a/devkit/registry/DictionaryRegistry.sol +++ b/devkit/registry/DictionaryRegistry.sol @@ -34,9 +34,9 @@ library DictionaryRegistryLib { ---------------------------------------*/ function deploy(DictionaryRegistry storage registry, string memory name, Bundle storage bundle, address owner) internal returns(Dictionary storage) { uint pid = registry.startProcess("deploy"); - Validate.notEmpty(name); - Validate.exists(bundle); - Validate.notZero(owner); + Validate.MUST_NotEmptyName(name); + Validate.MUST_completed(bundle); + Validate.MUST_AddressIsNotZero(owner); Dictionary memory dictionary = DictionaryLib.deploy(owner) .set(bundle) .upgradeFacade(bundle.facade); @@ -49,9 +49,9 @@ library DictionaryRegistryLib { -----------------------------*/ function register(DictionaryRegistry storage registry, string memory name, Dictionary memory dictionary) internal returns(Dictionary storage) { uint pid = registry.startProcess("register"); - Validate.notEmpty(name); - Validate.notEmpty(dictionary); - Validate.notRegistered(registry, name); + Validate.MUST_NotEmptyName(name); + Validate.MUST_haveContract(dictionary); + Validate.MUST_notRegistered(registry, name); Dictionary storage dictionaryStorage = registry.dictionaries[name] = dictionary; dictionaryStorage.build().lock(); registry.current.update(name); @@ -63,16 +63,16 @@ library DictionaryRegistryLib { --------------------------*/ function find(DictionaryRegistry storage registry, string memory name) internal returns(Dictionary storage) { uint pid = registry.startProcess("find"); - Validate.notEmpty(name); - Validate.validRegistration(registry, name); + Validate.MUST_NotEmptyName(name); + Validate.MUST_registered(registry, name); Dictionary storage dictionary = registry.dictionaries[name]; - Validate.valid(dictionary); + Validate.MUST_completed(dictionary); return dictionary.finishProcessInStorage(pid); } function findCurrent(DictionaryRegistry storage registry) internal returns(Dictionary storage) { uint pid = registry.startProcess("findCurrent"); string memory name = registry.current.name; - Validate.notEmpty(name); + Validate.MUST_NotEmptyName(name); return registry.find(name).finishProcessInStorage(pid); } diff --git a/devkit/registry/FunctionRegistry.sol b/devkit/registry/FunctionRegistry.sol index cad530d9..e79158b6 100644 --- a/devkit/registry/FunctionRegistry.sol +++ b/devkit/registry/FunctionRegistry.sol @@ -29,7 +29,7 @@ library FunctionRegistryLib { ----------------------------*/ function register(FunctionRegistry storage registry, string memory name, bytes4 selector, address implementation) internal returns(FunctionRegistry storage) { uint pid = registry.startProcess("register"); - Validate.notEmpty(name); + Validate.MUST_NotEmptyName(name); registry.functions[name].assign(name, selector, implementation).build().lock(); registry.current.update(name); return registry.finishProcess(pid); @@ -40,16 +40,16 @@ library FunctionRegistryLib { ------------------------*/ function find(FunctionRegistry storage registry, string memory name) internal returns(Function storage) { uint pid = registry.startProcess("find"); - Validate.notEmpty(name); - Validate.validRegistration(registry, name); + Validate.MUST_NotEmptyName(name); + Validate.MUST_registered(registry, name); Function storage func = registry.functions[name]; - Validate.valid(func); + Validate.MUST_completed(func); return func.finishProcess(pid); } function findCurrent(FunctionRegistry storage registry) internal returns(Function storage) { uint pid = registry.startProcess("findCurrent"); string memory name = registry.current.name; - Validate.notEmpty(name); + Validate.MUST_NotEmptyName(name); return registry.find(name).finishProcess(pid); } diff --git a/devkit/registry/ProxyRegistry.sol b/devkit/registry/ProxyRegistry.sol index 41fdc023..ccf946a3 100644 --- a/devkit/registry/ProxyRegistry.sol +++ b/devkit/registry/ProxyRegistry.sol @@ -34,8 +34,8 @@ library ProxyRegistryLib { ---------------------------------*/ function deploy(ProxyRegistry storage registry, string memory name, Dictionary memory dictionary, bytes memory initData) internal returns(Proxy storage) { uint pid = registry.startProcess("deploy"); - Validate.notEmpty(name); - Validate.notEmpty(dictionary); + Validate.MUST_NotEmptyName(name); + Validate.MUST_haveContract(dictionary); Proxy memory proxy = ProxyLib.deploy(dictionary, initData); registry.register(name, proxy); return registry.findCurrent().finishProcessInStorage(pid); @@ -46,9 +46,10 @@ library ProxyRegistryLib { -------------------------*/ function register(ProxyRegistry storage registry, string memory name, Proxy memory proxy) internal returns(Proxy storage) { uint pid = registry.startProcess("register"); - Validate.notEmpty(name); - Validate.notEmpty(proxy); - Validate.notRegistered(registry, name); + Validate.MUST_NotEmptyName(name); + Validate.MUST_haveContract(proxy); + Validate.MUST_haveKind(proxy); + Validate.MUST_notRegistered(registry, name); Proxy storage proxyStorage = registry.proxies[name] = proxy; proxyStorage.build().lock(); registry.current.update(name); @@ -60,16 +61,16 @@ library ProxyRegistryLib { ---------------------*/ function find(ProxyRegistry storage registry, string memory name) internal returns(Proxy storage) { uint pid = registry.startProcess("find"); - Validate.notEmpty(name); - Validate.validRegistration(registry, name); + Validate.MUST_NotEmptyName(name); + Validate.MUST_registered(registry, name); Proxy storage proxy = registry.proxies[name]; - Validate.valid(proxy); + Validate.MUST_completed(proxy); return proxy.finishProcessInStorage(pid); } function findCurrent(ProxyRegistry storage registry) internal returns(Proxy storage) { uint pid = registry.startProcess("findCurrent"); string memory name = registry.current.name; - Validate.notEmpty(name); + Validate.MUST_NotEmptyName(name); return registry.find(name).finishProcessInStorage(pid); } diff --git a/devkit/registry/StdFunctions.sol b/devkit/registry/StdFunctions.sol index 4f42e823..387c11cf 100644 --- a/devkit/registry/StdFunctions.sol +++ b/devkit/registry/StdFunctions.sol @@ -67,7 +67,7 @@ library StdFunctionsLib { /**===== Each Std Function =====*/ function fetch_InitSetAdmin(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { uint pid = stdFunctions.startProcess("fetch_InitSetAdmin"); - Validate.notLocked(stdFunctions.initSetAdmin.status); + Validate.MUST_FunctionNotLocked(stdFunctions.initSetAdmin); stdFunctions.initSetAdmin .fetch("InitSetAdmin") .assignSelector(InitSetAdmin.initSetAdmin.selector) .dump(); @@ -76,7 +76,7 @@ library StdFunctionsLib { function fetch_GetDeps(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { uint pid = stdFunctions.startProcess("fetch_GetDeps"); - Validate.notLocked(stdFunctions.getDeps.status); + Validate.MUST_FunctionNotLocked(stdFunctions.getDeps); stdFunctions.getDeps.fetch("GetDeps") .assignSelector(GetDeps.getDeps.selector) .dump(); @@ -85,7 +85,7 @@ library StdFunctionsLib { function fetch_Clone(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { uint pid = stdFunctions.startProcess("fetch_Clone"); - Validate.notLocked(stdFunctions.clone.status); + Validate.MUST_FunctionNotLocked(stdFunctions.clone); stdFunctions.clone .fetch("Clone") .assignSelector(Clone.clone.selector) .dump(); diff --git a/devkit/registry/StdRegistry.sol b/devkit/registry/StdRegistry.sol index 634e07e7..e2120637 100644 --- a/devkit/registry/StdRegistry.sol +++ b/devkit/registry/StdRegistry.sol @@ -42,7 +42,7 @@ library StdRegistryLib { ------------------------------------*/ function complete(StdRegistry storage registry) internal returns(StdRegistry storage) { uint pid = registry.startProcess("complete"); - Validate.notLocked(registry.status); + Validate.MUST_StdNotLocked(registry); registry.functions.complete(); registry.configureStdBundle(); return registry.build().lock().finishProcess(pid); @@ -58,7 +58,7 @@ library StdRegistryLib { /**===== Each Std Bundle =====*/ function configureStdBundle_All(StdRegistry storage registry) internal returns(StdRegistry storage) { uint pid = registry.startProcess("configureStdBundle_All"); - Validate.notLocked(registry.all.status); + Validate.MUST_BundleNotLocked(registry.all); registry.all.assignName("ALL_STD_FUNCTIONS") .pushFunction(registry.functions.initSetAdmin) .pushFunction(registry.functions.getDeps) diff --git a/devkit/registry/context/Current.sol b/devkit/registry/context/Current.sol index 5f41d228..8ae816c4 100644 --- a/devkit/registry/context/Current.sol +++ b/devkit/registry/context/Current.sol @@ -24,7 +24,7 @@ library CurrentLib { ---------------------------------*/ function update(Current storage current, string memory name) internal { uint pid = current.startProcess("update", Params.append(name)); - Validate.notEmpty(name); + Validate.MUST_NotEmptyName(name); current.name = name; ProcessLib.finishProcess(pid); } diff --git a/devkit/types/TypeGuard.sol b/devkit/types/TypeGuard.sol index dec3f85f..3d2f1457 100644 --- a/devkit/types/TypeGuard.sol +++ b/devkit/types/TypeGuard.sol @@ -7,6 +7,8 @@ pragma solidity ^0.8.24; // using AddressUtils for address; // import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; // using Bytes4Utils for bytes4; +import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; + using BoolUtils for bool; import {Validate} from "devkit/validate/Validate.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; @@ -34,11 +36,21 @@ library TypeGuard { function isLocked(TypeStatus status) internal returns(bool) { return status == TypeStatus.Locked; } + function isNotLocked(TypeStatus status) internal returns(bool) { + return status.isLocked().isNot(); + } function isComplete(TypeStatus status) internal returns(bool) { return status.isBuilt() || status.isLocked(); } + function initialized(TypeStatus status) internal returns(bool) { + return status != TypeStatus.Uninitialized; + } + function notInitialized(TypeStatus status) internal returns(bool) { + return status == TypeStatus.Uninitialized; + } + /**================== 🧩 Function @@ -48,14 +60,15 @@ library TypeGuard { return func; } function build(Function storage func) internal returns(Function storage) { - Validate.assigned(func.name); - Validate.assigned(func.selector); - Validate.contractAssigned(func.implementation); + uint pid = func.startProcess("build"); + Validate.MUST_nameAssigned(func); + Validate.MUST_selectorAssigned(func); + Validate.MUST_implementationAssigned(func); func.status = TypeStatus.Built; - return func; + return func.finishProcess(pid); } function lock(Function storage func) internal returns(Function storage) { - Validate.MUST_beBuilt(func.status); + Validate.MUST_built(func.status); func.status = TypeStatus.Locked; return func; } @@ -72,14 +85,14 @@ library TypeGuard { return bundle; } function build(Bundle storage bundle) internal returns(Bundle storage) { - Validate.assigned(bundle.name); - Validate.notZero(bundle.functions.length); - Validate.contractAssigned(bundle.facade); + Validate.MUST_NameAssigned(bundle); + Validate.MUST_HaveAtLeastOneFunction(bundle); + Validate.MUST_FacadeAssigned(bundle); bundle.status = TypeStatus.Built; return bundle; } function lock(Bundle storage bundle) internal returns(Bundle storage) { - Validate.MUST_beBuilt(bundle.status); + Validate.MUST_built(bundle.status); bundle.status = TypeStatus.Locked; return bundle; } @@ -96,13 +109,13 @@ library TypeGuard { return registry; } function build(StdRegistry storage registry) internal returns(StdRegistry storage) { - Validate.isComplete(registry.functions); - Validate.isComplete(registry.all); + Validate.MUST_Completed(registry.functions); + Validate.MUST_completed(registry.all); registry.status = TypeStatus.Built; return registry; } function lock(StdRegistry storage registry) internal returns(StdRegistry storage) { - Validate.MUST_beBuilt(registry.status); + Validate.MUST_built(registry.status); registry.status = TypeStatus.Locked; return registry; } @@ -116,14 +129,14 @@ library TypeGuard { return stdFunctions; } function build(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { - Validate.isComplete(stdFunctions.initSetAdmin); - Validate.isComplete(stdFunctions.getDeps); - Validate.isComplete(stdFunctions.clone); + Validate.MUST_completed(stdFunctions.initSetAdmin); + Validate.MUST_completed(stdFunctions.getDeps); + Validate.MUST_completed(stdFunctions.clone); stdFunctions.status = TypeStatus.Built; return stdFunctions; } function lock(StdFunctions storage stdFunctions) internal returns(StdFunctions storage) { - Validate.MUST_beBuilt(stdFunctions.status); + Validate.MUST_built(stdFunctions.status); stdFunctions.status = TypeStatus.Locked; return stdFunctions; } @@ -137,13 +150,13 @@ library TypeGuard { return dictionary; } function build(Dictionary storage dictionary) internal returns(Dictionary storage) { - Validate.isContract(dictionary.addr); - Validate.notUndefined(dictionary.kind); + Validate.MUST_contractAssigned(dictionary); + Validate.MUST_kindAssigned(dictionary); dictionary.status = TypeStatus.Built; return dictionary; } function lock(Dictionary storage dictionary) internal returns(Dictionary storage) { - Validate.MUST_beBuilt(dictionary.status); + Validate.MUST_built(dictionary.status); dictionary.status = TypeStatus.Locked; return dictionary; } @@ -160,13 +173,13 @@ library TypeGuard { return proxy; } function build(Proxy storage proxy) internal returns(Proxy storage) { - Validate.isContract(proxy.addr); - Validate.notUndefined(proxy.kind); + Validate.MUST_contractAssigned(proxy); + Validate.MUST_kindAssigned(proxy); proxy.status = TypeStatus.Built; return proxy; } function lock(Proxy storage proxy) internal returns(Proxy storage) { - Validate.MUST_beBuilt(proxy.status); + Validate.MUST_built(proxy.status); proxy.status = TypeStatus.Locked; return proxy; } diff --git a/devkit/utils/global/MCBundleLib.sol b/devkit/utils/global/MCBundleLib.sol index 44d0b60f..069c93b5 100644 --- a/devkit/utils/global/MCBundleLib.sol +++ b/devkit/utils/global/MCBundleLib.sol @@ -67,7 +67,7 @@ library MCBundleLib { // return mc; // } TODO function use(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - Validate.validRegistration(mc.functions, name); + Validate.MUST_registered(mc.functions, name); return mc.use(mc.findFunction(name)); } /**--------------------------- @@ -97,7 +97,7 @@ library MCBundleLib { --------------------*/ function useFacade(MCDevKit storage mc, address facade) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("set"); - Validate.MUST_beInitialized(mc.bundle); + Validate.MUST_haveCurrent(mc.bundle); mc.bundle.findCurrent().assignFacade(facade); return mc.recordExecFinish(pid); } diff --git a/devkit/utils/global/MCTestLib.sol b/devkit/utils/global/MCTestLib.sol index 00a94813..103dc5b6 100644 --- a/devkit/utils/global/MCTestLib.sol +++ b/devkit/utils/global/MCTestLib.sol @@ -52,7 +52,7 @@ library MCTestLib { */ function createProxySimpleMock(MCDevKit storage mc, string memory name, Function[] memory functions) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("createProxySimpleMock", Params.append(name)); // TODO append functions - Validate.notEmpty(name); + Validate.MUST_NotEmptyName(name); // TODO Check Functions? Proxy memory proxyMock = ProxyLib.createSimpleMock(functions); mc.proxy.register(name, proxyMock); @@ -86,7 +86,7 @@ library MCTestLib { */ function createMockDictionary(MCDevKit storage mc, string memory name, address owner, Function[] memory functions) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("createMockDictionary", Params.append(name, owner)); - Validate.notEmpty(name); + Validate.MUST_NotEmptyName(name); // TODO Check Functions? Dictionary memory dictionaryMock = DictionaryLib.createMock(owner, functions); mc.dictionary.register(name, dictionaryMock); diff --git a/devkit/utils/inspector/Inspector.sol b/devkit/utils/inspector/Inspector.sol index af56ebf1..8ff44808 100644 --- a/devkit/utils/inspector/Inspector.sol +++ b/devkit/utils/inspector/Inspector.sol @@ -28,6 +28,10 @@ import {DictionaryRegistry} from "devkit/registry/DictionaryRegistry.sol"; 🧐 Inspectors ----------------------*/ library Inspector { + using Inspector for string; + using Inspector for bytes4; + using Inspector for address; + /**================== 🧩 Function ====================*/ @@ -125,6 +129,9 @@ library Inspector { function isNotEmpty(Proxy memory proxy) internal returns(bool) { return proxy.addr.isContract(); } + function hasContract(Proxy memory proxy) internal returns(bool) { + return proxy.addr.isContract(); + } function isMock(Proxy memory proxy) internal pure returns(bool) { return proxy.kind == ProxyKind.Mock; @@ -206,4 +213,62 @@ library Inspector { // function existsInMocks(DictionaryRegistry storage dictionaries, string memory name) internal returns(bool) { // return dictionaries.mocks[name].exists(); // } + + + + /**=================== + 🧱 Primitives + =====================*/ + /// 📝 String + function isAssigned(string storage str) internal returns(bool) { + return str.isNotEmpty(); + } + function isEmpty(string memory str) internal returns(bool) { + return bytes(str).length == 0; + } + function isNotEmpty(string memory str) internal returns(bool) { + return str.isEmpty().isNot(); + } + function isEqual(string memory a, string memory b) internal returns(bool) { + return keccak256(abi.encode(a)) == keccak256(abi.encode(b)); + } + function isNotEqual(string memory a, string memory b) internal returns(bool) { + return a.isEqual(b).isNot(); + } + /// 💾 Bytes4 + function isAssigned(bytes4 selector) internal pure returns(bool) { + return selector.isNotEmpty(); + } + function isEmpty(bytes4 selector) internal pure returns(bool) { + return selector == bytes4(0); + } + function isNotEmpty(bytes4 selector) internal pure returns(bool) { + return selector.isEmpty().isFalse(); + } + function isEqual(bytes4 a, bytes4 b) internal pure returns(bool) { + return a == b; + } + function isNotEqual(bytes4 a, bytes4 b) internal pure returns(bool) { + return a.isEqual(b).isFalse(); + } + /// 📌 Address + function isZero(address addr) internal returns(bool) { + return addr == address(0); + } + function isNotZero(address addr) internal returns(bool) { + return addr.isZero().isNot(); + } + function hasCode(address addr) internal returns(bool) { + return addr.code.length != 0; + } + function hasNotCode(address addr) internal returns(bool) { + return addr.hasCode().isNot(); + } + function isContract(address addr) internal returns(bool) { + return addr.hasCode(); + } + function isNotContract(address addr) internal returns(bool) { + return addr.isContract().isNot(); + } + } diff --git a/devkit/utils/primitive/AddressUtils.sol b/devkit/utils/primitive/AddressUtils.sol index de0e7f66..9cdf3e6f 100644 --- a/devkit/utils/primitive/AddressUtils.sol +++ b/devkit/utils/primitive/AddressUtils.sol @@ -23,52 +23,6 @@ library AddressUtils { } - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - // isZero - function isZero(address addr) internal returns(bool) { - return addr == address(0); - } - function assertZero(address addr) internal returns(address) { - Validate.notZero(addr); - return addr; - } - - // isNotZero - function isNotZero(address addr) internal returns(bool) { - return addr.isZero().isNot(); - } - function assertNotZero(address addr) internal returns(address) { - Validate.notZero(addr); - return addr; - } - - // hasCode - function hasCode(address addr) internal returns(bool) { - return addr.code.length != 0; - } - - // hasNotCode - function hasNotCode(address addr) internal returns(bool) { - return addr.hasCode().isNot(); - } - - // isContract - function isContract(address addr) internal returns(bool) { - return addr.hasCode(); - } - function assertIsContract(address addr) internal returns(address) { - Validate.isContract(addr); - return addr; - } - - // isNotContract - function isNotContract(address addr) internal returns(bool) { - return addr.isContract().isNot(); - } - - /**------------------------- đŸ§Ē Utils for Testing ---------------------------*/ diff --git a/devkit/utils/primitive/Bytes4Utils.sol b/devkit/utils/primitive/Bytes4Utils.sol index cf61b566..a318baf8 100644 --- a/devkit/utils/primitive/Bytes4Utils.sol +++ b/devkit/utils/primitive/Bytes4Utils.sol @@ -28,30 +28,4 @@ library Bytes4Utils { return vm.toString(selector).substring(10); } - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function isEmpty(bytes4 selector) internal pure returns(bool) { - return selector == bytes4(0); - } - function assertEmpty(bytes4 selector) internal returns(bytes4) { - Validate.notEmpty(selector); - return selector; - } - - function isNotEmpty(bytes4 selector) internal pure returns(bool) { - return selector.isEmpty().isFalse(); - } - function assertNotEmpty(bytes4 selector) internal returns(bytes4) { - Validate.notEmpty(selector); - return selector; - } - - function isEqual(bytes4 a, bytes4 b) internal pure returns(bool) { - return a == b; - } - function isNotEqual(bytes4 a, bytes4 b) internal pure returns(bool) { - return a.isEqual(b).isFalse(); - } } diff --git a/devkit/utils/primitive/StringUtils.sol b/devkit/utils/primitive/StringUtils.sol index 9a4c6c19..886edf22 100644 --- a/devkit/utils/primitive/StringUtils.sol +++ b/devkit/utils/primitive/StringUtils.sol @@ -24,7 +24,7 @@ library StringUtils { return keccak256(abi.encode(name)); } function safeCalcHash(string memory name) internal returns(bytes32) { - Validate.notEmpty(name); + Validate.MUST_NotEmptyName(name); return name.calcHash(); } @@ -96,37 +96,6 @@ library StringUtils { } - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - // isEmpty - /// @dev only for memory - function isEmpty(string memory str) internal returns(bool) { - return bytes(str).length == 0; - } - function assertEmpty(string memory str) internal returns(string memory) { - Validate.notEmpty(str); - return str; - } - - // isNotEmpty - function isNotEmpty(string memory str) internal returns(bool) { - return str.isEmpty().isNot(); - } - function assertNotEmpty(string memory str) internal returns(string memory) { - Validate.notEmpty(str); - return str; - } - - // isEqual - function isEqual(string memory a, string memory b) internal returns(bool) { - return keccak256(abi.encode(a)) == keccak256(abi.encode(b)); - } - - // isNotEqual - function isNotEqual(string memory a, string memory b) internal returns(bool) { - return a.isEqual(b).isNot(); - } /**---------------- diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index 8c861948..9c86058b 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -5,6 +5,10 @@ import {throwError} from "devkit/log/error/ThrowError.sol"; import {ERR} from "devkit/log/message/ERR.sol"; import {Debug, LogLevel} from "devkit/log/debug/Debug.sol"; import {Logger} from "devkit/log/debug/Logger.sol"; +import {Inspector} from "devkit/utils/inspector/Inspector.sol"; + using Inspector for string; + using Inspector for bytes4; + using Inspector for address; // Utils import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; using BoolUtils for bool; @@ -48,240 +52,159 @@ library Validate { /**=================== 🔒 Type Guard =====================*/ - function MUST_beBuilt(TypeStatus status) internal { + function MUST_built(TypeStatus status) internal { validate(MUST, status.isBuilt(), "Not Built Yet", ""); } - // function MUST_beCompleted(TypeStatus status) internal { - // validate(MUST, status.isComplete(), "", ""); - // } - - /**================== + /**=================== 🧱 Primitives - ====================*/ - function notZero(uint256 num) internal { + =====================*/ + function MUST_NotZeroUint(uint256 num) internal { validate(MUST, num.isNotZero(), "Zero Number", ""); } - - function assigned(string memory str) internal { - validate(MUST, str.isNotEmpty(), "Not Assigned", ""); + function MUST_NotEmptyName(string memory name) internal { + validate(MUST, name.isNotEmpty(), ERR.EMPTY_STR, ""); } - - /**================== - 🧩 Function - ====================*/ - function exists(Function storage func) internal { - validate(MUST, func.exists(), "func does not exists", ""); - // validate(MUST, func.isBuilt(), "func does not exists", ""); // TODO + function MUST_NotEmptyEnvKey(string memory envKey) internal { + validate(MUST, envKey.isNotEmpty(), ERR.EMPTY_STR, ""); } - function isComplete(Function storage func) internal { - validate(MUST, func.isComplete(), "Function Not Complete", ""); + function MUST_Bytes4NotEmpty(bytes4 b4) internal { + validate(MUST, b4.isNotEmpty(), ERR.EMPTY_B4, ""); } - function valid(Function storage func) internal { - exists(func); - isComplete(func); + function MUST_AddressIsContract(address addr) internal { + validate(MUST, addr.isContract(), ERR.NOT_CONTRACT, ""); } - - function EmptyName(Function storage func) internal { - isUnassigned(func.name); + function MUST_AddressIsNotZero(address addr) internal { + validate(MUST, addr.isNotZero(), ERR.ZERO_ADDRESS, ""); } - function EmptySelector(Function storage func) internal { - isUnassigned(func.selector); + + + /**================== + 🧩 Function + ====================*/ + function MUST_nameAssigned(Function storage func) internal { + validate(MUST, func.name.isAssigned(), "Name must be assigned", ""); } - function EmptyImpl(Function storage func) internal { - validate(MUST, func.implementation.isNotContract(), "Implementation Already Exist", ""); + function MUST_selectorAssigned(Function storage func) internal { + validate(MUST, func.selector.isAssigned(), "Selector must be assigned", ""); } - - function NotEmpty(Function storage func) internal { - validate(MUST, func.exists(), "Empty Deployed Contract", ""); + function MUST_implementationAssigned(Function storage func) internal { + validate(MUST, func.implementation.isContract(), "Contract must be assigned", ""); } - - function NotIncludedIn(Function storage func, Bundle storage bundleInfo) internal { - validate(MUST, bundleInfo.hasNot(func), "Already exists in the Bundel", ""); + function MUST_completed(Function storage func) internal { + validate(MUST, func.isComplete(), "Function Not Complete", ""); } - - function implIsContract(Function storage func) internal { - validate(MUST, func.implementation.isContract(), "Implementation Not Contract", ""); + function MUST_FunctionNotLocked(Function storage func) internal { + validate(MUST, func.status.isNotLocked(), ERR.LOCKED_OBJECT, ""); } - function validRegistration(FunctionRegistry storage registry, string memory name) internal { - validate(MUST, registry.functions[name].isComplete(), "Function Not Complete", ""); + /**=========================== + 📗 Functions Registry + =============================*/ + function MUST_registered(FunctionRegistry storage registry, string memory name) internal { + validate(MUST, registry.functions[name].isComplete(), "Function Not Found", ""); } - /**=============== đŸ—‚ī¸ Bundle =================*/ - function isComplete(Bundle storage bundle) internal { - validate(MUST, bundle.isComplete(), "Bundle Info Not Complete", bundle.parse()); + function MUST_NameAssigned(Bundle storage bundle) internal { + validate(MUST, bundle.name.isNotEmpty(), "Bundle Name is required", ""); } - function valid(Bundle storage bundle) internal { - exists(bundle); - isComplete(bundle); + function MUST_HaveAtLeastOneFunction(Bundle storage bundle) internal { + validate(MUST, bundle.functions.length.isNotZero(), "At least one function is required", ""); } - function SHOULD_valid(Bundle storage bundle) internal { - validate(SHOULD, bundle.exists(), "Bundle Not Exists", ""); - // exists(bundle); - validate(SHOULD, bundle.isComplete(), "Bundle Not Complete", ""); - // isComplete(bundle); + function MUST_FacadeAssigned(Bundle storage bundle) internal { + validate(MUST, bundle.facade.isContract(), "Bundle Facade is required", ""); } - - function exists(Bundle storage bundle) internal { - validate(MUST, bundle.exists(), "Bundle Info Not Exists", ""); + function MUST_notInitialized(Bundle storage bundle) internal { + validate(MUST, bundle.status.notInitialized(), "Bundle already initialized", ""); } - function notExists(Bundle storage bundle) internal returns(Bundle storage) { - validate(MUST, bundle.notExists(), "Bundle Already Exists", ""); - return bundle; + function MUST_completed(Bundle storage bundle) internal { + validate(MUST, bundle.isComplete(), "Bundle Not Complete", bundle.parse()); } - function isUnassigned(Bundle storage bundle) internal { - validate(MUST, bundle.hasNotName(), "Bundle Already Assigned.", ""); + function SHOULD_completed(Bundle storage bundle) internal { + validate(SHOULD, bundle.isComplete(), "Bundle Not Complete", ""); } - function hasNot(Bundle storage bundle, Function storage func) internal { + function MUST_notHave(Bundle storage bundle, Function storage func) internal { validate(MUST, bundle.hasNot(func), "Bundle has same Function", ""); } + function MUST_BundleNotLocked(Bundle storage bundle) internal { + validate(MUST, bundle.status.isNotLocked(), ERR.LOCKED_OBJECT, ""); + } /**======================= 📙 Bundle Registry =========================*/ - function bundleNotExists(BundleRegistry storage bundle, string memory name) internal returns(BundleRegistry storage) { - validate(MUST, bundle.notExistsBundle(name), "Bundle Already Exists", ""); - return bundle; - } - function SHOULD_beCompleted(BundleRegistry storage registry, string memory name) internal { - validate(SHOULD, registry.bundles[name].isComplete(), "Incompleted Bundle", ""); - } - function MUST_existCurrent(BundleRegistry storage registry) internal { + function MUST_haveCurrent(BundleRegistry storage registry) internal { validate(MUST, registry.current.name.isNotEmpty(), "Current Not Exist", ""); } - function MUST_beInitialized(BundleRegistry storage registry) internal { - validate(MUST, registry.current.name.isNotEmpty(), ERR.NOT_INIT, ""); - } /**============== 🏠 Proxy ================*/ - function exists(Proxy storage proxy) internal returns(Proxy storage) { - validate(MUST, proxy.exists(), "Proxy Not Exist", ""); - return proxy; + function MUST_haveContract(Proxy memory proxy) internal { + validate(MUST, proxy.addr.isContract(), "Contract is required", ""); } - function isComplete(Proxy storage proxy) internal { - validate(MUST, proxy.isComplete(), "Proxy Not Complete", ""); + function MUST_haveKind(Proxy memory proxy) internal { + validate(MUST, proxy.kind.isNotUndefined(), "ProxyKind is required", ""); } - function valid(Proxy storage proxy) internal { - exists(proxy); - isComplete(proxy); + function MUST_contractAssigned(Proxy storage proxy) internal { + validate(MUST, proxy.addr.isContract(), "Contract is not assigned", ""); } - function notEmpty(Proxy memory proxy) internal returns(Proxy memory) { - validate(MUST, proxy.isNotEmpty(), "Empty Proxy", ""); - return proxy; + function MUST_kindAssigned(Proxy storage proxy) internal { + validate(MUST, proxy.kind.isNotUndefined(), "ProxyKind is not assigned", ""); } - /*---- Proxy Kind -----*/ - function NotUndefined(ProxyKind kind) internal returns(ProxyKind) { - validate(MUST, kind.isNotUndefined(), "Undefined Proxy Kind", ""); - return kind; + function MUST_completed(Proxy storage proxy) internal { + validate(MUST, proxy.isComplete(), "Proxy Not Complete", ""); } - - function notRegistered(ProxyRegistry storage registry, string memory name) internal { - validate(MUST, registry.proxies[name].notExists(), "Proxy Already Exists", ""); + /**======================= + 📕 Proxy Registry + =========================*/ + function MUST_registered(ProxyRegistry storage registry, string memory name) internal { + validate(MUST, registry.proxies[name].isComplete(), "Proxy Not Found", ""); } - function validRegistration(ProxyRegistry storage registry, string memory name) internal { - validate(MUST, registry.proxies[name].isComplete(), "Proxy Not Complete", ""); + function MUST_notRegistered(ProxyRegistry storage registry, string memory name) internal { + validate(MUST, registry.proxies[name].notExists(), "Proxy Already Exists", ""); } - /**==================== 📚 Dictionary ======================*/ - function exists(Dictionary storage dictionary) internal returns(Dictionary storage) { - validate(MUST, dictionary.exists(), "Dictionary Not Exists", ""); - return dictionary; + function MUST_haveContract(Dictionary memory dictionary) internal { + validate(MUST, dictionary.addr.isContract(), "Contract is required", ""); } - function isComplete(Dictionary storage dictionary) internal { - validate(MUST, dictionary.isComplete(), "Dictionary Not Complete", ""); + function MUST_haveKind(Dictionary memory dictionary) internal { + validate(MUST, dictionary.kind.isNotUndefined(), "DictionaryKind is required", ""); } - function valid(Dictionary storage dictionary) internal { - exists(dictionary); - isComplete(dictionary); + function MUST_contractAssigned(Dictionary storage dictionary) internal { + validate(MUST, dictionary.addr.isContract(), "Contract is not assigned", ""); } - function notEmpty(Dictionary memory dictionary) internal returns(Dictionary memory) { - validate(MUST, dictionary.isNotEmpty(), "Empty Dictionary", ""); - return dictionary; + function MUST_kindAssigned(Dictionary storage dictionary) internal { + validate(MUST, dictionary.kind.isNotUndefined(), "DictionaryKind is not assigned", ""); } - function Supports(Dictionary storage dictionary, bytes4 selector) internal returns(Dictionary storage) { - validate(MUST, dictionary.isSupported(selector), "Unsupported Selector", ""); - return dictionary; - } - function verifiable(Dictionary memory dictionary) internal returns(Dictionary memory) { - validate(MUST, dictionary.isVerifiable(), "Dictionary Not Verifiable", ""); - return dictionary; - } - /*---- Dictionary Kind -----*/ - function notUndefined(DictionaryKind kind) internal { - validate(MUST, kind.isNotUndefined(), "Undefined Dictionary Kind", ""); + function MUST_completed(Dictionary storage dictionary) internal { + validate(MUST, dictionary.isComplete(), "Dictionary Not Complete", ""); } - function notUndefined(ProxyKind kind) internal { - validate(MUST, kind.isNotUndefined(), "Undefined Dictionary Kind", ""); + /**============================ + 📘 Dictionary Registry + ==============================*/ + function MUST_registered(DictionaryRegistry storage registry, string memory name) internal { + validate(MUST, registry.dictionaries[name].isComplete(), "Dictionary Not Found", ""); } - - function notRegistered(DictionaryRegistry storage registry, string memory name) internal { + function MUST_notRegistered(DictionaryRegistry storage registry, string memory name) internal { validate(MUST, registry.dictionaries[name].notExists(), "Dictionary Already Exists", ""); } - function validRegistration(DictionaryRegistry storage registry, string memory name) internal { - validate(MUST, registry.dictionaries[name].isComplete(), "Dictionary Not Registered", ""); - } - - - function isUnassigned(string storage str) internal { - validate(MUST, str.isEmpty(), ERR.STR_ALREADY_ASSIGNED, ""); - } - function notEmpty(string memory str) internal { - validate(MUST, str.isNotEmpty(), ERR.EMPTY_STR, ""); - } - function MUST_notEmpty(string memory str) internal { - validate(MUST, str.isNotEmpty(), "Current Bundle Not Found", ""); - } - - function isUnassigned(bytes4 b4) internal { - validate(MUST, b4.isEmpty(), ERR.B4_ALREADY_ASSIGNED, ""); - } - function notEmpty(bytes4 b4) internal { - validate(MUST, b4.isNotEmpty(), ERR.EMPTY_B4, ""); - } - - function isContract(address addr) internal { - validate(MUST, addr.isContract(), ERR.NOT_CONTRACT, ""); - } - - function notEmptyString(string memory str) internal { - validate(MUST, str.isNotEmpty(), ERR.RQ_NOT_EMPTY_STRING, ""); - } - - function assigned(bytes4 b4) internal { - validate(MUST, b4.isNotEmpty(), ERR.RQ_SELECTOR, ""); - } - function contractAssigned(address addr) internal { - validate(MUST, addr.isContract(), ERR.RQ_CONTRACT, ""); - } - - function notLocked(TypeStatus status) internal { - validate(MUST, status != TypeStatus.Locked, ERR.LOCKED_OBJECT, ""); - } - - function isNotEmpty(Dictionary memory dictionary) internal { - validate(MUST, dictionary.isNotEmpty(), ERR.EMPTY_DICTIONARY, ""); - } - - function notZero(address addr) internal { - validate(MUST, addr.isNotZero(), ERR.ZERO_ADDRESS, ""); - } - /**========================== 🏛 Standard Registry ============================*/ - function isComplete(StdRegistry storage registry) internal { + function MUST_Completed(StdRegistry storage registry) internal { validate(MUST, registry.status.isComplete(), "Registry Not Complete", ""); } - function isComplete(StdFunctions storage stdFunctions) internal { + function MUST_StdNotLocked(StdRegistry storage registry) internal { + validate(MUST, registry.status.isNotLocked(), "Std Registry is locked", ""); + } + function MUST_Completed(StdFunctions storage stdFunctions) internal { validate(MUST, stdFunctions.status.isComplete(), "Registry Not Complete", ""); } } diff --git a/devkit/validate/ValidationHandler.sol b/devkit/validate/ValidationHandler.sol new file mode 100644 index 00000000..88a48c56 --- /dev/null +++ b/devkit/validate/ValidationHandler.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {throwError} from "devkit/log/error/ThrowError.sol"; +import {ERR} from "devkit/log/message/ERR.sol"; +import {Debug, LogLevel} from "devkit/log/debug/Debug.sol"; +// Utils +import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; + using BoolUtils for bool; +import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; + using StringUtils for string; +import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; + using Bytes4Utils for bytes4; +import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; + using AddressUtils for address; +import {UintUtils} from "devkit/utils/primitive/UintUtils.sol"; + using UintUtils for uint256; +import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; +// Core Types +import {Function} from "devkit/core/Function.sol"; +import {FunctionRegistry} from "devkit/registry/FunctionRegistry.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +import {BundleRegistry} from "devkit/registry/BundleRegistry.sol"; +import {Proxy, ProxyKind} from "devkit/core/Proxy.sol"; +import {ProxyRegistry} from "devkit/registry/ProxyRegistry.sol"; +import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; +import {DictionaryRegistry} from "devkit/registry/DictionaryRegistry.sol"; +import {StdRegistry} from "devkit/registry/StdRegistry.sol"; +import {StdFunctions} from "devkit/registry/StdFunctions.sol"; + + diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index c73dd339..00828a21 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -3,6 +3,9 @@ pragma solidity ^0.8.24; import {MCDevKitTest} from "devkit/MCTest.sol"; +import {Inspector} from "devkit/utils/inspector/Inspector.sol"; + using Inspector for string; + import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; import {Config} from "devkit/config/Config.sol"; @@ -117,7 +120,7 @@ contract DevKitTest_MCBundle is MCDevKitTest { function test_Revert_useFacade_withoutInit() public { address facade = address(new DummyFacade()); - vm.expectRevert(ERR.message(ERR.NOT_INIT).toBytes()); + vm.expectRevert(ERR.message("Current Not Exist").toBytes()); mc.useFacade(facade); } } diff --git a/test/utils/TestHelper.sol b/test/utils/TestHelper.sol index 6c999ef8..0f15b018 100644 --- a/test/utils/TestHelper.sol +++ b/test/utils/TestHelper.sol @@ -5,6 +5,9 @@ import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; using AddressUtils for address; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; +import {Inspector} from "devkit/utils/inspector/Inspector.sol"; + using Inspector for string; + using Inspector for address; import {Function} from "devkit/core/Function.sol"; // import {Bundle} from "./Bundle.sol"; From a8c0a30e11ae99109a053e5757767dd85111c4b1 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 16:18:22 +0900 Subject: [PATCH 092/111] Remove ValidationHandler file --- devkit/validate/ValidationHandler.sol | 31 --------------------------- 1 file changed, 31 deletions(-) delete mode 100644 devkit/validate/ValidationHandler.sol diff --git a/devkit/validate/ValidationHandler.sol b/devkit/validate/ValidationHandler.sol deleted file mode 100644 index 88a48c56..00000000 --- a/devkit/validate/ValidationHandler.sol +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import {throwError} from "devkit/log/error/ThrowError.sol"; -import {ERR} from "devkit/log/message/ERR.sol"; -import {Debug, LogLevel} from "devkit/log/debug/Debug.sol"; -// Utils -import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; - using BoolUtils for bool; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; - using StringUtils for string; -import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; -import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; - using AddressUtils for address; -import {UintUtils} from "devkit/utils/primitive/UintUtils.sol"; - using UintUtils for uint256; -import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; -// Core Types -import {Function} from "devkit/core/Function.sol"; -import {FunctionRegistry} from "devkit/registry/FunctionRegistry.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -import {BundleRegistry} from "devkit/registry/BundleRegistry.sol"; -import {Proxy, ProxyKind} from "devkit/core/Proxy.sol"; -import {ProxyRegistry} from "devkit/registry/ProxyRegistry.sol"; -import {Dictionary, DictionaryKind} from "devkit/core/Dictionary.sol"; -import {DictionaryRegistry} from "devkit/registry/DictionaryRegistry.sol"; -import {StdRegistry} from "devkit/registry/StdRegistry.sol"; -import {StdFunctions} from "devkit/registry/StdFunctions.sol"; - - From 43b11d340401864d6e56818ea68306045f56385d Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 16:30:37 +0900 Subject: [PATCH 093/111] Create Type Converter --- devkit/log/debug/Params.sol | 4 +-- devkit/registry/StdFunctions.sol | 3 -- devkit/registry/StdRegistry.sol | 3 -- devkit/types/TypeConverter.sol | 13 ++++++++ devkit/utils/inspector/Inspector.sol | 2 -- devkit/utils/primitive/AddressUtils.sol | 42 ------------------------- devkit/utils/test/TestLib.sol | 13 ++++++++ devkit/validate/Validate.sol | 2 -- test/utils/TestHelper.sol | 2 -- 9 files changed, 28 insertions(+), 56 deletions(-) create mode 100644 devkit/types/TypeConverter.sol delete mode 100644 devkit/utils/primitive/AddressUtils.sol diff --git a/devkit/log/debug/Params.sol b/devkit/log/debug/Params.sol index 90db71a9..238e335d 100644 --- a/devkit/log/debug/Params.sol +++ b/devkit/log/debug/Params.sol @@ -3,10 +3,10 @@ pragma solidity ^0.8.24; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; -import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; - using AddressUtils for address; import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; using Bytes4Utils for bytes4; +import {TypeConverter} from "devkit/types/TypeConverter.sol"; + using TypeConverter for address; library Params { diff --git a/devkit/registry/StdFunctions.sol b/devkit/registry/StdFunctions.sol index 387c11cf..8cdd6230 100644 --- a/devkit/registry/StdFunctions.sol +++ b/devkit/registry/StdFunctions.sol @@ -18,9 +18,6 @@ import {FeatureToggle} from "mc-std/functions/protected/FeatureToggle.sol"; import {InitSetAdmin} from "mc-std/functions/protected/InitSetAdmin.sol"; import {UpgradeDictionary} from "mc-std/functions/protected/UpgradeDictionary.sol"; import {StdFacade} from "mc-std/interfaces/StdFacade.sol"; -// Utils -import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; - using AddressUtils for address; /**========================== diff --git a/devkit/registry/StdRegistry.sol b/devkit/registry/StdRegistry.sol index e2120637..18c00241 100644 --- a/devkit/registry/StdRegistry.sol +++ b/devkit/registry/StdRegistry.sol @@ -7,9 +7,6 @@ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for StdRegistry global; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for StdRegistry global; -// Utils -import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; - using AddressUtils for address; // Validation import {Validate} from "devkit/validate/Validate.sol"; diff --git a/devkit/types/TypeConverter.sol b/devkit/types/TypeConverter.sol new file mode 100644 index 00000000..f527d19a --- /dev/null +++ b/devkit/types/TypeConverter.sol @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {vm} from "devkit/utils/ForgeHelper.sol"; + +/**=====================\ +| 🔀 Type Converter | +\======================*/ +library TypeConverter { + function toString(address addr) internal pure returns(string memory) { + return vm.toString(addr); + } +} diff --git a/devkit/utils/inspector/Inspector.sol b/devkit/utils/inspector/Inspector.sol index 8ff44808..ec962502 100644 --- a/devkit/utils/inspector/Inspector.sol +++ b/devkit/utils/inspector/Inspector.sol @@ -4,8 +4,6 @@ pragma solidity ^0.8.24; import {Validate} from "devkit/validate/Validate.sol"; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; -import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; - using AddressUtils for address; import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; using BoolUtils for bool; import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; diff --git a/devkit/utils/primitive/AddressUtils.sol b/devkit/utils/primitive/AddressUtils.sol deleted file mode 100644 index 9cdf3e6f..00000000 --- a/devkit/utils/primitive/AddressUtils.sol +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Validation -import {Validate} from "devkit/validate/Validate.sol"; -// Utils -import {vm} from "devkit/utils/ForgeHelper.sol"; -import {BoolUtils} from "./BoolUtils.sol"; - using BoolUtils for bool; -// External Lib -import {ERC7546Utils} from "@ucs.mc/proxy/ERC7546Utils.sol"; - -/**======================\ -| 📌 Address Utils | -\=======================*/ -using AddressUtils for address; -library AddressUtils { - /**----------------------- - 🔀 Type Convertor - -------------------------*/ - function toString(address addr) internal pure returns(string memory) { - return vm.toString(addr); - } - - - /**------------------------- - đŸ§Ē Utils for Testing - ---------------------------*/ - function injectCode(address target, bytes memory runtimeBytecode) internal { - // vm.assume(runtimeBytecode.length > 0); - vm.etch(target, runtimeBytecode); - } - - function injectDictionary(address target, address dictionary) internal { - injectAddressToStorage(target, ERC7546Utils.DICTIONARY_SLOT, dictionary); - } - - function injectAddressToStorage(address target, bytes32 slot, address addr) internal { - vm.store(target, slot, bytes32(uint256(uint160(addr)))); - } - -} diff --git a/devkit/utils/test/TestLib.sol b/devkit/utils/test/TestLib.sol index 95436043..b192c630 100644 --- a/devkit/utils/test/TestLib.sol +++ b/devkit/utils/test/TestLib.sol @@ -27,4 +27,17 @@ library TestLib { function changeDictionary(Proxy storage proxy) internal {} + function injectCode(address target, bytes memory runtimeBytecode) internal { + // vm.assume(runtimeBytecode.length > 0); + vm.etch(target, runtimeBytecode); + } + + function injectDictionary(address target, address dictionary) internal { + injectAddressToStorage(target, ERC7546Utils.DICTIONARY_SLOT, dictionary); + } + + function injectAddressToStorage(address target, bytes32 slot, address addr) internal { + vm.store(target, slot, bytes32(uint256(uint160(addr)))); + } + } diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index 9c86058b..9f08eb14 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -16,8 +16,6 @@ import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; using Bytes4Utils for bytes4; -import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; - using AddressUtils for address; import {UintUtils} from "devkit/utils/primitive/UintUtils.sol"; using UintUtils for uint256; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; diff --git a/test/utils/TestHelper.sol b/test/utils/TestHelper.sol index 0f15b018..e00a9419 100644 --- a/test/utils/TestHelper.sol +++ b/test/utils/TestHelper.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; - using AddressUtils for address; import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; using StringUtils for string; import {Inspector} from "devkit/utils/inspector/Inspector.sol"; From 0b47b019bd94050c5eea7c81819382b750d9332e Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 16:55:14 +0900 Subject: [PATCH 094/111] Move primitive method to converter and inspector --- devkit/core/Bundle.sol | 2 +- devkit/core/Dictionary.sol | 6 ++-- devkit/core/Function.sol | 2 +- devkit/core/Proxy.sol | 2 +- devkit/log/debug/Debug.sol | 8 ++--- devkit/log/debug/Logger.sol | 4 +-- devkit/log/debug/Params.sol | 5 ++- devkit/log/message/ERR.sol | 2 +- devkit/registry/BundleRegistry.sol | 2 +- devkit/registry/DictionaryRegistry.sol | 2 +- devkit/registry/ProxyRegistry.sol | 2 +- .../{utils/inspector => types}/Inspector.sol | 25 +++++++++++---- .../primitive => types}/StringUtils.sol | 22 ++++--------- devkit/types/TypeConverter.sol | 10 ++++++ devkit/types/TypeGuard.sol | 6 ++-- devkit/utils/debug/Parser.sol | 2 +- devkit/utils/inspector/MappingAnalyzer.sol | 2 +- devkit/utils/primitive/BoolUtils.sol | 24 -------------- devkit/utils/primitive/Bytes4Utils.sol | 31 ------------------ devkit/utils/primitive/UintUtils.sol | 32 ------------------- devkit/validate/Validate.sol | 18 ++++++----- test/devkit/global/MCBundle.t.sol | 6 ++-- test/utils/TestHelper.sol | 6 ++-- 23 files changed, 76 insertions(+), 145 deletions(-) rename devkit/{utils/inspector => types}/Inspector.sol (92%) rename devkit/{utils/primitive => types}/StringUtils.sol (86%) delete mode 100644 devkit/utils/primitive/BoolUtils.sol delete mode 100644 devkit/utils/primitive/Bytes4Utils.sol delete mode 100644 devkit/utils/primitive/UintUtils.sol diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 969aaafe..5bb6a9cb 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -7,7 +7,7 @@ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for Bundle global; import {Parser} from "devkit/utils/debug/Parser.sol"; using Parser for Bundle global; -import {Inspector} from "devkit/utils/inspector/Inspector.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Bundle global; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Bundle global; diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 5cf5c3e1..5014d6da 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -6,13 +6,13 @@ pragma solidity ^0.8.24; import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for Dictionary global; import {Params} from "devkit/log/debug/Params.sol"; -import {Inspector} from "devkit/utils/inspector/Inspector.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Dictionary global; using Inspector for bytes4; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; // Type Util -import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; +// import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; +// using Bytes4Utils for bytes4; // Validation import {Validate} from "devkit/validate/Validate.sol"; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index ea894f7a..140f8f9b 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -9,7 +9,7 @@ import {Parser} from "devkit/utils/debug/Parser.sol"; using Parser for Function global; import {Dumper} from "devkit/utils/debug/Dumper.sol"; using Dumper for Function global; -import {Inspector} from "devkit/utils/inspector/Inspector.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Function global; // Validation import {Validate} from "devkit/validate/Validate.sol"; diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index 1091a651..4747c0a7 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; -----------------------*/ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for Proxy global; -import {Inspector} from "devkit/utils/inspector/Inspector.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Proxy global; using Inspector for ProxyKind global; // Validation diff --git a/devkit/log/debug/Debug.sol b/devkit/log/debug/Debug.sol index d06af9bb..ecbc6007 100644 --- a/devkit/log/debug/Debug.sol +++ b/devkit/log/debug/Debug.sol @@ -4,10 +4,10 @@ pragma solidity ^0.8.24; // Utils import {console2, StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; - using BoolUtils for bool; +// import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; +// using StringUtils for string; +// import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; +// using BoolUtils for bool; import {Logger} from "./Logger.sol"; bytes32 constant DEBUGGER = 0x03d3692c02b7cdcaf0187e8ede4101c401cc53a33aa7e03ef4682fcca8a55300; diff --git a/devkit/log/debug/Logger.sol b/devkit/log/debug/Logger.sol index 482f1654..713a40da 100644 --- a/devkit/log/debug/Logger.sol +++ b/devkit/log/debug/Logger.sol @@ -4,10 +4,10 @@ pragma solidity ^0.8.24; import {ERR} from "devkit/log/message/ERR.sol"; // Utils import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; +import {StringUtils} from "devkit/types/StringUtils.sol"; // Debug import {Debug, Process} from "./Debug.sol"; -import {Inspector} from "devkit/utils/inspector/Inspector.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; //================ diff --git a/devkit/log/debug/Params.sol b/devkit/log/debug/Params.sol index 238e335d..ce30106d 100644 --- a/devkit/log/debug/Params.sol +++ b/devkit/log/debug/Params.sol @@ -1,12 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; +import {StringUtils} from "devkit/types/StringUtils.sol"; using StringUtils for string; -import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; import {TypeConverter} from "devkit/types/TypeConverter.sol"; using TypeConverter for address; + using TypeConverter for bytes4; library Params { diff --git a/devkit/log/message/ERR.sol b/devkit/log/message/ERR.sol index a275dd38..419a5c2b 100644 --- a/devkit/log/message/ERR.sol +++ b/devkit/log/message/ERR.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; // Utils import {StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; +import {StringUtils} from "devkit/types/StringUtils.sol"; /// @title Error Message library ERR { diff --git a/devkit/registry/BundleRegistry.sol b/devkit/registry/BundleRegistry.sol index 2d0c2490..f74ebebd 100644 --- a/devkit/registry/BundleRegistry.sol +++ b/devkit/registry/BundleRegistry.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; -----------------------*/ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for BundleRegistry global; -import {Inspector} from "devkit/utils/inspector/Inspector.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for BundleRegistry global; import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Bundle); diff --git a/devkit/registry/DictionaryRegistry.sol b/devkit/registry/DictionaryRegistry.sol index 1af9afae..3204cddb 100644 --- a/devkit/registry/DictionaryRegistry.sol +++ b/devkit/registry/DictionaryRegistry.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; -----------------------*/ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for DictionaryRegistry global; -import {Inspector} from "devkit/utils/inspector/Inspector.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for DictionaryRegistry global; import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Dictionary); diff --git a/devkit/registry/ProxyRegistry.sol b/devkit/registry/ProxyRegistry.sol index ccf946a3..6c82ac39 100644 --- a/devkit/registry/ProxyRegistry.sol +++ b/devkit/registry/ProxyRegistry.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; -----------------------*/ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for ProxyRegistry global; -import {Inspector} from "devkit/utils/inspector/Inspector.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for ProxyRegistry global; import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; using MappingAnalyzer for mapping(string => Proxy); diff --git a/devkit/utils/inspector/Inspector.sol b/devkit/types/Inspector.sol similarity index 92% rename from devkit/utils/inspector/Inspector.sol rename to devkit/types/Inspector.sol index ec962502..dad3480c 100644 --- a/devkit/utils/inspector/Inspector.sol +++ b/devkit/types/Inspector.sol @@ -2,12 +2,14 @@ pragma solidity ^0.8.24; import {Validate} from "devkit/validate/Validate.sol"; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; - using BoolUtils for bool; -import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; +// import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; +// using StringUtils for string; +// import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; +// using BoolUtils for bool; +// import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; +// using Bytes4Utils for bytes4; +import {Inspector} from "devkit/types/Inspector.sol"; + using Inspector for bool; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; // External Library import {IBeacon} from "@oz.mc/proxy/beacon/IBeacon.sol"; @@ -268,5 +270,16 @@ library Inspector { function isNotContract(address addr) internal returns(bool) { return addr.isContract().isNot(); } + /// ✅ Bool + function isNot(bool flag) internal pure returns(bool) { + return !flag; + } + function isFalse(bool flag) internal pure returns(bool) { + return flag == false; + } + /// #ī¸âƒŖ Uint + function isNotZero(uint256 num) internal pure returns(bool) { + return num != 0; + } } diff --git a/devkit/utils/primitive/StringUtils.sol b/devkit/types/StringUtils.sol similarity index 86% rename from devkit/utils/primitive/StringUtils.sol rename to devkit/types/StringUtils.sol index 886edf22..0cab26ec 100644 --- a/devkit/utils/primitive/StringUtils.sol +++ b/devkit/types/StringUtils.sol @@ -7,10 +7,10 @@ import {Debug} from "devkit/log/debug/Debug.sol"; // Utils import {StdStyle, ForgeHelper, vm} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; -import {Bytes4Utils} from "./Bytes4Utils.sol"; - using Bytes4Utils for bytes4; -import {BoolUtils} from "./BoolUtils.sol"; - using BoolUtils for bool; +import {TypeConverter} from "devkit/types//TypeConverter.sol"; + using TypeConverter for bytes4; +// import {BoolUtils} from "./BoolUtils.sol"; +// using BoolUtils for bool; /**=====================\ | 🖋 String Utils | @@ -28,9 +28,9 @@ library StringUtils { return name.calcHash(); } - function loadAddress(string memory envKey) internal returns(address) { - return ForgeHelper.loadAddressFromEnv(envKey); - } + // function loadAddress(string memory envKey) internal returns(address) { + // return ForgeHelper.loadAddressFromEnv(envKey); + // } function substring(string memory str, uint n) internal pure returns (string memory) { bytes memory strBytes = bytes(str); @@ -46,14 +46,6 @@ library StringUtils { } - /**----------------------- - 🔀 Type Convertor - -------------------------*/ - function toBytes(string memory str) internal returns (bytes memory) { - return bytes(str); - } - - /**---------------- ➕ Append ------------------*/ diff --git a/devkit/types/TypeConverter.sol b/devkit/types/TypeConverter.sol index f527d19a..4cb05977 100644 --- a/devkit/types/TypeConverter.sol +++ b/devkit/types/TypeConverter.sol @@ -2,6 +2,8 @@ pragma solidity ^0.8.24; import {vm} from "devkit/utils/ForgeHelper.sol"; +import {StringUtils} from "devkit/types/StringUtils.sol"; + using StringUtils for string; /**=====================\ | 🔀 Type Converter | @@ -10,4 +12,12 @@ library TypeConverter { function toString(address addr) internal pure returns(string memory) { return vm.toString(addr); } + + function toString(bytes4 selector) internal pure returns (string memory) { + return vm.toString(selector).substring(10); + } + + function toBytes(string memory str) internal returns (bytes memory) { + return bytes(str); + } } diff --git a/devkit/types/TypeGuard.sol b/devkit/types/TypeGuard.sol index 3d2f1457..f48d96a9 100644 --- a/devkit/types/TypeGuard.sol +++ b/devkit/types/TypeGuard.sol @@ -7,8 +7,10 @@ pragma solidity ^0.8.24; // using AddressUtils for address; // import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; // using Bytes4Utils for bytes4; -import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; - using BoolUtils for bool; +import {Inspector} from "devkit/types/Inspector.sol"; + using Inspector for bool; +import {TypeConverter} from "devkit/types/TypeConverter.sol"; + using TypeConverter for bool; import {Validate} from "devkit/validate/Validate.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; diff --git a/devkit/utils/debug/Parser.sol b/devkit/utils/debug/Parser.sol index dfdb9513..17a0714b 100644 --- a/devkit/utils/debug/Parser.sol +++ b/devkit/utils/debug/Parser.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; // Utils -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; +import {StringUtils} from "devkit/types/StringUtils.sol"; using StringUtils for string; diff --git a/devkit/utils/inspector/MappingAnalyzer.sol b/devkit/utils/inspector/MappingAnalyzer.sol index bc300c76..a9e50d05 100644 --- a/devkit/utils/inspector/MappingAnalyzer.sol +++ b/devkit/utils/inspector/MappingAnalyzer.sol @@ -10,7 +10,7 @@ import {Function} from "devkit/core/Function.sol"; import {Dictionary} from "devkit/core/Dictionary.sol"; import {Proxy} from "devkit/core/Proxy.sol"; // Utils -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; +import {StringUtils} from "devkit/types/StringUtils.sol"; using StringUtils for string; /*********************************** diff --git a/devkit/utils/primitive/BoolUtils.sol b/devkit/utils/primitive/BoolUtils.sol deleted file mode 100644 index caf1be10..00000000 --- a/devkit/utils/primitive/BoolUtils.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -/**===================\ -| ✅ Bool Utils | -\====================*/ -using BoolUtils for bool; -library BoolUtils { - /**--------------------------- - đŸ”ĸ Utils for Primitives - -----------------------------*/ - function isNot(bool flag) internal pure returns(bool) { - return !flag; - } - function isFalse(bool flag) internal pure returns(bool) { - return flag == false; - } - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - -} diff --git a/devkit/utils/primitive/Bytes4Utils.sol b/devkit/utils/primitive/Bytes4Utils.sol deleted file mode 100644 index a318baf8..00000000 --- a/devkit/utils/primitive/Bytes4Utils.sol +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Validation -import {Validate} from "devkit/validate/Validate.sol"; -// Utils -import {vm} from "devkit/utils/ForgeHelper.sol"; -import {StringUtils} from "./StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "./BoolUtils.sol"; - using BoolUtils for bool; - - -/**=====================\ -| 💾 Bytes4 Utils | -\======================*/ -using Bytes4Utils for bytes4; -library Bytes4Utils { - /**--------------------------- - đŸ”ĸ Utils for Primitives - -----------------------------*/ - - - /**----------------------- - 🔀 Type Convertor - -------------------------*/ - function toString(bytes4 selector) internal pure returns (string memory) { - return vm.toString(selector).substring(10); - } - -} diff --git a/devkit/utils/primitive/UintUtils.sol b/devkit/utils/primitive/UintUtils.sol deleted file mode 100644 index 381143cb..00000000 --- a/devkit/utils/primitive/UintUtils.sol +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; -// Utils -import {vm} from "devkit/utils/ForgeHelper.sol"; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; - using StringUtils for string; -import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; - using BoolUtils for bool; - - -/**=====================\ -| 💾 Bytes4 Utils | -\======================*/ -using UintUtils for bytes4; -library UintUtils { - /**--------------------------- - đŸ”ĸ Utils for Primitives - -----------------------------*/ - - - /**----------------------- - 🔀 Type Convertor - -------------------------*/ - - - /**------------------------------- - 🧐 Inspectors & Assertions - ---------------------------------*/ - function isNotZero(uint256 num) internal pure returns(bool) { - return num != 0; - } -} diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index 9f08eb14..72f2d12c 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -5,19 +5,21 @@ import {throwError} from "devkit/log/error/ThrowError.sol"; import {ERR} from "devkit/log/message/ERR.sol"; import {Debug, LogLevel} from "devkit/log/debug/Debug.sol"; import {Logger} from "devkit/log/debug/Logger.sol"; -import {Inspector} from "devkit/utils/inspector/Inspector.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; using Inspector for bytes4; using Inspector for address; + using Inspector for bool; + using Inspector for uint256; // Utils -import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; - using BoolUtils for bool; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; +// import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; +// using BoolUtils for bool; +import {StringUtils} from "devkit/types/StringUtils.sol"; using StringUtils for string; -import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; - using Bytes4Utils for bytes4; -import {UintUtils} from "devkit/utils/primitive/UintUtils.sol"; - using UintUtils for uint256; +// import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; +// using Bytes4Utils for bytes4; +// import {UintUtils} from "devkit/utils/primitive/UintUtils.sol"; +// using UintUtils for uint256; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 00828a21..727aad6a 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -3,11 +3,11 @@ pragma solidity ^0.8.24; import {MCDevKitTest} from "devkit/MCTest.sol"; -import {Inspector} from "devkit/utils/inspector/Inspector.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; - using StringUtils for string; +import {TypeConverter} from "devkit/types/TypeConverter.sol"; + using TypeConverter for string; import {Config} from "devkit/config/Config.sol"; import {ERR} from "devkit/log/message/ERR.sol"; diff --git a/test/utils/TestHelper.sol b/test/utils/TestHelper.sol index e00a9419..243df79a 100644 --- a/test/utils/TestHelper.sol +++ b/test/utils/TestHelper.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; - using StringUtils for string; -import {Inspector} from "devkit/utils/inspector/Inspector.sol"; +// import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; +// using StringUtils for string; +import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; using Inspector for address; From ad6748010bdb731e02fa8cd1bcdc74b0ddd9a7cb Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 17:04:01 +0900 Subject: [PATCH 095/111] Rename MappingAnalizer to mapping/NameGenerator --- devkit/registry/BundleRegistry.sol | 4 ++-- devkit/registry/DictionaryRegistry.sol | 4 ++-- devkit/registry/ProxyRegistry.sol | 4 ++-- devkit/utils/global/MCBundleLib.sol | 4 ++-- devkit/utils/global/MCDeployLib.sol | 6 +++--- .../MappingAnalyzer.sol => mapping/NameGenerator.sol} | 9 ++++----- 6 files changed, 15 insertions(+), 16 deletions(-) rename devkit/utils/{inspector/MappingAnalyzer.sol => mapping/NameGenerator.sol} (96%) diff --git a/devkit/registry/BundleRegistry.sol b/devkit/registry/BundleRegistry.sol index f74ebebd..43ff18fd 100644 --- a/devkit/registry/BundleRegistry.sol +++ b/devkit/registry/BundleRegistry.sol @@ -7,8 +7,8 @@ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for BundleRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for BundleRegistry global; -import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; - using MappingAnalyzer for mapping(string => Bundle); +import {NameGenerator} from "devkit/utils/mapping/NameGenerator.sol"; + using NameGenerator for mapping(string => Bundle); // Validation import {Validate} from "devkit/validate/Validate.sol"; diff --git a/devkit/registry/DictionaryRegistry.sol b/devkit/registry/DictionaryRegistry.sol index 3204cddb..3d650bb6 100644 --- a/devkit/registry/DictionaryRegistry.sol +++ b/devkit/registry/DictionaryRegistry.sol @@ -7,8 +7,8 @@ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for DictionaryRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for DictionaryRegistry global; -import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; - using MappingAnalyzer for mapping(string => Dictionary); +import {NameGenerator} from "devkit/utils/mapping/NameGenerator.sol"; + using NameGenerator for mapping(string => Dictionary); // Validation import {Validate} from "devkit/validate/Validate.sol"; diff --git a/devkit/registry/ProxyRegistry.sol b/devkit/registry/ProxyRegistry.sol index 6c82ac39..95f9b66f 100644 --- a/devkit/registry/ProxyRegistry.sol +++ b/devkit/registry/ProxyRegistry.sol @@ -7,8 +7,8 @@ import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; using ProcessLib for ProxyRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for ProxyRegistry global; -import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; - using MappingAnalyzer for mapping(string => Proxy); +import {NameGenerator} from "devkit/utils/mapping/NameGenerator.sol"; + using NameGenerator for mapping(string => Proxy); // Validation import {Validate} from "devkit/validate/Validate.sol"; diff --git a/devkit/utils/global/MCBundleLib.sol b/devkit/utils/global/MCBundleLib.sol index 069c93b5..54ba30e7 100644 --- a/devkit/utils/global/MCBundleLib.sol +++ b/devkit/utils/global/MCBundleLib.sol @@ -12,8 +12,8 @@ import {Params} from "devkit/log/debug/Params.sol"; import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; -import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; - using MappingAnalyzer for mapping(string => Bundle); +import {NameGenerator} from "devkit/utils/mapping/NameGenerator.sol"; + using NameGenerator for mapping(string => Bundle); /*********************************************** đŸ—‚ī¸ Bundle Configuration diff --git a/devkit/utils/global/MCDeployLib.sol b/devkit/utils/global/MCDeployLib.sol index 609db270..4534b293 100644 --- a/devkit/utils/global/MCDeployLib.sol +++ b/devkit/utils/global/MCDeployLib.sol @@ -17,9 +17,9 @@ import {StdFunctionsArgs} from "devkit/registry/StdRegistry.sol"; // proxy import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; -import {MappingAnalyzer} from "devkit/utils/inspector/MappingAnalyzer.sol"; - using MappingAnalyzer for mapping(string => Dictionary); - using MappingAnalyzer for mapping(string => Proxy); +import {NameGenerator} from "devkit/utils/mapping/NameGenerator.sol"; + using NameGenerator for mapping(string => Dictionary); + using NameGenerator for mapping(string => Proxy); /*********************************************** diff --git a/devkit/utils/inspector/MappingAnalyzer.sol b/devkit/utils/mapping/NameGenerator.sol similarity index 96% rename from devkit/utils/inspector/MappingAnalyzer.sol rename to devkit/utils/mapping/NameGenerator.sol index a9e50d05..17562e0d 100644 --- a/devkit/utils/inspector/MappingAnalyzer.sol +++ b/devkit/utils/mapping/NameGenerator.sol @@ -13,11 +13,10 @@ import {Proxy} from "devkit/core/Proxy.sol"; import {StringUtils} from "devkit/types/StringUtils.sol"; using StringUtils for string; -/*********************************** - đŸ—ēī¸ Mapping Analyzer - 🆕 Generate Unique Name -************************************/ -library MappingAnalyzer { +/**======================= + đŸ—ēī¸ Name Generator +=========================*/ +library NameGenerator { /**------------------------ đŸ—‚ī¸ Bundle Mapping From 13c6cc38c851738090c7061ad5460b78da3f3a9e Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 17:07:05 +0900 Subject: [PATCH 096/111] chore --- devkit/core/Dictionary.sol | 3 --- devkit/core/Proxy.sol | 2 +- devkit/log/debug/Debug.sol | 4 ---- devkit/log/message/WARN.sol | 1 - devkit/types/Inspector.sol | 6 ------ devkit/types/StringUtils.sol | 3 +-- devkit/types/TypeGuard.sol | 6 ------ devkit/validate/Validate.sol | 6 ------ 8 files changed, 2 insertions(+), 29 deletions(-) diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 5014d6da..77919060 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -10,9 +10,6 @@ import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Dictionary global; using Inspector for bytes4; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -// Type Util -// import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; -// using Bytes4Utils for bytes4; // Validation import {Validate} from "devkit/validate/Validate.sol"; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index 4747c0a7..7189affa 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -9,7 +9,7 @@ import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Proxy global; using Inspector for ProxyKind global; // Validation -import {Validate} from "devkit/validate/Validate.sol";// Core Type +import {Validate} from "devkit/validate/Validate.sol"; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Proxy global; diff --git a/devkit/log/debug/Debug.sol b/devkit/log/debug/Debug.sol index ecbc6007..3b3c2cf4 100644 --- a/devkit/log/debug/Debug.sol +++ b/devkit/log/debug/Debug.sol @@ -4,10 +4,6 @@ pragma solidity ^0.8.24; // Utils import {console2, StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; -// import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; -// using StringUtils for string; -// import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; -// using BoolUtils for bool; import {Logger} from "./Logger.sol"; bytes32 constant DEBUGGER = 0x03d3692c02b7cdcaf0187e8ede4101c401cc53a33aa7e03ef4682fcca8a55300; diff --git a/devkit/log/message/WARN.sol b/devkit/log/message/WARN.sol index a275dd38..d410112c 100644 --- a/devkit/log/message/WARN.sol +++ b/devkit/log/message/WARN.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.24; // Utils import {StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; -import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; /// @title Error Message library ERR { diff --git a/devkit/types/Inspector.sol b/devkit/types/Inspector.sol index dad3480c..e8340ed4 100644 --- a/devkit/types/Inspector.sol +++ b/devkit/types/Inspector.sol @@ -2,12 +2,6 @@ pragma solidity ^0.8.24; import {Validate} from "devkit/validate/Validate.sol"; -// import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; -// using StringUtils for string; -// import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; -// using BoolUtils for bool; -// import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; -// using Bytes4Utils for bytes4; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for bool; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; diff --git a/devkit/types/StringUtils.sol b/devkit/types/StringUtils.sol index 0cab26ec..0cd0f652 100644 --- a/devkit/types/StringUtils.sol +++ b/devkit/types/StringUtils.sol @@ -9,8 +9,7 @@ import {StdStyle, ForgeHelper, vm} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; import {TypeConverter} from "devkit/types//TypeConverter.sol"; using TypeConverter for bytes4; -// import {BoolUtils} from "./BoolUtils.sol"; -// using BoolUtils for bool; + /**=====================\ | 🖋 String Utils | diff --git a/devkit/types/TypeGuard.sol b/devkit/types/TypeGuard.sol index f48d96a9..7e41422f 100644 --- a/devkit/types/TypeGuard.sol +++ b/devkit/types/TypeGuard.sol @@ -1,12 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -// import {StringUtils} from "devkit/utils/primitive/StringUtils.sol"; -// using StringUtils for string; -// import {AddressUtils} from "devkit/utils/primitive/AddressUtils.sol"; -// using AddressUtils for address; -// import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; -// using Bytes4Utils for bytes4; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for bool; import {TypeConverter} from "devkit/types/TypeConverter.sol"; diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index 72f2d12c..1539de36 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -12,14 +12,8 @@ import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for bool; using Inspector for uint256; // Utils -// import {BoolUtils} from "devkit/utils/primitive/BoolUtils.sol"; -// using BoolUtils for bool; import {StringUtils} from "devkit/types/StringUtils.sol"; using StringUtils for string; -// import {Bytes4Utils} from "devkit/utils/primitive/Bytes4Utils.sol"; -// using Bytes4Utils for bytes4; -// import {UintUtils} from "devkit/utils/primitive/UintUtils.sol"; -// using UintUtils for uint256; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; From 2769756543024ff1d61e5996500da6db9939badd Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 17:19:04 +0900 Subject: [PATCH 097/111] Move debug files --- devkit/core/Bundle.sol | 4 +--- devkit/core/Dictionary.sol | 2 +- devkit/core/Function.sol | 6 ++---- devkit/core/Proxy.sol | 2 +- devkit/{utils => log}/debug/Dumper.sol | 6 +++--- devkit/{utils => log}/debug/Parser.sol | 2 +- devkit/{utils => log}/debug/ProcessLib.sol | 0 devkit/registry/BundleRegistry.sol | 2 +- devkit/registry/DictionaryRegistry.sol | 2 +- devkit/registry/FunctionRegistry.sol | 2 +- devkit/registry/ProxyRegistry.sol | 2 +- devkit/registry/StdFunctions.sol | 2 +- devkit/registry/StdRegistry.sol | 2 +- devkit/registry/context/Current.sol | 2 +- devkit/validate/Validate.sol | 3 ++- 15 files changed, 18 insertions(+), 21 deletions(-) rename devkit/{utils => log}/debug/Dumper.sol (83%) rename devkit/{utils => log}/debug/Parser.sol (94%) rename devkit/{utils => log}/debug/ProcessLib.sol (100%) diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 5bb6a9cb..40c6d7f5 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -3,10 +3,8 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; using ProcessLib for Bundle global; -import {Parser} from "devkit/utils/debug/Parser.sol"; - using Parser for Bundle global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Bundle global; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 77919060..0b6c8987 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; using ProcessLib for Dictionary global; import {Params} from "devkit/log/debug/Params.sol"; import {Inspector} from "devkit/types/Inspector.sol"; diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index 140f8f9b..0b31399a 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -3,11 +3,9 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; using ProcessLib for Function global; -import {Parser} from "devkit/utils/debug/Parser.sol"; - using Parser for Function global; -import {Dumper} from "devkit/utils/debug/Dumper.sol"; +import {Dumper} from "devkit/log/debug/Dumper.sol"; using Dumper for Function global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Function global; diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index 7189affa..108033e3 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; using ProcessLib for Proxy global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Proxy global; diff --git a/devkit/utils/debug/Dumper.sol b/devkit/log/debug/Dumper.sol similarity index 83% rename from devkit/utils/debug/Dumper.sol rename to devkit/log/debug/Dumper.sol index 87617a2a..8fa36c47 100644 --- a/devkit/utils/debug/Dumper.sol +++ b/devkit/log/debug/Dumper.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.24; import {Logger} from "devkit/log/debug/Logger.sol"; +import {Parser} from "devkit/log/debug/Parser.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; @@ -16,16 +17,15 @@ library Dumper { 🧩 Function ====================*/ function dump(Function storage func) internal returns(Function storage) { - Logger.log(func.parse()); + Logger.log(Parser.parse(func)); return func; } - /**=============== đŸ—‚ī¸ Bundle =================*/ function dump(Bundle storage bundle) internal returns(Bundle storage) { - Logger.logDebug(bundle.parse()); + Logger.log(Parser.parse(bundle)); return bundle; } diff --git a/devkit/utils/debug/Parser.sol b/devkit/log/debug/Parser.sol similarity index 94% rename from devkit/utils/debug/Parser.sol rename to devkit/log/debug/Parser.sol index 17a0714b..5f7e4522 100644 --- a/devkit/utils/debug/Parser.sol +++ b/devkit/log/debug/Parser.sol @@ -32,7 +32,7 @@ library Parser { Function[] memory _funcs = bundle.functions; for (uint i; i < _funcs.length; ++i) { - message = message.br().append(_funcs[i].parse()); + message = message.br().append(parse(_funcs[i])); } } diff --git a/devkit/utils/debug/ProcessLib.sol b/devkit/log/debug/ProcessLib.sol similarity index 100% rename from devkit/utils/debug/ProcessLib.sol rename to devkit/log/debug/ProcessLib.sol diff --git a/devkit/registry/BundleRegistry.sol b/devkit/registry/BundleRegistry.sol index 43ff18fd..5692924f 100644 --- a/devkit/registry/BundleRegistry.sol +++ b/devkit/registry/BundleRegistry.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; using ProcessLib for BundleRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for BundleRegistry global; diff --git a/devkit/registry/DictionaryRegistry.sol b/devkit/registry/DictionaryRegistry.sol index 3d650bb6..a64ad9d9 100644 --- a/devkit/registry/DictionaryRegistry.sol +++ b/devkit/registry/DictionaryRegistry.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; using ProcessLib for DictionaryRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for DictionaryRegistry global; diff --git a/devkit/registry/FunctionRegistry.sol b/devkit/registry/FunctionRegistry.sol index e79158b6..2d18ee52 100644 --- a/devkit/registry/FunctionRegistry.sol +++ b/devkit/registry/FunctionRegistry.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; using ProcessLib for FunctionRegistry global; // Validation import {Validate} from "devkit/validate/Validate.sol"; diff --git a/devkit/registry/ProxyRegistry.sol b/devkit/registry/ProxyRegistry.sol index 95f9b66f..88a8ffc2 100644 --- a/devkit/registry/ProxyRegistry.sol +++ b/devkit/registry/ProxyRegistry.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; using ProcessLib for ProxyRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for ProxyRegistry global; diff --git a/devkit/registry/StdFunctions.sol b/devkit/registry/StdFunctions.sol index 8cdd6230..211e2e67 100644 --- a/devkit/registry/StdFunctions.sol +++ b/devkit/registry/StdFunctions.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; using ProcessLib for StdFunctions global; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for StdFunctions global; diff --git a/devkit/registry/StdRegistry.sol b/devkit/registry/StdRegistry.sol index 18c00241..4fc50872 100644 --- a/devkit/registry/StdRegistry.sol +++ b/devkit/registry/StdRegistry.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; using ProcessLib for StdRegistry global; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for StdRegistry global; diff --git a/devkit/registry/context/Current.sol b/devkit/registry/context/Current.sol index 8ae816c4..94957a49 100644 --- a/devkit/registry/context/Current.sol +++ b/devkit/registry/context/Current.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; Support Methods -----------------------*/ import {Params} from "devkit/log/debug/Params.sol"; -import {ProcessLib} from "devkit/utils/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; using ProcessLib for Current global; // Validation import {Validate} from "devkit/validate/Validate.sol"; diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index 1539de36..c5e7e421 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.24; import {throwError} from "devkit/log/error/ThrowError.sol"; import {ERR} from "devkit/log/message/ERR.sol"; import {Debug, LogLevel} from "devkit/log/debug/Debug.sol"; +import {Parser} from "devkit/log/debug/Parser.sol"; import {Logger} from "devkit/log/debug/Logger.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; @@ -114,7 +115,7 @@ library Validate { validate(MUST, bundle.status.notInitialized(), "Bundle already initialized", ""); } function MUST_completed(Bundle storage bundle) internal { - validate(MUST, bundle.isComplete(), "Bundle Not Complete", bundle.parse()); + validate(MUST, bundle.isComplete(), "Bundle Not Complete", Parser.parse(bundle)); } function SHOULD_completed(Bundle storage bundle) internal { validate(SHOULD, bundle.isComplete(), "Bundle Not Complete", ""); From 19989b43c9affc1e10c45196a3d93fced206e0c7 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 17:34:32 +0900 Subject: [PATCH 098/111] Remove throwError --- devkit/MCTest.sol | 2 +- devkit/log/debug/Logger.sol | 4 ++++ devkit/log/error/ThrowError.sol | 10 ---------- devkit/log/{error => message}/DecodeErrorString.sol | 0 devkit/utils/mapping/NameGenerator.sol | 13 ++++++------- devkit/validate/Validate.sol | 9 ++++++++- 6 files changed, 19 insertions(+), 19 deletions(-) delete mode 100644 devkit/log/error/ThrowError.sol rename devkit/log/{error => message}/DecodeErrorString.sol (100%) diff --git a/devkit/MCTest.sol b/devkit/MCTest.sol index 4ca424aa..8394c854 100644 --- a/devkit/MCTest.sol +++ b/devkit/MCTest.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {Config} from "devkit/config/Config.sol"; -import {DecodeErrorString} from "devkit/log/error/DecodeErrorString.sol"; +import {DecodeErrorString} from "devkit/log/message/DecodeErrorString.sol"; // đŸ’Ŧ ABOUT // Meta Contract's default Test based on Forge Std Test diff --git a/devkit/log/debug/Logger.sol b/devkit/log/debug/Logger.sol index 713a40da..b476a011 100644 --- a/devkit/log/debug/Logger.sol +++ b/devkit/log/debug/Logger.sol @@ -46,6 +46,10 @@ library Logger { .append(parseLocations()) ); } + function logAndRevert(string memory message) internal { + logError(message); + revert(ERR.message(message)); + } // function logCritical(string memory message) internal { // console2.log(message); // } diff --git a/devkit/log/error/ThrowError.sol b/devkit/log/error/ThrowError.sol deleted file mode 100644 index 4b4a6d58..00000000 --- a/devkit/log/error/ThrowError.sol +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import {Logger} from "devkit/log/debug/Logger.sol"; -import {ERR} from "devkit/log/message/ERR.sol"; - -function throwError(string memory errorBody) { - Logger.logError(errorBody); - revert(ERR.message(errorBody)); -} diff --git a/devkit/log/error/DecodeErrorString.sol b/devkit/log/message/DecodeErrorString.sol similarity index 100% rename from devkit/log/error/DecodeErrorString.sol rename to devkit/log/message/DecodeErrorString.sol diff --git a/devkit/utils/mapping/NameGenerator.sol b/devkit/utils/mapping/NameGenerator.sol index 17562e0d..5ac8286b 100644 --- a/devkit/utils/mapping/NameGenerator.sol +++ b/devkit/utils/mapping/NameGenerator.sol @@ -1,8 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {throwError} from "devkit/log/error/ThrowError.sol"; -import {ERR} from "devkit/log/message/ERR.sol"; +import {Validate} from "devkit/validate/Validate.sol"; import {Config, ScanRange} from "devkit/config/Config.sol"; // Core Types import {Bundle} from "devkit/core/Bundle.sol"; @@ -14,7 +13,7 @@ import {StringUtils} from "devkit/types/StringUtils.sol"; using StringUtils for string; /**======================= - đŸ—ēī¸ Name Generator + đŸˇī¸ Name Generator =========================*/ library NameGenerator { @@ -27,7 +26,7 @@ library NameGenerator { name = baseName.toSequential(i); if (bundle[name].hasNotName()) return name; // TODO } - throwError(ERR.FIND_NAME_OVER_RANGE); + Validate.MUST_FoundInRange(); } function genUniqueName(mapping(string => Bundle) storage bundle) internal returns(string memory name) { return genUniqueName(bundle, Config().DEFAULT_BUNDLE_NAME); @@ -43,7 +42,7 @@ library NameGenerator { name = baseName.toSequential(i); if (func[name].notExists()) return name; } - throwError(ERR.FIND_NAME_OVER_RANGE); + Validate.MUST_FoundInRange(); } function genUniqueName(mapping(string => Function) storage func) internal returns(string memory name) { return genUniqueName(func, Config().DEFAULT_FUNCTION_NAME); @@ -59,7 +58,7 @@ library NameGenerator { name = baseName.toSequential(i); if (dictionary[name].notExists()) return name; } - throwError(ERR.FIND_NAME_OVER_RANGE); + Validate.MUST_FoundInRange(); } /*----- Dictionary -----*/ function genUniqueName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { @@ -100,7 +99,7 @@ library NameGenerator { name = baseName.toSequential(i); if (proxy[name].notExists()) return name; } - throwError(ERR.FIND_NAME_OVER_RANGE); + Validate.MUST_FoundInRange(); } /*----- Proxy -----*/ function genUniqueName(mapping(string => Proxy) storage proxy) internal returns(string memory name) { diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index c5e7e421..5c85512d 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {throwError} from "devkit/log/error/ThrowError.sol"; import {ERR} from "devkit/log/message/ERR.sol"; import {Debug, LogLevel} from "devkit/log/debug/Debug.sol"; import {Parser} from "devkit/log/debug/Parser.sol"; @@ -202,4 +201,12 @@ library Validate { function MUST_Completed(StdFunctions storage stdFunctions) internal { validate(MUST, stdFunctions.status.isComplete(), "Registry Not Complete", ""); } + + /**======================= + đŸˇī¸ Name Generator + =========================*/ + function MUST_FoundInRange() internal { + validate(MUST, false, ERR.FIND_NAME_OVER_RANGE, ""); + } + } From 1625bacb40fb9a23b608513a21e4125b8417c76a Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 17:55:27 +0900 Subject: [PATCH 099/111] update & rename debugger --- devkit/MCScript.sol | 8 ++-- devkit/config/Config.sol | 2 +- devkit/log/debug/{Debug.sol => Debugger.sol} | 22 +++++----- devkit/log/debug/Logger.sol | 14 +++---- devkit/log/debug/ProcessLib.sol | 42 ++++++++++---------- devkit/types/StringUtils.sol | 4 +- devkit/utils/global/MCDebugLib.sol | 14 ++++--- devkit/utils/global/MCSetupLib.sol | 8 +++- devkit/validate/Validate.sol | 2 +- 9 files changed, 62 insertions(+), 54 deletions(-) rename devkit/log/debug/{Debug.sol => Debugger.sol} (88%) diff --git a/devkit/MCScript.sol b/devkit/MCScript.sol index f1bf6361..3766b455 100644 --- a/devkit/MCScript.sol +++ b/devkit/MCScript.sol @@ -12,8 +12,8 @@ import {MCScriptBase} from "./MCBase.sol"; // â­ī¸ MC SCRIPT abstract contract MCScript is MCScriptBase { constructor() { - Config().load(); - if (Config().DEBUG_MODE) mc.startDebug(); + mc.loadConfig(); + mc.startDebug(); if (Config().SETUP_STD_FUNCS) mc.setupStdFunctions(); } } @@ -21,7 +21,7 @@ abstract contract MCScript is MCScriptBase { // â­ī¸ MC SCRIPT without Setup abstract contract MCScriptWithoutSetup is MCScriptBase { constructor() { - Config().load(); - if (Config().DEBUG_MODE) mc.startDebug(); + mc.loadConfig(); + mc.startDebug(); } } diff --git a/devkit/config/Config.sol b/devkit/config/Config.sol index 358bdb3e..49f92272 100644 --- a/devkit/config/Config.sol +++ b/devkit/config/Config.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -import {LogLevel} from "devkit/log/debug/Debug.sol"; +import {LogLevel} from "devkit/log/debug/Debugger.sol"; /**---------------------- diff --git a/devkit/log/debug/Debug.sol b/devkit/log/debug/Debugger.sol similarity index 88% rename from devkit/log/debug/Debug.sol rename to devkit/log/debug/Debugger.sol index 3b3c2cf4..8f69533d 100644 --- a/devkit/log/debug/Debug.sol +++ b/devkit/log/debug/Debugger.sol @@ -6,9 +6,9 @@ import {console2, StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; import {Logger} from "./Logger.sol"; -bytes32 constant DEBUGGER = 0x03d3692c02b7cdcaf0187e8ede4101c401cc53a33aa7e03ef4682fcca8a55300; + /// @custom:storage-location erc7201:mc.devkit.debugger -struct DebugState { +struct DebuggerState { LogLevel logLevel; string[] errorLocationStack; Process[] processes; @@ -28,14 +28,16 @@ struct DebugState { string params; } -//================= -// 🐞 Debug -library Debug { - /**+++++++++++++++++++++ - đŸ”ĩ Debug State - +++++++++++++++++++++++*/ - function State() internal pure returns(DebugState storage ref) { - assembly { ref.slot := DEBUGGER } + +/**=================\ +| 🐞 Debugger | +\==================*/ +library Debugger { + /**++++++++++++++++++++++++ + đŸ”ĩ Debugger State + ++++++++++++++++++++++++++*/ + function State() internal pure returns(DebuggerState storage ref) { + assembly { ref.slot := 0x03d3692c02b7cdcaf0187e8ede4101c401cc53a33aa7e03ef4682fcca8a55300 } } /**------------------------- diff --git a/devkit/log/debug/Logger.sol b/devkit/log/debug/Logger.sol index b476a011..29240b8c 100644 --- a/devkit/log/debug/Logger.sol +++ b/devkit/log/debug/Logger.sol @@ -6,7 +6,7 @@ import {ERR} from "devkit/log/message/ERR.sol"; import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/types/StringUtils.sol"; // Debug -import {Debug, Process} from "./Debug.sol"; +import {Debugger, Process} from "./Debugger.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; @@ -22,11 +22,11 @@ library Logger { đŸ’Ŧ Logging --------------------*/ function log(string memory message) internal { - if (Debug.isDebug()) logDebug(message); - if (Debug.isInfo()) logInfo(message); - if (Debug.isWarm()) logWarn(message); - if (Debug.isError()) logError(message); - // if (Debug.isCritical()) logCritical(message); + if (Debugger.isDebug()) logDebug(message); + if (Debugger.isInfo()) logInfo(message); + if (Debugger.isWarm()) logWarn(message); + if (Debugger.isError()) logError(message); + // if (Debugger.isCritical()) logCritical(message); } function logDebug(string memory message) internal { @@ -89,7 +89,7 @@ library Logger { 📑 Parser -----------------*/ function parseLocations() internal returns(string memory locations) { - Process[] memory processes = Debug.State().processes; + Process[] memory processes = Debugger.State().processes; for (uint i = processes.length; i > 0; --i) { locations = locations.append(formatLocation(processes[i-1])); } diff --git a/devkit/log/debug/ProcessLib.sol b/devkit/log/debug/ProcessLib.sol index 9f90aeec..72ffb007 100644 --- a/devkit/log/debug/ProcessLib.sol +++ b/devkit/log/debug/ProcessLib.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Debug} from "devkit/log/debug/Debug.sol"; +import {Debugger} from "devkit/log/debug/Debugger.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {FunctionRegistry} from "devkit/registry/FunctionRegistry.sol"; @@ -21,7 +21,7 @@ import {Current} from "devkit/registry/context/Current.sol"; ===================*/ library ProcessLib { function finishProcess(uint pid) internal { - Debug.recordExecFinish(pid); + Debugger.recordExecFinish(pid); } @@ -29,14 +29,14 @@ library ProcessLib { 🧩 Function --------------------*/ function startProcess(Function storage, string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("FunctionLib", name, params); + return Debugger.recordExecStart("FunctionLib", name, params); } function startProcess(Function storage func, string memory name) internal returns(uint) { return func.startProcess(name, ""); } function finishProcess(Function storage func, uint pid) internal returns(Function storage) { - Debug.recordExecFinish(pid); + Debugger.recordExecFinish(pid); return func; } @@ -44,14 +44,14 @@ library ProcessLib { 🧩 Functions Registry ----------------------------*/ function startProcess(FunctionRegistry storage, string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("FunctionRegistry", name, params); + return Debugger.recordExecStart("FunctionRegistry", name, params); } function startProcess(FunctionRegistry storage functions, string memory name) internal returns(uint) { return functions.startProcess(name, ""); } function finishProcess(FunctionRegistry storage functions, uint pid) internal returns(FunctionRegistry storage) { - Debug.recordExecFinish(pid); + Debugger.recordExecFinish(pid); return functions; } @@ -60,14 +60,14 @@ library ProcessLib { đŸ—‚ī¸ Bundle ------------------*/ function startProcess(Bundle storage, string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("Bundle", name, params); + return Debugger.recordExecStart("Bundle", name, params); } function startProcess(Bundle storage bundle, string memory name) internal returns(uint) { return bundle.startProcess(name, ""); } function finishProcess(Bundle storage bundle, uint pid) internal returns(Bundle storage) { - Debug.recordExecFinish(pid); + Debugger.recordExecFinish(pid); return bundle; } @@ -75,14 +75,14 @@ library ProcessLib { 🧩 Bundle Registry ----------------------------*/ function startProcess(BundleRegistry storage, string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("BundleRegistry", name, params); + return Debugger.recordExecStart("BundleRegistry", name, params); } function startProcess(BundleRegistry storage bundle, string memory name) internal returns(uint) { return bundle.startProcess(name, ""); } function finishProcess(BundleRegistry storage bundle, uint pid) internal returns(BundleRegistry storage) { - Debug.recordExecFinish(pid); + Debugger.recordExecFinish(pid); return bundle; } @@ -91,14 +91,14 @@ library ProcessLib { 🏛 Standard Registry ---------------------------*/ function startProcess(StdRegistry storage, string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("StdRegistryLib", name, params); + return Debugger.recordExecStart("StdRegistryLib", name, params); } function startProcess(StdRegistry storage std, string memory name) internal returns(uint) { return std.startProcess(name, ""); } function finishProcess(StdRegistry storage std, uint pid) internal returns(StdRegistry storage) { - Debug.recordExecFinish(pid); + Debugger.recordExecFinish(pid); return std; } @@ -107,14 +107,14 @@ library ProcessLib { 🏰 Standard Functions ----------------------------*/ function startProcess(StdFunctions storage, string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("StdFunctionsLib", name, params); + return Debugger.recordExecStart("StdFunctionsLib", name, params); } function startProcess(StdFunctions storage std, string memory name) internal returns(uint) { return std.startProcess(name, ""); } function finishProcess(StdFunctions storage std, uint pid) internal returns(StdFunctions storage) { - Debug.recordExecFinish(pid); + Debugger.recordExecFinish(pid); return std; } @@ -123,7 +123,7 @@ library ProcessLib { 🏠 Proxy -----------------*/ function startProxyLibProcess(string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("ProxyLib", name, params); + return Debugger.recordExecStart("ProxyLib", name, params); } function startProxyLibProcess(string memory name) internal returns(uint) { return startProxyLibProcess(name, ""); @@ -142,14 +142,14 @@ library ProcessLib { 🏠 Proxy Registry ------------------------*/ function startProcess(ProxyRegistry storage, string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("ProxyRegistryLib", name, params); + return Debugger.recordExecStart("ProxyRegistryLib", name, params); } function startProcess(ProxyRegistry storage proxies, string memory name) internal returns(uint) { return proxies.startProcess(name, ""); } function finishProcess(ProxyRegistry storage proxies, uint pid) internal returns(ProxyRegistry storage) { - Debug.recordExecFinish(pid); + Debugger.recordExecFinish(pid); return proxies; } @@ -158,7 +158,7 @@ library ProcessLib { 📚 Dictionary ---------------------*/ function startDictionaryLibProcess(string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("DictionaryLib", name, params); + return Debugger.recordExecStart("DictionaryLib", name, params); } function startDictionaryLibProcess(string memory name) internal returns(uint) { return startDictionaryLibProcess(name, ""); @@ -177,14 +177,14 @@ library ProcessLib { 📚 Dictionary Registry ------------------------------*/ function startProcess(DictionaryRegistry storage, string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("DictionaryRegistryLib", name, params); + return Debugger.recordExecStart("DictionaryRegistryLib", name, params); } function startProcess(DictionaryRegistry storage dictionaries, string memory name) internal returns(uint) { return dictionaries.startProcess(name, ""); } function finishProcess(DictionaryRegistry storage dictionaries, uint pid) internal returns(DictionaryRegistry storage) { - Debug.recordExecFinish(pid); + Debugger.recordExecFinish(pid); return dictionaries; } @@ -193,7 +193,7 @@ library ProcessLib { 📸 Current Context --------------------------*/ function startProcess(Current storage, string memory name, string memory params) internal returns(uint) { - return Debug.recordExecStart("CurrentLib", name, params); + return Debugger.recordExecStart("CurrentLib", name, params); } function startProcess(Current storage current, string memory name) internal returns(uint) { return current.startProcess(name, ""); diff --git a/devkit/types/StringUtils.sol b/devkit/types/StringUtils.sol index 0cd0f652..2f02e091 100644 --- a/devkit/types/StringUtils.sol +++ b/devkit/types/StringUtils.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; // Validation import {Validate} from "devkit/validate/Validate.sol"; -import {Debug} from "devkit/log/debug/Debug.sol"; +import {Debugger} from "devkit/log/debug/Debugger.sol"; // Utils import {StdStyle, ForgeHelper, vm} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; @@ -96,7 +96,7 @@ library StringUtils { Record Finish */ function recordExecFinish(string memory str, uint pid) internal returns(string memory) { - Debug.recordExecFinish(pid); + Debugger.recordExecFinish(pid); return str; } diff --git a/devkit/utils/global/MCDebugLib.sol b/devkit/utils/global/MCDebugLib.sol index 82271a02..ac5f2957 100644 --- a/devkit/utils/global/MCDebugLib.sol +++ b/devkit/utils/global/MCDebugLib.sol @@ -2,8 +2,9 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; +import {Config} from "devkit/config/Config.sol"; // Debug -import {Debug} from "devkit/log/debug/Debug.sol"; +import {Debugger} from "devkit/log/debug/Debugger.sol"; import {Logger} from "devkit/log/debug/Logger.sol"; @@ -22,8 +23,9 @@ library MCDebugLib { â–ļī¸ Start -----------------*/ function startDebug(MCDevKit storage mc) internal returns(MCDevKit storage) { - Debug.startDebug(); - return mc; + uint pid = mc.recordExecStart("startDebug"); + if (Config().DEBUG_MODE) Debugger.startDebug(); + return mc.recordExecFinish(pid); } @@ -31,7 +33,7 @@ library MCDebugLib { 🛑 Stop ---------------*/ function stopLog(MCDevKit storage mc) internal returns(MCDevKit storage) { - Debug.stopLog(); + Debugger.stopLog(); return mc; } @@ -49,7 +51,7 @@ library MCDebugLib { đŸ”Ŋ Record Start ----------------------*/ function recordExecStart(MCDevKit storage mc, string memory funcName, string memory params) internal returns(uint) { - return Debug.recordExecStart(LIB_NAME, funcName, params); + return Debugger.recordExecStart(LIB_NAME, funcName, params); } function recordExecStart(MCDevKit storage mc, string memory funcName) internal returns(uint) { return mc.recordExecStart(funcName, ""); @@ -60,7 +62,7 @@ library MCDebugLib { đŸ”ŧ Record Finish -----------------------*/ function recordExecFinish(MCDevKit storage mc, uint pid) internal returns(MCDevKit storage) { - Debug.recordExecFinish(pid); + Debugger.recordExecFinish(pid); return mc; } diff --git a/devkit/utils/global/MCSetupLib.sol b/devkit/utils/global/MCSetupLib.sol index 04689835..a99b91b0 100644 --- a/devkit/utils/global/MCSetupLib.sol +++ b/devkit/utils/global/MCSetupLib.sol @@ -2,14 +2,18 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; +import {Config} from "devkit/config/Config.sol"; /********************************** 🏗 Setup 🧩 Setup Standard Funcs ***********************************/ library MCSetupLib { - string constant LIB_NAME = "MCSetupLib"; - + function loadConfig(MCDevKit storage mc) internal returns(MCDevKit storage) { + uint pid = mc.recordExecStart("loadConfig"); + Config().load(); + return mc.recordExecFinish(pid); + } /**---------------------------- 🧩 Setup Standard Funcs diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index 5c85512d..87a96177 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {ERR} from "devkit/log/message/ERR.sol"; -import {Debug, LogLevel} from "devkit/log/debug/Debug.sol"; +import {Debugger, LogLevel} from "devkit/log/debug/Debugger.sol"; import {Parser} from "devkit/log/debug/Parser.sol"; import {Logger} from "devkit/log/debug/Logger.sol"; import {Inspector} from "devkit/types/Inspector.sol"; From b64a7f2aa81aa93170761c2c90c8403e94bf0957 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Fri, 12 Apr 2024 18:13:34 +0900 Subject: [PATCH 100/111] add config option "RECORD_EXECUTION_PROCESS" --- devkit/config/Config.sol | 2 ++ devkit/log/debug/Debugger.sol | 7 +++++-- devkit/log/debug/Logger.sol | 5 ----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/devkit/config/Config.sol b/devkit/config/Config.sol index 49f92272..41608892 100644 --- a/devkit/config/Config.sol +++ b/devkit/config/Config.sol @@ -13,6 +13,7 @@ using ConfigLib for Configuration global; struct Configuration { bool DEBUG_MODE; LogLevel DEFAULT_LOG_LEVEL; + bool RECORD_EXECUTION_PROCESS; bool SETUP_STD_FUNCS; @@ -39,6 +40,7 @@ library ConfigLib { function load(Configuration storage config) internal { config.DEBUG_MODE = true; config.DEFAULT_LOG_LEVEL = LogLevel.Warn; + config.RECORD_EXECUTION_PROCESS = true; config.SETUP_STD_FUNCS = true; diff --git a/devkit/log/debug/Debugger.sol b/devkit/log/debug/Debugger.sol index 8f69533d..509e4b1b 100644 --- a/devkit/log/debug/Debugger.sol +++ b/devkit/log/debug/Debugger.sol @@ -5,6 +5,9 @@ pragma solidity ^0.8.24; import {console2, StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; import {Logger} from "./Logger.sol"; +import {Config} from "devkit/config/Config.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; + using Inspector for bool; /// @custom:storage-location erc7201:mc.devkit.debugger @@ -89,7 +92,7 @@ library Debugger { 📈 Execution Tracking ------------------------------*/ function recordExecStart(string memory libName, string memory funcName, string memory params) internal returns(uint pid) { - if (isDisabled()) return 0; + if (Config().RECORD_EXECUTION_PROCESS.isFalse()) return 0; pid = State().nextPid; State().processes.push(Process(libName, funcName, params)); Logger.logExecStart(pid, libName, funcName); @@ -97,7 +100,7 @@ library Debugger { } function recordExecFinish(uint pid) internal { - if (isDisabled()) return; + if (Config().RECORD_EXECUTION_PROCESS.isFalse()) return; Process memory current = State().processes[pid]; Logger.logExecFinish(pid, current.libName, current.funcName); } diff --git a/devkit/log/debug/Logger.sol b/devkit/log/debug/Logger.sol index 29240b8c..14526872 100644 --- a/devkit/log/debug/Logger.sol +++ b/devkit/log/debug/Logger.sol @@ -38,7 +38,6 @@ library Logger { function logWarn(string memory message) internal { console2.log(message); } - function logError(string memory body) internal { console2.log( ERR.HEADER.red().br() @@ -46,10 +45,6 @@ library Logger { .append(parseLocations()) ); } - function logAndRevert(string memory message) internal { - logError(message); - revert(ERR.message(message)); - } // function logCritical(string memory message) internal { // console2.log(message); // } From 460a71c146bec74441a5b9c19a3009fb45010c18 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 15 Apr 2024 07:31:32 +0900 Subject: [PATCH 101/111] Update Debugger & Logger, Messages --- devkit/log/debug/Debugger.sol | 12 ++++++------ devkit/log/debug/Logger.sol | 20 +++++++++++++------ devkit/log/message/CRITICAL.sol | 16 ++++++++++++++++ devkit/log/message/DEBUG.sol | 34 +++++++++++++++++++++++++++++++++ devkit/log/message/INFO.sol | 34 +++++++++++++++++++++++++++++++++ devkit/log/message/WARN.sol | 3 ++- devkit/validate/Validate.sol | 2 +- 7 files changed, 107 insertions(+), 14 deletions(-) create mode 100644 devkit/log/message/CRITICAL.sol create mode 100644 devkit/log/message/DEBUG.sol create mode 100644 devkit/log/message/INFO.sol diff --git a/devkit/log/debug/Debugger.sol b/devkit/log/debug/Debugger.sol index 509e4b1b..7b8d0510 100644 --- a/devkit/log/debug/Debugger.sol +++ b/devkit/log/debug/Debugger.sol @@ -58,9 +58,9 @@ library Debugger { function startError() internal { setLogLevel(LogLevel.Error); } - // function startCritical() internal { - // setLogLevel(LogLevel.Critical); - // } + function startCritical() internal { + setLogLevel(LogLevel.Critical); + } function stopLog() internal { setLogLevel(LogLevel.Disable); } @@ -83,9 +83,9 @@ library Debugger { function isError() internal returns(bool) { return State().logLevel == LogLevel.Error; } - // function isCritical() internal returns(bool) { - // return State().logLevel == LogLevel.Critical; - // } + function isCritical() internal returns(bool) { + return State().logLevel == LogLevel.Critical; + } /**---------------------------- diff --git a/devkit/log/debug/Logger.sol b/devkit/log/debug/Logger.sol index 14526872..79d190a4 100644 --- a/devkit/log/debug/Logger.sol +++ b/devkit/log/debug/Logger.sol @@ -1,7 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; +import {DEBUG} from "devkit/log/message/DEBUG.sol"; +import {INFO} from "devkit/log/message/INFO.sol"; +import {WARN} from "devkit/log/message/WARN.sol"; import {ERR} from "devkit/log/message/ERR.sol"; +import {CRITICAL} from "devkit/log/message/CRITICAL.sol"; // Utils import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/types/StringUtils.sol"; @@ -26,7 +30,7 @@ library Logger { if (Debugger.isInfo()) logInfo(message); if (Debugger.isWarm()) logWarn(message); if (Debugger.isError()) logError(message); - // if (Debugger.isCritical()) logCritical(message); + if (Debugger.isCritical()) logCritical(message); } function logDebug(string memory message) internal { @@ -38,16 +42,20 @@ library Logger { function logWarn(string memory message) internal { console2.log(message); } - function logError(string memory body) internal { + function logError(string memory message) internal { + console2.log(message); + } + function logCritical(string memory message) internal { + console2.log(CRITICAL.header(message)); + } + + function logException(string memory message) internal { console2.log( ERR.HEADER.red().br() - .indent().append(body) + .indent().append(message) .append(parseLocations()) ); } - // function logCritical(string memory message) internal { - // console2.log(message); - // } /**----------------------- diff --git a/devkit/log/message/CRITICAL.sol b/devkit/log/message/CRITICAL.sol new file mode 100644 index 00000000..2e2322a7 --- /dev/null +++ b/devkit/log/message/CRITICAL.sol @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Utils +import {StdStyle} from "devkit/utils/ForgeHelper.sol"; + using StdStyle for string; +import {StringUtils} from "devkit/types/StringUtils.sol"; + +/// @title Error Message +library CRITICAL { + string constant HEADER = "\xF0\x9F\x9A\xA8 [CRITICAL] "; + + function header(string memory body) internal returns(string memory) { + return StringUtils.append(HEADER.red(), body).bold(); + } +} diff --git a/devkit/log/message/DEBUG.sol b/devkit/log/message/DEBUG.sol new file mode 100644 index 00000000..9dcfd913 --- /dev/null +++ b/devkit/log/message/DEBUG.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Utils +import {StdStyle} from "devkit/utils/ForgeHelper.sol"; + using StdStyle for string; +import {StringUtils} from "devkit/types/StringUtils.sol"; + +/// @title Error Message +library DEBUG { + string constant HEADER = "\u2716 DevKit Error: "; + string constant FIND_NAME_OVER_RANGE = "Default names are automatically set up to 5. Please manually assign names beyond that."; + string constant EMPTY_STR = "Empty String"; + string constant EMPTY_B4 = "Empty Bytes4"; + string constant NOT_CONTRACT = "Not Contract Address"; + string constant STR_ALREADY_ASSIGNED = "String Already Assigned"; + string constant B4_ALREADY_ASSIGNED = "Bytes4 Already Assigned"; + string constant ZERO_ADDRESS = "Zero Address"; + + // Require + string constant RQ_SELECTOR = "Selector is required."; + string constant RQ_CONTRACT = "Contract is required."; + string constant RQ_NOT_EMPTY_STRING = "String is empty."; + string constant DICTIONARY_NOT_EXISTS = "Dictionary Not Exists"; + string constant EMPTY_DICTIONARY = "Empty Dictionary"; + string constant LOCKED_OBJECT = "Locaked Object"; + + // string constant STR_EXISTS = "String Already Exist"; + string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; + + function message(string memory errorBody) internal returns(string memory) { + return StringUtils.append(HEADER, errorBody).bold(); + } +} diff --git a/devkit/log/message/INFO.sol b/devkit/log/message/INFO.sol new file mode 100644 index 00000000..4439d995 --- /dev/null +++ b/devkit/log/message/INFO.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Utils +import {StdStyle} from "devkit/utils/ForgeHelper.sol"; + using StdStyle for string; +import {StringUtils} from "devkit/types/StringUtils.sol"; + +/// @title Error Message +library INFO { + string constant HEADER = "\u2716 DevKit Error: "; + string constant FIND_NAME_OVER_RANGE = "Default names are automatically set up to 5. Please manually assign names beyond that."; + string constant EMPTY_STR = "Empty String"; + string constant EMPTY_B4 = "Empty Bytes4"; + string constant NOT_CONTRACT = "Not Contract Address"; + string constant STR_ALREADY_ASSIGNED = "String Already Assigned"; + string constant B4_ALREADY_ASSIGNED = "Bytes4 Already Assigned"; + string constant ZERO_ADDRESS = "Zero Address"; + + // Require + string constant RQ_SELECTOR = "Selector is required."; + string constant RQ_CONTRACT = "Contract is required."; + string constant RQ_NOT_EMPTY_STRING = "String is empty."; + string constant DICTIONARY_NOT_EXISTS = "Dictionary Not Exists"; + string constant EMPTY_DICTIONARY = "Empty Dictionary"; + string constant LOCKED_OBJECT = "Locaked Object"; + + // string constant STR_EXISTS = "String Already Exist"; + string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; + + function message(string memory errorBody) internal returns(string memory) { + return StringUtils.append(HEADER, errorBody).bold(); + } +} diff --git a/devkit/log/message/WARN.sol b/devkit/log/message/WARN.sol index d410112c..c5c22685 100644 --- a/devkit/log/message/WARN.sol +++ b/devkit/log/message/WARN.sol @@ -4,9 +4,10 @@ pragma solidity ^0.8.24; // Utils import {StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; +import {StringUtils} from "devkit/types/StringUtils.sol"; /// @title Error Message -library ERR { +library WARN { string constant HEADER = "\u2716 DevKit Error: "; string constant FIND_NAME_OVER_RANGE = "Default names are automatically set up to 5. Please manually assign names beyond that."; string constant EMPTY_STR = "Empty String"; diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index 87a96177..4ea430c7 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -38,7 +38,7 @@ library Validate { function validate(Type T, bool condition, string memory messageBody, string memory messageDetail) internal { if (condition) return; - Logger.log(messageBody.append(messageDetail)); + Logger.logException(messageBody.append(messageDetail)); if (T == MUST) revert(ERR.message(messageBody)); // TODO } From b9a1875b9dd435c615050af2013b8029ed2897f5 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 15 Apr 2024 08:35:04 +0900 Subject: [PATCH 102/111] Verifiable Check without Broadcast --- devkit/core/Dictionary.sol | 2 +- devkit/validate/Validate.sol | 7 ++++++- script/DeployLib.sol | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 0b6c8987..083911a4 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -123,7 +123,7 @@ library DictionaryLib { function upgradeFacade(Dictionary memory dictionary, address newFacade) internal returns(Dictionary memory) { uint pid = ProcessLib.startDictionaryLibProcess("upgradeFacade"); Validate.MUST_AddressIsContract(newFacade); - // Validate.verifiable(dictionary); TODO without CALL + Validate.MUST_Verifiable(dictionary); DictionaryEtherscan(dictionary.addr).upgradeFacade(newFacade); return dictionary.finishProcess(pid); } diff --git a/devkit/validate/Validate.sol b/devkit/validate/Validate.sol index 4ea430c7..58fca50c 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/validate/Validate.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; - +import {vm, ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {ERR} from "devkit/log/message/ERR.sol"; import {Debugger, LogLevel} from "devkit/log/debug/Debugger.sol"; import {Parser} from "devkit/log/debug/Parser.sol"; @@ -179,6 +179,11 @@ library Validate { function MUST_completed(Dictionary storage dictionary) internal { validate(MUST, dictionary.isComplete(), "Dictionary Not Complete", ""); } + function MUST_Verifiable(Dictionary memory dictionary) internal { + vm.stopBroadcast(); + validate(MUST, dictionary.isVerifiable(), "Dictionary Is Not Verifiable", ""); + vm.startBroadcast(ForgeHelper.getPrivateKey("DEPLOYER_PRIV_KEY")); // Without CALL TODO + } /**============================ 📘 Dictionary Registry ==============================*/ diff --git a/script/DeployLib.sol b/script/DeployLib.sol index 6f8e340a..0434b2e6 100755 --- a/script/DeployLib.sol +++ b/script/DeployLib.sol @@ -13,7 +13,7 @@ library DeployLib { } function deployStdDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { - mc.deployStdFunctions(); + mc.std.complete(); mc.deployDictionary(mc.std.all); return mc; } From ea348b302ff2dfd8d39884de7cb0d7d1a50983a1 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 15 Apr 2024 08:47:22 +0900 Subject: [PATCH 103/111] Create devkit/system --- devkit/MCScript.sol | 2 +- devkit/MCTest.sol | 4 ++-- devkit/core/Bundle.sol | 4 ++-- devkit/core/Dictionary.sol | 6 +++--- devkit/core/Function.sol | 6 +++--- devkit/core/Proxy.sol | 4 ++-- devkit/registry/BundleRegistry.sol | 4 ++-- devkit/registry/DictionaryRegistry.sol | 4 ++-- devkit/registry/FunctionRegistry.sol | 4 ++-- devkit/registry/ProxyRegistry.sol | 4 ++-- devkit/registry/StdFunctions.sol | 4 ++-- devkit/registry/StdRegistry.sol | 4 ++-- devkit/registry/context/Current.sol | 6 +++--- devkit/{config => system}/Config.sol | 2 +- devkit/{log => system}/debug/Debugger.sol | 2 +- devkit/{log => system}/debug/Dumper.sol | 4 ++-- devkit/{log => system}/debug/Logger.sol | 10 +++++----- devkit/{log => system}/debug/Params.sol | 0 devkit/{log => system}/debug/Parser.sol | 0 devkit/{log => system}/debug/ProcessLib.sol | 2 +- devkit/{log => system}/message/CRITICAL.sol | 0 devkit/{log => system}/message/DEBUG.sol | 0 devkit/{log => system}/message/DecodeErrorString.sol | 0 devkit/{log => system}/message/ERR.sol | 0 devkit/{log => system}/message/INFO.sol | 0 devkit/{log => system}/message/WARN.sol | 0 devkit/{ => system}/validate/Validate.sol | 8 ++++---- devkit/types/Inspector.sol | 2 +- devkit/types/StringUtils.sol | 4 ++-- devkit/types/TypeGuard.sol | 2 +- devkit/utils/global/MCBundleLib.sol | 6 +++--- devkit/utils/global/MCDebugLib.sol | 6 +++--- devkit/utils/global/MCDeployLib.sol | 6 +++--- devkit/utils/global/MCSetupLib.sol | 2 +- devkit/utils/global/MCTestLib.sol | 6 +++--- devkit/utils/mapping/NameGenerator.sol | 4 ++-- test/devkit/global/MCBundle.t.sol | 4 ++-- 37 files changed, 63 insertions(+), 63 deletions(-) rename devkit/{config => system}/Config.sol (98%) rename devkit/{log => system}/debug/Debugger.sol (98%) rename devkit/{log => system}/debug/Dumper.sol (86%) rename devkit/{log => system}/debug/Logger.sol (93%) rename devkit/{log => system}/debug/Params.sol (100%) rename devkit/{log => system}/debug/Parser.sol (100%) rename devkit/{log => system}/debug/ProcessLib.sol (99%) rename devkit/{log => system}/message/CRITICAL.sol (100%) rename devkit/{log => system}/message/DEBUG.sol (100%) rename devkit/{log => system}/message/DecodeErrorString.sol (100%) rename devkit/{log => system}/message/ERR.sol (100%) rename devkit/{log => system}/message/INFO.sol (100%) rename devkit/{log => system}/message/WARN.sol (100%) rename devkit/{ => system}/validate/Validate.sol (97%) diff --git a/devkit/MCScript.sol b/devkit/MCScript.sol index 3766b455..2bfe6d11 100644 --- a/devkit/MCScript.sol +++ b/devkit/MCScript.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Config} from "devkit/config/Config.sol"; +import {Config} from "devkit/system/Config.sol"; // đŸ’Ŧ ABOUT // Meta Contract's default Script based on Forge Std Script diff --git a/devkit/MCTest.sol b/devkit/MCTest.sol index 8394c854..7ebf307b 100644 --- a/devkit/MCTest.sol +++ b/devkit/MCTest.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Config} from "devkit/config/Config.sol"; -import {DecodeErrorString} from "devkit/log/message/DecodeErrorString.sol"; +import {Config} from "devkit/system/Config.sol"; +import {DecodeErrorString} from "devkit/system/message/DecodeErrorString.sol"; // đŸ’Ŧ ABOUT // Meta Contract's default Test based on Forge Std Test diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index 40c6d7f5..c7bf2df2 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -3,14 +3,14 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; using ProcessLib for Bundle global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Bundle global; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Bundle global; // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; // Core Type import {Function} from "devkit/core/Function.sol"; diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 083911a4..860fd0d5 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -3,15 +3,15 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; using ProcessLib for Dictionary global; -import {Params} from "devkit/log/debug/Params.sol"; +import {Params} from "devkit/system/debug/Params.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Dictionary global; using Inspector for bytes4; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Dictionary global; diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index 0b31399a..574666f3 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -3,14 +3,14 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; using ProcessLib for Function global; -import {Dumper} from "devkit/log/debug/Dumper.sol"; +import {Dumper} from "devkit/system/debug/Dumper.sol"; using Dumper for Function global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Function global; // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Function global; // Loader diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index 108033e3..902d58a9 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -3,13 +3,13 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; using ProcessLib for Proxy global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Proxy global; using Inspector for ProxyKind global; // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Proxy global; diff --git a/devkit/registry/BundleRegistry.sol b/devkit/registry/BundleRegistry.sol index 5692924f..11752f8d 100644 --- a/devkit/registry/BundleRegistry.sol +++ b/devkit/registry/BundleRegistry.sol @@ -3,14 +3,14 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; using ProcessLib for BundleRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for BundleRegistry global; import {NameGenerator} from "devkit/utils/mapping/NameGenerator.sol"; using NameGenerator for mapping(string => Bundle); // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; // Core Type import {Bundle} from "devkit/core/Bundle.sol"; diff --git a/devkit/registry/DictionaryRegistry.sol b/devkit/registry/DictionaryRegistry.sol index a64ad9d9..72ce9fba 100644 --- a/devkit/registry/DictionaryRegistry.sol +++ b/devkit/registry/DictionaryRegistry.sol @@ -3,14 +3,14 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; using ProcessLib for DictionaryRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for DictionaryRegistry global; import {NameGenerator} from "devkit/utils/mapping/NameGenerator.sol"; using NameGenerator for mapping(string => Dictionary); // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; // Core Type import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; diff --git a/devkit/registry/FunctionRegistry.sol b/devkit/registry/FunctionRegistry.sol index 2d18ee52..6778fc10 100644 --- a/devkit/registry/FunctionRegistry.sol +++ b/devkit/registry/FunctionRegistry.sol @@ -3,10 +3,10 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; using ProcessLib for FunctionRegistry global; // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; // Context import {Current} from "devkit/registry/context/Current.sol"; diff --git a/devkit/registry/ProxyRegistry.sol b/devkit/registry/ProxyRegistry.sol index 88a8ffc2..451d481f 100644 --- a/devkit/registry/ProxyRegistry.sol +++ b/devkit/registry/ProxyRegistry.sol @@ -3,14 +3,14 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; using ProcessLib for ProxyRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for ProxyRegistry global; import {NameGenerator} from "devkit/utils/mapping/NameGenerator.sol"; using NameGenerator for mapping(string => Proxy); // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; // Core Type import {Proxy, ProxyLib} from "devkit/core/Proxy.sol"; diff --git a/devkit/registry/StdFunctions.sol b/devkit/registry/StdFunctions.sol index 211e2e67..7c3b548a 100644 --- a/devkit/registry/StdFunctions.sol +++ b/devkit/registry/StdFunctions.sol @@ -3,11 +3,11 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; using ProcessLib for StdFunctions global; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for StdFunctions global; -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; diff --git a/devkit/registry/StdRegistry.sol b/devkit/registry/StdRegistry.sol index 4fc50872..5674e1c9 100644 --- a/devkit/registry/StdRegistry.sol +++ b/devkit/registry/StdRegistry.sol @@ -3,12 +3,12 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; using ProcessLib for StdRegistry global; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for StdRegistry global; // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; diff --git a/devkit/registry/context/Current.sol b/devkit/registry/context/Current.sol index 94957a49..93e685c1 100644 --- a/devkit/registry/context/Current.sol +++ b/devkit/registry/context/Current.sol @@ -3,11 +3,11 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {Params} from "devkit/log/debug/Params.sol"; -import {ProcessLib} from "devkit/log/debug/ProcessLib.sol"; +import {Params} from "devkit/system/debug/Params.sol"; +import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; using ProcessLib for Current global; // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; /**======================== diff --git a/devkit/config/Config.sol b/devkit/system/Config.sol similarity index 98% rename from devkit/config/Config.sol rename to devkit/system/Config.sol index 41608892..dd349b7c 100644 --- a/devkit/config/Config.sol +++ b/devkit/system/Config.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -import {LogLevel} from "devkit/log/debug/Debugger.sol"; +import {LogLevel} from "devkit/system/debug/Debugger.sol"; /**---------------------- diff --git a/devkit/log/debug/Debugger.sol b/devkit/system/debug/Debugger.sol similarity index 98% rename from devkit/log/debug/Debugger.sol rename to devkit/system/debug/Debugger.sol index 7b8d0510..102e44bd 100644 --- a/devkit/log/debug/Debugger.sol +++ b/devkit/system/debug/Debugger.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; import {console2, StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; import {Logger} from "./Logger.sol"; -import {Config} from "devkit/config/Config.sol"; +import {Config} from "devkit/system/Config.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for bool; diff --git a/devkit/log/debug/Dumper.sol b/devkit/system/debug/Dumper.sol similarity index 86% rename from devkit/log/debug/Dumper.sol rename to devkit/system/debug/Dumper.sol index 8fa36c47..69018bf2 100644 --- a/devkit/log/debug/Dumper.sol +++ b/devkit/system/debug/Dumper.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Logger} from "devkit/log/debug/Logger.sol"; -import {Parser} from "devkit/log/debug/Parser.sol"; +import {Logger} from "devkit/system/debug/Logger.sol"; +import {Parser} from "devkit/system/debug/Parser.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; diff --git a/devkit/log/debug/Logger.sol b/devkit/system/debug/Logger.sol similarity index 93% rename from devkit/log/debug/Logger.sol rename to devkit/system/debug/Logger.sol index 79d190a4..45e798d8 100644 --- a/devkit/log/debug/Logger.sol +++ b/devkit/system/debug/Logger.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {DEBUG} from "devkit/log/message/DEBUG.sol"; -import {INFO} from "devkit/log/message/INFO.sol"; -import {WARN} from "devkit/log/message/WARN.sol"; -import {ERR} from "devkit/log/message/ERR.sol"; -import {CRITICAL} from "devkit/log/message/CRITICAL.sol"; +import {DEBUG} from "devkit/system/message/DEBUG.sol"; +import {INFO} from "devkit/system/message/INFO.sol"; +import {WARN} from "devkit/system/message/WARN.sol"; +import {ERR} from "devkit/system/message/ERR.sol"; +import {CRITICAL} from "devkit/system/message/CRITICAL.sol"; // Utils import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/types/StringUtils.sol"; diff --git a/devkit/log/debug/Params.sol b/devkit/system/debug/Params.sol similarity index 100% rename from devkit/log/debug/Params.sol rename to devkit/system/debug/Params.sol diff --git a/devkit/log/debug/Parser.sol b/devkit/system/debug/Parser.sol similarity index 100% rename from devkit/log/debug/Parser.sol rename to devkit/system/debug/Parser.sol diff --git a/devkit/log/debug/ProcessLib.sol b/devkit/system/debug/ProcessLib.sol similarity index 99% rename from devkit/log/debug/ProcessLib.sol rename to devkit/system/debug/ProcessLib.sol index 72ffb007..5c410613 100644 --- a/devkit/log/debug/ProcessLib.sol +++ b/devkit/system/debug/ProcessLib.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Debugger} from "devkit/log/debug/Debugger.sol"; +import {Debugger} from "devkit/system/debug/Debugger.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {FunctionRegistry} from "devkit/registry/FunctionRegistry.sol"; diff --git a/devkit/log/message/CRITICAL.sol b/devkit/system/message/CRITICAL.sol similarity index 100% rename from devkit/log/message/CRITICAL.sol rename to devkit/system/message/CRITICAL.sol diff --git a/devkit/log/message/DEBUG.sol b/devkit/system/message/DEBUG.sol similarity index 100% rename from devkit/log/message/DEBUG.sol rename to devkit/system/message/DEBUG.sol diff --git a/devkit/log/message/DecodeErrorString.sol b/devkit/system/message/DecodeErrorString.sol similarity index 100% rename from devkit/log/message/DecodeErrorString.sol rename to devkit/system/message/DecodeErrorString.sol diff --git a/devkit/log/message/ERR.sol b/devkit/system/message/ERR.sol similarity index 100% rename from devkit/log/message/ERR.sol rename to devkit/system/message/ERR.sol diff --git a/devkit/log/message/INFO.sol b/devkit/system/message/INFO.sol similarity index 100% rename from devkit/log/message/INFO.sol rename to devkit/system/message/INFO.sol diff --git a/devkit/log/message/WARN.sol b/devkit/system/message/WARN.sol similarity index 100% rename from devkit/log/message/WARN.sol rename to devkit/system/message/WARN.sol diff --git a/devkit/validate/Validate.sol b/devkit/system/validate/Validate.sol similarity index 97% rename from devkit/validate/Validate.sol rename to devkit/system/validate/Validate.sol index 58fca50c..fe3412e9 100644 --- a/devkit/validate/Validate.sol +++ b/devkit/system/validate/Validate.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import {vm, ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -import {ERR} from "devkit/log/message/ERR.sol"; -import {Debugger, LogLevel} from "devkit/log/debug/Debugger.sol"; -import {Parser} from "devkit/log/debug/Parser.sol"; -import {Logger} from "devkit/log/debug/Logger.sol"; +import {ERR} from "devkit/system/message/ERR.sol"; +import {Debugger, LogLevel} from "devkit/system/debug/Debugger.sol"; +import {Parser} from "devkit/system/debug/Parser.sol"; +import {Logger} from "devkit/system/debug/Logger.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; using Inspector for bytes4; diff --git a/devkit/types/Inspector.sol b/devkit/types/Inspector.sol index e8340ed4..b2b9ef5f 100644 --- a/devkit/types/Inspector.sol +++ b/devkit/types/Inspector.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for bool; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; diff --git a/devkit/types/StringUtils.sol b/devkit/types/StringUtils.sol index 2f02e091..c1a5a3d6 100644 --- a/devkit/types/StringUtils.sol +++ b/devkit/types/StringUtils.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.24; // Validation -import {Validate} from "devkit/validate/Validate.sol"; -import {Debugger} from "devkit/log/debug/Debugger.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; +import {Debugger} from "devkit/system/debug/Debugger.sol"; // Utils import {StdStyle, ForgeHelper, vm} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; diff --git a/devkit/types/TypeGuard.sol b/devkit/types/TypeGuard.sol index 7e41422f..26da3619 100644 --- a/devkit/types/TypeGuard.sol +++ b/devkit/types/TypeGuard.sol @@ -5,7 +5,7 @@ import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for bool; import {TypeConverter} from "devkit/types/TypeConverter.sol"; using TypeConverter for bool; -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; diff --git a/devkit/utils/global/MCBundleLib.sol b/devkit/utils/global/MCBundleLib.sol index 54ba30e7..aaab6be6 100644 --- a/devkit/utils/global/MCBundleLib.sol +++ b/devkit/utils/global/MCBundleLib.sol @@ -3,11 +3,11 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; // Validation -import {Validate} from "devkit/validate/Validate.sol"; -import {ERR} from "devkit/log/message/ERR.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; +import {ERR} from "devkit/system/message/ERR.sol"; // Utils import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -import {Params} from "devkit/log/debug/Params.sol"; +import {Params} from "devkit/system/debug/Params.sol"; // Core import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; diff --git a/devkit/utils/global/MCDebugLib.sol b/devkit/utils/global/MCDebugLib.sol index ac5f2957..810b44bd 100644 --- a/devkit/utils/global/MCDebugLib.sol +++ b/devkit/utils/global/MCDebugLib.sol @@ -2,10 +2,10 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Config} from "devkit/config/Config.sol"; +import {Config} from "devkit/system/Config.sol"; // Debug -import {Debugger} from "devkit/log/debug/Debugger.sol"; -import {Logger} from "devkit/log/debug/Logger.sol"; +import {Debugger} from "devkit/system/debug/Debugger.sol"; +import {Logger} from "devkit/system/debug/Logger.sol"; /*********************************************** diff --git a/devkit/utils/global/MCDeployLib.sol b/devkit/utils/global/MCDeployLib.sol index 4534b293..60e74b66 100644 --- a/devkit/utils/global/MCDeployLib.sol +++ b/devkit/utils/global/MCDeployLib.sol @@ -2,11 +2,11 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Config} from "devkit/config/Config.sol"; +import {Config} from "devkit/system/Config.sol"; // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; // Utils -import {Params} from "devkit/log/debug/Params.sol"; +import {Params} from "devkit/system/debug/Params.sol"; // Core // dictionary import {Dictionary, DictionaryLib} from "devkit/core/Dictionary.sol"; diff --git a/devkit/utils/global/MCSetupLib.sol b/devkit/utils/global/MCSetupLib.sol index a99b91b0..37362754 100644 --- a/devkit/utils/global/MCSetupLib.sol +++ b/devkit/utils/global/MCSetupLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Config} from "devkit/config/Config.sol"; +import {Config} from "devkit/system/Config.sol"; /********************************** 🏗 Setup diff --git a/devkit/utils/global/MCTestLib.sol b/devkit/utils/global/MCTestLib.sol index 103dc5b6..37069778 100644 --- a/devkit/utils/global/MCTestLib.sol +++ b/devkit/utils/global/MCTestLib.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; // Validation -import {Validate} from "devkit/validate/Validate.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Config} from "devkit/config/Config.sol"; +import {Config} from "devkit/system/Config.sol"; // Utils -import {Params} from "devkit/log/debug/Params.sol"; +import {Params} from "devkit/system/debug/Params.sol"; // Core // functions import {Bundle} from "devkit/core/Bundle.sol"; diff --git a/devkit/utils/mapping/NameGenerator.sol b/devkit/utils/mapping/NameGenerator.sol index 5ac8286b..0c49386f 100644 --- a/devkit/utils/mapping/NameGenerator.sol +++ b/devkit/utils/mapping/NameGenerator.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Validate} from "devkit/validate/Validate.sol"; -import {Config, ScanRange} from "devkit/config/Config.sol"; +import {Validate} from "devkit/system/validate/Validate.sol"; +import {Config, ScanRange} from "devkit/system/Config.sol"; // Core Types import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 727aad6a..18c71622 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -8,8 +8,8 @@ import {Inspector} from "devkit/types/Inspector.sol"; import {TypeConverter} from "devkit/types/TypeConverter.sol"; using TypeConverter for string; -import {Config} from "devkit/config/Config.sol"; -import {ERR} from "devkit/log/message/ERR.sol"; +import {Config} from "devkit/system/Config.sol"; +import {ERR} from "devkit/system/message/ERR.sol"; import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; From 5278076d6e7ca5c527efcd96c2aa686d5a7da5c4 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 15 Apr 2024 09:44:37 +0900 Subject: [PATCH 104/111] update noBroadcast validation --- devkit/system/Config.sol | 2 +- devkit/system/validate/Validate.sol | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/devkit/system/Config.sol b/devkit/system/Config.sol index dd349b7c..a9985560 100644 --- a/devkit/system/Config.sol +++ b/devkit/system/Config.sol @@ -40,7 +40,7 @@ library ConfigLib { function load(Configuration storage config) internal { config.DEBUG_MODE = true; config.DEFAULT_LOG_LEVEL = LogLevel.Warn; - config.RECORD_EXECUTION_PROCESS = true; + config.RECORD_EXECUTION_PROCESS = false; config.SETUP_STD_FUNCS = true; diff --git a/devkit/system/validate/Validate.sol b/devkit/system/validate/Validate.sol index fe3412e9..c999bb68 100644 --- a/devkit/system/validate/Validate.sol +++ b/devkit/system/validate/Validate.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {vm, ForgeHelper} from "devkit/utils/ForgeHelper.sol"; +import {vm, VmSafe, ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {ERR} from "devkit/system/message/ERR.sol"; import {Debugger, LogLevel} from "devkit/system/debug/Debugger.sol"; import {Parser} from "devkit/system/debug/Parser.sol"; @@ -42,6 +42,14 @@ library Validate { if (T == MUST) revert(ERR.message(messageBody)); // TODO } + modifier noBroadcast() { + (VmSafe.CallerMode mode,,) = vm.readCallers(); + if (mode == VmSafe.CallerMode.RecurrentBroadcast) vm.stopBroadcast(); + _; + if (mode == VmSafe.CallerMode.RecurrentBroadcast) vm.startBroadcast(ForgeHelper.getPrivateKey("DEPLOYER_PRIV_KEY")); // Without CALL TODO + + } + /**=================== 🔒 Type Guard @@ -179,10 +187,8 @@ library Validate { function MUST_completed(Dictionary storage dictionary) internal { validate(MUST, dictionary.isComplete(), "Dictionary Not Complete", ""); } - function MUST_Verifiable(Dictionary memory dictionary) internal { - vm.stopBroadcast(); + function MUST_Verifiable(Dictionary memory dictionary) internal noBroadcast { validate(MUST, dictionary.isVerifiable(), "Dictionary Is Not Verifiable", ""); - vm.startBroadcast(ForgeHelper.getPrivateKey("DEPLOYER_PRIV_KEY")); // Without CALL TODO } /**============================ 📘 Dictionary Registry From 6f02022605e8f76705e1c35c6c7255033123ffbe Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 15 Apr 2024 10:26:08 +0900 Subject: [PATCH 105/111] Merge config to system --- devkit/MCScript.sol | 4 ++-- devkit/MCTest.sol | 10 ++++----- devkit/system/Config.sol | 18 ++++++--------- devkit/system/System.sol | 16 +++++++++++++ devkit/system/debug/Debugger.sol | 6 ++--- devkit/utils/global/MCDebugLib.sol | 4 ++-- devkit/utils/global/MCDeployLib.sol | 28 +++++++++++------------ devkit/utils/global/MCSetupLib.sol | 4 ++-- devkit/utils/global/MCTestLib.sol | 6 ++--- devkit/utils/mapping/NameGenerator.sol | 31 +++++++++++++------------- 10 files changed, 70 insertions(+), 57 deletions(-) create mode 100644 devkit/system/System.sol diff --git a/devkit/MCScript.sol b/devkit/MCScript.sol index 2bfe6d11..607090cf 100644 --- a/devkit/MCScript.sol +++ b/devkit/MCScript.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Config} from "devkit/system/Config.sol"; +import {System} from "devkit/system/System.sol"; // đŸ’Ŧ ABOUT // Meta Contract's default Script based on Forge Std Script @@ -14,7 +14,7 @@ abstract contract MCScript is MCScriptBase { constructor() { mc.loadConfig(); mc.startDebug(); - if (Config().SETUP_STD_FUNCS) mc.setupStdFunctions(); + if (System.config().SETUP_STD_FUNCS) mc.setupStdFunctions(); } } diff --git a/devkit/MCTest.sol b/devkit/MCTest.sol index 7ebf307b..e4fe4375 100644 --- a/devkit/MCTest.sol +++ b/devkit/MCTest.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Config} from "devkit/system/Config.sol"; +import {System} from "devkit/system/System.sol"; import {DecodeErrorString} from "devkit/system/message/DecodeErrorString.sol"; // đŸ’Ŧ ABOUT @@ -13,9 +13,9 @@ import {MCTestBase} from "./MCBase.sol"; // â­ī¸ MC TEST abstract contract MCTest is MCTestBase { constructor() { - Config().load(); - if (Config().DEBUG_MODE) mc.startDebug(); - if (Config().SETUP_STD_FUNCS) mc.setupStdFunctions(); + System.config().load(); + if (System.config().DEBUG_MODE) mc.startDebug(); + if (System.config().SETUP_STD_FUNCS) mc.setupStdFunctions(); } } @@ -47,7 +47,7 @@ abstract contract MCStateFuzzingTest is MCTestBase { // 🌟 MC TEST for DevKit abstract contract MCDevKitTest is MCTestBase { constructor() { - Config().load(); + System.config().load(); mc.stopLog(); } } diff --git a/devkit/system/Config.sol b/devkit/system/Config.sol index a9985560..b1efc6b2 100644 --- a/devkit/system/Config.sol +++ b/devkit/system/Config.sol @@ -6,11 +6,11 @@ import {LogLevel} from "devkit/system/debug/Debugger.sol"; /**---------------------- - 📝 Configuration + 📝 Config ------------------------*/ -using ConfigLib for Configuration global; +using ConfigLib for Config global; /// @custom:storage-location erc7201:mc.devkit.config -struct Configuration { +struct Config { bool DEBUG_MODE; LogLevel DEFAULT_LOG_LEVEL; bool RECORD_EXECUTION_PROCESS; @@ -29,15 +29,11 @@ struct Configuration { } struct ScanRange { uint128 START; uint128 END; } -function Config() pure returns(Configuration storage ref) { - assembly { ref.slot := 0x43faf0b0e69b78a7870a9a7da6e0bf9d6f14028444e1b48699a33401cb840400 } -} - /**===============\ | 📝 Config | \================*/ library ConfigLib { - function load(Configuration storage config) internal { + function load(Config storage config) internal { config.DEBUG_MODE = true; config.DEFAULT_LOG_LEVEL = LogLevel.Warn; config.RECORD_EXECUTION_PROCESS = false; @@ -56,11 +52,11 @@ library ConfigLib { config.SCAN_RANGE.END = 5; } - function defaultOwner(Configuration storage) internal returns(address) { + function defaultOwner(Config storage) internal returns(address) { return ForgeHelper.msgSender(); } - function defaultName(Configuration storage) internal pure returns(string memory) { + function defaultName(Config storage) internal pure returns(string memory) { return "ProjectName"; // TODO } @@ -88,7 +84,7 @@ library ConfigLib { // return mc.functions.genUniqueBundleName(); // } - function defaultInitData(Configuration storage) internal pure returns(bytes memory) { + function defaultInitData(Config storage) internal pure returns(bytes memory) { return ""; } } diff --git a/devkit/system/System.sol b/devkit/system/System.sol new file mode 100644 index 00000000..90779049 --- /dev/null +++ b/devkit/system/System.sol @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {Config} from "devkit/system/Config.sol"; + +/**===============\ +| đŸ’ģ System | +\================*/ +library System { + + function config() internal pure returns(Config storage ref) { + assembly { ref.slot := 0x43faf0b0e69b78a7870a9a7da6e0bf9d6f14028444e1b48699a33401cb840400 } + } + + +} diff --git a/devkit/system/debug/Debugger.sol b/devkit/system/debug/Debugger.sol index 102e44bd..22b77318 100644 --- a/devkit/system/debug/Debugger.sol +++ b/devkit/system/debug/Debugger.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.24; import {console2, StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; import {Logger} from "./Logger.sol"; -import {Config} from "devkit/system/Config.sol"; +import {System} from "devkit/system/System.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for bool; @@ -92,7 +92,7 @@ library Debugger { 📈 Execution Tracking ------------------------------*/ function recordExecStart(string memory libName, string memory funcName, string memory params) internal returns(uint pid) { - if (Config().RECORD_EXECUTION_PROCESS.isFalse()) return 0; + if (System.config().RECORD_EXECUTION_PROCESS.isFalse()) return 0; pid = State().nextPid; State().processes.push(Process(libName, funcName, params)); Logger.logExecStart(pid, libName, funcName); @@ -100,7 +100,7 @@ library Debugger { } function recordExecFinish(uint pid) internal { - if (Config().RECORD_EXECUTION_PROCESS.isFalse()) return; + if (System.config().RECORD_EXECUTION_PROCESS.isFalse()) return; Process memory current = State().processes[pid]; Logger.logExecFinish(pid, current.libName, current.funcName); } diff --git a/devkit/utils/global/MCDebugLib.sol b/devkit/utils/global/MCDebugLib.sol index 810b44bd..326c0496 100644 --- a/devkit/utils/global/MCDebugLib.sol +++ b/devkit/utils/global/MCDebugLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Config} from "devkit/system/Config.sol"; +import {System} from "devkit/system/System.sol"; // Debug import {Debugger} from "devkit/system/debug/Debugger.sol"; import {Logger} from "devkit/system/debug/Logger.sol"; @@ -24,7 +24,7 @@ library MCDebugLib { -----------------*/ function startDebug(MCDevKit storage mc) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("startDebug"); - if (Config().DEBUG_MODE) Debugger.startDebug(); + if (System.config().DEBUG_MODE) Debugger.startDebug(); return mc.recordExecFinish(pid); } diff --git a/devkit/utils/global/MCDeployLib.sol b/devkit/utils/global/MCDeployLib.sol index 60e74b66..aa17d3f4 100644 --- a/devkit/utils/global/MCDeployLib.sol +++ b/devkit/utils/global/MCDeployLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Config} from "devkit/system/Config.sol"; +import {System} from "devkit/system/System.sol"; // Validation import {Validate} from "devkit/system/validate/Validate.sol"; // Utils @@ -46,25 +46,25 @@ library MCDeployLib { } function deploy(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.deploy(mc.bundle.findCurrent().name, mc.bundle.findCurrent(), Config().defaultOwner(), Config().defaultInitData()); + return mc.deploy(mc.bundle.findCurrent().name, mc.bundle.findCurrent(), System.config().defaultOwner(), System.config().defaultInitData()); } // function deploy(MCDevKit storage mc, string memory name, Bundle storage bundleInfo, address facade, address owner) internal returns(MCDevKit storage) { - // return mc.deploy(name, bundleInfo, facade, owner, Config().defaultInitData()); + // return mc.deploy(name, bundleInfo, facade, owner, System.config().defaultInitData()); // } // function deploy(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(MCDevKit storage) { - // return mc.deploy(name, bundleInfo, Config().defaultInitData(), ); + // return mc.deploy(name, bundleInfo, System.config().defaultInitData(), ); // } // function deploy(MCDevKit storage mc, Bundle storage bundleInfo) internal returns(MCDevKit storage) { - // return mc.deploy(Config().defaultName(), bundleInfo, Config().defaultInitData()); + // return mc.deploy(System.config().defaultName(), bundleInfo, System.config().defaultInitData()); // } // function deploy(MCDevKit storage mc, string memory name, bytes memory initData) internal returns(MCDevKit storage) { // return mc.deploy(name, mc.functions.findBundle(name), initData); // } // function deploy(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - // return mc.deploy(name, mc.functions.findBundle(name), Config().defaultInitData()); + // return mc.deploy(name, mc.functions.findBundle(name), System.config().defaultInitData()); // } function deploy(MCDevKit storage mc, bytes memory initData) internal returns(MCDevKit storage) { - return mc.deploy(mc.bundle.findCurrent().name, mc.bundle.findCurrent(), Config().defaultOwner(), initData); + return mc.deploy(mc.bundle.findCurrent().name, mc.bundle.findCurrent(), System.config().defaultOwner(), initData); } @@ -81,10 +81,10 @@ library MCDeployLib { return mc.deployProxy(name, dictionary, owner.initSetAdminBytes()); } function deployProxy(MCDevKit storage mc, string memory name, Dictionary storage dictionary) internal returns(MCDevKit storage) { - return mc.deployProxy(name, dictionary, Config().defaultOwner().initSetAdminBytes()); + return mc.deployProxy(name, dictionary, System.config().defaultOwner().initSetAdminBytes()); } function deployProxy(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - return mc.deployProxy(name, mc.findCurrentDictionary(), Config().defaultOwner().initSetAdminBytes()); + return mc.deployProxy(name, mc.findCurrentDictionary(), System.config().defaultOwner().initSetAdminBytes()); } function deployProxy(MCDevKit storage mc, string memory name, bytes memory initData) internal returns(MCDevKit storage) { return mc.deployProxy(name, mc.findCurrentDictionary(), initData); @@ -93,7 +93,7 @@ library MCDeployLib { return mc.deployProxy(mc.proxy.proxies.genUniqueName(), mc.findCurrentDictionary(), initData); } function deployProxy(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.deployProxy(mc.proxy.proxies.genUniqueName(), mc.findCurrentDictionary(), Config().defaultOwner().initSetAdminBytes()); + return mc.deployProxy(mc.proxy.proxies.genUniqueName(), mc.findCurrentDictionary(), System.config().defaultOwner().initSetAdminBytes()); } @@ -110,19 +110,19 @@ library MCDeployLib { } function deployDictionary(MCDevKit storage mc) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), mc.bundle.findCurrent(), Config().defaultOwner()); + return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), mc.bundle.findCurrent(), System.config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, string memory name) internal returns(Dictionary memory) { - return mc.deployDictionary(name, mc.bundle.findCurrent(), Config().defaultOwner()); + return mc.deployDictionary(name, mc.bundle.findCurrent(), System.config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, Bundle storage bundleInfo) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), bundleInfo, Config().defaultOwner()); + return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), bundleInfo, System.config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, address owner) internal returns(Dictionary memory) { return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), mc.bundle.findCurrent(), owner); } function deployDictionary(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(Dictionary memory) { - return mc.deployDictionary(name, bundleInfo, Config().defaultOwner()); + return mc.deployDictionary(name, bundleInfo, System.config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, string memory name, address owner) internal returns(Dictionary memory) { return mc.deployDictionary(name, mc.bundle.findCurrent(), owner); diff --git a/devkit/utils/global/MCSetupLib.sol b/devkit/utils/global/MCSetupLib.sol index 37362754..aebd791c 100644 --- a/devkit/utils/global/MCSetupLib.sol +++ b/devkit/utils/global/MCSetupLib.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Config} from "devkit/system/Config.sol"; +import {System} from "devkit/system/System.sol"; /********************************** 🏗 Setup @@ -11,7 +11,7 @@ import {Config} from "devkit/system/Config.sol"; library MCSetupLib { function loadConfig(MCDevKit storage mc) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("loadConfig"); - Config().load(); + System.config().load(); return mc.recordExecFinish(pid); } diff --git a/devkit/utils/global/MCTestLib.sol b/devkit/utils/global/MCTestLib.sol index 37069778..b95cb26c 100644 --- a/devkit/utils/global/MCTestLib.sol +++ b/devkit/utils/global/MCTestLib.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; import {Validate} from "devkit/system/validate/Validate.sol"; import {MCDevKit} from "devkit/MCDevKit.sol"; -import {Config} from "devkit/system/Config.sol"; +import {System} from "devkit/system/System.sol"; // Utils import {Params} from "devkit/system/debug/Params.sol"; // Core @@ -99,10 +99,10 @@ library MCTestLib { return mc.createMockDictionary(name, owner, mc.std.all); } function createMockDictionary(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - return mc.createMockDictionary(name, Config().defaultOwner(), mc.std.all); + return mc.createMockDictionary(name, System.config().defaultOwner(), mc.std.all); } function createMockDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), Config().defaultOwner(), mc.std.all); + return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), System.config().defaultOwner(), mc.std.all); } diff --git a/devkit/utils/mapping/NameGenerator.sol b/devkit/utils/mapping/NameGenerator.sol index 0c49386f..59853472 100644 --- a/devkit/utils/mapping/NameGenerator.sol +++ b/devkit/utils/mapping/NameGenerator.sol @@ -2,7 +2,8 @@ pragma solidity ^0.8.24; import {Validate} from "devkit/system/validate/Validate.sol"; -import {Config, ScanRange} from "devkit/system/Config.sol"; +import {ScanRange} from "devkit/system/Config.sol"; +import {System} from "devkit/system/System.sol"; // Core Types import {Bundle} from "devkit/core/Bundle.sol"; import {Function} from "devkit/core/Function.sol"; @@ -21,7 +22,7 @@ library NameGenerator { đŸ—‚ī¸ Bundle Mapping --------------------------*/ function genUniqueName(mapping(string => Bundle) storage bundle, string memory baseName) internal returns(string memory name) { - ScanRange memory range = Config().SCAN_RANGE; + ScanRange memory range = System.config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = baseName.toSequential(i); if (bundle[name].hasNotName()) return name; // TODO @@ -29,7 +30,7 @@ library NameGenerator { Validate.MUST_FoundInRange(); } function genUniqueName(mapping(string => Bundle) storage bundle) internal returns(string memory name) { - return genUniqueName(bundle, Config().DEFAULT_BUNDLE_NAME); + return genUniqueName(bundle, System.config().DEFAULT_BUNDLE_NAME); } @@ -37,7 +38,7 @@ library NameGenerator { 🧩 Function Mapping ---------------------------*/ function genUniqueName(mapping(string => Function) storage func, string memory baseName) internal returns(string memory name) { - ScanRange memory range = Config().SCAN_RANGE; + ScanRange memory range = System.config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = baseName.toSequential(i); if (func[name].notExists()) return name; @@ -45,7 +46,7 @@ library NameGenerator { Validate.MUST_FoundInRange(); } function genUniqueName(mapping(string => Function) storage func) internal returns(string memory name) { - return genUniqueName(func, Config().DEFAULT_FUNCTION_NAME); + return genUniqueName(func, System.config().DEFAULT_FUNCTION_NAME); } @@ -53,7 +54,7 @@ library NameGenerator { 📚 Dictionary Mapping -----------------------------*/ function genUniqueName(mapping(string => Dictionary) storage dictionary, string memory baseName) internal returns(string memory name) { - ScanRange memory range = Config().SCAN_RANGE; + ScanRange memory range = System.config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = baseName.toSequential(i); if (dictionary[name].notExists()) return name; @@ -62,19 +63,19 @@ library NameGenerator { } /*----- Dictionary -----*/ function genUniqueName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { - return genUniqueName(dictionary, Config().DEFAULT_DICTIONARY_NAME); + return genUniqueName(dictionary, System.config().DEFAULT_DICTIONARY_NAME); } /*----- Dictionary -----*/ function genUniqueDuplicatedName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { - return genUniqueName(dictionary, Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); + return genUniqueName(dictionary, System.config().DEFAULT_DICTIONARY_DUPLICATED_NAME); } /*----- Mock Dictionary -----*/ function genUniqueMockName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { - return genUniqueName(dictionary, Config().DEFAULT_DICTIONARY_MOCK_NAME); + return genUniqueName(dictionary, System.config().DEFAULT_DICTIONARY_MOCK_NAME); } // function genUniqueName(DictionaryRegistry storage dictionaries, string memory baseName) internal returns(string memory name) { // uint pid = dictionaries.startProcess("genUniqueName"); - // ScanRange memory range = Config().SCAN_RANGE; + // ScanRange memory range = System.config().SCAN_RANGE; // for (uint i = range.START; i <= range.END; ++i) { // name = baseName.toSequential(i); // if (dictionaries.existsInDeployed(name).isFalse()) return name.recordExecFinish(pid); @@ -82,10 +83,10 @@ library NameGenerator { // throwError(ERR.FIND_NAME_OVER_RANGE); // } // function genUniqueName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { - // return dictionaries.genUniqueName(Config().DEFAULT_DICTIONARY_NAME); + // return dictionaries.genUniqueName(System.config().DEFAULT_DICTIONARY_NAME); // } // function genUniqueDuplicatedName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { - // return dictionaries.genUniqueName(Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); + // return dictionaries.genUniqueName(System.config().DEFAULT_DICTIONARY_DUPLICATED_NAME); // } @@ -94,7 +95,7 @@ library NameGenerator { -------------------------*/ /*----- Mock Proxy -----*/ function genUniqueName(mapping(string => Proxy) storage proxy, string memory baseName) internal returns(string memory name) { - ScanRange memory range = Config().SCAN_RANGE; + ScanRange memory range = System.config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = baseName.toSequential(i); if (proxy[name].notExists()) return name; @@ -103,11 +104,11 @@ library NameGenerator { } /*----- Proxy -----*/ function genUniqueName(mapping(string => Proxy) storage proxy) internal returns(string memory name) { - return genUniqueName(proxy, Config().DEFAULT_PROXY_NAME); + return genUniqueName(proxy, System.config().DEFAULT_PROXY_NAME); } /*----- Mock Proxy -----*/ function genUniqueMockName(mapping(string => Proxy) storage proxy) internal returns(string memory name) { - return genUniqueName(proxy, Config().DEFAULT_PROXY_MOCK_NAME); + return genUniqueName(proxy, System.config().DEFAULT_PROXY_MOCK_NAME); } } From fd0367249f8c4b9e05c8e49db0f67a102d9a7752 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 15 Apr 2024 11:10:22 +0900 Subject: [PATCH 106/111] merge debugger into system --- devkit/MCScript.sol | 2 +- devkit/MCTest.sol | 8 +-- devkit/system/Config.sol | 18 +++--- devkit/system/System.sol | 8 ++- devkit/system/debug/Debugger.sol | 83 +++++++++++--------------- devkit/system/debug/Logger.sol | 23 ++++--- devkit/system/debug/ProcessLib.sol | 42 ++++++------- devkit/system/validate/Validate.sol | 1 - devkit/types/StringUtils.sol | 5 +- devkit/utils/global/MCDebugLib.sol | 10 ++-- devkit/utils/global/MCDeployLib.sol | 26 ++++---- devkit/utils/global/MCSetupLib.sol | 2 +- devkit/utils/global/MCTestLib.sol | 4 +- devkit/utils/mapping/NameGenerator.sol | 28 ++++----- test/devkit/global/MCBundle.t.sol | 1 - 15 files changed, 130 insertions(+), 131 deletions(-) diff --git a/devkit/MCScript.sol b/devkit/MCScript.sol index 607090cf..0f8f58e7 100644 --- a/devkit/MCScript.sol +++ b/devkit/MCScript.sol @@ -14,7 +14,7 @@ abstract contract MCScript is MCScriptBase { constructor() { mc.loadConfig(); mc.startDebug(); - if (System.config().SETUP_STD_FUNCS) mc.setupStdFunctions(); + if (System.Config().SETUP_STD_FUNCS) mc.setupStdFunctions(); } } diff --git a/devkit/MCTest.sol b/devkit/MCTest.sol index e4fe4375..4fdaaf13 100644 --- a/devkit/MCTest.sol +++ b/devkit/MCTest.sol @@ -13,9 +13,9 @@ import {MCTestBase} from "./MCBase.sol"; // â­ī¸ MC TEST abstract contract MCTest is MCTestBase { constructor() { - System.config().load(); - if (System.config().DEBUG_MODE) mc.startDebug(); - if (System.config().SETUP_STD_FUNCS) mc.setupStdFunctions(); + System.Config().load(); + if (System.Config().DEBUG_MODE) mc.startDebug(); + if (System.Config().SETUP_STD_FUNCS) mc.setupStdFunctions(); } } @@ -47,7 +47,7 @@ abstract contract MCStateFuzzingTest is MCTestBase { // 🌟 MC TEST for DevKit abstract contract MCDevKitTest is MCTestBase { constructor() { - System.config().load(); + System.Config().load(); mc.stopLog(); } } diff --git a/devkit/system/Config.sol b/devkit/system/Config.sol index b1efc6b2..f93908ea 100644 --- a/devkit/system/Config.sol +++ b/devkit/system/Config.sol @@ -2,17 +2,17 @@ pragma solidity ^0.8.24; import {ForgeHelper} from "devkit/utils/ForgeHelper.sol"; -import {LogLevel} from "devkit/system/debug/Debugger.sol"; +import {Logger} from "devkit/system/debug/Logger.sol"; /**---------------------- 📝 Config ------------------------*/ -using ConfigLib for Config global; +using ConfigLib for ConfigState global; /// @custom:storage-location erc7201:mc.devkit.config -struct Config { +struct ConfigState { bool DEBUG_MODE; - LogLevel DEFAULT_LOG_LEVEL; + Logger.LogLevel DEFAULT_LOG_LEVEL; bool RECORD_EXECUTION_PROCESS; bool SETUP_STD_FUNCS; @@ -33,9 +33,9 @@ struct Config { | 📝 Config | \================*/ library ConfigLib { - function load(Config storage config) internal { + function load(ConfigState storage config) internal { config.DEBUG_MODE = true; - config.DEFAULT_LOG_LEVEL = LogLevel.Warn; + config.DEFAULT_LOG_LEVEL = Logger.LogLevel.Warn; config.RECORD_EXECUTION_PROCESS = false; config.SETUP_STD_FUNCS = true; @@ -52,11 +52,11 @@ library ConfigLib { config.SCAN_RANGE.END = 5; } - function defaultOwner(Config storage) internal returns(address) { + function defaultOwner(ConfigState storage) internal returns(address) { return ForgeHelper.msgSender(); } - function defaultName(Config storage) internal pure returns(string memory) { + function defaultName(ConfigState storage) internal pure returns(string memory) { return "ProjectName"; // TODO } @@ -84,7 +84,7 @@ library ConfigLib { // return mc.functions.genUniqueBundleName(); // } - function defaultInitData(Config storage) internal pure returns(bytes memory) { + function defaultInitData(ConfigState storage) internal pure returns(bytes memory) { return ""; } } diff --git a/devkit/system/System.sol b/devkit/system/System.sol index 90779049..976ee562 100644 --- a/devkit/system/System.sol +++ b/devkit/system/System.sol @@ -1,16 +1,20 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Config} from "devkit/system/Config.sol"; +import {ConfigState} from "devkit/system/Config.sol"; +import {DebuggerState} from "devkit/system/debug/Debugger.sol"; /**===============\ | đŸ’ģ System | \================*/ library System { - function config() internal pure returns(Config storage ref) { + function Config() internal pure returns(ConfigState storage ref) { assembly { ref.slot := 0x43faf0b0e69b78a7870a9a7da6e0bf9d6f14028444e1b48699a33401cb840400 } } + function Debug() internal pure returns(DebuggerState storage ref) { + assembly { ref.slot := 0x03d3692c02b7cdcaf0187e8ede4101c401cc53a33aa7e03ef4682fcca8a55300 } + } } diff --git a/devkit/system/debug/Debugger.sol b/devkit/system/debug/Debugger.sol index 22b77318..3fcbc308 100644 --- a/devkit/system/debug/Debugger.sol +++ b/devkit/system/debug/Debugger.sol @@ -10,21 +10,14 @@ import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for bool; +using DebuggerLib for DebuggerState global; /// @custom:storage-location erc7201:mc.devkit.debugger struct DebuggerState { - LogLevel logLevel; + Logger.LogLevel logLevel; string[] errorLocationStack; Process[] processes; uint nextPid; } - enum LogLevel { - Disable, // Display no message - Debug, // Display all messages including debug details - Info, // Display info, warning, and error messages - Warn, // Display warning and error messages - Error, // Display error messages only - Critical // Display critical error messages only - } struct Process { string libName; string funcName; @@ -35,56 +28,50 @@ struct DebuggerState { /**=================\ | 🐞 Debugger | \==================*/ -library Debugger { - /**++++++++++++++++++++++++ - đŸ”ĩ Debugger State - ++++++++++++++++++++++++++*/ - function State() internal pure returns(DebuggerState storage ref) { - assembly { ref.slot := 0x03d3692c02b7cdcaf0187e8ede4101c401cc53a33aa7e03ef4682fcca8a55300 } - } +library DebuggerLib { /**------------------------- đŸ•šī¸ Logging Control ---------------------------*/ - function startDebug() internal { - setLogLevel(LogLevel.Debug); + function startDebug(DebuggerState storage debugger) internal { + setLogLevel(debugger, Logger.LogLevel.Debug); } - function startInfo() internal { - setLogLevel(LogLevel.Info); + function startInfo(DebuggerState storage debugger) internal { + setLogLevel(debugger, Logger.LogLevel.Info); } - function startWarn() internal { - setLogLevel(LogLevel.Warn); + function startWarn(DebuggerState storage debugger) internal { + setLogLevel(debugger, Logger.LogLevel.Warn); } - function startError() internal { - setLogLevel(LogLevel.Error); + function startError(DebuggerState storage debugger) internal { + setLogLevel(debugger, Logger.LogLevel.Error); } - function startCritical() internal { - setLogLevel(LogLevel.Critical); + function startCritical(DebuggerState storage debugger) internal { + setLogLevel(debugger, Logger.LogLevel.Critical); } - function stopLog() internal { - setLogLevel(LogLevel.Disable); + function stopLog(DebuggerState storage debugger) internal { + setLogLevel(debugger, Logger.LogLevel.Disable); } - function setLogLevel(LogLevel level) internal { - State().logLevel = level; + function setLogLevel(DebuggerState storage debugger, Logger.LogLevel level) internal { + debugger.logLevel = level; } - function isDisabled() internal returns(bool) { - return State().logLevel == LogLevel.Disable; + function isDisabled(DebuggerState storage debugger) internal returns(bool) { + return debugger.logLevel == Logger.LogLevel.Disable; } - function isDebug() internal returns(bool) { - return State().logLevel == LogLevel.Debug; + function isDebug(DebuggerState storage debugger) internal returns(bool) { + return debugger.logLevel == Logger.LogLevel.Debug; } - function isInfo() internal returns(bool) { - return State().logLevel == LogLevel.Info; + function isInfo(DebuggerState storage debugger) internal returns(bool) { + return debugger.logLevel == Logger.LogLevel.Info; } - function isWarm() internal returns(bool) { - return State().logLevel == LogLevel.Warn; + function isWarm(DebuggerState storage debugger) internal returns(bool) { + return debugger.logLevel == Logger.LogLevel.Warn; } - function isError() internal returns(bool) { - return State().logLevel == LogLevel.Error; + function isError(DebuggerState storage debugger) internal returns(bool) { + return debugger.logLevel == Logger.LogLevel.Error; } - function isCritical() internal returns(bool) { - return State().logLevel == LogLevel.Critical; + function isCritical(DebuggerState storage debugger) internal returns(bool) { + return debugger.logLevel == Logger.LogLevel.Critical; } @@ -92,16 +79,16 @@ library Debugger { 📈 Execution Tracking ------------------------------*/ function recordExecStart(string memory libName, string memory funcName, string memory params) internal returns(uint pid) { - if (System.config().RECORD_EXECUTION_PROCESS.isFalse()) return 0; - pid = State().nextPid; - State().processes.push(Process(libName, funcName, params)); + if (System.Config().RECORD_EXECUTION_PROCESS.isFalse()) return 0; + pid = System.Debug().nextPid; + System.Debug().processes.push(Process(libName, funcName, params)); Logger.logExecStart(pid, libName, funcName); - State().nextPid++; + System.Debug().nextPid++; } function recordExecFinish(uint pid) internal { - if (System.config().RECORD_EXECUTION_PROCESS.isFalse()) return; - Process memory current = State().processes[pid]; + if (System.Config().RECORD_EXECUTION_PROCESS.isFalse()) return; + Process memory current = System.Debug().processes[pid]; Logger.logExecFinish(pid, current.libName, current.funcName); } } diff --git a/devkit/system/debug/Logger.sol b/devkit/system/debug/Logger.sol index 45e798d8..cec89b75 100644 --- a/devkit/system/debug/Logger.sol +++ b/devkit/system/debug/Logger.sol @@ -10,7 +10,8 @@ import {CRITICAL} from "devkit/system/message/CRITICAL.sol"; import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/types/StringUtils.sol"; // Debug -import {Debugger, Process} from "./Debugger.sol"; +import {Process} from "./Debugger.sol"; +import {System} from "devkit/system/System.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; @@ -21,16 +22,24 @@ library Logger { using StringUtils for string; using StdStyle for string; + enum LogLevel { + Disable, // Display no message + Debug, // Display all messages including debug details + Info, // Display info, warning, and error messages + Warn, // Display warning and error messages + Error, // Display error messages only + Critical // Display critical error messages only + } /**------------------ đŸ’Ŧ Logging --------------------*/ function log(string memory message) internal { - if (Debugger.isDebug()) logDebug(message); - if (Debugger.isInfo()) logInfo(message); - if (Debugger.isWarm()) logWarn(message); - if (Debugger.isError()) logError(message); - if (Debugger.isCritical()) logCritical(message); + if (System.Debug().isDebug()) logDebug(message); + if (System.Debug().isInfo()) logInfo(message); + if (System.Debug().isWarm()) logWarn(message); + if (System.Debug().isError()) logError(message); + if (System.Debug().isCritical()) logCritical(message); } function logDebug(string memory message) internal { @@ -92,7 +101,7 @@ library Logger { 📑 Parser -----------------*/ function parseLocations() internal returns(string memory locations) { - Process[] memory processes = Debugger.State().processes; + Process[] memory processes = System.Debug().processes; for (uint i = processes.length; i > 0; --i) { locations = locations.append(formatLocation(processes[i-1])); } diff --git a/devkit/system/debug/ProcessLib.sol b/devkit/system/debug/ProcessLib.sol index 5c410613..69c07d52 100644 --- a/devkit/system/debug/ProcessLib.sol +++ b/devkit/system/debug/ProcessLib.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Debugger} from "devkit/system/debug/Debugger.sol"; +import {DebuggerLib} from "devkit/system/debug/Debugger.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {FunctionRegistry} from "devkit/registry/FunctionRegistry.sol"; @@ -21,7 +21,7 @@ import {Current} from "devkit/registry/context/Current.sol"; ===================*/ library ProcessLib { function finishProcess(uint pid) internal { - Debugger.recordExecFinish(pid); + DebuggerLib.recordExecFinish(pid); } @@ -29,14 +29,14 @@ library ProcessLib { 🧩 Function --------------------*/ function startProcess(Function storage, string memory name, string memory params) internal returns(uint) { - return Debugger.recordExecStart("FunctionLib", name, params); + return DebuggerLib.recordExecStart("FunctionLib", name, params); } function startProcess(Function storage func, string memory name) internal returns(uint) { return func.startProcess(name, ""); } function finishProcess(Function storage func, uint pid) internal returns(Function storage) { - Debugger.recordExecFinish(pid); + DebuggerLib.recordExecFinish(pid); return func; } @@ -44,14 +44,14 @@ library ProcessLib { 🧩 Functions Registry ----------------------------*/ function startProcess(FunctionRegistry storage, string memory name, string memory params) internal returns(uint) { - return Debugger.recordExecStart("FunctionRegistry", name, params); + return DebuggerLib.recordExecStart("FunctionRegistry", name, params); } function startProcess(FunctionRegistry storage functions, string memory name) internal returns(uint) { return functions.startProcess(name, ""); } function finishProcess(FunctionRegistry storage functions, uint pid) internal returns(FunctionRegistry storage) { - Debugger.recordExecFinish(pid); + DebuggerLib.recordExecFinish(pid); return functions; } @@ -60,14 +60,14 @@ library ProcessLib { đŸ—‚ī¸ Bundle ------------------*/ function startProcess(Bundle storage, string memory name, string memory params) internal returns(uint) { - return Debugger.recordExecStart("Bundle", name, params); + return DebuggerLib.recordExecStart("Bundle", name, params); } function startProcess(Bundle storage bundle, string memory name) internal returns(uint) { return bundle.startProcess(name, ""); } function finishProcess(Bundle storage bundle, uint pid) internal returns(Bundle storage) { - Debugger.recordExecFinish(pid); + DebuggerLib.recordExecFinish(pid); return bundle; } @@ -75,14 +75,14 @@ library ProcessLib { 🧩 Bundle Registry ----------------------------*/ function startProcess(BundleRegistry storage, string memory name, string memory params) internal returns(uint) { - return Debugger.recordExecStart("BundleRegistry", name, params); + return DebuggerLib.recordExecStart("BundleRegistry", name, params); } function startProcess(BundleRegistry storage bundle, string memory name) internal returns(uint) { return bundle.startProcess(name, ""); } function finishProcess(BundleRegistry storage bundle, uint pid) internal returns(BundleRegistry storage) { - Debugger.recordExecFinish(pid); + DebuggerLib.recordExecFinish(pid); return bundle; } @@ -91,14 +91,14 @@ library ProcessLib { 🏛 Standard Registry ---------------------------*/ function startProcess(StdRegistry storage, string memory name, string memory params) internal returns(uint) { - return Debugger.recordExecStart("StdRegistryLib", name, params); + return DebuggerLib.recordExecStart("StdRegistryLib", name, params); } function startProcess(StdRegistry storage std, string memory name) internal returns(uint) { return std.startProcess(name, ""); } function finishProcess(StdRegistry storage std, uint pid) internal returns(StdRegistry storage) { - Debugger.recordExecFinish(pid); + DebuggerLib.recordExecFinish(pid); return std; } @@ -107,14 +107,14 @@ library ProcessLib { 🏰 Standard Functions ----------------------------*/ function startProcess(StdFunctions storage, string memory name, string memory params) internal returns(uint) { - return Debugger.recordExecStart("StdFunctionsLib", name, params); + return DebuggerLib.recordExecStart("StdFunctionsLib", name, params); } function startProcess(StdFunctions storage std, string memory name) internal returns(uint) { return std.startProcess(name, ""); } function finishProcess(StdFunctions storage std, uint pid) internal returns(StdFunctions storage) { - Debugger.recordExecFinish(pid); + DebuggerLib.recordExecFinish(pid); return std; } @@ -123,7 +123,7 @@ library ProcessLib { 🏠 Proxy -----------------*/ function startProxyLibProcess(string memory name, string memory params) internal returns(uint) { - return Debugger.recordExecStart("ProxyLib", name, params); + return DebuggerLib.recordExecStart("ProxyLib", name, params); } function startProxyLibProcess(string memory name) internal returns(uint) { return startProxyLibProcess(name, ""); @@ -142,14 +142,14 @@ library ProcessLib { 🏠 Proxy Registry ------------------------*/ function startProcess(ProxyRegistry storage, string memory name, string memory params) internal returns(uint) { - return Debugger.recordExecStart("ProxyRegistryLib", name, params); + return DebuggerLib.recordExecStart("ProxyRegistryLib", name, params); } function startProcess(ProxyRegistry storage proxies, string memory name) internal returns(uint) { return proxies.startProcess(name, ""); } function finishProcess(ProxyRegistry storage proxies, uint pid) internal returns(ProxyRegistry storage) { - Debugger.recordExecFinish(pid); + DebuggerLib.recordExecFinish(pid); return proxies; } @@ -158,7 +158,7 @@ library ProcessLib { 📚 Dictionary ---------------------*/ function startDictionaryLibProcess(string memory name, string memory params) internal returns(uint) { - return Debugger.recordExecStart("DictionaryLib", name, params); + return DebuggerLib.recordExecStart("DictionaryLib", name, params); } function startDictionaryLibProcess(string memory name) internal returns(uint) { return startDictionaryLibProcess(name, ""); @@ -177,14 +177,14 @@ library ProcessLib { 📚 Dictionary Registry ------------------------------*/ function startProcess(DictionaryRegistry storage, string memory name, string memory params) internal returns(uint) { - return Debugger.recordExecStart("DictionaryRegistryLib", name, params); + return DebuggerLib.recordExecStart("DictionaryRegistryLib", name, params); } function startProcess(DictionaryRegistry storage dictionaries, string memory name) internal returns(uint) { return dictionaries.startProcess(name, ""); } function finishProcess(DictionaryRegistry storage dictionaries, uint pid) internal returns(DictionaryRegistry storage) { - Debugger.recordExecFinish(pid); + DebuggerLib.recordExecFinish(pid); return dictionaries; } @@ -193,7 +193,7 @@ library ProcessLib { 📸 Current Context --------------------------*/ function startProcess(Current storage, string memory name, string memory params) internal returns(uint) { - return Debugger.recordExecStart("CurrentLib", name, params); + return DebuggerLib.recordExecStart("CurrentLib", name, params); } function startProcess(Current storage current, string memory name) internal returns(uint) { return current.startProcess(name, ""); diff --git a/devkit/system/validate/Validate.sol b/devkit/system/validate/Validate.sol index c999bb68..3e8b2562 100644 --- a/devkit/system/validate/Validate.sol +++ b/devkit/system/validate/Validate.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.24; import {vm, VmSafe, ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {ERR} from "devkit/system/message/ERR.sol"; -import {Debugger, LogLevel} from "devkit/system/debug/Debugger.sol"; import {Parser} from "devkit/system/debug/Parser.sol"; import {Logger} from "devkit/system/debug/Logger.sol"; import {Inspector} from "devkit/types/Inspector.sol"; diff --git a/devkit/types/StringUtils.sol b/devkit/types/StringUtils.sol index c1a5a3d6..b4690a76 100644 --- a/devkit/types/StringUtils.sol +++ b/devkit/types/StringUtils.sol @@ -3,7 +3,8 @@ pragma solidity ^0.8.24; // Validation import {Validate} from "devkit/system/validate/Validate.sol"; -import {Debugger} from "devkit/system/debug/Debugger.sol"; +import {System} from "devkit/system/System.sol"; +import {DebuggerLib} from "devkit/system/debug/Debugger.sol"; // Utils import {StdStyle, ForgeHelper, vm} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; @@ -96,7 +97,7 @@ library StringUtils { Record Finish */ function recordExecFinish(string memory str, uint pid) internal returns(string memory) { - Debugger.recordExecFinish(pid); + DebuggerLib.recordExecFinish(pid); return str; } diff --git a/devkit/utils/global/MCDebugLib.sol b/devkit/utils/global/MCDebugLib.sol index 326c0496..12d8c2a6 100644 --- a/devkit/utils/global/MCDebugLib.sol +++ b/devkit/utils/global/MCDebugLib.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; import {System} from "devkit/system/System.sol"; // Debug -import {Debugger} from "devkit/system/debug/Debugger.sol"; +import {DebuggerLib} from "devkit/system/debug/Debugger.sol"; import {Logger} from "devkit/system/debug/Logger.sol"; @@ -24,7 +24,7 @@ library MCDebugLib { -----------------*/ function startDebug(MCDevKit storage mc) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("startDebug"); - if (System.config().DEBUG_MODE) Debugger.startDebug(); + if (System.Config().DEBUG_MODE) System.Debug().startDebug(); return mc.recordExecFinish(pid); } @@ -33,7 +33,7 @@ library MCDebugLib { 🛑 Stop ---------------*/ function stopLog(MCDevKit storage mc) internal returns(MCDevKit storage) { - Debugger.stopLog(); + System.Debug().stopLog(); return mc; } @@ -51,7 +51,7 @@ library MCDebugLib { đŸ”Ŋ Record Start ----------------------*/ function recordExecStart(MCDevKit storage mc, string memory funcName, string memory params) internal returns(uint) { - return Debugger.recordExecStart(LIB_NAME, funcName, params); + return DebuggerLib.recordExecStart(LIB_NAME, funcName, params); } function recordExecStart(MCDevKit storage mc, string memory funcName) internal returns(uint) { return mc.recordExecStart(funcName, ""); @@ -62,7 +62,7 @@ library MCDebugLib { đŸ”ŧ Record Finish -----------------------*/ function recordExecFinish(MCDevKit storage mc, uint pid) internal returns(MCDevKit storage) { - Debugger.recordExecFinish(pid); + DebuggerLib.recordExecFinish(pid); return mc; } diff --git a/devkit/utils/global/MCDeployLib.sol b/devkit/utils/global/MCDeployLib.sol index aa17d3f4..2e00c166 100644 --- a/devkit/utils/global/MCDeployLib.sol +++ b/devkit/utils/global/MCDeployLib.sol @@ -46,25 +46,25 @@ library MCDeployLib { } function deploy(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.deploy(mc.bundle.findCurrent().name, mc.bundle.findCurrent(), System.config().defaultOwner(), System.config().defaultInitData()); + return mc.deploy(mc.bundle.findCurrent().name, mc.bundle.findCurrent(), System.Config().defaultOwner(), System.Config().defaultInitData()); } // function deploy(MCDevKit storage mc, string memory name, Bundle storage bundleInfo, address facade, address owner) internal returns(MCDevKit storage) { - // return mc.deploy(name, bundleInfo, facade, owner, System.config().defaultInitData()); + // return mc.deploy(name, bundleInfo, facade, owner, System.Config().defaultInitData()); // } // function deploy(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(MCDevKit storage) { - // return mc.deploy(name, bundleInfo, System.config().defaultInitData(), ); + // return mc.deploy(name, bundleInfo, System.Config().defaultInitData(), ); // } // function deploy(MCDevKit storage mc, Bundle storage bundleInfo) internal returns(MCDevKit storage) { - // return mc.deploy(System.config().defaultName(), bundleInfo, System.config().defaultInitData()); + // return mc.deploy(System.Config().defaultName(), bundleInfo, System.Config().defaultInitData()); // } // function deploy(MCDevKit storage mc, string memory name, bytes memory initData) internal returns(MCDevKit storage) { // return mc.deploy(name, mc.functions.findBundle(name), initData); // } // function deploy(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - // return mc.deploy(name, mc.functions.findBundle(name), System.config().defaultInitData()); + // return mc.deploy(name, mc.functions.findBundle(name), System.Config().defaultInitData()); // } function deploy(MCDevKit storage mc, bytes memory initData) internal returns(MCDevKit storage) { - return mc.deploy(mc.bundle.findCurrent().name, mc.bundle.findCurrent(), System.config().defaultOwner(), initData); + return mc.deploy(mc.bundle.findCurrent().name, mc.bundle.findCurrent(), System.Config().defaultOwner(), initData); } @@ -81,10 +81,10 @@ library MCDeployLib { return mc.deployProxy(name, dictionary, owner.initSetAdminBytes()); } function deployProxy(MCDevKit storage mc, string memory name, Dictionary storage dictionary) internal returns(MCDevKit storage) { - return mc.deployProxy(name, dictionary, System.config().defaultOwner().initSetAdminBytes()); + return mc.deployProxy(name, dictionary, System.Config().defaultOwner().initSetAdminBytes()); } function deployProxy(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - return mc.deployProxy(name, mc.findCurrentDictionary(), System.config().defaultOwner().initSetAdminBytes()); + return mc.deployProxy(name, mc.findCurrentDictionary(), System.Config().defaultOwner().initSetAdminBytes()); } function deployProxy(MCDevKit storage mc, string memory name, bytes memory initData) internal returns(MCDevKit storage) { return mc.deployProxy(name, mc.findCurrentDictionary(), initData); @@ -93,7 +93,7 @@ library MCDeployLib { return mc.deployProxy(mc.proxy.proxies.genUniqueName(), mc.findCurrentDictionary(), initData); } function deployProxy(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.deployProxy(mc.proxy.proxies.genUniqueName(), mc.findCurrentDictionary(), System.config().defaultOwner().initSetAdminBytes()); + return mc.deployProxy(mc.proxy.proxies.genUniqueName(), mc.findCurrentDictionary(), System.Config().defaultOwner().initSetAdminBytes()); } @@ -110,19 +110,19 @@ library MCDeployLib { } function deployDictionary(MCDevKit storage mc) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), mc.bundle.findCurrent(), System.config().defaultOwner()); + return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), mc.bundle.findCurrent(), System.Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, string memory name) internal returns(Dictionary memory) { - return mc.deployDictionary(name, mc.bundle.findCurrent(), System.config().defaultOwner()); + return mc.deployDictionary(name, mc.bundle.findCurrent(), System.Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, Bundle storage bundleInfo) internal returns(Dictionary memory) { - return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), bundleInfo, System.config().defaultOwner()); + return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), bundleInfo, System.Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, address owner) internal returns(Dictionary memory) { return mc.deployDictionary(mc.dictionary.dictionaries.genUniqueName(), mc.bundle.findCurrent(), owner); } function deployDictionary(MCDevKit storage mc, string memory name, Bundle storage bundleInfo) internal returns(Dictionary memory) { - return mc.deployDictionary(name, bundleInfo, System.config().defaultOwner()); + return mc.deployDictionary(name, bundleInfo, System.Config().defaultOwner()); } function deployDictionary(MCDevKit storage mc, string memory name, address owner) internal returns(Dictionary memory) { return mc.deployDictionary(name, mc.bundle.findCurrent(), owner); diff --git a/devkit/utils/global/MCSetupLib.sol b/devkit/utils/global/MCSetupLib.sol index aebd791c..943c97d4 100644 --- a/devkit/utils/global/MCSetupLib.sol +++ b/devkit/utils/global/MCSetupLib.sol @@ -11,7 +11,7 @@ import {System} from "devkit/system/System.sol"; library MCSetupLib { function loadConfig(MCDevKit storage mc) internal returns(MCDevKit storage) { uint pid = mc.recordExecStart("loadConfig"); - System.config().load(); + System.Config().load(); return mc.recordExecFinish(pid); } diff --git a/devkit/utils/global/MCTestLib.sol b/devkit/utils/global/MCTestLib.sol index b95cb26c..6c9c9bb1 100644 --- a/devkit/utils/global/MCTestLib.sol +++ b/devkit/utils/global/MCTestLib.sol @@ -99,10 +99,10 @@ library MCTestLib { return mc.createMockDictionary(name, owner, mc.std.all); } function createMockDictionary(MCDevKit storage mc, string memory name) internal returns(MCDevKit storage) { - return mc.createMockDictionary(name, System.config().defaultOwner(), mc.std.all); + return mc.createMockDictionary(name, System.Config().defaultOwner(), mc.std.all); } function createMockDictionary(MCDevKit storage mc) internal returns(MCDevKit storage) { - return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), System.config().defaultOwner(), mc.std.all); + return mc.createMockDictionary(mc.dictionary.genUniqueMockName(), System.Config().defaultOwner(), mc.std.all); } diff --git a/devkit/utils/mapping/NameGenerator.sol b/devkit/utils/mapping/NameGenerator.sol index 59853472..192287d1 100644 --- a/devkit/utils/mapping/NameGenerator.sol +++ b/devkit/utils/mapping/NameGenerator.sol @@ -22,7 +22,7 @@ library NameGenerator { đŸ—‚ī¸ Bundle Mapping --------------------------*/ function genUniqueName(mapping(string => Bundle) storage bundle, string memory baseName) internal returns(string memory name) { - ScanRange memory range = System.config().SCAN_RANGE; + ScanRange memory range = System.Config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = baseName.toSequential(i); if (bundle[name].hasNotName()) return name; // TODO @@ -30,7 +30,7 @@ library NameGenerator { Validate.MUST_FoundInRange(); } function genUniqueName(mapping(string => Bundle) storage bundle) internal returns(string memory name) { - return genUniqueName(bundle, System.config().DEFAULT_BUNDLE_NAME); + return genUniqueName(bundle, System.Config().DEFAULT_BUNDLE_NAME); } @@ -38,7 +38,7 @@ library NameGenerator { 🧩 Function Mapping ---------------------------*/ function genUniqueName(mapping(string => Function) storage func, string memory baseName) internal returns(string memory name) { - ScanRange memory range = System.config().SCAN_RANGE; + ScanRange memory range = System.Config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = baseName.toSequential(i); if (func[name].notExists()) return name; @@ -46,7 +46,7 @@ library NameGenerator { Validate.MUST_FoundInRange(); } function genUniqueName(mapping(string => Function) storage func) internal returns(string memory name) { - return genUniqueName(func, System.config().DEFAULT_FUNCTION_NAME); + return genUniqueName(func, System.Config().DEFAULT_FUNCTION_NAME); } @@ -54,7 +54,7 @@ library NameGenerator { 📚 Dictionary Mapping -----------------------------*/ function genUniqueName(mapping(string => Dictionary) storage dictionary, string memory baseName) internal returns(string memory name) { - ScanRange memory range = System.config().SCAN_RANGE; + ScanRange memory range = System.Config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = baseName.toSequential(i); if (dictionary[name].notExists()) return name; @@ -63,19 +63,19 @@ library NameGenerator { } /*----- Dictionary -----*/ function genUniqueName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { - return genUniqueName(dictionary, System.config().DEFAULT_DICTIONARY_NAME); + return genUniqueName(dictionary, System.Config().DEFAULT_DICTIONARY_NAME); } /*----- Dictionary -----*/ function genUniqueDuplicatedName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { - return genUniqueName(dictionary, System.config().DEFAULT_DICTIONARY_DUPLICATED_NAME); + return genUniqueName(dictionary, System.Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); } /*----- Mock Dictionary -----*/ function genUniqueMockName(mapping(string => Dictionary) storage dictionary) internal returns(string memory name) { - return genUniqueName(dictionary, System.config().DEFAULT_DICTIONARY_MOCK_NAME); + return genUniqueName(dictionary, System.Config().DEFAULT_DICTIONARY_MOCK_NAME); } // function genUniqueName(DictionaryRegistry storage dictionaries, string memory baseName) internal returns(string memory name) { // uint pid = dictionaries.startProcess("genUniqueName"); - // ScanRange memory range = System.config().SCAN_RANGE; + // ScanRange memory range = System.Config().SCAN_RANGE; // for (uint i = range.START; i <= range.END; ++i) { // name = baseName.toSequential(i); // if (dictionaries.existsInDeployed(name).isFalse()) return name.recordExecFinish(pid); @@ -83,10 +83,10 @@ library NameGenerator { // throwError(ERR.FIND_NAME_OVER_RANGE); // } // function genUniqueName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { - // return dictionaries.genUniqueName(System.config().DEFAULT_DICTIONARY_NAME); + // return dictionaries.genUniqueName(System.Config().DEFAULT_DICTIONARY_NAME); // } // function genUniqueDuplicatedName(DictionaryRegistry storage dictionaries) internal returns(string memory name) { - // return dictionaries.genUniqueName(System.config().DEFAULT_DICTIONARY_DUPLICATED_NAME); + // return dictionaries.genUniqueName(System.Config().DEFAULT_DICTIONARY_DUPLICATED_NAME); // } @@ -95,7 +95,7 @@ library NameGenerator { -------------------------*/ /*----- Mock Proxy -----*/ function genUniqueName(mapping(string => Proxy) storage proxy, string memory baseName) internal returns(string memory name) { - ScanRange memory range = System.config().SCAN_RANGE; + ScanRange memory range = System.Config().SCAN_RANGE; for (uint i = range.START; i <= range.END; ++i) { name = baseName.toSequential(i); if (proxy[name].notExists()) return name; @@ -104,11 +104,11 @@ library NameGenerator { } /*----- Proxy -----*/ function genUniqueName(mapping(string => Proxy) storage proxy) internal returns(string memory name) { - return genUniqueName(proxy, System.config().DEFAULT_PROXY_NAME); + return genUniqueName(proxy, System.Config().DEFAULT_PROXY_NAME); } /*----- Mock Proxy -----*/ function genUniqueMockName(mapping(string => Proxy) storage proxy) internal returns(string memory name) { - return genUniqueName(proxy, System.config().DEFAULT_PROXY_MOCK_NAME); + return genUniqueName(proxy, System.Config().DEFAULT_PROXY_MOCK_NAME); } } diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index 18c71622..f4253d12 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -8,7 +8,6 @@ import {Inspector} from "devkit/types/Inspector.sol"; import {TypeConverter} from "devkit/types/TypeConverter.sol"; using TypeConverter for string; -import {Config} from "devkit/system/Config.sol"; import {ERR} from "devkit/system/message/ERR.sol"; import {Bundle} from "devkit/core/Bundle.sol"; From 213ac08a89fab3ac5ec923be714930bb80bf84ec Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 15 Apr 2024 11:50:32 +0900 Subject: [PATCH 107/111] Update ProcessLib --- devkit/core/Bundle.sol | 2 +- devkit/core/Dictionary.sol | 2 +- devkit/core/Function.sol | 2 +- devkit/core/Proxy.sol | 2 +- devkit/registry/BundleRegistry.sol | 2 +- devkit/registry/DictionaryRegistry.sol | 2 +- devkit/registry/FunctionRegistry.sol | 2 +- devkit/registry/ProxyRegistry.sol | 2 +- devkit/registry/StdFunctions.sol | 2 +- devkit/registry/StdRegistry.sol | 2 +- devkit/registry/context/Current.sol | 2 +- devkit/system/System.sol | 4 +- devkit/system/debug/Debugger.sol | 60 ++++++----------- devkit/system/debug/Logger.sol | 2 +- .../debug/{ProcessLib.sol => Process.sol} | 65 +++++++++++++------ devkit/types/StringUtils.sol | 4 +- devkit/utils/global/MCDebugLib.sol | 6 +- 17 files changed, 82 insertions(+), 81 deletions(-) rename devkit/system/debug/{ProcessLib.sol => Process.sol} (76%) diff --git a/devkit/core/Bundle.sol b/devkit/core/Bundle.sol index c7bf2df2..059ff9a5 100644 --- a/devkit/core/Bundle.sol +++ b/devkit/core/Bundle.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; using ProcessLib for Bundle global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Bundle global; diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 860fd0d5..84126cad 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; using ProcessLib for Dictionary global; import {Params} from "devkit/system/debug/Params.sol"; import {Inspector} from "devkit/types/Inspector.sol"; diff --git a/devkit/core/Function.sol b/devkit/core/Function.sol index 574666f3..5c898169 100644 --- a/devkit/core/Function.sol +++ b/devkit/core/Function.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; using ProcessLib for Function global; import {Dumper} from "devkit/system/debug/Dumper.sol"; using Dumper for Function global; diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index 902d58a9..31de6de8 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; using ProcessLib for Proxy global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for Proxy global; diff --git a/devkit/registry/BundleRegistry.sol b/devkit/registry/BundleRegistry.sol index 11752f8d..01ee5966 100644 --- a/devkit/registry/BundleRegistry.sol +++ b/devkit/registry/BundleRegistry.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; using ProcessLib for BundleRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for BundleRegistry global; diff --git a/devkit/registry/DictionaryRegistry.sol b/devkit/registry/DictionaryRegistry.sol index 72ce9fba..d9885776 100644 --- a/devkit/registry/DictionaryRegistry.sol +++ b/devkit/registry/DictionaryRegistry.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; using ProcessLib for DictionaryRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for DictionaryRegistry global; diff --git a/devkit/registry/FunctionRegistry.sol b/devkit/registry/FunctionRegistry.sol index 6778fc10..7ee50187 100644 --- a/devkit/registry/FunctionRegistry.sol +++ b/devkit/registry/FunctionRegistry.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; using ProcessLib for FunctionRegistry global; // Validation import {Validate} from "devkit/system/validate/Validate.sol"; diff --git a/devkit/registry/ProxyRegistry.sol b/devkit/registry/ProxyRegistry.sol index 451d481f..b902fcbd 100644 --- a/devkit/registry/ProxyRegistry.sol +++ b/devkit/registry/ProxyRegistry.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; using ProcessLib for ProxyRegistry global; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for ProxyRegistry global; diff --git a/devkit/registry/StdFunctions.sol b/devkit/registry/StdFunctions.sol index 7c3b548a..5b92bd45 100644 --- a/devkit/registry/StdFunctions.sol +++ b/devkit/registry/StdFunctions.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; using ProcessLib for StdFunctions global; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for StdFunctions global; diff --git a/devkit/registry/StdRegistry.sol b/devkit/registry/StdRegistry.sol index 5674e1c9..00809212 100644 --- a/devkit/registry/StdRegistry.sol +++ b/devkit/registry/StdRegistry.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.24; /**--------------------- Support Methods -----------------------*/ -import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; using ProcessLib for StdRegistry global; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for StdRegistry global; diff --git a/devkit/registry/context/Current.sol b/devkit/registry/context/Current.sol index 93e685c1..45458872 100644 --- a/devkit/registry/context/Current.sol +++ b/devkit/registry/context/Current.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; Support Methods -----------------------*/ import {Params} from "devkit/system/debug/Params.sol"; -import {ProcessLib} from "devkit/system/debug/ProcessLib.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; using ProcessLib for Current global; // Validation import {Validate} from "devkit/system/validate/Validate.sol"; diff --git a/devkit/system/System.sol b/devkit/system/System.sol index 976ee562..c6ef26ee 100644 --- a/devkit/system/System.sol +++ b/devkit/system/System.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {ConfigState} from "devkit/system/Config.sol"; -import {DebuggerState} from "devkit/system/debug/Debugger.sol"; +import {Debugger} from "devkit/system/debug/Debugger.sol"; /**===============\ | đŸ’ģ System | @@ -13,7 +13,7 @@ library System { assembly { ref.slot := 0x43faf0b0e69b78a7870a9a7da6e0bf9d6f14028444e1b48699a33401cb840400 } } - function Debug() internal pure returns(DebuggerState storage ref) { + function Debug() internal pure returns(Debugger storage ref) { assembly { ref.slot := 0x03d3692c02b7cdcaf0187e8ede4101c401cc53a33aa7e03ef4682fcca8a55300 } } diff --git a/devkit/system/debug/Debugger.sol b/devkit/system/debug/Debugger.sol index 3fcbc308..c9caca71 100644 --- a/devkit/system/debug/Debugger.sol +++ b/devkit/system/debug/Debugger.sol @@ -6,89 +6,67 @@ import {console2, StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; import {Logger} from "./Logger.sol"; import {System} from "devkit/system/System.sol"; +import {Process} from "devkit/system/debug/Process.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for bool; -using DebuggerLib for DebuggerState global; +/**=================\ +| 🐞 Debugger | +\==================*/ +using DebuggerLib for Debugger global; /// @custom:storage-location erc7201:mc.devkit.debugger -struct DebuggerState { +struct Debugger { Logger.LogLevel logLevel; string[] errorLocationStack; Process[] processes; uint nextPid; } - struct Process { - string libName; - string funcName; - string params; - } - - -/**=================\ -| 🐞 Debugger | -\==================*/ library DebuggerLib { /**------------------------- đŸ•šī¸ Logging Control ---------------------------*/ - function startDebug(DebuggerState storage debugger) internal { + function startDebug(Debugger storage debugger) internal { setLogLevel(debugger, Logger.LogLevel.Debug); } - function startInfo(DebuggerState storage debugger) internal { + function startInfo(Debugger storage debugger) internal { setLogLevel(debugger, Logger.LogLevel.Info); } - function startWarn(DebuggerState storage debugger) internal { + function startWarn(Debugger storage debugger) internal { setLogLevel(debugger, Logger.LogLevel.Warn); } - function startError(DebuggerState storage debugger) internal { + function startError(Debugger storage debugger) internal { setLogLevel(debugger, Logger.LogLevel.Error); } - function startCritical(DebuggerState storage debugger) internal { + function startCritical(Debugger storage debugger) internal { setLogLevel(debugger, Logger.LogLevel.Critical); } - function stopLog(DebuggerState storage debugger) internal { + function stopLog(Debugger storage debugger) internal { setLogLevel(debugger, Logger.LogLevel.Disable); } - function setLogLevel(DebuggerState storage debugger, Logger.LogLevel level) internal { + function setLogLevel(Debugger storage debugger, Logger.LogLevel level) internal { debugger.logLevel = level; } - function isDisabled(DebuggerState storage debugger) internal returns(bool) { + function isDisabled(Debugger storage debugger) internal returns(bool) { return debugger.logLevel == Logger.LogLevel.Disable; } - function isDebug(DebuggerState storage debugger) internal returns(bool) { + function isDebug(Debugger storage debugger) internal returns(bool) { return debugger.logLevel == Logger.LogLevel.Debug; } - function isInfo(DebuggerState storage debugger) internal returns(bool) { + function isInfo(Debugger storage debugger) internal returns(bool) { return debugger.logLevel == Logger.LogLevel.Info; } - function isWarm(DebuggerState storage debugger) internal returns(bool) { + function isWarm(Debugger storage debugger) internal returns(bool) { return debugger.logLevel == Logger.LogLevel.Warn; } - function isError(DebuggerState storage debugger) internal returns(bool) { + function isError(Debugger storage debugger) internal returns(bool) { return debugger.logLevel == Logger.LogLevel.Error; } - function isCritical(DebuggerState storage debugger) internal returns(bool) { + function isCritical(Debugger storage debugger) internal returns(bool) { return debugger.logLevel == Logger.LogLevel.Critical; } - /**---------------------------- - 📈 Execution Tracking - ------------------------------*/ - function recordExecStart(string memory libName, string memory funcName, string memory params) internal returns(uint pid) { - if (System.Config().RECORD_EXECUTION_PROCESS.isFalse()) return 0; - pid = System.Debug().nextPid; - System.Debug().processes.push(Process(libName, funcName, params)); - Logger.logExecStart(pid, libName, funcName); - System.Debug().nextPid++; - } - - function recordExecFinish(uint pid) internal { - if (System.Config().RECORD_EXECUTION_PROCESS.isFalse()) return; - Process memory current = System.Debug().processes[pid]; - Logger.logExecFinish(pid, current.libName, current.funcName); - } } diff --git a/devkit/system/debug/Logger.sol b/devkit/system/debug/Logger.sol index cec89b75..5c0191dd 100644 --- a/devkit/system/debug/Logger.sol +++ b/devkit/system/debug/Logger.sol @@ -10,7 +10,7 @@ import {CRITICAL} from "devkit/system/message/CRITICAL.sol"; import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/types/StringUtils.sol"; // Debug -import {Process} from "./Debugger.sol"; +import {Process} from "devkit/system/debug/Process.sol"; import {System} from "devkit/system/System.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; diff --git a/devkit/system/debug/ProcessLib.sol b/devkit/system/debug/Process.sol similarity index 76% rename from devkit/system/debug/ProcessLib.sol rename to devkit/system/debug/Process.sol index 69c07d52..0bf242a6 100644 --- a/devkit/system/debug/ProcessLib.sol +++ b/devkit/system/debug/Process.sol @@ -1,7 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {DebuggerLib} from "devkit/system/debug/Debugger.sol"; +import {System} from "devkit/system/System.sol"; +import {Debugger, DebuggerLib} from "devkit/system/debug/Debugger.sol"; +import {Logger} from "devkit/system/debug/Logger.sol"; +import {Inspector} from "devkit/types/Inspector.sol"; + using Inspector for bool; // Core Types import {Function} from "devkit/core/Function.sol"; import {FunctionRegistry} from "devkit/registry/FunctionRegistry.sol"; @@ -19,9 +23,28 @@ import {Current} from "devkit/registry/context/Current.sol"; /**================= â›“ī¸ Process ===================*/ +struct Process { + string libName; + string funcName; + string params; +} library ProcessLib { + /**---------------------------- + 📈 Execution Tracking + ------------------------------*/ + function startProcess(string memory libName, string memory funcName, string memory params) internal returns(uint pid) { + if (System.Config().RECORD_EXECUTION_PROCESS.isFalse()) return 0; + Debugger storage debugger = System.Debug(); + pid = debugger.nextPid; + debugger.processes.push(Process(libName, funcName, params)); + Logger.logExecStart(pid, libName, funcName); + debugger.nextPid++; + } + function finishProcess(uint pid) internal { - DebuggerLib.recordExecFinish(pid); + if (System.Config().RECORD_EXECUTION_PROCESS.isFalse()) return; + Process memory current = System.Debug().processes[pid]; + Logger.logExecFinish(pid, current.libName, current.funcName); } @@ -29,14 +52,14 @@ library ProcessLib { 🧩 Function --------------------*/ function startProcess(Function storage, string memory name, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart("FunctionLib", name, params); + return startProcess("FunctionLib", name, params); } function startProcess(Function storage func, string memory name) internal returns(uint) { return func.startProcess(name, ""); } function finishProcess(Function storage func, uint pid) internal returns(Function storage) { - DebuggerLib.recordExecFinish(pid); + finishProcess(pid); return func; } @@ -44,14 +67,14 @@ library ProcessLib { 🧩 Functions Registry ----------------------------*/ function startProcess(FunctionRegistry storage, string memory name, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart("FunctionRegistry", name, params); + return startProcess("FunctionRegistry", name, params); } function startProcess(FunctionRegistry storage functions, string memory name) internal returns(uint) { return functions.startProcess(name, ""); } function finishProcess(FunctionRegistry storage functions, uint pid) internal returns(FunctionRegistry storage) { - DebuggerLib.recordExecFinish(pid); + finishProcess(pid); return functions; } @@ -60,14 +83,14 @@ library ProcessLib { đŸ—‚ī¸ Bundle ------------------*/ function startProcess(Bundle storage, string memory name, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart("Bundle", name, params); + return startProcess("Bundle", name, params); } function startProcess(Bundle storage bundle, string memory name) internal returns(uint) { return bundle.startProcess(name, ""); } function finishProcess(Bundle storage bundle, uint pid) internal returns(Bundle storage) { - DebuggerLib.recordExecFinish(pid); + finishProcess(pid); return bundle; } @@ -75,14 +98,14 @@ library ProcessLib { 🧩 Bundle Registry ----------------------------*/ function startProcess(BundleRegistry storage, string memory name, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart("BundleRegistry", name, params); + return startProcess("BundleRegistry", name, params); } function startProcess(BundleRegistry storage bundle, string memory name) internal returns(uint) { return bundle.startProcess(name, ""); } function finishProcess(BundleRegistry storage bundle, uint pid) internal returns(BundleRegistry storage) { - DebuggerLib.recordExecFinish(pid); + finishProcess(pid); return bundle; } @@ -91,14 +114,14 @@ library ProcessLib { 🏛 Standard Registry ---------------------------*/ function startProcess(StdRegistry storage, string memory name, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart("StdRegistryLib", name, params); + return startProcess("StdRegistryLib", name, params); } function startProcess(StdRegistry storage std, string memory name) internal returns(uint) { return std.startProcess(name, ""); } function finishProcess(StdRegistry storage std, uint pid) internal returns(StdRegistry storage) { - DebuggerLib.recordExecFinish(pid); + finishProcess(pid); return std; } @@ -107,14 +130,14 @@ library ProcessLib { 🏰 Standard Functions ----------------------------*/ function startProcess(StdFunctions storage, string memory name, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart("StdFunctionsLib", name, params); + return startProcess("StdFunctionsLib", name, params); } function startProcess(StdFunctions storage std, string memory name) internal returns(uint) { return std.startProcess(name, ""); } function finishProcess(StdFunctions storage std, uint pid) internal returns(StdFunctions storage) { - DebuggerLib.recordExecFinish(pid); + finishProcess(pid); return std; } @@ -123,7 +146,7 @@ library ProcessLib { 🏠 Proxy -----------------*/ function startProxyLibProcess(string memory name, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart("ProxyLib", name, params); + return startProcess("ProxyLib", name, params); } function startProxyLibProcess(string memory name) internal returns(uint) { return startProxyLibProcess(name, ""); @@ -142,14 +165,14 @@ library ProcessLib { 🏠 Proxy Registry ------------------------*/ function startProcess(ProxyRegistry storage, string memory name, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart("ProxyRegistryLib", name, params); + return startProcess("ProxyRegistryLib", name, params); } function startProcess(ProxyRegistry storage proxies, string memory name) internal returns(uint) { return proxies.startProcess(name, ""); } function finishProcess(ProxyRegistry storage proxies, uint pid) internal returns(ProxyRegistry storage) { - DebuggerLib.recordExecFinish(pid); + finishProcess(pid); return proxies; } @@ -158,7 +181,7 @@ library ProcessLib { 📚 Dictionary ---------------------*/ function startDictionaryLibProcess(string memory name, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart("DictionaryLib", name, params); + return startProcess("DictionaryLib", name, params); } function startDictionaryLibProcess(string memory name) internal returns(uint) { return startDictionaryLibProcess(name, ""); @@ -177,14 +200,14 @@ library ProcessLib { 📚 Dictionary Registry ------------------------------*/ function startProcess(DictionaryRegistry storage, string memory name, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart("DictionaryRegistryLib", name, params); + return startProcess("DictionaryRegistryLib", name, params); } function startProcess(DictionaryRegistry storage dictionaries, string memory name) internal returns(uint) { return dictionaries.startProcess(name, ""); } function finishProcess(DictionaryRegistry storage dictionaries, uint pid) internal returns(DictionaryRegistry storage) { - DebuggerLib.recordExecFinish(pid); + finishProcess(pid); return dictionaries; } @@ -193,7 +216,7 @@ library ProcessLib { 📸 Current Context --------------------------*/ function startProcess(Current storage, string memory name, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart("CurrentLib", name, params); + return startProcess("CurrentLib", name, params); } function startProcess(Current storage current, string memory name) internal returns(uint) { return current.startProcess(name, ""); diff --git a/devkit/types/StringUtils.sol b/devkit/types/StringUtils.sol index b4690a76..838141fe 100644 --- a/devkit/types/StringUtils.sol +++ b/devkit/types/StringUtils.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; // Validation import {Validate} from "devkit/system/validate/Validate.sol"; import {System} from "devkit/system/System.sol"; -import {DebuggerLib} from "devkit/system/debug/Debugger.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; // Utils import {StdStyle, ForgeHelper, vm} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; @@ -97,7 +97,7 @@ library StringUtils { Record Finish */ function recordExecFinish(string memory str, uint pid) internal returns(string memory) { - DebuggerLib.recordExecFinish(pid); + ProcessLib.finishProcess(pid); return str; } diff --git a/devkit/utils/global/MCDebugLib.sol b/devkit/utils/global/MCDebugLib.sol index 12d8c2a6..26bd6cbe 100644 --- a/devkit/utils/global/MCDebugLib.sol +++ b/devkit/utils/global/MCDebugLib.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; import {MCDevKit} from "devkit/MCDevKit.sol"; import {System} from "devkit/system/System.sol"; // Debug -import {DebuggerLib} from "devkit/system/debug/Debugger.sol"; +import {ProcessLib} from "devkit/system/debug/Process.sol"; import {Logger} from "devkit/system/debug/Logger.sol"; @@ -51,7 +51,7 @@ library MCDebugLib { đŸ”Ŋ Record Start ----------------------*/ function recordExecStart(MCDevKit storage mc, string memory funcName, string memory params) internal returns(uint) { - return DebuggerLib.recordExecStart(LIB_NAME, funcName, params); + return ProcessLib.startProcess(LIB_NAME, funcName, params); } function recordExecStart(MCDevKit storage mc, string memory funcName) internal returns(uint) { return mc.recordExecStart(funcName, ""); @@ -62,7 +62,7 @@ library MCDebugLib { đŸ”ŧ Record Finish -----------------------*/ function recordExecFinish(MCDevKit storage mc, uint pid) internal returns(MCDevKit storage) { - DebuggerLib.recordExecFinish(pid); + ProcessLib.finishProcess(pid); return mc; } From 36e126ecf1dc340b45bc775f22807fe52fa47bf1 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 15 Apr 2024 12:40:40 +0900 Subject: [PATCH 108/111] rename parser to formatter --- devkit/system/debug/Dumper.sol | 6 +-- devkit/system/debug/Formatter.sol | 57 +++++++++++++++++++++++++++++ devkit/system/debug/Logger.sol | 44 ++++++++-------------- devkit/system/debug/Parser.sol | 41 --------------------- devkit/system/validate/Validate.sol | 4 +- 5 files changed, 77 insertions(+), 75 deletions(-) create mode 100644 devkit/system/debug/Formatter.sol delete mode 100644 devkit/system/debug/Parser.sol diff --git a/devkit/system/debug/Dumper.sol b/devkit/system/debug/Dumper.sol index 69018bf2..b1208b92 100644 --- a/devkit/system/debug/Dumper.sol +++ b/devkit/system/debug/Dumper.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {Logger} from "devkit/system/debug/Logger.sol"; -import {Parser} from "devkit/system/debug/Parser.sol"; +import {Formatter} from "devkit/system/debug/Formatter.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; @@ -17,7 +17,7 @@ library Dumper { 🧩 Function ====================*/ function dump(Function storage func) internal returns(Function storage) { - Logger.log(Parser.parse(func)); + Logger.log(Formatter.toString(func)); return func; } @@ -25,7 +25,7 @@ library Dumper { đŸ—‚ī¸ Bundle =================*/ function dump(Bundle storage bundle) internal returns(Bundle storage) { - Logger.log(Parser.parse(bundle)); + Logger.log(Formatter.toString(bundle)); return bundle; } diff --git a/devkit/system/debug/Formatter.sol b/devkit/system/debug/Formatter.sol new file mode 100644 index 00000000..134e8367 --- /dev/null +++ b/devkit/system/debug/Formatter.sol @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Core Types +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +// Utils +import {StringUtils} from "devkit/types/StringUtils.sol"; + using StringUtils for string; +import {StdStyle} from "devkit/utils/ForgeHelper.sol"; + using StdStyle for string; +import {System} from "devkit/system/System.sol"; +import {Process} from "devkit/system/debug/Process.sol"; + + +/**================== + đŸ—’ī¸ Formatter +====================*/ +library Formatter { + + /**================== + 🧩 Function + ====================*/ + function toString(Function memory func) internal returns(string memory message) { + return message .append("Impl: ").append(func.implementation).comma() + .append("Selector: ").append(func.selector).comma() + .append("Name: ").append(func.name); + } + + + /**=============== + đŸ—‚ī¸ Bundle + =================*/ + function toString(Bundle storage bundle) internal returns(string memory message) { + message = message.append("Facade: ").append(bundle.facade); + + Function[] memory _funcs = bundle.functions; + for (uint i; i < _funcs.length; ++i) { + message = message.br().append(toString(_funcs[i])); + } + } + + string constant LOCATION_HEADER = "\n\t at "; + function toString(Process memory proc) internal returns(string memory) { + return LOCATION_HEADER.append(proc.libName.dot().append(proc.funcName).parens().append(proc.params.italic())).dim(); + } + + string constant PID = "pid:"; + function formatPid(uint pid) internal returns(string memory message) { + return message.brackL().append(PID).append(pid).brackR().sp().dim(); + } + function formatProc(uint pid, string memory status, string memory libName, string memory funcName) internal returns(string memory) { + return formatPid(pid).append(status).append(libName.dot().append(funcName)).parens(); + } +} + + diff --git a/devkit/system/debug/Logger.sol b/devkit/system/debug/Logger.sol index 5c0191dd..add3e1fb 100644 --- a/devkit/system/debug/Logger.sol +++ b/devkit/system/debug/Logger.sol @@ -11,14 +11,16 @@ import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/types/StringUtils.sol"; // Debug import {Process} from "devkit/system/debug/Process.sol"; +import {Formatter} from "devkit/system/debug/Formatter.sol"; import {System} from "devkit/system/System.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; -//================ -// 📊 Logger + +/**=============== + 📊 Logger +=================*/ library Logger { - using Logger for *; using StringUtils for string; using StdStyle for string; @@ -62,7 +64,7 @@ library Logger { console2.log( ERR.HEADER.red().br() .indent().append(message) - .append(parseLocations()) + .append(logLocations()) ); } @@ -70,6 +72,13 @@ library Logger { /**----------------------- 🎨 Log Formatting -------------------------*/ + function logLocations() internal returns(string memory locations) { + Process[] memory processes = System.Debug().processes; + for (uint i = processes.length; i > 0; --i) { + locations = locations.append(Formatter.toString(processes[i-1])); + } + } + function logProcess(string memory message) internal { log(message.underline()); } @@ -90,34 +99,11 @@ library Logger { string constant START = "Starting... "; function logExecStart(uint pid, string memory libName, string memory funcName) internal { - log(formatProc(pid, START, libName, funcName)); + log(Formatter.formatProc(pid, START, libName, funcName)); } string constant FINISH = "Finished "; function logExecFinish(uint pid, string memory libName, string memory funcName) internal { - log(formatProc(pid, FINISH, libName, funcName)); - } - - /**--------------- - 📑 Parser - -----------------*/ - function parseLocations() internal returns(string memory locations) { - Process[] memory processes = System.Debug().processes; - for (uint i = processes.length; i > 0; --i) { - locations = locations.append(formatLocation(processes[i-1])); - } - } - - string constant AT = "\n\t at "; - function formatLocation(Process memory proc) internal returns(string memory) { - return AT.append(proc.libName.dot().append(proc.funcName).parens().append(proc.params.italic())).dim(); - } - - string constant PID = "pid:"; - function formatPid(uint pid) internal returns(string memory message) { - return message.brackL().append(PID).append(pid).brackR().sp().dim(); - } - function formatProc(uint pid, string memory status, string memory libName, string memory funcName) internal returns(string memory) { - return formatPid(pid).append(status).append(libName.dot().append(funcName)).parens(); + log(Formatter.formatProc(pid, FINISH, libName, funcName)); } diff --git a/devkit/system/debug/Parser.sol b/devkit/system/debug/Parser.sol deleted file mode 100644 index 5f7e4522..00000000 --- a/devkit/system/debug/Parser.sol +++ /dev/null @@ -1,41 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Core Types -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -// Utils -import {StringUtils} from "devkit/types/StringUtils.sol"; - using StringUtils for string; - - -/**================= - đŸ—’ī¸ Parser -===================*/ -library Parser { - - /**================== - 🧩 Function - ====================*/ - function parse(Function memory func) internal returns(string memory message) { - return message .append("Impl: ").append(func.implementation).comma() - .append("Selector: ").append(func.selector).comma() - .append("Name: ").append(func.name); - } - - - /**=============== - đŸ—‚ī¸ Bundle - =================*/ - function parse(Bundle storage bundle) internal returns(string memory message) { - message = message.append("Facade: ").append(bundle.facade); - - Function[] memory _funcs = bundle.functions; - for (uint i; i < _funcs.length; ++i) { - message = message.br().append(parse(_funcs[i])); - } - } - -} - - diff --git a/devkit/system/validate/Validate.sol b/devkit/system/validate/Validate.sol index 3e8b2562..415a39ec 100644 --- a/devkit/system/validate/Validate.sol +++ b/devkit/system/validate/Validate.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {vm, VmSafe, ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {ERR} from "devkit/system/message/ERR.sol"; -import {Parser} from "devkit/system/debug/Parser.sol"; +import {Formatter} from "devkit/system/debug/Formatter.sol"; import {Logger} from "devkit/system/debug/Logger.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; @@ -121,7 +121,7 @@ library Validate { validate(MUST, bundle.status.notInitialized(), "Bundle already initialized", ""); } function MUST_completed(Bundle storage bundle) internal { - validate(MUST, bundle.isComplete(), "Bundle Not Complete", Parser.parse(bundle)); + validate(MUST, bundle.isComplete(), "Bundle Not Complete", Formatter.toString(bundle)); } function SHOULD_completed(Bundle storage bundle) internal { validate(SHOULD, bundle.isComplete(), "Bundle Not Complete", ""); From a18c757ec979f336e1db0a18bf814b6c44d3e2b9 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 15 Apr 2024 13:07:42 +0900 Subject: [PATCH 109/111] Update Formatter --- devkit/system/debug/Dumper.sol | 2 +- devkit/system/debug/Formatter.sol | 57 ----------- devkit/system/debug/Logger.sol | 3 +- devkit/system/debug/Params.sol | 9 +- devkit/system/debug/Process.sol | 5 + devkit/system/message/CRITICAL.sol | 4 +- devkit/system/message/DEBUG.sol | 4 +- devkit/system/message/ERR.sol | 4 +- devkit/system/message/INFO.sol | 4 +- devkit/system/message/WARN.sol | 4 +- devkit/system/validate/Validate.sol | 3 +- devkit/types/Formatter.sol | 126 +++++++++++++++++++++++++ devkit/types/StringUtils.sol | 104 -------------------- devkit/types/TypeConverter.sol | 23 ----- devkit/types/TypeGuard.sol | 2 - devkit/utils/mapping/NameGenerator.sol | 4 +- test/devkit/global/MCBundle.t.sol | 4 +- 17 files changed, 154 insertions(+), 208 deletions(-) delete mode 100644 devkit/system/debug/Formatter.sol create mode 100644 devkit/types/Formatter.sol delete mode 100644 devkit/types/StringUtils.sol delete mode 100644 devkit/types/TypeConverter.sol diff --git a/devkit/system/debug/Dumper.sol b/devkit/system/debug/Dumper.sol index b1208b92..da19f530 100644 --- a/devkit/system/debug/Dumper.sol +++ b/devkit/system/debug/Dumper.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.24; import {Logger} from "devkit/system/debug/Logger.sol"; -import {Formatter} from "devkit/system/debug/Formatter.sol"; +import {Formatter} from "devkit/types/Formatter.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; import {Bundle} from "devkit/core/Bundle.sol"; diff --git a/devkit/system/debug/Formatter.sol b/devkit/system/debug/Formatter.sol deleted file mode 100644 index 134e8367..00000000 --- a/devkit/system/debug/Formatter.sol +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Core Types -import {Function} from "devkit/core/Function.sol"; -import {Bundle} from "devkit/core/Bundle.sol"; -// Utils -import {StringUtils} from "devkit/types/StringUtils.sol"; - using StringUtils for string; -import {StdStyle} from "devkit/utils/ForgeHelper.sol"; - using StdStyle for string; -import {System} from "devkit/system/System.sol"; -import {Process} from "devkit/system/debug/Process.sol"; - - -/**================== - đŸ—’ī¸ Formatter -====================*/ -library Formatter { - - /**================== - 🧩 Function - ====================*/ - function toString(Function memory func) internal returns(string memory message) { - return message .append("Impl: ").append(func.implementation).comma() - .append("Selector: ").append(func.selector).comma() - .append("Name: ").append(func.name); - } - - - /**=============== - đŸ—‚ī¸ Bundle - =================*/ - function toString(Bundle storage bundle) internal returns(string memory message) { - message = message.append("Facade: ").append(bundle.facade); - - Function[] memory _funcs = bundle.functions; - for (uint i; i < _funcs.length; ++i) { - message = message.br().append(toString(_funcs[i])); - } - } - - string constant LOCATION_HEADER = "\n\t at "; - function toString(Process memory proc) internal returns(string memory) { - return LOCATION_HEADER.append(proc.libName.dot().append(proc.funcName).parens().append(proc.params.italic())).dim(); - } - - string constant PID = "pid:"; - function formatPid(uint pid) internal returns(string memory message) { - return message.brackL().append(PID).append(pid).brackR().sp().dim(); - } - function formatProc(uint pid, string memory status, string memory libName, string memory funcName) internal returns(string memory) { - return formatPid(pid).append(status).append(libName.dot().append(funcName)).parens(); - } -} - - diff --git a/devkit/system/debug/Logger.sol b/devkit/system/debug/Logger.sol index add3e1fb..873569db 100644 --- a/devkit/system/debug/Logger.sol +++ b/devkit/system/debug/Logger.sol @@ -11,7 +11,7 @@ import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; import {StringUtils} from "devkit/types/StringUtils.sol"; // Debug import {Process} from "devkit/system/debug/Process.sol"; -import {Formatter} from "devkit/system/debug/Formatter.sol"; +import {Formatter} from "devkit/types/Formatter.sol"; import {System} from "devkit/system/System.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; @@ -23,6 +23,7 @@ import {Inspector} from "devkit/types/Inspector.sol"; library Logger { using StringUtils for string; using StdStyle for string; + using Formatter for string; enum LogLevel { Disable, // Display no message diff --git a/devkit/system/debug/Params.sol b/devkit/system/debug/Params.sol index ce30106d..12f71eff 100644 --- a/devkit/system/debug/Params.sol +++ b/devkit/system/debug/Params.sol @@ -1,11 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {StringUtils} from "devkit/types/StringUtils.sol"; - using StringUtils for string; -import {TypeConverter} from "devkit/types/TypeConverter.sol"; - using TypeConverter for address; - using TypeConverter for bytes4; +import {Formatter} from "devkit/types/Formatter.sol"; + using Formatter for address; + using Formatter for bytes4; + using Formatter for string; library Params { diff --git a/devkit/system/debug/Process.sol b/devkit/system/debug/Process.sol index 0bf242a6..848336a5 100644 --- a/devkit/system/debug/Process.sol +++ b/devkit/system/debug/Process.sol @@ -48,6 +48,11 @@ library ProcessLib { } + function finishProcess(string memory str, uint pid) internal returns(string memory) { + finishProcess(pid); + return str; + } + /**------------------ 🧩 Function --------------------*/ diff --git a/devkit/system/message/CRITICAL.sol b/devkit/system/message/CRITICAL.sol index 2e2322a7..d2ca9173 100644 --- a/devkit/system/message/CRITICAL.sol +++ b/devkit/system/message/CRITICAL.sol @@ -4,13 +4,13 @@ pragma solidity ^0.8.24; // Utils import {StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; -import {StringUtils} from "devkit/types/StringUtils.sol"; +import {Formatter} from "devkit/types/Formatter.sol"; /// @title Error Message library CRITICAL { string constant HEADER = "\xF0\x9F\x9A\xA8 [CRITICAL] "; function header(string memory body) internal returns(string memory) { - return StringUtils.append(HEADER.red(), body).bold(); + return Formatter.append(HEADER.red(), body).bold(); } } diff --git a/devkit/system/message/DEBUG.sol b/devkit/system/message/DEBUG.sol index 9dcfd913..edd653f9 100644 --- a/devkit/system/message/DEBUG.sol +++ b/devkit/system/message/DEBUG.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; // Utils import {StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; -import {StringUtils} from "devkit/types/StringUtils.sol"; +import {Formatter} from "devkit/types/Formatter.sol"; /// @title Error Message library DEBUG { @@ -29,6 +29,6 @@ library DEBUG { string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; function message(string memory errorBody) internal returns(string memory) { - return StringUtils.append(HEADER, errorBody).bold(); + return Formatter.append(HEADER, errorBody).bold(); } } diff --git a/devkit/system/message/ERR.sol b/devkit/system/message/ERR.sol index 419a5c2b..43460011 100644 --- a/devkit/system/message/ERR.sol +++ b/devkit/system/message/ERR.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; // Utils import {StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; -import {StringUtils} from "devkit/types/StringUtils.sol"; +import {Formatter} from "devkit/types/Formatter.sol"; /// @title Error Message library ERR { @@ -29,6 +29,6 @@ library ERR { string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; function message(string memory errorBody) internal returns(string memory) { - return StringUtils.append(HEADER, errorBody).bold(); + return Formatter.append(HEADER, errorBody).bold(); } } diff --git a/devkit/system/message/INFO.sol b/devkit/system/message/INFO.sol index 4439d995..3c91f4e2 100644 --- a/devkit/system/message/INFO.sol +++ b/devkit/system/message/INFO.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; // Utils import {StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; -import {StringUtils} from "devkit/types/StringUtils.sol"; +import {Formatter} from "devkit/types/Formatter.sol"; /// @title Error Message library INFO { @@ -29,6 +29,6 @@ library INFO { string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; function message(string memory errorBody) internal returns(string memory) { - return StringUtils.append(HEADER, errorBody).bold(); + return Formatter.append(HEADER, errorBody).bold(); } } diff --git a/devkit/system/message/WARN.sol b/devkit/system/message/WARN.sol index c5c22685..6341bc06 100644 --- a/devkit/system/message/WARN.sol +++ b/devkit/system/message/WARN.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; // Utils import {StdStyle} from "devkit/utils/ForgeHelper.sol"; using StdStyle for string; -import {StringUtils} from "devkit/types/StringUtils.sol"; +import {Formatter} from "devkit/types/Formatter.sol"; /// @title Error Message library WARN { @@ -29,6 +29,6 @@ library WARN { string constant NOT_INIT = "Bundle has not initialized yet, please mc.init() first."; function message(string memory errorBody) internal returns(string memory) { - return StringUtils.append(HEADER, errorBody).bold(); + return Formatter.append(HEADER, errorBody).bold(); } } diff --git a/devkit/system/validate/Validate.sol b/devkit/system/validate/Validate.sol index 415a39ec..3fa4cdf1 100644 --- a/devkit/system/validate/Validate.sol +++ b/devkit/system/validate/Validate.sol @@ -2,7 +2,8 @@ pragma solidity ^0.8.24; import {vm, VmSafe, ForgeHelper} from "devkit/utils/ForgeHelper.sol"; import {ERR} from "devkit/system/message/ERR.sol"; -import {Formatter} from "devkit/system/debug/Formatter.sol"; +import {Formatter} from "devkit/types/Formatter.sol"; + using Formatter for string; import {Logger} from "devkit/system/debug/Logger.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; diff --git a/devkit/types/Formatter.sol b/devkit/types/Formatter.sol new file mode 100644 index 00000000..353da99c --- /dev/null +++ b/devkit/types/Formatter.sol @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +// Core Types +import {Function} from "devkit/core/Function.sol"; +import {Bundle} from "devkit/core/Bundle.sol"; +// Utils +import {StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; + using StdStyle for string; +import {System} from "devkit/system/System.sol"; +import {Process} from "devkit/system/debug/Process.sol"; + + +/**================== + đŸ—’ī¸ Formatter +====================*/ +library Formatter { + using Formatter for string; + using Formatter for bytes4; + + /**================== + 🧩 Function + ====================*/ + function toString(Function memory func) internal returns(string memory message) { + return message .append("Impl: ").append(func.implementation).comma() + .append("Selector: ").append(func.selector).comma() + .append("Name: ").append(func.name); + } + + + /**=============== + đŸ—‚ī¸ Bundle + =================*/ + function toString(Bundle storage bundle) internal returns(string memory message) { + message = message.append("Facade: ").append(bundle.facade); + + Function[] memory _funcs = bundle.functions; + for (uint i; i < _funcs.length; ++i) { + message = message.br().append(toString(_funcs[i])); + } + } + + string constant LOCATION_HEADER = "\n\t at "; + function toString(Process memory proc) internal returns(string memory) { + return LOCATION_HEADER.append(proc.libName.dot().append(proc.funcName).parens().append(proc.params.italic())).dim(); + } + + string constant PID = "pid:"; + function formatPid(uint pid) internal returns(string memory message) { + return message.brackL().append(PID).append(pid).brackR().sp().dim(); + } + function formatProc(uint pid, string memory status, string memory libName, string memory funcName) internal returns(string memory) { + return formatPid(pid).append(status).append(libName.dot().append(funcName)).parens(); + } + + + /**=================== + 🧱 Primitives + =====================*/ + /// 📝 String + function append(string memory str, string memory addition) internal returns(string memory) { + return string.concat(str, addition); + } + function append(string memory str, address addr) internal returns(string memory) { + return str.append(vm.toString(addr)); + } + function append(string memory str, bytes4 selector) internal returns(string memory) { + return str.append(selector.toString()); + } + function append(string memory str, uint num) internal returns(string memory) { + return str.append(vm.toString(num)); + } + + function br(string memory str) internal returns(string memory) { + return string.concat(str, "\n"); + } + function sp(string memory str) internal returns(string memory) { + return string.concat(str, " "); + } + function indent(string memory str) internal returns(string memory) { + return string.concat(str, "\t"); + } + function comma(string memory str) internal returns(string memory) { + return string.concat(str, ", "); + } + function dot(string memory str) internal returns(string memory) { + return string.concat(str, "."); + } + function parens(string memory str) internal returns(string memory) { + return string.concat(str, "()"); + } + function brackL(string memory str) internal returns(string memory) { + return string.concat("[", str); + } + function brackR(string memory str) internal returns(string memory) { + return string.concat(str, "]"); + } + + function toSequential(string memory str, uint i) internal returns(string memory) { + return i == 1 ? str : str.append(i); + } + + function toString(address addr) internal pure returns(string memory) { + return vm.toString(addr); + } + + function toString(bytes4 selector) internal pure returns (string memory) { + return vm.toString(selector).substring(10); + } + + function toBytes(string memory str) internal returns (bytes memory) { + return bytes(str); + } + + function substring(string memory str, uint n) internal pure returns (string memory) { + bytes memory strBytes = bytes(str); + bytes memory result = new bytes(n); + for(uint i = 0; i < n; i++) { + result[i] = strBytes[i]; + } + return string(result); + } + +} + + diff --git a/devkit/types/StringUtils.sol b/devkit/types/StringUtils.sol deleted file mode 100644 index 838141fe..00000000 --- a/devkit/types/StringUtils.sol +++ /dev/null @@ -1,104 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -// Validation -import {Validate} from "devkit/system/validate/Validate.sol"; -import {System} from "devkit/system/System.sol"; -import {ProcessLib} from "devkit/system/debug/Process.sol"; -// Utils -import {StdStyle, ForgeHelper, vm} from "devkit/utils/ForgeHelper.sol"; - using StdStyle for string; -import {TypeConverter} from "devkit/types//TypeConverter.sol"; - using TypeConverter for bytes4; - - -/**=====================\ -| 🖋 String Utils | -\======================*/ -using StringUtils for string; -library StringUtils { - /**--------------------------- - đŸ”ĸ Utils for Primitives - -----------------------------*/ - function calcHash(string memory name) internal pure returns(bytes32) { - return keccak256(abi.encode(name)); - } - function safeCalcHash(string memory name) internal returns(bytes32) { - Validate.MUST_NotEmptyName(name); - return name.calcHash(); - } - - // function loadAddress(string memory envKey) internal returns(address) { - // return ForgeHelper.loadAddressFromEnv(envKey); - // } - - function substring(string memory str, uint n) internal pure returns (string memory) { - bytes memory strBytes = bytes(str); - bytes memory result = new bytes(n); - for(uint i = 0; i < n; i++) { - result[i] = strBytes[i]; - } - return string(result); - } - - function toSequential(string memory str, uint i) internal returns(string memory) { - return i == 1 ? str : str.append(i); - } - - - /**---------------- - ➕ Append - ------------------*/ - function append(string memory str, string memory addition) internal returns(string memory) { - return string.concat(str, addition); - } - function append(string memory str, address addr) internal returns(string memory) { - return str.append(vm.toString(addr)); - } - function append(string memory str, bytes4 selector) internal returns(string memory) { - return str.append(selector.toString()); - } - function append(string memory str, uint num) internal returns(string memory) { - return str.append(vm.toString(num)); - } - - function br(string memory str) internal returns(string memory) { - return string.concat(str, "\n"); - } - function sp(string memory str) internal returns(string memory) { - return string.concat(str, " "); - } - function indent(string memory str) internal returns(string memory) { - return string.concat(str, "\t"); - } - function comma(string memory str) internal returns(string memory) { - return string.concat(str, ", "); - } - function dot(string memory str) internal returns(string memory) { - return string.concat(str, "."); - } - function parens(string memory str) internal returns(string memory) { - return string.concat(str, "()"); - } - function brackL(string memory str) internal returns(string memory) { - return string.concat("[", str); - } - function brackR(string memory str) internal returns(string memory) { - return string.concat(str, "]"); - } - - - - - /**---------------- - 🐞 Debug - ------------------*/ - /** - Record Finish - */ - function recordExecFinish(string memory str, uint pid) internal returns(string memory) { - ProcessLib.finishProcess(pid); - return str; - } - -} diff --git a/devkit/types/TypeConverter.sol b/devkit/types/TypeConverter.sol deleted file mode 100644 index 4cb05977..00000000 --- a/devkit/types/TypeConverter.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import {vm} from "devkit/utils/ForgeHelper.sol"; -import {StringUtils} from "devkit/types/StringUtils.sol"; - using StringUtils for string; - -/**=====================\ -| 🔀 Type Converter | -\======================*/ -library TypeConverter { - function toString(address addr) internal pure returns(string memory) { - return vm.toString(addr); - } - - function toString(bytes4 selector) internal pure returns (string memory) { - return vm.toString(selector).substring(10); - } - - function toBytes(string memory str) internal returns (bytes memory) { - return bytes(str); - } -} diff --git a/devkit/types/TypeGuard.sol b/devkit/types/TypeGuard.sol index 26da3619..b7b9fe30 100644 --- a/devkit/types/TypeGuard.sol +++ b/devkit/types/TypeGuard.sol @@ -3,8 +3,6 @@ pragma solidity ^0.8.24; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for bool; -import {TypeConverter} from "devkit/types/TypeConverter.sol"; - using TypeConverter for bool; import {Validate} from "devkit/system/validate/Validate.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; diff --git a/devkit/utils/mapping/NameGenerator.sol b/devkit/utils/mapping/NameGenerator.sol index 192287d1..cd8e4428 100644 --- a/devkit/utils/mapping/NameGenerator.sol +++ b/devkit/utils/mapping/NameGenerator.sol @@ -10,8 +10,8 @@ import {Function} from "devkit/core/Function.sol"; import {Dictionary} from "devkit/core/Dictionary.sol"; import {Proxy} from "devkit/core/Proxy.sol"; // Utils -import {StringUtils} from "devkit/types/StringUtils.sol"; - using StringUtils for string; +import {Formatter} from "devkit/types/Formatter.sol"; + using Formatter for string; /**======================= đŸˇī¸ Name Generator diff --git a/test/devkit/global/MCBundle.t.sol b/test/devkit/global/MCBundle.t.sol index f4253d12..0135fe72 100644 --- a/test/devkit/global/MCBundle.t.sol +++ b/test/devkit/global/MCBundle.t.sol @@ -6,8 +6,8 @@ import {MCDevKitTest} from "devkit/MCTest.sol"; import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for string; -import {TypeConverter} from "devkit/types/TypeConverter.sol"; - using TypeConverter for string; +import {Formatter} from "devkit/types/Formatter.sol"; + using Formatter for string; import {ERR} from "devkit/system/message/ERR.sol"; import {Bundle} from "devkit/core/Bundle.sol"; From de4ac2070eb8ffb6c2f29389879b8ffd7e523bd5 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 15 Apr 2024 13:15:56 +0900 Subject: [PATCH 110/111] Remove oz lib --- .gitmodules | 3 --- devkit/system/debug/Logger.sol | 2 -- devkit/system/validate/Validate.sol | 2 -- lib/openzeppelin-contracts | 1 - remappings.txt | 2 +- 5 files changed, 1 insertion(+), 9 deletions(-) delete mode 160000 lib/openzeppelin-contracts diff --git a/.gitmodules b/.gitmodules index b13777ca..38d8756a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "lib/ucs-contracts"] path = lib/ucs-contracts url = https://github.com/ecdysisxyz/ucs-contracts -[submodule "lib/openzeppelin-contracts"] - path = lib/openzeppelin-contracts - url = https://github.com/openzeppelin/openzeppelin-contracts diff --git a/devkit/system/debug/Logger.sol b/devkit/system/debug/Logger.sol index 873569db..20fef8f7 100644 --- a/devkit/system/debug/Logger.sol +++ b/devkit/system/debug/Logger.sol @@ -8,7 +8,6 @@ import {ERR} from "devkit/system/message/ERR.sol"; import {CRITICAL} from "devkit/system/message/CRITICAL.sol"; // Utils import {console2, StdStyle, vm} from "devkit/utils/ForgeHelper.sol"; -import {StringUtils} from "devkit/types/StringUtils.sol"; // Debug import {Process} from "devkit/system/debug/Process.sol"; import {Formatter} from "devkit/types/Formatter.sol"; @@ -21,7 +20,6 @@ import {Inspector} from "devkit/types/Inspector.sol"; 📊 Logger =================*/ library Logger { - using StringUtils for string; using StdStyle for string; using Formatter for string; diff --git a/devkit/system/validate/Validate.sol b/devkit/system/validate/Validate.sol index 3fa4cdf1..bf38db38 100644 --- a/devkit/system/validate/Validate.sol +++ b/devkit/system/validate/Validate.sol @@ -12,8 +12,6 @@ import {Inspector} from "devkit/types/Inspector.sol"; using Inspector for bool; using Inspector for uint256; // Utils -import {StringUtils} from "devkit/types/StringUtils.sol"; - using StringUtils for string; import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts deleted file mode 160000 index 9558e546..00000000 --- a/lib/openzeppelin-contracts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9558e546d9996d533eeb5151569a52d611eca08b diff --git a/remappings.txt b/remappings.txt index f257e9f1..2f552ef8 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,4 +1,4 @@ -@oz.mc/=lib/openzeppelin-contracts/contracts/ +@oz.mc/=lib/ucs-contracts/lib/openzeppelin-contracts/contracts/ @ucs.mc/=lib/ucs-contracts/src/ mc-std/=src/std/ devkit/=devkit/ From 206e18ee8a206bbb31f79c1ba0f6767633eb74a7 Mon Sep 17 00:00:00 2001 From: Kai Hiroi Date: Mon, 15 Apr 2024 16:23:09 +0900 Subject: [PATCH 111/111] Update UCS Contracts Lib --- devkit/core/Dictionary.sol | 6 +++--- devkit/core/Proxy.sol | 4 ++-- devkit/mocks/DictionaryMock.sol | 6 +++--- lib/ucs-contracts | 2 +- src/std/functions/Clone.sol | 6 +++--- src/std/functions/GetDeps.sol | 6 +++--- src/std/functions/Receive.sol | 3 --- src/std/functions/protected/UpgradeDictionary.sol | 4 ++-- src/std/interfaces/IStd.sol | 4 ++-- 9 files changed, 19 insertions(+), 22 deletions(-) diff --git a/devkit/core/Dictionary.sol b/devkit/core/Dictionary.sol index 84126cad..d20101b4 100644 --- a/devkit/core/Dictionary.sol +++ b/devkit/core/Dictionary.sol @@ -19,7 +19,7 @@ import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; import {DictionaryMock} from "devkit/mocks/DictionaryMock.sol"; // External Libs import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; -import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; +import {Dictionary as UCSDictionary} from "@ucs.mc/dictionary/Dictionary.sol"; // Core Types import {Function} from "devkit/core/Function.sol"; @@ -52,7 +52,7 @@ library DictionaryLib { Validate.MUST_AddressIsNotZero(owner); /// @dev Until Etherscan supports UCS, we are deploying contracts with additional features for Etherscan compatibility by default. return Dictionary({ - addr: address(new DictionaryEtherscan(owner)), + addr: address(new UCSDictionary(owner)), kind: DictionaryKind.Verifiable, status: TypeStatus.Building }).finishProcess(pid); @@ -124,7 +124,7 @@ library DictionaryLib { uint pid = ProcessLib.startDictionaryLibProcess("upgradeFacade"); Validate.MUST_AddressIsContract(newFacade); Validate.MUST_Verifiable(dictionary); - DictionaryEtherscan(dictionary.addr).upgradeFacade(newFacade); + IDictionary(dictionary.addr).upgradeFacade(newFacade); return dictionary.finishProcess(pid); } diff --git a/devkit/core/Proxy.sol b/devkit/core/Proxy.sol index 31de6de8..026782bd 100644 --- a/devkit/core/Proxy.sol +++ b/devkit/core/Proxy.sol @@ -14,7 +14,7 @@ import {TypeGuard, TypeStatus} from "devkit/types/TypeGuard.sol"; using TypeGuard for Proxy global; // External Lib Contract -import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; +import {Proxy as UCSProxy} from "@ucs.mc/proxy/Proxy.sol"; // Mock Contract import {ProxySimpleMock} from "devkit/mocks/ProxySimpleMock.sol"; @@ -41,7 +41,7 @@ library ProxyLib { uint pid = ProcessLib.startProxyLibProcess("deploy"); Validate.MUST_haveContract(dictionary); return Proxy({ - addr: address(new ERC7546ProxyEtherscan(dictionary.addr, initData)), + addr: address(new UCSProxy(dictionary.addr, initData)), kind: ProxyKind.Verifiable, status: TypeStatus.Building }).finishProcess(pid); diff --git a/devkit/mocks/DictionaryMock.sol b/devkit/mocks/DictionaryMock.sol index b4a1101c..70ad52e5 100644 --- a/devkit/mocks/DictionaryMock.sol +++ b/devkit/mocks/DictionaryMock.sol @@ -4,13 +4,13 @@ pragma solidity ^0.8.24; // Core import {Function} from "devkit/core/Function.sol"; // External Lib -import {DictionaryEtherscan} from "@ucs.mc/dictionary/DictionaryEtherscan.sol"; +import {Dictionary} from "@ucs.mc/dictionary/Dictionary.sol"; /** @title Mock Dictionary Contract */ -contract DictionaryMock is DictionaryEtherscan { - constructor (address owner, Function[] memory functions) DictionaryEtherscan(owner) { +contract DictionaryMock is Dictionary { + constructor (address owner, Function[] memory functions) Dictionary(owner) { for (uint i; i < functions.length; ++i) { setImplementation(functions[i].selector, functions[i].implementation); } diff --git a/lib/ucs-contracts b/lib/ucs-contracts index fddfe14d..eaaf372d 160000 --- a/lib/ucs-contracts +++ b/lib/ucs-contracts @@ -1 +1 @@ -Subproject commit fddfe14d21ce28ac0a015f474ef406706ddf773a +Subproject commit eaaf372d64785bac1ada738c2460fd47813f7dd3 diff --git a/src/std/functions/Clone.sol b/src/std/functions/Clone.sol index 4508e914..2d4bb920 100644 --- a/src/std/functions/Clone.sol +++ b/src/std/functions/Clone.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.22; -import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; -import {ERC7546Utils} from "@ucs.mc/proxy/ERC7546Utils.sol"; +import {Proxy} from "@ucs.mc/proxy/Proxy.sol"; +import {ProxyUtils} from "@ucs.mc/proxy/ProxyUtils.sol"; /** < MC Standard Function > @@ -15,7 +15,7 @@ contract Clone { event ProxyCloned(address proxy); function clone(bytes calldata initData) external returns (address proxy) { - proxy = address(new ERC7546ProxyEtherscan(ERC7546Utils.getDictionary(), initData)); + proxy = address(new Proxy(ProxyUtils.getDictionary(), initData)); emit ProxyCloned(proxy); } diff --git a/src/std/functions/GetDeps.sol b/src/std/functions/GetDeps.sol index 533a5aa2..dfa578f3 100644 --- a/src/std/functions/GetDeps.sol +++ b/src/std/functions/GetDeps.sol @@ -3,8 +3,8 @@ pragma solidity ^0.8.22; import {Dep} from "../storage/Schema.sol"; -import {ERC7546Utils} from "@ucs.mc/proxy/ERC7546Utils.sol"; -import {DictionaryBase} from "@ucs.mc/dictionary/DictionaryBase.sol"; +import {ProxyUtils} from "@ucs.mc/proxy/ProxyUtils.sol"; +import {IDictionary} from "@ucs.mc/dictionary/IDictionary.sol"; /** < MC Standard Function > @@ -16,7 +16,7 @@ contract GetDeps { /// DO NOT USE STORAGE DIRECTLY !!! function getDeps() external view returns(Dep[] memory) { - DictionaryBase dictionary = DictionaryBase(ERC7546Utils.getDictionary()); // TODO IDictionary + IDictionary dictionary = IDictionary(ProxyUtils.getDictionary()); bytes4[] memory selectors = dictionary.supportsInterfaces(); Dep[] memory deps = new Dep[](selectors.length); for (uint i; i < selectors.length; ++i) { diff --git a/src/std/functions/Receive.sol b/src/std/functions/Receive.sol index 8075333b..36dc2a22 100644 --- a/src/std/functions/Receive.sol +++ b/src/std/functions/Receive.sol @@ -1,9 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.22; -import {ERC7546ProxyEtherscan} from "@ucs.mc/proxy/ERC7546ProxyEtherscan.sol"; -import {ERC7546Utils} from "@ucs.mc/proxy/ERC7546Utils.sol"; - /** < MC Standard Function > @title Receive diff --git a/src/std/functions/protected/UpgradeDictionary.sol b/src/std/functions/protected/UpgradeDictionary.sol index 9af9da9a..b263ee96 100644 --- a/src/std/functions/protected/UpgradeDictionary.sol +++ b/src/std/functions/protected/UpgradeDictionary.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {ERC7546Utils} from "@ucs.mc/proxy/ERC7546Utils.sol"; +import {ProxyUtils} from "@ucs.mc/proxy/ProxyUtils.sol"; import {ProtectionBase} from "./utils/ProtectionBase.sol"; /** @@ -14,7 +14,7 @@ contract UpgradeDictionary is ProtectionBase { /// DO NOT USE STORAGE DIRECTLY !!! function upgradeDictionary(address newDictionary) external onlyAdmin { - ERC7546Utils.upgradeDictionaryToAndCall({ + ProxyUtils.upgradeDictionaryToAndCall({ newDictionary: newDictionary, data: "" }); diff --git a/src/std/interfaces/IStd.sol b/src/std/interfaces/IStd.sol index a077ec52..423f75ff 100644 --- a/src/std/interfaces/IStd.sol +++ b/src/std/interfaces/IStd.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {ERC7546ProxyEvents} from "@ucs.mc/proxy/ERC7546ProxyEvents.sol"; +import {IProxy} from "@ucs.mc/proxy/IProxy.sol"; import {Dep} from "../storage/Schema.sol"; -interface IStd is ERC7546ProxyEvents { +interface IStd is IProxy { function clone(bytes calldata initData) external returns (address proxy); function getDeps() external view returns(Dep[] memory); function featureToggle(bytes4 selector) external;