You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/fassets/developer-guides/4-fassets-redeem.mdx
+71-53Lines changed: 71 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,8 +37,9 @@ The following example demonstrates how to redeem FAssets using the `AssetManager
37
37
### Code Breakdown
38
38
39
39
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).
40
+
2.Approve FAssets (FXRP) tokens for redemption.
41
41
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.
42
+
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).
42
43
43
44
:::info
44
45
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 +56,7 @@ Create a new file, for example, `scripts/fassets/redeem.ts` and add the followin
55
56
At first, you need to import the required dependencies and smart contract TypeScript types:
56
57
57
58
```typescript
58
-
import { ethers, run } from"hardhat";
59
+
import { ethers, web3, run } from"hardhat";
59
60
import { formatUnits } from"ethers";
60
61
61
62
import {
@@ -72,14 +73,27 @@ Define the constants:
72
73
-`ASSET_MANAGER_ADDRESS` - asset manager address;
73
74
-`LOTS_TO_REDEEM` - the number of lots to redeem;
74
75
-`UNDERLYING_ADDRESS` - underlying chain address where the redeemed asset will be sent;
75
-
-`FXRP_TOKEN_ADDRESS` - FXRP token address.
76
76
77
77
```typescript
78
-
// AssetManager address on Songbird Testnet Coston network
@@ -109,36 +126,31 @@ async function deployAndVerifyContract() {
109
126
}
110
127
```
111
128
112
-
### Transfer FXRP to the Redeem Contract
129
+
### Approve the FXRP transfer to the Redeem Contract
113
130
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.
131
+
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.
In a production environment, you should use a more secure method to transfer FXRP to a smart contract.
148
+
In a production environment, it is recommended to use a more secure method for approving the transfer of FXRP to a smart contract.
137
149
:::
138
150
139
151
### Parse the Redemption Events
140
152
141
-
During the redemption process, the `AssetManager` emits an events:
153
+
During the redemption process, the `AssetManager` emits events:
142
154
143
155
-[`RedemptionRequested`](/fassets/reference/IAssetManagerEvents#redemptionrequested) - holds the agent vault address, redemption request id, the amount of FAssets to redeem, and other important information.
144
156
-[`RedemptionTicketCreated`](/fassets/reference/IAssetManagerEvents#redemptionticketcreated) - holds the redemption ticket information updated during the redemption process.
@@ -148,7 +160,7 @@ To parse the redemption events, you can use the following function:
@@ -185,12 +197,12 @@ async function parseRedemptionEvents(
185
197
186
198
### Redeeming FAssets
187
199
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:
200
+
To put it alltogether you can use the following function to deploy the contract, transfer FXRP to it, redeem the FAssets, and parse the redemption events:
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.
289
+
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.
272
290
273
291
For every minting, a redemption ticket is created, and during the redemption process, the redemption ticket is updated with the new redemption status.
274
292
@@ -283,18 +301,18 @@ Arguments: Result(3) [
283
301
284
302
Once decoding the most important data from the event is:
285
303
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).
304
+
-The agent vault address that will redeem the FAssets is `0x3c831Fe4417bEFFAc721d24996985eE2dd627053`;
305
+
-The redemption ticket id is `870`;
306
+
-The value of the redemption ticket in underlying chain currency is `3440000000` (partially redeemed).
289
307
290
308
You can read the full event description [here](/fassets/reference/IAssetManagerEvents#redemptionticketupdated).
291
309
292
310
### Agent Process
293
311
294
-
The FAssets agent should perform the redemption, and the user needs to get the redeemed assets from the agent.
312
+
The FAssets agent should perform the redemption, and the user must retrieve the redeemed assets from the agent.
295
313
296
314
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.
315
+
In that case, the user can execute the [`redemptionPaymentDefault`](/fassets/reference/IAssetManager#redemptionpaymentdefault) function to receive compensation from the agent's collateral.
298
316
299
317
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.
300
318
The agent can also call default if the redeemer is unresponsive to payout the redeemer and free the remaining collateral.
0 commit comments