Thanks to visit codestin.com
Credit goes to github.com

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

Commit 27e8ef7

Browse files
committed
(wip) draft market module
1 parent e633e21 commit 27e8ef7

File tree

7 files changed

+1781
-9
lines changed

7 files changed

+1781
-9
lines changed

nftlabs/abi/market/__init__.py

Lines changed: 1608 additions & 0 deletions
Large diffs are not rendered by default.

nftlabs/modules/currency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ..abi.erc20 import ERC20
77
from web3 import Web3
88
from typing import List, Dict
9-
9+
1010

1111
class CurrencyModule(BaseModule):
1212
address: str

nftlabs/modules/market.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
from web3 import Web3
2+
from typing import List, Dict
3+
from . import BaseModule
4+
from ..types import Role, Listing as ListingType
5+
from ..abi.market import Market
6+
#_types
7+
8+
9+
10+
# from ..errors import NoSignerException
11+
# from ..abi.erc20 import ERC20
12+
13+
14+
class MarketModule(BaseModule):
15+
address: str
16+
__abi_module: Market
17+
def __init__(self, client: Web3, address: str):
18+
super().__init__()
19+
self.address = address
20+
self.__abi_module = Market(client, address)
21+
22+
#todo: return types
23+
def list_item(self, arg: ListArg):
24+
if arg.properties is None:
25+
arg.properties = {}
26+
else:
27+
final_properties = copy.copy(arg.properties)
28+
tx = self.__abi_module.list.build_transaction(
29+
arg.asset_contract,
30+
arg.token_id,
31+
arg.currency,
32+
arg.price_per_token,
33+
arg.quantity,
34+
arg.tokens_per_buyer,
35+
arg.seconds_until_start,
36+
arg.seconds_until_end,
37+
self.get_transact_opts()
38+
)
39+
self.execute_tx(tx)
40+
41+
def unlist_item(self, listing_id, quantity):
42+
tx = self.__abi_module.unlist.build_transaction(
43+
listing_id,
44+
quantity,
45+
self.get_transact_opts()
46+
)
47+
self.execute_tx(tx)
48+
49+
def add_to_listing(self, listing_id, quantity):
50+
tx = self.__abi_module.add_to_listing.build_transaction(
51+
listing_id,
52+
quantity,
53+
self.get_transact_opts()
54+
)
55+
self.execute_tx(tx)
56+
57+
def updateListingParams(self, args: ListUpdate):
58+
tx = self.__abi_module.updateListingParams(
59+
args.listing_id,
60+
args.price_per_token,
61+
args.currency,
62+
args.tokens_per_buyer,
63+
args.seconds_until_start,
64+
args.seconds_until_end
65+
)
66+
self.execute_tx(tx)
67+
68+
def buy(self, listing_id: int, quantity: int):
69+
tx = self.__abi_module.buy.build_transaction(
70+
listing_id,
71+
quantity,
72+
buyer,
73+
self.get_transact_opts()
74+
)
75+
self.execute_tx(tx)
76+
77+
def set_market_fee_bps(self, amount: int):
78+
tx = self.__abi_module.set_market_fee_bps.build_transaction(
79+
amount,
80+
self.get_transact_opts())
81+
self.execute_tx(tx)
82+
83+
def get(self, listing_id) -> List:
84+
self.__abi_module.get_listing.call(listing_id)
85+
86+
def get_all(self) -> List[ListingType]:
87+
self.__abi_module.get_all_listings.call()
88+
89+
def get_all_by_seller(self, seller: str) -> List[ListingType]:
90+
self.__abi_module.get_listings_by_seller.call(seller)
91+
92+
def get_all_by_asset_contract(self, asset_contract: str) -> List[ListingType]:
93+
self.__abi_module.get_listings_by_asset_contract.call(asset_contract)
94+
95+
def get_all_by_asset(self, asset: str) -> List[ListingType]:
96+
self.__abi_module.get_listings_by_asset.call(asset)
97+
98+
99+
def grant_role(self, role: Role, address: str):
100+
role_hash = role.get_hash()
101+
tx = self.__abi_module.grant_role.build_transaction(
102+
role_hash,
103+
address,
104+
self.get_transact_opts()
105+
)
106+
107+
self.execute_tx(tx)
108+
109+
def revoke_role(self, role: Role, address: str):
110+
role_hash = role.get_hash()
111+
tx = self.__abi_module.revoke_role.build_transaction(
112+
role_hash,
113+
address,
114+
self.get_transact_opts()
115+
)
116+
self.execute_tx(tx)
117+
118+
def total_supply(self) -> int:
119+
self.__abi_module.total_listings.call()
120+
121+

nftlabs/modules/market_types.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass.dataclass
5+
class ListArg:
6+
asset_contract: str
7+
token_id: int
8+
currency: str
9+
price_per_token: int
10+
quantity: int
11+
tokens_per_buyer: int
12+
seconds_until_start: int
13+
seconds_until_end: int
14+
15+
16+
@dataclass.dataclass
17+
class ListUpdate:
18+
listing_id : int
19+
price_per_token: int
20+
currency: int
21+
tokens_per_buyer: int
22+
seconds_until_start: int
23+
seconds_until_end: int

nftlabs/modules/nft.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from ..types import NFT as NftType, Role
1212
from .nft_types import MintArg
13-
13+
1414

1515
class NftModule(BaseModule):
1616
address: str
@@ -54,9 +54,6 @@ def total_supply(self) -> int:
5454
return self.__abi_module.total_supply.call()
5555

5656
def get(self, nft_id: int) -> NftType:
57-
return self.__get_metadata(nft_id)
58-
59-
def __get_metadata(self, nft_id: int) -> NftType:
6057
uri = self.__get_metadata_uri(nft_id)
6158
meta = self.get_storage().get(uri)
6259
meta_obj: NftType = NftType.from_json(meta)
@@ -107,6 +104,7 @@ def transfer_from(self, from_address: str, to_address: str, token_id: int):
107104
"""
108105
Transfers NFT from the current signers wallet to another wallet
109106
"""
107+
110108
def transfer(self, to_address: str, token_id: int):
111109
tx = self.__abi_module.safe_transfer_from1.build_transaction(
112110
self.get_signer_address(),
@@ -138,6 +136,10 @@ def get_owned(self, address: str = "") -> List[NftType]:
138136

139137
def __token_of_owner_by_index(self, address: str, token_id: int) -> int:
140138
return self.__abi_module.token_of_owner_by_index.call(address, token_id)
139+
140+
def get_creator(self, token_id: int) -> str:
141+
return self.__abi_module.get_creator.call(token_id)
142+
141143

142144
"""
143145
Returns balance of the current signers wallet
@@ -161,11 +163,13 @@ def set_approval(self, operator: str, approved: bool = True):
161163

162164
def grant_role(self, role: Role, address: str):
163165
role_hash = role.get_hash()
164-
self.execute_tx(self.__abi_module.grant_role.build_transaction(
165-
role_hash, address, self.get_transact_opts()
166-
))
166+
tx = self.__abi_module.grant_role.build_transaction(
167+
role_hash, address,
168+
self.get_transact_opts()
169+
)
170+
self.execute_tx(tx)
167171

168-
def revoke_role(self, role, address: str):
172+
def revoke_role(self, role: Role, address: str):
169173
role_hash = role.get_hash()
170174
self.execute_tx(self.__abi_module.revoke_role.build_transaction(
171175
role_hash, address, self.get_transact_opts()

nftlabs/types/listing.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from dataclasses import dataclass
2+
from typing import Optional, Union
3+
4+
from dataclasses_json import dataclass_json
5+
6+
7+
@dataclass_json
8+
@dataclass
9+
class Listing:
10+
name: str
11+
description: str
12+
image: str
13+
properties: Optional[Union[str, dict]] = None
14+
token_id: int
15+
uri: str

nftlabs/types/role.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Role(enum.Enum):
77
minter = "MINTER_ROLE"
88
transfer = "TRANSFER_ROLE"
99
pauser = "PAUSER_ROLE"
10+
lister = "LISTER_ROLE"
1011

1112
def get_hash(self) -> bytes:
1213
if self.name == "admin":

0 commit comments

Comments
 (0)