Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 29ad0f3

Browse files
authored
token-2022: Add intro docs, structure for more docs (#3384)
* token-2022: Add intro docs, structure for more docs * Address feedback * Remove the word "migration"
1 parent 48e6acb commit 29ad0f3

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

docs/sidebars.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ module.exports = {
22
docs: [
33
"introduction",
44
"token",
5+
{
6+
type: 'category',
7+
label: 'Token-2022',
8+
collapsed: true,
9+
items: [
10+
"token-2022",
11+
"token-2022/extensions",
12+
"token-2022/wallet-migration",
13+
"token-2022/onchain-migration",
14+
],
15+
},
516
"token-swap",
617
"token-lending",
718
"associated-token-account",

docs/src/token-2022.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
title: Token-2022 Program
3+
---
4+
5+
A token program on the Solana blockchain, defining a common implementation for
6+
fungible and non-fungible tokens.
7+
8+
The Token-2022 Program is a superset of the functionality provided by the
9+
[Token Program](token.mdx), deployed to all networks.
10+
11+
| Information | Account Address |
12+
| --- | --- |
13+
| Token-2022 Program | `TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb` |
14+
15+
## Motivation
16+
17+
The existing Token Program serves most needs for fungible and non-fungible tokens
18+
on Solana through a simple set of interfaces and structures. It has been rigorously
19+
audited since its initial deployment in 2020.
20+
21+
As more developers have come to Solana with new ideas, however, they have forked the
22+
Token Program to add functionality. It's simple to change and deploy the program,
23+
but it's difficult to achieve adoption across the ecosystem.
24+
25+
Solana's programming model requires programs to be included in transactions
26+
along with accounts, making it complicated to craft transactions involving
27+
multiple token programs.
28+
29+
On top of the technical difficulty, wallets and on-chain programs must trust any
30+
token program that they choose to support.
31+
32+
We need to add new token functionality, with minimal disruption to users, wallets,
33+
and dApps. Most importantly, we must preserve the safety of existing tokens.
34+
35+
A new token program, Token-2022, was developed to achieve both of these goals,
36+
deployed to a different address than the Token program.
37+
38+
## Concept
39+
40+
To make adoption as easy as possible, the functionality and structures in
41+
Token-2022 are a strict superset of Token.
42+
43+
### Instructions
44+
45+
Token-2022 supports the exact same instruction layouts as Token, byte for
46+
byte. For example, if you want to transfer 100 tokens on a mint with 2 decimals,
47+
you create a `TransferChecked` instruction, with this byte-representated data:
48+
49+
```
50+
[12, 100, 0, 0, 0, 0, 0, 0, 0, 2]
51+
^^ TransferChecked enum
52+
^^^^^^^^^^^^^^^^^^^^^^^^ 100, as a little-endian 64-bit unsigned integer
53+
^ 2, as a byte
54+
```
55+
56+
This format means the exact same thing to both Token and Token-2022. If you want
57+
to target one program over another, you just need to change the `program_id` in
58+
the instruction.
59+
60+
All new instructions in Token-2022 start where Token stops. Token has 25 unique
61+
instructions, with indices 0 through 24. Token-2022 supports all of these
62+
instructions, and then adds new functionality at index 25.
63+
64+
There are no plans to ever add new instructions to Token.
65+
66+
### Mints and Accounts
67+
68+
For structure layouts, the same idea mostly applies. An `Account` has the same
69+
exact representation between Token and Token-2022 for the first `165` bytes, and
70+
a `Mint` has the same representation for the first `82` bytes.
71+
72+
### Extensions
73+
74+
New functionality requires new fields in mints and accounts, which
75+
makes it impossible to have the exact same layout for all accounts in Token-2022.
76+
77+
New fields are added in the form of extensions.
78+
79+
Mint creators and account owners can opt-in to Token-2022 features. Extension data
80+
is written after the end of the `Account` in Token, which is the byte at index
81+
`165`. This means it is always possible to differentiate mints and accounts.
82+
83+
You can read more about how this is done at the
84+
[source code](https://github.com/solana-labs/solana-program-library/tree/master/token/program-2022/src/extensions/mod.rs).
85+
86+
Mint extensions currently include:
87+
88+
* confidential transfers
89+
* transfer fees
90+
* closing mint
91+
* interest-bearing tokens
92+
93+
Account extensions currently include:
94+
95+
* memo required on incoming transfers
96+
* immutable ownership
97+
98+
Extensions can be mixed and matched, which means it's possible to create a mint
99+
with only transfer fees, only interest-bearing tokens, both, or neither!
100+
101+
### Associated Token Accounts
102+
103+
To make things simpler, there is still only one associated token account
104+
program, that creates new token accounts for either Token or Token-2022.
105+
106+
## Getting Started
107+
108+
To get started with Token-2022:
109+
110+
- [Install the Solana Tools](https://docs.solana.com/cli/install-solana-cli-tools)
111+
- [Extension Guide](token-2022/extensions.md)
112+
- [Wallet Guide](token-2022/wallet.md)
113+
- [On-Chain Program Guide](token-2022/onchain.md)
114+
115+
For existing functionality in the Token Program, see the [token docs](token.mdx).
116+
The Token functionality will always apply to Token-2022.
117+
118+
## Source
119+
120+
The Token-2022 Program's source is available on
121+
[GitHub](https://github.com/solana-labs/solana-program-library/tree/master/token/program-2022).
122+
123+
For information about the types and instructions, the Rust docs are available at
124+
[docs.rs](https://docs.rs/spl-token-2022/latest/spl_token_2022/).
125+
126+
## Security Audits
127+
128+
The Token-2022 Program is currently under multiple audits to ensure safety of
129+
funds. All audits will be published here as they are completed.

docs/src/token-2022/extensions.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Extension Guide
3+
---
4+
5+
Coming soon!

docs/src/token-2022/onchain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: On-chain Program Guide
3+
---
4+
5+
Coming soon!

docs/src/token-2022/wallet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Wallet Guide
3+
---
4+
5+
Coming soon!

0 commit comments

Comments
 (0)