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

[GraphQL]: Token-2022 Extension Instructions #2406

Closed
66 tasks done
buffalojoec opened this issue Apr 2, 2024 · 23 comments · Fixed by #2700
Closed
66 tasks done

[GraphQL]: Token-2022 Extension Instructions #2406

buffalojoec opened this issue Apr 2, 2024 · 23 comments · Fixed by #2700
Labels
enhancement New feature or request GraphQL
Milestone

Comments

@buffalojoec
Copy link
Collaborator

buffalojoec commented Apr 2, 2024

Motivation

Token-2022 extensions are live and gaining popularity on all clusters. The GraphQL library must offer support for these extension instructions within the schema.

  • ConfidentialTransferFee
    • InitializeConfidentialTransferFeeConfig
    • WithdrawWithheldTokensFromMint
    • WithdrawWithheldTokensFromAccounts
    • HarvestWithheldTokensToMint
    • EnableHarvestToMint
    • DisableHarvestToMint
  • ConfidentialTransfer
    • InitializeMint
    • UpdateMint
    • ConfigureAccount
    • ApproveAccount
    • EmptyAccount
    • Deposit
    • Withdraw
    • Transfer
    • ApplyPendingBalance
    • EnableConfidentialCredits
    • DisableConfidentialCredits
    • EnableNonConfidentialCredits
    • DisableNonConfidentialCredits
    • TransferWithSplitProofs
  • CpiGuardInstruction
    • Enable
    • Disable
  • DefaultAccountStateInstruction
    • Initialize
    • Update
  • GroupMemberPointerInstruction
    • Initialize
    • Update
  • GroupPointerInstruction
    • Initialize
    • Update
  • InterestBearingMintInstruction
    • Initialize
    • Update
  • RequiredMemoTransfersInstruction
    • Enable
    • Disable
  • MetadataPointerInstruction
    • Initialize
    • Update
  • InitializeMintCloseAuthority
  • InitializePermanentDelegate
  • Reallocate
  • TokenGroupInstruction
    • InitializeGroup
    • UpdateGroupMaxSize
    • UpdateGroupAuthority
    • InitializeMember
  • TokenMetadataInstruction
    • Initialize
    • UpdateField
    • RemoveKey
    • UpdateAuthority
    • Emit
  • TransferFeeInstruction
    • InitializeTransferFeeConfig
    • TransferCheckedWithFee
    • WithdrawWithheldTokensFromMint
    • WithdrawWithheldTokensFromAccounts
    • HarvestWithheldTokensToMint
  • TransferHookInstruction
    • Initialize
    • Update
@buffalojoec buffalojoec added enhancement New feature or request GraphQL labels Apr 2, 2024
@buffalojoec buffalojoec added this to the GraphQL Debut milestone Apr 2, 2024
@Hrushi20
Copy link
Contributor

Hey! I'm interested in working on this issue. Can I get more context on getting started?

@buffalojoec
Copy link
Collaborator Author

Basically we need to add schema support for Token-2022 extensions. These will appear in a JSON-parsed instruction from an RPC-retrieved transaction or block.

I've marked a little placeholder in the instructions schema module where they can live:

# TODO: Extensions!
# - TransferFeeExtension
# - ConfidentialTransferFeeExtension
# - DefaultAccountStateExtension
# - Reallocate
# - MemoTransferExtension
# - CreateNativeMint
# - InitializeNonTransferableMint
# - InterestBearingMintExtension
# - CpiGuardExtension
# - InitializePermanentDelegate
# - TransferHookExtension
# - ConfidentialTransferFeeExtension
# - WithdrawExcessLamports
# - MetadataPointerExtension

I think the easiest way to roll each of these is to grab their layouts from the Solana Transaction Status crate:
https://github.com/anza-xyz/agave/blob/master/transaction-status/src/parse_token.rs

That file should have all the Token-2022 extensions that are parseable by the RPC's JSON-parsed, and we can just adapt them into GraphQL schema types!

The tricky bit is going to be querying the RPC manually (likely via CLI or something) and finding transaction payloads that have some of these instructions and using them in tests. You can just copy-paste them into the __setup__ module as we've done already:
https://github.com/solana-labs/solana-web3.js/blob/master/packages/rpc-graphql/src/__tests__/__setup__.ts

@Hrushi20
Copy link
Contributor

Looking into it.

@Hrushi20
Copy link
Contributor

Hrushi20 commented Apr 20, 2024

Hey! I was going through transfer_fee.rs file. I see that mint field is stored as a String in json. In rpc-grpc module, in some places mint is used as Account type.. Not sure what is the right data type to use

Edit:
Or Should the type of mint be address?

