On each chain, in order to ensure the convenience of users, Meson will directly use the widely accepted tokens on the chain. For each Meson-backed token on each chain, the Meson smart contract will provide a liquidity pool to provide swap services for that token.
- 1.Swap request: The user (U) constructs a swap request off-chain which specifies the swap amount, the initial chain (X), the target chain (Y) and token type, as well as other necessary information. To publish the swap request, the user needs to sign it which authorizes the Meson contract to lock the swap amount + swap fee for matching LP. The signed swap will be broadcasted to the LP network through Meson relayer and wait for an LP to match. Since this process does not require actual on-chain transactions, users do not need to pay any gas fees (for ERC20 tokens, users need to
approvein advance and gas fees still need to be paid for this step). The signature for a swap request will be checked by Meson's smart contract (source) for the next step to proceed.
- 2.Post and bond a swap: LP needs to validate the swap request after receiving it. For a valid swap request, an LP can post the swap by calling the
postSwapmethod of Meson on the initial chain X and bond it to himself. Meson contract will check the signature, transfer user's swap amount + fee, and lock them for a certain time (tentatively set to 1-2 hours). During this period, the swap will be bonded to the LP for subsequent steps. At the same time, at most one LP can complete the bonding.
- 3.Lock the swap: For an LP successfully bonded to a swap, he needs to call the
lockmethod of Meson on the target chain Y to lock the swap funds (step 5) (tentatively 20 minutes) to ensure that the user can get paid;
- 4.Release signature: After the user validates the transactions in step 2 & 3, it is necessary to construct a signature for releasing funds within the lock period, specify the recipient address, and broadcast to inform the LP. This operation also does not require users to pay gas fees. The signature will also be checked by Meson's smart contract (source) for the next two steps to proceed.
- 5.Release fund: After the user's release signature is made public, anyone (including the user himself) can call the
releasemethod of the Meson contract on the target chain Y. When this transaction is executed, the validity of the signature will be checked. The funds locked in step 3 will be paid to the recipient designated by the user;
- 6.Receive initial funds: Finally, the LP uses the same release signature to call the
executeSwapmethod of the Meson contract on the initial chain X to obtain the funds (including swap fees) deposited by the user initially. LPs can choose to withdraw this part of funds or transfer them to his liquidity pool on chain X.
Flow of a Cross-chain Swap on Meson
In steps 1 and 4, the use of relayer service is not mandatory. Users can also post swap requests or release signatures directly on-chain. However, this requires the user to invoke the on-chain contract and pay the gas fee. The actual process is as follows
- Posting a swap request: The user should call the
postSwapcontract method directly without LP information on the initial chain. Once processed, the LP can call the
bondSwapmethod to bond the swap. The consequence of the prior two is the same as an LP executing
- Release the swap: The user should call the
releasecontract method directly on the target chain. The LP can then see the release signature from that transaction and subsequently call the
executeSwapmethod on the initial chain.
Please refer to the following diagram for the sequential process of swap.
After an LP provides swaps for a period of time, the distribution of his funds on different chains may be different from the initial state. If LP provides swaps in both directions of X → Y and Y → X, the overlapping parts can cancel each other so the funds that LP needs to rebalance are lower than the actual total swap amount.
When the LP rebalances the distribution of its fund pools, he can withdraw some funds from the pool by calling the
withdrawmethod, and use the existing cross-chain solutions (cross-chain bridges, centralized exchanges, etc.) for asset movement. The time requirement for this process is relatively low, and LPs can accumulate a certain amount of funds before rebalancing. Therefore, the ratio of cross-chain fees to the swap amount would become much lower.