Giter Site home page Giter Site logo

callistobridge's Introduction

CallistoBridge

Description

Deposit tokens

To swap tokens from one chain to another, a user calls the function depositTokens().

    function depositTokens(
        address token,      // token that user send (if token address < 32, then send native coin)
        uint256 value,      // tokens value
        uint256 toChainId   // destination chain Id where will be claimed tokens
    ) 
        external
        payable
        notFrozen

The event Deposit(address token, address sender, uint256 value, uint256 toChainId, address toToken) will be emitted, where:

  • address token - token address (if address < 32, then it's native coin).
  • address sender - the wallet address who sends tokens (only the same address may receive tokens on another chain).
  • uint256 value - amount of tokens.
  • uint256 toChainId - chain ID where a user can claim tokens/
  • address toToken - token address on the destination chain that user will claim.

Claim tokens

To get authority signature a user has to call Authority server function authorize(txId, fromChainId), where:

  • txId - deposit transaction ID (hash)
  • fromChainId - chain ID where deposited.

it returns JSON, where:

  • if all good:

    • isSuccess - true,
    • signature - authority signature,
    • token - token to receive,
    • value - tokens amount,
    • to- receiver (user's) address,
    • chainId - chain ID where to claim token,
    • bridge - address of bridge on destination network.
  • in case of error:

    • isSuccess - false,
    • message - error description

Use those values to claim tokens on destination chain, the user calls the function claimMultiSig()

    function claimMultiSig(
        address token,          // token to receive
        bytes32 txId,           // deposit transaction hash on fromChain 
        address to,             // user address
        uint256 value,          // value of tokens
        uint256 fromChainId,    // chain ID where user deposited
        bytes[] calldata sig    // authority signatures
    ) 

Create wrapped token

To created wrapped token the owner has to get nonce from function calculateNonce() then using this nonce calls the function createWrappedToken()

    function createWrappedToken(
        address fromToken,      // foreign token address
        uint256 fromChainId,    // foreign chain ID where token deployed
        string memory name,     // wrapped token name
        string memory symbol,   // wrapped token symbol
        uint8 decimals,         // wrapped token decimals (should be the same as in original token)
        uint256 nonce           // nonce to create wrapped token address begin with 0xCC.... 
    )
        external
        onlyOwner

On native token's chain the owner calls function createPair(address toToken, address fromToken, uint256 fromChainId), where:

  • toToken - address of token contract on native chain.
  • fromToken - address of wrapped token on foreign chain.
  • fromChainId - foreign chain ID.

Security settings

  1. Only owner can set/remove authority address, using function setAuthority().
  2. Only owner can set threshold (numbers of authority required to approve swap), using function setThreshold().
  3. The owner or any authority can freeze the Bridge contract in case of anomaly detection (anomaly detection module is not implemented).
  4. Only owner can unfreeze contract.

Server setup

Import authority.js module in server app using: const auth = require("./authority.js");

Call function auth.authorize(txId, fromChainId), where:

  • txId - transaction hash,
  • fromChainId - chain ID where transaction was sent.

returns JSON string, where:

  • if all good:

    • isSuccess - true,
    • signature - authority signature,
    • token - token to receive,
    • value - tokens amount,
    • to- receiver (user's) address,
    • chainId - chain ID where to claim token,
    • bridge - address of bridge on destination network.
  • in case of error:

    • isSuccess - false,
    • message - error description

Use signature, token, value, to to call function claimMultiSig it the bridge contract on destination network

Example

    auth.authorize(txId, fromChainId)
    .then(resp => {
        response.writeHead(200, {'Content-Type': 'application/json; charset=utf-8'});
        response.end(JSON.stringify(resp));

    })
    .catch(err => {
        response.writeHead(404, {'Content-Type': 'text/html'});
        response.end(err.toString());            
    })

Authority server security

Each authority script has own private key that stored in environment (.env).

To get transaction events the script use public RPC. There is a risk of compromising a public site and providing malicious data.

Therefore, I highly recommend to use local node instead of public RPC or, at least, use different public RPC for different authority script.

CLO test net

Bridge 0xE1AF7a91EBC36E66D89a6201680dC5242796b246

Bridge implementation 0x6bae44aa40df48204337Df2ED580a0FC2642dE1B

Token implementation 0xa89f3920D5F4B333d783C9cac33E13A26C78bc2b

BSC test net

Bridge 0x3777c0b1CBFC65743149D5559db0bC199B7C647c

Bridge implementation 0xe0553dcf6e9dc1e8097420b8dac26afe3e57a0c3

Token implementation 0x57a40032d14755B9e481584C51b8eF59e93120bE

wrapped CLO token 0xCCEA50dDA26F141Fcc41Ad7e94755936d8C57e28

ETH Kovan test net

Bridge 0x9b5e4b10b405cd5cd4b056a1b57c1c653379db3c

Bridge implementation 0x6664fd73ed95cf608b5e461a6ce89212f989edca

Token implementation 0x06c0d53112b522c2caa0b150dc431386ceec0cf0

wrapped CLO token 0xcc48d2250b55b82696978184e75811f1c0ef383f

BNB main net

Bridge 0x9a1fc8C0369D49f3040bF49c1490E7006657ea56

wrapped CLO token ccCLO 0xCcbf1C9E8b4f2cDF3Bfba1098b8f56f97d219D53

ETH main net

Bridge 0x9a1fc8C0369D49f3040bF49c1490E7006657ea56

wrapped CLO token ccCLO 0xCcbf1C9E8b4f2cDF3Bfba1098b8f56f97d219D53

ETC main net

Bridge 0x9a1fc8C0369D49f3040bF49c1490E7006657ea56

wrapped CLO token ccCLO 0xCcbf1C9E8b4f2cDF3Bfba1098b8f56f97d219D53

CLO main net

Bridge 0x9a1fc8C0369D49f3040bF49c1490E7006657ea56

wrapped BNB token ccBNB 0xCC78D0A86B0c0a3b32DEBd773Ec815130F9527CF

wrapped ETH token ccETH 0xcC00860947035a26Ffe24EcB1301ffAd3a89f910

wrapped ETC token ccETC 0xCc944bF3e76d483e41CC6154d5196E2e5d348fB0

callistobridge's People

Contributors

alex39web avatar dexaran avatar yuriy77k avatar

Watchers

 avatar  avatar

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.