-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
96 lines (90 loc) · 4.14 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<head>
<title>Velodrome Alternative Merkle Claim</title>
<meta charset="utf-8">
<meta name="description" content="Alternative page from claiming Velodrome airdrop because they closed the frontend">
<link href="./some.css" rel="stylesheet" type="text/css">
</head>
<body>
<label for="address">Your address</label> <input name="address" type="text" id="address">
<input type="button" id="push" value="Generate">
<p id="r_address"></p>
<p id="amount"></p>
<p id="proof"></p>
<p id="root"></p>
<p>root should be: 0xbb99a09fb3b8499385659e82a8da93596dd07082fe86981ec06c83181dee489f</p>
<script src="./merkletree.js"></script>
<script src="./keccak256.js"></script>
<script type="module">
import { ethers } from './ethers-5.6.esm.min.js';
const HEX_STRINGS = "0123456789abcdef";
const MAP_HEX = {
0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6,
7: 7, 8: 8, 9: 9, a: 10, b: 11, c: 12, d: 13,
e: 14, f: 15, A: 10, B: 11, C: 12, D: 13,
E: 14, F: 15
};
function genProof() {
let address = document.getElementById("address").value.toLowerCase();
let value = data.airdrop[address];
if(value === undefined) {
document.getElementById("proof").innerHTML = "address not found";
return;
}
let proof = merkleTree.getProof(generateLeaf(ethers.utils.getAddress(address), ethers.utils.parseUnits(value.toString(), data.decimals)));
console.log(proof);
let result = proof.map(x => "0x" + toHex(x.data));
document.getElementById("r_address").innerHTML = "On <a href=\"https://optimistic.etherscan.io/address/0x00d59bc35174c3b250dd92a363495d38c8777a49#writeContract/\">Optimistic Etherscan</a> go to write contract, connect your wallet and put the following value, address: " + address;
document.getElementById("amount").innerHTML = "amount: " + ethers.utils.parseUnits(value.toString(), data.decimals);
document.getElementById("proof").innerHTML = "proof (bytes32[]): " + JSON.stringify(result).replace(/"/g, '');
}
document.getElementById("push").addEventListener("click", genProof);
// Fast Uint8Array to hex
function toHex(bytes) {
return Array.from(bytes || [])
.map((b) => HEX_STRINGS[b >> 4] + HEX_STRINGS[b & 15])
.join("");
}
// Mimics Buffer.from(x, 'hex') logic
// Stops on first non-hex string and returns
// https://github.com/nodejs/node/blob/v14.18.1/src/string_bytes.cc#L246-L261
function fromHex(hexString) {
const bytes = new Uint8Array(Math.floor((hexString || "").length / 2));
let i;
for (i = 0; i < bytes.length; i++) {
const a = MAP_HEX[hexString[i * 2]];
const b = MAP_HEX[hexString[i * 2 + 1]];
if (a === undefined || b === undefined) {
break;
}
bytes[i] = (a << 4) | b;
}
return i === bytes.length ? bytes : bytes.slice(0, i);
}
let data = await fetch('./airdrop.json').then(res => res.json());
function generateLeaf(address, value) {
return fromHex(
ethers.utils
.solidityKeccak256(["address", "uint256"], [address, value])
.slice(2),
);
}
const merkleTree = new MerkleTree(
// Generate leafs
Object.entries(data.airdrop).map(([address, tokens]) => {
let d = generateLeaf(
ethers.utils.getAddress(address),
ethers.utils.parseUnits(tokens.toString(), data.decimals).toString()
);
return d;
}
),
// Hashing function
keccak256,
{ sortPairs: true }
);
document.getElementById("root").innerHTML = "root is: " + "0x" + toHex(merkleTree.getRoot());
</script>
<p>Tip/Delegate your power/Send Ape: onedickdao.eth</p>
</body>
</html>