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

Add Merkle Tree #1

Merged
merged 31 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d6875c1
Add Merkle Tree
Phanco Nov 30, 2023
4719b19
Changed editing, update main.ts scripts
Phanco Nov 30, 2023
09c12e5
Rename package to align with repo name
Phanco Nov 30, 2023
bba45fb
Added more details at README
Phanco Nov 30, 2023
0faa955
Addresses are now sorted, betting naming of `leaf`
Phanco Dec 7, 2023
54d60fe
Update Beddows value to balances.json
Phanco Dec 7, 2023
90672e9
Add unit test
Phanco Dec 8, 2023
1c931af
Update README
Phanco Dec 8, 2023
97b5279
Modulized merkleTree building process, updated test cases
Phanco Jan 2, 2024
c753d7c
Updated README
Phanco Jan 3, 2024
a9037d6
Add set instruction to README
Phanco Jan 3, 2024
3ff9267
Update test cases
Phanco Jan 4, 2024
37e9bfe
Rename merkleTree files, added merkleRoot file
Phanco Jan 4, 2024
e95c789
Improve README
Phanco Jan 4, 2024
7caf394
Merge branch 'main' of github.com:LiskHQ/lisk-token-claim into 115-im…
Phanco Jan 8, 2024
52753b6
Updated README and code according to PR suggestions
Phanco Jan 8, 2024
480430a
Update README
Phanco Jan 8, 2024
0392fc2
Fix unit test
Phanco Jan 8, 2024
2f73a29
Update format
Phanco Jan 9, 2024
4add790
keyPairs are calculated instead of stored, users can custom number of…
Phanco Jan 9, 2024
8f257da
Update comments
Phanco Jan 10, 2024
ade43be
Added append0x function, update tsconfig
Phanco Jan 10, 2024
28d64d5
Update files to snake case
Phanco Jan 10, 2024
d892067
Undo irrelavant changes
Phanco Jan 10, 2024
d3795d9
Update format
Phanco Jan 10, 2024
bedb635
Change example args to flags
Phanco Jan 10, 2024
523510c
Update code according to PR comments
Phanco Jan 11, 2024
044e9c7
Update test file names
Phanco Jan 12, 2024
2a0a7fa
Use oclif logging
Phanco Jan 17, 2024
646fc49
Update formatting and tsconfig
Phanco Jan 17, 2024
cd17364
Update log import, changed fn name build_tree -> buildTree
Phanco Jan 19, 2024
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
11 changes: 11 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
docs/
lisk/
templates/
types/
examples/
**/*.d.ts
jest.config.js
coverage
benchmark
.eslintrc.js
ecosystem.config.js
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
root: true,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
extends: ['lisk-base/ts'],
rules: {
'@typescript-eslint/member-ordering': 'off',
'@typescript-eslint/no-unsafe-argument': ['warn'],
},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all",
"useTabs": true,
"arrowParens": "avoid"
}
115 changes: 114 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,114 @@
# lisk-token-claim
# Lisk Token Claim

This library builds Merkle Tree from a snapshot and computes Merkle Root.
AndreasKendziorra marked this conversation as resolved.
Show resolved Hide resolved

## Installation

```
$ yarn
AndreasKendziorra marked this conversation as resolved.
Show resolved Hide resolved
```

## Run

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

## Files

| Name | Description | Generated By |
|--------------------------------------------------|---------------------------------------------------------------------------------------------------| ----------------------------- |
| `/data/<network>/balance.json` | Stores balance by address after a snapshot is taken, addresses must be sorted in ascending order. | Snapshot |
AndreasKendziorra marked this conversation as resolved.
Show resolved Hide resolved
| `/data/<network>/merkle-tree-result.json` | Stores MerkleRoot, and leaves for each account. | `$ yarn generate-merkle-tree` |
| `/data/<network>/merkle-tree-result-simple.json` | Stores MerkleRoot, and leaves for each account. | `$ yarn generate-merkle-tree` |

## 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

```
balance.json:
{
lskAddress: string;
balance: number;
matjazv marked this conversation as resolved.
Show resolved Hide resolved
balanceBeddows: number;
numberOfSignatures?: number;
mandatoryKeys?: string[];
optionalKeys?: string[];
}

merkle-tree-result.json:
{
merkleRoot: string;
leaves: {
lskAddress: string;
address: string;
AndreasKendziorra marked this conversation as resolved.
Show resolved Hide resolved
balance: number;
balanceBeddows: number;
AndreasKendziorra marked this conversation as resolved.
Show resolved Hide resolved
numberOfSignatures: number;
mandatoryKeys: string[];
optionalKeys: string[];
hash: string;
proof: string[];
}[];
}

merkle-tree-result-simple.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
```

matjazv marked this conversation as resolved.
Show resolved Hide resolved
### `merkle-tree-simple`
AndreasKendziorra marked this conversation as resolved.
Show resolved Hide resolved

AndreasKendziorra marked this conversation as resolved.
Show resolved Hide resolved
Due to the constraint of vm.parseJson in Foundry, fields in `merkle-tree-result` such as decimal field will trigger error.
AndreasKendziorra marked this conversation as resolved.
Show resolved Hide resolved

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merkle-tree-simple.json -> merkle-tree-result-simple.json?


## _Testing Only_

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

```
$ yarn create-balances: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
}[];
}[];
```
Loading