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

add deploy_token_drop #133

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/test_token_drop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from tkinter.tix import IMAGE
from eth_account.account import LocalAccount
from thirdweb.constants.currency import ZERO_ADDRESS
from thirdweb.core.sdk import ThirdwebSDK
from thirdweb.contracts import TokenDrop
from brownie import accounts
import pytest

from thirdweb.types.settings.metadata import TokenContractMetadata


@pytest.mark.usefixtures("sdk", "primary_account")
@pytest.fixture(scope="function")
def token_drop(sdk: ThirdwebSDK, primary_account) -> TokenDrop:
sdk.update_signer(primary_account)
return sdk.get_token(
sdk.deployer.deploy_token_drop(
TokenContractMetadata(
name="SDK Token",
symbol="SDK",
primary_sale_recipient=ZERO_ADDRESS,
)
)
)
1 change: 1 addition & 0 deletions thirdweb/contracts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
from .marketplace import Marketplace
from .nft_drop import NFTDrop
from .edition_drop import EditionDrop
from .token_drop import TokenDrop
from .multiwrap import Multiwrap
from .maps import *
4 changes: 4 additions & 0 deletions thirdweb/contracts/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Marketplace,
NFTDrop,
EditionDrop,
TokenDrop,
Multiwrap,
)

Expand All @@ -22,6 +23,7 @@
Marketplace.contract_type: Marketplace, # type: ignore
NFTDrop.contract_type: NFTDrop, # type: ignore
EditionDrop.contract_type: EditionDrop, # type: ignore
TokenDrop.contract_type: TokenDrop, # type: ignore
Multiwrap.contract_type: Multiwrap, # type: ignore
}

Expand All @@ -32,6 +34,7 @@
Marketplace.contract_type: "Marketplace",
NFTDrop.contract_type: "DropERC721",
EditionDrop.contract_type: "DropERC1155",
TokenDrop.contract_type: "DropERC20",
Multiwrap.contract_type: "Multiwrap",
}

Expand All @@ -42,5 +45,6 @@
"Marketplace": Marketplace.contract_type,
"DropERC721": NFTDrop.contract_type,
"DropERC1155": EditionDrop.contract_type,
"DropERC20": TokenDrop.contract_type,
"Multiwrap": Multiwrap.contract_type,
}
74 changes: 74 additions & 0 deletions thirdweb/contracts/token_drop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from typing import Any, Final, List, Optional
from thirdweb.abi import DropERC20
from thirdweb.constants.role import Role
from thirdweb.core.classes.contract_events import ContractEvents
from thirdweb.core.classes.contract_metadata import ContractMetadata
from thirdweb.core.classes.contract_platform_fee import ContractPlatformFee
from thirdweb.core.classes.contract_roles import ContractRoles
from thirdweb.core.classes.contract_sales import ContractPrimarySale
from thirdweb.core.classes.contract_wrapper import ContractWrapper
from thirdweb.core.classes.drop_claim_conditions import DropClaimConditions
from thirdweb.core.classes.erc_20_standard import ERC20Standard
from thirdweb.core.classes.ipfs_storage import IpfsStorage
from thirdweb.types.contract import ContractType
from thirdweb.types.sdk import SDKOptions
from thirdweb.types.settings.metadata import TokenDropContractMetadata
from eth_account.account import LocalAccount
from web3 import Web3
class TokenDrop(ERC20Standard[DropERC20]):
"""
Setup Tokens that are minted as users claim them.

```python
from thirdweb import ThirdwebSDK

# You can customize this to a supported network or your own RPC URL
network = "mumbai"

# Now we can create a new instance of the SDK
sdk = ThirdwebSDK(network)

# If you want to send transactions, you can instantiate the SDK with a private key instead:
# sdk = ThirdwebSDK.from_private_key(PRIVATE_KEY, network)

contract = sdk.get_token_drop("{{contract_address}}")
```
"""

_abi_type = DropERC20

contract_type: Final[ContractType] = ContractType.TOKEN_DROP
contract_roles: Final[List[Role]] = [Role.ADMIN, Role.MINTER, Role.TRANSFER]

