migrate
Contract: JBController
- Step by step
 - Code
 - Errors
 - Events
 - Bug bounty
 
Allows a project to migrate from this controller to another.
Only a project's owner or a designated operator can migrate it.
Definition
function migrate(uint256 _projectId, IJBMigratable _to)
  external
  virtual
  override
  requirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.MIGRATE_CONTROLLER) { ... }
- Arguments:
_projectIdis the ID of the project that will be migrated from this controller._tois theIJBMigratablecontroller to which the project is migrating.
 - Through the 
requirePermissionmodifier, the function is only accessible by the project's owner, or from an operator that has been given theJBOperations.MIGRATE_CONTROLLERpermission by the project owner for the provided_projectId. - The function can be overriden by inheriting contracts.
 - The function doesn't return anything.
 
Body
- 
Make sure this controller is the project's current controller.
// This controller must be the project's current controller.
if (directory.controllerOf(_projectId) != address(this)) revert NOT_CURRENT_CONTROLLER();Internal references:
External references:
 - 
Get a reference to the current funding cycle for the project.
// Get a reference to the project's current funding cycle.
JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);Internal references:
External references:
 - 
Make sure the project's current funding cycle is configured to allow controller migrations.
// Migration must be allowed.
if (!_fundingCycle.controllerMigrationAllowed()) revert MIGRATION_NOT_ALLOWED();Library references:
JBFundingCycleMetadataResolver.controllerMigrationAllowed(...)
 - 
Distribute any outstanding reserved tokens. There are reserved tokens to be distributed if the tracker does not equal the token's total supply.
// All reserved tokens must be minted before migrating.
if (uint256(_processedTokenTrackerOf[_projectId]) != tokenStore.totalSupplyOf(_projectId))
_distributeReservedTokensOf(_projectId, '');Internal references:
External references:
 - 
Let the new controller know that a migration to it is happening.
// Make sure the new controller is prepped for the migration.
_to.prepForMigrationOf(_projectId, address(this));External references:
 - 
Set the new controller of the project.
// Set the new controller.
directory.setControllerOf(_projectId, _to);Internal references:
External references:
 - 
Emit a
Migrateevent with the relevant parameters.emit Migrate(_projectId, _to, msg.sender);Event references:
 
/**
  @notice
  Allows a project to migrate from this controller to another.
  @dev
  Only a project's owner or a designated operator can migrate it.
  @param _projectId The ID of the project that will be migrated from this controller.
  @param _to The controller to which the project is migrating.
*/
function migrate(uint256 _projectId, IJBMigratable _to)
  external
  virtual
  override
  requirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.MIGRATE_CONTROLLER)
{
  // This controller must be the project's current controller.
  if (directory.controllerOf(_projectId) != address(this)) revert NOT_CURRENT_CONTROLLER();
  // Get a reference to the project's current funding cycle.
  JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);
  // Migration must be allowed.
  if (!_fundingCycle.controllerMigrationAllowed()) revert MIGRATION_NOT_ALLOWED();
  // All reserved tokens must be minted before migrating.
  if (uint256(_processedTokenTrackerOf[_projectId]) != tokenStore.totalSupplyOf(_projectId))
    _distributeReservedTokensOf(_projectId, '');
  // Make sure the new controller is prepped for the migration.
  _to.prepForMigrationOf(_projectId, address(this));
  // Set the new controller.
  directory.setControllerOf(_projectId, _to);
  emit Migrate(_projectId, _to, msg.sender);
}
| String | Description | 
|---|---|
NOT_CURRENT_CONTROLLER | Thrown if the controller isn't the project's current controller. | 
MIGRATION_NOT_ALLOWED | Thrown if the project's current funding cycle doesn't allow a controller migration. | 
| Name | Data | 
|---|---|
Migrate | 
  | 
| Category | Description | Reward | 
|---|---|---|
| Optimization | Help make this operation more efficient. | 0.5ETH | 
| Low severity | Identify a vulnerability in this operation that could lead to an inconvenience for a user of the protocol or for a protocol developer. | 1ETH | 
| High severity | Identify a vulnerability in this operation that could lead to data corruption or loss of funds. | 5+ETH |