forked from synapsecns/sanguine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeployBasicContract.s.sol
68 lines (61 loc) · 3.24 KB
/
DeployBasicContract.s.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {BasicContract} from "./BasicContract.sol";
import {SynapseScript, StringUtils} from "../src/SynapseScript.sol";
/// Note: it is recommended to handle the contract configuration in a separate script.
/// - `deployAndSave` will skip the deployment if the contract artifact is already saved in the deployments directory.
/// - `deployAndSave` will return the deployment address regardless of whether the contract
/// has been deployed previously or just now.
/// - `deployAndSaveAs` behaves similarly to `deployAndSave`, but allows for custom aliasing.
contract DeployBasicContract is SynapseScript {
using StringUtils for *;
string public contractName = "BasicContract";
/// @notice Showcases different deployment methods.
function run() external broadcastWithHooks {
// Deploy using the contract-specific callback
deployAndSave({contractName: contractName, deployContractFunc: cbDeployBasicContract});
// Or, deploy using a generic callback for vanilla deployment
// Need to craft the constructor arguments manually
deployAndSave({contractName: contractName, constructorArgs: abi.encode(42), deployCodeFunc: cbDeploy});
// Or, use the generic callback for CREATE2 deployment
// Need to craft the constructor arguments manually
deployAndSave({contractName: contractName, constructorArgs: abi.encode(42), deployCodeFunc: cbDeployCreate2});
}
/// @notice Showcases how to deploy a contract with a custom alias.
/// Note: it is recommended to handle the contract configuration in a separate script.
function run(string memory aliasSuffix) external broadcastWithHooks {
// Typical alias derivation scheme
string memory contractAlias = contractName.concat(".", aliasSuffix);
// Deploy using the contract-specific callback
deployAndSaveAs({
contractName: contractName,
contractAlias: contractAlias,
deployContractFunc: cbDeployBasicContract
});
// Or, deploy using a generic callback for vanilla deployment
// Need to craft the constructor arguments manually
deployAndSaveAs({
contractName: contractName,
contractAlias: contractAlias,
constructorArgs: abi.encode(42),
deployCodeFunc: cbDeploy
});
// Or, use the generic callback for CREATE2 deployment
// Need to craft the constructor arguments manually
deployAndSaveAs({
contractName: contractName,
contractAlias: contractAlias,
constructorArgs: abi.encode(42),
deployCodeFunc: cbDeployCreate2
});
}
/// @notice Contract-specific deployment callback.
/// - MUST follow the interface
/// - function deployContractFunc() internal returns (address deployedAt, bytes memory constructorArgs)
/// - MUST return the correct deployment address and constructor arguments
/// - SHOULD only deploy contract without any additional configuration
function cbDeployBasicContract() internal returns (address deployedAt, bytes memory constructorArgs) {
constructorArgs = abi.encode(42);
deployedAt = address(new BasicContract(42));
}
}