Function: ccm_deposit
Processes a CCM by calling the internal on_ccm_deposit
function. This function is intended to be called by the witnesser.
The destination address must be a valid address and be on the same chain as the destination asset.
If the CCM destination is not Ethereum, the principal is less than the gas budget, or the CCM intends to swap but the input asset is less than the minimum amount, it confiscates the assets and locks them in the protocol. This logic is implemented in the principal_and_gas_amounts
function:
Next, the CCM is determined to be either a swap CCM, which may also carry a message, or a messaging-only CCM (i.e., without a swap). If the source and destination assets are the same or the principal swap amount (after subtracting the gas budget) is zero, the CCM is a messaging-only swap. Otherwise, it is a swap CCM, too.
If the destination asset is not the same as the destination asset's chain's gas asset, the CCM requires an additional swap from the principal asset to the gas asset. This happens independently of whether the CCM intends to carry a swap or be messaging only:
If a gas swap is not required and the CCM is messaging only, the CCM is executed immediately. Otherwise, it is scheduled to be executed during block finalization (on_finalize
):
Note that if any swaps raise an error and revert the entire swapping transaction in on_finalize
, no future CCMs will work because the on_finalize
function will always revert. We did not identify a way to cause such an error to happen that would permanently cause a denial-of-service issue (lack of liquidity can be quickly fixed by depositing LP).