This repository contains implementations of on-chain agents responsible for calling public actions on the AFP Clearing Contracts. Each agent is designed to automate a specific aspect of protocol maintenance and risk management.
The Closeout Agent monitors on-chain products that have reached expiry. When a
product's earliestFSPSubmission time has passed and the Final Settlement Price
has been finalized on the clearing contracts, the agent triggers the closing of
positions at the final settlement price.
Typical Use Case:
- Automatically closes positions for expired products.
- Helps maintain protocol health by ensuring positions are settled at expiry.
- Caller of
initiateFinalSettlementearns a fee, credited to their margin account.
-
Clone the repository:
git clone https://github.com/autonity/afp-agents.git cd afp-agents -
Install dependencies using uv:
uv sync
-
Configure environment variables: Copy
.env.templateto.envand fill in the required values:cp .env.template .env
Required variables:
PRIVATE_KEY: The agent's account private key.RPC_URL: Autonity RPC node URL.SUBQUERY_URL: Autonity subquery node URL (defaults tohttps://subquery.autonity.org/graphql)
Optional AFP configuration: (defaults to mainnet addresses if not set)
AFP_CLEARING_DIAMOND_ADDRESSAFP_MARGIN_ACCOUNT_REGISTRY_ADDRESSAFP_ORACLE_PROVIDER_ADDRESSAFP_PRODUCT_REGISTRY_ADDRESSAFP_SYSTEM_VIEWER_ADDRESS
Optional notifications:
NOTIFIER_TYPE: Notification backend (defaultorslack)SLACK_TOKEN: Slack bot token (if using Slack)SLACK_CHANNEL: Slack channel for notificationsSLACK_ICON_EMOJI: Emoji for Slack messages
Optional healthcheck:
HEALTHCHECK_PING_URL: URL to ping on successful runs
The Closeout Agent requires a private key to sign transactions. The account must be funded with ATN to pay for gas fees. No margin account or collateral is required.
Agents can be run as Python modules. Make sure your .env file is configured
before running.
uv run --env-file .env -m closeoutAgents are intended to be run as cron jobs at a fixed periodic interval, ensuring timely execution of protocol actions.