# Token Logic Modules Introduction

### Introduction

Token Logic Module (TLM) processing consists of the following sequential steps:

{% stepper %}
{% step %}

### TLM pre-processing

General pre-processing to determine the number of tokens to settle per claim.
{% endstep %}

{% step %}

### TLM processing

Iterating through each TLM, sequentially, independently of each other.
{% endstep %}
{% endstepper %}

### Background: Max Claimable Amount

*tl;dr Max Claimable Amount ∝ (Application Stake / Number of Suppliers per Session)*

Per Algorithm 1 of the Relay Mining paper (<https://arxiv.org/pdf/2305.10672>), the maximum amount a supplier can claim from an application in a single session MUST NOT exceed the Application's stake divided by the number of suppliers in the session.

This is referred to as "Relay Mining Payable Relay Accumulation" in the paper and is described by the following pseudo-code:

![Algorithm 1](https://content.gitbook.com/content/xoQfEzGwpt9dsMlilFsh/blobs/dSgIwXTrd8mzXUI47CWg/d1a61535%20aa31%20447d%2088ea%20c8d14dcb20c6)

{% hint style="info" %}
See the relay mining docs (<https://dev.poktroll.com/protocol/primitives/relay\\_mining>) or the annotated presentation (<https://olshansky.substack.com/p/annotated-presentation-relay-mining>) for more information.
{% endhint %}

### TLM (pre) Processing

*tl;dr Determine if the claim amount is greater than the maximum claimable amount prior to running each individual TLM.*

Prior to processing each individual TLM, we need to understand if the amount claimed by the supplier adheres to the optimistic maxIA set per the limits of the Relay Mining algorithm.

{% hint style="info" %}
Pocket Network can be seen as a probabilistic, optimistic permissionless multi-tenant rate limiter.

This works by putting funds in escrow, burning it after work is done, and putting optimistic limits in place whose work volume is proven onchain.
{% endhint %}

Suppliers always have the option to over-service an Application (i.e. do free work) in order to ensure high quality service in the network. This may lead to offchain reputation benefits (e.g. Gateways favoring them), but suppliers' onchain rewards are always limited by the cumulative amounts Applications' stakes (at session start; per service) and the number of Suppliers in the session.

Max Claimable Amount (MCA) = Application Stake / NumSuppliersPerSession

* Claim Amount (CA)
* Max Claimable Amount (MCA) = (AppStake / NumSuppliersPerSession)

Questions evaluated prior to TLM processing:

* Is CA > MCA?
  * Yes → Broadcast event that Settlement Amount (SA) = MCA (Application Overserviced Event), then process TLMs with SA = MCA.
  * No → SA = CA; process TLMs with SA = CA.

Possible TLM examples:

* TLM: Burn Equals Mint
* TLM: Global Inflation
* TLM: Global Inflation Reimbursement Request
* TLM: ...

Token Logic Modules Pre-Processing

{% hint style="warning" %}
In order for the MaxClaimableAmount to prevent Applications from over-servicing, the Application.Stake must be claimable only by Suppliers from the same session (i.e. the same service).

For a given application MaxClaimableAmount is Application.Stake / NumSuppliersPerSession and defined per session/service.

If an Application is able to send traffic to n services then it could be over-servicing up to n times its stake for a given session number by performing MaxClaimableAmount \* NumSuppliersPerSession \* n > Application.Stake worth of work.

To avoid this type of over-servicing, the Pocket protocol requires Applications to only be able to stake for EXACTLY ONE service.
{% endhint %}
