Factory Contract Overview

AgoraStableSwapFactory is responsible for deploying Agora Stable Swap pairs. The deployment process uses CREATE3 for deterministic deployment based off token0 and token1, meaning integrators can discover every pool without relying on off-chain registries.

Access‑Control Roles

Role constantCapabilities
ACCESS_CONTROL_MANAGER_ROLEGrants/revokes any other role
APPROVED_DEPLOYER_ROLEAllowed to call createPair and deploy new pools. Curated by the ACCESS_CONTROL_MANAGER_ROLE.

Events

PairCreated

1event PairCreated(address indexed token0, address indexed token1, address pair);

Emitted each time a pair is created via createPair.

  • Only a user with APPROVED_DEPLOYER role can call the underlying function that triggers this event.
  • token0 is guaranteed to be strictly less than token1 by sorting order

SetApprovedDeployer

1event SetApprovedDeployer(address indexed approvedDeployer, bool isApproved);

Emitted when a new approved deployer is set, by calling setApprovedDeployers.


Read-Only Functions

getAllPairData

1function getAllPairData() public view returns (PairData[] memory)

Returns the information of all pairs deployed on a chain as an array of PairData structures, each containing the address of the pair, as well as information about the tokens that comprise the pair.

getPairFromTokens

1function getPairFromTokens(address _token0, address _token1) public view returns (address)

Returns the address of the pair for token0 and token1, if it has been created, else address(0)

computePairDeploymentAddress

1function computePairDeploymentAddress(
2 address _tokenA,
3 address _tokenB
4) public view returns (address _pairDeploymentAddress)

Returns the deterministic deployment address for a AgoraStableSwapPair deployed with tokenA and tokenB as swapping tokens.

version

1function version() public pure returns (Version memory _version)

Returns a Version structure with current deployment version for the factory


State-Changing Functions:

createPair

1function createPair(CreatePairArgs memory _pairArgs) external returns (address pair)

Creates a new pair with the given parameters, as long as a pair with token0 and token1 don’t exist already


Interface

1// SPDX-License-Identifier: BUSL-1.1
2pragma solidity ^0.8.4;
3
4library AgoraStableSwapFactory {
5 struct AgoraStableSwapDefaultParamsStorage {
6 address initialDefaultAdminAddress;
7 address initialDefaultWhitelister;
8 address initialDefaultFeeSetter;
9 address initialDefaultTokenRemover;
10 address initialDefaultPauser;
11 address initialDefaultPriceSetter;
12 address initialDefaultTokenReceiver;
13 address initialDefaultFeeReceiver;
14 }
15
16 struct CreatePairArgs {
17 address token0;
18 uint256 token0Decimals;
19 uint256 minToken0PurchaseFee;
20 uint256 maxToken0PurchaseFee;
21 uint256 token0PurchaseFee;
22 address token1;
23 uint256 token1Decimals;
24 uint256 minToken1PurchaseFee;
25 uint256 maxToken1PurchaseFee;
26 uint256 token1PurchaseFee;
27 uint256 minBasePrice;
28 uint256 maxBasePrice;
29 uint256 basePrice;
30 int256 minAnnualizedInterestRate;
31 int256 maxAnnualizedInterestRate;
32 int256 annualizedInterestRate;
33 }
34
35 struct PairData {
36 address pairAddress;
37 TokenInfo token0;
38 TokenInfo token1;
39 }
40
41 struct TokenInfo {
42 address tokenAddress;
43 string name;
44 string symbol;
45 uint256 decimals;
46 }
47
48 struct Version {
49 uint256 major;
50 uint256 minor;
51 uint256 patch;
52 }
53}
54
55interface IAgoraStableSwapFactory {
56 struct InitializeParams {
57 address initialStableSwapImplementation;
58 address initialStableSwapProxyAdminAddress;
59 address initialFactoryAccessControlManager;
60 address[] initialApprovedDeployers;
61 address initialDefaultAdminAddress;
62 address initialDefaultWhitelister;
63 address initialDefaultFeeSetter;
64 address initialDefaultTokenRemover;
65 address initialDefaultPauser;
66 address initialDefaultPriceSetter;
67 address initialDefaultTokenReceiver;
68 address initialDefaultFeeReceiver;
69 }
70
71 error AddressIsNotRole(string role);
72 error CannotRemoveLastManager();
73 error DecimalDeltaTooLarge();
74 error IdenticalAddresses();
75 error InvalidInitialization();
76 error InvalidTokenOrder();
77 error NotInitializing();
78 error PairExists();
79 error RoleNameTooLong();
80 error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
81 error ZeroAddress();
82
83 event Initialized(uint64 version);
84 event PairCreated(address indexed token0, address indexed token1, address pair);
85 event RoleAssigned(string indexed role, address indexed address_);
86 event RoleRevoked(string indexed role, address indexed address_);
87 event SetApprovedDeployer(address indexed approvedDeployer, bool isApproved);
88 event SetDefaultRoles(
89 address initialAdminAddress,
90 address initialWhitelister,
91 address initialFeeSetter,
92 address initialTokenRemover,
93 address initialPauser,
94 address initialPriceSetter,
95 address initialTokenReceiver,
96 address initialFeeReceiver
97 );
98
99 function ACCESS_CONTROL_MANAGER_ROLE() external view returns (string memory);
100
101 function AGORA_ACCESS_CONTROL_STORAGE_SLOT() external view returns (bytes32);
102
103 function AGORA_STABLE_SWAP_FACTORY_STORAGE_SLOT() external view returns (bytes32);
104
105 function APPROVED_DEPLOYER() external view returns (string memory);
106
107 function allPairs() external view returns (address[] memory _pairs);
108
109 function assignRole(string memory _role, address _newAddress, bool _addRole) external;
110
111 function computePairDeploymentAddress(
112 address _tokenA,
113 address _tokenB
114 ) external view returns (address _pairDeploymentAddress);
115
116 function createPair(AgoraStableSwapFactory.CreatePairArgs memory _pairArgs) external returns (address pair);
117
118 function getAgoraStableSwapDefaultParamsStorage()
119 external
120 view
121 returns (AgoraStableSwapFactory.AgoraStableSwapDefaultParamsStorage memory);
122
123 function getAllPairData() external view returns (AgoraStableSwapFactory.PairData[] memory);
124
125 function getAllRoles() external view returns (string[] memory _roles);
126
127 function getPairFromTokens(address _token0, address _token1) external view returns (address);
128
129 function getRoleMembers(string memory _role) external view returns (address[] memory _members);
130
131 function hasRole(string memory _role, address _address) external view returns (bool);
132
133 function initialize(InitializeParams memory _params) external;
134
135 function name() external pure returns (string memory);
136
137 function setApprovedDeployers(address[] memory _approvedDeployers, bool _setApproved) external;
138
139 function setDefaultRoles(
140 address _initialAdminAddress,
141 address _initialWhitelister,
142 address _initialFeeSetter,
143 address _initialTokenRemover,
144 address _initialPauser,
145 address _initialPriceSetter,
146 address _initialTokenReceiver,
147 address _initialFeeReceiver
148 ) external;
149
150 function sortTokens(address _tokenA, address _tokenB) external pure returns (address _token0, address _token1);
151
152 function stableSwapImplementation() external view returns (address);
153
154 function stableSwapProxyAdmin() external view returns (address);
155
156 function version() external pure returns (AgoraStableSwapFactory.Version memory _version);
157}

ABI

The ABI of the AgorastableSwapFactory is available here