Skip to content

Commit

Permalink
Merge pull request #723 from lukso-network/DEV-8049
Browse files Browse the repository at this point in the history
refactor!: change back parameter name from `allowNonLSP1Recipient` to `force`
  • Loading branch information
CJ42 authored Sep 19, 2023
2 parents 3f6d323 + 384caeb commit aaa4e9d
Show file tree
Hide file tree
Showing 54 changed files with 844 additions and 931 deletions.
18 changes: 9 additions & 9 deletions contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
* @param from The address which tokens were sent from (balance decreased by `-amount`).
* @param to The address that received the tokens (balance increased by `+amount`).
* @param amount The amount of tokens transferred.
* @param allowNonLSP1Recipient if the transferred enforced the `to` recipient address to be a contract that implements the LSP1 standard or not.
* @param force if the transferred enforced the `to` recipient address to be a contract that implements the LSP1 standard or not.
* @param data Any additional data included by the caller during the transfer, and sent in the LSP1 hooks to the `from` and `to` addresses.
*/
event Transfer(
address indexed operator,
address indexed from,
address indexed to,
uint256 amount,
bool allowNonLSP1Recipient,
bool force,
bytes data
);

Expand Down Expand Up @@ -173,7 +173,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
* @param from The sender address.
* @param to The recipient address.
* @param amount The amount of tokens to transfer.
* @param allowNonLSP1Recipient When set to `true`, the `to` address CAN be any address. When set to `false`, the `to` address MUST be a contract that supports the LSP1 UniversalReceiver standard.
* @param force When set to `true`, the `to` address CAN be any address. When set to `false`, the `to` address MUST be a contract that supports the LSP1 UniversalReceiver standard.
* @param data Any additional data the caller wants included in the emitted event, and sent in the hooks of the `from` and `to` addresses.
*
* @custom:requirements
Expand All @@ -188,19 +188,19 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
* - if the transfer is triggered by an operator, either the {AuthorizedOperator} event will be emitted with the updated allowance or the {RevokedOperator}
* event will be emitted if the operator has no more allowance left.
*
* @custom:hint The `allowNonLSP1Recipient` parameter **MUST be set to `true`** to transfer tokens to Externally Owned Accounts (EOAs)
* @custom:hint The `force` parameter **MUST be set to `true`** to transfer tokens to Externally Owned Accounts (EOAs)
* or contracts that do not implement the LSP1 Universal Receiver Standard. Otherwise the function will revert making the transfer fail.
*
* @custom:info if the `to` address is a contract that implements LSP1, it will always be notified via its `universalReceiver(...)` function, regardless if `allowNonLSP1Recipient` is set to `true` or `false`.
* @custom:info if the `to` address is a contract that implements LSP1, it will always be notified via its `universalReceiver(...)` function, regardless if `force` is set to `true` or `false`.
*
* @custom:warning Be aware that when either the sender or the recipient can have logic that revert in their `universalReceiver(...)` function when being notified.
* This even if the `allowNonLSP1Recipient` was set to `true`.
* This even if the `force` was set to `true`.
*/
function transfer(
address from,
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bool force,
bytes memory data
) external;

Expand All @@ -212,7 +212,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
* @param from An array of sending addresses.
* @param to An array of receiving addresses.
* @param amount An array of amount of tokens to transfer for each `from -> to` transfer.
* @param allowNonLSP1Recipient For each transfer, when set to `true`, the `to` address CAN be any address. When set to `false`, the `to` address MUST be a contract that supports the LSP1 UniversalReceiver standard.
* @param force For each transfer, when set to `true`, the `to` address CAN be any address. When set to `false`, the `to` address MUST be a contract that supports the LSP1 UniversalReceiver standard.
* @param data An array of additional data the caller wants included in the emitted event, and sent in the hooks to `from` and `to` addresses.
*
* @custom:requirements
Expand All @@ -228,7 +228,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
address[] memory from,
address[] memory to,
uint256[] memory amount,
bool[] memory allowNonLSP1Recipient,
bool[] memory force,
bytes[] memory data
) external;
}
67 changes: 27 additions & 40 deletions contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
address from,
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bool force,
bytes memory data
) public virtual {
if (from == to) revert LSP7CannotSendToSelf();
Expand All @@ -191,7 +191,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
_updateOperator(from, operator, operatorAmount - amount, "");
}

_transfer(from, to, amount, allowNonLSP1Recipient, data);
_transfer(from, to, amount, force, data);
}

