Skip to content

Commit

Permalink
Remove the need for proxy variables. Proxy addresses are obtained by …
Browse files Browse the repository at this point in the history
…default when resolving contract addresses, unless specified otherwise.
  • Loading branch information
derekpierre committed Nov 1, 2023
1 parent c36cd4c commit c338daa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
1 change: 0 additions & 1 deletion deployment/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
ARTIFACTS_DIR = DEPLOYMENT_DIR / "artifacts"
VARIABLE_PREFIX = "$"
SPECIAL_VARIABLE_DELIMITER = ":"
PROXY_PREFIX = "proxy"
HEX_PREFIX = "0x"
BYTES_PREFIX = "bytes"
DEPLOYER_INDICATOR = "deployer"
Expand Down
2 changes: 1 addition & 1 deletion deployment/constructor_params/lynx/child.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contracts:
_totalSupplyOfTokens: $TEN_MILLION_TOKENS_IN_WEI_UNITS
- Coordinator:
constructor:
_application: $proxy:LynxTACoChildApplication
_application: $LynxTACoChildApplication
_timeout: $ONE_HOUR_IN_SECONDS
_maxDkgSize: 4
_admin: $deployer
Expand Down
2 changes: 1 addition & 1 deletion deployment/constructor_params/lynx/root.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ contracts:
_commitmentDurationOptions: [$IN_SECONDS_182_DAYS, $IN_SECONDS_364_DAYS]
- MockPolygonRoot:
constructor:
_rootApplication: $proxy:TACoApplication
_rootApplication: $TACoApplication
53 changes: 18 additions & 35 deletions deployment/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
BYTES_PREFIX,
DEPLOYER_INDICATOR,
OZ_DEPENDENCY,
PROXY_PREFIX,
SPECIAL_VARIABLE_DELIMITER,
VARIABLE_PREFIX,
)
Expand All @@ -40,15 +39,10 @@ def _is_variable(param: Any) -> bool:

def _is_special_variable(variable: str) -> bool:
"""Returns True if the variable is a special variable."""
rules = [_is_bytes, _is_proxy_variable, _is_deployer, _is_constant]
rules = [_is_bytes, _is_deployer, _is_constant]
return any(rule(variable) for rule in rules)


def _is_proxy_variable(variable: str) -> bool:
"""Returns True if the variable is a special proxy variable."""
return variable.startswith(PROXY_PREFIX + SPECIAL_VARIABLE_DELIMITER)


def _is_bytes(variable: str) -> bool:
"""Returns True if the variable is a special bytes value."""
return variable.startswith(BYTES_PREFIX + SPECIAL_VARIABLE_DELIMITER)
Expand All @@ -64,22 +58,6 @@ def _is_constant(variable: str) -> bool:
return variable.isupper()


def _resolve_proxy_address(variable) -> str:
_, target = variable.split(SPECIAL_VARIABLE_DELIMITER)
target_contract_container = get_contract_container(target)
target_contract_instance = _get_contract_instance(target_contract_container)
if target_contract_instance == ZERO_ADDRESS:
# eager validation
return ZERO_ADDRESS

local_proxies = chain.contracts._local_proxies
for proxy_address, proxy_info in local_proxies.items():
if proxy_info.target == target_contract_instance.address:
return proxy_address

raise ConstructorParameters.Invalid(f"Could not determine proxy for {variable}")


def _get_contract_instance(
contract_container: ContractContainer,
) -> typing.Union[ContractInstance, ChecksumAddress]:
Expand Down Expand Up @@ -118,19 +96,26 @@ def _validate_transaction_args(
raise ValueError(f"Could not find ABI for {method} with {len(args)} args and given types")


def _resolve_contract_address(variable: str) -> str:
def _resolve_contract_address(variable: str, check_for_proxy_instances=True) -> str:
"""Resolves a contract address."""
contract_container = get_contract_container(variable)
contract_instance = _get_contract_instance(contract_container)
if contract_instance == ZERO_ADDRESS:
# eager validation
return ZERO_ADDRESS

if check_for_proxy_instances:
# check if contract is proxied - if so return proxy contract instead
local_proxies = chain.contracts._local_proxies
for proxy_address, proxy_info in local_proxies.items():
if proxy_info.target == contract_instance.address:
return proxy_address

return contract_instance.address


def _resolve_special_variable(variable: str, constants) -> Any:
if _is_proxy_variable(variable):
result = _resolve_proxy_address(variable)
elif _is_deployer(variable):
if _is_deployer(variable):
result = _resolve_deployer()
elif _is_constant(variable):
result = _resolve_constant(variable, constants=constants)
Expand All @@ -139,17 +124,17 @@ def _resolve_special_variable(variable: str, constants) -> Any:
return result


def _resolve_param(value: Any, constants) -> Any:
def _resolve_param(value: Any, constants, resolve_contracts_checking_proxies=True) -> Any:
"""Resolves a single parameter value or a list of parameter values."""
if isinstance(value, list):
return [_resolve_param(v, constants) for v in value]
return [_resolve_param(v, constants, resolve_contracts_checking_proxies) for v in value]
if not _is_variable(value):
return value # literally a value
variable = value.strip(VARIABLE_PREFIX)
if _is_special_variable(variable):
result = _resolve_special_variable(variable, constants=constants)
else:
result = _resolve_contract_address(variable)
result = _resolve_contract_address(variable, resolve_contracts_checking_proxies)
return result


Expand All @@ -172,10 +157,6 @@ def _validate_constructor_param(param: Any, contracts: List[str]) -> None:
return # literally a value
variable = param.strip(VARIABLE_PREFIX)

if _is_proxy_variable(variable):
_, target = variable.split(SPECIAL_VARIABLE_DELIMITER)
variable = target # check proxy target

if _is_special_variable(variable):
return # special variables are always marked as valid

Expand Down Expand Up @@ -354,7 +335,9 @@ def resolve(self, contract_name: str) -> typing.Tuple[ContractContainer, Ordered

resolved_params = OrderedDict()
for name, value in proxy_info.constructor_params.items():
resolved_params[name] = _resolve_param(value, constants=self.constants)
resolved_params[name] = _resolve_param(
value=value, constants=self.constants, resolve_contracts_checking_proxies=False
)

return contract_container, resolved_params

Expand Down

0 comments on commit c338daa

Please sign in to comment.