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

fix(website): multicall transactions on deployer #639

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 39 additions & 38 deletions packages/website/src/features/Deploy/QueueTransactionsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
'use client';

import { AddIcon } from '@chakra-ui/icons';
import { links } from '@/constants/links';
import { makeMultisend } from '@/helpers/multisend';
import { useStore } from '@/helpers/store';
import { useTxnStager } from '@/hooks/backend';
import { useCannonPackageContracts } from '@/hooks/cannon';
import { useSimulatedTxns } from '@/hooks/fork';
import { AddIcon, CloseIcon } from '@chakra-ui/icons';
import {
Alert,
AlertDescription,
Expand All @@ -9,21 +15,20 @@ import {
Box,
Button,
Container,
Flex,
FormControl,
FormHelperText,
FormLabel,
HStack,
Heading,
HStack,
IconButton,
Input,
Text,
Tooltip,
useToast,
Text,
IconButton,
Flex,
} from '@chakra-ui/react';
import { CloseIcon } from '@chakra-ui/icons';
import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import {
Abi,
decodeErrorResult,
Expand All @@ -34,15 +39,9 @@ import {
zeroAddress,
} from 'viem';
import { useContractWrite } from 'wagmi';
import 'react-diff-view/style/index.css';
import { links } from '@/constants/links';
import { useTxnStager } from '@/hooks/backend';
import { useCannonPackageContracts } from '@/hooks/cannon';
import { useSimulatedTxns } from '@/hooks/fork';
import { useStore } from '@/helpers/store';
import { makeMultisend } from '@/helpers/multisend';
import { DisplayedTransaction } from './DisplayedTransaction';
import NoncePicker from './NoncePicker';
import 'react-diff-view/style/index.css';

type IdentifiableTxn = {
txn: Omit<TransactionRequestBase, 'from'>;
Expand All @@ -68,22 +67,23 @@ function QueueTransactions() {

const cannonInfo = useCannonPackageContracts(target, currentSafe?.chainId);

const queuedTxns = queuedIdentifiableTxns.map((item) => item.txn);
const queuedTxns = queuedIdentifiableTxns
.map((item) => item.txn)
.filter((txn) => !!txn);

const multisendTxn =
queuedTxns.indexOf(null as any) === -1
? makeMultisend(
[
{
to: zeroAddress,
data: encodeAbiParameters(
[{ type: 'string[]' }],
[['invoke', cannonInfo.pkgUrl || '']]
),
} as Partial<TransactionRequestBase>,
].concat(queuedTxns)
)
: null;
const targetTxn =
queuedTxns.length > 0
? makeMultisend([
{
to: zeroAddress,
data: encodeAbiParameters(
[{ type: 'string[]' }],
[['invoke', cannonInfo.pkgUrl || '']]
),
} as Partial<TransactionRequestBase>,
...queuedTxns,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix makes sure to not add null values to the multicall txns

])
: {};

const txnInfo = useSimulatedTxns(currentSafe as any, queuedTxns);

Expand All @@ -92,13 +92,12 @@ function QueueTransactions() {

const toast = useToast();

// TODO: check types
const stager = useTxnStager(
(multisendTxn
targetTxn
? {
to: multisendTxn.to,
value: multisendTxn.value.toString(),
data: multisendTxn.data,
to: targetTxn.to as `0x${string}`,
value: targetTxn.value ? targetTxn.value.toString() : undefined,
data: targetTxn.data,
safeTxGas: txnInfo.txnResults.length
? txnInfo.txnResults
.reduce((prev, cur) => ({
Expand All @@ -109,9 +108,9 @@ function QueueTransactions() {
?.gasUsed.toString()
: undefined,
operation: '1',
_nonce: pickedNonce,
_nonce: pickedNonce === null ? undefined : pickedNonce,
}
: {}) as any,
: {},
{
onSignComplete() {
console.log('signing is complete, redirect');
Expand All @@ -126,6 +125,8 @@ function QueueTransactions() {
}
);

console.log('final tx:', stager.executeTxnConfig);

const execTxn = useContractWrite(stager.executeTxnConfig);

const funcIsPayable = false;
Expand Down Expand Up @@ -182,7 +183,7 @@ function QueueTransactions() {
}

const disableExecute =
!multisendTxn || txnHasError || !!stager.execConditionFailed;
!targetTxn || txnHasError || !!stager.execConditionFailed;

console.log('xxx cannonInfo: ', cannonInfo);

Expand Down Expand Up @@ -338,7 +339,7 @@ function QueueTransactions() {
colorScheme="teal"
w="100%"
isDisabled={
!multisendTxn || txnHasError || !!stager.signConditionFailed
!targetTxn || txnHasError || !!stager.signConditionFailed
}
onClick={() => stager.sign()}
>
Expand Down
7 changes: 3 additions & 4 deletions packages/website/src/helpers/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ function makeMulticall(txns: Partial<TransactionRequestBase>[]): {
value: bigint;
data: Hex;
} {
let totalValue = BigInt(0);
for (const txn of txns) {
totalValue = totalValue + (txn.value || BigInt(0));
}
const totalValue = txns.reduce((val, txn) => {
return val + (txn.value || BigInt(0));
}, BigInt(0));

return {
operation: '1', // multicall is a DELEGATECALL
Expand Down
7 changes: 3 additions & 4 deletions packages/website/src/helpers/multisend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ export function makeMultisend(txns: Partial<TransactionRequestBase>[]): {
value: string;
data: Hex;
} {
let totalValue = BigInt(0);
for (const txn of txns) {
totalValue = totalValue + (txn.value || BigInt(0));
}
const totalValue = txns.reduce((val, txn) => {
return val + (txn.value || BigInt(0));
}, BigInt(0));

return {
operation: '1', // multicall is a DELEGATECALL
Expand Down
Loading