Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: batch deposit&withdraw workflow #190

Merged
merged 4 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions .github/workflows/account-faucet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Account Faucet

on:
schedule:
- cron: '0 0 * * *' # every 24 hours
- cron: '0 22 * * *' # everyday at 06:00 AM (UTC+8)

jobs:
check-secrets:
Expand Down Expand Up @@ -44,34 +44,44 @@ jobs:
restore-keys: |
${{ runner.os }}-node_modules-

- name: Install dependencies
- name: Setup environment
working-directory: scripts/account-faucet
run: npm install
run: npm install && npm run build

- name: Claim faucet for open accounts
- name: Claim for open test accounts
working-directory: scripts/account-faucet
env:
KEY1: 1390c30e5d5867ee7246619173b5922d3b04009cab9e9d91e14506231281a997
KEY2: 2dc6374a2238e414e51874f514b0fa871f8ce0eb1e7ecaa0aed229312ffc91b0
KEY3: dd50cac37ec6dd12539a968c1a2cbedda75bd8724f7bcad486548eaabb87fc8b
run: |
npm run faucet -- claim -p $KEY1
npm run faucet -- claim -p $KEY2
npm run faucet -- claim -p $KEY3
npm run faucet -- claim -p $KEY1 -n alphanet_v1
npm run faucet -- claim -p $KEY2 -n alphanet_v1
npm run faucet -- claim -p $KEY3 -n alphanet_v1
account-faucet claim-l2 -p $KEY1
account-faucet claim-l2 -p $KEY2
account-faucet claim-l2 -p $KEY3
account-faucet claim-l2 -p $KEY1 -n alphanet_v1
account-faucet claim-l2 -p $KEY2 -n alphanet_v1
account-faucet claim-l2 -p $KEY3 -n alphanet_v1

- name: Claim faucet for testnet/alphanet accounts
- name: Claim for private accounts
working-directory: scripts/account-faucet
env:
KEY1: ${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }}
KEY2: ${{ secrets.GODWOKEN_TEST_PRIVATE_KEY2 }}
KEY3: ${{ secrets.GW_TESTNET_V1_TEST_PK }}
run: |
npm run faucet -- claim -p $KEY1
npm run faucet -- claim -p $KEY2
npm run faucet -- claim -p $KEY3
npm run faucet -- claim -p $KEY1 -n alphanet_v1
npm run faucet -- claim -p $KEY2 -n alphanet_v1
npm run faucet -- claim -p $KEY3 -n alphanet_v1
account-faucet claim-l2 -p $KEY1
account-faucet claim-l2 -p $KEY2
account-faucet claim-l2 -p $KEY3
account-faucet claim-l2 -p $KEY1 -n alphanet_v1
account-faucet claim-l2 -p $KEY2 -n alphanet_v1
account-faucet claim-l2 -p $KEY3 -n alphanet_v1

- name: Claim for batch-deposit/batch-withdraw derived accounts
working-directory: scripts/account-faucet
env:
KEY1: ${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }}
run: |
account-faucet batch-claim-l1 \
--private-key $KEY1 \
--derived-count 10 \
--network alphanet_v1
57 changes: 57 additions & 0 deletions .github/workflows/batch-deposit-withdraw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Batch Deposit & Withdraw On Alphanet_v1

on:
workflow_dispatch:
schedule:
- cron: '0 */4 * * *' # runs every 4 hour

jobs:
check-secrets:
runs-on: ubuntu-latest
if: github.repository == 'godwokenrises/godwoken-tests'
outputs:
available: ${{ steps.check.outputs.available }}
steps:
- id: check
env:
KEY1: '${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }}'
if: ${{ env.KEY1 != '' }}
run: echo "::set-output name=available::true"

batch-deposit-and-withdraw:
runs-on: ubuntu-latest
needs: check-secrets
if: needs.check-secrets.outputs.available
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'

- uses: actions/github-script@v6
id: start-time
with:
script: return Date.now()
result-encoding: string

- name: Print start-time
run: echo "${{ steps.start-time.outputs.result }}"

- name: Setup Light-Godwoken-CLI
working-directory: scripts/light-godwoken-cli
run: ./init.sh

- name: Run batch-deposit-withdraw
working-directory: scripts/light-godwoken-cli
run: |
lgc batch-deposit-withdraw \
--private-key ${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }} \
--start-time ${{ steps.start-time.outputs.result }} \
--duration 240 \
--network alphanet_v1

- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: batch-deposit-withdraw
path: ${{ github.workspace }}/scripts/light-godwoken-cli/artifacts
79 changes: 79 additions & 0 deletions .github/workflows/batch-prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Batch Prepare For Derived Accounts

on:
workflow_dispatch:
inputs:
prepare-sudt:
type: boolean
required: true
default: false
description: "Prepare sUDT for derived accounts (optional)"
schedule:
- cron: '0 22 * * 0,2,4' # at 06:00 AM on Monday & Wednesday & Friday (UTC+8)

jobs:
check-secrets:
runs-on: ubuntu-latest
if: github.repository == 'godwokenrises/godwoken-tests'
outputs:
available: ${{ steps.check.outputs.available }}
steps:
- id: check
env:
KEY1: '${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }}'
if: ${{ env.KEY1 != '' }}
run: echo "::set-output name=available::true"

batch-claim:
needs: check-secrets
if: needs.check-secrets.outputs.available
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
command: [ batch-claim-l1, batch-claim-l2 ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'npm'
cache-dependency-path: scripts/account-faucet/package-lock.json

- name: Setup Account-Faucet
working-directory: scripts/account-faucet
run: npm i && npm run build

- name: Claim for derived accounts
working-directory: scripts/account-faucet
run: |
account-faucet ${{ matrix.command }} \
--private-key ${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }} \
--network alphanet_v1

batch-prepare-sudt:
runs-on: ubuntu-latest
needs: [check-secrets, batch-claim]
if: needs.check-secrets.outputs.available && ${{ github.event.inputs.prepare-sudt }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'

- name: Setup Light-Godwoken-CLI
working-directory: scripts/light-godwoken-cli
run: ./init.sh

- name: Run batch-prepare-sudt
working-directory: scripts/light-godwoken-cli
run: |
lgc batch-prepare-sudt \
--private-key ${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }} \
--network alphanet_v1

- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: batch-prepare-sudt
path: ${{ github.workspace }}/scripts/light-godwoken-cli/artifacts
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
[submodule "light-godwoken"]
path = light-godwoken
url = https://github.com/nervosnetwork/light-godwoken.git
branch = ref-node-env
branch = v0.3.1
2 changes: 1 addition & 1 deletion light-godwoken
86 changes: 49 additions & 37 deletions scripts/account-faucet/README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,81 @@
# Account-Faucet

## What is this?
This is Account-Faucet, a CLI tool to claim faucet for your Godwoken layer 2 accounts.

## Why should I use it?
Originally, when you need to claim faucet to your Godwoken layer 2 wallet, you need to go through all these steps:
Originally, when you're claiming faucet for your Godwoken L2 account, you need to go through the following steps:
1. Go to [Faucet](https://faucet.nervos.org) page and claim faucet to your CKB account
2. Go to [Godwoken Bridge](https://testnet.bridge.godwoken.io/) and deposit CKB to your Godwoken layer 2 account

The steps above are fairly simple, but not so easy if you do it manually, every day.
With this CLI tool, you can actually finish the entire process in one command, which can save you a lot of time.
2. Go to [Godwoken Bridge](https://testnet.bridge.godwoken.io/) and deposit CKB to your Godwoken L2 account

All you need to prepare is your `ETH address`, or your `CKB private key`.
With this CLI tool, you can actually finish the entire process in one command, which should save you a lot of time. And this is Account-Faucet, a CLI tool to claim faucet for your Godwoken L2 accounts.

## Ready
1. Go to `Account-Faucet` folder in `Godwoken-Tests`:
## Setup environment
Go to `Account-Faucet` folder in `Godwoken-Tests` and set up the tool:
```bash
# Position: godwoken-tests/
$ cd scripts/account-faucet
$ npm install && npm run build
```
2. Install dependencies:

## Claim faucet for L2
If you want to claim faucet directly to your L2 account, you can try the `claim-l2` command.
The `claim-l2` command calculates your `L2 Deposit Address`, then automatically claim faucet to the address, so you don't waste extra fee or time doing them all manually.

### Claim with ETH Address (Recommended) or with Private Key
You can use `-e` or `--eth-address` to claim faucet for L2:
```bash
$ npm install
$ account-faucet claim-l2 --eth-address <ETH_ADDRESS>
```
Or if you only have a private key on hand, you can use `-p` or `--private-key` option to claim faucet for your L2 account:
```bash
$ account-faucet claim-l2 --private-key <PRIVATE_KEY>
```

## Claim faucet

### Claim with ETH Address
If you're more familiar with your `ETH address`, we recommend you to use this command:
### Claim on different networks
You can use `-n` or `--network` option to claim faucet on different network:
```bash
$ npm run faucet -- claim -e <ETH_ADDRESS>
$ account-faucet claim-l2 --private-key <PRIVATE_KEY> --network <NETWORK>
```
Right now the tool supports these networks:
- testnet_v1
- alphanet_v1

### Claim with CKB Private Key
If you prefer to claim faucet with your `CKB Layer 1 Private Key`:
## Claim faucet for L1
If you only want to claim faucet to your L1 account instead of L2 account, you can try the `claim-l1` command.
The `claim-l1` command takes either `--private-key` or `--ckb-address`, and will automatically claim faucet to your L1 account, so you don't need to do it by yourself.

### Claim with Private Key or CKB Address
You can use `-p` or `--private-key` to claim faucet for L1:
```bash
$ account-faucet claim-l1 -p <PRIVATE_KEY>
```
Or you can use `-c` or `--ckb-address`:
```bash
$ npm run faucet -- claim -p <CKB_PRIVATE_KEY>
$ account-faucet claim-l1 -c <CKB_ADDRESS>
```

### Claim faucet on different networks
### Claim on different networks
You can use `-n` or `--network` option to claim faucet on different network:
```bash
$ $ npm run faucet -- claim -p <CKB_PRIVATE_KEY> -n <NETWORK>
$ account-faucet claim-l1 --private-key <PRIVATE_KEY> --network <NETWORK>
```

One thing to be noted, `mainnet_v1` is not available for the `--network` option.

## Get Layer2 Deposit Address
## Get L2 Deposit Address

### Calculate with ETH Address or CKB Private Key
This is an util command to calculate the Layer2 Deposit Address.
It's a very similar command to the `claim` command, you can pass a ETH address:
This is an util command to calculate the `L2 Deposit Address` of your account.

L2 Deposit Address is an CKB address which if you transfer capacity to the specific address, Godwoken will take it away and then give you capacity on L2. The process of transferring capacity to a L2 Deposit Address is what we called "Deposit".

It's a very similar command to the `claim-l1` or `claim-l2` command, you can either pass an ETH address (`-e` or `--eth-address`):
```bash
$ npm run faucet -- get-l2-address -e <ETH_ADDRESS>
$ account-faucet get-l2-address --eth-address <ETH_ADDRESS>
```
Or pass a CKB Private Key:
Or pass a Private Key (`-p` or `--private-key`):
```bash
$ npm run faucet -- get-l2-address -p <CKB_PRIVATE_KEY>
$ account-faucet get-l2-address --private-key <PRIVATE_KEY>
```

### Address on different networks
You can use `-n` or `--network` option to calculate the Layer2 Deposit Address on different network:
You can use `-n` or `--network` option to calculate the `L2 Deposit Address` on different network:
```bash
$ npm run faucet -- get-l2-address -e <ETH_ADDRESS> -n <NETWORK>
$ account-faucet get-l2-address --eth-address <ETH_ADDRESS> --network <NETWORK>
```

Right now the supported networks are:
- testnet_v1
- alphanet_v1
File renamed without changes.
Loading