Skip to content

Commit

Permalink
🐁 First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymx95 committed Mar 19, 2024
0 parents commit b2f7c28
Show file tree
Hide file tree
Showing 19 changed files with 1,589 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Logs
logs
*.log
*.dump
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

.env
.env.prod

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# Generated
generated

# Postgres data
dev/data
dev/fileHashes
dev/db-autostart/2.vaultsfyi.sql
backup.sql

.turbo
cache
53 changes: 53 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"files": {
"ignore": ["lib/**", "build/**"]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"useExhaustiveDependencies": "off",
"noUnusedVariables": "error"
},
"complexity": {
"useLiteralKeys": "off",
"useArrowFunction": "off",
"noForEach": "off",
"useOptionalChain": "off",
"noUselessSwitchCase": "off",
"noUselessEmptyExport": "error",
"noUselessFragments": "error"
},
"style": {
"noParameterAssign": "off",
"noUselessElse": "off",
"noNonNullAssertion": "off",
"useDefaultParameterLast": "off"
},
"suspicious": {
"noExplicitAny": "off",
"noArrayIndexKey": "off",
"useDefaultSwitchClauseLast": "off",
"noAssignInExpressions": "off"
}
}
},
"formatter": {
"indentStyle": "space",
"lineWidth": 120
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"semicolons": "asNeeded",
"trailingComma": "es5"
}
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
}
}
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "callerV2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@biomejs/biome": "^1.6.1"
}
}
32 changes: 32 additions & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Cached data
data

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
pnpm-lock.yaml

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

.env

/build
20 changes: 20 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "core",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"typecheck": "tsc --noEmit",
"lint": "pnpm typecheck && biome check .",
"lint:fix": "biome check . --apply"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@biomejs/biome": "^1.6.1",
"@types/node": "^20.11.30",
"tsx": "^4.7.1",
"typescript": "^5.4.2"
}
}
35 changes: 35 additions & 0 deletions packages/core/src/OpCodeBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { OPCODES } from './constants/opcodes'
import { padHex } from './utils/padHex'

export class OpCodeBuilder {
private opCodes: string[] = []

public addBytes(bytes: string) {
this.opCodes.push(bytes)
return this
}

public addOpCode(opCode: keyof typeof OPCODES) {
this.opCodes.push(OPCODES[opCode])
return this
}

public pushToStack(bytes: string | number) {
if (typeof bytes === 'number') bytes = padHex(bytes.toString(16))
const bytesLength = bytes.length / 2
if (bytesLength > 32) throw new Error('Bytes length must be equal or less than 32')
const pushOpCode = (Number(`0x${OPCODES.PUSH0}`) + bytesLength).toString(16)
this.opCodes.push(pushOpCode, bytes)
return this
}

public pushBytesSizeToStack(bytes: string) {
const callDataSize = padHex((bytes.length / 2).toString(16))
this.pushToStack(callDataSize)
return this
}

public toString(): `0x${string}` {
return `0x${this.opCodes.join('')}`
}
}
145 changes: 145 additions & 0 deletions packages/core/src/constants/opcodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
export const OPCODES = {
STOP: '00',
ADD: '01',
MUL: '02',
SUB: '03',
DIV: '04',
SDIV: '05',
MOD: '06',
SMOD: '07',
ADDMOD: '08',
MULMOD: '09',
EXP: '0A',
SIGNEXTEND: '0B',
LT: '10',
GT: '11',
SLT: '12',
SGT: '13',
EQ: '14',
ISZERO: '15',
AND: '16',
OR: '17',
XOR: '18',
NOT: '19',
BYTE: '1A',
SHL: '1B',
SHR: '1C',
SAR: '1D',
KECCAK256: '20',
ADDRESS: '30',
BALANCE: '31',
ORIGIN: '32',
CALLER: '33',
CALLVALUE: '34',
CALLDATALOAD: '35',
CALLDATASIZE: '36',
CALLDATACOPY: '37',
CODESIZE: '38',
CODECOPY: '39',
GASPRICE: '3A',
EXTCODESIZE: '3B',
EXTCODECOPY: '3C',
RETURNDATASIZE: '3D',
RETURNDATACOPY: '3E',
EXTCODEHASH: '3F',
BLOCKHASH: '40',
COINBASE: '41',
TIMESTAMP: '42',
NUMBER: '43',
PREVRANDAO: '44',
GASLIMIT: '45',
CHAINID: '46',
SELFBALANCE: '47',
BASEFEE: '48',
POP: '50',
MLOAD: '51',
MSTORE: '52',
MSTORE8: '53',
SLOAD: '54',
SSTORE: '55',
JUMP: '56',
JUMPI: '57',
PC: '58',
MSIZE: '59',
GAS: '5A',
JUMPDEST: '5B',
PUSH0: '5F',
PUSH1: '60',
PUSH2: '61',
PUSH3: '62',
PUSH4: '63',
PUSH5: '64',
PUSH6: '65',
PUSH7: '66',
PUSH8: '67',
PUSH9: '68',
PUSH10: '69',
PUSH11: '6A',
PUSH12: '6B',
PUSH13: '6C',
PUSH14: '6D',
PUSH15: '6E',
PUSH16: '6F',
PUSH17: '70',
PUSH18: '71',
PUSH19: '72',
PUSH20: '73',
PUSH21: '74',
PUSH22: '75',
PUSH23: '76',
PUSH24: '77',
PUSH25: '78',
PUSH26: '79',
PUSH27: '7A',
PUSH28: '7B',
PUSH29: '7C',
PUSH30: '7D',
PUSH31: '7E',
PUSH32: '7F',
DUP1: '80',
DUP2: '81',
DUP3: '82',
DUP4: '83',
DUP5: '84',
DUP6: '85',
DUP7: '86',
DUP8: '87',
DUP9: '88',
DUP10: '89',
DUP11: '8A',
DUP12: '8B',
DUP13: '8C',
DUP14: '8D',
DUP15: '8E',
DUP16: '8F',
SWAP1: '90',
SWAP2: '91',
SWAP3: '92',
SWAP4: '93',
SWAP5: '94',
SWAP6: '95',
SWAP7: '96',
SWAP8: '97',
SWAP9: '98',
SWAP10: '99',
SWAP11: '9A',
SWAP12: '9B',
SWAP13: '9C',
SWAP14: '9D',
SWAP15: '9E',
SWAP16: '9F',
LOG0: 'A0',
LOG1: 'A1',
LOG2: 'A2',
LOG3: 'A3',
LOG4: 'A4',
CREATE: 'F0',
CALL: 'F1',
CALLCODE: 'F2',
RETURN: 'F3',
DELEGATECALL: 'F4',
CREATE2: 'F5',
STATICCALL: 'FA',
REVERT: 'FD',
SELFDESTRUCT: 'FF',
}
Loading

0 comments on commit b2f7c28

Please sign in to comment.