liquidation data type and inspector clean up
This commit is contained in:
parent
7236215a20
commit
244be7e990
@ -17,72 +17,88 @@ from mev_inspect import block
|
|||||||
# poetry run inspect -b 12498502 -r 'http://162.55.96.141:8546/'
|
# poetry run inspect -b 12498502 -r 'http://162.55.96.141:8546/'
|
||||||
all_traces = []
|
all_traces = []
|
||||||
result = []
|
result = []
|
||||||
|
addrs = ['0x3dfd23A6c5E8BbcFc9581d2E864a68feb6a076d3']
|
||||||
|
transfers = []
|
||||||
# Inspect list of classified traces and identify liquidation
|
# Inspect list of classified traces and identify liquidation
|
||||||
def liquidations(traces: List[ClassifiedTrace]):
|
def liquidations(traces: List[ClassifiedTrace]):
|
||||||
event = []
|
event = []
|
||||||
# For each trace
|
# For each trace
|
||||||
for k in range(1, len(traces)):
|
for k in range(len(traces)):
|
||||||
trace = traces[k]
|
trace = traces[k]
|
||||||
try:
|
|
||||||
next = traces[k+1]
|
# Check for liquidation and register trace and unique liquidator
|
||||||
except IndexError:
|
|
||||||
break
|
|
||||||
# Liquidation condition
|
|
||||||
if trace.classification == Classification.liquidate:
|
if trace.classification == Classification.liquidate:
|
||||||
# Collateral data from the liquidation.
|
|
||||||
# The inputs will differ by DEX, this is AAVE
|
|
||||||
all_traces.append(trace)
|
all_traces.append(trace)
|
||||||
liquidator = trace.from_address
|
liquidator = trace.from_address
|
||||||
prev = traces[k-1]
|
if liquidator not in addrs: addrs.append(liquidator)
|
||||||
#print(f"Previous: {prev.classification} from {prev.from_address} to {prev.to_address}")
|
|
||||||
print(f"Liquidation found: {liquidator}")
|
print(f"Liquidation found: {liquidator}")
|
||||||
print(f"Hash: {trace.transaction_hash}")
|
print(f"Hash: {trace.transaction_hash}")
|
||||||
|
|
||||||
|
# Found liquidation, now parse inputs for data
|
||||||
for i in trace.inputs:
|
for i in trace.inputs:
|
||||||
|
|
||||||
if(i == '_purchaseAmount'):
|
if(i == '_purchaseAmount'):
|
||||||
liquidation_amount = trace.inputs[i]
|
liquidation_amount = trace.inputs[i]
|
||||||
print(f"\tAmount: {liquidation_amount}")
|
|
||||||
elif (i == '_collateral'):
|
elif (i == '_collateral'):
|
||||||
collateral_type = trace.inputs[i]
|
collateral_type = trace.inputs[i]
|
||||||
print(f"\tCollateral Address: {collateral_type}")
|
|
||||||
elif (i == '_reserve'):
|
elif (i == '_reserve'):
|
||||||
reserve = trace.inputs[i]
|
reserve = trace.inputs[i]
|
||||||
print(f"\tReserve Address: {reserve}")
|
|
||||||
elif(i == '_user'):
|
elif(i == '_user'):
|
||||||
liquidated_usr = trace.inputs[i]
|
liquidated_usr = trace.inputs[i]
|
||||||
print(f"\tLiquidated Account Address: {liquidated_usr}")
|
|
||||||
# Define the address of the liquidator
|
|
||||||
|
|
||||||
# Find a transfer before liquidation with a to_address corresponding to the liquidator
|
# Register liquidation
|
||||||
for tx in traces[0:int(k)]:
|
result.append(
|
||||||
if ((tx.classification==Classification.transfer) and ('sender' in tx.inputs) and (tx.inputs['sender'] == liquidator)):
|
Liquidation(collateral_type=collateral_type,
|
||||||
amount_sent = tx.inputs['amount']
|
collateral_amount=liquidation_amount,
|
||||||
all_traces.append(tx)
|
collateral_source="",
|
||||||
print(f"Transfer from liquidator {liquidator}: \nAmount in received token: {tx.inputs['amount']} to \n{tx.inputs['recipient']} \nTransaction: {tx.transaction_hash}")
|
reserve=reserve,
|
||||||
elif ((tx.classification==Classification.transfer) and (tx.inputs['recipient']==liquidator)):
|
strategy=StrategyType.liquidation,
|
||||||
amount_received = tx.inputs['amount']
|
traces=all_traces,
|
||||||
all_traces.append(tx)
|
protocols=[trace.protocol],)
|
||||||
print(f"Transfer to liquidator {liquidator}: \nAmount in received token: {tx.inputs['amount']} from \n{tx.from_address} \nTransaction: {tx.transaction_hash}")
|
)
|
||||||
|
|
||||||
|
# Check for transfer from liquidator
|
||||||
|
elif (
|
||||||
|
trace.classification == Classification.transfer and
|
||||||
|
'sender' in trace.inputs and
|
||||||
|
trace.inputs['sender'] in addrs and
|
||||||
|
trace.inputs['amount'] not in transfers
|
||||||
|
):
|
||||||
|
|
||||||
|
liquidator = next(addrs[i] for i in range(len(addrs)) if trace.inputs['sender'] == addrs[i])
|
||||||
|
transfers.append(trace)
|
||||||
|
|
||||||
|
print(f"""
|
||||||
|
\nTransfer from liquidator {liquidator}:
|
||||||
|
\nAmount in received token: {trace.inputs['amount']} to
|
||||||
|
\n{trace.inputs['recipient']}
|
||||||
|
\nTransaction: {trace.transaction_hash}
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Check for transfer to liquidator
|
||||||
|
elif (
|
||||||
|
trace.classification == Classification.transfer and
|
||||||
|
trace.inputs['recipient'] in addrs
|
||||||
|
):
|
||||||
|
|
||||||
|
liquidator = next(addrs[i] for i in range(len(addrs)) if trace.inputs['recipient'] == addrs[i])
|
||||||
|
transfers.append(trace)
|
||||||
|
|
||||||
|
print(f"""
|
||||||
|
\nTransfer to liquidator {liquidator}:
|
||||||
|
\nAmount in received token: {trace.inputs['amount']} from
|
||||||
|
\n{trace.from_address}
|
||||||
|
\nTransaction: {trace.transaction_hash}
|
||||||
|
""")
|
||||||
|
|
||||||
try:
|
|
||||||
profit = amount_received - amount_sent
|
|
||||||
except UnboundLocalError:
|
|
||||||
print("No match ;[")
|
|
||||||
profit = 0
|
|
||||||
# Tag liquidation
|
|
||||||
result.append(Liquidation(strategy=StrategyType.liquidation,
|
|
||||||
traces=all_traces,
|
|
||||||
protocols=[trace.protocol],
|
|
||||||
collateral_type=collateral_type,
|
|
||||||
collateral_amount=liquidation_amount,
|
|
||||||
profit=profit,
|
|
||||||
reserve=reserve,
|
|
||||||
collateral_source="",))
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
rpc = 'http://162.55.96.141:8546/'
|
rpc = 'http://162.55.96.141:8546/'
|
||||||
block_number = 12498502
|
block_number = 12498502
|
||||||
base_provider = Web3.HTTPProvider(rpc)
|
base_provider = Web3.HTTPProvider(rpc)
|
||||||
block_data = block.create_from_block_number(block_number, base_provider)
|
block_data = block.create_from_block_number(block_number, base_provider)
|
||||||
trace_clasifier = TraceClassifier(CLASSIFIER_SPECS)
|
trace_clasifier = TraceClassifier(CLASSIFIER_SPECS)
|
||||||
classified_traces = trace_clasifier.classify(block_data.traces)
|
classified_traces = trace_clasifier.classify(block_data.traces)
|
||||||
print(liquidations(classified_traces)[2])
|
fin = liquidations(classified_traces)
|
||||||
|
@ -17,4 +17,6 @@ class Liquidation(Strategy):
|
|||||||
collateral_amount: int
|
collateral_amount: int
|
||||||
collateral_source: str
|
collateral_source: str
|
||||||
reserve: str
|
reserve: str
|
||||||
|
|
||||||
|
class LiquidationData(Liquidation):
|
||||||
profit: float
|
profit: float
|
||||||
|
Loading…
x
Reference in New Issue
Block a user