verbs_examples.agents.liquidation_agent.AdversarialLiquidationAgent#
- class AdversarialLiquidationAgent[source]#
Liquidation agent that manipulates the price in Uniswap to bring borrowers positions into distress
- __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, uniswap_pool_abi: type, quoter_abi: type, swap_router_abi, uniswap_pool_address: bytes, quoter_address: bytes, swap_router_address: bytes, uniswap_fee: int, aave_oracle_abi: type, aave_oracle_address: bytes)[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)aave_oracle_abi (
type
) – abi of the Aave oracle contract for the pair (token_a, token_b)aave_oracle_address (
bytes
) – Address of the Aave oracle contract 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] #
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)[source]#
Update the state of the agent and returns list of transactions according to their policy.
The liquidator agent will
Monitor those positions in Aave that are close to being in distress, and check whether it would be profitable to make a trade in Uniswap to decrease the price of collateral in order to trigger liquidations.
Liquidate positions in Aave that are in distress.
Realize a profit on Uniswap by selling the collateral obtained from liquidations.
References
- 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 transactions.