Skip to content

Commit

Permalink
Merge pull request #462 from HausDAO/fix/more-deep-decode
Browse files Browse the repository at this point in the history
Fix/more deep decode
  • Loading branch information
santteegt authored Dec 19, 2023
2 parents 84d433c + 83204f8 commit 7ec7b7c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ export const ProposalDetailsContainer = ({
let shouldUpdate = true;
const fetchPropActions = async (
chainId: ValidNetwork,
actionData: string,
_actionMeta?: MulticallAction[]
actionData: string
) => {
const proposalActions = await decodeProposalActions({
chainId,
Expand All @@ -78,12 +77,12 @@ export const ProposalDetailsContainer = ({
};

if (!isValidNetwork(daoChain) || !proposal) return;
fetchPropActions(daoChain, proposal.proposalData, actionsMeta);
fetchPropActions(daoChain, proposal.proposalData);

return () => {
shouldUpdate = false;
};
}, [daoChain, proposal, actionsMeta]);
}, [daoChain, proposal]);
return (
<>
<ProposalDetails
Expand Down
55 changes: 53 additions & 2 deletions libs/tx-builder/src/utils/deepDecoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ const decodeMethod = (options: {
name: input.name,
type: input.type,
value: Array.isArray(result.args?.[index])
? (result.args?.[index] as Array<any>).length
? (result.args?.[index] as Array<any>).toString()
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
(result.args?.[index] as Array<any>).length
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
(result.args?.[index] as Array<any>).toString()
: '[]'
: result.args?.[index]?.toString() || '0x',
}));
Expand Down Expand Up @@ -190,6 +192,7 @@ const actionDecoders: Record<
);
}
const input = decodedMethod.inputs[0];

if (input.type !== 'bytes') {
return createActionError(
action.data,
Expand Down Expand Up @@ -333,6 +336,54 @@ const actionDecoders: Record<
decodedActions: [],
};
},

// multicall(bytes)
'0xac9650d8': async (options, action, decodedMethod) => {
if (
decodedMethod.functionName !== 'multicall' ||
decodedMethod.inputs.length !== 1
) {
return createActionError(
action.data,
'Could not decode action: multiSend'
);
}
const input = decodedMethod.inputs[0];

if (input.type !== 'bytes[]') {
return createActionError(
action.data,
'Could not decode action: multicall'
);
}

const actions = input.value.split(',');

const res = await Promise.all(
actions.map(async (act, i) => {
const lol = await decodeAction(options, {
to: action.to as `0x${string}`,
data: act as `0x${string}`,
value: decodeValue(action.value),
operation:
decodeValue(action.operation) === '1'
? OperationType.DelegateCall
: OperationType.Call,
});

return lol;
})
);

return {
to: action.to,
operation: action.operation || OperationType.DelegateCall,
name: decodedMethod.functionName,
value: decodeValue(action.value),
params: decodedMethod.inputs,
decodedActions: res,
};
},
};

const decodeAction = async (
Expand Down

0 comments on commit 7ec7b7c

Please sign in to comment.