generated from mintlify/starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Add native programs and Rust client cookbook #14
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
Open
tilo-14
wants to merge
10
commits into
main
Choose a base branch
from
add-native-programs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
319d203
add cookbook rust client
8924f12
add cookbook rust client
af32503
add cookbook rust client
59e8429
component fix
ff3a6e5
update stream toolkit
02a5287
ata program
ffe985c
program tabs
979d714
program tabs reorder
1208e74
reduce shimmmer
59bfb77
links and program examples
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| --- | ||
| title: Approve and Revoke Delegates | ||
| sidebarTitle: Approve / Revoke | ||
| description: Rust client guide to approve and revoke delegates for light-token accounts. Includes step-by-step implementation and full code examples. | ||
| keywords: ["approve delegate solana", "revoke delegate solana", "token delegation"] | ||
| --- | ||
|
|
||
| --- | ||
|
|
||
| import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; | ||
| import { CodeCompare } from "/snippets/jsx/code-compare.jsx"; | ||
| import { | ||
| splApproveRustCode, | ||
| lightApproveRustCode, | ||
| splRevokeRustCode, | ||
| lightRevokeRustCode, | ||
| } from "/snippets/code-samples/code-compare-snippets.jsx"; | ||
| import ApproveFull from "/snippets/code-snippets/light-token/approve-revoke/rust-client/approve-full.mdx"; | ||
| import RevokeFull from "/snippets/code-snippets/light-token/approve-revoke/rust-client/revoke-full.mdx"; | ||
| import NativeProgram from "/snippets/code-snippets/light-token/approve-revoke/program/native.mdx"; | ||
| import AnchorProgram from "/snippets/code-snippets/light-token/approve-revoke/program/anchor.mdx"; | ||
|
|
||
| 1. Approve grants a delegate permission to transfer up to a specified amount of tokens from your account. | ||
| * Each token account can have only one delegate at a time. | ||
| * Any new approval overwrites the previous one. | ||
| 2. Revoke removes all delegate permissions from a light-token account. | ||
| 3. Only the token account owner can approve or revoke delegates. | ||
|
|
||
| <Tabs> | ||
| <Tab title="Rust Client"> | ||
|
|
||
| <Tabs> | ||
| <Tab title="Approve"> | ||
|
|
||
| <CodeCompare | ||
| firstCode={lightApproveRustCode} | ||
| secondCode={splApproveRustCode} | ||
| firstLabel="light-token" | ||
| secondLabel="SPL" | ||
| language="rust" | ||
| /> | ||
|
|
||
| </Tab> | ||
| <Tab title="Revoke"> | ||
|
|
||
| <CodeCompare | ||
| firstCode={lightRevokeRustCode} | ||
| secondCode={splRevokeRustCode} | ||
| firstLabel="light-token" | ||
| secondLabel="SPL" | ||
| language="rust" | ||
| /> | ||
|
|
||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| <Steps> | ||
| <Step> | ||
| ### Prerequisites | ||
|
|
||
| <TokenClientPrerequisites /> | ||
|
|
||
| </Step> | ||
|
|
||
| <Step> | ||
| ### Approve or revoke delegates | ||
|
|
||
| <Info> | ||
| View [Source Code](https://github.com/Lightprotocol/light-protocol/tree/main/sdk-libs/token-sdk/src/token) or find full examples with tests: [examples-light-token](https://github.com/Lightprotocol/examples-light-token/tree/main/rust-client). | ||
| </Info> | ||
|
|
||
| <Tabs> | ||
| <Tab title="Approve"> | ||
|
|
||
| <ApproveFull /> | ||
|
|
||
| </Tab> | ||
| <Tab title="Revoke"> | ||
|
|
||
| <RevokeFull /> | ||
|
|
||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| </Step> | ||
| </Steps> | ||
| </Tab> | ||
|
|
||
| <Tab title="Program Guide"> | ||
|
|
||
| <Steps> | ||
| <Step> | ||
|
|
||
| ### Approve | ||
|
|
||
| <Tabs> | ||
| <Tab title="invoke (External Signer)"> | ||
|
|
||
| ```rust | ||
| use light_token_sdk::token::ApproveCpi; | ||
|
|
||
| ApproveCpi { | ||
| token_account: token_account.clone(), | ||
| delegate: delegate.clone(), | ||
| owner: owner.clone(), | ||
| system_program: system_program.clone(), | ||
| amount, | ||
| } | ||
| .invoke() | ||
| ``` | ||
|
|
||
| </Tab> | ||
| <Tab title="invoke_signed (PDA Owner)"> | ||
|
|
||
| ```rust | ||
| use light_token_sdk::token::ApproveCpi; | ||
|
|
||
| let signer_seeds = authority_seeds!(bump); | ||
|
|
||
| ApproveCpi { | ||
| token_account: token_account.clone(), | ||
| delegate: delegate.clone(), | ||
| owner: owner.clone(), | ||
| system_program: system_program.clone(), | ||
| amount, | ||
| } | ||
| .invoke_signed(&[signer_seeds]) | ||
| ``` | ||
|
|
||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| </Step> | ||
|
|
||
| <Step> | ||
|
|
||
| ### Revoke | ||
|
|
||
| <Tabs> | ||
| <Tab title="invoke (External Signer)"> | ||
|
|
||
| ```rust | ||
| use light_token_sdk::token::RevokeCpi; | ||
|
|
||
| RevokeCpi { | ||
| token_account: token_account.clone(), | ||
| owner: owner.clone(), | ||
| system_program: system_program.clone(), | ||
| } | ||
| .invoke() | ||
| ``` | ||
|
|
||
| </Tab> | ||
| <Tab title="invoke_signed (PDA Owner)"> | ||
|
|
||
| ```rust | ||
| use light_token_sdk::token::RevokeCpi; | ||
|
|
||
| let signer_seeds = authority_seeds!(bump); | ||
|
|
||
| RevokeCpi { | ||
| token_account: token_account.clone(), | ||
| owner: owner.clone(), | ||
| system_program: system_program.clone(), | ||
| } | ||
| .invoke_signed(&[signer_seeds]) | ||
| ``` | ||
|
|
||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| </Step> | ||
| </Steps> | ||
|
|
||
| # Full Code Example | ||
|
|
||
| <Info> | ||
| View [Source Code](https://github.com/Lightprotocol/light-protocol/tree/main/programs/compressed-token/program/src/ctoken/approve_revoke.rs) or full examples with tests: [examples-light-token](https://github.com/Lightprotocol/examples-light-token/tree/main/program-examples). | ||
| </Info> | ||
|
|
||
| <Tabs> | ||
| <Tab title="Anchor"> | ||
| <AnchorProgram /> | ||
| </Tab> | ||
| <Tab title="Native"> | ||
| <NativeProgram /> | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| </Tab> | ||
|
|
||
| </Tabs> | ||
|
|
||
| # Next Steps | ||
|
|
||
| <Card | ||
| title="Use the Unified Transfer Interface for Light-Token, SPL and Token 22 Transfers" | ||
| icon="chevron-right" | ||
| color="#0066ff" | ||
| href="/light-token/cookbook/transfer-interface" | ||
| horizontal | ||
| /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| --- | ||
| title: Burn Light Tokens | ||
| sidebarTitle: Burn Light Tokens | ||
| description: Rust client guide to burn light-tokens. Includes step-by-step implementation and full code examples. | ||
| keywords: ["burn tokens on solana", "destroy tokens solana", "reduce token supply"] | ||
| --- | ||
|
|
||
| --- | ||
|
|
||
| import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; | ||
| import { CodeCompare } from "/snippets/jsx/code-compare.jsx"; | ||
| import { | ||
| splBurnRustCode, | ||
| lightBurnRustCode, | ||
| } from "/snippets/code-samples/code-compare-snippets.jsx"; | ||
| import RustFullCode from "/snippets/code-snippets/light-token/burn/rust-client/full.mdx"; | ||
| import NativeProgram from "/snippets/code-snippets/light-token/burn/program/native.mdx"; | ||
| import AnchorProgram from "/snippets/code-snippets/light-token/burn/program/anchor.mdx"; | ||
|
|
||
| 1. Burn permanently destroys tokens by reducing the balance in a token account. | ||
| 2. Burned tokens are removed from circulation and decreases the supply tracked on the mint account. | ||
| 3. Only the token account owner (or approved delegate) can burn tokens. | ||
|
|
||
| <Tabs> | ||
| <Tab title="Rust Client"> | ||
|
|
||
| Compare to SPL: | ||
|
|
||
| <CodeCompare | ||
| firstCode={lightBurnRustCode} | ||
| secondCode={splBurnRustCode} | ||
| firstLabel="light-token" | ||
| secondLabel="SPL" | ||
| language="rust" | ||
| /> | ||
|
|
||
| <Steps> | ||
| <Step> | ||
| ### Prerequisites | ||
|
|
||
| <TokenClientPrerequisites /> | ||
|
|
||
| </Step> | ||
|
|
||
| <Step> | ||
| ### Burn light-tokens | ||
|
|
||
| <Info> | ||
| View [Source Code](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-libs/token-sdk/src/token/burn.rs) or find full examples with tests: [examples-light-token](https://github.com/Lightprotocol/examples-light-token/tree/main/rust-client). | ||
| </Info> | ||
|
|
||
| <RustFullCode /> | ||
| </Step> | ||
| </Steps> | ||
| </Tab> | ||
|
|
||
| <Tab title="Program Guide"> | ||
|
|
||
| <Steps> | ||
| <Step> | ||
|
|
||
| ### Build Account Infos and CPI | ||
|
|
||
| <Tabs> | ||
| <Tab title="invoke (External Signer)"> | ||
|
|
||
| ```rust | ||
| use light_token_sdk::token::BurnCpi; | ||
|
|
||
| BurnCpi { | ||
| source: source.clone(), | ||
| mint: mint.clone(), | ||
| amount, | ||
| authority: authority.clone(), | ||
| max_top_up: None, | ||
| } | ||
| .invoke() | ||
| ``` | ||
|
|
||
| </Tab> | ||
| <Tab title="invoke_signed (PDA Authority)"> | ||
|
|
||
| ```rust | ||
| use light_token_sdk::token::BurnCpi; | ||
|
|
||
| let signer_seeds = authority_seeds!(bump); | ||
|
|
||
| BurnCpi { | ||
| source: source.clone(), | ||
| mint: mint.clone(), | ||
| amount, | ||
| authority: authority.clone(), | ||
| max_top_up: None, | ||
| } | ||
| .invoke_signed(&[signer_seeds]) | ||
| ``` | ||
|
|
||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| </Step> | ||
| </Steps> | ||
|
|
||
| # Full Code Example | ||
|
|
||
| <Info> | ||
| View [Source Code](https://github.com/Lightprotocol/light-protocol/tree/main/programs/compressed-token/program/src/ctoken/burn.rs) or full examples with tests: [examples-light-token](https://github.com/Lightprotocol/examples-light-token/tree/main/program-examples). | ||
| </Info> | ||
|
|
||
| <Tabs> | ||
| <Tab title="Anchor"> | ||
| <AnchorProgram /> | ||
| </Tab> | ||
| <Tab title="Native"> | ||
| <NativeProgram /> | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| </Tab> | ||
|
|
||
| </Tabs> | ||
|
|
||
| # Next Steps | ||
|
|
||
| <Card | ||
| title="Freeze and Thaw Light Token Accounts" | ||
| icon="chevron-right" | ||
| color="#0066ff" | ||
| href="/light-token/cookbook/freeze-thaw" | ||
| horizontal | ||
| /> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix subject‑verb agreement in the burn description.
✏️ Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents