Skip to content

Commit

Permalink
docs: update tokens docs for _afterTokenTransfer hook
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Oct 10, 2023
1 parent 4e3adc2 commit 2b475b2
Show file tree
Hide file tree
Showing 13 changed files with 549 additions and 24 deletions.
55 changes: 53 additions & 2 deletions docs/contracts/LSP7DigitalAsset/LSP7DigitalAsset.md
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,16 @@ If the amount is zero then the operator is being revoked, otherwise the operator

### \_mint

:::info

Any logic in the:

- {\_beforeTokenTransfer} function will run before updating the balances.

- {\_afterTokenTransfer} function will run after updating the balances, **but before notifying the recipient via LSP1**.

:::

```solidity
function _mint(
address to,
Expand Down Expand Up @@ -865,6 +875,16 @@ Mints `amount` of tokens and transfers it to `to`.

### \_burn

:::info

Any logic in the:

- {\_beforeTokenTransfer} function will run before updating the balances.

- {\_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender via LSP1**.

:::

:::tip 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 All @@ -879,7 +899,6 @@ Burns (= destroys) `amount` of tokens, decrease the `from` balance. This is done
Both the sender and recipient will be notified of the token transfer through the LSP1 [`universalReceiver`](#universalreceiver)
function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
all the parameters in the calldata packed encoded.
Any logic in the [`_beforeTokenTransfer`](#_beforetokentransfer) function will run before updating the balances.

<blockquote>

Expand Down Expand Up @@ -923,6 +942,16 @@ Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOw

### \_transfer

:::info

Any logic in the:

- {\_beforeTokenTransfer} function will run before updating the balances.

- {\_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender/recipient via LSP1**.

:::

```solidity
function _transfer(
address from,
Expand All @@ -938,7 +967,6 @@ of `to` by `+amount`.
Both the sender and recipient will be notified of the token transfer through the LSP1 [`universalReceiver`](#universalreceiver)
function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
all the parameters in the calldata packed encoded.
Any logic in the [`_beforeTokenTransfer`](#_beforetokentransfer) function will run before updating the balances.

<blockquote>

Expand Down Expand Up @@ -983,6 +1011,29 @@ Allows to run custom logic before updating balances and notifiying sender/recipi

<br/>

### \_afterTokenTransfer

```solidity
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal nonpayable;
```

Hook that is called after any token transfer, including minting and burning.
Allows to run custom logic after updating balances, but **before notifiying sender/recipient** by overriding this function.

#### Parameters

| Name | Type | Description |
| -------- | :-------: | ------------------------------- |
| `from` | `address` | The sender address |
| `to` | `address` | The recipient address |
| `amount` | `uint256` | The amount of token to transfer |

<br/>

### \_notifyTokenOperator

```solidity
Expand Down
55 changes: 53 additions & 2 deletions docs/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.md
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,16 @@ If the amount is zero then the operator is being revoked, otherwise the operator

### \_mint

:::info

Any logic in the:

- {\_beforeTokenTransfer} function will run before updating the balances.

- {\_afterTokenTransfer} function will run after updating the balances, **but before notifying the recipient via LSP1**.

:::

```solidity
function _mint(
address to,
Expand Down Expand Up @@ -890,6 +900,16 @@ Mints `amount` of tokens and transfers it to `to`.

### \_burn

:::info

Any logic in the:

- {\_beforeTokenTransfer} function will run before updating the balances.

- {\_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender via LSP1**.

:::

:::tip 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 All @@ -904,7 +924,6 @@ Burns (= destroys) `amount` of tokens, decrease the `from` balance. This is done
Both the sender and recipient will be notified of the token transfer through the LSP1 [`universalReceiver`](#universalreceiver)
function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
all the parameters in the calldata packed encoded.
Any logic in the [`_beforeTokenTransfer`](#_beforetokentransfer) function will run before updating the balances.

<blockquote>

Expand Down Expand Up @@ -948,6 +967,16 @@ Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOw

### \_transfer

:::info

Any logic in the:

- {\_beforeTokenTransfer} function will run before updating the balances.

- {\_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender/recipient via LSP1**.

:::

```solidity
function _transfer(
address from,
Expand All @@ -963,7 +992,6 @@ of `to` by `+amount`.
Both the sender and recipient will be notified of the token transfer through the LSP1 [`universalReceiver`](#universalreceiver)
function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
all the parameters in the calldata packed encoded.
Any logic in the [`_beforeTokenTransfer`](#_beforetokentransfer) function will run before updating the balances.

<blockquote>

Expand Down Expand Up @@ -1008,6 +1036,29 @@ Allows to run custom logic before updating balances and notifiying sender/recipi

<br/>

### \_afterTokenTransfer

```solidity
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal nonpayable;
```

Hook that is called after any token transfer, including minting and burning.
Allows to run custom logic after updating balances, but **before notifiying sender/recipient** by overriding this function.

#### Parameters

| Name | Type | Description |
| -------- | :-------: | ------------------------------- |
| `from` | `address` | The sender address |
| `to` | `address` | The recipient address |
| `amount` | `uint256` | The amount of token to transfer |

<br/>

### \_notifyTokenOperator

```solidity
Expand Down
45 changes: 43 additions & 2 deletions docs/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.md
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,16 @@ after `amount` of tokens have been minted.

### \_burn

:::info

Any logic in the:

- {\_beforeTokenTransfer} function will run before updating the balances.

- {\_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender via LSP1**.

:::

:::tip 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 All @@ -888,7 +898,6 @@ Burns (= destroys) `amount` of tokens, decrease the `from` balance. This is done
Both the sender and recipient will be notified of the token transfer through the LSP1 [`universalReceiver`](#universalreceiver)
function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
all the parameters in the calldata packed encoded.
Any logic in the [`_beforeTokenTransfer`](#_beforetokentransfer) function will run before updating the balances.

<blockquote>

Expand Down Expand Up @@ -932,6 +941,16 @@ Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOw

### \_transfer

:::info

Any logic in the:

- {\_beforeTokenTransfer} function will run before updating the balances.

- {\_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender/recipient via LSP1**.

:::

```solidity
function _transfer(
address from,
Expand All @@ -947,7 +966,6 @@ of `to` by `+amount`.
Both the sender and recipient will be notified of the token transfer through the LSP1 [`universalReceiver`](#universalreceiver)
function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
all the parameters in the calldata packed encoded.
Any logic in the [`_beforeTokenTransfer`](#_beforetokentransfer) function will run before updating the balances.

<blockquote>

Expand Down Expand Up @@ -992,6 +1010,29 @@ Allows to run custom logic before updating balances and notifiying sender/recipi

<br/>

### \_afterTokenTransfer

```solidity
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal nonpayable;
```

Hook that is called after any token transfer, including minting and burning.
Allows to run custom logic after updating balances, but **before notifiying sender/recipient** by overriding this function.

#### Parameters

| Name | Type | Description |
| -------- | :-------: | ------------------------------- |
| `from` | `address` | The sender address |
| `to` | `address` | The recipient address |
| `amount` | `uint256` | The amount of token to transfer |

<br/>

### \_notifyTokenOperator

```solidity
Expand Down
23 changes: 23 additions & 0 deletions docs/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.md
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,29 @@ Allows to run custom logic before updating balances and notifiying sender/recipi

<br/>

### \_afterTokenTransfer

```solidity
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal nonpayable;
```

Hook that is called after any token transfer, including minting and burning.
Allows to run custom logic after updating balances, but **before notifiying sender/recipient** by overriding this function.

#### Parameters

| Name | Type | Description |
| -------- | :-------: | ------------------------------- |
| `from` | `address` | The sender address |
| `to` | `address` | The recipient address |
| `amount` | `uint256` | The amount of token to transfer |

<br/>

### \_notifyTokenOperator

```solidity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,29 @@ Allows to run custom logic before updating balances and notifiying sender/recipi

<br/>

### \_afterTokenTransfer

```solidity
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal nonpayable;
```

Hook that is called after any token transfer, including minting and burning.
Allows to run custom logic after updating balances, but **before notifiying sender/recipient** by overriding this function.

#### Parameters

| Name | Type | Description |
| -------- | :-------: | ------------------------------- |
| `from` | `address` | The sender address |
| `to` | `address` | The recipient address |
| `amount` | `uint256` | The amount of token to transfer |

<br/>

### \_notifyTokenOperator

```solidity
Expand Down
Loading

0 comments on commit 2b475b2

Please sign in to comment.