fixed profit calculation and return object
This commit is contained in:
parent
31ffc20a52
commit
7236215a20
@ -15,24 +15,25 @@ from mev_inspect.trace_classifier import TraceClassifier
|
|||||||
from mev_inspect import block
|
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 = []
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
# 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 i in range(1, len(traces)):
|
for k in range(1, len(traces)):
|
||||||
trace = traces[i]
|
trace = traces[k]
|
||||||
try:
|
try:
|
||||||
next = traces[i+1]
|
next = traces[k+1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
break
|
break
|
||||||
# Liquidation condition
|
# Liquidation condition
|
||||||
if trace.classification == Classification.liquidate:
|
if trace.classification == Classification.liquidate:
|
||||||
# Collateral data from the liquidation.
|
# Collateral data from the liquidation.
|
||||||
# The inputs will differ by DEX, this is AAVE
|
# The inputs will differ by DEX, this is AAVE
|
||||||
|
all_traces.append(trace)
|
||||||
liquidator = trace.from_address
|
liquidator = trace.from_address
|
||||||
prev = traces[i-1]
|
prev = traces[k-1]
|
||||||
#print(f"Previous: {prev.classification} from {prev.from_address} to {prev.to_address}")
|
#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}")
|
||||||
@ -42,27 +43,38 @@ def liquidations(traces: List[ClassifiedTrace]):
|
|||||||
print(f"\tAmount: {liquidation_amount}")
|
print(f"\tAmount: {liquidation_amount}")
|
||||||
elif (i == '_collateral'):
|
elif (i == '_collateral'):
|
||||||
collateral_type = trace.inputs[i]
|
collateral_type = trace.inputs[i]
|
||||||
print(f"\tType: {collateral_type}")
|
print(f"\tCollateral Address: {collateral_type}")
|
||||||
elif (i == '_reserve'):
|
elif (i == '_reserve'):
|
||||||
reserve = trace.inputs[i]
|
reserve = trace.inputs[i]
|
||||||
print(f"\tUnderlying: {reserve}")
|
print(f"\tReserve Address: {reserve}")
|
||||||
elif(i == '_user'):
|
elif(i == '_user'):
|
||||||
liquidated_usr = trace.inputs[i]
|
liquidated_usr = trace.inputs[i]
|
||||||
print(f"\tLiquidated: {liquidated_usr}")
|
print(f"\tLiquidated Account Address: {liquidated_usr}")
|
||||||
# Define the address of the liquidator
|
# Define the address of the liquidator
|
||||||
|
|
||||||
# Find a transfer before liquidation with a to_address corresponding to the liquidator
|
# Find a transfer before liquidation with a to_address corresponding to the liquidator
|
||||||
for tx in traces:
|
for tx in traces[0:int(k)]:
|
||||||
if ((tx.classification==Classification.transfer) and (tx.inputs['recipient'] == liquidator)):
|
if ((tx.classification==Classification.transfer) and ('sender' in tx.inputs) and (tx.inputs['sender'] == liquidator)):
|
||||||
|
amount_sent = tx.inputs['amount']
|
||||||
|
all_traces.append(tx)
|
||||||
|
print(f"Transfer from liquidator {liquidator}: \nAmount in received token: {tx.inputs['amount']} to \n{tx.inputs['recipient']} \nTransaction: {tx.transaction_hash}")
|
||||||
|
elif ((tx.classification==Classification.transfer) and (tx.inputs['recipient']==liquidator)):
|
||||||
amount_received = tx.inputs['amount']
|
amount_received = tx.inputs['amount']
|
||||||
print(f"Transfer to liquidator {liquidator}: \nAmount in received token: {tx.inputs['amount']} \nTransaction: {tx.transaction_hash}")
|
all_traces.append(tx)
|
||||||
|
print(f"Transfer to liquidator {liquidator}: \nAmount in received token: {tx.inputs['amount']} from \n{tx.from_address} \nTransaction: {tx.transaction_hash}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
profit = amount_received - amount_sent
|
||||||
|
except UnboundLocalError:
|
||||||
|
print("No match ;[")
|
||||||
|
profit = 0
|
||||||
# Tag liquidation
|
# Tag liquidation
|
||||||
result.append(Liquidation(strategy=StrategyType.liquidation,
|
result.append(Liquidation(strategy=StrategyType.liquidation,
|
||||||
traces=[trace, next],
|
traces=all_traces,
|
||||||
protocols=[trace.protocol],
|
protocols=[trace.protocol],
|
||||||
collateral_type=collateral_type,
|
collateral_type=collateral_type,
|
||||||
collateral_amount=liquidation_amount,
|
collateral_amount=liquidation_amount,
|
||||||
|
profit=profit,
|
||||||
reserve=reserve,
|
reserve=reserve,
|
||||||
collateral_source="",))
|
collateral_source="",))
|
||||||
return result
|
return result
|
||||||
|
@ -17,3 +17,4 @@ class Liquidation(Strategy):
|
|||||||
collateral_amount: int
|
collateral_amount: int
|
||||||
collateral_source: str
|
collateral_source: str
|
||||||
reserve: str
|
reserve: str
|
||||||
|
profit: float
|
||||||
|
Loading…
x
Reference in New Issue
Block a user