Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Aug 5, 2024
2 parents 9a7a87f + 00c0e3a commit e32e196
Show file tree
Hide file tree
Showing 19 changed files with 815 additions and 46 deletions.
28 changes: 18 additions & 10 deletions ethfull/apicalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
"github.com/tidwall/gjson"
)

var etherscanAPIKey = os.Getenv("SUBDEV_ETHERSCAN_API_KEY")

var httpClient = http.Client{
Transport: dhttp.NewLoggingRoundTripper(zlog, tracer, http.DefaultTransport),
Timeout: 30 * time.Second,
Expand All @@ -37,20 +35,20 @@ func getContractABIFollowingProxy(ctx context.Context, contractAddress string, c
}
return &ABI{abi, abiContent}, nil
}
abi, abiContent, wait, err := getContractABI(ctx, contractAddress, chain.ApiEndpoint)
abi, abiContent, wait, err := getContractABI(ctx, contractAddress, chain.ApiEndpoint, os.Getenv(chain.APIKeyEnvVar))
if err != nil {
return nil, err
}

<-wait.C
implementationAddress, wait, err := getProxyContractImplementation(ctx, contractAddress, chain.ApiEndpoint)
implementationAddress, wait, err := getProxyContractImplementation(ctx, contractAddress, chain.ApiEndpoint, os.Getenv(chain.APIKeyEnvVar))
if err != nil {
return nil, err
}
<-wait.C

if implementationAddress != "" {
implementationABI, implementationABIContent, wait, err := getContractABI(ctx, implementationAddress, chain.ApiEndpoint)
implementationABI, implementationABIContent, wait, err := getContractABI(ctx, implementationAddress, chain.ApiEndpoint, os.Getenv(chain.APIKeyEnvVar))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -121,8 +119,11 @@ func getContractABIDirect(ctx context.Context, address string, endpoint string)

}

func getContractABI(ctx context.Context, address string, endpoint string) (*eth.ABI, string, *time.Timer, error) {
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/api?module=contract&action=getabi&address=%s&apiKey=%s", endpoint, address, etherscanAPIKey), nil)
func getContractABI(ctx context.Context, address string, endpoint string, apiKey string) (*eth.ABI, string, *time.Timer, error) {
if apiKey != "" {
apiKey = fmt.Sprintf("&apiKey=%s", apiKey)
}
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/api?module=contract&action=getabi&address=%s%s", endpoint, address, apiKey), nil)
if err != nil {
return nil, "", nil, fmt.Errorf("new request: %w", err)
}
Expand Down Expand Up @@ -158,9 +159,12 @@ func getContractABI(ctx context.Context, address string, endpoint string) (*eth.
}

// getProxyContractImplementation returns the implementation address and a timer to wait before next call
func getProxyContractImplementation(ctx context.Context, address string, endpoint string) (string, *time.Timer, error) {
func getProxyContractImplementation(ctx context.Context, address string, endpoint string, apiKey string) (string, *time.Timer, error) {
if apiKey != "" {
apiKey = fmt.Sprintf("&apiKey=%s", apiKey)
}
// check for proxy contract's implementation
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/api?module=contract&action=getsourcecode&address=%s&apiKey=%s", endpoint, address, etherscanAPIKey), nil)
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/api?module=contract&action=getsourcecode&address=%s%s", endpoint, address, apiKey), nil)

if err != nil {
return "", nil, fmt.Errorf("new request: %w", err)
Expand Down Expand Up @@ -236,7 +240,11 @@ func getContractInitialBlock(ctx context.Context, chain *ChainConfig, contractAd
return initBlock, nil
}

req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/api?module=account&action=txlist&address=%s&page=1&offset=1&sort=asc&apikey=%s", chain.ApiEndpoint, contractAddress, etherscanAPIKey), nil)
apiKey := ""
if key := os.Getenv(chain.APIKeyEnvVar); key != "" {
apiKey = fmt.Sprintf("&apiKey=%s", key)
}
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/api?module=account&action=txlist&address=%s&page=1&offset=1&sort=asc%s", chain.ApiEndpoint, contractAddress, apiKey), nil)
if err != nil {
return chain.FirstStreamableBlock, fmt.Errorf("new request: %w", err)
}
Expand Down
17 changes: 17 additions & 0 deletions ethfull/chain_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ChainConfig struct {
FirstStreamableBlock uint64
Network string
SupportsCalls bool
APIKeyEnvVar string

abiCache map[string]*ABI
initialBlockCache map[string]uint64
Expand All @@ -36,6 +37,7 @@ var ChainConfigByID = map[string]*ChainConfig{
abiCache: make(map[string]*ABI),
initialBlockCache: make(map[string]uint64),
SupportsCalls: true,
APIKeyEnvVar: "CODEGEN_MAINNET_API_KEY",
},
"bnb": {
DisplayName: "BNB",
Expand All @@ -47,6 +49,7 @@ var ChainConfigByID = map[string]*ChainConfig{
abiCache: make(map[string]*ABI),
initialBlockCache: make(map[string]uint64),
SupportsCalls: true,
APIKeyEnvVar: "CODEGEN_BNB_API_KEY",
},
"polygon": {
DisplayName: "Polygon",
Expand All @@ -58,6 +61,7 @@ var ChainConfigByID = map[string]*ChainConfig{
abiCache: make(map[string]*ABI),
initialBlockCache: make(map[string]uint64),
SupportsCalls: true,
APIKeyEnvVar: "CODEGEN_POLYGON_API_KEY",
},
"amoy": {
DisplayName: "Polygon Amoy Testnet",
Expand Down Expand Up @@ -113,6 +117,7 @@ var ChainConfigByID = map[string]*ChainConfig{
abiCache: make(map[string]*ABI),
initialBlockCache: make(map[string]uint64),
SupportsCalls: false,
APIKeyEnvVar: "CODEGEN_OPTIMISM_API_KEY",
},
"avalanche": {
DisplayName: "Avalanche C-chain",
Expand Down Expand Up @@ -148,6 +153,18 @@ var ChainConfigByID = map[string]*ChainConfig{
initialBlockCache: make(map[string]uint64),
SupportsCalls: true,
},
"base-mainnet": {
DisplayName: "Base Mainnet",
ExplorerLink: "https://basescan.org",
ApiEndpoint: "https://api.basescan.org",
FirehoseEndpoint: "base-mainnet.streamingfast.io",
FirstStreamableBlock: 0,
Network: "base-mainnet",
abiCache: make(map[string]*ABI),
initialBlockCache: make(map[string]uint64),
SupportsCalls: true,
APIKeyEnvVar: "CODEGEN_BASE_API_KEY",
},
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion ethfull/templates/Cargo.toml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ num-bigint = "0.4"
num-traits = "0.2.15"
prost = "0.11"
prost-types = "0.11"
substreams = "0.5"
substreams = "0.5.21"
substreams-ethereum = "0.9"
substreams-database-change = "1"
substreams-entity-change = "1"
Expand Down
10 changes: 0 additions & 10 deletions ethfull/templates/entities/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ To run a local `graph-node` instance, you will need to install Docker. You can d

To run the proto assembly script bindings, you will need to install the `buf` [cli](https://buf.build/docs/installation).

## Run the entire stack with the `run-local.sh` script

You can run the entire stack (`docker`, `npm` installations and `graph` creation with deployment) by running the below script

```bash
./run-local.sh
```

However, if you want to run each commen individually, follow the instructions below:

## Install npm and nodeJS packages

Run the following command in the `root` of the repository:
Expand Down
2 changes: 2 additions & 0 deletions ethfull/templates/src/lib.rs.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ fn map_events(blk: eth::Block) -> Result<contract::Events, substreams::errors::E
map_{{ $ddsContract.Identifier }}_events(&blk, &store_{{ $ddsContract.Identifier }}, &mut events);
{{- end }}
{{- end }}
substreams::skip_empty_output();
Ok(events)
}
{{- end }}
Expand Down Expand Up @@ -457,6 +458,7 @@ let mut calls = contract::Calls::default();
{{- end }}
{{- end }}
{{- end }}
substreams::skip_empty_output();
Ok(calls)
}
{{- end }}
Expand Down
10 changes: 0 additions & 10 deletions ethfull/testoutput/bayc_triggers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ To run a local `graph-node` instance, you will need to install Docker. You can d

To run the proto assembly script bindings, you will need to install the `buf` [cli](https://buf.build/docs/installation).

## Run the entire stack with the `run-local.sh` script

You can run the entire stack (`docker`, `npm` installations and `graph` creation with deployment) by running the below script

```bash
./run-local.sh
```

However, if you want to run each commen individually, follow the instructions below:

## Install npm and nodeJS packages

Run the following command in the `root` of the repository:
Expand Down
2 changes: 1 addition & 1 deletion ethfull/testoutput/bayc_triggers/substreams/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ num-bigint = "0.4"
num-traits = "0.2.15"
prost = "0.11"
prost-types = "0.11"
substreams = "0.5"
substreams = "0.5.21"
substreams-ethereum = "0.9"
substreams-database-change = "1"
substreams-entity-change = "1"
Expand Down
2 changes: 2 additions & 0 deletions ethfull/testoutput/bayc_triggers/substreams/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,14 @@ fn zipped_events_calls(
fn map_events(blk: eth::Block) -> Result<contract::Events, substreams::errors::Error> {
let mut events = contract::Events::default();
map_bayc_events(&blk, &mut events);
substreams::skip_empty_output();
Ok(events)
}
#[substreams::handlers::map]
fn map_calls(blk: eth::Block) -> Result<contract::Calls, substreams::errors::Error> {
let mut calls = contract::Calls::default();
map_bayc_calls(&blk, &mut calls);
substreams::skip_empty_output();
Ok(calls)
}

2 changes: 1 addition & 1 deletion ethfull/testoutput/complex_abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ num-bigint = "0.4"
num-traits = "0.2.15"
prost = "0.11"
prost-types = "0.11"
substreams = "0.5"
substreams = "0.5.21"
substreams-ethereum = "0.9"
substreams-database-change = "1"
substreams-entity-change = "1"
Expand Down
2 changes: 2 additions & 0 deletions ethfull/testoutput/complex_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ fn map_events(
let mut events = contract::Events::default();
map_ewqocontraadd123_events(&blk, &mut events);
map_test_events(&blk, &store_test, &mut events);
substreams::skip_empty_output();
Ok(events)
}
#[substreams::handlers::map]
Expand All @@ -1059,6 +1060,7 @@ fn map_calls(
let mut calls = contract::Calls::default();
map_ewqocontraadd123_calls(&blk, &mut calls);
map_test_calls(&blk, &store_test, &mut calls);
substreams::skip_empty_output();
Ok(calls)
}
#[substreams::handlers::map]
Expand Down
10 changes: 0 additions & 10 deletions ethfull/testoutput/uniswap_factory_v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ To run a local `graph-node` instance, you will need to install Docker. You can d

To run the proto assembly script bindings, you will need to install the `buf` [cli](https://buf.build/docs/installation).

## Run the entire stack with the `run-local.sh` script

You can run the entire stack (`docker`, `npm` installations and `graph` creation with deployment) by running the below script

```bash
./run-local.sh
```

However, if you want to run each commen individually, follow the instructions below:

## Install npm and nodeJS packages

Run the following command in the `root` of the repository:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ num-bigint = "0.4"
num-traits = "0.2.15"
prost = "0.11"
prost-types = "0.11"
substreams = "0.5"
substreams = "0.5.21"
substreams-ethereum = "0.9"
substreams-database-change = "1"
substreams-entity-change = "1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn map_unifactory_events(blk: &eth::Block, events: &mut contract::Events) {
fn map_events(blk: eth::Block) -> Result<contract::Events, substreams::errors::Error> {
let mut events = contract::Events::default();
map_unifactory_events(&blk, &mut events);
substreams::skip_empty_output();
Ok(events)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "uniswap_v3"
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.21"
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"
Loading

0 comments on commit e32e196

Please sign in to comment.