Skip to content

Commit

Permalink
Migrate EVM typegen to new codec (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanruch authored May 3, 2024
1 parent 1a6d5da commit b7fa5d8
Show file tree
Hide file tree
Showing 18 changed files with 627 additions and 882 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/evm-abi",
"comment": "Added types for event arguments, function parameters and return values",
"type": "minor"
}
],
"packageName": "@subsquid/evm-abi"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/evm-typegen",
"comment": "Migrate typegen to new codec; Drop dependency to ethers.js",
"type": "major"
}
],
"packageName": "@subsquid/evm-typegen"
}
148 changes: 103 additions & 45 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion evm/evm-abi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"build": "rm -rf lib && tsc -p tsconfig.build.json"
},
"dependencies": {
"@subsquid/evm-codec": "^0.0.0"
"@subsquid/evm-codec": "^0.0.0",
"keccak256": "^1.0.6"
},
"devDependencies": {
"@types/node": "^18.18.14",
Expand Down
2 changes: 2 additions & 0 deletions evm/evm-abi/src/abi-components/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type IndexedCodecs<T extends EventArgs> = Pretty<{
[K in keyof T]: T[K] extends { indexed: true; isDynamic: true } ? typeof bytes32 & { indexed: true } : T[K]
}>

export type EventParams<T extends AbiEvent<any>> = T extends AbiEvent<infer U> ? StructTypes<U> : never

export class AbiEvent<const T extends EventArgs> {
public readonly params: any
constructor(public readonly topic: string, args: T) {
Expand Down
4 changes: 3 additions & 1 deletion evm/evm-abi/src/abi-components/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ function slotsCount(codecs: readonly Codec<any>[]) {
return count
}

type FunctionReturn<T> = T extends Codec<infer U> ? U : T extends Struct ? StructTypes<T> : undefined
export type FunctionReturn<T> = T extends Codec<infer U> ? U : T extends Struct ? StructTypes<T> : void

export type FunctionArguments<T extends AbiFunction<any, any>> = T extends AbiFunction<infer U, any> ? StructTypes<U> : never

export class AbiFunction<const T extends Struct, const R extends Codec<any> | Struct | undefined> {
readonly #selector: Buffer
Expand Down
6 changes: 4 additions & 2 deletions evm/evm-abi/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export { ContractBase } from './contract-base'

export { indexed } from './indexed'
export { fun, AbiFunction } from './abi-components/function'
export { event, AbiEvent, type EventRecord } from './abi-components/event'
export { fun, AbiFunction, type FunctionReturn, type FunctionArguments } from './abi-components/function'
export { event, AbiEvent, type EventRecord, type EventParams } from './abi-components/event'
import keccak256 from 'keccak256'
export { keccak256 }
6 changes: 3 additions & 3 deletions evm/evm-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"@subsquid/util-internal": "^3.2.0",
"@subsquid/util-internal-code-printer": "^1.2.2",
"@subsquid/util-internal-commander": "^1.4.0",
"@subsquid/evm-codec": "0.0.0",
"@subsquid/evm-abi": "0.0.0",
"commander": "^11.1.0"
},
"peerDependencies": {
"ethers": "^6.9.0"
},
"devDependencies": {
"abitype": "^1.0.0",
"@types/node": "^18.18.14",
"typescript": "~5.3.2"
}
Expand Down
135 changes: 0 additions & 135 deletions evm/evm-typegen/src/abi.support.ts

This file was deleted.

Loading

0 comments on commit b7fa5d8

Please sign in to comment.