Skip to content

Commit 0204830

Browse files
committed
feat(docs): add guide for listing FAssets agents and update IAssetManager reference
1 parent 8bb1552 commit 0204830

File tree

4 files changed

+214
-31
lines changed

4 files changed

+214
-31
lines changed

docs/fassets/developer-guides.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,17 @@ Guides for reading and working with agent data.
102102

103103
<DocCardList
104104
items={[
105+
{
106+
type: "link",
107+
label: "List FAssets Agents",
108+
href: "/fassets/developer-guides/fassets-list-agents",
109+
docId: "fassets/developer-guides/fassets-list-agents",
110+
},
105111
{
106112
type: "link",
107113
label: "Read FAssets Agent Details",
108114
href: "/fassets/developer-guides/fassets-agent-details",
109115
docId: "fassets/developer-guides/fassets-agent-details",
110-
},
116+
}
111117
]}
112118
/>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
title: List FAssets Agents
3+
tags: [intermediate, fassets]
4+
slug: fassets-list-agents
5+
description: Learn how to get a list of FAssets agents
6+
keywords: [fassets, flare-network]
7+
---
8+
9+
import CodeBlock from "@theme/CodeBlock";
10+
import FAssetsListAgents from "!!raw-loader!/examples/developer-hub-javascript/fassets_list_agents.ts";
11+
12+
## Overview
13+
14+
In this guide, you will learn how to list FAssets agents using the [AssetManager](/fassets/reference/IAssetManager) smart contract.
15+
16+
## Prerequisites
17+
18+
- Basic understanding of the [FAssets system](/fassets/overview).
19+
- [Flare Network Periphery Contracts](https://www.npmjs.com/package/@flarenetwork/flare-periphery-contracts) package.
20+
21+
## List FAssets Agents
22+
23+
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.
53+
54+
<CodeBlock language="typescript" title="scripts/fassets/listAgents.ts">
55+
{FAssetsListAgents}
56+
</CodeBlock>
57+
58+
### How the Code Works
59+
60+
The script follows these steps:
61+
62+
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)
107+
:::

docs/fassets/reference/IAssetManager.mdx

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ Returns the collateral reservation fee amount.
5757

5858
Parameters:
5959

60-
- `_lots`: The number of lots for which to reserve collateral
60+
- `_lots`: The number of lots for which to reserve collateral.
6161

6262
Returns:
6363

64-
- `_reservationFeeNATWei`: The amount of reservation fee in NAT wei
64+
- `_reservationFeeNATWei`: The amount of reservation fee in NAT wei.
6565

6666
```solidity
6767
function collateralReservationFee(
@@ -76,7 +76,7 @@ Note: once the minting is executed or defaulted, the collateral reservation is d
7676

7777
Parameters:
7878

79-
- `_collateralReservationId`: The collateral reservation ID, as used for executing or defaulting the minting
79+
- `_collateralReservationId`: The collateral reservation ID, as used for executing or defaulting the minting.
8080

8181
```solidity
8282
function collateralReservationInfo(uint256 _collateralReservationId)
@@ -90,7 +90,7 @@ Returns the FAsset token contract (ERC-20) that is managed by this asset manager
9090

9191
Returns:
9292

93-
- `IERC20`: The address of the FAsset token contract
93+
- `IERC20`: The address of the FAsset token contract.
9494

9595
```solidity
9696
function fAsset()
@@ -100,19 +100,39 @@ function fAsset()
100100

101101
## Agents
102102

103+
## `getAllAgents`
104+
105+
Returns the list of all agents.
106+
107+
Parameters:
108+
109+
- `_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.
111+
112+
Returns:
113+
114+
- `_agents`: The list of all agents.
115+
- `_totalLength`: The total length of the all agents list.
116+
117+
```solidity
118+
function getAllAgents(uint256 _start, uint256 _end)
119+
external view
120+
returns (address[] memory _agents, uint256 _totalLength);
121+
```
122+
103123
### `getAvailableAgentsList`
104124

