Skip to content

Commit 4ea653e

Browse files
committed
refactor(docs): enhance FAssets minting guide and update TypeScript scripts for clarity and consistency
1 parent d20a30d commit 4ea653e

File tree

3 files changed

+86
-122
lines changed

3 files changed

+86
-122
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,17 @@ This script demonstrates how to retrieve the FDC proof and execute minting.
100100
### Execute Minting Script Breakdown
101101

102102
1. Get environment variables.
103-
2. Declare the constant `ASSET_MANAGER_ADDRESS` pointing to the FXRP AssetManager on the Songbird Testnet (Coston network).
104-
105-
3. Set the collateral reservation ID to the previously reserved minting request.
106-
4. Set the Flare Data Connector (FDC) round ID to retrieve the proof.
107-
5. Prepare the FDC request payload data.
108-
6. Create a function to get the proof from the FDC.
103+
2. Set the collateral reservation ID to the previously reserved minting request.
104+
3. Set the FDC round ID to retrieve the proof.
105+
4. Provide the FDC request data.
106+
5. Asset manager contract artifact.
107+
6. Define the function to prepare the FDC request.
108+
7. Create a function to get the proof from the FDC.
109109
It sends a POST request to the [Flare Data Availability Layer](/fdc/overview#data-availability-layer) and returns a Merkle proof and attestation response from FDC.
110-
7. Retrieve the FDC proof from the Data Availability Layer.
111-
8. Call the [`executeMinting`](/fassets/reference/IAssetManager#executeminting) function on the AssetManager contract and send a transaction to the Flare network to convert the attested XRP payment into FXRP (minting).
112-
9. On a successful transaction call `parseExecutemintingEvents` to extract and log events [`RedemptionTicketCreated`](/fassets/reference/IAssetManagerEvents#redemptionticketcreated) and [`MintingExecuted`](/fassets/reference/IAssetManagerEvents#mintingexecuted).
110+
8. Define the function to parse the events.
111+
9. Retrieve the FDC proof from the Data Availability Layer.
112+
10. Call the [`executeMinting`](/fassets/reference/IAssetManager#executeminting) function on the AssetManager contract and send a transaction to the Flare network to convert the attested XRP payment into FXRP (minting).
113+
11. On a successful transaction call `parseExecutemintingEvents` to extract and log events [`RedemptionTicketCreated`](/fassets/reference/IAssetManagerEvents#redemptionticketcreated) and [`MintingExecuted`](/fassets/reference/IAssetManagerEvents#mintingexecuted).
113114

114115
## Next Steps
115116

Lines changed: 74 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,99 @@
1-
import { artifacts, ethers } from "hardhat";
1+
import { getFXRPAssetManager } from "../utils/fassets";
2+
import { prepareAttestationRequestBase } from "../utils/fdc";
3+
import { IAssetManagerInstance } from "../../typechain-types";
4+
import { logEvents } from "../../scripts/utils/core";
25

3-
import { prepareAttestationRequestBase } from "../fdcExample/Base";
4-
import {
5-
IAssetManagerInstance,
6-
IAssetManagerContract,
7-
} from "../../typechain-types";
6+
// yarn hardhat run scripts/fassets/executeMinting.ts --network coston2
87

98
// 1. Environment variables
10-
const { COSTON2_DA_LAYER_URL, VERIFIER_URL_TESTNET, VERIFIER_API_KEY_TESTNET } =
11-
process.env;
9+
const { COSTON2_DA_LAYER_URL, VERIFIER_URL_TESTNET, VERIFIER_API_KEY_TESTNET } = process.env;
1210

13-
// 2. AssetManager address on Flare Testnet Coston2 network
14-
const ASSET_MANAGER_ADDRESS = "0xDeD50DA9C3492Bee44560a4B35cFe0e778F41eC5";
11+
// 2. Collateral reservation ID
12+
const COLLATERAL_RESERVATION_ID = 10255417;
1513

16-
// 3. Collateral reservation ID
17-
const COLLATERAL_RESERVATION_ID = 18615047;
18-
19-
// 4. Data to get the proof for
20-
const TARGET_ROUND_ID = 987510;
14+
// 3. FDC round id to get the proof for
15+
const TARGET_ROUND_ID = 1053806;
2116

17+
// 4. FDC request data
2218
const attestationTypeBase = "Payment";
2319
const sourceIdBase = "testXRP";
2420
const verifierUrlBase = VERIFIER_URL_TESTNET;
2521
const urlTypeBase = "xrp";
2622

27-
// XRP transaction
28-
const transactionId =
29-
"65520665BB83D582E01D6813DA8B5ECB041F613F9891F9BE90EE2668AAC30543";
23+
const transactionId = "EC0FC5F40FBE6AEAD31138898C71687B2902E462FD1BFEF3FB443BE5E2C018F9";
3024
const inUtxo = "0";
3125
const utxo = "0";
3226

33-
// 5. Prepare FDC request
34-
async function prepareFdcRequest(
35-
transactionId: string,
36-
inUtxo: string,
37-
utxo: string,
38-
) {
39-
const requestBody = {
40-
transactionId: transactionId,
41-
inUtxo: inUtxo,
42-
utxo: utxo,
43-
};
44-
45-
const url = `${verifierUrlBase}verifier/${urlTypeBase}/Payment/prepareRequest`;
46-
47-
return await prepareAttestationRequestBase(
48-
url,
49-
VERIFIER_API_KEY_TESTNET,
50-
attestationTypeBase,
51-
sourceIdBase,
52-
requestBody,
53-
);
27+
// 5. AssetManager contract
28+
const AssetManager = artifacts.require("IAssetManager");
29+
30+
// 6. Prepare FDC request
31+
async function prepareFdcRequest(transactionId: string, inUtxo: string, utxo: string) {
32+
const requestBody = {
33+
transactionId: transactionId,
34+
inUtxo: inUtxo,
35+
utxo: utxo,
36+
};
37+
38+
const url = `${verifierUrlBase}verifier/${urlTypeBase}/Payment/prepareRequest`;
39+
40+
return await prepareAttestationRequestBase(
41+
url,
42+
VERIFIER_API_KEY_TESTNET,
43+
attestationTypeBase,
44+
sourceIdBase,
45+
requestBody
46+
);
5447
}
5548

56-
// 6. Get proof from FDC
49+
// 7. Get proof from FDC
5750
async function getProof(roundId: number) {
58-
const request = await prepareFdcRequest(transactionId, inUtxo, utxo);
59-
const proofAndData = await fetch(
60-
`${COSTON2_DA_LAYER_URL}api/v0/fdc/get-proof-round-id-bytes`,
61-
{
62-
method: "POST",
63-
headers: {
64-
"Content-Type": "application/json",
65-
"X-API-KEY": VERIFIER_API_KEY_TESTNET,
66-
},
67-
body: JSON.stringify({
68-
votingRoundId: roundId,
69-
requestBytes: request.abiEncodedRequest,
70-
}),
71-
},
72-
);
73-
74-
return await proofAndData.json();
51+
const request = await prepareFdcRequest(transactionId, inUtxo, utxo);
52+
const proofAndData = await fetch(`${COSTON2_DA_LAYER_URL}api/v0/fdc/get-proof-round-id-bytes`, {
53+
method: "POST",
54+
headers: {
55+
"Content-Type": "application/json",
56+
"X-API-KEY": VERIFIER_API_KEY_TESTNET,
57+
},
58+
body: JSON.stringify({
59+
votingRoundId: roundId,
60+
requestBytes: request.abiEncodedRequest,
61+
}),
62+
});
63+
64+
return await proofAndData.json();
7565
}
7666

77-
async function parseEvents(receipt) {
78-
console.log("\nParsing events...", receipt.rawLogs);
79-
80-
const assetManager = (await ethers.getContractAt(
81-
"IAssetManager",
82-
ASSET_MANAGER_ADDRESS,
83-
)) as IAssetManagerContract;
84-
85-
for (const log of receipt.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 = [
95-
"RedemptionTicketCreated",
96-
"MintingExecuted",
97-
];
98-
if (!collateralReservedEvents.includes(parsedLog.name)) continue;
99-
100-
console.log(`\nEvent: ${parsedLog.name}`);
101-
console.log("Arguments:", parsedLog.args);
102-
} catch (e) {
103-
console.log("Error parsing event:", e);
104-
}
105-
}
67+
// 8. Parse events
68+
async function parseEvents(receipt: any) {
69+
console.log("\nParsing events...", receipt.rawLogs);
70+
71+
logEvents(receipt.rawLogs, "RedemptionTicketCreated", AssetManager.abi);
72+
73+
logEvents(receipt.rawLogs, "MintingExecuted", AssetManager.abi);
10674
}
10775

10876
async function main() {
109-
// 7. Get proof from FDC
110-
const proof = await getProof(TARGET_ROUND_ID);
111-
112-
// FAssets FXRP asset manager on Songbird Testnet Coston2 network
113-
const AssetManager = artifacts.require("IAssetManager");
114-
const assetManager: IAssetManagerInstance = await AssetManager.at(
115-
ASSET_MANAGER_ADDRESS,
116-
);
117-
118-
// 8. Execute minting with the proof
119-
const tx = await assetManager.executeMinting(
120-
{
121-
merkleProof: proof.proof,
122-
data: proof.response,
123-
},
124-
COLLATERAL_RESERVATION_ID,
125-
);
126-
console.log("Transaction successful:", tx);
127-
128-
// 9. Parse execute minting log events
129-
await parseEvents(tx.receipt);
77+
// 9. Get proof from FDC
78+
const proof = await getProof(TARGET_ROUND_ID);
79+
80+
const assetManager: IAssetManagerInstance = await getFXRPAssetManager();
81+
82+
// 10. Execute minting
83+
const tx = await assetManager.executeMinting(
84+
{
85+
merkleProof: proof.proof,
86+
data: proof.response,
87+
},
88+
COLLATERAL_RESERVATION_ID
89+
);
90+
console.log("Transaction successful:", tx);
91+
92+
// 11. Parse execute minting log events
93+
await parseEvents(tx.receipt);
13094
}
13195

132-
main().catch((error) => {
133-
console.error(error);
134-
process.exitCode = 1;
96+
main().catch(error => {
97+
console.error(error);
98+
process.exitCode = 1;
13599
});

examples/developer-hub-javascript/fassetsReserveCollateral.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getFXRPAssetManagerAddress } from "../utils/fassets";
1+
import { getFXRPAssetManager } from "../utils/fassets";
22
import { IAssetManagerInstance } from "../../typechain-types";
33
import { logEvents } from "../../scripts/utils/core";
44

@@ -83,8 +83,7 @@ async function parseCollateralReservedEvent(
8383

8484
async function main() {
8585
// 6. Get the AssetManager contract from the Flare Contract Registry
86-
const assetManager: IAssetManagerInstance =
87-
await getFXRPAssetManagerAddress();
86+
const assetManager: IAssetManagerInstance = await getAssetManagerFXRP();
8887

8988
// 7. Find the best agent with enough free collateral lots
9089
const agentVaultAddress = await findBestAgent(assetManager, LOTS_TO_MINT);

0 commit comments

Comments
 (0)