@1upmonster/duel 0.1.8 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +110 -59
  2. package/dist/admin.d.ts +25 -40
  3. package/dist/admin.js +93 -114
  4. package/dist/encryption.js +1 -2
  5. package/dist/generated/duel/accounts/index.d.ts +10 -0
  6. package/dist/generated/duel/accounts/index.js +11 -0
  7. package/dist/generated/duel/accounts/matchTicket.d.ts +38 -0
  8. package/dist/generated/duel/accounts/matchTicket.js +45 -0
  9. package/dist/generated/duel/accounts/queue.d.ts +42 -0
  10. package/dist/generated/duel/accounts/queue.js +45 -0
  11. package/dist/generated/duel/accounts/tenant.d.ts +41 -0
  12. package/dist/generated/duel/accounts/tenant.js +44 -0
  13. package/dist/generated/duel/errors/duel.d.ts +31 -0
  14. package/dist/generated/duel/errors/duel.js +35 -0
  15. package/dist/generated/duel/errors/index.d.ts +8 -0
  16. package/dist/generated/duel/errors/index.js +9 -0
  17. package/dist/generated/duel/index.d.ts +12 -0
  18. package/dist/generated/duel/index.js +13 -0
  19. package/dist/generated/duel/instructions/cancelTicket.d.ts +45 -0
  20. package/dist/generated/duel/instructions/cancelTicket.js +56 -0
  21. package/dist/generated/duel/instructions/closeTicket.d.ts +45 -0
  22. package/dist/generated/duel/instructions/closeTicket.js +56 -0
  23. package/dist/generated/duel/instructions/commitTickets.d.ts +39 -0
  24. package/dist/generated/duel/instructions/commitTickets.js +50 -0
  25. package/dist/generated/duel/instructions/createTicket.d.ts +48 -0
  26. package/dist/generated/duel/instructions/createTicket.js +63 -0
  27. package/dist/generated/duel/instructions/delegateQueue.d.ts +69 -0
  28. package/dist/generated/duel/instructions/delegateQueue.js +90 -0
  29. package/dist/generated/duel/instructions/delegateTicket.d.ts +69 -0
  30. package/dist/generated/duel/instructions/delegateTicket.js +90 -0
  31. package/dist/generated/duel/instructions/flushMatches.d.ts +37 -0
  32. package/dist/generated/duel/instructions/flushMatches.js +43 -0
  33. package/dist/generated/duel/instructions/index.d.ts +19 -0
  34. package/dist/generated/duel/instructions/index.js +20 -0
  35. package/dist/generated/duel/instructions/initializeQueue.d.ts +48 -0
  36. package/dist/generated/duel/instructions/initializeQueue.js +63 -0
  37. package/dist/generated/duel/instructions/initializeTenant.d.ts +70 -0
  38. package/dist/generated/duel/instructions/initializeTenant.js +67 -0
  39. package/dist/generated/duel/instructions/joinQueue.d.ts +51 -0
  40. package/dist/generated/duel/instructions/joinQueue.js +56 -0
  41. package/dist/generated/duel/instructions/processUndelegation.d.ts +43 -0
  42. package/dist/generated/duel/instructions/processUndelegation.js +49 -0
  43. package/dist/generated/duel/instructions/setupTicketPermission.d.ts +54 -0
  44. package/dist/generated/duel/instructions/setupTicketPermission.js +63 -0
  45. package/dist/generated/duel/programs/duel.d.ts +92 -0
  46. package/dist/generated/duel/programs/duel.js +146 -0
  47. package/dist/generated/duel/programs/index.d.ts +8 -0
  48. package/dist/generated/duel/programs/index.js +9 -0
  49. package/dist/generated/duel/types/accountType.d.ts +25 -0
  50. package/dist/generated/duel/types/accountType.js +25 -0
  51. package/dist/generated/duel/types/index.d.ts +13 -0
  52. package/dist/generated/duel/types/index.js +14 -0
  53. package/dist/generated/duel/types/matchEntry.d.ts +23 -0
  54. package/dist/generated/duel/types/matchEntry.js +18 -0
  55. package/dist/generated/duel/types/matchFound.d.ts +23 -0
  56. package/dist/generated/duel/types/matchFound.js +18 -0
  57. package/dist/generated/duel/types/pendingMatch.d.ts +21 -0
  58. package/dist/generated/duel/types/pendingMatch.js +18 -0
  59. package/dist/generated/duel/types/queueEntry.d.ts +19 -0
  60. package/dist/generated/duel/types/queueEntry.js +18 -0
  61. package/dist/generated/duel/types/ticketStatus.d.ts +40 -0
  62. package/dist/generated/duel/types/ticketStatus.js +25 -0
  63. package/dist/generated/rps-game/accounts/gameSession.d.ts +40 -0
  64. package/dist/generated/rps-game/accounts/gameSession.js +45 -0
  65. package/dist/generated/rps-game/accounts/index.d.ts +9 -0
  66. package/dist/generated/rps-game/accounts/index.js +10 -0
  67. package/dist/generated/rps-game/accounts/playerProfile.d.ts +36 -0
  68. package/dist/generated/rps-game/accounts/playerProfile.js +47 -0
  69. package/dist/generated/rps-game/errors/index.d.ts +8 -0
  70. package/dist/generated/rps-game/errors/index.js +9 -0
  71. package/dist/generated/rps-game/errors/rpsGame.d.ts +25 -0
  72. package/dist/generated/rps-game/errors/rpsGame.js +29 -0
  73. package/dist/generated/rps-game/index.d.ts +12 -0
  74. package/dist/generated/rps-game/index.js +13 -0
  75. package/dist/generated/rps-game/instructions/closePlayer.d.ts +45 -0
  76. package/dist/generated/rps-game/instructions/closePlayer.js +56 -0
  77. package/dist/generated/rps-game/instructions/delegatePda.d.ts +69 -0
  78. package/dist/generated/rps-game/instructions/delegatePda.js +90 -0
  79. package/dist/generated/rps-game/instructions/index.d.ts +16 -0
  80. package/dist/generated/rps-game/instructions/index.js +17 -0
  81. package/dist/generated/rps-game/instructions/initializePlayer.d.ts +48 -0
  82. package/dist/generated/rps-game/instructions/initializePlayer.js +63 -0
  83. package/dist/generated/rps-game/instructions/makeChoice.d.ts +44 -0
  84. package/dist/generated/rps-game/instructions/makeChoice.js +46 -0
  85. package/dist/generated/rps-game/instructions/onMatchFound.d.ts +43 -0
  86. package/dist/generated/rps-game/instructions/onMatchFound.js +45 -0
  87. package/dist/generated/rps-game/instructions/persistResults.d.ts +43 -0
  88. package/dist/generated/rps-game/instructions/persistResults.js +50 -0
  89. package/dist/generated/rps-game/instructions/processUndelegation.d.ts +43 -0
  90. package/dist/generated/rps-game/instructions/processUndelegation.js +49 -0
  91. package/dist/generated/rps-game/instructions/startGame.d.ts +54 -0
  92. package/dist/generated/rps-game/instructions/startGame.js +67 -0
  93. package/dist/generated/rps-game/instructions/startGameWithTicket.d.ts +57 -0
  94. package/dist/generated/rps-game/instructions/startGameWithTicket.js +67 -0
  95. package/dist/generated/rps-game/programs/index.d.ts +8 -0
  96. package/dist/generated/rps-game/programs/index.js +9 -0
  97. package/dist/generated/rps-game/programs/rpsGame.d.ts +78 -0
  98. package/dist/generated/rps-game/programs/rpsGame.js +118 -0
  99. package/dist/generated/rps-game/types/accountType.d.ts +34 -0
  100. package/dist/generated/rps-game/types/accountType.js +25 -0
  101. package/dist/generated/rps-game/types/choice.d.ts +17 -0
  102. package/dist/generated/rps-game/types/choice.js +25 -0
  103. package/dist/generated/rps-game/types/gameResult.d.ts +26 -0
  104. package/dist/generated/rps-game/types/gameResult.js +25 -0
  105. package/dist/generated/rps-game/types/index.d.ts +10 -0
  106. package/dist/generated/rps-game/types/index.js +11 -0
  107. package/dist/index.d.ts +2 -1
  108. package/dist/index.js +3 -2
  109. package/dist/player.d.ts +25 -46
  110. package/dist/player.js +81 -140
  111. package/dist/tee.d.ts +14 -0
  112. package/dist/tee.js +62 -0
  113. package/dist/transaction.d.ts +11 -0
  114. package/dist/transaction.js +50 -0
  115. package/dist/utils.d.ts +4 -4
  116. package/dist/utils.js +23 -8
  117. package/package.json +3 -6
  118. package/src/admin.ts +151 -161
  119. package/src/duel.json +66 -7
  120. package/src/encryption.ts +0 -3
  121. package/src/generated/duel/accounts/index.ts +11 -0
  122. package/src/generated/duel/accounts/matchTicket.ts +77 -0
  123. package/src/generated/duel/accounts/queue.ts +77 -0
  124. package/src/generated/duel/accounts/tenant.ts +76 -0
  125. package/src/generated/duel/errors/duel.ts +46 -0
  126. package/src/generated/duel/errors/index.ts +9 -0
  127. package/src/generated/duel/index.ts +13 -0
  128. package/src/generated/duel/instructions/cancelTicket.ts +100 -0
  129. package/src/generated/duel/instructions/closeTicket.ts +100 -0
  130. package/src/generated/duel/instructions/commitTickets.ts +84 -0
  131. package/src/generated/duel/instructions/createTicket.ts +109 -0
  132. package/src/generated/duel/instructions/delegateQueue.ts +157 -0
  133. package/src/generated/duel/instructions/delegateTicket.ts +157 -0
  134. package/src/generated/duel/instructions/flushMatches.ts +76 -0
  135. package/src/generated/duel/instructions/index.ts +20 -0
  136. package/src/generated/duel/instructions/initializeQueue.ts +109 -0
  137. package/src/generated/duel/instructions/initializeTenant.ts +126 -0
  138. package/src/generated/duel/instructions/joinQueue.ts +106 -0
  139. package/src/generated/duel/instructions/processUndelegation.ts +86 -0
  140. package/src/generated/duel/instructions/setupTicketPermission.ts +115 -0
  141. package/src/generated/duel/programs/duel.ts +108 -0
  142. package/src/generated/duel/programs/index.ts +9 -0
  143. package/src/generated/duel/types/accountType.ts +36 -0
  144. package/src/generated/duel/types/index.ts +14 -0
  145. package/src/generated/duel/types/matchEntry.ts +25 -0
  146. package/src/generated/duel/types/matchFound.ts +25 -0
  147. package/src/generated/duel/types/pendingMatch.ts +25 -0
  148. package/src/generated/duel/types/queueEntry.ts +25 -0
  149. package/src/generated/duel/types/ticketStatus.ts +38 -0
  150. package/src/generated/rps-game/accounts/gameSession.ts +77 -0
  151. package/src/generated/rps-game/accounts/index.ts +10 -0
  152. package/src/generated/rps-game/accounts/playerProfile.ts +80 -0
  153. package/src/generated/rps-game/errors/index.ts +9 -0
  154. package/src/generated/rps-game/errors/rpsGame.ts +40 -0
  155. package/src/generated/rps-game/index.ts +13 -0
  156. package/src/generated/rps-game/instructions/closePlayer.ts +100 -0
  157. package/src/generated/rps-game/instructions/delegatePda.ts +157 -0
  158. package/src/generated/rps-game/instructions/index.ts +17 -0
  159. package/src/generated/rps-game/instructions/initializePlayer.ts +109 -0
  160. package/src/generated/rps-game/instructions/makeChoice.ts +84 -0
  161. package/src/generated/rps-game/instructions/onMatchFound.ts +79 -0
  162. package/src/generated/rps-game/instructions/persistResults.ts +88 -0
  163. package/src/generated/rps-game/instructions/processUndelegation.ts +86 -0
  164. package/src/generated/rps-game/instructions/startGame.ts +118 -0
  165. package/src/generated/rps-game/instructions/startGameWithTicket.ts +121 -0
  166. package/src/generated/rps-game/programs/index.ts +9 -0
  167. package/src/generated/rps-game/programs/rpsGame.ts +95 -0
  168. package/src/generated/rps-game/types/accountType.ts +36 -0
  169. package/src/generated/rps-game/types/choice.ts +25 -0
  170. package/src/generated/rps-game/types/gameResult.ts +37 -0
  171. package/src/generated/rps-game/types/index.ts +11 -0
  172. package/src/index.ts +2 -1
  173. package/src/player.ts +129 -192
  174. package/src/{idl/private_matchmaking.json → rps_game.json} +547 -583
  175. package/src/tee.ts +79 -0
  176. package/src/transaction.ts +90 -0
  177. package/src/utils.ts +35 -20
  178. package/tsconfig.json +2 -2
  179. package/dist/client.d.ts +0 -54
  180. package/dist/client.js +0 -265
  181. package/dist/duel.json +0 -1207
  182. package/dist/private_matchmaking.json +0 -534
  183. package/dist/types.d.ts +0 -635
  184. package/dist/types.js +0 -2
  185. package/src/idl/private_matchmaking.ts +0 -1033
  186. package/src/types.ts +0 -300
