Skip to content

Commit

Permalink
Merge pull request #79 from alexandrewolff/live-training-2
Browse files Browse the repository at this point in the history
remove erc20-bridge submodule
  • Loading branch information
jklepatch authored Jun 4, 2021
2 parents ccedd0b + 6525a4a commit 4eaaf7d
Show file tree
Hide file tree
Showing 18 changed files with 13,373 additions and 1 deletion.
1 change: 0 additions & 1 deletion live-trainings/2-polygon-matic/erc20-bridge
Submodule erc20-bridge deleted from feb539
23 changes: 23 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
31 changes: 31 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Polygon Matic bridge for ERC20

1. Run
```
yarn install
```

2. Populate the src/infura.js file with the url of your endpoint to Ethereum.

3. Run the app with
```
yarn run start
```
The app will be available at
```
http://localhost:3000/
```

4. Make sure you have Matic Mumbai testnet set in you metamask as well as matic tokens on the matic testnet, and ether + test erc20 tokens on the Ethereum Goerli testnet.

5. From the Goerli testnet, run Approve.

6. From the Goerli testnet, run Deposit.

7. Wait for ~10 minutes, your tokens should be available on Matic testnet.

8. From the Matic testnet, run Burn. Copy the transaction hash that appears in the window.

9. Wait for ~15 minutes (can be more), paste the burn transaction hash in the input and from the Goerli testnet, and run Exit. You erc20 tokens should be back on your Goerli wallet !

*Don't forget to refresh the page when you change network*
39 changes: 39 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "live-training-bridge",
"version": "0.1.0",
"private": true,
"dependencies": {
"@maticnetwork/maticjs": "^2.0.40",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file not shown.
43 changes: 43 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
19 changes: 19 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.App {
display: flex;
flex-direction: column;
align-items: center;
}

.cards {
display: flex;
justify-content: center;
}

.card {
border: 1px solid black;
padding: 50px;
margin: 10px;
display: flex;
flex-direction: column;
align-items: center;
}
98 changes: 98 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { useState, useEffect } from 'react'
import './App.css';
import infuraUrl from './infura'
import { MaticPOSClient } from '@maticnetwork/maticjs'

function App() {
const rootTokenAddress = '0x655F2166b0709cd575202630952D71E2bB0d61Af'
const childTokenAddress = '0xfe4F5145f6e09952a5ba9e956ED0C25e3Fa4c7F1'
const parentProvider = infuraUrl
const childProvider = 'https://rpc-mumbai.matic.today'
const amount = '1000000000000000000'

const [account, setAccount] = useState('')
const [parentMaticPOSClient, setParentMaticPOSClient] = useState(null)
const [childMaticPOSClient, setChildMaticPOSClient] = useState(null)
const [burnTxHash, setBurnTxHash] = useState('')

useEffect(() => {
const init = async () => {
const accounts = await window.ethereum.request({
method: 'eth_requestAccounts',
})

const parentMaticPOSClient = new MaticPOSClient({
network: "testnet",
version: "mumbai",
parentProvider: window.ethereum,
maticProvider: childProvider,
});

const childMaticPOSClient = new MaticPOSClient({
network: "testnet",
version: "mumbai",
parentProvider: parentProvider,
maticProvider: window.ethereum,
});

setAccount(accounts[0])
setParentMaticPOSClient(parentMaticPOSClient)
setChildMaticPOSClient(childMaticPOSClient)
}

if (window.ethereum) {
init()
} else {
alert('No Ethereum provider')
}
}, [])

const handleApprove = async () => {
await parentMaticPOSClient.approveERC20ForDeposit(rootTokenAddress, amount, { from: account })
}

const handleDeposit = async () => {
await parentMaticPOSClient.depositERC20ForUser(rootTokenAddress, account, amount, {
from: account,
gasPrice: '10000000000',
})
}

const handleBurn = async () => {
const burnTxHash = await childMaticPOSClient.burnERC20(childTokenAddress, amount, { from: account })
alert('Copy this transaction hash: ' + burnTxHash.transactionHash)
}

const handleExit = async () => {
await parentMaticPOSClient.exitERC20(burnTxHash, { from: account, fastProof: true })
}

return (
<div className="App">
<h1 className="title">Polygon Matic bridge functions</h1>
<div className="cards">
<div className="card">
<h2>ETH {'>'} Matic</h2>
<div>
<button onClick={handleApprove}>Approve</button>
<button onClick={handleDeposit}>Deposit</button>
</div>
</div>
<div className="card">
<h2>Matic {">"} ETH</h2>
<input
type="text"
onChange={(event) => setBurnTxHash(event.target.value)}
value={burnTxHash}
placeholder="Paste burn tx hash here" />
<div>
<button onClick={handleBurn}>Burn</button>
<button onClick={handleExit}>Exit</button>
</div>
</div>
</div>
</div>
);
}

export default App;
13 changes: 13 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
17 changes: 17 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
3 changes: 3 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/src/infura.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const infuraUrl = // paste Ethereum node URL here

export default infuraUrl
13 changes: 13 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/src/reportWebVitals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};

export default reportWebVitals;
5 changes: 5 additions & 0 deletions live-trainings/2-polygon-matic/erc20-bridge/src/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
Loading

0 comments on commit 4eaaf7d

Please sign in to comment.