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

WIP: Detect interfaces #54

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

pkgs.graphviz # For debugging
pkgs.gnumake
pkgs.bun
];

shellHook = ''
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/__tests__/interfaces.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect } from '@jest/globals';

import { selectorsToInterfaces } from '../interfaces';

import { test } from "./env";


test('selectors to interfaces', async ({}) => {
// Given a set of interfaces, get the interfaces that it implements
const selectors = ['0x02751cec', '0x054d50d4', '0x18cbafe5', '0x1f00ca74', '0x2195995c', '0x38ed1739', '0x4a25d94a', '0x5b0d5984', '0x5c11d795', '0x791ac947', '0x7ff36ab5', '0x85f8c259', '0x8803dbee', '0xad5c4648', '0xad615dec', '0xaf2979eb', '0xb6f9de95', '0xbaa2abde', '0xc45a0155', '0xd06ca61f', '0xded9382a', '0xe8e33700', '0xf305d719', '0xfb3bdb41'];

const got = selectorsToInterfaces(selectors);

});

58 changes: 58 additions & 0 deletions src/embedded/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export const interfaces = {
"ERC-20": [
"function totalSupply() view returns (uint256)",
"function balanceOf(address) view returns (uint256)",
"function transfer(address, uint256) returns (bool)",
"function allowance(address, address) returns (uint256)",
"function approve(address, uint256) returns (bool)",
"function transferFrom(address, address, uint256) returns (bool)",
],
"ERC-165": [
"function supportsInterface(bytes4 interfaceId) view returns (bool)",
],
"ERC-721": [
"function balanceOf(address owner) view returns (uint256 balance)",
"function ownerOf(uint256 tokenId) view returns (address owner)",
"function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data)",
"function safeTransferFrom(address from, address to, uint256 tokenId)",
"function transferFrom(address from, address to, uint256 tokenId)",
"function approve(address to, uint256 tokenId)",
"function setApprovalForAll(address operator, bool _approved)",
"function getApproved(uint256 tokenId) view returns (address operator)",
"function isApprovedForAll(address owner, address operator) view returns (bool)",
],
"ERC-777": [
"function name() view returns (string memory)",
"function symbol() view returns (string memory)",
"function granularity() view returns (uint256)",
"function totalSupply() view returns (uint256)",
"function balanceOf(address owner) view returns (uint256)",
"function send(address recipient, uint256 amount, bytes calldata data)",
"function burn(uint256 amount, bytes calldata data)",
"function isOperatorFor(address operator, address tokenHolder) view returns (bool)",
"function authorizeOperator(address operator)",
"function revokeOperator(address operator)",
"function defaultOperators() view returns (address[] memory)",
"function operatorSend(address sender, address recipient, uint256 amount, bytes calldata data, bytes calldata operatorData)",
"function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData)",
],
"ERC-1155": [
"function balanceOf(address account, uint256 id) view returns (uint256)",
"function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) view returns (uint256[] memory)",
"function setApprovalForAll(address operator, bool approved)",
"function isApprovedForAll(address account, address operator) view returns (bool)",
"function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes calldata data)",
"function safeBatchTransferFrom( address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data)",
],
"ERC-4626": [
],
"Ownable": [
"function owner() view returns (address)",
"function renounceOwnership()",
"function transferOwnership(address)",
],
"Multicall": [
"function multicall(bytes[]) returns (bytes[] memory)",
],
}

5 changes: 5 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Given a list of selectors, return a mapping of interfaces it implements to a list of present function signatures that belong to it.
export function selectorsToInterfaces(selectors: string[], index?: any): Record<string, string[]> {
// XXX
return {}
}
Loading