Calculate all data (ENS nodes, IPFS CIDs and hashes for ENS) to paste in solidity code

This commit is contained in:
Theo 2023-07-28 05:11:38 -07:00
parent 22418191ec
commit cf6c4c6ff2
7 changed files with 143 additions and 0 deletions

@ -0,0 +1,4 @@
bytes memory classicUiIPFSContenthash = hex"e301017012208124caa06a8419371b1d2eab9180191727d1ce0c0832975362f77a679ce614b6";
bytes memory novaUiIPFSContenthash = hex"e3010170122069648b09fb7ed9a89ca153a000bc8c1bf82a779195a640609e1510dc36c28bb7";
bytes memory relayersUiIPFSContenthash = hex"e301017012203d61bed0641d7c53d5f036b6448f9d455ae6e0ceda44563009536a12e51d52cf";
bytes memory docsIPFSContenthash = hex"e3010170122008ba5879914413355290e3c8574825f7a09e59a9802a5fad1edfb3ce6a4f825b";

@ -0,0 +1,10 @@
bytes32 rootTornadoENSNode = 0xe6ae31d630cc7a8279c0f1c7cbe6e7064814c47d1785fa2703d9ae511ee2be0c;
bytes32 tornadoContractENSNode = 0xe7e1d618367ebadd8e172150a43cfc839fd19022c2be81a6e8d45e06aa1011cd;
bytes32 stakingRewardsENSNode = 0x3da4b79cd8c20d2fafb1c7cb37a62be8668f543393f6636d421fba0be735e68f;
bytes32 novaENSNode = 0xc3964c598b56aeaee4c253283fb1ebb12510b95db00960589cdc62807a2537a0;
bytes32 docsENSNode = 0xd7b8aac14a9b2507ab99b5fde3060197fddb9735afa9bf38b1f7e34923cb935e;
bytes32 relayersUIENSNode = 0x4e37047f2c961db41dfb7d38cf79ca745faf134a8392cfb834d3a93330b9108d;
bytes32 testNode = 0x121818cfd40893900bebefa5ccf60544db43ba8fa1d2d56433984132883bee88;
bytes32 tornadoContractENSLabelhash = 0x7f6dd79f0020bee2024a097aaa5d32ab7ca31126fa375538de047e7475fa8572;
bytes32 stakingRewardsENSLabelhash = 0x15826fcf9999635849b273bcd226f436dc42a8fabf43049b60971ab51d8d6b8f;

4
data/ipfsV1CIDs.txt Normal file

@ -0,0 +1,4 @@
const classicUiIPFSHash = "bafybeiebetfka2uede3rwhjovoiyagixe7i44daigklvgyxxpjtzzzquwy";
const novaUiIPFSHash = "bafybeidjmsfqt6363gujziktuaalzda37avhpemvuzagbhqvcdodnqulw4";
const relayersUiIPFSHash = "bafybeib5mg7naza5prj5l4bwwzci7hkflltobtw2irldacktnijokhksz4";
const docsIPFSHash = "bafybeiaixjmhtekecm2vfehdzbluqjpxucpftkmafjp22hw7wphgut4clm";

@ -0,0 +1,39 @@
import fs from "fs";
import path from "path";
// @ts-ignore
import { hash } from "@ensdomains/eth-ens-namehash";
import { keccak_256 } from "js-sha3";
import { DeclCalculator } from "./utils";
const rootTornadoDomain = "tornadocash.eth";
const stakingDomain = "staking-rewards.contract.tornadocash.eth";
const novaUIDomain = "nova.tornadocash.eth";
const docsDomain = "docs.tornadocash.eth";
const relayersUIDomain = "relayers-network.tornadocash.eth";
const tornadoContractDomain = "contract.tornadocash.eth";
const rootTornadoENSNode = hash(rootTornadoDomain);
const tornadoContractENSNode = hash(tornadoContractDomain);
const stakingRewardsENSNode = hash(stakingDomain);
const novaENSNode = hash(novaUIDomain);
const docsENSNode = hash(docsDomain);
const relayersUIENSNode = hash(relayersUIDomain);
const getLabelhashFromDomain = (ensDomain: string) => "0x" + keccak_256(ensDomain.split(".")[0]);
const tornadoContractENSLabelhash = getLabelhashFromDomain(tornadoContractDomain);
const stakingRewardsENSLabelhash = getLabelhashFromDomain(stakingDomain);
const { calculateDecl } = new DeclCalculator("bytes32");
const solidityCode =
calculateDecl({ rootTornadoENSNode }) +
calculateDecl({ tornadoContractENSNode }) +
calculateDecl({ stakingRewardsENSNode }) +
calculateDecl({ novaENSNode }) +
calculateDecl({ docsENSNode }) +
calculateDecl({ relayersUIENSNode }) +
"\n" +
calculateDecl({ tornadoContractENSLabelhash }) +
calculateDecl({ stakingRewardsENSLabelhash });
fs.writeFileSync(path.join("data", "ensNodesDeclarations.txt"), solidityCode);

@ -0,0 +1,28 @@
// @ts-ignore
import contentHash from "content-hash";
import fs from "fs";
import path from "path";
import { DeclCalculator } from "./utils";
const classicUiIPFSCid = "QmX2mqjsZYaZGoLHCBFX9QpV38jFtU5eNDUR3M7a7fzRY9";
const novaUiIPFSCid = "QmVS4SPsH44oJPCffUZZUGTXqCpSx3eK8UJ8YmZsSDygop";
const relayersUiIPFSCid = "QmSUG2SNSPc6UUc6tgTZJWQKExhUGqjxHQPcJNZuU5FcxW";
const docsIPFSCid = "QmNvimy7WNYG3H8cYmANLZjfvKeDFLUHDVvLMLiKj5AWsC";
const contentHashToBytesMemory = (hash: string) => `hex"${hash}"`;
const classicUiIPFSContenthash = contentHash.fromIpfs(classicUiIPFSCid);
const novaUiIPFSContenthash = contentHash.fromIpfs(novaUiIPFSCid);
const relayersUiIPFSContenthash = contentHash.fromIpfs(relayersUiIPFSCid);
const docsIPFSContenthash = contentHash.fromIpfs(docsIPFSCid);
const solidityDoublePadding = " ".repeat(8);
const { calculateDecl } = new DeclCalculator("bytes memory", solidityDoublePadding, contentHashToBytesMemory);
const solidityCode =
calculateDecl({ classicUiIPFSContenthash }) +
calculateDecl({ novaUiIPFSContenthash }) +
calculateDecl({ relayersUiIPFSContenthash }) +
calculateDecl({ docsIPFSContenthash });
fs.writeFileSync(path.join("data", "ensDomainsIPFSContenthashes.txt"), solidityCode);

@ -0,0 +1,21 @@
import fs from "fs";
import path from "path";
import CID from "cids";
import { DeclCalculator } from "./utils";
const classicUiIPFSHash = "QmX2mqjsZYaZGoLHCBFX9QpV38jFtU5eNDUR3M7a7fzRY9";
const novaUiIPFSHash = "QmVS4SPsH44oJPCffUZZUGTXqCpSx3eK8UJ8YmZsSDygop";
const relayersUiIPFSHash = "QmSUG2SNSPc6UUc6tgTZJWQKExhUGqjxHQPcJNZuU5FcxW";
const docsIPFSHash = "QmNvimy7WNYG3H8cYmANLZjfvKeDFLUHDVvLMLiKj5AWsC";
const convertCIDToV1 = (cidV0: string) => `"${new CID(cidV0).toV1().toString()}"`;
const { calculateDecl } = new DeclCalculator("const", "", convertCIDToV1);
const typescriptCode =
calculateDecl({ classicUiIPFSHash }) +
calculateDecl({ novaUiIPFSHash }) +
calculateDecl({ relayersUiIPFSHash }) +
calculateDecl({ docsIPFSHash });
fs.writeFileSync(path.join(".", "data", "ipfsV1CIDs.txt"), typescriptCode);

37
scripts/utils.ts Normal file

@ -0,0 +1,37 @@
type NodeVarObject = { [key: string]: string };
const solidityCodePadding = " ".repeat(4);
const pad = (decl: string, padding: string = solidityCodePadding) => padding + decl + "\n";
class DeclCalculator {
declType!: string;
padding!: string;
transformator!: Function;
public constructor(
declType: string,
padding: string = solidityCodePadding,
transformator: Function = (
() => (x: any) =>
x
)()
) {
this.declType = declType;
this.padding = padding;
this.transformator = transformator;
}
private displayVariableName(varObj: NodeVarObject) {
return Object.keys(varObj)[0];
}
public calculateDecl = (varObj: NodeVarObject, type: string = "bytes32") => {
const solidityVariableName = this.displayVariableName(varObj);
const solidityVariableValue = this.transformator(Object.values(varObj)[0]);
const solidityDeclaration = `${this.declType || type} ${solidityVariableName} = ${solidityVariableValue};`;
return pad(solidityDeclaration, this.padding);
};
}
export { DeclCalculator };