token.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. * 1. `[]` Rent sysvar
  110. *
  111. */
  112. Token_TokenInstruction_InitializeMint,
  113. /**
  114. * Initializes a new account to hold tokens. If this account is associated with the native
  115. * mint then the token balance of the initialized account will be equal to the amount of SOL
  116. * in the account. If this account is associated with another mint, that mint must be
  117. * initialized before this command can succeed.
  118. *
  119. * The `InitializeAccount` instruction requires no signers and MUST be included within
  120. * the same Transaction as the system program's `CreateInstruction` that creates the account
  121. * being initialized. Otherwise another party can acquire ownership of the uninitialized account.
  122. *
  123. * Accounts expected by this instruction:
  124. *
  125. * 0. `[writable]` The account to initialize.
  126. * 1. `[]` The mint this account will be associated with.
  127. * 2. `[]` The new account's owner/multisignature.
  128. * 3. `[]` Rent sysvar
  129. */
  130. Token_TokenInstruction_InitializeAccount,
  131. /**
  132. * Initializes a multisignature account with N provided signers.
  133. *
  134. * Multisignature accounts can used in place of any single owner/delegate accounts in any
  135. * token instruction that require an owner/delegate to be present. The variant field represents the
  136. * number of signers (M) required to validate this multisignature account.
  137. *
  138. * The `InitializeMultisig` instruction requires no signers and MUST be included within
  139. * the same Transaction as the system program's `CreateInstruction` that creates the account
  140. * being initialized. Otherwise another party can acquire ownership of the uninitialized account.
  141. *
  142. * Accounts expected by this instruction:
  143. *
  144. * 0. `[writable]` The multisignature account to initialize.
  145. * 1. `[]` Rent sysvar
  146. * 2. ..2+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
  147. */
  148. Token_TokenInstruction_InitializeMultisig,
  149. /**
  150. * Transfers tokens from one account to another either directly or via a delegate. If this
  151. * account is associated with the native mint then equal amounts of SOL and Tokens will be
  152. * transferred to the destination account.
  153. *
  154. * Accounts expected by this instruction:
  155. *
  156. * * Single owner/delegate
  157. * 0. `[writable]` The source account.
  158. * 1. `[writable]` The destination account.
  159. * 2. '[signer]' The source account's owner/delegate.
  160. *
  161. * * Multisignature owner/delegate
  162. * 0. `[writable]` The source account.
  163. * 1. `[writable]` The destination account.
  164. * 2. '[]' The source account's multisignature owner/delegate.
  165. * 3. ..3+M '[signer]' M signer accounts.
  166. */
  167. Token_TokenInstruction_Transfer,
  168. /**
  169. * Approves a delegate. A delegate is given the authority over
  170. * tokens on behalf of the source account's owner.
  171. * Accounts expected by this instruction:
  172. *
  173. * * Single owner
  174. * 0. `[writable]` The source account.
  175. * 1. `[]` The delegate.
  176. * 2. `[signer]` The source account owner.
  177. *
  178. * * Multisignature owner
  179. * 0. `[writable]` The source account.
  180. * 1. `[]` The delegate.
  181. * 2. '[]' The source account's multisignature owner.
  182. * 3. ..3+M '[signer]' M signer accounts
  183. */
  184. Token_TokenInstruction_Approve,
  185. /**
  186. * Revokes the delegate's authority.
  187. *
  188. * Accounts expected by this instruction:
  189. *
  190. * * Single owner
  191. * 0. `[writable]` The source account.
  192. * 1. `[signer]` The source account owner.
  193. *
  194. * * Multisignature owner
  195. * 0. `[writable]` The source account.
  196. * 1. '[]' The source account's multisignature owner.
  197. * 2. ..2+M '[signer]' M signer accounts
  198. */
  199. Token_TokenInstruction_Revoke,
  200. /**
  201. * Sets a new authority of a mint or account.
  202. *
  203. * Accounts expected by this instruction:
  204. *
  205. * * Single authority
  206. * 0. `[writable]` The mint or account to change the authority of.
  207. * 1. `[signer]` The current authority of the mint or account.
  208. *
  209. * * Multisignature authority
  210. * 0. `[writable]` The mint or account to change the authority of.
  211. * 1. `[]` The mint's or account's multisignature authority.
  212. * 2. ..2+M '[signer]' M signer accounts
  213. */
  214. Token_TokenInstruction_SetAuthority,
  215. /**
  216. * Mints new tokens to an account. The native mint does not support minting.
  217. *
  218. * Accounts expected by this instruction:
  219. *
  220. * * Single authority
  221. * 0. `[writable]` The mint.
  222. * 1. `[writable]` The account to mint tokens to.
  223. * 2. `[signer]` The mint's minting authority.
  224. *
  225. * * Multisignature authority
  226. * 0. `[writable]` The mint.
  227. * 1. `[writable]` The account to mint tokens to.
  228. * 2. `[]` The mint's multisignature mint-tokens authority.
  229. * 3. ..3+M '[signer]' M signer accounts.
  230. */
  231. Token_TokenInstruction_MintTo,
  232. /**
  233. * Burns tokens by removing them from an account. `Burn` does not support accounts
  234. * associated with the native mint, use `CloseAccount` instead.
  235. *
  236. * Accounts expected by this instruction:
  237. *
  238. * * Single owner/delegate
  239. * 0. `[writable]` The account to burn from.
  240. * 1. '[writable]' The token mint.
  241. * 2. `[signer]` The account's owner/delegate.
  242. *
  243. * * Multisignature owner/delegate
  244. * 0. `[writable]` The account to burn from.
  245. * 1. '[writable]' The token mint.
  246. * 2. `[]` The account's multisignature owner/delegate.
  247. * 3. ..3+M '[signer]' M signer accounts.
  248. */
  249. Token_TokenInstruction_Burn,
  250. /**
  251. * Close an account by transferring all its SOL to the destination account.
  252. * Non-native accounts may only be closed if its token amount is zero.
  253. *
  254. * Accounts expected by this instruction:
  255. *
  256. * * Single owner
  257. * 0. `[writable]` The account to close.
  258. * 1. '[writable]' The destination account.
  259. * 2. `[signer]` The account's owner.
  260. *
  261. * * Multisignature owner
  262. * 0. `[writable]` The account to close.
  263. * 1. '[writable]' The destination account.
  264. * 2. `[]` The account's multisignature owner.
  265. * 3. ..3+M '[signer]' M signer accounts.
  266. */
  267. Token_TokenInstruction_CloseAccount,
  268. /**
  269. * Freeze an Initialized account using the Mint's freeze_authority (if set).
  270. *
  271. * Accounts expected by this instruction:
  272. *
  273. * * Single owner
  274. * 0. `[writable]` The account to freeze.
  275. * 1. '[]' The token mint.
  276. * 2. `[signer]` The mint freeze authority.
  277. *
  278. * * Multisignature owner
  279. * 0. `[writable]` The account to freeze.
  280. * 1. '[]' The token mint.
  281. * 2. `[]` The mint's multisignature freeze authority.
  282. * 3. ..3+M '[signer]' M signer accounts.
  283. */
  284. Token_TokenInstruction_FreezeAccount,
  285. /**
  286. * Thaw a Frozen account using the Mint's freeze_authority (if set).
  287. *
  288. * Accounts expected by this instruction:
  289. *
  290. * * Single owner
  291. * 0. `[writable]` The account to freeze.
  292. * 1. '[]' The token mint.
  293. * 2. `[signer]` The mint freeze authority.
  294. *
  295. * * Multisignature owner
  296. * 0. `[writable]` The account to freeze.
  297. * 1. '[]' The token mint.
  298. * 2. `[]` The mint's multisignature freeze authority.
  299. * 3. ..3+M '[signer]' M signer accounts.
  300. */
  301. Token_TokenInstruction_ThawAccount,
  302. } Token_TokenInstruction_Tag;
  303. typedef struct Token_TokenInstruction_Token_InitializeMint_Body {
  304. /**
  305. * Number of base 10 digits to the right of the decimal place.
  306. */
  307. uint8_t decimals;
  308. /**
  309. * The authority/multisignature to mint tokens.
  310. */
  311. Token_Pubkey mint_authority;
  312. /**
  313. * The freeze authority/multisignature of the mint.
  314. */
  315. Token_COption_Pubkey freeze_authority;
  316. } Token_TokenInstruction_Token_InitializeMint_Body;
  317. typedef struct Token_TokenInstruction_Token_InitializeMultisig_Body {
  318. /**
  319. * The number of signers (M) required to validate this multisignature account.
  320. */
  321. uint8_t m;
  322. } Token_TokenInstruction_Token_InitializeMultisig_Body;
  323. typedef struct Token_TokenInstruction_Token_Transfer_Body {
  324. /**
  325. * The amount of tokens to transfer.
  326. */
  327. uint64_t amount;
  328. } Token_TokenInstruction_Token_Transfer_Body;
  329. typedef struct Token_TokenInstruction_Token_Approve_Body {
  330. /**
  331. * The amount of tokens the delegate is approved for.
  332. */
  333. uint64_t amount;
  334. } Token_TokenInstruction_Token_Approve_Body;
  335. typedef struct Token_TokenInstruction_Token_SetAuthority_Body {
  336. /**
  337. * The type of authority to update.
  338. */
  339. Token_AuthorityType authority_type;
  340. /**
  341. * The new authority
  342. */
  343. Token_COption_Pubkey new_authority;
  344. } Token_TokenInstruction_Token_SetAuthority_Body;
  345. typedef struct Token_TokenInstruction_Token_MintTo_Body {
  346. /**
  347. * The amount of new tokens to mint.
  348. */
  349. uint64_t amount;
  350. } Token_TokenInstruction_Token_MintTo_Body;
  351. typedef struct Token_TokenInstruction_Token_Burn_Body {
  352. /**
  353. * The amount of tokens to burn.
  354. */
  355. uint64_t amount;
  356. } Token_TokenInstruction_Token_Burn_Body;
  357. typedef struct Token_TokenInstruction {
  358. Token_TokenInstruction_Tag tag;
  359. union {
  360. Token_TokenInstruction_Token_InitializeMint_Body initialize_mint;
  361. Token_TokenInstruction_Token_InitializeMultisig_Body initialize_multisig;
  362. Token_TokenInstruction_Token_Transfer_Body transfer;
  363. Token_TokenInstruction_Token_Approve_Body approve;
  364. Token_TokenInstruction_Token_SetAuthority_Body set_authority;
  365. Token_TokenInstruction_Token_MintTo_Body mint_to;
  366. Token_TokenInstruction_Token_Burn_Body burn;
  367. };
  368. } Token_TokenInstruction;
  369. /**
  370. * Mint data.
  371. */
  372. typedef struct Token_Mint {
  373. /**
  374. * Optional authority used to mint new tokens. The mint authority may only be provided during
  375. * mint creation. If no mint authority is present then the mint has a fixed supply and no
  376. * further tokens may be minted.
  377. */
  378. Token_COption_Pubkey mint_authority;
  379. /**
  380. * Total supply of tokens.
  381. */
  382. uint64_t supply;
  383. /**
  384. * Number of base 10 digits to the right of the decimal place.
  385. */
  386. uint8_t decimals;
  387. /**
  388. * Is `true` if this structure has been initialized
  389. */
  390. bool is_initialized;
  391. /**
  392. * Optional authority to freeze token accounts.
  393. */
  394. Token_COption_Pubkey freeze_authority;
  395. } Token_Mint;
  396. /**
  397. * A C representation of Rust's `std::option::Option`
  398. */
  399. typedef enum Token_COption_u64_Tag {
  400. /**
  401. * No value
  402. */
  403. Token_COption_u64_None_u64,
  404. /**
  405. * Some value `T`
  406. */
  407. Token_COption_u64_Some_u64,
  408. } Token_COption_u64_Tag;
  409. typedef struct Token_COption_u64_Token_Some_Body_u64 {
  410. uint64_t _0;
  411. } Token_COption_u64_Token_Some_Body_u64;
  412. typedef struct Token_COption_u64 {
  413. Token_COption_u64_Tag tag;
  414. union {
  415. Token_COption_u64_Token_Some_Body_u64 some;
  416. };
  417. } Token_COption_u64;
  418. /**
  419. * Account data.
  420. */
  421. typedef struct Token_Account {
  422. /**
  423. * The mint associated with this account
  424. */
  425. Token_Pubkey mint;
  426. /**
  427. * The owner of this account.
  428. */
  429. Token_Pubkey owner;
  430. /**
  431. * The amount of tokens this account holds.
  432. */
  433. uint64_t amount;
  434. /**
  435. * If `delegate` is `Some` then `delegated_amount` represents
  436. * the amount authorized by the delegate
  437. */
  438. Token_COption_Pubkey delegate;
  439. /**
  440. * The account's state
  441. */
  442. Token_AccountState state;
  443. /**
  444. * If is_some, this is a native token, and the value logs the rent-exempt reserve. An Account
  445. * is required to be rent-exempt, so the value is used by the Processor to ensure that wrapped
  446. * SOL accounts do not drop below this threshold.
  447. */
  448. Token_COption_u64 is_native;
  449. /**
  450. * The amount delegated
  451. */
  452. uint64_t delegated_amount;
  453. /**
  454. * Optional authority to close the account.
  455. */
  456. Token_COption_Pubkey close_authority;
  457. } Token_Account;
  458. /**
  459. * Multisignature data.
  460. */
  461. typedef struct Token_Multisig {
  462. /**
  463. * Number of signers required
  464. */
  465. uint8_t m;
  466. /**
  467. * Number of valid signers
  468. */
  469. uint8_t n;
  470. /**
  471. * Is `true` if this structure has been initialized
  472. */
  473. bool is_initialized;
  474. /**
  475. * Signer public keys
  476. */
  477. Token_Pubkey signers[Token_MAX_SIGNERS];
  478. } Token_Multisig;