Pair Contract
Deployment Address: AgoraStableSwap is deployed with CREATE3 using a salt derived from token0 + token1, which guarantees the address can be predicted off-chain before the contract exists. The contract is a proxy‐based upgradeable contract, so the address remains constant while logic can be upgraded.
Access‑Control Roles
Events
Swap
Emitted at the end of every successful swap call. Tracks exact in/out amounts (including fees).
- Only a caller with the
APPROVED_SWAPPERrole can trigger this event.
Sync
Emitted whenever on‑chain reserves are brought in‑sync with the contract’s internal state.
- Fired from
swap,sync,removeTokens, andcollectFees. - No roles required for
sync()
SwapFees
Logs the incremental fee amounts captured during a swap.
ConfigureOraclePrice
Fired by configureOraclePrice whenever the on‑chain oracle price curve is updated.
- Callable only by
PRICE_SETTER_ROLE.
SetOraclePriceBounds
Signals an update to the guardrails enforced on future oracle‑price changes.
- Emitted by
setOraclePriceBounds; caller must holdACCESS_CONTROL_MANAGER_ROLE.
SetTokenPurchaseFees
Emitted when live purchase fees are changed via setTokenPurchaseFees.
- Requires
FEE_SETTER_ROLE.
SetFeeBounds
Defines the outer limits within which future purchase‑fee updates must fall.
- Emitted by
setFeeBounds - caller must hold
ACCESS_CONTROL_MANAGER_ROLE.
SetApprovedSwapper
Logged when an address is granted or revoked permission to call the low‑level swap.
- Emitted by
setApprovedSwappers - Caller must hold
WHITELISTER_ROLE.
SetTokenReceiver
Fired by setTokenReceiver when the treasury destination for non‑fee token withdrawals is updated.
- Requires
ACCESS_CONTROL_MANAGER_ROLE.
SetFeeReceiver
Fired by setFeeReceiver when the destination for fee withdrawals is updated.
- Requires
ACCESS_CONTROL_MANAGER_ROLE.
RemoveTokens
Emitted by both removeTokens and collectFees.
removeTokensmoves “excess” liquidity totokenReceiverAddress.collectFeestransfers accumulated fees tofeeReceiverAddress.- Both functions require
TOKEN_REMOVER_ROLE.
SetPaused
Global circuit‑breaker toggle, emitted by setPaused.
- Callable only by
PAUSER_ROLE.
Read-Only Functions
getAmountsOut
Determines how many output tokens a router‑style swap would return for a given amountIn.
- Path rules – Must be length 2 and equal to
[token0, token1]or[token1, token0]; otherwise revertsInvalidPath/InvalidPathLength. - Pricing – Uses the live oracle price
getPrice()and the current purchase‑fee parameters for the outgoing token. - Liquidity check – Reverts
InsufficientLiquidity()if reserves can’t satisfy the quote. - Return value –
amounts[0] == amountIn,amounts[1] == deterministic quote(fees already deducted).
This is a pure view helper—calling it does not move funds or mutate state. This function is used by swapExactTokensForTokens
getAmountsIn
Inverse of getAmountsOut: calculates the minimum tokens required to receive a specified amountOut.
- Path rules – Same as above; reverts on invalid path length or composition.
- Pricing – Considers current oracle price plus purchase fee for the incoming token.
- Reserve guard – Reverts
InsufficientLiquidity()ifamountOutexceeds current reserves of the outgoing asset. - Return value –
amounts[0] == required amountIn,amounts[1] == amountOut. This function is used byswapTokensForExactTokens
State-Changing Functions
Admin / Config
Treasury
removeTokens
- Who / Role –
TOKEN_REMOVER_ROLE - Purpose – Withdraws surplus tokens (not counted as fees) to
tokenReceiverAddress. - Events –
RemoveTokens(token, amount) thenSync(reserve0,reserve1) - Reverts –
InsufficientTokens()– trying to pull more than surplus balanceInvalidTokenAddress()– token not part of the pair
collectFees
- Who / Role –
TOKEN_REMOVER_ROLE - Purpose – Transfers accrued fees to
feeReceiverAddress. - Events –
RemoveTokens(token, amount) thenSync(…) - Reverts – Same conditions as
removeTokens, but checked against_FeesAccumulated.
Swapping APIs
swapExactTokensForTokens
High‑level “exact‑in” swap helper (router style).
- Flow
- Quotes output via internal math.
- Requires
amountOut ≥ amountOutMin; elseInsufficientOutputAmount(). - Pulls
amountInfrom caller viasafeTransferFrom. - Delegates to the low‑level
swap.
- Events – Propagates
Swap,SwapFees,Sync. - Reverts –
Expired(),InvalidPath*, liquidity or price‑related errors.
swapTokensForExactTokens
High‑level “exact‑out” variant.
- Checks – Requires
amountIn ≤ amountInMaxor revertsExcessiveInputAmount(). - Mirrors
swapExactTokensForTokensotherwise.
swap
Low‑level primitive that can perform flash‑swaps if data is non‑empty.
- Who / Role –
APPROVED_SWAPPER - Rules – Exactly one of
amount0Out,amount1Outmust be non‑zero; elseInvalidSwapAmounts(). - Callback – If
datais supplied,tomust implement UniswapV2CallbackInterface. - Invariant – Ensures required tokens plus fees are returned, else reverts
InsufficientInputAmount(). - Events –
SwapFees→Sync→Swap(in that order).
Errors
Interface
ABI
The ABI of the AgorastableSwapPair is available here

