kopia lustrzana https://github.com/bugout-dev/dao
commit
c4cff2065c
|
@ -13,8 +13,9 @@ have the badge in question. It mints a single badge to all addresses that do *no
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
from brownie import network
|
from brownie import network, web3
|
||||||
from dao import TerminusFacet
|
from dao import TerminusFacet
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Mint Terminus badges to addresses")
|
parser = argparse.ArgumentParser(description="Mint Terminus badges to addresses")
|
||||||
|
@ -26,7 +27,12 @@ parser.add_argument(
|
||||||
help="ID of Terminus pool representing the badge",
|
help="ID of Terminus pool representing the badge",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--recipients", nargs="+", help="Addresses that badge should be minted to"
|
"--recipients", nargs="*", help="Addresses that badge should be minted to"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--recipients-file",
|
||||||
|
type=argparse.FileType("r"),
|
||||||
|
help="(Optional) File containing addresses to mint badges to, one address per line. The addresses in this file are added to the addresses passed with the --recipients argument.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-y",
|
"-y",
|
||||||
|
@ -34,6 +40,12 @@ parser.add_argument(
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Set this flag to signal y on all confirmation prompts",
|
help="Set this flag to signal y on all confirmation prompts",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--batch-size",
|
||||||
|
type=int,
|
||||||
|
default=200,
|
||||||
|
help="Number of recipients to mint badges to per transaction.",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -42,36 +54,58 @@ if args.address is None:
|
||||||
"Please specify the address of a Terminus contract using the --address argument."
|
"Please specify the address of a Terminus contract using the --address argument."
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(args.recipients) > 200:
|
if args.batch_size > 200:
|
||||||
raise ValueError("This script can process at most 200 recipients at a time.")
|
raise ValueError("This script can process at most 200 recipients per batch.")
|
||||||
|
|
||||||
network.connect(args.network)
|
network.connect(args.network)
|
||||||
|
|
||||||
recipients = list(set(args.recipients))
|
recipients_raw = args.recipients
|
||||||
|
if not recipients_raw:
|
||||||
|
recipients_raw = []
|
||||||
|
|
||||||
|
with args.recipients_file as ifp:
|
||||||
|
for line in ifp:
|
||||||
|
try:
|
||||||
|
parsed_line = web3.toChecksumAddress(line.strip())
|
||||||
|
recipients_raw.append(parsed_line)
|
||||||
|
except Exception:
|
||||||
|
print(f"Not a valid web3 address: {line.strip()}")
|
||||||
|
|
||||||
|
recipients = list(set(recipients_raw))
|
||||||
|
|
||||||
|
batches = []
|
||||||
|
for i in range(0, len(recipients), args.batch_size):
|
||||||
|
batches.append(recipients[i : i + args.batch_size])
|
||||||
|
|
||||||
terminus = TerminusFacet.TerminusFacet(args.address)
|
terminus = TerminusFacet.TerminusFacet(args.address)
|
||||||
pool_uri = terminus.uri(args.pool_id)
|
pool_uri = terminus.uri(args.pool_id)
|
||||||
balances = zip(
|
|
||||||
recipients,
|
|
||||||
terminus.balance_of_batch(recipients, [args.pool_id for _ in recipients]),
|
|
||||||
)
|
|
||||||
|
|
||||||
valid_recipients = [recipient for recipient, balance in balances if balance == 0]
|
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Badge information -- Terminus address: {args.address}, pool ID: {args.pool_id}, pool URI: {pool_uri}"
|
f"Badge information -- Terminus address: {args.address}, pool ID: {args.pool_id}, pool URI: {pool_uri}"
|
||||||
)
|
)
|
||||||
print("\n- ".join(["Intended recipients:"] + valid_recipients))
|
|
||||||
|
|
||||||
if not args.yes:
|
for i, batch in enumerate(batches):
|
||||||
permission_check = input("Proceed? (y/N)")
|
balances = zip(
|
||||||
if permission_check.strip().lower() != "y":
|
batch,
|
||||||
raise Exception("You did not wish to proceed")
|
terminus.balance_of_batch(batch, [args.pool_id for _ in batch]),
|
||||||
|
)
|
||||||
|
|
||||||
amounts = [1 for _ in valid_recipients]
|
valid_recipients = [recipient for recipient, balance in balances if balance == 0]
|
||||||
transaction_config = TerminusFacet.get_transaction_config(args)
|
if len(valid_recipients) == 0:
|
||||||
transaction_info = terminus.pool_mint_batch(
|
print("No valid recipients in this batch", file=sys.stderr)
|
||||||
args.pool_id, valid_recipients, amounts, transaction_config
|
continue
|
||||||
)
|
|
||||||
|
|
||||||
print(transaction_info)
|
print("\n- ".join([f"Intended recipients in batch {i+1}:"] + valid_recipients))
|
||||||
|
|
||||||
|
if not args.yes:
|
||||||
|
permission_check = input("Proceed? (y/N)")
|
||||||
|
if permission_check.strip().lower() != "y":
|
||||||
|
raise Exception("You did not wish to proceed")
|
||||||
|
|
||||||
|
amounts = [1 for _ in valid_recipients]
|
||||||
|
transaction_config = TerminusFacet.get_transaction_config(args)
|
||||||
|
transaction_info = terminus.pool_mint_batch(
|
||||||
|
args.pool_id, valid_recipients, amounts, transaction_config
|
||||||
|
)
|
||||||
|
|
||||||
|
print(transaction_info)
|
||||||
|
|
Ładowanie…
Reference in New Issue