Coder Social home page Coder Social logo

ccmp-contracts's Introduction

Biconomy Cross Chain Messaging Protocol (CCMP)

This repository contains the smart contracts for Biconomy's CCM Protocol.

Introduction

CCMP faciliates cross-chain transfer of messages via Biconomy's network of decentralized relayers.

With CCMP, smart contracts deployed on one chain are able to execute arbitrary logic on another chain.

Usage

Sending Messages

To send a "message" to another chain, smart contracts will interact with the CCMPGateway contract, specifically call the sendMessage function as follows:

/// @param _destinationChainId The chain id of the destination chain.
/// @param _adaptorName The name of the router adaptor to use. Currently "axelar", "wormhole" and "abacus" are supported.
/// @param _gasFeePaymentArgs Contains details for the fee quoted by the relayer
/// @param _routerArgs Contains abi encoded router specific arguments. For ex, CONSISTENCY_LEVEL when sending message via wormhole.
/// @return sent The hash of the message sent.
function sendMessage(
    uint256 _destinationChainId,
    string calldata _adaptorName,
    CCMPMessagePayload[] calldata _payloads,
    GasFeePaymentArgs calldata _gasFeePaymentArgs,
    bytes calldata _routerArgs
) external payable;

The _payloads argument is an array of the following form:

[
    {
        // Address of contract on the destination chain
        address to;

        // Calldata to execute on 'to'
        bytes _calldata; 
    },
    {
        address to;
        bytes _calldata;
    },
    {
        address to;
        bytes _calldata;
    }...
]

The _gasFeePaymentArgs argument specified the exected gas fee to be paid to confirm the transaction on the destination chain. This can be fetched by calling and API Exposed by the Biconomy SDK.

Receiving Messages

Inherit contracts/receiver/CCMPReceiver.sol in the contract receiving the messages (to from the payload array). The function _ccmpMessageOrigin() will return the chainId of the source chain and the address of the sender contract.

Overview

Scenario: A smart contract 0xCONTRACT on ethereum wants to send a cross-chain message to 0xCONTRACT on Polygon.

Source Chain

  1. 0xCONTRACT on ethereum prepares the required payload to be executed om polygon (calldata), selects an underlying protcol supported by CCMP and calls 0xCCMPGateway.sendMessage. The fee required to execute the message on the exit chain is assumed to be negotiated previously b/w the sender and relayer and the required payment mode is sent as gasFeePaymentArgs along with the actual tokens are sent with the same call.
  2. 0xCCMPGateway will do some validations and pass on the message to 0xCCMPExecutor.
  3. 0xCCMPExecutor verifies the fee payment and does some accounting so that fee can be claimed later by the executor. In case there are any token transfer via Hyphen involved,0xExecutor will perform the token deposits into existing Hyphen Liquidity Pools as well.
  4. 0xCCMPGatway calls the underlying protocol's adapter which sends the message to the exit chain.

Intermediate Off-Chain Steps

  1. In case the underlying protocol requires a fee payment for the message to be sent to the destination chain, the relayer will pay the fee to the underlying protocol on the user's behalf. This fee is assumed to be accounted for in the original fee negotiation b/w the user and the relayer.
  2. The relayer the waits for the message to be confirmed on the destination chain by the underlying protocol.
  3. Once the message is confirmed, the relayer calls 0xCCMPGateway on the destination chain.

Destination Chain

  1. 0xCCMPGateway calls the underlying adapter to verify the message with the underlying protocol.
  2. The message is passed on 0xCCMPExecutor, which executes the contract calls and Hyphen Token Transfers included in the original payload.

ccmp-contracts's People

Contributors

ankurdubey521 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

ankurdubey521

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.