metadata: ContractMetadata[DropERC20, TokenDropContractMetadata]
roles: ContractRoles
primary_sale: ContractPrimarySale[DropERC20]
platform_fee: ContractPlatformFee[DropERC20]
claim_conditions: DropClaimConditions
events: ContractEvents[DropERC20]

def __init__(
self,
provider: Web3,
address: str,
storage: IpfsStorage,
signer: Optional[LocalAccount] = None,
options: SDKOptions = SDKOptions(),
):
abi = DropERC20(provider, address)
contract_wrapper = ContractWrapper(abi, provider, signer, options)
super().__init__(contract_wrapper, storage)

self.metadata = ContractMetadata(
contract_wrapper, storage, TokenDropContractMetadata
)
self.roles = ContractRoles(contract_wrapper, self.contract_roles)
self.primary_sale = ContractPrimarySale(contract_wrapper)
self.platform_fee = ContractPlatformFee(contract_wrapper)
self.claim_conditions = DropClaimConditions(
self._contract_wrapper, self.metadata, self._storage
)
self.events = ContractEvents(contract_wrapper)

def call(self, fn: str, *args) -> Any:
return self._contract_wrapper.call(fn, *args)
8 changes: 8 additions & 0 deletions thirdweb/core/classes/contract_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
MarketplaceContractMetadata,
NFTCollectionContractMetadata,
TokenContractMetadata,
TokenDropContractMetadata,
)


Expand Down Expand Up @@ -78,6 +79,13 @@ def deploy_edition_drop(self, metadata: EditionDropContractMetadata) -> str:
"""

return self._deploy_contract(ContractType.EDITION_DROP, metadata.to_json())

def deploy_token_drop(self, metadata: TokenDropContractMetadata) -> str:
"""
Deploy a Token Drop contract
"""

return self._deploy_contract(ContractType.TOKEN_DROP, metadata.to_json())

def deploy_multiwrap(self, metadata: MultiwrapContractMetadata) -> str:
"""
Expand Down
8 changes: 6 additions & 2 deletions thirdweb/types/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
IERC1155,
DropERC721,
DropERC1155,
DropERC20,
Multiwrap,
)
from thirdweb.abi.i_mintable_erc20 import IMintableERC20
Expand All @@ -31,6 +32,7 @@
TWFactory,
DropERC721,
DropERC1155,
DropERC20,
Multiwrap,
IMintableERC20
],
Expand All @@ -41,13 +43,13 @@

TPrimarySaleABI = TypeVar(
"TPrimarySaleABI",
bound=Union[TokenERC721, TokenERC1155, TokenERC20, DropERC721, DropERC1155],
bound=Union[TokenERC721, TokenERC1155, TokenERC20, DropERC721, DropERC1155, DropERC20],
)

TPlatformFeeABI = TypeVar(
"TPlatformFeeABI",
bound=Union[
TokenERC721, TokenERC1155, TokenERC20, Marketplace, DropERC721, DropERC1155
TokenERC721, TokenERC1155, TokenERC20, Marketplace, DropERC721, DropERC1155, DropERC20
],
)

Expand All @@ -65,6 +67,7 @@
Marketplace,
DropERC721,
DropERC1155,
DropERC20,
Multiwrap,
],
)
Expand All @@ -75,6 +78,7 @@ class ContractType(Enum):
NFT_COLLECTION = "nft-collection"
EDITION = "edition"
TOKEN = "token"
TOKEN_DROP = "token-drop"
MARKETPLACE = "marketplace"
NFT_DROP = "nft-drop"
EDITION_DROP = "edition-drop"
Expand Down
13 changes: 13 additions & 0 deletions thirdweb/types/settings/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ class TokenContractMetadata(
@staticmethod
def from_json(json: Dict[str, Any]) -> "TokenContractMetadata":
return from_dict(TokenContractMetadata, json)

@dataclass
class TokenDropContractMetadata(
ContractMetadataSchema,
ContractSymbolSchema,
ContractPrimarySaleSchema,
ContractTrustedForwarderSchema,
ContractPlatformFeeSchema,
MerkleSchema,
):
@staticmethod
def from_json(json: Dict[str, Any]) -> "TokenDropContractMetadata":
return from_dict(TokenDropContractMetadata, json)


@dataclass
Expand Down