Conditional transfers are off-chain transfers that are valid only if an on-chain event occurred. Use cases of conditional transfers can include (but are not limited to):
Fast Withdrawals: Alice wants to receive money on-chain without waiting for a proof (remember that in the regular withdrawal flow, the funds become available on-chain only once the proof is accepted). She signs a conditional transfer, giving 1000 USDC to a Liquidity Provider's off-chain vault, conditional on getting 1000 USDC minus a fee, from his Ethereum Address on-chain to her Ethereum Address on-chain.
More info on fast withdrawals can be found here.
Swap assets at Uniswap: Alice doesn't like the current ETH/DAI ratio in the off-chain app, and wants to take advantage of a really high ETH price on Uniswap. She signs an off-chain Conditional Transfer, giving 1ETH to an LP vault. This transfer is conditional on the fact that this LP deposits in her name, to StarkEx, the amount of DAI she expects to get for 0.99ETH on Uniswap.
Alice sends a Conditional Transfer request to the Application. In addition to fields used for a regular Transfer, the Conditional Transfers include two additional fields:
address: an address of a smart contract on Ethereum. This contract should implement the fact registry pattern.
fact: a fact that should be registered in this smart contract in order to approve the conditional transfer.
Alice knows that only if the
fact is true in the
address, her transaction will be valid and the Application will be able to execute it.
See here for Conditional Transfer structure.
An on-chain transaction to the fact registry contract at
address is transacted and results in the registration of the
fact as valid.
fact is registered as true in
address, the Application sends the Conditional Transfer transaction to StarkEx. Then, the same validity checks as in transfer are done
If the transaction is valid, it is included in a batch to be submitted on-chain along with validity proof. The
stateUpdate on-chain transaction includes as calldata the
address and the
fact. If this fact is not registered as true, the state update is rejected.