Skip to content

Commit

Permalink
feat: add force to internal functions LSP7
Browse files Browse the repository at this point in the history
  • Loading branch information
skimaharvey authored and CJ42 committed Jan 9, 2025
1 parent 06c9703 commit a402e74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
18 changes: 11 additions & 7 deletions packages/lsp7-contracts/contracts/LSP7DigitalAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ abstract contract LSP7DigitalAsset is
revert LSP7CannotSendWithAddressZero();
}

_beforeTokenTransfer(address(0), to, amount, data);
_beforeTokenTransfer(address(0), to, amount, force, data);

// tokens being minted
_existingTokens += amount;
Expand All @@ -616,7 +616,7 @@ abstract contract LSP7DigitalAsset is
data: data
});

_afterTokenTransfer(address(0), to, amount, data);
_afterTokenTransfer(address(0), to, amount, force, data);

bytes memory lsp1Data = abi.encode(
msg.sender,
Expand Down Expand Up @@ -662,7 +662,7 @@ abstract contract LSP7DigitalAsset is
revert LSP7CannotSendWithAddressZero();
}

_beforeTokenTransfer(from, address(0), amount, data);
_beforeTokenTransfer(from, address(0), amount, false, data);

uint256 balance = _tokenOwnerBalances[from];
if (amount > balance) {
Expand All @@ -682,7 +682,7 @@ abstract contract LSP7DigitalAsset is
data: data
});

_afterTokenTransfer(from, address(0), amount, data);
_afterTokenTransfer(from, address(0), amount, false, data);

bytes memory lsp1Data = abi.encode(
msg.sender,
Expand Down Expand Up @@ -773,11 +773,11 @@ abstract contract LSP7DigitalAsset is
revert LSP7CannotSendWithAddressZero();
}

_beforeTokenTransfer(from, to, amount, data);
_beforeTokenTransfer(from, to, amount, force, data);

_update(from, to, amount, force, data);

_afterTokenTransfer(from, to, amount, data);
_afterTokenTransfer(from, to, amount, force, data);

bytes memory lsp1Data = abi.encode(msg.sender, from, to, amount, data);

Expand Down Expand Up @@ -834,7 +834,7 @@ abstract contract LSP7DigitalAsset is
data: data
});

_afterTokenTransfer(from, to, amount, data);
_afterTokenTransfer(from, to, amount, force, data);

bytes memory lsp1Data = abi.encode(msg.sender, from, to, amount, data);

Expand All @@ -849,12 +849,14 @@ abstract contract LSP7DigitalAsset is
* @param from The sender address
* @param to The recipient address
* @param amount The amount of token to transfer
* @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
* @param data The data sent alongside the transfer
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount,
bool force,
bytes memory data // solhint-disable-next-line no-empty-blocks
) internal virtual {}

Expand All @@ -865,12 +867,14 @@ abstract contract LSP7DigitalAsset is
* @param from The sender address
* @param to The recipient address
* @param amount The amount of token to transfer
* @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
* @param data The data sent alongside the transfer
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount,
bool force,
bytes memory data // solhint-disable-next-line no-empty-blocks
) internal virtual {}

Expand Down
18 changes: 11 additions & 7 deletions packages/lsp7-contracts/contracts/LSP7DigitalAssetInitAbstract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ abstract contract LSP7DigitalAssetInitAbstract is
revert LSP7CannotSendWithAddressZero();
}

_beforeTokenTransfer(address(0), to, amount, data);
_beforeTokenTransfer(address(0), to, amount, force, data);

// tokens being minted
_existingTokens += amount;
Expand All @@ -629,7 +629,7 @@ abstract contract LSP7DigitalAssetInitAbstract is
data: data
});

_afterTokenTransfer(address(0), to, amount, data);
_afterTokenTransfer(address(0), to, amount, force, data);

bytes memory lsp1Data = abi.encode(
msg.sender,
Expand Down Expand Up @@ -675,7 +675,7 @@ abstract contract LSP7DigitalAssetInitAbstract is
revert LSP7CannotSendWithAddressZero();
}

_beforeTokenTransfer(from, address(0), amount, data);
_beforeTokenTransfer(from, address(0), amount, false, data);

uint256 balance = _tokenOwnerBalances[from];
if (amount > balance) {
Expand All @@ -695,7 +695,7 @@ abstract contract LSP7DigitalAssetInitAbstract is
data: data
});

_afterTokenTransfer(from, address(0), amount, data);
_afterTokenTransfer(from, address(0), amount, false, data);

bytes memory lsp1Data = abi.encode(
msg.sender,
Expand Down Expand Up @@ -786,11 +786,11 @@ abstract contract LSP7DigitalAssetInitAbstract is
revert LSP7CannotSendWithAddressZero();
}

_beforeTokenTransfer(from, to, amount, data);
_beforeTokenTransfer(from, to, amount, force, data);

_update(from, to, amount, force, data);

_afterTokenTransfer(from, to, amount, data);
_afterTokenTransfer(from, to, amount, force, data);

bytes memory lsp1Data = abi.encode(msg.sender, from, to, amount, data);

Expand Down Expand Up @@ -847,7 +847,7 @@ abstract contract LSP7DigitalAssetInitAbstract is
data: data
});

_afterTokenTransfer(from, to, amount, data);
_afterTokenTransfer(from, to, amount, force, data);

bytes memory lsp1Data = abi.encode(msg.sender, from, to, amount, data);

Expand All @@ -862,12 +862,14 @@ abstract contract LSP7DigitalAssetInitAbstract is
* @param from The sender address
* @param to The recipient address
* @param amount The amount of token to transfer
* @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
* @param data The data sent alongside the transfer
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount,
bool force,
bytes memory data // solhint-disable-next-line no-empty-blocks
) internal virtual {}

Expand All @@ -878,12 +880,14 @@ abstract contract LSP7DigitalAssetInitAbstract is
* @param from The sender address
* @param to The recipient address
* @param amount The amount of token to transfer
* @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
* @param data The data sent alongside the transfer
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount,
bool force,
bytes memory data // solhint-disable-next-line no-empty-blocks
) internal virtual {}

Expand Down

0 comments on commit a402e74

Please sign in to comment.