Skip to main content

TokenVestingManagerFactory

Factory for deploying standard ERC20 token vesting managers with flexible fee structures and funding models.

Contract Information

File Location: contracts/factories/TokenVestingManagerFactory.sol

Inheritance:

contract TokenVestingManagerFactory is ITokenVestingManagerFactory, FactoryFeeManager

Overview

The TokenVestingManagerFactory provides standardized deployment of TokenVestingManager instances with consistent fee structures and proper initialization. It ensures that all deployed managers follow the same patterns while allowing for customization of fee structures based on deployer identity.

Key Features

  • Standardized deployment with consistent constructor patterns
  • Custom fee support for different deployer types through FactoryFeeManager
  • Flexible funding models (Full or Partial funding)
  • Admin privilege management - Deployer becomes admin, factory relinquishes control
  • Event emission for deployment tracking and indexing

Constructor

constructor(
address feeCollector_,
uint256 defaultGasFee_,
uint256 defaultTokenFee_
) FactoryFeeManager(feeCollector_, defaultGasFee_, defaultTokenFee_)

Parameters:

  • feeCollector_: Address that will receive deployment and usage fees
  • defaultGasFee_: Default gas fee amount (in wei) for deployments without custom fees
  • defaultTokenFee_: Default token fee percentage (in basis points) for deployments without custom fees

Example:

// Deploy factory with standard fees
TokenVestingManagerFactory factory = new TokenVestingManagerFactory(
0x123...789, // Fee collector address
0.001 ether, // 0.001 ETH gas fee
100 // 1% token fee (100 basis points)
);

Core Functions

newTokenVestingManager

function newTokenVestingManager(
address tokenAddress,
ITypes.FundingType fundingType
) external returns (TokenVestingManager)

Deploys a new TokenVestingManager instance with caller-specific fee configuration.

Parameters:

  • tokenAddress: ERC20 token contract address to be managed
  • fundingType: Funding model (ITypes.FundingType.Full or ITypes.FundingType.Partial)

Returns: Address of the newly deployed TokenVestingManager

Process:

  1. Fee determination - Checks for custom fees for msg.sender, otherwise uses defaults
  2. Manager deployment - Creates new TokenVestingManager with determined parameters
  3. Admin transfer - Sets deployer as admin and removes factory admin privileges
  4. Event emission - Emits TokenVestingManagerCreated event

Example:

// Deploy manager with full funding for USDC
TokenVestingManager manager = factory.newTokenVestingManager(
0xA0b86a33E6417c5d..., // USDC address
ITypes.FundingType.Full
);

// Manager is deployed with:
// - Token: USDC
// - Fee type: Determined by deployer's custom config or factory default
// - Fee amount: Determined by deployer's custom config or factory default
// - Fee collector: Factory's fee collector
// - Funding type: Full
// - Admin: msg.sender (deployer)

Events

TokenVestingManagerCreated

event TokenVestingManagerCreated(
TokenVestingManager indexed tokenVestingManager,
address indexed token,
ITypes.FeeType feeType,
uint256 fee,
address indexed feeCollector,
address creator,
ITypes.FundingType fundingType
)

Emitted when a new TokenVestingManager is deployed.

Parameters:

  • tokenVestingManager: Address of the deployed manager contract
  • token: ERC20 token address being managed
  • feeType: Fee structure type (Gas or DistributionToken)
  • fee: Fee amount (wei for gas fees, basis points for token fees)
  • feeCollector: Address that will collect fees
  • creator: Address that deployed the manager
  • fundingType: Funding model used

Fee Structure Logic

The factory determines fee structure based on deployer identity:

// Pseudocode for fee determination
if (customFees[msg.sender].enabled) {
// Use custom fees set by factory admin
if(customFees[msg.sender].preferredFeeType == ITypes.FeeType.DistributionToken) {
fee = customFees[msg.sender].tokenFee;
} else {
fee = customFees[msg.sender].gasFee;
}
} else {
// Use factory defaults
fee = defaultFeeType == ITypes.FeeType.Gas ? defaultGasFee : defaultTokenFee;
}

Security Considerations

Access Control

  • Factory admin controls - Only factory admin can set custom fees
  • Manager admin transfer - Deployer becomes manager admin immediately
  • Fee collector security - Fee collector address is immutable per deployment

Deployment Security

  • Address validation - Token address cannot be zero
  • Funding type validation - Must be valid enum value
  • Fee structure validation - Ensures proper fee configuration

Gas Optimization

  • Minimal factory logic - Factory only handles deployment, not ongoing operations
  • Efficient storage - Uses inherited FactoryFeeManager for fee storage
  • Event indexing - Events properly indexed for efficient querying

Common Use Cases

1. Employee Token Vesting

// Deploy manager for company tokens
TokenVestingManager companyManager = factory.newTokenVestingManager(
companyTokenAddress,
ITypes.FundingType.Full
);

// Set up employee vesting schedules
// 4-year vesting, 1-year cliff, monthly releases

2. Investor Token Distribution

// Deploy manager for investor tokens
TokenVestingManager investorManager = factory.newTokenVestingManager(
investorTokenAddress,
ITypes.FundingType.Partial
);

// Fund and vest tokens based on milestones

3. Community Rewards

// Deploy manager for community rewards
TokenVestingManager rewardsManager = factory.newTokenVestingManager(
rewardTokenAddress,
ITypes.FundingType.Full
);

// Create various vesting schedules for community members

Best Practices

  1. Test deployment parameters - Verify token address and funding type before deployment
  2. Monitor events - Listen for TokenVestingManagerCreated events for indexing
  3. Admin setup - Ensure proper admin configuration after deployment
  4. Fee planning - Understand fee structure before deployment
  5. Security review - Audit manager configuration and admin controls

The TokenVestingManagerFactory provides a robust foundation for deploying standardized token vesting solutions with flexible fee structures and proper security controls.