Ride execution

Main flow

Once the DeFi Pooling admin decides to depart the ride, it informs the Operator to stop accepting new join requests from users.

In the analogy of a bus ride, the ride can only depart once all passengers are physically standing on the bus.

Pre-departure, the collated DeFi Pooling funds must exist on-chain in order to execute an on-chain operation to trade them. Therefore, the admin waits until the StarkEx state includes all settlements by users joining the ride. Once this is done, the funds of all the passengers are available on-chain in the StarkEx smart contract for the Pool Manager to use.

Next, the admin calls the Pool Manager Ride Departure function. This function executes the following operations:

  1. The Pool Manager withdraws funds from the StarkEx smart contract and applies them to the Pool Manager smart contract.

  2. The Pool Manager buys strategy tokens for the entire value of Invested tokens it controls. This operation succeeds only if the price of this trade is lower or equal to the price that the users agreed to when they joined the ride.

  3. If the trade succeeds, the Pool Manager smart contract deposits the entire value of strategy tokens it controls back to the StarkEx smart contract; and submits an on-chain limit order to sell those for ride tickets. The price to buy one strategy token should be exactly the total amount of ride tickets divided by the total amount of strategy tokens.

DeFi Pooling 4A

Fallback flow

If the trade doesn’t succeed, i.e., the price to buy strategy tokens was higher than the price the users agreed to pay, the Pool Manager smart contract deposits back the investment tokens and submits an on-chain limit order to sell them back to the users in exchange for their ride tickets.