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

Deployment Tools: Constructor Parameter and Artifact Tracking + Lynx Alpha 13 Deployent #119

Merged
merged 112 commits into from
Sep 28, 2023

Conversation

derekpierre
Copy link
Member

@derekpierre derekpierre commented Sep 18, 2023

Required Approvals

3

What this does

This PR introduces a comprehensive short and long-term solution for contract constructor parameters, scripting, and artifact tracking.

  • Invents standard practices and conventions for deployments
  • Removes stale and legacy-style deployment scripts (we will reintroduce as needed with new-style)
  • Decouples constructor parameters, deployment scripts, and deployment artifacts
  • Introduces a tiny domain-specific-language (DSL) for constructor parameters
  • Verifies constructor parameter length, order, name, and abi-encodable type before deployments
  • Automated generation of nucypher-style contract registries from ape deployment APIs
  • Registry merge scripts to assist in integration with nucypher/nucypher
  • Performs "pre-wrapping" of contracts in proxies in registry entries
  • Convenience functions and sanity checks for deployment scripts
  • Lynx Deployment registries for Goerli/Mumbai from September 25th, 2023 deployment.
  • Adds authorizationIncreased to TestnetThresholdStaking
  • Fixes missing/incorrect contract licensing to SPDX-License-Identifier: AGPL-3.0-or-later
Issues
Notes for reviewers
  • Many of the diff lines consist of new registries (+5,903) and a dependency relock (+2,614)
  • The constructor parameters DSL may be re-implemented as an ape plugin in the future:
  • Here's an example of constructor parameters DSL/JSON that uses most of it's features:
{
  "LynxStakingToken": {
    "_totalSupplyOfTokens": 10000000000000000000000000
  },
  "TestnetThresholdStaking": {},
  "ProxyAdmin": {},
  "TACoApplication": {
    "_token": "$LynxStakingToken",
    "_tStaking": "$TestnetThresholdStaking",
    "_minimumAuthorization": 40000000000000000000000,
    "_minOperatorSeconds": 3600,
    "_rewardDuration": 604800,
    "_deauthorizationDuration": 5184000,
    "_commitmentDurationOptions": [15724800, 31449600]
  },
  "TransparentUpgradeableProxy": {
    "_logic": "$TACoApplication",
    "admin_": "$ProxyAdmin",
    "_data": "$bytes:0x"
  },
  "MockPolygonRoot": {
    "_rootApplication": "$TransparentUpgradeableProxy:TACoApplication"
  }
}
  • Example deployment script execution output
$ ape run lynx deploy_root --network ethereum:local:test
0. lynx-deployer
Or 'TEST::account_idx', where `account_idx` is in [0..{len_test_accounts}]

Select an account: TEST::3

Constructor parameters for LynxStakingToken
        _totalSupplyOfTokens=10000000000000000000000000
Deploy LynxStakingToken Y/N? y
SUCCESS: Contract 'LynxStakingToken' deployed to: 0x8507A58140b13eFDaae4a94b9bAcaED116f05728

(i) No constructor parameters for TestnetThresholdStaking
Deploy TestnetThresholdStaking Y/N? y
SUCCESS: Contract 'TestnetThresholdStaking' deployed to: 0xDBA4D9F7245FD081fDfC3cD2593754Bc7e805E7e

(i) No constructor parameters for ProxyAdmin
Deploy ProxyAdmin Y/N? y
SUCCESS: Contract 'ProxyAdmin' deployed to: 0x23f8e661ea6D8C84523b1566a9F075ECa6D4748F

Constructor parameters for TACoApplication
        _token=0x8507A58140b13eFDaae4a94b9bAcaED116f05728
        _tStaking=0xDBA4D9F7245FD081fDfC3cD2593754Bc7e805E7e
        _minimumAuthorization=40000000000000000000000
        _minOperatorSeconds=3600
        _rewardDuration=604800
        _deauthorizationDuration=5184000
        _commitmentDurationOptions=[15724800, 31449600]
Deploy TACoApplication Y/N? y
SUCCESS: Contract 'TACoApplication' deployed to: 0x8779eD9CA1140AE6106A8Febb4A9B6e26A54f0FC

Constructor parameters for TransparentUpgradeableProxy
        _logic=0x8779eD9CA1140AE6106A8Febb4A9B6e26A54f0FC
        admin_=0x23f8e661ea6D8C84523b1566a9F075ECa6D4748F
        _data=b''
Deploy TransparentUpgradeableProxy Y/N? y
SUCCESS: Contract 'TransparentUpgradeableProxy' deployed to: 0xb949b6513e5A4B24D4668bc62B7dd9a8F4dd3333
Wrapping TACoApplication in at TransparentUpgradeableProxy:0xb949b6513e5A4B24D4668bc62B7dd9a8F4dd3333.
Transacting TestnetThresholdStaking[0xDBA4D9F7].setApplication(address _application) with arguments:
        _application=0xb949b6513e5A4B24D4668bc62B7dd9a8F4dd3333
