You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The [AssetManager](/fassets/reference/IAssetManager) smart contract provides these functions to list FAssets agents:
24
+
25
+
-[`getAllAgents`](/fassets/reference/IAssetManager#getallagents): Returns all agents in the system, including both available and unavailable agents, with basic information.
26
+
-[`getAvailableAgentsList`](/fassets/reference/IAssetManager#getavailableagentslist): Returns only available agents (agents accepting new minting requests) with basic information.
27
+
-[`getAvailableAgentsDetailedList`](/fassets/reference/IAssetManager#getavailableagentsdetailedlist): Returns only available agents with comprehensive details, including collateral ratios, fees, and vault status.
28
+
29
+
### Function Parameters
30
+
31
+
All of these functions take two parameters:
32
+
33
+
-`_start`: First index to return from the agents list.
34
+
-`_end`: End index to return from the agents list (exclusive).
35
+
36
+
And return two values:
37
+
38
+
-`_agents`: Array of agent information structures.
39
+
-`_totalLength`: Total number of agents in the system (used for pagination).
40
+
41
+
:::tip Index Parameters
42
+
All of these functions use array-like slicing:
43
+
-`start`: Inclusive start index (0-based).
44
+
-`end`: Exclusive end index.
45
+
46
+
For example, `getAllAgents(0, 3)` returns agents at indices 0, 1, and 2.
47
+
:::
48
+
49
+
## Example
50
+
51
+
This example demonstrates how to use the [`getAvailableAgentsList`](/fassets/reference/IAssetManager#getavailableagentslist) function to list available agents in chunks.
52
+
The chunking approach prevents RPC timeouts when dealing with many agents by fetching data in smaller, manageable batches.
1.**Get Asset Manager Contract**: Retrieve the FAssets FXRP Asset Manager contract instance using the helper function `getAssetManagerFXRP()` from the Flare periphery contracts package.
63
+
64
+
2.**Define Chunk Size**: Set `chunkSize` to `3`, determining how many agents to fetch per request.
65
+
Using smaller chunks helps avoid RPC timeout issues when dealing with many agents.
66
+
You can adjust this value based on your network conditions and RPC provider limits.
67
+
68
+
3.**Fetch First Chunk**: Call `getAvailableAgentsList(0, chunkSize)` which:
69
+
- Returns the first three agents (indices 0, 1, 2).
70
+
- Provides the `_totalLength` property showing the total number of agents in the system.
71
+
72
+
4.**Iterate Through Remaining Agents**: Loop through the remaining agents in chunks:
73
+
- Start from `offset = chunkSize` (3) and increment by `chunkSize` each iteration.
74
+
- Calculate `endIndex = Math.min(offset + chunkSize, totalLength)` to ensure we do not exceed the total length.
75
+
- Fetch each chunk using `getAvailableAgentsList(offset, endIndex)`.
76
+
- Display the agents in each chunk for processing or analysis.
77
+
78
+
:::info
79
+
A similar approach can be used to list all agents using the [`getAllAgents`](/fassets/reference/IAssetManager#getallagents) and [`getAvailableAgentsDetailedList`](/fassets/reference/IAssetManager#getavailableagentsdetailedlist) functions.
80
+
:::
81
+
82
+
### Run the Script
83
+
84
+
To run the script, use the following command:
85
+
86
+
```bash
87
+
yarn hardhat run scripts/fassets/listAgents.ts --network coston2
88
+
```
89
+
90
+
To use the script, replace `coston2` with the network you are using.
91
+
The script will output information about the available agents on the [Coston2](/network/overview) network.
92
+
93
+
## Summary
94
+
95
+
This guide covered:
96
+
97
+
-**Agent List Functions**: Three different methods to retrieve agent information with varying levels of detail.
98
+
-**Pagination Strategy**: How to use chunking to retrieve large agent lists without overwhelming RPC endpoints efficiently.
99
+
-**Practical Implementation**: A complete TypeScript example demonstrating agent list retrieval with proper pagination and error handling considerations.
100
+
101
+
:::tip Next Steps
102
+
To continue your FAssets development journey, you can:
103
+
104
+
- Learn how to [mint FXRP](/fassets/developer-guides/fassets-mint)
105
+
- Understand how to [redeem FXRP](/fassets/developer-guides/fassets-redeem)
106
+
- Explore [FAssets system settings](/fassets/operational-parameters)
-`_start`: First index to return from the available agent's list
110
-
-`_end`: End index (one above last) to return from the available agent's list
129
+
-`_start`: First index to return from the available agent's list.
130
+
-`_end`: End index (one above last) to return from the available agent's list.
111
131
112
132
Returns:
113
133
114
-
-`_agents`: The list of available agents
115
-
-`_totalLength`: The total length of the available agents list
134
+
-`_agents`: The list of available agents.
135
+
-`_totalLength`: The total length of the available agents list.
116
136
117
137
```solidity
118
138
function getAvailableAgentsList(uint256 _start, uint256 _end)
@@ -126,13 +146,13 @@ Returns the list of available agents with extra information about agents like fe
126
146
127
147
Parameters:
128
148
129
-
-`_start`: First index to return from the available agent's list
130
-
-`_end`: End index (one above last) to return from the available agent's list
149
+
-`_start`: First index to return from the available agent's list.
150
+
-`_end`: End index (one above last) to return from the available agent's list.
131
151
132
152
Returns:
133
153
134
-
-`_agents`: The list of available agents with extra information
135
-
-`_totalLength`: The total length of the available agents list
154
+
-`_agents`: The list of available agents with extra information.
155
+
-`_totalLength`: The total length of the available agents list.
136
156
137
157
```solidity
138
158
function getAvailableAgentsDetailedList(uint256 _start, uint256 _end)
@@ -148,13 +168,13 @@ Returns the redemption queue in the form of an array of [`RedemptionTicketInfo`]
148
168
149
169
Parameters:
150
170
151
-
-`_firstRedemptionTicketId`: the ticket id to start listing from; if `0`, starts from the beginning
152
-
-`_pageSize`: the maximum number of redemption tickets to return
171
+
-`_firstRedemptionTicketId`: the ticket id to start listing from; if `0`, starts from the beginning.
172
+
-`_pageSize`: the maximum number of redemption tickets to return.
153
173
154
174
Returns:
155
175
156
-
-`_queue`: the (part of) the redemption queue; maximum length is \_pageSize
157
-
-`_nextRedemptionTicketId`: works as a cursor - if the `_pageSize` is reached and there are more tickets, it is the first ticket id not returned; if the end is reached, it is 0
176
+
-`_queue`: the (part of) the redemption queue; maximum length is \_pageSize.
177
+
-`_nextRedemptionTicketId`: works as a cursor - if the `_pageSize` is reached and there are more tickets, it is the first ticket id not returned; if the end is reached, it is 0.
158
178
159
179
```solidity
160
180
function redemptionQueue(
@@ -170,14 +190,14 @@ Returns the redemption queue for specific agent in the form of an array of [`Red
170
190
171
191
Parameters:
172
192
173
-
-`_agentVault`: the agent vault address of the queried agent
174
-
-`_firstRedemptionTicketId`: the ticket id to start listing from; if `0`, starts from the beginning
175
-
-`_pageSize`: the maximum number of redemption tickets to return
193
+
-`_agentVault`: the agent vault address of the queried agent.
194
+
-`_firstRedemptionTicketId`: the ticket id to start listing from; if `0`, starts from the beginning.
195
+
-`_pageSize`: the maximum number of redemption tickets to return.
176
196
177
197
Returns:
178
198
179
-
-`_queue`: the (part of) the redemption queue; maximum length is \_pageSize
180
-
-`_nextRedemptionTicketId`: works as a cursor - if the` _pageSize` is reached and there are more tickets, it is the first ticket id not returned; if the end is reached, it is 0
199
+
-`_queue`: the (part of) the redemption queue; maximum length is \_pageSize.
200
+
-`_nextRedemptionTicketId`: works as a cursor - if the` _pageSize` is reached and there are more tickets, it is the first ticket id not returned; if the end is reached, it is 0.
181
201
182
202
```solidity
183
203
function agentRedemptionQueue(
@@ -197,10 +217,10 @@ Before paying underlying assets for minting, the minter must reserve collateral
197
217
198
218
Parameters:
199
219
200
-
-`_agentVault`: Agent vault address
201
-
-`_lots`: Number of lots for which to reserve collateral
202
-
-`_maxMintingFeeBIPS`: Maximum minting fee (BIPS) that can be charged by the agent - best practice is to copy the current agent's published fee; used to prevent agent from front-running reservation request and increasing fee
203
-
-`_executor`: Account that is allowed to execute minting (besides minter and agent)
220
+
-`_agentVault`: Agent vault address.
221
+
-`_lots`: Number of lots for which to reserve collateral.
222
+
-`_maxMintingFeeBIPS`: Maximum minting fee (BIPS) that can be charged by the agent - best practice is to copy the current agent's published fee; used to prevent agent from front-running reservation request and increasing fee.
223
+
-`_executor`: Account that is allowed to execute minting (besides minter and agent).
204
224
205
225
```solidity
206
226
function reserveCollateral(
@@ -219,14 +239,14 @@ After obtaining proof of underlying payment, the minter calls this method to fin
219
239
220
240
Note: May only be called by:
221
241
222
-
- The minter (creator of the collateral reservation request)
223
-
- The executor appointed by the minter
224
-
- The agent owner (owner of the agent vault in the collateral reservation)
242
+
- The minter (creator of the collateral reservation request).
243
+
- The executor appointed by the minter.
244
+
- The agent owner (owner of the agent vault in the collateral reservation).
225
245
226
246
Parameters:
227
247
228
-
-`_payment`: Proof of the underlying payment (must contain exact `value + fee` amount and correct payment reference)
229
-
-`_collateralReservationId`: Collateral reservation ID
248
+
-`_payment`: Proof of the underlying payment (must contain exact `value + fee` amount and correct payment reference).
0 commit comments