Skip to content

Commit b01bf09

Browse files
committed
refactor(docs): enhance Firelight vault scripts
1 parent 7e14393 commit b01bf09

File tree

10 files changed

+142
-116
lines changed

10 files changed

+142
-116
lines changed

docs/fassets/firelight/01-status.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ The following script retrieves and displays information about the Firelight vaul
3535
The `main()` function executes the following steps:
3636

3737
1. **Get the account and vault instance**: Retrieves the signer account and connects to the Firelight vault contract.
38-
2. **Get vault information**: Fetches vault data, including asset address, balances, and period configuration.
39-
3. **Get asset token information**: Retrieves the asset token's symbol and decimals.
38+
2. **Get vault information**: Fetches vault data, including asset address, total assets, total supply, and period configuration.
39+
3. **Get asset token information**: Retrieves the asset token's symbol and decimals for formatting.
4040
4. **Log asset information**: Displays the asset address, symbol, and decimals.
41-
5. **Log vault balances and exchange rate**: Shows total assets, total supply (shares), and the exchange rate.
42-
6. **Log period configuration**: Displays current period details and timing information.
43-
Firelight vaults operate on a [period-based logic](https://docs.firelight.finance/technical-documents#period-based-logic).
44-
7. **Get and log user information**: Shows user balances (shares and assets), and maximum limits for deposit, mint, withdraw, and redeem.
45-
8. **Log user withdrawals**: Displays pending withdrawals for the current and previous periods.
41+
5. **Log vault balances and exchange rate**: Shows total assets, total supply, and the current exchange rate.
42+
6. **Log period configuration**: Displays period timing and configuration.
43+
Firelight vaults operate on [period-based logic](https://docs.firelight.finance/technical-documents#period-based-logic).
44+
7. **Get and log user information**: Shows user balances and maximum limits for deposit, mint, withdraw, and redeem.
45+
8. **Log user withdrawals**: Displays pending withdrawals for current and previous periods.
4646

4747
## Running the Script
4848

docs/fassets/firelight/02-deposit.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ The following script demonstrates how to deposit assets into the Firelight vault
3737
The `main()` function executes the following steps:
3838

3939
1. **Get the account**: Retrieves the signer account from the Hardhat environment.
40-
2. **Get the vault and asset token**: Connects to the Firelight vault contract and retrieves the underlying asset token.
40+
2. **Get the vault and asset token**: Connects to the vault contract and retrieves the underlying asset token.
4141
3. **Get asset info**: Fetches the asset token's symbol and decimals.
42-
4. **Calculate the deposit amount**: Converts the desired deposit amount into the correct units based on token decimals.
43-
5. **Log deposit info**: Displays the deposit details, including sender, vault, asset, and amount.
44-
6. **Validate the deposit**: Checks if the requested amount exceeds the maximum allowed deposit using `maxDeposit()`.
45-
7. **Approve tokens for transfer**: Approves the vault to spend the deposit amount using the ERC-20 `approve()` function.
46-
8. **Execute the deposit**: Calls the vault's `deposit()` function, which transfers assets and mints shares to the recipient.
42+
4. **Calculate the deposit amount**: Converts the desired amount into the correct units based on decimals.
43+
5. **Log deposit info**: Displays the deposit details, including sender, vault, and amount.
44+
6. **Validate the deposit**: Checks if the amount exceeds the maximum allowed.
45+
7. **Approve tokens for transfer**: Approves the vault to spend the deposit amount.
46+
8. **Execute the deposit**: Calls `deposit()` to transfer assets and mint shares.
4747

4848
## Running the Script
4949

docs/fassets/firelight/03-mint.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ The following script demonstrates how to mint vault shares by depositing assets
3737
The `main()` function executes the following steps:
3838

3939
1. **Get the account**: Retrieves the signer account from the Hardhat environment.
40-
2. **Get the vault and asset token**: Connects to the Firelight vault contract and retrieves the underlying asset token.
40+
2. **Get the vault and asset token**: Connects to the vault contract and retrieves the underlying asset token.
4141
3. **Get asset info**: Fetches the asset token's symbol and decimals.
42-
4. **Calculate the shares amount to mint**: Converts the desired number of shares into the correct units based on token decimals.
43-
5. **Log mint info**: Displays the mint details, including sender, vault, asset, and shares amount.
44-
6. **Validate the mint**: Checks if the requested amount exceeds the maximum allowed using `maxMint()`.
45-
7. **Calculate assets needed**: Uses `previewMint()` to determine how many assets are required for the desired shares.
46-
8. **Approve tokens for transfer**: Approves the vault to spend the required assets using the ERC-20 `approve()` function.
47-
9. **Execute the mint**: Calls the vault's `mint()` function, which transfers assets and mints shares to the recipient.
42+
4. **Calculate the shares amount to mint**: Converts the desired shares into the correct units based on decimals.
43+
5. **Log mint info**: Displays the mint details, including sender, vault, and shares.
44+
6. **Validate the mint**: Checks if the amount exceeds the maximum allowed.
45+
7. **Calculate assets needed**: Uses `previewMint()` to determine the required assets.
46+
8. **Approve tokens for transfer**: Approves the vault to spend the required assets.
47+
9. **Execute the mint**: Calls `mint()` to transfer assets and mint shares.
4848

4949
## Running the Script
5050

docs/fassets/firelight/04-withdraw.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ The following script demonstrates how to create a withdrawal request from the Fi
3838
The `main()` function executes the following steps:
3939

4040
1. **Get the account**: Retrieves the signer account from the Hardhat environment.
41-
2. **Get the vault and asset token**: Connects to the Firelight vault contract and retrieves the underlying asset token.
41+
2. **Get the vault and asset token**: Connects to the vault contract and retrieves the underlying asset token.
4242
3. **Get asset info**: Fetches the asset token's symbol and decimals.
43-
4. **Calculate the withdrawal amount**: Converts the desired withdrawal amount into the correct units based on token decimals.
44-
5. **Log withdraw info**: Displays the withdrawal details, including sender, vault, asset, and amount.
45-
6. **Validate the withdrawal**: Checks if the requested amount exceeds the maximum allowed using `maxWithdraw()`.
46-
7. **Check user balance and shares needed**: Verifies the user has sufficient shares using `balanceOf()` and `previewWithdraw()`.
47-
8. **Execute the withdrawal**: Calls the vault's `withdraw()` function to create a withdrawal request for the current period.
43+
4. **Calculate the withdrawal amount**: Converts the desired amount into the correct units based on decimals.
44+
5. **Log withdraw info**: Displays the withdrawal details, including sender, vault, and amount.
45+
6. **Validate the withdrawal**: Checks if the amount exceeds the maximum allowed.
46+
7. **Check user balance and shares needed**: Verifies the user has sufficient shares for the withdrawal.
47+
8. **Execute the withdrawal**: Calls `withdraw()` to create a withdrawal request for the current period.
4848

4949
## Understanding Withdrawal Process
5050

docs/fassets/firelight/05-redeem.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ The following script demonstrates how to create a redemption request from the Fi
3838
The `main()` function executes the following steps:
3939

4040
1. **Get the account**: Retrieves the signer account from the Hardhat environment.
41-
2. **Get the vault and asset token**: Connects to the Firelight vault contract and retrieves the underlying asset token.
41+
2. **Get the vault and asset token**: Connects to the vault contract and retrieves the underlying asset token.
4242
3. **Get asset info**: Fetches the asset token's symbol and decimals.
43-
4. **Calculate the shares amount to redeem**: Converts the desired number of shares into the correct units based on token decimals.
44-
5. **Log redeem info**: Displays the redemption details, including sender, vault, asset, and shares amount.
45-
6. **Validate the redeem**: Checks if the requested amount exceeds the maximum allowed using `maxRedeem()`.
46-
7. **Check user balance**: Verifies the user has sufficient shares using `balanceOf()`.
47-
8. **Execute the redemption**: Calls the vault's `redeem()` function to create a redemption request for the current period.
43+
4. **Calculate the shares amount to redeem**: Converts the desired shares into the correct units based on decimals.
44+
5. **Log redeem info**: Displays the redemption details, including sender, vault, and shares.
45+
6. **Validate the redeem**: Checks if the amount exceeds the maximum allowed.
46+
7. **Check user balance**: Verifies the user has sufficient shares.
47+
8. **Execute the redemption**: Calls `redeem()` to create a redemption request for the current period.
4848

4949
## Understanding Redemption Process
5050

examples/developer-hub-javascript/firelight-deposit.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*/
77

88
import { ethers } from "hardhat";
9-
import { IFirelightVaultInstance } from "../../typechain-types/contracts/firelight/IFirelightVault";
9+
import type { IFirelightVaultInstance } from "../../typechain-types/contracts/firelight/IFirelightVault";
10+
import type { ERC20Instance } from "../../typechain-types/@openzeppelin/contracts/token/ERC20/ERC20";
1011
import { bnToBigInt } from "../utils/core";
1112

1213
export const FIRELIGHT_VAULT_ADDRESS = "0x91Bfe6A68aB035DFebb6A770FFfB748C03C0E40B";
@@ -26,17 +27,17 @@ async function getAccount() {
2627
async function getVaultAndAsset() {
2728
const vault = await IFirelightVault.at(FIRELIGHT_VAULT_ADDRESS) as IFirelightVaultInstance;
2829
const assetAddress = await vault.asset();
29-
const assetToken = await IERC20.at(assetAddress);
30+
const assetToken = await IERC20.at(assetAddress) as ERC20Instance;
3031
return { vault, assetAddress, assetToken };
3132
}
3233

33-
async function getAssetInfo(assetToken: any) {
34+
async function getAssetInfo(assetToken: ERC20Instance) {
3435
const symbol = await assetToken.symbol();
35-
const assetDecimals = await assetToken.decimals();
36+
const assetDecimals = (await assetToken.decimals()).toNumber();
3637
return { symbol, assetDecimals };
3738
}
3839

39-
function logDepositInfo(account: string, assetAddress: string, symbol: string, assetDecimals: any, amount: bigint) {
40+
function logDepositInfo(account: string, assetAddress: string, symbol: string, assetDecimals: number, amount: bigint) {
4041
console.log("=== Deposit (ERC-4626) ===");
4142
console.log("Sender:", account);
4243
console.log("Vault:", FIRELIGHT_VAULT_ADDRESS);
@@ -53,13 +54,13 @@ async function validateDeposit(vault: IFirelightVaultInstance, account: string,
5354
}
5455
}
5556

56-
async function approveTokens(assetToken: any, vault: any, amount: bigint, account: string) {
57-
const approveTx = await assetToken.approve(vault.address, amount, { from: account });
57+
async function approveTokens(assetToken: ERC20Instance, vault: IFirelightVaultInstance, amount: bigint, account: string) {
58+
const approveTx = await assetToken.approve(vault.address, amount.toString(), { from: account });
5859
console.log("Approve tx:", approveTx.tx);
5960
}
6061

61-
async function executeDeposit(vault: any, amount: bigint, account: string) {
62-
const depositTx = await vault.deposit(amount, account, { from: account });
62+
async function executeDeposit(vault: IFirelightVaultInstance, amount: bigint, account: string) {
63+
const depositTx = await vault.deposit(amount.toString(), account, { from: account });
6364
console.log("Deposit tx:", depositTx.tx);
6465
}
6566

@@ -74,7 +75,7 @@ async function main() {
7475
const { symbol, assetDecimals } = await getAssetInfo(assetToken);
7576

7677
// 4. Calculate the deposit amount
77-
const depositAmount = BigInt(tokensToDeposit * (10 ** Number(assetDecimals)));
78+
const depositAmount = BigInt(tokensToDeposit * (10 ** assetDecimals));
7879

7980
// 5. Log deposit info
8081
logDepositInfo(account, assetAddress, symbol, assetDecimals, depositAmount);

examples/developer-hub-javascript/firelight-mint.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import { ethers } from "hardhat";
99
import { bnToBigInt } from "../utils/core";
10-
import { IFirelightVaultInstance } from "../../typechain-types/contracts/firelight/IFirelightVault";
10+
import type { IFirelightVaultInstance } from "../../typechain-types/contracts/firelight/IFirelightVault";
11+
import type { ERC20Instance } from "../../typechain-types/@openzeppelin/contracts/token/ERC20/ERC20";
1112

1213
export const FIRELIGHT_VAULT_ADDRESS = "0x91Bfe6A68aB035DFebb6A770FFfB748C03C0E40B";
1314

@@ -26,17 +27,17 @@ async function getAccount() {
2627
async function getVaultAndAsset() {
2728
const vault = await FirelightVault.at(FIRELIGHT_VAULT_ADDRESS) as IFirelightVaultInstance;
2829
const assetAddress = await vault.asset();
29-
const assetToken = await IERC20.at(assetAddress);
30+
const assetToken = await IERC20.at(assetAddress) as ERC20Instance;
3031
return { vault, assetAddress, assetToken };
3132
}
3233

33-
async function getAssetInfo(assetToken: any) {
34+
async function getAssetInfo(assetToken: ERC20Instance) {
3435
const symbol = await assetToken.symbol();
35-
const assetDecimals = await assetToken.decimals();
36+
const assetDecimals = (await assetToken.decimals()).toNumber();
3637
return { symbol, assetDecimals };
3738
}
3839

39-
function logMintInfo(account: string, assetAddress: string, symbol: string, assetDecimals: any, sharesAmount: bigint) {
40+
function logMintInfo(account: string, assetAddress: string, symbol: string, assetDecimals: number, sharesAmount: bigint) {
4041
console.log("=== Mint vault shares (ERC-4626) ===");
4142
console.log("Sender:", account);
4243
console.log("Vault:", FIRELIGHT_VAULT_ADDRESS);
@@ -59,8 +60,8 @@ async function calculateAssetsNeeded(vault: IFirelightVaultInstance, sharesAmoun
5960
return assetsNeeded;
6061
}
6162

62-
async function approveTokens(assetToken: any, vault: any, amount: bigint, account: string) {
63-
const approveTx = await assetToken.approve(vault.address, amount, { from: account });
63+
async function approveTokens(assetToken: ERC20Instance, vault: IFirelightVaultInstance, amount: bigint, account: string) {
64+
const approveTx = await assetToken.approve(vault.address, amount.toString(), { from: account });
6465
console.log("Approve tx:", approveTx.tx);
6566
}
6667

@@ -80,7 +81,7 @@ async function main() {
8081
const { symbol, assetDecimals } = await getAssetInfo(assetToken);
8182

8283
// 4. Calculate the shares amount to mint
83-
const sharesAmount = BigInt(sharesToMint * (10 ** Number(assetDecimals)));
84+
const sharesAmount = BigInt(sharesToMint * (10 ** assetDecimals));
8485

8586
// 5. Log mint info
8687
logMintInfo(account, assetAddress, symbol, assetDecimals, sharesAmount);

examples/developer-hub-javascript/firelight-redeem.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*/
77

88
import { ethers } from "hardhat";
9-
import { IFirelightVaultInstance } from "../../typechain-types/contracts/firelight/IFirelightVault";
9+
import type { IFirelightVaultInstance } from "../../typechain-types/contracts/firelight/IFirelightVault";
10+
import type { ERC20Instance } from "../../typechain-types/@openzeppelin/contracts/token/ERC20/ERC20";
1011
import { bnToBigInt } from "../utils/core";
1112

1213
export const FIRELIGHT_VAULT_ADDRESS = "0x91Bfe6A68aB035DFebb6A770FFfB748C03C0E40B";
@@ -26,17 +27,17 @@ async function getAccount() {
2627
async function getVaultAndAsset() {
2728
const vault = await IFirelightVault.at(FIRELIGHT_VAULT_ADDRESS) as IFirelightVaultInstance;
2829
const assetAddress = await vault.asset();
29-
const assetToken = await IERC20.at(assetAddress);
30+
const assetToken = await IERC20.at(assetAddress) as ERC20Instance;
3031
return { vault, assetAddress, assetToken };
3132
}
3233

33-
async function getAssetInfo(assetToken: any) {
34+
async function getAssetInfo(assetToken: ERC20Instance) {
3435
const symbol = await assetToken.symbol();
35-
const assetDecimals = await assetToken.decimals();
36+
const assetDecimals = (await assetToken.decimals()).toNumber();
3637
return { symbol, assetDecimals };
3738
}
3839

39-
function logRedeemInfo(account: string, assetAddress: string, symbol: string, assetDecimals: any, sharesAmount: bigint) {
40+
function logRedeemInfo(account: string, assetAddress: string, symbol: string, assetDecimals: number, sharesAmount: bigint) {
4041
console.log("=== Redeem (ERC-4626) ===");
4142
console.log("Sender:", account);
4243
console.log("Vault:", FIRELIGHT_VAULT_ADDRESS);
@@ -53,9 +54,9 @@ async function validateRedeem(vault: IFirelightVaultInstance, account: string, s
5354
}
5455
}
5556

56-
async function checkUserBalance(vault: IFirelightVaultInstance, account: string, sharesAmount: bigint, assetDecimals: bigint) {
57+
async function checkUserBalance(vault: IFirelightVaultInstance, account: string, sharesAmount: bigint, assetDecimals: number) {
5758
const userBalance = await vault.balanceOf(account);
58-
const formattedUserBalance = (Number(userBalance.toString()) / Math.pow(10, Number(assetDecimals))).toFixed(Number(assetDecimals));
59+
const formattedUserBalance = (Number(userBalance.toString()) / Math.pow(10, assetDecimals)).toFixed(assetDecimals);
5960
console.log("User balance (shares):", userBalance.toString(), `(= ${formattedUserBalance} shares)`);
6061
if (bnToBigInt(userBalance) < sharesAmount) {
6162
console.error(`Insufficient balance. Need ${sharesAmount.toString()} shares, have ${userBalance.toString()}`);
@@ -79,7 +80,7 @@ async function main() {
7980
const { symbol, assetDecimals } = await getAssetInfo(assetToken);
8081

8182
// 4. Calculate the shares amount to redeem
82-
const sharesAmount = BigInt(sharesToRedeem * (10 ** Number(assetDecimals)));
83+
const sharesAmount = BigInt(sharesToRedeem * (10 ** assetDecimals));
8384

8485
// 5. Log redeem info
8586
logRedeemInfo(account, assetAddress, symbol, assetDecimals, sharesAmount);

0 commit comments

Comments
 (0)