/**
Expand All @@ -201,28 +201,22 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
address[] memory from,
address[] memory to,
uint256[] memory amount,
bool[] memory allowNonLSP1Recipient,
bool[] memory force,
bytes[] memory data
) public virtual {
uint256 fromLength = from.length;
if (
fromLength != to.length ||
fromLength != amount.length ||
fromLength != allowNonLSP1Recipient.length ||
fromLength != force.length ||
fromLength != data.length
) {
revert LSP7InvalidTransferBatch();
}

for (uint256 i = 0; i < fromLength; ) {
// using the public transfer function to handle updates to operator authorized amounts
transfer(
from[i],
to[i],
amount[i],
allowNonLSP1Recipient[i],
data[i]
);
transfer(from[i], to[i], amount[i], force[i], data[i]);

unchecked {
++i;
Expand Down Expand Up @@ -374,9 +368,9 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
/**
* @dev Mints `amount` of tokens and transfers it to `to`.
*
* @param to the address to mint tokens for.
* @param amount the amount of tokens to mint.
* @param allowNonLSP1Recipient a boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
* @param to The address to mint tokens for.
* @param amount The amount of tokens to mint.
* @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
* @param data Additional data the caller wants included in the emitted {Transfer} event, and sent in the LSP1 hook to the `to` address.
*
* @custom:requirements
Expand All @@ -387,7 +381,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
function _mint(
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bool force,
bytes memory data
) internal virtual {
if (to == address(0)) {
Expand All @@ -403,17 +397,10 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {

_tokenOwnerBalances[to] += amount;

emit Transfer(
operator,
address(0),
to,
amount,
allowNonLSP1Recipient,
data
);
emit Transfer(operator, address(0), to, amount, force, data);

bytes memory lsp1Data = abi.encode(address(0), to, amount, data);
_notifyTokenReceiver(to, allowNonLSP1Recipient, lsp1Data);
_notifyTokenReceiver(to, force, lsp1Data);
}

/**
Expand All @@ -425,8 +412,8 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
*
* Any logic in the {_beforeTokenTransfer} function will run before updating the balances.
*
* @param from the address to burn tokens from its balance.
* @param amount the amount of tokens to burn.
* @param from The address to burn tokens from its balance.
* @param amount The amount of tokens to burn.
* @param data Additional data the caller wants included in the emitted event, and sent in the LSP1 hook to the `from` and `to` address.
*
* @custom:hint In dApps, you can know which address is burning tokens by listening for the `Transfer` event and filter with the zero address as `to`.
Expand Down Expand Up @@ -492,10 +479,10 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
*
* Any logic in the {_beforeTokenTransfer} function will run before updating the balances.
*
* @param from the address to decrease the balance.
* @param to the address to increase the balance.
* @param amount the amount of tokens to transfer from `from` to `to`.
* @param allowNonLSP1Recipient a boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
* @param from The address to decrease the balance.
* @param to The address to increase the balance.
* @param amount The amount of tokens to transfer from `from` to `to`.
* @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
* @param data Additional data the caller wants included in the emitted event, and sent in the LSP1 hook to the `from` and `to` address.
*
* @custom:requirements
Expand All @@ -509,7 +496,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
address from,
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bool force,
bytes memory data
) internal virtual {
if (from == address(0) || to == address(0)) {
Expand All @@ -528,12 +515,12 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
_tokenOwnerBalances[from] -= amount;
_tokenOwnerBalances[to] += amount;

emit Transfer(operator, from, to, amount, allowNonLSP1Recipient, data);
emit Transfer(operator, from, to, amount, force, data);

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

_notifyTokenSender(from, lsp1Data);
_notifyTokenReceiver(to, allowNonLSP1Recipient, lsp1Data);
_notifyTokenReceiver(to, force, lsp1Data);
}

/**
Expand Down Expand Up @@ -607,17 +594,17 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
* @dev Attempt to notify the token receiver `to` about the `amount` tokens being received.
* This is done by calling its {universalReceiver} function with the `_TYPEID_LSP7_TOKENSRECIPIENT` as typeId, if `to` is a contract that supports the LSP1 interface.
*
* If `to` is is an EOA or a contract that does not support the LSP1 interface, the behaviour will depend on the `allowNonLSP1Recipient` boolean flag.
* - if `allowNonLSP1Recipient` is set to `true`, nothing will happen and no notification will be sent.
* - if `allowNonLSP1Recipient` is set to `false, the transaction will revert.
* If `to` is is an EOA or a contract that does not support the LSP1 interface, the behaviour will depend on the `force` boolean flag.
* - if `force` is set to `true`, nothing will happen and no notification will be sent.
* - if `force` is set to `false, the transaction will revert.
*
* @param to The address to call the {universalReceiver} function on.
* @param allowNonLSP1Recipient a boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
* @param lsp1Data the data to be sent to the `to` address in the `universalReceiver(...)` call.
* @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
* @param lsp1Data The data to be sent to the `to` address in the `universalReceiver(...)` call.
*/
function _notifyTokenReceiver(
address to,
bool allowNonLSP1Recipient,
bool force,
bytes memory lsp1Data
) internal virtual {
if (
Expand All @@ -630,7 +617,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
_TYPEID_LSP7_TOKENSRECIPIENT,
lsp1Data
);
} else if (!allowNonLSP1Recipient) {
} else if (!force) {
if (to.code.length > 0) {
revert LSP7NotifyTokenReceiverContractMissingLSP1Interface(to);
} else {
Expand Down
4 changes: 2 additions & 2 deletions contracts/LSP7DigitalAsset/LSP7Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ error LSP7InvalidTransferBatch();

/**
* @dev reverts if the `tokenReceiver` does not implement LSP1
* when minting or transferring tokens with `bool allowNonLSP1Recipient` set as `false`.
* when minting or transferring tokens with `bool force` set as `false`.
*/
error LSP7NotifyTokenReceiverContractMissingLSP1Interface(
address tokenReceiver
);

/**
* @dev reverts if the `tokenReceiver` is an EOA when minting or transferring tokens with `bool allowNonLSP1Recipient` set as `false`.
* @dev reverts if the `tokenReceiver` is an EOA when minting or transferring tokens with `bool force` set as `false`.
*/
error LSP7NotifyTokenReceiverIsEOA(address tokenReceiver);

Expand Down
4 changes: 2 additions & 2 deletions contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ abstract contract LSP7CappedSupply is LSP7DigitalAsset {
function _mint(
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bool force,
bytes memory data
) internal virtual override {
if (totalSupply() + amount > tokenSupplyCap()) {
revert LSP7CappedSupplyCannotMintOverCap();
}

super._mint(to, amount, allowNonLSP1Recipient, data);
super._mint(to, amount, force, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ abstract contract LSP7CappedSupplyInitAbstract is LSP7DigitalAssetInitAbstract {
function _mint(
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bool force,
bytes memory data
) internal virtual override {
if (totalSupply() + amount > tokenSupplyCap()) {
revert LSP7CappedSupplyCannotMintOverCap();
}

super._mint(to, amount, allowNonLSP1Recipient, data);
super._mint(to, amount, force, data);
}
}
12 changes: 6 additions & 6 deletions contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ abstract contract LSP7CompatibleERC20 is
/**
* @inheritdoc ILSP7CompatibleERC20
*
* @custom:info This function uses the `allowNonLSP1Recipient` parameter as `true` so that EOA and any contract can receive tokens.
* @custom:info This function uses the `force` parameter as `true` so that EOA and any contract can receive tokens.
*/
function transferFrom(
address from,
Expand All @@ -92,7 +92,7 @@ abstract contract LSP7CompatibleERC20 is
/**
* @inheritdoc ILSP7CompatibleERC20
*
* @custom:info This function uses the `allowNonLSP1Recipient` parameter as `true` so that EOA and any contract can receive tokens.
* @custom:info This function uses the `force` parameter as `true` so that EOA and any contract can receive tokens.
*/
function transfer(
address to,
Expand Down Expand Up @@ -126,11 +126,11 @@ abstract contract LSP7CompatibleERC20 is
address from,
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bool force,
bytes memory data
) internal virtual override {
emit Transfer(from, to, amount);
super._transfer(from, to, amount, allowNonLSP1Recipient, data);
super._transfer(from, to, amount, force, data);
}

/**
Expand All @@ -141,11 +141,11 @@ abstract contract LSP7CompatibleERC20 is
function _mint(
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bool force,
bytes memory data
) internal virtual override {
emit Transfer(address(0), to, amount);
super._mint(to, amount, allowNonLSP1Recipient, data);
super._mint(to, amount, force, data);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ abstract contract LSP7CompatibleERC20InitAbstract is
/**
* @inheritdoc ILSP7CompatibleERC20
*
* @custom:info This function uses the `allowNonLSP1Recipient` parameter as `true` so that EOA and any contract can receive tokens.
* @custom:info This function uses the `force` parameter as `true` so that EOA and any contract can receive tokens.
*/
function transferFrom(
address from,
Expand All @@ -99,7 +99,7 @@ abstract contract LSP7CompatibleERC20InitAbstract is
/**
* @inheritdoc ILSP7CompatibleERC20
*
* @custom:info This function uses the `allowNonLSP1Recipient` parameter as `true` so that EOA and any contract can receive tokens.
* @custom:info This function uses the `force` parameter as `true` so that EOA and any contract can receive tokens.
*/
function transfer(
address to,
Expand Down Expand Up @@ -133,11 +133,11 @@ abstract contract LSP7CompatibleERC20InitAbstract is
address from,
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bool force,
bytes memory data
) internal virtual override {
emit Transfer(from, to, amount);
super._transfer(from, to, amount, allowNonLSP1Recipient, data);
super._transfer(from, to, amount, force, data);
}

/**
Expand All @@ -148,11 +148,11 @@ abstract contract LSP7CompatibleERC20InitAbstract is
function _mint(
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bool force,
bytes memory data
) internal virtual override {
emit Transfer(address(0), to, amount);
super._mint(to, amount, allowNonLSP1Recipient, data);
super._mint(to, amount, force, data);
}

/**
Expand Down
Loading

0 comments on commit aaa4e9d

Please sign in to comment.