token.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 0
  9. #define TOKEN_PATCH_VERSION 6
  10. /**
  11. * There are 10^9 lamports in one SOL
  12. */
  13. #define Token_DECIMALS 9
  14. /**
  15. * Maximum number of multisignature signers (max N)
  16. */
  17. #define Token_MAX_SIGNERS 11
  18. /**
  19. * Minimum number of multisignature signers (min N)
  20. */
  21. #define Token_MIN_SIGNERS 1
  22. /**
  23. * Instructions supported by the token program.
  24. */
  25. typedef enum Token_TokenInstruction_Tag {
  26. /**
  27. * Initializes a new mint and optionally deposits all the newly minted tokens in an account.
  28. *
  29. * The `InitializeMint` instruction requires no signers and MUST be included within
  30. * the same Transaction as the system program's `CreateInstruction` that creates the account
  31. * being initialized. Otherwise another party can acquire ownership of the uninitialized account.
  32. *
  33. * Accounts expected by this instruction:
  34. *
  35. * 0. `[writable]` The mint to initialize.
  36. * 1.
  37. * * If supply is non-zero: `[writable]` The account to hold all the newly minted tokens.
  38. * * If supply is zero: `[]` The owner/multisignature of the mint.
  39. * 2. `[]` (optional) The owner/multisignature of the mint if supply is non-zero, if
  40. * present then further minting is supported.
  41. *
  42. */
  43. Token_TokenInstruction_InitializeMint,
  44. /**
  45. * Initializes a new account to hold tokens. If this account is associated with the native mint
  46. * then the token balance of the initialized account will be equal to the amount of SOL in the account.
  47. *
  48. * The `InitializeAccount` instruction requires no signers and MUST be included within
  49. * the same Transaction as the system program's `CreateInstruction` that creates the account
  50. * being initialized. Otherwise another party can acquire ownership of the uninitialized account.
  51. *
  52. * Accounts expected by this instruction:
  53. *
  54. * 0. `[writable]` The account to initialize.
  55. * 1. `[]` The mint this account will be associated with.
  56. * 2. `[]` The new account's owner/multisignature.
  57. */
  58. Token_TokenInstruction_InitializeAccount,
  59. /**
  60. * Initializes a multisignature account with N provided signers.
  61. *
  62. * Multisignature accounts can used in place of any single owner/delegate accounts in any
  63. * token instruction that require an owner/delegate to be present. The variant field represents the
  64. * number of signers (M) required to validate this multisignature account.
  65. *
  66. * The `InitializeMultisig` instruction requires no signers and MUST be included within
  67. * the same Transaction as the system program's `CreateInstruction` that creates the account
  68. * being initialized. Otherwise another party can acquire ownership of the uninitialized account.
  69. *
  70. * Accounts expected by this instruction:
  71. *
  72. * 0. `[writable]` The multisignature account to initialize.
  73. * 1. ..1+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
  74. */
  75. Token_TokenInstruction_InitializeMultisig,
  76. /**
  77. * Transfers tokens from one account to another either directly or via a delegate. If this
  78. * account is associated with the native mint then equal amounts of SOL and Tokens will be
  79. * transferred to the destination account.
  80. *
  81. * Accounts expected by this instruction:
  82. *
  83. * * Single owner/delegate
  84. * 0. `[writable]` The source account.
  85. * 1. `[writable]` The destination account.
  86. * 2. '[signer]' The source account's owner/delegate.
  87. *
  88. * * Multisignature owner/delegate
  89. * 0. `[writable]` The source account.
  90. * 1. `[writable]` The destination account.
  91. * 2. '[]' The source account's multisignature owner/delegate.
  92. * 3. ..3+M '[signer]' M signer accounts.
  93. */
  94. Token_TokenInstruction_Transfer,
  95. /**
  96. * Approves a delegate. A delegate is given the authority over
  97. * tokens on behalf of the source account's owner.
  98. * Accounts expected by this instruction:
  99. *
  100. * * Single owner
  101. * 0. `[writable]` The source account.
  102. * 1. `[]` The delegate.
  103. * 2. `[signer]` The source account owner.
  104. *
  105. * * Multisignature owner
  106. * 0. `[writable]` The source account.
  107. * 1. `[]` The delegate.
  108. * 2. '[]' The source account's multisignature owner.
  109. * 3. ..3+M '[signer]' M signer accounts
  110. */
  111. Token_TokenInstruction_Approve,
  112. /**
  113. * Revokes the delegate's authority.
  114. *
  115. * Accounts expected by this instruction:
  116. *
  117. * * Single owner
  118. * 0. `[writable]` The source account.
  119. * 1. `[signer]` The source account owner.
  120. *
  121. * * Multisignature owner
  122. * 0. `[writable]` The source account.
  123. * 1. '[]' The source account's multisignature owner.
  124. * 2. ..2+M '[signer]' M signer accounts
  125. */
  126. Token_TokenInstruction_Revoke,
  127. /**
  128. * Sets a new owner of a mint or account.
  129. *
  130. * Accounts expected by this instruction:
  131. *
  132. * * Single owner
  133. * 0. `[writable]` The mint or account to change the owner of.
  134. * 1. `[]` The new owner/delegate/multisignature.
  135. * 2. `[signer]` The owner of the mint or account.
  136. *
  137. * * Multisignature owner
  138. * 0. `[writable]` The mint or account to change the owner of.
  139. * 1. `[]` The new owner/delegate/multisignature.
  140. * 2. `[]` The mint's or account's multisignature owner.
  141. * 3. ..3+M '[signer]' M signer accounts
  142. */
  143. Token_TokenInstruction_SetOwner,
  144. /**
  145. * Mints new tokens to an account. The native mint does not support minting.
  146. *
  147. * Accounts expected by this instruction:
  148. *
  149. * * Single owner
  150. * 0. `[writable]` The mint.
  151. * 1. `[writable]` The account to mint tokens to.
  152. * 2. `[signer]` The mint's owner.
  153. *
  154. * * Multisignature owner
  155. * 0. `[writable]` The mint.
  156. * 1. `[writable]` The account to mint tokens to.
  157. * 2. `[]` The mint's multisignature owner.
  158. * 3. ..3+M '[signer]' M signer accounts.
  159. */
  160. Token_TokenInstruction_MintTo,
  161. /**
  162. * Burns tokens by removing them from an account. `Burn` does not support accounts
  163. * associated with the native mint, use `CloseAccount` instead.
  164. *
  165. * Accounts expected by this instruction:
  166. *
  167. * * Single owner/delegate
  168. * 0. `[writable]` The account to burn from.
  169. * 1. `[signer]` The account's owner/delegate.
  170. *
  171. * * Multisignature owner/delegate
  172. * 0. `[writable]` The account to burn from.
  173. * 1. `[]` The account's multisignature owner/delegate.
  174. * 2. ..2+M '[signer]' M signer accounts.
  175. */
  176. Token_TokenInstruction_Burn,
  177. /**
  178. * Close an account by transferring all its SOL to the destination account.
  179. * Non-native accounts may only be closed if its token amount is zero.
  180. *
  181. * Accounts expected by this instruction:
  182. *
  183. * * Single owner
  184. * 0. `[writable]` The account to close.
  185. * 1. '[writable]' The destination account.
  186. * 2. `[signer]` The account's owner.
  187. *
  188. * * Multisignature owner
  189. * 0. `[writable]` The account to close.
  190. * 1. '[writable]' The destination account.
  191. * 2. `[]` The account's multisignature owner.
  192. * 3. ..3+M '[signer]' M signer accounts.
  193. */
  194. Token_TokenInstruction_CloseAccount,
  195. } Token_TokenInstruction_Tag;
  196. typedef struct Token_TokenInstruction_Token_InitializeMint_Body {
  197. /**
  198. * Initial amount of tokens to mint.
  199. */
  200. uint64_t amount;
  201. /**
  202. * Number of base 10 digits to the right of the decimal place.
  203. */
  204. uint8_t decimals;
  205. } Token_TokenInstruction_Token_InitializeMint_Body;
  206. typedef struct Token_TokenInstruction_Token_InitializeMultisig_Body {
  207. /**
  208. * The number of signers (M) required to validate this multisignature account.
  209. */
  210. uint8_t m;
  211. } Token_TokenInstruction_Token_InitializeMultisig_Body;
  212. typedef struct Token_TokenInstruction_Token_Transfer_Body {
  213. /**
  214. * The amount of tokens to transfer.
  215. */
  216. uint64_t amount;
  217. } Token_TokenInstruction_Token_Transfer_Body;
  218. typedef struct Token_TokenInstruction_Token_Approve_Body {
  219. /**
  220. * The amount of tokens the delegate is approved for.
  221. */
  222. uint64_t amount;
  223. } Token_TokenInstruction_Token_Approve_Body;
  224. typedef struct Token_TokenInstruction_Token_MintTo_Body {
  225. /**
  226. * The amount of new tokens to mint.
  227. */
  228. uint64_t amount;
  229. } Token_TokenInstruction_Token_MintTo_Body;
  230. typedef struct Token_TokenInstruction_Token_Burn_Body {
  231. /**
  232. * The amount of tokens to burn.
  233. */
  234. uint64_t amount;
  235. } Token_TokenInstruction_Token_Burn_Body;
  236. typedef struct Token_TokenInstruction {
  237. Token_TokenInstruction_Tag tag;
  238. union {
  239. Token_TokenInstruction_Token_InitializeMint_Body initialize_mint;
  240. Token_TokenInstruction_Token_InitializeMultisig_Body initialize_multisig;
  241. Token_TokenInstruction_Token_Transfer_Body transfer;
  242. Token_TokenInstruction_Token_Approve_Body approve;
  243. Token_TokenInstruction_Token_MintTo_Body mint_to;
  244. Token_TokenInstruction_Token_Burn_Body burn;
  245. };
  246. } Token_TokenInstruction;
  247. typedef uint8_t Token_Pubkey[32];
  248. /**
  249. * A C representation of Rust's `std::option::Option`
  250. */
  251. typedef enum Token_COption_Pubkey_Tag {
  252. /**
  253. * No value
  254. */
  255. Token_COption_Pubkey_None_Pubkey,
  256. /**
  257. * Some value `T`
  258. */
  259. Token_COption_Pubkey_Some_Pubkey,
  260. } Token_COption_Pubkey_Tag;
  261. typedef struct Token_COption_Pubkey_Token_Some_Body_Pubkey {
  262. Token_Pubkey _0;
  263. } Token_COption_Pubkey_Token_Some_Body_Pubkey;
  264. typedef struct Token_COption_Pubkey {
  265. Token_COption_Pubkey_Tag tag;
  266. union {
  267. Token_COption_Pubkey_Token_Some_Body_Pubkey some;
  268. };
  269. } Token_COption_Pubkey;
  270. /**
  271. * Mint data.
  272. */
  273. typedef struct Token_Mint {
  274. /**
  275. * Optional owner, used to mint new tokens. The owner may only
  276. * be provided during mint creation. If no owner is present then the mint
  277. * has a fixed supply and no further tokens may be minted.
  278. */
  279. Token_COption_Pubkey owner;
  280. /**
  281. * Number of base 10 digits to the right of the decimal place.
  282. */
  283. uint8_t decimals;
  284. /**
  285. * Is `true` if this structure has been initialized
  286. */
  287. bool is_initialized;
  288. } Token_Mint;
  289. /**
  290. * Account data.
  291. */
  292. typedef struct Token_Account {
  293. /**
  294. * The mint associated with this account
  295. */
  296. Token_Pubkey mint;
  297. /**
  298. * The owner of this account.
  299. */
  300. Token_Pubkey owner;
  301. /**
  302. * The amount of tokens this account holds.
  303. */
  304. uint64_t amount;
  305. /**
  306. * If `delegate` is `Some` then `delegated_amount` represents
  307. * the amount authorized by the delegate
  308. */
  309. Token_COption_Pubkey delegate;
  310. /**
  311. * Is `true` if this structure has been initialized
  312. */
  313. bool is_initialized;
  314. /**
  315. * Is this a native token
  316. */
  317. bool is_native;
  318. /**
  319. * The amount delegated
  320. */
  321. uint64_t delegated_amount;
  322. } Token_Account;
  323. /**
  324. * Multisignature data.
  325. */
  326. typedef struct Token_Multisig {
  327. /**
  328. * Number of signers required
  329. */
  330. uint8_t m;
  331. /**
  332. * Number of valid signers
  333. */
  334. uint8_t n;
  335. /**
  336. * Is `true` if this structure has been initialized
  337. */
  338. bool is_initialized;
  339. /**
  340. * Signer public keys
  341. */
  342. Token_Pubkey signers[Token_MAX_SIGNERS];
  343. } Token_Multisig;