coinbase / mesh-geth-sdk

go-ethereum based sdk for Mesh API
https://docs.cdp.coinbase.com/mesh/docs/getting-started/
Apache License 2.0
28 stars 29 forks source link

ERC20 Voting Delegation #50

Open Inphi opened 1 year ago

Inphi commented 1 year ago

Is your feature request related to a problem? Please describe. Support ERC20Votes delegation as a built-in operation type.

Describe the solution you'd like The interface can be similar to ERC20_TRANSFER operations. When a user queries the /construction/preprocess endpoint for token delegation, they'll need to provide operations with the following schema:

 "operations": [
    {
      "operation_identifier": {
        "index": 0
      },
      "type": "ERC20VOTES_DELEGATE",
      "account": { "address": "<sender>"},
      "amount": {
        "value": "0",
        "currency": {
          "symbol": "TOKEN",
          "decimals": 18,
          "metadata": {
            "contractAddress": "0x..."
          }
        }
      }
    },
    {
      "operation_identifier": {
        "index": 1
      },
      "type": "ERC20VOTES_DELEGATE",
      "account": { "address": "<delegatee>"},
      "amount": {
        "value": "0",
        "currency": {
          "symbol": "TOKEN",
          "decimals": 18,
          "metadata": {
            "contractAddress": "0x..."
          }
        }
      }
    }
  ]
  1. A new operation type, ERC20VOTERS_DELEGATE, is introduced to describe the intent of an ERC20Votes delegate call.
  2. There must be exactly two operations for an ERC20Votes delegate call; the first representing an account that's delegating votes, and the second represents the account that's being delegated votes to.
  3. The type of each operation must be set to ERC20VOTES_DELEGATE.
  4. The value of each operation must be set to zero.
  5. The currency must contain a valid contractAddress in its metadata. The contractAddress should point to an ERC20Votes compatible token.

Once the metadata is created, it can be forwarded through the usual flow to construct, sign and submit the tx.

Describe alternatives you've considered

Additional context The outlined schema is based off of the design used in optimism-rosetta.

xiaying-peng commented 1 year ago

Quick question, what is the best way to parse this type of transaction in Block API?

Inphi commented 1 year ago

The receipt of such transactions contain DelegateChanged events. There's already logic in roseta-geth-sdk to parse ERC20 transfer events. Parsing delegate calls would be similar.