Bridge funds and anyCall (Router V7)
Last updated
Last updated
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
.
Cross-chain atomic swaps
Cross-chain staking
Cross-chain lending
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.
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.
function anySwapOutAndCall( address token, string calldata to, uint256 amount, uint256 toChainID, string calldata anycallProxy, bytes calldata data )
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
.
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.
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.
AnycallProxy Example
Source Tx:
Destination Tx: