lib.rs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. // This file is autogenerated with https://github.com/acheroncrypto/native-to-anchor
  2. use anchor_lang::prelude::*;
  3. declare_id!("11111111111111111111111111111111");
  4. #[program]
  5. pub mod spl_token {
  6. use super::*;
  7. pub fn initialize_mint(
  8. ctx: Context<InitializeMint>,
  9. decimals: u8,
  10. mint_authority: Pubkey,
  11. freeze_authority: COption<Pubkey>,
  12. ) -> Result<()> {
  13. Ok(())
  14. }
  15. pub fn initialize_account(ctx: Context<InitializeAccount>) -> Result<()> {
  16. Ok(())
  17. }
  18. pub fn initialize_multisig(ctx: Context<InitializeMultisig>, m: u8) -> Result<()> {
  19. Ok(())
  20. }
  21. pub fn transfer(ctx: Context<Transfer>, amount: u64) -> Result<()> {
  22. Ok(())
  23. }
  24. pub fn approve(ctx: Context<Approve>, amount: u64) -> Result<()> {
  25. Ok(())
  26. }
  27. pub fn revoke(ctx: Context<Revoke>) -> Result<()> {
  28. Ok(())
  29. }
  30. pub fn set_authority(
  31. ctx: Context<SetAuthority>,
  32. authority_type: AuthorityType,
  33. new_authority: COption<Pubkey>,
  34. ) -> Result<()> {
  35. Ok(())
  36. }
  37. pub fn mint_to(ctx: Context<MintTo>, amount: u64) -> Result<()> {
  38. Ok(())
  39. }
  40. pub fn burn(ctx: Context<Burn>, amount: u64) -> Result<()> {
  41. Ok(())
  42. }
  43. pub fn close_account(ctx: Context<CloseAccount>) -> Result<()> {
  44. Ok(())
  45. }
  46. pub fn freeze_account(ctx: Context<FreezeAccount>) -> Result<()> {
  47. Ok(())
  48. }
  49. pub fn thaw_account(ctx: Context<ThawAccount>) -> Result<()> {
  50. Ok(())
  51. }
  52. pub fn transfer_checked(
  53. ctx: Context<TransferChecked>,
  54. amount: u64,
  55. decimals: u8,
  56. ) -> Result<()> {
  57. Ok(())
  58. }
  59. pub fn approve_checked(ctx: Context<ApproveChecked>, amount: u64, decimals: u8) -> Result<()> {
  60. Ok(())
  61. }
  62. pub fn mint_to_checked(ctx: Context<MintToChecked>, amount: u64, decimals: u8) -> Result<()> {
  63. Ok(())
  64. }
  65. pub fn burn_checked(ctx: Context<BurnChecked>, amount: u64, decimals: u8) -> Result<()> {
  66. Ok(())
  67. }
  68. pub fn initialize_account2(ctx: Context<InitializeAccount2>, owner: Pubkey) -> Result<()> {
  69. Ok(())
  70. }
  71. pub fn sync_native(ctx: Context<SyncNative>) -> Result<()> {
  72. Ok(())
  73. }
  74. pub fn initialize_account3(ctx: Context<InitializeAccount3>, owner: Pubkey) -> Result<()> {
  75. Ok(())
  76. }
  77. pub fn initialize_multisig2(ctx: Context<InitializeMultisig2>, m: u8) -> Result<()> {
  78. Ok(())
  79. }
  80. pub fn initialize_mint2(
  81. ctx: Context<InitializeMint2>,
  82. decimals: u8,
  83. mint_authority: Pubkey,
  84. freeze_authority: COption<Pubkey>,
  85. ) -> Result<()> {
  86. Ok(())
  87. }
  88. pub fn get_account_data_size(ctx: Context<GetAccountDataSize>) -> Result<()> {
  89. Ok(())
  90. }
  91. pub fn initialize_immutable_owner(ctx: Context<InitializeImmutableOwner>) -> Result<()> {
  92. Ok(())
  93. }
  94. pub fn amount_to_ui_amount(ctx: Context<AmountToUiAmount>, amount: u64) -> Result<()> {
  95. Ok(())
  96. }
  97. pub fn ui_amount_to_amount(ctx: Context<UiAmountToAmount>, ui_amount: &'a str) -> Result<()> {
  98. Ok(())
  99. }
  100. }
  101. #[derive(Accounts)]
  102. pub struct InitializeMint<'info> {
  103. #[account(mut)]
  104. mint: AccountInfo<'info>,
  105. rent: Sysvar<'info, Rent>,
  106. }
  107. #[derive(Accounts)]
  108. pub struct InitializeAccount<'info> {
  109. #[account(mut)]
  110. account: AccountInfo<'info>,
  111. mint: AccountInfo<'info>,
  112. owner: AccountInfo<'info>,
  113. rent: Sysvar<'info, Rent>,
  114. }
  115. #[derive(Accounts)]
  116. pub struct InitializeMultisig<'info> {
  117. #[account(mut)]
  118. multisig: AccountInfo<'info>,
  119. rent: Sysvar<'info, Rent>,
  120. // optional_signer: AccountInfo<'info>,
  121. }
  122. #[derive(Accounts)]
  123. pub struct Transfer<'info> {
  124. #[account(mut)]
  125. source: AccountInfo<'info>,
  126. #[account(mut)]
  127. destination: AccountInfo<'info>,
  128. authority: Signer<'info>,
  129. // optional_signer: Signer<'info>,
  130. }
  131. #[derive(Accounts)]
  132. pub struct Approve<'info> {
  133. #[account(mut)]
  134. source: AccountInfo<'info>,
  135. delegate: AccountInfo<'info>,
  136. owner: Signer<'info>,
  137. // optional_signer: Signer<'info>,
  138. }
  139. #[derive(Accounts)]
  140. pub struct Revoke<'info> {
  141. #[account(mut)]
  142. source: AccountInfo<'info>,
  143. owner: Signer<'info>,
  144. // optional_signer: Signer<'info>,
  145. }
  146. #[derive(Accounts)]
  147. pub struct SetAuthority<'info> {
  148. #[account(mut)]
  149. owned: AccountInfo<'info>,
  150. owner: Signer<'info>,
  151. signer: Signer<'info>,
  152. }
  153. #[derive(Accounts)]
  154. pub struct MintTo<'info> {
  155. #[account(mut)]
  156. mint: AccountInfo<'info>,
  157. #[account(mut)]
  158. account: AccountInfo<'info>,
  159. owner: Signer<'info>,
  160. // optional_signer: Signer<'info>,
  161. }
  162. #[derive(Accounts)]
  163. pub struct Burn<'info> {
  164. #[account(mut)]
  165. account: AccountInfo<'info>,
  166. #[account(mut)]
  167. mint: AccountInfo<'info>,
  168. authority: Signer<'info>,
  169. // optional_signer: Signer<'info>,
  170. }
  171. #[derive(Accounts)]
  172. pub struct CloseAccount<'info> {
  173. #[account(mut)]
  174. account: AccountInfo<'info>,
  175. #[account(mut)]
  176. destination: AccountInfo<'info>,
  177. owner: Signer<'info>,
  178. // optional_signer: Signer<'info>,
  179. }
  180. #[derive(Accounts)]
  181. pub struct FreezeAccount<'info> {
  182. #[account(mut)]
  183. account: AccountInfo<'info>,
  184. mint: AccountInfo<'info>,
  185. owner: Signer<'info>,
  186. // optional_signer: Signer<'info>,
  187. }
  188. #[derive(Accounts)]
  189. pub struct ThawAccount<'info> {
  190. #[account(mut)]
  191. account: AccountInfo<'info>,
  192. mint: AccountInfo<'info>,
  193. owner: Signer<'info>,
  194. // optional_signer: Signer<'info>,
  195. }
  196. #[derive(Accounts)]
  197. pub struct TransferChecked<'info> {
  198. #[account(mut)]
  199. source: AccountInfo<'info>,
  200. mint: AccountInfo<'info>,
  201. #[account(mut)]
  202. destination: AccountInfo<'info>,
  203. authority: Signer<'info>,
  204. // optional_signer: Signer<'info>,
  205. }
  206. #[derive(Accounts)]
  207. pub struct ApproveChecked<'info> {
  208. #[account(mut)]
  209. source: AccountInfo<'info>,
  210. mint: AccountInfo<'info>,
  211. delegate: AccountInfo<'info>,
  212. owner: Signer<'info>,
  213. // optional_signer: Signer<'info>,
  214. }
  215. #[derive(Accounts)]
  216. pub struct MintToChecked<'info> {
  217. #[account(mut)]
  218. mint: AccountInfo<'info>,
  219. #[account(mut)]
  220. account: AccountInfo<'info>,
  221. owner: Signer<'info>,
  222. // optional_signer: Signer<'info>,
  223. }
  224. #[derive(Accounts)]
  225. pub struct BurnChecked<'info> {
  226. #[account(mut)]
  227. account: AccountInfo<'info>,
  228. #[account(mut)]
  229. mint: AccountInfo<'info>,
  230. authority: Signer<'info>,
  231. // optional_signer: Signer<'info>,
  232. }
  233. #[derive(Accounts)]
  234. pub struct InitializeAccount2<'info> {
  235. #[account(mut)]
  236. account: AccountInfo<'info>,
  237. mint: AccountInfo<'info>,
  238. rent: Sysvar<'info, Rent>,
  239. }
  240. #[derive(Accounts)]
  241. pub struct SyncNative<'info> {
  242. #[account(mut)]
  243. account: AccountInfo<'info>,
  244. }
  245. #[derive(Accounts)]
  246. pub struct InitializeAccount3<'info> {
  247. #[account(mut)]
  248. account: AccountInfo<'info>,
  249. mint: AccountInfo<'info>,
  250. }
  251. #[derive(Accounts)]
  252. pub struct InitializeMultisig2<'info> {
  253. #[account(mut)]
  254. multisig: AccountInfo<'info>,
  255. signer: AccountInfo<'info>,
  256. }
  257. #[derive(Accounts)]
  258. pub struct InitializeMint2<'info> {
  259. #[account(mut)]
  260. mint: AccountInfo<'info>,
  261. }
  262. #[derive(Accounts)]
  263. pub struct GetAccountDataSize<'info> {
  264. mint: AccountInfo<'info>,
  265. }
  266. #[derive(Accounts)]
  267. pub struct InitializeImmutableOwner<'info> {
  268. #[account(mut)]
  269. account: AccountInfo<'info>,
  270. }
  271. #[derive(Accounts)]
  272. pub struct AmountToUiAmount<'info> {
  273. mint: AccountInfo<'info>,
  274. }
  275. #[derive(Accounts)]
  276. pub struct UiAmountToAmount<'info> {
  277. mint: AccountInfo<'info>,
  278. }
  279. #[account]
  280. pub struct Mint {
  281. /// Optional authority used to mint new tokens. The mint authority may only be provided during
  282. /// mint creation. If no mint authority is present then the mint has a fixed supply and no
  283. /// further tokens may be minted.
  284. pub mint_authority: COption<Pubkey>,
  285. /// Total supply of tokens.
  286. pub supply: u64,
  287. /// Number of base 10 digits to the right of the decimal place.
  288. pub decimals: u8,
  289. /// Is `true` if this structure has been initialized
  290. pub is_initialized: bool,
  291. /// Optional authority to freeze token accounts.
  292. pub freeze_authority: COption<Pubkey>,
  293. }
  294. #[account]
  295. pub struct Account {
  296. /// The mint associated with this account
  297. pub mint: Pubkey,
  298. /// The owner of this account.
  299. pub owner: Pubkey,
  300. /// The amount of tokens this account holds.
  301. pub amount: u64,
  302. /// If `delegate` is `Some` then `delegated_amount` represents
  303. /// the amount authorized by the delegate
  304. pub delegate: COption<Pubkey>,
  305. /// The account's state
  306. pub state: AccountState,
  307. /// If is_native.is_some, this is a native token, and the value logs the rent-exempt reserve. An
  308. /// Account is required to be rent-exempt, so the value is used by the Processor to ensure that
  309. /// wrapped SOL accounts do not drop below this threshold.
  310. pub is_native: COption<u64>,
  311. /// The amount delegated
  312. pub delegated_amount: u64,
  313. /// Optional authority to close the account.
  314. pub close_authority: COption<Pubkey>,
  315. }
  316. #[account]
  317. pub struct Multisig {
  318. /// Number of signers required
  319. pub m: u8,
  320. /// Number of valid signers
  321. pub n: u8,
  322. /// Is `true` if this structure has been initialized
  323. pub is_initialized: bool,
  324. /// Signer public keys
  325. pub signers: [Pubkey; 11],
  326. }
  327. #[derive(AnchorSerialize, AnchorDeserialize)]
  328. pub enum AccountState {
  329. /// Account is not yet initialized
  330. Uninitialized,
  331. /// Account is initialized; the account owner and/or delegate may perform permitted operations
  332. /// on this account
  333. Initialized,
  334. /// Account has been frozen by the mint freeze authority. Neither the account owner nor
  335. /// the delegate are able to perform operations on this account.
  336. Frozen,
  337. }
  338. #[derive(AnchorSerialize, AnchorDeserialize)]
  339. pub enum AuthorityType {
  340. /// Authority to mint new tokens
  341. MintTokens,
  342. /// Authority to freeze any account associated with the Mint
  343. FreezeAccount,
  344. /// Owner of a given token account
  345. AccountOwner,
  346. /// Authority to close a token account
  347. CloseAccount,
  348. }
  349. #[error_code]
  350. pub enum TokenError {
  351. // 0
  352. /// Lamport balance below rent-exempt threshold.
  353. #[msg("Lamport balance below rent-exempt threshold")]
  354. NotRentExempt,
  355. /// Insufficient funds for the operation requested.
  356. #[msg("Insufficient funds")]
  357. InsufficientFunds,
  358. /// Invalid Mint.
  359. #[msg("Invalid Mint")]
  360. InvalidMint,
  361. /// Account not associated with this Mint.
  362. #[msg("Account not associated with this Mint")]
  363. MintMismatch,
  364. /// Owner does not match.
  365. #[msg("Owner does not match")]
  366. OwnerMismatch,
  367. // 5
  368. /// This token's supply is fixed and new tokens cannot be minted.
  369. #[msg("Fixed supply")]
  370. FixedSupply,
  371. /// The account cannot be initialized because it is already being used.
  372. #[msg("Already in use")]
  373. AlreadyInUse,
  374. /// Invalid number of provided signers.
  375. #[msg("Invalid number of provided signers")]
  376. InvalidNumberOfProvidedSigners,
  377. /// Invalid number of required signers.
  378. #[msg("Invalid number of required signers")]
  379. InvalidNumberOfRequiredSigners,
  380. /// State is uninitialized.
  381. #[msg("State is unititialized")]
  382. UninitializedState,
  383. // 10
  384. /// Instruction does not support native tokens
  385. #[msg("Instruction does not support native tokens")]
  386. NativeNotSupported,
  387. /// Non-native account can only be closed if its balance is zero
  388. #[msg("Non-native account can only be closed if its balance is zero")]
  389. NonNativeHasBalance,
  390. /// Invalid instruction
  391. #[msg("Invalid instruction")]
  392. InvalidInstruction,
  393. /// State is invalid for requested operation.
  394. #[msg("State is invalid for requested operation")]
  395. InvalidState,
  396. /// Operation overflowed
  397. #[msg("Operation overflowed")]
  398. Overflow,
  399. // 15
  400. /// Account does not support specified authority type.
  401. #[msg("Account does not support specified authority type")]
  402. AuthorityTypeNotSupported,
  403. /// This token mint cannot freeze accounts.
  404. #[msg("This token mint cannot freeze accounts")]
  405. MintCannotFreeze,
  406. /// Account is frozen; all account operations will fail
  407. #[msg("Account is frozen")]
  408. AccountFrozen,
  409. /// Mint decimals mismatch between the client and mint
  410. #[msg("The provided decimals value different from the Mint decimals")]
  411. MintDecimalsMismatch,
  412. /// Instruction does not support non-native tokens
  413. #[msg("Instruction does not support non-native tokens")]
  414. NonNativeNotSupported,
  415. }