# ERC-8464: Agent Repay-First Payees

> Robinhood Chain testnet (46630). Test tokens, no value. Reference contracts not audited. These are drafts under review, not standards.

A draft under review on ethereum/ERCs. A revenue address for an agent identity that pays its creditors before its owner, and token holders after them.

Status: Being built.

- Pull request: https://github.com/ethereum/ERCs/pull/2108
- Text pinned at the pull request's head commit 75cc2e53a4cd7c8deb86b09aaa46e1dc343cec43 (ERCS/erc-8464.md, CC0): https://github.com/priors-agents/ERCs/blob/75cc2e53a4cd7c8deb86b09aaa46e1dc343cec43/ERCS/erc-8464.md
- Discussion: https://ethereum-magicians.org/t/erc-8464-agent-repay-first-payees/30025
- Reference implementation: https://github.com/priors-agents/erc-repay-first-payees/tree/56f7fa0efd1b24b697b10c72b4b639ecb99a8f2f (commit 56f7fa0efd1b24b697b10c72b4b639ecb99a8f2f)
- This page: https://lab.priors.trade/erc/8464

## Abstract

This proposal defines a payee: a contract that an agent identity, held in an [ERC-721](https://eips.ethereum.org/EIPS/eip-721) identity registry, uses as the address where it is paid. When the payee is swept, it pays each registered creditor what that creditor says it is owed, most senior first and up to a share of the swept balance the creditor agreed to, and forwards the rest to the agent's owner or an address the owner chose. What a creditor does not take, up to what it is owed, stays in the payee in reserve for it, so a lender that takes repayment only in full is repaid once its reserve covers what is due. The owner adds creditors, each junior to the ones before, and cannot remove a creditor that still has a claim. A small creditor interface lets any lender take part, and any payer, explorer or lender can tell that an identity's revenue address is encumbered. An optional part lets the payee be the provider of an [ERC-8183](https://eips.ethereum.org/EIPS/eip-8183) job: ERC-8183 pays the provider and takes the work only from it, so the payee submits the work for the owner and is paid by the job. Another lets the holders of an [ERC-7254](https://eips.ethereum.org/EIPS/eip-7254) revenue-sharing token share what the creditors leave, with the token as the payee's beneficiary.

## Specification headings

1. Interfaces
2. The payee
3. Adding and removing creditors
4. Sweeping
5. The creditor
6. Acting as an ERC-8183 provider (optional)
7. Paying holders after creditors (optional)

## At Priors

Priors is building an income router after this draft. Nothing of it is live yet.

## Try it on testnet (46630)

Every action is prepared as an unsigned transaction { chainId: 46630, to, data, value }, signed by your own wallet or testnet key. Test tokens have no value.

Contracts:

- payeeFactory: 0xc22AEe8022CD230544a454B3566Bba0d5476C9da (https://explorer.testnet.chain.robinhood.com/address/0xc22AEe8022CD230544a454B3566Bba0d5476C9da)
- refPayeeFactory: 0x4d42d8026a7B95070b17d63f65Ef1b0129D7211A (https://explorer.testnet.chain.robinhood.com/address/0x4d42d8026a7B95070b17d63f65Ef1b0129D7211A)
- lineCreditor: 0xC97B451Ff90A093C978BBC818F1F7c3F0d7AEDDF (https://explorer.testnet.chain.robinhood.com/address/0xC97B451Ff90A093C978BBC818F1F7c3F0d7AEDDF)
- identityRegistry: 0x8004A818BFB912233c491871b3d84c89A494BD9e (https://explorer.testnet.chain.robinhood.com/address/0x8004A818BFB912233c491871b3d84c89A494BD9e)
- testDollar: 0x64A419191369E6a79d562A65336073ec1bfbf4BD (https://explorer.testnet.chain.robinhood.com/address/0x64A419191369E6a79d562A65336073ec1bfbf4BD)

Actions:

- `deploy_payee`: Deploy the identity's payee (at the address shown before). Who signs: anyone Params: `agent_id` (The identity, agentId), `factory` (Which factory: lab (payees settable as the ERC-8004 agentWallet) or reference (the unmodified RepayFirstPayeeFactory), string, optional, default lab).
- `set_agent_wallet`: Make the payee the identity's ERC-8004 agentWallet. Who signs: the identity's owner Params: `agent_id` (The identity, agentId), `payee` (Its lab payee (deployed by the lab factory), address), `deadline` (Deadline: at most 5 minutes after the block that includes it (+4m), time, optional, default +240).
- `track_loan`: Have the lab's line creditor follow a lab loan. Who signs: anyone Params: `loan_id` (The loan, uint), `line` (Which shared line: normal (1-day grace, terms up to 30 days) or fast (5-minute grace, terms up to 10 minutes), string, optional, default normal).
- `add_creditor`: Add a creditor. Who signs: the identity's owner Params: `payee` (The payee, address), `creditor` (The creditor (empty: the lab's line creditor), address, optional, default (the lab's)), `max_share_bps` (The most of one sweep it may take, in basis points, uint, optional, default 10000).
- `remove_creditor`: Remove a creditor. Who signs: the creditor, or the owner once it has no claim Params: `payee` (The payee, address), `creditor` (The creditor, address).
- `set_beneficiary`: Set where what is left goes. Who signs: the identity's owner Params: `payee` (The payee, address), `beneficiary` (The beneficiary (0x0: the owner), address).
- `pay`: Pay the agent at its payee. Who signs: a buyer Params: `payee` (The payee, address), `amount` (How many test dollars, amount).
- `sweep`: Sweep: creditors first, then the beneficiary. Who signs: anyone Params: `payee` (The payee, address), `token` (The token (empty: the test dollar), address, optional, default (the lab's)).
- `set_operator`: Name the payee's job operator (ERC-8183 provider). Who signs: the identity's owner Params: `payee` (The payee, address), `operator` (The operator, address).

Reads:

- `payee_address`: The identity's payee address (before or after it is deployed). Params: `agent_id` (The identity, agentId), `factory` (Which factory: lab (payees settable as the ERC-8004 agentWallet) or reference (the unmodified RepayFirstPayeeFactory), string, optional, default lab).
- `payee`: A payee: its agent, beneficiary, creditors and balance. Params: `payee` (The payee, address).
- `reserved`: What a payee holds for a creditor. Params: `payee` (The payee, address), `creditor` (The creditor (empty: the lab's line creditor), address, optional, default (the lab's)), `token` (The token (empty: the test dollar), address, optional, default (the lab's)).
- `owed`: What an identity owes the lab's line creditor, and the loans it follows. Params: `agent_id` (The identity, agentId).

Deploy your own:

- `payee`: Your own RepayFirstPayee for an identity (the reference, without the factory). Params: `agent_id` (The identity, agentId), `registry` (The identity registry (empty: the testnet ERC-8004 one), address, optional, default (the lab's)).
- `factory`: Your own RepayFirstPayeeFactory. Params: `registry` (The identity registry (empty: the testnet ERC-8004 one), address, optional, default (the lab's)).

## With an agent

- MCP (Streamable HTTP): https://lab.priors.trade/mcp. Tools for this draft: `lab_erc(8464)`, `lab_setup(address)`, `lab_read(8464, read, params)`, `lab_prepare(8464, action, params)`, `lab_deploy_prepare(8464, deploy, params)`, `lab_check_contract(8464, chain, address)`, `lab_feedback_draft(8464, note, txHash?)`.
- HTTP: https://lab.priors.trade/openapi.json describes GET https://lab.priors.trade/api/lab/erc/8464, /api/lab/read/8464/{read}, /api/lab/prepare/8464/{action}, /api/lab/deploy/8464/{deploy}, /api/lab/check/8464/{chain}/{address} and /api/lab/setup/{address}.

A prompt to give your agent:

```text
Use the Priors lab on Robinhood Chain testnet (chain id 46630), where every token is a test token of no value. Its MCP server is https://lab.priors.trade/mcp and this draft's page is https://lab.priors.trade/erc/8464.md. Try ERC-8464, Agent Repay-First Payees (a draft under review). Start with lab_setup for my testnet address to see my test ETH, test dollars and identities, then deploy the identity's payee (at the address shown before), then make the payee the identity's erc-8004 agentwallet, then have the lab's line creditor follow a lab loan, then add a creditor, then remove a creditor, then set where what is left goes with lab_prepare(8464, <action>, params). Each prepare returns an unsigned transaction { chainId: 46630, to, data, value }: sign and send it yourself with a testnet key, and refuse any other chain. Never ask me for a key. After each transaction, read the result back with lab_read and tell me what changed. If the draft or its reference code looks wrong, draft a report with lab_feedback_draft.
```

## Check a contract

Any address on testnet or mainnet: supportsInterface(0xb5649e43) and the views, read only (`lab_check_contract`, or GET https://lab.priors.trade/api/lab/check/8464/{chain}/{address}).

## Feedback

The discussion of the text belongs in its thread: https://ethereum-magicians.org/t/erc-8464-agent-repay-first-payees/30025. A bug in the reference implementation goes to its repository's issues: https://github.com/priors-agents/erc-repay-first-payees/issues (a new one: https://github.com/priors-agents/erc-repay-first-payees/issues/new). The text under review: https://github.com/ethereum/ERCs/pull/2108/files. `lab_feedback_draft` writes the report; the lab posts nothing for anyone.
