Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

[BUG] Failed to deserialize etherscan response: data did not match any variant of untagged enum ResponseData #2324

Closed
shekohex opened this issue Apr 5, 2023 · 2 comments · Fixed by #2325
Labels
bug Something isn't working

Comments

@shekohex
Copy link
Contributor

shekohex commented Apr 5, 2023

Version
List the versions of all ethers-rs crates you are using.

ethers v2.0.2
├── ethers-addressbook v2.0.2
├── ethers-contract v2.0.2
├── ethers-core v2.0.2
├── ethers-etherscan v2.0.2
├── ethers-middleware v2.0.2
├── ethers-providers v2.0.2
├── ethers-signers v2.0.2
└── ethers-solc v2.0.2

Platform
Linux workstation 5.15.104-2-MANJARO #1 SMP PREEMPT Thu Mar 23 01:40:42 UTC 2023 x86_64 GNU/Linux

Description

As the title says, there is a bug in etherscan data while working with Polygon mainnet or the testnet

I tried this code: https://github.com/shekohex/ethers-etherscan-issue

I expected to see this happen: To have the gas oracle information

Instead, this happened:

Looks like there is a need to handle a new update with the etherscan returned data!

Logs

  ERROR etherscan: Failed to deserialize response: data did not match any variant of untagged enum ResponseData, res: "{\"status\":\"1\",\"message\":\"OK\",\"result\":{\"LastBlock\":\"41171167\",\"SafeGasPrice\":\"119.9\",\"ProposeGasPrice\":\"141.9\",\"FastGasPrice\":\"142.9\",\"suggestBaseFee\":\"89.82627877\",\"gasUsedRatio\":\"0.399191166666667,0.4847166,0.997667533333333,0.538075133333333,0.343416033333333\",\"UsdPrice\":\"1.15\"}}"
    at /home/shady/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ethers-etherscan-2.0.2/src/lib.rs:205

   INFO ethers_etherscan_issue: Gas Oracle Info, gas_oracle: Err(Serde(Error("data did not match any variant of untagged enum ResponseData", line: 0, column: 0)))
    at src/main.rs:39

JSON Response

{
    "status": "1",
    "message": "OK",
    "result": {
        "LastBlock": "41171167",
        "SafeGasPrice": "119.9",
        "ProposeGasPrice": "141.9",
        "FastGasPrice": "142.9",
        "suggestBaseFee": "89.82627877",
        "gasUsedRatio": "0.399191166666667,0.4847166,0.997667533333333,0.538075133333333,0.343416033333333",
        "UsdPrice": "1.15"
    }
}
@shekohex shekohex added the bug Something isn't working label Apr 5, 2023
@mattsse
Copy link
Collaborator

mattsse commented Apr 5, 2023

looks like we need to change the types from u64 to f64

do you want to give this a try?

@shekohex
Copy link
Contributor Author

shekohex commented Apr 5, 2023

After narrowing down the issue to just as simple as this Playground it returns the error: "invalid digit found in string", line: 7, column: 31" and this points out to the SafeGasPrice I guess.

Changing these values to be f64 Like here in the updated Playground Solves the issue.

Will open a PR with the quick fix shortly!

prestwich pushed a commit that referenced this issue Apr 5, 2023
* fix(etherscan)!: change the `GasOracle` fields to be `f64`

This updates the `GasOracle`'s {safe_gase_price,propose_gas_price,fast_gas_price} from `u64` to `f64` to fix [BUG] Failed to deserialize etherscan response: data did not match any variant of untagged enum ResponseData #2324

BREAKING CHANGE: This considered a public api breaking change, since `f64` and `u64` is not compatible with each other.

* fix(ethers-middleware): update etherscan oracle

This a required change after chaning the gas prices to be `f64`

* test(etherscan): add more tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants