Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 2b1b254

Browse files
wip
1 parent d58c81d commit 2b1b254

File tree

5 files changed

+111
-2
lines changed

5 files changed

+111
-2
lines changed

thirdweb/contracts/maps.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Marketplace,
1212
NFTDrop,
1313
EditionDrop,
14+
TokenDrop,
1415
Multiwrap,
1516
)
1617

@@ -22,6 +23,7 @@
2223
Marketplace.contract_type: Marketplace, # type: ignore
2324
NFTDrop.contract_type: NFTDrop, # type: ignore
2425
EditionDrop.contract_type: EditionDrop, # type: ignore
26+
TokenDrop.contract_type: TokenDrop, # type: ignore
2527
Multiwrap.contract_type: Multiwrap, # type: ignore
2628
}
2729

@@ -32,6 +34,7 @@
3234
Marketplace.contract_type: "Marketplace",
3335
NFTDrop.contract_type: "DropERC721",
3436
EditionDrop.contract_type: "DropERC1155",
37+
TokenDrop.contract_type: "DropERC20",
3538
Multiwrap.contract_type: "Multiwrap",
3639
}
3740

@@ -42,5 +45,6 @@
4245
"Marketplace": Marketplace.contract_type,
4346
"DropERC721": NFTDrop.contract_type,
4447
"DropERC1155": EditionDrop.contract_type,
48+
"DropERC20": TokenDrop.contract_type,
4549
"Multiwrap": Multiwrap.contract_type,
4650
}

thirdweb/contracts/token_drop.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from typing import Any, Final, List, Optional
2+
from thirdweb.abi import DropERC20
3+
from thirdweb.abi.drop_erc20 import IDropAllowlistProof
4+
from thirdweb.constants.role import Role
5+
from thirdweb.core.classes.contract_events import ContractEvents
6+
from thirdweb.core.classes.contract_metadata import ContractMetadata
7+
from thirdweb.core.classes.contract_platform_fee import ContractPlatformFee
8+
from thirdweb.core.classes.contract_roles import ContractRoles
9+
from thirdweb.core.classes.contract_sales import ContractPrimarySale
10+
from thirdweb.core.classes.contract_wrapper import ContractWrapper
11+
from thirdweb.core.classes.drop_claim_conditions import DropClaimConditions
12+
from thirdweb.core.classes.erc_20_standard import ERC20Standard
13+
from thirdweb.core.classes.ipfs_storage import IpfsStorage
14+
from thirdweb.types.contract import ContractType
15+
from thirdweb.types.currency import CurrencyValue, Price, TokenAmount
16+
from thirdweb.types.sdk import SDKOptions
17+
from thirdweb.types.settings.metadata import TokenDropContractMetadata
18+
from eth_account.account import LocalAccount
19+
from web3 import Web3
20+
21+
from thirdweb.types.tx import TxResultWithId
22+
23+
24+
class TokenDrop(ERC20Standard[DropERC20]):
25+
"""
26+
Setup Tokens that are minted as users claim them.
27+
28+
```python
29+
from thirdweb import ThirdwebSDK
30+
31+
# You can customize this to a supported network or your own RPC URL
32+
network = "mumbai"
33+
34+
# Now we can create a new instance of the SDK
35+
sdk = ThirdwebSDK(network)
36+
37+
# If you want to send transactions, you can instantiate the SDK with a private key instead:
38+
# sdk = ThirdwebSDK.from_private_key(PRIVATE_KEY, network)
39+
40+
contract = sdk.get_token_drop("{{contract_address}}")
41+
```
42+
"""
43+
44+
_abi_type = DropERC20
45+
46+
contract_type: Final[ContractType] = ContractType.TOKEN_DROP
47+
contract_roles: Final[List[Role]] = [Role.ADMIN, Role.MINTER, Role.TRANSFER]
48+
49+
metadata: ContractMetadata[DropERC20, TokenDropContractMetadata]
50+
roles: ContractRoles
51+
primary_sale: ContractPrimarySale[DropERC20]
52+
platform_fee: ContractPlatformFee[DropERC20]
53+
claim_conditions: DropClaimConditions
54+
events: ContractEvents[DropERC20]
55+
56+
def __init__(
57+
self,
58+
provider: Web3,
59+
address: str,
60+
storage: IpfsStorage,
61+
signer: Optional[LocalAccount] = None,
62+
options: SDKOptions = SDKOptions(),
63+
):
64+
abi = DropERC20(provider, address)
65+
contract_wrapper = ContractWrapper(abi, provider, signer, options)
66+
super().__init__(contract_wrapper, storage)
67+
68+
self.metadata = ContractMetadata(
69+
contract_wrapper, storage, TokenDropContractMetadata
70+
)
71+
self.roles = ContractRoles(contract_wrapper, self.contract_roles)
72+
self.primary_sale = ContractPrimarySale(contract_wrapper)
73+
self.platform_fee = ContractPlatformFee(contract_wrapper)
74+
self.claim_conditions = DropClaimConditions(
75+
self._contract_wrapper, self.metadata, self._storage
76+
)
77+
self.events = ContractEvents(contract_wrapper)
78+
79+
def call(self, fn: str, *args) -> Any:
80+
return self._contract_wrapper.call(fn, *args)

thirdweb/core/classes/contract_deployer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
MarketplaceContractMetadata,
1919
NFTCollectionContractMetadata,
2020
TokenContractMetadata,
21+
TokenDropContractMetadata,
2122
)
2223

2324

@@ -78,6 +79,13 @@ def deploy_edition_drop(self, metadata: EditionDropContractMetadata) -> str:
7879
"""
7980

8081
return self._deploy_contract(ContractType.EDITION_DROP, metadata.to_json())
82+
83+
def deploy_token_drop(self, metadata: TokenDropContractMetadata) -> str:
84+
"""
85+
Deploy a Token Drop contract
86+
"""
87+
88+
return self._deploy_contract(ContractType.TOKEN_DROP, metadata.to_json())
8189

8290
def deploy_multiwrap(self, metadata: MultiwrapContractMetadata) -> str:
8391
"""

thirdweb/types/contract.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
IERC1155,
1313
DropERC721,
1414
DropERC1155,
15+
DropERC20,
1516
Multiwrap,
1617
)
1718
from thirdweb.abi.i_mintable_erc20 import IMintableERC20
@@ -31,6 +32,7 @@
3132
TWFactory,
3233
DropERC721,
3334
DropERC1155,
35+
DropERC20,
3436
Multiwrap,
3537
IMintableERC20
3638
],
@@ -41,13 +43,13 @@
4143

4244
TPrimarySaleABI = TypeVar(
4345
"TPrimarySaleABI",
44-
bound=Union[TokenERC721, TokenERC1155, TokenERC20, DropERC721, DropERC1155],
46+
bound=Union[TokenERC721, TokenERC1155, TokenERC20, DropERC721, DropERC1155, DropERC20],
4547
)
4648

4749
TPlatformFeeABI = TypeVar(
4850
"TPlatformFeeABI",
4951
bound=Union[
50-
TokenERC721, TokenERC1155, TokenERC20, Marketplace, DropERC721, DropERC1155
52+
TokenERC721, TokenERC1155, TokenERC20, Marketplace, DropERC721, DropERC1155, DropERC20
5153
],
5254
)
5355

@@ -65,6 +67,7 @@
6567
Marketplace,
6668
DropERC721,
6769
DropERC1155,
70+
DropERC20,
6871
Multiwrap,
6972
],
7073
)
@@ -75,6 +78,7 @@ class ContractType(Enum):
7578
NFT_COLLECTION = "nft-collection"
7679
EDITION = "edition"
7780
TOKEN = "token"
81+
TOKEN_DROP = "token-drop"
7882
MARKETPLACE = "marketplace"
7983
NFT_DROP = "nft-drop"
8084
EDITION_DROP = "edition-drop"

thirdweb/types/settings/metadata.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ class TokenContractMetadata(
9595
@staticmethod
9696
def from_json(json: Dict[str, Any]) -> "TokenContractMetadata":
9797
return from_dict(TokenContractMetadata, json)
98+
99+
@dataclass
100+
class TokenDropContractMetadata(
101+
ContractMetadataSchema,
102+
ContractSymbolSchema,
103+
ContractPrimarySaleSchema,
104+
ContractTrustedForwarderSchema,
105+
ContractPlatformFeeSchema,
106+
MerkleSchema,
107+
):
108+
@staticmethod
109+
def from_json(json: Dict[str, Any]) -> "TokenDropContractMetadata":
110+
return from_dict(TokenDropContractMetadata, json)
98111

99112

100113
@dataclass

0 commit comments

Comments
 (0)