# KintoAppRegistry

**Deployment Address:**

Mainnet: [<mark style="color:purple;">0x5A2b641b84b0230C8e75F55d5afd27f4Dbd59d5b</mark>](https://explorer.kinto.xyz/address/0x5A2b641b84b0230C8e75F55d5afd27f4Dbd59d5b)

Interface: [<mark style="color:purple;">IKintoAppRegistry.sol</mark>](https://github.com/KintoXYZ/kinto-id/tree/main/src/interfaces)

***

## Basics

The easiest way to register a new app is to use the `registerApp` method. It registers a new app and mints the NFT to the creator.

For example, if you want to register a new app, you can call:

```solidity
registerApp(<NAME>, <PARENT_CONTRACT>, <APP_CONTRACTS>, <APP_LIMITS>, <DEV_EOAS>)
```

### App Limits

Every app has limits that define its rate and gas usage.

The following limits will be used to define the app's properties.

| Name                   | Number     |
| ---------------------- | ---------- |
| RATE\_LIMIT\_PERIOD    | 1 minute   |
| RATE\_LIMIT\_THRESHOLD | 10         |
| GAS\_LIMIT\_PERIOD     | 30 days    |
| GAS\_LIMIT\_THRESHOLD  | 0.01 ether |

Using the following call method, you can quickly check an app's limits:

```solidity
getContractLimits(<CONTRACT_ADDRESS>)
```

### Sponsored Contracts

Apps can sponsor other contracts, allowing them to operate under their limits.

For example, to check whether a contract is sponsored by an app:

```solidity
isSponsored(<APP_ADDRESS>, <CONTRACT_ADDRESS>)
```

### State Functions

Privileged roles can call the following functions.

```solidity
function registerApp(string calldata appName, address parentContract, address[] calldata appContracts, uint256[4] calldata appLimits, address[] calldata devEOAs) external;

function updateMetadata(string calldata appName, address parentContract, address[] calldata appContracts, uint256[4] calldata appLimits, address[] calldata devEOAs) external;

function setSponsoredContracts(address _app, address[] calldata _contracts, bool[] calldata _flags) external;

function enableDSA(address app) external;

function overrideChildToParentContract(address child, address parent) external;

function updateSystemContracts(address[] calldata newSystemContracts) external;

function updateSystemApps(address[] calldata newSystemApps) external;

function updateReservedContracts(address[] calldata newReservedContracts) external;

function setDeployerEOA(address wallet, address deployer) external;
```

**1. registerApp**

This function registers a new app and mints the NFT to the creator. Only KYC verified addresses can call this function.

```solidity
function registerApp(string calldata appName, address parentContract, address[] calldata appContracts, uint256[4] calldata appLimits, address[] calldata devEOAs) external;
```

| Parameter      | Type                 | Explanation                          |
| -------------- | -------------------- | ------------------------------------ |
| appName        | string calldata      | The name of the app                  |
| parentContract | address              | The address of the parent contract   |
| appContracts   | address\[] calldata  | The addresses of the child contracts |
| appLimits      | uint256\[4] calldata | The limits of the app                |
| devEOAs        | address\[] calldata  | The addresses of developer EOAs      |

***

**2. updateMetadata**

This function updates the metadata of an app. Only the app developer can call this function.

```solidity
function updateMetadata(string calldata appName, address parentContract, address[] calldata appContracts, uint256[4] calldata appLimits, address[] calldata devEOAs) external;
```

| Parameter      | Type                 | Explanation                          |
| -------------- | -------------------- | ------------------------------------ |
| appName        | string calldata      | The name of the app                  |
| parentContract | address              | The address of the parent contract   |
| appContracts   | address\[] calldata  | The addresses of the child contracts |
| appLimits      | uint256\[4] calldata | The limits of the app                |
| devEOAs        | address\[] calldata  | The addresses of developer EOAs      |

***

**3. setSponsoredContracts**

This function sets the sponsored contracts for an app. Only the app developer or contract owner can call this function.

```solidity
function setSponsoredContracts(address _app, address[] calldata _contracts, bool[] calldata _flags) external;
```

| Parameter   | Type                | Explanation                    |
| ----------- | ------------------- | ------------------------------ |
| \_app       | address             | The address of the app         |
| \_contracts | address\[] calldata | The addresses of the contracts |
| \_flags     | bool\[] calldata    | The flags of the contracts     |

***

**4. enableDSA**

This function enables DSA for an app. Only the contract owner can call this function.

```solidity
function enableDSA(address app) external;
```

| Parameter | Type    | Explanation            |
| --------- | ------- | ---------------------- |
| app       | address | The address of the app |

***

**5. overrideChildToParentContract**

This function allows the owner to override the parent contract of a child contract.

```solidity
function overrideChildToParentContract(address child, address parent) external;
```

| Parameter | Type    | Explanation                        |
| --------- | ------- | ---------------------------------- |
| child     | address | The address of the child contract  |
| parent    | address | The address of the parent contract |

***

**6. updateSystemContracts**

This function updates the system contracts array. Only the contract owner can call this function.

```solidity
function updateSystemContracts(address[] calldata newSystemContracts) external;
```

| Parameter          | Type                | Explanation                       |
| ------------------ | ------------------- | --------------------------------- |
| newSystemContracts | address\[] calldata | The new array of system contracts |

***

**7. updateSystemApps**

This function updates the system apps array. Only the contract owner can call this function.

```solidity
function updateSystemApps(address[] calldata newSystemApps) external;
```

| Parameter     | Type                | Explanation                  |
| ------------- | ------------------- | ---------------------------- |
| newSystemApps | address\[] calldata | The new array of system apps |

***

**8. updateReservedContracts**

This function updates the reserved contracts array. Only the contract owner can call this function.

```solidity
function updateReservedContracts(address[] calldata newReservedContracts) external;
```

| Parameter            | Type                | Explanation                         |
| -------------------- | ------------------- | ----------------------------------- |
| newReservedContracts | address\[] calldata | The new array of reserved contracts |

***

**9. setDeployerEOA**

This function sets the deployer EOA for a wallet. Can be called by the wallet itself or the contract owner.

```solidity
function setDeployerEOA(address wallet, address deployer) external;
```

| Parameter | Type    | Explanation                     |
| --------- | ------- | ------------------------------- |
| wallet    | address | The address of the wallet       |
| deployer  | address | The address of the deployer EOA |

***

### View Functions

Anyone can call the following functions without a transaction to retrieve information from the contract.

```solidity
function name() external pure returns (string memory);

function symbol() external pure returns (string memory);

function getAppMetadata(address _contract) external view returns (IKintoAppRegistry.Metadata memory);

function getContractLimits(address _contract) external view returns (uint256[4] memory);

function isSponsored(address _app, address _contract) external view returns (bool);

function getSponsor(address _contract) external view returns (address);

function supportsInterface(bytes4 interfaceId) public view returns (bool);

function isContractCallAllowedFromEOA(address from, address to) external view returns (bool);

function getSystemContracts() external view returns (address[] memory);

function getSystemApps() external view returns (address[] memory);

function getReservedContracts() external view returns (address[] memory);

function isSystemApp(address app) external view returns (bool);

function isReservedContract(address contract) external view returns (bool);
```

**1. name**

This function gets the token name.

```solidity
function name() external pure override returns (string memory);
```

| Parameter | Type | Explanation            |
| --------- | ---- | ---------------------- |
|           |      | Returns the token name |

**2. symbol**

This function gets the token symbol.

```solidity
function symbol() external pure override returns (string memory);
```

| Parameter | Type | Explanation              |
| --------- | ---- | ------------------------ |
|           |      | Returns the token symbol |

***

**3. getAppMetadata**

This function returns the metadata of the app.

```solidity
function getAppMetadata(address _contract) external view override returns (IKintoAppRegistry.Metadata memory);
```

| Parameter  | Type    | Explanation            |
| ---------- | ------- | ---------------------- |
| \_contract | address | The address of the app |

***

**4. getContractLimits**

This function returns the limits of the app.

```solidity
function getContractLimits(address _contract) external view override returns (uint256[4] memory);
```

| Parameter  | Type    | Explanation            |
| ---------- | ------- | ---------------------- |
| \_contract | address | The address of the app |

***

**5. isSponsored**

This function checks whether a contract is sponsored by an app.

```solidity
function isSponsored(address _app, address _contract) external view override returns (bool);
```

| Parameter  | Type    | Explanation                 |
| ---------- | ------- | --------------------------- |
| \_app      | address | The address of the app      |
| \_contract | address | The address of the contract |

***

**6. getSponsor**

This function returns the sponsoring contract for a given contract.

```solidity
function getSponsor(address _contract) external view override returns (address);
```

| Parameter  | Type    | Explanation                 |
| ---------- | ------- | --------------------------- |
| \_contract | address | The address of the contract |

**7. supportsInterface**

Returns whether the contract implements the interface defined by the id

```solidity
function supportsInterface(bytes4 interfaceId);
```

| Parameter   | Type   | Explanation                       |
| ----------- | ------ | --------------------------------- |
| interfaceId | bytes4 | id of the interface to be checked |

**8. isContractCallAllowedFromEOA**

This function determines if a contract call is allowed from an EOA (Externally Owned Account).

```solidity
function isContractCallAllowedFromEOA(address from, address to) external view returns (bool);
```

| Parameter | Type    | Explanation                                |
| --------- | ------- | ------------------------------------------ |
| from      | address | The address of the EOA initiating the call |
| to        | address | The address of the contract being called   |

This function checks various conditions to decide if an EOA can call a specific contract, including system contracts, linked wallets, dev mode, KYC status, and more.

**9. getSystemContracts**

This function returns the array of system contracts.

```solidity
function getSystemContracts() external view returns (address[] memory);
```

No parameters.

**10. getSystemApps**

This function returns the array of system apps.

```solidity
function getSystemApps() external view returns (address[] memory);
```

No parameters.

**11. getReservedContracts**

This function returns the array of reserved contracts.

```solidity
function getReservedContracts() external view returns (address[] memory);
```

No parameters.

**12. isSystemApp**

This function checks if an address is a system app.

```solidity
function isSystemApp(address app) external view returns (bool);
```

| Parameter | Type    | Explanation          |
| --------- | ------- | -------------------- |
| app       | address | The address to check |

**13. isReservedContract**

This function checks if an address is a reserved contract.

```solidity
function isReservedContract(address contract) external view returns (bool);
```

| Parameter | Type    | Explanation          |
| --------- | ------- | -------------------- |
| contract  | address | The address to check |