package/src/duel.json CHANGED
@@ -759,8 +759,7 @@
759
759
  "name": "tenant"
760
760
  },
761
761
  {
762
- "name": "player_data",
763
- "writable": true
762
+ "name": "player_data"
764
763
  },
765
764
  {
766
765
  "name": "player_ticket",
@@ -832,6 +831,71 @@
832
831
  }
833
832
  }
834
833
  ]
834
+ },
835
+ {
836
+ "name": "setup_ticket_permission",
837
+ "docs": [
838
+ "Set up permission for ticket PDA so queueAuthority can write it on TEE.",
839
+ "Must be called BEFORE delegate_ticket while the program still owns the PDA."
840
+ ],
841
+ "discriminator": [
842
+ 164,
843
+ 29,
844
+ 7,
845
+ 235,
846
+ 183,
847
+ 223,
848
+ 11,
849
+ 85
850
+ ],
851
+ "accounts": [
852
+ {
853
+ "name": "ticket",
854
+ "pda": {
855
+ "seeds": [
856
+ {
857
+ "kind": "const",
858
+ "value": [
859
+ 116,
860
+ 105,
861
+ 99,
862
+ 107,
863
+ 101,
864
+ 116
865
+ ]
866
+ },
867
+ {
868
+ "kind": "account",
869
+ "path": "player"
870
+ },
871
+ {
872
+ "kind": "account",
873
+ "path": "tenant"
874
+ }
875
+ ]
876
+ }
877
+ },
878
+ {
879
+ "name": "tenant"
880
+ },
881
+ {
882
+ "name": "player",
883
+ "writable": true,
884
+ "signer": true
885
+ },
886
+ {
887
+ "name": "permission",
888
+ "writable": true
889
+ },
890
+ {
891
+ "name": "permission_program"
892
+ },
893
+ {
894
+ "name": "system_program",
895
+ "address": "11111111111111111111111111111111"
896
+ }
897
+ ],
898
+ "args": []
835
899
  }
