Skip to content

Commit

Permalink
first commit - add parse command to bin.js
Browse files Browse the repository at this point in the history
  • Loading branch information
leomassazza committed Aug 3, 2022
1 parent 0cb16b5 commit 4e742a9
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions bin.js
Expand Up @@ -60,6 +60,53 @@ program
console.log(util.inspect(decode({ network, data, target, useOvm }), false, null, true));
});

program
.command('multisenddecode <txsdata> [target]')
.description('Decode a data payload from a gnosis multi-send staged to Synthetix contracts')
.option('-n, --network <value>', 'The network to use', x => x.toLowerCase(), 'mainnet')
.option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
.action(async (txsdata, target, { network, useOvm }) => {
if (txsdata.length <= 2) {
console.log('data too short');
}
const cleanData = txsdata.toLowerCase().startsWith('0x')
? txsdata.slice(2).toLowerCase()
: txsdata.toLowerCase();

const splitByLen = (s, len) => [s.slice(0, len), s.slice(len)];

let parts;
let rest = cleanData;
while (rest.length > 20) {
// operation type
parts = splitByLen(rest, 2);
const operationType = parts[0] === '00' ? 'Call' : 'DelegateCall';

// destination
parts = splitByLen(parts[1], 40);
const to = '0x' + parts[0];

// value
parts = splitByLen(parts[1], 64);
const txValue = parts[0];
const valueDecimal = parseInt(txValue, 16);

// data Len
parts = splitByLen(parts[1], 64);
const dataLen = parts[0];

const dataLenDecimal = parseInt(dataLen, 16);

// data Len
parts = splitByLen(parts[1], dataLenDecimal * 2);
const data = dataLenDecimal.toString(16) + parts[0];

console.log(`Target: ${to} Calltype: ${operationType} Value: ${valueDecimal}`);
console.log(util.inspect(decode({ network, data, target, useOvm }), false, null, true));
rest = parts[1];
}
});

program
.command('networks')
.description('Get networks')
Expand Down

0 comments on commit 4e742a9

Please sign in to comment.