migrate
Contract: JBPayoutRedemptionPaymentTerminal
Interface: IJBPayoutRedemptionPaymentTerminal
- Step by step
- Code
- Errors
- Events
- Bug bounty
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:
_projectIdis the ID of the project being migrated._tois the terminal contract that will gain the project's funds.
- Through the
requirePermissionmodifier, the function is only accessible by the project's owner, or from an operator that has been given theJBOperations.MIGRATE_TERMINALpermission 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
IJBPayoutRedemptionPaymentTerminalinterface. - 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
-
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:
-
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:
-
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:
JBTokens.ETH
Virtual references:
Internal references:
-
Emit a
Migrateevent with the relevant parameters.emit Migrate(_projectId, _to, balance, msg.sender);Event references:
/**
@notice
Allows a project owner to migrate its funds and operations to a new terminal that accepts the same token type.
@dev
Only a project's owner or a designated operator can migrate it.
@param _projectId The ID of the project being migrated.
@param _to The terminal contract that will gain the project's funds.
@return balance The amount of funds that were migrated, as a fixed point number with the same amount of decimals as this terminal.
*/
function migrate(uint256 _projectId, IJBPaymentTerminal _to)
external
virtual
override
requirePermission(projects.ownerOf(_projectId), _projectId, JBOperations.MIGRATE_TERMINAL)
returns (uint256 balance)
{
// The terminal being migrated to must accept the same token as this terminal.
if (!_to.acceptsToken(token, _projectId)) revert TERMINAL_TOKENS_INCOMPATIBLE();
// Record the migration in the store.
balance = store.recordMigration(_projectId);
// 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(''));
}
emit Migrate(_projectId, _to, balance, msg.sender);
}
| String | Description |
|---|---|
TERMINAL_TOKENS_INCOMPATIBLE | Thrown if the terminal being migrated to doesn't use the same token as this terminal. |
| 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 |