Skip to content
Merged
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
3 changes: 2 additions & 1 deletion docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"group": "Examples",
"expanded": true,
"pages": [
"light-token/examples/client"
"light-token/examples/client",
"light-token/examples/program"
]
},
{
Expand Down
Binary file added light-terms.skill
Binary file not shown.
131 changes: 129 additions & 2 deletions light-token/cookbook/approve-revoke.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ import RevokeAnchorProgramCode from "/snippets/code-snippets/light-token/revoke/
### Approve or revoke delegates

<Info>
Find the full example including shared test utilities in the
[examples-light-token](https://github.com/Lightprotocol/examples-light-token/tree/main/rust-client).
View the [source code](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-libs/token-sdk/src/instruction/approve.rs) and [full example](https://github.com/Lightprotocol/examples-light-token/blob/main/rust-client/instructions/approve.rs) with shared test utilities.
</Info>

<Tabs>
Expand Down Expand Up @@ -161,6 +160,134 @@ import RevokeAnchorProgramCode from "/snippets/code-snippets/light-token/revoke/
</Steps>
</Tab>

<Tab title="Program">

<Note>
Find [a full code example at the end](#full-code-example).
</Note>

<Tabs>
<Tab title="Approve">
<Steps>
<Step>

### Build Account Infos and CPI the Light Token Program

Use `invoke` for external signers or `invoke_signed` when the authority is a PDA.

<Tabs>
<Tab title="invoke (External signer)">

```rust
use light_token::instruction::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::instruction::ApproveCpi;

let approve_cpi = ApproveCpi {
token_account: token_account.clone(),
delegate: delegate.clone(),
owner: owner.clone(),
system_program: system_program.clone(),
amount,
};

let signer_seeds: &[&[u8]] = &[TOKEN_ACCOUNT_SEED, &[bump]];
approve_cpi.invoke_signed(&[signer_seeds])?;
```

</Tab>
</Tabs>

</Step>
</Steps>
</Tab>

<Tab title="Revoke">
<Steps>
<Step>

### Build Account Infos and CPI the Light Token Program

Use `invoke` for external signers or `invoke_signed` when the authority is a PDA.

<Tabs>
<Tab title="invoke (External signer)">

```rust
use light_token::instruction::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::instruction::RevokeCpi;

let revoke_cpi = RevokeCpi {
token_account: token_account.clone(),
owner: owner.clone(),
system_program: system_program.clone(),
};

let signer_seeds: &[&[u8]] = &[TOKEN_ACCOUNT_SEED, &[bump]];
revoke_cpi.invoke_signed(&[signer_seeds])?;
```

</Tab>
</Tabs>

</Step>
</Steps>
</Tab>
</Tabs>

# Full Code Example

<Tabs>
<Tab title="Approve">

<Info>
View the [source code](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-libs/token-sdk/src/instruction/approve.rs) and [full example](https://github.com/Lightprotocol/examples-light-token/tree/main/programs/anchor/basic-instructions/approve) with shared test utilities.
</Info>

<ApproveAnchorProgramCode />

</Tab>

<Tab title="Revoke">

<Info>
View the [source code](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-libs/token-sdk/src/instruction/revoke.rs) and [full example](https://github.com/Lightprotocol/examples-light-token/tree/main/programs/anchor/basic-instructions/revoke) with shared test utilities.
</Info>

<RevokeAnchorProgramCode />

</Tab>
</Tabs>

</Tab>

</Tabs>

# Next Steps
Expand Down
70 changes: 67 additions & 3 deletions light-token/cookbook/burn.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "/snippets/code-samples/code-compare-snippets.jsx";
import RustInstructionCode from "/snippets/code-snippets/light-token/burn/rust-client/instruction.mdx";
import BurnCheckedRustInstructionCode from "/snippets/code-snippets/light-token/burn-checked/rust-client/instruction.mdx";

import AnchorProgramCode from "/snippets/code-snippets/light-token/burn/anchor-program/full-example.mdx";


1. Burn permanently destroys tokens by reducing the balance in a token account.
Expand Down Expand Up @@ -47,8 +47,7 @@ Compare to SPL:
### Burn Light Tokens

<Info>
Find the full example including shared test utilities in the
[examples-light-token](https://github.com/Lightprotocol/examples-light-token/tree/main/rust-client).
View the [source code](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-libs/token-sdk/src/instruction/burn.rs) and [full example](https://github.com/Lightprotocol/examples-light-token/blob/main/rust-client/instructions/burn.rs) with shared test utilities.
</Info>

<Tabs>
Expand All @@ -60,6 +59,71 @@ Compare to SPL:
</Steps>
</Tab>

<Tab title="Program">

<Note>
Find [a full code example at the end](#full-code-example).
</Note>

<Steps>
<Step>

### Build Account Infos and CPI the Light Token Program

Use `invoke` for external signers or `invoke_signed` when the authority is a PDA.

<Tabs>
<Tab title="invoke (External signer)">

```rust
use light_token::instruction::BurnCpi;

BurnCpi {
source: source.clone(),
mint: mint.clone(),
amount,
authority: authority.clone(),
system_program: system_program.clone(),
fee_payer: None,
max_top_up: None,
}
.invoke()
```

</Tab>
<Tab title="invoke_signed (PDA owner)">

```rust
use light_token::instruction::BurnCpi;

BurnCpi {
source: source.clone(),
mint: mint.clone(),
amount,
authority: authority.clone(),
system_program: system_program.clone(),
fee_payer: None,
max_top_up: None,
}
.invoke_signed(&[signer_seeds])
```
Comment on lines +96 to +109
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

Undefined signer_seeds variable and missing error propagation.

The invoke_signed example references signer_seeds on line 108 but doesn't define it. Add the seed definition for completeness:

Proposed fix
 use light_token::instruction::BurnCpi;

+let signer_seeds: &[&[u8]] = &[OWNER_SEED, &[bump]];
+
 BurnCpi {
     source: source.clone(),
     mint: mint.clone(),
     amount,
     authority: authority.clone(),
     system_program: system_program.clone(),
     fee_payer: None,
     max_top_up: None,
 }
-.invoke_signed(&[signer_seeds])
+.invoke_signed(&[signer_seeds])?;
+Ok(())
🤖 Prompt for AI Agents
In `@light-token/cookbook/burn.mdx` around lines 96 - 109, Define the missing
signer_seeds and propagate the CPI error: add a signer_seeds variable (e.g., let
signer_seeds: &[&[&[u8]]] = /* your PDA seed slices and bump */) and pass that
to BurnCpi.invoke_signed, then propagate the Result (use the ? operator or
return the Result) instead of ignoring it; reference the BurnCpi invocation
(BurnCpi { ... }.invoke_signed(...)) and ensure the signer_seeds shape matches
the expected invoke_signed parameter.


</Tab>
</Tabs>

</Step>
</Steps>

# Full Code Example

<Info>
View the [source code](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-libs/token-sdk/src/instruction/burn.rs) and [full example](https://github.com/Lightprotocol/examples-light-token/tree/main/programs/anchor/basic-instructions/burn) with shared test utilities.
</Info>

<AnchorProgramCode />

</Tab>

</Tabs>

# Next Steps
Expand Down
69 changes: 67 additions & 2 deletions light-token/cookbook/close-token-account.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ keywords: ["close token account on solana", "reclaim rent on solana"]

---

import CloseAccountInfosAccountsList from "/snippets/accounts-list/close-account-infos-accounts-list.mdx";
import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx";
import ClientCustomRentConfig from "/snippets/light-token-guides/client-custom-rent-config.mdx";
import { CodeCompare } from "/snippets/jsx/code-compare.jsx";
Expand All @@ -15,6 +16,7 @@ import {
lightCloseAccountRustCode,
} from "/snippets/code-samples/code-compare-snippets.jsx";
import RustInstructionCode from "/snippets/code-snippets/light-token/close-token-account/rust-client/instruction.mdx";
import AnchorProgramCode from "/snippets/code-snippets/light-token/close-token-account/anchor-program/full-example.mdx";

1. Closing a Light Token account transfers remaining lamports to a destination account and the rent sponsor can reclaim sponsored rent.
2. Light token accounts can be closed by the owner.
Expand Down Expand Up @@ -52,8 +54,7 @@ Compare to SPL:
### Close Light Token Account

<Info>
Find the full example including shared test utilities in the
[examples-light-token](https://github.com/Lightprotocol/examples-light-token/tree/main/rust-client).
View the [source code](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-libs/token-sdk/src/instruction/close.rs) and [full example](https://github.com/Lightprotocol/examples-light-token/blob/main/rust-client/instructions/close.rs) with shared test utilities.
</Info>

<Tabs>
Expand All @@ -66,6 +67,70 @@ Compare to SPL:
</Steps>
</Tab>

<Tab title="Program">

<Note>
Find [a full code example at the end](#full-code-example).
</Note>
<Steps>
<Step>

### Build Account Infos and CPI the Light Token Program

Use `invoke` for external signers or `invoke_signed` when the authority is a PDA.

<Tabs>
<Tab title="invoke (External signer)">

```rust
use light_token::instruction::CloseAccountCpi;

CloseAccountCpi {
token_program: token_program.clone(),
account: account.clone(),
destination: destination.clone(),
owner: owner.clone(),
rent_sponsor: rent_sponsor.clone(),
}
.invoke()?;
```

</Tab>
<Tab title="invoke_signed (PDA owner)">

```rust
use light_token::instruction::CloseAccountCpi;

CloseAccountCpi {
token_program: token_program.clone(),
account: account.clone(),
destination: destination.clone(),
owner: owner.clone(),
rent_sponsor: rent_sponsor.clone(),
}
.invoke_signed(&[signer_seeds])?;
```

</Tab>
</Tabs>

<Accordion title="Account List">
<CloseAccountInfosAccountsList />
</Accordion>

</Step>
</Steps>

# Full Code Example

<Info>
View the [source code](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-libs/token-sdk/src/instruction/close.rs) and [full example](https://github.com/Lightprotocol/examples-light-token/tree/main/programs/anchor/basic-instructions/close) with shared test utilities.
</Info>

<AnchorProgramCode />

</Tab>

</Tabs>

# Next Steps
Expand Down
Loading
Loading