# Bridge funds and anyCall (Router V7)

{% hint style="info" %}
You're able to utilize Multichain's vast liquidity to bridge funds and execute the destination contract in one tx.&#x20;
{% endhint %}

### 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.&#x20;

The method is called **`anySwapOutAndCall`** .

### Applications include:

* Cross-chain atomic swaps
* Cross-chain staking
* Cross-chain lending

{% hint style="info" %}
Please follow our testnet quickstart to try this out.&#x20;
{% endhint %}

### Mainnet Information <a href="#undefined" id="undefined"></a>

{% content-ref url="bridge-funds-and-anycall-router-v7/mainnet" %}
[mainnet](https://docs.multichain.org/developer-guide/bridge-funds-and-anycall-router-v7/mainnet)
{% endcontent-ref %}

### Testnet Information

{% content-ref url="bridge-funds-and-anycall-router-v7/testnet-quick-start-example" %}
[testnet-quick-start-example](https://docs.multichain.org/developer-guide/bridge-funds-and-anycall-router-v7/testnet-quick-start-example)
{% endcontent-ref %}

### **anySwapOutAndCall workflow**

{% hint style="info" %}
Make sure you're familiar with the basics of anyCall before reading on as this method combines anyCall and bridge functions.
{% endhint %}

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**.

{% hint style="info" %}
A sender contract is optional. You can deploy a sender contract that calls&#x20;

**anySwapOutAndCall** if you want to implement additional features like extra fees, swap on the source chain.
{% endhint %}

The general flow is specified below:

&#x20;<mark style="color:green;">**DAPPS**</mark>**&#x20;-> `anySwapOutAndCall`**(Chain A) **->** *SMPC Network* **->** `anySwapInAndExec`(Chain B) **->**`AnycallExecutor`**->** `exec` by <mark style="color:green;">**DAPP receiver contract(Chain B)**</mark>

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.&#x20;

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**

#### <mark style="color:orange;">**anySwapOutAndCall**</mark> (Called by Dapps)

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

#### Parameters <a href="#request-parameters" id="request-parameters"></a>

<table><thead><tr><th width="209">Param</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>token</td><td>address</td><td>The token you want to bridge. </td></tr><tr><td>to</td><td>string</td><td><code>to</code> is the fallback receive address if exec failed on the destination chain</td></tr><tr><td>amount</td><td>uint256</td><td>Amount of tokens bridged</td></tr><tr><td>toChainID</td><td>uint256</td><td>The target chain id to interact with</td></tr><tr><td>anycallProxy</td><td>string</td><td>Your destination contract to process the bridge tokens. </td></tr><tr><td>data</td><td>bytes</td><td>The bytes calldata to pass into your destination contract <code>anycallProxy</code>.</td></tr></tbody></table>

####

### Requirements to be compatible with anyCall interfaces:

1. **Receiver Contract:** A method named `exec`needs to exist on your `anycallProxy` contract address. This is needed because the destination router will call `exec`on your receiver contract.&#x20;

{% hint style="info" %}
The exec function below is an example of an implementation to allow cross-chain swap.
{% endhint %}

```
    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

{% hint style="info" %}
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.
{% endhint %}

|                          | Polygon mumbai                                                                                                                  | BNB Testnet                                                                                                                  |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| **AnycallProxy Example** | [0xcaf870dad882b00f4b20d714bbf7fceada5e4195](https://mumbai.polygonscan.com/address/0xcaf870dad882b00f4b20d714bbf7fceada5e4195) | [0x9af276A66946d1B3B09760892AA08c9618381464](https://testnet.bscscan.com/address/0x9af276A66946d1B3B09760892AA08c9618381464) |

Source Tx: <https://mumbai.polygonscan.com/tx/0x92cf47a53cc2bf93976e36921ee4acb6f134a141df87baf5126d86f659c22d96>

Destination Tx:[ ](https://rinkeby.etherscan.io/tx/0x0e6ed4135abaff4f363e7fff147f1367e200400302afa182c37c1bcb57d0c4a9)<https://testnet.bscscan.com/tx/0x4a4a748de1c962d7153abe141da6e3c0382eea7cf20a0e0433012f021e445e57#eventlog>

{% hint style="info" %}
Please follow our testnet quickstart to try this out.&#x20;
{% endhint %}
