Skip to content

Commit 3502beb

Browse files
authored
Merge pull request nounsDAO#1276 from nounsDAO/fix/transaction-errors
webapp: fix proposal encoding issues
2 parents 432cfb8 + 18433b7 commit 3502beb

File tree

3 files changed

+31
-37
lines changed

3 files changed

+31
-37
lines changed

packages/nouns-webapp/src/components/ProposalActionsModal/steps/TransferFundsReviewStep/index.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22

33
import { Trans } from '@lingui/react/macro';
4-
import { encodeFunctionData, parseAbi, parseEther } from 'viem';
4+
import { encodeAbiParameters, parseEther } from 'viem';
55

66
import ModalBottomButtonRow from '@/components/ModalBottomButtonRow';
77
import ModalTitle from '@/components/ModalTitle';
88
import ShortAddress from '@/components/ShortAddress';
9-
import { nounsPayerAbi, stEthAddress, nounsPayerAddress } from '@/contracts';
9+
import { stEthAddress, nounsPayerAddress } from '@/contracts';
1010
import { Address, Hex } from '@/utils/types';
1111
import { defaultChain } from '@/wagmi';
1212

@@ -40,14 +40,7 @@ const handleActionAdd = (
4040
const value = parseEther((state.amount ?? 0).toString()).toString();
4141
const args = [state.address, BigInt(value)] as const;
4242

43-
// Define the transfer function ABI
44-
const transferAbi = parseAbi(['function transfer(address to, uint256 value) returns (bool)']);
45-
46-
const calldata = encodeFunctionData({
47-
abi: transferAbi,
48-
functionName: 'transfer',
49-
args,
50-
});
43+
const calldata = encodeAbiParameters([{ type: 'address' }, { type: 'uint256' }], args);
5144

5245
onActionAdd({
5346
address: stEthAddress[chainId],
@@ -59,11 +52,10 @@ const handleActionAdd = (
5952
} else if (state.TransferFundsCurrency === SupportedCurrency.USDC) {
6053
// Convert USDC amount - USDC has 6 decimals
6154
const usdcAmount = Math.round(parseFloat(state.amount ?? '0') * 1_000_000).toString();
62-
const calldata = encodeFunctionData({
63-
abi: nounsPayerAbi,
64-
functionName: 'sendOrRegisterDebt',
65-
args: [state.address, BigInt(usdcAmount)],
66-
});
55+
const calldata = encodeAbiParameters(
56+
[{ type: 'address' }, { type: 'uint256' }],
57+
[state.address, BigInt(usdcAmount)],
58+
);
6759

6860
onActionAdd({
6961
address: nounsPayerAddress[chainId],

packages/nouns-webapp/src/hooks/useStreamPaymentTransactions.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import type { Address } from '@/utils/types';
22

3-
import { encodeFunctionData, parseEther } from 'viem';
3+
import { encodeAbiParameters, parseEther } from 'viem';
44

55
import { ProposalActionModalState } from '@/components/ProposalActionsModal';
66
import { SupportedCurrency } from '@/components/ProposalActionsModal/steps/TransferFundsDetailsStep';
77
import {
8-
nounsPayerAbi,
98
nounsPayerAddress,
10-
nounsStreamFactoryAbi,
119
nounsStreamFactoryAddress,
1210
usdcAddress,
13-
wethAbi,
1411
wethAddress,
1512
} from '@/contracts';
1613
import {
@@ -63,19 +60,26 @@ export default function useStreamPaymentTransactions({
6360
0,
6461
predictedAddress,
6562
]),
66-
calldata: encodeFunctionData({
67-
abi: nounsStreamFactoryAbi,
68-
functionName: fundStreamFunction,
69-
args: [
63+
calldata: encodeAbiParameters(
64+
[
65+
{ type: 'address' },
66+
{ type: 'uint256' },
67+
{ type: 'address' },
68+
{ type: 'uint256' },
69+
{ type: 'uint256' },
70+
{ type: 'uint8' },
71+
{ type: 'address' },
72+
],
73+
[
7074
state.address,
7175
formatTokenAmount(Number(amount), state.TransferFundsCurrency),
7276
getTokenAddressForCurrency(state.TransferFundsCurrency),
73-
BigInt(state.streamStartTimestamp ? state.streamStartTimestamp : 0),
74-
BigInt(state.streamEndTimestamp ? state.streamEndTimestamp : 0),
77+
BigInt(state.streamStartTimestamp ?? 0),
78+
BigInt(state.streamEndTimestamp ?? 0),
7579
0,
7680
predictedAddress,
7781
],
78-
}),
82+
),
7983
},
8084
];
8185

@@ -98,11 +102,10 @@ export default function useStreamPaymentTransactions({
98102
predictedAddress,
99103
parseEther((amount ?? 0).toString()).toString(),
100104
]),
101-
calldata: encodeFunctionData({
102-
abi: wethAbi,
103-
functionName: wethTransfer,
104-
args: [predictedAddress, parseEther(amount.toString())],
105-
}),
105+
calldata: encodeAbiParameters(
106+
[{ type: 'address' }, { type: 'uint256' }],
107+
[predictedAddress, parseEther(amount.toString())],
108+
),
106109
});
107110
} else {
108111
const signature = 'sendOrRegisterDebt';
@@ -112,11 +115,10 @@ export default function useStreamPaymentTransactions({
112115
usdcValue: Number(human2ContractUSDCFormat(amount)),
113116
signature: signature,
114117
decodedCalldata: JSON.stringify([predictedAddress, human2ContractUSDCFormat(amount)]),
115-
calldata: encodeFunctionData({
116-
abi: nounsPayerAbi,
117-
functionName: signature,
118-
args: [predictedAddress, BigInt(human2ContractUSDCFormat(amount))],
119-
}),
118+
calldata: encodeAbiParameters(
119+
[{ type: 'address' }, { type: 'uint256' }],
120+
[predictedAddress, BigInt(human2ContractUSDCFormat(amount))],
121+
),
120122
});
121123
}
122124

packages/nouns-webapp/src/wrappers/nounsDao.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ export const formatProposalTransactionDetails = (details: {
493493
return {
494494
target,
495495
functionSig: name,
496-
callData: (decoded as string[]).join() as Hex,
496+
callData: decoded.map(v => String(v)).join(',') as Hex,
497497
value,
498498
};
499499
} catch (err) {

0 commit comments

Comments
 (0)