Skip to content

Commit

Permalink
chore: deployment scripts (#163)
Browse files Browse the repository at this point in the history
* chore: add compute address script

* chore(deployment): fix check tdoc existence

* chore(deployment): output deployed address

* chore(deployment): support ledger in deploy script
  • Loading branch information
superical authored Apr 2, 2024
1 parent 87d9400 commit e317640
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 5 deletions.
8 changes: 7 additions & 1 deletion bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ if [[ "$4" != "" && "$5" != -* ]]; then
fi

# forge command
COMMAND="forge script \"$SCRIPT\" --broadcast -i 1 -f \"$NETWORK\" --sender \"$DEPLOYER_ADDRESS\""
COMMAND="forge script \"$SCRIPT\" --broadcast -f \"$NETWORK\" --sender \"$DEPLOYER_ADDRESS\""

if [ "$VERIFY" -eq 1 ]; then
COMMAND="$COMMAND --verify"
fi

if [ ! -z "$OA_LEDGER" ]; then
COMMAND="$COMMAND --ledger --hd-paths \"$OA_LEDGER\""
else
COMMAND="$COMMAND -i 1"
fi

if [ ! -z "$SIG" ]; then
COMMAND="$COMMAND -s \"$SIG\""
if [ ! -z "${SIG_PARAMS[*]}" ]; then
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"deploy:ds:upgradeable": "npm run -s deploy script/DocumentStoreUpgradeable.s.sol:DocumentStoreUpgradeableScript \"run(string,address)\" \"$npm_config_name\" \"$npm_config_admin\"",
"deploy:tds": "npm run -s deploy script/TransferableDocumentStore.s.sol:TransferableDocumentStoreScript \"run(string,string,address)\" \"$npm_config_name\" \"$npm_config_symbol\" \"$npm_config_admin\"",
"deploy:tds:impl": "npm run -s deploy script/TransferableDocumentStoreInitializable.s.sol:TransferableDocumentStoreInitializableScript",
"deploy:tds:upgradeable": "npm run -s deploy script/TransferableDocumentStoreUpgradeable.s.sol:TransferableDocumentStoreUpgradeableScript \"run(string,string,address)\" \"$npm_config_name\" \"$npm_config_symbol\" \"$npm_config_admin\""
"deploy:tds:upgradeable": "npm run -s deploy script/TransferableDocumentStoreUpgradeable.s.sol:TransferableDocumentStoreUpgradeableScript \"run(string,string,address)\" \"$npm_config_name\" \"$npm_config_symbol\" \"$npm_config_admin\"",
"deploy:impl:addresses": "npm run -s deploy script/ComputeInitializableAddresses.s.sol:ComputeInitializableAddresses"
},
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
Expand Down
18 changes: 18 additions & 0 deletions script/ComputeInitializableAddresses.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.23 <0.9.0;

import { console2 } from "forge-std/console2.sol";
import { DocumentStoreDeployScript } from "./DeployBase.s.sol";

contract ComputeInitializableAddresses is DocumentStoreDeployScript {
function run() public view {
bytes32 dsSalt = getDocumentStoreSalt();
bytes32 tdsSalt = getTransferableDocumentStoreSalt();

address dsComputedAddr = computeAddr(dsSalt);
address tdsComputedAddr = computeAddr(tdsSalt);

console2.log("Document Store Address: ", dsComputedAddr);
console2.log("Transferable Document Store Address: ", tdsComputedAddr);
}
}
2 changes: 2 additions & 0 deletions script/DocumentStore.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ contract DocumentStoreScript is DocumentStoreDeployScript {
address dsAddr = clone(DS_IMPL, initData);

ds = DocumentStore(dsAddr);
console2.log("Deployed Address: ", dsAddr);
} else {
vm.broadcast();
ds = new DocumentStore(name, admin);
console2.log("Deployed Address: ", address(ds));
}
}
}
4 changes: 4 additions & 0 deletions script/DocumentStoreInitializable.s.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.23 <0.9.0;

import { console2 } from "forge-std/console2.sol";

import { DocumentStoreDeployScript } from "./DeployBase.s.sol";
import "../src/initializables/DocumentStoreInitializable.sol";

Expand All @@ -19,5 +21,7 @@ contract DocumentStoreInitializableScript is DocumentStoreDeployScript {
address dsAddr = deploy(dsSalt, initCode);

documentStore = DocumentStoreInitializable(dsAddr);

console2.log("Deployed Address: ", dsAddr);
}
}
6 changes: 5 additions & 1 deletion script/DocumentStoreUpgradeable.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ contract DocumentStoreUpgradeableScript is DocumentStoreDeployScript {
console2.log("DocumentStore Name: ", name);
console2.log("DocumentStore Admin: ", admin);

vm.broadcast();
vm.startBroadcast();
(address pAddr, ) = DeployUtils.deployDocumentStoreUpgradeable(name, admin);
vm.stopBroadcast();

ds = DocumentStoreUpgradeable(pAddr);

console2.log("Deployed Address: ", pAddr);
}
}
4 changes: 4 additions & 0 deletions script/TransferableDocumentStore.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ contract TransferableDocumentStoreScript is TransferableDocumentStoreDeployScrip
address dsAddr = clone(TDS_IMPL, initData);

ds = TransferableDocumentStore(dsAddr);

console2.log("Deployed Address: ", dsAddr);
} else {
vm.broadcast();
ds = new TransferableDocumentStore(name, symbol, admin);

console2.log("Deployed Address: ", address(ds));
}
}
}
6 changes: 5 additions & 1 deletion script/TransferableDocumentStoreInitializable.s.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.23 <0.9.0;

import { console2 } from "forge-std/console2.sol";

import { TransferableDocumentStoreDeployScript } from "./DeployBase.s.sol";
import "../src/initializables/TransferableDocumentStoreInitializable.sol";

contract TransferableDocumentStoreInitializableScript is TransferableDocumentStoreDeployScript {
function run() public returns (TransferableDocumentStoreInitializable documentStore) {
require(!dsImplExists(), "TransferableDocumentStoreInitializable already exists");
require(!tdsImplExists(), "TransferableDocumentStoreInitializable already exists");

bytes memory initCode = abi.encodePacked(type(TransferableDocumentStoreInitializable).creationCode);

Expand All @@ -19,5 +21,7 @@ contract TransferableDocumentStoreInitializableScript is TransferableDocumentSto
address dsAddr = deploy(dsSalt, initCode);

documentStore = TransferableDocumentStoreInitializable(dsAddr);

console2.log("Deployed Address: ", dsAddr);
}
}
6 changes: 5 additions & 1 deletion script/TransferableDocumentStoreUpgradeable.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ contract TransferableDocumentStoreUpgradeableScript is TransferableDocumentStore
console2.log("TransferableDocumentStore Symbol: ", symbol);
console2.log("TransferableDocumentStore Admin: ", admin);

vm.broadcast();
vm.startBroadcast();
(address pAddr, ) = DeployUtils.deployTransferableDocumentStoreUpgradeable(name, symbol, admin);
vm.stopBroadcast();

ds = TransferableDocumentStoreUpgradeable(pAddr);

console2.log("Deployed Address: ", pAddr);
}
}

0 comments on commit e317640

Please sign in to comment.