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

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
Contributor

@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
Contributor

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
Contributor

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
Contributor

@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
Contributor

@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
Contributor

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
Contributor

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
Copy link
Contributor

Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants