Skip to content

Commit

Permalink
feat: long-running batch deposit&withdraw workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ShookLyngs committed Sep 19, 2022
1 parent e0640be commit e0c3734
Show file tree
Hide file tree
Showing 54 changed files with 12,798 additions and 1,424 deletions.
103 changes: 28 additions & 75 deletions .github/workflows/batch-deposit-withdraw.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
name: Batch Deposit&Withdraw
name: Batch Deposit & Withdraw On Alphanet_v1

on:
workflow_dispatch:
inputs:
derived:
description: 'how many derived accounts to use'
required: true
default: '10'
type: string
claim:
description: 'claim for derived accounts'
required: true
default: true
type: boolean
rounds:
description: 'for-loop rounds'
required: true
default: '1'
type: string
capacity:
description: 'deposit/withdraw CKB capacity'
required: true
default: '400'
type: string
sudt-lock-args:
description: 'sudt lock_args'
required: false
type: string
sudt-amount:
description: 'deposit/withdraw sudt amount'
required: false
type: string
sudt-decimals:
description: 'decimals of sudt amount'
required: false
type: string
workflow_dispatch

jobs:
check-secrets:
Expand All @@ -48,54 +15,40 @@ jobs:
if: ${{ env.KEY1 != '' }}
run: echo "::set-output name=available::true"

batch-claim-for-l1:
batch-transactions:
runs-on: ubuntu-latest
needs: check-secrets
if: needs.check-secrets.outputs.available
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Account-Faucet
working-directory: scripts/account-faucet
if: ${{ inputs.claim }}
run: npm install && npm run build
- name: Claim for derived accounts
working-directory: scripts/account-faucet
if: ${{ inputs.claim }}
run: |
account-faucet batch-claim-l1 \
--private-key ${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }} \
--derived-count ${{ inputs.derived }} \
--network alphanet_v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'

batch-actions:
runs-on: ubuntu-latest
needs: [check-secrets, batch-claim-for-l1]
if: needs.check-secrets.outputs.available
strategy:
fail-fast: false
matrix:
action: [batch-deposit, batch-withdraw]
steps:
- uses: actions/checkout@v2
- 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: Create batch action
- name: Run batch-transactions
working-directory: scripts/light-godwoken-cli
run: |
for _ in $(seq 1 ${{ inputs.rounds }})
do
echo "[${{ matrix.action }}] round $_"
lgc ${{ matrix.action }} \
--private-key ${{ secrets.GODWOKEN_TESTNET_PK1 }} \
--derived-count ${{ inputs.derived }} \
--capacity ${{ inputs.capacity }} \
--sudt-lock-args "${{ inputs.sudt-lock-args }}" \
--sudt-amount "${{ inputs.sudt-amount }}" \
--sudt-decimals "${{ inputs.sudt-decimals }}" \
--network alphanet_v1;
echo "---"
sleep 10s
done
lgc batch-transactions \
--private-key ${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }} \
--start-time ${{ steps.start-time.outputs.result }} \
--duration 180 \
--network alphanet_v1
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: batch-transactions
path: ${{ github.workspace }}/scripts/light-godwoken-cli/artifacts
73 changes: 73 additions & 0 deletions .github/workflows/batch-prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Batch Prepare For Batch Transactions

on:
workflow_dispatch

jobs:
check-secrets:
runs-on: ubuntu-latest
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
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 on L1
working-directory: scripts/account-faucet
run: |
account-faucet batch-claim-l1 \
--private-key ${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }} \
--network alphanet_v1
- name: Claim for derived accounts on L2
working-directory: scripts/account-faucet
run: |
account-faucet batch-claim-l2 \
--private-key ${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }} \
--network alphanet_v1
batch-prepare:
runs-on: ubuntu-latest
needs: [check-secrets, batch-claim]
if: needs.check-secrets.outputs.available
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
working-directory: scripts/light-godwoken-cli
run: |
lgc batch-prepare \
--private-key ${{ secrets.GODWOKEN_TEST_PRIVATE_KEY }} \
--network alphanet_v1
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: batch-prepare
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 = ref-custom-tokens
2 changes: 1 addition & 1 deletion light-godwoken
37 changes: 20 additions & 17 deletions scripts/account-faucet/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Account-Faucet

## What is this?
Originally, when you're claiming faucet for your Godwoken layer 2 account, you need to go through the following 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
2. Go to [Godwoken Bridge](https://testnet.bridge.godwoken.io/) and deposit CKB to your Godwoken L2 account

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 layer 2 accounts.
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.

## Setup environment
Go to `Account-Faucet` folder in `Godwoken-Tests` and set up the tool:
Expand All @@ -15,16 +15,16 @@ $ cd scripts/account-faucet
$ npm install && npm run build
```

## Claim faucet for layer 2
If you want to claim faucet directly to your layer 2 account, you can try the `claim-l2` command.
The `claim-l2` command calculates your layer 2 address, then automatically claim faucet to it, so you don't waste extra fee or time doing them all manually.
## 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 layer 2:
You can use `-e` or `--eth-address` to claim faucet for L2:
```bash
$ account-faucet claim-l2 --eth-address <ETH_ADDRESS>
```
Or if you only have a privateKey on hand, you can use `-p` or `--private-key` to claim faucet for layer 2:
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>
```
Expand All @@ -38,16 +38,16 @@ Right now the tool supports these networks:
- testnet_v1
- alphanet_v1

## Claim faucet for layer1
If you only want to claim faucet to your L1 account instead of layer 2 account, you can try the `claim-l1` command.
The `claim-l1` command takes either `--private-key` or `--ckb-address` as param, and will automatically claim faucet to your L1 account, so you don't need to do it by yourself.
## 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` to claim faucet for L1:
Or you can use `-c` or `--ckb-address`:
```bash
$ account-faucet claim-l1 -c <CKB_ADDRESS>
```
Expand All @@ -58,21 +58,24 @@ You can use `-n` or `--network` option to claim faucet on different network:
$ account-faucet claim-l1 --private-key <PRIVATE_KEY> --network <NETWORK>
```

## 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 (`-e` or `--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
$ account-faucet get-l2-address --eth-address <ETH_ADDRESS>
```
Or pass a CKB Private Key (`-p` or `--private-key`):
Or pass a Private Key (`-p` or `--private-key`):
```bash
$ 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
$ account-faucet get-l2-address --eth-address <ETH_ADDRESS> --network <NETWORK>
```
2 changes: 1 addition & 1 deletion scripts/account-faucet/bin/cli
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
#!/usr/bin/env -S node --enable-source-maps
require('../dist/index')
Loading

0 comments on commit e0c3734

Please sign in to comment.