Sovryn-smart-contracts
Sovryn-smart-contracts copied to clipboard
functionSelectors.js
Script in python or js to extend functionSignatures.sh, add params as needed, compute selectors (four bytes of the Keccak-256 or SHA-3 hash of the signature of the function)
In order to quickly update current function and event selectors, I used this recipe, pending yet to develop a complete js script to do all the job by itself.
To get signatures from selectors, use keccak256.js script found at: https://github.com/DistributedCollective/Sovryn-smart-contracts/commit/f830aa932efd9ab5eab7f3156aa8a3615e75b07a#diff-35603448485527fb547e0033f6c899e63235d8834924bbe3af371e548df6b73d Pipeline code to get event signatures:
find . -type f -name '.sol' ! -path 'node_modules/' -print0 | xargs -0 sed -z "s///[^\n]\n//g" | awk '/event/,/;/' | sed "s/[[:space:]]+event/event/" | sed -z "s/\n[\t ]//g" | sed -z "s/;/;\n/g" | egrep "^event " | sed "s/ indexed / /g" | sed -E "s/(address|uint[0-9]+|bytes[0-9]|bool|string)([]) [^,)]+/\1/g" | sed "s/event //" | sed -r "s/\s+//g" | xargs -0 node scripts/keccak256.js > eventSignatures.txt
Pipeline code to get function signatures:
find . -type f -name '.sol' ! -path 'node_modules/' -print0 | xargs -0 sed -z "s///[^\n]\n//g" | awk '/function/,/{/' | awk '/function/,/;/' | sed "s/[[:space:]]+function/function/" | sed -z "s/\n[\t ]//g" | sed -z "s/{/\n/g" | sed -z "s/;/\n/g" | egrep --text "^function " | egrep --text " (public|external) " | sed -E "s/(address|uint[0-9]+|bytes[0-9]|bool|string)([[0-9]])* [^,)]+/\1/g" | sed "s/function //" | sed -r "s/ (public|external).*$//" | sed -r "s/\s+//g" | xargs -0 node scripts/keccak256.js > functionSignatures.txt
Script is done! Updated event topics and function selector spreadsheet, now including AMM contracts as well: https://docs.google.com/spreadsheets/d/16IOcLe3itNsG1fJjMrpTM802sZGd37hvb6I-leBYPUI/edit?usp=sharing
Pending to fix 3 issues: 1.- On function signatures, interfaces should be typed as addresses. 2.- On function signatures, structs should be exploded into their components, around brackets () 3.- According to the list swapExternal(address,address,address,address,uint256,uint256,bytes) has selector: 0x11058a8a According to vscode: e321b540 => swapExternal(address,address,address,address,uint256,uint256,uint256,bytes) It has an additional parameter. This case should be debugged.