Skip to content

Commit 89408e5

Browse files
authored
feat(docs): get fassets asset manager address (#727)
1 parent be49aaa commit 89408e5

File tree

9 files changed

+128
-9
lines changed

9 files changed

+128
-9
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: Get FXRP Asset Manager Address
3+
tags: [intermediate, fassets]
4+
slug: fassets-asset-manager-address-contracts-registry
5+
description: Get FXRP asset manager address from the Flare contract registry
6+
keywords: [fassets, flare-network, fxrp, asset-manager]
7+
sidebar_position: 1
8+
---
9+
10+
import CodeBlock from "@theme/CodeBlock";
11+
import Remix from "@site/src/components/remix";
12+
import AssetManagerRegistry from "!!raw-loader!/examples/developer-hub-solidity/FAssetsAssetManagerRegistry.sol";
13+
import ExploringAdditionalParameters from "./_exploring-additional-parameters.mdx";
14+
15+
## Overview
16+
17+
When building on the Flare Network, it is important to **avoid hardcoding contract addresses**, especially for key components such as the FXRP Asset Manager.
18+
These addresses can change between Flare testnets and mainnet deployments, and relying on fixed values can lead to broken integrations.
19+
20+
Instead, you should dynamically fetch the FXRP Asset Manager address using the [Flare Contract Registry](/network/guides/flare-contracts-registry), the trusted source for obtaining contract addresses on any Flare network.
21+
22+
In this guide, you will learn:
23+
24+
- How to retrieve the [Asset Manager Controller](/fassets/reference/IAssetManagerController) using the Flare Contract Registry.
25+
- How to find the specific FXRP [Asset Manager](/fassets/reference/IAssetManager).
26+
- A sample Solidity contract that encapsulates this logic.
27+
28+
## Sample code
29+
30+
To get the [FAssets asset manager](/fassets/reference/IAssetManager) address, you can use the following smart contract that retrieves the [Asset Manager Controller](/fassets/reference/IAssetManagerController) address from the [Flare contract registry](/network/guides/flare-contracts-registry).
31+
32+
<CodeBlock language="solidity" title="contracts/AssetManagerRegistry.sol">
33+
{AssetManagerRegistry}
34+
</CodeBlock>
35+
36+
{/* prettier-ignore */}
37+
<Remix fileName="FAssetsAssetManagerRegistry.sol">Open in Remix</Remix>
38+
<br></br>
39+
40+
### Contract Breakdown
41+
42+
1. Imports the necessary interfaces and libraries from the [Flare Periphery Contracts package](https://www.npmjs.com/package/@flarenetwork/flare-periphery-contracts).
43+
2. Defines a constant `TXRP_HASH` that is the hash of the string `TXRP`.
44+
This is used to identify the FXRP asset manager.
45+
3. Implements a function `getFxrpAssetManager` that returns the FXRP [Asset Manager](/fassets/reference/IAssetManager) address.
46+
4. Uses the `ContractRegistry` library from the Flare Periphery Contracts package to get the [Asset Manager Controller](/fassets/reference/IAssetManagerController) address from the Flare contract registry.
47+
5. Uses the `IAssetManagerController` interface from the Flare Periphery Contracts package to get all the asset managers from the Asset Manager Controller.
48+
6. Iterates over the asset managers and returns the FXRP Asset Manager address.
49+
7. Gets the settings of the asset manager.
50+
8. Checks if the pool token suffix is `TXRP` and if true returns the FXRP Asset Manager address.
51+
52+
You can find out this sample code in the [Flare starter kit](/network/guides/hardhat-foundry-starter-kit).
53+
54+
:::tip Reusable Library
55+
56+
To reuse this code to get the FXRP Asset Manager address in other smart contracts, you can wrap it in a reusable library.
57+
This is useful if you want to use the FXRP Asset Manager address in multiple smart contracts and avoid repeating the same code.
58+
59+
:::
60+
61+
## Next Steps
62+
63+
In this guide, you learned how to get the FXRP Asset Manager address for the FAssets system by interacting with the `AssetManager` contract using the [`IAssetManager`](/fassets/reference/IAssetManager) interface.
64+
65+
You should not hardcode the FXRP Asset Manager address in your smart contracts.
66+
67+
To continue your FAssets development journey, you can:
68+
69+
- Learn how to [mint FXRP](/fassets/developer-guides/fassets-mint).
70+
- Understand how to [redeem FXRP](/fassets/developer-guides/fassets-redeem).
71+
- Explore [FAssets system settings](/fassets/operational-parameters).

docs/fassets/developer-guides/6-fassets-fxrp.mdx renamed to docs/fassets/developer-guides/2-fassets-fxrp.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tags: [intermediate, fassets]
44
slug: fassets-fxrp-address
55
description: Learn how to get FXRP address for interacting with the FAssets system
66
keywords: [fassets, flare-network, fxrp, asset-manager]
7-
sidebar_position: 6
7+
sidebar_position: 2
88
---
99

1010
import CodeBlock from "@theme/CodeBlock";

docs/fassets/developer-guides/2-fassets-asset-manager-settings-solidity.mdx renamed to docs/fassets/developer-guides/3-fassets-asset-manager-settings-solidity.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tags: [intermediate, fassets]
44
slug: fassets-settings-solidity
55
description: Fetch FAsset Lot Size and Value in USD (via FTSO) from a smart contract
66
keywords: [fassets, ftso, oracle, flare-time-series-oracle, flare-network, node]
7-
sidebar_position: 4
7+
sidebar_position: 3
88
---
99

1010
import CodeBlock from "@theme/CodeBlock";

docs/fassets/developer-guides/1-fassets-asset-manager-settings-node.mdx renamed to docs/fassets/developer-guides/4-fassets-asset-manager-settings-node.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tags: [intermediate, fassets]
44
slug: fassets-settings-node
55
description: Fetch FAsset Lot Size and Value in USD (via FTSO) using Node.js
66
keywords: [fassets, ftso, oracle, flare-time-series-oracle, flare-network, node]
7-
sidebar_position: 3
7+
sidebar_position: 4
88
---
99

1010
import ExploringAdditionalParameters from "./_exploring-additional-parameters.mdx";

docs/fassets/developer-guides/3-fassets-minting.mdx renamed to docs/fassets/developer-guides/5-fassets-minting.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tags: [intermediate, fassets]
44
slug: fassets-mint
55
description: Learn how to mint FAssets
66
keywords: [fassets, flare-network]
7-
sidebar_position: 1
7+
sidebar_position: 5
88
---
99

1010
import CodeBlock from "@theme/CodeBlock";

docs/fassets/developer-guides/4-fassets-redeem.mdx renamed to docs/fassets/developer-guides/6-fassets-redeem.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tags: [intermediate, fassets]
44
slug: fassets-redeem
55
description: Learn how to redeem FAssets
66
keywords: [fassets, flare-network]
7-
sidebar_position: 2
7+
sidebar_position: 6
88
---
99

1010
import CodeBlock from "@theme/CodeBlock";

docs/fassets/developer-guides/5-fassets-swap-redeem.mdx renamed to docs/fassets/developer-guides/7-fassets-swap-redeem.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tags: [intermediate, fassets]
44
slug: fassets-swap-redeem
55
description: Learn how to swap and redeem FAssets
66
keywords: [fassets, flare-network]
7-
sidebar_position: 5
7+
sidebar_position: 7
88
---
99

1010
import CodeBlock from "@theme/CodeBlock";

docs/network/guides/flare-contracts-registry.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ This library provides shorthand functions for accessing common protocol contract
9797

9898
In the example, the `getRandomNumberViaContractLibrary` function demonstrates this approach.
9999

100-
<br />
101-
:::tip If the contract you are looking for does not have a shorthand method in
100+
:::tip
101+
If the contract you are looking for does not have a shorthand method in
102102
the `ContractRegistry` library, you can fall back to using
103103
`getContractAddressByName` or call `getAllContracts` to list all registered
104-
contracts. :::
104+
contracts.
105+
:::
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
// 1. Import the necessary interfaces and libraries
5+
import {IFlareContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/IFlareContractRegistry.sol";
6+
7+
import {IAssetManager} from "@flarenetwork/flare-periphery-contracts/coston2/IAssetManager.sol";
8+
import {IAssetManagerController} from "@flarenetwork/flare-periphery-contracts/coston2/IAssetManagerController.sol";
9+
10+
import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";
11+
12+
import {AssetManagerSettings} from "@flarenetwork/flare-periphery-contracts/coston2/userInterfaces/data/AssetManagerSettings.sol";
13+
14+
contract AssetManagerRegistry {
15+
// 2. Define a constant TXRP_HASH that is the hash of the string "TXRP"
16+
bytes32 private constant TXRP_HASH = keccak256(abi.encodePacked("TXRP"));
17+
18+
// 3. Implement a function that returns the FXRP Asset Manager address
19+
function getFxrpAssetManager() public view returns (address) {
20+
// 4. Use the ContractRegistry library to get the AssetManagerController
21+
IAssetManagerController assetManagerController = ContractRegistry
22+
.getAssetManagerController();
23+
24+
// 5. Get all the asset managers from the AssetManagerController
25+
IAssetManager[] memory assetManagers = assetManagerController
26+
.getAssetManagers();
27+
28+
// 6. Iterate over the asset managers and return the FXRP Asset Manager address
29+
for (uint256 i = 0; i < assetManagers.length; i++) {
30+
IAssetManager assetManager = IAssetManager(assetManagers[i]);
31+
32+
// 7. Get the settings of the asset manager
33+
AssetManagerSettings.Data memory settings = assetManager
34+
.getSettings();
35+
36+
// Calculate the hash of the pool token suffix
37+
bytes32 poolTokenSuffixHash = keccak256(abi.encodePacked(poolTokenSuffix));
38+
39+
//8. return the address of the asset manager that has the pool token suffix "TXRP"
40+
if (poolTokenSuffixHash == TXRP_HASH) {
41+
return address(assetManager);
42+
}
43+
}
44+
// If no asset manager is found, return the zero address
45+
return address(0);
46+
}
47+
}

0 commit comments

Comments
 (0)