Created
December 6, 2023 18:29
-
-
Save jeffywu/882111d670faaacc7a0541989bb46fb2 to your computer and use it in GitHub Desktop.
Gnosis Transaction Builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity 0.8.17; | |
import "forge-std/Script.sol"; | |
struct MethodCall { | |
address to; | |
uint256 value; | |
bytes callData; | |
} | |
contract GnosisHelper is Script { | |
function generateBatch(string memory path, MethodCall[] memory calls) internal { | |
string memory meta = "meta"; | |
vm.serializeString(meta, "name", "Transactions Batch"); | |
meta = vm.serializeString(meta, "txBuilderVersion", "1.16.1"); | |
string memory id = "base"; | |
vm.serializeUint(id, "chainId", block.chainid); | |
vm.serializeUint(id, "createdAt", block.timestamp * 1000); | |
vm.serializeString(id, "version", "1.0"); | |
vm.serializeString(id, "transactions", new string[](calls.length)); | |
string memory output = vm.serializeString(id, "meta", meta); | |
vm.writeJson(output, path); | |
for (uint256 i; i < calls.length; i++) { | |
string memory t = "txn"; | |
vm.serializeAddress(t, "to", calls[i].to); | |
vm.serializeUint(t, "value", calls[i].value); | |
vm.serializeBytes(t, "data", calls[i].callData); | |
string memory txn = _txnTemplate(t); | |
string memory key = string(abi.encodePacked(".transactions[", vm.toString(i), "]")); | |
vm.writeJson(txn, path, key); | |
} | |
} | |
function _txnTemplate(string memory t) private returns (string memory) { | |
string memory method = "contractMethod"; | |
vm.serializeString(method, "inputs", new string[](0)); | |
vm.serializeString(method, "name", "fallback"); | |
method = vm.serializeBool(method, "payable", true); | |
return vm.serializeString(t, "contractMethod", method); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment