transferFrom
Contract: JBTokenStore
Interface: IJBTokenStore
- Step by step
- Code
- Errors
- Events
- Bug bounty
Allows a holder to transfer unclaimed tokens to another account.
Only a token holder or an operator can transfer its unclaimed tokens.
Definition
function transferFrom(
address _holder,
uint256 _projectId,
address _recipient,
uint256 _amount
) external override requirePermission(_holder, _projectId, JBOperations.TRANSFER) { ... }
- Arguments:
_holderis the address to transfer tokens from._projectIdis the ID of the project whose tokens are being transferred._recipientis thhe recipient of the tokens._amountis the amount of tokens to transfer.
- Through the
requirePermissionmodifier, the function is only accessible by the token holder, or from an operator that has been given theJBOperations.TRANSFERpermission by the token holder. - The function overrides a function definition from the
IJBTokenStoreinterface. - The function doesn't return anything.
Body
-
Get a reference to the project's current funding cycle.
// Get a reference to the current funding cycle for the project.
JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);Internal references:
-
Make sure the project's current funding cycle is not set to pause transfers.
// Must not be paused.
if (_fundingCycle.global().pauseTransfers) revert TRANSFERS_PAUSED();Library references:
JBFundingCycleMetadataResolver.global(...)
-
Make sure a non-zero recipient was specified.
// Can't transfer to the zero address.
if (_recipient == address(0)) revert RECIPIENT_ZERO_ADDRESS(); -
Get a reference to the amount of unclaimed project tokens the holder has.
// Get a reference to the holder's unclaimed project token balance.
uint256 _unclaimedBalance = unclaimedBalanceOf[_holder][_projectId];Internal references:
-
Make sure the holder has enough unclaimed tokens to transfer.
// The holder must have enough unclaimed tokens to transfer.
if (_amount > _unclaimedBalance) revert INSUFFICIENT_UNCLAIMED_TOKENS(); -
Subtract the amount from the holder's unclaimed balance of project tokens.
// Subtract from the holder's unclaimed token balance.
unchecked {
unclaimedBalanceOf[_holder][_projectId] = _unclaimedBalance - _amount;
}Internal references:
-
Add the amount of unclaimed project tokens to the recipient's balance.
// Add the unclaimed project tokens to the recipient's balance.
unclaimedBalanceOf[_recipient][_projectId] =
unclaimedBalanceOf[_recipient][_projectId] +
_amount;Internal references:
-
Emit a
Transferevent with the relevant parameters.emit Transfer(_holder, _projectId, _recipient, _amount, msg.sender);Event references:
/**
@notice
Allows a holder to transfer unclaimed tokens to another account.
@dev
Only a token holder or an operator can transfer its unclaimed tokens.
@param _holder The address to transfer tokens from.
@param _projectId The ID of the project whose tokens are being transferred.
@param _recipient The recipient of the tokens.
@param _amount The amount of tokens to transfer.
*/
function transferFrom(
address _holder,
uint256 _projectId,
address _recipient,
uint256 _amount
) external override requirePermission(_holder, _projectId, JBOperations.TRANSFER) {
// Get a reference to the current funding cycle for the project.
JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);
// Must not be paused.
if (_fundingCycle.global().pauseTransfers) revert TRANSFERS_PAUSED();
// Can't transfer to the zero address.
if (_recipient == address(0)) revert RECIPIENT_ZERO_ADDRESS();
// Get a reference to the holder's unclaimed project token balance.
uint256 _unclaimedBalance = unclaimedBalanceOf[_holder][_projectId];
// The holder must have enough unclaimed tokens to transfer.
if (_amount > _unclaimedBalance) revert INSUFFICIENT_UNCLAIMED_TOKENS();
// Subtract from the holder's unclaimed token balance.
unchecked {
unclaimedBalanceOf[_holder][_projectId] = _unclaimedBalance - _amount;
}
// Add the unclaimed project tokens to the recipient's balance.
unclaimedBalanceOf[_recipient][_projectId] =
unclaimedBalanceOf[_recipient][_projectId] +
_amount;
emit Transfer(_holder, _projectId, _recipient, _amount, msg.sender);
}
| String | Description |
|---|---|
RECIPIENT_ZERO_ADDRESS | Thrown if no recipient was speicified. |
INSUFFICIENT_UNCLAIMED_TOKENS | Thrown if the holder doesn't have enough tokens to transfer. |
TRANSFERS_PAUSED | Thrown if the project has paused transfers. |
| Name | Data |
|---|---|
Transfer |
|
| 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 |