From 2f527c3fe5facd4ab8ce7a0ae730fd17439f3ec8 Mon Sep 17 00:00:00 2001 From: skuhlmann Date: Mon, 18 Dec 2023 15:04:02 -0700 Subject: [PATCH 1/2] stuck in a loop --- libs/tx-builder/src/utils/deepDecoding.ts | 71 ++++++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/libs/tx-builder/src/utils/deepDecoding.ts b/libs/tx-builder/src/utils/deepDecoding.ts index c4d12c87..b276bc18 100644 --- a/libs/tx-builder/src/utils/deepDecoding.ts +++ b/libs/tx-builder/src/utils/deepDecoding.ts @@ -158,8 +158,10 @@ const decodeMethod = (options: { name: input.name, type: input.type, value: Array.isArray(result.args?.[index]) - ? (result.args?.[index] as Array).length - ? (result.args?.[index] as Array).toString() + ? // eslint-disable-next-line @typescript-eslint/no-explicit-any + (result.args?.[index] as Array).length + ? // eslint-disable-next-line @typescript-eslint/no-explicit-any + (result.args?.[index] as Array).toString() : '[]' : result.args?.[index]?.toString() || '0x', })); @@ -190,6 +192,8 @@ const actionDecoders: Record< ); } const input = decodedMethod.inputs[0]; + + console.log('input', input); if (input.type !== 'bytes') { return createActionError( action.data, @@ -212,6 +216,67 @@ 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 ( @@ -379,6 +444,8 @@ 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); From 83204f84e472902a251d2d98d8dfe8e97ed23576 Mon Sep 17 00:00:00 2001 From: skuhlmann Date: Tue, 19 Dec 2023 08:48:41 -0700 Subject: [PATCH 2/2] adds a deep deocde handler for the hats multicall function. --- .../ProposalDetailsContainer.tsx | 7 +- libs/tx-builder/src/utils/deepDecoding.ts | 112 ++++++++---------- 2 files changed, 51 insertions(+), 68 deletions(-) diff --git a/libs/moloch-v3-macro-ui/src/components/ProposalDetails/ProposalDetailsContainer.tsx b/libs/moloch-v3-macro-ui/src/components/ProposalDetails/ProposalDetailsContainer.tsx index 9f0e21ee..d6678f17 100644 --- a/libs/moloch-v3-macro-ui/src/components/ProposalDetails/ProposalDetailsContainer.tsx +++ b/libs/moloch-v3-macro-ui/src/components/ProposalDetails/ProposalDetailsContainer.tsx @@ -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, @@ -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 ( <> { - 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 ( @@ -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 ( @@ -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);