Read FAssets Settings (Solidity)
Overview
This guide will show you how to fetch FAsset lot size for FXRP using the Solidity smart contract on the Flare network. You will deploy the contract using Hardhat and interact with it via a TypeScript script.
Prerequisites
- Flare Hardhat Starter Kit
- Flare Network Periphery Contracts
- Node.js, TypeScript, and hardhat.config.ts with the Songbird Testnet Coston network configured
Create Smart Contract to Fetch FAsset Lot Size
To get the FAsset lot size, you can use the following smart contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
// 1. Import the Flare Contract Registry
import {ContractRegistry} from "flare-periphery-contracts-fassets-test/coston2/ContractRegistry.sol";
// 2. Import the AssetManager interface
import {IAssetManager} from "flare-periphery-contracts-fassets-test/coston2/IAssetManager.sol";
// 3. Contract for accessing FAssets settings from the asset manager
contract FAssetsSettings {
// 4. This function gets two important numbers from the asset manager settings:
// * lotSizeAMG: The smallest amount you can trade (in AMG units)
// * assetDecimals: How many decimal places the asset uses
// FAssets Operation Parameters https://dev.flare.network/fassets/operational-parameters
function getLotSize()
public
view
returns (uint64 lotSizeAMG, uint8 assetDecimals)
{
// 5. Get the AssetManager contract from the Flare Contract Registry
IAssetManager assetManager = ContractRegistry.getAssetManagerFXRP();
// 6. Get the lot size and asset decimals from the AssetManager contract
lotSizeAMG = assetManager.getSettings().lotSizeAMG;
assetDecimals = assetManager.getSettings().assetDecimals;
return (lotSizeAMG, assetDecimals);
}
}
Code Breakdown
- Import the ContractRegistry library to access the Flare Network contract registry.
- Import the interface
IAssetManager
from the Flare Periphery Contracts package, which provides access to the FAssets system. - Create a contract called
FAssetsSettings
that will be used to fetch the FAssets settings from the asset manager. - Use the ContractRegistry to get the FAssets FXRP asset manager address.
- Use the
getLotSize
function to retrieve settings from the FAssets FXRP asset manager. The function callsgetSettings
which returns the complete asset manager settings that you can find in the FAssets Operational Parameters documentation:lotSizeAMG
: The smallest amount you can trade (in AMG units).assetDecimals
: How many decimal places the FAssets asset uses.
- The
getLotSize
function returns two values:lotSizeAMG
: The smallest amount you can trade (in AMG units).assetDecimals
: How many decimal places the FAssets asset uses.
Using the Flare Hardhat Starter Kit you can quickly deploy the contract and generate TypeChain bindings for seamless TypeScript integration. It streamlines development by providing a ready-made project structure, preconfigured networks, and needed packages.
Deploy and Interact with the Smart Contract
Use the following TypeScript script to deploy the contract and fetch the FAsset settings using the Hardhat tool:
// yarn hardhat run scripts/fassets/getLotSize.ts --network coston2
// 1. Get the contract artifact
const FAssetsSettings = artifacts.require("FAssetsSettings");
async function main() {
// 2. Deploy the contract
const fAssetsSettings = await FAssetsSettings.new();
console.log("FAssetsSettings deployed to:", fAssetsSettings.address);
// 3. Call getSettings function
const lotSize = await fAssetsSettings.getLotSize();
console.log("Lot size:", lotSize[0]);
console.log("Decimals:", lotSize[1]);
// 4. Convert lot size to XRP
const lotSizeFXRP = Number(lotSize[0]) / Math.pow(10, Number(lotSize[1]));
console.log("Lot size in XRP", lotSizeFXRP);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Code Explanation
- Get the contract artifact
FAssetsSettings
from the Hardhat artifacts. - Deploy the
FAssetsSettings
on the network and get the contract address. - Call the
getLotSize
function to get the lot size and asset decimals. - Convert the lot size to XRP.
Run the Script
Now you can run the script using the Hardhat tool with the following command:
npx hardhat run scripts/fassets/getLotSize.ts --network coston2
You should see the following output:
Compiled 1 Solidity file successfully (evm target: shanghai).
Deploying FAssetsSettings...
FAssetsSettings deployed to: 0x40deEaA76224Ca9439D4e1c86F827Be829b89D9E
Lot size: 20000000n
Decimals: 6n
Lot size in XRP 20
This script is included in the Flare Hardhat Starter Kit.
Congratulations! You have now deployed a Solidity helper contract and used a TypeScript script to:
- Fetch FAsset FXRP lot size and decimals
- Convert the value to a user-friendly format using decimal precision.
The FAssets asset manager exposes key parameters like collateral ratios, minting fees, and liquidation thresholds via the getSettings
function.
See the FAssets Operational Parameters for details.