Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
feat: refactor deploy script to use more dependency injection (#27)
Browse files Browse the repository at this point in the history
* feat: refactor deploy script to use more dependency injection

* fix: Uniswap Router address per chain

* fix: printing name of contract during deployment
  • Loading branch information
akramhussein authored Dec 17, 2021
1 parent 1031a39 commit 036b51f
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,56 @@


from brownie import CMove, CSwap, Invoker, accounts, chain, network
from brownie.network.state import Chain

commands = [CMove, CSwap]
APPROVED_COMMAND = "410a6a8d01da3028e7c041b5925a6d26ed38599db21a26cf9a5e87c68941f98a"


weth_address = {
WETH_ADDRESS = {
1: "0xC02AAA39B223FE8D0A0E5C4F27EAD9083C756CC2", # Mainnet
4: "0xc778417E063141139Fce010982780140Aa0cD5Ab", # Rinkeby
1337: "0xC02AAA39B223FE8D0A0E5C4F27EAD9083C756CC2", # Hardhat fork
}


def get_weth_address():
return weth_address[Chain().id]
def get_deployer_opts(deployer, chain):
if chain.id == 1 or chain.id == 4:
# TODO: Define deployment strategy based on chain.id
return {"from": deployer, "priority_fee": "2 gwei"}
else:
return {"from": deployer}


def deploy_invoker(deployer):
def deploy_invoker(deployer, chain):
print("Deploying invoker")
invoker = Invoker.deploy({"from": deployer})
invoker = Invoker.deploy(get_deployer_opts(deployer, chain))
return invoker


def deploy_commands(deployer, invoker):
def deploy_commands(deployer, invoker, chain):
for command in commands:
print(f"Deploying {command}")
print(f"Deploying {command._name}")
if command is CSwap:
deployed_command = command.deploy(get_weth_address(), {"from": deployer})
deployed_command = command.deploy(
WETH_ADDRESS[chain.id],
get_deployer_opts(deployer, chain),
)
else:
deployed_command = command.deploy({"from": deployer})
invoker.grantRole(APPROVED_COMMAND, deployed_command.address, {"from": deployer})
deployed_command = command.deploy(get_deployer_opts(deployer, chain))
invoker.grantRole(
APPROVED_COMMAND, deployed_command.address, get_deployer_opts(deployer, chain)
)


def deploy_all_contracts():
def main():
deployer = accounts[0]
print(f"Deployment user: {accounts[0]}")
invoker = deploy_invoker(deployer)
deploy_commands(deployer, invoker)

print(f"Deployment network: '{network.show_active()}' network (Chain ID: {chain.id})")
print(f"Deployment user: {deployer}")

invoker = deploy_invoker(deployer, chain)
deploy_commands(deployer, invoker, chain)

print(f"Gas used for deployment: {deployer.gas_used} gwei\n")

def main():
print(f"Deploying to '{network.show_active()}' network")
print(f"Chain ID: {Chain().id}")
deploy_all_contracts()
accounts[0].transfer("0xc7711f36b2C13E00821fFD9EC54B04A60AEfbd1b", "1 ether")
for block in chain.new_blocks():
print(f"Mining block {block.number}")

0 comments on commit 036b51f

Please sign in to comment.