diff --git a/cdp/__init__.py b/cdp/__init__.py index 4ed7d0e..a894791 100644 --- a/cdp/__init__.py +++ b/cdp/__init__.py @@ -6,6 +6,7 @@ from cdp.cdp import Cdp from cdp.contract_invocation import ContractInvocation from cdp.faucet_transaction import FaucetTransaction +from cdp.smart_contract import SmartContract from cdp.sponsored_send import SponsoredSend from cdp.trade import Trade from cdp.transaction import Transaction diff --git a/cdp/smart_contract.py b/cdp/smart_contract.py index 7f2ea80..b592b55 100644 --- a/cdp/smart_contract.py +++ b/cdp/smart_contract.py @@ -22,9 +22,9 @@ class SmartContract: class Type(Enum): """Enumeration of SmartContract types.""" - ERC20 = "ERC20" - ERC721 = "ERC721" - ERC1155 = "ERC1155" + ERC20 = "erc20" + ERC721 = "erc721" + ERC1155 = "erc1155" def __str__(self) -> str: """Return a string representation of the Type.""" @@ -34,30 +34,17 @@ def __repr__(self) -> str: """Return a string representation of the Type.""" return str(self) - class ContractOptions: - """Base class for contract options.""" - - def __init__(self, name: str, symbol: str): - """Initialize the ContractOptions. - - Args: - name: The name of the contract. - symbol: The symbol of the contract. - - """ - self.name = name - self.symbol = symbol - class TokenContractOptions(dict[str, Any]): """Options for token contracts (ERC20).""" - def __init__(self, name: str, symbol: str, total_supply: int): + def __init__(self, name: str, symbol: str, total_supply: str): """Initialize the TokenContractOptions. Args: name: The name of the token. symbol: The symbol of the token. total_supply: The total supply of the token. + """ super().__init__(name=name, symbol=symbol, total_supply=total_supply) @@ -71,6 +58,7 @@ def __init__(self, name: str, symbol: str, base_uri: str): name: The name of the NFT collection. symbol: The symbol of the NFT collection. base_uri: The base URI for the NFT metadata. + """ super().__init__(name=name, symbol=symbol, base_uri=base_uri) @@ -82,6 +70,7 @@ def __init__(self, uri: str): Args: uri: The URI for all token metadata. + """ super().__init__(uri=uri) @@ -187,11 +176,11 @@ def abi(self) -> dict[str, Any]: return json.loads(self._model.abi) @property - def transaction(self) -> Transaction: - """Get the transaction associated with the smart contract deployment. + def transaction(self) -> Transaction | None: + """Get the transaction associated with the contract invocation. Returns: - The transaction. + Transaction: The transaction. """ if self._transaction is None and self._model.transaction is not None: @@ -305,6 +294,7 @@ def create( Raises: ValueError: If the options type is unsupported. + """ if isinstance(options, cls.TokenContractOptions): openapi_options = TokenContractOptions(**options) @@ -317,7 +307,7 @@ def create( smart_contract_options = SmartContractOptions(actual_instance=openapi_options) - smart_contract_request = CreateSmartContractRequest( + create_smart_contract_request = CreateSmartContractRequest( type=type.value, options=smart_contract_options, ) @@ -325,7 +315,7 @@ def create( model = Cdp.api_clients.smart_contracts.create_smart_contract( wallet_id=wallet_id, address_id=address_id, - smart_contract_request=smart_contract_request, + create_smart_contract_request=create_smart_contract_request, ) return cls(model) diff --git a/cdp/wallet_address.py b/cdp/wallet_address.py index 04c82d9..f7e983a 100644 --- a/cdp/wallet_address.py +++ b/cdp/wallet_address.py @@ -197,9 +197,7 @@ def invoke_contract( return invocation - def deploy_token( - self, name: str, symbol: str, total_supply: int | float | Decimal | str - ) -> SmartContract: + def deploy_token(self, name: str, symbol: str, total_supply: str) -> SmartContract: """Deploy a token smart contract. Args: @@ -215,7 +213,9 @@ def deploy_token( wallet_id=self.wallet_id, address_id=self.address_id, type=SmartContract.Type.ERC20, - options=SmartContract.TokenOptions(name=name, symbol=symbol, total_supply=total_supply), + options=SmartContract.TokenContractOptions( + name=name, symbol=symbol, total_supply=total_supply + ), ) if Cdp.use_server_signer: @@ -242,7 +242,7 @@ def deploy_nft(self, name: str, symbol: str, base_uri: str) -> SmartContract: wallet_id=self.wallet_id, address_id=self.address_id, type=SmartContract.Type.ERC721, - options=SmartContract.NFTOptions(name=name, symbol=symbol, base_uri=base_uri), + options=SmartContract.NFTContractOptions(name=name, symbol=symbol, base_uri=base_uri), ) if Cdp.use_server_signer: @@ -267,7 +267,7 @@ def deploy_multi_token(self, uri: str) -> SmartContract: wallet_id=self.wallet_id, address_id=self.address_id, type=SmartContract.Type.ERC1155, - options=SmartContract.MultiTokenOptions(uri=uri), + options=SmartContract.MultiTokenContractOptions(uri=uri), ) if Cdp.use_server_signer: