verbs_examples.agents.liquidation_agent.LiquidationAgent#
- class LiquidationAgent[source]#
Agent that monitors Aave borrowers and liquidate positions
- __init__(env, i: int, pool_implementation_abi: type, mintable_erc20_abi: type, pool_address: bytes, token_a_address: bytes, token_b_address: bytes, liquidation_addresses: List[bytes], uniswap_pool_abi: type, quoter_abi: type, swap_router_abi: type, uniswap_pool_address: bytes, quoter_address: bytes, swap_router_address: bytes, uniswap_fee: int)[source]#
Initialise the Liquidator agent and create the corresponding account in the EVM.
The agent stores the ABIs of the Aave contracts, the Uniswap contracts and the token contracts that they will be interacting with. ABIs are previously loaded using the function
verbs.abi.load_abi()
.- Parameters:
env (
verbs.types.Env
) – Simulation environmenti (
int
) – Agent index in the simulationpool_implementation_abi (
type
) – abi of the Aave v3 pool contractmintable_erc20_abi (
type
) – abi of ERC20 contractpool_address (
bytes
) – Addres of Aave v3 pool contracttoken_a_address (
bytes
) – Address of collateral token (usually the risky token)token_b_address (
bytes
) – Address of debt token (usually the less risky token)liquidation_addresses (
list[bytes]
) – List of borrowers’ addresses that the liquidator will be monitoring.uniswap_pool_abi (
type
) – abi of the Uniswap v3 pool contractquoter_abi (
type
) – abi of the Uniswap v3 QuoterV2 contractswap_router_abi (
type
) – abi of the Uniswap v3 SwapRouter contractuniswap_pool_address (
bytes
) – Addres of Uniswap v3 pool for the pair (token_a, token_b)quoter_address (
bytes
) – Address of the QuoterV2 contractswap_router_address (
bytes
) – Address of the SwapRouter contractuniswap_fee (
int
) – Fee tier of the Uniswap v3 pool for the pair (token_a, token_b)
- accountability(env, liquidation_address, amount: int) bool [source]#
Calculates if a liquidation is profitable
Makes the accountability of a liquidation and returns a boolean indicating whether the liquidation is profitable or not
- record(env) Tuple[float, float] [source]#
Record the state of the agent
This method is called at the end of each step for all agents. It should return any data to be recorded over the course of the simulation.
- Parameters:
env (
verbs.types.Env
) – Network/EVM that the simulation interacts with.- Returns:
tuple[float
,float]
– Tuple containing: - Balance of collateral asset in the current step. - Balance of debt asset in the current step.
- update(rng: Generator, env) List[Tuple[bytes, bytes, bytes, bool, int | None, int | None, int | None]] [source]#
Update the state of the agent and returns list of transactions according to their policy.
The liquidator agent will
Liquidate positions in Aave that are in distress
Realize a profit on Uniswap by selling the collateral obtained from liquidations
- Parameters:
rng (
np.random.Generator
) – Numpy random generator, used for any random sampling to ensure determinism of the simulation.env (
verbs.types.Env
) – Network/EVM that the simulation interacts with.
- Returns:
list
– List of transactions to be processed in the next block of the simulation. This can be an empty list if the agent is not submitting any transacti