Skip to content

Commit

Permalink
WIP - OnChain DAO
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshpw committed Dec 18, 2024
1 parent 619629b commit 7122514
Show file tree
Hide file tree
Showing 10 changed files with 4,976 additions and 3,165 deletions.
3,918 changes: 1,660 additions & 2,258 deletions src/assets/abis/hb_dao.json

Large diffs are not rendered by default.

1,849 changes: 956 additions & 893 deletions src/assets/abis/hb_evm.json

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions src/assets/abis/hb_timelock.json

Large diffs are not rendered by default.

255 changes: 255 additions & 0 deletions src/assets/abis/hb_wrapper.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/modules/etherlink/components/EvmTreasuryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { useContext } from "react"
import { EtherlinkContext } from "services/wagmi/context"

export const EvmTreasuryTable = () => {
const { daoSelected } = useContext(EtherlinkContext)
console.log("daoSelected", daoSelected)
const { daoSelected, daoRegistryDetails } = useContext(EtherlinkContext)
console.log("daoSelected", daoRegistryDetails)
return (
<TableContainer>
<Table>
Expand All @@ -26,12 +26,12 @@ export const EvmTreasuryTable = () => {
</TableHead>
<TableBody>
<TableRow>
<TableCell>Tezos</TableCell>
<TableCell>Etherink Testnet</TableCell>
<TableCell>XTZ</TableCell>
<TableCell>1000.00</TableCell>
<TableCell>{daoRegistryDetails?.balance}</TableCell>
<TableCell>
<Grid container direction="row" alignItems="center">
0x1234...5678
native token
<CopyButton text="0x1234567890abcdef" />
</Grid>
</TableCell>
Expand Down
4 changes: 0 additions & 4 deletions src/services/contracts/baseDAO/hooks/useOriginate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import { getSignature } from "services/lite/utils"
import { saveLiteCommunity } from "services/services/lite/lite-services"
import { Community } from "models/Community"
import { EnvKey, getEnv } from "services/config"
import HomebaseDaoEvm from "assets/abis/hb_dao.json"

const ERC20_ABI = HomebaseDaoEvm.output.abi
const ERC20_BYTECODE = HomebaseDaoEvm.output.bytecode

const INITIAL_STATES = [
{
Expand Down
1,875 changes: 1,875 additions & 0 deletions src/services/contracts/etherlinkDAO/hooks/temp-config.ts

Large diffs are not rendered by default.

150 changes: 146 additions & 4 deletions src/services/contracts/etherlinkDAO/hooks/useEvmDaoCreateStore.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { ethers } from "ethers"
import { create } from "zustand"
import { STEPS } from "modules/etherlink/config"
import { useHistory } from "react-router-dom"
import HbEvmAbi from "assets/abis/hb_evm.json"
import HbDaoAbi from "assets/abis/hb_dao.json"
import HbTimelockAbi from "assets/abis/hb_timelock.json"
import HbWrapperAbi from "assets/abis/hb_wrapper.json"

import { useCallback, useState } from "react"
import { useTezos } from "services/beacon/hooks/useTezos"
import { DAO_ABI, DAO_BYTECODE, wrapperAbiGlobal } from "./temp-config"

// const DAO_ABI = HbDaoAbi.output.abi
// const DAO_BYTECODE = HbDaoAbi.output.bytecode

interface EvmDaoCreateStore {
currentStep: number
Expand Down Expand Up @@ -81,16 +93,146 @@ const useEvmDaoCreateZustantStore = create<EvmDaoCreateStore>((set, get) => ({
}))

const useEvmDaoCreateStore = () => {
const [isDeploying, setIsDeploying] = useState(false)
const data = useEvmDaoCreateZustantStore()
const history = useHistory()
const { etherlink } = useTezos()
const initialMembers = ["0x1E4f6Bbb0448ad06b7b777BBBe6909385d477EE1"]
const initialAmounts = [1000]
const minDelay = 0
const minVotingDelay = 4
const proposalThreshhold = 1
const quorumRequired = 1

const proposers = [] as string[]
const executors = [] as string[]

const deployDao = useCallback(async () => {
const daoData = data.data

try {
const tokenFactory = new ethers.ContractFactory(HbEvmAbi.abi, HbEvmAbi.bytecode, etherlink.signer)
const timelockFactory = new ethers.ContractFactory(HbTimelockAbi.abi, HbTimelockAbi.bytecode, etherlink.signer)
const daoFactory = new ethers.ContractFactory(HbDaoAbi.abi, HbDaoAbi.bytecode, etherlink.signer)

const token = await tokenFactory.deploy("MyToken", "MTK", 3, initialMembers, initialAmounts)
await token.waitForDeployment()
console.log("Token deployed at:", token.target)

const deployedToken = new ethers.Contract(token.target, HbEvmAbi.abi, etherlink.signer)
const setDelegateTx = await deployedToken.delegate(etherlink.signer.address)
await setDelegateTx.wait()
console.log("Token delegate set at:", etherlink.signer.address)

console.log("Deploying TimeLockController contract...")

const timeLock = await timelockFactory.deploy(minDelay, proposers, executors, etherlink.signer.address)
await timeLock.waitForDeployment()
console.log("TimeLockController deployed at:", timeLock.target)

const hbDao = await daoFactory.deploy(
deployedToken.target,
timeLock.target,
"AKDAO",
minDelay,
minVotingDelay,
proposalThreshhold,
quorumRequired
)
await hbDao.waitForDeployment()
console.log("HomebaseDAO deployed at:", hbDao.target)
} catch (e) {
console.error("Error deploying DAO", e)
return null
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [data.data])

const deployDaoWrapper = useCallback(async () => {
const daoData = data.data

try {
const wrapperFactory = new ethers.ContractFactory(HbWrapperAbi.abi, HbWrapperAbi.bytecode, etherlink.signer)
const wrapper = await wrapperFactory.deploy(
"AK DAO1", // DAO Name
"AKD", // DAO Symbol
"About DAO1", // DAO Description
"3", // Token Decimals
"6", // Execution Delay in minutes
initialMembers, // Initial Members
[
...initialAmounts, // Members 1 Token Allocation
"5", // voting delay in minutes
"10", // voting duration in minutes (e.g.10 minutes)
"1", // proposal threshold (1% of total supply)
"4" // quorum (4% of total supply)
],
["RKEY"], // Registry Keys
["RVALUE"] // Registry Values
)
await wrapper.waitForDeployment()
const wrapperAddress = await wrapper.getAddress()
console.log("Wrapper deployed at:", wrapperAddress)

// const contract = await factory.deploy(
// "AK DAO1", // DAO Name
// "AKD", // DAO Symbol
// "About DAO1", // DAO Description
// "3", // Token Decimals
// "6", // Execution Delay in minutes
// ["0x1E4f6Bbb0448ad06b7b777BBBe6909385d477EE1"], // Initial Members
// [
// "1000", // Members 1 Token Allocation
// "5", // voting delay in minutes
// "10", // voting duration in minutes (e.g.10 minutes)
// "1", // proposal threshold (1% of total supply)
// "4" // quorum (4% of total supply)
// ],
// ["RKEY"], // Registry Keys
// ["RVALUE"] // Registry Values
// )
// const contract = await factory.deploy(
// "AK DAO1", // DAO Name
// "AKD", // DAO Symbol
// "About DAO1", // DAO Description
// "3", // Token Decimals
// "6", // Execution Delay in minutes
// ["0x1E4f6Bbb0448ad06b7b777BBBe6909385d477EE1"], // Initial Members
// [
// "1000", // Members 1 Token Allocation
// "5", // voting delay in minutes
// "10", // voting duration in minutes (e.g.10 minutes)
// "1", // proposal threshold (1% of total supply)
// "4" // quorum (4% of total supply)
// ],
// ["RKEY"], // Registry Keys
// ["RVALUE"] // Registry Values
// )

// await contract.waitForDeployment()
// const contractAddress = await contract.getAddress()
// alert("Contract deployed at: " + contractAddress)
// return contractAddress
} catch (error) {
console.error("Error deploying DAO", error)
return null
}
}, [data.data, etherlink.signer])
const isFinalStep = data.currentStep === STEPS.length - 1

return {
...data,
deployDao,
next: {
text: "Next",
text: isFinalStep ? "Deploy" : "Next",
handler: () => {
const nextStep = data.next.handler()
if (nextStep) {
history.push(nextStep)
if (isFinalStep) {
deployDao()
} else {
const nextStep = data.next.handler()
if (nextStep) {
history.push(nextStep)
}
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/services/contracts/token/hooks/useToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ export const useTokenOriginate = (tokenData: TokenContractParams) => {
const { tezos, connect, network, account, etherlink } = useTezos()
const provider = etherlink.provider
const signer = etherlink.signer
console.log({ provider })

const openNotification = useNotification()

const result = useMutation<ContractAbstraction<ContractProvider | Wallet>, Error, TokenContractParams>(
async ({ tokenDistribution, tokenSettings }) => {
console.log({ tokenDistribution, tokenSettings, network })
console.log({ provider })

if (network.startsWith("etherlink")) {
try {
console.log("Deployer", signer?.getAddress())
Expand Down
22 changes: 22 additions & 0 deletions src/services/wagmi/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useParams } from "react-router-dom"
import { ProposalStatus } from "services/services/dao/mappers/proposal/types"
import { useTezos } from "services/beacon/hooks/useTezos"
import dayjs from "dayjs"
import { ethers } from "ethers"

interface EtherlinkType {
isConnected: boolean
Expand Down Expand Up @@ -53,8 +54,13 @@ const useEtherlinkDao = ({ network }: { network: string }) => {

const [daoData, setDaoData] = useState<any[]>([])
const [daoSelected, setDaoSelected] = useState<any>({})
const [daoRegistryDetails, setDaoRegistryDetails] = useState<{
balance: string
}>({ balance: "0" })

const [daoProposals, setDaoProposals] = useState<any[]>([])
const [daoProposalSelected, setDaoProposalSelected] = useState<any>({})

const [daoMembers, setDaoMembers] = useState<any[]>([])
const { data: firestoreData, loading, fetchCollection } = useFirestoreStore()

Expand Down Expand Up @@ -114,12 +120,26 @@ const useEtherlinkDao = ({ network }: { network: string }) => {
if (daoSelected.id && firebaseRootCollection) {
fetchCollection(`${firebaseRootCollection}/${daoSelected.id}/proposals`)
fetchCollection(`${firebaseRootCollection}/${daoSelected.id}/members`)
console.log({ daoSelected })
// TODO: Replace this with proper service
fetch(`https://testnet.explorer.etherlink.com/api/v2/addresses/${daoSelected.registryAddress}`)
.then(res => res.json())
.then(data => {
const tokenDecimals = daoSelected.decimals
const coinBalance = data?.coin_balance
const ethBalance = ethers.formatEther(coinBalance)
setDaoRegistryDetails({
balance: ethBalance
})
console.log("Treasury Data", ethBalance)
})
}
}, [daoSelected, fetchCollection, firebaseRootCollection])

return {
daos: daoData,
daoSelected,
daoRegistryDetails,
daoProposals,
daoProposalSelected,
daoMembers,
Expand Down Expand Up @@ -203,6 +223,7 @@ export const EtherlinkProvider: React.FC<{ children: ReactNode }> = ({ children
daos,
isLoadingDaos,
daoSelected,
daoRegistryDetails,
daoProposals,
isLoadingDaoProposals,
daoProposalSelected,
Expand Down Expand Up @@ -235,6 +256,7 @@ export const EtherlinkProvider: React.FC<{ children: ReactNode }> = ({ children
isLoadingDaos,
isLoadingDaoProposals,
daoSelected,
daoRegistryDetails,
daoProposals,
daoProposalSelected,
daoMembers,
Expand Down

0 comments on commit 7122514

Please sign in to comment.