Skip to content

Commit

Permalink
Custom docker network names (#84)
Browse files Browse the repository at this point in the history
* chore: custom network names
  • Loading branch information
scolear authored Jul 16, 2024
1 parent f712ce8 commit 11c9087
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ services:
- '8545:8545'
volumes:
- ../dlc-attestor-stack/attestor/observer/contracts:/app/dlc-solidity/deploymentFiles
environment:
- BTC_FEE_RECIPIENT=03edf233daf20679848c38450c7feca2b32601d8150a68559de8ffefda7a03bd87
- NETWORK_NAME=hardhat-arb
9 changes: 7 additions & 2 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Start the Hardhat node in the background
npx hardhat node >hardhat.log 2>&1 &
mkdir -p deploymentFiles/localhost 2>/dev/null
mkdir -p deploymentFiles/$NETWORK_NAME 2>/dev/null

# Wait for the Hardhat node to start
while ! grep -q "Started HTTP and WebSocket JSON-RPC server" hardhat.log; do
Expand All @@ -13,7 +13,12 @@ done
export CLI_MODE='noninteractive'
npx hardhat run --network localhost docker/scripts/deploy-all.js

dlc-link-eth set-btc-fee-recipient 03c9fc819e3c26ec4a58639add07f6372e810513f5d3d7374c25c65fdf1aefe4c5
# Use BTC_FEE_RECIPIENT environment variable
if [ -z "$BTC_FEE_RECIPIENT" ]; then
$BTC_FEE_RECIPIENT = "03c9fc819e3c26ec4a58639add07f6372e810513f5d3d7374c25c65fdf1aefe4c5"
exit 1
fi
dlc-link-eth set-btc-fee-recipient $BTC_FEE_RECIPIENT
dlc-link-eth set-attestor-gpk tpubDCFu4tR41DrKFeSrKHvtCy3eojuSwRfxPhGfG6iskApasoWUExBHh7rq21mGXudMycbwZppfVx89ZXMUNrZtFq235fz37Fu1869tWAw1qYi
# push the message "Deployment Complete" into the log file
# NOTE: This is important! It's how the health check finishes
Expand Down
12 changes: 6 additions & 6 deletions docker/scripts/deploy-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ const { loadContractAddress } = require('../../scripts/helpers/utils');
process.env.CLI_MODE = 'noninteractive';

async function main() {
const network = hardhat.network.name;
const network = process.env.NETWORK_NAME ?? 'localhost';
const accounts = await hardhat.ethers.getSigners();
const deployer = accounts[0];
const dlcAdminSafes = dlcAdminSafesConfigs[network];

console.log(network, dlcAdminSafes);

if (!dlcAdminSafes) throw new Error('DLC Admin Safe address not found.');
const dlcAdminSafes = {
medium: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
critical: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
}; // Hardhat default deployer account

const contractConfigs = getContractConfigs(
{
deployer,
dlcAdminSafes,
networkName: network,
},
process.env.BTC_FEE_RECIPIENT
);
Expand Down
1 change: 1 addition & 0 deletions scripts/50_contract-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = async function contractAdmin() {
if (!dlcAdminSafes) throw new Error('DLC Admin Safe address not found.');

const contractConfigs = getContractConfigs({
networkName: network,
deployer,
dlcAdminSafes,
});
Expand Down
24 changes: 13 additions & 11 deletions scripts/99_contract-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ async function beforeDeployment(contractName, constructorArguments, network) {

// This is an effectful function that saves deployment info
// contractName will be used as the key in the deployment info!
async function afterDeployment(contractName, contractObject) {
async function afterDeployment(contractName, contractObject, networkName) {
console.log(
`Deployed contract ${contractName} to ${contractObject.address}`
`Deployed contract ${contractName} to ${contractObject.address} on ${networkName}`
);
try {
await saveDeploymentInfo(
deploymentInfo(hardhat, contractObject, contractName)
deploymentInfo(networkName, contractObject, contractName)
);
} catch (error) {
console.error(error);
}
}

module.exports = function getContractConfigs(networkConfig, _btcFeeRecipient) {
const network = hardhat.network.name;
const { deployer, dlcAdminSafes } = networkConfig;
const { deployer, dlcAdminSafes, networkName } = networkConfig;
const btcFeeRecipient =
_btcFeeRecipient ?? '0014e60f61fa2f2941217934d5f9976bf27381b3b036';
const threshold = 2;
Expand All @@ -46,19 +45,22 @@ module.exports = function getContractConfigs(networkConfig, _btcFeeRecipient) {
upgradeable: true,
requirements: [],
deploy: async (requirementAddresses) => {
await beforeDeployment('DLCBTC', '', network);
await beforeDeployment('DLCBTC', '', networkName);

const DLCBTC =
await hardhat.ethers.getContractFactory('DLCBTC');
const dlcBtc = await hardhat.upgrades.deployProxy(DLCBTC);
await dlcBtc.deployed();

await afterDeployment('DLCBTC', dlcBtc);
await afterDeployment('DLCBTC', dlcBtc, networkName);

return dlcBtc.address;
},
verify: async () => {
const address = await loadContractAddress('DLCBTC', network);
const address = await loadContractAddress(
'DLCBTC',
networkName
);
await hardhat.run('verify:verify', {
address: address,
});
Expand All @@ -82,7 +84,7 @@ module.exports = function getContractConfigs(networkConfig, _btcFeeRecipient) {
threshold: ${threshold}, \
tokenContract: ${DLCBTCAddress}, \
btcFeeRecipient: ${btcFeeRecipient}`,
network
networkName
);
const DLCManager =
await hardhat.ethers.getContractFactory('DLCManager');
Expand All @@ -98,7 +100,7 @@ module.exports = function getContractConfigs(networkConfig, _btcFeeRecipient) {
);
await dlcManager.deployed();

await afterDeployment('DLCManager', dlcManager);
await afterDeployment('DLCManager', dlcManager, networkName);

const dlcBtc = await hardhat.ethers.getContractAt(
'DLCBTC',
Expand Down Expand Up @@ -151,7 +153,7 @@ module.exports = function getContractConfigs(networkConfig, _btcFeeRecipient) {
verify: async () => {
const address = await loadContractAddress(
'DlcManager',
network
networkName
);
await hardhat.run('verify:verify', {
address: address,
Expand Down
4 changes: 2 additions & 2 deletions scripts/helpers/deployment-handlers_versioned.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs/promises');
const { execSync } = require('child_process');

function deploymentInfo(hardhat, contract, contractName) {
function deploymentInfo(networkName, contract, contractName) {
let _gitSHA;
try {
_gitSHA = execSync('git rev-parse --short HEAD').toString().trim();
Expand All @@ -10,7 +10,7 @@ function deploymentInfo(hardhat, contract, contractName) {
}

const deployInfo = {
network: hardhat.network.name,
network: networkName,
updatedAt: new Date().toISOString(),
gitSHA: _gitSHA,
contract: {
Expand Down

0 comments on commit 11c9087

Please sign in to comment.