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

Add Token Extension 2022 Extension schema in Graphql along with tests. #2535

Closed

Conversation

Hrushi20
Copy link
Contributor

@Hrushi20 Hrushi20 commented Apr 20, 2024

  • TransferFeeExtension
  • ConfidentialTransferFeeExtension
  • DefaultAccountStateExtension
  • Reallocate
  • MemoTransferExtension
  • CreateNativeMint
  • InitializeNonTransferableMint
  • InterestBearingMintExtension
  • CpiGuardExtension
  • InitializePermanentDelegate
  • TransferHookExtension
  • ConfidentialTransferFeeExtension
  • WithdrawExcessLamports
  • MetadataPointerExtension

Additional:

Need to add tests to above schemas.

Copy link

changeset-bot bot commented Apr 20, 2024

⚠️ No Changeset found

Latest commit: c972cc6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mergify mergify bot added the community label Apr 20, 2024
@mergify mergify bot requested a review from a team April 20, 2024 07:52
@Hrushi20
Copy link
Contributor Author

@buffalojoec, can you review the sample TransferFeeExtension schema?

Copy link
Collaborator

@buffalojoec buffalojoec left a comment

Choose a reason for hiding this comment

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

Here's what initializeTransferFeeConfig looks like on the RPC if you just create a token using the CLI on the local validator and then query the transaction.

"instructions": [
    {
        "parsed": {
            "info": {
                "lamports": 2825760,
                "newAccount": "EXXcv32qEKo7nfs4dKnseB977Ky9qpedQzeqLG2nD8kJ",
                "owner": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
                "source": "2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB",
                "space": 278
            },
            "type": "createAccount"
        },
        "program": "system",
        "programId": "11111111111111111111111111111111",
        "stackHeight": null
    },
    {
        "parsed": {
            "info": {
                "maximumFee": 5000,
                "mint": "EXXcv32qEKo7nfs4dKnseB977Ky9qpedQzeqLG2nD8kJ",
                "transferFeeBasisPoints": 50,
                "transferFeeConfigAuthority": "2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB",
                "withdrawWithheldAuthority": "2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB"
            },
            "type": "initializeTransferFeeConfig"
        },
        "program": "spl-token",
        "programId": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
        "stackHeight": null
    },
    {
        "parsed": {
            "info": {
                "decimals": 9,
                "mint": "EXXcv32qEKo7nfs4dKnseB977Ky9qpedQzeqLG2nD8kJ",
                "mintAuthority": "2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB",
                "rentSysvar": "SysvarRent111111111111111111111111111111111"
            },
            "type": "initializeMint"
        },
        "program": "spl-token",
        "programId": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
        "stackHeight": null
    }
],

As you can see, the transaction-status, and therefore the jsonParsed module of the RPC, just treats Token-2022 extension instructions as any old Token-2022 instruction.

Let's do exactly that with GraphQL! Here's an example of what I mean:

type SplToken2022InitializeTransferFeeConfigInstruction implements TransactionInstrucion {
  programId: Address
  maximumFee: BigInt
  mint: Account
  transferFeeConfigAuthority: Account
  withdrawWithheldAuthority: Account
}

What do you think?

Comment on lines +518 to +535
type TransferFeeExtension {
mint: String
transferFeeBasisPoints: Int
maximumFee: Int
transferFeeConfigAuthority: String
withdrawWithheldAuthority: String
source: String
destination: String
tokenAmount: TokenAmount
feeAmount: TokenAmount
signers: [Address]
authority: String
multisigWithdrawWithheldAuthority: String
feeRecipient: String
sourceAccounts: [String]
multisigtransferFeeConfigAuthority: String
multisigAuthority: String
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

TransferFeeExtension actually has its own set of instructions, as each extension does. I think you've globbed together all of them here:

  • TransferCheckedWithFee
  • WithdrawWithheldTokensFromMint
  • WithdrawWithheldTokensFromAccounts
  • HarvestWithheldTokensToMint
  • SetTransferFee

@buffalojoec
Copy link
Collaborator

As I mentioned in my comment here, all Token-2022 extensions actually have their own set of instructions (sometimes just one), and we can just treat each of those instructions as individual Token-2022 instructions!

@buffalojoec
Copy link
Collaborator

@Hrushi20 Thanks for taking on this effort. I'm pumped we're going to be adding support for Token-2022 extensions!

I have a few suggestions, if you don't mind.

For starters, maybe let's use the issue to track the overall effort, and then just do one PR per extension, where you add the extension to the schema and add a test? They'll all be super small but it will be easier to track as we go. I can update the issue with a list of all instructions if that's easier?

To start the process off, it might be a huge help to create a token on the CLI that has every single extension possible, and just copy-paste that transaction into the __setup__.ts test module to use for all your tests!

@buffalojoec
Copy link
Collaborator

@Hrushi20 I've updated the issue with the big list of all extensions. #2406 (comment)

And I've also added a PR with a mock transaction! #2544

@Hrushi20
Copy link
Contributor Author

Hey! Thanks a lot for explaining and helping me out. I'll start of by creating a token having all extensions and adding it to __setup.js. Then we add incrementally add schema and test them separately in different PR's.

@buffalojoec
Copy link
Collaborator

Hey! Thanks a lot for explaining and helping me out. I'll start of by creating a token having all extensions and adding it to __setup.js. Then we add incrementally add schema and test them separately in different PR's.

I did this already! I linked a PR in my previous comment where I laid this up. If you follow the Graphite stack I also did a couple extensions with tests, as reference.
#2535 (comment)

@Hrushi20
Copy link
Contributor Author

I missed that comment. Too late here in my country. Will work on this tmr. Thanks :)

@buffalojoec
Copy link
Collaborator

I think we can close this, since we've rallied around the issue and you've got a few other PR's in flight!

@buffalojoec buffalojoec closed this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants