@@ -7,6 +7,10 @@ import "forge-std/Script.sol";
7
7
import "solady/utils/CREATE3.sol " ;
8
8
import "solady/utils/LibString.sol " ;
9
9
import "solady/utils/LibBytes.sol " ;
10
+ import "solady/utils/LibSort.sol " ;
11
+ import "solady/utils/MerkleTreeLib.sol " ;
12
+ import "solady/utils/EfficientHashLib.sol " ;
13
+
10
14
import "@openzeppelin-foundry-upgradeable/Upgrades.sol " ;
11
15
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol " ;
12
16
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol " ;
@@ -2334,3 +2338,55 @@ contract MintedAddress is VersionedScript {
2334
2338
console.log (mintedAddress);
2335
2339
}
2336
2340
}
2341
+
2342
+ struct AirdropEntry {
2343
+ address beneficiary;
2344
+ uint256 amount;
2345
+ }
2346
+
2347
+ contract SimpleMerkleTree is Script {
2348
+ mapping (bytes32 => AirdropEntry) preimages;
2349
+
2350
+ function pushEntry (
2351
+ address beneficiary ,
2352
+ uint256 amount
2353
+ ) internal returns (bytes32 ) {
2354
+ bytes32 image =
2355
+ EfficientHashLib.hash (abi.encodePacked (beneficiary, amount));
2356
+ preimages[image] =
2357
+ AirdropEntry ({beneficiary: beneficiary, amount: amount});
2358
+ return image;
2359
+ }
2360
+
2361
+ function run () public {
2362
+ bytes32 [] memory leaves = new bytes32 [](8 );
2363
+ leaves[0 ] = pushEntry (address (1 ), 1 );
2364
+ leaves[1 ] = pushEntry (address (2 ), 2 );
2365
+ leaves[2 ] =
2366
+ pushEntry (address (0x50A22f95bcB21E7bFb63c7A8544AC0683dCeA302 ), 3 );
2367
+ leaves[3 ] = pushEntry (address (4 ), 4 );
2368
+ leaves[4 ] = pushEntry (address (5 ), 5 );
2369
+ leaves[5 ] =
2370
+ pushEntry (address (0x2FB055fC77D751e2E6B7c88A1B404505154521c3 ), 6 );
2371
+ leaves[6 ] = pushEntry (address (7 ), 7 );
2372
+ leaves[7 ] = pushEntry (address (8 ), 8 );
2373
+ LibSort.sort (leaves);
2374
+
2375
+ bytes32 [] memory tree = MerkleTreeLib.build (leaves);
2376
+ bytes32 root = MerkleTreeLib.root (tree);
2377
+ console.log ("Root: " );
2378
+ console.logBytes32 (root);
2379
+ for (uint256 i = 0 ; i < leaves.length ; i++ ) {
2380
+ bytes32 [] memory proof = MerkleTreeLib.leafProof (tree, i);
2381
+ console.log ("================================== " );
2382
+ console.log ("index: " );
2383
+ console.log (i);
2384
+ console.log ("beneficiary: " );
2385
+ console.log (preimages[leaves[i]].beneficiary);
2386
+ console.log ("amount: " );
2387
+ console.log (preimages[leaves[i]].amount);
2388
+ console.log ("proof: " );
2389
+ console.logBytes (abi.encode (proof));
2390
+ }
2391
+ }
2392
+ }
0 commit comments