Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-agarwal-coinbase committed Sep 30, 2024
1 parent 74c335c commit b9b792f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
1 change: 1 addition & 0 deletions cdp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 13 additions & 23 deletions cdp/smart_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -82,6 +70,7 @@ def __init__(self, uri: str):
Args:
uri: The URI for all token metadata.
"""
super().__init__(uri=uri)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -305,6 +294,7 @@ def create(
Raises:
ValueError: If the options type is unsupported.
"""
if isinstance(options, cls.TokenContractOptions):
openapi_options = TokenContractOptions(**options)
Expand All @@ -317,15 +307,15 @@ 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,
)

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)
Expand Down
12 changes: 6 additions & 6 deletions cdp/wallet_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit b9b792f

Please sign in to comment.