Funding payments are part of the perpetual-application business logic. In short - funding is a mechanism to credit or debit the users' positions, according to a predefined logic, in order to incentivize certain strategies.
The funding tick has the following parameters:
global_index for every
assetId in the system
StarkEx checks the following conditions:
system_timeis greater than the previous
After the funding tick is accepted, an array called
global_indices is updated with a new value per
Every transaction execution that touches a position (Deposit, Withdrawal, Trade, Transfer, Forced Withdrawal and Forced Trade) applies a funding operation on this position. For this, each position stores a value called
assetId , which represents the last funding tick that affected it. The execution of a transaction consists of two steps:
assetIdreduce the funding debit from the balance and update the position indices, as described below:
Apply the transaction specific logic.
These two steps are atomic, meaning, if a transaction is invalid then both steps are not executed.
If the Funding Tick is valid, it is included in a batch to be submitted on-chain along with a validity proof. See here for full details on state update on-chain.
As part of the batch validity checks, the StarkEx contract checks that the last funding timestamp in the batch was within the last week. This limits the time between two funding ticks and thus limits the funding debits.