Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add Project Management Extension #224

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 190 additions & 0 deletions abi/ProjectManagement.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
[
{
"inputs": [],
"name": "ForbiddenDifferentDao",
"type": "error"
},
{
"inputs": [],
"name": "ForbiddenSenderNotManager",
"type": "error"
},
{
"inputs": [],
"name": "ProjectExpired",
"type": "error"
},
{
"inputs": [],
"name": "ProjectManagerNeedsDaoTokens",
"type": "error"
},
{
"inputs": [],
"name": "ProjectNotEnoughBudget",
"type": "error"
},
{
"inputs": [],
"name": "ProjectUnknown",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "dao",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes[]",
"name": "updates",
"type": "bytes[]"
}
],
"name": "ExtensionCalled",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "dao",
"type": "address"
},
{
"components": [
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"internalType": "address",
"name": "dao",
"type": "address"
},
{
"internalType": "address",
"name": "manager",
"type": "address"
},
{
"internalType": "uint256",
"name": "budget",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "deadline",
"type": "uint256"
},
{
"internalType": "string",
"name": "goals",
"type": "string"
}
],
"indexed": false,
"internalType": "struct ProjectManagement.Project",
"name": "project",
"type": "tuple"
}
],
"name": "ExtensionSet",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "dao",
"type": "address"
},
{
"internalType": "bytes[]",
"name": "extensionData",
"type": "bytes[]"
}
],
"name": "callExtension",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "nextProjectId",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "projects",
"outputs": [
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"internalType": "address",
"name": "dao",
"type": "address"
},
{
"internalType": "address",
"name": "manager",
"type": "address"
},
{
"internalType": "uint256",
"name": "budget",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "deadline",
"type": "uint256"
},
{
"internalType": "string",
"name": "goals",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "extensionData",
"type": "bytes"
}
],
"name": "setExtension",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}
]
108 changes: 108 additions & 0 deletions components/dao-dashboard/newproposal/apps/SetProject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import React, { useState, useEffect } from 'react'
import { useRouter } from 'next/router'
import { ethers } from 'ethers'
import { useContractWrite } from 'wagmi'
import { Flex, Text, Button } from '../../../../styles/elements'
import { Form, FormElement, Label, Input, Switch } from '../../../../styles/form-elements'
import { useForm } from 'react-hook-form'
import { addresses } from '../../../../constants/addresses'
import KALIDAO_ABI from '../../../../abi/KaliDAO.json'
import Back from '../../../../styles/proposal/Back'

export default function SetProject({ setProposal }) {
const router = useRouter()
const { dao, chainId } = router.query
// addresses[daoChainId]['extensions']['projectmanagement']
const {
control,
register,
handleSubmit,
formState: { errors },
} = useForm()

const {
data,
isLoading: isWritePending,
isSuccess: isWriteSuccess,
isError,
error,
writeAsync,
} = useContractWrite(
{
addressOrName: dao,
contractInterface: KALIDAO_ABI,
},
'propose',
{
onSuccess(data) {
console.log('success!', data)
},
},
)

const onSubmit = async (data) => {
const { id, manager, budget, deadline, goals, description } = data
let payload
try {
const abiCoder = ethers.utils.defaultAbiCoder
payload = abiCoder.encode(
['uint256', 'address', 'uint256', 'uint256', 'string'],
[0, manager, ethers.utils.parseEther(budget), parseInt(new Date(deadline).getTime() / 1000), goals],
)
} catch (e) {
console.log('error', e)
return
}

const tx = await writeAsync({
args: [9, description, [addresses[chainId]['extensions']['projectmanagement']], [1], [payload]],
overrides: {
gasLimit: 1050000,
},
}).catch((e) => {
console.log('error', e.code, e.reason)
})
}

return (
<Flex dir="col" gap="md" as="form" onSubmit={handleSubmit(onSubmit)}>
<FormElement>
<Label htmlFor="manager">Manager</Label>
<Input type="text" {...register('manager', { required: true })} />
</FormElement>
<FormElement>
<Label htmlFor="budget">Budget</Label>
<Input type="text" {...register('budget', { required: true })} />
</FormElement>
<FormElement>
<Label htmlFor="deadline">Deadline</Label>
<Input variant="calendar" type="datetime-local" {...register('deadline', { required: true })} />
</FormElement>
<FormElement variant="vertical">
<Label htmlFor="goals">Goals</Label>
<Input
as="textarea"
type="text"
{...register('goals', { required: true })}
css={{ padding: '0.5rem', width: '97%', height: '10vh' }}
/>
</FormElement>
<FormElement variant="vertical">
<Label htmlFor="description">Description</Label>
<Input
as="textarea"
name="description"
type="text"
// defaultValue={description}
// onChange={(e) => setDescription(e.target.value)}
{...register('description', { required: true })}
css={{ padding: '0.5rem', width: '97%', height: '10vh' }}
/>
</FormElement>
<Back onClick={() => setProposal('appsMenu')} />
<Button type="submit" variant="cta">
Submit
</Button>
</Flex>
)
}
9 changes: 7 additions & 2 deletions components/dao-dashboard/newproposal/apps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React from 'react'
import { Menu } from '../../../../styles/proposal/Menu'
import { Flex } from '../../../../styles/elements'
import { FcSalesPerformance } from 'react-icons/fc'
import { MdOutlineRedeem } from 'react-icons/md'
import { MdOutlineRedeem, MdManageAccounts } from 'react-icons/md'
// menu items
import SetCrowdsale from './SetCrowdsale'
import SetRedemption from './SetRedemption'
import SetProject from './SetProject'
import Tribute from './Tribute'
import Back from '../../../../styles/proposal/Back'

Expand All @@ -21,6 +22,10 @@ function AppsMenu({ setProposal }) {
<MdOutlineRedeem />
Redemption
</Menu.Item>
<Menu.Item onClick={() => setProposal('projectmanagement')}>
<MdManageAccounts />
Projects
</Menu.Item>
{/* <Menu.Item onClick={() => setProposal('crowdsaleWithVesting')}>Crowdsale with Vesting</Menu.Item> */}
{/* <Menu.Item onClick={() => setProposal('tributeWithVesting')}>Tribute with Vesting</Menu.Item> */}
</Menu>
Expand All @@ -29,4 +34,4 @@ function AppsMenu({ setProposal }) {
)
}

export { AppsMenu, SetCrowdsale, SetRedemption, Tribute }
export { AppsMenu, SetCrowdsale, SetRedemption, Tribute, SetProject }
6 changes: 5 additions & 1 deletion components/dao-dashboard/newproposal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Escape,
InternalMenu,
} from './internal'
import { AppsMenu, SetCrowdsale, SetRedemption, Tribute } from './apps'
import { AppsMenu, SetCrowdsale, SetRedemption, SetProject, Tribute } from './apps'
import { AssetMenu } from './mint'
import MintArt from './mint/MintArt'
import MintReal from './mint/MintReal'
Expand Down Expand Up @@ -152,6 +152,10 @@ export function NewProposalModal({ proposalProp }) {
title: 'Tribute',
component: <Tribute setProposal={setView} />,
},
projectmanagement: {
title: 'Project Management',
component: <SetProject setProposal={setView} />,
},
}

return (
Expand Down
1 change: 1 addition & 0 deletions components/dao-dashboard/newproposal/internal/Escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function Escape({ setProposal }) {
chainId: Number(daoChain),
},
)
console.log(proposalCount)
const proposalCount = _proposalCount ? _proposalCount.toNumber() : 0
// Form
const [proposalSelected, setProposalSelected] = useState(0)
Expand Down
2 changes: 2 additions & 0 deletions constants/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const addresses =
crowdsale2: '0x2DCA7b86564Ade753062D6Cd60fb3a61fF1f2f9a',
redemption: '0x11f44975e1B204E50108Af6BCB6539798cb15F75',
manager: '0xCFAEA98787d835D127863ED4127F42d00F3D267d',
projectmanagement: '0x9f0ad778385a2c688533958c6ada56f201ffc246',
},
blockExplorer: 'https://rinkeby.etherscan.io',
kaliMaster: '0x55967de5aE91F6E1D98b813b9Dca3946bE9f5C20',
Expand All @@ -105,6 +106,7 @@ export const addresses =
tribute: '0xc64F31b76FDc6B45d703B95A95a3A7F8A0B509aE',
crowdsale2: '0x8c183bf7f68F70104657C6446d638178cbd6Fd11',
redemption: '0x2b8f116e4D9E73A3A9E7CAF1655B9FC01588Db8d',
projectmanagement: '0x9F0AD778385A2C688533958C6ada56f201ffc246',
},
blockExplorer: 'https://goerli.etherscan.io/',
},
Expand Down