diff --git a/tplus/client/clearingengine/assetregistry.py b/tplus/client/clearingengine/assetregistry.py index cacffb8..d99a9c5 100644 --- a/tplus/client/clearingengine/assetregistry.py +++ b/tplus/client/clearingengine/assetregistry.py @@ -49,8 +49,9 @@ async def update_fee_account(self): """ await self._post("fee-account/update") - async def get_fee_account(self): + async def get_fee_account(self) -> str: """ - Request that the clearing engine update its fee account. + Get the fee account. """ - await self._post("fee-account") + account = await self._get("fee-account") + return f"{account}" diff --git a/tplus/evm/constants.py b/tplus/evm/constants.py index fac5bb7..2f908ed 100644 --- a/tplus/evm/constants.py +++ b/tplus/evm/constants.py @@ -1,2 +1,2 @@ -REGISTRY_ADDRESS = "0xBBd0020ae0DAB578515d0c72EdFf37Bf30D31BE5" +REGISTRY_ADDRESS = "0x9700c54DFB6C8a77bA151556a41dC035B60e4B91" LATEST_ARB_DEPOSIT_VAULT = "0x7a9eAA74eF31ed3eca5447252b443651Ad250916" diff --git a/tplus/evm/contracts.py b/tplus/evm/contracts.py index edd63db..4ce0f92 100644 --- a/tplus/evm/contracts.py +++ b/tplus/evm/contracts.py @@ -191,11 +191,12 @@ def __init__( address: str | None = None, tplus_contracts_version: str | None = None, ) -> None: - self._deployments: dict[int, ContractInstance] = {} + self._deployments: dict[str, ContractInstance] = {} self._default_deployer = default_deployer self._chain_id = chain_id self._address = address self._tplus_contracts_version = tplus_contracts_version + self._attempted_deploy_dev = False if address is not None and chain_id is not None: self._deployments[f"{chain_id}"] = self._contract_container.at(address) @@ -219,6 +220,13 @@ def deploy_dev(cls): owner = get_dev_default_owner() return cls.deploy(owner, sender=owner) + def deploy_dev_and_set_deployment(self) -> "TPlusContract": + self._attempted_deploy_dev = True + instance = self.deploy_dev() + self._address = instance.address + self._deployments[f"{instance.chain_id}"] = instance + return instance + def __repr__(self) -> str: return f"<{self.name}>" @@ -227,20 +235,27 @@ def __getattr__(self, attr_name: str): # First, try a regular attribute on the class return self.__getattribute__(attr_name) except AttributeError: - # Resort to something defined on the contract. + if attr_name.startswith("_"): + # Ignore internals, causes integration issues. + raise + + # Try something defined on the contract. return getattr(self.contract, attr_name) @property def name(self) -> str: return self.__class__.NAME + @cached_property + def chain_id(self) -> ChainID: + return self._chain_id or ChainID.evm(self.chain_manager.chain_id) + @property def address(self) -> str: if address := self._address: return address - chain_id = self._chain_id or ChainID.evm(self.chain_manager.chain_id) - return self.get_address(chain_id=chain_id) + return self.get_address(chain_id=self.chain_id) @property def tplus_contracts_project(self) -> "Project": @@ -259,15 +274,16 @@ def contract(self) -> "ContractInstance": try: return self.get_contract() except ContractNotExists: - if self.chain_manager.provider.network.is_local: + if self.is_local_network and not self._attempted_deploy_dev: # If simulating, deploy it now. - instance = self.deploy_dev() - self._address = instance.address - self._deployments[self.chain_manager.chain_id] = instance - return instance + return self.deploy_dev_and_set_deployment() raise # This error. + @property + def is_local_network(self) -> bool: + return self.chain_manager.provider.network.is_local + @property def default_deployer(self) -> AccountAPI: if deployer := self._default_deployer: @@ -304,7 +320,7 @@ def get_contract(self, chain_id: ChainID | None = None) -> "ContractInstance": Returns: ContractInstance """ - chain_id = chain_id or self._chain_id or ChainID.evm(self.chain_manager.chain_id) + chain_id = chain_id or self.chain_id if chain_id in self._deployments: # Get previously cached instance. return self._deployments[chain_id] @@ -321,11 +337,14 @@ def get_address(self, chain_id: ChainID | None = None) -> str: if self._address and self._chain_id and chain_id == self._chain_id: return self._address - chain_id = chain_id or self._chain_id or ChainID.evm(self.chain_manager.chain_id) + chain_id = chain_id or self.chain_id try: return TPLUS_DEPLOYMENTS[chain_id][self.name] - except KeyError: - raise ContractNotExists(f"{self.name} not deployed on chain '{chain_id}'.") + except KeyError as err: + if self.is_local_network and not self._attempted_deploy_dev: + self.deploy_dev_and_set_deployment() + + raise ContractNotExists(f"{self.name} not deployed on chain '{chain_id}'.") from err class Registry(TPlusContract):