Skip to content

AgentFactory

contracts/src/agents/AgentFactory.sol

Deploys and wires the full agent stack in a single transaction. Anyone can call launch(); the factory owns no special privileges after deployment — agents are self-contained once launched.

Constructor

solidity
constructor(
    IPoolManager poolManager_,
    AgentHook    hook_,
    address      diem_,
    address      usdc_,
    address      kPool_   // Kairence Pool address
)

All parameters are immutable. pool() exposes kPool_ so AgentToken contracts can look up the pool address without caching it.

launch()

solidity
function launch(
    string  memory name,
    string  memory symbol,
    uint256        totalSupply,
    uint24         baseFee,
    uint24         maxFee,
    uint32         decayBlocks,
    address        agentWallet
) external returns (address agentToken, address yieldToken, PoolId poolId)

Parameters

NameDescription
nameAgentToken name (e.g. "My Agent")
symbolAgentToken symbol (e.g. "MYAT")
totalSupplyTotal AT minted at launch (sent to agentWallet)
baseFeeFee after full decay, in pips (e.g. 3_000 = 0.3%)
maxFeeFee at launch, in pips (e.g. 500_000 = 50%)
decayBlocksBlocks from launch until fee reaches baseFee
agentWalletReceives all AT at launch; becomes Ownable.owner()

Deploy sequence

1. Deploy AgentToken(name, symbol, totalSupply, agentWallet, this, usdc)
     → full supply minted to agentWallet
     → agentWallet is Ownable2Step owner

2. Deploy YieldToken(name + " Yield", symbol + "y", agentToken, usdc)
     → linked to agentToken; can only be minted by agentToken

3. agentToken.setYieldToken(yieldToken)
     → one-shot link; cannot be changed after

4. Build PoolKey (diem, agentToken, fee=DYNAMIC_FEE_FLAG, tickSpacing, hook)
   poolManager.initialize(key, sqrtPriceX96)
     → V4 pool created at starting price

5. hook.registerPool(key, agentToken, baseFee, maxFee, decayBlocks)
     → PoolState written for this PoolId

6. agentToken.transferFrom(agentWallet, hook, totalSupply)
   hook.addInitialLiquidity(key, liquidityDelta)
     → all AT added as one-sided LP (no DIEM required at launch)
     → hook becomes the sole LP; external providers are blocked

Return values

ValueDescription
agentTokenAddress of the newly deployed AgentToken
yieldTokenAddress of the newly deployed YieldToken
poolIdUniswap V4 PoolId for the agent's trading pool

pool() view

solidity
function pool() external view returns (address)

Returns the Kairence Pool address (kPool). Called by every AgentToken on every harvest(), setReserve(), and borrow() call so that a Pool upgrade only requires updating the factory — existing AgentToken contracts continue to work.

Events

solidity
event AgentLaunched(
    address indexed agentToken,
    address indexed yieldToken,
    address indexed agentWallet,
    PoolId  poolId
);

Released under the MIT License.