Skip to content

Commit

Permalink
Remove helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
orkunkl committed Jul 19, 2021
1 parent 5c4c7d8 commit 6c8c4c7
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 2,781 deletions.
45 changes: 45 additions & 0 deletions contracts/cw20-merkle-airdrop/Airdrop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import keccak256 from 'keccak256';
import { MerkleTree } from 'merkletreejs';

class Airdrop {
private tree: MerkleTree;

constructor(accounts: Array<{ address: string; amount: string }>) {
const leaves = accounts.map((a) => keccak256(a.address + a.amount));
this.tree = new MerkleTree(leaves, keccak256, { sort: true });
}

public getMerkleRoot(): string {
return this.tree.getHexRoot().replace('0x', '');
}

public getMerkleProof(account: {
address: string;
amount: string;
}): string[] {
return this.tree
.getHexProof(keccak256(account.address + account.amount))
.map((v) => v.replace('0x', ''));
}

public verify(
proof: string[],
account: { address: string; amount: string }
): boolean {
let hashBuf = keccak256(account.address + account.amount);

proof.forEach((proofElem) => {
const proofBuf = Buffer.from(proofElem, 'hex');

if (hashBuf < proofBuf) {
hashBuf = keccak256(Buffer.concat([hashBuf, proofBuf]));
} else {
hashBuf = keccak256(Buffer.concat([proofBuf, hashBuf]));
}
});

return this.getMerkleRoot() === hashBuf.toString('hex');
}
}

export = Airdrop;
11 changes: 0 additions & 11 deletions contracts/cw20-merkle-airdrop/helpers/.editorconfig

This file was deleted.

1 change: 0 additions & 1 deletion contracts/cw20-merkle-airdrop/helpers/.eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions contracts/cw20-merkle-airdrop/helpers/.eslintrc

This file was deleted.

8 changes: 0 additions & 8 deletions contracts/cw20-merkle-airdrop/helpers/.gitignore

This file was deleted.

70 changes: 0 additions & 70 deletions contracts/cw20-merkle-airdrop/helpers/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions contracts/cw20-merkle-airdrop/helpers/bin/run

This file was deleted.

3 changes: 0 additions & 3 deletions contracts/cw20-merkle-airdrop/helpers/bin/run.cmd

This file was deleted.

59 changes: 0 additions & 59 deletions contracts/cw20-merkle-airdrop/helpers/package.json

This file was deleted.

42 changes: 0 additions & 42 deletions contracts/cw20-merkle-airdrop/helpers/src/commands/generateRoot.ts

This file was deleted.

7 changes: 0 additions & 7 deletions contracts/cw20-merkle-airdrop/helpers/src/helpers.ts

This file was deleted.

1 change: 0 additions & 1 deletion contracts/cw20-merkle-airdrop/helpers/src/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions contracts/cw20-merkle-airdrop/helpers/tsconfig.json

This file was deleted.

Loading

0 comments on commit 6c8c4c7

Please sign in to comment.