Git Product home page Git Product 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 0x6664fD73ed95CF608B5e461A6cE89212F989EdCA

Token implementation 0xa89f3920D5F4B333d783C9cac33E13A26C78bc2b

BSC test net

Bridge 0x05ef4B789C75c02d5182e6EfB7c64230Ec9B58b2

Token implementation 0x57a40032d14755B9e481584C51b8eF59e93120bE

wrapped CLO token 0xBf48DCa064aC248Ba2096Fb7e5F41724322942E9

callistobridge's People

Contributors

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