Go wilderness with UCS
Let's start with experiencing the simplest use case of the Upgradeable Clone Standard (UCS). This walkthrough will guide you through:
- Deploying a UCS proxy contract with default Operations (Ops)
- Enabling a CloneOp
- Trying out cloning
Deploying the Proxy Contract​
First, we'll deploy the UCS proxy contract along with the default Ops.
1. Create Script​
Create a new script file at ./script/Deployment.s.sol.
2. Import UCSScriptBase​
Import the utils/UCSScriptBase.sol from the ucs-ops library into your script.
import { UCSScriptBase } from "@ucs-ops/utils/UCSScriptBase.sol";
3. Define run Function​
Declare a run() function as public and apply the startBroadcastWithDeployerPrivKey modifier. Inside this function, call the newProxy() to deploy the proxy contract.
function run() public startBroadcastWithDeployerPrivKey {
newProxy();
}
4. Execute Script​
Run the script using Foundry with the command:
forge script Deployment -vvvvv
Ensure the script executes successfully.
Registering Clone Op​
Next, we'll register a CloneOp in the Dictionary contract.
5. Update run Function​
Modify the run() function to include registration of the CloneOp in the Dictionary contract.
address proxy = newProxy();
address dictionary = getDictionary(proxy);
opNames.push(OpName.Clone);
setOps(dictionary, opNames);
Executing Clone​
Finally, let's execute the Clone operation.
6. Execute CloneOp​
Use the ICloneOp interface to execute the CloneOp.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import { UCSScriptBase } from "@ucs-ops/utils/UCSScriptBase.sol";
import { ICloneOp } from "@ucs-ops/src/interfaces/ops/ICloneOp.sol";
contract Deployment is UCSScriptBase {
function run() public startBroadcastWithDeployerPrivKey {
address proxy = newProxy();
address dictionary = getDictionary(proxy);
opNames.push(OpName.Clone);
setOps(dictionary, opNames);
ICloneOp(proxy).clone("");
}
}
7. Verify in Trace​
Check the trace to confirm that the same Dictionary contract is registered with the cloned Proxy contract.
forge script Deployment -vvvvv
Congratulations🎉​
You've now covered the basic usage of UCS.
From here, you can explore combining Standard Ops or creating Custom Ops to develop your unique contracts!