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

Support token-2022 in RPC instruction parsing #24537

Merged
merged 4 commits into from
Apr 27, 2022

Conversation

CriesofCarrots
Copy link
Contributor

@CriesofCarrots CriesofCarrots commented Apr 20, 2022

Problem

RPC now recognizes the spl_token_2022 program id, but cannot parse all its instructions.

Summary of Changes

Following the changes in #23067, this change set uses the spl_token_2022 to parse Instructions for RPC.
Currently supports only the subset of instructions also supported by the upcoming spl_token library.

It is expected that spl_token_2022 be an exact superset of spl_token, so using spl_token_2022::instruction::Instruction::unpack should be correct for instructions for both token programs. However, we will add tests upstream in SPL to be certain (edit) done here: solana-labs/solana-program-library#3106

Note: I considered parsing extensions in this PR, but discovered that I need the various instruction decoders made pub in a new spl-token-2022 release. So in the interest of moving faster, and smaller PRs, here's the basic functionality.

@CriesofCarrots CriesofCarrots force-pushed the token-2022-ix-parsers branch from 17e0f8b to 9bb3f5d Compare April 20, 2022 21:26
@codecov
Copy link

codecov bot commented Apr 20, 2022

Codecov Report

Merging #24537 (0d5cda3) into master (27a1757) will increase coverage by 11.9%.
The diff coverage is 82.2%.

@@             Coverage Diff             @@
##           master   #24537       +/-   ##
===========================================
+ Coverage    70.0%    82.0%    +11.9%     
===========================================
  Files          37      596      +559     
  Lines        2301   165453   +163152     
  Branches      325        0      -325     
===========================================
+ Hits         1613   135806   +134193     
- Misses        573    29647    +29074     
+ Partials      115        0      -115     

@CriesofCarrots CriesofCarrots marked this pull request as ready for review April 23, 2022 02:46
@CriesofCarrots
Copy link
Contributor Author

Here's an example of a token-2022 transaction that creates a mint with the DefaultTokenState extension (note the unparsed instruction):

$ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0","id":1,"method":"getTransaction","params":["4mTJieejqzYXVjnrEifU98BC2DU87s5ZJrfsW2jN4eHApxW2RgfzoMMDyvwmqngRYDn7DszKLR16HTi1iqcGfttJ", {"encoding":"jsonParsed", "commitment":"confirmed"}]}' 127.0.0.1:8899

{
  "jsonrpc": "2.0",
  "result": {
    "blockTime": 1650658833,
    "meta": {
      "err": null,
      "fee": 10000,
      "innerInstructions": [],
      "loadedAddresses": {
        "readonly": [],
        "writable": []
      },
      "logMessages": [
        "Program 11111111111111111111111111111111 invoke [1]",
        "Program 11111111111111111111111111111111 success",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]",
        "Program log: DefaultAccountStateInstruction::Initialize",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 2508 of 1400000 compute units",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]",
        "Program log: Instruction: InitializeMint",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 4302 of 1397492 compute units",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success"
      ],
      "postBalances": [
        499999999997909000,
        2081040,
        1,
        1009200,
        1
      ],
      "postTokenBalances": [],
      "preBalances": [
        5e+17,
        0,
        1,
        1009200,
        1
      ],
      "preTokenBalances": [],
      "returnData": null,
      "rewards": [],
      "status": {
        "Ok": null
      }
    },
    "slot": 15,
    "transaction": {
      "message": {
        "accountKeys": [
          {
            "pubkey": "CTZ7Q1ZAUY7tmPuadazoSJSUzNiknGTfryYVhpzcfHTj",
            "signer": true,
            "writable": true
          },
          {
            "pubkey": "8w7s2bppTRrfiZewzhazp9TaJsWbysphPUtrAp2DZJaC",
            "signer": true,
            "writable": true
          },
          {
            "pubkey": "11111111111111111111111111111111",
            "signer": false,
            "writable": false
          },
          {
            "pubkey": "SysvarRent111111111111111111111111111111111",
            "signer": false,
            "writable": false
          },
          {
            "pubkey": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
            "signer": false,
            "writable": false
          }
        ],
        "addressTableLookups": null,
        "instructions": [
          {
            "parsed": {
              "info": {
                "lamports": 2081040,
                "newAccount": "8w7s2bppTRrfiZewzhazp9TaJsWbysphPUtrAp2DZJaC",
                "owner": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
                "source": "CTZ7Q1ZAUY7tmPuadazoSJSUzNiknGTfryYVhpzcfHTj",
                "space": 171
              },
              "type": "createAccount"
            },
            "program": "system",
            "programId": "11111111111111111111111111111111"
          },
          {
            "accounts": [
              "8w7s2bppTRrfiZewzhazp9TaJsWbysphPUtrAp2DZJaC"
            ],
            "data": "AQV7",
            "programId": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
          },
          {
            "parsed": {
              "info": {
                "decimals": 2,
                "freezeAuthority": "CTZ7Q1ZAUY7tmPuadazoSJSUzNiknGTfryYVhpzcfHTj",
                "mint": "8w7s2bppTRrfiZewzhazp9TaJsWbysphPUtrAp2DZJaC",
                "mintAuthority": "CTZ7Q1ZAUY7tmPuadazoSJSUzNiknGTfryYVhpzcfHTj",
                "rentSysvar": "SysvarRent111111111111111111111111111111111"
              },
              "type": "initializeMint"
            },
            "program": "spl-token",
            "programId": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
          }
        ],
        "recentBlockhash": "Cr2RA2syApCJK28vo25teQmgQikwHTQ8zbkQD1Uc1Dp5"
      },
      "signatures": [
        "4mTJieejqzYXVjnrEifU98BC2DU87s5ZJrfsW2jN4eHApxW2RgfzoMMDyvwmqngRYDn7DszKLR16HTi1iqcGfttJ",
        "5qwDWkSYzxWmwfvqSxQwh6GeXRNVeTDKYWQATFw5GXPPFyqXir74JrSDiKU5eCwZhJuM2rxg3uJYy29EserK9KUU"
      ]
    }
  },
  "id": 1
}

joncinque
joncinque previously approved these changes Apr 25, 2022
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.

Just the one question about closable mints, but otherwise the rest of this is good to go for spl-token-v3 compatibility

joncinque
joncinque previously approved these changes Apr 26, 2022
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.

Looks good!

@CriesofCarrots CriesofCarrots force-pushed the token-2022-ix-parsers branch from 7980b1c to 5f3b4a7 Compare April 27, 2022 04:26
@mergify mergify bot dismissed joncinque’s stale review April 27, 2022 04:31

Pull request has been modified.

@CriesofCarrots CriesofCarrots force-pushed the token-2022-ix-parsers branch from f10bb2f to 6e9c61a Compare April 27, 2022 15:21
@CriesofCarrots CriesofCarrots added the automerge Merge this Pull Request automatically once CI passes label Apr 27, 2022
@mergify mergify bot removed the automerge Merge this Pull Request automatically once CI passes label Apr 27, 2022
@mergify
Copy link
Contributor

mergify bot commented Apr 27, 2022

automerge label removed due to a CI failure

@CriesofCarrots CriesofCarrots force-pushed the token-2022-ix-parsers branch from 6e9c61a to 0d5cda3 Compare April 27, 2022 17:13
@CriesofCarrots CriesofCarrots added the automerge Merge this Pull Request automatically once CI passes label Apr 27, 2022
@mergify mergify bot merged commit a1b066a into solana-labs:master Apr 27, 2022
@CriesofCarrots
Copy link
Contributor Author

\o/

jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 29, 2022
* Use token-2022 dependency in parse_token and add tests for new variants

* Remove test hack

* Bump spl-token-2022 and use new AuthorityType::CloseMint

* Add zk-token-sdk to patch-crates.sh
@joncinque joncinque added the v1.10 label Aug 5, 2022
mergify bot pushed a commit that referenced this pull request Aug 5, 2022
* Use token-2022 dependency in parse_token and add tests for new variants

* Remove test hack

* Bump spl-token-2022 and use new AuthorityType::CloseMint

* Add zk-token-sdk to patch-crates.sh

(cherry picked from commit a1b066a)

# Conflicts:
#	Cargo.lock
#	account-decoder/Cargo.toml
#	client/Cargo.toml
#	programs/bpf/Cargo.lock
#	rpc/Cargo.toml
#	transaction-status/Cargo.toml
#	transaction-status/src/parse_token.rs
mergify bot added a commit that referenced this pull request Aug 5, 2022
* Support token-2022 in RPC instruction parsing (#24537)

* Use token-2022 dependency in parse_token and add tests for new variants

* Remove test hack

* Bump spl-token-2022 and use new AuthorityType::CloseMint

* Add zk-token-sdk to patch-crates.sh

(cherry picked from commit a1b066a)

# Conflicts:
#	Cargo.lock
#	account-decoder/Cargo.toml
#	client/Cargo.toml
#	programs/bpf/Cargo.lock
#	rpc/Cargo.toml
#	transaction-status/Cargo.toml
#	transaction-status/src/parse_token.rs

* Fix merge conflicts

Co-authored-by: Tyera Eulberg <tyera@solana.com>
Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
automerge Merge this Pull Request automatically once CI passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants