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

Commit b62c272

Browse files
committed
Update token.h
1 parent 68db5f7 commit b62c272

File tree

1 file changed

+163
-56
lines changed

1 file changed

+163
-56
lines changed

token/program/inc/token.h

Lines changed: 163 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,89 @@
2121
*/
2222
#define Token_MIN_SIGNERS 1
2323

24+
/**
25+
* Account state.
26+
*/
27+
enum Token_AccountState
28+
#ifdef __cplusplus
29+
: uint8_t
30+
#endif // __cplusplus
31+
{
32+
/**
33+
* Account is not yet initialized
34+
*/
35+
Token_AccountState_Uninitialized,
36+
/**
37+
* Account is initialized; the account owner and/or delegate may perform permitted operations
38+
* on this account
39+
*/
40+
Token_AccountState_Initialized,
41+
/**
42+
* Account has been frozen by the mint freeze authority. Neither the account owner nor
43+
* the delegate are able to perform operations on this account.
44+
*/
45+
Token_AccountState_Frozen,
46+
};
47+
#ifndef __cplusplus
48+
typedef uint8_t Token_AccountState;
49+
#endif // __cplusplus
50+
51+
/**
52+
* Specifies the authority type for SetAuthority instructions
53+
*/
54+
enum Token_AuthorityType
55+
#ifdef __cplusplus
56+
: uint8_t
57+
#endif // __cplusplus
58+
{
59+
/**
60+
* Authority to mint new tokens
61+
*/
62+
Token_AuthorityType_MintTokens,
63+
/**
64+
* Authority to freeze any account associated with the Mint
65+
*/
66+
Token_AuthorityType_FreezeAccount,
67+
/**
68+
* Holder of a given token account
69+
*/
70+
Token_AuthorityType_AccountHolder,
71+
/**
72+
* Authority to close a token account
73+
*/
74+
Token_AuthorityType_CloseAccount,
75+
};
76+
#ifndef __cplusplus
77+
typedef uint8_t Token_AuthorityType;
78+
#endif // __cplusplus
79+
80+
typedef uint8_t Token_Pubkey[32];
81+
82+
/**
83+
* A C representation of Rust's `std::option::Option`
84+
*/
85+
typedef enum Token_COption_Pubkey_Tag {
86+
/**
87+
* No value
88+
*/
89+
Token_COption_Pubkey_None_Pubkey,
90+
/**
91+
* Some value `T`
92+
*/
93+
Token_COption_Pubkey_Some_Pubkey,
94+
} Token_COption_Pubkey_Tag;
95+
96+
typedef struct Token_COption_Pubkey_Token_Some_Body_Pubkey {
97+
Token_Pubkey _0;
98+
} Token_COption_Pubkey_Token_Some_Body_Pubkey;
99+
100+
typedef struct Token_COption_Pubkey {
101+
Token_COption_Pubkey_Tag tag;
102+
union {
103+
Token_COption_Pubkey_Token_Some_Body_Pubkey some;
104+
};
105+
} Token_COption_Pubkey;
106+
24107
/**
25108
* Instructions supported by the token program.
26109
*/
@@ -35,11 +118,6 @@ typedef enum Token_TokenInstruction_Tag {
35118
* Accounts expected by this instruction:
36119
*
37120
* 0. `[writable]` The mint to initialize.
38-
* 1.
39-
* * If supply is non-zero: `[writable]` The account to hold all the newly minted tokens.
40-
* * If supply is zero: `[]` The owner/multisignature of the mint.
41-
* 2. `[]` (optional) The owner/multisignature of the mint if supply is non-zero, if
42-
* present then further minting is supported.
43121
*
44122
*/
45123
Token_TokenInstruction_InitializeMint,
@@ -127,36 +205,34 @@ typedef enum Token_TokenInstruction_Tag {
127205
*/
128206
Token_TokenInstruction_Revoke,
129207
/**
130-
* Sets a new owner of a mint or account.
208+
* Sets a new authority of a mint or account.
131209
*
132210
* Accounts expected by this instruction:
133211
*
134-
* * Single owner
135-
* 0. `[writable]` The mint or account to change the owner of.
136-
* 1. `[]` The new owner/delegate/multisignature.
137-
* 2. `[signer]` The owner of the mint or account.
212+
* * Single authority
213+
* 0. `[writable]` The mint or account to change the authority of.
214+
* 1. `[signer]` The current authority of the mint or account.
138215
*
139-
* * Multisignature owner
140-
* 0. `[writable]` The mint or account to change the owner of.
141-
* 1. `[]` The new owner/delegate/multisignature.
142-
* 2. `[]` The mint's or account's multisignature owner.
216+
* * Multisignature authority
217+
* 0. `[writable]` The mint or account to change the authority of.
218+
* 1. `[]` The mint's or account's multisignature authority.
143219
* 3. ..3+M '[signer]' M signer accounts
144220
*/
145-
Token_TokenInstruction_SetOwner,
221+
Token_TokenInstruction_SetAuthority,
146222
/**
147223
* Mints new tokens to an account. The native mint does not support minting.
148224
*
149225
* Accounts expected by this instruction:
150226
*
151-
* * Single owner
227+
* * Single authority
152228
* 0. `[writable]` The mint.
153229
* 1. `[writable]` The account to mint tokens to.
154-
* 2. `[signer]` The mint's owner.
230+
* 2. `[signer]` The mint's minting authority.
155231
*
156-
* * Multisignature owner
232+
* * Multisignature authority
157233
* 0. `[writable]` The mint.
158234
* 1. `[writable]` The account to mint tokens to.
159-
* 2. `[]` The mint's multisignature owner.
235+
* 2. `[]` The mint's multisignature mint-tokens authority.
160236
* 3. ..3+M '[signer]' M signer accounts.
161237
*/
162238
Token_TokenInstruction_MintTo,
@@ -194,17 +270,55 @@ typedef enum Token_TokenInstruction_Tag {
194270
* 3. ..3+M '[signer]' M signer accounts.
195271
*/
196272
Token_TokenInstruction_CloseAccount,
273+
/**
274+
* Freeze an Initialized account using the Mint's freeze_authority (if set).
275+
*
276+
* Accounts expected by this instruction:
277+
*
278+
* * Single owner
279+
* 0. `[writable]` The account to freeze.
280+
* 1. '[]' The token mint.
281+
* 2. `[signer]` The mint freeze authority.
282+
*
283+
* * Multisignature owner
284+
* 0. `[writable]` The account to freeze.
285+
* 1. '[]' The token mint.
286+
* 2. `[]` The mint's multisignature freeze authority.
287+
* 3. ..3+M '[signer]' M signer accounts.
288+
*/
289+
Token_TokenInstruction_FreezeAccount,
290+
/**
291+
* Thaw a Frozen account using the Mint's freeze_authority (if set).
292+
*
293+
* Accounts expected by this instruction:
294+
*
295+
* * Single owner
296+
* 0. `[writable]` The account to freeze.
297+
* 1. '[]' The token mint.
298+
* 2. `[signer]` The mint freeze authority.
299+
*
300+
* * Multisignature owner
301+
* 0. `[writable]` The account to freeze.
302+
* 1. '[]' The token mint.
303+
* 2. `[]` The mint's multisignature freeze authority.
304+
* 3. ..3+M '[signer]' M signer accounts.
305+
*/
306+
Token_TokenInstruction_ThawAccount,
197307
} Token_TokenInstruction_Tag;
198308

199309
typedef struct Token_TokenInstruction_Token_InitializeMint_Body {
200-
/**
201-
* Initial amount of tokens to mint.
202-
*/
203-
uint64_t amount;
204310
/**
205311
* Number of base 10 digits to the right of the decimal place.
206312
*/
207313
uint8_t decimals;
314+
/**
315+
* The authority/multisignature to mint tokens.
316+
*/
317+
Token_Pubkey mint_authority;
318+
/**
319+
* The freeze authority/multisignature of the mint.
320+
*/
321+
Token_COption_Pubkey freeze_authority;
208322
} Token_TokenInstruction_Token_InitializeMint_Body;
209323

210324
typedef struct Token_TokenInstruction_Token_InitializeMultisig_Body {
@@ -228,6 +342,17 @@ typedef struct Token_TokenInstruction_Token_Approve_Body {
228342
uint64_t amount;
229343
} Token_TokenInstruction_Token_Approve_Body;
230344

345+
typedef struct Token_TokenInstruction_Token_SetAuthority_Body {
346+
/**
347+
* The type of authority to update.
348+
*/
349+
Token_AuthorityType authority_type;
350+
/**
351+
* The new authority
352+
*/
353+
Token_COption_Pubkey new_authority;
354+
} Token_TokenInstruction_Token_SetAuthority_Body;
355+
231356
typedef struct Token_TokenInstruction_Token_MintTo_Body {
232357
/**
233358
* The amount of new tokens to mint.
@@ -249,48 +374,22 @@ typedef struct Token_TokenInstruction {
249374
Token_TokenInstruction_Token_InitializeMultisig_Body initialize_multisig;
250375
Token_TokenInstruction_Token_Transfer_Body transfer;
251376
Token_TokenInstruction_Token_Approve_Body approve;
377+
Token_TokenInstruction_Token_SetAuthority_Body set_authority;
252378
Token_TokenInstruction_Token_MintTo_Body mint_to;
253379
Token_TokenInstruction_Token_Burn_Body burn;
254380
};
255381
} Token_TokenInstruction;
256382

257-
typedef uint8_t Token_Pubkey[32];
258-
259-
/**
260-
* A C representation of Rust's `std::option::Option`
261-
*/
262-
typedef enum Token_COption_Pubkey_Tag {
263-
/**
264-
* No value
265-
*/
266-
Token_COption_Pubkey_None_Pubkey,
267-
/**
268-
* Some value `T`
269-
*/
270-
Token_COption_Pubkey_Some_Pubkey,
271-
} Token_COption_Pubkey_Tag;
272-
273-
typedef struct Token_COption_Pubkey_Token_Some_Body_Pubkey {
274-
Token_Pubkey _0;
275-
} Token_COption_Pubkey_Token_Some_Body_Pubkey;
276-
277-
typedef struct Token_COption_Pubkey {
278-
Token_COption_Pubkey_Tag tag;
279-
union {
280-
Token_COption_Pubkey_Token_Some_Body_Pubkey some;
281-
};
282-
} Token_COption_Pubkey;
283-
284383
/**
285384
* Mint data.
286385
*/
287386
typedef struct Token_Mint {
288387
/**
289-
* Optional owner, used to mint new tokens. The owner may only
290-
* be provided during mint creation. If no owner is present then the mint
291-
* has a fixed supply and no further tokens may be minted.
388+
* Optional authority used to mint new tokens. The mint authority may only be provided during
389+
* mint creation. If no mint authority is present then the mint has a fixed supply and no
390+
* further tokens may be minted.
292391
*/
293-
Token_COption_Pubkey owner;
392+
Token_COption_Pubkey mint_authority;
294393
/**
295394
* Number of base 10 digits to the right of the decimal place.
296395
*/
@@ -299,6 +398,10 @@ typedef struct Token_Mint {
299398
* Is `true` if this structure has been initialized
300399
*/
301400
bool is_initialized;
401+
/**
402+
* Optional authority to freeze token accounts.
403+
*/
404+
Token_COption_Pubkey freeze_authority;
302405
} Token_Mint;
303406

304407
/**
@@ -323,9 +426,9 @@ typedef struct Token_Account {
323426
*/
324427
Token_COption_Pubkey delegate;
325428
/**
326-
* Is `true` if this structure has been initialized
429+
* The account's state
327430
*/
328-
bool is_initialized;
431+
Token_AccountState state;
329432
/**
330433
* Is this a native token
331434
*/
@@ -334,6 +437,10 @@ typedef struct Token_Account {
334437
* The amount delegated
335438
*/
336439
uint64_t delegated_amount;
440+
/**
441+
* Optional authority to close the account.
442+
*/
443+
Token_COption_Pubkey close_authority;
337444
} Token_Account;
338445

339446
/**

0 commit comments

Comments
 (0)