token.h 15 KB

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