-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from 0xEigenLabs/develop
feat: merge develop
- Loading branch information
Showing
102 changed files
with
22,080 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: npm i | ||
- name: Check lint | ||
run: npm run lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
node_modules | ||
lib | ||
.DS_Store | ||
*.log | ||
dump.rdb | ||
|
||
*.env | ||
bundle.js | ||
dist | ||
|
||
*.tgz | ||
config.json | ||
.nuxt | ||
docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
### Eigen Network JS SDK | ||
This repository will help developers to move assets between Ethereum chain and Eigen Network chain. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./eigen.node.min.js') | ||
} else { | ||
module.exports = require('./eigen.node.js') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
USER1_FROM=0x | ||
USER1_PRIVATE_KEY=0x | ||
USER2_FROM=0x | ||
GOERLI_ROOT_RPC= | ||
ZKEVM_RPC= | ||
PROOF_API= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Example | ||
|
||
This folder contains different examples for different cases. All examples are nodejs scripts, so can be easily run by `node` command. | ||
|
||
- plasma - plasma folder contains examples related to plasma api | ||
- pos - pos folder contains examples related to pos api | ||
|
||
## How to use | ||
|
||
### 1. Set configuration | ||
|
||
You need to configure your environment variables now. Copy `.env.example` and rename as `.env`. Now provide values for the keys mentioned there. | ||
|
||
There are some prefilled data in `config.js` but feel free to change anything as per your needs. | ||
|
||
|
||
**Note:** - Be careful with your private key, Use a key you are comfortable with for development purposes. And try not to make it public by doing actions such as committing to repo or referencing on any online site. | ||
|
||
### 2. Install package | ||
|
||
install related package by running command - | ||
|
||
``` | ||
npm i | ||
``` | ||
|
||
**Note:-** Make sure you are inside examples folder. | ||
|
||
### 3. Run script | ||
|
||
run any example script by using | ||
|
||
``` | ||
node <file_path> | ||
``` | ||
|
||
let's run a plasma erc20 balance example | ||
|
||
``` | ||
node plasma/erc20/balance.js | ||
``` | ||
|
||
## Run example using source code | ||
|
||
This section helps you to run the example code with current source code. Generally it is needed for debugging purpose. | ||
|
||
### 1. Build & link source code | ||
|
||
Run the below command inside root of this project. | ||
|
||
``` | ||
npm run build:link | ||
``` | ||
|
||
You might get permission issue, in this case run the command using `sudo`. | ||
|
||
### 2. Link the library | ||
|
||
#### 2.1 Move into examples folder | ||
|
||
``` | ||
cd examples | ||
``` | ||
|
||
#### 2.2 run link command | ||
|
||
``` | ||
npm run link:lib | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const dotenv = require('dotenv'); | ||
const path = require('path'); | ||
const env = dotenv.config({ | ||
path: path.join(__dirname, '.env') | ||
}); | ||
|
||
if (env.error) { | ||
throw new Error("no env file found"); | ||
} | ||
|
||
module.exports = { | ||
rpc: { | ||
zkEvm: { | ||
parent: process.env.GOERLI_ROOT_RPC, | ||
child: process.env.ZKEVM_RPC, | ||
}, | ||
}, | ||
zkEvm: { | ||
parent: { | ||
ether: '0x0000000000000000000000000000000000000000', | ||
erc20: 'your erc20 address' | ||
}, | ||
child: { | ||
ether: '0x0000000000000000000000000000000000000000', | ||
erc20: 'your erc20 address' | ||
}, | ||
}, | ||
user1: { | ||
// '<paste your private key here>' - A sample private key prefix with `0x` | ||
privateKey: process.env.USER1_PRIVATE_KEY, | ||
//'<paste address belonging to private key here>', Your address | ||
address: process.env.USER1_FROM | ||
}, | ||
user2: { | ||
address: process.env.USER2_FROM | ||
}, | ||
proofApi: process.env.PROOF_API | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "examples", | ||
"version": "1.0.0", | ||
"description": "## How to use", | ||
"main": "config.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"link:lib": "npm link @0xEigenLabs/eigen-sdk-js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@maticnetwork/maticjs-web3": "^1.0.4", | ||
"@truffle/hdwallet-provider": "^1.5.1-alpha.1", | ||
"dotenv": "^10.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const bn = require('bn.js') | ||
const HDWalletProvider = require('@truffle/hdwallet-provider') | ||
const config = require('./config') | ||
const { ZkEvmClient, use } = require('../dist/eigen.node') | ||
const SCALING_FACTOR = new bn(10).pow(new bn(18)) | ||
const { Web3ClientPlugin } = require('@maticnetwork/maticjs-web3') | ||
|
||
use(Web3ClientPlugin) | ||
|
||
const privateKey = config.user1.privateKey | ||
const userAddress = config.user1.address | ||
|
||
const getZkEvmClient = (network = 'zkevm', version = '0.0.1') => { | ||
const zkEvmClient = new ZkEvmClient() | ||
console.log("the rpc address:") | ||
console.log(config.rpc.zkEvm.child) | ||
console.log(config.rpc.zkEvm.parent) | ||
return zkEvmClient.init({ | ||
log: true, | ||
network: network, | ||
version: version, | ||
child: { | ||
provider: new HDWalletProvider(privateKey, config.rpc.zkEvm.child), | ||
defaultConfig: { | ||
from: userAddress, | ||
}, | ||
}, | ||
parent: { | ||
provider: new HDWalletProvider(privateKey, config.rpc.zkEvm.parent), | ||
defaultConfig: { | ||
from: userAddress, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
module.exports = { | ||
SCALING_FACTOR, | ||
getZkEvmClient: getZkEvmClient, | ||
zkEvm: config.zkEvm, | ||
from: config.user1.address, | ||
privateKey: config.user1.privateKey, | ||
to: config.user2.address, | ||
proofApi: config.proofApi, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const { getZkEvmClient, zkEvm, from } = require('../../utils_zkevm'); | ||
|
||
const execute = async () => { | ||
const client = await getZkEvmClient(); | ||
const erc20Token = client.erc20(zkEvm.parent.erc20, true); | ||
|
||
const result = await erc20Token.approve(1000); | ||
|
||
const txHash = await result.getTransactionHash(); | ||
console.log("txHash", txHash); | ||
const receipt = await result.getReceipt(); | ||
console.log("receipt", receipt); | ||
|
||
} | ||
execute().then(() => { | ||
}).catch(err => { | ||
console.error("err", err); | ||
}).finally(_ => { | ||
process.exit(0); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const { getZkEvmClient, zkEvm, from } = require('../../utils_zkevm'); | ||
|
||
const execute = async () => { | ||
const client = await getZkEvmClient(); | ||
const erc20Token = client.erc20(zkEvm.parent.erc20, true); | ||
|
||
const result = await erc20Token.approveMax(); | ||
|
||
const txHash = await result.getTransactionHash(); | ||
console.log("txHash", txHash); | ||
const receipt = await result.getReceipt(); | ||
console.log("receipt", receipt); | ||
|
||
} | ||
execute().then(() => { | ||
}).catch(err => { | ||
console.error("err", err); | ||
}).finally(_ => { | ||
process.exit(0); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { getZkEvmClient, zkEvm, from } = require('../../utils_zkevm'); | ||
|
||
const execute = async () => { | ||
const client = await getZkEvmClient(); | ||
const erc20Token = client.erc20(zkEvm.child.ether); | ||
|
||
const result = await erc20Token.getBalance(from); | ||
|
||
console.log("result", result); | ||
|
||
} | ||
execute().then(() => { | ||
}).catch(err => { | ||
console.error("err", err); | ||
}).finally(_ => { | ||
process.exit(0); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { getZkEvmClient, zkEvm, from } = require('../../utils_zkevm'); | ||
|
||
const execute = async () => { | ||
const client = await getZkEvmClient(); | ||
const erc20Token = client.erc20(zkEvm.parent.erc20, true); | ||
|
||
const result = await erc20Token.deposit(10, from, { | ||
from | ||
}); | ||
|
||
const txHash = await result.getTransactionHash(); | ||
console.log("txHash", txHash); | ||
const receipt = await result.getReceipt(); | ||
console.log("receipt", receipt); | ||
|
||
} | ||
execute().then(() => { | ||
}).catch(err => { | ||
console.error("err", err); | ||
}).finally(_ => { | ||
process.exit(0); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { getZkEvmClient, zkEvm, from } = require('../../utils_zkevm'); | ||
//const transactionHash = '0x4cd97048e77215b93bbfeb1e5ee7eadef74cccba13de7cd286e55f17726385c2'; | ||
const transactionHash = '0x0596ba594f764a53759f584731a435a111f0d5d4eaa790a6c34fb63768d3f384'; | ||
|
||
|
||
const execute = async () => { | ||
const client = await getZkEvmClient(); | ||
const erc20Token = client.erc20(zkEvm.child.erc20); | ||
|
||
const result = await erc20Token.depositClaim(transactionHash, { | ||
from, | ||
gasLimit: 300000, | ||
gasPrice: 10000000000, | ||
// maxPriorityFeePerGas: 6000000000, | ||
}); | ||
|
||
const txHash = await result.getTransactionHash(); | ||
console.log("txHash", txHash); | ||
const receipt = await result.getReceipt(); | ||
console.log("receipt", receipt); | ||
|
||
} | ||
execute().then(() => { | ||
}).catch(err => { | ||
console.error("err", err); | ||
}).finally(_ => { | ||
process.exit(0); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { getZkEvmClient, zkEvm, from } = require('../../utils_zkevm'); | ||
const ether = require("ethers") | ||
|
||
const execute = async () => { | ||
const client = await getZkEvmClient(); | ||
const etherToken = client.erc20(zkEvm.parent.ether, true); | ||
const result = await etherToken.deposit("20000000000000000", from); | ||
|
||
const txHash = await result.getTransactionHash(); | ||
console.log("txHash", txHash); | ||
const receipt = await result.getReceipt(); | ||
console.log("receipt", receipt); | ||
|
||
}; | ||
|
||
execute().then(() => { | ||
}).catch(err => { | ||
console.error("err", err); | ||
}).finally(_ => { | ||
process.exit(0); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { getZkEvmClient, zkEvm, from } = require('../../utils_zkevm'); | ||
|
||
const execute = async () => { | ||
const client = await getZkEvmClient(); | ||
const erc20Token = client.erc20(zkEvm.parent.erc20, true); | ||
|
||
const result = await erc20Token.depositWithPermit(100, from, { | ||
from | ||
}); | ||
|
||
const txHash = await result.getTransactionHash(); | ||
console.log("txHash", txHash); | ||
const receipt = await result.getReceipt(); | ||
console.log("receipt", receipt); | ||
|
||
} | ||
execute().then(() => { | ||
}).catch(err => { | ||
console.error("err", err); | ||
}).finally(_ => { | ||
process.exit(0); | ||
}) |
Oops, something went wrong.