This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d72779f
commit ae5740c
Showing
36 changed files
with
9,204 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1 +1,105 @@ | ||
# 🛹 Transfer Hooks [IN CONSTRUCTION] | ||
# 🛹 Transfer Hooks | ||
|
||
<br> | ||
|
||
### tl; dr | ||
|
||
|
||
<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. | ||
|
||
|
||
<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> | ||
|
||
--- | ||
|
||
### How Token Hooks Work | ||
|
||
<br> | ||
|
||
* Whenever the token is minted, the `Execute` instruction is triggered together with a Transfer Instruction (the custom logic). | ||
|
||
* All accounts from the initial transfer are converted to read-only accounts (i.e., the signer privileges of the sender do not extend to the Transfer Hook program). | ||
|
||
* Extra accounts required by `Execute` are stored in a predefined PDA that must be derived using the following seeds: `extra-account-metas` string, the mint account address, the transfer hook `program_id`. | ||
|
||
<br> | ||
|
||
```javascript | ||
const [pda] = PublicKey.findProgramAddressSync( | ||
[Buffer.from("extra-account-metas"), | ||
mint.publicKey.toBuffer()], | ||
program.programId, | ||
); | ||
``` | ||
|
||
<br> | ||
|
||
--- | ||
|
||
### Specifications | ||
|
||
<br> | ||
|
||
* [The Transfer Hook interface specification](https://spl.solana.com/transfer-hook-interface/specification) includes two optional instructions and one required one; each uses a specific 8-byte discriminator at the start of its data. | ||
|
||
* The `Execute` instruction is required, and this is the instruction in which custom transfer functionality lives. | ||
- It contains the following parts: | ||
- `Discriminator`, the first 8 bytes of the hash of "spl-transfer-hook-interface:execute" | ||
- `Data`: | ||
- `amount`: `u64`, the transfer amount | ||
- `accounts: | ||
- 1 []: Source token account | ||
- 2 []: Mint | ||
- 3 []: Destination token account | ||
- 4 []: Source token account authority | ||
- 5 []: Validation account | ||
|
||
* `InitializeExtraAccountMetaList` is optional and intializes the validation account to store a list of extra required `AccountMeta` configurations for the `Execute` instruction. | ||
|
||
|
||
* `UpdateExtraAccountMetaList` is optional and allows an on-chain program to update its list of required accounts for 1Execute`. | ||
|
||
|
||
<br> | ||
|
||
--- | ||
|
||
### Demos | ||
|
||
<br> | ||
|
||
* [Backend's demo 5: Transfer Hooks](https://github.com/urani-labs/solana-dev-onboarding-rs/tree/main/demos/backend/05_transfer_hooks) | ||
|
||
|
||
<br> | ||
|
||
|
||
--- | ||
|
||
### References | ||
|
||
<br> | ||
|
||
|
||
* [Transfer Hook Interface, by Solana Labs](https://spl.solana.com/transfer-hook-interface) | ||
* [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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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 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 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 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 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,18 @@ | ||
[toolchain] | ||
|
||
[features] | ||
seeds = false | ||
skip-lint = false | ||
|
||
[programs.localnet] | ||
vesting_template = "FohntM2s5Z1uqyDbBAu1CHxYh9umzeiRSKr198rSSdvT" | ||
|
||
[registry] | ||
url = "https://api.apr.dev" | ||
|
||
[provider] | ||
cluster = "Localnet" | ||
wallet = "/Users/leo/.config/solana/id.json" | ||
|
||
[scripts] | ||
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts" |
This file contains 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,13 @@ | ||
[workspace] | ||
members = [ | ||
"programs/*" | ||
] | ||
|
||
[profile.release] | ||
overflow-checks = true | ||
lto = "fat" | ||
codegen-units = 1 | ||
[profile.release.build-override] | ||
opt-level = 3 | ||
incremental = false | ||
codegen-units = 1 |
This file contains 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,12 @@ | ||
// Migrations are an early feature. Currently, they're nothing more than this | ||
// single deploy script that's invoked from the CLI, injecting a provider | ||
// configured from the workspace's Anchor.toml. | ||
|
||
const anchor = require("@coral-xyz/anchor"); | ||
|
||
module.exports = async function (provider) { | ||
// Configure client to use the provider. | ||
anchor.setProvider(provider); | ||
|
||
// Add your deploy script here. | ||
}; |
This file contains 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,20 @@ | ||
{ | ||
"scripts": { | ||
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w", | ||
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check" | ||
}, | ||
"dependencies": { | ||
"@coral-xyz/anchor": "^0.29.0", | ||
"@solana/spl-token": "^0.4.1" | ||
}, | ||
"devDependencies": { | ||
"@types/bn.js": "^5.1.0", | ||
"@types/chai": "^4.3.0", | ||
"@types/mocha": "^9.0.0", | ||
"chai": "^4.3.4", | ||
"mocha": "^9.0.3", | ||
"prettier": "^2.6.2", | ||
"ts-mocha": "^10.0.0", | ||
"typescript": "^4.3.5" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
demos/backend/05_transfer_hooks/programs/vesting-template/Cargo.toml
This file contains 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,24 @@ | ||
[package] | ||
name = "vesting-template" | ||
version = "0.1.0" | ||
description = "Created with Anchor" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] | ||
name = "vesting_template" | ||
|
||
[features] | ||
no-entrypoint = [] | ||
no-idl = [] | ||
no-log-ix-name = [] | ||
cpi = ["no-entrypoint"] | ||
default = [] | ||
|
||
[dependencies] | ||
anchor-lang = { version = "0.29.0", features = ["init-if-needed"]} | ||
anchor-spl = { version = "0.29.0", features = ["token", "metadata"]} | ||
spl-tlv-account-resolution = "0.5.0" | ||
spl-transfer-hook-interface = "0.5.0" | ||
toml_edit = "=0.21.0" | ||
solana-program = "=1.17" |
2 changes: 2 additions & 0 deletions
2
demos/backend/05_transfer_hooks/programs/vesting-template/Xargo.toml
This file contains 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,2 @@ | ||
[target.bpfel-unknown-unknown.dependencies.std] | ||
features = [] |
Oops, something went wrong.