Skip to content

Commit

Permalink
Merge branch 'main' of github.com:LiskHQ/lisk-token-claim into 115-im…
Browse files Browse the repository at this point in the history
…plement-merkle-tree-builder
  • Loading branch information
Phanco committed Jan 8, 2024
2 parents e95c789 + 3ee3243 commit 7caf394
Show file tree
Hide file tree
Showing 48 changed files with 4,521 additions and 3,878 deletions.
12 changes: 1 addition & 11 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
docs/
lisk/
templates/
types/
examples/
**/*.d.ts
jest.config.js
coverage
benchmark
.eslintrc.js
ecosystem.config.js
**/dist/**
25 changes: 20 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
/* eslint-env node */
module.exports = {
root: true,
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
project: [
'./tsconfig.eslint.json',
'./packages/*/tsconfig.json',
'./packages/*/test/tsconfig.json',
],
},
extends: ['lisk-base/ts'],
plugins: ['@typescript-eslint'],
root: true,
rules: {
'@typescript-eslint/member-ordering': 'off',
'@typescript-eslint/no-unsafe-argument': ['warn'],
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
"@typescript-eslint/no-unsafe-member-access": 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-argument': 'off'
},
};
15 changes: 15 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: 'type: bug'
assignees: ''
---

### Expected behavior

### Actual behavior

### Steps to reproduce

### Which version(s) does this affect? (Environment, OS, etc...)
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Propose an idea for new improvements/features
title: ''
labels: ''
assignees: ''
---

### Description

Please describe what functionality is needed

### Motivation

Please describe why it is needed

### Additional Information
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_specification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature specification
about: Specification of new features/improvements
title: ''
labels: ''
assignees: ''
---

### Description

Please describe the specification of new features/improvements

### Acceptance Criteria

Please describe the conditions which must be met for this issue to close

### Additional Information
11 changes: 11 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### What was the problem?

This PR resolves #INSERT_ISSUE_NUMBER

### How was it solved?

<!--- Please describe your technical implementation -->

### How was it tested?

<!--- Please describe how you tested your changes -->
33 changes: 33 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'PR'
on:
pull_request:

jobs:
build-and-test:
runs-on: self-hosted
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install yarn
run: npm install --global yarn
- name: Install dependencies
shell: bash
run: yarn --prefer-offline
- name: Build
shell: bash
run: yarn build
- run: yarn format
- name: Check format
run: |
if [ -z "$(git status --untracked-files=no --porcelain)" ]; then
echo "All files formatted"
else
echo "Running format is required"
exit 1
fi
- run: yarn test
81 changes: 80 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,80 @@
node_modules
Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local


# generate output
dist
.cache/

# vuepress v2.x temp and cache directory
.temp
.cache

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# Example Accounts and MerkleTree are not committed
data/example/accounts.json
data/example/merkle-root.json
data/example/merkle-tree-result.json
data/example/merkle-tree-result-detailed.json
data/example/signatures.json
32 changes: 32 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Files
LICENSE
.gitkeep
mocha.opts
.DS_Store
REVISION

# rc files
.*rc
## ignore files
.*ignore

# Ignore extensions
*.png
*.sql
*.sh
*.html
*.info
*.xml
*.log
*.proto
*.csv
*.cmd
*.tsbuildinfo
*.blob
*.lock

## jest snapshot
*.snap

# project specific paths
dist/
120 changes: 6 additions & 114 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,119 +1,11 @@
# Lisk Token Claim
# lisk-token-claim
This library is the monorepo for:

This library builds Merkle Tree from a snapshot and computes Merkle Root.
### Tree Builder
Builds Merkle Tree from a snapshot and computes Merkle Root.

## Setup and Installation

```
$ git clone [email protected]:LiskHQ/lisk-token-claim.git && cd lisk-token-claim
$ yarn
```

## Run

```
$ yarn generate-merkle-tree:mainnet # Using ./data/mainnet
$ yarn generate-merkle-tree:testnet # Using ./data/testnet
$ yarn generate-merkle-tree:example # Using ./data/example
```

## Files

| Name | Description | Generated By |
|----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| --------------------------------------- |
| `/data/<network>/accounts.json` | Stores addresses, balances, and multisig details(If any) per account after a snapshot is taken, addresses must be sorted in ascending order. Will be used for MerkleTree computation. | Snapshot |
| `/data/<network>/merkle-tree-result-detailed.json` | Stores MerkleRoot, and leaves for each account. Will be used for examination by 3rd Party or public. | `$ yarn generate-merkle-tree:<network>` |
| `/data/<network>/merkle-tree-result.json` | Stores MerkleRoot, and leaves for each account. Will be used for testing and simulation for Claim Contract. | `$ yarn generate-merkle-tree:<network>` |
| `/data/<network>/merkle-root.json` | Stores MerkleRoot only. Will be used for deployment of Claim Contract. | `$ yarn generate-merkle-tree:<network>` |

## Merkle Leaf

Each leaf will be encoded as ABI-format, in the following order:

```
LSK_ADDRESS_IN_HEX: bytes20
BALANCE_IN_BEDDOWS: uint64
NUMBER_OF_SIGNATURES: uint32
MANDATORY_KEYS: bytes32[]
OPTIONAL_KEYS: bytes32[]
P.S. If the address is not a multisig address, NUMBER_OF_SIGNATURES would be 0, MANDATORY_KEYS and OPTIONAL_KEYS be []
```

## Params

```
accounts.json:
{
lskAddress: string;
balance: number;
balanceBeddows: number;
numberOfSignatures?: number;
mandatoryKeys?: string[];
optionalKeys?: string[];
}
merkle-tree-result-detailed.json:
{
merkleRoot: string;
leaves: {
lskAddress: string;
address: string;
balance: number;
balanceBeddows: number;
numberOfSignatures: number;
mandatoryKeys: string[];
optionalKeys: string[];
hash: string;
proof: string[];
}[];
}
merkle-tree-result.json:
{
merkleRoot: string;
leaves: {
b32Address: string;
balanceBeddows: number;
mandatoryKeys: string[];
numberOfSignatures: number;
optionalKeys: string[];
proof: string[];
}[];
}
# `address` is a reserved in solidity, hence `b32Address` here
```

### `merkle-tree-simple`

Due to the constraint of vm.parseJson in Foundry, fields in `merkle-tree-result` such as decimal field will trigger error.

`merkle-tree-simple.json` is a lightweight version of `merkle-tree-result-detailed.json`, which also has sufficient params for claiming.

## _Testing Only_

### Generate accounts.json from `dev-validators.json`

```
$ yarn create-accounts:example
```

### (After running `generate-merkle-tree:example`) Sign all accounts and generates `signatures.json`

```
$ yarn sign:example
```

### Params (For testing purposes only)

```
signatures.json:
{
message: string;
sigs: {
pubKey: string
r: string
s: string
}[];
}[];
```
$ yarn && yarn build
```
Loading

0 comments on commit 7caf394

Please sign in to comment.