def handle(self, *args, **options): network = options['network'] syncmethod = options['syncmethod'] interval = options['interval'] kudos_contract = KudosContract(network) logger.info('Listening for new Kudos events...') if syncmethod == 'filter': kudos_contract = KudosContract(network, sockets=True) self.filter_listener(kudos_contract, interval) elif syncmethod == 'block': self.block_listener(kudos_contract, interval) elif syncmethod == 'opensea': self.opensea_listener(kudos_contract, interval)
def handle(self, *args, **options): # config if options['debug']: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) network = options['network'] gitcoin_account = options['gitcoin_account'] gas_price_gwei = options['gas_price_gwei'] kudos_filter = options['kudos_filter'] if gitcoin_account: account = settings.KUDOS_OWNER_ACCOUNT private_key = settings.KUDOS_PRIVATE_KEY else: account = options['account'] private_key = options['private_key'] skip_sync = options['skip_sync'] kudos_contract = KudosContract(network=network) yaml_file = options['yaml_file'] with open(yaml_file) as f: all_kudos = yaml.load(f) for __, kudos in enumerate(all_kudos): if kudos_filter not in kudos['name']: continue mint_kudos(kudos_contract, kudos, account, private_key, gas_price_gwei, options['mint_to'], options['live'])
def mint(self, gas_price_gwei=None): """Approve / mint this token.""" from kudos.management.commands.mint_all_kudos import mint_kudos # avoid circular import from kudos.utils import KudosContract # avoid circular import account = settings.KUDOS_OWNER_ACCOUNT private_key = settings.KUDOS_PRIVATE_KEY kudos = { 'name': self.name, 'description': self.description, 'priceFinney': self.priceFinney, 'artist': self.artist, 'platform': self.platform, 'numClonesAllowed': self.numClonesAllowed, 'tags': self.tags, 'artwork_url': self.artwork_url, } kudos_contract = KudosContract(network=self.network) gas_price_gwei = recommend_min_gas_price_to_confirm_in_time( 1) * 2 if not gas_price_gwei else None tx_id = mint_kudos(kudos_contract, kudos, account, private_key, gas_price_gwei, mint_to=self.to_address, live=True, dont_wait_for_kudos_id_return_tx_hash_instead=True) self.processed = True self.approved = True self.save() return tx_id
def handle(self, *args, **options): # config network = options['network'] _filter = options['kudos_filter'] live = options['live'] multiplier = options['multiplier'] tokens = Token.objects.filter(owner_address=settings.KUDOS_OWNER_ACCOUNT, contract__network=network) if _filter: tokens = tokens.filter(name__contains=_filter) kudos_contract = KudosContract(network=network)._get_contract() w3 = get_web3(network) for token in tokens: if token.gen != 1: continue print(token) if live: _tokenId = token.token_id _newPriceFinney = token.price_finney * multiplier tx = kudos_contract.functions.setPrice(_tokenId, _newPriceFinney).buildTransaction({ 'nonce': get_nonce(network, settings.KUDOS_OWNER_ACCOUNT), 'gas': 47000, 'gasPrice': int(recommend_min_gas_price_to_confirm_in_time(5) * 10**9), 'value': 0, }) signed = w3.eth.account.signTransaction(tx, settings.KUDOS_PRIVATE_KEY) txid = w3.eth.sendRawTransaction(signed.rawTransaction).hex() print(txid)
def handle(self, *args, **options): # config network = options['network'] token_id = options['token_id'] # to = options['to'] numClonesRequested = options['numClonesRequested'] skip_sync = options['skip_sync'] gitcoin_account = options['gitcoin_account'] if gitcoin_account: account = settings.KUDOS_OWNER_ACCOUNT private_key = settings.KUDOS_PRIVATE_KEY else: account = options['account'] private_key = options['private_key'] kudos_contract = KudosContract(network=network) clone_to = kudos_contract._w3.toChecksumAddress(options['clone_to']) args = (clone_to, token_id, numClonesRequested) kudos_contract.clone(*args, account=account, private_key=private_key, skip_sync=skip_sync)
def handle(self, *args, **options): # config network = options['network'] token_id = options['token_id'] skip_sync = options['skip_sync'] gitcoin_account = options['gitcoin_account'] if gitcoin_account: account = settings.KUDOS_OWNER_ACCOUNT private_key = settings.KUDOS_PRIVATE_KEY else: account = options['account'] private_key = options['private_key'] kudos_contract = KudosContract(network=network) owner = kudos_contract._w3.toChecksumAddress(options['owner']) args = (owner, token_id) kudos_contract.burn(*args, account=account, private_key=private_key, skip_sync=skip_sync)
def sync_latest(the_buffer=0, network='mainnet'): kudos_contract = KudosContract(network=network) kudos_contract.sync_latest(the_buffer)
def handle(self, *args, **options): # config network = options['network'] syncmethod = options['syncmethod'] start = options['start'] rewind = options['rewind'] catchup = options['catchup'] kudos_contract = KudosContract(network, sockets=True) # kudos_contract._w3.middleware_stack.add(local_filter_middleware()) # Handle the filter sync if syncmethod == 'filter': if start: if start.isdigit(): raise RuntimeError( 'This option is unstable if not on web3py 4.7.2. May crash testrpc.' ) if start in ['earliest', 'latest']: fromBlock = start else: raise ValueError( '--fromBlock must be "earliest", or "latest"') elif rewind: if web3.__version__ != '4.7.2': raise RuntimeError( 'This option is unstable if not on web3py 4.7.2. May crash testrpc.' ) fromBlock = kudos_contract._w3.eth.getBlock( 'latest')['number'] - rewind elif catchup: raise ValueError( '--catchup option is not valid for filter syncing') logger.info(fromBlock) self.filter_sync(kudos_contract, fromBlock) return # Handle the block sync if syncmethod == 'block': if start: if start.isdigit(): fromBlock = start elif start in ['earliest', 'latest']: fromBlock = start else: raise ValueError( '--fromBlock must be "earliest", or "latest"') elif rewind: fromBlock = kudos_contract._w3.eth.getBlock( 'latest')['number'] - rewind elif catchup: raise ValueError( '--catchup option is not valid for block syncing') logger.info(fromBlock) self.block_sync(kudos_contract, fromBlock) return # Handle the other sync methods if start: start_id = start elif rewind: start_id = kudos_contract._contract.functions.getLatestId().call( ) - rewind elif catchup: start_id = Token.objects.filter( contract__address=kudos_contract.address).aggregate( Max('token_id'))['token_id__max'] if start_id is None or isinstance(start_id, int) and start_id < 0: start_id = 1 if syncmethod == 'id': self.id_sync(kudos_contract, int(start_id)) elif syncmethod == 'opensea': self.opensea_sync(kudos_contract, int(start_id)) return
def handle(self, *args, **options): # config if options['debug']: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) network = options['network'] gitcoin_account = options['gitcoin_account'] gas_price_gwei = options['gas_price_gwei'] kudos_filter = options['kudos_filter'] if gitcoin_account: account = settings.KUDOS_OWNER_ACCOUNT private_key = settings.KUDOS_PRIVATE_KEY else: account = options['account'] private_key = options['private_key'] skip_sync = options['skip_sync'] kudos_contract = KudosContract(network=network) yaml_file = options['yaml_file'] with open(yaml_file) as f: all_kudos = yaml.load(f) for __, kudos in enumerate(all_kudos): if kudos_filter not in kudos['name']: continue image_name = urllib.parse.quote(kudos.get('image')) if image_name: # Support Open Sea if kudos_contract.network == 'rinkeby': image_path = f'https://ss.gitcoin.co/static/v2/images/kudos/{image_name}' external_url = f'https://stage.gitcoin.co/kudos/{kudos_contract.address}/{kudos_contract.getLatestId() + 1}' elif kudos_contract.network == 'mainnet': image_path = f'https://s.gitcoin.co/static/v2/images/kudos/{image_name}' external_url = f'https://gitcoin.co/kudos/{kudos_contract.address}/{kudos_contract.getLatestId() + 1}' elif kudos_contract.network == 'localhost': image_path = f'v2/images/kudos/{image_name}' external_url = f'http://localhost:8000/kudos/{kudos_contract.address}/{kudos_contract.getLatestId() + 1}' else: raise RuntimeError( 'Need to set the image path for that network') else: image_path = '' attributes = [] # "trait_type": "investor_experience", # "value": 20, # "display_type": "boost_number", # "max_value": 100 rarity = { "trait_type": "rarity", "value": get_rarity_score(kudos['numClonesAllowed']), } attributes.append(rarity) artist = {"trait_type": "artist", "value": kudos.get('artist')} attributes.append(artist) platform = { "trait_type": "platform", "value": kudos.get('platform') } attributes.append(platform) tags = kudos['tags'] price_finney = kudos['priceFinney'] # append tags if price_finney < 2: tags.append('budget') if price_finney < 5: tags.append('affordable') if price_finney > 20: tags.append('premium') if price_finney > 200: tags.append('expensive') for tag in tags: attributes.append({"trait_type": "tag", "value": tag}) readable_name = humanize_name(kudos['name']) metadata = { 'name': readable_name, 'image': image_path, 'description': kudos['description'], 'external_url': external_url, 'background_color': 'fbfbfb', 'attributes': attributes } if not options['mint_to']: mint_to = kudos_contract._w3.toChecksumAddress( settings.KUDOS_OWNER_ACCOUNT) else: mint_to = kudos_contract._w3.toChecksumAddress( options['mint_to']) is_live = options['live'] if is_live: try: token_uri_url = kudos_contract.create_token_uri_url( **metadata) args = (mint_to, kudos['priceFinney'], kudos['numClonesAllowed'], token_uri_url) kudos_contract.mint( *args, account=account, private_key=private_key, skip_sync=skip_sync, gas_price_gwei=gas_price_gwei, ) print('Live run - Name: ', readable_name, ' - Account: ', account, 'Minted!') except Exception as e: print(f'Error minting: {readable_name} - {e}') else: print('Dry run - Name: ', readable_name, ' - Account: ', account, 'Skipping!')
def handle(self, *args, **options): # config network = options['network'] start_id = options['start_id'] kudos_contract = KudosContract(network) if options['end_id']: end_id = options['end_id'] else: end_id = kudos_contract._w3.functions.getLatestId().call() for kudos_id in range(start_id, end_id + 1): kudos = kudos_contract.getKudosById(kudos_id, to_dict=True) # Copied from mint_all_kudos image_name = kudos.get('image') if image_name: # Support Open Sea if kudos_contract.network == 'mainnet': image_path = 'http://kudosdemo.gitcoin.co/static/v2/images/kudos/' + image_name else: image_path = 'v2/images/kudos/' + image_name else: image_path = '' attributes = [] rarity = { "trait_type": "rarity", "value": get_rarity_score(kudos['numClonesAllowed']), } attributes.append(rarity) artist = {"trait_type": "artist", "value": kudos.get('artist')} attributes.append(artist) platform = { "trait_type": "platform", "value": kudos.get('platform') } attributes.append(platform) tags = kudos['tags'] # append tags if kudos['priceFinney'] < 2: tags.append('budget') if kudos['priceFinney'] < 5: tags.append('affordable') if kudos['priceFinney'] > 20: tags.append('premium') if kudos['priceFinney'] > 200: tags.append('expensive') for tag in tags: if tag: tag = {"trait_type": "tag", "value": tag} attributes.append(tag) metadata = { 'name': humanize_name(kudos['name']), 'image': image_path, 'description': kudos['description'], 'external_url': f'http://kudosdemo.gitcoin.co/kudos', 'background_color': '#fbfbfb', 'attributes': attributes } for __ in range(1, 4): try: kudos_contract.create_token_uri_url(**metadata) args = () except Exception as e: logger.error(e) logger.info("Trying the mint again...") time.sleep(2) continue else: break
def sync_latest(the_buffer=0, network='mainnet'): try: kudos_contract = KudosContract(network=network) kudos_contract.sync_latest(the_buffer) except IntegrityError as e: print(e)
def handle(self, *args, **options): # config network = options['network'] kudos_contract = KudosContract(network) kudos_contract.remove_kudos_orphans_db()