Trigger and Function
Last updated
Last updated
The Opensea job is triggered when an Opensea-related transaction occurs or an event is produced. Specifically:
OrderFulfilled
: When an order is successfully fulfilled
def parse_opensea_transaction_order_fulfilled_event(
transaction: Transaction, contract_address: str, protocol_version: str = 1.6, fee_addresses: List[str] = []
) -> List[OpenseaLog]:
results = []
logs = transaction.receipt.logs
for log in logs:
if (
log.topic0 == OPENSEA_EVENT_ABI_SIGNATURE_MAPPING["ORDER_FULFILLED_EVENT"]
and log.address == contract_address
):
opensea_transaction = decode_log(OPENSEA_EVENT_ABI_MAPPING["ORDER_FULFILLED_EVENT"], log)
results.append(
OpenseaLog(
orderHash="0x" + opensea_transaction["orderHash"].hex(),
offerer=opensea_transaction["offerer"],
zone=opensea_transaction["zone"],
recipient=opensea_transaction["recipient"],
offer=opensea_transaction["offer"],
consideration=opensea_transaction["consideration"],
block_timestamp=transaction.block_timestamp,
block_hash=transaction.block_hash,
block_number=transaction.block_number,
transaction_hash=transaction.hash,
log_index=log.log_index,
protocol_version=protocol_version,
fee_addresses=fee_addresses,
)
)
return results
and the function to extract the data from the opensea event log:
def transfer(self, opensea_logs: List[OpenseaLog]):
for opensea_log in opensea_logs:
yield OpenseaOrder(
order_hash=opensea_log.orderHash,
zone=opensea_log.zone,
offerer=opensea_log.offerer,
recipient=opensea_log.recipient,
offer=opensea_log.offer,
consideration=opensea_log.consideration,
block_timestamp=opensea_log.block_timestamp,
block_hash=opensea_log.block_hash,
transaction_hash=opensea_log.transaction_hash,
block_number=opensea_log.block_number,
log_index=opensea_log.log_index,
protocol_version=opensea_log.protocol_version,
)
offer = calculate_total_amount(opensea_log.offer)
consideration = calculate_total_amount(opensea_log.consideration)
fee = calculate_fee_amount(opensea_log.consideration, opensea_log.fee_addresses)
opensea_transaciton_type = get_opensea_transaction_type(opensea_log.offer, opensea_log.consideration)
if opensea_log.offerer == opensea_log.recipient:
continue
yield AddressOpenseaTransaction(
address=opensea_log.offerer,
related_address=opensea_log.recipient,
is_offer=True,
transaction_type=opensea_transaciton_type.value,
order_hash=opensea_log.orderHash,
zone=opensea_log.zone,
offer=offer,
consideration=consideration,
fee=fee,
transaction_hash=opensea_log.transaction_hash,
block_number=opensea_log.block_number,
log_index=opensea_log.log_index,
block_timestamp=opensea_log.block_timestamp,
block_hash=opensea_log.block_hash,
protocol_version=opensea_log.protocol_version,
)
yield AddressOpenseaTransaction(
address=opensea_log.recipient,
related_address=opensea_log.offerer,
is_offer=False,
transaction_type=(
1 - opensea_transaciton_type.value
if opensea_transaciton_type.value <= 1
else opensea_transaciton_type.value
),
order_hash=opensea_log.orderHash,
zone=opensea_log.zone,
offer=offer,
consideration=consideration,
fee=fee,
transaction_hash=opensea_log.transaction_hash,
block_number=opensea_log.block_number,
log_index=opensea_log.log_index,
block_timestamp=opensea_log.block_timestamp,
block_hash=opensea_log.block_hash,
protocol_version=opensea_log.protocol_version,
)