105125
Returns the list of available agents.
106126

107127
Parameters:
108128

109-
- `_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.
111131

112132
Returns:
113133

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.
116136

117137
```solidity
118138
function getAvailableAgentsList(uint256 _start, uint256 _end)
@@ -126,13 +146,13 @@ Returns the list of available agents with extra information about agents like fe
126146

127147
Parameters:
128148

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.
131151

132152
Returns:
133153

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.
136156

137157
```solidity
138158
function getAvailableAgentsDetailedList(uint256 _start, uint256 _end)
@@ -148,13 +168,13 @@ Returns the redemption queue in the form of an array of [`RedemptionTicketInfo`]
148168

149169
Parameters:
150170

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.
153173

154174
Returns:
155175

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.
158178

159179
```solidity
160180
function redemptionQueue(
@@ -170,14 +190,14 @@ Returns the redemption queue for specific agent in the form of an array of [`Red
170190

171191
Parameters:
172192

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.
176196

177197
Returns:
178198

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.
181201

182202
```solidity
183203
function agentRedemptionQueue(
@@ -197,10 +217,10 @@ Before paying underlying assets for minting, the minter must reserve collateral
197217

198218
Parameters:
199219

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).
204224

205225
```solidity
206226
function reserveCollateral(
@@ -219,14 +239,14 @@ After obtaining proof of underlying payment, the minter calls this method to fin
219239

220240
Note: May only be called by:
221241

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).
225245

226246
Parameters:
227247

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).
249+
- `_collateralReservationId`: Collateral reservation ID.
230250

231251
```solidity
232252
function executeMinting(
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { getAssetManagerFXRP } from "../utils/getters";
2+
3+
/**
4+
* Script to list all available FAssets agents in chunks
5+
*
6+
* This script demonstrates how to iterate through all agents in the FAssets system
7+
* by fetching them in chunks to avoid overwhelming the RPC endpoint with large requests.
8+
*
9+
* Run with: yarn hardhat run scripts/fassets/listAgents.ts --network coston2
10+
*/
11+
12+
async function main() {
13+
// 1. Get the FAssets FXRP asset manager contract instance
14+
const assetManager = await getAssetManagerFXRP();
15+
16+
// 2. Define how many agents to fetch per request
17+
// Using smaller chunks (e.g., 3) helps avoid RPC timeout issues
18+
const chunkSize = 3;
19+
20+
// 3. Fetch the first chunk and get the total count
21+
// The _totalLength property tells us how many agents exist in total
22+
console.log("Fetching first chunk with offset 0 and chunk size " + chunkSize);
23+
const firstChunk = await assetManager.getAvailableAgentsList(0, chunkSize);
24+
console.log(firstChunk._agents);
25+
26+
const totalLength = Number(BigInt(firstChunk._totalLength).toString());
27+
console.log(`Total number of agents: ${totalLength}`);
28+
29+
// 4. Iterate through remaining agents in chunks
30+
// The getAvailableAgentsDetailedList(start, end) function uses:
31+
// - start: inclusive start index (0-based)
32+
// - end: exclusive end index (like array slicing)
33+
// Example: (0, 3) returns agents at indices 0, 1, 2
34+
for (let offset = chunkSize; offset < totalLength; offset += chunkSize) {
35+
// Calculate end index, ensuring we don't exceed totalLength
36+
const endIndex = Math.min(offset + chunkSize, totalLength);
37+
console.log(`\n--- Fetching agents ${offset} to ${endIndex - 1} (end index ${endIndex} exclusive) ---`);
38+
39+
// Fetch the chunk of agents
40+
const agents = await assetManager.getAvailableAgentsList(offset, endIndex);
41+
console.log(agents._agents);
42+
}
43+
44+
console.log(`\nCompleted processing all ${totalLength} agents`);
45+
}
46+
47+
main().catch(error => {
48+
console.error(error);
49+
process.exitCode = 1;
50+
});

0 commit comments

Comments
 (0)