---
# System prepended metadata

title: 'MEP-01: ISO Application Contract'

---

# MEP-01: ISO Application Contract

**Created**: 2023-04-19

## Simple Summary

Specification allowing users to create ISO applications on-chain. 

## Abstract

ISO applications are projects that enable the caller to create ISOs (Initial Sensor Offerings). The applications created on this contract prove that the ownership of a particular sensor application belongs to the transaction signer.

An on-chain application links a given ISO project with the set of smart contracts deployed afterwards.

Before a user creates an application, he needs to create a Tenant by calling the `createTenant` method. After that, any application he wants to create, the application lands under his Tenant.

## Motivation

The goal is to allow the setup of a Tenant to create ISO applications.

## Terminology

- Tenant - Is the most fundamental construct of an instance on a SaaS environment; the Tenant sets specific privileges to the software instance to the user that creates it.
- Tenant Owner - Is the user that creates the Tenant and hase all the privileges to change its configuration, including adding more users.
- ISO Application - A project which the Tenant owner creates in order to start a ISO (Initial Sensor Offering), create devices and device profiles linked to the ISO application
- Provisioning Contract - A contract defined by MEP-02; responsible for provisioning new sensor IDs (also called PIDs) in form of NFTs
- Sensor Data Contract - A contract defined by MEP-03; defines the device profile that each sensor belongs to, encoding/decoding, formats, etc.



## Specification

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

Every MEP-01 compliant contract must implement the following interface:

```solidity=
pragma solidity ^0.4.20;

/// @title MEP-01 ISO Application Contract
interface MEP01 {
    /// @dev This event gets emitted when a new application is created.
    ///  The parameters are the id, owner and the application name
    event CreateApplication(uint256 indexed _id, address indexed _owner, string _name);
    
    /// @dev This event gets emitted when the provisioning contract (MEP-02) gets deployed.
    ///  The parameters are the id and the address of the contract
    event CreateProvisioningContract(uint256 indexed _id, address indexed _contractAddress);
    
    /// @dev This event gets emitted when a new tenant is created.
    ///  The parameters are the id and the tenant name
    event CreateTenant(uint256 indexed _id, string _name);
    
    /// @dev This event gets emitted when a the sensor data contract (MEP-03) gets deployed.
    ///  The parameters are the id and the address of the contract
    event CreateSensorContract(uint256 indexed _id, address indexed _contractAddress);
    
    /// @notice Creates a new tenant
    /// @dev Checks if the tenant with the given _id exists;
    ///  should return an error if it does.
    ///
    /// @param _id The identifier of the tenant
    /// @param _name The name of the tenant represented as string
    function createTenant(uint256 _id, string _name) external;
    
    /// @notice Creates a new ISO application
    /// @dev The smart contract needs to check whether there an application
    ///  with the same _id exists; in that case it should return an error. 
    ///  Also, needs to check if the given tenant exists.
    ///
    /// @remark The createApplication method needs to deploy all the 
    ///  other contracts specified with MEP-02 and MEP-03. 
    ///  After the contracts are deployed and proper ownership assigned, 
    ///  this contract needs to act as a registry and store the addresses 
    ///  of the set of contracts belonging to this application.
    /// @param _tenantId The identifier of the tenant
    /// @param _id The identifier of the application
    /// @param _name The name of the application
    function createApplication(uint256 _tenantId, uint256 _id, string _name) external;
    
    /// @notice Find the owner of a ISO application
    /// @dev Applications assigned to zero address are considered invalid, 
    ///  and queries about them do throw.
    /// @param _tenantId The identifier of the tenant
    /// @param _id The identifier of the application
    /// @return The address of the owner of the application
    function ownerOfApplication(uint256 _tenantId, uint256 _id) external view returns (address);
    
    /// @notice Find the owner address of the given tenant
    /// @dev Tenants assigned to zero address are considered invalid, 
    ///  and queries about them do throw.
    /// @param _id The identifier of the tenant
    /// @return The address of the owner of the tenant
    function ownerOfTenant(uint256 _id) external view returns (address);
}

```

## Rationale

Before interacting with the applications, the caller needs to create a tenant first with the `createTenant` method. A single address can own multiple tenants.

To create an application under a specific tenant, the caller needs to use the `createApplication` method. A single tenant can have multiple applications.

The `createApplication` method needs to store the application id on-chain, and deploy two more contracts:

- Provisioning Contract (MEP02)
- Sensor Data Contract (MEP03)

The owner of the two contracts above should be the caller of the `createApplication` method.