Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Add Token Extensions (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
urani-engineering-helper authored Mar 29, 2024
1 parent b0334c5 commit 2b7d373
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 31 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ Compared to older platforms like Bitcoin and EVM-based protocols, Solana is:
* **[4. Program Derived Addresses](chapters/04_pda.md)**
* **[5. Events and Communication](chapters/05_events.md)**
* **[6. Mastering Solana Frontend](chapters/06_frontend.md)**
* **[7. Mastering Transfer Hooks](chapters/07_transfer_hooks.md)**
* **[8. Mastering Security on Solana](chapters/08_security.md)**
* **[9. Mastering Mobile Development](chapters/09_mobile.md)**
* **[10. Additional Resources](chapters/10_additional_resources.md)**
* **[7. Mastering Transfer Extensions](chapters/07_transfer_extensions.md)**
* **[8. Mastering Transfer Hooks](chapters/08_transfer_hooks.md)**
* **[9. Mastering Security on Solana](chapters/09_security.md)**
* **[10. Mastering Mobile Development](chapters/10_mobile.md)**
* **[11. Additional Resources](chapters/11_additional_resources.md)**



Expand All @@ -54,7 +55,7 @@ Compared to older platforms like Bitcoin and EVM-based protocols, Solana is:
* **[Demo 2. Anchor and CPI](demos/backend/02_anchor_cpi)**
* **[Demo 3. Program Derived Addresses](demos/backend/03_anchor_pda)**
* **[Demo 4: PDA and CPI on Anchor](demos/backend/04_pda_and_cpi)**
* **[Demo 5: Transfer Hooks](demos/backend/05_transfer_hooks)**
* **[Demo 5: Transfer Hooks for Vesting](demos/backend/05_transfer_hooks)**

<br>

Expand Down
6 changes: 3 additions & 3 deletions chapters/04_pda.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub struct UserStats {
* A program with global state:

```javascript
const [pda, bump] = await findProgramAddress(Buffer.from("GLOBAL_STATE"), programId)
const [pda, bump] = await findProgramAddress(Buffer.from("GLOBAL_STATE"), program_id)
```

<br>
Expand All @@ -139,7 +139,7 @@ const [pda, bump] = await web3.PublicKey.findProgramAddress(
[
publicKey.toBuffer()
],
programId
program_id
)
```

Expand All @@ -153,7 +153,7 @@ const [pda, bump] = await web3.PublicKey.findProgramAddress(
publicKey.toBuffer(),
Buffer.from("Shopping list")
],
programId,
program_id,
);
```

Expand Down
8 changes: 4 additions & 4 deletions chapters/06_frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@
- Like records in a database, with the address being the primary key used to look up the values inside.

* PDAs do not have a corresponding secret key.
- To store and locate data, we derive a PDA using the `findProgramAddress(seeds, programid)` method.
- To store and locate data, we derive a PDA using the `findProgramAddress(seeds, program_id)` method.

* The accounts belonging to a program can be retrieved with `getProgramAccounts(programId)`.
* The accounts belonging to a program can be retrieved with `getProgramAccounts(program_id)`.
- Account data needs to be deserialized using the same layout used to store it in the first place.
- Accounts created by a program can be fetched with `connection.getProgramAccounts(programId)`.
- Accounts created by a program can be fetched with `connection.getProgramAccounts(program_id)`.



Expand All @@ -141,7 +141,7 @@

```javascript
const accountsWithoutData = await connection.getProgramAccounts(
programId,
program_id,
{
dataSlice: { offset: 0, length: 0 }
}
Expand Down
56 changes: 56 additions & 0 deletions chapters/07_transfer_extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 🛹 Token Extensions

<br>

### tl; dr

<br>

* Solana ecosystem faced a demand for enhanced token features:
- Before, expanding the capabilities of tokens required forking the existing Token Program, which introduced challenges due to architectural requirements for transactions specifying the involved programs and accounts.

* Token-2022 was created to add new token functionality, with minimal disruption to users, wallets, and dApps.
- This enabled Token Extensions, introducing a suite of program-level enhancements such as confidential transactions, customizable transfer logic, and enriched metadata.


<br>

---

### Creating a Token with Token Extensions

<br>

* You can use the [Solana Tool Suite]() to create tokens with a CLI:

<br>

```rust
spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token <extension flags>
```

<br>

* These are the flags to add to create tokens with each type of extension:
- Mint Close Authority: `--enable-close`
- Transfer Fees :`--transfer-fee <basis points> <max fee>`
- Non-Transferable: `--enable-non-transferable``
- Interest-Bearing: `--interest-rate <rate>`
- Permanent Delegate: `--enable-permanent-delegate`
- Transfer Hook: `--transfer-hook <programID>`
- Metadata: `--enable-metadata`
- Metadata Pointer: `--metadata-address <accountId>`
- Confidential Transfers: `--enable-confidential-transfers auto`



<br>

---

### References

<br>


* [Token Extensions on Solana Developer Guides](https://www.youtube.com/playlist?list=PLilwLeBwGuK6imBuGLSLmzMEyj6yVHGDO)
22 changes: 4 additions & 18 deletions chapters/07_transfer_hooks.md → chapters/08_transfer_hooks.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 🛹 Transfer Hooks
# 🛹 Transfer Hooks

<br>

Expand All @@ -7,24 +7,11 @@

<br>

* The Transfer Hook Interface, introduced within the Solana Program Library, allows token creators to "hook" additional custom logic into token transfers to shape the dynamics of users' and tokens' interactions.
* The [Transfer Hook Interface](https://spl.solana.com/transfer-hook-interface), introduced within the [Solana Program Library](https://spl.solana.com/) allows token creators to "hook" additional custom logic into token transfers to shape the dynamics of users' and tokens' interactions.


<br>

---

### Token-2022 and Token Extensions

<br>

* Solana ecosystem faced a demand for enhanced token features:
- Before, expanding the capabilities of tokens required forking the existing Token Program, which introduced challenges due to architectural requirements for transactions specifying the involved programs and accounts.

* Token-2022 was created to add new token functionality, with minimal disruption to users, wallets, and dApps.
- This enabled Token Extensions, introducing a suite of program-level enhancements such as confidential transactions, customizable transfer logic, and enriched metadata.

<br>

---

Expand All @@ -44,7 +31,7 @@
const [pda] = PublicKey.findProgramAddressSync(
[Buffer.from("extra-account-metas"),
mint.publicKey.toBuffer()],
program.programId,
program.program_id,
);
```

Expand Down Expand Up @@ -84,7 +71,7 @@ const [pda] = PublicKey.findProgramAddressSync(

<br>

* [Backend's demo 5: Transfer Hooks](https://github.com/urani-labs/solana-dev-onboarding-rs/tree/main/demos/backend/05_transfer_hooks)
* [Backend's demo 5: Transfer Hooks for Vesting](https://github.com/urani-labs/solana-dev-onboarding-rs/tree/main/demos/backend/05_transfer_hooks)


<br>
Expand All @@ -101,5 +88,4 @@ const [pda] = PublicKey.findProgramAddressSync(
* [Token Transfer Hooks with Token Extensions on Solana](https://www.youtube.com/watch?v=Cc6CZWd-iMw)
* [How to use the Transfer Hooks Token Extension Part 2](https://www.youtube.com/watch?v=LsduWRtT3r8)
* [How to use the Transfer Hook extension, by Solana Labs](https://solana.com/developers/guides/token-extensions/transfer-hook)
* [Leveraging Transfer Hooks on Solana, by Leo](https://medium.com/@LeoOnSol/hooked-the-power-of-leveraging-transfer-hooks-on-solana-2b0f15770e64)
* [5 Ways to Get Hooked, by Solandy](https://www.youtube.com/watch?v=Sr-HiJdbf6w)
File renamed without changes.
File renamed without changes.
12 changes: 11 additions & 1 deletion demos/backend/05_transfer_hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,14 @@ anchor keys list

```
anchor test
```
```

<br>

---

### References

<br>

* [Leveraging Transfer Hooks on Solana, by Leo](https://medium.com/@LeoOnSol/hooked-the-power-of-leveraging-transfer-hooks-on-solana-2b0f15770e64)

0 comments on commit 2b7d373

Please sign in to comment.