Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Add SPL Token 2022 to the list of known token ids #23067

Merged
merged 3 commits into from
Apr 20, 2022

Conversation

mvines
Copy link
Contributor

@mvines mvines commented Feb 11, 2022

There's a lot more to do wrt. integrating Token 2022 into the JSON RPC methods, this is just the tip of the spear.

@mvines mvines added the v1.9 label Feb 11, 2022
@mvines mvines force-pushed the known_tids branch 2 times, most recently from 630f765 to 192bcd6 Compare February 11, 2022 00:40
@stale
Copy link

stale bot commented Mar 2, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale [bot only] Added to stale content; results in auto-close after a week. label Mar 2, 2022
@stale
Copy link

stale bot commented Apr 16, 2022

This stale pull request has been automatically closed. Thank you for your contributions.

@stale stale bot closed this Apr 16, 2022
@stale stale bot removed the stale [bot only] Added to stale content; results in auto-close after a week. label Apr 19, 2022
@CriesofCarrots
Copy link
Contributor

Yoink!

@CriesofCarrots
Copy link
Contributor

This is step 1 of token-2022 rpc support, enabling RPC handling for token-2022 basic features (ie. those that are the same as spl-token v3.2):

  • Instruction parsing
  • Account decoding
  • Token-specific RPC endpoints

Examples below

@CriesofCarrots
Copy link
Contributor

CriesofCarrots commented Apr 19, 2022

Example 1, getTokenAccountsByOwner with explicit programId (mint also works), and json-parsing of accounts for token-2022:

$ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0","id":1,"method":"getTokenAccountsByOwner","params":["6J5DvqR4XX8zwMNG3XUf7c4ELYNHcyyPEJK9JjZPqfhJ",{"programId":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"}, {"encoding":"jsonParsed"}]}' 127.0.0.1:8899 
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "slot": 277
    },
    "value": [
      {
        "account": {
          "data": {
            "parsed": {
              "info": {
                "isNative": false,
                "mint": "Gpk8zJjpP3UhDo1QAhFQmnU3trL2iZxnZ6n75iLDVFdQ",
                "owner": "6J5DvqR4XX8zwMNG3XUf7c4ELYNHcyyPEJK9JjZPqfhJ",
                "state": "initialized",
                "tokenAmount": {
                  "amount": "0",
                  "decimals": 9,
                  "uiAmount": 0,
                  "uiAmountString": "0"
                }
              },
              "type": "account"
            },
            "program": "spl-token",
            "space": 165
          },
          "executable": false,
          "lamports": 2039280,
          "owner": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
          "rentEpoch": 0
        },
        "pubkey": "7sgyaFEYF9iUpw8uvJShdAa4PPtKnkCJ77EJHZQKHnZo"
      }
    ]
  },
  "id": 1
}

@CriesofCarrots
Copy link
Contributor

Example 2, json-parsing of token-2022 instructions:

$ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0","id":1,"method":"getTransaction","params":["2wzhcJTeMuQ2FkYwuizTb6CkiDqKtqFMRUSTJxJyXaFHQZaMNJRFek1i1A3YLyxNXNzcx6fq9snJurReo33z6qYj",{"encoding":"jsonParsed","commitment":"confirmed"}]}' 127.0.0.1:8899
{
  "jsonrpc": "2.0",
  "result": {
    "blockTime": 1650404679,
    "meta": {
      "err": null,
      "fee": 10000,
      "innerInstructions": [],
      "loadedAddresses": {
        "readonly": [],
        "writable": []
      },
      "logMessages": [
        "Program 11111111111111111111111111111111 invoke [1]",
        "Program 11111111111111111111111111111111 success",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]",
        "Program log: Instruction: InitializeAccount",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 5142 of 1400000 compute units",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success"
      ],
      "postBalances": [
        499999999992958200,
        2039280,
        1,
        1009200,
        1,
        1461600
      ],
      "postTokenBalances": [
        {
          "accountIndex": 1,
          "mint": "Gpk8zJjpP3UhDo1QAhFQmnU3trL2iZxnZ6n75iLDVFdQ",
          "owner": "6J5DvqR4XX8zwMNG3XUf7c4ELYNHcyyPEJK9JjZPqfhJ",
          "uiTokenAmount": {
            "amount": "0",
            "decimals": 9,
            "uiAmount": null,
            "uiAmountString": "0"
          }
        }
      ],
      "preBalances": [
        499999999995007500,
        0,
        1,
        1009200,
        1,
        1461600
      ],
      "preTokenBalances": [],
      "returnData": null,
      "rewards": [],
      "status": {
        "Ok": null
      }
    },
    "slot": 95,
    "transaction": {
      "message": {
        "accountKeys": [
          {
            "pubkey": "6J5DvqR4XX8zwMNG3XUf7c4ELYNHcyyPEJK9JjZPqfhJ",
            "signer": true,
            "writable": true
          },
          {
            "pubkey": "7sgyaFEYF9iUpw8uvJShdAa4PPtKnkCJ77EJHZQKHnZo",
            "signer": true,
            "writable": true
          },
          {
            "pubkey": "11111111111111111111111111111111",
            "signer": false,
            "writable": false
          },
          {
            "pubkey": "SysvarRent111111111111111111111111111111111",
            "signer": false,
            "writable": false
          },
          {
            "pubkey": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
            "signer": false,
            "writable": false
          },
          {
            "pubkey": "Gpk8zJjpP3UhDo1QAhFQmnU3trL2iZxnZ6n75iLDVFdQ",
            "signer": false,
            "writable": false
          }
        ],
        "addressTableLookups": null,
        "instructions": [
          {
            "parsed": {
              "info": {
                "lamports": 2039280,
                "newAccount": "7sgyaFEYF9iUpw8uvJShdAa4PPtKnkCJ77EJHZQKHnZo",
                "owner": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
                "source": "6J5DvqR4XX8zwMNG3XUf7c4ELYNHcyyPEJK9JjZPqfhJ",
                "space": 165
              },
              "type": "createAccount"
            },
            "program": "system",
            "programId": "11111111111111111111111111111111"
          },
          {
            "parsed": {
              "info": {
                "account": "7sgyaFEYF9iUpw8uvJShdAa4PPtKnkCJ77EJHZQKHnZo",
                "mint": "Gpk8zJjpP3UhDo1QAhFQmnU3trL2iZxnZ6n75iLDVFdQ",
                "owner": "6J5DvqR4XX8zwMNG3XUf7c4ELYNHcyyPEJK9JjZPqfhJ",
                "rentSysvar": "SysvarRent111111111111111111111111111111111"
              },
              "type": "initializeAccount"
            },
            "program": "spl-token",
            "programId": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
          }
        ],
        "recentBlockhash": "2YNbNK1F8Ek6kL3Mh8yV4HeDX34XZqfgqWusoGqhw9Dn"
      },
      "signatures": [
        "2wzhcJTeMuQ2FkYwuizTb6CkiDqKtqFMRUSTJxJyXaFHQZaMNJRFek1i1A3YLyxNXNzcx6fq9snJurReo33z6qYj",
        "2swpagv9Eqfh86Ji7kv8rcfKLqiqriHC91axnbW1FZuouWd9x5haYrm1icQr845mFd4XXWw1idjo4L88AjJGycSd"
      ]
    }
  },
  "id": 1
}

@CriesofCarrots
Copy link
Contributor

Example 3, getTokenAccountBalance of a token-22 account:

$ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0","id":1,"method":"getTokenAccountBalance","params":["7sgyaFEYF9iUpw8uvJShdAa4PPtKnkCJ77EJHZQKHnZo"]}' 127.0.0.1:8899
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "slot": 424
    },
    "value": {
      "amount": "0",
      "decimals": 9,
      "uiAmount": 0,
      "uiAmountString": "0"
    }
  },
  "id": 1
}

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Thanks for updating all these tests! It'll be much easier to debug and improve in the future

@CriesofCarrots CriesofCarrots merged commit 4138066 into solana-labs:master Apr 20, 2022
mergify bot pushed a commit that referenced this pull request Apr 23, 2022
* Add SPL Token 2022 to the list of known token ids

* Fix tests to accommodate #23729

* Test parsing of basic token-2022 instructsions

Co-authored-by: Tyera Eulberg <tyera@solana.com>
(cherry picked from commit 4138066)

# Conflicts:
#	Cargo.lock
#	programs/bpf/Cargo.lock
CriesofCarrots pushed a commit that referenced this pull request Apr 23, 2022
…24625)

* Add SPL Token 2022 to the list of known token ids (#23067)

* Add SPL Token 2022 to the list of known token ids

* Fix tests to accommodate #23729

* Test parsing of basic token-2022 instructsions

Co-authored-by: Tyera Eulberg <tyera@solana.com>
(cherry picked from commit 4138066)

# Conflicts:
#	Cargo.lock
#	programs/bpf/Cargo.lock

* Fix lock conflicts

Co-authored-by: Michael Vines <mvines@gmail.com>
Co-authored-by: Tyera Eulberg <tyera@solana.com>
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 29, 2022
* Add SPL Token 2022 to the list of known token ids

* Fix tests to accommodate solana-labs#23729

* Test parsing of basic token-2022 instructsions

Co-authored-by: Tyera Eulberg <tyera@solana.com>
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 29, 2022
* Add SPL Token 2022 to the list of known token ids

* Fix tests to accommodate solana-labs#23729

* Test parsing of basic token-2022 instructsions

Co-authored-by: Tyera Eulberg <tyera@solana.com>
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 30, 2022
* Add SPL Token 2022 to the list of known token ids

* Fix tests to accommodate solana-labs#23729

* Test parsing of basic token-2022 instructsions

Co-authored-by: Tyera Eulberg <tyera@solana.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants