Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,19 @@
"light-token/cookbook/overview",
{
"group": "Recipes",
"expanded": true,
"pages": [
"light-token/cookbook/create-mint",
"light-token/cookbook/create-ata",
"light-token/cookbook/create-token-account",
"light-token/cookbook/mint-to",
"light-token/cookbook/close-token-account",
"light-token/cookbook/transfer-interface",
"light-token/cookbook/wrap-unwrap",
"light-token/cookbook/load-ata"
"light-token/cookbook/load-ata",
"light-token/cookbook/close-token-account",
"light-token/cookbook/burn",
"light-token/cookbook/freeze-thaw",
"light-token/cookbook/approve-revoke"
]
}
]
Expand Down
202 changes: 202 additions & 0 deletions light-token/cookbook/approve-revoke.mdx
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
/>
131 changes: 131 additions & 0 deletions light-token/cookbook/burn.mdx
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.
Comment on lines +20 to +22
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix subject‑verb agreement in the burn description.

✏️ Proposed fix
-2. Burned tokens are removed from circulation and decreases the supply tracked on the mint account.
+2. Burned tokens are removed from circulation and decrease the supply tracked on the mint account.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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.
1. Burn permanently destroys tokens by reducing the balance in a token account.
2. Burned tokens are removed from circulation and decrease the supply tracked on the mint account.
3. Only the token account owner (or approved delegate) can burn tokens.
🤖 Prompt for AI Agents
In `@light-token/cookbook/burn.mdx` around lines 20 - 22, The second sentence has
a subject-verb agreement error: in the sentence starting with "Burned tokens are
removed from circulation and decreases the supply tracked on the mint account"
change the verb "decreases" to "decrease" so it agrees with the plural subject
"Burned tokens" (i.e., update the sentence that begins "Burned tokens are
removed from circulation..." to use "decrease the supply tracked on the mint
account").


<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
/>
Loading
Loading