> For the complete documentation index, see [llms.txt](https://kipprotocol.gitbook.io/kip-protocol-developer-guide-v6.8/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kipprotocol.gitbook.io/kip-protocol-developer-guide-v6.8/4-developer-guide/1-overview/5-kip-service.md).

# KIP Service

* The contract is used to manage payment-related features in the ecosystem.
* The current version of the contract supports several features:
  * As the `App Owner` | `Model Owner` | `Data Owner`:
    * Set a listing price for their items.
    * Set a payment pool to receive the accumulated revenue
    * Claim the revenue generated by their items.
  * As the `User` (payer)
    * Make a payment for using an `app`
* Deployed `KIPService` contract:
  * Network `Sepolia Base`: [0x87a7A0223D6F96B3DECaAf3666d5c550b36fEfEe](https://sepolia.basescan.org/address/0x87a7A0223D6F96B3DECaAf3666d5c550b36fEfEe)
* Supported roles/actors/users (`msg.sender`):
  * `DEFAULT_ADMIN_ROLE`:

    ```solidity
    bytes32 DEFAULT_ADMIN_ROLE = 0x0000000000000000000000000000000000000000000000000000000000000000;
    ```
  * `OPERATOR_ROLE`:

    ```solidity
    ///  OPERATOR_ROLE = keccak256("OPERATOR_ROLE")
    bytes32 OPERATOR_ROLE = 0x97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b929;
    ```
  * `Users`:
    * `App Owner`
    * `Model Owner`
    * `Dataset Owner`
    * `Payer`

## Contract Interfaces

### Getter functions:

```solidity
function KIPManagement() external view returns (address);
```

* Purpose: Query the current address of the `KIPManagement` contract.
* Parameters: `None`
* Return:
  * Type: `address`
  * Value: The address of the `KIPManagement` contract

```solidity
function KIPIdentification() external view returns (address);
```

* Purpose: Query the current address of the `KIPIdentification` contract.
* Parameters: `None`
* Return:
  * Type: `address`
  * Value: The address of the `KIPIdentification` contract

```solidity
function KIPRegister() external view returns (address);
```

* Purpose: Query the current address of the `KIPRegistration` contract.
* Parameters: `None`
* Return:
  * Type: `address`
  * Value: The address of the `KIPRegistration` contract

```solidity
function feeRate() external view returns (uint256);
```

* Purpose: Query the current setting rate of the commission fee.
* Parameters: `None`
* Return:
  * Type: `uint256`
  * Value: The commission fee's rate.

```solidity
function accumulatedFee() external view returns (uint256);
```

* Purpose: Query the total amount of the accumulated commission fee.
* Parameters: `None`
* Return:
  * Type: `uint256`
  * Value: The commission fee's total amount.

```solidity
function listingPrices(uint256 tokenId) external view returns (uint256);
```

* Purpose: Query the current listing price of the `tokenId`.
* Parameter:
  * `tokenId`:
    * Type: `uint256`
    * Value: The unique ID assigned to the `app`, `model` or `dataset`
* Return:
  * Type: `uint256`
  * Value: The listing price of the `tokenId`

```solidity
function revenues(uint256 tokenId) external view returns (uint256);
```

* Purpose: Query the accumulated revenues acquired per `tokenId`.
* Parameter:
  * `tokenId`:
    * Type: `uint256`
    * Value: The unique ID assigned to the `app`, `model` or `dataset`
* Return:
  * Type: `uint256`
  * Value: The `tokenId`'s accumulated revenue

```solidity
function pools(uint256 tokenId) external view returns (address);
```

* Purpose: Query the designated address, set by the tokenId's owner, to receive the accumulated revenue.
* Parameter:
  * `tokenId`:
    * Type: `uint256`
    * Value: The unique ID assigned to the `app`, `model` or `dataset`.
* Return:
  * Type: `address`
  * Value: The receiver's address to whom the accumulated revenue is transferred.

### Setter functions:

```solidity
function setManagement(address management) external;
```

* Purpose: Update the address of `KIPManagement` contract
* Requirement:
  * Caller must have `DEFAULT_ADMIN_ROLE`
* Parameter:
  * `management`:
    * Type: `address`
    * Value: The address of the `KIPManagement` contract.

```solidity
function setFeeRate(uint256 newFee) external;
```

* Purpose: Update the new rate of the commission fee.
* Requirement:
  * Caller must have `OPERATOR_ROLE`
* Parameter:
  * `newFee`:
    * Type: `uint256`
    * Value: The new rate of the commission fee.

```solidity
function payment(uint256 appId) external;
```

* Purpose: Make a payment for the `appId`.
* Requirements:
  * The provided `appId` should be valid
  * `msg.sender` should meet following requirements:
    * Have sufficient balance
    * Have already approved a sufficient amount to `KIPService` contract.
* Parameter:
  * `appId`:
    * Type: `uint256`
    * Value: The unique ID assigned to the `app`.

```solidity
function setPrice(uint256 tokenId, uint256 idType, uint256 price) external;
```

* Purpose: Set a listing price for `tokenId`.
* Requirements:
  * Caller must be the `owner` of the `tokenId`
  * The provided `idType` should match the `tokenId`'s classification
* Parameters:
  * `tokenID`:
    * Type: `uint256`
    * Value: The unique ID assigned to the `app`, `model`, and `dataset`.
  * `idType`:
    * Type: `uint256`
    * Value: The classification of the `tokenId`.
  * `price`:
    * Type: `uint256`
    * Value: The expected listing price for the item.

```solidity
function setPaymentPool(uint256 tokenId, address pool) external;
```

* Purpose: Set a designated address to receive the accumulated revenue.
* Requirements:
  * Caller must be the `owner` of the `tokenId`
  * The provided `pool` address should not be `0x0`
* Parameters:
  * `tokenID`:
    * Type: `uint256`
    * Value: The unique ID assigned to the `app`, `model`, and `dataset`.
  * `pool`:
    * Type: `address`
    * Value: The receiver's address.

```solidity
function setPriceAndPool(
  uint256 tokenId,
  uint256 idType,
  uint256 price,
  address pool
) external;
```

* Purpose: Set a listing price and receiver's address for the `tokenId`.
* Requirements:
  * Caller must be the `owner` of the `tokenId`
  * The provided `idType` should match the `tokenId`'s classification
  * The provided `pool` address should not be `0x0`
* Parameters:
  * `tokenID`:
    * Type: `uint256`
    * Value: The unique ID assigned to the `app`, `model`, and `dataset`.
  * `idType`:
    * Type: `uint256`
    * Value: The classification of the `tokenId`.
  * `price`:
    * Type: `uint256`
    * Value: The expected listing price for the item.
  * `pool`:
    * Type: `address`
    * Value: The receiver's address.

```solidity
function claimFee() external;
```

* Purpose: Call to transfer the `accumulated fee` to the `Treasury` wallet.
* Requirement:
  * Caller can be `ANY`
* Parameters: `None`

```solidity
function claimRevenue(uint256 tokenId) external;
```

* Purpose: Call to transfer the `accumulated revenue` to a designated receiver address set by the `tokenId`'s owner.
* Requirements:
  * Caller can be `ANY`
* Parameter:
  * `tokenID`:
    * Type: `uint256`
    * Value: The unique ID assigned to the `app`, `model`, and `dataset`.