Hrushi20 added a commit to Hrushi20/solana-web3.js that referenced this issue Apr 20, 2024
Hrushi20 added a commit to Hrushi20/solana-web3.js that referenced this issue Apr 22, 2024
Hrushi20 added a commit to Hrushi20/solana-web3.js that referenced this issue Apr 22, 2024
@buffalojoec
Copy link
Collaborator Author

buffalojoec commented Apr 22, 2024

Hey! I was going through transfer_fee.rs file. I see that mint field is stored as a String in json. In rpc-grpc module, in some places mint is used as Account type.. Not sure what is the right data type to use

Edit: Or Should the type of mint be address?

So, with the way the GraphQL schema is configured, we can choose to use Account where the RPC would otherwise place an address. This allows queries to embed an account query on that address.

In other words, if initializeTransferFeeConfig comes back with:

mint: 'BrdbK35MgB3keCWx87eMpWf5v1QudW9vddxyH2Hb2m5r'

You could do something like:

query notARealQuery {
  transaction(signature: '5UJYEYLqHrdmnMU546Gs3Tj6PTnWPpwjarYAcG7Fp165PTnWPpwjarYAcG7Fp165') {
    instructions {
       ... on TransferFeeInitializeTransferFeeConfig {
         mint {
            lamports
            # More fields from `Account`...
            ... on MintAccount {
              supply
              # More fields from `MintAccount`...
            }
         }
       }
    }
  }
}

Note this only works if you add the field to the schema's resolver!

buffalojoec added a commit that referenced this issue Apr 22, 2024
…ructions to tests

@Hrushi20 here's the mock transaction payload I was talking about for testing.

Sets up for #2406.
buffalojoec added a commit that referenced this issue Apr 22, 2024
…rmanent-delegate

This PR adds support for Token-2022's `InitializePermanentDelegate` extension
in the GraphQL schema.

cc @Hrushi20.

Continuing work on #2406.
buffalojoec added a commit that referenced this issue Apr 22, 2024
This PR adds support for Token-2022's `MetadataPointer` extension
in the GraphQL schema.

cc @Hrushi20.

Continuing work on #2406.
Hrushi20 added a commit to Hrushi20/solana-web3.js that referenced this issue Apr 26, 2024
Hrushi20 added a commit to Hrushi20/solana-web3.js that referenced this issue Apr 26, 2024
Hrushi20 added a commit to Hrushi20/solana-web3.js that referenced this issue Apr 26, 2024
buffalojoec pushed a commit that referenced this issue Apr 27, 2024
* #2406: initializeTransferFeeConfig

* #2406: initializeTransferFeeConfig test

* #2406: Fix lint issue
Hrushi20 added a commit to Hrushi20/solana-web3.js that referenced this issue Apr 27, 2024
Hrushi20 added a commit to Hrushi20/solana-web3.js that referenced this issue Apr 28, 2024
Hrushi20 added a commit to Hrushi20/solana-web3.js that referenced this issue Apr 28, 2024
Hrushi20 added a commit to Hrushi20/solana-web3.js that referenced this issue Apr 28, 2024
Hrushi20 added a commit to Hrushi20/solana-web3.js that referenced this issue Apr 28, 2024
@Hrushi20
Copy link
Contributor

I'm unable to tick the checkbox in the PR.

@nasjuice
Copy link
Contributor

nasjuice commented May 7, 2024

I believe InitializeMint has been done for ConfidentialTransfer

SplToken-2022: InitializeConfidentialTransferMint instruction

@nasjuice
Copy link
Contributor

nasjuice commented May 7, 2024

@buffalojoec
Copy link
Collaborator Author

Also just noticed this

I believe that should be a BigInt since it is a u64

https://github.com/anza-xyz/agave/blob/a645d07e06a5b2da8076539d5799a5087c5cff52/transaction-status/src/parse_token/extension/transfer_fee.rs#L21

Thanks I'll look into this. I think all Int fields in the instructions may need to become BigInt, but I can make that change.

@buffalojoec
Copy link
Collaborator Author

@Hrushi20 @nasjuice Hey guys, let's make sure to use the type aliases, such as Slot, Epoch and Lamports wherever appropriate.

I've added more of them in this PR: #2634.

@buffalojoec
Copy link
Collaborator Author

@Hrushi20 @nasjuice Thank you both for an awesome effort and hammering out all of these extensions!! I'll be sure to shout you guys out in the release.

If there's anything else you're interested in working on, feel free to tag me and ask any questions. As I continue to build the GraphQL demo application, I'll uncover more issues and things that need to be done in the GraphQL library.

The repository is public, and if you have ideas on stuff you want to add/showcase in the demo app, go ahead and dive in! Maybe we can work in the issues here, and over there as well!

https://github.com/buffalojoec/graphql-wallet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request GraphQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants