Skip to content

Commit 1a87a46

Browse files
committed
refactor(docs): clean up whitespace and improve formatting in FAssets documentation and TypeScript examples
1 parent 05268d9 commit 1a87a46

File tree

9 files changed

+155
-131
lines changed

9 files changed

+155
-131
lines changed

docs/fassets/developer-guides/1-fassets-get-asset-amanager-address-registry.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@ To continue your FAssets development journey, you can:
4242
- Learn how to [mint FXRP](/fassets/developer-guides/fassets-mint).
4343
- Understand how to [redeem FXRP](/fassets/developer-guides/fassets-redeem).
4444
- Explore [FAssets system settings](/fassets/operational-parameters).
45-

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ To get the FAsset lot size, you can use the following smart contract:
4141
2. Import the interface `IAssetManager` from the [Flare Periphery Contracts package](https://www.npmjs.com/package/@flarenetwork/flare-periphery-contracts), which provides access to the FAssets system.
4242
3. Create a contract called `FAssetsSettings` that will be used to fetch the FAssets settings from the asset manager.
4343
4. The `getLotSize` function gets numbers from the FAssets FXRP asset manager settings.
44-
Using the [`getSettings`](/fassets/reference/IAssetManager#getsettings) function returns the complete asset manager settings that you can find in the [FAssets Operational Parameters](/fassets/operational-parameters/#asset-manager-operational-parameters) documentation:
44+
Using the [`getSettings`](/fassets/reference/IAssetManager#getsettings) function returns the complete asset manager settings that you can find in the [FAssets Operational Parameters](/fassets/operational-parameters/#asset-manager-operational-parameters) documentation:
4545
- `lotSizeAMG`: The smallest amount you can trade (in AMG units).
4646
- `assetDecimals`: How many decimal places the FAssets asset uses.
4747
5. The `getLotSize` function returns two values:
@@ -64,23 +64,23 @@ Use the following TypeScript script to deploy the contract and fetch the FAsset
6464
const FAssetsSettings = artifacts.require("FAssetsSettings");
6565

6666
async function main() {
67-
// 2. Deploy the contract
68-
const fAssetsSettings = await FAssetsSettings.new();
69-
console.log("FAssetsSettings deployed to:", fAssetsSettings.address);
70-
71-
// 3. Call getSettings function
72-
const lotSize = await fAssetsSettings.getLotSize();
73-
console.log("Lot size:", lotSize[0]);
74-
console.log("Decimals:", lotSize[1]);
75-
76-
// 4. Convert lot size to XRP
77-
const lotSizeFXRP = Number(lotSize[0]) / Math.pow(10, Number(lotSize[1]));
78-
console.log("Lot size in XRP", lotSizeFXRP);
67+
// 2. Deploy the contract
68+
const fAssetsSettings = await FAssetsSettings.new();
69+
console.log("FAssetsSettings deployed to:", fAssetsSettings.address);
70+
71+
// 3. Call getSettings function
72+
const lotSize = await fAssetsSettings.getLotSize();
73+
console.log("Lot size:", lotSize[0]);
74+
console.log("Decimals:", lotSize[1]);
75+
76+
// 4. Convert lot size to XRP
77+
const lotSizeFXRP = Number(lotSize[0]) / Math.pow(10, Number(lotSize[1]));
78+
console.log("Lot size in XRP", lotSizeFXRP);
7979
}
8080

81-
main().catch(error => {
82-
console.error(error);
83-
process.exitCode = 1;
81+
main().catch((error) => {
82+
console.error(error);
83+
process.exitCode = 1;
8484
});
8585
```
8686

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ The following code demonstrates how to reserve collateral by calling the [`reser
7070
9. Calculate the collateral reservation fee by calling [`collateralReservationFee`](/fassets/reference/IAssetManager#collateralreservationfee).
7171
10. Set the executor fee the same as the collateral reservation fee to make this example simpler.
7272
11. Reserve collateral from agent by calling [`reserveCollateral`](/fassets/reference/IAssetManager#reservecollateral) with the executor address.
73-
The executor fee is on top of the collateral reservation fee in native tokens.
74-
The fee is agreed between the minter and the executor.
73+
The executor fee is on top of the collateral reservation fee in native tokens.
74+
The fee is agreed between the minter and the executor.
7575
12. Call `assetMintingDecimals` to determine the XRP token's decimal precision.
7676
13. Parse the [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event to get the collateral reservation ID and other important collateral reservation details.
7777
14. Calculate the total XRP value required for payment.

docs/fassets/developer-guides/7-fassets-redeem.mdx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,23 @@ You can find this function in the [Flare Hardhat Starter Kit](/network/guides/ha
175175
In this guide, we are not focusing on the event parsing.
176176
:::
177177

178-
### Output the Redemption Result
178+
### Output the Redemption Result
179179

180180
The following function is used to output the redemption request information.
181181

182182
```typescript
183-
async function printRedemptionRequestInfo(fAssetsRedeem: any, redemptionRequestedEvents: any[]) {
184-
console.log("\n=== Redemption Request Information ===");
185-
186-
for (const event of redemptionRequestedEvents) {
187-
const redemptionRequestInfo = await fAssetsRedeem
188-
.getRedemptionRequestInfo(event.decoded.requestId);
189-
console.log("Redemption request info:", redemptionRequestInfo);
190-
}
183+
async function printRedemptionRequestInfo(
184+
fAssetsRedeem: any,
185+
redemptionRequestedEvents: any[],
186+
) {
187+
console.log("\n=== Redemption Request Information ===");
188+
189+
for (const event of redemptionRequestedEvents) {
190+
const redemptionRequestInfo = await fAssetsRedeem.getRedemptionRequestInfo(
191+
event.decoded.requestId,
192+
);
193+
console.log("Redemption request info:", redemptionRequestInfo);
194+
}
191195
}
192196
```
193197

docs/fassets/developer-guides/8-fassets-swap-redeem.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,22 @@ It initializes the token as the first token in the swap path.
6666
The `swapAndRedeem` is the core function that executes the swap and redemption flow.
6767

6868
- **1. Validation**
69+
6970
- Ensure the caller has sufficient WCFLR balance.
7071
- Confirm the contract has enough FXRP allowance for redemption.
7172

7273
- **2. Transfer**
74+
7375
- Move WCFLR from the caller to the contract.
7476
- Approve the router to spend WCFLR on behalf of the contract.
7577

7678
- **3. Swap**
79+
7780
- Perform the swap from WCFLR to FXRP using the specified swap path.
7881
- Apply a 10-minute deadline for the swap operation.
7982

8083
- **4. Redemption**
84+
8185
- Redeem the obtained FXRP through the FAssets system.
8286
- Transfer the resulting XRP to the caller's XRPL address.
8387

@@ -105,18 +109,22 @@ To execute the swap and redeem process, you need to deploy the smart contract in
105109
### Code Breakdown
106110

107111
- **1. Dependencies and Constants**
112+
108113
- `LOTS_TO_REDEEM`: The number of FAsset lots to redeem (typically set to 1).
109114
- `UNDERLYING_ADDRESS`: The XRPL address that will receive the redeemed assets.
110115
- `SWAP_ROUTER_ADDRESS`: The address of the Uniswap V2-compatible swap router.
111116
- `WC2FLR`: Wrapped CFLR token address.
112117

113118
- **2. Deploy and Verify**
119+
114120
- Deploys the `SwapAndRedeem` contract and verifies it using [Flare Hardhat Starter Kit](/network/guides/hardhat-foundry-starter-kit).
115121

116122
- **3. Calculate Redemption Amounts**
123+
117124
- Calls `calculateRedemptionAmountIn` to determine the required WCFLR amount.
118125

119126
- **4. Approve Tokens**
127+
120128
- Uses the ERC-20 `approve` method to allow the contract to spend WCFLR.
121129
:::warning
122130
In a production environment, you should use a secure method to approve spending the tokens.

examples/developer-hub-javascript/fassetsExecuteMinting.ts

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { logEvents } from "../../scripts/utils/core";
66
// yarn hardhat run scripts/fassets/executeMinting.ts --network coston2
77

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

1112
// 2. Collateral reservation ID
1213
const COLLATERAL_RESERVATION_ID = 10255417;
@@ -20,80 +21,88 @@ const sourceIdBase = "testXRP";
2021
const verifierUrlBase = VERIFIER_URL_TESTNET;
2122
const urlTypeBase = "xrp";
2223

23-
const transactionId = "EC0FC5F40FBE6AEAD31138898C71687B2902E462FD1BFEF3FB443BE5E2C018F9";
24+
const transactionId =
25+
"EC0FC5F40FBE6AEAD31138898C71687B2902E462FD1BFEF3FB443BE5E2C018F9";
2426
const inUtxo = "0";
2527
const utxo = "0";
2628

2729
// 5. AssetManager contract
2830
const AssetManager = artifacts.require("IAssetManager");
2931

3032
// 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-
);
33+
async function prepareFdcRequest(
34+
transactionId: string,
35+
inUtxo: string,
36+
utxo: string,
37+
) {
38+
const requestBody = {
39+
transactionId: transactionId,
40+
inUtxo: inUtxo,
41+
utxo: utxo,
42+
};
43+
44+
const url = `${verifierUrlBase}verifier/${urlTypeBase}/Payment/prepareRequest`;
45+
46+
return await prepareAttestationRequestBase(
47+
url,
48+
VERIFIER_API_KEY_TESTNET,
49+
attestationTypeBase,
50+
sourceIdBase,
51+
requestBody,
52+
);
4753
}
4854

4955
// 7. Get proof from FDC
5056
async function getProof(roundId: number) {
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();
57+
const request = await prepareFdcRequest(transactionId, inUtxo, utxo);
58+
const proofAndData = await fetch(
59+
`${COSTON2_DA_LAYER_URL}api/v0/fdc/get-proof-round-id-bytes`,
60+
{
61+
method: "POST",
62+
headers: {
63+
"Content-Type": "application/json",
64+
"X-API-KEY": VERIFIER_API_KEY_TESTNET,
65+
},
66+
body: JSON.stringify({
67+
votingRoundId: roundId,
68+
requestBytes: request.abiEncodedRequest,
69+
}),
70+
},
71+
);
72+
73+
return await proofAndData.json();
6574
}
6675

6776
// 8. Parse events
6877
async function parseEvents(receipt: any) {
69-
console.log("\nParsing events...", receipt.rawLogs);
78+
console.log("\nParsing events...", receipt.rawLogs);
7079

71-
logEvents(receipt.rawLogs, "RedemptionTicketCreated", AssetManager.abi);
80+
logEvents(receipt.rawLogs, "RedemptionTicketCreated", AssetManager.abi);
7281

73-
logEvents(receipt.rawLogs, "MintingExecuted", AssetManager.abi);
82+
logEvents(receipt.rawLogs, "MintingExecuted", AssetManager.abi);
7483
}
7584

7685
async function main() {
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);
86+
// 9. Get proof from FDC
87+
const proof = await getProof(TARGET_ROUND_ID);
88+
89+
const assetManager: IAssetManagerInstance = await getFXRPAssetManager();
90+
91+
// 10. Execute minting
92+
const tx = await assetManager.executeMinting(
93+
{
94+
merkleProof: proof.proof,
95+
data: proof.response,
96+
},
97+
COLLATERAL_RESERVATION_ID,
98+
);
99+
console.log("Transaction successful:", tx);
100+
101+
// 11. Parse execute minting log events
102+
await parseEvents(tx.receipt);
94103
}
95104

96-
main().catch(error => {
97-
console.error(error);
98-
process.exitCode = 1;
105+
main().catch((error) => {
106+
console.error(error);
107+
process.exitCode = 1;
99108
});

examples/developer-hub-javascript/fassetsSwapAndRedeem.ts

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,59 @@ const SwapAndRedeem = artifacts.require("SwapAndRedeem");
1919

2020
// 2. Deploy and verify the `SwapAndRedeem` smart contract
2121
async function deployAndVerifyContract() {
22-
const assetManager = await getAssetManagerFXRP();
23-
const fassetAddress = await assetManager.fAsset();
24-
const swapPath = [WC2FLR, fassetAddress];
22+
const assetManager = await getAssetManagerFXRP();
23+
const fassetAddress = await assetManager.fAsset();
24+
const swapPath = [WC2FLR, fassetAddress];
2525

26-
const args = [SWAP_ROUTER_ADDRESS, swapPath];
27-
const swapAndRedeem: SwapAndRedeemInstance = await SwapAndRedeem.new(...args);
26+
const args = [SWAP_ROUTER_ADDRESS, swapPath];
27+
const swapAndRedeem: SwapAndRedeemInstance = await SwapAndRedeem.new(...args);
2828

29-
const fassetsSwapAndRedeemAddress = await swapAndRedeem.address;
29+
const fassetsSwapAndRedeemAddress = await swapAndRedeem.address;
3030

31-
try {
32-
await run("verify:verify", {
33-
address: fassetsSwapAndRedeemAddress,
34-
constructorArguments: args,
35-
});
36-
} catch (e: any) {
37-
console.log(e);
38-
}
31+
try {
32+
await run("verify:verify", {
33+
address: fassetsSwapAndRedeemAddress,
34+
constructorArguments: args,
35+
});
36+
} catch (e: any) {
37+
console.log(e);
38+
}
3939

40-
console.log("FAssetsSwapAndRedeem deployed to:", fassetsSwapAndRedeemAddress);
40+
console.log("FAssetsSwapAndRedeem deployed to:", fassetsSwapAndRedeemAddress);
4141

42-
return swapAndRedeem;
42+
return swapAndRedeem;
4343
}
4444

4545
async function main() {
46-
// 2. Deploy and verify the `SwapAndRedeem` smart contract
47-
const swapAndRedeem: SwapAndRedeemInstance = await deployAndVerifyContract();
48-
49-
// 3. Calculate Required Amounts
50-
const swapAndRedeemAddress = await swapAndRedeem.address;
51-
const amounts = await swapAndRedeem.calculateRedemptionAmountIn(LOTS_TO_REDEEM);
52-
const amountIn = amounts.amountIn;
53-
const amountOut = amounts.amountOut;
54-
console.log("Amount of tokens out (FXRP): ", amountOut.toString());
55-
console.log("Amount of tokens in (WCFLR): ", amountIn.toString());
56-
57-
// 4. Approve spending WCFLR tokens
58-
// Get WCFLR token
59-
const ERC20 = artifacts.require("ERC20");
60-
const wcflr: ERC20Instance = await ERC20.at(WC2FLR);
61-
62-
const approveTx = await wcflr.approve(swapAndRedeemAddress, amountOut);
63-
console.log("Approve transaction: ", approveTx);
64-
65-
// 5. Swap WCFLR for FXRP and redeem to underlying XRP token on XRP Ledger
66-
const swapResult = await swapAndRedeem.swapAndRedeem(LOTS_TO_REDEEM, UNDERLYING_ADDRESS);
67-
console.log("Swap and redeem transaction: ", swapResult);
46+
// 2. Deploy and verify the `SwapAndRedeem` smart contract
47+
const swapAndRedeem: SwapAndRedeemInstance = await deployAndVerifyContract();
48+
49+
// 3. Calculate Required Amounts
50+
const swapAndRedeemAddress = await swapAndRedeem.address;
51+
const amounts =
52+
await swapAndRedeem.calculateRedemptionAmountIn(LOTS_TO_REDEEM);
53+
const amountIn = amounts.amountIn;
54+
const amountOut = amounts.amountOut;
55+
console.log("Amount of tokens out (FXRP): ", amountOut.toString());
56+
console.log("Amount of tokens in (WCFLR): ", amountIn.toString());
57+
58+
// 4. Approve spending WCFLR tokens
59+
// Get WCFLR token
60+
const ERC20 = artifacts.require("ERC20");
61+
const wcflr: ERC20Instance = await ERC20.at(WC2FLR);
62+
63+
const approveTx = await wcflr.approve(swapAndRedeemAddress, amountOut);
64+
console.log("Approve transaction: ", approveTx);
65+
66+
// 5. Swap WCFLR for FXRP and redeem to underlying XRP token on XRP Ledger
67+
const swapResult = await swapAndRedeem.swapAndRedeem(
68+
LOTS_TO_REDEEM,
69+
UNDERLYING_ADDRESS,
70+
);
71+
console.log("Swap and redeem transaction: ", swapResult);
6872
}
6973

70-
main().catch(error => {
71-
console.error(error);
72-
process.exitCode = 1;
74+
main().catch((error) => {
75+
console.error(error);
76+
process.exitCode = 1;
7377
});

0 commit comments

Comments
 (0)