11// SPDX-License-Identifier: MPL-2.0
2- // Migration 3: Deploy Example Contracts (SimpleVault, SimpleRWA20, ERC20Blox)
2+ // Migration 3: Deploy Example Contracts (SimpleVault, SimpleRWA20, ERC20Blox, FactoryBlox, BloxchainWallet )
33
44const SimpleVault = artifacts . require ( "SimpleVault" ) ;
55const SimpleRWA20 = artifacts . require ( "SimpleRWA20" ) ;
66const ERC20Blox = artifacts . require ( "ERC20Blox" ) ;
7+ const FactoryBlox = artifacts . require ( "FactoryBlox" ) ;
8+ const BloxchainWallet = artifacts . require ( "BloxchainWallet" ) ;
79
810// Import the deployed library artifacts to get their addresses
911const EngineBlox = artifacts . require ( "EngineBlox" ) ;
@@ -15,6 +17,7 @@ const GuardControllerDefinitions = artifacts.require("GuardControllerDefinitions
1517const SimpleVaultDefinitions = artifacts . require ( "SimpleVaultDefinitions" ) ;
1618const SimpleRWA20Definitions = artifacts . require ( "SimpleRWA20Definitions" ) ;
1719const ERC20BloxDefinitions = artifacts . require ( "ERC20BloxDefinitions" ) ;
20+ const FactoryBloxDefinitions = artifacts . require ( "FactoryBloxDefinitions" ) ;
1821const { saveArtifactNetwork } = require ( './helpers/save-artifact-network.cjs' ) ;
1922
2023module . exports = async function ( deployer , network , accounts ) {
@@ -28,41 +31,53 @@ module.exports = async function(deployer, network, accounts) {
2831 const deploySimpleVault = process . env . DEPLOY_SIMPLE_VAULT === 'true' ; // Default: false
2932 const deploySimpleRWA20 = process . env . DEPLOY_SIMPLE_RWA20 === 'true' ; // Default: false
3033 const deployERC20Blox = process . env . DEPLOY_ERC20_BLOX === 'true' ; // Default: false
31-
34+ const deployFactoryBlox = process . env . DEPLOY_FACTORY_BLOX === 'true' ; // Default: false
35+ const deployWalletBlox = process . env . DEPLOY_WALLET_BLOX === 'true' ; // Default: false
36+
3237 console . log ( "\n🎯 Deployment Configuration:" ) ;
3338 console . log ( ` SimpleVault: ${ deploySimpleVault ? '✅ YES' : '❌ NO' } ` ) ;
3439 console . log ( ` SimpleRWA20: ${ deploySimpleRWA20 ? '✅ YES' : '❌ NO' } ` ) ;
3540 console . log ( ` ERC20Blox: ${ deployERC20Blox ? '✅ YES' : '❌ NO' } ` ) ;
41+ console . log ( ` FactoryBlox: ${ deployFactoryBlox ? '✅ YES' : '❌ NO' } ` ) ;
42+ console . log ( ` BloxchainWallet: ${ deployWalletBlox ? '✅ YES' : '❌ NO' } ` ) ;
3643
3744 try {
3845 // Step 1: Deploy Example-Specific Definitions Libraries (only if needed)
3946 let simpleVaultDefinitions = null ;
4047 let simpleRWA20Definitions = null ;
4148 let erc20BloxDefinitions = null ;
42-
43- if ( deploySimpleVault || deploySimpleRWA20 || deployERC20Blox ) {
49+ let factoryBloxDefinitions = null ;
50+
51+ if ( deploySimpleVault || deploySimpleRWA20 || deployERC20Blox || deployFactoryBlox || deployWalletBlox ) {
4452 console . log ( "\n📦 Step 1: Deploying Example-Specific Definitions Libraries..." ) ;
45-
53+
4654 if ( deploySimpleVault ) {
4755 // Deploy SimpleVaultDefinitions
4856 await deployer . deploy ( SimpleVaultDefinitions ) ;
4957 simpleVaultDefinitions = await SimpleVaultDefinitions . deployed ( ) ;
5058 console . log ( `✅ SimpleVaultDefinitions deployed at: ${ simpleVaultDefinitions . address } ` ) ;
5159 }
52-
60+
5361 if ( deploySimpleRWA20 ) {
5462 // Deploy SimpleRWA20Definitions
5563 await deployer . deploy ( SimpleRWA20Definitions ) ;
5664 simpleRWA20Definitions = await SimpleRWA20Definitions . deployed ( ) ;
5765 console . log ( `✅ SimpleRWA20Definitions deployed at: ${ simpleRWA20Definitions . address } ` ) ;
5866 }
59-
67+
6068 if ( deployERC20Blox ) {
6169 // Deploy ERC20BloxDefinitions
6270 await deployer . deploy ( ERC20BloxDefinitions ) ;
6371 erc20BloxDefinitions = await ERC20BloxDefinitions . deployed ( ) ;
6472 console . log ( `✅ ERC20BloxDefinitions deployed at: ${ erc20BloxDefinitions . address } ` ) ;
6573 }
74+
75+ if ( deployFactoryBlox ) {
76+ // Deploy FactoryBloxDefinitions
77+ await deployer . deploy ( FactoryBloxDefinitions ) ;
78+ factoryBloxDefinitions = await FactoryBloxDefinitions . deployed ( ) ;
79+ console . log ( `✅ FactoryBloxDefinitions deployed at: ${ factoryBloxDefinitions . address } ` ) ;
80+ }
6681 } else {
6782 console . log ( "\n📦 Step 1: Skipping Example-Specific Definitions Libraries (no contracts enabled)" ) ;
6883 }
@@ -255,11 +270,81 @@ module.exports = async function(deployer, network, accounts) {
255270 console . log ( "\n📦 Step 5: Skipping ERC20Blox deployment (disabled)" ) ;
256271 }
257272
273+ // Step 6: Deploy FactoryBlox (if enabled)
274+ let factoryBlox = null ;
275+ if ( deployFactoryBlox ) {
276+ console . log ( "\n📦 Step 6: Deploying FactoryBlox..." ) ;
277+ await deployer . link ( sa , FactoryBlox ) ;
278+ await deployer . link ( sod , FactoryBlox ) ;
279+ await deployer . link ( drbd , FactoryBlox ) ;
280+ await deployer . link ( gcd , FactoryBlox ) ;
281+ await deployer . link ( factoryBloxDefinitions , FactoryBlox ) ;
282+ await deployer . deploy ( FactoryBlox ) ;
283+ factoryBlox = await FactoryBlox . deployed ( ) ;
284+ console . log ( `✅ FactoryBlox deployed at: ${ factoryBlox . address } ` ) ;
285+ const web3Factory = factoryBlox . constructor . web3 || global . web3 ;
286+ await saveArtifactNetwork ( FactoryBlox , factoryBlox . address , web3Factory , network ) ;
287+
288+ // Initialize FactoryBlox (5 params)
289+ console . log ( "🔧 Initializing FactoryBlox..." ) ;
290+ try {
291+ await factoryBlox . initialize (
292+ accounts [ 0 ] , // initialOwner
293+ accounts [ 1 ] , // broadcaster
294+ accounts [ 2 ] , // recovery
295+ 1 , // timeLockPeriodInSeconds (1 second for fast testing)
296+ "0x0000000000000000000000000000000000000000" // eventForwarder (none)
297+ ) ;
298+ console . log ( "✅ FactoryBlox initialized successfully" ) ;
299+ } catch ( error ) {
300+ console . log ( "❌ FactoryBlox initialize failed:" , error . message ) ;
301+ console . log ( "⚠️ Contract deployed but not initialized." ) ;
302+ }
303+ } else {
304+ console . log ( "\n📦 Step 6: Skipping FactoryBlox deployment (disabled)" ) ;
305+ }
306+
307+ // Step 7: Deploy BloxchainWallet (if enabled) - Account-based, no definitions library; timeLock 1–90 days
308+ const ONE_DAY_SEC = 86400 ;
309+ let bloxchainWallet = null ;
310+ if ( deployWalletBlox ) {
311+ console . log ( "\n📦 Step 7: Deploying BloxchainWallet..." ) ;
312+ await deployer . link ( sa , BloxchainWallet ) ;
313+ await deployer . link ( sod , BloxchainWallet ) ;
314+ await deployer . link ( drbd , BloxchainWallet ) ;
315+ await deployer . link ( gcd , BloxchainWallet ) ;
316+ await deployer . deploy ( BloxchainWallet ) ;
317+ bloxchainWallet = await BloxchainWallet . deployed ( ) ;
318+ console . log ( `✅ BloxchainWallet deployed at: ${ bloxchainWallet . address } ` ) ;
319+ const web3Wallet = bloxchainWallet . constructor . web3 || global . web3 ;
320+ await saveArtifactNetwork ( BloxchainWallet , bloxchainWallet . address , web3Wallet , network ) ;
321+
322+ // Initialize BloxchainWallet (5 params); timeLock must be between 1 and 90 days
323+ console . log ( "🔧 Initializing BloxchainWallet..." ) ;
324+ try {
325+ await bloxchainWallet . initialize (
326+ accounts [ 0 ] , // initialOwner
327+ accounts [ 1 ] , // broadcaster
328+ accounts [ 2 ] , // recovery
329+ ONE_DAY_SEC , // timeLockPeriodInSeconds (min 1 day per contract)
330+ "0x0000000000000000000000000000000000000000" // eventForwarder (none)
331+ ) ;
332+ console . log ( "✅ BloxchainWallet initialized successfully" ) ;
333+ } catch ( error ) {
334+ console . log ( "❌ BloxchainWallet initialize failed:" , error . message ) ;
335+ console . log ( "⚠️ Contract deployed but not initialized." ) ;
336+ }
337+ } else {
338+ console . log ( "\n📦 Step 7: Skipping BloxchainWallet deployment (disabled)" ) ;
339+ }
340+
258341 console . log ( "\n🎉 Migration 3 completed successfully!" ) ;
259342 console . log ( "📋 Example Contracts Deployed & Initialized:" ) ;
260343 if ( simpleVault ) console . log ( ` SimpleVault: ${ simpleVault . address } ` ) ;
261344 if ( simpleRWA20 ) console . log ( ` SimpleRWA20: ${ simpleRWA20 . address } ` ) ;
262345 if ( erc20Blox ) console . log ( ` ERC20Blox: ${ erc20Blox . address } ` ) ;
346+ if ( factoryBlox ) console . log ( ` FactoryBlox: ${ factoryBlox . address } ` ) ;
347+ if ( bloxchainWallet ) console . log ( ` BloxchainWallet: ${ bloxchainWallet . address } ` ) ;
263348
264349 // Save deployed addresses to file for auto mode fallback
265350 const fs = require ( 'fs' ) ;
@@ -293,6 +378,12 @@ module.exports = async function(deployer, network, accounts) {
293378 deployedAt : new Date ( ) . toISOString ( )
294379 } ;
295380 }
381+ if ( factoryBloxDefinitions ) {
382+ addresses [ network ] . FactoryBloxDefinitions = {
383+ address : factoryBloxDefinitions . address ,
384+ deployedAt : new Date ( ) . toISOString ( )
385+ } ;
386+ }
296387 if ( simpleVault ) {
297388 addresses [ network ] . SimpleVault = {
298389 address : simpleVault . address ,
@@ -311,7 +402,19 @@ module.exports = async function(deployer, network, accounts) {
311402 deployedAt : new Date ( ) . toISOString ( )
312403 } ;
313404 }
314-
405+ if ( factoryBlox ) {
406+ addresses [ network ] . FactoryBlox = {
407+ address : factoryBlox . address ,
408+ deployedAt : new Date ( ) . toISOString ( )
409+ } ;
410+ }
411+ if ( bloxchainWallet ) {
412+ addresses [ network ] . BloxchainWallet = {
413+ address : bloxchainWallet . address ,
414+ deployedAt : new Date ( ) . toISOString ( )
415+ } ;
416+ }
417+
315418 fs . writeFileSync ( addressesFile , JSON . stringify ( addresses , null , 2 ) ) ;
316419 console . log ( `\n💾 Saved addresses to ${ addressesFile } ` ) ;
317420
@@ -325,13 +428,16 @@ module.exports = async function(deployer, network, accounts) {
325428 if ( simpleVaultDefinitions ) console . log ( ` SimpleVaultDefinitions: ${ simpleVaultDefinitions . address } ` ) ;
326429 if ( simpleRWA20Definitions ) console . log ( ` SimpleRWA20Definitions: ${ simpleRWA20Definitions . address } ` ) ;
327430 if ( erc20BloxDefinitions ) console . log ( ` ERC20BloxDefinitions: ${ erc20BloxDefinitions . address } ` ) ;
431+ if ( factoryBloxDefinitions ) console . log ( ` FactoryBloxDefinitions: ${ factoryBloxDefinitions . address } ` ) ;
328432 console . log ( "🛡️ Guardian Contracts (Deployed & Initialized):" ) ;
329433 console . log ( ` GuardianAccountAbstraction: 0xf759A0e8F2fFBb5F5a9DD50f1106668FBE29bC93` ) ;
330434 console . log ( ` GuardianAccountAbstractionWithRoles: 0xA5682DF1987D214Fe4dfC3a262179eBDc205b525` ) ;
331435 console . log ( "🏦 Example Contracts (Deployed & Initialized):" ) ;
332436 if ( simpleVault ) console . log ( ` SimpleVault: ${ simpleVault . address } ` ) ;
333437 if ( simpleRWA20 ) console . log ( ` SimpleRWA20: ${ simpleRWA20 . address } ` ) ;
334438 if ( erc20Blox ) console . log ( ` ERC20Blox: ${ erc20Blox . address } ` ) ;
439+ if ( factoryBlox ) console . log ( ` FactoryBlox: ${ factoryBlox . address } ` ) ;
440+ if ( bloxchainWallet ) console . log ( ` BloxchainWallet: ${ bloxchainWallet . address } ` ) ;
335441 console . log ( "\n✅ All contracts deployed and initialized successfully!" ) ;
336442 console . log ( "🎯 Ready for comprehensive analyzer testing with fully functional contracts!" ) ;
337443 console . log ( "🔧 Initialization Parameters:" ) ;
@@ -344,10 +450,12 @@ module.exports = async function(deployer, network, accounts) {
344450 console . log ( ` Token Symbol: SRWA` ) ;
345451
346452 console . log ( "\n💡 Usage Examples:" ) ;
347- console . log ( " Deploy only SimpleVault: DEPLOY_SIMPLE_VAULT=true DEPLOY_SIMPLE_RWA20=false DEPLOY_ERC20_BLOX=false truffle migrate" ) ;
348- console . log ( " Deploy only SimpleRWA20: DEPLOY_SIMPLE_VAULT=false DEPLOY_SIMPLE_RWA20=true DEPLOY_ERC20_BLOX=false truffle migrate" ) ;
349- console . log ( " Deploy only ERC20Blox: DEPLOY_SIMPLE_VAULT=false DEPLOY_SIMPLE_RWA20=false DEPLOY_ERC20_BLOX=true truffle migrate" ) ;
350- console . log ( " Deploy all example contracts: DEPLOY_SIMPLE_VAULT=true DEPLOY_SIMPLE_RWA20=true DEPLOY_ERC20_BLOX=true truffle migrate" ) ;
453+ console . log ( " Deploy only SimpleVault: DEPLOY_SIMPLE_VAULT=true DEPLOY_SIMPLE_RWA20=false DEPLOY_ERC20_BLOX=false DEPLOY_FACTORY_BLOX=false DEPLOY_WALLET_BLOX=false truffle migrate" ) ;
454+ console . log ( " Deploy only SimpleRWA20: DEPLOY_SIMPLE_VAULT=false DEPLOY_SIMPLE_RWA20=true DEPLOY_ERC20_BLOX=false DEPLOY_FACTORY_BLOX=false DEPLOY_WALLET_BLOX=false truffle migrate" ) ;
455+ console . log ( " Deploy only ERC20Blox: DEPLOY_SIMPLE_VAULT=false DEPLOY_SIMPLE_RWA20=false DEPLOY_ERC20_BLOX=true DEPLOY_FACTORY_BLOX=false DEPLOY_WALLET_BLOX=false truffle migrate" ) ;
456+ console . log ( " Deploy only FactoryBlox: DEPLOY_SIMPLE_VAULT=false DEPLOY_SIMPLE_RWA20=false DEPLOY_ERC20_BLOX=false DEPLOY_FACTORY_BLOX=true DEPLOY_WALLET_BLOX=false truffle migrate" ) ;
457+ console . log ( " Deploy only BloxchainWallet: DEPLOY_SIMPLE_VAULT=false DEPLOY_SIMPLE_RWA20=false DEPLOY_ERC20_BLOX=false DEPLOY_FACTORY_BLOX=false DEPLOY_WALLET_BLOX=true truffle migrate" ) ;
458+ console . log ( " Deploy all example contracts: DEPLOY_SIMPLE_VAULT=true DEPLOY_SIMPLE_RWA20=true DEPLOY_ERC20_BLOX=true DEPLOY_FACTORY_BLOX=true DEPLOY_WALLET_BLOX=true truffle migrate" ) ;
351459 console . log ( " Deploy none (default): truffle migrate" ) ;
352460
353461 } catch ( error ) {
0 commit comments