From 67149d02cafe67bdfac70f249583ad3bb0b9fa9f Mon Sep 17 00:00:00 2001 From: CJ42 Date: Wed, 20 Sep 2023 18:28:39 +0100 Subject: [PATCH 1/3] refactor!: remove operator logic from internal `_burn` function --- .../LSP7DigitalAsset/LSP7DigitalAssetCore.sol | 108 +++++++++++------- .../extensions/LSP7Burnable.sol | 10 ++ .../extensions/LSP7BurnableInitAbstract.sol | 3 + .../LSP7DigitalAsset.behaviour.ts | 1 + 4 files changed, 82 insertions(+), 40 deletions(-) diff --git a/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol b/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol index f58222cd3..429f17347 100644 --- a/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +++ b/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol @@ -176,21 +176,12 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { ) public virtual { if (from == to) revert LSP7CannotSendToSelf(); - // if the caller is an operator if (msg.sender != from) { - uint256 operatorAmount = _operatorAuthorizedAmount[from][ - msg.sender - ]; - if (amount > operatorAmount) { - revert LSP7AmountExceedsAuthorizedAmount( - from, - operatorAmount, - msg.sender, - amount - ); - } - - _updateOperator(from, msg.sender, operatorAmount - amount, ""); + _spendAllowance({ + operator: msg.sender, + tokenOwner: from, + amountToSpend: amount + }); } _transfer(from, to, amount, force, data); @@ -237,8 +228,8 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { * This is an alternative approach to {authorizeOperator} that can be used as a mitigation * for the double spending allowance problem. * - * @param operator the operator to increase the allowance for `msg.sender` - * @param addedAmount the additional amount to add on top of the current operator's allowance + * @param operator The operator to increase the allowance for `msg.sender` + * @param addedAmount The additional amount to add on top of the current operator's allowance * * @custom:requirements * - `operator` cannot be the same address as `msg.sender` @@ -253,6 +244,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { ) public virtual { uint256 newAllowance = authorizedAmountFor(operator, msg.sender) + addedAmount; + _updateOperator( msg.sender, operator, @@ -284,8 +276,8 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { * - {RevokeOperator} event if `subtractedAmount` is the full allowance, * indicating `operator` does not have any alauthorizedAmountForlowance left for `msg.sender`. * - * @param operator the operator to decrease allowance for `msg.sender` - * @param subtractedAmount the amount to decrease by in the operator's allowance. + * @param operator The operator to decrease allowance for `msg.sender` + * @param substractedAmount The amount to decrease by in the operator's allowance. * * @custom:requirements * - `operator` cannot be the zero address. @@ -325,6 +317,10 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { * If the amount is zero the operator is removed from the list of operators, otherwise he is added to the list of operators. * If the amount is zero then the operator is being revoked, otherwise the operator amount is being modified. * + * @param tokenOwner The address that will give `operator` an allowance for on its balance. + * @param operator The address to grant an allowance to spend. + * @param allowance The maximum amount of token that `operator` can spend from the `tokenOwner`'s balance. + * * @custom:events * - {RevokedOperator} event when operator's allowance is set to `0`. * - {AuthorizedOperator} event when operator's allowance is set to any other amount. @@ -336,7 +332,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { function _updateOperator( address tokenOwner, address operator, - uint256 amount, + uint256 allowance, bytes memory operatorNotificationData ) internal virtual { if (operator == address(0)) { @@ -347,14 +343,14 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { revert LSP7TokenOwnerCannotBeOperator(); } - _operatorAuthorizedAmount[tokenOwner][operator] = amount; + _operatorAuthorizedAmount[tokenOwner][operator] = allowance; - if (amount != 0) { + if (allowance != 0) { _operators[tokenOwner].add(operator); emit AuthorizedOperator( operator, tokenOwner, - amount, + allowance, operatorNotificationData ); } else { @@ -440,24 +436,6 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { revert LSP7AmountExceedsBalance(balance, from, amount); } - // if the caller is an operator - if (msg.sender != from) { - uint256 authorizedAmount = _operatorAuthorizedAmount[from][ - msg.sender - ]; - if (amount > authorizedAmount) { - revert LSP7AmountExceedsAuthorizedAmount( - from, - authorizedAmount, - msg.sender, - amount - ); - } - _operatorAuthorizedAmount[from][msg.sender] = - authorizedAmount - - amount; - } - _beforeTokenTransfer(from, address(0), amount); // tokens being burnt @@ -466,11 +444,61 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { _tokenOwnerBalances[from] -= amount; emit Transfer(msg.sender, from, address(0), amount, false, data); + emit Transfer({ + operator: msg.sender, + from: from, + to: address(0), + amount: amount, + force: false, + data: data + }); bytes memory lsp1Data = abi.encode(from, address(0), amount, data); _notifyTokenSender(from, lsp1Data); } + /** + * @dev Spend `amount` from the `operator`'s authorized on behalf of the `tokenOwner`. + * + * @param operator The address of the operator to decrease the allowance of. + * @param tokenOwner The address that granted an allowance on its balance to `operator`. + * @param amountToSpend The amount of tokens to substract in allowance of `operator`. + * + * @custom:events + * - {RevokedOperator} event when operator's allowance is set to `0`. + * - {AuthorizedOperator} event when operator's allowance is set to any other amount. + * + * @custom:requirements + * - The `amountToSpend` MUST be at least the allowance granted to `operator` (accessible via {`authorizedAmountFor}`) + * - `operator` cannot be the zero address. + * - `operator` cannot be the same address as `tokenOwner`. + */ + function _spendAllowance( + address operator, + address tokenOwner, + uint256 amountToSpend + ) internal virtual { + uint256 authorizedAmount = _operatorAuthorizedAmount[tokenOwner][ + operator + ]; + + if (amountToSpend > authorizedAmount) { + revert LSP7AmountExceedsAuthorizedAmount( + tokenOwner, + authorizedAmount, + operator, + amountToSpend + ); + } + + _updateOperator({ + tokenOwner: tokenOwner, + operator: operator, + allowance: authorizedAmount - amountToSpend, + operatorNotificationData: "" + }); + } + /** * @dev Transfer tokens from `from` to `to` by decreasing the balance of `from` by `-amount` and increasing the balance * of `to` by `+amount`. diff --git a/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol b/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol index 40a2289f7..e1e3989e2 100644 --- a/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +++ b/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol @@ -4,6 +4,12 @@ pragma solidity ^0.8.4; // modules import {LSP7DigitalAsset} from "../LSP7DigitalAsset.sol"; +// errors +import { + LSP7AmountExceedsAuthorizedAmount, + LSP7CannotSendWithAddressZero +} from "../LSP7Errors.sol"; + /** * @title LSP7 token extension that allows token holders to destroy both * their own tokens and those that they have an allowance for as an operator. @@ -17,6 +23,10 @@ abstract contract LSP7Burnable is LSP7DigitalAsset { uint256 amount, bytes memory data ) public virtual { + if (msg.sender != from) { + _spendAllowance(msg.sender, from, amount); + } + _burn(from, amount, data); } } diff --git a/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol b/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol index 8dd541eb8..9915fafa7 100644 --- a/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +++ b/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol @@ -19,6 +19,9 @@ abstract contract LSP7BurnableInitAbstract is LSP7DigitalAssetInitAbstract { uint256 amount, bytes memory data ) public virtual { + if (msg.sender != from) { + _spendAllowance(msg.sender, from, amount); + } _burn(from, amount, data); } } diff --git a/tests/LSP7DigitalAsset/LSP7DigitalAsset.behaviour.ts b/tests/LSP7DigitalAsset/LSP7DigitalAsset.behaviour.ts index 5e57cc931..cba68b26a 100644 --- a/tests/LSP7DigitalAsset/LSP7DigitalAsset.behaviour.ts +++ b/tests/LSP7DigitalAsset/LSP7DigitalAsset.behaviour.ts @@ -1776,6 +1776,7 @@ export const shouldBehaveLikeLSP7 = (buildContext: () => Promise { describe('when using address(0) as `from` address', () => { it('should revert', async () => { From 1f985e3e018441a6d341b40419c1e5b88b56e255 Mon Sep 17 00:00:00 2001 From: CJ42 Date: Thu, 21 Sep 2023 10:06:28 +0100 Subject: [PATCH 2/3] test: add extra tests in LSP7 for transfers as operators --- .../LSP7DigitalAsset.behaviour.ts | 69 ++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/LSP7DigitalAsset/LSP7DigitalAsset.behaviour.ts b/tests/LSP7DigitalAsset/LSP7DigitalAsset.behaviour.ts index cba68b26a..da3dc0141 100644 --- a/tests/LSP7DigitalAsset/LSP7DigitalAsset.behaviour.ts +++ b/tests/LSP7DigitalAsset/LSP7DigitalAsset.behaviour.ts @@ -1785,7 +1785,14 @@ export const shouldBehaveLikeLSP7 = (buildContext: () => Promise Promise { + const operator = context.accounts.operator; + const amount = operatorAllowance; + + const operatorsList = await context.lsp7.getOperatorsOf(context.accounts.owner.address); + expect(operatorsList).to.include(operator.address); + + await context.lsp7.connect(operator).burn(context.accounts.owner.address, amount, '0x'); + + const updatedOperatorList = await context.lsp7.getOperatorsOf( + context.accounts.owner.address, + ); + expect(updatedOperatorList.length).to.equal(operatorsList.length - 1); + expect(updatedOperatorList).to.not.include(operator.address); + }); + it('token owner balance should have decreased', async () => { const operator = context.accounts.operator; const amount = operatorAllowance; @@ -1982,6 +2005,20 @@ export const shouldBehaveLikeLSP7 = (buildContext: () => Promise { + const operator = context.accounts.operator; + const amount = operatorAllowance; + + const operatorsList = await context.lsp7.getOperatorsOf(context.accounts.owner.address); + expect(operatorsList).to.include(operator.address); + + await expect( + context.lsp7.connect(operator).burn(context.accounts.owner.address, amount, '0x'), + ) + .to.emit(context.lsp7, 'RevokedOperator') + .withArgs(operator.address, context.accounts.owner.address, '0x'); + }); }); describe('when burning part of its allowance', () => { @@ -2005,6 +2042,18 @@ export const shouldBehaveLikeLSP7 = (buildContext: () => Promise { + const amount = 10; + assert.isBelow(amount, operatorAllowance); + + const operator = context.accounts.operator; + + await context.lsp7.connect(operator).burn(context.accounts.owner.address, amount, '0x'); + + const operatorsList = await context.lsp7.getOperatorsOf(context.accounts.owner.address); + expect(operatorsList).to.include(operator.address); + }); + it('token owner balance should have decreased', async () => { const amount = 10; assert.isBelow(amount, operatorAllowance); @@ -2050,6 +2099,24 @@ export const shouldBehaveLikeLSP7 = (buildContext: () => Promise { + const amount = 10; + assert.isBelow(amount, operatorAllowance); + + const operator = context.accounts.operator; + + await expect( + context.lsp7.connect(operator).burn(context.accounts.owner.address, amount, '0x'), + ) + .to.emit(context.lsp7, 'AuthorizedOperator') + .withArgs( + operator.address, + context.accounts.owner.address, + operatorAllowance - amount, + '0x', + ); + }); }); describe('when burning more than its allowance', () => { From 85690ed9cb0b3487c2ad7bcb4c7a124380592a78 Mon Sep 17 00:00:00 2001 From: CJ42 Date: Thu, 21 Sep 2023 10:16:26 +0100 Subject: [PATCH 3/3] docs: update Markdown docs for LSP7 --- .../LSP7DigitalAsset/LSP7DigitalAssetCore.sol | 4 +- .../extensions/LSP7Burnable.sol | 6 --- .../LSP7DigitalAsset/LSP7DigitalAsset.md | 41 ++++++++++++++++--- .../extensions/LSP7Burnable.md | 41 ++++++++++++++++--- .../extensions/LSP7CappedSupply.md | 41 ++++++++++++++++--- .../extensions/LSP7CompatibleERC20.md | 30 ++++++++++++-- .../presets/LSP7CompatibleERC20Mintable.md | 30 ++++++++++++-- .../LSP7DigitalAsset/presets/LSP7Mintable.md | 41 ++++++++++++++++--- 8 files changed, 198 insertions(+), 36 deletions(-) diff --git a/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol b/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol index 429f17347..4c9d2176d 100644 --- a/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +++ b/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol @@ -277,7 +277,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { * indicating `operator` does not have any alauthorizedAmountForlowance left for `msg.sender`. * * @param operator The operator to decrease allowance for `msg.sender` - * @param substractedAmount The amount to decrease by in the operator's allowance. + * @param subtractedAmount The amount to decrease by in the operator's allowance. * * @custom:requirements * - `operator` cannot be the zero address. @@ -458,7 +458,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { } /** - * @dev Spend `amount` from the `operator`'s authorized on behalf of the `tokenOwner`. + * @dev Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOwner`. * * @param operator The address of the operator to decrease the allowance of. * @param tokenOwner The address that granted an allowance on its balance to `operator`. diff --git a/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol b/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol index e1e3989e2..e95130639 100644 --- a/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +++ b/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol @@ -4,12 +4,6 @@ pragma solidity ^0.8.4; // modules import {LSP7DigitalAsset} from "../LSP7DigitalAsset.sol"; -// errors -import { - LSP7AmountExceedsAuthorizedAmount, - LSP7CannotSendWithAddressZero -} from "../LSP7Errors.sol"; - /** * @title LSP7 token extension that allows token holders to destroy both * their own tokens and those that they have an allowance for as an operator. diff --git a/docs/contracts/LSP7DigitalAsset/LSP7DigitalAsset.md b/docs/contracts/LSP7DigitalAsset/LSP7DigitalAsset.md index 9b93c0984..101dc5629 100644 --- a/docs/contracts/LSP7DigitalAsset/LSP7DigitalAsset.md +++ b/docs/contracts/LSP7DigitalAsset/LSP7DigitalAsset.md @@ -256,8 +256,8 @@ Atomically decreases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ------------------------------------------------------ | -| `operator` | `address` | the operator to decrease allowance for `msg.sender` | -| `subtractedAmount` | `uint256` | the amount to decrease by in the operator's allowance. | +| `operator` | `address` | The operator to decrease allowance for `msg.sender` | +| `subtractedAmount` | `uint256` | The amount to decrease by in the operator's allowance. | | `operatorNotificationData` | `bytes` | - |
@@ -411,8 +411,8 @@ Atomically increases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ----------------------------------------------------------------------- | -| `operator` | `address` | the operator to increase the allowance for `msg.sender` | -| `addedAmount` | `uint256` | the additional amount to add on top of the current operator's allowance | +| `operator` | `address` | The operator to increase the allowance for `msg.sender` | +| `addedAmount` | `uint256` | The additional amount to add on top of the current operator's allowance | | `operatorNotificationData` | `bytes` | - |
@@ -811,7 +811,7 @@ Save gas by emitting the [`DataChanged`](#datachanged) event with only the first function _updateOperator( address tokenOwner, address operator, - uint256 amount, + uint256 allowance, bytes operatorNotificationData ) internal nonpayable; ``` @@ -820,6 +820,15 @@ Changes token `amount` the `operator` has access to from `tokenOwner` tokens. If the amount is zero the operator is removed from the list of operators, otherwise he is added to the list of operators. If the amount is zero then the operator is being revoked, otherwise the operator amount is being modified. +#### Parameters + +| Name | Type | Description | +| -------------------------- | :-------: | -------------------------------------------------------------------------------------- | +| `tokenOwner` | `address` | The address that will give `operator` an allowance for on its balance. | +| `operator` | `address` | The address to grant an allowance to spend. | +| `allowance` | `uint256` | The maximum amount of token that `operator` can spend from the `tokenOwner`'s balance. | +| `operatorNotificationData` | `bytes` | - | +
### \_mint @@ -890,6 +899,28 @@ Any logic in the [`_beforeTokenTransfer`](#_beforetokentransfer) function will r
+### \_spendAllowance + +```solidity +function _spendAllowance( + address operator, + address tokenOwner, + uint256 amountToSpend +) internal nonpayable; +``` + +Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOwner`. + +#### Parameters + +| Name | Type | Description | +| --------------- | :-------: | ------------------------------------------------------------------- | +| `operator` | `address` | The address of the operator to decrease the allowance of. | +| `tokenOwner` | `address` | The address that granted an allowance on its balance to `operator`. | +| `amountToSpend` | `uint256` | The amount of tokens to substract in allowance of `operator`. | + +
+ ### \_transfer ```solidity diff --git a/docs/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.md b/docs/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.md index 791796c97..2a2652731 100644 --- a/docs/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.md +++ b/docs/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.md @@ -281,8 +281,8 @@ Atomically decreases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ------------------------------------------------------ | -| `operator` | `address` | the operator to decrease allowance for `msg.sender` | -| `subtractedAmount` | `uint256` | the amount to decrease by in the operator's allowance. | +| `operator` | `address` | The operator to decrease allowance for `msg.sender` | +| `subtractedAmount` | `uint256` | The amount to decrease by in the operator's allowance. | | `operatorNotificationData` | `bytes` | - |
@@ -436,8 +436,8 @@ Atomically increases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ----------------------------------------------------------------------- | -| `operator` | `address` | the operator to increase the allowance for `msg.sender` | -| `addedAmount` | `uint256` | the additional amount to add on top of the current operator's allowance | +| `operator` | `address` | The operator to increase the allowance for `msg.sender` | +| `addedAmount` | `uint256` | The additional amount to add on top of the current operator's allowance | | `operatorNotificationData` | `bytes` | - |
@@ -836,7 +836,7 @@ Save gas by emitting the [`DataChanged`](#datachanged) event with only the first function _updateOperator( address tokenOwner, address operator, - uint256 amount, + uint256 allowance, bytes operatorNotificationData ) internal nonpayable; ``` @@ -845,6 +845,15 @@ Changes token `amount` the `operator` has access to from `tokenOwner` tokens. If the amount is zero the operator is removed from the list of operators, otherwise he is added to the list of operators. If the amount is zero then the operator is being revoked, otherwise the operator amount is being modified. +#### Parameters + +| Name | Type | Description | +| -------------------------- | :-------: | -------------------------------------------------------------------------------------- | +| `tokenOwner` | `address` | The address that will give `operator` an allowance for on its balance. | +| `operator` | `address` | The address to grant an allowance to spend. | +| `allowance` | `uint256` | The maximum amount of token that `operator` can spend from the `tokenOwner`'s balance. | +| `operatorNotificationData` | `bytes` | - | +
### \_mint @@ -915,6 +924,28 @@ Any logic in the [`_beforeTokenTransfer`](#_beforetokentransfer) function will r
+### \_spendAllowance + +```solidity +function _spendAllowance( + address operator, + address tokenOwner, + uint256 amountToSpend +) internal nonpayable; +``` + +Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOwner`. + +#### Parameters + +| Name | Type | Description | +| --------------- | :-------: | ------------------------------------------------------------------- | +| `operator` | `address` | The address of the operator to decrease the allowance of. | +| `tokenOwner` | `address` | The address that granted an allowance on its balance to `operator`. | +| `amountToSpend` | `uint256` | The amount of tokens to substract in allowance of `operator`. | + +
+ ### \_transfer ```solidity diff --git a/docs/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.md b/docs/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.md index 51e5e5e61..cc2501eae 100644 --- a/docs/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.md +++ b/docs/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.md @@ -254,8 +254,8 @@ Atomically decreases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ------------------------------------------------------ | -| `operator` | `address` | the operator to decrease allowance for `msg.sender` | -| `subtractedAmount` | `uint256` | the amount to decrease by in the operator's allowance. | +| `operator` | `address` | The operator to decrease allowance for `msg.sender` | +| `subtractedAmount` | `uint256` | The amount to decrease by in the operator's allowance. | | `operatorNotificationData` | `bytes` | - |
@@ -409,8 +409,8 @@ Atomically increases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ----------------------------------------------------------------------- | -| `operator` | `address` | the operator to increase the allowance for `msg.sender` | -| `addedAmount` | `uint256` | the additional amount to add on top of the current operator's allowance | +| `operator` | `address` | The operator to increase the allowance for `msg.sender` | +| `addedAmount` | `uint256` | The additional amount to add on top of the current operator's allowance | | `operatorNotificationData` | `bytes` | - |
@@ -836,7 +836,7 @@ Save gas by emitting the [`DataChanged`](#datachanged) event with only the first function _updateOperator( address tokenOwner, address operator, - uint256 amount, + uint256 allowance, bytes operatorNotificationData ) internal nonpayable; ``` @@ -845,6 +845,15 @@ Changes token `amount` the `operator` has access to from `tokenOwner` tokens. If the amount is zero the operator is removed from the list of operators, otherwise he is added to the list of operators. If the amount is zero then the operator is being revoked, otherwise the operator amount is being modified. +#### Parameters + +| Name | Type | Description | +| -------------------------- | :-------: | -------------------------------------------------------------------------------------- | +| `tokenOwner` | `address` | The address that will give `operator` an allowance for on its balance. | +| `operator` | `address` | The address to grant an allowance to spend. | +| `allowance` | `uint256` | The maximum amount of token that `operator` can spend from the `tokenOwner`'s balance. | +| `operatorNotificationData` | `bytes` | - | +
### \_mint @@ -899,6 +908,28 @@ Any logic in the [`_beforeTokenTransfer`](#_beforetokentransfer) function will r
+### \_spendAllowance + +```solidity +function _spendAllowance( + address operator, + address tokenOwner, + uint256 amountToSpend +) internal nonpayable; +``` + +Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOwner`. + +#### Parameters + +| Name | Type | Description | +| --------------- | :-------: | ------------------------------------------------------------------- | +| `operator` | `address` | The address of the operator to decrease the allowance of. | +| `tokenOwner` | `address` | The address that granted an allowance on its balance to `operator`. | +| `amountToSpend` | `uint256` | The amount of tokens to substract in allowance of `operator`. | + +
+ ### \_transfer ```solidity diff --git a/docs/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.md b/docs/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.md index 649bc8d60..b5892952b 100644 --- a/docs/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.md +++ b/docs/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.md @@ -320,8 +320,8 @@ Atomically decreases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ------------------------------------------------------ | -| `operator` | `address` | the operator to decrease allowance for `msg.sender` | -| `subtractedAmount` | `uint256` | the amount to decrease by in the operator's allowance. | +| `operator` | `address` | The operator to decrease allowance for `msg.sender` | +| `subtractedAmount` | `uint256` | The amount to decrease by in the operator's allowance. | | `operatorNotificationData` | `bytes` | - |
@@ -475,8 +475,8 @@ Atomically increases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ----------------------------------------------------------------------- | -| `operator` | `address` | the operator to increase the allowance for `msg.sender` | -| `addedAmount` | `uint256` | the additional amount to add on top of the current operator's allowance | +| `operator` | `address` | The operator to increase the allowance for `msg.sender` | +| `addedAmount` | `uint256` | The additional amount to add on top of the current operator's allowance | | `operatorNotificationData` | `bytes` | - |
@@ -1031,6 +1031,28 @@ function _burn(address from, uint256 amount, bytes data) internal nonpayable;
+### \_spendAllowance + +```solidity +function _spendAllowance( + address operator, + address tokenOwner, + uint256 amountToSpend +) internal nonpayable; +``` + +Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOwner`. + +#### Parameters + +| Name | Type | Description | +| --------------- | :-------: | ------------------------------------------------------------------- | +| `operator` | `address` | The address of the operator to decrease the allowance of. | +| `tokenOwner` | `address` | The address that granted an allowance on its balance to `operator`. | +| `amountToSpend` | `uint256` | The amount of tokens to substract in allowance of `operator`. | + +
+ ### \_transfer ```solidity diff --git a/docs/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.md b/docs/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.md index e14dbe18d..8a5d97d56 100644 --- a/docs/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.md +++ b/docs/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.md @@ -321,8 +321,8 @@ Atomically decreases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ------------------------------------------------------ | -| `operator` | `address` | the operator to decrease allowance for `msg.sender` | -| `subtractedAmount` | `uint256` | the amount to decrease by in the operator's allowance. | +| `operator` | `address` | The operator to decrease allowance for `msg.sender` | +| `subtractedAmount` | `uint256` | The amount to decrease by in the operator's allowance. | | `operatorNotificationData` | `bytes` | - |
@@ -476,8 +476,8 @@ Atomically increases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ----------------------------------------------------------------------- | -| `operator` | `address` | the operator to increase the allowance for `msg.sender` | -| `addedAmount` | `uint256` | the additional amount to add on top of the current operator's allowance | +| `operator` | `address` | The operator to increase the allowance for `msg.sender` | +| `addedAmount` | `uint256` | The additional amount to add on top of the current operator's allowance | | `operatorNotificationData` | `bytes` | - |
@@ -1065,6 +1065,28 @@ function _burn(address from, uint256 amount, bytes data) internal nonpayable;
+### \_spendAllowance + +```solidity +function _spendAllowance( + address operator, + address tokenOwner, + uint256 amountToSpend +) internal nonpayable; +``` + +Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOwner`. + +#### Parameters + +| Name | Type | Description | +| --------------- | :-------: | ------------------------------------------------------------------- | +| `operator` | `address` | The address of the operator to decrease the allowance of. | +| `tokenOwner` | `address` | The address that granted an allowance on its balance to `operator`. | +| `amountToSpend` | `uint256` | The amount of tokens to substract in allowance of `operator`. | + +
+ ### \_transfer ```solidity diff --git a/docs/contracts/LSP7DigitalAsset/presets/LSP7Mintable.md b/docs/contracts/LSP7DigitalAsset/presets/LSP7Mintable.md index c3f22bcc6..b9de110e4 100644 --- a/docs/contracts/LSP7DigitalAsset/presets/LSP7Mintable.md +++ b/docs/contracts/LSP7DigitalAsset/presets/LSP7Mintable.md @@ -285,8 +285,8 @@ Atomically decreases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ------------------------------------------------------ | -| `operator` | `address` | the operator to decrease allowance for `msg.sender` | -| `subtractedAmount` | `uint256` | the amount to decrease by in the operator's allowance. | +| `operator` | `address` | The operator to decrease allowance for `msg.sender` | +| `subtractedAmount` | `uint256` | The amount to decrease by in the operator's allowance. | | `operatorNotificationData` | `bytes` | - |
@@ -440,8 +440,8 @@ Atomically increases the allowance granted to `operator` by the caller. This is | Name | Type | Description | | -------------------------- | :-------: | ----------------------------------------------------------------------- | -| `operator` | `address` | the operator to increase the allowance for `msg.sender` | -| `addedAmount` | `uint256` | the additional amount to add on top of the current operator's allowance | +| `operator` | `address` | The operator to increase the allowance for `msg.sender` | +| `addedAmount` | `uint256` | The additional amount to add on top of the current operator's allowance | | `operatorNotificationData` | `bytes` | - |
@@ -873,7 +873,7 @@ Save gas by emitting the [`DataChanged`](#datachanged) event with only the first function _updateOperator( address tokenOwner, address operator, - uint256 amount, + uint256 allowance, bytes operatorNotificationData ) internal nonpayable; ``` @@ -882,6 +882,15 @@ Changes token `amount` the `operator` has access to from `tokenOwner` tokens. If the amount is zero the operator is removed from the list of operators, otherwise he is added to the list of operators. If the amount is zero then the operator is being revoked, otherwise the operator amount is being modified. +#### Parameters + +| Name | Type | Description | +| -------------------------- | :-------: | -------------------------------------------------------------------------------------- | +| `tokenOwner` | `address` | The address that will give `operator` an allowance for on its balance. | +| `operator` | `address` | The address to grant an allowance to spend. | +| `allowance` | `uint256` | The maximum amount of token that `operator` can spend from the `tokenOwner`'s balance. | +| `operatorNotificationData` | `bytes` | - | +
### \_mint @@ -952,6 +961,28 @@ Any logic in the [`_beforeTokenTransfer`](#_beforetokentransfer) function will r
+### \_spendAllowance + +```solidity +function _spendAllowance( + address operator, + address tokenOwner, + uint256 amountToSpend +) internal nonpayable; +``` + +Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOwner`. + +#### Parameters + +| Name | Type | Description | +| --------------- | :-------: | ------------------------------------------------------------------- | +| `operator` | `address` | The address of the operator to decrease the allowance of. | +| `tokenOwner` | `address` | The address that granted an allowance on its balance to `operator`. | +| `amountToSpend` | `uint256` | The amount of tokens to substract in allowance of `operator`. | + +
+ ### \_transfer ```solidity