Continue Y/N? y
Transacting TACoApplication[0xb949b651].initialize() with no arguments.
Continue Y/N? y

Constructor parameters for MockPolygonRoot
        _rootApplication=0xb949b6513e5A4B24D4668bc62B7dd9a8F4dd3333
Deploy MockPolygonRoot Y/N? y
SUCCESS: Contract 'MockPolygonRoot' deployed to: 0xBAfC935E5bF719742B67cF9b77431C6005F47dc7
Transacting TACoApplication[0xb949b651].setChildApplication(address _childApplication) with arguments:
        _childApplication=0xBAfC935E5bF719742B67cF9b77431C6005F47dc7
Continue Y/N? y
(i) Registry written to .../lynx-alpha-13-root-registry-test.json!

scripts/testnet/deploy_lynx.py Outdated Show resolved Hide resolved
contracts/contracts/testnet/LynxSet.sol Show resolved Hide resolved
Pipfile Show resolved Hide resolved
Fix parameters to deploy() command to include ContractContainer value.
Add check_etherscan_plugin to utils
Rename ConstructorParams to DeploymentConfig; get_params to get_constructor_params.
@derekpierre
Copy link
Member Author

Deployment now works locally, as of 9eab251.

You can run locally:

$ ape run deploy_lynx --network ethereum:local:test

when prompted for an account use TEST::0

Example output:

 [145] → ape run deploy_lynx --network ethereum:local:test
WARNING: ...
0. deployer
Or 'TEST::account_idx', where `account_idx` is in [0..{len_test_accounts}]

Select an account: TEST::0
(i) No constructor parameters for LynxRootApplication; proceeding
SUCCESS: Contract 'LynxRootApplication' deployed to: 0x274b028b03A250cA03644E6c578D81f019eE1323
Resolved constructor parameters for LynxTACoChildApplication
	_rootApplication=0x274b028b03A250cA03644E6c578D81f019eE1323
Continue Y/N? y
SUCCESS: Contract 'LynxTACoChildApplication' deployed to: 0xBcF7FFFD8B256Ec51a36782a52D0c34f6474D951
Resolved constructor parameters for LynxRitualToken
	_totalSupplyOfTokens=10000000000000000000000000
Continue Y/N? y
SUCCESS: Contract 'LynxRitualToken' deployed to: 0x4B3E65104805A303c274f078127D5a7E9F9b47b2
Resolved constructor parameters for Coordinator
	_application=0xBcF7FFFD8B256Ec51a36782a52D0c34f6474D951
	_timeout=3600
	_maxDkgSize=4
	_admin=0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600
	_currency=0x4B3E65104805A303c274f078127D5a7E9F9b47b2
	_feeRatePerSecond=1
Continue Y/N? y
SUCCESS: Contract 'Coordinator' deployed to: 0x6Af9BB9Cf7307AC439cc7E37859bdD844874ebc1

derekpierre and others added 2 commits September 19, 2023 16:52
… use contract container as first entry so that it isn't repeated in the deployment script.
…nd reorg of constructor parameter utilities
deployment/utils.py Outdated Show resolved Hide resolved
deployment/params.py Outdated Show resolved Hide resolved
Space out actions in deployment scripts for clarity.
KPrasch and others added 2 commits September 27, 2023 16:30
…n and includes validation and annotated information.

Use Transactor in scripts which only perform transactions based on already deployed contracts i.e. no fresh deployments.
Update configure_staking script to use MockPolygonChild entry from child registry.
@derekpierre
Copy link
Member Author

For reviewers: I know that @KPrasch and I have been making rapid code updates to this PR, 😅, but we are now enacting a PR freeze unless there are RFCs.

We intend to leave the functionality as is - and any new functionality will be done in follow-up PRs. This PR provides a great base for future work.

"TransparentUpgradeableProxy": {
"_logic": "$TACoApplication",
"admin_": "$ProxyAdmin",
"_data": "$bytes:0x"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still thinks that in the same way the parser needs to process "$bytes:0x" into b"", it would be simpler to try to process "" into b"", since we already know the type of _data. In any case, not for this PR. We can definitely accept current version.

def verify_contracts(contracts: List[ContractInstance]) -> None:
explorer = networks.provider.network.explorer
for instance in contracts:
print(f"(i) Verifying {instance.contract_type.name}...")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️



def _validate_transaction_args(args: typing.Tuple[Any, ...], abi) -> typing.Dict[str, Any]:
"""Validates the transaction arguments against the function ABI."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is already performed by either web3py or perhaps ape.

@@ -308,21 +300,52 @@ def resolve(self, contract_name: str) -> OrderedDict:
return result


class Deployer:
class Transactor:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider repurposing this class to wrap the ape project instead, so you can maintain the same ape syntax for transactions (plus any additional processing you want):

from nucypher.ape import project
...
project.Contract[-1].method(param1, param2, sender=alice, interactive=True)

and in nucypher.ape:

from ape import project

project = Transactor(project)

In any case, not a blocker for this PR.

@KPrasch KPrasch merged commit 3726379 into nucypher:main Sep 28, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants