Skip to main content

🎯 FINAL SOLUTION: SCRIPT-BASED DEPLOYMENT

🚨 THE PROBLEM​

Even an ultra-minimal factory is >100KB because it embeds bytecode for 3 large contracts:

  • CreatorOVault (~30KB)
  • CreatorOVaultWrapper (~25KB)
  • CreatorShareOFT (~40KB)

Total embedded bytecode: ~95KB + factory code = >100KB

EVM limit: 24KB ❌


βœ… THE SOLUTION: DEPLOYMENT SCRIPTS​

Instead of a factory contract, use Foundry scripts for deployment:

How It Works:​

  1. No contract size limit (scripts run off-chain)
  2. Full CREATE2 support (deterministic addresses)
  3. More flexible (can deploy anything)
  4. Gas efficient (no factory overhead)

πŸš€ IMPLEMENTATION​

Script: DeployCreatorVault.s.sol​

// Deploy vault infrastructure with CREATE2
function run() external {
address token = vm.envAddress("TOKEN");
address creator = vm.envAddress("CREATOR");

// Generate salt
bytes32 salt = keccak256(abi.encodePacked("CV1_", token));

// Deploy with CREATE2
vault = new CreatorOVault{salt: salt}(token, creator, ...);
wrapper = new CreatorOVaultWrapper{salt: salt}(token, vault, creator);
shareOFT = new CreatorShareOFT{salt: salt}(name, symbol, lz, creator);

// Configure
wrapper.setShareOFT(shareOFT);
shareOFT.setVault(vault);
shareOFT.setMinter(wrapper, true);
vault.setWhitelist(wrapper, true);
}

Frontend Integration:​

// Call script via backend API
async function deployVault(token: string, creator: string) {
const response = await fetch('/api/deploy-vault', {
method: 'POST',
body: JSON.stringify({ token, creator })
});

const { vault, wrapper, shareOFT } = await response.json();
return { vault, wrapper, shareOFT };
}

Backend API:​

// api/deploy-vault.ts
import { exec } from 'child_process';

export async function POST(req: Request) {
const { token, creator } = await req.json();

// Run forge script
const result = await exec(`
forge script script/DeployCreatorVault.s.sol \
--rpc-url base \
--private-key ${DEPLOYER_KEY} \
--broadcast \
-vvv
`);

// Parse output for addresses
const { vault, wrapper, shareOFT } = parseOutput(result);

return Response.json({ vault, wrapper, shareOFT });
}

🎯 BENEFITS​

FeatureFactoryScript
Size limit❌ 24KBβœ… Unlimited
CREATE2βœ… Yesβœ… Yes
Gas costHigher (factory call)Lower (direct deploy)
FlexibilityLimitedβœ… Full control
Frontend integrationDirectVia API

Frontend
↓ (Call API)
Backend API
↓ (Run script)
Forge Script
↓ (Deploy with CREATE2)
Vault + Wrapper + ShareOFT on Base

User Experience:

  1. User clicks "Create Vault"
  2. Frontend calls backend API
  3. Backend runs forge script
  4. Script deploys with CREATE2
  5. Returns addresses to frontend
  6. Same addresses on all chains! βœ…

πŸš€ WHAT YOU ALREADY HAVE​

You already have the script approach ready to use:

  • βœ… CreatorOVaultFactory.sol (onchain registry of deployments)
  • βœ… CREATE2-based deployment flow (AA + deployers)
  • βœ… VaultActivationBatcher deployed

You just need:

  1. Use the existing AA deploy flow (frontend/src/components/DeployVaultAA.tsx / script/deploy-with-aa.ts)
  2. Or run Foundry scripts to deploy and then registerDeployment(...) in CreatorOVaultFactory

πŸ“‹ QUICK START​

1. Create Script​

# Prefer the AA deploy flow (one-signature) or the existing Foundry scripts in /script.
# See:
# - script/DeployInfrastructure.s.sol
# - script/deploy-with-aa.ts

2. Test Locally​

forge script script/DeployVaultWithCREATE2.s.sol --rpc-url base --broadcast

3. Integrate with Frontend​

// Simple API call
const { vault, wrapper, shareOFT } = await deployVault(token, creator);

πŸŽ‰ ADVANTAGES OVER FACTORY​

βœ… No 24KB limit βœ… Same CREATE2 benefits βœ… Lower gas costs βœ… More control βœ… Easier to update


Want me to create the deployment script now? πŸš€

This is the BEST solution for your use case!