Skip to content

Commit

Permalink
adds a deep deocde handler for the hats multicall function.
Browse files Browse the repository at this point in the history
  • Loading branch information
skuhlmann committed Dec 19, 2023
1 parent 2f527c3 commit 83204f8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 68 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
112 changes: 48 additions & 64 deletions libs/tx-builder/src/utils/deepDecoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ const actionDecoders: Record<
}
const input = decodedMethod.inputs[0];

console.log('input', input);
if (input.type !== 'bytes') {
return createActionError(
action.data,
Expand All @@ -216,67 +215,6 @@ const actionDecoders: Record<
};
},

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

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

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

console.log('actions', actions.length);

// const decodedActions = await decodeMultiCall(
// options,
// action.data as `0x${string}`
// );

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(act),
operation:
decodeValue(action.operation) === '1'
? OperationType.DelegateCall
: OperationType.Call,
});

console.log('lol', i, lol);
return lol;
})
);

console.log('res', res);

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

// execTransactionFromModule(address,uint256,bytes,uint8)
'0x468721a7': async (options, action, decodedMethod) => {
if (
Expand Down Expand Up @@ -398,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 Expand Up @@ -444,8 +430,6 @@ const decodeAction = async (

const methodSignature = data.slice(0, 10);

console.log('methodSignature', methodSignature);

const actionDecoder = actionDecoders[methodSignature];
if (actionDecoder) {
return await actionDecoder(options, action, decodedMethod);
Expand Down

0 comments on commit 83204f8

Please sign in to comment.