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

[WIP] Console: show additional info for functions / events on New Action #260

Closed
wants to merge 11 commits into from
325 changes: 210 additions & 115 deletions packages/govern-console/src/components/NewAction/NewAction.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Contract as EthersContract } from 'ethers'
import { Input } from '../../../lib/abi-types'

interface InputStateData extends Input {
value: string
}
export default async function callContractFunction(
functionName: string,
rawFunctionArguments: InputStateData[],
targetContract: EthersContract,
): Promise<string> {
const args = rawFunctionArguments.map((value: InputStateData) => value.value)

const callResponse = args
? await targetContract[functionName](...args)
: await targetContract[functionName]()

return callResponse.toString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sendAction from './send-action'
import callContractFunction from './call-function'

export { callContractFunction, sendAction }
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import BN from 'bn.js'
import { Contract as EthersContract, ContractTransaction } from 'ethers'
import abiCoder from 'web3-eth-abi'
import { marshallContainer } from '../../../lib/queue-utils'
import { Config } from '../../../lib/queue-types'
import { AbiType, Input } from '../../../lib/abi-types'

const EMPTY_BYTES = '0x00'

interface InputStateData extends Input {
value: string
}

export default async function sendAction(
account: string,
config: Config,
executorAddress: string,
proof: string,
rawFunctionAbi: AbiType,
rawFunctionArguments: InputStateData[],
targetContractAddress: string,
queueContract: EthersContract,
): Promise<ContractTransaction> {
const functionValues = rawFunctionArguments.map(
(val: InputStateData) => val.value,
)

// @ts-ignore
const encodedFunctionCall = abiCoder.encodeFunctionCall(
rawFunctionAbi,
functionValues,
)

const nonce = await queueContract.nonce()
const bnNonce = new BN(nonce.toString())
const newNonce = bnNonce.add(new BN('1'))

// Current time + 30 secs buffer.
// This is necessary for DAOs with lower execution delays, in which
// the tx getting picked up by a later block can make the tx fail.
const executionTime =
Math.ceil(Date.now() / 1000) + Number(config.executionDelay) + 60
const container = marshallContainer(
account,
[
{
to: targetContractAddress,
value: EMPTY_BYTES,
data: encodedFunctionCall,
},
],
config,
executorAddress,
executionTime.toString(),
newNonce.toString(),
proof,
)

const tx = await queueContract.schedule(container, {
gasLimit: 500000,
})

return tx
}
127 changes: 19 additions & 108 deletions packages/govern-console/src/components/ViewAction/ViewAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,125 +8,25 @@ import Button from '../Button'
import Entity from '../Entity/Entity'
import Frame from '../Frame/Frame'
import Info from '../Info/Info'
import { usePermissions } from '../../Providers/Permissions'
import { useWallet } from '../../Providers/Wallet'
import { useContract } from '../../lib/web3-contracts'
import { shortenAddress, ETH_EMPTY_HEX } from '../../lib/web3-utils'
import queueAbi from '../../lib/abi/GovernQueue.json'
import { usePermissions } from '../../Providers/Permissions'
import { useWallet } from '../../Providers/Wallet'
import { Action, Container, ContainerEvent } from '../../lib/queue-types'

const EMPTY_FAILURE_MAP =
'0x0000000000000000000000000000000000000000000000000000000000000000'

type Collateral = {
token: string
amount: string
}

type Config = {
executionDelay: string
scheduleDeposit: Collateral
challengeDeposit: Collateral
resolver: string
rules: string
}

type Action = {
id: string
to: string
value: string
data: string
}

type Payload = {
id: string
nonce: string
executionTime: string
submitter: string
executor: any
actions: Action[]
proof: string
}

type ContainerEventChallenge = {
id: string
container: any
createdAt: string
actor: string
collateral: Collateral
disputeId: string
reason: string
resolver: string
}

type ContainerEventExecute = {
id: string
container: any
createdAt: string
execResults: string[]
}

type ContainerEventResolve = {
id: string
container: any
createdAt: string
approved: boolean
}

type ContainerEventRule = {
id: string
container: any
createdAt: string
ruling: string
}

type ContainerEventSchedule = {
id: string
container: any
createdAt: string
collateral: Collateral
}

type ContainerEventSubmitEvidence = {
id: string
container: any
createdAt: string
evidence: string
submitter: string
finished: boolean
}

type ContainerEventVeto = {
id: string
container: any
created: string
reason: string
}

type ContainerEvent =
| ContainerEventChallenge
| ContainerEventExecute
| ContainerEventResolve
| ContainerEventRule
| ContainerEventSchedule
| ContainerEventSubmitEvidence
| ContainerEventVeto

type Container = {
interface ActionContainer extends Container {
id: string
queue: string
state: string
config: Config
payload: Payload
history: ContainerEvent[]
}

type ViewActionWrapperProps = {
containers: Container[]
queueAddress: string
}

type ViewActionProps = {
container: Container
container: ActionContainer
queueAddress: string
}

Expand Down Expand Up @@ -402,13 +302,19 @@ function ViewAction({ container, queueAddress }: ViewActionProps) {
margin-left: 16px;
`}
>
{container.payload.actions.map((action: Action) => (
<React.Fragment key={action.id}>
{container.payload.actions.map((action: Action, index: number) => (
<React.Fragment key={index}>
<li>
to: <Entity address={action.to} type="address" />
</li>
<li>value: {action.value}</li>
<li>data: {action.data}</li>
<li
css={`
word-wrap: break-word;
`}
>
data: {action.data}
</li>
</React.Fragment>
))}
</ul>
Expand Down Expand Up @@ -454,6 +360,11 @@ function ViewAction({ container, queueAddress }: ViewActionProps) {
)
}

type ViewActionWrapperProps = {
containers: ActionContainer[]
queueAddress: string
}

export default function ViewActionWrapper({
containers,
queueAddress,
Expand Down
11 changes: 9 additions & 2 deletions packages/govern-console/src/components/ViewDao/ViewDao.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ import FilteredActions from '../FilteredActions/FilteredActions'
import Frame from '../Frame/Frame'
import { usePermissions } from '../../Providers/Permissions'
import { useWalletAugmented } from '../../Providers/Wallet'
import { useChainId } from '../../lib/chain-id'
import { KNOWN_GOVERN_ROLES, KNOWN_QUEUE_ROLES } from '../../lib/known-roles'
import { ETH_ANY_ADDRESS, ETH_EMPTY_HEX } from '../../lib/web3-utils'
import {
getNetworkName,
ETH_ANY_ADDRESS,
ETH_EMPTY_HEX,
} from '../../lib/web3-utils'

const ACTIONS_PER_PAGE = 8

Expand All @@ -23,6 +28,8 @@ export default function ViewDao({ dao }: ViewDaoProps): JSX.Element {
const history = useHistory()
const { ethers } = useWalletAugmented()
const { permissions, populatePermissions } = usePermissions()
const { chainId } = useChainId()

const { schedule: canSchedule } = permissions

useEffect(() => {
Expand All @@ -38,7 +45,7 @@ export default function ViewDao({ dao }: ViewDaoProps): JSX.Element {
}, [dao, populatePermissions])

const handleNewAction = useCallback(() => {
history.push(`/${daoAddress}/new-action`)
history.push(`/${getNetworkName(chainId)}/${daoAddress}/new-action`)
}, [history, daoAddress])

return (
Expand Down
12 changes: 12 additions & 0 deletions packages/govern-console/src/lib/abi-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type Input = {
name: string
type: string
}

export type AbiType = {
name: string
inputs: Input[]
payable: string
stateMutability: string
type: string
}
Loading