836
900
  ],
837
901
  "accounts": [
@@ -920,11 +984,6 @@
920
984
  "code": 6005,
921
985
  "name": "InvalidTicketAccount",
922
986
  "msg": "Invalid ticket account"
923
- },
924
- {
925
- "code": 6006,
926
- "name": "MissingCallbackProgram",
927
- "msg": "Missing or invalid callback program in remaining accounts"
928
987
  }
929
988
  ],
930
989
  "types": [
package/src/encryption.ts CHANGED
@@ -1,6 +1,3 @@
1
- import { PublicKey } from "@solana/web3.js";
2
- // import { x25519 } from "@noble/curves/ed25519";
3
-
4
1
  export class EncryptionProvider {
5
2
  private keyPair: CryptoKeyPair | null = null;
6
3
 
@@ -0,0 +1,11 @@
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
+
9
+ export * from './matchTicket';
10
+ export * from './queue';
11
+ export * from './tenant';
@@ -0,0 +1,77 @@
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
+
9
+ import { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type Codec, type Decoder, type EncodedAccount, type Encoder, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array } from '@solana/kit';
10
+ import { getTicketStatusDecoder, getTicketStatusEncoder, type TicketStatus, type TicketStatusArgs } from '../types';
11
+
12
+ export const MATCH_TICKET_DISCRIMINATOR = new Uint8Array([11, 131, 4, 157, 207, 79, 126, 5]);
13
+
14
+ export function getMatchTicketDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(MATCH_TICKET_DISCRIMINATOR); }
15
+
16
+ export type MatchTicket = { discriminator: ReadonlyUint8Array; player: Address; tenant: Address; status: TicketStatus; createdAt: bigint; bump: number; };
17
+
18
+ export type MatchTicketArgs = { player: Address; tenant: Address; status: TicketStatusArgs; createdAt: number | bigint; bump: number; };
19
+
20
+ /** Gets the encoder for {@link MatchTicketArgs} account data. */
21
+ export function getMatchTicketEncoder(): Encoder<MatchTicketArgs> {
22
+ return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['player', getAddressEncoder()], ['tenant', getAddressEncoder()], ['status', getTicketStatusEncoder()], ['createdAt', getI64Encoder()], ['bump', getU8Encoder()]]), (value) => ({ ...value, discriminator: MATCH_TICKET_DISCRIMINATOR }));
23
+ }
24
+
25
+ /** Gets the decoder for {@link MatchTicket} account data. */
26
+ export function getMatchTicketDecoder(): Decoder<MatchTicket> {
27
+ return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['player', getAddressDecoder()], ['tenant', getAddressDecoder()], ['status', getTicketStatusDecoder()], ['createdAt', getI64Decoder()], ['bump', getU8Decoder()]]);
28
+ }
29
+
30
+ /** Gets the codec for {@link MatchTicket} account data. */
31
+ export function getMatchTicketCodec(): Codec<MatchTicketArgs, MatchTicket> {
32
+ return combineCodec(getMatchTicketEncoder(), getMatchTicketDecoder());
33
+ }
34
+
35
+ export function decodeMatchTicket<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<MatchTicket, TAddress>;
36
+ export function decodeMatchTicket<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<MatchTicket, TAddress>;
37
+ export function decodeMatchTicket<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<MatchTicket, TAddress> | MaybeAccount<MatchTicket, TAddress> {
38
+ return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getMatchTicketDecoder());
39
+ }
40
+
41
+ export async function fetchMatchTicket<TAddress extends string = string>(
42
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
43
+ address: Address<TAddress>,
44
+ config?: FetchAccountConfig,
45
+ ): Promise<Account<MatchTicket, TAddress>> {
46
+ const maybeAccount = await fetchMaybeMatchTicket(rpc, address, config);
47
+ assertAccountExists(maybeAccount);
48
+ return maybeAccount;
49
+ }
50
+
51
+ export async function fetchMaybeMatchTicket<TAddress extends string = string>(
52
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
53
+ address: Address<TAddress>,
54
+ config?: FetchAccountConfig,
55
+ ): Promise<MaybeAccount<MatchTicket, TAddress>> {
56
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
57
+ return decodeMatchTicket(maybeAccount);
58
+ }
59
+
60
+ export async function fetchAllMatchTicket(
61
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
62
+ addresses: Array<Address>,
63
+ config?: FetchAccountsConfig,
64
+ ): Promise<Account<MatchTicket>[]> {
65
+ const maybeAccounts = await fetchAllMaybeMatchTicket(rpc, addresses, config);
66
+ assertAccountsExist(maybeAccounts);
67
+ return maybeAccounts;
68
+ }
69
+
70
+ export async function fetchAllMaybeMatchTicket(
71
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
72
+ addresses: Array<Address>,
73
+ config?: FetchAccountsConfig,
74
+ ): Promise<MaybeAccount<MatchTicket>[]> {
75
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
76
+ return maybeAccounts.map((maybeAccount) => decodeMatchTicket(maybeAccount));
77
+ }
@@ -0,0 +1,77 @@
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
+
9
+ import { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type Codec, type Decoder, type EncodedAccount, type Encoder, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array } from '@solana/kit';
10
+ import { getMatchEntryDecoder, getMatchEntryEncoder, getPendingMatchDecoder, getPendingMatchEncoder, getQueueEntryDecoder, getQueueEntryEncoder, type MatchEntry, type MatchEntryArgs, type PendingMatch, type PendingMatchArgs, type QueueEntry, type QueueEntryArgs } from '../types';
11
+
12
+ export const QUEUE_DISCRIMINATOR = new Uint8Array([204, 167, 6, 247, 20, 33, 2, 188]);
13
+
14
+ export function getQueueDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(QUEUE_DISCRIMINATOR); }
15
+
16
+ export type Queue = { discriminator: ReadonlyUint8Array; authority: Address; tenant: Address; bump: number; matchCounter: bigint; entries: Array<QueueEntry>; matches: Array<MatchEntry>; pendingMatches: Array<PendingMatch>; };
17
+
18
+ export type QueueArgs = { authority: Address; tenant: Address; bump: number; matchCounter: number | bigint; entries: Array<QueueEntryArgs>; matches: Array<MatchEntryArgs>; pendingMatches: Array<PendingMatchArgs>; };
19
+
20
+ /** Gets the encoder for {@link QueueArgs} account data. */
21
+ export function getQueueEncoder(): Encoder<QueueArgs> {
22
+ return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['authority', getAddressEncoder()], ['tenant', getAddressEncoder()], ['bump', getU8Encoder()], ['matchCounter', getU64Encoder()], ['entries', getArrayEncoder(getQueueEntryEncoder())], ['matches', getArrayEncoder(getMatchEntryEncoder())], ['pendingMatches', getArrayEncoder(getPendingMatchEncoder())]]), (value) => ({ ...value, discriminator: QUEUE_DISCRIMINATOR }));
23
+ }
24
+
25
+ /** Gets the decoder for {@link Queue} account data. */
26
+ export function getQueueDecoder(): Decoder<Queue> {
27
+ return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['authority', getAddressDecoder()], ['tenant', getAddressDecoder()], ['bump', getU8Decoder()], ['matchCounter', getU64Decoder()], ['entries', getArrayDecoder(getQueueEntryDecoder())], ['matches', getArrayDecoder(getMatchEntryDecoder())], ['pendingMatches', getArrayDecoder(getPendingMatchDecoder())]]);
28
+ }
29
+
30
+ /** Gets the codec for {@link Queue} account data. */
31
+ export function getQueueCodec(): Codec<QueueArgs, Queue> {
32
+ return combineCodec(getQueueEncoder(), getQueueDecoder());
33
+ }
34
+
35
+ export function decodeQueue<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<Queue, TAddress>;
36
+ export function decodeQueue<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<Queue, TAddress>;
37
+ export function decodeQueue<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<Queue, TAddress> | MaybeAccount<Queue, TAddress> {
38
+ return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getQueueDecoder());
39
+ }
40
+
41
+ export async function fetchQueue<TAddress extends string = string>(
42
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
43
+ address: Address<TAddress>,
44
+ config?: FetchAccountConfig,
45
+ ): Promise<Account<Queue, TAddress>> {
46
+ const maybeAccount = await fetchMaybeQueue(rpc, address, config);
47
+ assertAccountExists(maybeAccount);
48
+ return maybeAccount;
49
+ }
50
+
51
+ export async function fetchMaybeQueue<TAddress extends string = string>(
52
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
53
+ address: Address<TAddress>,
54
+ config?: FetchAccountConfig,
55
+ ): Promise<MaybeAccount<Queue, TAddress>> {
56
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
57
+ return decodeQueue(maybeAccount);
58
+ }
59
+
60
+ export async function fetchAllQueue(
61
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
62
+ addresses: Array<Address>,
63
+ config?: FetchAccountsConfig,
64
+ ): Promise<Account<Queue>[]> {
65
+ const maybeAccounts = await fetchAllMaybeQueue(rpc, addresses, config);
66
+ assertAccountsExist(maybeAccounts);
67
+ return maybeAccounts;
68
+ }
69
+
70
+ export async function fetchAllMaybeQueue(
71
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
72
+ addresses: Array<Address>,
73
+ config?: FetchAccountsConfig,
74
+ ): Promise<MaybeAccount<Queue>[]> {
75
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
76
+ return maybeAccounts.map((maybeAccount) => decodeQueue(maybeAccount));
77
+ }
@@ -0,0 +1,76 @@
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
+
9
+ import { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getOptionDecoder, getOptionEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type Codec, type Decoder, type EncodedAccount, type Encoder, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, type Option, type OptionOrNullable, type ReadonlyUint8Array } from '@solana/kit';
10
+
11
+ export const TENANT_DISCRIMINATOR = new Uint8Array([61, 43, 215, 51, 232, 242, 209, 170]);
12
+
13
+ export function getTenantDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(TENANT_DISCRIMINATOR); }
14
+
15
+ export type Tenant = { discriminator: ReadonlyUint8Array; authority: Address; tenantProgramId: Address; eloOffset: number; eloSize: number; eloWindow: bigint; callbackProgramId: Option<Address>; callbackDiscriminator: Option<ReadonlyUint8Array>; };
16
+
17
+ export type TenantArgs = { authority: Address; tenantProgramId: Address; eloOffset: number; eloSize: number; eloWindow: number | bigint; callbackProgramId: OptionOrNullable<Address>; callbackDiscriminator: OptionOrNullable<ReadonlyUint8Array>; };
18
+
19
+ /** Gets the encoder for {@link TenantArgs} account data. */
20
+ export function getTenantEncoder(): Encoder<TenantArgs> {
21
+ return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['authority', getAddressEncoder()], ['tenantProgramId', getAddressEncoder()], ['eloOffset', getU32Encoder()], ['eloSize', getU8Encoder()], ['eloWindow', getU64Encoder()], ['callbackProgramId', getOptionEncoder(getAddressEncoder())], ['callbackDiscriminator', getOptionEncoder(fixEncoderSize(getBytesEncoder(), 8))]]), (value) => ({ ...value, discriminator: TENANT_DISCRIMINATOR }));
22
+ }
23
+
24
+ /** Gets the decoder for {@link Tenant} account data. */
25
+ export function getTenantDecoder(): Decoder<Tenant> {
26
+ return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['authority', getAddressDecoder()], ['tenantProgramId', getAddressDecoder()], ['eloOffset', getU32Decoder()], ['eloSize', getU8Decoder()], ['eloWindow', getU64Decoder()], ['callbackProgramId', getOptionDecoder(getAddressDecoder())], ['callbackDiscriminator', getOptionDecoder(fixDecoderSize(getBytesDecoder(), 8))]]);
27
+ }
28
+
29
+ /** Gets the codec for {@link Tenant} account data. */
30
+ export function getTenantCodec(): Codec<TenantArgs, Tenant> {
31
+ return combineCodec(getTenantEncoder(), getTenantDecoder());
32
+ }
33
+
34
+ export function decodeTenant<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<Tenant, TAddress>;
35
+ export function decodeTenant<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<Tenant, TAddress>;
36
+ export function decodeTenant<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<Tenant, TAddress> | MaybeAccount<Tenant, TAddress> {
37
+ return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getTenantDecoder());
38
+ }
39
+
40
+ export async function fetchTenant<TAddress extends string = string>(
41
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
42
+ address: Address<TAddress>,
43
+ config?: FetchAccountConfig,
44
+ ): Promise<Account<Tenant, TAddress>> {
45
+ const maybeAccount = await fetchMaybeTenant(rpc, address, config);
46
+ assertAccountExists(maybeAccount);
47
+ return maybeAccount;
48
+ }
49
+
50
+ export async function fetchMaybeTenant<TAddress extends string = string>(
51
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
52
+ address: Address<TAddress>,
53
+ config?: FetchAccountConfig,
54
+ ): Promise<MaybeAccount<Tenant, TAddress>> {
55
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
56
+ return decodeTenant(maybeAccount);
57
+ }
58
+
59
+ export async function fetchAllTenant(
60
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
61
+ addresses: Array<Address>,
62
+ config?: FetchAccountsConfig,
63
+ ): Promise<Account<Tenant>[]> {
64
+ const maybeAccounts = await fetchAllMaybeTenant(rpc, addresses, config);
65
+ assertAccountsExist(maybeAccounts);
66
+ return maybeAccounts;
67
+ }
68
+
69
+ export async function fetchAllMaybeTenant(
70
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
71
+ addresses: Array<Address>,
72
+ config?: FetchAccountsConfig,
73
+ ): Promise<MaybeAccount<Tenant>[]> {
74
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
75
+ return maybeAccounts.map((maybeAccount) => decodeTenant(maybeAccount));
76
+ }
@@ -0,0 +1,46 @@
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
+
9
+ import { isProgramError, type Address, type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, type SolanaError } from '@solana/kit';
10
+ import { DUEL_PROGRAM_ADDRESS } from '../programs';
11
+
12
+ /** InvalidTenant: Account does not belong to the specified Tenant Program */
13
+ export const DUEL_ERROR__INVALID_TENANT = 0x1770; // 6000
14
+ /** DataTooSmall: Account data too small for ELO read */
15
+ export const DUEL_ERROR__DATA_TOO_SMALL = 0x1771; // 6001
16
+ /** Unauthorized: Unauthorized access */
17
+ export const DUEL_ERROR__UNAUTHORIZED = 0x1772; // 6002
18
+ /** InvalidEloSize: Invalid ELO size (must be 1, 2, 4, or 8 bytes) */
19
+ export const DUEL_ERROR__INVALID_ELO_SIZE = 0x1773; // 6003
20
+ /** InvalidTicketStatus: Invalid ticket status for this operation */
21
+ export const DUEL_ERROR__INVALID_TICKET_STATUS = 0x1774; // 6004
22
+ /** InvalidTicketAccount: Invalid ticket account */
23
+ export const DUEL_ERROR__INVALID_TICKET_ACCOUNT = 0x1775; // 6005
24
+
25
+ export type DuelError = typeof DUEL_ERROR__DATA_TOO_SMALL | typeof DUEL_ERROR__INVALID_ELO_SIZE | typeof DUEL_ERROR__INVALID_TENANT | typeof DUEL_ERROR__INVALID_TICKET_ACCOUNT | typeof DUEL_ERROR__INVALID_TICKET_STATUS | typeof DUEL_ERROR__UNAUTHORIZED;
26
+
27
+ let duelErrorMessages: Record<DuelError, string> | undefined;
28
+ if (process.env.NODE_ENV !== 'production') {
29
+ duelErrorMessages = { [DUEL_ERROR__DATA_TOO_SMALL]: `Account data too small for ELO read`, [DUEL_ERROR__INVALID_ELO_SIZE]: `Invalid ELO size (must be 1, 2, 4, or 8 bytes)`, [DUEL_ERROR__INVALID_TENANT]: `Account does not belong to the specified Tenant Program`, [DUEL_ERROR__INVALID_TICKET_ACCOUNT]: `Invalid ticket account`, [DUEL_ERROR__INVALID_TICKET_STATUS]: `Invalid ticket status for this operation`, [DUEL_ERROR__UNAUTHORIZED]: `Unauthorized access` };
30
+ }
31
+
32
+ export function getDuelErrorMessage(code: DuelError): string {
33
+ if (process.env.NODE_ENV !== 'production') {
34
+ return (duelErrorMessages as Record<DuelError, string>)[code];
35
+ }
36
+
37
+ return 'Error message not available in production bundles.';
38
+ }
39
+
40
+ export function isDuelError<TProgramErrorCode extends DuelError>(
41
+ error: unknown,
42
+ transactionMessage: { instructions: Record<number, { programAddress: Address }> },
43
+ code?: TProgramErrorCode,
44
+ ): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> & Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> {
45
+ return isProgramError<TProgramErrorCode>(error, transactionMessage, DUEL_PROGRAM_ADDRESS, code);
46
+ }
@@ -0,0 +1,9 @@
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
+
9
+ export * from './duel';
@@ -0,0 +1,13 @@
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
+
9
+ export * from './accounts';
10
+ export * from './errors';
11
+ export * from './instructions';
12
+ export * from './programs';
13
+ export * from './types';
@@ -0,0 +1,100 @@
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
+
9
+ import { combineCodec, fixDecoderSize, fixEncoderSize, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit';
10
+ import { getAccountMetaFactory, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount } from '@solana/program-client-core';
11
+ import { DUEL_PROGRAM_ADDRESS } from '../programs';
12
+
13
+ export const CANCEL_TICKET_DISCRIMINATOR = new Uint8Array([216, 28, 247, 206, 195, 171, 100, 143]);
14
+
15
+ export function getCancelTicketDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CANCEL_TICKET_DISCRIMINATOR); }
16
+
17
+ export type CancelTicketInstruction<TProgram extends string = typeof DUEL_PROGRAM_ADDRESS, TAccountTicket extends string | AccountMeta<string> = string, TAccountTenant extends string | AccountMeta<string> = string, TAccountPlayer extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
18
+ Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountTicket extends string ? WritableAccount<TAccountTicket> : TAccountTicket, TAccountTenant extends string ? ReadonlyAccount<TAccountTenant> : TAccountTenant, TAccountPlayer extends string ? ReadonlySignerAccount<TAccountPlayer> & AccountSignerMeta<TAccountPlayer> : TAccountPlayer, ...TRemainingAccounts]>;
19
+
20
+ export type CancelTicketInstructionData = { discriminator: ReadonlyUint8Array; };
21
+
22
+ export type CancelTicketInstructionDataArgs = { };
23
+
24
+ export function getCancelTicketInstructionDataEncoder(): FixedSizeEncoder<CancelTicketInstructionDataArgs> {
25
+ return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CANCEL_TICKET_DISCRIMINATOR }));
26
+ }
27
+
28
+ export function getCancelTicketInstructionDataDecoder(): FixedSizeDecoder<CancelTicketInstructionData> {
29
+ return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
30
+ }
31
+
32
+ export function getCancelTicketInstructionDataCodec(): FixedSizeCodec<CancelTicketInstructionDataArgs, CancelTicketInstructionData> {
33
+ return combineCodec(getCancelTicketInstructionDataEncoder(), getCancelTicketInstructionDataDecoder());
34
+ }
35
+
36
+ export type CancelTicketAsyncInput<TAccountTicket extends string = string, TAccountTenant extends string = string, TAccountPlayer extends string = string> = {
37
+ ticket?: Address<TAccountTicket>;
38
+ tenant: Address<TAccountTenant>;
39
+ player: TransactionSigner<TAccountPlayer>;
40
+ }
41
+
42
+ export async function getCancelTicketInstructionAsync<TAccountTicket extends string, TAccountTenant extends string, TAccountPlayer extends string, TProgramAddress extends Address = typeof DUEL_PROGRAM_ADDRESS>(input: CancelTicketAsyncInput<TAccountTicket, TAccountTenant, TAccountPlayer>, config?: { programAddress?: TProgramAddress } ): Promise<CancelTicketInstruction<TProgramAddress, TAccountTicket, TAccountTenant, TAccountPlayer>> {
43
+ // Program address.
44
+ const programAddress = config?.programAddress ?? DUEL_PROGRAM_ADDRESS;
45
+
46
+ // Original accounts.
47
+ const originalAccounts = { ticket: { value: input.ticket ?? null, isWritable: true }, tenant: { value: input.tenant ?? null, isWritable: false }, player: { value: input.player ?? null, isWritable: false } }
48
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
49
+
50
+
51
+ // Resolve default values.
52
+ if (!accounts.ticket.value) {
53
+ accounts.ticket.value = await getProgramDerivedAddress({ programAddress, seeds: [getBytesEncoder().encode(new Uint8Array([116, 105, 99, 107, 101, 116])), getAddressEncoder().encode(getAddressFromResolvedInstructionAccount("player", accounts.player.value)), getAddressEncoder().encode(getAddressFromResolvedInstructionAccount("tenant", accounts.tenant.value))] });
54
+ }
55
+
56
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
57
+ return Object.freeze({ accounts: [getAccountMeta("ticket", accounts.ticket), getAccountMeta("tenant", accounts.tenant), getAccountMeta("player", accounts.player)], data: getCancelTicketInstructionDataEncoder().encode({}), programAddress } as CancelTicketInstruction<TProgramAddress, TAccountTicket, TAccountTenant, TAccountPlayer>);
58
+ }
59
+
60
+ export type CancelTicketInput<TAccountTicket extends string = string, TAccountTenant extends string = string, TAccountPlayer extends string = string> = {
61
+ ticket: Address<TAccountTicket>;
62
+ tenant: Address<TAccountTenant>;
63
+ player: TransactionSigner<TAccountPlayer>;
64
+ }
65
+
66
+ export function getCancelTicketInstruction<TAccountTicket extends string, TAccountTenant extends string, TAccountPlayer extends string, TProgramAddress extends Address = typeof DUEL_PROGRAM_ADDRESS>(input: CancelTicketInput<TAccountTicket, TAccountTenant, TAccountPlayer>, config?: { programAddress?: TProgramAddress } ): CancelTicketInstruction<TProgramAddress, TAccountTicket, TAccountTenant, TAccountPlayer> {
67
+ // Program address.
68
+ const programAddress = config?.programAddress ?? DUEL_PROGRAM_ADDRESS;
69
+
70
+ // Original accounts.
71
+ const originalAccounts = { ticket: { value: input.ticket ?? null, isWritable: true }, tenant: { value: input.tenant ?? null, isWritable: false }, player: { value: input.player ?? null, isWritable: false } }
72
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
73
+
74
+
75
+
76
+
77
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
78
+ return Object.freeze({ accounts: [getAccountMeta("ticket", accounts.ticket), getAccountMeta("tenant", accounts.tenant), getAccountMeta("player", accounts.player)], data: getCancelTicketInstructionDataEncoder().encode({}), programAddress } as CancelTicketInstruction<TProgramAddress, TAccountTicket, TAccountTenant, TAccountPlayer>);
79
+ }
80
+
81
+ export type ParsedCancelTicketInstruction<TProgram extends string = typeof DUEL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
82
+ accounts: {
83
+ ticket: TAccountMetas[0];
84
+ tenant: TAccountMetas[1];
85
+ player: TAccountMetas[2];
86
+ };
87
+ data: CancelTicketInstructionData; };
88
+
89
+ export function parseCancelTicketInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedCancelTicketInstruction<TProgram, TAccountMetas> {
90
+ if (instruction.accounts.length < 3) {
91
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 3 });
92
+ }
93
+ let accountIndex = 0;
94
+ const getNextAccount = () => {
95
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
96
+ accountIndex += 1;
97
+ return accountMeta;
98
+ }
99
+ return { programAddress: instruction.programAddress, accounts: { ticket: getNextAccount(), tenant: getNextAccount(), player: getNextAccount() }, data: getCancelTicketInstructionDataDecoder().decode(instruction.data) };
100
+ }
@@ -0,0 +1,100 @@
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
+
9
+ import { combineCodec, fixDecoderSize, fixEncoderSize, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount } from '@solana/kit';
10
+ import { getAccountMetaFactory, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount } from '@solana/program-client-core';
11
+ import { DUEL_PROGRAM_ADDRESS } from '../programs';
12
+
13
+ export const CLOSE_TICKET_DISCRIMINATOR = new Uint8Array([66, 209, 114, 197, 75, 27, 182, 117]);
14
+
15
+ export function getCloseTicketDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CLOSE_TICKET_DISCRIMINATOR); }
16
+
17
+ export type CloseTicketInstruction<TProgram extends string = typeof DUEL_PROGRAM_ADDRESS, TAccountTicket extends string | AccountMeta<string> = string, TAccountTenant extends string | AccountMeta<string> = string, TAccountPlayer extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
18
+ Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountTicket extends string ? WritableAccount<TAccountTicket> : TAccountTicket, TAccountTenant extends string ? ReadonlyAccount<TAccountTenant> : TAccountTenant, TAccountPlayer extends string ? WritableSignerAccount<TAccountPlayer> & AccountSignerMeta<TAccountPlayer> : TAccountPlayer, ...TRemainingAccounts]>;
19
+
20
+ export type CloseTicketInstructionData = { discriminator: ReadonlyUint8Array; };
21
+
22
+ export type CloseTicketInstructionDataArgs = { };
23
+
24
+ export function getCloseTicketInstructionDataEncoder(): FixedSizeEncoder<CloseTicketInstructionDataArgs> {
25
+ return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_TICKET_DISCRIMINATOR }));
26
+ }
27
+
28
+ export function getCloseTicketInstructionDataDecoder(): FixedSizeDecoder<CloseTicketInstructionData> {
29
+ return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
30
+ }
31
+
32
+ export function getCloseTicketInstructionDataCodec(): FixedSizeCodec<CloseTicketInstructionDataArgs, CloseTicketInstructionData> {
33
+ return combineCodec(getCloseTicketInstructionDataEncoder(), getCloseTicketInstructionDataDecoder());
34
+ }
35
+
36
+ export type CloseTicketAsyncInput<TAccountTicket extends string = string, TAccountTenant extends string = string, TAccountPlayer extends string = string> = {
37
+ ticket?: Address<TAccountTicket>;
38
+ tenant: Address<TAccountTenant>;
39
+ player: TransactionSigner<TAccountPlayer>;
40
+ }
41
+
42
+ export async function getCloseTicketInstructionAsync<TAccountTicket extends string, TAccountTenant extends string, TAccountPlayer extends string, TProgramAddress extends Address = typeof DUEL_PROGRAM_ADDRESS>(input: CloseTicketAsyncInput<TAccountTicket, TAccountTenant, TAccountPlayer>, config?: { programAddress?: TProgramAddress } ): Promise<CloseTicketInstruction<TProgramAddress, TAccountTicket, TAccountTenant, TAccountPlayer>> {
43
+ // Program address.
44
+ const programAddress = config?.programAddress ?? DUEL_PROGRAM_ADDRESS;
45
+
46
+ // Original accounts.
47
+ const originalAccounts = { ticket: { value: input.ticket ?? null, isWritable: true }, tenant: { value: input.tenant ?? null, isWritable: false }, player: { value: input.player ?? null, isWritable: true } }
48
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
49
+
50
+
51
+ // Resolve default values.
52
+ if (!accounts.ticket.value) {
53
+ accounts.ticket.value = await getProgramDerivedAddress({ programAddress, seeds: [getBytesEncoder().encode(new Uint8Array([116, 105, 99, 107, 101, 116])), getAddressEncoder().encode(getAddressFromResolvedInstructionAccount("player", accounts.player.value)), getAddressEncoder().encode(getAddressFromResolvedInstructionAccount("tenant", accounts.tenant.value))] });
54
+ }
55
+
56
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
57
+ return Object.freeze({ accounts: [getAccountMeta("ticket", accounts.ticket), getAccountMeta("tenant", accounts.tenant), getAccountMeta("player", accounts.player)], data: getCloseTicketInstructionDataEncoder().encode({}), programAddress } as CloseTicketInstruction<TProgramAddress, TAccountTicket, TAccountTenant, TAccountPlayer>);
58
+ }
59
+
60
+ export type CloseTicketInput<TAccountTicket extends string = string, TAccountTenant extends string = string, TAccountPlayer extends string = string> = {
61
+ ticket: Address<TAccountTicket>;
62
+ tenant: Address<TAccountTenant>;
63
+ player: TransactionSigner<TAccountPlayer>;
64
+ }
65
+
66
+ export function getCloseTicketInstruction<TAccountTicket extends string, TAccountTenant extends string, TAccountPlayer extends string, TProgramAddress extends Address = typeof DUEL_PROGRAM_ADDRESS>(input: CloseTicketInput<TAccountTicket, TAccountTenant, TAccountPlayer>, config?: { programAddress?: TProgramAddress } ): CloseTicketInstruction<TProgramAddress, TAccountTicket, TAccountTenant, TAccountPlayer> {
67
+ // Program address.
68
+ const programAddress = config?.programAddress ?? DUEL_PROGRAM_ADDRESS;
69
+
70
+ // Original accounts.
71
+ const originalAccounts = { ticket: { value: input.ticket ?? null, isWritable: true }, tenant: { value: input.tenant ?? null, isWritable: false }, player: { value: input.player ?? null, isWritable: true } }
72
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
73
+
74
+
75
+
76
+
77
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
78
+ return Object.freeze({ accounts: [getAccountMeta("ticket", accounts.ticket), getAccountMeta("tenant", accounts.tenant), getAccountMeta("player", accounts.player)], data: getCloseTicketInstructionDataEncoder().encode({}), programAddress } as CloseTicketInstruction<TProgramAddress, TAccountTicket, TAccountTenant, TAccountPlayer>);
79
+ }
80
+
81
+ export type ParsedCloseTicketInstruction<TProgram extends string = typeof DUEL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
82
+ accounts: {
83
+ ticket: TAccountMetas[0];
84
+ tenant: TAccountMetas[1];
85
+ player: TAccountMetas[2];
86
+ };
87
+ data: CloseTicketInstructionData; };
88
+
89
+ export function parseCloseTicketInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedCloseTicketInstruction<TProgram, TAccountMetas> {
90
+ if (instruction.accounts.length < 3) {
91
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 3 });
92
+ }
93
+ let accountIndex = 0;
94
+ const getNextAccount = () => {
95
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
96
+ accountIndex += 1;
97
+ return accountMeta;
98
+ }
99
+ return { programAddress: instruction.programAddress, accounts: { ticket: getNextAccount(), tenant: getNextAccount(), player: getNextAccount() }, data: getCloseTicketInstructionDataDecoder().decode(instruction.data) };
100
+ }