mint.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * This code was AUTOGENERATED using the codama library.
  3. * Please DO NOT EDIT THIS FILE, instead use visitors
  4. * to add features, then rerun codama to update it.
  5. *
  6. * @see https://github.com/codama-idl/codama
  7. */
  8. import {
  9. assertAccountExists,
  10. assertAccountsExist,
  11. combineCodec,
  12. decodeAccount,
  13. fetchEncodedAccount,
  14. fetchEncodedAccounts,
  15. getAddressDecoder,
  16. getAddressEncoder,
  17. getBooleanDecoder,
  18. getBooleanEncoder,
  19. getOptionDecoder,
  20. getOptionEncoder,
  21. getStructDecoder,
  22. getStructEncoder,
  23. getU32Decoder,
  24. getU32Encoder,
  25. getU64Decoder,
  26. getU64Encoder,
  27. getU8Decoder,
  28. getU8Encoder,
  29. type Account,
  30. type Address,
  31. type EncodedAccount,
  32. type FetchAccountConfig,
  33. type FetchAccountsConfig,
  34. type FixedSizeCodec,
  35. type FixedSizeDecoder,
  36. type FixedSizeEncoder,
  37. type MaybeAccount,
  38. type MaybeEncodedAccount,
  39. type Option,
  40. type OptionOrNullable,
  41. } from '@solana/kit';
  42. export type Mint = {
  43. /**
  44. * Optional authority used to mint new tokens. The mint authority may only
  45. * be provided during mint creation. If no mint authority is present
  46. * then the mint has a fixed supply and no further tokens may be minted.
  47. */
  48. mintAuthority: Option<Address>;
  49. /** Total supply of tokens. */
  50. supply: bigint;
  51. /** Number of base 10 digits to the right of the decimal place. */
  52. decimals: number;
  53. /** Is `true` if this structure has been initialized. */
  54. isInitialized: boolean;
  55. /** Optional authority to freeze token accounts. */
  56. freezeAuthority: Option<Address>;
  57. };
  58. export type MintArgs = {
  59. /**
  60. * Optional authority used to mint new tokens. The mint authority may only
  61. * be provided during mint creation. If no mint authority is present
  62. * then the mint has a fixed supply and no further tokens may be minted.
  63. */
  64. mintAuthority: OptionOrNullable<Address>;
  65. /** Total supply of tokens. */
  66. supply: number | bigint;
  67. /** Number of base 10 digits to the right of the decimal place. */
  68. decimals: number;
  69. /** Is `true` if this structure has been initialized. */
  70. isInitialized: boolean;
  71. /** Optional authority to freeze token accounts. */
  72. freezeAuthority: OptionOrNullable<Address>;
  73. };
  74. export function getMintEncoder(): FixedSizeEncoder<MintArgs> {
  75. return getStructEncoder([
  76. [
  77. 'mintAuthority',
  78. getOptionEncoder(getAddressEncoder(), {
  79. prefix: getU32Encoder(),
  80. noneValue: 'zeroes',
  81. }),
  82. ],
  83. ['supply', getU64Encoder()],
  84. ['decimals', getU8Encoder()],
  85. ['isInitialized', getBooleanEncoder()],
  86. [
  87. 'freezeAuthority',
  88. getOptionEncoder(getAddressEncoder(), {
  89. prefix: getU32Encoder(),
  90. noneValue: 'zeroes',
  91. }),
  92. ],
  93. ]);
  94. }
  95. export function getMintDecoder(): FixedSizeDecoder<Mint> {
  96. return getStructDecoder([
  97. [
  98. 'mintAuthority',
  99. getOptionDecoder(getAddressDecoder(), {
  100. prefix: getU32Decoder(),
  101. noneValue: 'zeroes',
  102. }),
  103. ],
  104. ['supply', getU64Decoder()],
  105. ['decimals', getU8Decoder()],
  106. ['isInitialized', getBooleanDecoder()],
  107. [
  108. 'freezeAuthority',
  109. getOptionDecoder(getAddressDecoder(), {
  110. prefix: getU32Decoder(),
  111. noneValue: 'zeroes',
  112. }),
  113. ],
  114. ]);
  115. }
  116. export function getMintCodec(): FixedSizeCodec<MintArgs, Mint> {
  117. return combineCodec(getMintEncoder(), getMintDecoder());
  118. }
  119. export function decodeMint<TAddress extends string = string>(
  120. encodedAccount: EncodedAccount<TAddress>
  121. ): Account<Mint, TAddress>;
  122. export function decodeMint<TAddress extends string = string>(
  123. encodedAccount: MaybeEncodedAccount<TAddress>
  124. ): MaybeAccount<Mint, TAddress>;
  125. export function decodeMint<TAddress extends string = string>(
  126. encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>
  127. ): Account<Mint, TAddress> | MaybeAccount<Mint, TAddress> {
  128. return decodeAccount(
  129. encodedAccount as MaybeEncodedAccount<TAddress>,
  130. getMintDecoder()
  131. );
  132. }
  133. export async function fetchMint<TAddress extends string = string>(
  134. rpc: Parameters<typeof fetchEncodedAccount>[0],
  135. address: Address<TAddress>,
  136. config?: FetchAccountConfig
  137. ): Promise<Account<Mint, TAddress>> {
  138. const maybeAccount = await fetchMaybeMint(rpc, address, config);
  139. assertAccountExists(maybeAccount);
  140. return maybeAccount;
  141. }
  142. export async function fetchMaybeMint<TAddress extends string = string>(
  143. rpc: Parameters<typeof fetchEncodedAccount>[0],
  144. address: Address<TAddress>,
  145. config?: FetchAccountConfig
  146. ): Promise<MaybeAccount<Mint, TAddress>> {
  147. const maybeAccount = await fetchEncodedAccount(rpc, address, config);
  148. return decodeMint(maybeAccount);
  149. }
  150. export async function fetchAllMint(
  151. rpc: Parameters<typeof fetchEncodedAccounts>[0],
  152. addresses: Array<Address>,
  153. config?: FetchAccountsConfig
  154. ): Promise<Account<Mint>[]> {
  155. const maybeAccounts = await fetchAllMaybeMint(rpc, addresses, config);
  156. assertAccountsExist(maybeAccounts);
  157. return maybeAccounts;
  158. }
  159. export async function fetchAllMaybeMint(
  160. rpc: Parameters<typeof fetchEncodedAccounts>[0],
  161. addresses: Array<Address>,
  162. config?: FetchAccountsConfig
  163. ): Promise<MaybeAccount<Mint>[]> {
  164. const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
  165. return maybeAccounts.map((maybeAccount) => decodeMint(maybeAccount));
  166. }
  167. export function getMintSize(): number {
  168. return 82;
  169. }