Wombat Exchange
Wombat Exchange
Search
K
Links

Cross Chain

Wombat’s foundational algorithm for the swaps has remained largely unchanged. You may refer Wombat’s Whitepaper and the Wombat Side Pool and Dynamic Whitepaper to better understand Wombat’s mechanics.

Invariant in the Context of Single-Chain

To facilitate cross chain transactions, we modify our stableswap invariant with an additional term, Credit, which serves as a network-neutral representation of value.
Credit is equivalent to the value of 1 token in the pool when the coverage ratio of the token is 100%. In other words, 1 credit can swap into 1 token when its coverage ratio is 100%, vice versa. Users will only obtain credit when the transaction of the designated chain is not executed. Let’s define the cross-chain pool invariant for a single chain as follows:
iLi(riAri)=D+(1+A)C\sum_{i} L_i(r_i −\frac{A}{r_i} ) = D + (1 + A)C
C represents the amount of outstanding credit, which represents the net amount of unrealized credit for that network. In a scenario where all credits are settled (swapped into tokens), C equals zero and it is identical with our stableswap invariant.

Invariant in the Context of Cross-Chain Network

nNetwork[iTokenLni(rniAnrni)]=nNetworkDn+(1+An)Cn\sum^{Network}_{n}[ \sum^{Token}_{i}L_{ni}(r_{ni}-\frac{A_{n}}{r_ni})]=\sum^{Network}_{n}D_n+(1+A_n)C_n
Users can swap between native assets on different chains using a cross-chain pool. In a multi-networks setting, we allow for network-specific amplification factors, A, and Credit, Cn.
Users can obtain gas tokens on the designated network by sending more gas from the source network, supported by the Wormhole relayer. If a user wants to swap token x from Network A to token B on Network B, we can understand the process in three steps.
  1. 1.
    User swaps token X to credit by putting a certain amount of token X into the pool on chain A, to get the corresponding amount of C.
  2. 2.
    Credit is relayed from Network A to Network B with an identical amount of credit.
  3. 3.
    User swaps credit to token and get token Y on Network B.

Wormhole’s Messaging Layer

Wormhole is used as the message layer to relay messages in cross-chain trans- actions. The WormholeAdaptor contract serves as an adapter between the pool and the Wormhole Relayer, publishing messages to the Wormhole Network. It also completes the swap at the designated chain when it receives the signed message, also known as Verified Action Approvals (VAA).

Credit, Mitigating MEV, and Slippage

As the transaction between the source chain and the designated chain is asyn-chronous, the final received amount is not deterministic when the transaction at the source chain is executed. To address this issue, we introduce the concept of ”credit” – an imaginary intermediate token.
  1. 1.
    The transaction in the source chain swap fromToken into credit.
  2. 2.
    The amount of credit is then relayed to the designated chain, where it is swapped into the toToken.
  3. 3.
    If no intermediate transactions are performed on the toToken, the final amount received will equal that of a same-chain swap.
  4. 4.
    Users can specify a minimum receive amount for the first and second steps.
  5. 5.
    If the slippage in the first step exceeds the specified amount, the transaction will be reverted to the source chain.
  6. 6.
    If the slippage at the second step exceeds the specified amount, the user will receive credit instead.
  7. 7.
    Users can swap credit for native tokens on the designated network or bridge the credit back to the source chain and swap it for native tokens in the source network.

Steps of a Cross-Chain Swap

  1. 1.
    To initiate a cross-chain swap, the sender will call CrossChainPool. swapTokensForTokensCrossChain.
    • The Wormhole Relayer requires extra gas tokens to relay the message to the contract on the designated chain. These tokens should be attached in the value field of the message.
    • To determine the amount of value required, use WormholeAdap- tor.estimateDeliveryFee.
  2. 2.
    The Guardian Network observes and signs messages.
  3. 3.
    Wormhole Relayers are responsible for relaying the signed message (the VAA) to the designated chain. Once complete, they will invoke the pool to swap tokens and send them to the receiver.
  4. 4.
    Users will receive credit if the slippage is too significant and the swap is reverted on the designated chain. Users can then exchange their credit for native tokens.