Skip to content

Commit

Permalink
fix(website): multicall transactions on deployer (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlescano authored and StuartGavidia committed Nov 30, 2023
1 parent 7a887d3 commit ad177bf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
78 changes: 40 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,10 @@ 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';
import { SafeTransaction } from '@/types/SafeTransaction';

type IdentifiableTxn = {
txn: Omit<TransactionRequestBase, 'from'>;
Expand All @@ -68,22 +68,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: Partial<SafeTransaction> =
queuedTxns.length > 0
? makeMultisend([
{
to: zeroAddress,
data: encodeAbiParameters(
[{ type: 'string[]' }],
[['invoke', cannonInfo.pkgUrl || '']]
),
} as Partial<TransactionRequestBase>,
...queuedTxns,
])
: {};

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

Expand All @@ -92,13 +93,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 +109,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 +126,8 @@ function QueueTransactions() {
}
);

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

const execTxn = useContractWrite(stager.executeTxnConfig);

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

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

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

Expand Down Expand Up @@ -338,7 +340,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

0 comments on commit ad177bf

Please sign in to comment.