> For the complete documentation index, see [llms.txt](https://docs.lossless.io/protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lossless.io/protocol/technical-reference/wrapped-tokens/extensible-wrapped-tokens/lossless-extensions-core.md).

# Lossless Extensions Core

## Workflow <a href="#workflow" id="workflow"></a>

<figure><img src="https://2406906599-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWd1iFH2pSxHtVxpot5%2Fuploads%2F4GlUEkimNrVo0LIgiXZp%2Fimage.png?alt=media&amp;token=938ec51a-12dc-4910-b62c-986140d67184" alt=""><figcaption></figcaption></figure>

## Overview <a href="#overview" id="overview"></a>

The Lossless Extensions Core is the smart contract in charge of managing the extensions installed on the Lossless Wrapped ERC20 Extensible contract.

Through this contracts the users can interact in order to register and unregister extensions. Additionally when an extension is registered it needs to be set as one of the following bases:

* `beforeTransferBase`: The logic of the extension is ran before a transfer takes place.
* `afterTransferBase`: The logic is ran after a transfer takes place
* `beforeMintBase`: The logic is ran before a mint takes place
* `afterMintBase`: The logic is ran after a mint takes place
* `beforeBurnBase`: The logic is ran before burning takes place
* `afterBurnBase`: The logic is ran after burning takes place

In order to properly implement the extensions the [corresponding interface](https://github.com/Lossless-Cash/wrapped-lossless-erc20/tree/master/src/Interfaces) has to be implemented.

## Extensions <a href="#extensions" id="extensions"></a>

An extension is a smart contract that implements one or more of the interfaces stated in the [repository](https://github.com/Lossless-Cash/wrapped-lossless-erc20/tree/master/src/Interfaces).

For instance, when a user interacts with the Lossless WERC20 Extensible to perform a transfer, the wrapping contract will check if a`beforeTransferBase` is set and if so, if it has an extension registered with the same address. If both of this conditions are true, the call to the extension is made, applying the deployed logic.

**More info**

[Lossless Core Extension ](https://lossless.atlassian.net/wiki/spaces/LOSSLESSCO/pages/254050332)can be taken as an example of an extension that implements before and after transfer base, effectively expanding the logic by interacting with the Lossless Core Protocol.

&#x20;

## Variables <a href="#variables" id="variables"></a>

#### `_extensions` <a href="#extensions" id="extensions"></a>

| Type        | `EnumerableSet.AddressSet`                      |
| ----------- | ----------------------------------------------- |
| Visibility  | `internal`                                      |
| Description | Corresponds to a list of registered extensions. |

#### `losslessCoreExtension` <a href="#losslesscoreextension" id="losslesscoreextension"></a>

| Type        | `address`                                                             |
| ----------- | --------------------------------------------------------------------- |
| Visibility  | `public`                                                              |
| Description | Corresponds to the registered address as the lossless core extension. |

#### `beforeTransferBase` <a href="#beforetransferbase" id="beforetransferbase"></a>

| Type        | `address`                                                                                                           |
| ----------- | ------------------------------------------------------------------------------------------------------------------- |
| Visibility  | `public`                                                                                                            |
| Description | Corresponds to the registered address as the before transfer base. Executes its logic before performing a transfer. |

#### `beforeMintBase` <a href="#beforemintbase" id="beforemintbase"></a>

| Type        | `address`                                                                                         |
| ----------- | ------------------------------------------------------------------------------------------------- |
| Visibility  | `public`                                                                                          |
| Description | Corresponds to the registered address as the before mint base. Executes its logic before minting. |

#### `afterMintBase` <a href="#aftermintbase" id="aftermintbase"></a>

| Type        | `address`                                                                                       |
| ----------- | ----------------------------------------------------------------------------------------------- |
| Visibility  | `public`                                                                                        |
| Description | Corresponds to the registered address as the after mint base. Executes its logic after minting. |

#### `beforeBurnBase` <a href="#beforeburnbase" id="beforeburnbase"></a>

| Type        | `address`                                                                                         |
| ----------- | ------------------------------------------------------------------------------------------------- |
| Visibility  | `public`                                                                                          |
| Description | Corresponds to the registered address as the before burn base. Executes its logic before burning. |

#### `afterBurnBase` <a href="#afterburnbase" id="afterburnbase"></a>

| Type        | `address`                                                                                       |
| ----------- | ----------------------------------------------------------------------------------------------- |
| Visibility  | `public`                                                                                        |
| Description | Corresponds to the registered address as the after burn base. Executes its logic after burning. |

#### `_CREATOR_CORE_V1` <a href="#creator_core_v1" id="creator_core_v1"></a>

| Type        | `bytes4`                                                       |
| ----------- | -------------------------------------------------------------- |
| Visibility  | `public` constant                                              |
| Description | Corresponds to the interfaceID of the Extensions Core Contract |

## Events <a href="#events" id="events"></a>

#### ExtensionRegistered <a href="#extensionregistered" id="extensionregistered"></a>

| Parameters  | <p><code>Address of the registered extension. Indexed.</code></p><p><code>Address of the one registering the extension. Indexed.</code></p> |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| Description | It is emitted when a new extension is registered.                                                                                           |

#### ExtensionUnregistered <a href="#extensionunregistered" id="extensionunregistered"></a>

| Parameters  | <p><code>Address of the unregistered extension. Indexed.</code></p><p><code>Address of the one unregistering the extension. Indexed.</code></p> |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| Description | It is emitted when a new extension is registered.                                                                                               |

#### BeforeTransferUpdated <a href="#beforetransferupdated" id="beforetransferupdated"></a>

| Parameters  | `Address of the set before transfer base.`            |
| ----------- | ----------------------------------------------------- |
| Description | It is emitted when a new transfer base is registered. |

#### AfterTransferUpdated <a href="#aftertransferupdated" id="aftertransferupdated"></a>

| Parameters  | `Address of the set after transfer base.`                   |
| ----------- | ----------------------------------------------------------- |
| Description | It is emitted when a new after transfer base is registered. |

#### BeforeMintUpdated <a href="#beforemintupdated" id="beforemintupdated"></a>

| Parameters  | `Address of the set before mint base.`                   |
| ----------- | -------------------------------------------------------- |
| Description | It is emitted when a new before mint base is registered. |

#### AfterMintUpdated <a href="#aftermintupdated" id="aftermintupdated"></a>

| Parameters  | `Address of the set after mint base.`                   |
| ----------- | ------------------------------------------------------- |
| Description | It is emitted when a new after mint base is registered. |

#### BeforeBurnUpdated <a href="#beforeburnupdated" id="beforeburnupdated"></a>

| Parameters  | `Address of the set before burn base.`                   |
| ----------- | -------------------------------------------------------- |
| Description | It is emitted when a new before burn base is registered. |

#### AfterBurnUpdated <a href="#afterburnupdated" id="afterburnupdated"></a>

| Parameters  | `Address of the set after burn base.`                   |
| ----------- | ------------------------------------------------------- |
| Description | It is emitted when a new after burn base is registered. |

## Functions <a href="#functions" id="functions"></a>

#### getExtensions <a href="#getextensions" id="getextensions"></a>

| Type         | external view                                                |
| ------------ | ------------------------------------------------------------ |
| Restrictions | -                                                            |
| Parameters   | -                                                            |
| Returns      | Returns an array of addresses                                |
| Description  | Returns a list of all registered extensions in the contract. |

#### registerExtension <a href="#registerextension" id="registerextension"></a>

| Type         | external                                                    |
| ------------ | ----------------------------------------------------------- |
| Restrictions | Only admin                                                  |
| Parameters   | extension address                                           |
| Returns      | -                                                           |
| Description  | Adds the address of the extension to the \_extensions list. |

#### registerExtension <a href="#registerextension.1" id="registerextension.1"></a>

| Type         | external                                                         |
| ------------ | ---------------------------------------------------------------- |
| Restrictions | Only admin                                                       |
| Parameters   | extension address                                                |
| Returns      | -                                                                |
| Description  | Removes the address of the extension from the \_extensions list. |

#### setLosslessCoreExtension <a href="#setlosslesscoreextension" id="setlosslesscoreextension"></a>

| Type         | external                                                  |
| ------------ | --------------------------------------------------------- |
| Restrictions | Only registered extension                                 |
| Parameters   | -                                                         |
| Returns      | -                                                         |
| Description  | Sets the calling extension as the Lossless Core Extension |

#### setBeforeTransferExtension <a href="#setbeforetransferextension" id="setbeforetransferextension"></a>

| Type         | external                                                |
| ------------ | ------------------------------------------------------- |
| Restrictions | Only registered extension                               |
| Parameters   | -                                                       |
| Returns      | -                                                       |
| Description  | Sets the calling extension as the before transfer base. |

#### setAfterTransferExtension <a href="#setaftertransferextension" id="setaftertransferextension"></a>

| Type         | external                                               |
| ------------ | ------------------------------------------------------ |
| Restrictions | Only registered extension                              |
| Parameters   | -                                                      |
| Returns      | -                                                      |
| Description  | Sets the calling extension as the after transfer base. |

#### setBeforeMintExtension <a href="#setbeforemintextension" id="setbeforemintextension"></a>

| Type         | external                                            |
| ------------ | --------------------------------------------------- |
| Restrictions | Only registered extension                           |
| Parameters   | -                                                   |
| Returns      | -                                                   |
| Description  | Sets the calling extension as the before mint base. |

#### setAfterMintExtension <a href="#setaftermintextension" id="setaftermintextension"></a>

| Type         | external                                           |
| ------------ | -------------------------------------------------- |
| Restrictions | Only registered extension                          |
| Parameters   | -                                                  |
| Returns      | -                                                  |
| Description  | Sets the calling extension as the after mint base. |

#### setBeforeBurnExtension <a href="#setbeforeburnextension" id="setbeforeburnextension"></a>

| Type         | external                                            |
| ------------ | --------------------------------------------------- |
| Restrictions | Only registered extension                           |
| Parameters   | -                                                   |
| Returns      | -                                                   |
| Description  | Sets the calling extension as the before burn base. |

#### setAfterBurnExtension <a href="#setafterburnextension" id="setafterburnextension"></a>

| Type         | external                                           |
| ------------ | -------------------------------------------------- |
| Restrictions | Only registered extension                          |
| Parameters   | -                                                  |
| Returns      | -                                                  |
| Description  | Sets the calling extension as the after burn base. |
