-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathflows.py
252 lines (201 loc) · 7.63 KB
/
flows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import argparse
from enum import Enum
import json
import os
from re import I
import sys
import time
from typing import Any, Dict, Optional, List, Set
from .core import lootbox_item_to_tuple
from .MockErc20 import MockErc20
from brownie import network
from . import abi, Lootbox, ITerminus, InventoryFacet
MAX_UINT = 2**256 - 1
ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"
def handle_create_item_pools_from_config(args: argparse.Namespace) -> None:
with open(args.config_file, "r") as f:
config = json.load(f)
if type(config) is not list:
raise Exception("Config must be a list of equippable items.")
network.connect(args.network)
transaction_config = ITerminus.get_transaction_config(args)
equipment = ITerminus.ITerminus(args.equipment_address)
print("Started with " + str(equipment.total_pools()) + " pools.")
print("{Item Id} => {Pool Id}")
for item in config:
equipment.create_pool_v2(
MAX_UINT, True, True, item["metadata"], transaction_config
)
pool_id = equipment.total_pools()
print(item["id"] + " => " + str(pool_id))
print("Ended with " + str(equipment.total_pools()) + " pools.")
def handle_create_items_lootbox_from_config(args: argparse.Namespace) -> None:
with open(args.config_file, "r") as f:
config = json.load(f)
if type(config) is not list:
raise Exception("Config must be a list of equippable items.")
print(args.lootbox_pool_id)
network.connect(args.network)
transaction_config = ITerminus.get_transaction_config(args)
lootbox_contract = Lootbox.Lootbox(args.lootbox_address)
equipment = ITerminus.ITerminus(args.equipment_address)
lootbox_items = []
for item in config:
lootbox_items.append(
lootbox_item_to_tuple(
reward_type=1,
token_address=args.equipment_address,
token_id=item["pool_id"],
token_amount=1,
weight=int(item["weight"] * 1000),
)
)
equipment.approve_for_pool(
item["pool_id"], args.lootbox_address, transaction_config
)
print(lootbox_items)
# Magic number "1" is the random lootbox type. Currently it's only enumerated in test file.
lootbox_contract.create_lootbox_with_terminus_pool(
lootbox_items, args.lootbox_pool_id, 1, transaction_config
)
def handle_create_inventory_slots_from_config(args: argparse.Namespace) -> None:
with open(args.config_file, "r") as f:
config = json.load(f)
if type(config) is not list:
raise Exception("Config must be a list of equippable items.")
network.connect(args.network)
transaction_config = ITerminus.get_transaction_config(args)
inventory = InventoryFacet.InventoryFacet(args.inventory_address)
equipment_address = args.equipment_address
slot_type_mapping = dict()
slot_mapping = dict()
pool_mapping = dict()
# No good way to search the existing slot types. This just starts creating slot types from id 11. Perhaps it could be a parameter, but really
# needs a contract change to support slot type creation.
next_slot_type_id = 11
for item in config:
slot_type = item["type"]
if not slot_type in slot_type_mapping:
inventory.create_slot_type(next_slot_type_id, slot_type, transaction_config)
slot_type_mapping[slot_type] = next_slot_type_id
print(
"Created slot type " + slot_type + " with id " + str(next_slot_type_id)
)
inventory.create_slot(True, next_slot_type_id, "", transaction_config)
next_slot_id = inventory.num_slots()
slot_mapping[slot_type] = next_slot_id
print(
"Created slot with type " + slot_type + " and id " + str(next_slot_id)
)
next_slot_type_id = next_slot_type_id + 1
pool_id = item["pool_id"]
slot_id = slot_mapping[slot_type]
inventory.mark_item_as_equippable_in_slot(
slot_id,
1155,
equipment_address,
pool_id,
1,
transaction_config,
)
pool_mapping[item["id"]] = {
"pool_id": pool_id,
"slot_id": slot_id,
"slot_type": slot_type,
}
print(item["id"] + " is equippable in slot " + str(slot_id))
print(slot_type_mapping)
print(slot_mapping)
print(pool_mapping)
def generate_cli():
parser = argparse.ArgumentParser(
description="CLI to manage Lootbox contract",
)
parser.set_defaults(func=lambda _: parser.print_help())
subcommands = parser.add_subparsers()
create_item_pools_from_config_parser = subcommands.add_parser(
"create-item-pools-from-config",
help="Creates metagame equipment",
description="Creates base metagame equipment for Crypto Guilds",
)
create_item_pools_from_config_parser.add_argument(
"--equipment-address",
type=str,
required=True,
help="Address of the equipment terminus contract",
)
create_item_pools_from_config_parser.add_argument(
"--config-file",
type=str,
required=True,
help="Path to the config file",
)
ITerminus.add_default_arguments(create_item_pools_from_config_parser, transact=True)
create_item_pools_from_config_parser.set_defaults(
func=handle_create_item_pools_from_config
)
create_items_lootbox_from_config_parser = subcommands.add_parser(
"create-items-lootbox-from-config",
help="Creates lootbox",
description="Creates lootbox with weights from item config file.",
)
create_items_lootbox_from_config_parser.add_argument(
"--lootbox-address",
type=str,
required=True,
help="Address of the lootbox contract",
)
create_items_lootbox_from_config_parser.add_argument(
"--equipment-address",
type=str,
required=True,
help="Address of the equipment terminus contract",
)
create_items_lootbox_from_config_parser.add_argument(
"--lootbox-pool-id",
type=str,
required=True,
help="Terminus pool housing lootboxes created by the contract",
)
create_items_lootbox_from_config_parser.add_argument(
"--config-file",
type=str,
required=True,
help="Path to the config file",
)
ITerminus.add_default_arguments(
create_items_lootbox_from_config_parser, transact=True
)
create_items_lootbox_from_config_parser.set_defaults(
func=handle_create_items_lootbox_from_config
)
create_inventory_slots_from_config_parser = subcommands.add_parser(
"create-inventory-slots-from-config",
help="Creates Inventory slots",
description="Creates inventory slots with types from config file.",
)
create_inventory_slots_from_config_parser.add_argument(
"--inventory-address",
type=str,
required=True,
help="Address of the lootbox contract",
)
create_inventory_slots_from_config_parser.add_argument(
"--equipment-address",
type=str,
required=True,
help="Address of the equipment (terminus) contract",
)
create_inventory_slots_from_config_parser.add_argument(
"--config-file",
type=str,
required=True,
help="Path to the config file",
)
ITerminus.add_default_arguments(
create_inventory_slots_from_config_parser, transact=True
)
create_inventory_slots_from_config_parser.set_defaults(
func=handle_create_inventory_slots_from_config
)
return parser