Skip to content

Commit

Permalink
Private proposal creation
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Jun 6, 2024
1 parent e719332 commit 2615a49
Show file tree
Hide file tree
Showing 7 changed files with 451 additions and 143 deletions.
14 changes: 7 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# PUBLIC ENV VARS

# General
NEXT_PUBLIC_DAO_ADDRESS=0xeB4586617089270Fe042F69Bf799590AF224807a
NEXT_PUBLIC_TOKEN_ADDRESS=0x12b2574840dB17C2278d9725a2679E97FE266075
NEXT_PUBLIC_DAO_ADDRESS=0x6C477915CC803518723d4Bdd5B2170cf38A57203
NEXT_PUBLIC_TOKEN_ADDRESS=0xf7A8F99a1d0AFB3C95f80770223b00e062C6Ec19

# Plugin addresses
NEXT_PUBLIC_MULTISIG_PLUGIN_ADDRESS=0xd8Fe1194Cf90eF38b54A110EcfeAE8F2AA5Dfe86
NEXT_PUBLIC_EMERGENCY_MULTISIG_PLUGIN_ADDRESS=0xeCBa720A8645B198b2637f6559B9155E4bc3B566
NEXT_PUBLIC_DUAL_GOVERNANCE_PLUGIN_ADDRESS=0xd9F6A2533efab98bA016Cb1D3001b6Ec1C246485
NEXT_PUBLIC_PUBLIC_KEY_REGISTRY_CONTRACT_ADDRESS=0xbD8E6796c937217fD728567C650Ab64F8CB702fC
NEXT_PUBLIC_DELEGATION_WALL_CONTRACT_ADDRESS=0x964140B4Aad144bfe9cCDc6EB06baeBc4bed3357
NEXT_PUBLIC_MULTISIG_PLUGIN_ADDRESS=0x0fC611670228A61824c317926f30e8a2615aa1A3
NEXT_PUBLIC_EMERGENCY_MULTISIG_PLUGIN_ADDRESS=0x619d6661eA06b917e26694f23c5Bb32fa0456773
NEXT_PUBLIC_DUAL_GOVERNANCE_PLUGIN_ADDRESS=0xC9304930f6a4fB2DAe74A17032426Aa1E817897A
NEXT_PUBLIC_PUBLIC_KEY_REGISTRY_CONTRACT_ADDRESS=0xadAb459A189AAaa17D4807805e6Fab55d3fb5C44
NEXT_PUBLIC_DELEGATION_WALL_CONTRACT_ADDRESS=0x0cE7f031BA69abFB404fE148dD09F597db8AB3a0

# Network and services
NEXT_PUBLIC_CHAIN_NAME=sepolia
Expand Down
13 changes: 9 additions & 4 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { ChainName, getChain } from "./utils/chains";
export const PUB_DAO_ADDRESS = (process.env.NEXT_PUBLIC_DAO_ADDRESS ?? "") as Address;
export const PUB_TOKEN_ADDRESS = (process.env.NEXT_PUBLIC_TOKEN_ADDRESS ?? "") as Address;

