Skip to content

Commit 2e6ebd4

Browse files
authored
Merge branch 'main' into docusaurus-v4
2 parents b913591 + 5c2057e commit 2e6ebd4

19 files changed

+1029
-116
lines changed

.github/workflows/test-rust-examples.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@ jobs:
1414
working-directory: ./examples/developer-hub-rust
1515
steps:
1616
- uses: actions/checkout@v4
17-
- name: Install dependencies
18-
run: cargo build
17+
18+
- name: Install Rust toolchain
19+
uses: dtolnay/rust-toolchain@stable
20+
with:
21+
components: rustfmt, clippy
22+
23+
- name: Cache dependencies
24+
uses: Swatinem/rust-cache@v2
25+
1926
- name: Format with rustfmt
2027
run: cargo fmt -- --check
28+
2129
- name: Lint with clippy
2230
run: cargo clippy -- -D warnings
31+
2332
- name: Run tests
2433
run: ./test.sh

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

Lines changed: 71 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ In this guide, you will learn how to redeem FAssets using the Asset Manager smar
1818

1919
<RedemptionProcessPrerequisites />
2020

21-
## Prerequisites
22-
23-
- [Flare Hardhat Starter Kit](/network/guides/hardhat-foundry-starter-kit)
24-
- [Flare Network Periphery Contracts](https://www.npmjs.com/package/@flarenetwork/flare-periphery-contracts)
25-
2621
## Redeem FAssets Smart Contract
2722

2823
The following example demonstrates how to redeem FAssets using the `AssetManager` smart contract.
@@ -37,8 +32,9 @@ The following example demonstrates how to redeem FAssets using the `AssetManager
3732
### Code Breakdown
3833

3934
1. Define the asset manager contract address to interact with it.
40-
2. Get the asset manager settings to calculate the redeemed amount; for that, you need to get the `lotSizeAMG` and `assetDecimals` from the asset manager [settings](/fassets/developer-guides/fassets-settings-solidity).
35+
2. Approve FAssets (FXRP) tokens for redemption.
4136
3. Redeem the FAssets using the [`redeem`](/fassets/reference/IAssetManager#redeem) function by specifying the number of lots to redeem and the underlying chain address.
37+
4. Retrieve the asset manager settings to calculate the redeemed amount; for this, you need to obtain the `lotSizeAMG` and `assetDecimals` from the asset manager settings [document](/fassets/developer-guides/fassets-settings-solidity).
4238

4339
:::info
4440
In this example, you are not using the executor vault address, but you can use it to redeem FAssets on behalf of another address.
@@ -55,7 +51,7 @@ Create a new file, for example, `scripts/fassets/redeem.ts` and add the followin
5551
At first, you need to import the required dependencies and smart contract TypeScript types:
5652

5753
```typescript
58-
import { ethers, run } from "hardhat";
54+
import { ethers, web3, run } from "hardhat";
5955
import { formatUnits } from "ethers";
6056

6157
import {
@@ -72,14 +68,27 @@ Define the constants:
7268
- `ASSET_MANAGER_ADDRESS` - asset manager address;
7369
- `LOTS_TO_REDEEM` - the number of lots to redeem;
7470
- `UNDERLYING_ADDRESS` - underlying chain address where the redeemed asset will be sent;
75-
- `FXRP_TOKEN_ADDRESS` - FXRP token address.
7671

7772
```typescript
78-
// AssetManager address on Songbird Testnet Coston network
79-
const ASSET_MANAGER_ADDRESS = "0x56728e46908fB6FcC5BCD2cc0c0F9BB91C3e4D34";
73+
// AssetManager address on Flare Testnet Coston2 network
74+
const ASSET_MANAGER_ADDRESS = "0xDeD50DA9C3492Bee44560a4B35cFe0e778F41eC5";
8075
const LOTS_TO_REDEEM = 1;
8176
const UNDERLYING_ADDRESS = "rSHYuiEvsYsKR8uUHhBTuGP5zjRcGt4nm";
82-
const FXRP_TOKEN_ADDRESS = "0x36be8f2e1CC3339Cf6702CEfA69626271C36E2fd";
77+
```
78+
79+
### Import Contract Artifacts
80+
81+
Import the contract artifacts to interact with the smart contracts:
82+
83+
- `FAssetsRedeem` - the `FAssetsRedeem` contract;
84+
- `IAssetManager` - the asset manager interface;
85+
- `IERC20` - the `IERC20` contract for FXRP token;
86+
87+
```typescript
88+
const FAssetsRedeem = artifacts.require("FAssetsRedeem");
89+
90+
const IAssetManager = artifacts.require("IAssetManager");
91+
const IERC20 = artifacts.require("IERC20");
8392
```
8493

8594
### Deploy and Verify the Redeem Contract
@@ -88,15 +97,18 @@ Deploy and verify the smart contract providing the asset manager address as a co
8897

8998
```typescript
9099
async function deployAndVerifyContract() {
91-
const FAssetsRedeem = artifacts.require("FAssetsRedeem");
92-
const args = [ASSET_MANAGER_ADDRESS];
100+
// Get FXRP address first
101+
const fxrpAddress = await getFXRPAddress();
102+
console.log("FXRP address:", fxrpAddress);
103+
104+
const args = [ASSET_MANAGER_ADDRESS, fxrpAddress];
93105
const fAssetsRedeem: FAssetsRedeemInstance = await FAssetsRedeem.new(...args);
94106

95107
const fAssetsRedeemAddress = await fAssetsRedeem.address;
96108

97109
try {
98110
await run("verify:verify", {
99-
address: fAssetsRedeemAddress,
111+
address: fAssetsRedeem.address,
100112
constructorArguments: args,
101113
});
102114
} catch (e: any) {
@@ -109,36 +121,31 @@ async function deployAndVerifyContract() {
109121
}
110122
```
111123

112-
### Transfer FXRP to the Redeem Contract
124+
### Approve the FXRP transfer to the Redeem Contract
113125

114-
To redeem FAssets, you must transfer a sufficient amount of FXRP to the `FAssetsRedeem` contract address after it is deployed, as it acts as the invoker during the redemption process.
126+
To redeem FAssets, you must approve a sufficient amount of transfer of FXRP to the `FAssetsRedeem` contract address after it is deployed, as it acts as the invoker during the redemption process.
115127

116128
```typescript
117-
async function transferFXRP(
118-
fAssetsRedeemAddress: string,
119-
amountToRedeem: number,
120-
) {
121-
// Get FXRP token contract
122-
const fxrp = (await ethers.getContractAt(
123-
"IERC20",
124-
FXRP_TOKEN_ADDRESS,
125-
)) as ERC20Instance;
126-
127-
// Transfer FXRP to the deployed contract
128-
console.log("Transferring FXRP to contract...");
129-
const transferTx = await fxrp.transfer(fAssetsRedeemAddress, amountToRedeem);
130-
await transferTx.wait();
131-
console.log("FXRP transfer completed");
129+
async function approveFAssets(fAssetsRedeem: any, amountToRedeem: string) {
130+
console.log("Approving FAssetsRedeem contract to spend FXRP...");
131+
const fxrpAddress = await getFXRPAddress();
132+
const fxrp: ERC20Instance = await IERC20.at(fxrpAddress);
133+
134+
const approveTx = await fxrp.approve(
135+
await fAssetsRedeem.address,
136+
amountToRedeem,
137+
);
138+
console.log("FXRP approval completed");
132139
}
133140
```
134141

135142
:::warning
136-
In a production environment, you should use a more secure method to transfer FXRP to a smart contract.
143+
In a production environment, it is recommended to use a more secure method for approving the transfer of FXRP to a smart contract.
137144
:::
138145

139146
### Parse the Redemption Events
140147

141-
During the redemption process, the `AssetManager` emits an events:
148+
During the redemption process, the `AssetManager` emits events:
142149

143150
- [`RedemptionRequested`](/fassets/reference/IAssetManagerEvents#redemptionrequested) - holds the agent vault address, redemption request id, the amount of FAssets to redeem, and other important information.
144151
- [`RedemptionTicketCreated`](/fassets/reference/IAssetManagerEvents#redemptionticketcreated) - holds the redemption ticket information updated during the redemption process.
@@ -148,7 +155,7 @@ To parse the redemption events, you can use the following function:
148155
```typescript
149156
async function parseRedemptionEvents(
150157
transactionReceipt: any,
151-
fAssetsRedeem: FAssetsRedeemInstance,
158+
fAssetsRedeem: any,
152159
) {
153160
console.log("\nParsing events...", transactionReceipt.rawLogs);
154161

@@ -185,12 +192,12 @@ async function parseRedemptionEvents(
185192

186193
### Redeeming FAssets
187194

188-
To put it all together you can use the following function to deploy the contract, transfer FXRP to it, redeem the FAssets, and parse the redemption events:
195+
To put it altogether you can use the following function to deploy the contract, transfer FXRP to it, redeem the FAssets, and parse the redemption events:
189196

190197
```typescript
191198
async function main() {
192199
// Deploy and verify the contract
193-
const fAssetsRedeem: FAssetsRedeemInstance = await deployAndVerifyContract();
200+
const fAssetsRedeem = await deployAndVerifyContract();
194201

195202
// Get the lot size and decimals to calculate the amount to redeem
196203
const settings = await fAssetsRedeem.getSettings();
@@ -200,21 +207,27 @@ async function main() {
200207
console.log("Asset decimals:", decimals.toString());
201208

202209
// Calculate the amount to redeem according to the lot size and the number of lots to redeem
203-
const amountToRedeem = Number(lotSize) * Number(LOTS_TO_REDEEM);
210+
const amountToRedeem = web3.utils
211+
.toBN(lotSize)
212+
.mul(web3.utils.toBN(LOTS_TO_REDEEM));
204213
console.log(
205-
`Required FXRP amount ${formatUnits(amountToRedeem, Number(decimals))} FXRP`,
214+
`Required FXRP amount ${formatUnits(amountToRedeem.toString(), Number(decimals))} FXRP`,
206215
);
207216
console.log(`Required amount in base units: ${amountToRedeem.toString()}`);
208217

209-
// Transfer FXRP to the contract
210-
await transferFXRP(fAssetsRedeem.address, amountToRedeem);
218+
// Approve FXRP for redemption
219+
await approveFAssets(fAssetsRedeem, amountToRedeem.toString());
211220

212221
// Call redeem function and wait for transaction
213-
const tx = await fAssetsRedeem.redeem(LOTS_TO_REDEEM, UNDERLYING_ADDRESS);
214-
console.log("TX receipt", tx.receipt);
222+
const redeemTx = await fAssetsRedeem.redeem(
223+
LOTS_TO_REDEEM,
224+
UNDERLYING_ADDRESS,
225+
);
226+
// const receipt = await tx.wait();
227+
console.log("Redeem transaction receipt", redeemTx);
215228

216-
// Parse events from the transaction
217-
await parseRedemptionEvents(tx.receipt, fAssetsRedeem);
229+
// // Parse events from the transaction
230+
await parseRedemptionEvents(redeemTx.receipt, fAssetsRedeem);
218231
}
219232

220233
main().catch((error) => {
@@ -228,7 +241,7 @@ main().catch((error) => {
228241
To run the script, use the [Flare Hardhat Starter Kit](/network/guides/hardhat-foundry-starter-kit) with the following command:
229242

230243
```bash
231-
npx hardhat run scripts/fassets/getLotSize.ts --network coston
244+
npx hardhat run scripts/fassets/getLotSize.ts --network coston2
232245
```
233246

234247
Once the script is executed, two events hold the important information:
@@ -257,18 +270,18 @@ Arguments: Result(12) [
257270

258271
When decoding an event, the most important data from the event is:
259272

260-
- agent vault address that will redeem the FAssets is `0x3c831Fe4417bEFFAc721d24996985eE2dd627053`;
261-
- redeemer address is `0xCA7C9fBbA56E44C508bcb4872775c5fEd169cDb3`;
262-
- redemption ticket id is `1898730`;
263-
- underlying chain address is `rSHYuiEvsYsKR8uUHhBTuGP5zjRcGt4nm`;
264-
- amount of FAssets to redeem is `20000000`;
265-
- redemption fee is `20000`;
273+
- The agent vault address that will redeem the FAssets is `0x3c831Fe4417bEFFAc721d24996985eE2dd627053`;
274+
- The redeemer address is `0xCA7C9fBbA56E44C508bcb4872775c5fEd169cDb3`;
275+
- The redemption ticket id is `1898730`;
276+
- The underlying chain address is `rSHYuiEvsYsKR8uUHhBTuGP5zjRcGt4nm`;
277+
- The amount of FAssets to redeem is `20000000`;
278+
- The redemption fee is `20000`;
266279

267-
You can see the full event description [here](/fassets/reference/IAssetManagerEvents#redemptionrequested) section.
280+
You can view the full event description [here](/fassets/reference/IAssetManagerEvents#redemptionrequested).
268281

269282
#### [`RedemptionTicketUpdated`](/fassets/reference/IAssetManagerEvents#redemptionticketupdated)
270283

271-
The event `RedemptionTicketUpdated` holds the redemption ticket information like agent vault address, redemption ticket ID and the value of the redemption ticket in underlying chain currency.
284+
The event `RedemptionTicketUpdated` contains the redemption ticket information, including the agent vault address, redemption ticket ID, and the value of the redemption ticket in the underlying chain currency.
272285

273286
For every minting, a redemption ticket is created, and during the redemption process, the redemption ticket is updated with the new redemption status.
274287

@@ -283,18 +296,18 @@ Arguments: Result(3) [
283296

284297
Once decoding the most important data from the event is:
285298

286-
- agent vault address that will redeem the FAssets is `0x3c831Fe4417bEFFAc721d24996985eE2dd627053`;
287-
- redemption ticket id is `870`;
288-
- value of the redemption ticket in underlying chain currency is `3440000000` (partially redeemed).
299+
- The agent vault address that will redeem the FAssets is `0x3c831Fe4417bEFFAc721d24996985eE2dd627053`;
300+
- The redemption ticket id is `870`;
301+
- The value of the redemption ticket in underlying chain currency is `3440000000` (partially redeemed).
289302

290303
You can read the full event description [here](/fassets/reference/IAssetManagerEvents#redemptionticketupdated).
291304

292305
### Agent Process
293306

294-
The FAssets agent should perform the redemption, and the user needs to get the redeemed assets from the agent.
307+
The FAssets agent should perform the redemption, and the user must retrieve the redeemed assets from the agent.
295308

296309
If the agent is unable to redeem the assets on the underlying chain in the specified time.
297-
In that case, the user can execute the [`redemptionPaymentDefault`](/fassets/reference/IAssetManager#redemptionpaymentdefault) function to receive compensation from agent's collateral.
310+
In that case, the user can execute the [`redemptionPaymentDefault`](/fassets/reference/IAssetManager#redemptionpaymentdefault) function to receive compensation from the agent's collateral.
298311

299312
If the agent rejects the redemption request and no other agent takes over the redemption, the redeemer or appointed executor calls [`rejectedRedemptionPaymentDefault`](/fassets/reference/IAssetManager#rejectedredemptionpaymentdefault) method and receives payment in collateral.
300313
The agent can also call default if the redeemer is unresponsive to payout the redeemer and free the remaining collateral.

docs/ftso/2-feeds.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,24 @@ The resulting string is then prefixed with `0x`.
4141

4242
## Custom Feeds
4343

44-
:::warning
44+
:::warning[Risk Profile]
4545

46-
Custom Feeds, introduced in [FIP.13](https://proposals.flare.network/FIP/FIP_13.html), have a distinct risk profile compared to standard FTSO feeds. Unlike standard FTSO feeds, the security of a Custom Feed is conditional on the logic defined in its smart contract.
46+
Each Custom Feed has a unique risk profile determined by its smart contract and data source, which users and developers must assess individually.
4747

4848
:::
4949

50+
Custom Feeds, introduced in [FIP.13](https://proposals.flare.network/FIP/FIP_13.html), extend the FTSO by enabling developers to create onchain feeds for arbitrary time-series data.
51+
Unlike standard FTSO feeds, which are secured by a decentralized network of data providers, Custom Feeds derive their values from logic defined in a developer-controlled smart contract.
52+
This expands the FTSO's capabilities beyond traditional price pairs, allowing for a wider variety of data to be brought onto the Flare network, such as prices for Liquid Staked Tokens (LSTs), data from specific offchain APIs, or other bespoke datasets.
53+
5054
<CustomFeeds />
5155

56+
:::tip[Create a new Custom Feed]
57+
58+
Follow the [create a Custom Feed](/ftso/guides/create-custom-feed) guide to learn how a build a new Custom Feed.
59+
60+
:::
61+
5262
## Need more feeds?
5363

5464
FTSOv2 can scale up to 1000 feeds. If you need additional FTSOv2 feeds beyond what is currently available, you can raise a New Feed Request Issue on GitHub. When a feed request is submitted, it is reviewed by the FTSO Management Group, which is comprised of the FTSO data providers as outlined in [FIP.08](https://proposals.flare.network/FIP/FIP_8.html#222-through-the-ftso-management-group).

0 commit comments

Comments
 (0)