Funding ticks and state synchronization

Be aware that in order to optimize resources, StarkEx updates the funding of a user’s position only when the user touches that position by executing some transaction.

When a user queries their position without actually executing a transaction, the application can update that user’s position based on a funding tick, without sending any transaction to StarkEx. Each funding tick is rounded to the next lowest integer. For example, -2.1 is rounded to -3.

When a user ultimately executes a transaction, StarkEx first updates the position, calculating the new position based on all the funding ticks that occurred since the last time the user touched their position.

At this point, the application’s state and StarkEx’s state can diverge.

Example: The application’s state is out of synch with StarkEx
  1. On Monday, the collateral in Alice’s position is 100 USDC.

  2. On Tuesday, the application submits a funding tick that updates the collateral in Alice’s position by -2.1, which is rounded to -3.

  3. Alice queries her position, at which point the application applies the funding tick.

    Her new collateral balance is 100-3=97 USDC.

  4. On Wednesday, the application submits another funding tick that updates the collateral in Alice’s position by -1.9, which is rounded to -2.

  5. She then executes a trade for some synthetic ETH she has in her position. This trade affects her synthetic ETH balance but not her collateral. But the funding tick changes apply.

    1. Her new collateral balance is 97-2=95 USDC.

    2. StarkEx applies the prior funding ticks, (-2.1) + (-1.9), to the original collateral balance as follows:

      100-2.1-1.9=96 USDC.

So in StarkEx, her new collateral balance is 96 USDC, while the application shows her collateral balance to be 95 USDC.

un synched states
Figure 1. Un-synched state

You need to consider this discrepancy when developing an application and ensure that the application’s state remains synchronized with StarkEx’s state.