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

✨ Upgrade Wagmi #301

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions abi/KaliAccessManagerV2.json → abi/ACCESS.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
export const ACCESS_ABI = [
{
"inputs": [],
"stateMutability": "nonpayable",
Expand Down Expand Up @@ -504,4 +504,4 @@
"stateMutability": "view",
"type": "function"
}
]
] as const;
4 changes: 2 additions & 2 deletions abi/KaliDAO.json → abi/DAO.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
export const DAO_ABI = [
{
"inputs": [],
"name": "AlreadyVoted",
Expand Down Expand Up @@ -1523,4 +1523,4 @@
"stateMutability": "view",
"type": "function"
}
]
] as const;
4 changes: 2 additions & 2 deletions abi/KaliDAOcrowdsaleV2.json → abi/SWAP.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
export const SWAP_ABI = [
{
"inputs": [
{
Expand Down Expand Up @@ -521,4 +521,4 @@
"stateMutability": "view",
"type": "function"
}
]
] as const;
5 changes: 5 additions & 0 deletions abi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SWAP_ABI } from "./SWAP";
import { DAO_ABI } from './DAO';
import { ACCESS_ABI } from "./ACCESS";

export { SWAP_ABI, ACCESS_ABI, DAO_ABI }
8 changes: 4 additions & 4 deletions components/dao-dashboard/layout/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useContractRead } from 'wagmi'
import { DashboardElementProps } from './types'
import Link from 'next/link'
import { addresses } from '@constants/addresses'
import SWAP_ABI from '@abi/KaliDAOcrowdsaleV2.json'
import { SWAP_ABI } from '@abi/index'
import { AddressZero } from '@ethersproject/constants'
import { navItem, navMenu } from './layout.css'
import Wrappr from './Wrappr'
Expand All @@ -17,8 +17,8 @@ const Nav = ({ address, chainId }: DashboardElementProps) => {
error: swapError,
isError: isSwapError,
} = useContractRead({
addressOrName: chainId ? addresses?.[chainId]?.['extensions']['crowdsale2'] : AddressZero,
contractInterface: SWAP_ABI,
address: chainId ? addresses?.[chainId]?.['extensions']['crowdsale2'] : AddressZero,
abi: SWAP_ABI,
chainId: chainId,
functionName: 'crowdsales',
args: [address],
Expand All @@ -43,7 +43,7 @@ const Nav = ({ address, chainId }: DashboardElementProps) => {
},
]

if (swap && swap?.saleEnds * 1000 > Date.now()) {
if (swap && swap.saleEnds * 1000 > Date.now()) {
items.push({
id: 2,
title: 'Swap',
Expand Down
2 changes: 1 addition & 1 deletion components/dao-dashboard/layout/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
IconGitHub,
} from '@kalidao/reality'
import { useRouter } from 'next/router'
import { chain, useQuery } from 'wagmi'
import { useQuery } from 'wagmi'
import { getDaoInfo } from '@graph/queries'
import { DashboardElementProps } from './types'
import Link from 'next/link'
Expand Down
6 changes: 3 additions & 3 deletions components/dao-dashboard/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const DashboardLayout = ({ title, content, children }: Props) => {
}}
justify="space-between"
>
<Profile address={dao as string} chainId={Number(chainId)} />
<Nav address={dao as string} chainId={Number(chainId)} />
<Treasury address={dao as string} chainId={Number(chainId)} />
<Profile address={dao as `0x${string}`} chainId={Number(chainId)} />
<Nav address={dao as `0x${string}`} chainId={Number(chainId)} />
<Treasury address={dao as `0x${string}`} chainId={Number(chainId)} />
<Members />
</Stack>
{children}
Expand Down
2 changes: 1 addition & 1 deletion components/dao-dashboard/layout/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type DashboardElementProps = {
address: string
address: `0x${string}`
chainId: number
}
2 changes: 1 addition & 1 deletion components/dao-dashboard/members/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface Member {
address: string
address: `0x${string}`
proposals: any[]
shares: string
}
16 changes: 8 additions & 8 deletions components/dao-dashboard/newproposal/apps/SetRedemption.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState, useEffect } from 'react'
import { useRouter } from 'next/router'
import { ethers } from 'ethers'
import { ethers, BigNumber } from 'ethers'
import { useContract, useSigner } from 'wagmi'
import KALIDAO_ABI from '@abi/KaliDAO.json'
import { DAO_ABI } from '@abi/index'
import { addresses } from '@constants/addresses'
import { fetchExtensionStatus } from '@utils/fetchExtensionStatus'
import { Warning } from '@design/elements'
Expand All @@ -17,15 +17,15 @@ import { DateInput } from '@design/DateInput'

export default function SetRedemption({ setProposal, title, content }: ProposalProps) {
const router = useRouter()
const daoAddress = router.query.dao as string
const daoAddress = router.query.dao as `0x${string}`
const daoChainId = Number(router.query.chainId)
const { data: signer } = useSigner()
const redemptionAddress = addresses[daoChainId]['extensions']['redemption']
const tokenArray = getRedemptionTokens(daoChainId)

const kalidao = useContract({
addressOrName: daoAddress,
contractInterface: KALIDAO_ABI,
address: daoAddress,
abi: DAO_ABI,
signerOrProvider: signer,
})

Expand Down Expand Up @@ -92,12 +92,12 @@ export default function SetRedemption({ setProposal, title, content }: ProposalP
)

try {
const tx = await kalidao.propose(
const tx = await kalidao?.propose(
9, // EXTENSION prop
docs,
[addresses[daoChainId]['extensions']['redemption']],
[_toggleRedemption],
[payload],
[BigNumber.from(_toggleRedemption)],
[payload as `0x${string}`],
)
console.log('tx', tx)
} catch (e) {
Expand Down
51 changes: 30 additions & 21 deletions components/dao-dashboard/newproposal/apps/SetSwap.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { useState, useEffect } from 'react'
import { useRouter } from 'next/router'
import { ethers } from 'ethers'
import { ethers, BigNumber } from 'ethers'
import { erc20ABI, useContract, useContractRead, useSigner } from 'wagmi'
import { Select } from '@design/Select'
import { Stack, Input, Box, Text, Button, FieldSet, FileInput, Textarea } from '@kalidao/reality'
import { Stack, Input, Button, FieldSet, Textarea } from '@kalidao/reality'
import FileUploader from '@components/tools/FileUpload'
import KALIDAO_ABI from '@abi/KaliDAO.json'
import KALIACCESS_ABI from '@abi/KaliAccessManagerV2.json'
import { DAO_ABI, ACCESS_ABI } from '@abi/index'
import { addresses } from '@constants/addresses'
import { Warning } from '@design/elements'
import { fetchEnsAddress } from '@utils/fetchEnsAddress'
Expand All @@ -19,29 +18,37 @@ import { DateInput } from '@design/DateInput'
import { JSONContent } from '@tiptap/react'
import { createSwapDetails } from './createSwapDetails'

class List {
readonly list: `0x${string}[]`

constructor(list: `0x${string}[]`) {
this.list = list
}
}

export default function SetCrowdsale({ setProposal, title, content }: ProposalProps) {
const router = useRouter()
const daoAddress = router.query.dao as string
const daoAddress = router.query.dao as `0x${string}`
const chainId = Number(router.query.chainId)
const { data: signer } = useSigner()
const crowdsaleAddress = addresses[chainId]['extensions']['crowdsale2']

const { data: kalidaoToken } = useContractRead({
addressOrName: daoAddress,
contractInterface: KALIDAO_ABI,
address: daoAddress,
abi: DAO_ABI,
functionName: 'symbol',
chainId: Number(chainId),
})

const kalidao = useContract({
addressOrName: daoAddress,
contractInterface: KALIDAO_ABI,
address: daoAddress,
abi: DAO_ABI,
signerOrProvider: signer,
})

const kaliAccess = useContract({
addressOrName: addresses[chainId]['access2'],
contractInterface: KALIACCESS_ABI,
address: addresses[chainId]['access2'],
abi: ACCESS_ABI,
signerOrProvider: signer,
})

Expand All @@ -67,9 +74,8 @@ export default function SetCrowdsale({ setProposal, title, content }: ProposalPr
return
}

let list = []
let list: `0x${string}`[] = []
let _customAccess = customAccess.split(', ')

for (let i = 0; i < _customAccess.length; i++) {
const address = await fetchEnsAddress(_customAccess[i])

Expand All @@ -79,11 +85,13 @@ export default function SetCrowdsale({ setProposal, title, content }: ProposalPr
return
}

list.push(address)
if (address) {
list.push(address as `0x${string}`)
}
}

try {
const tx = await kaliAccess.createList(list, ethers.utils.formatBytes32String('0x0'), '')
const tx = await kaliAccess?.createList(list, ethers.constants.HashZero, '')
console.log('tx ', tx)
setIsRecorded(true)
setWarning('')
Expand Down Expand Up @@ -142,9 +150,10 @@ export default function SetCrowdsale({ setProposal, title, content }: ProposalPr
_purchaseAccess = 1
} else {
try {
let id = await kaliAccess.listCount()
id = ethers.utils.formatUnits(id, 'wei')
_purchaseAccess = parseInt(id)
const id = await kaliAccess?.listCount()
if (!id) return
const idWei = ethers.utils.formatUnits(id, 'wei')
_purchaseAccess = parseInt(idWei)
} catch (e) {
console.log(e)
}
Expand Down Expand Up @@ -227,7 +236,7 @@ export default function SetCrowdsale({ setProposal, title, content }: ProposalPr
payload = abiCoder.encode(
['uint256', 'uint256', 'address', 'uint32', 'uint96', 'uint96', 'string'],
[_purchaseAccess, _swapMultiplier, _tokenToSwap, crowdsaleEnd, _totalLimit, _personalLimit, detailsHash],
)
) as `0x${string}`
// console.log(payload)
} catch (e) {
setWarning('Error setting the crowdsale proposal.')
Expand All @@ -240,11 +249,11 @@ export default function SetCrowdsale({ setProposal, title, content }: ProposalPr
setStatus('Creating proposal...')
try {
setWarning('')
const tx = await kalidao.propose(
const tx = await kalidao?.propose(
9, // EXTENSION prop
docs,
[crowdsaleAddress],
[1],
[BigNumber.from(1)],
[payload],
)
console.log('tx', tx)
Expand Down
29 changes: 18 additions & 11 deletions components/dao-dashboard/newproposal/internal/CallContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import { useContract, useSigner } from 'wagmi'
import { Warning } from '@design/elements'
import { Box, Button, Text, Stack, Input, Textarea } from '@kalidao/reality'
import { Select } from '@design/Select'
import KALIDAO_ABI from '@abi/KaliDAO.json'
import { DAO_ABI } from '@abi/index'
import { useRouter } from 'next/router'
import { ethers } from 'ethers'
import { ethers, BigNumber } from 'ethers'
import Back from '@design/proposal/Back'
import { createProposal } from '../utils'
import { ProposalProps } from '../utils/types'

export default function CallContract({ setProposal, title, content }: ProposalProps) {
const router = useRouter()
const daoChainId = Number(router.query.chainId)
const daoAddress = router.query.dao as string
const daoAddress = router.query.dao as `0x${string}`
const { data: signer } = useSigner()

const kalidao = useContract({
addressOrName: daoAddress as string,
contractInterface: KALIDAO_ABI,
address: daoAddress,
abi: DAO_ABI,
signerOrProvider: signer,
})

// form
const [contractAddress, setContractAddress] = useState<string>()
const [contractAddress, setContractAddress] = useState<`0x${string}`>()
const [contractAbi, setContractAbi] = useState<string>()
const [writeFuncs, setWriteFuncs] = useState<any[]>()
const [writeOptions, setWriteOptions] = useState<any[]>()
Expand Down Expand Up @@ -96,7 +96,7 @@ export default function CallContract({ setProposal, title, content }: ProposalPr

// TODO: Popup to change network if on different network from DAO
const submit = async () => {
if (!functionName) return
if (!functionName || !contractAddress) return
let docs
try {
docs = await createProposal(daoAddress, daoChainId, 2, title, content)
Expand All @@ -107,15 +107,15 @@ export default function CallContract({ setProposal, title, content }: ProposalPr

try {
let iface = new ethers.utils.Interface(contractAbi as string)
let payload = iface.encodeFunctionData(functionName, inputParams)
let payload = iface.encodeFunctionData(functionName, inputParams) as `0x${string}`
console.log('Proposal Params - ', 2, docs, [contractAddress], [0], [payload])

try {
const tx = await kalidao.propose(
const tx = await kalidao?.propose(
2, // CALL prop
docs,
[contractAddress],
[0],
[BigNumber.from(0)],
[payload],
)
console.log('tx', tx)
Expand All @@ -128,6 +128,13 @@ export default function CallContract({ setProposal, title, content }: ProposalPr
}
}

const handleContractAddress = (e: React.ChangeEvent<HTMLInputElement>) => {
e.preventDefault()
if (e.currentTarget.value.slice(0, 2) == '0x' && ethers.utils.isAddress(e.currentTarget.value)) {
setContractAddress(e.currentTarget.value as `0x${string}`)
}
}

return (
<Stack>
<Text>
Expand All @@ -145,7 +152,7 @@ export default function CallContract({ setProposal, title, content }: ProposalPr
name="contractAddress"
type="text"
defaultValue={contractAddress}
onChange={(e) => setContractAddress(e.target.value)}
onChange={handleContractAddress}
/>
<Textarea
label="Contract ABI"
Expand Down
2 changes: 1 addition & 1 deletion components/dao-dashboard/newproposal/internal/Escape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from 'react'
import { useContractWrite } from 'wagmi'
import { Warning } from '@design/elements'
import { Stack, Text, Button, Input } from '@kalidao/reality'
import KALIDAO_ABI from '@abi/KaliDAO.json'
import KALIDAO_ABI from '@abi/DAO'
import { AddressZero } from '@ethersproject/constants'
import { createProposal } from '@components/dao-dashboard/newproposal/utils/'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react'
import { useContractWrite, useContractRead } from 'wagmi'
import KALIDAO_ABI from '@abi/KaliDAO.json'
import KALIDAO_ABI from '@abi/DAO'
import { useRouter } from 'next/router'
import { AddressZero } from '@ethersproject/constants'
import Editor from '@components/editor'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useContract, useContractRead, useSigner } from 'wagmi'
import { Warning } from '@design/elements'
import { Stack, Text, Button, FieldSet, Divider, Input, IconLink, Spinner } from '@kalidao/reality'
import FileUploader from '@components/tools/FileUpload'
import KALIDAO_ABI from '@abi/KaliDAO.json'
import KALIDAO_ABI from '@abi/DAO'
import { useRouter } from 'next/router'
import { AddressZero } from '@ethersproject/constants'
import { uploadFile } from '@utils/ipfs'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react'
import { useContractRead, useContractWrite } from 'wagmi'
import { Warning } from '@design/elements'
import DAO_ABI from '@abi/KaliDAO.json'
import DAO_ABI from '@abi/DAO'
import { useRouter } from 'next/router'
import { AddressZero } from '@ethersproject/constants'
import Editor from '@components/editor'
Expand Down
Loading