Skip to main content

migrate

Contract: JBPayoutRedemptionPaymentTerminal​‌

Interface: IJBPayoutRedemptionPaymentTerminal

Allows a project owner to migrate its funds and operations to a new terminal that accepts the same token type.

Only a project's owner or a designated operator can migrate it.

Definition

function migrate(uint256 _projectId, IJBPaymentTerminal _to)
external
virtual
override
requirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.MIGRATE_TERMINAL)
returns (uint256 balance) { ... }
  • Arguments:
    • _projectId is the ID of the project being migrated.
    • _to is the terminal contract that will gain the project's funds.
  • Through the requirePermission modifier, the function is only accessible by the project's owner, or from an operator that has been given the JBOperations.MIGRATE_TERMINAL permission by the project owner for the provided _projectId.
  • The function can be overriden by inheriting contracts.
  • The resulting function overrides a function definition from the IJBPayoutRedemptionPaymentTerminal interface.
  • The function returns the amount of funds that were migrated, as a fixed point number with the same amount of decimals as this terminal.

Body

  1. Make sure the token type of the terminal being migrated to matches the token type of this terminal.

    // The terminal being migrated to must accept the same token as this terminal.
    if (!_to.acceptsToken(token, _projectId)) revert TERMINAL_TOKENS_INCOMPATIBLE();

    Internal references:

    External references:

  2. Record the migration and get a reference to the project's balance.

    // Record the migration in the store.
    balance = store.recordMigration(_projectId);

    Internal references:

    External references:

  3. If there's a balance to migrate, move the funds over to the new terminal. Send ETH along with the transaction if this terminal is an ETH terminal. Make sure any inherited pre-transfer logic is called before transferring.

    // Transfer the balance if needed.
    if (balance > 0) {
    // Trigger any inherited pre-transfer logic.
    _beforeTransferTo(address(_to), balance);

    // If this terminal's token is ETH, send it in msg.value.
    uint256 _payableValue = token == JBTokens.ETH ? balance : 0;

    // Withdraw the balance to transfer to the new terminal;
    _to.addToBalanceOf{value: _payableValue}(balance, _projectId, token, '', bytes(''));
    }

    Library references:

    Virtual references:

    Internal references:

  4. Emit a Migrate event with the relevant parameters.

    emit Migrate(_projectId, _to, balance, msg.sender);

    Event references: