token.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /* Autogenerated SPL Token program C Bindings */
  2. #pragma once
  3. #include <stdarg.h>
  4. #include <stdbool.h>
  5. #include <stdint.h>
  6. #include <stdlib.h>
  7. #define TOKEN_MAJOR_VERSION 1
  8. #define TOKEN_MINOR_VERSION 1
  9. #define TOKEN_PATCH_VERSION 0
  10. /**
  11. * Maximum number of multisignature signers (max N)
  12. */
  13. #define Token_MAX_SIGNERS 11
  14. /**
  15. * Minimum number of multisignature signers (min N)
  16. */
  17. #define Token_MIN_SIGNERS 1
  18. /**
  19. * Account state.
  20. */
  21. enum Token_AccountState
  22. #ifdef __cplusplus
  23. : uint8_t
  24. #endif // __cplusplus
  25. {
  26. /**
  27. * Account is not yet initialized
  28. */
  29. Token_AccountState_Uninitialized,
  30. /**
  31. * Account is initialized; the account owner and/or delegate may perform permitted operations
  32. * on this account
  33. */
  34. Token_AccountState_Initialized,
  35. /**
  36. * Account has been frozen by the mint freeze authority. Neither the account owner nor
  37. * the delegate are able to perform operations on this account.
  38. */
  39. Token_AccountState_Frozen,
  40. };
  41. #ifndef __cplusplus
  42. typedef uint8_t Token_AccountState;
  43. #endif // __cplusplus
  44. /**
  45. * Specifies the authority type for SetAuthority instructions
  46. */
  47. enum Token_AuthorityType
  48. #ifdef __cplusplus
  49. : uint8_t
  50. #endif // __cplusplus
  51. {
  52. /**
  53. * Authority to mint new tokens
  54. */
  55. Token_AuthorityType_MintTokens,
  56. /**
  57. * Authority to freeze any account associated with the Mint
  58. */
  59. Token_AuthorityType_FreezeAccount,
  60. /**
  61. * Holder of a given token account
  62. */
  63. Token_AuthorityType_AccountHolder,
  64. /**
  65. * Authority to close a token account
  66. */
  67. Token_AuthorityType_CloseAccount,
  68. };
  69. #ifndef __cplusplus
  70. typedef uint8_t Token_AuthorityType;
  71. #endif // __cplusplus
  72. typedef uint8_t Token_Pubkey[32];
  73. /**
  74. * A C representation of Rust's `std::option::Option`
  75. */
  76. typedef enum Token_COption_Pubkey_Tag {
  77. /**
  78. * No value
  79. */
  80. Token_COption_Pubkey_None_Pubkey,
  81. /**
  82. * Some value `T`
  83. */
  84. Token_COption_Pubkey_Some_Pubkey,
  85. } Token_COption_Pubkey_Tag;
  86. typedef struct Token_COption_Pubkey_Token_Some_Body_Pubkey {
  87. Token_Pubkey _0;
  88. } Token_COption_Pubkey_Token_Some_Body_Pubkey;
  89. typedef struct Token_COption_Pubkey {
  90. Token_COption_Pubkey_Tag tag;
  91. union {
  92. Token_COption_Pubkey_Token_Some_Body_Pubkey some;
  93. };
  94. } Token_COption_Pubkey;
  95. /**
  96. * Instructions supported by the token program.
  97. */
  98. typedef enum Token_TokenInstruction_Tag {
  99. /**
  100. * Initializes a new mint and optionally deposits all the newly minted tokens in an account.
  101. *
  102. * The `InitializeMint` instruction requires no signers and MUST be included within
  103. * the same Transaction as the system program's `CreateInstruction` that creates the account
  104. * being initialized. Otherwise another party can acquire ownership of the uninitialized account.
  105. *
  106. * Accounts expected by this instruction:
  107. *
  108. * 0. `[writable]` The mint to initialize.
  109. *
  110. */
  111. Token_TokenInstruction_InitializeMint,
  112. /**
  113. * Initializes a new account to hold tokens. If this account is associated with the native mint
  114. * then the token balance of the initialized account will be equal to the amount of SOL in the account.
  115. *
  116. * The `InitializeAccount` instruction requires no signers and MUST be included within
  117. * the same Transaction as the system program's `CreateInstruction` that creates the account
  118. * being initialized. Otherwise another party can acquire ownership of the uninitialized account.
  119. *
  120. * Accounts expected by this instruction:
  121. *
  122. * 0. `[writable]` The account to initialize.
  123. * 1. `[]` The mint this account will be associated with.
  124. * 2. `[]` The new account's owner/multisignature.
  125. */
  126. Token_TokenInstruction_InitializeAccount,
  127. /**
  128. * Initializes a multisignature account with N provided signers.
  129. *
  130. * Multisignature accounts can used in place of any single owner/delegate accounts in any
  131. * token instruction that require an owner/delegate to be present. The variant field represents the
  132. * number of signers (M) required to validate this multisignature account.
  133. *
  134. * The `InitializeMultisig` instruction requires no signers and MUST be included within
  135. * the same Transaction as the system program's `CreateInstruction` that creates the account
  136. * being initialized. Otherwise another party can acquire ownership of the uninitialized account.
  137. *
  138. * Accounts expected by this instruction:
  139. *
  140. * 0. `[writable]` The multisignature account to initialize.
  141. * 1. ..1+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
  142. */
  143. Token_TokenInstruction_InitializeMultisig,
  144. /**
  145. * Transfers tokens from one account to another either directly or via a delegate. If this
  146. * account is associated with the native mint then equal amounts of SOL and Tokens will be
  147. * transferred to the destination account.
  148. *
  149. * Accounts expected by this instruction:
  150. *
  151. * * Single owner/delegate
  152. * 0. `[writable]` The source account.
  153. * 1. `[writable]` The destination account.
  154. * 2. '[signer]' The source account's owner/delegate.
  155. *
  156. * * Multisignature owner/delegate
  157. * 0. `[writable]` The source account.
  158. * 1. `[writable]` The destination account.
  159. * 2. '[]' The source account's multisignature owner/delegate.
  160. * 3. ..3+M '[signer]' M signer accounts.
  161. */
  162. Token_TokenInstruction_Transfer,
  163. /**
  164. * Approves a delegate. A delegate is given the authority over
  165. * tokens on behalf of the source account's owner.
  166. * Accounts expected by this instruction:
  167. *
  168. * * Single owner
  169. * 0. `[writable]` The source account.
  170. * 1. `[]` The delegate.
  171. * 2. `[signer]` The source account owner.
  172. *
  173. * * Multisignature owner
  174. * 0. `[writable]` The source account.
  175. * 1. `[]` The delegate.
  176. * 2. '[]' The source account's multisignature owner.
  177. * 3. ..3+M '[signer]' M signer accounts
  178. */
  179. Token_TokenInstruction_Approve,
  180. /**
  181. * Revokes the delegate's authority.
  182. *
  183. * Accounts expected by this instruction:
  184. *
  185. * * Single owner
  186. * 0. `[writable]` The source account.
  187. * 1. `[signer]` The source account owner.
  188. *
  189. * * Multisignature owner
  190. * 0. `[writable]` The source account.
  191. * 1. '[]' The source account's multisignature owner.
  192. * 2. ..2+M '[signer]' M signer accounts
  193. */
  194. Token_TokenInstruction_Revoke,
  195. /**
  196. * Sets a new authority of a mint or account.
  197. *
  198. * Accounts expected by this instruction:
  199. *
  200. * * Single authority
  201. * 0. `[writable]` The mint or account to change the authority of.
  202. * 1. `[signer]` The current authority of the mint or account.
  203. *
  204. * * Multisignature authority
  205. * 0. `[writable]` The mint or account to change the authority of.
  206. * 1. `[]` The mint's or account's multisignature authority.
  207. * 3. ..3+M '[signer]' M signer accounts
  208. */
  209. Token_TokenInstruction_SetAuthority,
  210. /**
  211. * Mints new tokens to an account. The native mint does not support minting.
  212. *
  213. * Accounts expected by this instruction:
  214. *
  215. * * Single authority
  216. * 0. `[writable]` The mint.
  217. * 1. `[writable]` The account to mint tokens to.
  218. * 2. `[signer]` The mint's minting authority.
  219. *
  220. * * Multisignature authority
  221. * 0. `[writable]` The mint.
  222. * 1. `[writable]` The account to mint tokens to.
  223. * 2. `[]` The mint's multisignature mint-tokens authority.
  224. * 3. ..3+M '[signer]' M signer accounts.
  225. */
  226. Token_TokenInstruction_MintTo,
  227. /**
  228. * Burns tokens by removing them from an account. `Burn` does not support accounts
  229. * associated with the native mint, use `CloseAccount` instead.
  230. *
  231. * Accounts expected by this instruction:
  232. *
  233. * * Single owner/delegate
  234. * 0. `[writable]` The account to burn from.
  235. * 1. `[signer]` The account's owner/delegate.
  236. *
  237. * * Multisignature owner/delegate
  238. * 0. `[writable]` The account to burn from.
  239. * 1. `[]` The account's multisignature owner/delegate.
  240. * 2. ..2+M '[signer]' M signer accounts.
  241. */
  242. Token_TokenInstruction_Burn,
  243. /**
  244. * Close an account by transferring all its SOL to the destination account.
  245. * Non-native accounts may only be closed if its token amount is zero.
  246. *
  247. * Accounts expected by this instruction:
  248. *
  249. * * Single owner
  250. * 0. `[writable]` The account to close.
  251. * 1. '[writable]' The destination account.
  252. * 2. `[signer]` The account's owner.
  253. *
  254. * * Multisignature owner
  255. * 0. `[writable]` The account to close.
  256. * 1. '[writable]' The destination account.
  257. * 2. `[]` The account's multisignature owner.
  258. * 3. ..3+M '[signer]' M signer accounts.
  259. */
  260. Token_TokenInstruction_CloseAccount,
  261. /**
  262. * Freeze an Initialized account using the Mint's freeze_authority (if set).
  263. *
  264. * Accounts expected by this instruction:
  265. *
  266. * * Single owner
  267. * 0. `[writable]` The account to freeze.
  268. * 1. '[]' The token mint.
  269. * 2. `[signer]` The mint freeze authority.
  270. *
  271. * * Multisignature owner
  272. * 0. `[writable]` The account to freeze.
  273. * 1. '[]' The token mint.
  274. * 2. `[]` The mint's multisignature freeze authority.
  275. * 3. ..3+M '[signer]' M signer accounts.
  276. */
  277. Token_TokenInstruction_FreezeAccount,
  278. /**
  279. * Thaw a Frozen account using the Mint's freeze_authority (if set).
  280. *
  281. * Accounts expected by this instruction:
  282. *
  283. * * Single owner
  284. * 0. `[writable]` The account to freeze.
  285. * 1. '[]' The token mint.
  286. * 2. `[signer]` The mint freeze authority.
  287. *
  288. * * Multisignature owner
  289. * 0. `[writable]` The account to freeze.
  290. * 1. '[]' The token mint.
  291. * 2. `[]` The mint's multisignature freeze authority.
  292. * 3. ..3+M '[signer]' M signer accounts.
  293. */
  294. Token_TokenInstruction_ThawAccount,
  295. } Token_TokenInstruction_Tag;
  296. typedef struct Token_TokenInstruction_Token_InitializeMint_Body {
  297. /**
  298. * Number of base 10 digits to the right of the decimal place.
  299. */
  300. uint8_t decimals;
  301. /**
  302. * The authority/multisignature to mint tokens.
  303. */
  304. Token_Pubkey mint_authority;
  305. /**
  306. * The freeze authority/multisignature of the mint.
  307. */
  308. Token_COption_Pubkey freeze_authority;
  309. } Token_TokenInstruction_Token_InitializeMint_Body;
  310. typedef struct Token_TokenInstruction_Token_InitializeMultisig_Body {
  311. /**
  312. * The number of signers (M) required to validate this multisignature account.
  313. */
  314. uint8_t m;
  315. } Token_TokenInstruction_Token_InitializeMultisig_Body;
  316. typedef struct Token_TokenInstruction_Token_Transfer_Body {
  317. /**
  318. * The amount of tokens to transfer.
  319. */
  320. uint64_t amount;
  321. } Token_TokenInstruction_Token_Transfer_Body;
  322. typedef struct Token_TokenInstruction_Token_Approve_Body {
  323. /**
  324. * The amount of tokens the delegate is approved for.
  325. */
  326. uint64_t amount;
  327. } Token_TokenInstruction_Token_Approve_Body;
  328. typedef struct Token_TokenInstruction_Token_SetAuthority_Body {
  329. /**
  330. * The type of authority to update.
  331. */
  332. Token_AuthorityType authority_type;
  333. /**
  334. * The new authority
  335. */
  336. Token_COption_Pubkey new_authority;
  337. } Token_TokenInstruction_Token_SetAuthority_Body;
  338. typedef struct Token_TokenInstruction_Token_MintTo_Body {
  339. /**
  340. * The amount of new tokens to mint.
  341. */
  342. uint64_t amount;
  343. } Token_TokenInstruction_Token_MintTo_Body;
  344. typedef struct Token_TokenInstruction_Token_Burn_Body {
  345. /**
  346. * The amount of tokens to burn.
  347. */
  348. uint64_t amount;
  349. } Token_TokenInstruction_Token_Burn_Body;
  350. typedef struct Token_TokenInstruction {
  351. Token_TokenInstruction_Tag tag;
  352. union {
  353. Token_TokenInstruction_Token_InitializeMint_Body initialize_mint;
  354. Token_TokenInstruction_Token_InitializeMultisig_Body initialize_multisig;
  355. Token_TokenInstruction_Token_Transfer_Body transfer;
  356. Token_TokenInstruction_Token_Approve_Body approve;
  357. Token_TokenInstruction_Token_SetAuthority_Body set_authority;
  358. Token_TokenInstruction_Token_MintTo_Body mint_to;
  359. Token_TokenInstruction_Token_Burn_Body burn;
  360. };
  361. } Token_TokenInstruction;
  362. /**
  363. * Mint data.
  364. */
  365. typedef struct Token_Mint {
  366. /**
  367. * Optional authority used to mint new tokens. The mint authority may only be provided during
  368. * mint creation. If no mint authority is present then the mint has a fixed supply and no
  369. * further tokens may be minted.
  370. */
  371. Token_COption_Pubkey mint_authority;
  372. /**
  373. * Number of base 10 digits to the right of the decimal place.
  374. */
  375. uint8_t decimals;
  376. /**
  377. * Is `true` if this structure has been initialized
  378. */
  379. bool is_initialized;
  380. /**
  381. * Optional authority to freeze token accounts.
  382. */
  383. Token_COption_Pubkey freeze_authority;
  384. } Token_Mint;
  385. /**
  386. * Account data.
  387. */
  388. typedef struct Token_Account {
  389. /**
  390. * The mint associated with this account
  391. */
  392. Token_Pubkey mint;
  393. /**
  394. * The owner of this account.
  395. */
  396. Token_Pubkey owner;
  397. /**
  398. * The amount of tokens this account holds.
  399. */
  400. uint64_t amount;
  401. /**
  402. * If `delegate` is `Some` then `delegated_amount` represents
  403. * the amount authorized by the delegate
  404. */
  405. Token_COption_Pubkey delegate;
  406. /**
  407. * The account's state
  408. */
  409. Token_AccountState state;
  410. /**
  411. * Is this a native token
  412. */
  413. bool is_native;
  414. /**
  415. * The amount delegated
  416. */
  417. uint64_t delegated_amount;
  418. /**
  419. * Optional authority to close the account.
  420. */
  421. Token_COption_Pubkey close_authority;
  422. } Token_Account;
  423. /**
  424. * Multisignature data.
  425. */
  426. typedef struct Token_Multisig {
  427. /**
  428. * Number of signers required
  429. */
  430. uint8_t m;
  431. /**
  432. * Number of valid signers
  433. */
  434. uint8_t n;
  435. /**
  436. * Is `true` if this structure has been initialized
  437. */
  438. bool is_initialized;
  439. /**
  440. * Signer public keys
  441. */
  442. Token_Pubkey signers[Token_MAX_SIGNERS];
  443. } Token_Multisig;