export const PUB_LOCK_TO_VOTE_PLUGIN_ADDRESS = (process.env.NEXT_PUBLIC_LOCK_TO_VOTE_PLUGIN_ADDRESS ?? "") as Address;
export const PUB_MULTISIG_PLUGIN_ADDRESS = (process.env.NEXT_PUBLIC_MULTISIG_PLUGIN_ADDRESS ?? "") as Address;
export const PUB_EMERGENCY_MULTISIG_PLUGIN_ADDRESS = (process.env.NEXT_PUBLIC_EMERGENCY_MULTISIG_PLUGIN_ADDRESS ??
"") as Address;
export const PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS = (process.env.NEXT_PUBLIC_DUAL_GOVERNANCE_PLUGIN_ADDRESS ??
"") as Address;
export const PUB_DELEGATION_WALL_CONTRACT_ADDRESS = (process.env.NEXT_PUBLIC_DELEGATION_WALL_CONTRACT_ADDRESS ??
export const PUB_PUBLIC_KEY_REGISTRY_CONTRACT_ADDRESS = (process.env.NEXT_PUBLIC_PUBLIC_KEY_REGISTRY_CONTRACT_ADDRESS ??
"") as Address;
export const PUB_MULTISIG_PLUGIN_ADDRESS = (process.env.NEXT_PUBLIC_MULTISIG_PLUGIN_ADDRESS ?? "") as Address;
export const PUB_EMERGENCY_MULTISIG_PLUGIN_ADDRESS = (process.env.NEXT_PUBLIC_EMERGENCY_MULTISIG_PLUGIN_ADDRESS ??
export const PUB_DELEGATION_WALL_CONTRACT_ADDRESS = (process.env.NEXT_PUBLIC_DELEGATION_WALL_CONTRACT_ADDRESS ??
"") as Address;

// Target chain
Expand All @@ -30,6 +31,10 @@ export const PUB_WALLET_CONNECT_PROJECT_ID = process.env.NEXT_PUBLIC_WALLET_CONN
export const PUB_IPFS_ENDPOINT = process.env.NEXT_PUBLIC_IPFS_ENDPOINT ?? "";
export const PUB_IPFS_API_KEY = process.env.NEXT_PUBLIC_IPFS_API_KEY ?? "";

// Private multisig
export const DETERMINISTIC_EMERGENCY_PAYLOAD =
"This text is used to generate an encryption key that can only be used by the Security Council of the Taiko DAO. Sign this message only if you are about to create or approve a private proposal on this DAO.";

// General
export const PUB_APP_NAME = "Taiko";
export const PUB_APP_DESCRIPTION = "Taiko's official UI to interact with the DAO smart contract";
Expand Down
103 changes: 103 additions & 0 deletions plugins/emergencyMultisig/artifacts/PublicKeyRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
export const PublicKeyRegistryAbi = [
{
type: "function",
name: "getRegisteredWallets",
inputs: [],
outputs: [
{
name: "",
type: "address[]",
internalType: "address[]",
},
],
stateMutability: "view",
},
{
type: "function",
name: "publicKeys",
inputs: [
{
name: "",
type: "address",
internalType: "address",
},
],
outputs: [
{
name: "",
type: "bytes32",
internalType: "bytes32",
},
],
stateMutability: "view",
},
{
type: "function",
name: "registeredWalletCount",
inputs: [],
outputs: [
{
name: "",
type: "uint256",
internalType: "uint256",
},
],
stateMutability: "view",
},
{
type: "function",
name: "registeredWallets",
inputs: [
{
name: "",
type: "uint256",
internalType: "uint256",
},
],
outputs: [
{
name: "",
type: "address",
internalType: "address",
},
],
stateMutability: "view",
},
{
type: "function",
name: "setPublicKey",
inputs: [
{
name: "_publicKey",
type: "bytes32",
internalType: "bytes32",
},
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "event",
name: "PublicKeyRegistered",
inputs: [
{
name: "wallet",
type: "address",
indexed: false,
internalType: "address",
},
{
name: "publicKey",
type: "bytes32",
indexed: false,
internalType: "bytes32",
},
],
anonymous: false,
},
{
type: "error",
name: "AlreadySet",
inputs: [],
},
] as const;
72 changes: 72 additions & 0 deletions plugins/emergencyMultisig/hooks/usePublicKeyRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { useEffect } from "react";
import { Address, Hex, keccak256 } from "viem";
import { PublicKeyRegistryAbi } from "../artifacts/PublicKeyRegistry";
import { useConfig, useWriteContract } from "wagmi";
import { readContract, signMessage } from "@wagmi/core";
import { DETERMINISTIC_EMERGENCY_PAYLOAD, PUB_PUBLIC_KEY_REGISTRY_CONTRACT_ADDRESS } from "@/constants";
import { useQuery } from "@tanstack/react-query";
import { computePublicKey } from "@/utils/encryption/asymmetric";
import { hexToUint8Array, uint8ArrayToHex } from "@/utils/hex";

export function usePublicKeyRegistry() {
const config = useConfig();
const { writeContract, status: registrationStatus } = useWriteContract();

const { data, isLoading, isSuccess, error, refetch } = useQuery({
queryKey: ["public-key-registry-values"],
queryFn: () => {
return readContract(config, {
abi: PublicKeyRegistryAbi,
address: PUB_PUBLIC_KEY_REGISTRY_CONTRACT_ADDRESS,
functionName: "getRegisteredWallets",
}).then((addresses) => {
return Promise.all(
addresses.map((addr) => {
return readContract(config, {
abi: PublicKeyRegistryAbi,
address: PUB_PUBLIC_KEY_REGISTRY_CONTRACT_ADDRESS,
functionName: "publicKeys",
args: [addr],
});
})
).then((publicKeys: Hex[]) => {
return { addresses, publicKeys };
});
});
},
initialData: {
publicKeys: [],
addresses: [],
},
retry: true,
refetchOnMount: false,
refetchOnReconnect: false,
retryOnMount: true,
staleTime: 1000 * 60 * 10,
});

const registerPublicKey = async () => {
const privateSignature = await signMessage(config, { message: DETERMINISTIC_EMERGENCY_PAYLOAD });
const derivedPrivateKey = keccak256(privateSignature);
const pubKey = computePublicKey(hexToUint8Array(derivedPrivateKey));

writeContract({
abi: PublicKeyRegistryAbi,
address: PUB_PUBLIC_KEY_REGISTRY_CONTRACT_ADDRESS,
functionName: "setPublicKey",
args: [uint8ArrayToHex(pubKey)],
});
};

useEffect(() => {
refetch();
}, [registrationStatus]);

return {
data,
registerPublicKey,
isLoading,
isSuccess,
error,
};
}
Loading

0 comments on commit 2615a49

Please sign in to comment.