Multichain
  • Getting Started
    • Introduction
      • Supported Chains
      • Supported Tokens
    • How it works
      • Cross-Chain Bridge
      • Cross-Chain Router
    • Governance Token
      • VeMulti
      • How to Convert ANY to MULTI
    • Security
      • Security model
      • Bug bounty (Immunefi)
      • Bug bounty (alternative)
    • How to Use
      • Fees
    • Road Map
    • FAQ
    • Careers
      • Front-end developer
      • Back-end developer
      • Test Engineer
      • Test Development Engineer
      • Security Engineer (Code Auditing)
      • Blockchain Development Engineer
      • Senior Content Editor
      • Event Manager
  • Listing and Integration
    • Token Listing
      • ERC20 Cross-chain Options
      • Difference between V2&V3
    • Chain Integration
      • EVM Networks Integration
      • Non-EVM Networks Integration
    • FAQ
  • Developer Guide
    • How to Integrate Front-end Router
    • Bridge API (Token list/Tx Status)
    • Scan API (Tx Status/Account History)
    • Token Router Testnet
    • anyCall V7
      • How to integrate anyCall V7?
      • API/Explorer
      • Quickstart (Cross-chain text example)
      • Estimate Fee/Pay Fees on destination chain
    • anyCall V6
      • How to integrate anyCall V6?
      • anyFallback
      • anyCall V6 Testnet Environments
      • Fees Paid on Source Chain
      • Context (Verify msg.sender)
    • $USDC CCTP X anyCall
      • Contract Addresses and example
    • anyCall NFT Bridge
    • Permissionless Token bridging
    • How to develop under Anyswap ERC20 standards
    • Bridge funds and anyCall (Router V7)
      • Mainnet
      • Testnet (Quick Start Example)
    • How to Integrate Front-end Bridges
Powered by GitBook
On this page
  • Introduction
  • Applications include:
  • Mainnet Information
  • Testnet Information
  • anySwapOutAndCall workflow
  • Interfaces
  • Requirements to be compatible with anyCall interfaces:
  • Examples
  1. Developer Guide

Bridge funds and anyCall (Router V7)

PreviousHow to develop under Anyswap ERC20 standardsNextMainnet

Last updated 2 years ago

You're able to utilize Multichain's vast liquidity to bridge funds and execute the destination contract in one tx.

Introduction

This feature has been implemented in Router V7. This would combine our token router and anyCall which allows dapps to bridge funds and execute destination contracts with flexibility.

This allows the transfer of monetary values and data information cross-chain in one transaction.

The method is called anySwapOutAndCall .

Applications include:

  • Cross-chain atomic swaps

  • Cross-chain staking

  • Cross-chain lending

Please follow our testnet quickstart to try this out.

Mainnet Information

Testnet Information

anySwapOutAndCall workflow

Make sure you're familiar with the basics of anyCall before reading on as this method combines anyCall and bridge functions.

The anySwapOutAndCall function exists on our router contracts. This function would bridge tokens and call your receiver contract on the destination chain.

DAPPS need to deploy a receiver Exec/Anycallproxy Contract which would handle the bridged funds. On the receiver contract, a function named exec needs to be present and it will be called.

A sender contract is optional. You can deploy a sender contract that calls

anySwapOutAndCall if you want to implement additional features like extra fees, swap on the source chain.

The general flow is specified below:

DAPPS -> anySwapOutAndCall(Chain A) -> SMPC Network -> anySwapInAndExec(Chain B) ->AnycallExecutor-> exec by DAPP receiver contract(Chain B)

DAPPS call anySwapOutAndCall on Chain A. Then the SMPC network will relay this event and invoke anySwapInAndExec on Chain B which will send the tokens to the DAPP receiver contract.

Then use AnycallExecutortor as a sandbox to call the exec function on the DAPP receiver contract. Hence a function named exec needs to be present in the DAPP receiver contract.

If the exec function execution failed on Chain B, your Exec Contract would handle the failure case.

Interfaces

anySwapOutAndCall (Called by Dapps)

function anySwapOutAndCall( address token, string calldata to, uint256 amount, uint256 toChainID, string calldata anycallProxy, bytes calldata data )

Parameters

Param
Type
Description

token

address

The token you want to bridge.

to

string

to is the fallback receive address if exec failed on the destination chain

amount

uint256

Amount of tokens bridged

toChainID

uint256

The target chain id to interact with

anycallProxy

string

Your destination contract to process the bridge tokens.

data

bytes

The bytes calldata to pass into your destination contract anycallProxy.

Requirements to be compatible with anyCall interfaces:

  1. Receiver Contract: A method named execneeds to exist on your anycallProxy contract address. This is needed because the destination router will call execon your receiver contract.

The exec function below is an example of an implementation to allow cross-chain swap.

    function exec(
        address token,
        address receiver,
        uint256 amount,
        bytes calldata data
    ) external onlyAuth returns (bool success, bytes memory result) {

2. Whitelist: Your anycallProxy contract needs to be whitelisted by our team. Please contact us on telegram. A proxy contract can be whitelisted on testnet to ease development.

3. If your anycallProxy contract needs role control, use the AnycallExecutor listed in the above table. It will be the sandbox executing the contract. Refer to the role control below.

    modifier onlyAuth() {
        require(supportedCaller[msg.sender], "SushiSwapAnycallProxy: only auth");
        _; 
    }

Examples

Please read through our example contracts to see how to design an anycallproxy contract. This contract swaps the users' funds via Sushiswap to other tokens after receiving the bridged tokens on the destination chain.

Polygon mumbai
BNB Testnet

AnycallProxy Example

Please follow our testnet quickstart to try this out.

Source Tx:

Destination Tx:

Mainnet
Testnet (Quick Start Example)
https://mumbai.polygonscan.com/tx/0x92cf47a53cc2bf93976e36921ee4acb6f134a141df87baf5126d86f659c22d96
https://testnet.bscscan.com/tx/0x4a4a748de1c962d7153abe141da6e3c0382eea7cf20a0e0433012f021e445e57#eventlog
0xcaf870dad882b00f4b20d714bbf7fceada5e4195
0x9af276A66946d1B3B09760892AA08c9618381464