Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[draft] Add Optimism & OptimismKovan chains #737

Merged
merged 2 commits into from Dec 25, 2021

Conversation

pyk
Copy link
Contributor

@pyk pyk commented Dec 25, 2021

Motivation

I want to add Optimism verification support for foundry, but it turns out foundry depends on this package and optimism is not supported yet. This PR add support for Optimism network.

More information about Optimism:

  1. What is Optimism?
  2. Optimism Networks and Public RPC Endpoints

Solution

There are two packages that need to be updated:

  1. Core: Add chain types
  2. Etherscan: add support for ETHERSCAN_API_KEY on optimism

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

@pyk pyk changed the title Add Optimism & OptimismKovan chains [draft] Add Optimism & OptimismKovan chains Dec 25, 2021
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@gakonst gakonst merged commit 3f095f4 into gakonst:master Dec 25, 2021
@pyk
Copy link
Contributor Author

pyk commented Dec 26, 2021

@mattsse @gakonst Ser, I'm sorry I marked this PR as a draft coz when I try to deploy contract via forge using this implementation it's failed due to error in gas estimation. So it's not ready yet.

This line

.ok_or_else(|| ProviderError::CustomError("EIP-1559 not activated".into()))?;

It turns out that the JSON-RPC response from Optimism is a bit different.

Here is response from kovan

foundry-optimism on 🌱 master [✘?]
✦ curl https://kovan.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161 \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params": ["0x1B9ECBF",false],"id":1}' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2130  100  2044  100    86   1672     70  0:00:01  0:00:01 --:--:--  1753
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "author": "0x03801efb0efe2a25ede5dd3a003ae880c0292e4d",
    "baseFeePerGas": "0x7",
    "difficulty": "0xfffffffffffffffffffffffffffffffe",
    "extraData": "0xdb830303018c4f70656e457468657265756d86312e34372e30826c69",
    "gasLimit": "0x1c9c380",
    "gasUsed": "0x2f232",
    "hash": "0x77ee67b0539362891ec198b2c0956bcce7d233f38e0a945e14b138242b44eded",
    "logsBloom": "0x00000000000008000000000018000000000000400000000000000000008000000020000000800000000000000000000000000000000200000000000000000000100000000000000000000000002000001000000001000000000000000000800000000000000000000000000000000000400000000400000000000000100000000000200000000000000000000000000000000480000000000000000000000000000008001000000000000000000000000002000000000000000000000000000000000000000000040000000000200008000000000000000000000000000000000000000001000000000000000000000000000000000000020000000000000000",
    "miner": "0x03801efb0efe2a25ede5dd3a003ae880c0292e4d",
    "number": "0x1b9ecbf",
    "parentHash": "0xd3ad06ca887f081bf11c97e3c9f7e23c8a35da930098dfa3971f9c1c699d7d8d",
    "receiptsRoot": "0x12adb242ef50cb5450c49e4d85437979663f85a83867099af7bc6b1efd634ce0",
    "sealFields": [
      "0x8418721f1d",
      "0xb8419f7bc3ea952d5bc93064306f034493d6b485afbaf84ad88d7a41356d4b5bd49f3de5f1951ed5761427f4280bf0ad329c2a6752ee903c438918ecc27f1af8ecff00"
    ],
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "signature": "9f7bc3ea952d5bc93064306f034493d6b485afbaf84ad88d7a41356d4b5bd49f3de5f1951ed5761427f4280bf0ad329c2a6752ee903c438918ecc27f1af8ecff00",
    "size": "0x3ee",
    "stateRoot": "0xd9f3985dec744c9ecb29acf3a03b2f3071b1706be95b976142822ad986252855",
    "step": "410132253",
    "timestamp": "0x61c87c74",
    "totalDifficulty": "0x1b7a9b0000000000000000000000004822ae54d",
    "transactions": [
      "0x33c94e1de7f0d7ada758e2743d16ff9f969ab4b572340a443c3cd374062b7a90",
      "0x1cf55a97345cd3b6b09d83bf725b2d3a3b9fe3e980fb87358719b8bea53c8ff8",
      "0x82488b081252bb075a90779a44c30d98f1fb82768e0088446e47725f4beeb66e"
    ],
    "transactionsRoot": "0x6cb65ef738b55c7bd49f22d71a703751ddb2a7b1d50250755e6913a3626fc7b1",
    "uncles": []
  }
}

here is from optimism kovan:

foundry-optimism on 🌱 master [✘?]
✦ curl https://kovan.optimism.io \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params": ["0x2D87",false],"id":1}' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1757  100  1674  100    83   4588    227 --:--:-- --:--:-- --:--:--  4907
{
  "jsonrpc": "2.0",
  "result": {
    "difficulty": "0x2",
    "extraData": "0xd98301090a846765746889676f312e31352e3133856c696e757800000000000000900c3bfe9a04b7577748baa6498abd6f7edd2eecc007b5acb0d34458626aef78257e1cb9d03aaf11832a729f5bdbda4e5ba0b813eac980dbb78ebfee591b9d00",
    "gasLimit": "0xe4e1c0",
    "gasUsed": "0x2f9e5",
    "hash": "0x323e1caafc8529374f3f0df815b07a36f7218a75d3b8f5a17758eb79e398da31",
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000800000000020200000000000000000000100004010000000100000000012000000000000001000000000000000000000000000000000000000000000000040200400000000400000000000000100000000010000000010000020000000000000000000480000000000000000000000000000000001000000000000000000004000000000000000000000080000000000000000000000000001000000000000008000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "miner": "0x0000000000000000000000000000000000000000",
    "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "nonce": "0x0000000000000000",
    "number": "0x2d87",
    "parentHash": "0xada07dac184dce34a07963b11bae1884d175c038812918bfb5b5b95b87fa5ff9",
    "receiptsRoot": "0x19b8f29cc262993a5241a691682c99345c8e863a106251b9d88e1698d1aea929",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size": "0x311",
    "stateRoot": "0x114f494f25e8120b38b2c0d2ac4e4b45726327b7fd2735d3c653dd8ff2fb649c",
    "timestamp": "0x617e8580",
    "totalDifficulty": "0x5b0f",
    "transactions": [
      "0x89e3281a30371aea2426c660ebef724b0e5e986bf9862de95975e9582463c5ac"
    ],
    "transactionsRoot": "0xbea45c7f3b6ea624c1d3f4ceef8b0b5d64ea7c771ae75034b6354ef6b63bd10b",
    "uncles": []
  },
  "id": 1
}

Notice that there is no baseFeePerGas field on Optimism.

If forge(1) use this, it will error like this:

foundry-optimism on 🌱 master [✘?]
✦ ./deploy-to-optimism-kovan.sh
compiling...
no files changed, compilation skippped.
Dec 26 21:40:13.205 ERROR forge: error=custom error: EIP-1559 not activated
Error:
   0: custom error: EIP-1559 not activated

Location:
   /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/result.rs:1914

Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

@pyk
Copy link
Contributor Author

pyk commented Dec 26, 2021

It seems that I need to enable legacy trx when deploying to optimism:

// create the tx object. Since we're deploying a contract, `to` is `None`
// We default to EIP-1559 transactions, but the sender can convert it back
// to a legacy one
#[cfg(feature = "legacy")]
let tx = TransactionRequest { to: None, data: Some(data), ..Default::default() };
#[cfg(not(feature = "legacy"))]
let tx = Eip1559TransactionRequest { to: None, data: Some(data), ..Default::default() };
let tx = tx.into();
Ok(Deployer {
client: Arc::clone(&self.client), // cheap clone behind the arc
abi: self.abi,
tx,
confs: 1,
block: BlockNumber::Latest,
})

@gakonst
Copy link
Owner

gakonst commented Dec 26, 2021

Yeah Optimism does not have 1559 enabled so you should use legacy indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants