Skip to content

Commit

Permalink
Generate proofs into json from json
Browse files Browse the repository at this point in the history
  • Loading branch information
lykhonis committed Oct 24, 2023
1 parent 4dbfb4b commit 556a312
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ src = "src"
out = "out"
libs = ["lib"]
extra_output_files = ["metadata"]
fs_permissions = [{ access = "read", path = "./scripts/" }]
fs_permissions = [{ access = "read-write", path = "./scripts/" }]

# solidity compiler
solc = "0.8.17"
Expand Down
1 change: 1 addition & 0 deletions scripts/assets/lsp7/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/genesis-drop.json
/genesis-deployed.json
40 changes: 26 additions & 14 deletions scripts/assets/lsp7/GenesisDigitalAsset.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ contract Drop is Script {
for (uint256 i = 0; i < jsonData.claims.length; i++) {
Claim memory claim = jsonData.claims[i];
console.log("-", i, claim.profile, claim.amount);
data[i] = keccak256(abi.encodePacked(uint256(i), claim.profile, claim.amount));
data[i] = keccak256(abi.encodePacked(i, claim.profile, claim.amount));
console.logBytes32(data[i]);
fundAmount += claim.amount;
}

Expand All @@ -59,20 +60,31 @@ contract Drop is Script {

// fund drop
console.log("Fund drop:", fundAmount);
vm.broadcast(owner);
vm.startBroadcast(owner);
genesisAsset.reserve(fundAmount);
genesisAsset.transfer(owner, address(drop), fundAmount, true, "");
vm.stopBroadcast();

// generate proofs
{
string memory claimsJson = "{}";
for (uint256 i = 0; i < jsonData.claims.length; i++) {
Claim memory claim = jsonData.claims[i];
bytes32[] memory proof = merkle.getProof(data, i);

string memory object = string.concat("claim-", Strings.toString(i));
vm.serializeUint(object, "index", i);
vm.serializeAddress(object, "profile", claim.profile);
vm.serializeUint(object, "amount", claim.amount);
string memory json = vm.serializeBytes32(object, "proof", proof);

// dispose drop and remaining assets
// {
// vm.broadcast(owner);
// drop.dispose(owner);

// uint256 balance = genesisAsset.balanceOf(owner);
// if (balance > 0) {
// console.log("Dispose remaining assets:", balance);
// vm.broadcast(owner);
// genesisAsset.release(balance);
// }
// }
claimsJson = vm.serializeString("claims", Strings.toString(i), json);
}

vm.serializeString("", "claims", claimsJson);
string memory json = vm.serializeAddress("", "address", address(drop));

vm.writeJson(json, string.concat(vm.projectRoot(), "/scripts/assets/lsp7/genesis-deployed.json"));
}
}
}

0 comments on commit 556a312

Please sign in to comment.