11/**
22 * FirelightVault Mint Script
3- *
3+ *
44 * This script mints vault shares (ERC-4626) by depositing assets into the FirelightVault.
55 * It checks max mint capacity, calculates required assets, approves tokens, and mints shares.
66 */
@@ -10,97 +10,133 @@ import { bnToBigInt } from "../utils/core";
1010import type { IFirelightVaultInstance } from "../../typechain-types/contracts/firelight/IFirelightVault" ;
1111import type { ERC20Instance } from "../../typechain-types/@openzeppelin/contracts/token/ERC20/ERC20" ;
1212
13- export const FIRELIGHT_VAULT_ADDRESS = "0x91Bfe6A68aB035DFebb6A770FFfB748C03C0E40B" ;
13+ export const FIRELIGHT_VAULT_ADDRESS =
14+ "0x91Bfe6A68aB035DFebb6A770FFfB748C03C0E40B" ;
1415
1516const sharesToMint = 1 ; // Number of shares to mint
1617
1718// @ts -expect-error - Type definitions issue, but works at runtime
18- const IERC20 = artifacts . require ( "@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20" ) ;
19+ const IERC20 = artifacts . require (
20+ "@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20" ,
21+ ) ;
1922
2023const FirelightVault = artifacts . require ( "IFirelightVault" ) ;
2124
2225async function getAccount ( ) {
23- const [ signer ] = await ethers . getSigners ( ) ;
24- return { signer, account : signer . address } ;
26+ const [ signer ] = await ethers . getSigners ( ) ;
27+ return { signer, account : signer . address } ;
2528}
2629
2730async function getVaultAndAsset ( ) {
28- const vault = await FirelightVault . at ( FIRELIGHT_VAULT_ADDRESS ) as IFirelightVaultInstance ;
29- const assetAddress = await vault . asset ( ) ;
30- const assetToken = await IERC20 . at ( assetAddress ) as ERC20Instance ;
31- return { vault, assetAddress, assetToken } ;
31+ const vault = ( await FirelightVault . at (
32+ FIRELIGHT_VAULT_ADDRESS ,
33+ ) ) as IFirelightVaultInstance ;
34+ const assetAddress = await vault . asset ( ) ;
35+ const assetToken = ( await IERC20 . at ( assetAddress ) ) as ERC20Instance ;
36+ return { vault, assetAddress, assetToken } ;
3237}
3338
3439async function getAssetInfo ( assetToken : ERC20Instance ) {
35- const symbol = await assetToken . symbol ( ) ;
36- const assetDecimals = ( await assetToken . decimals ( ) ) . toNumber ( ) ;
37- return { symbol, assetDecimals } ;
40+ const symbol = await assetToken . symbol ( ) ;
41+ const assetDecimals = ( await assetToken . decimals ( ) ) . toNumber ( ) ;
42+ return { symbol, assetDecimals } ;
3843}
3944
40- function logMintInfo ( account : string , assetAddress : string , symbol : string , assetDecimals : number , sharesAmount : bigint ) {
41- console . log ( "=== Mint vault shares (ERC-4626) ===" ) ;
42- console . log ( "Sender:" , account ) ;
43- console . log ( "Vault:" , FIRELIGHT_VAULT_ADDRESS ) ;
44- console . log ( "Asset:" , assetAddress , `(${ symbol } , decimals=${ assetDecimals } )` ) ;
45- console . log ( "Shares to mint:" , sharesAmount . toString ( ) , `(= ${ sharesToMint } share${ sharesToMint > 1 ? 's' : '' } )` ) ;
45+ function logMintInfo (
46+ account : string ,
47+ assetAddress : string ,
48+ symbol : string ,
49+ assetDecimals : number ,
50+ sharesAmount : bigint ,
51+ ) {
52+ console . log ( "=== Mint vault shares (ERC-4626) ===" ) ;
53+ console . log ( "Sender:" , account ) ;
54+ console . log ( "Vault:" , FIRELIGHT_VAULT_ADDRESS ) ;
55+ console . log ( "Asset:" , assetAddress , `(${ symbol } , decimals=${ assetDecimals } )` ) ;
56+ console . log (
57+ "Shares to mint:" ,
58+ sharesAmount . toString ( ) ,
59+ `(= ${ sharesToMint } share${ sharesToMint > 1 ? "s" : "" } )` ,
60+ ) ;
4661}
4762
48- async function validateMint ( vault : IFirelightVaultInstance , account : string , sharesAmount : bigint ) {
49- const maxMint = bnToBigInt ( await vault . maxMint ( account ) ) ;
50- console . log ( "Max mint:" , maxMint . toString ( ) ) ;
51- if ( sharesAmount > maxMint ) {
52- console . error ( `Cannot mint ${ sharesAmount . toString ( ) } shares. Max allowed: ${ maxMint . toString ( ) } ` ) ;
53- process . exit ( 1 ) ;
54- }
63+ async function validateMint (
64+ vault : IFirelightVaultInstance ,
65+ account : string ,
66+ sharesAmount : bigint ,
67+ ) {
68+ const maxMint = bnToBigInt ( await vault . maxMint ( account ) ) ;
69+ console . log ( "Max mint:" , maxMint . toString ( ) ) ;
70+ if ( sharesAmount > maxMint ) {
71+ console . error (
72+ `Cannot mint ${ sharesAmount . toString ( ) } shares. Max allowed: ${ maxMint . toString ( ) } ` ,
73+ ) ;
74+ process . exit ( 1 ) ;
75+ }
5576}
5677
57- async function calculateAssetsNeeded ( vault : IFirelightVaultInstance , sharesAmount : bigint ) {
58- const assetsNeeded = await vault . previewMint ( sharesAmount . toString ( ) ) ;
59- console . log ( "Assets needed (from previewMint):" , assetsNeeded . toString ( ) ) ;
60- return assetsNeeded ;
78+ async function calculateAssetsNeeded (
79+ vault : IFirelightVaultInstance ,
80+ sharesAmount : bigint ,
81+ ) {
82+ const assetsNeeded = await vault . previewMint ( sharesAmount . toString ( ) ) ;
83+ console . log ( "Assets needed (from previewMint):" , assetsNeeded . toString ( ) ) ;
84+ return assetsNeeded ;
6185}
6286
63- async function approveTokens ( assetToken : ERC20Instance , vault : IFirelightVaultInstance , amount : bigint , account : string ) {
64- const approveTx = await assetToken . approve ( vault . address , amount . toString ( ) , { from : account } ) ;
65- console . log ( "Approve tx:" , approveTx . tx ) ;
87+ async function approveTokens (
88+ assetToken : ERC20Instance ,
89+ vault : IFirelightVaultInstance ,
90+ amount : bigint ,
91+ account : string ,
92+ ) {
93+ const approveTx = await assetToken . approve ( vault . address , amount . toString ( ) , {
94+ from : account ,
95+ } ) ;
96+ console . log ( "Approve tx:" , approveTx . tx ) ;
6697}
6798
68- async function executeMint ( vault : IFirelightVaultInstance , sharesAmount : bigint , account : string ) {
69- const mintTx = await vault . mint ( sharesAmount . toString ( ) , account , { from : account } ) ;
70- console . log ( "Mint tx:" , mintTx . tx ) ;
99+ async function executeMint (
100+ vault : IFirelightVaultInstance ,
101+ sharesAmount : bigint ,
102+ account : string ,
103+ ) {
104+ const mintTx = await vault . mint ( sharesAmount . toString ( ) , account , {
105+ from : account ,
106+ } ) ;
107+ console . log ( "Mint tx:" , mintTx . tx ) ;
71108}
72109
73110async function main ( ) {
74- // 1. Get the account
75- const { account } = await getAccount ( ) ;
111+ // 1. Get the account
112+ const { account } = await getAccount ( ) ;
76113
77- // 2. Get the vault and asset token
78- const { vault, assetAddress, assetToken } = await getVaultAndAsset ( ) ;
114+ // 2. Get the vault and asset token
115+ const { vault, assetAddress, assetToken } = await getVaultAndAsset ( ) ;
79116
80- // 3. Get asset info (symbol, decimals)
81- const { symbol, assetDecimals } = await getAssetInfo ( assetToken ) ;
117+ // 3. Get asset info (symbol, decimals)
118+ const { symbol, assetDecimals } = await getAssetInfo ( assetToken ) ;
82119
83- // 4. Calculate the shares amount to mint
84- const sharesAmount = BigInt ( sharesToMint * ( 10 ** assetDecimals ) ) ;
120+ // 4. Calculate the shares amount to mint
121+ const sharesAmount = BigInt ( sharesToMint * 10 ** assetDecimals ) ;
85122
86- // 5. Log mint info
87- logMintInfo ( account , assetAddress , symbol , assetDecimals , sharesAmount ) ;
123+ // 5. Log mint info
124+ logMintInfo ( account , assetAddress , symbol , assetDecimals , sharesAmount ) ;
88125
89- // 6. Validate the mint (check max mint)
90- await validateMint ( vault , account , sharesAmount ) ;
126+ // 6. Validate the mint (check max mint)
127+ await validateMint ( vault , account , sharesAmount ) ;
91128
92- // 7. Calculate assets needed using previewMint
93- const assetsNeeded = await calculateAssetsNeeded ( vault , sharesAmount ) ;
129+ // 7. Calculate assets needed using previewMint
130+ const assetsNeeded = await calculateAssetsNeeded ( vault , sharesAmount ) ;
94131
95- // 8. Approve tokens for transfer
96- await approveTokens ( assetToken , vault , bnToBigInt ( assetsNeeded ) , account ) ;
132+ // 8. Approve tokens for transfer
133+ await approveTokens ( assetToken , vault , bnToBigInt ( assetsNeeded ) , account ) ;
97134
98- // 9. Execute the mint
99- await executeMint ( vault , sharesAmount , account ) ;
135+ // 9. Execute the mint
136+ await executeMint ( vault , sharesAmount , account ) ;
100137}
101138
102139main ( ) . catch ( ( error ) => {
103- console . error ( error ) ;
104- process . exitCode = 1 ;
140+ console . error ( error ) ;
141+ process . exitCode = 1 ;
105142} ) ;
106-
0 commit comments