Giter Site home page Giter Site logo

sujithsomraaj / matic-proofs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tomafrench/matic-proofs

0.0 0.0 0.0 40.46 MB

Package to generate the required proofs to exit funds from Matic Network

License: MIT License

JavaScript 0.84% Solidity 24.52% TypeScript 74.64%

matic-proofs's Introduction

Matic Proofs Generator

Library to construct Proof of Burn manually using the burn transaction hash. Currently in MaticJs, this is not possible. It also includes the necessary helper functions to determine whether a withdrawal is ready to be claimed or has already been claimed.

For moving tokens from L2 > L1 (Matic > Ethereum), the tokens are burned on the Matic network by calling the native withdraw() function in any token contracts. Then the burn transaction hash has to be included to the matic checkpoint by the validators. Once the block has been included by the validators, we can generate the "Proof of Burn" by using the burn transaction hash on L2. Then the proof has to be submitted to the RootChainProxy to get the tokens to the same address on L1.

During the movement of tokens from L2 > L1, we cannot send the tokens to the address of our choice. So anyone can verify the proof of burn irrespective of the sender.

Why should I generate these proofs manually ?

If you're developing a smart contract on L1 that receives funds from another smart contract from L2, then at some point you've to generate the proofs off-chain and include them on-chain. For the purpose of acheiveing L2 > L1 communication between smart contract & transferrring tokens between them we need to have the ability to generate the proofs manually.

Built with

Prerequisites

The repository is built using hardhat. So it is recommended to install hardhat globally through npm or yarn using the following commands.

sudo npm i -g hardhat

Installation

You can install using npm (or) yarn

$ npm i @tomfrench/matic-proofs

(or)

$ yarn install @tomfrench/matic-proofs

Usage

Once installed, you can use the contracts in the library by importing them:

import {ethers} from "ethers";
import {
    buildPayloadForExit,
    encodePayload,
    EventSignature
} from "@tomfrench/matic-proofs";

let eth_provider = new ethers.providers.InfuraProvider(
    'goerli', '<YOUR INFURA KEY>'
);

let matic_provider = new ethers.providers.JsonRpcProvider('https://matic-mumbai.chainstacklabs.com');

const txHash = "<YOUR TX HASH>"; // Burn Tx Hash
const RootChainManager = "0xBbD7cBFA79faee899Eaf900F13C9065bF03B1A74"; // For Mainnet use: 0x86E4Dc95c7FBdBf52e33D563BbDB00823894C287

// Generating the proof
const proof = await buildPayloadForExit(eth_provider, matic_provider, , txHash, EventSignature.ERC20Transfer);

// Encoding the proof (RLP Encoding)
const encodedPayload = await encodePayload(proof);

// Use this Proof to Claim Tokens
console.log(encodedPayload);

Additional Info

Full list of smart contract can be found at: Testnet - Mumbai & Goerli Contracts Mainnet - Polygon & Ethereum Mainnet Contracts

All updates to the RootChain, ERC20Predicate can be found on the above links.

Setting up Local Repository

Clone the Repository using the following command

git clone https://github.com/TomAFrench/matic-proofs

Install all dependencies

yarn install

Testing

For running unit & integration tests, run the following command

yarn test

License

This Library is released under the MIT License.

matic-proofs's People

Contributors

arthcp avatar tomafrench avatar jdkanani avatar ayushkaul avatar sanchaymittal avatar atvanguard avatar ssomraaj 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.