Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Automated DKG Inititaiton #338

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/scripts/import_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3

import os

from ape_accounts import import_account_from_private_key


def main():
try:
passphrase = os.environ["DKG_INITIATOR_PASSPHRASE"]
private_key = os.environ["DKG_INITIATOR_PRIVATE_KEY"]
except KeyError:
raise Exception(
"There are missing environment variables."
"Please set DKG_INITIATOR_PASSPHRASE and DKG_INITIATOR_PRIVATE_KEY."
)
account = import_account_from_private_key(
'AUTOMATION',
passphrase,
private_key
)
print(f"Account imported: {account.address}")


if __name__ == '__main__':
main()
11 changes: 11 additions & 0 deletions .github/scripts/initiate_ritual.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ape run initiate_ritual \
--autosign \
--account AUTOMATION \
--network polygon:mainnet:${RPC_PROVIDER} \
--domain mainnet \
--duration 86400 \
--access-controller GlobalAllowList \
--fee-model FreeFeeModel \
--authority ${DKG_AUTHORITY_ADDRESS} \
--min-version ${MIN_VERSION} \
--num-nodes 30
40 changes: 40 additions & 0 deletions .github/workflows/dkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Heartbeat DKG

on:
schedule:
- cron: '0 0 * * *'

jobs:
initiate_dkg:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
pip3 install eth-ape ape-infura ape-polygon ape-etherscan
pip3 install -e .

- name: Import Ape Account
run: .github/scripts/import_account.py
env:
DKG_INITIATOR_PRIVATE_KEY: ${{ secrets.DKG_INITIATOR_PRIVATE_KEY }}
DKG_INITIATOR_PASSPHRASE: ${{ secrets.DKG_INITIATOR_PASSPHRASE }}

- name: Initiate Ritual
run: .github/scripts/initiate_ritual.sh
env:
DKG_INITIATOR_ADDRESS: ${{ secrets.DKG_INITIATOR_ADDRESS }}
APE_ACCOUNTS_AUTOMATION_PASSPHRASE: ${{ secrets.DKG_INITIATOR_PASSPHRASE }}
DKG_AUTHORITY_ADDRESS: ${{ secrets.DKG_AUTHORITY_ADDRESS }}
RPC_PROVIDER: ${{ secrets.RPC_PROVIDER }}
MIN_VERSION: ${{ secrets.MIN_VERSION }}
WEB3_INFURA_API_KEY: ${{ secrets.WEB3_INFURA_API_KEY }}
POLYGONSCAN_API_KEY: ${{ secrets.POLYGONSCAN_API_KEY }}
23 changes: 12 additions & 11 deletions deployment/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ape.cli.choices import select_account
from ape.contracts.base import ContractContainer, ContractInstance, ContractTransactionHandler
from ape.utils import EMPTY_BYTES32, ZERO_ADDRESS
from ape_test import TestAccount
from eth_typing import ChecksumAddress
from eth_utils import to_checksum_address
from ethpm_types import MethodABI
Expand Down Expand Up @@ -480,15 +481,16 @@ class Transactor:
Represents an ape account plus validated/annotated transaction execution.
"""

def __init__(self, account: typing.Optional[AccountAPI] = None, non_interactive: bool = False):
if non_interactive and not account:
raise ValueError("'non_interactive' can only be used if an account is provided")

self._non_interactive = non_interactive
def __init__(self, account: typing.Optional[AccountAPI] = None, autosign: bool = False):
if account is None:
self._account = select_account()
else:
self._account = account
if autosign:
print("WARNING: Autosign is enabled. Transactions will be signed automatically.")
self._autosign = autosign
if not isinstance(self._account, TestAccount):
self._account.set_autosign(autosign)

def get_account(self) -> AccountAPI:
"""Returns the transactor account."""
Expand All @@ -506,8 +508,7 @@ def transact(self, method: ContractTransactionHandler, *args) -> ReceiptAPI:
else:
message = f"{base_message} with no arguments"
print(message)

if not self._non_interactive:
if not self._autosign:
_continue()

result = method(
Expand All @@ -534,9 +535,9 @@ def __init__(
path: Path,
verify: bool,
account: typing.Optional[AccountAPI] = None,
non_interactive: bool = False,
autosign: bool = False,
):
super().__init__(account, non_interactive)
super().__init__(account, autosign)

check_plugins()
self.path = path
Expand All @@ -554,7 +555,7 @@ def __init__(
self.verify = verify
self._print_deployment_info()

if not self._non_interactive:
if not self._autosign:
# Confirms the start of the deployment.
_continue()

Expand Down Expand Up @@ -597,7 +598,7 @@ def _deploy_contract(
self, container: ContractContainer, resolved_params: OrderedDict
) -> ContractInstance:
contract_name = container.contract_type.name
if not self._non_interactive:
if not self._autosign:
_confirm_resolution(resolved_params, contract_name)
deployment_params = [container, *resolved_params.values()]
kwargs = self._get_kwargs()
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/deploy_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def main():
filepath=CONSTRUCTOR_PARAMS_FILEPATH,
verify=VERIFY,
account=test_account,
non_interactive=True,
autosign=True,
)

mock_polygon_child = deployer.deploy(project.MockPolygonChild)
Expand Down
7 changes: 6 additions & 1 deletion scripts/initiate_ritual.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
help="The filepath of a file containing newline separated staking provider addresses.",
type=click.File("r"),
)
@click.option(
"--autosign",
is_flag=True,
)
def cli(
domain,
account,
Expand All @@ -84,6 +88,7 @@ def cli(
random_seed,
handpicked,
min_version,
autosign,
):
"""Initiate a ritual for a TACo domain."""

Expand Down Expand Up @@ -147,7 +152,7 @@ def cli(
)

# Initiate the ritual
transactor = Transactor(account=account)
transactor = Transactor(account=account, autosign=autosign)
transactor.transact(
coordinator_contract.initiateRitual,
fee_model_contract.address,
Expand Down
Loading