From 8a398f8b24e89b15711389f5b22bcdec1b636ef5 Mon Sep 17 00:00:00 2001 From: arnaudberger Date: Mon, 8 Jul 2024 09:50:57 -0400 Subject: [PATCH] fix snake case issues and add golden image state --- ethfull/abi.go | 27 +- ethfull/generate_test.go | 80 ++ ethfull/helpers.go | 1 - ethfull/state.go | 22 +- ethfull/templates/proto/contract.proto.gotmpl | 16 +- ethfull/templates/src/lib.rs.gotmpl | 34 +- ethfull/testdata/complex_abi.json | 1249 +++++++++++++++++ ethfull/testoutput/complex_abi/.gitignore | 2 + ethfull/testoutput/complex_abi/Cargo.toml | 34 + ethfull/testoutput/complex_abi/Makefile | 29 + .../abi/ewqocontraadd123_contract.abi.json | 236 ++++ .../complex_abi/abi/test_contract.abi.json | 988 +++++++++++++ ethfull/testoutput/complex_abi/build.rs | 42 + .../complex_abi/proto/contract.proto | 329 +++++ .../complex_abi/rust-toolchain.toml | 3 + ethfull/testoutput/complex_abi/src/abi/mod.rs | 3 + ethfull/testoutput/complex_abi/src/lib.rs | 1074 ++++++++++++++ ethfull/testoutput/complex_abi/src/pb/mod.rs | 8 + .../testoutput/complex_abi/substreams.yaml | 58 + go.mod | 5 +- go.sum | 2 + templating.go | 24 +- 22 files changed, 4210 insertions(+), 56 deletions(-) create mode 100644 ethfull/testoutput/complex_abi/.gitignore create mode 100644 ethfull/testoutput/complex_abi/Cargo.toml create mode 100644 ethfull/testoutput/complex_abi/Makefile create mode 100644 ethfull/testoutput/complex_abi/abi/ewqocontraadd123_contract.abi.json create mode 100644 ethfull/testoutput/complex_abi/abi/test_contract.abi.json create mode 100644 ethfull/testoutput/complex_abi/build.rs create mode 100644 ethfull/testoutput/complex_abi/proto/contract.proto create mode 100644 ethfull/testoutput/complex_abi/rust-toolchain.toml create mode 100644 ethfull/testoutput/complex_abi/src/abi/mod.rs create mode 100644 ethfull/testoutput/complex_abi/src/lib.rs create mode 100644 ethfull/testoutput/complex_abi/src/pb/mod.rs create mode 100644 ethfull/testoutput/complex_abi/substreams.yaml diff --git a/ethfull/abi.go b/ethfull/abi.go index 1447b88..74cd84e 100644 --- a/ethfull/abi.go +++ b/ethfull/abi.go @@ -3,12 +3,13 @@ package ethfull import ( "encoding/hex" "fmt" + "github.com/golang-cz/textcase" + "github.com/huandu/xstrings" "sort" "strconv" "strings" "github.com/gertd/go-pluralize" - "github.com/huandu/xstrings" "github.com/iancoleman/strcase" "github.com/streamingfast/eth-go" codegen "github.com/streamingfast/substreams-codegen" @@ -87,7 +88,7 @@ func (a *ABI) BuildEventModels() (out []codegenEvent, err error) { protoFieldName := xstrings.ToSnakeCase(pluralizerSingleton.Plural(rustABIStructName)) // prost will do a to_lower_camel_case() on any struct name - rustGeneratedStructName := xstrings.ToCamelCase(xstrings.ToSnakeCase(rustABIStructName)) + rustGeneratedStructName := textcase.PascalCase(xstrings.ToSnakeCase(rustABIStructName)) eventID := hex.EncodeToString(event.LogID()) @@ -156,9 +157,10 @@ func (a *ABI) BuildCallModels() (out []codegenCall, err error) { rustABIStructName = sanitizeABIStructName(rustABIStructName) protoFieldName := "call_" + xstrings.ToSnakeCase(pluralizerSingleton.Plural(rustABIStructName)) + // prost will do a to_lower_camel_case() on any struct name - rustGeneratedStructName := xstrings.ToCamelCase(xstrings.ToSnakeCase(rustABIStructName)) - protoMessageName := xstrings.ToCamelCase(xstrings.ToSnakeCase(rustABIStructName) + "Call") + rustGeneratedStructName := textcase.PascalCase(xstrings.ToSnakeCase(rustABIStructName)) + protoMessageName := textcase.PascalCase(xstrings.ToSnakeCase(rustABIStructName) + "Call") codegenCall := codegenCall{ Rust: &rustCallModel{ @@ -253,8 +255,8 @@ func (e *rustEventModel) populateFields(log *eth.LogEventDef) error { zlog.Info("Generating ABI Events", zap.String("name", log.Name), zap.String("param_names", strings.Join(paramNames, ","))) for _, parameter := range log.Parameters { - name := xstrings.ToSnakeCase(parameter.Name) - name = codegen.SanitizeProtoFieldName(name) + name := codegen.SanitizeProtoFieldName(parameter.Name) + name = xstrings.ToSnakeCase(name) toProtoCode := generateFieldTransformCode(parameter.Type, "event."+name, false) if toProtoCode == SKIP_FIELD { @@ -387,8 +389,8 @@ func methodToABIConversionMaps( abiConversionMap = make(map[string]string) } for _, parameter := range parameters { - name := xstrings.ToSnakeCase(parameter.Name) - name = codegen.SanitizeProtoFieldName(name) + name := codegen.SanitizeProtoFieldName(parameter.Name) + name = xstrings.ToSnakeCase(name) toProtoCode := generateFieldTransformCode(parameter.Type, "decoded_call."+name, false) if toProtoCode != SKIP_FIELD { @@ -499,8 +501,9 @@ func (e *protoEventModel) populateFields(log *eth.LogEventDef) error { e.Fields = make([]protoField, 0, len(log.Parameters)) for _, parameter := range log.Parameters { - fieldName := xstrings.ToSnakeCase(parameter.Name) - fieldName = codegen.SanitizeProtoFieldName(fieldName) + fieldName := codegen.SanitizeProtoFieldName(parameter.Name) + fieldName = xstrings.ToSnakeCase(fieldName) + fieldType := getProtoFieldType(parameter.Type) if fieldType == SKIP_FIELD { continue @@ -524,8 +527,8 @@ func (e *protoCallModel) populateFields(call *eth.MethodDef) error { e.Fields = make([]protoField, 0, len(call.Parameters)+len(call.ReturnParameters)) for _, parameter := range call.Parameters { - fieldName := xstrings.ToSnakeCase(parameter.Name) - fieldName = codegen.SanitizeProtoFieldName(fieldName) + fieldName := codegen.SanitizeProtoFieldName(parameter.Name) + fieldName = xstrings.ToSnakeCase(fieldName) fieldType := getProtoFieldType(parameter.Type) if fieldType == SKIP_FIELD { continue diff --git a/ethfull/generate_test.go b/ethfull/generate_test.go index 1df5c52..b8461cc 100644 --- a/ethfull/generate_test.go +++ b/ethfull/generate_test.go @@ -1,10 +1,13 @@ package ethfull import ( + "archive/zip" "bytes" "context" "encoding/json" + "io" "os" + "strings" "testing" "github.com/saracen/fastzip" @@ -70,6 +73,11 @@ func Test_Generate(t *testing.T) { generatorFile: "./testdata/uniswap_track_calls_clickhouse.json", outputType: outputTypeSQL, }, + { + name: "Complex abi with digits and specific character", + generatorFile: "./testdata/complex_abi.json", + outputType: outputTypeSubgraph, + }, } for _, c := range cases { @@ -127,6 +135,78 @@ func Test_Generate(t *testing.T) { } } +func TestGoldenImage(t *testing.T) { + cases := []struct { + name string + generatorFile string + expectedOutput string + }{ + { + name: "complex_abi", + generatorFile: "./testdata/complex_abi.json", + expectedOutput: "./testoutput/complex_abi", + }, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + p := testProjectFromState(t, c.generatorFile) + + for _, contract := range p.Contracts { + res := cmdDecodeABI(contract)().(ReturnRunDecodeContractABI) + require.NoError(t, res.err) + contract.abi = res.abi + } + + for _, dynamicContract := range p.DynamicContracts { + res := cmdDecodeDynamicABI(dynamicContract)().(ReturnRunDecodeDynamicContractABI) + require.NoError(t, res.err) + dynamicContract.abi = res.abi + + for _, contract := range p.Contracts { + if contract.Name == dynamicContract.ParentContractName { + dynamicContract.parentContract = contract + } + } + } + + p.outputType = outputTypeSubgraph + + srcZip, projZip, err := p.generate(outputTypeSubgraph) + require.NoError(t, err) + assert.NotEmpty(t, srcZip) + assert.NotEmpty(t, projZip) + + //Unzip srcZip and compare with expectedOutput + reader := bytes.NewReader(srcZip) + zipReader, err := zip.NewReader(reader, int64(len(srcZip))) + require.NoError(t, err) + + for _, f := range zipReader.File { + //Should not modify the abi.json at all + if strings.HasSuffix(f.Name, "abi.json") { + continue + } + + goldenFileName := c.expectedOutput + "/" + strings.TrimPrefix(f.Name, "substreams/") + goldenContent, err := os.ReadFile(goldenFileName) + require.NoError(t, err) + + fileReader, err := f.Open() + require.NoError(t, err) + + unzipFileContent, err := io.ReadAll(fileReader) + + //Remove /n from both files + goldenContent = bytes.ReplaceAll(goldenContent, []byte("\n"), []byte("")) + unzipFileContent = bytes.ReplaceAll(unzipFileContent, []byte("\n"), []byte("")) + + require.Equal(t, goldenContent, unzipFileContent) + } + }) + } +} + func TestUniFactory(t *testing.T) { p := testProjectFromState(t, "./testdata/uniswap_factory_v3.json") diff --git a/ethfull/helpers.go b/ethfull/helpers.go index e7193f1..444bb3e 100644 --- a/ethfull/helpers.go +++ b/ethfull/helpers.go @@ -15,6 +15,5 @@ func sanitizeABIStructName(rustABIStructName string) string { return replacement }) - return result } diff --git a/ethfull/state.go b/ethfull/state.go index 61585a1..65e11d7 100644 --- a/ethfull/state.go +++ b/ethfull/state.go @@ -5,13 +5,14 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/codemodus/kace" + "github.com/golang-cz/textcase" + "github.com/huandu/xstrings" "math" "regexp" "strings" "time" - "github.com/huandu/xstrings" - "github.com/iancoleman/strcase" "github.com/streamingfast/eth-go" ) @@ -59,7 +60,7 @@ func contractNames(contracts []*Contract) (out []string) { func (p *Project) ChainConfig() *ChainConfig { return ChainConfigByID[p.ChainName] } func (p *Project) ChainEndpoint() string { return ChainConfigByID[p.ChainName].FirehoseEndpoint } -func (p *Project) SubgraphProjectName() string { return xstrings.ToKebabCase(p.Name) } +func (p *Project) SubgraphProjectName() string { return textcase.KebabCase(p.Name) } func (p *Project) SQLImportVersion() string { return "1.0.7" } func (p *Project) GraphImportVersion() string { return "0.1.0" } func (p *Project) DatabaseChangeImportVersion() string { return "1.2.1" } @@ -199,9 +200,13 @@ type BaseContract struct { abi *ABI } -func (c *BaseContract) Identifier() string { return c.Name } -func (c *BaseContract) IdentityCamelCase() string { return strcase.ToLowerCamel(c.Name) } -func (c *BaseContract) IdentifierUpper() string { return strings.ToUpper(c.Name) } +func (c *BaseContract) Identifier() string { return c.Name } +func (c *BaseContract) IdentifierSnakeCase() string { + return xstrings.ToSnakeCase(c.Name) +} +func (c *BaseContract) IdentifierPascalCase() string { return textcase.PascalCase(c.Name) } +func (c *BaseContract) IdentityCamelCase() string { return textcase.CamelCase(c.Name) } +func (c *BaseContract) IdentifierUpper() string { return strings.ToUpper(c.Name) } func (c *BaseContract) EventFields(event string) ([]*eth.LogParameter, error) { hash, err := hex.DecodeString(event) @@ -288,8 +293,9 @@ func (d DynamicContract) FactoryInitialBlock() uint64 { return *d.parentContract.InitialBlock } -func (d DynamicContract) ParentContract() *Contract { return d.parentContract } -func (d DynamicContract) Identifier() string { return d.Name } +func (d DynamicContract) ParentContract() *Contract { return d.parentContract } +func (d DynamicContract) Identifier() string { return d.Name } +func (d DynamicContract) IdentifierSnakeCase() string { return kace.Snake(d.Name) } func (d DynamicContract) FetchABI(chainConfig *ChainConfig) (abi string, err error) { a, err := getContractABIFollowingProxy(context.Background(), d.referenceContractAddress, chainConfig) if err != nil { diff --git a/ethfull/templates/proto/contract.proto.gotmpl b/ethfull/templates/proto/contract.proto.gotmpl index 0c74bf8..cc0f5b3 100644 --- a/ethfull/templates/proto/contract.proto.gotmpl +++ b/ethfull/templates/proto/contract.proto.gotmpl @@ -12,7 +12,7 @@ message Events { {{- range $index, $event := $contract.EventModels }} {{- $proto := $event.Proto }} {{- $eventsCounter = add $eventsCounter 1 }} - repeated {{ toPascalCase $contract.Identifier }}_{{$proto.MessageName}} {{ toSnakeCase $contract.Identifier }}_{{$proto.OutputModuleFieldName}} = {{ $eventsCounter }}; + repeated {{ $contract.IdentifierPascalCase }}_{{$proto.MessageName}} {{ $contract.IdentifierSnakeCase }}_{{$proto.OutputModuleFieldName}} = {{ $eventsCounter }}; {{- end}} {{- end}} {{- end}} @@ -21,7 +21,7 @@ message Events { {{- range $index, $event := $ddsContract.EventModels -}} {{- $proto := $event.Proto }} {{- $eventsCounter = add $eventsCounter 1 }} - repeated {{ toPascalCase $ddsContract.Identifier }}_{{$proto.MessageName}} {{ toSnakeCase $ddsContract.Identifier }}_{{$proto.OutputModuleFieldName}} = {{ $eventsCounter }}; + repeated {{ $ddsContract.IdentifierPascalCase }}_{{$proto.MessageName}} {{ $ddsContract.IdentifierSnakeCase }}_{{$proto.OutputModuleFieldName}} = {{ $eventsCounter }}; {{- end}} {{- end}} {{- end}} @@ -35,7 +35,7 @@ message Calls { {{- range $index, $call := $contract.CallModels }} {{- $proto := $call.Proto }} {{- $callsCounter = add $callsCounter 1 }} - repeated {{ toPascalCase $contract.Identifier }}_{{$proto.MessageName}} {{ toSnakeCase $contract.Identifier }}_{{$proto.OutputModuleFieldName}} = {{ $callsCounter }}; + repeated {{ $contract.IdentifierPascalCase }}_{{$proto.MessageName}} {{ $contract.IdentifierSnakeCase }}_{{$proto.OutputModuleFieldName}} = {{ $callsCounter }}; {{- end}} {{- end}} {{- end}} @@ -44,7 +44,7 @@ message Calls { {{- range $index, $call := $ddsContract.CallModels -}} {{- $proto := $call.Proto }} {{- $callsCounter = add $callsCounter 1 }} - repeated {{ toPascalCase $ddsContract.Identifier }}_{{$proto.MessageName}} {{ toSnakeCase $ddsContract.Identifier }}_{{$proto.OutputModuleFieldName}} = {{ $callsCounter }}; + repeated {{ $ddsContract.IdentifierPascalCase }}_{{$proto.MessageName}} {{ $ddsContract.IdentifierSnakeCase }}_{{$proto.OutputModuleFieldName}} = {{ $callsCounter }}; {{- end}} {{- end}} {{- end}} @@ -60,7 +60,7 @@ message EventsCalls { {{- if .TrackEvents }} {{- range $index, $event := $contract.EventModels }} {{- $proto := $event.Proto }} -message {{ toPascalCase $contract.Identifier }}_{{ $proto.MessageName }} { +message {{ $contract.IdentifierPascalCase }}_{{ $proto.MessageName }} { string evt_tx_hash = 1; uint32 evt_index = 2; google.protobuf.Timestamp evt_block_time = 3; @@ -74,7 +74,7 @@ message {{ toPascalCase $contract.Identifier }}_{{ $proto.MessageName }} { {{ if .TrackCalls }} {{- range $index, $call := $contract.CallModels }} {{- $proto := $call.Proto }} -message {{ toPascalCase $contract.Identifier }}_{{ $proto.MessageName }} { +message {{ $contract.IdentifierPascalCase }}_{{ $proto.MessageName }} { string call_tx_hash = 1; google.protobuf.Timestamp call_block_time = 2; uint64 call_block_number = 3; @@ -92,7 +92,7 @@ message {{ toPascalCase $contract.Identifier }}_{{ $proto.MessageName }} { {{- range $index, $event := $ddsContract.EventModels }} {{ $proto := $event.Proto }} -message {{ toPascalCase $ddsContract.Identifier }}_{{ $proto.MessageName }} { +message {{ $ddsContract.IdentifierPascalCase }}_{{ $proto.MessageName }} { string evt_tx_hash = 1; uint32 evt_index = 2; google.protobuf.Timestamp evt_block_time = 3; @@ -106,7 +106,7 @@ message {{ toPascalCase $ddsContract.Identifier }}_{{ $proto.MessageName }} { {{- range $index, $call := $ddsContract.CallModels }} {{ $proto := $call.Proto }} -message {{ toPascalCase $ddsContract.Identifier }}_{{ $proto.MessageName }} { +message {{ $ddsContract.IdentifierPascalCase }}_{{ $proto.MessageName }} { string call_tx_hash = 1; google.protobuf.Timestamp call_block_time = 2; uint64 call_block_number = 3; diff --git a/ethfull/templates/src/lib.rs.gotmpl b/ethfull/templates/src/lib.rs.gotmpl index 7aef9ba..ceb06d5 100644 --- a/ethfull/templates/src/lib.rs.gotmpl +++ b/ethfull/templates/src/lib.rs.gotmpl @@ -36,14 +36,14 @@ const {{ $contract.IdentifierUpper }}_TRACKED_CONTRACT: [u8; 20] = hex!("{{ $con fn map_{{ $contract.Identifier }}_events(blk: ð::Block, events: &mut contract::Events) { {{- range $event := $contract.EventModels }} {{- $rust := $event.Rust }} - events.{{ $contract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.append(&mut blk + events.{{ $contract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.append(&mut blk .receipts() .flat_map(|view| { view.receipt.logs.iter() .filter(|log| log.address == {{ $contract.IdentifierUpper }}_TRACKED_CONTRACT) .filter_map(|log| { if let Some(event) = abi::{{ $contract.Identifier }}_contract::events::{{$rust.ABIStructName}}::match_and_decode(log) { - return Some(contract::{{ toPascalCase $contract.Identifier }}{{$rust.ProtoMessageName}} { + return Some(contract::{{ $contract.IdentifierPascalCase }}{{$rust.ProtoMessageName}} { evt_tx_hash: Hex(&view.transaction.hash).to_string(), evt_index: log.block_index, evt_block_time: Some(blk.timestamp().to_owned()), @@ -65,7 +65,7 @@ fn map_{{ $contract.Identifier }}_events(blk: ð::Block, events: &mut contract fn map_{{ $contract.Identifier }}_calls(blk: ð::Block, calls: &mut contract::Calls) { {{- range $call := $contract.CallModels }} {{- $rust := $call.Rust }} - calls.{{ $contract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.append(&mut blk + calls.{{ $contract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.append(&mut blk .transactions() .flat_map(|tx| { tx.calls.iter() @@ -79,7 +79,7 @@ fn map_{{ $contract.Identifier }}_calls(blk: ð::Block, calls: &mut contract:: Err(_) => Default::default(), }; {{ end }} - Some(contract::{{ toPascalCase $contract.Identifier }}{{$rust.ProtoMessageName}} { + Some(contract::{{ $contract.IdentifierPascalCase }}{{$rust.ProtoMessageName}} { call_tx_hash: Hex(&tx.hash).to_string(), call_block_time: Some(blk.timestamp().to_owned()), call_block_number: blk.number, @@ -131,14 +131,14 @@ fn map_{{ $ddsContract.Identifier }}_events( {{- range $index, $event := $ddsContract.EventModels }} {{- $rust := $event.Rust }} - events.{{ $ddsContract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.append(&mut blk + events.{{ $ddsContract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.append(&mut blk .receipts() .flat_map(|view| { view.receipt.logs.iter() .filter(|log| is_declared_dds_address(&log.address, log.ordinal, dds_store)) .filter_map(|log| { if let Some(event) = abi::{{ $ddsContract.Identifier }}_contract::events::{{$rust.ABIStructName}}::match_and_decode(log) { - return Some(contract::{{ toPascalCase $ddsContract.Identifier }}{{$rust.ProtoMessageName}} { + return Some(contract::{{ $ddsContract.IdentifierPascalCase }}{{$rust.ProtoMessageName}} { evt_tx_hash: Hex(&view.transaction.hash).to_string(), evt_index: log.block_index, evt_block_time: Some(blk.timestamp().to_owned()), @@ -165,7 +165,7 @@ fn map_{{ $ddsContract.Identifier }}_calls( ) { {{- range $i, $call := $ddsContract.CallModels }} {{- $rust := $call.Rust }} - calls.{{ $ddsContract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.append(&mut blk + calls.{{ $ddsContract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.append(&mut blk .transactions() .flat_map(|tx| { tx.calls.iter() @@ -179,7 +179,7 @@ fn map_{{ $ddsContract.Identifier }}_calls( Err(_) => Default::default(), }; {{ end }} - Some(contract::{{ toPascalCase $ddsContract.Identifier }}{{$rust.ProtoMessageName}} { + Some(contract::{{ $ddsContract.IdentifierPascalCase }}{{$rust.ProtoMessageName}} { call_tx_hash: Hex(&tx.hash).to_string(), call_block_time: Some(blk.timestamp().to_owned()), call_block_number: blk.number, @@ -204,11 +204,11 @@ fn map_{{ $ddsContract.Identifier }}_calls( {{- if .IsOutputSQL }} {{- range $i, $contract := .Contracts }} {{- if $contract.TrackEvents }} -fn db_{{ toSnakeCase $contract.Identifier }}_out(events: &contract::Events, tables: &mut DatabaseChangeTables) { +fn db_{{ $contract.Identifier }}_out(events: &contract::Events, tables: &mut DatabaseChangeTables) { // Loop over all the abis events to create table changes {{- range $index, $event := $contract.EventModels }} {{- $rust := $event.Rust }} - events.{{ $contract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|evt| { + events.{{ $contract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|evt| { tables .create_row("{{ $contract.Identifier }}_{{ $rust.TableChangeEntityName }}", [("evt_tx_hash", evt.evt_tx_hash.to_string()),("evt_index", evt.evt_index.to_string())]) .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) @@ -227,7 +227,7 @@ fn db_{{ $contract.Identifier }}_calls_out(calls: &contract::Calls, tables: &mut // Loop over all the abis calls to create table changes {{- range $index, $call := $contract.CallModels }} {{- $rust := $call.Rust }} - calls.{{ $contract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|call| { + calls.{{ $contract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|call| { tables .create_row("{{ $contract.Identifier }}_{{ $rust.TableChangeEntityName }}", [("call_tx_hash", call.call_tx_hash.to_string()),("call_ordinal", call.call_ordinal.to_string())]) .set("call_block_time", call.call_block_time.as_ref().unwrap()) @@ -250,7 +250,7 @@ fn db_{{ $ddsContract.Identifier }}_out(events: &contract::Events, tables: &mut // Loop over all the abis events to create table changes {{- range $index, $event := $ddsContract.EventModels }} {{- $rust := $event.Rust }} - events.{{ $ddsContract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|evt| { + events.{{ $ddsContract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|evt| { tables .create_row("{{ $ddsContract.Identifier }}_{{ $rust.TableChangeEntityName }}", [("evt_tx_hash", evt.evt_tx_hash.to_string()),("evt_index", evt.evt_index.to_string())]) .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) @@ -270,7 +270,7 @@ fn db_{{ $ddsContract.Identifier }}_calls_out(calls: &contract::Calls, tables: & // Loop over all the abis calls to create table changes {{- range $index, $call := $ddsContract.CallModels }} {{- $rust := $call.Rust }} - calls.{{ $ddsContract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|call| { + calls.{{ $ddsContract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|call| { tables .create_row("{{ $ddsContract.Identifier }}_{{ $rust.TableChangeEntityName }}", [("call_tx_hash", call.call_tx_hash.to_string()),("call_ordinal", call.call_ordinal.to_string())]) .set("call_block_time", call.call_block_time.as_ref().unwrap()) @@ -296,7 +296,7 @@ fn graph_{{ $contract.Identifier }}_out(events: &contract::Events, tables: &mut // Loop over all the abis events to create table changes {{- range $index, $event := $contract.EventModels }} {{- $rust := $event.Rust }} - events.{{ $contract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|evt| { + events.{{ $contract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|evt| { tables .create_row("{{ $contract.Identifier }}_{{ $rust.TableChangeEntityName }}", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) .set("evt_tx_hash", &evt.evt_tx_hash) @@ -317,7 +317,7 @@ fn graph_{{ $contract.Identifier }}_calls_out(calls: &contract::Calls, tables: & // Loop over all the abis calls to create table changes {{- range $index, $call := $contract.CallModels }} {{- $rust := $call.Rust }} - calls.{{ $contract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|call| { + calls.{{ $contract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|call| { tables .create_row("{{ $contract.Identifier }}_{{ $rust.TableChangeEntityName }}", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) .set("call_tx_hash", &call.call_tx_hash) @@ -341,7 +341,7 @@ fn graph_{{ $ddsContract.Identifier }}_out(events: &contract::Events, tables: &m // Loop over all the abis events to create table changes {{- range $index, $event := $ddsContract.EventModels }} {{- $rust := $event.Rust }} - events.{{ $ddsContract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|evt| { + events.{{ $ddsContract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|evt| { tables .create_row("{{ $ddsContract.Identifier }}_{{ $rust.TableChangeEntityName }}", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) .set("evt_tx_hash", &evt.evt_tx_hash) @@ -363,7 +363,7 @@ fn graph_{{ $ddsContract.Identifier }}_calls_out(calls: &contract::Calls, tables // Loop over all the abis calls to create table changes {{- range $index, $call := $ddsContract.CallModels }} {{- $rust := $call.Rust }} - calls.{{ $ddsContract.Identifier }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|call| { + calls.{{ $ddsContract.IdentifierSnakeCase }}_{{ $rust.ProtoOutputModuleFieldName }}.iter().for_each(|call| { tables .create_row("{{ $ddsContract.Identifier }}_{{ $rust.TableChangeEntityName }}", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) .set("call_tx_hash", &call.call_tx_hash) diff --git a/ethfull/testdata/complex_abi.json b/ethfull/testdata/complex_abi.json index e69de29..2f8c749 100644 --- a/ethfull/testdata/complex_abi.json +++ b/ethfull/testdata/complex_abi.json @@ -0,0 +1,1249 @@ +{ + "name": "test", + "chainName": "mainnet", + "contracts": [ + { + "name": "ewqocontraadd123", + "trackEvents": true, + "trackCalls": true, + "rawAbi": [ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + } + ], + "name": "FeeAmount__Enabled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "oldOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "Owner123_Changed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "indexed": false, + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + }, + { + "indexed": false, + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "name": "PoolCreated", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenB", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + } + ], + "name": "createPool", + "outputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + } + ], + "name": "enable123Aeemount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint24", + "name": "", + "type": "uint24" + } + ], + "name": "feeAmountTICKSpacing", + "outputs": [ + { + "internalType": "int24", + "name": "", + "type": "int24" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint24", + "name": "", + "type": "uint24" + } + ], + "name": "getPool", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "parameters", + "outputs": [ + { + "internalType": "address", + "name": "factory", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "setOwner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "address": "0x1f98431c8ad98523631ae4a59f267346ea31f984", + "initialBlock": 213919, + "trackFactory": true, + "factoryCreationEvent": "783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118", + "factoryCreationEventFieldIdx": 4 + } + ], + "dynamic_contracts": [ + { + "name": "test", + "trackEvents": true, + "trackCalls": true, + "rawAbi": [ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "name": "Burn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount0", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount1", + "type": "uint128" + } + ], + "name": "Collect", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount0", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount1", + "type": "uint128" + } + ], + "name": "CollectProtocol", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "paid0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "paid1", + "type": "uint256" + } + ], + "name": "Flash", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "observationCardinalityNextOld", + "type": "uint16" + }, + { + "indexed": false, + "internalType": "uint16", + "name": "observationCardinalityNextNew", + "type": "uint16" + } + ], + "name": "IncreaseObservationCardinalityNext", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint160", + "name": "sqrtPriceX96", + "type": "uint160" + }, + { + "indexed": false, + "internalType": "int24", + "name": "tick", + "type": "int24" + } + ], + "name": "Initialize", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "feeProtocol0Old", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "feeProtocol1Old", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "feeProtocol0New", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "feeProtocol1New", + "type": "uint8" + } + ], + "name": "SetFeeProtocol", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": false, + "internalType": "int256", + "name": "amount0", + "type": "int256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "amount1", + "type": "int256" + }, + { + "indexed": false, + "internalType": "uint160", + "name": "sqrtPriceX96", + "type": "uint160" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "liquidity", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "int24", + "name": "tick", + "type": "int24" + } + ], + "name": "Swap", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "internalType": "uint128", + "name": "amount", + "type": "uint128" + } + ], + "name": "burn", + "outputs": [ + { + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "internalType": "uint128", + "name": "amount0Requested", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amount1Requested", + "type": "uint128" + } + ], + "name": "collect", + "outputs": [ + { + "internalType": "uint128", + "name": "amount0", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amount1", + "type": "uint128" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint128", + "name": "amount0Requested", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amount1Requested", + "type": "uint128" + } + ], + "name": "collectProtocol", + "outputs": [ + { + "internalType": "uint128", + "name": "amount0", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amount1", + "type": "uint128" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "factory", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "fee", + "outputs": [ + { + "internalType": "uint24", + "name": "", + "type": "uint24" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "feeGrowthGlobal0X128", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "feeGrowthGlobal1X128", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "flash", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "observationCardinalityNext", + "type": "uint16" + } + ], + "name": "increaseObservationCardinalityNext", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint160", + "name": "sqrtPriceX96", + "type": "uint160" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "liquidity", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxLiquidityPerTick", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "internalType": "uint128", + "name": "amount", + "type": "uint128" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "observations", + "outputs": [ + { + "internalType": "uint32", + "name": "blockTimestamp", + "type": "uint32" + }, + { + "internalType": "int56", + "name": "tickCumulative", + "type": "int56" + }, + { + "internalType": "uint160", + "name": "secondsPerLiquidityCumulativeX128", + "type": "uint160" + }, + { + "internalType": "bool", + "name": "initialized", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint32[]", + "name": "secondsAgos", + "type": "uint32[]" + } + ], + "name": "observe", + "outputs": [ + { + "internalType": "int56[]", + "name": "tickCumulatives", + "type": "int56[]" + }, + { + "internalType": "uint160[]", + "name": "secondsPerLiquidityCumulativeX128s", + "type": "uint160[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "positions", + "outputs": [ + { + "internalType": "uint128", + "name": "liquidity", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "feeGrowthInside0LastX128", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "feeGrowthInside1LastX128", + "type": "uint256" + }, + { + "internalType": "uint128", + "name": "tokensOwed0", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "tokensOwed1", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "protocolFees", + "outputs": [ + { + "internalType": "uint128", + "name": "token0", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "token1", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "feeProtocol0", + "type": "uint8" + }, + { + "internalType": "uint8", + "name": "feeProtocol1", + "type": "uint8" + } + ], + "name": "setFeeProtocol", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "slot0", + "outputs": [ + { + "internalType": "uint160", + "name": "sqrtPriceX96", + "type": "uint160" + }, + { + "internalType": "int24", + "name": "tick", + "type": "int24" + }, + { + "internalType": "uint16", + "name": "observationIndex", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "observationCardinality", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "observationCardinalityNext", + "type": "uint16" + }, + { + "internalType": "uint8", + "name": "feeProtocol", + "type": "uint8" + }, + { + "internalType": "bool", + "name": "unlocked", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + } + ], + "name": "snapshotCumulativesInside", + "outputs": [ + { + "internalType": "int56", + "name": "tickCumulativeInside", + "type": "int56" + }, + { + "internalType": "uint160", + "name": "secondsPerLiquidityInsideX128", + "type": "uint160" + }, + { + "internalType": "uint32", + "name": "secondsInside", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "bool", + "name": "zeroForOne", + "type": "bool" + }, + { + "internalType": "int256", + "name": "amountSpecified", + "type": "int256" + }, + { + "internalType": "uint160", + "name": "sqrtPriceLimitX96", + "type": "uint160" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "swap", + "outputs": [ + { + "internalType": "int256", + "name": "amount0", + "type": "int256" + }, + { + "internalType": "int256", + "name": "amount1", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int16", + "name": "", + "type": "int16" + } + ], + "name": "tickBitmap", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "tickSpacing", + "outputs": [ + { + "internalType": "int24", + "name": "", + "type": "int24" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int24", + "name": "", + "type": "int24" + } + ], + "name": "ticks", + "outputs": [ + { + "internalType": "uint128", + "name": "liquidityGross", + "type": "uint128" + }, + { + "internalType": "int128", + "name": "liquidityNet", + "type": "int128" + }, + { + "internalType": "uint256", + "name": "feeGrowthOutside0X128", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "feeGrowthOutside1X128", + "type": "uint256" + }, + { + "internalType": "int56", + "name": "tickCumulativeOutside", + "type": "int56" + }, + { + "internalType": "uint160", + "name": "secondsPerLiquidityOutsideX128", + "type": "uint160" + }, + { + "internalType": "uint32", + "name": "secondsOutside", + "type": "uint32" + }, + { + "internalType": "bool", + "name": "initialized", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "token0", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "token1", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } + ], + "parentContractName": "ewqocontraadd123" + } + ], + "subgraph_output_flavor": "entity" + } \ No newline at end of file diff --git a/ethfull/testoutput/complex_abi/.gitignore b/ethfull/testoutput/complex_abi/.gitignore new file mode 100644 index 0000000..289d3c4 --- /dev/null +++ b/ethfull/testoutput/complex_abi/.gitignore @@ -0,0 +1,2 @@ +entities/dev-environment/data/ +node_modules/ diff --git a/ethfull/testoutput/complex_abi/Cargo.toml b/ethfull/testoutput/complex_abi/Cargo.toml new file mode 100644 index 0000000..e63a30e --- /dev/null +++ b/ethfull/testoutput/complex_abi/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "test" +version = "0.0.1" +edition = "2021" + +[lib] +name = "substreams" +crate-type = ["cdylib"] + +[dependencies] +ethabi = "17" +hex-literal = "0.3.4" +num-bigint = "0.4" +num-traits = "0.2.15" +prost = "0.11" +prost-types = "0.11" +substreams = "0.5" +substreams-ethereum = "0.9" +substreams-database-change = "1" +substreams-entity-change = "1" + +# Required so that ethabi > ethereum-types build correctly under wasm32-unknown-unknown +[target.wasm32-unknown-unknown.dependencies] +getrandom = { version = "0.2", features = ["custom"] } + +[build-dependencies] +anyhow = "1" +substreams-ethereum = "0.9" +regex = "1.8" + +[profile.release] +lto = true +opt-level = 's' +strip = "debuginfo" diff --git a/ethfull/testoutput/complex_abi/Makefile b/ethfull/testoutput/complex_abi/Makefile new file mode 100644 index 0000000..9c748c9 --- /dev/null +++ b/ethfull/testoutput/complex_abi/Makefile @@ -0,0 +1,29 @@ +CARGO_VERSION := $(shell cargo version 2>/dev/null) + +.PHONY: protogen +protogen: + substreams protogen ./substreams.yaml --exclude-paths="sf/substreams,google" + +.PHONY: build +build: protogen +ifdef CARGO_VERSION + cargo build --target wasm32-unknown-unknown --release +else + @echo "Building substreams target using Docker. To speed up this step, install a Rust development environment." + docker run --rm -ti --init -v ${PWD}:/usr/src --workdir /usr/src/ rust:bullseye cargo build --target wasm32-unknown-unknown --release +endif + +.PHONY: run +run: build + substreams run substreams.yaml $(if $(MODULE),$(MODULE),map_events) $(if $(START_BLOCK),-s $(START_BLOCK)) $(if $(STOP_BLOCK),-t $(STOP_BLOCK)) + +.PHONY: gui +gui: build + substreams gui substreams.yaml $(if $(MODULE),$(MODULE),map_events) $(if $(START_BLOCK),-s $(START_BLOCK)) $(if $(STOP_BLOCK),-t $(STOP_BLOCK)) + +.PHONY: all +all: protogen build package + +.PHONY: package +package: build + substreams pack substreams.yaml diff --git a/ethfull/testoutput/complex_abi/abi/ewqocontraadd123_contract.abi.json b/ethfull/testoutput/complex_abi/abi/ewqocontraadd123_contract.abi.json new file mode 100644 index 0000000..be4020f --- /dev/null +++ b/ethfull/testoutput/complex_abi/abi/ewqocontraadd123_contract.abi.json @@ -0,0 +1,236 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + } + ], + "name": "FeeAmount__Enabled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "oldOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "Owner123_Changed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "indexed": false, + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + }, + { + "indexed": false, + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "name": "PoolCreated", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenB", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + } + ], + "name": "createPool", + "outputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + } + ], + "name": "enable123Aeemount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint24", + "name": "", + "type": "uint24" + } + ], + "name": "feeAmountTICKSpacing", + "outputs": [ + { + "internalType": "int24", + "name": "", + "type": "int24" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint24", + "name": "", + "type": "uint24" + } + ], + "name": "getPool", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "parameters", + "outputs": [ + { + "internalType": "address", + "name": "factory", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "setOwner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ] \ No newline at end of file diff --git a/ethfull/testoutput/complex_abi/abi/test_contract.abi.json b/ethfull/testoutput/complex_abi/abi/test_contract.abi.json new file mode 100644 index 0000000..d5e265d --- /dev/null +++ b/ethfull/testoutput/complex_abi/abi/test_contract.abi.json @@ -0,0 +1,988 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "name": "Burn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount0", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount1", + "type": "uint128" + } + ], + "name": "Collect", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount0", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount1", + "type": "uint128" + } + ], + "name": "CollectProtocol", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "paid0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "paid1", + "type": "uint256" + } + ], + "name": "Flash", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "observationCardinalityNextOld", + "type": "uint16" + }, + { + "indexed": false, + "internalType": "uint16", + "name": "observationCardinalityNextNew", + "type": "uint16" + } + ], + "name": "IncreaseObservationCardinalityNext", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint160", + "name": "sqrtPriceX96", + "type": "uint160" + }, + { + "indexed": false, + "internalType": "int24", + "name": "tick", + "type": "int24" + } + ], + "name": "Initialize", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "amount", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "feeProtocol0Old", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "feeProtocol1Old", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "feeProtocol0New", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "feeProtocol1New", + "type": "uint8" + } + ], + "name": "SetFeeProtocol", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": false, + "internalType": "int256", + "name": "amount0", + "type": "int256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "amount1", + "type": "int256" + }, + { + "indexed": false, + "internalType": "uint160", + "name": "sqrtPriceX96", + "type": "uint160" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "liquidity", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "int24", + "name": "tick", + "type": "int24" + } + ], + "name": "Swap", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "internalType": "uint128", + "name": "amount", + "type": "uint128" + } + ], + "name": "burn", + "outputs": [ + { + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "internalType": "uint128", + "name": "amount0Requested", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amount1Requested", + "type": "uint128" + } + ], + "name": "collect", + "outputs": [ + { + "internalType": "uint128", + "name": "amount0", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amount1", + "type": "uint128" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint128", + "name": "amount0Requested", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amount1Requested", + "type": "uint128" + } + ], + "name": "collectProtocol", + "outputs": [ + { + "internalType": "uint128", + "name": "amount0", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amount1", + "type": "uint128" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "factory", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "fee", + "outputs": [ + { + "internalType": "uint24", + "name": "", + "type": "uint24" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "feeGrowthGlobal0X128", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "feeGrowthGlobal1X128", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "flash", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "observationCardinalityNext", + "type": "uint16" + } + ], + "name": "increaseObservationCardinalityNext", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint160", + "name": "sqrtPriceX96", + "type": "uint160" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "liquidity", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxLiquidityPerTick", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + }, + { + "internalType": "uint128", + "name": "amount", + "type": "uint128" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "observations", + "outputs": [ + { + "internalType": "uint32", + "name": "blockTimestamp", + "type": "uint32" + }, + { + "internalType": "int56", + "name": "tickCumulative", + "type": "int56" + }, + { + "internalType": "uint160", + "name": "secondsPerLiquidityCumulativeX128", + "type": "uint160" + }, + { + "internalType": "bool", + "name": "initialized", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint32[]", + "name": "secondsAgos", + "type": "uint32[]" + } + ], + "name": "observe", + "outputs": [ + { + "internalType": "int56[]", + "name": "tickCumulatives", + "type": "int56[]" + }, + { + "internalType": "uint160[]", + "name": "secondsPerLiquidityCumulativeX128s", + "type": "uint160[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "positions", + "outputs": [ + { + "internalType": "uint128", + "name": "liquidity", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "feeGrowthInside0LastX128", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "feeGrowthInside1LastX128", + "type": "uint256" + }, + { + "internalType": "uint128", + "name": "tokensOwed0", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "tokensOwed1", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "protocolFees", + "outputs": [ + { + "internalType": "uint128", + "name": "token0", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "token1", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "feeProtocol0", + "type": "uint8" + }, + { + "internalType": "uint8", + "name": "feeProtocol1", + "type": "uint8" + } + ], + "name": "setFeeProtocol", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "slot0", + "outputs": [ + { + "internalType": "uint160", + "name": "sqrtPriceX96", + "type": "uint160" + }, + { + "internalType": "int24", + "name": "tick", + "type": "int24" + }, + { + "internalType": "uint16", + "name": "observationIndex", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "observationCardinality", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "observationCardinalityNext", + "type": "uint16" + }, + { + "internalType": "uint8", + "name": "feeProtocol", + "type": "uint8" + }, + { + "internalType": "bool", + "name": "unlocked", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int24", + "name": "tickLower", + "type": "int24" + }, + { + "internalType": "int24", + "name": "tickUpper", + "type": "int24" + } + ], + "name": "snapshotCumulativesInside", + "outputs": [ + { + "internalType": "int56", + "name": "tickCumulativeInside", + "type": "int56" + }, + { + "internalType": "uint160", + "name": "secondsPerLiquidityInsideX128", + "type": "uint160" + }, + { + "internalType": "uint32", + "name": "secondsInside", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "bool", + "name": "zeroForOne", + "type": "bool" + }, + { + "internalType": "int256", + "name": "amountSpecified", + "type": "int256" + }, + { + "internalType": "uint160", + "name": "sqrtPriceLimitX96", + "type": "uint160" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "swap", + "outputs": [ + { + "internalType": "int256", + "name": "amount0", + "type": "int256" + }, + { + "internalType": "int256", + "name": "amount1", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int16", + "name": "", + "type": "int16" + } + ], + "name": "tickBitmap", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "tickSpacing", + "outputs": [ + { + "internalType": "int24", + "name": "", + "type": "int24" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int24", + "name": "", + "type": "int24" + } + ], + "name": "ticks", + "outputs": [ + { + "internalType": "uint128", + "name": "liquidityGross", + "type": "uint128" + }, + { + "internalType": "int128", + "name": "liquidityNet", + "type": "int128" + }, + { + "internalType": "uint256", + "name": "feeGrowthOutside0X128", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "feeGrowthOutside1X128", + "type": "uint256" + }, + { + "internalType": "int56", + "name": "tickCumulativeOutside", + "type": "int56" + }, + { + "internalType": "uint160", + "name": "secondsPerLiquidityOutsideX128", + "type": "uint160" + }, + { + "internalType": "uint32", + "name": "secondsOutside", + "type": "uint32" + }, + { + "internalType": "bool", + "name": "initialized", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "token0", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "token1", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } + ] \ No newline at end of file diff --git a/ethfull/testoutput/complex_abi/build.rs b/ethfull/testoutput/complex_abi/build.rs new file mode 100644 index 0000000..747a496 --- /dev/null +++ b/ethfull/testoutput/complex_abi/build.rs @@ -0,0 +1,42 @@ +use anyhow::{Ok, Result}; +use regex::Regex; +use substreams_ethereum::Abigen; +use std::fs; + +fn main() -> Result<(), anyhow::Error> { + let file_names = [ + "abi/ewqocontraadd123_contract.abi.json", + "abi/test_contract.abi.json", + ]; + let file_output_names = [ + "src/abi/ewqocontraadd123_contract.rs", + "src/abi/test_contract.rs", + ]; + + let mut i = 0; + for f in file_names { + let contents = fs::read_to_string(f) + .expect("Should have been able to read the file"); + + // sanitize fields and attributes starting with an underscore + let regex = Regex::new(r#"("\w+"\s?:\s?")_(\w+")"#).unwrap(); + let sanitized_abi_file = regex.replace_all(contents.as_str(), "${1}u_${2}"); + + // sanitize fields and attributes with multiple consecutive underscores + let re = Regex::new(r"_+").unwrap(); + + let re_sanitized_abi_file = re.replace_all(&sanitized_abi_file, |caps: ®ex::Captures| { + let count = caps[0].len(); + let replacement = format!("{}_", "_u".repeat(count - 1)); + replacement + }); + + Abigen::from_bytes("Contract", re_sanitized_abi_file.as_bytes())? + .generate()? + .write_to_file(file_output_names[i])?; + + i = i+1; + } + + Ok(()) +} diff --git a/ethfull/testoutput/complex_abi/proto/contract.proto b/ethfull/testoutput/complex_abi/proto/contract.proto new file mode 100644 index 0000000..4cd0c75 --- /dev/null +++ b/ethfull/testoutput/complex_abi/proto/contract.proto @@ -0,0 +1,329 @@ +syntax = "proto3"; + +import "google/protobuf/timestamp.proto"; + +package contract.v1; +message Events { + repeated Ewqocontraadd123_FeeAmountUEnabled ewqocontraadd123_fee_amount_u_enableds = 1; + repeated Ewqocontraadd123_Owner123Changed ewqocontraadd123_owner123_changeds = 2; + repeated Ewqocontraadd123_PoolCreated ewqocontraadd123_pool_createds = 3; + repeated Test_Burn test_burns = 4; + repeated Test_Collect test_collects = 5; + repeated Test_CollectProtocol test_collect_protocols = 6; + repeated Test_Flash test_flashes = 7; + repeated Test_IncreaseObservationCardinalityNext test_increase_observation_cardinality_nexts = 8; + repeated Test_Initialize test_initializes = 9; + repeated Test_Mint test_mints = 10; + repeated Test_SetFeeProtocol test_set_fee_protocols = 11; + repeated Test_Swap test_swaps = 12; +} +message Calls { + repeated Ewqocontraadd123_CreatePoolCall ewqocontraadd123_call_create_pools = 1; + repeated Ewqocontraadd123_Enable123AeemountCall ewqocontraadd123_call_enable123_aeemounts = 2; + repeated Ewqocontraadd123_SetOwnerCall ewqocontraadd123_call_set_owners = 3; + repeated Test_BurnCall test_call_burns = 4; + repeated Test_CollectCall test_call_collects = 5; + repeated Test_CollectProtocolCall test_call_collect_protocols = 6; + repeated Test_FlashCall test_call_flashes = 7; + repeated Test_IncreaseObservationCardinalityNextCall test_call_increase_observation_cardinality_nexts = 8; + repeated Test_InitializeCall test_call_initializes = 9; + repeated Test_MintCall test_call_mints = 10; + repeated Test_SetFeeProtocolCall test_call_set_fee_protocols = 11; + repeated Test_SwapCall test_call_swaps = 12; +} +message EventsCalls { + Events events = 1; + Calls calls = 2; +} +message Ewqocontraadd123_FeeAmountUEnabled { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + uint64 fee = 5; + int64 tick_spacing = 6; +} +message Ewqocontraadd123_Owner123Changed { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + bytes old_owner = 5; + bytes new_owner = 6; +} +message Ewqocontraadd123_PoolCreated { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + bytes token0 = 5; + bytes token1 = 6; + uint64 fee = 7; + int64 tick_spacing = 8; + bytes pool = 9; +} + +message Ewqocontraadd123_CreatePoolCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + bytes token_a = 6; + bytes token_b = 7; + uint64 fee = 8; + bytes output_pool = 9; +} +message Ewqocontraadd123_Enable123AeemountCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + uint64 fee = 6; + int64 tick_spacing = 7; +} +message Ewqocontraadd123_SetOwnerCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + bytes u_owner = 6; +} + +message Test_Burn { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + string evt_address = 5; + bytes owner = 6; + int64 tick_lower = 7; + int64 tick_upper = 8; + string amount = 9; + string amount0 = 10; + string amount1 = 11; +} + +message Test_Collect { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + string evt_address = 5; + bytes owner = 6; + bytes recipient = 7; + int64 tick_lower = 8; + int64 tick_upper = 9; + string amount0 = 10; + string amount1 = 11; +} + +message Test_CollectProtocol { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + string evt_address = 5; + bytes sender = 6; + bytes recipient = 7; + string amount0 = 8; + string amount1 = 9; +} + +message Test_Flash { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + string evt_address = 5; + bytes sender = 6; + bytes recipient = 7; + string amount0 = 8; + string amount1 = 9; + string paid0 = 10; + string paid1 = 11; +} + +message Test_IncreaseObservationCardinalityNext { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + string evt_address = 5; + uint64 observation_cardinality_next_old = 6; + uint64 observation_cardinality_next_new = 7; +} + +message Test_Initialize { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + string evt_address = 5; + string sqrt_price_x96 = 6; + int64 tick = 7; +} + +message Test_Mint { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + string evt_address = 5; + bytes sender = 6; + bytes owner = 7; + int64 tick_lower = 8; + int64 tick_upper = 9; + string amount = 10; + string amount0 = 11; + string amount1 = 12; +} + +message Test_SetFeeProtocol { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + string evt_address = 5; + uint64 fee_protocol0_old = 6; + uint64 fee_protocol1_old = 7; + uint64 fee_protocol0_new = 8; + uint64 fee_protocol1_new = 9; +} + +message Test_Swap { + string evt_tx_hash = 1; + uint32 evt_index = 2; + google.protobuf.Timestamp evt_block_time = 3; + uint64 evt_block_number = 4; + string evt_address = 5; + bytes sender = 6; + bytes recipient = 7; + string amount0 = 8; + string amount1 = 9; + string sqrt_price_x96 = 10; + string liquidity = 11; + int64 tick = 12; +} + +message Test_BurnCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + string call_address = 6; + int64 tick_lower = 7; + int64 tick_upper = 8; + string amount = 9; + string output_amount0 = 10; + string output_amount1 = 11; +} + +message Test_CollectCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + string call_address = 6; + bytes recipient = 7; + int64 tick_lower = 8; + int64 tick_upper = 9; + string amount0_requested = 10; + string amount1_requested = 11; + string output_amount0 = 12; + string output_amount1 = 13; +} + +message Test_CollectProtocolCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + string call_address = 6; + bytes recipient = 7; + string amount0_requested = 8; + string amount1_requested = 9; + string output_amount0 = 10; + string output_amount1 = 11; +} + +message Test_FlashCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + string call_address = 6; + bytes recipient = 7; + string amount0 = 8; + string amount1 = 9; + bytes data = 10; +} + +message Test_IncreaseObservationCardinalityNextCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + string call_address = 6; + uint64 observation_cardinality_next = 7; +} + +message Test_InitializeCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + string call_address = 6; + string sqrt_price_x96 = 7; +} + +message Test_MintCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + string call_address = 6; + bytes recipient = 7; + int64 tick_lower = 8; + int64 tick_upper = 9; + string amount = 10; + bytes data = 11; + string output_amount0 = 12; + string output_amount1 = 13; +} + +message Test_SetFeeProtocolCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + string call_address = 6; + uint64 fee_protocol0 = 7; + uint64 fee_protocol1 = 8; +} + +message Test_SwapCall { + string call_tx_hash = 1; + google.protobuf.Timestamp call_block_time = 2; + uint64 call_block_number = 3; + uint64 call_ordinal = 4; + bool call_success = 5; + string call_address = 6; + bytes recipient = 7; + bool zero_for_one = 8; + string amount_specified = 9; + string sqrt_price_limit_x96 = 10; + bytes data = 11; + string output_amount0 = 12; + string output_amount1 = 13; +} diff --git a/ethfull/testoutput/complex_abi/rust-toolchain.toml b/ethfull/testoutput/complex_abi/rust-toolchain.toml new file mode 100644 index 0000000..5ecd48c --- /dev/null +++ b/ethfull/testoutput/complex_abi/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +components = [ "rustfmt" ] +targets = [ "wasm32-unknown-unknown" ] diff --git a/ethfull/testoutput/complex_abi/src/abi/mod.rs b/ethfull/testoutput/complex_abi/src/abi/mod.rs new file mode 100644 index 0000000..daae1b2 --- /dev/null +++ b/ethfull/testoutput/complex_abi/src/abi/mod.rs @@ -0,0 +1,3 @@ + +pub mod ewqocontraadd123_contract; +pub mod test_contract; diff --git a/ethfull/testoutput/complex_abi/src/lib.rs b/ethfull/testoutput/complex_abi/src/lib.rs new file mode 100644 index 0000000..d5ca4a8 --- /dev/null +++ b/ethfull/testoutput/complex_abi/src/lib.rs @@ -0,0 +1,1074 @@ +mod abi; +mod pb; +use hex_literal::hex; +use pb::contract::v1 as contract; +use substreams::prelude::*; +use substreams::store; +use substreams::Hex; +use substreams_entity_change::pb::entity::EntityChanges; +use substreams_entity_change::tables::Tables as EntityChangesTables; +use substreams_ethereum::pb::eth::v2 as eth; +use substreams_ethereum::Event; + +#[allow(unused_imports)] +use num_traits::cast::ToPrimitive; +use std::str::FromStr; +use substreams::scalar::BigDecimal; + +substreams_ethereum::init!(); + +const EWQOCONTRAADD123_TRACKED_CONTRACT: [u8; 20] = hex!("1f98431c8ad98523631ae4a59f267346ea31f984"); + +fn map_ewqocontraadd123_events(blk: ð::Block, events: &mut contract::Events) { + events.ewqocontraadd123_fee_amount_u_enableds.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| log.address == EWQOCONTRAADD123_TRACKED_CONTRACT) + .filter_map(|log| { + if let Some(event) = abi::ewqocontraadd123_contract::events::FeeAmountUEnabled::match_and_decode(log) { + return Some(contract::Ewqocontraadd123FeeAmountUEnabled { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + fee: event.fee.to_u64(), + tick_spacing: Into::::into(event.tick_spacing).to_i64().unwrap(), + }); + } + + None + }) + }) + .collect()); + events.ewqocontraadd123_owner123_changeds.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| log.address == EWQOCONTRAADD123_TRACKED_CONTRACT) + .filter_map(|log| { + if let Some(event) = abi::ewqocontraadd123_contract::events::Owner123Changed::match_and_decode(log) { + return Some(contract::Ewqocontraadd123Owner123Changed { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + new_owner: event.new_owner, + old_owner: event.old_owner, + }); + } + + None + }) + }) + .collect()); + events.ewqocontraadd123_pool_createds.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| log.address == EWQOCONTRAADD123_TRACKED_CONTRACT) + .filter_map(|log| { + if let Some(event) = abi::ewqocontraadd123_contract::events::PoolCreated::match_and_decode(log) { + return Some(contract::Ewqocontraadd123PoolCreated { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + fee: event.fee.to_u64(), + pool: event.pool, + tick_spacing: Into::::into(event.tick_spacing).to_i64().unwrap(), + token0: event.token0, + token1: event.token1, + }); + } + + None + }) + }) + .collect()); +} +fn map_ewqocontraadd123_calls(blk: ð::Block, calls: &mut contract::Calls) { + calls.ewqocontraadd123_call_create_pools.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| call.address == EWQOCONTRAADD123_TRACKED_CONTRACT && abi::ewqocontraadd123_contract::functions::CreatePool::match_call(call)) + .filter_map(|call| { + match abi::ewqocontraadd123_contract::functions::CreatePool::decode(call) { + Ok(decoded_call) => { + let output_pool = match abi::ewqocontraadd123_contract::functions::CreatePool::output(&call.return_data) { + Ok(output_pool) => {output_pool} + Err(_) => Default::default(), + }; + + Some(contract::Ewqocontraadd123CreatePoolCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + fee: decoded_call.fee.to_u64(), + output_pool: output_pool, + token_a: decoded_call.token_a, + token_b: decoded_call.token_b, + }) + }, + Err(_) => None, + } + }) + }) + .collect()); + calls.ewqocontraadd123_call_enable123_aeemounts.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| call.address == EWQOCONTRAADD123_TRACKED_CONTRACT && abi::ewqocontraadd123_contract::functions::Enable123Aeemount::match_call(call)) + .filter_map(|call| { + match abi::ewqocontraadd123_contract::functions::Enable123Aeemount::decode(call) { + Ok(decoded_call) => { + Some(contract::Ewqocontraadd123Enable123AeemountCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + fee: decoded_call.fee.to_u64(), + tick_spacing: Into::::into(decoded_call.tick_spacing).to_i64().unwrap(), + }) + }, + Err(_) => None, + } + }) + }) + .collect()); + calls.ewqocontraadd123_call_set_owners.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| call.address == EWQOCONTRAADD123_TRACKED_CONTRACT && abi::ewqocontraadd123_contract::functions::SetOwner::match_call(call)) + .filter_map(|call| { + match abi::ewqocontraadd123_contract::functions::SetOwner::decode(call) { + Ok(decoded_call) => { + Some(contract::Ewqocontraadd123SetOwnerCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + u_owner: decoded_call.u_owner, + }) + }, + Err(_) => None, + } + }) + }) + .collect()); +} + +#[substreams::handlers::map] +fn zipped_events_calls( + events: contract::Events, + calls: contract::Calls, +) -> Result { + Ok(contract::EventsCalls { + events: Some(events), + calls: Some(calls), + }) +} +fn is_declared_dds_address(addr: &Vec, ordinal: u64, dds_store: &store::StoreGetInt64) -> bool { + // substreams::log::info!("Checking if address {} is declared dds address", Hex(addr).to_string()); + if dds_store.get_at(ordinal, Hex(addr).to_string()).is_some() { + return true; + } + return false; +} +fn map_test_events( + blk: ð::Block, + dds_store: &store::StoreGetInt64, + events: &mut contract::Events, +) { + + events.test_burns.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| is_declared_dds_address(&log.address, log.ordinal, dds_store)) + .filter_map(|log| { + if let Some(event) = abi::test_contract::events::Burn::match_and_decode(log) { + return Some(contract::TestBurn { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + evt_address: Hex(&log.address).to_string(), + amount: event.amount.to_string(), + amount0: event.amount0.to_string(), + amount1: event.amount1.to_string(), + owner: event.owner, + tick_lower: Into::::into(event.tick_lower).to_i64().unwrap(), + tick_upper: Into::::into(event.tick_upper).to_i64().unwrap(), + }); + } + + None + }) + }) + .collect()); + + events.test_collects.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| is_declared_dds_address(&log.address, log.ordinal, dds_store)) + .filter_map(|log| { + if let Some(event) = abi::test_contract::events::Collect::match_and_decode(log) { + return Some(contract::TestCollect { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + evt_address: Hex(&log.address).to_string(), + amount0: event.amount0.to_string(), + amount1: event.amount1.to_string(), + owner: event.owner, + recipient: event.recipient, + tick_lower: Into::::into(event.tick_lower).to_i64().unwrap(), + tick_upper: Into::::into(event.tick_upper).to_i64().unwrap(), + }); + } + + None + }) + }) + .collect()); + + events.test_collect_protocols.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| is_declared_dds_address(&log.address, log.ordinal, dds_store)) + .filter_map(|log| { + if let Some(event) = abi::test_contract::events::CollectProtocol::match_and_decode(log) { + return Some(contract::TestCollectProtocol { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + evt_address: Hex(&log.address).to_string(), + amount0: event.amount0.to_string(), + amount1: event.amount1.to_string(), + recipient: event.recipient, + sender: event.sender, + }); + } + + None + }) + }) + .collect()); + + events.test_flashes.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| is_declared_dds_address(&log.address, log.ordinal, dds_store)) + .filter_map(|log| { + if let Some(event) = abi::test_contract::events::Flash::match_and_decode(log) { + return Some(contract::TestFlash { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + evt_address: Hex(&log.address).to_string(), + amount0: event.amount0.to_string(), + amount1: event.amount1.to_string(), + paid0: event.paid0.to_string(), + paid1: event.paid1.to_string(), + recipient: event.recipient, + sender: event.sender, + }); + } + + None + }) + }) + .collect()); + + events.test_increase_observation_cardinality_nexts.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| is_declared_dds_address(&log.address, log.ordinal, dds_store)) + .filter_map(|log| { + if let Some(event) = abi::test_contract::events::IncreaseObservationCardinalityNext::match_and_decode(log) { + return Some(contract::TestIncreaseObservationCardinalityNext { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + evt_address: Hex(&log.address).to_string(), + observation_cardinality_next_new: event.observation_cardinality_next_new.to_u64(), + observation_cardinality_next_old: event.observation_cardinality_next_old.to_u64(), + }); + } + + None + }) + }) + .collect()); + + events.test_initializes.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| is_declared_dds_address(&log.address, log.ordinal, dds_store)) + .filter_map(|log| { + if let Some(event) = abi::test_contract::events::Initialize::match_and_decode(log) { + return Some(contract::TestInitialize { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + evt_address: Hex(&log.address).to_string(), + sqrt_price_x96: event.sqrt_price_x96.to_string(), + tick: Into::::into(event.tick).to_i64().unwrap(), + }); + } + + None + }) + }) + .collect()); + + events.test_mints.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| is_declared_dds_address(&log.address, log.ordinal, dds_store)) + .filter_map(|log| { + if let Some(event) = abi::test_contract::events::Mint::match_and_decode(log) { + return Some(contract::TestMint { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + evt_address: Hex(&log.address).to_string(), + amount: event.amount.to_string(), + amount0: event.amount0.to_string(), + amount1: event.amount1.to_string(), + owner: event.owner, + sender: event.sender, + tick_lower: Into::::into(event.tick_lower).to_i64().unwrap(), + tick_upper: Into::::into(event.tick_upper).to_i64().unwrap(), + }); + } + + None + }) + }) + .collect()); + + events.test_set_fee_protocols.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| is_declared_dds_address(&log.address, log.ordinal, dds_store)) + .filter_map(|log| { + if let Some(event) = abi::test_contract::events::SetFeeProtocol::match_and_decode(log) { + return Some(contract::TestSetFeeProtocol { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + evt_address: Hex(&log.address).to_string(), + fee_protocol0_new: event.fee_protocol0_new.to_u64(), + fee_protocol0_old: event.fee_protocol0_old.to_u64(), + fee_protocol1_new: event.fee_protocol1_new.to_u64(), + fee_protocol1_old: event.fee_protocol1_old.to_u64(), + }); + } + + None + }) + }) + .collect()); + + events.test_swaps.append(&mut blk + .receipts() + .flat_map(|view| { + view.receipt.logs.iter() + .filter(|log| is_declared_dds_address(&log.address, log.ordinal, dds_store)) + .filter_map(|log| { + if let Some(event) = abi::test_contract::events::Swap::match_and_decode(log) { + return Some(contract::TestSwap { + evt_tx_hash: Hex(&view.transaction.hash).to_string(), + evt_index: log.block_index, + evt_block_time: Some(blk.timestamp().to_owned()), + evt_block_number: blk.number, + evt_address: Hex(&log.address).to_string(), + amount0: event.amount0.to_string(), + amount1: event.amount1.to_string(), + liquidity: event.liquidity.to_string(), + recipient: event.recipient, + sender: event.sender, + sqrt_price_x96: event.sqrt_price_x96.to_string(), + tick: Into::::into(event.tick).to_i64().unwrap(), + }); + } + + None + }) + }) + .collect()); +} +fn map_test_calls( + blk: ð::Block, + dds_store: &store::StoreGetInt64, + calls: &mut contract::Calls, +) { + calls.test_call_burns.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| is_declared_dds_address(&call.address, call.begin_ordinal, dds_store) && abi::test_contract::functions::Burn::match_call(call)) + .filter_map(|call| { + match abi::test_contract::functions::Burn::decode(call) { + Ok(decoded_call) => { + let (output_amount0, output_amount1) = match abi::test_contract::functions::Burn::output(&call.return_data) { + Ok((output_amount0, output_amount1)) => {(output_amount0, output_amount1)} + Err(_) => Default::default(), + }; + + Some(contract::TestBurnCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + call_address: Hex(&call.address).to_string(), + amount: decoded_call.amount.to_string(), + output_amount0: output_amount0.to_string(), + output_amount1: output_amount1.to_string(), + tick_lower: Into::::into(decoded_call.tick_lower).to_i64().unwrap(), + tick_upper: Into::::into(decoded_call.tick_upper).to_i64().unwrap(), + }) + }, + Err(_) => None, + } + }) + }) + .collect()); + calls.test_call_collects.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| is_declared_dds_address(&call.address, call.begin_ordinal, dds_store) && abi::test_contract::functions::Collect::match_call(call)) + .filter_map(|call| { + match abi::test_contract::functions::Collect::decode(call) { + Ok(decoded_call) => { + let (output_amount0, output_amount1) = match abi::test_contract::functions::Collect::output(&call.return_data) { + Ok((output_amount0, output_amount1)) => {(output_amount0, output_amount1)} + Err(_) => Default::default(), + }; + + Some(contract::TestCollectCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + call_address: Hex(&call.address).to_string(), + amount0_requested: decoded_call.amount0_requested.to_string(), + amount1_requested: decoded_call.amount1_requested.to_string(), + output_amount0: output_amount0.to_string(), + output_amount1: output_amount1.to_string(), + recipient: decoded_call.recipient, + tick_lower: Into::::into(decoded_call.tick_lower).to_i64().unwrap(), + tick_upper: Into::::into(decoded_call.tick_upper).to_i64().unwrap(), + }) + }, + Err(_) => None, + } + }) + }) + .collect()); + calls.test_call_collect_protocols.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| is_declared_dds_address(&call.address, call.begin_ordinal, dds_store) && abi::test_contract::functions::CollectProtocol::match_call(call)) + .filter_map(|call| { + match abi::test_contract::functions::CollectProtocol::decode(call) { + Ok(decoded_call) => { + let (output_amount0, output_amount1) = match abi::test_contract::functions::CollectProtocol::output(&call.return_data) { + Ok((output_amount0, output_amount1)) => {(output_amount0, output_amount1)} + Err(_) => Default::default(), + }; + + Some(contract::TestCollectProtocolCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + call_address: Hex(&call.address).to_string(), + amount0_requested: decoded_call.amount0_requested.to_string(), + amount1_requested: decoded_call.amount1_requested.to_string(), + output_amount0: output_amount0.to_string(), + output_amount1: output_amount1.to_string(), + recipient: decoded_call.recipient, + }) + }, + Err(_) => None, + } + }) + }) + .collect()); + calls.test_call_flashes.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| is_declared_dds_address(&call.address, call.begin_ordinal, dds_store) && abi::test_contract::functions::Flash::match_call(call)) + .filter_map(|call| { + match abi::test_contract::functions::Flash::decode(call) { + Ok(decoded_call) => { + Some(contract::TestFlashCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + call_address: Hex(&call.address).to_string(), + amount0: decoded_call.amount0.to_string(), + amount1: decoded_call.amount1.to_string(), + data: decoded_call.data, + recipient: decoded_call.recipient, + }) + }, + Err(_) => None, + } + }) + }) + .collect()); + calls.test_call_increase_observation_cardinality_nexts.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| is_declared_dds_address(&call.address, call.begin_ordinal, dds_store) && abi::test_contract::functions::IncreaseObservationCardinalityNext::match_call(call)) + .filter_map(|call| { + match abi::test_contract::functions::IncreaseObservationCardinalityNext::decode(call) { + Ok(decoded_call) => { + Some(contract::TestIncreaseObservationCardinalityNextCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + call_address: Hex(&call.address).to_string(), + observation_cardinality_next: decoded_call.observation_cardinality_next.to_u64(), + }) + }, + Err(_) => None, + } + }) + }) + .collect()); + calls.test_call_initializes.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| is_declared_dds_address(&call.address, call.begin_ordinal, dds_store) && abi::test_contract::functions::Initialize::match_call(call)) + .filter_map(|call| { + match abi::test_contract::functions::Initialize::decode(call) { + Ok(decoded_call) => { + Some(contract::TestInitializeCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + call_address: Hex(&call.address).to_string(), + sqrt_price_x96: decoded_call.sqrt_price_x96.to_string(), + }) + }, + Err(_) => None, + } + }) + }) + .collect()); + calls.test_call_mints.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| is_declared_dds_address(&call.address, call.begin_ordinal, dds_store) && abi::test_contract::functions::Mint::match_call(call)) + .filter_map(|call| { + match abi::test_contract::functions::Mint::decode(call) { + Ok(decoded_call) => { + let (output_amount0, output_amount1) = match abi::test_contract::functions::Mint::output(&call.return_data) { + Ok((output_amount0, output_amount1)) => {(output_amount0, output_amount1)} + Err(_) => Default::default(), + }; + + Some(contract::TestMintCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + call_address: Hex(&call.address).to_string(), + amount: decoded_call.amount.to_string(), + data: decoded_call.data, + output_amount0: output_amount0.to_string(), + output_amount1: output_amount1.to_string(), + recipient: decoded_call.recipient, + tick_lower: Into::::into(decoded_call.tick_lower).to_i64().unwrap(), + tick_upper: Into::::into(decoded_call.tick_upper).to_i64().unwrap(), + }) + }, + Err(_) => None, + } + }) + }) + .collect()); + calls.test_call_set_fee_protocols.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| is_declared_dds_address(&call.address, call.begin_ordinal, dds_store) && abi::test_contract::functions::SetFeeProtocol::match_call(call)) + .filter_map(|call| { + match abi::test_contract::functions::SetFeeProtocol::decode(call) { + Ok(decoded_call) => { + Some(contract::TestSetFeeProtocolCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + call_address: Hex(&call.address).to_string(), + fee_protocol0: decoded_call.fee_protocol0.to_u64(), + fee_protocol1: decoded_call.fee_protocol1.to_u64(), + }) + }, + Err(_) => None, + } + }) + }) + .collect()); + calls.test_call_swaps.append(&mut blk + .transactions() + .flat_map(|tx| { + tx.calls.iter() + .filter(|call| is_declared_dds_address(&call.address, call.begin_ordinal, dds_store) && abi::test_contract::functions::Swap::match_call(call)) + .filter_map(|call| { + match abi::test_contract::functions::Swap::decode(call) { + Ok(decoded_call) => { + let (output_amount0, output_amount1) = match abi::test_contract::functions::Swap::output(&call.return_data) { + Ok((output_amount0, output_amount1)) => {(output_amount0, output_amount1)} + Err(_) => Default::default(), + }; + + Some(contract::TestSwapCall { + call_tx_hash: Hex(&tx.hash).to_string(), + call_block_time: Some(blk.timestamp().to_owned()), + call_block_number: blk.number, + call_ordinal: call.begin_ordinal, + call_success: !call.state_reverted, + call_address: Hex(&call.address).to_string(), + amount_specified: decoded_call.amount_specified.to_string(), + data: decoded_call.data, + output_amount0: output_amount0.to_string(), + output_amount1: output_amount1.to_string(), + recipient: decoded_call.recipient, + sqrt_price_limit_x96: decoded_call.sqrt_price_limit_x96.to_string(), + zero_for_one: decoded_call.zero_for_one, + }) + }, + Err(_) => None, + } + }) + }) + .collect()); +} + + + +fn graph_ewqocontraadd123_out(events: &contract::Events, tables: &mut EntityChangesTables) { + // Loop over all the abis events to create table changes + events.ewqocontraadd123_fee_amount_u_enableds.iter().for_each(|evt| { + tables + .create_row("ewqocontraadd123_fee_amount_u_enabled", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("fee", evt.fee) + .set("tick_spacing", evt.tick_spacing); + }); + events.ewqocontraadd123_owner123_changeds.iter().for_each(|evt| { + tables + .create_row("ewqocontraadd123_owner123_changed", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("new_owner", Hex(&evt.new_owner).to_string()) + .set("old_owner", Hex(&evt.old_owner).to_string()); + }); + events.ewqocontraadd123_pool_createds.iter().for_each(|evt| { + tables + .create_row("ewqocontraadd123_pool_created", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("fee", evt.fee) + .set("pool", Hex(&evt.pool).to_string()) + .set("tick_spacing", evt.tick_spacing) + .set("token0", Hex(&evt.token0).to_string()) + .set("token1", Hex(&evt.token1).to_string()); + }); +} +fn graph_ewqocontraadd123_calls_out(calls: &contract::Calls, tables: &mut EntityChangesTables) { + // Loop over all the abis calls to create table changes + calls.ewqocontraadd123_call_create_pools.iter().for_each(|call| { + tables + .create_row("ewqocontraadd123_call_create_pool", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("fee", call.fee) + .set("output_pool", Hex(&call.output_pool).to_string()) + .set("token_a", Hex(&call.token_a).to_string()) + .set("token_b", Hex(&call.token_b).to_string()); + }); + calls.ewqocontraadd123_call_enable123_aeemounts.iter().for_each(|call| { + tables + .create_row("ewqocontraadd123_call_enable123_aeemount", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("fee", call.fee) + .set("tick_spacing", call.tick_spacing); + }); + calls.ewqocontraadd123_call_set_owners.iter().for_each(|call| { + tables + .create_row("ewqocontraadd123_call_set_owner", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("u_owner", Hex(&call.u_owner).to_string()); + }); + } +fn graph_test_out(events: &contract::Events, tables: &mut EntityChangesTables) { + // Loop over all the abis events to create table changes + events.test_burns.iter().for_each(|evt| { + tables + .create_row("test_burn", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("evt_address", &evt.evt_address) + .set("amount", BigDecimal::from_str(&evt.amount).unwrap()) + .set("amount0", BigDecimal::from_str(&evt.amount0).unwrap()) + .set("amount1", BigDecimal::from_str(&evt.amount1).unwrap()) + .set("owner", Hex(&evt.owner).to_string()) + .set("tick_lower", evt.tick_lower) + .set("tick_upper", evt.tick_upper); + }); + events.test_collects.iter().for_each(|evt| { + tables + .create_row("test_collect", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("evt_address", &evt.evt_address) + .set("amount0", BigDecimal::from_str(&evt.amount0).unwrap()) + .set("amount1", BigDecimal::from_str(&evt.amount1).unwrap()) + .set("owner", Hex(&evt.owner).to_string()) + .set("recipient", Hex(&evt.recipient).to_string()) + .set("tick_lower", evt.tick_lower) + .set("tick_upper", evt.tick_upper); + }); + events.test_collect_protocols.iter().for_each(|evt| { + tables + .create_row("test_collect_protocol", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("evt_address", &evt.evt_address) + .set("amount0", BigDecimal::from_str(&evt.amount0).unwrap()) + .set("amount1", BigDecimal::from_str(&evt.amount1).unwrap()) + .set("recipient", Hex(&evt.recipient).to_string()) + .set("sender", Hex(&evt.sender).to_string()); + }); + events.test_flashes.iter().for_each(|evt| { + tables + .create_row("test_flash", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("evt_address", &evt.evt_address) + .set("amount0", BigDecimal::from_str(&evt.amount0).unwrap()) + .set("amount1", BigDecimal::from_str(&evt.amount1).unwrap()) + .set("paid0", BigDecimal::from_str(&evt.paid0).unwrap()) + .set("paid1", BigDecimal::from_str(&evt.paid1).unwrap()) + .set("recipient", Hex(&evt.recipient).to_string()) + .set("sender", Hex(&evt.sender).to_string()); + }); + events.test_increase_observation_cardinality_nexts.iter().for_each(|evt| { + tables + .create_row("test_increase_observation_cardinality_next", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("evt_address", &evt.evt_address) + .set("observation_cardinality_next_new", evt.observation_cardinality_next_new) + .set("observation_cardinality_next_old", evt.observation_cardinality_next_old); + }); + events.test_initializes.iter().for_each(|evt| { + tables + .create_row("test_initialize", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("evt_address", &evt.evt_address) + .set("sqrt_price_x96", BigDecimal::from_str(&evt.sqrt_price_x96).unwrap()) + .set("tick", evt.tick); + }); + events.test_mints.iter().for_each(|evt| { + tables + .create_row("test_mint", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("evt_address", &evt.evt_address) + .set("amount", BigDecimal::from_str(&evt.amount).unwrap()) + .set("amount0", BigDecimal::from_str(&evt.amount0).unwrap()) + .set("amount1", BigDecimal::from_str(&evt.amount1).unwrap()) + .set("owner", Hex(&evt.owner).to_string()) + .set("sender", Hex(&evt.sender).to_string()) + .set("tick_lower", evt.tick_lower) + .set("tick_upper", evt.tick_upper); + }); + events.test_set_fee_protocols.iter().for_each(|evt| { + tables + .create_row("test_set_fee_protocol", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("evt_address", &evt.evt_address) + .set("fee_protocol0_new", evt.fee_protocol0_new) + .set("fee_protocol0_old", evt.fee_protocol0_old) + .set("fee_protocol1_new", evt.fee_protocol1_new) + .set("fee_protocol1_old", evt.fee_protocol1_old); + }); + events.test_swaps.iter().for_each(|evt| { + tables + .create_row("test_swap", format!("{}-{}", evt.evt_tx_hash, evt.evt_index)) + .set("evt_tx_hash", &evt.evt_tx_hash) + .set("evt_index", evt.evt_index) + .set("evt_block_time", evt.evt_block_time.as_ref().unwrap()) + .set("evt_block_number", evt.evt_block_number) + .set("evt_address", &evt.evt_address) + .set("amount0", BigDecimal::from_str(&evt.amount0).unwrap()) + .set("amount1", BigDecimal::from_str(&evt.amount1).unwrap()) + .set("liquidity", BigDecimal::from_str(&evt.liquidity).unwrap()) + .set("recipient", Hex(&evt.recipient).to_string()) + .set("sender", Hex(&evt.sender).to_string()) + .set("sqrt_price_x96", BigDecimal::from_str(&evt.sqrt_price_x96).unwrap()) + .set("tick", evt.tick); + }); +} +fn graph_test_calls_out(calls: &contract::Calls, tables: &mut EntityChangesTables) { + // Loop over all the abis calls to create table changes + calls.test_call_burns.iter().for_each(|call| { + tables + .create_row("test_call_burn", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("call_address", &call.call_address) + .set("amount", BigDecimal::from_str(&call.amount).unwrap()) + .set("output_amount0", BigDecimal::from_str(&call.output_amount0).unwrap()) + .set("output_amount1", BigDecimal::from_str(&call.output_amount1).unwrap()) + .set("tick_lower", call.tick_lower) + .set("tick_upper", call.tick_upper); + }); + calls.test_call_collects.iter().for_each(|call| { + tables + .create_row("test_call_collect", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("call_address", &call.call_address) + .set("amount0_requested", BigDecimal::from_str(&call.amount0_requested).unwrap()) + .set("amount1_requested", BigDecimal::from_str(&call.amount1_requested).unwrap()) + .set("output_amount0", BigDecimal::from_str(&call.output_amount0).unwrap()) + .set("output_amount1", BigDecimal::from_str(&call.output_amount1).unwrap()) + .set("recipient", Hex(&call.recipient).to_string()) + .set("tick_lower", call.tick_lower) + .set("tick_upper", call.tick_upper); + }); + calls.test_call_collect_protocols.iter().for_each(|call| { + tables + .create_row("test_call_collect_protocol", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("call_address", &call.call_address) + .set("amount0_requested", BigDecimal::from_str(&call.amount0_requested).unwrap()) + .set("amount1_requested", BigDecimal::from_str(&call.amount1_requested).unwrap()) + .set("output_amount0", BigDecimal::from_str(&call.output_amount0).unwrap()) + .set("output_amount1", BigDecimal::from_str(&call.output_amount1).unwrap()) + .set("recipient", Hex(&call.recipient).to_string()); + }); + calls.test_call_flashes.iter().for_each(|call| { + tables + .create_row("test_call_flash", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("call_address", &call.call_address) + .set("amount0", BigDecimal::from_str(&call.amount0).unwrap()) + .set("amount1", BigDecimal::from_str(&call.amount1).unwrap()) + .set("data", Hex(&call.data).to_string()) + .set("recipient", Hex(&call.recipient).to_string()); + }); + calls.test_call_increase_observation_cardinality_nexts.iter().for_each(|call| { + tables + .create_row("test_call_increase_observation_cardinality_next", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("call_address", &call.call_address) + .set("observation_cardinality_next", call.observation_cardinality_next); + }); + calls.test_call_initializes.iter().for_each(|call| { + tables + .create_row("test_call_initialize", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("call_address", &call.call_address) + .set("sqrt_price_x96", BigDecimal::from_str(&call.sqrt_price_x96).unwrap()); + }); + calls.test_call_mints.iter().for_each(|call| { + tables + .create_row("test_call_mint", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("call_address", &call.call_address) + .set("amount", BigDecimal::from_str(&call.amount).unwrap()) + .set("data", Hex(&call.data).to_string()) + .set("output_amount0", BigDecimal::from_str(&call.output_amount0).unwrap()) + .set("output_amount1", BigDecimal::from_str(&call.output_amount1).unwrap()) + .set("recipient", Hex(&call.recipient).to_string()) + .set("tick_lower", call.tick_lower) + .set("tick_upper", call.tick_upper); + }); + calls.test_call_set_fee_protocols.iter().for_each(|call| { + tables + .create_row("test_call_set_fee_protocol", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("call_address", &call.call_address) + .set("fee_protocol0", call.fee_protocol0) + .set("fee_protocol1", call.fee_protocol1); + }); + calls.test_call_swaps.iter().for_each(|call| { + tables + .create_row("test_call_swap", format!("{}-{}", call.call_tx_hash, call.call_ordinal)) + .set("call_tx_hash", &call.call_tx_hash) + .set("call_ordinal", call.call_ordinal) + .set("call_block_time", call.call_block_time.as_ref().unwrap()) + .set("call_block_number", call.call_block_number) + .set("call_success", call.call_success) + .set("call_address", &call.call_address) + .set("amount_specified", BigDecimal::from_str(&call.amount_specified).unwrap()) + .set("data", Hex(&call.data).to_string()) + .set("output_amount0", BigDecimal::from_str(&call.output_amount0).unwrap()) + .set("output_amount1", BigDecimal::from_str(&call.output_amount1).unwrap()) + .set("recipient", Hex(&call.recipient).to_string()) + .set("sqrt_price_limit_x96", BigDecimal::from_str(&call.sqrt_price_limit_x96).unwrap()) + .set("zero_for_one", call.zero_for_one); + }); + } +#[substreams::handlers::store] +fn store_test_created(blk: eth::Block, store: StoreSetInt64) { + for rcpt in blk.receipts() { + for log in rcpt + .receipt + .logs + .iter() + .filter(|log| log.address == EWQOCONTRAADD123_TRACKED_CONTRACT) + { + if let Some(event) = abi::ewqocontraadd123_contract::events::PoolCreated::match_and_decode(log) { + store.set(log.ordinal, Hex(event.pool).to_string(), &1); + } + } + } +} +#[substreams::handlers::map] +fn map_events( + blk: eth::Block, + store_test: StoreGetInt64, +) -> Result { + let mut events = contract::Events::default(); + map_ewqocontraadd123_events(&blk, &mut events); + map_test_events(&blk, &store_test, &mut events); + Ok(events) +} +#[substreams::handlers::map] +fn map_calls( + blk: eth::Block, + store_test: StoreGetInt64, + +) -> Result { +let mut calls = contract::Calls::default(); + map_ewqocontraadd123_calls(&blk, &mut calls); + map_test_calls(&blk, &store_test, &mut calls); + Ok(calls) +} +#[substreams::handlers::map] +fn graph_out(events: contract::Events, calls: contract::Calls) -> Result { + // Initialize Database Changes container + let mut tables = EntityChangesTables::new(); + graph_ewqocontraadd123_out(&events, &mut tables); + graph_ewqocontraadd123_calls_out(&calls, &mut tables); + graph_test_out(&events, &mut tables); + graph_test_calls_out(&calls, &mut tables); + Ok(tables.to_entity_changes()) +} + diff --git a/ethfull/testoutput/complex_abi/src/pb/mod.rs b/ethfull/testoutput/complex_abi/src/pb/mod.rs new file mode 100644 index 0000000..611ea83 --- /dev/null +++ b/ethfull/testoutput/complex_abi/src/pb/mod.rs @@ -0,0 +1,8 @@ +// @generated +pub mod contract { + // @@protoc_insertion_point(attribute:contract.v1) + pub mod v1 { + include!("contract.v1.rs"); + // @@protoc_insertion_point(contract.v1) + } +} diff --git a/ethfull/testoutput/complex_abi/substreams.yaml b/ethfull/testoutput/complex_abi/substreams.yaml new file mode 100644 index 0000000..80030af --- /dev/null +++ b/ethfull/testoutput/complex_abi/substreams.yaml @@ -0,0 +1,58 @@ +specVersion: v0.1.0 +package: + name: test + version: v0.1.0 + +imports: + graph: https://github.com/streamingfast/substreams-sink-subgraph/releases/download/v0.1.0/substreams-sink-subgraph-protodefs-v0.1.0.spkg + entity: https://github.com/streamingfast/substreams-entity-change/releases/download/v1.1.0/substreams-entity-change-v1.1.0.spkg + +protobuf: + files: + - contract.proto + importPaths: + - ./proto + +binaries: + default: + type: wasm/rust-v1 + file: ./target/wasm32-unknown-unknown/release/substreams.wasm + +modules: + + - name: store_test_created + kind: store + initialBlock: 213919 + updatePolicy: set + valueType: proto:dynamic_datasource + inputs: + - source: sf.ethereum.type.v2.Block + + - name: map_events + kind: map + initialBlock: 213919 + inputs: + - source: sf.ethereum.type.v2.Block + - store: store_test_created + output: + type: proto:contract.v1.Events + + - name: map_calls + kind: map + initialBlock: 213919 + inputs: + - source: sf.ethereum.type.v2.Block + - store: store_test_created + output: + type: proto:contract.v1.Calls + + - name: graph_out + kind: map + initialBlock: 213919 + inputs: + - map: map_events + - map: map_calls + output: + type: proto:sf.substreams.entity.v1.EntityChanges + +network: mainnet diff --git a/go.mod b/go.mod index 82f5c9a..427be4a 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,10 @@ require ( github.com/codemodus/kace v0.5.1 github.com/dustin/go-humanize v1.0.1 github.com/gertd/go-pluralize v0.2.1 + github.com/golang-cz/textcase v1.2.1 github.com/huandu/xstrings v1.4.0 github.com/iancoleman/strcase v0.3.0 github.com/lib/pq v1.10.9 - github.com/lithammer/dedent v1.1.0 github.com/rs/cors v1.10.0 github.com/saracen/fastzip v0.1.11 github.com/spf13/cobra v1.7.0 @@ -30,7 +30,6 @@ require ( go.opentelemetry.io/otel v1.23.1 go.uber.org/zap v1.26.0 golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 - golang.org/x/net v0.26.0 golang.org/x/sync v0.7.0 google.golang.org/grpc v1.62.0 google.golang.org/protobuf v1.33.0 @@ -82,6 +81,7 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/klauspost/compress v1.16.6 // indirect + github.com/lithammer/dedent v1.1.0 // indirect github.com/logrusorgru/aurora v2.0.3+incompatible // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/manifoldco/promptui v0.9.0 // indirect @@ -127,6 +127,7 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.10.0 // indirect golang.org/x/crypto v0.24.0 // indirect + golang.org/x/net v0.26.0 // indirect golang.org/x/oauth2 v0.16.0 // indirect golang.org/x/sys v0.21.0 // indirect golang.org/x/term v0.21.0 // indirect diff --git a/go.sum b/go.sum index e90522e..8fcc2e7 100644 --- a/go.sum +++ b/go.sum @@ -184,6 +184,8 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-cz/textcase v1.2.1 h1:0xRtKo+abtJojre5ONjuMzyg9fSfiKBj5bWZ6fpTYxI= +github.com/golang-cz/textcase v1.2.1/go.mod h1:aWsQknYwxtTS2zSCrGGoRIsxmzjsHomRqLeMeVb+SKU= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= diff --git a/templating.go b/templating.go index ed9f3d4..afe8437 100644 --- a/templating.go +++ b/templating.go @@ -2,13 +2,15 @@ package codegen import ( "fmt" + "github.com/huandu/xstrings" + "github.com/iancoleman/strcase" "io/fs" + "regexp" "strings" "text/template" "github.com/bmatcuk/doublestar/v4" - "github.com/codemodus/kace" - "github.com/iancoleman/strcase" + "github.com/golang-cz/textcase" ) var templateFuncs = template.FuncMap{ @@ -16,13 +18,10 @@ var templateFuncs = template.FuncMap{ return left + right }, "toUpper": strings.ToUpper, - "toKebabCase": kace.Kebab, - "toKebabUpperCase": kace.KebabUpper, - "toSnakeCase": kace.Snake, - "toSnakeUpperCase": kace.SnakeUpper, - "toCamelCase": kace.Camel, + "toKebabCase": textcase.KebabCase, + "toSnakeCase": xstrings.ToSnakeCase, "toLowerCamelCase": strcase.ToLowerCamel, - "toPascalCase": kace.Pascal, + "toPascalCase": textcase.PascalCase, "sanitizeProtoFieldName": SanitizeProtoFieldName, } @@ -54,9 +53,18 @@ func ParseFS(myFuncs template.FuncMap, fsys fs.FS, pattern string) (*template.Te } func SanitizeProtoFieldName(name string) string { + regex := regexp.MustCompile("(\\d+)(_*)") + name = regex.ReplaceAllStringFunc(name, func(match string) string { + if strings.HasSuffix(match, "_") { + return match + } + return match + "_" + }) + if strings.HasPrefix(name, "_") { name = "u" + name } + if strings.HasSuffix(name, "_") { name = strings.TrimSuffix(name, "_") }