Skip to content

Commit 3702a21

Browse files
committed
refactor(docs): enhance FAssets minting guides and update TypeScript examples for improved clarity and consistency
1 parent ca4694b commit 3702a21

File tree

4 files changed

+65
-83
lines changed

4 files changed

+65
-83
lines changed

docs/fassets/developer-guides/5-fassets-minting.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,21 @@ The following code demonstrates how to reserve collateral by calling the [`reser
4747

4848
1. Define constants
4949

50-
- `ASSET_MANAGER_ADDRESS`: FXRP AssetManager address on Songbird Testnet (Coston).
5150
- `LOTS_TO_MINT`: Number of FAsset lots to reserve.
52-
- `UNDERLYING_ADDRESS`: Target XRP Ledger address for the minted asset.
5351
- `ZERO_ADDRESS`: Placeholder for `executor` (not used in this script).
5452

5553
2. Retrieve and filter agents with enough free collateral and select the agent with the lowest fee and normal status.
5654
3. Parse [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event.
5755
4. Start the minting reservation process at the script's entry point.
5856
5. Call `findBestAgent` with the required number of lots.
59-
6. Fetch agent metadata from [`getAgentInfo`](/fassets/reference/IAssetManager#getagentinfo) to get the agent's `feeBIPS`, which is used to calculate the collateral reservation fee.
60-
7. Calculate the collateral reservation fee by calling [`collateralReservationFee`](/fassets/reference/IAssetManager#collateralreservationfee).
61-
8. Reserve collateral from agent by calling [`reserveCollateral`](/fassets/reference/IAssetManager#reservecollateral)
62-
9. Call `assetMintingDecimals` to determine the XRP token's decimal precision.
63-
10. Parse the [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event.
64-
11. Calculate the total XRP value required for payment.
57+
6. Get the asset manager from the [Flare Contract Registry](/fassets/reference/ContractRegistry).
58+
7. Find the best agent with enough free collateral lots.
59+
8. Fetch agent metadata from [`getAgentInfo`](/fassets/reference/IAssetManager#getagentinfo) to get the agent's `feeBIPS`, which is used to calculate the collateral reservation fee.
60+
9. Calculate the collateral reservation fee by calling [`collateralReservationFee`](/fassets/reference/IAssetManager#collateralreservationfee).
61+
10. Reserve collateral from agent by calling [`reserveCollateral`](/fassets/reference/IAssetManager#reservecollateral)
62+
11. Call `assetMintingDecimals` to determine the XRP token's decimal precision.
63+
12. Parse the [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event.
64+
13. Calculate the total XRP value required for payment.
6565

6666
## Send Payment on XRP Ledger
6767

docs/fassets/developer-guides/6-fassets-minting-executor.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,24 @@ The following code demonstrates how to reserve collateral by calling the [`reser
5757

5858
1. Define constants
5959

60-
- `ASSET_MANAGER_ADDRESS`: FXRP AssetManager address on Songbird Testnet (Coston).
6160
- `LOTS_TO_MINT`: Number of FAssets [lots](/fassets/minting#lots) to reserve.
62-
- `UNDERLYING_ADDRESS`: Target XRP Ledger address for the minted asset.
6361
- `EXECUTOR_ADDRESS`: Executor address that will execute the minting process and provide the proof of underlying asset payment.
6462

65-
2. Retrieve and filter agents with enough free collateral and select the agent with the lowest fee and normal status.
66-
3. Parse [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event.
67-
4. Start the minting reservation process at the script's entry point.
68-
5. Call `findBestAgen` with the required number of lots.
69-
6. Fetch agent metadata from [`getAgentInfo`](/fassets/reference/IAssetManager#getagentinfo) to get the agent's `feeBIPS`, which is used to calculate the collateral reservation fee.
70-
7. Calculate the collateral reservation fee by calling [`collateralReservationFee`](/fassets/reference/IAssetManager#collateralreservationfee).
71-
8. Set the executor fee the same as the collateral reservation fee to make this example simpler.
72-
9. Reserve collateral from agent by calling [`reserveCollateral`](/fassets/reference/IAssetManager#reservecollateral) with the executor address.
63+
2. Get the AssetManager artifact
64+
3. Retrieve and filter agents with enough free collateral and select the agent with the lowest fee and normal status.
65+
4. Parse [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event.
66+
5. Start the minting reservation process at the script's entry point.
67+
6. Get the asset manager artifact.
68+
7. Call `findBestAgent` with the required number of lots.
69+
8. Fetch agent metadata from [`getAgentInfo`](/fassets/reference/IAssetManager#getagentinfo) to get the agent's `feeBIPS`, which is used to calculate the collateral reservation fee.
70+
9. Calculate the collateral reservation fee by calling [`collateralReservationFee`](/fassets/reference/IAssetManager#collateralreservationfee).
71+
10. Set the executor fee the same as the collateral reservation fee to make this example simpler.
72+
11. Reserve collateral from agent by calling [`reserveCollateral`](/fassets/reference/IAssetManager#reservecollateral) with the executor address.
7373
The executor fee is on top of the collateral reservation fee in native tokens.
7474
The fee is agreed between the minter and the executor.
75-
10. Call `assetMintingDecimals` to determine the XRP token's decimal precision.
76-
11. Parse the [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event to get the collateral reservation ID and other important collateral reservation details.
77-
12. Calculate the total XRP value required for payment.
75+
12. Call `assetMintingDecimals` to determine the XRP token's decimal precision.
76+
13. Parse the [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event to get the collateral reservation ID and other important collateral reservation details.
77+
14. Calculate the total XRP value required for payment.
7878

7979
## Send Payment on XRP Ledger
8080

examples/developer-hub-javascript/fassetsReserveCollateral.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async function parseCollateralReservedEvent(
7171
) {
7272
console.log("\nParsing events...", transactionReceipt.rawLogs);
7373

74-
// 5. The logEvents function is included in the Flare starter kit
74+
// The logEvents function is included in the Flare starter kit
7575
const collateralReservedEvents = logEvents(
7676
transactionReceipt.rawLogs,
7777
"CollateralReserved",
@@ -81,6 +81,7 @@ async function parseCollateralReservedEvent(
8181
return collateralReservedEvents[0].decoded;
8282
}
8383

84+
// 5. Main function
8485
async function main() {
8586
// 6. Get the AssetManager contract from the Flare Contract Registry
8687
const assetManager: IAssetManagerInstance = await getAssetManagerFXRP();

examples/developer-hub-javascript/fassetsReserveCollateralWithExecutor.ts

Lines changed: 42 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
import { ethers } from "hardhat";
2-
3-
import {
4-
IAssetManagerInstance,
5-
IAssetManagerContract,
6-
} from "../../typechain-types";
7-
8-
// Initialize the FAssets FXRP AssetManager contract
9-
const AssetManager = artifacts.require("IAssetManager");
1+
import { getFXRPAssetManager } from "../utils/fassets";
2+
import { IAssetManagerInstance } from "../../typechain-types";
3+
import { logEvents } from "../../scripts/utils/core";
104

115
// 1. Define constants
126

13-
// AssetManager address on Flare Testnet Coston2 network
14-
const ASSET_MANAGER_ADDRESS = "0xDeD50DA9C3492Bee44560a4B35cFe0e778F41eC5";
157
// Number of lots to reserve
168
const LOTS_TO_MINT = 1;
17-
// XRP Ledger address
18-
const UNDERLYING_ADDRESS = "rSHYuiEvsYsKR8uUHhBTuGP5zjRcGt4nm";
199

2010
// Executor address
2111
const EXECUTOR_ADDRESS = "0xb292348a4Cb9f5F008589B3596405FBba6986c55";
2212

23-
// 2. Function to find the best agent with enough free collateral lots
13+
// 2. Get the AssetManager artifact
14+
const AssetManager = artifacts.require("IAssetManager");
15+
16+
// 3. Function to find the best agent with enough free collateral lots
2417

2518
// Function from FAssets Bot repository
2619
// https://github.com/flare-foundation/fasset-bots/blob/main/packages/fasset-bots-core/src/commands/InfoBotCommands.ts#L83
@@ -72,107 +65,95 @@ async function findBestAgent(
7265
}
7366
}
7467

75-
// 3. Function to parse the CollateralReserved event
76-
77-
async function parseCollateralReservedEvent(transactionReceipt) {
68+
// 4. Function to parse the CollateralReserved event
69+
async function parseCollateralReservedEvent(
70+
transactionReceipt: any,
71+
decimals: number,
72+
) {
7873
console.log("\nParsing events...", transactionReceipt.rawLogs);
7974

80-
const assetManager = (await ethers.getContractAt(
81-
"IAssetManager",
82-
ASSET_MANAGER_ADDRESS,
83-
)) as IAssetManagerContract;
84-
85-
for (const log of transactionReceipt.rawLogs) {
86-
try {
87-
const parsedLog = assetManager.interface.parseLog({
88-
topics: log.topics,
89-
data: log.data,
90-
});
91-
92-
if (!parsedLog) continue;
93-
94-
const collateralReservedEvents = ["CollateralReserved"];
95-
if (!collateralReservedEvents.includes(parsedLog.name)) continue;
96-
97-
console.log(`\nEvent: ${parsedLog.name}`);
98-
console.log("Arguments:", parsedLog.args);
99-
const collateralReservedEvent = parsedLog.args;
75+
// The logEvents function is included in the Flare starter kit
76+
const collateralReservedEvents = logEvents(
77+
transactionReceipt.rawLogs,
78+
"CollateralReserved",
79+
AssetManager.abi,
80+
);
10081

101-
return collateralReservedEvent;
102-
} catch (e) {
103-
console.log("Error parsing event:", e);
104-
}
105-
}
82+
return collateralReservedEvents[0].decoded;
10683
}
10784

108-
// 4. Main function
109-
85+
// 5. Main function
11086
async function main() {
111-
const assetManager: IAssetManagerInstance = await AssetManager.at(
112-
ASSET_MANAGER_ADDRESS,
113-
);
87+
// 6. Get the AssetManager contract from the Flare Contract Registry
88+
const assetManager: IAssetManagerInstance = await getAssetManagerFXRP();
11489

115-
// 5. Find the best agent with enough free collateral lots
90+
// 7. Find the best agent with enough free collateral lots
11691
const agentVaultAddress = await findBestAgent(assetManager, LOTS_TO_MINT);
11792
if (!agentVaultAddress) {
11893
throw new Error("No suitable agent found with enough free collateral lots");
11994
}
12095
console.log(agentVaultAddress);
12196

122-
// 6. Get the agent info
97+
// 8. Get the agent info
12398
const agentInfo = await assetManager.getAgentInfo(agentVaultAddress);
12499
console.log("Agent info:", agentInfo);
125100

126-
// 7. Get the collateral reservation fee according to the number of lots to reserve
101+
// 9. Get the collateral reservation fee according to the number of lots to reserve
127102
// https://dev.flare.network/fassets/minting/#collateral-reservation-fee
128103
const collateralReservationFee =
129104
await assetManager.collateralReservationFee(LOTS_TO_MINT);
130105
console.log(
131106
"Collateral reservation fee:",
132107
collateralReservationFee.toString(),
133108
);
134-
const assetManager: IAssetManagerInstance = await AssetManager.at(
135-
ASSET_MANAGER_ADDRESS,
136-
);
137109

138-
// 8. To make this example simpler we're using the same fee for the executor and the agent
110+
// 10. To make this example simpler we're using the same fee for the executor and the agent
139111
const executorFee = collateralReservationFee;
140112
const totalFee = collateralReservationFee.add(executorFee);
141113

142114
console.log("Total reservation fee:", totalFee.toString());
143115

144-
// 9. Reserve collateral
116+
console.log("agentVaultAddress", agentVaultAddress);
117+
console.log("LOTS_TO_MINT", LOTS_TO_MINT);
118+
console.log("agentInfo.feeBIPS", agentInfo.feeBIPS);
119+
console.log("EXECUTOR_ADDRESS", EXECUTOR_ADDRESS);
120+
121+
console.log("collateralReservationFee", collateralReservationFee);
122+
123+
// 11. Reserve collateral
145124
// https://dev.flare.network/fassets/reference/IAssetManager#reservecollateral
146125
const tx = await assetManager.reserveCollateral(
147126
agentVaultAddress,
148127
LOTS_TO_MINT,
149128
agentInfo.feeBIPS,
150129
// Not using the executor
151130
EXECUTOR_ADDRESS,
152-
[UNDERLYING_ADDRESS],
153131
// Sending the collateral reservation fee as native tokens
154132
{ value: totalFee },
155133
);
156134

157135
console.log("Collateral reservation successful:", tx);
158136

159-
// 10. Get the asset decimals
137+
// 112 Get the asset decimals
160138
const decimals = await assetManager.assetMintingDecimals();
161139

162-
// 11. Parse the CollateralReserved event
140+
// 13. Parse the CollateralReserved event
163141
const collateralReservedEvent = await parseCollateralReservedEvent(
164142
tx.receipt,
143+
decimals,
165144
);
166145

146+
// 14. Get the collateral reservation info
167147
const collateralReservationInfo =
168148
await assetManager.collateralReservationInfo(
169149
collateralReservedEvent.collateralReservationId,
170150
);
171151
console.log("Collateral reservation info:", collateralReservationInfo);
172152

173-
// 11. Calculate the total amount of XRP to pay
174-
const totalUBA =
175-
collateralReservedEvent.valueUBA + collateralReservedEvent.feeUBA;
153+
// 14. Calculate the total XRP value required for payment
154+
const valueUBA = BigInt(collateralReservedEvent.valueUBA.toString());
155+
const feeUBA = BigInt(collateralReservedEvent.feeUBA.toString());
156+
const totalUBA = valueUBA + feeUBA;
176157
const totalXRP = Number(totalUBA) / 10 ** decimals;
177158
console.log(`You need to pay ${totalXRP} XRP`);
178159
}

0 commit comments

Comments
 (0)