From 4d8619a81ef255e6a089f18b94284a91d3cd77ec Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Sun, 20 Aug 2023 18:27:04 -0700 Subject: [PATCH] Added `terminus-gogogo` Removed all `TerminusController` related functionality (see PR for more details). --- cli/web3cli/TerminusControllerFacet.py | 1114 ----------------- cli/web3cli/core.py | 144 +++ .../controller/LibTerminusController.sol | 36 - .../controller/TerminusControllerFacet.sol | 272 ---- 4 files changed, 144 insertions(+), 1422 deletions(-) delete mode 100644 cli/web3cli/TerminusControllerFacet.py delete mode 100644 contracts/terminus/controller/LibTerminusController.sol delete mode 100644 contracts/terminus/controller/TerminusControllerFacet.sol diff --git a/cli/web3cli/TerminusControllerFacet.py b/cli/web3cli/TerminusControllerFacet.py deleted file mode 100644 index 601e9018..00000000 --- a/cli/web3cli/TerminusControllerFacet.py +++ /dev/null @@ -1,1114 +0,0 @@ -# Code generated by moonworm : https://github.com/moonstream-to/moonworm -# Moonworm version : 0.7.1 - -import argparse -import json -import os -from pathlib import Path -from typing import Any, Dict, List, Optional, Union - -from brownie import Contract, network, project -from brownie.network.contract import ContractContainer -from eth_typing.evm import ChecksumAddress - - -PROJECT_DIRECTORY = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) -BUILD_DIRECTORY = os.path.join(PROJECT_DIRECTORY, "build", "contracts") - - -def boolean_argument_type(raw_value: str) -> bool: - TRUE_VALUES = ["1", "t", "y", "true", "yes"] - FALSE_VALUES = ["0", "f", "n", "false", "no"] - - if raw_value.lower() in TRUE_VALUES: - return True - elif raw_value.lower() in FALSE_VALUES: - return False - - raise ValueError( - f"Invalid boolean argument: {raw_value}. Value must be one of: {','.join(TRUE_VALUES + FALSE_VALUES)}" - ) - - -def bytes_argument_type(raw_value: str) -> str: - return raw_value - - -def get_abi_json(abi_name: str) -> List[Dict[str, Any]]: - abi_full_path = os.path.join(BUILD_DIRECTORY, f"{abi_name}.json") - if not os.path.isfile(abi_full_path): - raise IOError( - f"File does not exist: {abi_full_path}. Maybe you have to compile the smart contracts?" - ) - - with open(abi_full_path, "r") as ifp: - build = json.load(ifp) - - abi_json = build.get("abi") - if abi_json is None: - raise ValueError(f"Could not find ABI definition in: {abi_full_path}") - - return abi_json - - -def contract_from_build(abi_name: str) -> ContractContainer: - # This is workaround because brownie currently doesn't support loading the same project multiple - # times. This causes problems when using multiple contracts from the same project in the same - # python project. - PROJECT = project.main.Project("moonworm", Path(PROJECT_DIRECTORY)) - - abi_full_path = os.path.join(BUILD_DIRECTORY, f"{abi_name}.json") - if not os.path.isfile(abi_full_path): - raise IOError( - f"File does not exist: {abi_full_path}. Maybe you have to compile the smart contracts?" - ) - - with open(abi_full_path, "r") as ifp: - build = json.load(ifp) - - return ContractContainer(PROJECT, build) - - -class TerminusControllerFacet: - def __init__(self, contract_address: Optional[ChecksumAddress]): - self.contract_name = "TerminusControllerFacet" - self.address = contract_address - self.contract = None - self.abi = get_abi_json("TerminusControllerFacet") - if self.address is not None: - self.contract: Optional[Contract] = Contract.from_abi( - self.contract_name, self.address, self.abi - ) - - def deploy(self, transaction_config): - contract_class = contract_from_build(self.contract_name) - deployed_contract = contract_class.deploy(transaction_config) - self.address = deployed_contract.address - self.contract = deployed_contract - return deployed_contract.tx - - def assert_contract_is_instantiated(self) -> None: - if self.contract is None: - raise Exception("contract has not been instantiated") - - def verify_contract(self): - self.assert_contract_is_instantiated() - contract_class = contract_from_build(self.contract_name) - contract_class.publish_source(self.contract) - - def approve_for_pool( - self, pool_id: int, operator: ChecksumAddress, transaction_config - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.approveForPool(pool_id, operator, transaction_config) - - def balance_of( - self, - account: ChecksumAddress, - id: int, - block_number: Optional[Union[str, int]] = "latest", - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.balanceOf.call(account, id, block_identifier=block_number) - - def burn( - self, from_: ChecksumAddress, pool_id: int, amount: int, transaction_config - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.burn(from_, pool_id, amount, transaction_config) - - def contract_uri(self, block_number: Optional[Union[str, int]] = "latest") -> Any: - self.assert_contract_is_instantiated() - return self.contract.contractURI.call(block_identifier=block_number) - - def create_pool_v1( - self, _capacity: int, _transferable: bool, _burnable: bool, transaction_config - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.createPoolV1( - _capacity, _transferable, _burnable, transaction_config - ) - - def create_simple_pool(self, _capacity: int, transaction_config) -> Any: - self.assert_contract_is_instantiated() - return self.contract.createSimplePool(_capacity, transaction_config) - - def drain_erc1155( - self, - token_address: ChecksumAddress, - token_id: int, - receiver_address: ChecksumAddress, - transaction_config, - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.drainERC1155( - token_address, token_id, receiver_address, transaction_config - ) - - def drain_erc20( - self, - token_address: ChecksumAddress, - receiver_address: ChecksumAddress, - transaction_config, - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.drainERC20( - token_address, receiver_address, transaction_config - ) - - def get_terminus_address( - self, block_number: Optional[Union[str, int]] = "latest" - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.getTerminusAddress.call(block_identifier=block_number) - - def get_terminus_main_admin_pool_id( - self, block_number: Optional[Union[str, int]] = "latest" - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.getTerminusMainAdminPoolId.call( - block_identifier=block_number - ) - - def get_terminus_pool_controller_pool( - self, pool_id: int, block_number: Optional[Union[str, int]] = "latest" - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.getTerminusPoolControllerPool.call( - pool_id, block_identifier=block_number - ) - - def init_terminus_controller( - self, - terminus_address: ChecksumAddress, - _terminus_main_admin_pool_terminus_address: ChecksumAddress, - _terminus_main_admin_pool_id: int, - transaction_config, - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.initTerminusController( - terminus_address, - _terminus_main_admin_pool_terminus_address, - _terminus_main_admin_pool_id, - transaction_config, - ) - - def is_approved_for_pool( - self, - pool_id: int, - operator: ChecksumAddress, - block_number: Optional[Union[str, int]] = "latest", - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.isApprovedForPool.call( - pool_id, operator, block_identifier=block_number - ) - - def mint( - self, - to: ChecksumAddress, - pool_id: int, - amount: int, - data: bytes, - transaction_config, - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.mint(to, pool_id, amount, data, transaction_config) - - def mint_batch( - self, - to: ChecksumAddress, - pool_i_ds: List, - amounts: List, - data: bytes, - transaction_config, - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.mintBatch(to, pool_i_ds, amounts, data, transaction_config) - - def pool_mint_batch( - self, id: int, to_addresses: List, amounts: List, transaction_config - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.poolMintBatch( - id, to_addresses, amounts, transaction_config - ) - - def set_contract_uri(self, _contract_uri: str, transaction_config) -> Any: - self.assert_contract_is_instantiated() - return self.contract.setContractURI(_contract_uri, transaction_config) - - def set_controller( - self, new_controller: ChecksumAddress, transaction_config - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.setController(new_controller, transaction_config) - - def set_pool_control_permissions( - self, - pool_id: int, - terminus_address: ChecksumAddress, - pool_controller_pool_id: int, - transaction_config, - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.setPoolControlPermissions( - pool_id, terminus_address, pool_controller_pool_id, transaction_config - ) - - def set_pool_controller( - self, pool_id: int, new_controller: ChecksumAddress, transaction_config - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.setPoolController( - pool_id, new_controller, transaction_config - ) - - def set_uri(self, pool_id: int, pool_uri: str, transaction_config) -> Any: - self.assert_contract_is_instantiated() - return self.contract.setURI(pool_id, pool_uri, transaction_config) - - def terminus_controller( - self, block_number: Optional[Union[str, int]] = "latest" - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.terminusController.call(block_identifier=block_number) - - def terminus_pool_capacity( - self, pool_id: int, block_number: Optional[Union[str, int]] = "latest" - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.terminusPoolCapacity.call( - pool_id, block_identifier=block_number - ) - - def terminus_pool_controller( - self, pool_id: int, block_number: Optional[Union[str, int]] = "latest" - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.terminusPoolController.call( - pool_id, block_identifier=block_number - ) - - def terminus_pool_supply( - self, pool_id: int, block_number: Optional[Union[str, int]] = "latest" - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.terminusPoolSupply.call( - pool_id, block_identifier=block_number - ) - - def total_pools(self, block_number: Optional[Union[str, int]] = "latest") -> Any: - self.assert_contract_is_instantiated() - return self.contract.totalPools.call(block_identifier=block_number) - - def unapprove_for_pool( - self, pool_id: int, operator: ChecksumAddress, transaction_config - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.unapproveForPool(pool_id, operator, transaction_config) - - def withdraw_erc1155( - self, - token_address: ChecksumAddress, - token_id: int, - amount: int, - receiver_address: ChecksumAddress, - transaction_config, - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.withdrawERC1155( - token_address, token_id, amount, receiver_address, transaction_config - ) - - def withdraw_erc20( - self, - token_address: ChecksumAddress, - amount: int, - receiver_address: ChecksumAddress, - transaction_config, - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.withdrawERC20( - token_address, amount, receiver_address, transaction_config - ) - - def withdraw_erc721( - self, - token_address: ChecksumAddress, - token_id: int, - receiver_address: ChecksumAddress, - transaction_config, - ) -> Any: - self.assert_contract_is_instantiated() - return self.contract.withdrawERC721( - token_address, token_id, receiver_address, transaction_config - ) - - -def get_transaction_config(args: argparse.Namespace) -> Dict[str, Any]: - signer = network.accounts.load(args.sender, args.password) - transaction_config: Dict[str, Any] = {"from": signer} - if args.gas_price is not None: - transaction_config["gas_price"] = args.gas_price - if args.max_fee_per_gas is not None: - transaction_config["max_fee"] = args.max_fee_per_gas - if args.max_priority_fee_per_gas is not None: - transaction_config["priority_fee"] = args.max_priority_fee_per_gas - if args.confirmations is not None: - transaction_config["required_confs"] = args.confirmations - if args.nonce is not None: - transaction_config["nonce"] = args.nonce - return transaction_config - - -def add_default_arguments(parser: argparse.ArgumentParser, transact: bool) -> None: - parser.add_argument( - "--network", required=True, help="Name of brownie network to connect to" - ) - parser.add_argument( - "--address", required=False, help="Address of deployed contract to connect to" - ) - if not transact: - parser.add_argument( - "--block-number", - required=False, - type=int, - help="Call at the given block number, defaults to latest", - ) - return - parser.add_argument( - "--sender", required=True, help="Path to keystore file for transaction sender" - ) - parser.add_argument( - "--password", - required=False, - help="Password to keystore file (if you do not provide it, you will be prompted for it)", - ) - parser.add_argument( - "--gas-price", default=None, help="Gas price at which to submit transaction" - ) - parser.add_argument( - "--max-fee-per-gas", - default=None, - help="Max fee per gas for EIP1559 transactions", - ) - parser.add_argument( - "--max-priority-fee-per-gas", - default=None, - help="Max priority fee per gas for EIP1559 transactions", - ) - parser.add_argument( - "--confirmations", - type=int, - default=None, - help="Number of confirmations to await before considering a transaction completed", - ) - parser.add_argument( - "--nonce", type=int, default=None, help="Nonce for the transaction (optional)" - ) - parser.add_argument( - "--value", default=None, help="Value of the transaction in wei(optional)" - ) - parser.add_argument("--verbose", action="store_true", help="Print verbose output") - - -def handle_deploy(args: argparse.Namespace) -> None: - network.connect(args.network) - transaction_config = get_transaction_config(args) - contract = TerminusControllerFacet(None) - result = contract.deploy(transaction_config=transaction_config) - print(result) - if args.verbose: - print(result.info()) - - -def handle_verify_contract(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.verify_contract() - print(result) - - -def handle_approve_for_pool(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.approve_for_pool( - pool_id=args.pool_id, - operator=args.operator, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_balance_of(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.balance_of( - account=args.account, id=args.id, block_number=args.block_number - ) - print(result) - - -def handle_burn(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.burn( - from_=args.from_arg, - pool_id=args.pool_id, - amount=args.amount, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_contract_uri(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.contract_uri(block_number=args.block_number) - print(result) - - -def handle_create_pool_v1(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.create_pool_v1( - _capacity=args.capacity_arg, - _transferable=args.transferable_arg, - _burnable=args.burnable_arg, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_create_simple_pool(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.create_simple_pool( - _capacity=args.capacity_arg, transaction_config=transaction_config - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_drain_erc1155(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.drain_erc1155( - token_address=args.token_address, - token_id=args.token_id, - receiver_address=args.receiver_address, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_drain_erc20(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.drain_erc20( - token_address=args.token_address, - receiver_address=args.receiver_address, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_get_terminus_address(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.get_terminus_address(block_number=args.block_number) - print(result) - - -def handle_get_terminus_main_admin_pool_id(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.get_terminus_main_admin_pool_id(block_number=args.block_number) - print(result) - - -def handle_get_terminus_pool_controller_pool(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.get_terminus_pool_controller_pool( - pool_id=args.pool_id, block_number=args.block_number - ) - print(result) - - -def handle_init_terminus_controller(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.init_terminus_controller( - terminus_address=args.terminus_address, - _terminus_main_admin_pool_terminus_address=args.terminus_main_admin_pool_terminus_address_arg, - _terminus_main_admin_pool_id=args.terminus_main_admin_pool_id_arg, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_is_approved_for_pool(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.is_approved_for_pool( - pool_id=args.pool_id, operator=args.operator, block_number=args.block_number - ) - print(result) - - -def handle_mint(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.mint( - to=args.to, - pool_id=args.pool_id, - amount=args.amount, - data=args.data, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_mint_batch(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.mint_batch( - to=args.to, - pool_i_ds=args.pool_i_ds, - amounts=args.amounts, - data=args.data, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_pool_mint_batch(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.pool_mint_batch( - id=args.id, - to_addresses=args.to_addresses, - amounts=args.amounts, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_set_contract_uri(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.set_contract_uri( - _contract_uri=args.contract_uri_arg, transaction_config=transaction_config - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_set_controller(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.set_controller( - new_controller=args.new_controller, transaction_config=transaction_config - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_set_pool_control_permissions(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.set_pool_control_permissions( - pool_id=args.pool_id, - terminus_address=args.terminus_address, - pool_controller_pool_id=args.pool_controller_pool_id, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_set_pool_controller(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.set_pool_controller( - pool_id=args.pool_id, - new_controller=args.new_controller, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_set_uri(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.set_uri( - pool_id=args.pool_id, - pool_uri=args.pool_uri, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_terminus_controller(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.terminus_controller(block_number=args.block_number) - print(result) - - -def handle_terminus_pool_capacity(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.terminus_pool_capacity( - pool_id=args.pool_id, block_number=args.block_number - ) - print(result) - - -def handle_terminus_pool_controller(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.terminus_pool_controller( - pool_id=args.pool_id, block_number=args.block_number - ) - print(result) - - -def handle_terminus_pool_supply(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.terminus_pool_supply( - pool_id=args.pool_id, block_number=args.block_number - ) - print(result) - - -def handle_total_pools(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - result = contract.total_pools(block_number=args.block_number) - print(result) - - -def handle_unapprove_for_pool(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.unapprove_for_pool( - pool_id=args.pool_id, - operator=args.operator, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_withdraw_erc1155(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.withdraw_erc1155( - token_address=args.token_address, - token_id=args.token_id, - amount=args.amount, - receiver_address=args.receiver_address, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_withdraw_erc20(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.withdraw_erc20( - token_address=args.token_address, - amount=args.amount, - receiver_address=args.receiver_address, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def handle_withdraw_erc721(args: argparse.Namespace) -> None: - network.connect(args.network) - contract = TerminusControllerFacet(args.address) - transaction_config = get_transaction_config(args) - result = contract.withdraw_erc721( - token_address=args.token_address, - token_id=args.token_id, - receiver_address=args.receiver_address, - transaction_config=transaction_config, - ) - print(result) - if args.verbose: - print(result.info()) - - -def generate_cli() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description="CLI for TerminusControllerFacet") - parser.set_defaults(func=lambda _: parser.print_help()) - subcommands = parser.add_subparsers() - - deploy_parser = subcommands.add_parser("deploy") - add_default_arguments(deploy_parser, True) - deploy_parser.set_defaults(func=handle_deploy) - - verify_contract_parser = subcommands.add_parser("verify-contract") - add_default_arguments(verify_contract_parser, False) - verify_contract_parser.set_defaults(func=handle_verify_contract) - - approve_for_pool_parser = subcommands.add_parser("approve-for-pool") - add_default_arguments(approve_for_pool_parser, True) - approve_for_pool_parser.add_argument( - "--pool-id", required=True, help="Type: uint256", type=int - ) - approve_for_pool_parser.add_argument( - "--operator", required=True, help="Type: address" - ) - approve_for_pool_parser.set_defaults(func=handle_approve_for_pool) - - balance_of_parser = subcommands.add_parser("balance-of") - add_default_arguments(balance_of_parser, False) - balance_of_parser.add_argument("--account", required=True, help="Type: address") - balance_of_parser.add_argument( - "--id", required=True, help="Type: uint256", type=int - ) - balance_of_parser.set_defaults(func=handle_balance_of) - - burn_parser = subcommands.add_parser("burn") - add_default_arguments(burn_parser, True) - burn_parser.add_argument("--from-arg", required=True, help="Type: address") - burn_parser.add_argument("--pool-id", required=True, help="Type: uint256", type=int) - burn_parser.add_argument("--amount", required=True, help="Type: uint256", type=int) - burn_parser.set_defaults(func=handle_burn) - - contract_uri_parser = subcommands.add_parser("contract-uri") - add_default_arguments(contract_uri_parser, False) - contract_uri_parser.set_defaults(func=handle_contract_uri) - - create_pool_v1_parser = subcommands.add_parser("create-pool-v1") - add_default_arguments(create_pool_v1_parser, True) - create_pool_v1_parser.add_argument( - "--capacity-arg", required=True, help="Type: uint256", type=int - ) - create_pool_v1_parser.add_argument( - "--transferable-arg", - required=True, - help="Type: bool", - type=boolean_argument_type, - ) - create_pool_v1_parser.add_argument( - "--burnable-arg", required=True, help="Type: bool", type=boolean_argument_type - ) - create_pool_v1_parser.set_defaults(func=handle_create_pool_v1) - - create_simple_pool_parser = subcommands.add_parser("create-simple-pool") - add_default_arguments(create_simple_pool_parser, True) - create_simple_pool_parser.add_argument( - "--capacity-arg", required=True, help="Type: uint256", type=int - ) - create_simple_pool_parser.set_defaults(func=handle_create_simple_pool) - - drain_erc1155_parser = subcommands.add_parser("drain-erc1155") - add_default_arguments(drain_erc1155_parser, True) - drain_erc1155_parser.add_argument( - "--token-address", required=True, help="Type: address" - ) - drain_erc1155_parser.add_argument( - "--token-id", required=True, help="Type: uint256", type=int - ) - drain_erc1155_parser.add_argument( - "--receiver-address", required=True, help="Type: address" - ) - drain_erc1155_parser.set_defaults(func=handle_drain_erc1155) - - drain_erc20_parser = subcommands.add_parser("drain-erc20") - add_default_arguments(drain_erc20_parser, True) - drain_erc20_parser.add_argument( - "--token-address", required=True, help="Type: address" - ) - drain_erc20_parser.add_argument( - "--receiver-address", required=True, help="Type: address" - ) - drain_erc20_parser.set_defaults(func=handle_drain_erc20) - - get_terminus_address_parser = subcommands.add_parser("get-terminus-address") - add_default_arguments(get_terminus_address_parser, False) - get_terminus_address_parser.set_defaults(func=handle_get_terminus_address) - - get_terminus_main_admin_pool_id_parser = subcommands.add_parser( - "get-terminus-main-admin-pool-id" - ) - add_default_arguments(get_terminus_main_admin_pool_id_parser, False) - get_terminus_main_admin_pool_id_parser.set_defaults( - func=handle_get_terminus_main_admin_pool_id - ) - - get_terminus_pool_controller_pool_parser = subcommands.add_parser( - "get-terminus-pool-controller-pool" - ) - add_default_arguments(get_terminus_pool_controller_pool_parser, False) - get_terminus_pool_controller_pool_parser.add_argument( - "--pool-id", required=True, help="Type: uint256", type=int - ) - get_terminus_pool_controller_pool_parser.set_defaults( - func=handle_get_terminus_pool_controller_pool - ) - - init_terminus_controller_parser = subcommands.add_parser("init-terminus-controller") - add_default_arguments(init_terminus_controller_parser, True) - init_terminus_controller_parser.add_argument( - "--terminus-address", required=True, help="Type: address" - ) - init_terminus_controller_parser.add_argument( - "--terminus-main-admin-pool-terminus-address-arg", - required=True, - help="Type: address", - ) - init_terminus_controller_parser.add_argument( - "--terminus-main-admin-pool-id-arg", - required=True, - help="Type: uint256", - type=int, - ) - init_terminus_controller_parser.set_defaults(func=handle_init_terminus_controller) - - is_approved_for_pool_parser = subcommands.add_parser("is-approved-for-pool") - add_default_arguments(is_approved_for_pool_parser, False) - is_approved_for_pool_parser.add_argument( - "--pool-id", required=True, help="Type: uint256", type=int - ) - is_approved_for_pool_parser.add_argument( - "--operator", required=True, help="Type: address" - ) - is_approved_for_pool_parser.set_defaults(func=handle_is_approved_for_pool) - - mint_parser = subcommands.add_parser("mint") - add_default_arguments(mint_parser, True) - mint_parser.add_argument("--to", required=True, help="Type: address") - mint_parser.add_argument("--pool-id", required=True, help="Type: uint256", type=int) - mint_parser.add_argument("--amount", required=True, help="Type: uint256", type=int) - mint_parser.add_argument( - "--data", required=True, help="Type: bytes", type=bytes_argument_type - ) - mint_parser.set_defaults(func=handle_mint) - - mint_batch_parser = subcommands.add_parser("mint-batch") - add_default_arguments(mint_batch_parser, True) - mint_batch_parser.add_argument("--to", required=True, help="Type: address") - mint_batch_parser.add_argument( - "--pool-i-ds", required=True, help="Type: uint256[]", nargs="+" - ) - mint_batch_parser.add_argument( - "--amounts", required=True, help="Type: uint256[]", nargs="+" - ) - mint_batch_parser.add_argument( - "--data", required=True, help="Type: bytes", type=bytes_argument_type - ) - mint_batch_parser.set_defaults(func=handle_mint_batch) - - pool_mint_batch_parser = subcommands.add_parser("pool-mint-batch") - add_default_arguments(pool_mint_batch_parser, True) - pool_mint_batch_parser.add_argument( - "--id", required=True, help="Type: uint256", type=int - ) - pool_mint_batch_parser.add_argument( - "--to-addresses", required=True, help="Type: address[]", nargs="+" - ) - pool_mint_batch_parser.add_argument( - "--amounts", required=True, help="Type: uint256[]", nargs="+" - ) - pool_mint_batch_parser.set_defaults(func=handle_pool_mint_batch) - - set_contract_uri_parser = subcommands.add_parser("set-contract-uri") - add_default_arguments(set_contract_uri_parser, True) - set_contract_uri_parser.add_argument( - "--contract-uri-arg", required=True, help="Type: string", type=str - ) - set_contract_uri_parser.set_defaults(func=handle_set_contract_uri) - - set_controller_parser = subcommands.add_parser("set-controller") - add_default_arguments(set_controller_parser, True) - set_controller_parser.add_argument( - "--new-controller", required=True, help="Type: address" - ) - set_controller_parser.set_defaults(func=handle_set_controller) - - set_pool_control_permissions_parser = subcommands.add_parser( - "set-pool-control-permissions" - ) - add_default_arguments(set_pool_control_permissions_parser, True) - set_pool_control_permissions_parser.add_argument( - "--pool-id", required=True, help="Type: uint256", type=int - ) - set_pool_control_permissions_parser.add_argument( - "--terminus-address", required=True, help="Type: address" - ) - set_pool_control_permissions_parser.add_argument( - "--pool-controller-pool-id", required=True, help="Type: uint256", type=int - ) - set_pool_control_permissions_parser.set_defaults( - func=handle_set_pool_control_permissions - ) - - set_pool_controller_parser = subcommands.add_parser("set-pool-controller") - add_default_arguments(set_pool_controller_parser, True) - set_pool_controller_parser.add_argument( - "--pool-id", required=True, help="Type: uint256", type=int - ) - set_pool_controller_parser.add_argument( - "--new-controller", required=True, help="Type: address" - ) - set_pool_controller_parser.set_defaults(func=handle_set_pool_controller) - - set_uri_parser = subcommands.add_parser("set-uri") - add_default_arguments(set_uri_parser, True) - set_uri_parser.add_argument( - "--pool-id", required=True, help="Type: uint256", type=int - ) - set_uri_parser.add_argument( - "--pool-uri", required=True, help="Type: string", type=str - ) - set_uri_parser.set_defaults(func=handle_set_uri) - - terminus_controller_parser = subcommands.add_parser("terminus-controller") - add_default_arguments(terminus_controller_parser, False) - terminus_controller_parser.set_defaults(func=handle_terminus_controller) - - terminus_pool_capacity_parser = subcommands.add_parser("terminus-pool-capacity") - add_default_arguments(terminus_pool_capacity_parser, False) - terminus_pool_capacity_parser.add_argument( - "--pool-id", required=True, help="Type: uint256", type=int - ) - terminus_pool_capacity_parser.set_defaults(func=handle_terminus_pool_capacity) - - terminus_pool_controller_parser = subcommands.add_parser("terminus-pool-controller") - add_default_arguments(terminus_pool_controller_parser, False) - terminus_pool_controller_parser.add_argument( - "--pool-id", required=True, help="Type: uint256", type=int - ) - terminus_pool_controller_parser.set_defaults(func=handle_terminus_pool_controller) - - terminus_pool_supply_parser = subcommands.add_parser("terminus-pool-supply") - add_default_arguments(terminus_pool_supply_parser, False) - terminus_pool_supply_parser.add_argument( - "--pool-id", required=True, help="Type: uint256", type=int - ) - terminus_pool_supply_parser.set_defaults(func=handle_terminus_pool_supply) - - total_pools_parser = subcommands.add_parser("total-pools") - add_default_arguments(total_pools_parser, False) - total_pools_parser.set_defaults(func=handle_total_pools) - - unapprove_for_pool_parser = subcommands.add_parser("unapprove-for-pool") - add_default_arguments(unapprove_for_pool_parser, True) - unapprove_for_pool_parser.add_argument( - "--pool-id", required=True, help="Type: uint256", type=int - ) - unapprove_for_pool_parser.add_argument( - "--operator", required=True, help="Type: address" - ) - unapprove_for_pool_parser.set_defaults(func=handle_unapprove_for_pool) - - withdraw_erc1155_parser = subcommands.add_parser("withdraw-erc1155") - add_default_arguments(withdraw_erc1155_parser, True) - withdraw_erc1155_parser.add_argument( - "--token-address", required=True, help="Type: address" - ) - withdraw_erc1155_parser.add_argument( - "--token-id", required=True, help="Type: uint256", type=int - ) - withdraw_erc1155_parser.add_argument( - "--amount", required=True, help="Type: uint256", type=int - ) - withdraw_erc1155_parser.add_argument( - "--receiver-address", required=True, help="Type: address" - ) - withdraw_erc1155_parser.set_defaults(func=handle_withdraw_erc1155) - - withdraw_erc20_parser = subcommands.add_parser("withdraw-erc20") - add_default_arguments(withdraw_erc20_parser, True) - withdraw_erc20_parser.add_argument( - "--token-address", required=True, help="Type: address" - ) - withdraw_erc20_parser.add_argument( - "--amount", required=True, help="Type: uint256", type=int - ) - withdraw_erc20_parser.add_argument( - "--receiver-address", required=True, help="Type: address" - ) - withdraw_erc20_parser.set_defaults(func=handle_withdraw_erc20) - - withdraw_erc721_parser = subcommands.add_parser("withdraw-erc721") - add_default_arguments(withdraw_erc721_parser, True) - withdraw_erc721_parser.add_argument( - "--token-address", required=True, help="Type: address" - ) - withdraw_erc721_parser.add_argument( - "--token-id", required=True, help="Type: uint256", type=int - ) - withdraw_erc721_parser.add_argument( - "--receiver-address", required=True, help="Type: address" - ) - withdraw_erc721_parser.set_defaults(func=handle_withdraw_erc721) - - return parser - - -def main() -> None: - parser = generate_cli() - args = parser.parse_args() - args.func(args) - - -if __name__ == "__main__": - main() diff --git a/cli/web3cli/core.py b/cli/web3cli/core.py index 4b05a01a..4de58ca6 100644 --- a/cli/web3cli/core.py +++ b/cli/web3cli/core.py @@ -24,6 +24,8 @@ CraftingFacet, GOFPFacet, InventoryFacet, + TerminusFacet, + TerminusInitializer, ) FACETS: Dict[str, Any] = { @@ -35,6 +37,7 @@ "CraftingFacet": CraftingFacet, "GOFPFacet": GOFPFacet, "InventoryFacet": InventoryFacet, + "TerminusFacet": TerminusFacet, } FACET_INIT_CALLDATA: Dict[str, str] = { @@ -47,6 +50,9 @@ "InventoryFacet": lambda address, *args: InventoryFacet.InventoryFacet( address ).contract.init.encode_input(*args), + "TerminusFacet": lambda address, *args: TerminusInitializer.TerminusInitializer( + address + ).contract.init.encode_input(*args), } DIAMOND_FACET_PRECEDENCE: List[str] = [ @@ -66,6 +72,7 @@ class EngineFeatures(Enum): DROPPER = "DropperFacet" GOFP = "GOFPFacet" INVENTORY = "InventoryFacet" + TERMINUS = "TerminusFacet" def feature_from_facet_name(facet_name: str) -> Optional[EngineFeatures]: @@ -79,12 +86,14 @@ def feature_from_facet_name(facet_name: str) -> Optional[EngineFeatures]: EngineFeatures.DROPPER: ["DropperFacet"], EngineFeatures.GOFP: ["GOFPFacet"], EngineFeatures.INVENTORY: ["InventoryFacet"], + EngineFeatures.TERMINUS: ["TerminusFacet"], } FEATURE_IGNORES: Dict[EngineFeatures, List[str]] = { EngineFeatures.DROPPER: {"methods": ["init"], "selectors": []}, EngineFeatures.GOFP: {"methods": ["init"], "selectors": []}, EngineFeatures.INVENTORY: {"methods": ["init"], "selectors": []}, + EngineFeatures.TERMINUS: {"methods": [], "selectors": []}, } FACET_ACTIONS: Dict[str, int] = {"add": 0, "replace": 1, "remove": 2} @@ -710,6 +719,67 @@ def inventory_gogogo( return deployment_info +def terminus_gogogo( + transaction_config: Dict[str, Any], + diamond_cut_address: Optional[str] = None, + diamond_address: Optional[str] = None, + diamond_loupe_address: Optional[str] = None, + ownership_address: Optional[str] = None, + terminus_facet_address: Optional[str] = None, + terminus_initializer_address: Optional[str] = None, + verify_contracts: Optional[bool] = False, +) -> Dict[str, Any]: + """ + Deploys an EIP2535 Diamond contract and a TerminusFacet and mounts the TerminusFacet onto the Diamond contract. + + Returns the addresses and attachments. + """ + deployment_info = diamond_gogogo( + owner_address=transaction_config["from"].address, + transaction_config=transaction_config, + diamond_cut_address=diamond_cut_address, + diamond_address=diamond_address, + diamond_loupe_address=diamond_loupe_address, + ownership_address=ownership_address, + verify_contracts=verify_contracts, + ) + + if terminus_facet_address is None: + terminus_facet = TerminusFacet.TerminusFacet(None) + terminus_facet.deploy(transaction_config=transaction_config) + else: + terminus_facet = TerminusFacet.TerminusFacet(terminus_facet_address) + + if terminus_initializer_address is None: + terminus_initializer = TerminusInitializer.TerminusInitializer(None) + terminus_initializer.deploy(transaction_config=transaction_config) + terminus_initializer_address = terminus_initializer.address + + deployment_info["contracts"]["TerminusFacet"] = terminus_facet.address + deployment_info["contracts"]["TerminusInitializer"] = terminus_initializer_address + + if verify_contracts: + try: + terminus_facet.verify_contract() + deployment_info["verified"].append("InventoryFacet") + except Exception as e: + deployment_info["verification_errors"].append(repr(e)) + + facet_cut( + deployment_info["contracts"]["Diamond"], + "TerminusFacet", + terminus_facet.address, + "add", + transaction_config, + initializer_address=terminus_initializer_address, + feature=EngineFeatures.TERMINUS, + initializer_args=[], + ) + deployment_info["attached"].append("TerminusFacet") + + return deployment_info + + def handle_facet_cut(args: argparse.Namespace) -> None: network.connect(args.network) diamond_address = args.address @@ -805,6 +875,25 @@ def handle_inventory_gogogo(args: argparse.Namespace) -> None: json.dump(result, sys.stdout, indent=4) +def handle_terminus_gogogo(args: argparse.Namespace) -> None: + network.connect(args.network) + transaction_config = TerminusFacet.get_transaction_config(args) + result = terminus_gogogo( + transaction_config=transaction_config, + diamond_cut_address=args.diamond_cut_address, + diamond_address=args.diamond_address, + diamond_loupe_address=args.diamond_loupe_address, + ownership_address=args.ownership_address, + terminus_facet_address=args.terminus_facet_address, + terminus_initializer_address=args.terminus_initializer_address, + verify_contracts=args.verify_contracts, + ) + if args.outfile is not None: + with args.outfile: + json.dump(result, args.outfile) + json.dump(result, sys.stdout, indent=4) + + def handle_crafting_gogogo(args: argparse.Namespace) -> None: network.connect(args.network) @@ -1044,6 +1133,61 @@ def generate_cli(): ) inventory_gogogo_parser.set_defaults(func=handle_inventory_gogogo) + terminus_gogogo_parser = subcommands.add_parser( + "terminus-gogogo", + description="Deploy Terminus diamond contract", + ) + Diamond.add_default_arguments(terminus_gogogo_parser, transact=True) + terminus_gogogo_parser.add_argument( + "--verify-contracts", + action="store_true", + help="Verify contracts", + ) + terminus_gogogo_parser.add_argument( + "--diamond-cut-address", + required=False, + default=None, + help="Address to deployed DiamondCutFacet. If provided, this command skips deployment of a new DiamondCutFacet.", + ) + terminus_gogogo_parser.add_argument( + "--diamond-address", + required=False, + default=None, + help="Address to deployed Diamond contract. If provided, this command skips deployment of a new Diamond contract and simply mounts the required facets onto the existing Diamond contract. Assumes that there is no collision of selectors.", + ) + terminus_gogogo_parser.add_argument( + "--diamond-loupe-address", + required=False, + default=None, + help="Address to deployed DiamondLoupeFacet. If provided, this command skips deployment of a new DiamondLoupeFacet. It mounts the existing DiamondLoupeFacet onto the Diamond.", + ) + terminus_gogogo_parser.add_argument( + "--ownership-address", + required=False, + default=None, + help="Address to deployed OwnershipFacet. If provided, this command skips deployment of a new OwnershipFacet. It mounts the existing OwnershipFacet onto the Diamond.", + ) + terminus_gogogo_parser.add_argument( + "--terminus-facet-address", + required=False, + default=None, + help="Address to deployed TerminusFacet. If provided, this command skips deployment of a new TerminusFacet. It mounts the existing TerminusFacet onto the Diamond.", + ) + terminus_gogogo_parser.add_argument( + "--terminus-initializer-address", + required=False, + default=None, + help="Address to deployed TerminusInitializer. If provided, this command skips deployment of a new TerminusInitializer. It uses the given TerminusInitializer to initialize the diamond upon the mounting of the TerminusFacet.", + ) + terminus_gogogo_parser.add_argument( + "-o", + "--outfile", + type=argparse.FileType("w"), + default=None, + help="(Optional) file to write deployed addresses to", + ) + terminus_gogogo_parser.set_defaults(func=handle_terminus_gogogo) + lootbox_gogogo_parser = subcommands.add_parser( "lootbox-gogogo", help="Deploys Lootbox contract", diff --git a/contracts/terminus/controller/LibTerminusController.sol b/contracts/terminus/controller/LibTerminusController.sol deleted file mode 100644 index 7ad1aec7..00000000 --- a/contracts/terminus/controller/LibTerminusController.sol +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -/** - * Authors: Moonstream Engineering (engineering@moonstream.to) - * GitHub: https://github.com/bugout-dev/dao - * - */ - -pragma solidity ^0.8.9; - -struct TerminusPool { - address terminusAddress; - uint256 poolId; -} - -library LibTerminusController { - bytes32 constant TERMINUS_CONTROLLER_STORAGE_POSITION = - keccak256("moonstreamdao.eth.storage.terminus.controller"); - - struct TerminusControllerStorage { - address terminusAddress; - TerminusPool terminusMainAdminPool; - mapping(uint256 => TerminusPool) poolController; - } - - function terminusControllerStorage() - internal - pure - returns (TerminusControllerStorage storage es) - { - bytes32 position = TERMINUS_CONTROLLER_STORAGE_POSITION; - assembly { - es.slot := position - } - } -} diff --git a/contracts/terminus/controller/TerminusControllerFacet.sol b/contracts/terminus/controller/TerminusControllerFacet.sol deleted file mode 100644 index 06f1bea2..00000000 --- a/contracts/terminus/controller/TerminusControllerFacet.sol +++ /dev/null @@ -1,272 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -/** - * Authors: Moonstream Engineering (engineering@moonstream.to) - * GitHub: https://github.com/bugout-dev/dao - * - * This contract stands as a proxy for the Terminus contract - * with a ability to whitelist operators by using Terminus Pools - */ -import "@openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import "../TerminusFacet.sol"; -import "../TerminusPermissions.sol"; -import "./LibTerminusController.sol"; -import "../../TokenDrainerFacet.sol"; - -pragma solidity ^0.8.9; - -// Permissions: -// - Contract owner can change _TERMINUS_MAIN_ADMIN_POOL_ID (+ all other operations?) -// - Holder of _TERMINUS_MAIN_ADMIN_POOL_ID can change poolControllerPoolID, create pool (+ pool operations?) -// - PoolController can: mint/burn + setURI - -contract TerminusControllerFacet is TerminusPermissions, TokenDrainerFacet { - /** - * @dev Checks if the caller holds the Admin Pool token or PoolController of pool with poolID - * @param poolId The poolID to check - */ - modifier onlyPoolController(uint256 poolId) { - TerminusPool memory pool = LibTerminusController - .terminusControllerStorage() - .poolController[poolId]; - - TerminusPool memory adminPool = LibTerminusController - .terminusControllerStorage() - .terminusMainAdminPool; - require( - _holdsPoolToken(adminPool.terminusAddress, adminPool.poolId, 1) || - _holdsPoolToken(pool.terminusAddress, pool.poolId, 1), - "TerminusControllerFacet.onlyPoolController: Sender doens't hold pool controller token" - ); - _; - } - - /** - * @dev Checks if the caller holds the Admin Pool token - */ - modifier onlyMainAdmin() { - TerminusPool memory adminPool = LibTerminusController - .terminusControllerStorage() - .terminusMainAdminPool; - require( - _holdsPoolToken(adminPool.terminusAddress, adminPool.poolId, 1), - "TerminusControllerFacet.onlyPoolController: Sender doens't hold pool controller token" - ); - _; - } - - function initTerminusController( - address terminusAddress, - address _TERMINUS_MAIN_ADMIN_POOL_TERMINUS_ADDRESS, - uint256 _TERMINUS_MAIN_ADMIN_POOL_ID - ) public { - LibTerminusController.TerminusControllerStorage - storage ts = LibTerminusController.terminusControllerStorage(); - - ts.terminusMainAdminPool = TerminusPool( - _TERMINUS_MAIN_ADMIN_POOL_TERMINUS_ADDRESS, - _TERMINUS_MAIN_ADMIN_POOL_ID - ); - ts.terminusAddress = terminusAddress; - } - - function terminusContract() internal view returns (TerminusFacet) { - return - TerminusFacet( - LibTerminusController - .terminusControllerStorage() - .terminusAddress - ); - } - - function getTerminusPoolControllerPool( - uint256 poolId - ) public view returns (TerminusPool memory) { - return - LibTerminusController.terminusControllerStorage().poolController[ - poolId - ]; - } - - function getTerminusAddress() public view returns (address) { - return - LibTerminusController.terminusControllerStorage().terminusAddress; - } - - function getTerminusMainAdminPoolId() - public - view - returns (TerminusPool memory) - { - return - LibTerminusController - .terminusControllerStorage() - .terminusMainAdminPool; - } - - /** - * @dev Gives permission to the holder of the (poolControllerPoolId,terminusAddress) - * to mint/burn/setURI for the pool with poolId - */ - function setPoolControlPermissions( - uint256 poolId, - address terminusAddress, - uint256 poolControllerPoolId - ) public onlyMainAdmin { - LibTerminusController.terminusControllerStorage().poolController[ - poolId - ] = TerminusPool(terminusAddress, poolControllerPoolId); - } - - // PROXY FUNCTIONS: - - /** - * @dev Sets the controller of the terminus contract - */ - function setController(address newController) external { - LibDiamond.enforceIsContractOwner(); - terminusContract().setController(newController); - } - - function poolMintBatch( - uint256 id, - address[] memory toAddresses, - uint256[] memory amounts - ) public onlyPoolController(id) { - terminusContract().poolMintBatch(id, toAddresses, amounts); - } - - function terminusController() external view returns (address) { - return terminusContract().terminusController(); - } - - function contractURI() public view returns (string memory) { - return terminusContract().contractURI(); - } - - function setContractURI(string memory _contractURI) external onlyMainAdmin { - terminusContract().setContractURI(_contractURI); - } - - function setURI( - uint256 poolID, - string memory poolURI - ) external onlyPoolController(poolID) { - terminusContract().setURI(poolID, poolURI); - } - - function totalPools() external view returns (uint256) { - return terminusContract().totalPools(); - } - - function setPoolController( - uint256 poolID, - address newController - ) external onlyMainAdmin { - terminusContract().setPoolController(poolID, newController); - } - - function terminusPoolController( - uint256 poolID - ) external view returns (address) { - return terminusContract().terminusPoolController(poolID); - } - - function terminusPoolCapacity( - uint256 poolID - ) external view returns (uint256) { - return terminusContract().terminusPoolCapacity(poolID); - } - - function terminusPoolSupply( - uint256 poolID - ) external view returns (uint256) { - return terminusContract().terminusPoolSupply(poolID); - } - - function isApprovedForPool( - uint256 poolID, - address operator - ) public view returns (bool) { - return terminusContract().isApprovedForPool(poolID, operator); - } - - function approveForPool( - uint256 poolID, - address operator - ) external onlyPoolController(poolID) { - terminusContract().approveForPool(poolID, operator); - } - - function unapproveForPool( - uint256 poolID, - address operator - ) external onlyPoolController(poolID) { - terminusContract().unapproveForPool(poolID, operator); - } - - function _approvePoolCreationPayments() internal { - IERC20 paymentToken = IERC20(terminusContract().paymentToken()); - uint256 fee = terminusContract().poolBasePrice(); - uint256 contractBalance = paymentToken.balanceOf(address(this)); - require( - contractBalance >= fee, - "TerminusControllerFacet._getPoolCreationPayments: Not enough funds, pls transfet payment tokens to terminusController contract" - ); - paymentToken.approve(getTerminusAddress(), fee); - } - - function createSimplePool( - uint256 _capacity - ) external onlyMainAdmin returns (uint256) { - _approvePoolCreationPayments(); - return terminusContract().createSimplePool(_capacity); - } - - function createPoolV1( - uint256 _capacity, - bool _transferable, - bool _burnable - ) external onlyMainAdmin returns (uint256) { - _approvePoolCreationPayments(); - return - terminusContract().createPoolV1( - _capacity, - _transferable, - _burnable - ); - } - - function mint( - address to, - uint256 poolID, - uint256 amount, - bytes memory data - ) external onlyPoolController(poolID) { - terminusContract().mint(to, poolID, amount, data); - } - - function mintBatch( - address to, - uint256[] memory poolIDs, - uint256[] memory amounts, - bytes memory data - ) external onlyMainAdmin { - terminusContract().mintBatch(to, poolIDs, amounts, data); - } - - function burn( - address from, - uint256 poolID, - uint256 amount - ) external onlyPoolController(poolID) { - terminusContract().burn(from, poolID, amount); - } - - function balanceOf( - address account, - uint256 id - ) public view returns (uint256) { - return terminusContract().balanceOf(account, id); - } -}