Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode MultiSend transactions into MetaTransactionData[] #291

Closed
germartinez opened this issue Nov 18, 2022 · 1 comment · Fixed by #342
Closed

Decode MultiSend transactions into MetaTransactionData[] #291

germartinez opened this issue Nov 18, 2022 · 1 comment · Fixed by #342

Comments

@germartinez
Copy link
Member

Currently MultiSend transactions can only be encoded in the safe-core-sdk.
It would be a nice to have to allow decoding transactions in the safe-core-sdk as well.

Currently only this option to decode is available in the safe-service-client, but it does not return a MetaTransactionData[]:

const decodedData = await safeService.decodeData(data)

Use this code from Manu as a reference:

export const decodeMultiSendTxs = (data: string): MetaTransactionData[] => {
  const multiSendInterface = new ethers.utils.Interface([
    'function multiSend(bytes memory transactions) public payable ',
  ])
  const abiCoder = new ethers.utils.AbiCoder()
  // decode multiSend and remove '0x'
  let remainingData = multiSendInterface.decodeFunctionData('multiSend', data)[0].slice(2)

  const txs: MetaTransactionData[] = []
  while (remainingData.length > 0) {
    const txDataEncoded = ethers.utils.hexZeroPad(`0x${remainingData.slice(2, 170)}`, 32 * 3)
    const [txTo, txValue, txDataByteLength] = abiCoder.decode(['address', 'uint256', 'uint256'], txDataEncoded)
    remainingData = remainingData.slice(170)

    const dataLength = (txDataByteLength as BigNumber).toNumber() * 2
    let txData = `0x${remainingData.slice(0, dataLength)}`
    remainingData = remainingData.slice(dataLength)
    txs.push({
      to: txTo.toString(),
      value: txValue.toString(),
      data: txData,
      operation: 0,
    })
  }

  return txs
}
@dasanra
Copy link
Collaborator

dasanra commented Jan 31, 2025

Solved by #342

@dasanra dasanra closed this as completed Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants