Skip to content

Commit 63ee81f

Browse files
Address feedback
1 parent 257ddef commit 63ee81f

File tree

2 files changed

+20
-62
lines changed

2 files changed

+20
-62
lines changed

cdp/smart_contract.py

Lines changed: 17 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import json
22
import time
33
from typing import Any
4+
from enum import Enum
45

56
from eth_account.signers.local import LocalAccount
67

78
from cdp.cdp import Cdp
89
from cdp.client.models.create_smart_contract_request import CreateSmartContractRequest
910
from cdp.client.models.deploy_smart_contract_request import DeploySmartContractRequest
1011
from cdp.client.models.smart_contract import SmartContract as SmartContractModel
11-
from cdp.client.models.smart_contract_type import SmartContractType as SmartContractTypeModel
1212
from cdp.transaction import Transaction
1313

1414

1515
class SmartContract:
1616
"""A representation of a SmartContract on the blockchain."""
1717

18-
class Type:
18+
class Type(Enum):
1919
"""Enumeration of SmartContract types."""
2020

2121
ERC20 = "ERC20"
@@ -30,28 +30,6 @@ def __repr__(self) -> str:
3030
"""Return a string representation of the Type."""
3131
return str(self)
3232

33-
class TokenOptions:
34-
"""Options for ERC20 token contracts."""
35-
36-
def __init__(self, name: str, symbol: str, total_supply: int | str):
37-
self.name = name
38-
self.symbol = symbol
39-
self.total_supply = total_supply
40-
41-
class NFTOptions:
42-
"""Options for ERC721 NFT contracts."""
43-
44-
def __init__(self, name: str, symbol: str, base_uri: str):
45-
self.name = name
46-
self.symbol = symbol
47-
self.base_uri = base_uri
48-
49-
class MultiTokenOptions:
50-
"""Options for ERC1155 multi-token contracts."""
51-
52-
def __init__(self, uri: str):
53-
self.uri = uri
54-
5533
def __init__(self, model: SmartContractModel) -> None:
5634
"""Initialize the SmartContract class.
5735
@@ -118,47 +96,30 @@ def deployer_address(self) -> str:
11896
return self._model.deployer_address
11997

12098
@property
121-
def type(self) -> str:
99+
def type(self) -> Type:
122100
"""Get the type of the smart contract.
123101
124102
Returns:
125-
str: The smart contract type.
103+
Type: The smart contract type.
126104
127105
Raises:
128106
ValueError: If the smart contract type is unknown.
129107
130108
"""
131-
if self._model.type == SmartContractTypeModel.ERC20.value:
132-
return self.Type.ERC20
133-
elif self._model.type == SmartContractTypeModel.ERC721.value:
134-
return self.Type.ERC721
135-
elif self._model.type == SmartContractTypeModel.ERC1155.value:
136-
return self.Type.ERC1155
137-
else:
109+
try:
110+
return self.Type(self._model.type)
111+
except ValueError:
138112
raise ValueError(f"Unknown smart contract type: {self._model.type}")
139113

140114
@property
141-
def options(self) -> TokenOptions | NFTOptions | MultiTokenOptions:
115+
def options(self) -> dict[str, Any]:
142116
"""Get the options of the smart contract.
143117
144118
Returns:
145-
Union[TokenOptions, NFTOptions, MultiTokenOptions]: The smart contract options.
119+
dict[str, Any]: The smart contract options.
146120
147121
"""
148-
if self.type == self.Type.ERC20:
149-
return self.TokenOptions(
150-
name=self._model.options.name,
151-
symbol=self._model.options.symbol,
152-
total_supply=self._model.options.total_supply,
153-
)
154-
elif self.type == self.Type.ERC721:
155-
return self.NFTOptions(
156-
name=self._model.options.name,
157-
symbol=self._model.options.symbol,
158-
base_uri=self._model.options.base_uri,
159-
)
160-
else:
161-
return self.MultiTokenOptions(uri=self._model.options.uri)
122+
return self._model.options.__dict__
162123

163124
@property
164125
def abi(self) -> dict[str, Any]:
@@ -240,11 +201,11 @@ def reload(self) -> "SmartContract":
240201
smart_contract_id=self.smart_contract_id,
241202
)
242203
self._model = model
243-
self._transaction = None
204+
self._update_transaction(model)
244205
return self
245206

246207
def wait(self, interval_seconds: float = 0.2, timeout_seconds: float = 10) -> "SmartContract":
247-
"""Wait until the smart contract deployment is confirmed on the network or fails on chain.
208+
"""Wait until the smart contract deployment is confirmed on the network or fails onchain.
248209
249210
Args:
250211
interval_seconds (float): The interval to check the status of the smart contract deployment.
@@ -273,26 +234,20 @@ def create(
273234
cls,
274235
wallet_id: str,
275236
address_id: str,
276-
options: TokenOptions | NFTOptions | MultiTokenOptions,
237+
type: Type,
238+
options: dict[str, Any],
277239
) -> "SmartContract":
278240
"""Create a new SmartContract object.
279241
280242
Args:
281243
wallet_id (str): The ID of the wallet that will deploy the smart contract.
282244
address_id (str): The ID of the address that will deploy the smart contract.
283-
options (Union[TokenOptions, NFTOptions, MultiTokenOptions]): The options of the smart contract.
245+
type (Type): The type of the smart contract (ERC20, ERC721, or ERC1155).
246+
options (dict[str, Any]): The options of the smart contract.
284247
285248
"""
286-
if isinstance(options, cls.TokenOptions):
287-
type = "erc20"
288-
elif isinstance(options, cls.NFTOptions):
289-
type = "erc721"
290-
elif isinstance(options, cls.MultiTokenOptions):
291-
type = "erc1155"
292-
else:
293-
raise ValueError("Invalid options type provided")
294249
smart_contract_request = CreateSmartContractRequest(
295-
type=type,
250+
type=type.value,
296251
options=options,
297252
)
298253

cdp/wallet_address.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ def deploy_token(
214214
smart_contract = SmartContract.create(
215215
wallet_id=self.wallet_id,
216216
address_id=self.address_id,
217+
type=SmartContract.Type.ERC20,
217218
options=SmartContract.TokenOptions(name=name, symbol=symbol, total_supply=total_supply),
218219
)
219220

@@ -240,6 +241,7 @@ def deploy_nft(self, name: str, symbol: str, base_uri: str) -> SmartContract:
240241
smart_contract = SmartContract.create(
241242
wallet_id=self.wallet_id,
242243
address_id=self.address_id,
244+
type=SmartContract.Type.ERC721,
243245
options=SmartContract.NFTOptions(name=name, symbol=symbol, base_uri=base_uri),
244246
)
245247

@@ -264,6 +266,7 @@ def deploy_multi_token(self, uri: str) -> SmartContract:
264266
smart_contract = SmartContract.create(
265267
wallet_id=self.wallet_id,
266268
address_id=self.address_id,
269+
type=SmartContract.Type.ERC1155,
267270
options=SmartContract.MultiTokenOptions(uri=uri),
268271
)
269272

0 commit comments

Comments
 (0)